SteamWar/BauSystem2.0
Archiviert
12
0

Fix CustomCommandListener StackOverFlowError

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-07-10 12:56:40 +02:00
Ursprung 0811f41b45
Commit e0483beb54
2 geänderte Dateien mit 23 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -81,6 +81,11 @@ public class CustomCommandListener implements Listener {
@EventHandler @EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) { public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) {
if (e.getMessage().startsWith("/script:")) {
e.setMessage("/" + e.getMessage().substring(8));
return;
}
Map<String, BookMeta> bookMetaMap = playerMap.get(e.getPlayer()); Map<String, BookMeta> bookMetaMap = playerMap.get(e.getPlayer());
if (bookMetaMap == null) { if (bookMetaMap == null) {
return; return;
@ -90,7 +95,11 @@ public class CustomCommandListener implements Listener {
return; return;
} }
e.setCancelled(true); e.setCancelled(true);
try {
new ScriptExecutor(bookMeta, e.getPlayer()); new ScriptExecutor(bookMeta, e.getPlayer());
} catch (StackOverflowError exception) {
// Ignored
}
} }
private boolean isNoBook(ItemStack item) { private boolean isNoBook(ItemStack item) {

Datei anzeigen

@ -18,6 +18,8 @@ public final class ScriptExecutor {
public static final Set<SpecialCommand> SPECIAL_COMMANDS = new HashSet<>(); public static final Set<SpecialCommand> SPECIAL_COMMANDS = new HashSet<>();
private String specialCommand = null;
@Getter @Getter
private final Player player; private final Player player;
@ -40,10 +42,18 @@ public final class ScriptExecutor {
this.player = player; this.player = player;
globalVariables = ScriptListener.getGlobalContext(player); globalVariables = ScriptListener.getGlobalContext(player);
boolean initial = true;
for (String page : bookMeta.getPages()) { for (String page : bookMeta.getPages()) {
for (String command : page.split("\n")) { for (String command : page.split("\n")) {
command = command.replaceAll(" +", " "); command = command.replaceAll(" +", " ");
if (command.startsWith("#") || command.trim().isEmpty()) continue; if (command.startsWith("#") || command.trim().isEmpty()) {
if (initial && command.startsWith("#!CMD /")) {
specialCommand = command.substring(7);
}
initial = false;
continue;
}
initial = false;
if (command.startsWith(".")) { if (command.startsWith(".")) {
jumpPoints.put(command.substring(1), commands.size()); jumpPoints.put(command.substring(1), commands.size());
continue; continue;
@ -86,7 +96,8 @@ public final class ScriptExecutor {
continue; continue;
} }
PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + command);
PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + (command.equals(specialCommand) ? "script:" : "") + command);
Bukkit.getServer().getPluginManager().callEvent(preprocessEvent); Bukkit.getServer().getPluginManager().callEvent(preprocessEvent);
if (preprocessEvent.isCancelled()) { if (preprocessEvent.isCancelled()) {
continue; continue;