mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-18 08:35:52 +01:00
Fix command signs
This commit is contained in:
parent
5e7b28ea55
commit
77fbcdd68a
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user