diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java index 4d38f96a..81df2f26 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java @@ -113,6 +113,6 @@ public class ScriptRunner { public static void callHotkey(int mods, int key, Player player, boolean pressed) { Hotkey hotkey = Hotkey.fromChar(key, mods); - HOTKEY_MAP.get(player).getOrDefault(hotkey, Collections.emptyList()).forEach(luaFunction -> luaFunction.call(LuaValue.valueOf(pressed))); + HOTKEY_MAP.getOrDefault(player, Collections.emptyMap()).getOrDefault(hotkey, Collections.emptyList()).forEach(luaFunction -> luaFunction.call(LuaValue.valueOf(pressed))); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java index d6280b50..68e9720a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java @@ -22,12 +22,13 @@ package de.steamwar.bausystem.features.script.event; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.script.ScriptRunner; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.api.Plain; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; @Linked -public class HotkeyListener implements PluginMessageListener { +public class HotkeyListener implements PluginMessageListener, Plain { { Bukkit.getServer().getMessenger().registerIncomingPluginChannel(BauSystem.getInstance(), "sw:hotkeys", this); @@ -43,10 +44,10 @@ public class HotkeyListener implements PluginMessageListener { if (!(key >= 'A' && key <= 'Z' || key >= '0' && key <= '9')) return; if (message.length >= 9) { int mods = (message[5] & 0xFF) << 24 | (message[6] & 0xFF) << 16 | (message[7] & 0xFF) << 8 | (message[8] & 0xFF); - // player.sendMessage("Hotkey: " + (char) key + " " + action + " " + Long.toBinaryString(mods)); + player.sendMessage("Hotkey: " + (char) key + " " + action + " " + Long.toBinaryString(mods)); ScriptRunner.callHotkey(mods, key, player, action == 1); } else { - // player.sendMessage("Hotkey: " + (char) key + " " + action); + player.sendMessage("Hotkey: " + (char) key + " " + action); ScriptRunner.callHotkey(0, key, player, action == 1); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java index fab18532..59326fb4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java @@ -100,6 +100,6 @@ public class SteamWarGlobalLuaPlugin extends TwoArgFunction { SelfJoin, SelfLeave, DropItem, - EntityDeath; + EntityDeath } } diff --git a/SCRIPT.md b/SCRIPT.md index fcbffae2..bab3b9a5 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -161,11 +161,11 @@ Die `global`-Api stellt Funktionen zur Verfügung um auf Events, Commands und Ho Es gibt folgende Funktionen: -| Name | Signature | Beschreibung | -|-----------|---------------------------------|---------------------------------| -| `event` | event(EventType, Function(Any)) | Registriere einen Event Handler | -| `command` | command(String, Function(Any)) | Registriere einen Command | -| `hotkey` | hotkey(String, Function(Any)) | Registriere einen Hotkey | +| Name | Signature | Beschreibung | +|-----------|-----------------------------------|-----------------------------------------------------------------------------| +| `event` | event(EventType, Function(Any)) | Registriere einen Event Handler | +| `command` | command(String, Function(Args)) | Registriere einen Command | +| `hotkey` | hotkey(String, Function(Boolean)) | Registriere einen Hotkey, the function gets a boolean if the key is pressed | Es gibt folgende Variablen: @@ -273,7 +273,7 @@ Ein einfacher Command Redefiner. #### Code ```lua -function handler(event) +function handler(args) exec("stoplag") end @@ -285,8 +285,10 @@ Ein Hotkey zum pasten des Clipboard-Inhalts. #### Code ```lua -function handler(event) - exec("/paste -o") +function handler(pressed) + if pressed then + exec("/paste -o") + end end hotkey("ctrl+v", handler)