Fixed long standing bug in unused Util method getClosestIsland
Changed AdminRegisterCommand to use the method to remove code duplication.
This commit is contained in:
parent
969b413588
commit
04be4cf7de
|
@ -54,7 +54,7 @@ public class AdminRegisterCommand extends ConfirmableCommand {
|
|||
}
|
||||
|
||||
// Check if this spot is still being deleted
|
||||
Location closestIsland = getClosestIsland(user.getLocation());
|
||||
Location closestIsland = Util.getClosestIsland(user.getLocation());
|
||||
if (getPlugin().getIslandDeletionManager().inDeletion(closestIsland)) {
|
||||
user.sendMessage("commands.admin.register.in-deletion");
|
||||
return false;
|
||||
|
@ -141,18 +141,4 @@ public class AdminRegisterCommand extends ConfirmableCommand {
|
|||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the coordinate of where an island should be on the grid.
|
||||
*
|
||||
* @param location - location to check
|
||||
* @return Location of where an island should be on a grid in this world
|
||||
*/
|
||||
public Location getClosestIsland(Location location) {
|
||||
int dist = getIWM().getIslandDistance(getWorld()) * 2;
|
||||
long x = Math.round((double) location.getBlockX() / dist) * dist + getIWM().getIslandXOffset(getWorld());
|
||||
long z = Math.round((double) location.getBlockZ() / dist) * dist + getIWM().getIslandZOffset(getWorld());
|
||||
long y = getIWM().getIslandHeight(getWorld());
|
||||
return new Location(location.getWorld(), x, y, z);
|
||||
}
|
||||
|
||||
}
|
|
@ -88,7 +88,7 @@ public class Util {
|
|||
* @return Location of closest island
|
||||
*/
|
||||
public static Location getClosestIsland(Location location) {
|
||||
int dist = plugin.getIWM().getIslandDistance(location.getWorld());
|
||||
int dist = plugin.getIWM().getIslandDistance(location.getWorld()) * 2;
|
||||
long x = Math.round((double) location.getBlockX() / dist) * dist + plugin.getIWM().getIslandXOffset(location.getWorld());
|
||||
long z = Math.round((double) location.getBlockZ() / dist) * dist + plugin.getIWM().getIslandZOffset(location.getWorld());
|
||||
if (location.getBlockX() == x && location.getBlockZ() == z) {
|
||||
|
|
|
@ -139,8 +139,8 @@ public class UtilTest {
|
|||
when(location.getBlockX()).thenReturn(456);
|
||||
when(location.getBlockZ()).thenReturn(456);
|
||||
Location l = Util.getClosestIsland(location);
|
||||
assertEquals(500, l.getBlockX());
|
||||
assertEquals(500, l.getBlockZ());
|
||||
assertEquals(400, l.getBlockX());
|
||||
assertEquals(400, l.getBlockZ());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue