Fixed code smells

This commit is contained in:
Florian CUNY 2019-02-21 10:00:59 +01:00
parent 160ef002e4
commit e115a1df4d
3 changed files with 13 additions and 11 deletions

View File

@ -228,7 +228,7 @@ public class User {
if (!NumberUtils.isNumber(spl[1])) { if (!NumberUtils.isNumber(spl[1])) {
plugin.logError("Player " + player.getName() + " has permission: '" + perms.getPermission() + "' <-- the last part MUST be a number! Ignoring..."); plugin.logError("Player " + player.getName() + " has permission: '" + perms.getPermission() + "' <-- the last part MUST be a number! Ignoring...");
} else { } else {
int v = Integer.valueOf(spl[1]); int v = Integer.parseInt(spl[1]);
if (v < 0) { if (v < 0) {
return v; return v;
} }

View File

@ -737,6 +737,7 @@ public class IslandsManager {
* Island coordinates should always be a multiple of the island distance x 2. If they are not, this method * Island coordinates should always be a multiple of the island distance x 2. If they are not, this method
* realigns the grid coordinates. * realigns the grid coordinates.
* @param island - island * @param island - island
* @since 1.3.0
*/ */
public void fixIslandCenter(Island island) { public void fixIslandCenter(Island island) {
World world = island.getWorld(); World world = island.getWorld();
@ -744,8 +745,8 @@ public class IslandsManager {
return; return;
} }
int distance = island.getRange() * 2; int distance = island.getRange() * 2;
long x = island.getCenter().getBlockX() - plugin.getIWM().getIslandXOffset(world); long x = ((long) island.getCenter().getBlockX()) - plugin.getIWM().getIslandXOffset(world);
long z = island.getCenter().getBlockZ() - plugin.getIWM().getIslandZOffset(world); long z = ((long) island.getCenter().getBlockZ()) - plugin.getIWM().getIslandZOffset(world);
if (x % distance != 0 || z % distance != 0) { if (x % distance != 0 || z % distance != 0) {
// Island is off grid // Island is off grid
x = Math.round((double) x / distance) * distance + plugin.getIWM().getIslandXOffset(world); x = Math.round((double) x / distance) * distance + plugin.getIWM().getIslandXOffset(world);
@ -975,6 +976,7 @@ public class IslandsManager {
* @return optional island * @return optional island
* @since 1.3.0 * @since 1.3.0
*/ */
@NonNull
public Optional<Island> getIslandById(String uniqueId) { public Optional<Island> getIslandById(String uniqueId) {
return Optional.ofNullable(islandCache.getIslandById(uniqueId)); return Optional.ofNullable(islandCache.getIslandById(uniqueId));
} }
@ -987,6 +989,7 @@ public class IslandsManager {
* @return list of islands; may be empty * @return list of islands; may be empty
* @since 1.3.0 * @since 1.3.0
*/ */
@NonNull
public List<Island> getQuarantinedIslandByUser(@NonNull World world, @Nullable UUID uuid) { public List<Island> getQuarantinedIslandByUser(@NonNull World world, @Nullable UUID uuid) {
return quarantineCache.getOrDefault(uuid, Collections.emptyList()).stream() return quarantineCache.getOrDefault(uuid, Collections.emptyList()).stream()
.filter(i -> i.getWorld().equals(world)).collect(Collectors.toList()); .filter(i -> i.getWorld().equals(world)).collect(Collectors.toList());
@ -1011,6 +1014,7 @@ public class IslandsManager {
* @return the quarantineCache * @return the quarantineCache
* @since 1.3.0 * @since 1.3.0
*/ */
@NonNull
public Map<UUID, List<Island>> getQuarantineCache() { public Map<UUID, List<Island>> getQuarantineCache() {
return quarantineCache; return quarantineCache;
} }
@ -1019,15 +1023,13 @@ public class IslandsManager {
* Remove a quarantined island and delete it from the database completely. * Remove a quarantined island and delete it from the database completely.
* This is NOT recoverable unless you have database backups. * This is NOT recoverable unless you have database backups.
* @param island island * @param island island
* @return <tt>true</tt> if island is quarantined and removed * @return {@code true} if island is quarantined and removed
* @since 1.3.0 * @since 1.3.0
*/ */
public boolean purgeQuarantinedIsland(Island island) { public boolean purgeQuarantinedIsland(Island island) {
if (quarantineCache.containsKey(island.getOwner())) { if (quarantineCache.containsKey(island.getOwner()) && quarantineCache.get(island.getOwner()).remove(island)) {
if (quarantineCache.get(island.getOwner()).remove(island)) { handler.deleteObject(island);
handler.deleteObject(island); return true;
return true;
}
} }
return false; return false;
} }

View File

@ -257,7 +257,7 @@ public class IslandCache {
/** /**
* Get the island by unique id * Get the island by unique id
* @param uniqueId * @param uniqueId unique id of the Island.
* @return island or null if none found * @return island or null if none found
* @since 1.3.0 * @since 1.3.0
*/ */
@ -289,6 +289,6 @@ public class IslandCache {
*/ */
public void resetAllFlags(World world) { public void resetAllFlags(World world) {
World w = Util.getWorld(world); World w = Util.getWorld(world);
islandsById.values().stream().filter(i -> i.getWorld().equals(w)).forEach(i -> i.setFlagsDefaults()); islandsById.values().stream().filter(i -> i.getWorld().equals(w)).forEach(Island::setFlagsDefaults);
} }
} }