mirror of
https://github.com/kaboomserver/icontrolu.git
synced 2024-11-25 00:47:55 -05:00
Split command into smaller methods
This commit is contained in:
parent
aa8e5bb70e
commit
f3abebe888
1 changed files with 77 additions and 66 deletions
|
@ -17,78 +17,89 @@ import pw.kaboom.icontrolu.Main;
|
||||||
import pw.kaboom.icontrolu.utilities.PlayerList;
|
import pw.kaboom.icontrolu.utilities.PlayerList;
|
||||||
|
|
||||||
public final class CommandIcu implements CommandExecutor {
|
public final class CommandIcu implements CommandExecutor {
|
||||||
|
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 {
|
||||||
|
final Player target = Bukkit.getPlayer(args[1]);
|
||||||
|
|
||||||
|
if (target != null) {
|
||||||
|
if (target == controller) {
|
||||||
|
controller.sendMessage("You are already controlling yourself");
|
||||||
|
} else if (PlayerList.getTarget(controller.getUniqueId()) != null) {
|
||||||
|
controller.sendMessage("You are already controlling \"" + target.getName() + "\"");
|
||||||
|
} else if (PlayerList.getController(target.getUniqueId()) != null) {
|
||||||
|
controller.sendMessage("Player \"" + target.getName() + "\" is already being controlled");
|
||||||
|
} else if (PlayerList.getTarget(target.getUniqueId()) != null) {
|
||||||
|
controller.sendMessage("Player \"" + target.getName() + "\" is already controlling another player");
|
||||||
|
} else if (!controller.canSee(target)) {
|
||||||
|
controller.sendMessage("You may not control this player");
|
||||||
|
} else {
|
||||||
|
controller.teleportAsync(target.getLocation());
|
||||||
|
|
||||||
|
controller.getInventory().setContents(target.getInventory().getContents());
|
||||||
|
|
||||||
|
PlayerList.setTarget(controller.getUniqueId(), target);
|
||||||
|
PlayerList.setController(target.getUniqueId(), controller);
|
||||||
|
|
||||||
|
controller.sendMessage("You are now controlling \"" + target.getName() + "\"");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
controller.sendMessage("Player \"" + args[1] + "\" not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopCommand(final Player controller) {
|
||||||
|
final Player target = PlayerList.getTarget(controller.getUniqueId());
|
||||||
|
|
||||||
|
if (target != null) {
|
||||||
|
PlayerList.removeTarget(controller.getUniqueId());
|
||||||
|
PlayerList.removeController(target.getUniqueId());
|
||||||
|
|
||||||
|
final int tickDelay = 200;
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (Player player: Bukkit.getOnlinePlayers()) {
|
||||||
|
player.showPlayer(JavaPlugin.getPlugin(Main.class), controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||||
|
Team team = scoreboard.getTeam("icuDisableCollision");
|
||||||
|
if (team != null && team.hasEntry(controller.getName())) {
|
||||||
|
team.removeEntry(controller.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
controller.removePotionEffect(PotionEffectType.INVISIBILITY);
|
||||||
|
controller.sendMessage("You are now visible");
|
||||||
|
}
|
||||||
|
}.runTaskLater(JavaPlugin.getPlugin(Main.class), tickDelay);
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
if (sender instanceof ConsoleCommandSender) {
|
if (sender instanceof ConsoleCommandSender) {
|
||||||
sender.sendMessage("Command has to be run by a player");
|
sender.sendMessage("Command has to be run by a player");
|
||||||
} else {
|
return true;
|
||||||
final Player controller = (Player) sender;
|
}
|
||||||
|
|
||||||
if (args.length == 0) {
|
final Player controller = (Player) sender;
|
||||||
controller.sendMessage(ChatColor.RED + "Usage: /" + label + " <control|stop>");
|
|
||||||
} else if (args[0].equalsIgnoreCase("control")) {
|
|
||||||
if (args.length == 1) {
|
|
||||||
controller.sendMessage(ChatColor.RED + "Usage: /" + label + " control <player>");
|
|
||||||
} else {
|
|
||||||
final Player target = Bukkit.getPlayer(args[1]);
|
|
||||||
|
|
||||||
if (target != null) {
|
if (args.length == 0) {
|
||||||
if (target == controller) {
|
controller.sendMessage(ChatColor.RED + "Usage: /" + label + " <control|stop>");
|
||||||
controller.sendMessage("You are already controlling yourself");
|
} else if (args[0].equalsIgnoreCase("control")) {
|
||||||
} else if (PlayerList.getTarget(controller.getUniqueId()) != null) {
|
controlCommand(controller, label, args);
|
||||||
controller.sendMessage("You are already controlling \"" + target.getName() + "\"");
|
} else if (args[0].equalsIgnoreCase("stop")) {
|
||||||
} else if (PlayerList.getController(target.getUniqueId()) != null) {
|
stopCommand(controller);
|
||||||
controller.sendMessage("Player \"" + target.getName() + "\" is already being controlled");
|
|
||||||
} else if (PlayerList.getTarget(target.getUniqueId()) != null) {
|
|
||||||
controller.sendMessage("Player \"" + target.getName() + "\" is already controlling another player");
|
|
||||||
} else if (!controller.canSee(target)) {
|
|
||||||
controller.sendMessage("You may not control this player");
|
|
||||||
} else {
|
|
||||||
controller.teleportAsync(target.getLocation());
|
|
||||||
|
|
||||||
controller.getInventory().setContents(target.getInventory().getContents());
|
|
||||||
|
|
||||||
PlayerList.setTarget(controller.getUniqueId(), target);
|
|
||||||
PlayerList.setController(target.getUniqueId(), controller);
|
|
||||||
|
|
||||||
controller.sendMessage("You are now controlling \"" + target.getName() + "\"");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
controller.sendMessage("Player \"" + args[1] + "\" not found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (args[0].equalsIgnoreCase("stop")) {
|
|
||||||
final Player target = PlayerList.getTarget(controller.getUniqueId());
|
|
||||||
|
|
||||||
if (target != null) {
|
|
||||||
PlayerList.removeTarget(controller.getUniqueId());
|
|
||||||
PlayerList.removeController(target.getUniqueId());
|
|
||||||
|
|
||||||
final int tickDelay = 200;
|
|
||||||
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
for (Player player: Bukkit.getOnlinePlayers()) {
|
|
||||||
player.showPlayer(JavaPlugin.getPlugin(Main.class), controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
|
|
||||||
Team team = scoreboard.getTeam("icuDisableCollision");
|
|
||||||
if (team != null && team.hasEntry(controller.getName())) {
|
|
||||||
team.removeEntry(controller.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
controller.removePotionEffect(PotionEffectType.INVISIBILITY);
|
|
||||||
controller.sendMessage("You are now visible");
|
|
||||||
}
|
|
||||||
}.runTaskLater(JavaPlugin.getPlugin(Main.class), tickDelay);
|
|
||||||
|
|
||||||
controller.sendMessage("You are no longer controlling \"" + target.getName() + "\". You are invisible for 10 seconds.");
|
|
||||||
} else {
|
|
||||||
controller.sendMessage("You are not controlling anyone at the moment");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue