Split command into smaller methods

This commit is contained in:
mathiascode 2019-12-17 20:51:46 +02:00
parent aa8e5bb70e
commit f3abebe888

View file

@ -17,16 +17,7 @@ import pw.kaboom.icontrolu.Main;
import pw.kaboom.icontrolu.utilities.PlayerList;
public final class CommandIcu implements CommandExecutor {
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage("Command has to be run by a player");
} else {
final Player controller = (Player) sender;
if (args.length == 0) {
controller.sendMessage(ChatColor.RED + "Usage: /" + label + " <control|stop>");
} else if (args[0].equalsIgnoreCase("control")) {
private void controlCommand(final Player controller, final String label, final String[] args) {
if (args.length == 1) {
controller.sendMessage(ChatColor.RED + "Usage: /" + label + " control <player>");
} else {
@ -57,7 +48,9 @@ public final class CommandIcu implements CommandExecutor {
controller.sendMessage("Player \"" + args[1] + "\" not found");
}
}
} else if (args[0].equalsIgnoreCase("stop")) {
}
private void stopCommand(final Player controller) {
final Player target = PlayerList.getTarget(controller.getUniqueId());
if (target != null) {
@ -84,11 +77,29 @@ public final class CommandIcu implements CommandExecutor {
}
}.runTaskLater(JavaPlugin.getPlugin(Main.class), tickDelay);
controller.sendMessage("You are no longer controlling \"" + target.getName() + "\". You are invisible for 10 seconds.");
final int seconds = tickDelay / 20;
controller.sendMessage("You are no longer controlling \"" + target.getName() + "\". You are invisible for " + seconds + " seconds.");
} else {
controller.sendMessage("You are not controlling anyone at the moment");
}
}
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage("Command has to be run by a player");
return true;
}
final Player controller = (Player) sender;
if (args.length == 0) {
controller.sendMessage(ChatColor.RED + "Usage: /" + label + " <control|stop>");
} else if (args[0].equalsIgnoreCase("control")) {
controlCommand(controller, label, args);
} else if (args[0].equalsIgnoreCase("stop")) {
stopCommand(controller);
}
return true;
}