Object Location changes, why?

Discussion in 'Spigot Plugin Development' started by Goofan, Jun 11, 2016.

  1. Can't seem to figure this one out :/

    With this code:
    Code (Text):

                    Location loc = op.getLocation();
                    loc.setY(loc.getY() - 4);
                    loc.setX(loc.getX() - Math.ceil((3/ 2)) - 1);
                    loc.setZ(loc.getZ() - Math.ceil((3/ 2)) - 1);
    The code changes the op Location which is private and it's a simple getter(#getLocation())
    But after this the op.getLocation had shifted and is now the loc Location :/

  2. Locations are mutable. you need to clone() the op location so you arent modifying it.