Script System Lua #178
@ -246,6 +246,7 @@ SCRIPT_COMMAND_ITEM_NAME = §7Command§8: §e/{0}
|
|||||||
SCRIPT_MENU_GUI_ITEM_LORE_1 = §7Click to retrieve
|
SCRIPT_MENU_GUI_ITEM_LORE_1 = §7Click to retrieve
|
||||||
SCRIPT_MENU_GUI_ITEM_LORE_2 = §7Shift-Click to copy
|
SCRIPT_MENU_GUI_ITEM_LORE_2 = §7Shift-Click to copy
|
||||||
SCRIPT_MENU_GUI_ITEM_LORE_3 = §7Right-Click to edit
|
SCRIPT_MENU_GUI_ITEM_LORE_3 = §7Right-Click to edit
|
||||||
|
SCRIPT_MENU_GUI_ITEM_LORE_4 = §7Middle-Click to preview
|
||||||
SCRIPT_MENU_GUI_NAME = §eScript-Menu
|
SCRIPT_MENU_GUI_NAME = §eScript-Menu
|
||||||
SCRIPT_MENU_GUI_ITEM_ADD_NAME = §eInsert
|
SCRIPT_MENU_GUI_ITEM_ADD_NAME = §eInsert
|
||||||
SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Click with a book to insert
|
SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Click with a book to insert
|
||||||
|
@ -238,6 +238,7 @@ SCRIPT_COMMAND_ITEM_NAME = §7Command§8: §e/{0}
|
|||||||
SCRIPT_MENU_GUI_ITEM_LORE_1 = §7Klicke zum rausnehmen
|
SCRIPT_MENU_GUI_ITEM_LORE_1 = §7Klicke zum rausnehmen
|
||||||
SCRIPT_MENU_GUI_ITEM_LORE_2 = §7Shift Klicke zum kopieren
|
SCRIPT_MENU_GUI_ITEM_LORE_2 = §7Shift Klicke zum kopieren
|
||||||
SCRIPT_MENU_GUI_ITEM_LORE_3 = §7Rechts Klicke zum editieren
|
SCRIPT_MENU_GUI_ITEM_LORE_3 = §7Rechts Klicke zum editieren
|
||||||
|
SCRIPT_MENU_GUI_ITEM_LORE_4 = §7Mittel Klicke zum anschauen
|
||||||
SCRIPT_MENU_GUI_NAME = §eScript-Menü
|
SCRIPT_MENU_GUI_NAME = §eScript-Menü
|
||||||
SCRIPT_MENU_GUI_ITEM_ADD_NAME = §eHinzufügen
|
SCRIPT_MENU_GUI_ITEM_ADD_NAME = §eHinzufügen
|
||||||
SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Klicke mit einem Buch zum hinzufügen
|
SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Klicke mit einem Buch zum hinzufügen
|
||||||
|
@ -30,6 +30,7 @@ import de.steamwar.sql.SteamwarUser;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.BookMeta;
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
import org.luaj.vm2.Globals;
|
import org.luaj.vm2.Globals;
|
||||||
@ -69,6 +70,7 @@ public class ScriptGUI implements Listener {
|
|||||||
lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_1", player));
|
lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_1", player));
|
||||||
lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_2", player));
|
lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_2", player));
|
||||||
lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_3", player));
|
lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_3", player));
|
||||||
|
lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_4", player));
|
||||||
|
|
||||||
entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.ENCHANTED_BOOK, script.getName(), new ArrayList<>(lore), false, clickType -> {}), script));
|
entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.ENCHANTED_BOOK, script.getName(), new ArrayList<>(lore), false, clickType -> {}), script));
|
||||||
lore.clear();
|
lore.clear();
|
||||||
@ -76,7 +78,10 @@ public class ScriptGUI implements Listener {
|
|||||||
|
|
||||||
SWListInv<Script> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_NAME", player), false, entries, (clickType, script) -> {
|
SWListInv<Script> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_NAME", player), false, entries, (clickType, script) -> {
|
||||||
ItemStack itemStack = ScriptHelper.getScriptItem(script, clickType.isRightClick());
|
ItemStack itemStack = ScriptHelper.getScriptItem(script, clickType.isRightClick());
|
||||||
if(!clickType.isShiftClick()) {
|
|
||||||
|
if(clickType == ClickType.MIDDLE) {
|
||||||
|
player.openBook(itemStack);
|
||||||
|
} else if(!clickType.isShiftClick()) {
|
||||||
script.delete();
|
script.delete();
|
||||||
ScriptRunner.updateGlobalScript(player);
|
ScriptRunner.updateGlobalScript(player);
|
||||||
open(player, itemStack);
|
open(player, itemStack);
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.sk89q.worldedit.WorldEdit;
|
||||||
|
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import de.steamwar.bausystem.region.Point;
|
||||||
|
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||||
|
import de.steamwar.linkage.Linked;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.luaj.vm2.LuaTable;
|
||||||
|
|
||||||
|
@Linked
|
||||||
|
public class WorldEditLib implements LuaLib {
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "_worldedit";
|
||||||
Chaoscaot markierte diese Unterhaltung als gelöst
|
|||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LuaTable get(Player player) {
|
||||||
|
LuaTable table = new LuaTable();
|
||||||
|
table.set("selection", getterAndSetter(() -> {
|
||||||
|
LuaTable selection = new LuaTable();
|
||||||
|
selection.set("min", posFromVec(WorldEdit.getInstance().getSessionManager().get(new BukkitPlayer(player)).getSelectionWorld().getMinimumPoint()));
|
||||||
|
selection.set("max", posFromVec(WorldEdit.getInstance().getSessionManager().get(new BukkitPlayer(player)).getSelectionWorld().getMaximumPoint()));
|
||||||
|
return selection;
|
||||||
|
}, o -> {
|
||||||
|
LuaTable selection = o.checktable();
|
||||||
|
if(selection.length() != 2) {
|
||||||
|
throw new IllegalArgumentException("selection must have exactly 2 elements");
|
||||||
|
}
|
||||||
|
|
||||||
|
Point one = vecFromPos(selection.get(1).checktable());
|
||||||
|
Point two = vecFromPos(selection.get(2).checktable());
|
||||||
|
|
||||||
|
FlatteningWrapper.impl.setSelection(player, one, two);
|
||||||
|
}));
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LuaTable posFromVec(BlockVector3 vec) {
|
||||||
|
LuaTable table = new LuaTable();
|
||||||
|
table.set("x", vec.getBlockX());
|
||||||
|
table.set("y", vec.getBlockY());
|
||||||
|
table.set("z", vec.getBlockZ());
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Point vecFromPos(LuaTable table) {
|
||||||
|
return new Point(table.get("x").checkint(), table.get("y").checkint(), table.get("z").checkint());
|
||||||
|
}
|
||||||
|
}
|
@ -31,6 +31,7 @@ import java.util.List;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Getter
|
@Getter
|
||||||
public class Script {
|
public class Script {
|
||||||
|
// TODO: 28.05.23 REMOVE THIS
|
||||||
|
|
||||||
private static final Table<Script> table = new Table<>(Script.class);
|
private static final Table<Script> table = new Table<>(Script.class);
|
||||||
|
|
||||||
|
@ -33,7 +33,8 @@
|
|||||||
|
|
||||||
|
|
||||||
## Einleitung
|
## Einleitung
|
||||||
Das Script System auf SteamWar.de basiert auf [Lua](https://www.lua.org/docs.html). Der Code wird einfach in ein Minecraft Buch geschrieben und kann mit einem Links-Klick ausgeführt werden.
|
Das Script System auf SteamWar.de basiert auf [Lua](https://www.lua.org/docs.html).
|
||||||
|
Der Code wird einfach in ein Minecraft Buch geschrieben und kann mit einem Links-Klick ausgeführt werden.
|
||||||
|
|
||||||
# Basis-Apis
|
# Basis-Apis
|
||||||
Es werden folgende Standard-Apis zur Verfügung gestellt:
|
Es werden folgende Standard-Apis zur Verfügung gestellt:
|
||||||
@ -43,10 +44,15 @@ Es werden folgende Standard-Apis zur Verfügung gestellt:
|
|||||||
- `bit32`
|
- `bit32`
|
||||||
Chaoscaot markierte diese Unterhaltung als gelöst
Lixfel
hat
Warum hier kein Link? Warum hier kein Link?
|
|||||||
|
|
||||||
# SteamWar.de-Api
|
# SteamWar.de-Api
|
||||||
|
APIs, die mit einem `_` beginnen sind noch nicht stabil und können sich jederzeit ändern.
|
||||||
|
Sie sollten daher nicht verwendet werden, da sie sich noch in der Entwicklung befinden.
|
||||||
|
Diese können auch undokumentierte Funktionen enthalten, die nicht in der Dokumentation aufgeführt sind.
|
||||||
|
|
||||||
In den Scripten gibt es dazu noch folgende globale Variablen:
|
In den Scripten gibt es dazu noch folgende globale Variablen:
|
||||||
- [`player`](#player)
|
- [`player`](#player)
|
||||||
- [`region`](#region)
|
- [`region`](#region)
|
||||||
- [`server`](#server)
|
- [`server`](#server)
|
||||||
|
- `_worldedit`
|
||||||
|
|
||||||
### global
|
### global
|
||||||
Die `global`-Api stellt Funktionen zur Verfügung, QOL sind.
|
Die `global`-Api stellt Funktionen zur Verfügung, QOL sind.
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Trotz dass diese Lib noch im Prototypenstadium ist, wäre es schön für die Spieler, wenn sie auch kurz in der Dokumentation beschrieben wird. Schließlich haben die Spieler keinen anderen Anhaltspunkt und keine IDE, wo sie die Funktionalität nachschlagen können.