public void processCommandPlayer(EntityPlayer sender, String[] args)
{
/*
* Get the right zone. If nothing valid is given, defaults to the senders position.
*/
Zone zone = APIRegistry.perms.getZoneAt(new WorldPoint(sender));
if (args.length > 0)
{
if (args[0].equalsIgnoreCase("world"))
{
zone = APIRegistry.perms.getWorldZone(sender.worldObj);
}
if (args[0].equalsIgnoreCase("global"))
{
zone = APIRegistry.perms.getServerZone();
}
// TODO: Identify zones by unique names
// if (APIRegistry.perms.doesZoneExist(args[0]))
// {
// zone = APIRegistry.perms.getZone(args[0]);
// }
}
/*
* Need to make a new one?
*/
AutoPromote ap = AutoPromoteManager.instance().map.get(zone.toString());
if (ap == null)
{
AutoPromoteManager.instance().map.put(zone.getId(), new AutoPromote(zone.getId(), false));
ap = AutoPromoteManager.instance().map.get(zone.toString());
}
/*
* Nope, View the existing one?
*/
if (args.length == 0 || args.length == 1 || args[1].equalsIgnoreCase("get"))
{
String header = "--- AutoPromote for: " + ap.getZone() + " ---";
OutputHandler.chatNotification(sender, header);
OutputHandler.chatNotification(sender, "Enabled: " + (ap.isEnabled() ? EnumChatFormatting.GREEN : EnumChatFormatting.RED) + ap.isEnabled());
OutputHandler.chatNotification(sender, "Promotion times: ");
for (String i : ap.getPromoteList().keySet())
{
OutputHandler.chatNotification(sender, " " + i + " > " + ap.getPromoteList().get(i));
}
StringBuilder footer = new StringBuilder();
for (int i = 3; i < header.length(); i++)
{
footer.append("-");
}
OutputHandler.chatNotification(sender, footer.toString());
return;
}
/*
* Nope, Enable?
*/
if (args[1].equalsIgnoreCase("enable"))
{
if (ap.isEnabled())
{
OutputHandler.chatWarning(sender, "AutoPromote for " + ap.getZone() + " was already enabled.");
}
else
{
ap.setEnabled(true);
OutputHandler.chatConfirmation(sender, "AutoPromote for " + ap.getZone() + " enabled.");
}
}
/*
* Nope, Disable?
*/
if (args[1].equalsIgnoreCase("disable"))
{
if (!ap.isEnabled())
{
OutputHandler.chatWarning(sender, "AutoPromote for " + ap.getZone() + " was already disabled.");
}
else
{
ap.setEnabled(false);
OutputHandler.chatConfirmation(sender, "AutoPromote for " + ap.getZone() + " disabled.");
}
}
/*
* Nope, Edit?
*/
if (args[1].equalsIgnoreCase("edit"))
{
if (args.length == 2)
{
OutputHandler.chatError(sender, "Available options: 'del', 'add'");
}
else if (args[2].equalsIgnoreCase("del") || args[2].equalsIgnoreCase("delete"))
{
if (args.length == 4)
{
int i = parseInt(sender, args[3]);
if (ap.getPromoteList().containsKey(i))
{
String group = ap.getPromoteList().remove(i);
OutputHandler.chatConfirmation(sender, "You have removed " + i + ":" + group + " from the list.");
}
else
{
OutputHandler.chatError(sender, args[3] + " is not a number in the list.");
}
}
else
{
OutputHandler.chatError(sender, "You have to specify a number to remvove from the list.");
}
}
else if (args[2].equalsIgnoreCase("add"))
{
if (args.length == 5)
{
int i = parseInt(sender, args[3]);
if (!ap.getPromoteList().containsKey(i))
{
String group = args[4];
if (!APIRegistry.perms.groupExists(group))
{
ap.getPromoteList().put(i + "", group);
OutputHandler.chatConfirmation(sender, "You have added " + i + ":" + group + " to the list.");
}
else
{
OutputHandler.chatError(sender, args[4] + " is not a valid group in " + zone.toString() + ".");
}
}
else
{
OutputHandler.chatError(sender, args[3] + " is already on the list.");