Advertisement
Jnk1296

CmdPotionsEnable

Aug 8th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.89 KB | None | 0 0
  1. package net.risenphoenix.jnk.Commands;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import net.risenphoenix.jnk.ExplodingArrows;
  6. import net.risenphoenix.jnk.PlayerObject;
  7.  
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.entity.Player;
  10.  
  11. public class CmdPotionsEnable {
  12.  
  13.     private final String potionList = "Valid Potion Types: BLINDNESS, CONFUSION, FAST_DIGGING, FIRE_RESISTANCE, HARM, " +
  14.             "HEAL, HUNGER, INVISIBILITY, JUMP, NIGHT_VISION, POISON, REGENERATION, SLOW, SLOW_DIGGING, SPEED, " +
  15.             "WATER_BREATHING, WEAKNESS, WITHER";
  16.    
  17.     public CmdPotionsEnable(CommandSender sender, String[] args) {
  18.         execute(sender, args);
  19.     }
  20.    
  21.     private void execute(CommandSender sender, String[] args) {
  22.         PlayerObject po = ExplodingArrows.instance.getPlayerManager().getPlayerObject((Player) sender);
  23.        
  24.         if (args.length == 1) {
  25.             if (po != null) {
  26.                 ExplodingArrows.tellSender(sender, "Potion Arrows set to: " + po.togglePotionArrows());
  27.                 clearConflictions(po);
  28.                 po.setEnabled(true);
  29.             }
  30.            
  31.             return;
  32.         }
  33.        
  34.         if (args.length == 2) {
  35.             try {
  36.                 Integer value = Integer.parseInt(args[1]);
  37.                
  38.                 if (value < ExplodingArrows.instance.getConfigurationManager().maxPotionTime && !sender.hasPermission("explodingarrows.potiontime.override") && !sender.isOp()) {
  39.                     value = ExplodingArrows.instance.getConfigurationManager().maxPotionTime;
  40.                 } else if (value < 1) {
  41.                     value = 1;
  42.                 }
  43.                
  44.                 po.setPotionTime(value);
  45.                
  46.                 ExplodingArrows.tellSender(sender, "Potion duration set to: " + args[1]);
  47.                
  48.                 if (!po.usingPotionArrows()) po.togglePotionArrows();
  49.                 clearConflictions(po);
  50.                 po.setEnabled(true);
  51.                
  52.             } catch (NumberFormatException e) {
  53.                 if (isValidPotionType(args[1])) {
  54.                     if (ExplodingArrows.instance.getConfigurationManager().isAllowedPotion(args[1]) || sender.hasPermission("explodingarrows.potionblacklist.override") || sender.isOp()) {
  55.                         po.setPotionEffects(new String[]{ args[1].toUpperCase() });
  56.                         ExplodingArrows.tellSender(sender, "Potion Type set to: " + args[1].toUpperCase());
  57.                         if (!po.usingPotionArrows()) po.togglePotionArrows();
  58.                         clearConflictions(po);
  59.                         po.setEnabled(true);
  60.                     } else {
  61.                         ExplodingArrows.tellSender(sender, "You may not use that potion type.");
  62.                     }
  63.                 } else {
  64.                     ExplodingArrows.tellSender(sender, "That is not a valid integer or potion type");
  65.                     ExplodingArrows.tellSender(sender, potionList);
  66.                 }
  67.             }
  68.            
  69.             return;
  70.         }
  71.        
  72.         if (args.length >= 3) {
  73.             ArrayList<String> effects = new ArrayList<String>();
  74.            
  75.             if (ExplodingArrows.instance.getConfigurationManager().allowMultiPotions) {
  76.                 if (sender.hasPermission("explodingarrows.multiplepotions")) {
  77.                     try {
  78.                         Integer value = Integer.parseInt(args[1]);
  79.                        
  80.                         if (value < ExplodingArrows.instance.getConfigurationManager().maxPotionTime && !sender.hasPermission("explodingarrows.potiontime.override") && !sender.isOp()) {
  81.                             value = ExplodingArrows.instance.getConfigurationManager().maxPotionTime;
  82.                         } else if (value < 1) {
  83.                             value = 1;
  84.                         }
  85.                        
  86.                         po.setPotionTime(value);
  87.                        
  88.                         ExplodingArrows.tellSender(sender, "Potion duration set to: " + args[1]);
  89.                        
  90.                         if (!po.usingPotionArrows()) po.togglePotionArrows();
  91.                         clearConflictions(po);
  92.                         po.setEnabled(true);
  93.                        
  94.                     } catch (NumberFormatException e) {
  95.                         if (isValidPotionType(args[1])) {
  96.                             if (ExplodingArrows.instance.getConfigurationManager().isAllowedPotion(args[1]) || sender.hasPermission("explodingarrows.potionblacklist.override") || sender.isOp()) {
  97.                                 effects.add(args[1].toUpperCase());
  98.                             }
  99.                         } else {
  100.                             ExplodingArrows.tellSender(sender, "That is not a valid integer or potion type");
  101.                             ExplodingArrows.tellSender(sender, potionList);
  102.                             return;
  103.                         }
  104.                     }
  105.                    
  106.                     for (int i = 2; i < args.length; i++) {
  107.                         if (isValidPotionType(args[i]) && (ExplodingArrows.instance.getConfigurationManager().isAllowedPotion(args[i])  ||
  108.                                 sender.hasPermission("explodingarrows.potionblacklist.override") || sender.isOp())) effects.add(args[i].toUpperCase());
  109.                     }
  110.                    
  111.                     String[] effectsFinal = new String[effects.size()];
  112.                     effectsFinal = effects.toArray(effectsFinal);
  113.                     po.setPotionEffects(effectsFinal);
  114.                    
  115.                     StringBuilder sb = new StringBuilder();
  116.                     sb.append("Potion types set to: ");
  117.                    
  118.                     for (int i = 0; i < effects.size(); i++) {
  119.                         sb.append(effects.get(i));
  120.                        
  121.                         if (i < effects.size() - 1) sb.append(", ");
  122.                     }
  123.                    
  124.                     ExplodingArrows.tellSender(sender, sb.toString());
  125.                     if (!po.usingPotionArrows()) {
  126.                         po.togglePotionArrows();
  127.                         clearConflictions(po);
  128.                     }
  129.                    
  130.                     po.setEnabled(true);
  131.                    
  132.                     return;
  133.                 } else {
  134.                     ExplodingArrows.tellSender(sender, "You may not use multiple potions at once");
  135.                 }
  136.             } else {
  137.                 ExplodingArrows.tellSender(sender, "Multi-potion arrows are not enabled on your server");
  138.             }
  139.         }
  140.     }
  141.    
  142.     private boolean isValidPotionType(String arg) {
  143.         return (arg.equalsIgnoreCase("BLINDNESS") || arg.equalsIgnoreCase("CONFUSION") || arg.equalsIgnoreCase("FAST_DIGGING") ||
  144.                 arg.equalsIgnoreCase("FIRE_RESISTANCE") || arg.equalsIgnoreCase("HARM") || arg.equalsIgnoreCase("HEAL") ||
  145.                 arg.equalsIgnoreCase("HUNGER") || arg.equalsIgnoreCase("INVISIBILITY") || arg.equalsIgnoreCase("JUMP") ||
  146.                 arg.equalsIgnoreCase("NIGHT_VISION") || arg.equalsIgnoreCase("POISON") || arg.equalsIgnoreCase("REGENERATION") ||
  147.                 arg.equalsIgnoreCase("SLOW") || arg.equalsIgnoreCase("SLOW_DIGGING") || arg.equalsIgnoreCase("SPEED") ||
  148.                 arg.equalsIgnoreCase("WATER_BREATHING") || arg.equalsIgnoreCase("WEAKNESS") || arg.equalsIgnoreCase("WITHER")) ? true : false;
  149.     }
  150.    
  151.     private void clearConflictions(PlayerObject po) {
  152.         po.setFireArrows(false);
  153.         po.setFireworkArrows(false);
  154.         po.setLightningArrows(false);
  155.         po.setSpawningArrows(false);
  156.     }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement