Fix CustomCommandListener StackOverFlowError
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
0811f41b45
Commit
e0483beb54
@ -81,6 +81,11 @@ public class CustomCommandListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
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());
|
||||
if (bookMetaMap == null) {
|
||||
return;
|
||||
@ -90,7 +95,11 @@ public class CustomCommandListener implements Listener {
|
||||
return;
|
||||
}
|
||||
e.setCancelled(true);
|
||||
new ScriptExecutor(bookMeta, e.getPlayer());
|
||||
try {
|
||||
new ScriptExecutor(bookMeta, e.getPlayer());
|
||||
} catch (StackOverflowError exception) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNoBook(ItemStack item) {
|
||||
|
@ -18,6 +18,8 @@ public final class ScriptExecutor {
|
||||
|
||||
public static final Set<SpecialCommand> SPECIAL_COMMANDS = new HashSet<>();
|
||||
|
||||
private String specialCommand = null;
|
||||
|
||||
@Getter
|
||||
private final Player player;
|
||||
|
||||
@ -40,10 +42,18 @@ public final class ScriptExecutor {
|
||||
this.player = player;
|
||||
globalVariables = ScriptListener.getGlobalContext(player);
|
||||
|
||||
boolean initial = true;
|
||||
for (String page : bookMeta.getPages()) {
|
||||
for (String command : page.split("\n")) {
|
||||
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(".")) {
|
||||
jumpPoints.put(command.substring(1), commands.size());
|
||||
continue;
|
||||
@ -86,7 +96,8 @@ public final class ScriptExecutor {
|
||||
continue;
|
||||
}
|
||||
|
||||
PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + command);
|
||||
|
||||
PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + (command.equals(specialCommand) ? "script:" : "") + command);
|
||||
Bukkit.getServer().getPluginManager().callEvent(preprocessEvent);
|
||||
if (preprocessEvent.isCancelled()) {
|
||||
continue;
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren