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 f749a782..6130ab0c 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 @@ -36,7 +36,7 @@ import org.bukkit.entity.Player; */ public class CommandSign extends Windup { - private enum Executor { + public enum Executor { DEFAULT, OP, CONSOLE @@ -78,6 +78,10 @@ public class CommandSign extends Windup { return true; } + public Executor getExecutor() { + return executor; + } + @Override public boolean validate() { script = ((DungeonsXL) api).getCommandScriptRegistry().get(getLine(1)); @@ -159,12 +163,11 @@ public class CommandSign extends Windup { public boolean activate(Player player) { CommandSender sender = player; boolean wasOp = player.isOp(); - if (executor == Executor.OP) { - player.setOp(true); - } else if (executor == Executor.CONSOLE) { + if (executor == Executor.CONSOLE) { sender = Bukkit.getConsoleSender(); } ((CommandTask) getRunnable()).setSender(sender, wasOp); + ((CommandTask) getRunnable()).setPlayer(player); startTask(); active = true; return true; 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 ddea196a..c572d552 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 @@ -47,6 +47,10 @@ public class CommandTask extends BukkitRunnable { this.wasOp = wasOp; } + public void setPlayer(Player player) { + this.player = player; + } + @Override public void run() { if (sign.isWorldFinished()) { @@ -56,22 +60,23 @@ public class CommandTask extends BukkitRunnable { if (k >= script.getCommands().size()) { sign.deactivate(); k = 0; + return; } 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 (player != null) { + command = command.replace("%player%", player.getName()).replace("%player_name%", player.getName()); + } + if (sign.getExecutor() == CommandSign.Executor.OP) { + sender.setOp(true); + } if (papi) { Bukkit.getServer().dispatchCommand(sender, PlaceholderAPI.setPlaceholders(player, command)); } else { Bukkit.getServer().dispatchCommand(sender, command); } - } - - @Override - public void cancel() { - super.cancel(); - if (sender != Bukkit.getConsoleSender()) { + if (sign.getExecutor() == CommandSign.Executor.OP) { sender.setOp(wasOp); } }