From bae39e292199e7c1d4e8e095cadd53da2a187c8c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 30 Jul 2023 11:55:51 +0200 Subject: [PATCH 1/6] Hotfix punishments for ResetCommand and TestblockCommand Signed-off-by: yoyosource --- .../steamwar/bausystem/features/region/ResetCommand.java | 9 +++++---- .../bausystem/features/region/TestblockCommand.java | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java index d057d59f..38e6a3e2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java @@ -67,12 +67,13 @@ public class ResetCommand extends SWCommand { Region region = regionCheck(p); if (region == null) return; - if (bauServer.getOwner() != p.getUniqueId()) { - if (Punishment.isPunished(SteamwarUser.get(p.getUniqueId()), Punishment.PunishmentType.NoSchemSharing, punishment -> BauSystem.MESSAGE.parse("REGION_TB_NO_SCHEMSHARING", p, punishment.getEndTime()))) { + if (!p.getUniqueId().equals(bauServer.getOwner())) { + if (Punishment.isPunished(SteamwarUser.get(bauServer.getOwner()), Punishment.PunishmentType.NoSchemReceiving, punishment -> BauSystem.MESSAGE.send("REGION_TB_NO_SCHEMRECEIVING", p, punishment.getEndTime()))) { + return; + } + if (Punishment.isPunished(SteamwarUser.get(p.getUniqueId()), Punishment.PunishmentType.NoSchemSharing, punishment -> BauSystem.MESSAGE.send("REGION_TB_NO_SCHEMSHARING", p, punishment.getEndTime()))) { return; } - } else if (Punishment.isPunished(SteamwarUser.get(bauServer.getOwner()), Punishment.PunishmentType.NoSchemReceiving, punishment -> BauSystem.MESSAGE.parse("REGION_TB_NO_SCHEMRECEIVING", p, punishment.getEndTime()))) { - return; } if (node.isDir()) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index f4d45fb4..46bfe951 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -92,12 +92,13 @@ public class TestblockCommand extends SWCommand { return; } - if (bauServer.getOwner() != p.getUniqueId()) { - if (Punishment.isPunished(SteamwarUser.get(p.getUniqueId()), Punishment.PunishmentType.NoSchemSharing, punishment -> BauSystem.MESSAGE.parse("REGION_TB_NO_SCHEMSHARING", p, punishment.getEndTime()))) { + if (!p.getUniqueId().equals(bauServer.getOwner())) { + if (Punishment.isPunished(SteamwarUser.get(bauServer.getOwner()), Punishment.PunishmentType.NoSchemReceiving, punishment -> BauSystem.MESSAGE.send("REGION_TB_NO_SCHEMRECEIVING", p, punishment.getEndTime()))) { + return; + } + if (Punishment.isPunished(SteamwarUser.get(p.getUniqueId()), Punishment.PunishmentType.NoSchemSharing, punishment -> BauSystem.MESSAGE.send("REGION_TB_NO_SCHEMSHARING", p, punishment.getEndTime()))) { return; } - } else if (Punishment.isPunished(SteamwarUser.get(bauServer.getOwner()), Punishment.PunishmentType.NoSchemReceiving, punishment -> BauSystem.MESSAGE.parse("REGION_TB_NO_SCHEMRECEIVING", p, punishment.getEndTime()))) { - return; } try { From 13ec64a4fa61187823e70224dd4119e06ac113d4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 30 Jul 2023 12:08:47 +0200 Subject: [PATCH 2/6] Hotfix NPE in StorageLib Signed-off-by: yoyosource --- .../bausystem/features/script/lua/libs/StorageLib.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java index 5388a696..3554ac05 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java @@ -49,7 +49,7 @@ public class StorageLib implements LuaLib { global.set("get", new OneArgFunction() { @Override public LuaValue call(LuaValue arg) { - return GLOBAL_STORAGE.get(arg.checkjstring()); + return GLOBAL_STORAGE.getOrDefault(arg.checkjstring(), NIL); } }); global.set("set", new TwoArgFunction() { @@ -58,7 +58,6 @@ public class StorageLib implements LuaLib { return GLOBAL_STORAGE.put(arg1.checkjstring(), arg2); } }); - storageLib.set("global", global); LuaTable playerStorage = new LuaTable(); @@ -66,7 +65,7 @@ public class StorageLib implements LuaLib { playerStorage.set("get", new OneArgFunction() { @Override public LuaValue call(LuaValue arg) { - return playerStorageMap.get(arg.checkjstring()); + return playerStorageMap.getOrDefault(arg.checkjstring(), NIL); } }); playerStorage.set("set", new TwoArgFunction() { @@ -82,7 +81,7 @@ public class StorageLib implements LuaLib { regionStorage.set("get", new OneArgFunction() { @Override public LuaValue call(LuaValue arg) { - return regionStorageMap.get(arg.checkjstring()); + return regionStorageMap.getOrDefault(arg.checkjstring(), NIL); } }); regionStorage.set("set", new TwoArgFunction() { From 9ca83f02d902afdd0b5faa46b2da41a2223cd3a1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 30 Jul 2023 14:02:36 +0200 Subject: [PATCH 3/6] Update StorageLib and add some utility functions Signed-off-by: yoyosource --- .../features/script/lua/libs/StorageLib.java | 86 +++++++++++++++++++ SCRIPT.md | 20 ++++- sw.def.lua | 16 ++++ 3 files changed, 118 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java index 3554ac05..e1953c6f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java @@ -24,8 +24,10 @@ 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.OneArgFunction; import org.luaj.vm2.lib.TwoArgFunction; +import org.luaj.vm2.lib.VarArgFunction; import java.util.HashMap; @@ -58,6 +60,34 @@ public class StorageLib implements LuaLib { return GLOBAL_STORAGE.put(arg1.checkjstring(), arg2); } }); + global.set("has", new OneArgFunction() { + @Override + public LuaValue call(LuaValue arg) { + return valueOf(GLOBAL_STORAGE.containsKey(arg.checkjstring())); + } + }); + global.set("remove", new OneArgFunction() { + @Override + public LuaValue call(LuaValue arg) { + return GLOBAL_STORAGE.remove(arg.checkjstring()); + } + }); + global.set("accessor", new OneArgFunction() { + @Override + public LuaValue call(LuaValue arg) { + String key = arg.checkjstring(); + return new VarArgFunction() { + @Override + public Varargs invoke(Varargs args) { + if (args.narg() == 0) { + return GLOBAL_STORAGE.getOrDefault(key, NIL); + } else { + return GLOBAL_STORAGE.put(key, args.arg(1)); + } + } + }; + }; + }); storageLib.set("global", global); LuaTable playerStorage = new LuaTable(); @@ -74,6 +104,34 @@ public class StorageLib implements LuaLib { return playerStorageMap.put(arg1.checkjstring(), arg2); } }); + playerStorage.set("has", new OneArgFunction() { + @Override + public LuaValue call(LuaValue arg) { + return valueOf(playerStorageMap.containsKey(arg.checkjstring())); + } + }); + playerStorage.set("remove", new OneArgFunction() { + @Override + public LuaValue call(LuaValue arg) { + return playerStorageMap.remove(arg.checkjstring()); + } + }); + playerStorage.set("accessor", new OneArgFunction() { + @Override + public LuaValue call(LuaValue arg) { + String key = arg.checkjstring(); + return new VarArgFunction() { + @Override + public Varargs invoke(Varargs args) { + if (args.narg() == 0) { + return playerStorageMap.getOrDefault(key, NIL); + } else { + return playerStorageMap.put(key, args.arg(1)); + } + } + }; + }; + }); storageLib.set("player", playerStorage); LuaTable regionStorage = new LuaTable(); @@ -90,6 +148,34 @@ public class StorageLib implements LuaLib { return regionStorageMap.put(arg1.checkjstring(), arg2); } }); + regionStorage.set("has", new OneArgFunction() { + @Override + public LuaValue call(LuaValue arg) { + return valueOf(regionStorageMap.containsKey(arg.checkjstring())); + } + }); + regionStorage.set("remove", new OneArgFunction() { + @Override + public LuaValue call(LuaValue arg) { + return regionStorageMap.remove(arg.checkjstring()); + } + }); + regionStorage.set("accessor", new OneArgFunction() { + @Override + public LuaValue call(LuaValue arg) { + String key = arg.checkjstring(); + return new VarArgFunction() { + @Override + public Varargs invoke(Varargs args) { + if (args.narg() == 0) { + return regionStorageMap.getOrDefault(key, NIL); + } else { + return regionStorageMap.put(key, args.arg(1)); + } + } + }; + }; + }); storageLib.set("region", regionStorage); return storageLib; diff --git a/SCRIPT.md b/SCRIPT.md index c6d05155..2931b995 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -206,10 +206,22 @@ Es gibt folgende Module: 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 | +| 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 | +| `has` | set(String): Boolean | Prüft ob ein Wert vorhanden ist | +| `remove` | remove(String) | Löscht den Schlüssel | +| `accessor` | accessor(String): Accessor | Gibt einen Accessor zurück | + +Ein Accessor ist ein Objekt, womit du direkt auf einen Wert zugreifen kannst und es ändern kannst. +Es geht wie folgt: +```lua +keyAccessor = storage.player.accessor("key") + +keyAccessor("Hello World") -- Setzt den Wert auf "Hello World" +print(keyAccessor()) -- Gibt den Wert zurück +``` ## inventory Das `inventory`-Modul stellt Funktionen zur Verfügung, um ein Inventar zu öffnen. diff --git a/sw.def.lua b/sw.def.lua index abf96dc7..d1570fd8 100644 --- a/sw.def.lua +++ b/sw.def.lua @@ -255,6 +255,22 @@ function storageLib.get(key) return nil end ---@return void function storageLib.set(key, value) end +---@param key string +---@return boolean +function storageLib.has(key) return nil end + +---@param key string +---@return void +function storageLib.remove(key) end + +---@param key string +---@return Accessor +function storageLib.accessor(key) return nil end + +---@class Accessor +---@overload fun(): any +---@overload fun(value: any) + ---@class Selection ---@field max Position ---@field min Position From b5e67bc576a030c84408f3b8fabebc71814a14b7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 30 Jul 2023 14:04:33 +0200 Subject: [PATCH 4/6] Hotfix SCRIPT.md Signed-off-by: yoyosource --- SCRIPT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SCRIPT.md b/SCRIPT.md index 2931b995..bd4edd7c 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -210,7 +210,7 @@ Alle Module haben folgende Funktionen: |------------|----------------------------|--------------------------------------------------------| | `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 | -| `has` | set(String): Boolean | Prüft ob ein Wert vorhanden ist | +| `has` | has(String): Boolean | Prüft ob ein Wert vorhanden ist | | `remove` | remove(String) | Löscht den Schlüssel | | `accessor` | accessor(String): Accessor | Gibt einen Accessor zurück | From a1c45b86af19d2c753cf7ff36f1695b09ce4daf3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 30 Jul 2023 14:10:28 +0200 Subject: [PATCH 5/6] Update StorageLib Signed-off-by: yoyosource --- .../bausystem/features/script/lua/libs/StorageLib.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java index e1953c6f..033c5f98 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java @@ -82,7 +82,8 @@ public class StorageLib implements LuaLib { if (args.narg() == 0) { return GLOBAL_STORAGE.getOrDefault(key, NIL); } else { - return GLOBAL_STORAGE.put(key, args.arg(1)); + GLOBAL_STORAGE.put(key, args.arg(1)); + return NIL; } } }; @@ -126,7 +127,8 @@ public class StorageLib implements LuaLib { if (args.narg() == 0) { return playerStorageMap.getOrDefault(key, NIL); } else { - return playerStorageMap.put(key, args.arg(1)); + playerStorageMap.put(key, args.arg(1)); + return NIL; } } }; @@ -170,7 +172,8 @@ public class StorageLib implements LuaLib { if (args.narg() == 0) { return regionStorageMap.getOrDefault(key, NIL); } else { - return regionStorageMap.put(key, args.arg(1)); + regionStorageMap.put(key, args.arg(1)); + return NIL; } } }; From 82b385e5fff2da5c3b10e93cae5f217db1e43e7d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 30 Jul 2023 14:22:36 +0200 Subject: [PATCH 6/6] Hotfix ScriptGUI removing script on pressing escape when naming Signed-off-by: yoyosource --- .../bausystem/features/script/ScriptGUI.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java index c8098fed..add7ad81 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java @@ -20,13 +20,16 @@ package de.steamwar.bausystem.features.script; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.script.lua.SteamWarPlatform; +import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import de.steamwar.linkage.Linked; import de.steamwar.sql.Script; import de.steamwar.sql.SteamwarUser; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -39,6 +42,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; @Linked public class ScriptGUI implements Listener { @@ -119,7 +123,18 @@ public class ScriptGUI implements Listener { open(player); } else { SWAnvilInv inv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ENTER_NAME", player), name == null ? "" : name); - inv.setCallback(s -> saveWithName(player, meta, s)); + AtomicBoolean saved = new AtomicBoolean(false); + ItemStack itemStack = player.getOpenInventory().getCursor(); + inv.setCallback(s -> { + saveWithName(player, meta, s); + saved.set(true); + }); + inv.addCloseCallback(() -> { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + if (saved.get()) return; + SWUtils.giveItemToPlayer(player, itemStack); + }, 1); + }); inv.open(); } }