SteamWar/BauSystem2.0
Archiviert
12
0

Fix command stack overflow
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-07-17 20:14:38 +02:00
Ursprung abc053bf8b
Commit 9207d3c966
2 geänderte Dateien mit 28 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -21,21 +21,48 @@ package de.steamwar.bausystem.features.script.event;
import de.steamwar.bausystem.features.script.ScriptRunner;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.luaj.vm2.LuaValue;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@Linked
public class CommandListener implements Listener {
private Map<Player, Set<String>> calledCommands = new HashMap<>();
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
String[] split = event.getMessage().split(" ");
if (calledCommands.getOrDefault(event.getPlayer(), new HashSet<>()).contains(split[0])) {
return;
}
LuaValue[] values = new LuaValue[split.length - 1];
for (int i = 1; i < split.length; i++) {
values[i - 1] = LuaValue.valueOf(split[i]);
}
calledCommands.getOrDefault(event.getPlayer(), new HashSet<>()).add(split[0]);
event.setCancelled(ScriptRunner.callCommand(event.getPlayer(), split[0].substring(1), LuaValue.listOf(values)));
calledCommands.getOrDefault(event.getPlayer(), new HashSet<>()).remove(split[0]);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
calledCommands.put(event.getPlayer(), new HashSet<>());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
calledCommands.remove(event.getPlayer());
}
}

Datei anzeigen

@ -159,7 +159,7 @@ public class EventListener implements Listener {
for (Player player : Bukkit.getOnlinePlayers()) {
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table, event)
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table, event);
}
}
}