diff --git a/src/main/java/bskyblock/addon/level/Level.java b/src/main/java/bskyblock/addon/level/Level.java index 9e8a31c..98b9cde 100644 --- a/src/main/java/bskyblock/addon/level/Level.java +++ b/src/main/java/bskyblock/addon/level/Level.java @@ -20,6 +20,7 @@ import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.database.AbstractDatabaseHandler; import us.tastybento.bskyblock.database.BSBDatabase; + /** * Addon to BSkyBlock that enables island level scoring and top ten functionality * @author tastybento diff --git a/src/main/java/bskyblock/addon/level/TopTen.java b/src/main/java/bskyblock/addon/level/TopTen.java index 9753bd6..b095282 100644 --- a/src/main/java/bskyblock/addon/level/TopTen.java +++ b/src/main/java/bskyblock/addon/level/TopTen.java @@ -37,7 +37,7 @@ public class TopTen implements Listener { // Top ten list of players private TopTenData topTenList; private final int[] SLOTS = new int[] {4, 12, 14, 19, 20, 21, 22, 23, 24, 25}; - private final boolean DEBUG = false; + private final boolean DEBUG = true; private BSBDatabase database; private AbstractDatabaseHandler handler; @@ -129,6 +129,8 @@ public class TopTen implements Listener { Player entry = addon.getServer().getPlayer(topTenUUID); boolean show = true; if (entry != null) { + if (DEBUG) + addon.getLogger().info("DEBUG: removing from topten"); if (!entry.hasPermission(Constants.PERMPREFIX + "intopten")) { it.remove(); show = false; diff --git a/src/main/java/bskyblock/addon/level/commands/IslandTop.java b/src/main/java/bskyblock/addon/level/commands/IslandTop.java index 56378da..66eb92b 100644 --- a/src/main/java/bskyblock/addon/level/commands/IslandTop.java +++ b/src/main/java/bskyblock/addon/level/commands/IslandTop.java @@ -19,7 +19,7 @@ public class IslandTop extends CompositeCommand { @Override public boolean execute(User user, List list) { plugin.getTopTen().getGUI(user); - return false; + return true; } @Override diff --git a/src/main/java/bskyblock/addon/level/database/object/TopTenData.java b/src/main/java/bskyblock/addon/level/database/object/TopTenData.java index 0f86490..3f81768 100644 --- a/src/main/java/bskyblock/addon/level/database/object/TopTenData.java +++ b/src/main/java/bskyblock/addon/level/database/object/TopTenData.java @@ -1,7 +1,7 @@ package bskyblock.addon.level.database.object; -import java.util.Comparator; -import java.util.HashMap; +import java.util.Collections; +import java.util.LinkedHashMap; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; @@ -20,13 +20,16 @@ public class TopTenData implements DataObject { @Expose private String uniqueId = "topten"; @Expose - private Map topTen = new HashMap<>(); + private Map topTen = new LinkedHashMap<>(); public Map getTopTen() { - return topTen; + return topTen.entrySet().stream() + .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).limit(10) + .collect(Collectors.toMap( + Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); } - public void setTopTen(HashMap topTen) { + public void setTopTen(Map topTen) { this.topTen = topTen; } @@ -47,7 +50,6 @@ public class TopTenData implements DataObject { */ public void addLevel(UUID uuid, Long level) { this.topTen.put(uuid, level); - sortTopTen(); } /** @@ -69,13 +71,4 @@ public class TopTenData implements DataObject { this.topTen.remove(ownerUUID); } - /** - * Sorts the top ten and limits it to 10 entries - */ - void sortTopTen() { - topTen = (HashMap) topTen.entrySet().stream() - .sorted(Map.Entry.comparingByKey(Comparator.reverseOrder())) - .limit(10) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - } }