|
| 1 | +package me.dabuseck.Tutorial.Events; |
| 2 | + |
| 3 | +import org.bukkit.Location; |
| 4 | +import org.bukkit.Material; |
| 5 | +import org.bukkit.entity.Entity; |
| 6 | +import org.bukkit.entity.Player; |
| 7 | +import org.bukkit.event.EventHandler; |
| 8 | +import org.bukkit.event.Listener; |
| 9 | +import org.bukkit.event.block.Action; |
| 10 | +import org.bukkit.event.player.PlayerInteractEvent; |
| 11 | +import org.bukkit.inventory.ItemStack; |
| 12 | +import org.bukkit.scheduler.BukkitRunnable; |
| 13 | + |
| 14 | +import me.dabuseck.Tutorial.Tutorial; |
| 15 | + |
| 16 | +public class EventsClass implements Listener { |
| 17 | + |
| 18 | +private Tutorial plugin = Tutorial.getPlugin(Tutorial.class); |
| 19 | + |
| 20 | +@EventHandler |
| 21 | +public void grenadeLaunch(PlayerInteractEvent event) { |
| 22 | +ItemStack item = event.getItem(); |
| 23 | +Action action = event.getAction(); |
| 24 | +Player player = event.getPlayer(); |
| 25 | +Location loc = player.getLocation(); |
| 26 | +loc.setY(loc.getY() + 1.5f); |
| 27 | + |
| 28 | +if (item == null) { |
| 29 | +return; |
| 30 | +} |
| 31 | + |
| 32 | +if (action.equals(Action.RIGHT_CLICK_AIR) || action.equals(Action.RIGHT_CLICK_BLOCK)) { |
| 33 | +if (item.getType().equals(Material.DIAMOND)) { |
| 34 | +item.setAmount(item.getAmount() - 1); |
| 35 | +ItemStack bomb = new ItemStack(item.getType(), 1); |
| 36 | +Entity drop = loc.getWorld().dropItemNaturally(loc, bomb); |
| 37 | +drop.setVelocity(loc.getDirection().multiply(2)); |
| 38 | +new BukkitRunnable() { |
| 39 | + |
| 40 | +@Override |
| 41 | +public void run() { |
| 42 | +loc.getWorld().createExplosion(drop.getLocation(), 10, true); |
| 43 | +} |
| 44 | + |
| 45 | +}.runTaskLater(plugin, 40); |
| 46 | +} |
| 47 | +} |
| 48 | +} |
| 49 | + |
| 50 | +} |
0 commit comments