Script System Lua #178
@ -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)));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +100,6 @@ public class SteamWarGlobalLuaPlugin extends TwoArgFunction {
|
||||
SelfJoin,
|
||||
SelfLeave,
|
||||
DropItem,
|
||||
EntityDeath;
|
||||
EntityDeath
|
||||
}
|
||||
}
|
||||
|
18
SCRIPT.md
18
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 |
|
||||
Chaoscaot markierte diese Unterhaltung als gelöst
|
||||
|-----------|-----------------------------------|-----------------------------------------------------------------------------|
|
||||
| `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)
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Was unterscheidet diese Global-API von der obengenannten global-API? Absolut verwirrend, muss mindestens unbenannt werden.