Update pos definition and some other stuff
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Dieser Commit ist enthalten in:
Ursprung
f7481bfa0f
Commit
a91c352b15
@ -43,6 +43,8 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class LoaderRecorder implements Listener {
|
||||
|
||||
@ -124,53 +126,10 @@ public class LoaderRecorder implements Listener {
|
||||
|
||||
addWaitTime(false);
|
||||
Block block = event.getClickedBlock();
|
||||
Material type = block.getType();
|
||||
switch (type) {
|
||||
case COMPARATOR:
|
||||
loaderElementList.add(new LoaderComparator(block.getLocation()));
|
||||
message("LOADER_BUTTON_COMPARATOR");
|
||||
break;
|
||||
case REPEATER:
|
||||
loaderElementList.add(new LoaderRepeater(block.getLocation()));
|
||||
message("LOADER_BUTTON_REPEATER");
|
||||
break;
|
||||
case NOTE_BLOCK:
|
||||
loaderElementList.add(new LoaderNoteBlock(block.getLocation()));
|
||||
message("LOADER_BUTTON_NOTEBLOCK");
|
||||
break;
|
||||
case LEVER:
|
||||
loaderElementList.add(new LoaderLever(block.getLocation()));
|
||||
message("LOADER_BUTTON_SWITCH");
|
||||
break;
|
||||
case DAYLIGHT_DETECTOR:
|
||||
loaderElementList.add(new LoaderDaylightDetector(block.getLocation()));
|
||||
message("LOADER_BUTTON_DAYLIGHT_DETECTOR");
|
||||
break;
|
||||
case LECTERN:
|
||||
loaderElementList.add(new LoaderLectern(block.getLocation()));
|
||||
message("LOADER_BUTTON_LECTERN");
|
||||
break;
|
||||
case IRON_TRAPDOOR:
|
||||
break;
|
||||
default:
|
||||
if (type.name().endsWith("_TRAPDOOR")) {
|
||||
loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_TRAPDOOR", type));
|
||||
message("LOADER_BUTTON_TRAPDOOR");
|
||||
} else if (type.name().endsWith("_DOOR")) {
|
||||
loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_DOOR", type));
|
||||
message("LOADER_BUTTON_DOOR");
|
||||
} else if (type.name().endsWith("FENCE_GATE")) {
|
||||
loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_FENCEGATE", type));
|
||||
message("LOADER_BUTTON_FENCEGATE");
|
||||
} else if (type.name().endsWith("STONE_BUTTON")) {
|
||||
loaderElementList.add(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_STONE_BUTTON", type, 20));
|
||||
message("LOADER_BUTTON_STONE_BUTTON");
|
||||
} else if (type.name().endsWith("BUTTON")) {
|
||||
loaderElementList.add(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_WOOD_BUTTON", type, 30));
|
||||
message("LOADER_BUTTON_WOOD_BUTTON");
|
||||
}
|
||||
break;
|
||||
}
|
||||
getLoaderInteractionElement(block, (loaderInteractionElement, s) -> {
|
||||
loaderElementList.add(loaderInteractionElement);
|
||||
message(s);
|
||||
});
|
||||
}
|
||||
|
||||
private Map<Location, Long> blockSet = new HashMap<>();
|
||||
@ -226,6 +185,46 @@ public class LoaderRecorder implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public static void getLoaderInteractionElement(Block block, BiConsumer<LoaderInteractionElement<?>, String> consumer) {
|
||||
Material type = block.getType();
|
||||
switch (type) {
|
||||
case COMPARATOR:
|
||||
consumer.accept(new LoaderComparator(block.getLocation()), "LOADER_BUTTON_COMPARATOR");
|
||||
break;
|
||||
case REPEATER:
|
||||
consumer.accept(new LoaderRepeater(block.getLocation()), "LOADER_BUTTON_REPEATER");
|
||||
break;
|
||||
case NOTE_BLOCK:
|
||||
consumer.accept(new LoaderNoteBlock(block.getLocation()), "LOADER_BUTTON_NOTEBLOCK");
|
||||
break;
|
||||
case LEVER:
|
||||
consumer.accept(new LoaderLever(block.getLocation()), "LOADER_BUTTON_SWITCH");
|
||||
break;
|
||||
case DAYLIGHT_DETECTOR:
|
||||
consumer.accept(new LoaderDaylightDetector(block.getLocation()), "LOADER_BUTTON_DAYLIGHT_DETECTOR");
|
||||
break;
|
||||
case LECTERN:
|
||||
consumer.accept(new LoaderLectern(block.getLocation()), "LOADER_BUTTON_LECTERN");
|
||||
break;
|
||||
case IRON_TRAPDOOR:
|
||||
case IRON_DOOR:
|
||||
break;
|
||||
default:
|
||||
if (type.name().endsWith("_TRAPDOOR")) {
|
||||
consumer.accept(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_TRAPDOOR", type), "LOADER_BUTTON_TRAPDOOR");
|
||||
} else if (type.name().endsWith("_DOOR")) {
|
||||
consumer.accept(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_DOOR", type), "LOADER_BUTTON_DOOR");
|
||||
} else if (type.name().endsWith("FENCE_GATE")) {
|
||||
consumer.accept(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_FENCEGATE", type), "LOADER_BUTTON_FENCEGATE");
|
||||
} else if (type.name().endsWith("STONE_BUTTON")) {
|
||||
consumer.accept(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_STONE_BUTTON", type, 20), "LOADER_BUTTON_STONE_BUTTON");
|
||||
} else if (type.name().endsWith("BUTTON")) {
|
||||
consumer.accept(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_WOOD_BUTTON", type, 30), "LOADER_BUTTON_WOOD_BUTTON");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void message(String type) {
|
||||
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("LOADER_MESSAGE_INTERACT", player, BauSystem.MESSAGE.parse(type, player), loaderElementList.size()));
|
||||
}
|
||||
|
@ -22,15 +22,19 @@ package de.steamwar.bausystem.features.script.lua;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.event.platform.CommandEvent;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
import de.steamwar.bausystem.features.script.ScriptRunner;
|
||||
import de.steamwar.bausystem.features.script.lua.libs.LuaLib;
|
||||
import de.steamwar.bausystem.features.world.WorldEditListener;
|
||||
import de.steamwar.bausystem.utils.WorldEditUtils;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -41,11 +45,10 @@ import org.luaj.vm2.LuaFunction;
|
||||
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.ThreeArgFunction;
|
||||
import org.luaj.vm2.lib.TwoArgFunction;
|
||||
import org.luaj.vm2.lib.VarArgFunction;
|
||||
import org.luaj.vm2.lib.*;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -104,14 +107,7 @@ public class SteamWarLuaPlugin extends TwoArgFunction {
|
||||
double x = arg1.checkdouble();
|
||||
double y = arg2.checkdouble();
|
||||
double z = arg3.checkdouble();
|
||||
|
||||
Location loc = new Location(player.getWorld(), x, y, z);
|
||||
|
||||
return tableOf(new LuaValue[] {
|
||||
valueOf("x"), valueOf(loc.getBlockX()),
|
||||
valueOf("y"), valueOf(loc.getBlockY()),
|
||||
valueOf("z"), valueOf(loc.getBlockZ())
|
||||
});
|
||||
return pos(x, y, z);
|
||||
}
|
||||
});
|
||||
env.set("exec", new VarArgFunction() {
|
||||
@ -169,11 +165,86 @@ public class SteamWarLuaPlugin extends TwoArgFunction {
|
||||
env.set("rawget", NIL);
|
||||
env.set("rawlen", NIL);
|
||||
env.set("rawset", NIL);
|
||||
env.set("setmetatable", NIL);
|
||||
env.set("xpcall", NIL);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static LuaTable pos(double x, double y, double z) {
|
||||
LuaTable position = new LuaTable();
|
||||
position.set("x", x);
|
||||
position.set("y", y);
|
||||
position.set("z", z);
|
||||
|
||||
position.set("add", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
LuaTable table = luaValue.checktable();
|
||||
double dx = table.get("x").checkdouble();
|
||||
double dy = table.get("y").checkdouble();
|
||||
double dz = table.get("z").checkdouble();
|
||||
return pos(x + dx, y + dy, z + dz);
|
||||
}
|
||||
});
|
||||
|
||||
position.set("subtract", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
LuaTable table = luaValue.checktable();
|
||||
double dx = table.get("x").checkdouble();
|
||||
double dy = table.get("y").checkdouble();
|
||||
double dz = table.get("z").checkdouble();
|
||||
return pos(x - dx, y - dy, z - dz);
|
||||
}
|
||||
});
|
||||
|
||||
position.set("addX", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
return pos(x + luaValue.checkdouble(), y, z);
|
||||
}
|
||||
});
|
||||
position.set("subtractX", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
return pos(x - luaValue.checkdouble(), y, z);
|
||||
}
|
||||
});
|
||||
position.set("addY", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
return pos(x, y + luaValue.checkdouble(), z);
|
||||
}
|
||||
});
|
||||
position.set("subtractY", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
return pos(x, y - luaValue.checkdouble(), z);
|
||||
}
|
||||
});
|
||||
position.set("addZ", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
return pos(x, y, z + luaValue.checkdouble());
|
||||
}
|
||||
});
|
||||
position.set("subtractZ", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
return pos(x, y, z - luaValue.checkdouble());
|
||||
}
|
||||
});
|
||||
|
||||
position.set("blockPos", new ZeroArgFunction() {
|
||||
@Override
|
||||
public LuaValue call() {
|
||||
Location location = new Location(Bukkit.getWorlds().get(0), x, y, z);
|
||||
return pos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
});
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
public static String varArgsToString(Varargs args) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 1; i <= args.narg(); i++) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.features.script.lua.libs;
|
||||
|
||||
import de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
@ -44,6 +45,12 @@ public class PlayerLib implements LuaLib {
|
||||
table.set("chat", new Print(player));
|
||||
table.set("actionbar", new SendActionbar(player));
|
||||
|
||||
table.set("pos", getter(() -> {
|
||||
return SteamWarLuaPlugin.pos(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ());
|
||||
}));
|
||||
table.set("blockPos", getter(() -> {
|
||||
return SteamWarLuaPlugin.pos(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
|
||||
}));
|
||||
table.set("x", getterAndSetter("x", () -> player.getLocation().getX(), x -> {
|
||||
Location location = player.getLocation();
|
||||
location.setX(x);
|
||||
|
@ -21,11 +21,14 @@ package de.steamwar.bausystem.features.script.lua.libs;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.features.loader.Loader;
|
||||
import de.steamwar.bausystem.features.loader.LoaderRecorder;
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.luaj.vm2.LuaString;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
@ -75,6 +78,19 @@ public class ServerLib implements LuaLib {
|
||||
return NIL;
|
||||
}
|
||||
});
|
||||
serverLib.set("interactAt", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue arg1) {
|
||||
LuaTable pos = arg1.checktable();
|
||||
Block block = player.getWorld().getBlockAt(pos.get("x").checkint(), pos.get("y").checkint(), pos.get("z").checkint());
|
||||
LoaderRecorder.getLoaderInteractionElement(block, (loaderInteractionElement, s) -> {
|
||||
loaderInteractionElement.execute(aLong -> {
|
||||
// Ignore
|
||||
});
|
||||
});
|
||||
return NIL;
|
||||
}
|
||||
});
|
||||
return serverLib;
|
||||
}
|
||||
}
|
||||
|
20
SCRIPT.md
20
SCRIPT.md
@ -75,15 +75,29 @@ In den Scripten gibt es dazu noch folgende globale Variablen:
|
||||
Ohne eine Kategorie sind folgende Funktionen verfügbar, die nicht allgemein sind:
|
||||
|
||||
| Name | Signature | Beschreibung |
|
||||
|-----------|-----------------------------------|-------------------------------------------------------------------------------------------------------------------|
|
||||
|-----------|---------------------------------------|-------------------------------------------------------------------------------------------------------------------|
|
||||
| `print` | print(String...) | @see chat(String...) |
|
||||
| `input` | input(String, Function\<String>) | Fragt den User nach einer Eingabe mit der Nachricht und called die zugehörige Funktion nach dieser |
|
||||
| `delayed` | delayed(Number, Function\<Void>) | Wartet die angegebene Anzahl an Ticks und führt danach die zugehörige Funktion aus |
|
||||
| `pos` | pos(Number, Number, Number) | Erstellt aus drei Zahlen eine Position-Table. Die Koordinaten sind unter den Namen `x`, `y` und `z` abgespeichert |
|
||||
| `pos` | pos(Number, Number, Number): Position | Erstellt aus drei Zahlen eine Position-Table. Die Koordinaten sind unter den Namen `x`, `y` und `z` abgespeichert |
|
||||
| `exec` | exec(String...) | Führt den angegebenen Befehl als Spieler aus |
|
||||
| `length` | length(Any): Int | Gibt die Länge des Objekts zurück |
|
||||
| `join` | length(String, String...): String | Füge die Texte mit den ersten Parameter zusammen |
|
||||
|
||||
Position besteht aus einer x, y und z Koordinate als auch aus folgenden Methoden:
|
||||
|
||||
| Name | Signature | Beschreibung |
|
||||
|-----------|------------------------------|--------------------------------------------------------------|
|
||||
| add | add(Position): Position | Erstellt eine neue Position mit neuen X, Y und Z Koordinaten |
|
||||
| addX | addX(Number): Position | Erstellt eine neue Position mit neuer X Koordinate |
|
||||
| addY | addY(Number): Position | Erstellt eine neue Position mit neuer Y Koordinate |
|
||||
| addZ | addZ(Number): Position | Erstellt eine neue Position mit neuer Z Koordinate |
|
||||
| subtract | subtract(Position): Position | Erstellt eine neue Position mit neuen X, Y und Z Koordinaten |
|
||||
| subtractX | subtractX(Number): Position | Erstellt eine neue Position mit neuer X Koordinate |
|
||||
| subtractY | subtractY(Number): Position | Erstellt eine neue Position mit neuer Y Koordinate |
|
||||
| subtractZ | subtractZ(Number): Position | Erstellt eine neue Position mit neuer Z Koordinate |
|
||||
| blockPos | blockPos(): Position | Erstellt eine neue Position mit Block-Koordinaten |
|
||||
|
||||
### player
|
||||
Das `player`-Modul stellt Funktionen zur Verfügung, die den Spieler betreffen.
|
||||
Es gibt folgende Funktionen:
|
||||
@ -93,6 +107,8 @@ Es gibt folgende Funktionen:
|
||||
| `name` | name(): String | Gibt den `displayName` des Spielers zurück |
|
||||
| `chat` | chat(String...) | Sendet den Text in den Chat des Spielers |
|
||||
| `actionbar` | actionbar(String...) | Sendet den Text in die ActionBar des Spielers |
|
||||
| `pos` | pos() | Position of Player |
|
||||
| `blockPos` | blockPos() | Block Position of Player |
|
||||
| `x` | x(Number), x(): Number | Setzt oder gibt die X-Koordinate des Spielers |
|
||||
| `y` | y(Number), y(): Number | Setzt oder gibt die Y-Koordinate des Spielers |
|
||||
| `z` | z(Number), z(): Number | Setzt oder gibt die Z-Koordinate des Spielers |
|
||||
|
52
sw.def.lua
52
sw.def.lua
@ -92,6 +92,12 @@ function player.chat(...) end
|
||||
---Send a message to the actionbar of the player.
|
||||
function player.actionbar(...) end
|
||||
|
||||
---@return Position
|
||||
function player.pos() end
|
||||
|
||||
---@return Position
|
||||
function player.blockPos() end
|
||||
|
||||
---@overload fun(): number
|
||||
---@param newX number
|
||||
function player.x(newX) end
|
||||
@ -248,11 +254,6 @@ function region.get(name) return nil end
|
||||
---@return iregion[]
|
||||
function region.list() return nil end
|
||||
|
||||
---@class Position
|
||||
---@field x number
|
||||
---@field y number
|
||||
---@field z number
|
||||
|
||||
---@class server
|
||||
---@field tps tps
|
||||
server = {}
|
||||
@ -361,6 +362,47 @@ function delayed(ticks, callback) end
|
||||
---@return Position
|
||||
function pos(x, y, z) return nil end
|
||||
|
||||
---@class Position
|
||||
---@field x number
|
||||
---@field y number
|
||||
---@field z number
|
||||
local position = {}
|
||||
|
||||
---@param pos Position
|
||||
---@return Position
|
||||
function position.add(pos) return nil end
|
||||
|
||||
---@param pos Position
|
||||
---@return Position
|
||||
function position.subtract(pos) return nil end
|
||||
|
||||
---@param x number
|
||||
---@return Position
|
||||
function position.addX(x) return nil end
|
||||
|
||||
---@param y number
|
||||
---@return Position
|
||||
function position.addY(y) return nil end
|
||||
|
||||
---@param z number
|
||||
---@return Position
|
||||
function position.addZ(z) return nil end
|
||||
|
||||
---@param x number
|
||||
---@return Position
|
||||
function position.subtractX(x) return nil end
|
||||
|
||||
---@param y number
|
||||
---@return Position
|
||||
function position.subtractY(y) return nil end
|
||||
|
||||
---@param z number
|
||||
---@return Position
|
||||
function position.subtractZ(z) return nil end
|
||||
|
||||
---@return Position
|
||||
function position.blockPos() return nil end
|
||||
|
||||
---@return void
|
||||
function exec(...) end
|
||||
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren