diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfly.java b/Essentials/src/com/earth2me/essentials/commands/Commandfly.java index 9b30e4ff9..40ddfccf2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfly.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfly.java @@ -19,18 +19,7 @@ public class Commandfly extends EssentialsToggleCommand { @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - if (args.length == 1) { - Boolean toggle = matchToggleArgument(args[0]); - if (toggle == null && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getSource(), args); - } else { - togglePlayer(user.getSource(), user, toggle); - } - } else if (args.length == 2 && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getSource(), args); - } else { - togglePlayer(user.getSource(), user, null); - } + handleToggleWithArgs(server, user, args); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java index 5e156476f..295f2c619 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java @@ -20,18 +20,7 @@ public class Commandgod extends EssentialsToggleCommand { @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - if (args.length == 1) { - Boolean toggle = matchToggleArgument(args[0]); - if (toggle == null && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getSource(), args); - } else { - togglePlayer(user.getSource(), user, toggle); - } - } else if (args.length == 2 && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getSource(), args); - } else { - togglePlayer(user.getSource(), user, null); - } + handleToggleWithArgs(server, user, args); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsgtoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsgtoggle.java index f757e46a9..be9bcd022 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsgtoggle.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsgtoggle.java @@ -19,18 +19,7 @@ public class Commandmsgtoggle extends EssentialsToggleCommand { @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - if (args.length == 1) { - Boolean toggle = matchToggleArgument(args[0]); - if (toggle == null && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getSource(), args); - } else { - togglePlayer(user.getSource(), user, toggle); - } - } else if (args.length == 2 && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getSource(), args); - } else { - togglePlayer(user.getSource(), user, null); - } + handleToggleWithArgs(server, user, args); } @Override @@ -42,7 +31,7 @@ public class Commandmsgtoggle extends EssentialsToggleCommand { user.setIgnoreMsg(enabled); user.sendMessage(!enabled ? tl("msgEnabled") : tl("msgDisabled")); - if (!sender.isPlayer() || !sender.getPlayer().equals(user.getBase())) { + if (!sender.isPlayer() || !user.getBase().equals(sender.getPlayer())) { sender.sendMessage(!enabled ? tl("msgEnabledFor", user.getDisplayName()) : tl("msgDisabledFor", user.getDisplayName())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java b/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java index 53777483a..76ce77ac5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java @@ -19,18 +19,7 @@ public class Commandsocialspy extends EssentialsToggleCommand { @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - if (args.length == 1) { - Boolean toggle = matchToggleArgument(args[0]); - if (toggle == null && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getSource(), args); - } else { - togglePlayer(user.getSource(), user, toggle); - } - } else if (args.length == 2 && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getSource(), args); - } else { - togglePlayer(user.getSource(), user, null); - } + handleToggleWithArgs(server, user, args); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java index 9ba5b5191..122e37218 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java @@ -19,18 +19,7 @@ public class Commandtptoggle extends EssentialsToggleCommand { @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - if (args.length == 1) { - Boolean toggle = matchToggleArgument(args[0]); - if (toggle == null && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getSource(), args); - } else { - togglePlayer(user.getSource(), user, toggle); - } - } else if (args.length == 2 && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getSource(), args); - } else { - togglePlayer(user.getSource(), user, null); - } + handleToggleWithArgs(server, user, args); } @Override @@ -42,7 +31,7 @@ public class Commandtptoggle extends EssentialsToggleCommand { user.setTeleportEnabled(enabled); user.sendMessage(enabled ? tl("teleportationEnabled") : tl("teleportationDisabled")); - if (!sender.isPlayer() || !sender.getPlayer().equals(user.getBase())) { + if (!sender.isPlayer() || !user.getBase().equals(sender.getPlayer())) { sender.sendMessage(enabled ? tl("teleportationEnabledFor", user.getDisplayName()) : tl("teleportationDisabledFor", user.getDisplayName())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandvanish.java b/Essentials/src/com/earth2me/essentials/commands/Commandvanish.java index 839023e00..fcd0fce48 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandvanish.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandvanish.java @@ -19,18 +19,7 @@ public class Commandvanish extends EssentialsToggleCommand { @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - if (args.length == 1) { - Boolean toggle = matchToggleArgument(args[0]); - if (toggle == null && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getSource(), args); - } else { - togglePlayer(user.getSource(), user, toggle); - } - } else if (args.length == 2 && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getSource(), args); - } else { - togglePlayer(user.getSource(), user, null); - } + handleToggleWithArgs(server, user, args); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java index a88f18b9d..22b6ee95e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java @@ -16,6 +16,21 @@ public abstract class EssentialsToggleCommand extends EssentialsCommand { this.othersPermission = othersPermission; } + protected void handleToggleWithArgs(Server server, User user, String[] args) throws Exception { + if (args.length == 1) { + Boolean toggle = matchToggleArgument(args[0]); + if (toggle == null && user.isAuthorized(othersPermission)) { + toggleOtherPlayers(server, user.getSource(), args); + } else { + togglePlayer(user.getSource(), user, toggle); + } + } else if (args.length == 2 && user.isAuthorized(othersPermission)) { + toggleOtherPlayers(server, user.getSource(), args); + } else { + togglePlayer(user.getSource(), user, null); + } + } + protected Boolean matchToggleArgument(final String arg) { if (arg.equalsIgnoreCase("on") || arg.startsWith("ena") || arg.equalsIgnoreCase("1")) { return true;