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