mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 06:57:39 +01:00
Deduplicate toggle argument handling code
This commit is contained in:
parent
8102bab3ff
commit
7967f62131
@ -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
|
||||
|
@ -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
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user