Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.45 KB | None | 0 0
  1. package de.ilurch.main;
  2. import java.util.HashMap;
  3. import java.util.Random;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Color;
  7. import org.bukkit.FireworkEffect;
  8. import org.bukkit.FireworkEffect.Type;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandExecutor;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.entity.Firework;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.inventory.meta.FireworkMeta;
  15.  
  16. public class Commands implements CommandExecutor {
  17.    
  18.     public HashMap<String, Long> cooldowns = new HashMap<String, Long>();
  19.     private Main plugin;
  20.  
  21.     public Commands(Main plugin) {
  22.         this.plugin = plugin;
  23.     }
  24.    
  25.     private Color getColor(int i) {
  26.         Color c = null;
  27.         if (i == 1) {
  28.             c = Color.AQUA;
  29.         }
  30.         if (i == 2) {
  31.             c = Color.BLACK;
  32.         }
  33.         if (i == 3) {
  34.             c = Color.BLUE;
  35.         }
  36.         if (i == 4) {
  37.             c = Color.FUCHSIA;
  38.         }
  39.         if (i == 5) {
  40.             c = Color.GRAY;
  41.         }
  42.         if (i == 6) {
  43.             c = Color.GREEN;
  44.         }
  45.         if (i == 7) {
  46.             c = Color.LIME;
  47.         }
  48.         if (i == 8) {
  49.             c = Color.MAROON;
  50.         }
  51.         if (i == 9) {
  52.             c = Color.NAVY;
  53.         }
  54.         if (i == 10) {
  55.             c = Color.OLIVE;
  56.         }
  57.         if (i == 11) {
  58.             c = Color.ORANGE;
  59.         }
  60.         if (i == 12) {
  61.             c = Color.PURPLE;
  62.         }
  63.         if (i == 13) {
  64.             c = Color.RED;
  65.         }
  66.         if (i == 14) {
  67.             c = Color.SILVER;
  68.         }
  69.         if (i == 15) {
  70.             c = Color.TEAL;
  71.         }
  72.         if (i == 16) {
  73.             c = Color.WHITE;
  74.         }
  75.         if (i == 17) {
  76.             c = Color.YELLOW;
  77.         }
  78.         return c;
  79.     }
  80.    
  81.     @SuppressWarnings("unused")
  82.     @Override
  83.     public boolean onCommand(final CommandSender sender, Command cmd, String label, final String[] args) {
  84.         Player p = null;
  85.         if (sender instanceof Player) {
  86.             p = (Player) sender;
  87.            
  88.             if (p == null) {
  89.                 sender.sendMessage(this.plugin.getConfig().getString("Firework.Message.isConsole"));  // Der CMD sender ist die Console
  90.                 return true;
  91.             } else {
  92.                
  93.                 if (args.length == 0) {
  94.                    
  95.                     if (p.hasPermission("firework.launch")) {
  96.                    
  97.                         if (!p.hasPermission("firework.bypass.cooldown")) {
  98.                             if (cooldowns.containsKey(sender.getName())) {  //Cooldown -
  99.                                 long secondsLeft = ((cooldowns.get(sender.getName())/1000)+this.plugin.getConfig().getInt("FireworkCommand.CooldownTime")) - (System.currentTimeMillis()/1000);
  100.                                 if (secondsLeft>0) {
  101.                                     sender.sendMessage(this.plugin.getConfig().getString("FireworkCommand.Messages.Cooldown") + secondsLeft);
  102.                                     return true;
  103.                                 }
  104.                             }
  105.                             cooldowns.put(sender.getName(), System.currentTimeMillis()); // Cooldown
  106.                         }
  107.                        
  108.                        
  109.                        
  110.                         Firework f = (Firework) p.getWorld().spawn(p.getLocation(), Firework.class);   //command -
  111.                        
  112.                         Random r = new Random();
  113.                         int rt = r.nextInt(5);
  114.                         Type type = Type.BALL;
  115.                         if (rt == 0)
  116.                             type = Type.BALL;
  117.                         if (rt == 1)
  118.                             type = Type.BALL_LARGE;
  119.                         if (rt == 2)
  120.                             type = Type.BURST;
  121.                         if (rt == 3)
  122.                             type = Type.CREEPER;
  123.                         if (rt == 4)
  124.                             type = Type.STAR;
  125.                                
  126.                         int r1i = r.nextInt(17) + 1;
  127.                         int r2i = r.nextInt(17) + 1;
  128.                         Color c1 = getColor(r1i);
  129.                         Color c2 = getColor(r2i);
  130.                              
  131.                         FireworkMeta fm = f.getFireworkMeta();
  132.                         fm.addEffect(FireworkEffect.builder()
  133.                                         .flicker(r.nextBoolean())
  134.                                         .trail(r.nextBoolean())
  135.                                         .with(type)
  136.                                         .withColor(c1)
  137.                                         .withFade(c2)
  138.                                         .build());
  139.                         fm.setPower(1);
  140.                         f.setFireworkMeta(fm);
  141.                         return true;                                    // command
  142.                        
  143.                        
  144.                     } else {
  145.                         p.sendMessage(this.plugin.getConfig().getString("FireworkCommand.Messages.noPermission"));
  146.                         return true;
  147.                     }
  148.                 } else if (args.length == 1) {
  149.                    
  150.                     if (args[0].equalsIgnoreCase("reload")) {
  151.                        
  152.                         this.plugin.reloadConfig();
  153.                         p.sendMessage("§cFirework §3" + this.plugin.getDescription().getVersion() + "§c reloaded");
  154.                        
  155.                     } else if (args[0].equalsIgnoreCase("help")) {                                    // help -
  156.                        
  157.                         p.sendMessage("§6Usage: §r/firework [numberOfFireworks] [speedInTicks]");
  158.                         return true;                                                            //help
  159.                        
  160.                     } else if (p.hasPermission("firework.multiple")) {
  161.                         try {
  162.                            
  163.                             if (args.length == 1 ) {
  164.                                
  165.                                 final int i = Integer.valueOf(args[0]);
  166.                                 if (i <= this.plugin.getConfig().getInt("FireworkCommand.Multiple.MaxFireworks")) {
  167.                                     Bukkit.getScheduler().scheduleSyncRepeatingTask(this.plugin, new Runnable() {
  168.  
  169.                                         @Override
  170.                                         public void run() {
  171.                                             int count = 0;
  172.                                             if (count  < i) {
  173.                                                 Bukkit.dispatchCommand(sender, "spawnfirework");
  174.                                                 count++;
  175.                                             }
  176.                                         }
  177.                                     }, 0, this.plugin.getConfig().getInt("FireworkCommand.Multiple.DefaultSpeedInTicks"));
  178.                                 }
  179.  
  180.                            
  181.                             }
  182.                            
  183.                             if (args.length == 2) {
  184.                                
  185.                                 final int i = Integer.valueOf(args[0]);
  186.                                
  187.                                 if (i <= this.plugin.getConfig().getInt("FireworkCommand.Multiple.MaxFireworks")) {
  188.                                     if (args.length == 1) {
  189.                                        
  190.                                         final int j = Integer.valueOf(args[0]);
  191.                                        
  192.                                         if (j >= this.plugin.getConfig().getInt("FireworkCommand.Multiple.MinSpeedInTicks")) {
  193.                                             if (j <= this.plugin.getConfig().getInt("FireworkCommand.Messages.MaxSpeedInTicks")) {
  194.                                                
  195.                                                 Bukkit.getScheduler().scheduleSyncRepeatingTask(this.plugin, new Runnable() {
  196.  
  197.                                                     @Override
  198.                                                     public void run() {
  199.                                                         int count = 0;
  200.                                                         if (count  < i) {
  201.                                                             Bukkit.dispatchCommand(sender, "spawnfirework");
  202.                                                             count++;
  203.                                                         }
  204.                                                     }
  205.                                                 }, 0, j);
  206.                                                
  207.                                                 return true;
  208.                                             } else {                    //MaxSpeedInTicks
  209.                                                 p.sendMessage(this.plugin.getConfig().getString(this.plugin.getConfig().getString("FireworkCommand.Messages.MaxSpeedInTicks")));
  210.                                                 return true;
  211.                                             }
  212.                                         } else {                        //MinSpeedInTicks
  213.                                             p.sendMessage(this.plugin.getConfig().getString(this.plugin.getConfig().getString("FireworkCommand.Messages.MinSpeedInTicks")));
  214.                                             return true;
  215.                                         }
  216.                                     }
  217.  
  218.                                 } else {
  219.                                     p.sendMessage("FireworkCommand.Messages.MaxFireworks " + this.plugin.getConfig().getInt("FireworkCommand.Multiple.MaxFireworks"));      //MaxFireworks
  220.                                     return true;
  221.                                 }
  222.                                 return true;
  223.    
  224.                                 }
  225.                            
  226.                         } catch (Exception exe) {
  227.                             p.sendMessage(this.plugin.getConfig().getString(this.plugin.getConfig().getString("FireworkCommand.Messages.wrongInt")));
  228.                             return true;
  229.                         }
  230.                        
  231.                     }
  232.                    
  233.                     return true;
  234.                    
  235.                 } else if (args.length > 3) {
  236.                     p.sendMessage("§cToo much arguments!");
  237.                     p.sendMessage("§6Usage: §r/firework [numberOfFireworks] [speedInTicks]");
  238.                     return true;
  239.                 } else if (args.length == 3) {
  240.                     p.sendMessage("§cToo less arguments!");
  241.                     p.sendMessage("§6Usage: §r/firework [numberOfFireworks] [speedInTicks]");
  242.                 }
  243.                 return true;
  244.             }
  245.    
  246.         }
  247.        
  248.         return false;
  249.     }
  250.    
  251.    
  252. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement