Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBomber.java

212 lines
5.1 KiB
Java
Raw Normal View History

2013-08-27 17:14:08 +02:00
package nautilus.game.arcade.kit.perks;
2014-08-18 22:41:16 +02:00
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.*;
2014-11-18 01:09:58 +01:00
import org.bukkit.metadata.FixedMetadataValue;
2014-08-18 22:41:16 +02:00
import java.util.*;
2013-08-27 17:14:08 +02:00
public class PerkBomber extends Perk
{
2014-08-18 22:41:16 +02:00
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;
2014-08-20 03:16:28 +02:00
public BomberExplodeDiamondBlock(Player who, Block block)
2014-08-18 22:41:16 +02:00
{
super(who);
_block = block;
}
public Block getBlock()
{
return _block;
}
}
2013-08-27 17:14:08 +02:00
private HashMap<Entity, Player> _tntMap = new HashMap<Entity, Player>();
2014-08-18 22:41:16 +02:00
2013-08-27 17:14:08 +02:00
private int _spawnRate;
private int _max;
private int _fuse;
2013-11-14 06:28:29 +01:00
2014-08-18 22:41:16 +02:00
public PerkBomber(int spawnRate, int max, int fuse)
2013-08-27 17:14:08 +02:00
{
2014-08-18 22:41:16 +02:00
super("Bomber", new String[]
2013-08-27 17:14:08 +02:00
{
2014-08-18 22:41:16 +02:00
C.cGray + "Receive 1 TNT every " + spawnRate + " seconds. Maximum of " + max + ".",
C.cYellow + "Click" + C.cGray + " with TNT to " + C.cGreen + "Throw TNT"
2013-08-27 17:14:08 +02:00
});
2014-08-18 22:41:16 +02:00
2013-08-27 17:14:08 +02:00
_spawnRate = spawnRate;
_max = max;
_fuse = fuse;
2013-08-27 17:14:08 +02:00
}
2014-08-18 22:41:16 +02:00
public void Apply(Player player)
2013-08-27 17:14:08 +02:00
{
2014-08-18 22:41:16 +02:00
Recharge.Instance.use(player, GetName(), _spawnRate * 1000, false, false);
2013-08-27 17:14:08 +02:00
}
2014-08-18 22:41:16 +02:00
2013-08-27 17:14:08 +02:00
@EventHandler
public void TNTSpawn(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
for (Player cur : UtilServer.getPlayers())
{
if (!Kit.HasKit(cur))
continue;
2014-08-18 22:41:16 +02:00
2013-08-27 17:14:08 +02:00
if (!Manager.GetGame().IsAlive(cur))
continue;
2014-08-18 22:41:16 +02:00
if (!Recharge.Instance.use(cur, GetName(), _spawnRate * 1000, false, false))
2013-08-27 17:14:08 +02:00
continue;
2014-08-18 22:41:16 +02:00
if (UtilInv.contains(cur, Material.TNT, (byte) 0, _max))
2013-08-27 17:14:08 +02:00
continue;
//Add
2014-08-18 22:41:16 +02:00
cur.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.TNT, (byte) 0, 1, F.item("Throwing TNT")));
2013-08-27 17:14:08 +02:00
cur.playSound(cur.getLocation(), Sound.ITEM_PICKUP, 2f, 1f);
}
}
@EventHandler
public void TNTDrop(PlayerDropItemEvent event)
{
2013-08-31 05:15:16 +02:00
if (event.isCancelled())
return;
2014-08-18 22:41:16 +02:00
if (!UtilInv.IsItem(event.getItemDrop().getItemStack(), Material.TNT, (byte) 0))
2013-08-27 17:14:08 +02:00
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)
2014-08-18 22:41:16 +02:00
{
2013-08-27 17:14:08 +02:00
HashSet<org.bukkit.inventory.ItemStack> remove = new HashSet<org.bukkit.inventory.ItemStack>();
for (org.bukkit.inventory.ItemStack item : event.getDrops())
2014-08-18 22:41:16 +02:00
if (UtilInv.IsItem(item, Material.TNT, (byte) 0))
2013-08-27 17:14:08 +02:00
remove.add(item);
for (org.bukkit.inventory.ItemStack item : remove)
event.getDrops().remove(item);
}
@EventHandler
public void TNTInvClick(InventoryClickEvent event)
{
2014-08-18 22:41:16 +02:00
UtilInv.DisallowMovementOf(event, "Throwing TNT", Material.TNT, (byte) 0, true);
2013-08-27 17:14:08 +02:00
}
@EventHandler
public void TNTThrow(PlayerInteractEvent event)
{
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK &&
2014-08-18 22:41:16 +02:00
event.getAction() != Action.LEFT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_AIR)
2013-08-27 17:14:08 +02:00
return;
2014-08-18 22:41:16 +02:00
2013-08-27 17:14:08 +02:00
Player player = event.getPlayer();
2014-08-18 22:41:16 +02:00
if (!UtilInv.IsItem(player.getItemInHand(), Material.TNT, (byte) 0))
2013-08-27 17:14:08 +02:00
return;
2014-08-18 22:41:16 +02:00
2013-08-27 17:14:08 +02:00
if (!Kit.HasKit(player))
return;
2014-08-18 22:41:16 +02:00
2013-08-27 17:14:08 +02:00
event.setCancelled(true);
2014-08-18 22:41:16 +02:00
2013-11-14 06:28:29 +01:00
if (!Manager.GetGame().CanThrowTNT(player.getLocation()))
{
//Inform
UtilPlayer.message(event.getPlayer(), F.main(GetName(), "You cannot use " + F.item("Throwing TNT") + " here."));
return;
}
2014-08-18 22:41:16 +02:00
UtilInv.remove(player, Material.TNT, (byte) 0, 1);
2013-08-27 17:14:08 +02:00
UtilInv.Update(player);
2014-08-18 22:41:16 +02:00
2013-08-27 17:14:08 +02:00
TNTPrimed tnt = player.getWorld().spawn(player.getEyeLocation().add(player.getLocation().getDirection()), TNTPrimed.class);
2014-08-18 22:41:16 +02:00
if (_fuse != -1)
tnt.setFuseTicks(_fuse);
2014-08-18 22:41:16 +02:00
2013-08-27 17:14:08 +02:00
UtilAction.velocity(tnt, player.getLocation().getDirection(), 0.5, false, 0, 0.1, 10, false);
2014-08-18 22:41:16 +02:00
tnt.setMetadata("owner", new FixedMetadataValue(Manager.getPlugin(), player.getUniqueId()));
2014-11-18 01:09:58 +01:00
2013-08-27 17:14:08 +02:00
_tntMap.put(tnt, player);
}
2014-08-18 22:41:16 +02:00
2013-08-27 17:14:08 +02:00
@EventHandler
public void ExplosionPrime(ExplosionPrimeEvent event)
{
2014-10-27 23:09:23 +01:00
Player player = _tntMap.get(event.getEntity());
2014-08-18 22:41:16 +02:00
if (player != null)
2013-08-27 17:14:08 +02:00
{
2014-08-18 22:41:16 +02:00
for (Player other : UtilPlayer.getNearby(event.getEntity().getLocation(), 14))
{
Manager.GetCondition().Factory().Explosion("Throwing TNT", other, player, 50, 0.1, false, false);
}
}
}
2014-10-27 23:09:23 +01:00
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
2014-08-18 22:41:16 +02:00
public void onEntityExplode(EntityExplodeEvent event)
{
Player player = _tntMap.remove(event.getEntity());
if (player != null)
{
for (Iterator<Block> it = event.blockList().iterator(); it.hasNext(); )
{
Block block = it.next();
if (block.getType() == Material.DIAMOND_ORE)
{
2014-10-27 23:09:23 +01:00
Bukkit.getPluginManager().callEvent(new BomberExplodeDiamondBlock(player, block));
block.breakNaturally();
2014-08-18 22:41:16 +02:00
it.remove();
}
}
2013-08-27 17:14:08 +02:00
}
}
}