potions = potions.substring(0, potions.length() - 2);
sender.sendMessageToPlayer("Potion effects [name (" + FontColour.AQUA + "ID" + FontColour.WHITE + ")]: ");
sender.sendMessageToPlayer(potions);
}
if (params.size() < 2) {
throw new CommandException("Not enough parameters.");
}
// Gets the specified potion
String args[] = ((String)params.get(1)).split(" ");
Integer id = null;
try {
id = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
id = Potion.getPotions().get(args[0].toLowerCase());
}
if (id == null && !(args[0].equalsIgnoreCase("all"))) {
throw new CommandException("Could not find specified effect.");
}
if (id != null && id < 1) {
throw new CommandException("Invalid effect specified.");
}
Player player = super.getSenderAsPlayer(sender);
// Removes the specified effect
if (((String)params.get(0)).equalsIgnoreCase("remove")) {
if (id == null) {
player.removeAllPotionEffects();
} else {
player.removePotionEffect(id);
}
// Adds the specified effect
} else if (((String)params.get(0)).equalsIgnoreCase("add")) {
int duration = 1;
int strength = 1;
if (args.length > 1) {
try {
duration = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
throw new CommandException("Could not parse duration argument.");
}
}
if (args.length > 2) {
try {
strength = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
throw new CommandException("Could not parse strength argument.");
}
}
if (id == null) {
for (Integer i : Potion.getPotions().values()) {
player.addPotionEffect(i, duration * 20, strength);
}
} else {
player.addPotionEffect(id, duration * 20, strength);
}
} else {
throw new CommandException("Invalid argument specified.");
}
}