diff --git a/src/main/java/bentobox/addon/level/LevelPresenter.java b/src/main/java/bentobox/addon/level/LevelPresenter.java index a55bbb2..9c01f5c 100644 --- a/src/main/java/bentobox/addon/level/LevelPresenter.java +++ b/src/main/java/bentobox/addon/level/LevelPresenter.java @@ -76,11 +76,8 @@ public class LevelPresenter { private boolean onLevelWaitTime(final User sender) { if (levelWaitTime.containsKey(sender.getUniqueId())) { - if (levelWaitTime.get(sender.getUniqueId()).longValue() > Calendar.getInstance().getTimeInMillis()) { - return true; - } + return levelWaitTime.get(sender.getUniqueId()).longValue() > Calendar.getInstance().getTimeInMillis(); - return false; } return false; diff --git a/src/main/java/bentobox/addon/level/TopTen.java b/src/main/java/bentobox/addon/level/TopTen.java index 80025f6..042e426 100644 --- a/src/main/java/bentobox/addon/level/TopTen.java +++ b/src/main/java/bentobox/addon/level/TopTen.java @@ -33,7 +33,6 @@ public class TopTen implements Listener { // Top ten list of players private Map topTenList; private final int[] SLOTS = new int[] {4, 12, 14, 19, 20, 21, 22, 23, 24, 25}; - private final boolean DEBUG = false; private Database handler; public TopTen(Level addon) { @@ -104,6 +103,7 @@ public class TopTen implements Listener { // Check world topTenList.putIfAbsent(world, new TopTenData()); topTenList.get(world).setUniqueId(world.getName()); + boolean DEBUG = false; if (DEBUG) addon.getLogger().info("DEBUG: GUI display"); diff --git a/src/main/java/bentobox/addon/level/calculators/CalcIslandLevel.java b/src/main/java/bentobox/addon/level/calculators/CalcIslandLevel.java index 21aa74b..4ef9675 100644 --- a/src/main/java/bentobox/addon/level/calculators/CalcIslandLevel.java +++ b/src/main/java/bentobox/addon/level/calculators/CalcIslandLevel.java @@ -31,19 +31,19 @@ public class CalcIslandLevel { private static final int MAX_CHUNKS = 200; private static final long SPEED = 1; - private boolean checking = true; - private BukkitTask task; + private boolean checking; + private final BukkitTask task; - private Level addon; + private final Level addon; - private Set> chunksToScan; - private Island island; - private World world; - private Results result; - private Runnable onExit; + private final Set> chunksToScan; + private final Island island; + private final World world; + private final Results result; + private final Runnable onExit; - // Copy the limits hashmap - HashMap limitCount; + // Copy the limits hash map + private final HashMap limitCount; /** @@ -56,7 +56,7 @@ public class CalcIslandLevel { public CalcIslandLevel(final Level addon, final Island island, final Runnable onExit) { this.addon = addon; this.island = island; - this.world = island != null ? island.getCenter().getWorld() : null; + this.world = island.getCenter().getWorld(); this.limitCount = new HashMap<>(addon.getSettings().getBlockLimits()); this.onExit = onExit; @@ -112,19 +112,19 @@ public class CalcIslandLevel { private void scanChunk(ChunkSnapshot chunk) { for (int x = 0; x< 16; x++) { - // Check if the block coord is inside the protection zone and if not, don't count it + // Check if the block coordinate is inside the protection zone and if not, don't count it if (chunk.getX() * 16 + x < island.getMinProtectedX() || chunk.getX() * 16 + x >= island.getMinProtectedX() + island.getProtectionRange() * 2) { continue; } for (int z = 0; z < 16; z++) { - // Check if the block coord is inside the protection zone and if not, don't count it + // Check if the block coordinate is inside the protection zone and if not, don't count it if (chunk.getZ() * 16 + z < island.getMinProtectedZ() || chunk.getZ() * 16 + z >= island.getMinProtectedZ() + island.getProtectionRange() * 2) { continue; } for (int y = 0; y < island.getCenter().getWorld().getMaxHeight(); y++) { Material blockData = chunk.getBlockType(x, y, z); - boolean belowSeaLevel = (addon.getSettings().getSeaHeight() > 0 && y<=addon.getSettings().getSeaHeight()) ? true : false; + boolean belowSeaLevel = addon.getSettings().getSeaHeight() > 0 && y <= addon.getSettings().getSeaHeight(); // Air is free if (!blockData.equals(Material.AIR)) { checkBlock(blockData, belowSeaLevel); @@ -147,7 +147,7 @@ public class CalcIslandLevel { /** * Checks if a block has been limited or not and whether a block has any value or not - * @param md + * @param md Material * @return value of the block if can be counted */ private int limitCount(Material md) { @@ -171,7 +171,7 @@ public class CalcIslandLevel { /** * Get value of a material * World blocks trump regular block values - * @param md + * @param md Material * @return value of a material */ private int getValue(Material md) { @@ -183,8 +183,8 @@ public class CalcIslandLevel { /** * Get a set of all the chunks in island - * @param island - * @return + * @param island - island + * @return - set of all the chunks in the island to scan */ private Set> getChunksToScan(Island island) { Set> chunkSnapshot = new HashSet<>(); @@ -238,7 +238,6 @@ public class CalcIslandLevel { reportLines.addAll(sortedReport(total, result.mdCount)); reportLines.add("Blocks not counted because they exceeded limits: " + String.format("%,d",result.ofCount.size())); - //entriesSortedByCount = Multisets.copyHighestCountFirst(ofCount).entrySet(); Iterable> entriesSortedByCount = result.ofCount.entrySet(); Iterator> it = entriesSortedByCount.iterator(); while (it.hasNext()) { @@ -255,7 +254,6 @@ public class CalcIslandLevel { reportLines.add("=================================="); reportLines.add("Blocks on island that are not in config.yml"); reportLines.add("Total number = " + String.format("%,d",result.ncCount.size())); - //entriesSortedByCount = Multisets.copyHighestCountFirst(ncCount).entrySet(); entriesSortedByCount = result.ncCount.entrySet(); it = entriesSortedByCount.iterator(); while (it.hasNext()) { @@ -270,9 +268,7 @@ public class CalcIslandLevel { private Collection sortedReport(int total, Multiset MaterialCount) { Collection result = new ArrayList<>(); Iterable> entriesSortedByCount = Multisets.copyHighestCountFirst(MaterialCount).entrySet(); - Iterator> it = entriesSortedByCount.iterator(); - while (it.hasNext()) { - Entry en = it.next(); + for (Entry en : entriesSortedByCount) { Material type = en.getElement(); int value = 0; @@ -281,7 +277,7 @@ public class CalcIslandLevel { value = addon.getSettings().getBlockValues().get(type); } result.add(type.toString() + ":" - + String.format("%,d",en.getCount()) + " blocks x " + value + " = " + (value * en.getCount())); + + String.format("%,d", en.getCount()) + " blocks x " + value + " = " + (value * en.getCount())); total += (value * en.getCount()); } result.add("Subtotal = " + total); @@ -302,10 +298,10 @@ public class CalcIslandLevel { */ public class Results { private List report; - private Multiset mdCount = HashMultiset.create(); - private Multiset uwCount = HashMultiset.create(); - private Multiset ncCount = HashMultiset.create(); - private Multiset ofCount = HashMultiset.create(); + private final Multiset mdCount = HashMultiset.create(); + private final Multiset uwCount = HashMultiset.create(); + private final Multiset ncCount = HashMultiset.create(); + private final Multiset ofCount = HashMultiset.create(); private long rawBlockCount = 0; private long underWaterBlockCount = 0; private long level = 0; @@ -317,12 +313,7 @@ public class CalcIslandLevel { public int getDeathHandicap() { return deathHandicap; } - /** - * @param deathHandicap the deathHandicap to set - */ - public void setDeathHandicap(int deathHandicap) { - this.deathHandicap = deathHandicap; - } + /** * @return the report */ @@ -341,24 +332,6 @@ public class CalcIslandLevel { public long getPointsToNextLevel() { return pointsToNextLevel; } - /** - * @param report the report to set - */ - public void setReport(List report) { - this.report = report; - } - /** - * @param level the level to set - */ - public void setLevel(long level) { - this.level = level; - } - /** - * @param pointsToNextLevel the pointsToNextLevel to set - */ - public void setPointsToNextLevel(long pointsToNextLevel) { - this.pointsToNextLevel = pointsToNextLevel; - } } } diff --git a/src/main/java/bentobox/addon/level/commands/AdminTop.java b/src/main/java/bentobox/addon/level/commands/AdminTop.java index 72d6ce6..6644098 100644 --- a/src/main/java/bentobox/addon/level/commands/AdminTop.java +++ b/src/main/java/bentobox/addon/level/commands/AdminTop.java @@ -23,7 +23,7 @@ public class AdminTop extends CompositeCommand { @Override public boolean execute(User user, String label, List args) { // Get world - World world = null; + World world; if (args.isEmpty()) { if (getPlugin().getIWM().getOverWorlds().size() == 1) { world = getPlugin().getIWM().getOverWorlds().get(0); diff --git a/src/test/java/bentobox/addon/level/LevelPresenterTest.java b/src/test/java/bentobox/addon/level/LevelPresenterTest.java index 523de08..a1c5861 100644 --- a/src/test/java/bentobox/addon/level/LevelPresenterTest.java +++ b/src/test/java/bentobox/addon/level/LevelPresenterTest.java @@ -35,7 +35,6 @@ public class LevelPresenterTest { private BentoBox plugin; private Level addon; - private IslandsManager im; private PlayerLevel pl; /** @@ -48,7 +47,7 @@ public class LevelPresenterTest { IslandWorldManager iwm = mock(IslandWorldManager.class); when(plugin.getIWM()).thenReturn(iwm); when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("world"); - im = mock(IslandsManager.class); + IslandsManager im = mock(IslandsManager.class); when(plugin.getIslands()).thenReturn(im); // Has island when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);