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

109 lines
2.8 KiB
Java
Raw Normal View History

package nautilus.game.arcade.kit.perks;
2015-01-30 01:08:23 +01:00
import java.util.HashMap;
import java.util.HashSet;
2015-01-30 01:08:23 +01:00
import java.util.Iterator;
import org.bukkit.Material;
2015-01-30 01:08:23 +01:00
import org.bukkit.Sound;
import org.bukkit.entity.Item;
2015-01-30 01:08:23 +01:00
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
2015-01-30 01:08:23 +01:00
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.core.common.util.C;
2015-01-30 01:08:23 +01:00
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
2015-01-30 01:08:23 +01:00
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.kit.SmashPerk;
public class PerkDeadlyBones extends SmashPerk
{
2015-01-30 01:08:23 +01:00
private HashMap<Item, Player> _active = new HashMap<Item, Player>();
public PerkDeadlyBones()
{
super("Deadly Bones", new String[]
{
C.cGray + "Drop explosive bones when you take damage."
});
}
@EventHandler
public void damageActivate(CustomDamageEvent event)
{
if (event.IsCancelled())
return;
Player player = event.GetDamageePlayer();
if (player == null)
return;
if (!Kit.HasKit(player))
return;
if (!Recharge.Instance.use(player, GetName(), 400, true, true))
return;
2015-01-30 01:08:23 +01:00
_active.put(player.getWorld().dropItemNaturally(player.getLocation().add(0, 0.5, 0),
ItemStackFactory.Instance.CreateStack(Material.BONE, (byte)0, 1, "Explosive Bone " + System.currentTimeMillis())), player);
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
Iterator<Item> itemIter = _active.keySet().iterator();
while (itemIter.hasNext())
{
Item item = itemIter.next();
//Not Ready
if (item.isValid() && item.getTicksLived() < 60)
continue;
//Effect
UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, item.getLocation(), 0, 0, 0, 0, 1);
item.getWorld().playSound(item.getLocation(), Sound.EXPLODE, 0.8f, 1.4f);
Player player = _active.get(item);
//Damage
HashMap<LivingEntity, Double> targets = UtilEnt.getInRadius(player.getLocation(), 4);
for (LivingEntity cur : targets.keySet())
{
if (cur.equals(player))
continue;
Manager.GetDamage().NewDamageEvent(cur, player, null,
DamageCause.CUSTOM, 4 * targets.get(cur) + 0.5, true, true, false,
player.getName(), GetName());
}
//Remove
item.remove();
itemIter.remove();
}
}
@EventHandler
public void knockback(CustomDamageEvent event)
{
if (event.GetReason() == null || !event.GetReason().contains(GetName()))
return;
2015-01-30 01:08:23 +01:00
event.AddKnockback(GetName(), 3);
}
}