Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.36 KB | None | 0 0
  1. package me.munsin.throwcreeper;
  2.  
  3. import net.minecraft.server.v1_8_R3.EntityLiving;
  4. import net.minecraft.server.v1_8_R3.NBTTagCompound;
  5. import net.minecraft.server.v1_8_R3.PathfinderGoalMeleeAttack;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Location;
  8. import org.bukkit.Material;
  9. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreeper;
  10. import org.bukkit.enchantments.Enchantment;
  11. import org.bukkit.entity.Entity;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.event.EventHandler;
  14. import org.bukkit.event.Listener;
  15. import org.bukkit.event.block.Action;
  16. import org.bukkit.event.entity.ItemMergeEvent;
  17. import org.bukkit.event.player.PlayerInteractEvent;
  18. import org.bukkit.event.player.PlayerPickupItemEvent;
  19. import org.bukkit.inventory.ItemFlag;
  20. import org.bukkit.inventory.ItemStack;
  21. import org.bukkit.inventory.meta.ItemMeta;
  22. import org.bukkit.scheduler.BukkitRunnable;
  23.  
  24.  
  25. public class EventsClass implements Listener {
  26.     private Main plugin = Main.getPlugin(Main.class);
  27.  
  28.     @EventHandler
  29.     public void throwCreeper(PlayerInteractEvent event) {
  30.  
  31.         ItemStack item = event.getItem();
  32.         Action action = event.getAction();
  33.         Player player = event.getPlayer();
  34.         Location loc = player.getEyeLocation();
  35.         loc.add(player.getLocation().getDirection());
  36.  
  37.         if (item == null) {
  38.             return;
  39.         }
  40.  
  41.         if(item.getItemMeta() == null){
  42.             return;
  43.         }
  44.  
  45.         if(item.getItemMeta().getLore() == null){
  46.             return;
  47.         }
  48.  
  49.         ItemStack CreeperEgg = new ItemStack(Material.MONSTER_EGG, (byte)50);
  50.         if (item.getItemMeta().getLore().equals(CreeperEgg.getItemMeta().getLore())){
  51.             if(action.equals(Action.RIGHT_CLICK_BLOCK)){
  52.                 ItemStack hand = player.getItemInHand();
  53.                 int amount = hand.getAmount();
  54.                 if (amount > 1) {
  55.                     hand.setAmount(amount - 1);
  56.                 } else {
  57.                     player.setItemInHand(new ItemStack(Material.AIR));
  58.                 }
  59.             } else {
  60.                 event.setCancelled(true);
  61.             }
  62.         }
  63.  
  64.  
  65.         ItemStack egg = Utils.invItem(Material.MONSTER_EGG, ChatColor.LIGHT_PURPLE.toString() + ChatColor.BOLD.toString()
  66.                 + "&b&lThrowable Creeper Egg", 1, 50, Utils.formatLore("&1Right click to throw a creeper egg that explodes!"));
  67.  
  68.         ItemMeta eggMeta = egg.getItemMeta();
  69.         eggMeta.addEnchant(Enchantment.ARROW_DAMAGE, 1, true);
  70.         eggMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
  71.         egg.setItemMeta(eggMeta);
  72.  
  73.         if (item.getItemMeta().getLore().equals(egg.getItemMeta().getLore())) {
  74.             if(action.equals(Action.RIGHT_CLICK_BLOCK)){
  75.                 event.setCancelled(true);
  76.             }
  77.         }
  78.  
  79.         if (item.getItemMeta().getLore().equals(egg.getItemMeta().getLore())) {
  80.             if (action.equals(Action.RIGHT_CLICK_AIR) || action.equals(Action.RIGHT_CLICK_BLOCK)) {
  81.                 egg = Utils.invItem(Material.MONSTER_EGG, ChatColor.LIGHT_PURPLE.toString() + ChatColor.BOLD.toString()
  82.                         + "&b&lThrowable Creeper Egg", 1, 50, Utils.formatLore("&1Right click to throw a creeper egg that explodes!"));
  83.                 ItemStack hand = player.getItemInHand();
  84.                 int amount = hand.getAmount();
  85.                 if (amount > 1) {
  86.                     hand.setAmount(amount - 1);
  87.                 } else {
  88.                     player.setItemInHand(new ItemStack(Material.AIR));
  89.                 }
  90.                 Entity drop = loc.getWorld().dropItemNaturally(loc, egg);
  91.                 drop.setVelocity(loc.getDirection().multiply(1.8f));
  92.                 new BukkitRunnable() {
  93.                     @Override
  94.                     public void run() {
  95.                         CraftCreeper e = drop.getWorld().spawn(drop.getLocation(), CraftCreeper.class);
  96.                         net.minecraft.server.v1_8_R3.EntityCreeper nms = e.getHandle();
  97.                         NBTTagCompound nbttag = new NBTTagCompound();
  98.                         nms.c(nbttag);
  99.                         nbttag.setInt("Fuse", 0);
  100.                         EntityLiving livingcreeper = nms;
  101.                         livingcreeper.a(nbttag);
  102.                         nms.goalSelector.a(2, new PathfinderGoalMeleeAttack(nms, 1.0D, false));
  103.                     }
  104.                 }.runTaskLater(plugin, 20);
  105.             }
  106.         }
  107.     }
  108.  
  109.     @EventHandler
  110.     public void cancelEggPickup(PlayerPickupItemEvent event){
  111.         ItemStack item = event.getItem().getItemStack();
  112.         ItemStack egg = Utils.invItem(Material.MONSTER_EGG, ChatColor.LIGHT_PURPLE.toString() + ChatColor.BOLD.toString()
  113.                 + "&b&lThrowable Creeper Egg", 1, 50, Utils.formatLore("&1Right click to throw a creeper egg that explodes!"));
  114.  
  115.         if(item.equals(egg)){
  116.             event.setCancelled(true);
  117.         }
  118.     }
  119.  
  120.     @EventHandler
  121.     public void cancelMerge(ItemMergeEvent event){
  122.         ItemStack egg = Utils.invItem(Material.MONSTER_EGG, ChatColor.LIGHT_PURPLE.toString() + ChatColor.BOLD.toString()
  123.                 + "&b&lThrowable Creeper Egg", 1, 50, Utils.formatLore("&1Right click to throw a creeper egg that explodes!"));
  124.  
  125.         if(event.getTarget().getItemStack().equals(egg) || event.getEntity().getItemStack().equals(egg)){
  126.             event.setCancelled(true);
  127.         }
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement