Fix command signs; resolves #827

This commit is contained in:
Daniel Saukel 2020-06-22 21:27:47 +02:00
parent 9a45ab0b6c
commit bd1d76b531
2 changed files with 17 additions and 12 deletions

View File

@ -81,7 +81,7 @@ public class CommandSign extends Windup {
@Override @Override
public boolean validate() { public boolean validate() {
script = ((DungeonsXL) api).getCommandScriptRegistry().get(getLine(1)); script = ((DungeonsXL) api).getCommandScriptRegistry().get(getLine(1));
return script != null; return script != null && !script.getCommands().isEmpty();
} }
@Override @Override
@ -99,27 +99,30 @@ public class CommandSign extends Windup {
} else if (attributes.length == 2) { } else if (attributes.length == 2) {
delay = NumberUtil.parseDouble(attributes[0]); delay = NumberUtil.parseDouble(attributes[0]);
double interval = NumberUtil.parseDouble(attributes[1], -1); interval = NumberUtil.parseDouble(attributes[1], -1);
if (interval == -1) { if (interval == -1) {
interval = delay;
executor = EnumUtil.getEnumIgnoreCase(Executor.class, attributes[1]); executor = EnumUtil.getEnumIgnoreCase(Executor.class, attributes[1]);
} else {
this.interval = interval;
} }
if (executor == null) { if (executor == null) {
executor = Executor.DEFAULT; executor = Executor.DEFAULT;
} }
} else if (attributes.length == 1) { } else if (attributes.length == 1) {
double delay = NumberUtil.parseDouble(attributes[0], -1); delay = NumberUtil.parseDouble(attributes[0], -1);
if (delay == -1) { if (delay == -1) {
delay = 0;
interval = 0;
executor = EnumUtil.getEnumIgnoreCase(Executor.class, attributes[0]); executor = EnumUtil.getEnumIgnoreCase(Executor.class, attributes[0]);
} else { }
this.delay = delay; if (executor == null) {
executor = Executor.DEFAULT;
} }
} else if (attributes.length == 0) { } else if (attributes.length == 0) {
executor = Executor.DEFAULT; executor = Executor.DEFAULT;
} }
n = script.getCommands().size();
setRunnable(new CommandTask(this, Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"))); setRunnable(new CommandTask(this, Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")));

View File

@ -53,17 +53,19 @@ public class CommandTask extends BukkitRunnable {
sign.deactivate(); sign.deactivate();
return; 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) { if (papi) {
Bukkit.getServer().dispatchCommand(sender, PlaceholderAPI.setPlaceholders(player, command)); Bukkit.getServer().dispatchCommand(sender, PlaceholderAPI.setPlaceholders(player, command));
} else { } else {
Bukkit.getServer().dispatchCommand(sender, command); Bukkit.getServer().dispatchCommand(sender, command);
} }
if (k >= script.getCommands().size()) {
sign.deactivate();
}
} }
@Override @Override