From bd1d76b531baae93f7c551a1d70efedc8361a03d Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 22 Jun 2020 21:27:47 +0200 Subject: [PATCH] Fix command signs; resolves #827 --- .../dungeonsxl/sign/windup/CommandSign.java | 17 ++++++++++------- .../dungeonsxl/sign/windup/CommandTask.java | 12 +++++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/CommandSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/CommandSign.java index 1b1197cc..08901e41 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/CommandSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/CommandSign.java @@ -81,7 +81,7 @@ public class CommandSign extends Windup { @Override public boolean validate() { script = ((DungeonsXL) api).getCommandScriptRegistry().get(getLine(1)); - return script != null; + return script != null && !script.getCommands().isEmpty(); } @Override @@ -99,27 +99,30 @@ public class CommandSign extends Windup { } else if (attributes.length == 2) { delay = NumberUtil.parseDouble(attributes[0]); - double interval = NumberUtil.parseDouble(attributes[1], -1); + interval = NumberUtil.parseDouble(attributes[1], -1); if (interval == -1) { + interval = delay; executor = EnumUtil.getEnumIgnoreCase(Executor.class, attributes[1]); - } else { - this.interval = interval; } if (executor == null) { executor = Executor.DEFAULT; } } else if (attributes.length == 1) { - double delay = NumberUtil.parseDouble(attributes[0], -1); + delay = NumberUtil.parseDouble(attributes[0], -1); if (delay == -1) { + delay = 0; + interval = 0; executor = EnumUtil.getEnumIgnoreCase(Executor.class, attributes[0]); - } else { - this.delay = delay; + } + if (executor == null) { + executor = Executor.DEFAULT; } } else if (attributes.length == 0) { executor = Executor.DEFAULT; } + n = script.getCommands().size(); setRunnable(new CommandTask(this, Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"))); diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/CommandTask.java b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/CommandTask.java index 138c8119..13c70116 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/CommandTask.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/CommandTask.java @@ -53,17 +53,19 @@ public class CommandTask extends BukkitRunnable { sign.deactivate(); return; } + if (k >= script.getCommands().size()) { + sign.deactivate(); + k = 0; + } - String command = script.getCommands().get(k++).replace("%player%", sender.getName()).replace("%player_name%", sender.getName()); + String command = script.getCommands().get(k++) + .replace("%player%", sender.getName()).replace("%player_name%", sender.getName()) + .replace("%world%", sign.getGameWorld().getWorld().getName()).replace("%world_name%", sign.getGameWorld().getWorld().getName()); if (papi) { Bukkit.getServer().dispatchCommand(sender, PlaceholderAPI.setPlaceholders(player, command)); } else { Bukkit.getServer().dispatchCommand(sender, command); } - - if (k >= script.getCommands().size()) { - sign.deactivate(); - } } @Override