Signed-off-by: Chaoscaot <chaoscaot@zohomail.eu>
Dieser Commit ist enthalten in:
Ursprung
96b37e1df1
Commit
dd69f7ba83
@ -30,8 +30,10 @@ import org.bukkit.entity.Player;
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LuaFunction;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.OneArgFunction;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
@ -85,20 +87,36 @@ public class ScriptRunner {
|
||||
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);
|
||||
if (stringListMap == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
List<LuaFunction> luaFunctions = stringListMap.get(event);
|
||||
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) {
|
||||
luaFunction.call(eventValue);
|
||||
}
|
||||
|
||||
return cancelled.get();
|
||||
}
|
||||
|
||||
public static boolean callCommand(Player player, String command, LuaValue args) {
|
||||
|
@ -72,7 +72,7 @@ public class EventListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||
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 {
|
||||
LAST_FS.put(event.getPlayer(), System.currentTimeMillis());
|
||||
}
|
||||
@ -85,7 +85,7 @@ public class EventListener implements Listener {
|
||||
table.set("y", event.getBlock().getY());
|
||||
table.set("z", event.getBlock().getZ());
|
||||
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
|
||||
@ -95,10 +95,10 @@ public class EventListener implements Listener {
|
||||
table.set("y", event.getBlock().getY());
|
||||
table.set("z", event.getBlock().getZ());
|
||||
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
|
||||
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) {
|
||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.RightClick, table);
|
||||
}
|
||||
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.LeftClick, 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) {
|
||||
event.setCancelled(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("z", event.getLocation().getZ());
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
||||
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table);
|
||||
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL) &&
|
||||
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table)) {
|
||||
cancel = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
event.setCancelled(cancel);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -165,7 +170,7 @@ public class EventListener implements Listener {
|
||||
ignore.add(event.getPlayer());
|
||||
LuaTable table = new LuaTable();
|
||||
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
|
||||
|
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.
|
||||
|
||||
## Event Type
|
||||
Einige Events sind auch cancelbar, dazu muss die Funktion `setCanceled()` aufgerufen werden.
|
||||
Es gibt folgende Event-Typen:
|
||||
|
||||
| Name | Wenn | Parameter |
|
||||
|---------------------|-----------------------------------------------------|---------------------------------|
|
||||
| `FF` | Beim Doppelten Drücken der Swap-Hands taste | NIL |
|
||||
| `PlaceBlock` | Beim Platzieren von Blöcken | [BlockEvent](#blockevent) |
|
||||
| `BreakBlock` | Beim Zerstören von Blöcken | [BlockEvent](#blockevent) |
|
||||
| `RightClick` | Beim Rechts klicken | [InteractEvent](#interactevent) |
|
||||
| `LeftClick` | Beim Links Klicken | [InteractEvent](#interactevent) |
|
||||
| `TNTSpawn` | Wenn ein TNT in der aktuellen Region spawnt | NIL |
|
||||
| `TNTExplode` | Wenn ein TNT in der aktuellen Region explodiert | [Position](#position) |
|
||||
| `TNTExplodeInBuild` | Wenn ein TNT in der aktuellen Bau Region explodiert | [Position](#position) |
|
||||
| `SelfJoin` | Wenn man selbst den Server betritt | NIL |
|
||||
| `SelfLeave` | Wenn man den Server verlässt | NIL |
|
||||
| `DropItem` | Wenn man ein item Droppt | (type: Material) |
|
||||
| `EntityDeath` | Wenn ein Entity Stirbt | (type: Entity Type) |
|
||||
| Name | Wenn | Parameter | Cancelbar |
|
||||
|---------------------|-----------------------------------------------------|---------------------------------|-----------|
|
||||
| `FF` | Beim Doppelten Drücken der Swap-Hands taste | NIL | false |
|
||||
| `PlaceBlock` | Beim Platzieren von Blöcken | [BlockEvent](#blockevent) | true |
|
||||
| `BreakBlock` | Beim Zerstören von Blöcken | [BlockEvent](#blockevent) | true |
|
||||
| `RightClick` | Beim Rechts klicken | [InteractEvent](#interactevent) | true |
|
||||
| `LeftClick` | Beim Links Klicken | [InteractEvent](#interactevent) | true |
|
||||
| `TNTSpawn` | Wenn ein TNT in der aktuellen Region spawnt | NIL | false |
|
||||
| `TNTExplode` | Wenn ein TNT in der aktuellen Region explodiert | [Position](#position) | true |
|
||||
| `TNTExplodeInBuild` | Wenn ein TNT in der aktuellen Bau Region explodiert | [Position](#position) | true |
|
||||
| `SelfJoin` | Wenn man selbst den Server betritt | NIL | false |
|
||||
| `SelfLeave` | Wenn man den Server verlässt | NIL | false |
|
||||
| `DropItem` | Wenn man ein item Droppt | (type: Material) | true |
|
||||
| `EntityDeath` | Wenn ein Entity Stirbt | (type: Entity Type) | false |
|
||||
|
||||
### BlockEvent
|
||||
Das übergebene Objekt an den Handler hat folgende Variablen:
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren