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