mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-23 18:45:17 +01:00
Fixed issues with Top Ten
This commit is contained in:
parent
c31c2bcbf5
commit
6837218ae4
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user