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

77 lines
2.3 KiB
Java
Raw Normal View History

2014-11-29 04:39:09 +01:00
package nautilus.game.arcade.kit.perks;
import java.util.Iterator;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.kit.Perk;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
public class PerkPinned extends Perk
{
public PerkPinned()
{
super("Pinned", new String[]
{
"Gravity is suddenly much stronger", "You also have a hard time moving"
});
}
2014-12-03 11:32:18 +01:00
private NautHashMap<LivingEntity, Integer> _ticksPinned = new NautHashMap<LivingEntity, Integer>();
2014-11-29 04:39:09 +01:00
@EventHandler
public void onSecond(UpdateEvent event)
{
2014-12-03 11:32:18 +01:00
if (event.getType() != UpdateType.FASTEST)
2014-11-29 04:39:09 +01:00
{
return;
}
2014-12-03 11:32:18 +01:00
Iterator<LivingEntity> itel = _ticksPinned.keySet().iterator();
2014-11-29 04:39:09 +01:00
while (itel.hasNext())
{
LivingEntity entity = itel.next();
if (entity.isDead() || (entity instanceof Player && !Manager.IsAlive((Player) entity)))
{
itel.remove();
continue;
}
2014-12-03 11:32:18 +01:00
entity.setVelocity(entity.getVelocity().add(new Vector(0, -0.2, 0)));
if (_ticksPinned.get(entity) <= 1)
2014-11-29 04:39:09 +01:00
{
itel.remove();
}
else
{
2014-12-03 11:32:18 +01:00
_ticksPinned.put(entity, _ticksPinned.get(entity) - 1);
2014-11-29 04:39:09 +01:00
}
}
}
@EventHandler(ignoreCancelled = true)
public void onDamage(CustomDamageEvent event)
{
if (event.GetCause() == DamageCause.PROJECTILE)
{
Player player = event.GetDamagerPlayer(true);
if (player != null && this.Kit.HasKit(player))
{
LivingEntity entity = event.GetDamageeEntity();
2014-12-03 11:32:18 +01:00
entity.setVelocity(entity.getVelocity().add(new Vector(0, -0.4, 0)));
2014-11-29 04:39:09 +01:00
entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 40, 1), true);
2014-12-03 11:32:18 +01:00
_ticksPinned.put(entity, 40);
2014-11-29 04:39:09 +01:00
}
}
}
}