Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. private void onItemRightClick(PlayerRightClickEvent e) {
  2.         Player p = e.getPlayer();
  3.         Vector dir = p.getEyeLocation().getDirection();
  4.         time = System.currentTimeMillis();
  5.         p.setItemInHand(new ItemStack(Material.AIR));
  6.  
  7.         ArmorStand as = p.getWorld().spawn(p.getLocation().add(dir), ArmorStand.class);
  8.  
  9.         as.getEquipment().setHelmet(new ItemStack(Material.DIAMOND_SWORD));
  10.         as.setVisible(false);
  11.         as.setCanPickupItems(false);
  12.         as.setGravity(false);
  13.  
  14.         loop = Bukkit.getScheduler().runTaskTimer(NewBeginnings.getInstance(),
  15.             () -> excecute(as,dir,p), 1 ,1).getTaskId();
  16.  
  17.     }
  18.  
  19.     private void excecute(ArmorStand as, Vector dir, Player p) {
  20.         as.teleport(as.getLocation().add(dir));
  21.         if (as.getLocation().add(dir).getBlock().getType() != Material.AIR) {
  22.             entities = as.getNearbyEntities(2,2,2);
  23.             for (Entity entity : entities) {
  24.                 if (entity instanceof LivingEntity) {
  25.                     livingEntity = (LivingEntity) entity;
  26.                     if (livingEntity.getHealth() > 7) {
  27.                         livingEntity.setHealth(livingEntity.getHealth() - 7);
  28.                     } else {
  29.                         livingEntity.setHealth(0);
  30.                     }
  31.                 }
  32.             }
  33.             as.remove();
  34.             p.setItemInHand(ExtraItemStack.MYTHRIL_BLADE_STACK);
  35.             Bukkit.getScheduler().cancelTask(loop);
  36.         } else if ((time + 1500) >= System.currentTimeMillis()) {
  37.             as.remove();
  38.             p.setItemInHand(ExtraItemStack.MYTHRIL_BLADE_STACK);
  39.             Bukkit.getScheduler().cancelTask(loop);
  40.         }
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement