Fixed long standing bug in unused Util method getClosestIsland

Changed AdminRegisterCommand to use the method to remove code
duplication.
This commit is contained in:
tastybento 2021-02-17 18:36:57 -08:00
parent 969b413588
commit 04be4cf7de
3 changed files with 4 additions and 18 deletions

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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());
}
/**