package nautilus.game.arcade.kit.perks; import mineplex.core.common.util.*; import mineplex.core.itemstack.*; import mineplex.core.recharge.*; import mineplex.core.updater.*; import mineplex.core.updater.event.*; import nautilus.game.arcade.kit.*; import org.bukkit.*; import org.bukkit.block.*; import org.bukkit.entity.*; import org.bukkit.event.*; import org.bukkit.event.block.*; import org.bukkit.event.entity.*; import org.bukkit.event.inventory.*; import org.bukkit.event.player.*; import java.util.*; public class PerkBomber extends Perk { public static class BomberExplodeDiamondBlock extends PlayerEvent { private static final HandlerList handlers = new HandlerList(); public static HandlerList getHandlerList() { return handlers; } @Override public HandlerList getHandlers() { return getHandlerList(); } private final Block _block; public BomberExplodeEntityEvent(Player who, Block block) { super(who); _block = block; } public Block getBlock() { return _block; } } private HashMap _tntMap = new HashMap(); private int _spawnRate; private int _max; private int _fuse; public PerkBomber(int spawnRate, int max, int fuse) { super("Bomber", new String[] { C.cGray + "Receive 1 TNT every " + spawnRate + " seconds. Maximum of " + max + ".", C.cYellow + "Click" + C.cGray + " with TNT to " + C.cGreen + "Throw TNT" }); _spawnRate = spawnRate; _max = max; _fuse = fuse; } public void Apply(Player player) { Recharge.Instance.use(player, GetName(), _spawnRate * 1000, false, false); } @EventHandler public void TNTSpawn(UpdateEvent event) { if (event.getType() != UpdateType.FAST) return; for (Player cur : UtilServer.getPlayers()) { if (!Kit.HasKit(cur)) continue; if (!Manager.GetGame().IsAlive(cur)) continue; if (!Recharge.Instance.use(cur, GetName(), _spawnRate * 1000, false, false)) continue; if (UtilInv.contains(cur, Material.TNT, (byte) 0, _max)) continue; //Add cur.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.TNT, (byte) 0, 1, F.item("Throwing TNT"))); cur.playSound(cur.getLocation(), Sound.ITEM_PICKUP, 2f, 1f); } } @EventHandler public void TNTDrop(PlayerDropItemEvent event) { if (event.isCancelled()) return; if (!UtilInv.IsItem(event.getItemDrop().getItemStack(), Material.TNT, (byte) 0)) return; //Cancel event.setCancelled(true); //Inform UtilPlayer.message(event.getPlayer(), F.main(GetName(), "You cannot drop " + F.item("Throwing TNT") + ".")); } @EventHandler public void TNTDeathRemove(PlayerDeathEvent event) { HashSet remove = new HashSet(); for (org.bukkit.inventory.ItemStack item : event.getDrops()) if (UtilInv.IsItem(item, Material.TNT, (byte) 0)) remove.add(item); for (org.bukkit.inventory.ItemStack item : remove) event.getDrops().remove(item); } @EventHandler public void TNTInvClick(InventoryClickEvent event) { UtilInv.DisallowMovementOf(event, "Throwing TNT", Material.TNT, (byte) 0, true); } @EventHandler public void TNTThrow(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_AIR) return; Player player = event.getPlayer(); if (!UtilInv.IsItem(player.getItemInHand(), Material.TNT, (byte) 0)) return; if (!Kit.HasKit(player)) return; event.setCancelled(true); if (!Manager.GetGame().CanThrowTNT(player.getLocation())) { //Inform UtilPlayer.message(event.getPlayer(), F.main(GetName(), "You cannot use " + F.item("Throwing TNT") + " here.")); return; } UtilInv.remove(player, Material.TNT, (byte) 0, 1); UtilInv.Update(player); TNTPrimed tnt = player.getWorld().spawn(player.getEyeLocation().add(player.getLocation().getDirection()), TNTPrimed.class); if (_fuse != -1) tnt.setFuseTicks(_fuse); UtilAction.velocity(tnt, player.getLocation().getDirection(), 0.5, false, 0, 0.1, 10, false); _tntMap.put(tnt, player); } @EventHandler public void ExplosionPrime(ExplosionPrimeEvent event) { Player player = _tntMap.remove(event.getEntity()); if (player != null) { for (Player other : UtilPlayer.getNearby(event.getEntity().getLocation(), 14)) { Manager.GetCondition().Factory().Explosion("Throwing TNT", other, player, 50, 0.1, false, false); } } } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityExplode(EntityExplodeEvent event) { Player player = _tntMap.remove(event.getEntity()); if (player != null) { for (Iterator it = event.blockList().iterator(); it.hasNext(); ) { Block block = it.next(); if (block.getType() == Material.DIAMOND_ORE) { it.remove(); if (Math.random() < event.getYield()) { block.breakNaturally(); Bukkit.getPluginManager().callEvent(new BomberExplodeDiamondBlock(player, block)); } else block.setType(Material.AIR); } } } } }