Fixed issues with Top Ten

This commit is contained in:
Tastybento 2018-04-02 18:20:26 -07:00
parent c31c2bcbf5
commit 6837218ae4
4 changed files with 13 additions and 17 deletions

View File

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

View File

@ -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<TopTenData> 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;

View File

@ -19,7 +19,7 @@ public class IslandTop extends CompositeCommand {
@Override
public boolean execute(User user, List<String> list) {
plugin.getTopTen().getGUI(user);
return false;
return true;
}
@Override

View File

@ -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<UUID, Long> topTen = new HashMap<>();
private Map<UUID, Long> topTen = new LinkedHashMap<>();
public Map<UUID, Long> 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<UUID, Long> topTen) {
public void setTopTen(Map<UUID, Long> 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<UUID, Long>) topTen.entrySet().stream()
.sorted(Map.Entry.comparingByKey(Comparator.reverseOrder()))
.limit(10)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
}