2013-09-05 05:55:42 +02:00
|
|
|
package nautilus.game.arcade.kit.perks;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import org.bukkit.Sound;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
|
|
|
|
|
|
import mineplex.core.common.util.C;
|
|
|
|
import mineplex.core.common.util.F;
|
|
|
|
import mineplex.core.common.util.UtilEnt;
|
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
|
|
|
import mineplex.core.common.util.UtilTime;
|
|
|
|
import mineplex.core.disguise.disguises.DisguiseBase;
|
|
|
|
import mineplex.core.disguise.disguises.DisguiseCreeper;
|
|
|
|
import mineplex.core.updater.UpdateType;
|
|
|
|
import mineplex.core.updater.event.UpdateEvent;
|
|
|
|
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
|
|
|
import nautilus.game.arcade.kit.Perk;
|
|
|
|
|
|
|
|
public class PerkCreeperElectricity extends Perk
|
|
|
|
{
|
|
|
|
private HashMap<Player, Long> _active = new HashMap<Player, Long>();
|
|
|
|
|
|
|
|
public PerkCreeperElectricity()
|
|
|
|
{
|
|
|
|
super("Lightning Shield", new String[]
|
|
|
|
{
|
|
|
|
"When hit by a non-melee attack, you gain " + C.cGreen + "Lightning Shield"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Shield(CustomDamageEvent event)
|
|
|
|
{
|
|
|
|
if (event.IsCancelled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.GetCause() == DamageCause.ENTITY_ATTACK)
|
|
|
|
return;
|
|
|
|
|
2013-09-09 10:06:44 +02:00
|
|
|
if (event.GetCause() == DamageCause.FIRE_TICK)
|
|
|
|
return;
|
|
|
|
|
2013-09-05 05:55:42 +02:00
|
|
|
Player damagee = event.GetDamageePlayer();
|
|
|
|
if (damagee == null) return;
|
|
|
|
|
|
|
|
if (!Kit.HasKit(damagee))
|
|
|
|
return;
|
|
|
|
|
|
|
|
_active.put(damagee, System.currentTimeMillis());
|
|
|
|
|
|
|
|
SetPowered(damagee, true);
|
|
|
|
|
|
|
|
//Sound
|
|
|
|
damagee.getWorld().playSound(damagee.getLocation(), Sound.CREEPER_HISS, 3f, 1.25f);
|
|
|
|
|
|
|
|
//Inform
|
|
|
|
UtilPlayer.message(damagee, F.main("Skill", "You gained " + F.skill(GetName()) + "."));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Update(UpdateEvent event)
|
|
|
|
{
|
|
|
|
if (event.getType() != UpdateType.TICK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Iterator<Player> shieldIterator = _active.keySet().iterator();
|
|
|
|
|
|
|
|
while (shieldIterator.hasNext())
|
|
|
|
{
|
|
|
|
Player player = shieldIterator.next();
|
|
|
|
|
|
|
|
if (!IsPowered(player))
|
|
|
|
{
|
|
|
|
shieldIterator.remove();
|
|
|
|
SetPowered(player, false);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-09-14 08:13:24 +02:00
|
|
|
if (UtilTime.elapsed(_active.get(player), 2000))
|
2013-09-05 05:55:42 +02:00
|
|
|
{
|
|
|
|
shieldIterator.remove();
|
|
|
|
|
|
|
|
SetPowered(player, false);
|
|
|
|
|
|
|
|
//Sound
|
|
|
|
player.getWorld().playSound(player.getLocation(), Sound.CREEPER_HISS, 3f, 0.75f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Damage(CustomDamageEvent event)
|
|
|
|
{
|
|
|
|
if (event.IsCancelled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.GetCause() != DamageCause.ENTITY_ATTACK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Player damagee = event.GetDamageePlayer();
|
|
|
|
if (damagee == null) return;
|
|
|
|
|
|
|
|
if (!Kit.HasKit(damagee))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!IsPowered(damagee))
|
|
|
|
return;
|
|
|
|
|
|
|
|
event.SetCancelled("Lightning Shield");
|
|
|
|
|
|
|
|
//Inform
|
|
|
|
UtilPlayer.message(damagee, F.main("Skill", "You hit " + F.elem(UtilEnt.getName(event.GetDamagerPlayer(false))) + " with " + F.skill(GetName()) + "."));
|
|
|
|
|
|
|
|
//Lightning
|
|
|
|
damagee.getWorld().strikeLightningEffect(damagee.getLocation());
|
|
|
|
SetPowered(damagee, false);
|
|
|
|
|
|
|
|
//Damage Event
|
|
|
|
Manager.GetDamage().NewDamageEvent(event.GetDamagerEntity(false), damagee, null,
|
2014-01-18 02:34:24 +01:00
|
|
|
DamageCause.LIGHTNING, 4, true, true, false,
|
2013-09-05 05:55:42 +02:00
|
|
|
damagee.getName(), GetName());
|
|
|
|
}
|
|
|
|
|
|
|
|
public DisguiseCreeper GetDisguise(Player player)
|
|
|
|
{
|
|
|
|
DisguiseBase disguise = Manager.GetDisguise().getDisguise(player);
|
|
|
|
if (disguise == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
if (!(disguise instanceof DisguiseCreeper))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return (DisguiseCreeper)disguise;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPowered(Player player, boolean powered)
|
|
|
|
{
|
|
|
|
DisguiseCreeper creeper = GetDisguise(player);
|
|
|
|
if (creeper == null) return;
|
|
|
|
|
|
|
|
creeper.SetPowered(powered);
|
|
|
|
|
|
|
|
Manager.GetDisguise().updateDisguise(creeper);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean IsPowered(Player player)
|
|
|
|
{
|
|
|
|
DisguiseCreeper creeper = GetDisguise(player);
|
|
|
|
if (creeper == null) return false;
|
|
|
|
|
|
|
|
return creeper.IsPowered();
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Knockback(CustomDamageEvent event)
|
|
|
|
{
|
|
|
|
if (event.GetReason() == null || !event.GetReason().contains(GetName()))
|
|
|
|
return;
|
|
|
|
|
2014-01-18 02:34:24 +01:00
|
|
|
event.AddKnockback(GetName(), 2.5);
|
2013-09-05 05:55:42 +02:00
|
|
|
}
|
|
|
|
}
|