Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.risenphoenix.jnk.Commands;
- import java.util.ArrayList;
- import net.risenphoenix.jnk.ExplodingArrows;
- import net.risenphoenix.jnk.PlayerObject;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- public class CmdPotionsEnable {
- private final String potionList = "Valid Potion Types: BLINDNESS, CONFUSION, FAST_DIGGING, FIRE_RESISTANCE, HARM, " +
- "HEAL, HUNGER, INVISIBILITY, JUMP, NIGHT_VISION, POISON, REGENERATION, SLOW, SLOW_DIGGING, SPEED, " +
- "WATER_BREATHING, WEAKNESS, WITHER";
- public CmdPotionsEnable(CommandSender sender, String[] args) {
- execute(sender, args);
- }
- private void execute(CommandSender sender, String[] args) {
- PlayerObject po = ExplodingArrows.instance.getPlayerManager().getPlayerObject((Player) sender);
- if (args.length == 1) {
- if (po != null) {
- ExplodingArrows.tellSender(sender, "Potion Arrows set to: " + po.togglePotionArrows());
- clearConflictions(po);
- po.setEnabled(true);
- }
- return;
- }
- if (args.length == 2) {
- try {
- Integer value = Integer.parseInt(args[1]);
- if (value < ExplodingArrows.instance.getConfigurationManager().maxPotionTime && !sender.hasPermission("explodingarrows.potiontime.override") && !sender.isOp()) {
- value = ExplodingArrows.instance.getConfigurationManager().maxPotionTime;
- } else if (value < 1) {
- value = 1;
- }
- po.setPotionTime(value);
- ExplodingArrows.tellSender(sender, "Potion duration set to: " + args[1]);
- if (!po.usingPotionArrows()) po.togglePotionArrows();
- clearConflictions(po);
- po.setEnabled(true);
- } catch (NumberFormatException e) {
- if (isValidPotionType(args[1])) {
- if (ExplodingArrows.instance.getConfigurationManager().isAllowedPotion(args[1]) || sender.hasPermission("explodingarrows.potionblacklist.override") || sender.isOp()) {
- po.setPotionEffects(new String[]{ args[1].toUpperCase() });
- ExplodingArrows.tellSender(sender, "Potion Type set to: " + args[1].toUpperCase());
- if (!po.usingPotionArrows()) po.togglePotionArrows();
- clearConflictions(po);
- po.setEnabled(true);
- } else {
- ExplodingArrows.tellSender(sender, "You may not use that potion type.");
- }
- } else {
- ExplodingArrows.tellSender(sender, "That is not a valid integer or potion type");
- ExplodingArrows.tellSender(sender, potionList);
- }
- }
- return;
- }
- if (args.length >= 3) {
- ArrayList<String> effects = new ArrayList<String>();
- if (ExplodingArrows.instance.getConfigurationManager().allowMultiPotions) {
- if (sender.hasPermission("explodingarrows.multiplepotions")) {
- try {
- Integer value = Integer.parseInt(args[1]);
- if (value < ExplodingArrows.instance.getConfigurationManager().maxPotionTime && !sender.hasPermission("explodingarrows.potiontime.override") && !sender.isOp()) {
- value = ExplodingArrows.instance.getConfigurationManager().maxPotionTime;
- } else if (value < 1) {
- value = 1;
- }
- po.setPotionTime(value);
- ExplodingArrows.tellSender(sender, "Potion duration set to: " + args[1]);
- if (!po.usingPotionArrows()) po.togglePotionArrows();
- clearConflictions(po);
- po.setEnabled(true);
- } catch (NumberFormatException e) {
- if (isValidPotionType(args[1])) {
- if (ExplodingArrows.instance.getConfigurationManager().isAllowedPotion(args[1]) || sender.hasPermission("explodingarrows.potionblacklist.override") || sender.isOp()) {
- effects.add(args[1].toUpperCase());
- }
- } else {
- ExplodingArrows.tellSender(sender, "That is not a valid integer or potion type");
- ExplodingArrows.tellSender(sender, potionList);
- return;
- }
- }
- for (int i = 2; i < args.length; i++) {
- if (isValidPotionType(args[i]) && (ExplodingArrows.instance.getConfigurationManager().isAllowedPotion(args[i]) ||
- sender.hasPermission("explodingarrows.potionblacklist.override") || sender.isOp())) effects.add(args[i].toUpperCase());
- }
- String[] effectsFinal = new String[effects.size()];
- effectsFinal = effects.toArray(effectsFinal);
- po.setPotionEffects(effectsFinal);
- StringBuilder sb = new StringBuilder();
- sb.append("Potion types set to: ");
- for (int i = 0; i < effects.size(); i++) {
- sb.append(effects.get(i));
- if (i < effects.size() - 1) sb.append(", ");
- }
- ExplodingArrows.tellSender(sender, sb.toString());
- if (!po.usingPotionArrows()) {
- po.togglePotionArrows();
- clearConflictions(po);
- }
- po.setEnabled(true);
- return;
- } else {
- ExplodingArrows.tellSender(sender, "You may not use multiple potions at once");
- }
- } else {
- ExplodingArrows.tellSender(sender, "Multi-potion arrows are not enabled on your server");
- }
- }
- }
- private boolean isValidPotionType(String arg) {
- return (arg.equalsIgnoreCase("BLINDNESS") || arg.equalsIgnoreCase("CONFUSION") || arg.equalsIgnoreCase("FAST_DIGGING") ||
- arg.equalsIgnoreCase("FIRE_RESISTANCE") || arg.equalsIgnoreCase("HARM") || arg.equalsIgnoreCase("HEAL") ||
- arg.equalsIgnoreCase("HUNGER") || arg.equalsIgnoreCase("INVISIBILITY") || arg.equalsIgnoreCase("JUMP") ||
- arg.equalsIgnoreCase("NIGHT_VISION") || arg.equalsIgnoreCase("POISON") || arg.equalsIgnoreCase("REGENERATION") ||
- arg.equalsIgnoreCase("SLOW") || arg.equalsIgnoreCase("SLOW_DIGGING") || arg.equalsIgnoreCase("SPEED") ||
- arg.equalsIgnoreCase("WATER_BREATHING") || arg.equalsIgnoreCase("WEAKNESS") || arg.equalsIgnoreCase("WITHER")) ? true : false;
- }
- private void clearConflictions(PlayerObject po) {
- po.setFireArrows(false);
- po.setFireworkArrows(false);
- po.setLightningArrows(false);
- po.setSpawningArrows(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement