The following code should find the closest Enemy class object (if any Enemy class objects are in the world), no matter how far it may be from the player, and transport it to that player.
if (!getObjectsInRange(1000, Enemy.class).isEmpty) { int closeness = 0; while (getObjectsInRange(closeness, Enemy.class).isEmpty) closeness++; Enemy enemy = (Enemy) getObjectsInRange(closeness, Enemy.class).get(0); enemy.setLocation(getX(), getY()); }