Help with game I'm making

I am trying to make a simple game in java. This is the code I am using to make the player object unable to pass through the other objects

public void SolidObject(GameObject sObject) {
if(player.x>=(sObject.x-sObject.dimX-6)&&player.y>(sObject.y-sObject.dimY)&&player.y<(sObject.y+sObject.dimY)) {
if(player.x<sObject.x) {
player.rightObstacle = true;
sObject.removeRemoveRightBlock = false;
}
}
if(player.x<(sObject.x-sObject.dimX-6)||player.y<(sObject.y-sObject.dimY)||player.y>(sObject.y+sObject.dimY)||player.x>(sObject.x+sObject.dimX)) {
if(sObject.removeRemoveRightBlock==false) {
player.rightObstacle = false;
sObject.removeRemoveRightBlock = true;
}
}
if(player.x<=(sObject.x+sObject.dimX+6)&&player.y>(sObject.y-sObject.dimY)&&player.y<(sObject.y+sObject.dimY)) {
if(player.x>sObject.x) {
player.leftObstacle = true;
sObject.removeRemoveLeftBlock = false;
}
}
if(player.x>(sObject.x+sObject.dimX+6)||player.y<(sObject.y-sObject.dimY)||player.y>(sObject.y+sObject.dimY)||player.x<(sObject.x-sObject.dimX)) {
if(sObject.removeRemoveLeftBlock==false) {
player.leftObstacle = false;
sObject.removeRemoveLeftBlock = true;
}
}
if(player.y>=(sObject.y-sObject.dimY-6)&&player.x>(sObject.x-sObject.dimX)&&player.x<(sObject.x+sObject.dimX)) {
if(player.y<sObject.y) {
player.upObstacle = true;
sObject.removeRemoveUpBlock = false;
}
}
if(player.y<(sObject.y-sObject.dimY-6)||player.x<(sObject.x-sObject.dimX)||player.x>(sObject.x+sObject.dimX)||player.y>(sObject.y+sObject.dimY)) {
if(sObject.removeRemoveUpBlock==false) {
player.upObstacle = false;
sObject.removeRemoveUpBlock = true;
}
}
if(player.y<=(sObject.y+sObject.dimY+6)&&player.x>(sObject.x-sObject.dimX-6)&&player.x<(sObject.x+sObject.dimX+6)) {
if(player.y>sObject.y) {
player.lowObstacle = true;
sObject.removeRemoveLowBlock = false;
}
}
if(player.y>(sObject.y+sObject.dimY+6)||player.x<(sObject.x-sObject.dimX)||player.x>(sObject.x+sObject.dimX)||player.y<(sObject.y-sObject.dimY)) {
if(sObject.removeRemoveLowBlock==false) {
player.lowObstacle = false;
sObject.removeRemoveLowBlock = true;
}
}
}

every currently loaded object besides the player runs this code every frame, to stop the player from moving towards them when they are touching. However, despite the code being the same for both sides, the player can actually push slightly inside the right side of this object, but is stopped a ways back from its left side. Changing the movement speed of the player doesn’t fix this. Moving the position of the object can reduce this problem, but the included images are showing it already reduced as far as it can be. Object is size 45. Any idea how to fix this?


Here is the other image since github wouldn’t let me upload both images in one post