Script System Lua #178
@ -30,8 +30,10 @@ import org.bukkit.entity.Player;
|
|||||||
import org.luaj.vm2.Globals;
|
import org.luaj.vm2.Globals;
|
||||||
import org.luaj.vm2.LuaFunction;
|
import org.luaj.vm2.LuaFunction;
|
||||||
import org.luaj.vm2.LuaValue;
|
import org.luaj.vm2.LuaValue;
|
||||||
|
import org.luaj.vm2.lib.OneArgFunction;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
@ -85,20 +87,36 @@ public class ScriptRunner {
|
|||||||
HOTKEY_MAP.remove(player);
|
HOTKEY_MAP.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void callEvent(Player player, SteamWarGlobalLuaPlugin.EventType event, LuaValue eventValue) {
|
public static boolean callEvent(Player player, SteamWarGlobalLuaPlugin.EventType event, LuaValue eventValue) {
|
||||||
Map<SteamWarGlobalLuaPlugin.EventType, List<LuaFunction>> stringListMap = EVENT_MAP.get(player);
|
Map<SteamWarGlobalLuaPlugin.EventType, List<LuaFunction>> stringListMap = EVENT_MAP.get(player);
|
||||||
if (stringListMap == null) {
|
if (stringListMap == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<LuaFunction> luaFunctions = stringListMap.get(event);
|
List<LuaFunction> luaFunctions = stringListMap.get(event);
|
||||||
if (luaFunctions == null) {
|
if (luaFunctions == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (eventValue == LuaValue.NIL) {
|
||||||
|
eventValue = LuaValue.tableOf();
|
||||||
|
}
|
||||||
|
|
||||||
|
AtomicBoolean cancelled = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
eventValue.set("setCancelled", new OneArgFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call(LuaValue arg) {
|
||||||
|
cancelled.set(arg.checkboolean());
|
||||||
|
return valueOf(cancelled.get());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
for (LuaFunction luaFunction : luaFunctions) {
|
for (LuaFunction luaFunction : luaFunctions) {
|
||||||
luaFunction.call(eventValue);
|
luaFunction.call(eventValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return cancelled.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean callCommand(Player player, String command, LuaValue args) {
|
public static boolean callCommand(Player player, String command, LuaValue args) {
|
||||||
|
@ -72,7 +72,7 @@ public class EventListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||||
if (LAST_FS.containsKey(event.getPlayer())) {
|
if (LAST_FS.containsKey(event.getPlayer())) {
|
||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.FF, LuaValue.NIL);
|
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.FF, LuaValue.NIL));
|
||||||
} else {
|
} else {
|
||||||
LAST_FS.put(event.getPlayer(), System.currentTimeMillis());
|
LAST_FS.put(event.getPlayer(), System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ public class EventListener implements Listener {
|
|||||||
table.set("y", event.getBlock().getY());
|
table.set("y", event.getBlock().getY());
|
||||||
table.set("z", event.getBlock().getZ());
|
table.set("z", event.getBlock().getZ());
|
||||||
table.set("type", event.getBlock().getType().name());
|
table.set("type", event.getBlock().getType().name());
|
||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.PlaceBlock, table);
|
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.PlaceBlock, table));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -95,10 +95,10 @@ public class EventListener implements Listener {
|
|||||||
table.set("y", event.getBlock().getY());
|
table.set("y", event.getBlock().getY());
|
||||||
table.set("z", event.getBlock().getZ());
|
table.set("z", event.getBlock().getZ());
|
||||||
table.set("type", event.getBlock().getType().name());
|
table.set("type", event.getBlock().getType().name());
|
||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.BreakBlock, table);
|
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.BreakBlock, table));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<Player> ignore = new HashSet<>();
|
private final Set<Player> ignore = new HashSet<>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
@ -120,10 +120,9 @@ public class EventListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.RightClick, table);
|
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.RightClick, table));
|
||||||
}
|
} else if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||||
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.LeftClick, table));
|
||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.LeftClick, table);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,11 +152,17 @@ public class EventListener implements Listener {
|
|||||||
table.set("y", event.getLocation().getY());
|
table.set("y", event.getLocation().getY());
|
||||||
table.set("z", event.getLocation().getZ());
|
table.set("z", event.getLocation().getZ());
|
||||||
|
|
||||||
|
boolean cancel = false;
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL) &&
|
||||||
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table);
|
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table)) {
|
||||||
|
cancel = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event.setCancelled(cancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -165,7 +170,7 @@ public class EventListener implements Listener {
|
|||||||
ignore.add(event.getPlayer());
|
ignore.add(event.getPlayer());
|
||||||
LuaTable table = new LuaTable();
|
LuaTable table = new LuaTable();
|
||||||
table.set("type", event.getItemDrop().getItemStack().getType().name());
|
table.set("type", event.getItemDrop().getItemStack().getType().name());
|
||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DropItem, table);
|
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DropItem, table));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
29
SCRIPT.md
29
SCRIPT.md
@ -184,22 +184,23 @@ Hotkeys werden im folgenden Format angegeben: `MODIFIER+KEY`. Es gibt folgende M
|
|||||||
Es können auch mehrere Modifier angegeben werden, z.B. `ctrl+shift+alt+c`. Die Reihenfolge der Modifier und des Keys ist egal.
|
Es können auch mehrere Modifier angegeben werden, z.B. `ctrl+shift+alt+c`. Die Reihenfolge der Modifier und des Keys ist egal.
|
||||||
|
|
||||||
Chaoscaot markierte diese Unterhaltung als gelöst
|
|||||||
## Event Type
|
## Event Type
|
||||||
|
Einige Events sind auch cancelbar, dazu muss die Funktion `setCanceled()` aufgerufen werden.
|
||||||
Es gibt folgende Event-Typen:
|
Es gibt folgende Event-Typen:
|
||||||
|
|
||||||
| Name | Wenn | Parameter |
|
| Name | Wenn | Parameter | Cancelbar |
|
||||||
|---------------------|-----------------------------------------------------|---------------------------------|
|
|---------------------|-----------------------------------------------------|---------------------------------|-----------|
|
||||||
| `FF` | Beim Doppelten Drücken der Swap-Hands taste | NIL |
|
| `FF` | Beim Doppelten Drücken der Swap-Hands taste | NIL | false |
|
||||||
| `PlaceBlock` | Beim Platzieren von Blöcken | [BlockEvent](#blockevent) |
|
| `PlaceBlock` | Beim Platzieren von Blöcken | [BlockEvent](#blockevent) | true |
|
||||||
| `BreakBlock` | Beim Zerstören von Blöcken | [BlockEvent](#blockevent) |
|
| `BreakBlock` | Beim Zerstören von Blöcken | [BlockEvent](#blockevent) | true |
|
||||||
| `RightClick` | Beim Rechts klicken | [InteractEvent](#interactevent) |
|
| `RightClick` | Beim Rechts klicken | [InteractEvent](#interactevent) | true |
|
||||||
| `LeftClick` | Beim Links Klicken | [InteractEvent](#interactevent) |
|
| `LeftClick` | Beim Links Klicken | [InteractEvent](#interactevent) | true |
|
||||||
| `TNTSpawn` | Wenn ein TNT in der aktuellen Region spawnt | NIL |
|
| `TNTSpawn` | Wenn ein TNT in der aktuellen Region spawnt | NIL | false |
|
||||||
| `TNTExplode` | Wenn ein TNT in der aktuellen Region explodiert | [Position](#position) |
|
| `TNTExplode` | Wenn ein TNT in der aktuellen Region explodiert | [Position](#position) | true |
|
||||||
| `TNTExplodeInBuild` | Wenn ein TNT in der aktuellen Bau Region explodiert | [Position](#position) |
|
| `TNTExplodeInBuild` | Wenn ein TNT in der aktuellen Bau Region explodiert | [Position](#position) | true |
|
||||||
| `SelfJoin` | Wenn man selbst den Server betritt | NIL |
|
| `SelfJoin` | Wenn man selbst den Server betritt | NIL | false |
|
||||||
| `SelfLeave` | Wenn man den Server verlässt | NIL |
|
| `SelfLeave` | Wenn man den Server verlässt | NIL | false |
|
||||||
| `DropItem` | Wenn man ein item Droppt | (type: Material) |
|
| `DropItem` | Wenn man ein item Droppt | (type: Material) | true |
|
||||||
| `EntityDeath` | Wenn ein Entity Stirbt | (type: Entity Type) |
|
| `EntityDeath` | Wenn ein Entity Stirbt | (type: Entity Type) | false |
|
||||||
|
|
||||||
### BlockEvent
|
### BlockEvent
|
||||||
Das übergebene Objekt an den Handler hat folgende Variablen:
|
Das übergebene Objekt an den Handler hat folgende Variablen:
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Jetzt großgeschrieben oder kleingeschrieben? Unklar.