Global scoreboard testing
Possible implementation -> needs testing Hashmap implementation for leaderboards is garbage Remake this structure and just sort the hashmap into a linkedhashmap on values https://www.digitalocean.com/community/tutorials/sort-hashmap-by-value-java
This commit is contained in:
1 parent
df962e2f49
commit
a460007521
3 files changed
+102
No files matched your search
@@ -175,6 +175,11 @@ public class LanguageConfig {
|
||||
defaults.put("SCOREBOARD_PERSONAL_DEATHS", " &7Deaths: &b%VALUE%");
|
||||
defaults.put("SCOREBOARD_PERSONAL_KD", " &7K/D Ratio: &b%VALUE%");
|
||||
defaults.put("SCOREBOARD_PERSONAL_LEVEL", " &7Level: &b%VALUE%");
|
||||
defaults.put("SCOREBOARD_GLOBAL_TITLE", "&6Global Stats");
|
||||
defaults.put("SCOREBOARD_GLOBAL_KILLSTREAK", " &7Killstreak");
|
||||
defaults.put("SCOREBOARD_GLOBAL_KILLS", " &7Kills");
|
||||
defaults.put("SCOREBOARD_GLOBAL_KD", " &7K/D Ratio");
|
||||
defaults.put("SCOREBOARD_GLOBAL_LEVEL", " &7Level");
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package me.lifelessnerd.purekitpvp;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class sample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Map<Integer, Integer> treeMap = new TreeMap<>();
|
||||
|
||||
// Adding elements to the tree map
|
||||
treeMap.put(1, 0);
|
||||
treeMap.put(2, 0);
|
||||
treeMap.put(3, 0);
|
||||
|
||||
ArrayList<String> array = new ArrayList<>();
|
||||
|
||||
// Iterating over the elements of the tree map
|
||||
int enumerator = 0;
|
||||
for (Integer key : treeMap.keySet()) {
|
||||
if (enumerator >= 6){
|
||||
break;
|
||||
}
|
||||
array.add("Key: " + key + ", Value: " + treeMap.get(key));
|
||||
enumerator++;
|
||||
}
|
||||
|
||||
var dab = "dab";
|
||||
System.out.println(array);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+61
@@ -13,6 +13,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class SidebarScoreboard implements Listener {
|
||||
@@ -63,9 +64,69 @@ public class SidebarScoreboard implements Listener {
|
||||
int places = plugin.getConfig().getInt("global-stats-place-amount");
|
||||
List<String> enabled = plugin.getConfig().getStringList("global-stats-components");
|
||||
|
||||
sidebar.addLine(LanguageConfig.lang.get("SCOREBOARD_GLOBAL_TITLE"));
|
||||
|
||||
for (String component : enabled){
|
||||
ArrayList<Component> createdLeaderboard;
|
||||
switch(component) {
|
||||
case "Killstreak":
|
||||
sidebar.addLine(LanguageConfig.lang.get("SCOREBOARD_GLOBAL_KILLSTREAK"));
|
||||
createdLeaderboard = createLeaderboard(".killstreak", places);
|
||||
System.out.println("LIST: " + createdLeaderboard);
|
||||
sidebar.addUpdatableLine(
|
||||
(player) -> createdLeaderboard.get(0) // TODO test this when hashmap bug is fix -> use hashmap with string.int and use sort
|
||||
// https://www.digitalocean.com/community/tutorials/sort-hashmap-by-value-java
|
||||
);
|
||||
|
||||
break;
|
||||
case "Level":
|
||||
sidebar.addLine(LanguageConfig.lang.get("SCOREBOARD_GLOBAL_LEVEL"));
|
||||
// createdLeaderboard = createLeaderboard(".level", places);
|
||||
|
||||
break;
|
||||
case "Kills":
|
||||
sidebar.addLine(LanguageConfig.lang.get("SCOREBOARD_GLOBAL_KILLS"));
|
||||
// createdLeaderboard = createLeaderboard(".kills", places);
|
||||
|
||||
break;
|
||||
case "KD":
|
||||
sidebar.addLine(LanguageConfig.lang.get("SCOREBOARD_GLOBAL_KD"));
|
||||
// createdLeaderboard = createLeaderboard(".kdratio", places);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sidebar.updateLinesPeriodically(0, 20);
|
||||
}
|
||||
|
||||
private ArrayList<Component> createLeaderboard(String statKey, int places) {
|
||||
TreeMap<Integer, String> leaderboard = new TreeMap<>();
|
||||
|
||||
Set<String> players = PlayerStatsConfig.get().getKeys(false);
|
||||
System.out.println(players.size() + "," + places);
|
||||
for (String player : players){
|
||||
int statValue = PlayerStatsConfig.get().getInt(player + statKey);
|
||||
leaderboard.put(statValue, player);
|
||||
}
|
||||
System.out.println(leaderboard.size());
|
||||
ArrayList<Component> toBeReturned = new ArrayList<>();
|
||||
|
||||
int enumerator = 0;
|
||||
for (Integer stat : leaderboard.keySet()) {
|
||||
if (enumerator >= places){
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.println(leaderboard.get(stat) + ": " + stat);
|
||||
toBeReturned.add(Component.text(leaderboard.get(stat) + ": " + stat));
|
||||
|
||||
enumerator++;
|
||||
}
|
||||
|
||||
return toBeReturned;
|
||||
}
|
||||
|
||||
private void fillPersonalSidebar(Sidebar<Component> sidebar){
|
||||
|
||||
sidebar.addLine(LanguageConfig.lang.get("SCOREBOARD_PERSONAL_TITLE"));
|
||||
|
||||
Reference in new issue
Block a user