forked from SteamWar/SteamWar
Hotfix BauScoreboard
This commit is contained in:
+21
-12
@@ -4,13 +4,13 @@ import de.steamwar.bausystem.BauSystem;
|
|||||||
import de.steamwar.bausystem.region.GlobalRegion;
|
import de.steamwar.bausystem.region.GlobalRegion;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
|
||||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import de.steamwar.scoreboard.SWScoreboard;
|
import de.steamwar.scoreboard.SWScoreboard;
|
||||||
import de.steamwar.scoreboard.ScoreboardCallback;
|
import de.steamwar.scoreboard.ScoreboardCallback;
|
||||||
import org.apache.commons.lang3.tuple.MutableTriple;
|
import lombok.AllArgsConstructor;
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -22,8 +22,17 @@ import java.util.*;
|
|||||||
@Linked
|
@Linked
|
||||||
public class BauScoreboard implements Listener {
|
public class BauScoreboard implements Listener {
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class Data {
|
||||||
|
private ScoreboardElement.ScoreboardGroup group;
|
||||||
|
private Integer priority;
|
||||||
|
private String text;
|
||||||
|
}
|
||||||
|
|
||||||
private static final Map<ScoreboardElement.ScoreboardGroup, List<ScoreboardElement>> ELEMENTS = new HashMap<>();
|
private static final Map<ScoreboardElement.ScoreboardGroup, List<ScoreboardElement>> ELEMENTS = new HashMap<>();
|
||||||
private static final Map<Player, Map<String, MutableTriple<ScoreboardElement.ScoreboardGroup, Integer, String>>> ADDITIONAL_SCOREBOARD_LINES = new HashMap<>();
|
private static final Map<Player, Map<String, Data>> ADDITIONAL_SCOREBOARD_LINES = new HashMap<>();
|
||||||
|
|
||||||
public static void addElement(ScoreboardElement scoreboardElement) {
|
public static void addElement(ScoreboardElement scoreboardElement) {
|
||||||
List<ScoreboardElement> elements = ELEMENTS.computeIfAbsent(scoreboardElement.getGroup(), scoreboardGroup -> new ArrayList<>());
|
List<ScoreboardElement> elements = ELEMENTS.computeIfAbsent(scoreboardElement.getGroup(), scoreboardGroup -> new ArrayList<>());
|
||||||
@@ -32,15 +41,15 @@ public class BauScoreboard implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setAdditionalElement(Player player, String key, ScoreboardElement.ScoreboardGroup group, int priority, String value) {
|
public static void setAdditionalElement(Player player, String key, ScoreboardElement.ScoreboardGroup group, int priority, String value) {
|
||||||
Map<String, MutableTriple<ScoreboardElement.ScoreboardGroup, Integer, String>> playerElements = ADDITIONAL_SCOREBOARD_LINES.computeIfAbsent(player, player1 -> new HashMap<>());
|
Map<String, Data> playerElements = ADDITIONAL_SCOREBOARD_LINES.computeIfAbsent(player, player1 -> new HashMap<>());
|
||||||
if (value == null || value.isBlank()) {
|
if (value == null || value.isBlank()) {
|
||||||
playerElements.remove(key);
|
playerElements.remove(key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MutableTriple<ScoreboardElement.ScoreboardGroup, Integer, String> element = playerElements.computeIfAbsent(key, s -> new MutableTriple<>(null, null, null));
|
Data element = playerElements.computeIfAbsent(key, s -> new Data(null, null, null));
|
||||||
element.setLeft(group);
|
element.setGroup(group);
|
||||||
element.setMiddle(priority);
|
element.setPriority(priority);
|
||||||
element.setRight(value);
|
element.setText(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -76,10 +85,10 @@ public class BauScoreboard implements Listener {
|
|||||||
if (ADDITIONAL_SCOREBOARD_LINES.containsKey(player)) {
|
if (ADDITIONAL_SCOREBOARD_LINES.containsKey(player)) {
|
||||||
ADDITIONAL_SCOREBOARD_LINES.get(player).values()
|
ADDITIONAL_SCOREBOARD_LINES.get(player).values()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(triple -> triple.getLeft() == group)
|
.filter(triple -> triple.getGroup() == group)
|
||||||
.sorted(Comparator.comparing(MutableTriple::getMiddle))
|
.sorted(Comparator.comparing(Data::getPriority))
|
||||||
.forEach(triple -> {
|
.forEach(triple -> {
|
||||||
groupElements.add(triple.getRight());
|
groupElements.add(triple.getText());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
groupElements.removeIf(Objects::isNull);
|
groupElements.removeIf(Objects::isNull);
|
||||||
|
|||||||
Reference in New Issue
Block a user