Signed-off-by: Chaoscaot <chaoscaot@zohomail.eu>
Dieser Commit ist enthalten in:
Ursprung
bb133b8d7d
Commit
aa0594fa6c
@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.script.event;
|
|||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.script.ScriptRunner;
|
import de.steamwar.bausystem.features.script.ScriptRunner;
|
||||||
import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin;
|
import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin;
|
||||||
|
import de.steamwar.bausystem.features.script.lua.libs.StorageLib;
|
||||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||||
@ -67,6 +68,7 @@ public class EventListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
StorageLib.removePlayer(event.getPlayer());
|
||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL, event);
|
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 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.region.Region;
|
||||||
|
import de.steamwar.linkage.Linked;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.luaj.vm2.LuaTable;
|
||||||
|
import org.luaj.vm2.LuaValue;
|
||||||
|
import org.luaj.vm2.lib.OneArgFunction;
|
||||||
|
import org.luaj.vm2.lib.TwoArgFunction;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@Linked
|
||||||
|
public class StorageLib implements LuaLib {
|
||||||
|
|
||||||
|
private static final HashMap<String, LuaValue> GLOBAL_STORAGE = new HashMap<>();
|
||||||
|
private static final HashMap<Player, HashMap<String, LuaValue>> PLAYER_STORAGE = new HashMap<>();
|
||||||
|
private static final HashMap<Region, HashMap<String, LuaValue>> REGION_STORAGE = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "storage";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LuaTable get(Player player) {
|
||||||
|
LuaTable storageLib = new LuaTable();
|
||||||
|
|
||||||
|
LuaTable global = new LuaTable();
|
||||||
|
global.set("get", new OneArgFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call(LuaValue arg) {
|
||||||
|
return GLOBAL_STORAGE.get(arg.checkjstring());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
global.set("set", new TwoArgFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call(LuaValue arg1, LuaValue arg2) {
|
||||||
|
return GLOBAL_STORAGE.put(arg1.checkjstring(), arg2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
storageLib.set("global", global);
|
||||||
|
|
||||||
|
LuaTable playerStorage = new LuaTable();
|
||||||
|
HashMap<String, LuaValue> playerStorageMap = PLAYER_STORAGE.computeIfAbsent(player, k -> new HashMap<>());
|
||||||
|
playerStorage.set("get", new OneArgFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call(LuaValue arg) {
|
||||||
|
return playerStorageMap.get(arg.checkjstring());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
playerStorage.set("set", new TwoArgFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call(LuaValue arg1, LuaValue arg2) {
|
||||||
|
return playerStorageMap.put(arg1.checkjstring(), arg2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
storageLib.set("player", playerStorage);
|
||||||
|
|
||||||
|
LuaTable regionStorage = new LuaTable();
|
||||||
|
HashMap<String, LuaValue> regionStorageMap = REGION_STORAGE.computeIfAbsent(Region.getRegion(player.getLocation()), k -> new HashMap<>());
|
||||||
|
regionStorage.set("get", new OneArgFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call(LuaValue arg) {
|
||||||
|
return regionStorageMap.get(arg.checkjstring());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
regionStorage.set("set", new TwoArgFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call(LuaValue arg1, LuaValue arg2) {
|
||||||
|
return regionStorageMap.put(arg1.checkjstring(), arg2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
storageLib.set("region", regionStorage);
|
||||||
|
|
||||||
|
return storageLib;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removePlayer(Player player) {
|
||||||
|
PLAYER_STORAGE.remove(player);
|
||||||
|
}
|
||||||
|
}
|
20
SCRIPT.md
20
SCRIPT.md
@ -12,6 +12,7 @@
|
|||||||
* [trace](#trace)
|
* [trace](#trace)
|
||||||
* [server](#server)
|
* [server](#server)
|
||||||
* [tps](#tps)
|
* [tps](#tps)
|
||||||
|
* [storage](#storage)
|
||||||
* [SteamWar.de-Global-Api](#steamwarde-global-api)
|
* [SteamWar.de-Global-Api](#steamwarde-global-api)
|
||||||
* [Hotkeys](#hotkeys)
|
* [Hotkeys](#hotkeys)
|
||||||
* [Eventtypen](#eventtypen)
|
* [Eventtypen](#eventtypen)
|
||||||
@ -53,6 +54,7 @@ In den Scripten gibt es dazu noch folgende globale Variablen:
|
|||||||
- [`player`](#player)
|
- [`player`](#player)
|
||||||
- [`region`](#region)
|
- [`region`](#region)
|
||||||
- [`server`](#server)
|
- [`server`](#server)
|
||||||
|
- [`storage`](#storage)
|
||||||
- `_worldedit`
|
- `_worldedit`
|
||||||
|
|
||||||
Ohne eine Kategorie sind folgende Funktionen verfügbar, die nicht allgemein sind:
|
Ohne eine Kategorie sind folgende Funktionen verfügbar, die nicht allgemein sind:
|
||||||
@ -160,6 +162,24 @@ Es gibt folgende Funktionen:
|
|||||||
| `tenMinute` | tenMinute(): Number | Gibt die durchschnittliche TPS über die letzte 10 Minuten zurück |
|
| `tenMinute` | tenMinute(): Number | Gibt die durchschnittliche TPS über die letzte 10 Minuten zurück |
|
||||||
| `limit` | limit(): Number | Gibt das TPS-Limit zurück |
|
| `limit` | limit(): Number | Gibt das TPS-Limit zurück |
|
||||||
|
|
||||||
|
## storage
|
||||||
|
Das `storage`-Modul stellt Funktionen zur Verfügung, mit welchen man Werte speichern kann.
|
||||||
|
|
||||||
|
Es gibt folgende Module:
|
||||||
|
|
||||||
|
| Name | Beschreibung |
|
||||||
|
|----------|---------------------|
|
||||||
|
| `player` | Spieler abhängig |
|
||||||
|
| `region` | Region des Spielers |
|
||||||
|
| `global` | Alle Skripte |
|
||||||
|
|
||||||
|
Alle Module haben folgende Funktionen:
|
||||||
|
|
||||||
|
| Name | Signature | Beschreibung |
|
||||||
|
|-----------|--------------------|------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `get` | get(String): Any | Gibt den Wert des Schlüssels zurück |
|
||||||
|
| `set` | set(String, Any) | Setzt den Wert des Schlüssels auf den angegebenen Wert |
|
||||||
|
|
||||||
# SteamWar.de-Global-Api
|
# SteamWar.de-Global-Api
|
||||||
Mit `/script` kann man Script-Bücher global abspeichern. Diese haben dann zugrif auf die `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.
|
Die `global`-Api stellt Funktionen zur Verfügung um auf Events, Commands und Hotkeys mit einem Script zu reagieren.
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren