use of com.elmakers.mine.bukkit.wand.WandCleanupRunnable in project MagicPlugin by elBukkit.
the class MagicCommandExecutor method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0) {
if (!api.hasPermission(sender, "Magic.commands.magic")) {
sendNoPermission(sender);
return true;
}
sender.sendMessage("Magic " + getMagicVersion());
sender.sendMessage("Use /magic help for more info");
return true;
}
String subCommand = args[0];
if (sender instanceof Player) {
if (!api.hasPermission(sender, "Magic.commands.magic." + subCommand)) {
sendNoPermission(sender);
return true;
}
}
if (subCommand.equalsIgnoreCase("help")) {
sender.sendMessage(ChatColor.AQUA + "See help information for Magic commands with /help <command>");
sender.sendMessage("wand Create or modify wand items");
sender.sendMessage("mage Inspect or modify mage data");
sender.sendMessage("mconfig Configure Magic in-game");
sender.sendMessage("magic Reload configs and other admin functions");
sender.sendMessage("mitem Create or modify vanilla items");
sender.sendMessage("mmob Spwan vanilla or magic mobs");
sender.sendMessage("cast Cast spells and test parameter changes");
sender.sendMessage("mtrait Create or modify Magic Citizens NPCs");
sender.sendMessage("mmap Create maps from images or players");
sender.sendMessage("castp Cast spells as another player");
sender.sendMessage("wandp Modify other players' wands");
sender.sendMessage("mskills Show the skill selector");
return true;
}
if (subCommand.equalsIgnoreCase("rpcheck")) {
api.getController().checkResourcePack(sender);
return true;
}
if (subCommand.equalsIgnoreCase("rpsend")) {
api.getController().sendResourcePackToAllPlayers(sender);
return true;
}
if (subCommand.equalsIgnoreCase("save")) {
api.save();
sender.sendMessage("Data saved.");
return true;
}
if (subCommand.equalsIgnoreCase("load") || subCommand.equalsIgnoreCase("reload")) {
api.reload(sender);
return true;
}
if (subCommand.equalsIgnoreCase("clearcache")) {
api.clearCache();
sender.sendMessage("Image map cache cleared.");
return true;
}
if (subCommand.equalsIgnoreCase("commit")) {
if (api.commit()) {
sender.sendMessage("All changes committed");
} else {
sender.sendMessage("Nothing to commit");
}
return true;
}
if (subCommand.equalsIgnoreCase("give") || subCommand.equalsIgnoreCase("sell")) {
Player player = null;
int argStart = 1;
if (sender instanceof Player) {
if (args.length > 1) {
player = DeprecatedUtils.getPlayer(args[1]);
}
if (player == null) {
player = (Player) sender;
} else {
argStart = 2;
}
} else {
if (args.length <= 1) {
sender.sendMessage("Must specify a player name");
return true;
}
argStart = 2;
player = DeprecatedUtils.getPlayer(args[1]);
if (player == null) {
sender.sendMessage("Can't find player " + args[1]);
return true;
}
if (!player.isOnline()) {
sender.sendMessage("Player " + args[1] + " is not online");
return true;
}
}
String[] args2 = Arrays.copyOfRange(args, argStart, args.length);
if (subCommand.equalsIgnoreCase("give") || subCommand.equalsIgnoreCase("sell")) {
return onMagicGive(sender, player, subCommand, args2);
}
}
if (subCommand.equalsIgnoreCase("worth")) {
if (!(sender instanceof Player)) {
sender.sendMessage("This command may only be used in-game");
return true;
}
Player player = (Player) sender;
ItemStack item = player.getInventory().getItemInMainHand();
if (item == null || item.getType() == Material.AIR) {
player.sendMessage("You must be holding an item");
return true;
}
showWorth(player, item);
return true;
}
if (subCommand.equalsIgnoreCase("list")) {
return onMagicList(sender, subCommand, args);
}
if (subCommand.equalsIgnoreCase("cancel")) {
checkRunningTask();
if (runningTask != null) {
runningTask.cancel();
runningTask = null;
sender.sendMessage("Job cancelled");
}
int stoppedPending = 0;
for (Mage mage : controller.getMages()) {
while (mage.cancelPending() != null) stoppedPending++;
}
sender.sendMessage("Stopped " + stoppedPending + " pending spell casts");
return true;
}
if (subCommand.equalsIgnoreCase("clean")) {
checkRunningTask();
if (runningTask != null) {
sender.sendMessage("Cancel current job first");
return true;
}
World world = null;
String owner = null;
if (args.length > 1) {
owner = args[1];
}
if (sender instanceof Player) {
world = ((Player) sender).getWorld();
} else {
if (args.length > 2) {
String worldName = args[2];
world = Bukkit.getWorld(worldName);
}
}
boolean check = false;
if (owner != null && owner.equals("check")) {
check = true;
owner = "ALL";
}
String description = check ? "Checking for" : "Cleaning up";
String ownerName = owner == null ? "(Unowned)" : owner;
if (world == null) {
sender.sendMessage(description + " lost wands in all worlds for owner: " + ownerName);
} else if (ownerName.equals("ALL")) {
sender.sendMessage(description + " lost wands in world '" + world.getName() + "' for ALL owners");
} else {
sender.sendMessage(description + " lost wands in world '" + world.getName() + "' for owner " + ownerName);
}
runningTask = new WandCleanupRunnable(api, world, owner, check);
runningTask.runTaskTimer(api.getPlugin(), 5, 5);
return true;
}
sender.sendMessage("Unknown magic command: " + subCommand);
return true;
}
Aggregations