diff --git a/src/main/java/bentobox/addon/level/TopTen.java b/src/main/java/bentobox/addon/level/TopTen.java index 80025f6..df728a3 100644 --- a/src/main/java/bentobox/addon/level/TopTen.java +++ b/src/main/java/bentobox/addon/level/TopTen.java @@ -14,7 +14,6 @@ import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Listener; -import bentobox.addon.level.database.object.LevelsData; import bentobox.addon.level.database.object.TopTenData; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; @@ -33,7 +32,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) { @@ -61,37 +59,13 @@ public class TopTen implements Listener { // Try and see if the player is online Player player = addon.getServer().getPlayer(ownerUUID); - if (player != null) { - // Online - if (!player.hasPermission(addon.getPlugin().getIWM().getPermissionPrefix(world) + ".intopten")) { - topTenList.get(world).remove(ownerUUID); - return; - } + if (player != null && !player.hasPermission(addon.getPlugin().getIWM().getPermissionPrefix(world) + ".intopten")) { + topTenList.get(world).remove(ownerUUID); + return; } topTenList.get(world).addLevel(ownerUUID, l); } - /** - * Creates the top ten list from scratch. Does not get the level of each island. Just - * takes the level from the player's file. - * Runs asynchronously from the main thread. - */ - public void create(String permPrefix) { - // Obtain all the levels for each known player - Database levelHandler = addon.getHandler(); - long index = 0; - for (LevelsData lv : levelHandler.loadObjects()) { - if (index++ % 1000 == 0) { - addon.getLogger().info("Processed " + index + " players for top ten"); - } - // Convert to UUID - UUID playerUUID = UUID.fromString(lv.getUniqueId()); - // Get the world - lv.getLevels().forEach((k,v) -> addEntry(Bukkit.getWorld(k), playerUUID, v)); - } - saveTopTen(); - } - /** * Displays the Top Ten list * @param world @@ -104,8 +78,6 @@ public class TopTen implements Listener { // Check world topTenList.putIfAbsent(world, new TopTenData()); topTenList.get(world).setUniqueId(world.getName()); - if (DEBUG) - addon.getLogger().info("DEBUG: GUI display"); PanelBuilder panel = new PanelBuilder() .name(user.getTranslation("island.top.gui-title")) @@ -116,22 +88,14 @@ public class TopTen implements Listener { while (it.hasNext()) { Map.Entry m = it.next(); UUID topTenUUID = m.getKey(); - if (DEBUG) - addon.getLogger().info("DEBUG: " + i + ": " + topTenUUID); // Remove from TopTen if the player is online and has the permission Player entry = addon.getServer().getPlayer(topTenUUID); boolean show = true; if (entry != null) { - if (DEBUG) - addon.getLogger().info("DEBUG: removing from topten"); if (!entry.hasPermission(permPrefix + "intopten")) { it.remove(); show = false; } - } else { - if (DEBUG) - addon.getLogger().info("DEBUG: player not online, so no per check"); - } if (show) { panel.item(SLOTS[i-1], getHead(i, m.getValue(), topTenUUID, user, world)); @@ -168,21 +132,6 @@ public class TopTen implements Listener { .icon(name) .name(name) .description(description); - - // If welcome warps is present then add warping - /* - addon.getAddonByName("BSkyBlock-WelcomeWarps").ifPresent(warp -> { - - if (((Warp)warp).getWarpSignsManager().hasWarp(world, playerUUID)) { - builder.clickHandler((panel, user, click, slot) -> { - if (click.equals(ClickType.LEFT)) { - user.sendMessage("island.top.warp-to", "[name]", name); - ((Warp)warp).getWarpSignsManager().warpPlayer(world, user, playerUUID); - } - return true; - }); - } - });*/ return builder.build(); } diff --git a/src/main/java/bentobox/addon/level/calculators/CalcIslandLevel.java b/src/main/java/bentobox/addon/level/calculators/CalcIslandLevel.java index 21aa74b..79cff3c 100644 --- a/src/main/java/bentobox/addon/level/calculators/CalcIslandLevel.java +++ b/src/main/java/bentobox/addon/level/calculators/CalcIslandLevel.java @@ -17,11 +17,9 @@ import org.bukkit.scheduler.BukkitTask; import com.google.common.collect.HashMultiset; import com.google.common.collect.Multiset; import com.google.common.collect.Multiset.Entry; - -import bentobox.addon.level.Level; - import com.google.common.collect.Multisets; +import bentobox.addon.level.Level; import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.util.Pair; import world.bentobox.bentobox.util.Util; @@ -31,6 +29,7 @@ public class CalcIslandLevel { private static final int MAX_CHUNKS = 200; private static final long SPEED = 1; + private static final String LINE_BREAK = "=================================="; private boolean checking = true; private BukkitTask task; @@ -56,7 +55,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; @@ -226,7 +225,7 @@ public class CalcIslandLevel { reportLines.add("Level cost = " + addon.getSettings().getLevelCost()); reportLines.add("Deaths handicap = " + result.deathHandicap); reportLines.add("Level calculated = " + result.level); - reportLines.add("=================================="); + reportLines.add(LINE_BREAK); int total = 0; if (!result.uwCount.isEmpty()) { reportLines.add("Underwater block count (Multiplier = x" + addon.getSettings().getUnderWaterMultiplier() + ") value"); @@ -238,7 +237,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()) { @@ -252,23 +250,22 @@ public class CalcIslandLevel { } reportLines.add(type.getElement().toString() + ": " + String.format("%,d",type.getCount()) + " blocks (max " + limit + explain); } - reportLines.add("=================================="); + reportLines.add(LINE_BREAK); 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()) { Entry type = it.next(); reportLines.add(type.getElement().toString() + ": " + String.format("%,d",type.getCount()) + " blocks"); } - reportLines.add("================================="); + reportLines.add(LINE_BREAK); return reportLines; } private Collection sortedReport(int total, Multiset MaterialCount) { - Collection result = new ArrayList<>(); + Collection r = new ArrayList<>(); Iterable> entriesSortedByCount = Multisets.copyHighestCountFirst(MaterialCount).entrySet(); Iterator> it = entriesSortedByCount.iterator(); while (it.hasNext()) { @@ -280,13 +277,13 @@ public class CalcIslandLevel { // Specific value = addon.getSettings().getBlockValues().get(type); } - result.add(type.toString() + ":" + r.add(type.toString() + ":" + String.format("%,d",en.getCount()) + " blocks x " + value + " = " + (value * en.getCount())); total += (value * en.getCount()); } - result.add("Subtotal = " + total); - result.add("=================================="); - return result; + r.add("Subtotal = " + total); + r.add(LINE_BREAK); + return r; } /** diff --git a/src/main/java/bentobox/addon/level/calculators/PlayerLevel.java b/src/main/java/bentobox/addon/level/calculators/PlayerLevel.java index 6adfeed..dee5af5 100644 --- a/src/main/java/bentobox/addon/level/calculators/PlayerLevel.java +++ b/src/main/java/bentobox/addon/level/calculators/PlayerLevel.java @@ -44,45 +44,49 @@ public class PlayerLevel { addon.getServer().getPluginManager().callEvent(e); if (!e.isCancelled()) { // Calculate if not cancelled - calc = new CalcIslandLevel(addon, island, ()-> informPlayers()); + calc = new CalcIslandLevel(addon, island, ()-> fireIslandLevelCalcEvent()); } } - private void informPlayers() { + private void fireIslandLevelCalcEvent() { // Fire post calculation event IslandLevelCalculatedEvent ilce = new IslandLevelCalculatedEvent(targetPlayer, island, calc.getResult()); addon.getServer().getPluginManager().callEvent(ilce); Results results = ilce.getResults(); // Save the results island.getMemberSet().forEach(m -> addon.setIslandLevel(world, m, results.getLevel())); - // Display result + // Display result if event is not cancelled if (!ilce.isCancelled()) { - // Tell the asker - asker.sendMessage("island.level.island-level-is", "[level]", String.valueOf(addon.getIslandLevel(world, targetPlayer))); - // Console - if (!asker.isPlayer()) { - results.getReport().forEach(asker::sendRawMessage); - return; - } - // Player - if (addon.getSettings().getDeathPenalty() != 0) { - asker.sendMessage("island.level.deaths", "[number]", String.valueOf(results.getDeathHandicap())); - } - // Send player how many points are required to reach next island level - if (results.getPointsToNextLevel() >= 0) { - asker.sendMessage("island.level.required-points-to-next-level", "[points]", String.valueOf(results.getPointsToNextLevel())); - } - // Tell other team members - if (addon.getIslandLevel(world, targetPlayer) != oldLevel) { - for (UUID member : island.getMemberSet()) { - if (!member.equals(asker.getUniqueId())) { - User.getInstance(member).sendMessage("island.level.island-level-is", "[level]", String.valueOf(addon.getIslandLevel(world, targetPlayer))); - } - } - } + informPlayers(results); } } + private void informPlayers(Results results) { + // Tell the asker + asker.sendMessage("island.level.island-level-is", "[level]", String.valueOf(addon.getIslandLevel(world, targetPlayer))); + // Console + if (!asker.isPlayer()) { + results.getReport().forEach(asker::sendRawMessage); + return; + } + // Player + if (addon.getSettings().getDeathPenalty() != 0) { + asker.sendMessage("island.level.deaths", "[number]", String.valueOf(results.getDeathHandicap())); + } + // Send player how many points are required to reach next island level + if (results.getPointsToNextLevel() >= 0) { + asker.sendMessage("island.level.required-points-to-next-level", "[points]", String.valueOf(results.getPointsToNextLevel())); + } + // Tell other team members + if (addon.getIslandLevel(world, targetPlayer) != oldLevel) { + island.getMemberSet().stream() + .filter(u -> !u.equals(asker.getUniqueId())) + .forEach(m -> User.getInstance(m).sendMessage("island.level.island-level-is", "[level]", String.valueOf(addon.getIslandLevel(world, targetPlayer)))); + } + + } + + } diff --git a/src/main/java/bentobox/addon/level/commands/AdminLevel.java b/src/main/java/bentobox/addon/level/commands/AdminLevel.java index b48fb4a..eb2c7ba 100644 --- a/src/main/java/bentobox/addon/level/commands/AdminLevel.java +++ b/src/main/java/bentobox/addon/level/commands/AdminLevel.java @@ -22,7 +22,6 @@ public class AdminLevel extends CompositeCommand { // Asking for another player's level? // Convert name to a UUID final UUID playerUUID = getPlugin().getPlayers().getUUID(args.get(0)); - //getLogger().info("DEBUG: console player info UUID = " + playerUUID); if (playerUUID == null) { user.sendMessage("general.errors.unknown-player"); return true; diff --git a/src/main/java/bentobox/addon/level/commands/IslandLevel.java b/src/main/java/bentobox/addon/level/commands/IslandLevel.java index 72dec86..7620cd4 100644 --- a/src/main/java/bentobox/addon/level/commands/IslandLevel.java +++ b/src/main/java/bentobox/addon/level/commands/IslandLevel.java @@ -22,7 +22,6 @@ public class IslandLevel extends CompositeCommand { // Asking for another player's level? // Convert name to a UUID final UUID playerUUID = getPlugin().getPlayers().getUUID(args.get(0)); - //getLogger().info("DEBUG: console player info UUID = " + playerUUID); if (playerUUID == null) { user.sendMessage("general.errors.unknown-player"); return true; diff --git a/src/main/java/bentobox/addon/level/config/Settings.java b/src/main/java/bentobox/addon/level/config/Settings.java index 3757a75..a492daf 100644 --- a/src/main/java/bentobox/addon/level/config/Settings.java +++ b/src/main/java/bentobox/addon/level/config/Settings.java @@ -47,30 +47,29 @@ public class Settings { } if (level.getConfig().isSet("limits")) { - HashMap blockLimits = new HashMap<>(); + HashMap bl = new HashMap<>(); for (String material : level.getConfig().getConfigurationSection("limits").getKeys(false)) { try { Material mat = Material.valueOf(material); - blockLimits.put(mat, level.getConfig().getInt("limits." + material, 0)); + bl.put(mat, level.getConfig().getInt("limits." + material, 0)); } catch (Exception e) { - level.getLogger().warning("Unknown material (" + material + ") in blockvalues.yml Limits section. Skipping..."); + level.getLogger().warning(() -> "Unknown material (" + material + ") in blockvalues.yml Limits section. Skipping..."); } } - setBlockLimits(blockLimits); + setBlockLimits(bl); } if (level.getConfig().isSet("blocks")) { - Map blockValues = new HashMap<>(); + Map bv = new HashMap<>(); for (String material : level.getConfig().getConfigurationSection("blocks").getKeys(false)) { try { Material mat = Material.valueOf(material); - blockValues.put(mat, level.getConfig().getInt("blocks." + material, 0)); + bv.put(mat, level.getConfig().getInt("blocks." + material, 0)); } catch (Exception e) { - // e.printStackTrace(); - level.getLogger().warning("Unknown material (" + material + ") in config.yml blocks section. Skipping..."); + level.getLogger().warning(()-> "Unknown material (" + material + ") in config.yml blocks section. Skipping..."); } } - setBlockValues(blockValues); + setBlockValues(bv); } else { level.getLogger().severe("No block values in config.yml! All island levels will be zero!"); } @@ -88,7 +87,7 @@ public class Settings { worldBlockValues.put(bWorld, values); } } else { - level.getLogger().severe("Level Addon: No such world : " + world); + level.getLogger().severe(() -> "Level Addon: No such world : " + world); } } } diff --git a/src/main/java/bentobox/addon/level/database/object/TopTenData.java b/src/main/java/bentobox/addon/level/database/object/TopTenData.java index 3a31b56..63f17cf 100644 --- a/src/main/java/bentobox/addon/level/database/object/TopTenData.java +++ b/src/main/java/bentobox/addon/level/database/object/TopTenData.java @@ -16,14 +16,12 @@ import world.bentobox.bentobox.database.objects.DataObject; * */ public class TopTenData implements DataObject { - + // UniqueId is the world name @Expose private String uniqueId = ""; @Expose private Map topTen = new LinkedHashMap<>(); - - public TopTenData() {} public Map getTopTen() { return topTen.entrySet().stream() @@ -54,7 +52,7 @@ public class TopTenData implements DataObject { public void addLevel(UUID uuid, Long level) { this.topTen.put(uuid, level); } - + /** * Get the level for this UUID, or zero if the UUID is not found * @param uuid @@ -71,7 +69,7 @@ public class TopTenData implements DataObject { * @param ownerUUID */ public void remove(UUID ownerUUID) { - this.topTen.remove(ownerUUID); + this.topTen.remove(ownerUUID); } - + } diff --git a/src/main/java/bentobox/addon/level/event/TopTenClick.java b/src/main/java/bentobox/addon/level/event/TopTenClick.java index 7bc9d34..20e35a8 100644 --- a/src/main/java/bentobox/addon/level/event/TopTenClick.java +++ b/src/main/java/bentobox/addon/level/event/TopTenClick.java @@ -6,15 +6,15 @@ import org.bukkit.event.HandlerList; /** * This event is fired when a player clicks on a top ten head. - * + * * @author tastybento */ public class TopTenClick extends Event implements Cancellable { - + private boolean cancelled; private static final HandlerList handlers = new HandlerList(); private final String owner; - + public TopTenClick(String owner) { this.owner = owner; @@ -35,12 +35,12 @@ public class TopTenClick extends Event implements Cancellable { @Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; - + } @Override public HandlerList getHandlers() { - return handlers; + return getHandlerList(); } public static HandlerList getHandlerList() {