SteamWar/BauSystem2.0
Archiviert
12
0

TestBlockPaste-Without-Water #146

Zusammengeführt
YoyoNow hat 25 Commits von TestBlockPaste-Without-Water nach master 2023-08-19 23:29:20 +02:00 zusammengeführt
6 geänderte Dateien mit 150 neuen und 17 gelöschten Zeilen
Nur Änderungen aus Commit c398ad239d werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -68,12 +68,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()) {

Datei anzeigen

@ -86,12 +86,13 @@ public class TestblockCommand extends SWCommand {
}
}
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())) {
zOnlyKroks markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

Siehe oben

Siehe oben
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 {

Datei anzeigen

@ -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();
}
}

Datei anzeigen

@ -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;
@ -49,7 +51,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 +60,35 @@ 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 {
GLOBAL_STORAGE.put(key, args.arg(1));
return NIL;
}
}
};
};
});
storageLib.set("global", global);
LuaTable playerStorage = new LuaTable();
@ -66,7 +96,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() {
@ -75,6 +105,35 @@ 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 {
playerStorageMap.put(key, args.arg(1));
return NIL;
}
}
};
};
});
storageLib.set("player", playerStorage);
LuaTable regionStorage = new LuaTable();
@ -82,7 +141,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() {
@ -91,6 +150,35 @@ 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 {
regionStorageMap.put(key, args.arg(1));
return NIL;
}
}
};
};
});
storageLib.set("region", regionStorage);
return storageLib;

Datei anzeigen

@ -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` | 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 |
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.

Datei anzeigen

@ -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