Vinetos

Explosive Sheep (Sheepwars)

Jan 3rd, 2016
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.83 KB | None | 0 0
  1. private HashMap<Sheep, Integer> launchedEntities = new HashMap<Sheep, Integer>();
  2.     private HashMap<Integer, Sheep> tasksEntities = new HashMap<Integer, Sheep>();
  3.  
  4.     @EventHandler
  5.     public void listen(PlayerInteractEvent e){
  6.         Player p = e.getPlayer();
  7.         if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
  8.             if(e.getItem() == null)return;
  9.             if(e.getItem().getType() != Material.WOOL || e.getItem().getItemMeta() == null || !e.getItem().getItemMeta().getDisplayName().contains("Mouton Explosif")) return;
  10.  
  11.             Sheep s = (Sheep) p.getWorld().spawnEntity(p.getLocation(), EntityType.SHEEP);
  12.             Vector v = new Vector(p.getLocation().getDirection().getX(), p.getLocation().getDirection().getY(), p.getLocation().getDirection().getZ());
  13.             v.multiply(5);
  14.             s.setVelocity(v);
  15.             s.setColor(DyeColor.RED);
  16.             s.setCustomName("§cMouton Explosif");
  17.  
  18.             int cooldown = 6;//Temps avant l'explosion
  19.             launchedEntities.put(s, cooldown);
  20.             launchTask(s);
  21.         }
  22.     }
  23.  
  24.     private void launchTask(final Sheep s){
  25.         new BukkitRunnable(){
  26.             @Override
  27.             public void run() {
  28.                 if(!tasksEntities.containsKey(this.getTaskId())){
  29.                     tasksEntities.put(this.getTaskId(), s);
  30.                 }
  31.                 Sheep s = tasksEntities.get(this.getTaskId());
  32.                 int cooldown = launchedEntities.get(s);
  33.                 cooldown--;
  34.                 switch (cooldown){
  35.                     case 0://Explosion
  36.                         s.setColor(DyeColor.RED);
  37.                         tasksEntities.remove(this.getTaskId());
  38.                         s.getWorld().createExplosion(s.getLocation(), 4F);//Creation de l'explosion
  39.                         s.remove();//On enlève le mouton
  40.                         this.cancel();
  41.                         break;
  42.                     case 1:
  43.                         s.setColor(DyeColor.WHITE);
  44.                         break;
  45.                     case 2:
  46.                         s.setColor(DyeColor.RED);
  47.                         break;
  48.                     case 3:
  49.                         s.setColor(DyeColor.WHITE);
  50.                         break;
  51.                     case 4:
  52.                         s.setColor(DyeColor.RED);
  53.                         break;
  54.                     case 5:
  55.                         s.setColor(DyeColor.WHITE);
  56.                         break;
  57.                     default:
  58.                         break;
  59.                 }
  60.                 launchedEntities.remove(s);
  61.                 if(cooldown != 0){
  62.                     launchedEntities.put(s, cooldown);
  63.                 }
  64.             }
  65.         }.runTaskTimer(Bukkit.getPluginManager().getPlugin("SheepWars"), 0, 20);
  66.     }
Advertisement
Add Comment
Please, Sign In to add comment