SteamWar/BauSystem2.0
Archiviert
12
0

Add ScoreboardLib and TpsLib
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2024-03-05 11:06:31 +01:00
Ursprung b47d85ebe9
Commit 1da5b65460
9 geänderte Dateien mit 210 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -35,6 +35,6 @@ public class ScoreboardElement_GENERIC implements LinkageType {
@Override
public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) {
buildPlan.addImport("de.steamwar.bausystem.features.world.BauScoreboard");
methodBuilder.addLine("BauScoreboard.ELEMENTS.add(" + s + ");");
methodBuilder.addLine("BauScoreboard.addElement(" + s + ");");
}
}

Datei anzeigen

@ -566,7 +566,6 @@ LOADER_PAUSED=§7The Loader is now paused.
LOADER_SMALL_TIME=§cThe wait time is too small
LOADER_NEW_TIME=§7The wait time is now: {0}
LOADER_NEW_LOAD_TIME=§7The action wait time is now: {0}
LOADER_PERMS=§cYou are not allowed to use the Loader here
LOADER_NOTHING_RECORDED=§cYou have not recorded anything yet!
LOADER_GUI_TITLE=Loader GUI

Datei anzeigen

@ -534,7 +534,6 @@ LOADER_PAUSED=§7Der Loader ist nun pausiert.
LOADER_SMALL_TIME=§cDie Wartezeit ist zu klein
LOADER_NEW_TIME=§7Die Schusswartezeit ist nun: {0}
LOADER_NEW_LOAD_TIME=§7Die Setzwartezeit ist nun: {0}
LOADER_PERMS=§cDu darfst hier nicht den Detonator nutzen
LOADER_NOTHING_RECORDED=§cEs wurden keine Elemente aufgenommen!
LOADER_GUI_TITLE=Loader Einstellungen

Datei anzeigen

@ -0,0 +1,71 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.lua.libs;
import de.steamwar.bausystem.features.world.BauScoreboard;
import de.steamwar.bausystem.utils.ScoreboardElement;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
import org.luaj.vm2.lib.TwoArgFunction;
import org.luaj.vm2.lib.VarArgFunction;
@Linked
public class ScoreboardLib implements LuaLib {
@Override
public String name() {
return "scoreboard";
}
@Override
public LuaTable get(Player player) {
LuaTable luaTable = new LuaTable();
LuaTable groups = new LuaTable();
for (ScoreboardElement.ScoreboardGroup group : ScoreboardElement.ScoreboardGroup.values()) {
groups.set(group.name(), group.ordinal());
}
luaTable.set("group", groups);
luaTable.set("element", new TwoArgFunction() {
@Override
public LuaValue call(LuaValue key, LuaValue group) {
String elementKey = key.checkjstring();
ScoreboardElement.ScoreboardGroup elementGroup = ScoreboardElement.ScoreboardGroup.values()[group.checkint()];
return new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
if (args.narg() == 0) {
BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, null);
} else {
BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, args.arg1().checkjstring());
}
return NIL;
}
};
}
});
return luaTable;
}
}

Datei anzeigen

@ -21,9 +21,7 @@ package de.steamwar.bausystem.features.script.lua.libs;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.features.tpslimit.TPSSystem;
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.core.TPSWatcher;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@ -75,17 +73,6 @@ public class ServerLib implements LuaLib {
return NIL;
}
});
LuaValue tpsLib = LuaValue.tableOf();
tpsLib.set("oneSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND)));
tpsLib.set("tenSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS)));
tpsLib.set("oneMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE)));
tpsLib.set("fiveMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES)));
tpsLib.set("tenMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)));
tpsLib.set("current", getter(TPSWatcher::getTPS));
tpsLib.set("limit", getter(TPSSystem.getInstance()::getCurrentTPSLimit));
serverLib.set("tps", tpsLib);
return serverLib;
}
}

Datei anzeigen

@ -0,0 +1,53 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.lua.libs;
import de.steamwar.bausystem.features.tpslimit.TPSSystem;
import de.steamwar.core.TPSWatcher;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
import org.luaj.vm2.LuaTable;
@Linked
public class TpsLib implements LuaLib {
@Override
public Class<? extends LuaLib> parent() {
return ServerLib.class;
}
@Override
public String name() {
return "tps";
}
@Override
public LuaTable get(Player player) {
LuaTable tpsLib = new LuaTable();
tpsLib.set("oneSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND)));
tpsLib.set("tenSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS)));
tpsLib.set("oneMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE)));
tpsLib.set("fiveMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES)));
tpsLib.set("tenMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)));
tpsLib.set("current", getter(TPSWatcher::getTPS));
tpsLib.set("limit", getter(TPSSystem.getInstance()::getCurrentTPSLimit));
return tpsLib;
}
}

Datei anzeigen

@ -4,6 +4,7 @@ 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;
@ -12,26 +13,37 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.*;
@Linked
public class BauScoreboard implements Listener {
public static final List<ScoreboardElement> ELEMENTS = new ArrayList<>();
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<>();
public static void addElement(ScoreboardElement scoreboardElement) {
List<ScoreboardElement> elements = ELEMENTS.computeIfAbsent(scoreboardElement.getGroup(), scoreboardGroup -> new ArrayList<>());
elements.add(scoreboardElement);
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<>());
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);
}
@EventHandler
public void handlePlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
Map<ScoreboardElement.ScoreboardGroup, List<ScoreboardElement>> map = new HashMap<>();
for (ScoreboardElement element : ELEMENTS) {
map.computeIfAbsent(element.getGroup(), scoreboardGroup -> new ArrayList<>()).add(element);
}
map.forEach((scoreboardGroup, scoreboardElements) -> {
scoreboardElements.sort(Comparator.comparingInt(ScoreboardElement::order));
});
SWScoreboard.createScoreboard(player, new ScoreboardCallback() {
@Override
public HashMap<String, Integer> getData() {
@ -52,9 +64,9 @@ public class BauScoreboard implements Listener {
}
private void calcGroup(List<String> elements, String separator, Region region, ScoreboardElement.ScoreboardGroup group) {
if (map.containsKey(group)) {
if (ELEMENTS.containsKey(group)) {
List<String> groupElements = new ArrayList<>();
for (ScoreboardElement element : map.get(group)) {
for (ScoreboardElement element : ELEMENTS.get(group)) {
groupElements.add(element.get(region, player));
}
groupElements.removeIf(Objects::isNull);
@ -63,6 +75,14 @@ public class BauScoreboard implements Listener {
elements.addAll(groupElements);
}
}
if (ADDITIONAL_SCOREBOARD_LINES.containsKey(player)) {
ADDITIONAL_SCOREBOARD_LINES.get(player).values().forEach(scoreboardGroupStringPair -> {
if (scoreboardGroupStringPair.getKey() != group) {
return;
}
elements.add(scoreboardGroupStringPair.getValue());
});
}
}
@Override
@ -74,4 +94,9 @@ public class BauScoreboard implements Listener {
}
});
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
ADDITIONAL_SCOREBOARD_LINES.remove(event.getPlayer());
}
}

Datei anzeigen

@ -69,6 +69,7 @@ In den Scripten gibt es dazu noch folgende globale Variablen:
- [`server`](#server)
- [`storage`](#storage)
- [`inventory`](#inventory)
- [`scoreboard`](#scoreboard)
- `_worldedit`
Ohne eine Kategorie sind folgende Funktionen verfügbar, die nicht allgemein sind:
@ -255,6 +256,33 @@ Wenn eine Barrier statt des richtigen Items angezeigt wird, dann ist das angegeb
⚠️⚠️⚠️
```
## scoreboard
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 |
Ein ScoreboardElement ist ein Objekt, womit du direkt auf einen Wert zugreifen kannst und es ändern kannst.
Es geht wie folgt:
```lua
key = scoreboard.element("key", scoreboard.group.OTHER)
key("Hello World") -- Setzt im Bereich Other den Text "Hello World" unter allem anderen
key() -- Removed im Bereich Other den vorherigen Text "Hello World"
```
## Scoreboardgroups
| Name |
|----------|
| `Header` |
| `Region` |
| `Other` |
| `Footer` |
# SteamWar.de-Global-Api
Mit `/script` kann man Script-Bücher global abspeichern. Diese haben dann zugrif auf die `global`-Api.
Die `global`-Api stellt Funktionen zur Verfügung um auf Events, Commands und Hotkeys mit einem Script zu reagieren.

Datei anzeigen

@ -18,9 +18,29 @@
---
--- This file contains the definitions for the SteamWar.de script API.
--- It is used by the IDE to provide code completion and type checking.
--- Created by Chaoscaot
--- Created by Chaoscaot and YoyoNow
---
scoreboard = {}
---@param key string
---@param group ScoreboardGroup
---@return ScoreboardElement
function scoreboard.element(key, group) return nil end
---@class ScoreboardElement
---@overload fun(): void
---@overload fun(value: string): void
---@class ScoreboardGroup
---@class group
---@field HEADER ScoreboardGroup
---@field REGION ScoreboardGroup
---@field OTHER ScoreboardGroup
---@field FOOTER ScoreboardGroup
local group = {}
scoreboard.group = group
inventory = {}
---@param title string