Dieser Commit ist enthalten in:
Ursprung
1da5b65460
Commit
3ecd31e80c
@ -47,19 +47,23 @@ public class ScoreboardLib implements LuaLib {
|
||||
}
|
||||
luaTable.set("group", groups);
|
||||
|
||||
luaTable.set("element", new TwoArgFunction() {
|
||||
luaTable.set("element", new VarArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue key, LuaValue group) {
|
||||
String elementKey = key.checkjstring();
|
||||
ScoreboardElement.ScoreboardGroup elementGroup = ScoreboardElement.ScoreboardGroup.values()[group.checkint()];
|
||||
public Varargs invoke(Varargs varargs) {
|
||||
if (varargs.narg() < 2) {
|
||||
return NIL;
|
||||
}
|
||||
String elementKey = varargs.arg(1).checkjstring();
|
||||
ScoreboardElement.ScoreboardGroup elementGroup = ScoreboardElement.ScoreboardGroup.values()[varargs.arg(2).checkint()];
|
||||
int priority = varargs.narg() > 2 ? varargs.arg(2).checkint() : Integer.MAX_VALUE;
|
||||
|
||||
return new VarArgFunction() {
|
||||
@Override
|
||||
public Varargs invoke(Varargs args) {
|
||||
if (args.narg() == 0) {
|
||||
BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, null);
|
||||
BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, priority, null);
|
||||
} else {
|
||||
BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, args.arg1().checkjstring());
|
||||
BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, priority, args.arg1().checkjstring());
|
||||
}
|
||||
return NIL;
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ 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 org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -21,7 +23,7 @@ import java.util.*;
|
||||
public class BauScoreboard implements Listener {
|
||||
|
||||
private static final Map<ScoreboardElement.ScoreboardGroup, List<ScoreboardElement>> ELEMENTS = new HashMap<>();
|
||||
private static final Map<Player, Map<String, Pair<ScoreboardElement.ScoreboardGroup, String>>> ADDITIONAL_SCOREBOARD_LINES = new HashMap<>();
|
||||
private static final Map<Player, Map<String, MutableTriple<ScoreboardElement.ScoreboardGroup, Integer, String>>> ADDITIONAL_SCOREBOARD_LINES = new HashMap<>();
|
||||
|
||||
public static void addElement(ScoreboardElement scoreboardElement) {
|
||||
List<ScoreboardElement> elements = ELEMENTS.computeIfAbsent(scoreboardElement.getGroup(), scoreboardGroup -> new ArrayList<>());
|
||||
@ -29,15 +31,16 @@ public class BauScoreboard implements Listener {
|
||||
elements.sort(Comparator.comparingInt(ScoreboardElement::order));
|
||||
}
|
||||
|
||||
public static void setAdditionalElement(Player player, String key, ScoreboardElement.ScoreboardGroup group, String value) {
|
||||
Map<String, Pair<ScoreboardElement.ScoreboardGroup, String>> playerElements = ADDITIONAL_SCOREBOARD_LINES.computeIfAbsent(player, player1 -> new HashMap<>());
|
||||
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<>());
|
||||
if (value == null || value.isBlank()) {
|
||||
playerElements.remove(key);
|
||||
return;
|
||||
}
|
||||
Pair<ScoreboardElement.ScoreboardGroup, String> element = playerElements.computeIfAbsent(key, s -> new Pair<>(null, null));
|
||||
element.setKey(group);
|
||||
element.setValue(value);
|
||||
MutableTriple<ScoreboardElement.ScoreboardGroup, Integer, String> element = playerElements.computeIfAbsent(key, s -> new MutableTriple<>(null, null, null));
|
||||
element.setLeft(group);
|
||||
element.setMiddle(priority);
|
||||
element.setRight(value);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -76,12 +79,13 @@ public class BauScoreboard implements Listener {
|
||||
}
|
||||
}
|
||||
if (ADDITIONAL_SCOREBOARD_LINES.containsKey(player)) {
|
||||
ADDITIONAL_SCOREBOARD_LINES.get(player).values().forEach(scoreboardGroupStringPair -> {
|
||||
if (scoreboardGroupStringPair.getKey() != group) {
|
||||
return;
|
||||
}
|
||||
elements.add(scoreboardGroupStringPair.getValue());
|
||||
});
|
||||
ADDITIONAL_SCOREBOARD_LINES.get(player).values()
|
||||
.stream()
|
||||
.filter(triple -> triple.getLeft() == group)
|
||||
.sorted(Comparator.comparing(triple -> triple.getMiddle()))
|
||||
.forEach(triple -> {
|
||||
elements.add(triple.getRight());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -260,10 +260,11 @@ Wenn eine Barrier statt des richtigen Items angezeigt wird, dann ist das angegeb
|
||||
Das `scoreboard`-Modul stellt Funktionen zur Verfügung, um Zeilen im Scoreboard hinzuzufügen.
|
||||
Es gibt folgende Funktionen:
|
||||
|
||||
| Name | Signature | Beschreibung |
|
||||
|-----------|-------------------------------------------|----------------------------------------------------------------------|
|
||||
| `group` | | Siehe: [Scoreboardgroups](#scoreboardgroups) |
|
||||
| `element` | element(String, Group): ScoreboardElement | Erstellt ein ScoreboardElement, welche man nachfolgend befüllen kann |
|
||||
| Name | Signature | Beschreibung |
|
||||
|-----------|----------------------------------------------------|-------------------------------------------------------------------------------------------|
|
||||
| `group` | | Siehe: [Scoreboardgroups](#scoreboardgroups) |
|
||||
| `element` | element(String, Group): ScoreboardElement | Erstellt ein ScoreboardElement, welche man nachfolgend befüllen kann |
|
||||
| `element` | element(String, Group, Integer): ScoreboardElement | Erstellt ein ScoreboardElement, welche man nachfolgend befüllen kann mit einer Sortierung |
|
||||
|
||||
Ein ScoreboardElement ist ein Objekt, womit du direkt auf einen Wert zugreifen kannst und es ändern kannst.
|
||||
Es geht wie folgt:
|
||||
|
@ -28,6 +28,12 @@ scoreboard = {}
|
||||
---@return ScoreboardElement
|
||||
function scoreboard.element(key, group) return nil end
|
||||
|
||||
---@param key string
|
||||
---@param group ScoreboardGroup
|
||||
---@param order number
|
||||
---@return ScoreboardElement
|
||||
function scoreboard.element(key, group, order) return nil end
|
||||
|
||||
---@class ScoreboardElement
|
||||
---@overload fun(): void
|
||||
---@overload fun(value: string): void
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren