Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.munsin.throwcreeper;
- import net.minecraft.server.v1_8_R3.EntityLiving;
- import net.minecraft.server.v1_8_R3.NBTTagCompound;
- import net.minecraft.server.v1_8_R3.PathfinderGoalMeleeAttack;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreeper;
- import org.bukkit.enchantments.Enchantment;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.entity.ItemMergeEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerPickupItemEvent;
- import org.bukkit.inventory.ItemFlag;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.scheduler.BukkitRunnable;
- public class EventsClass implements Listener {
- private Main plugin = Main.getPlugin(Main.class);
- @EventHandler
- public void throwCreeper(PlayerInteractEvent event) {
- ItemStack item = event.getItem();
- Action action = event.getAction();
- Player player = event.getPlayer();
- Location loc = player.getEyeLocation();
- loc.add(player.getLocation().getDirection());
- if (item == null) {
- return;
- }
- if(item.getItemMeta() == null){
- return;
- }
- if(item.getItemMeta().getLore() == null){
- return;
- }
- ItemStack CreeperEgg = new ItemStack(Material.MONSTER_EGG, (byte)50);
- if (item.getItemMeta().getLore().equals(CreeperEgg.getItemMeta().getLore())){
- if(action.equals(Action.RIGHT_CLICK_BLOCK)){
- ItemStack hand = player.getItemInHand();
- int amount = hand.getAmount();
- if (amount > 1) {
- hand.setAmount(amount - 1);
- } else {
- player.setItemInHand(new ItemStack(Material.AIR));
- }
- } else {
- event.setCancelled(true);
- }
- }
- ItemStack egg = Utils.invItem(Material.MONSTER_EGG, ChatColor.LIGHT_PURPLE.toString() + ChatColor.BOLD.toString()
- + "&b&lThrowable Creeper Egg", 1, 50, Utils.formatLore("&1Right click to throw a creeper egg that explodes!"));
- ItemMeta eggMeta = egg.getItemMeta();
- eggMeta.addEnchant(Enchantment.ARROW_DAMAGE, 1, true);
- eggMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
- egg.setItemMeta(eggMeta);
- if (item.getItemMeta().getLore().equals(egg.getItemMeta().getLore())) {
- if(action.equals(Action.RIGHT_CLICK_BLOCK)){
- event.setCancelled(true);
- }
- }
- if (item.getItemMeta().getLore().equals(egg.getItemMeta().getLore())) {
- if (action.equals(Action.RIGHT_CLICK_AIR) || action.equals(Action.RIGHT_CLICK_BLOCK)) {
- egg = Utils.invItem(Material.MONSTER_EGG, ChatColor.LIGHT_PURPLE.toString() + ChatColor.BOLD.toString()
- + "&b&lThrowable Creeper Egg", 1, 50, Utils.formatLore("&1Right click to throw a creeper egg that explodes!"));
- ItemStack hand = player.getItemInHand();
- int amount = hand.getAmount();
- if (amount > 1) {
- hand.setAmount(amount - 1);
- } else {
- player.setItemInHand(new ItemStack(Material.AIR));
- }
- Entity drop = loc.getWorld().dropItemNaturally(loc, egg);
- drop.setVelocity(loc.getDirection().multiply(1.8f));
- new BukkitRunnable() {
- @Override
- public void run() {
- CraftCreeper e = drop.getWorld().spawn(drop.getLocation(), CraftCreeper.class);
- net.minecraft.server.v1_8_R3.EntityCreeper nms = e.getHandle();
- NBTTagCompound nbttag = new NBTTagCompound();
- nms.c(nbttag);
- nbttag.setInt("Fuse", 0);
- EntityLiving livingcreeper = nms;
- livingcreeper.a(nbttag);
- nms.goalSelector.a(2, new PathfinderGoalMeleeAttack(nms, 1.0D, false));
- }
- }.runTaskLater(plugin, 20);
- }
- }
- }
- @EventHandler
- public void cancelEggPickup(PlayerPickupItemEvent event){
- ItemStack item = event.getItem().getItemStack();
- ItemStack egg = Utils.invItem(Material.MONSTER_EGG, ChatColor.LIGHT_PURPLE.toString() + ChatColor.BOLD.toString()
- + "&b&lThrowable Creeper Egg", 1, 50, Utils.formatLore("&1Right click to throw a creeper egg that explodes!"));
- if(item.equals(egg)){
- event.setCancelled(true);
- }
- }
- @EventHandler
- public void cancelMerge(ItemMergeEvent event){
- ItemStack egg = Utils.invItem(Material.MONSTER_EGG, ChatColor.LIGHT_PURPLE.toString() + ChatColor.BOLD.toString()
- + "&b&lThrowable Creeper Egg", 1, 50, Utils.formatLore("&1Right click to throw a creeper egg that explodes!"));
- if(event.getTarget().getItemStack().equals(egg) || event.getEntity().getItemStack().equals(egg)){
- event.setCancelled(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement