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

143 lines
3.4 KiB
Java
Raw Normal View History

2014-11-14 04:14:31 +01:00
package nautilus.game.arcade.kit.perks;
import java.util.ArrayList;
import java.util.Iterator;
import org.bukkit.ChatColor;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityShootBowEvent;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilServer;
2014-11-14 04:14:31 +01:00
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
2014-11-14 04:14:31 +01:00
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.kit.Perk;
public class PerkWitherArrowBlind extends Perk
{
private ArrayList<Arrow> _arrows = new ArrayList<Arrow>();
private int _proximityHit;
public PerkWitherArrowBlind(int proximityHit)
{
super("Smoke Arrow", new String[]
{
"Your arrows give Blindness for 4 seconds"
});
_proximityHit = proximityHit;
}
@EventHandler
public void FireBow(EntityShootBowEvent event)
{
if (!(event.getEntity() instanceof Player))
return;
if (!(event.getProjectile() instanceof Arrow))
return;
Player player = (Player)event.getEntity();
if (!Kit.HasKit(player))
return;
//Start
_arrows.add((Arrow)event.getProjectile());
}
@EventHandler(priority = EventPriority.HIGH)
public void Damage(CustomDamageEvent event)
{
if (event.IsCancelled())
return;
if (event.GetProjectile() == null)
return;
if (event.GetDamagerPlayer(true) == null)
return;
if (!(event.GetProjectile() instanceof Arrow))
return;
Arrow arrow = (Arrow)event.GetProjectile();
if (!_arrows.remove(arrow))
return;
Manager.GetCondition().Factory().Blind(GetName(), event.GetDamageeEntity(), null, 4, 0, false, false, false);
UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, arrow.getLocation(), 0, 0, 0, 0, 1,
ViewDist.MAX, UtilServer.getPlayers());
2014-11-14 04:14:31 +01:00
event.SetCancelled("Smoke Arrow");
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
for (Iterator<Arrow> arrowIterator = _arrows.iterator(); arrowIterator.hasNext();)
{
Arrow arrow = arrowIterator.next();
//Proxy
if (_proximityHit > 0 && getWitherTeam() != null)
{
boolean hit = false;
for (Player player : getWitherTeam().GetPlayers(true))
{
if (UtilMath.offset(player.getLocation().add(0, 3, 0), arrow.getLocation()) < _proximityHit)
2014-11-14 04:14:31 +01:00
{
Manager.GetCondition().Factory().Blind(GetName(), player, null, 4, 0, false, false, false);
hit = true;
}
}
if (hit)
2014-11-21 06:32:12 +01:00
{
UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, arrow.getLocation(), 0, 0, 0, 0, 1,
ViewDist.MAX, UtilServer.getPlayers());
2014-11-21 06:32:12 +01:00
arrowIterator.remove();
arrow.remove();
2014-11-14 04:14:31 +01:00
continue;
2014-11-21 06:32:12 +01:00
}
2014-11-14 04:14:31 +01:00
}
//Dead
if (arrow.isDead() || !arrow.isValid() || arrow.getTicksLived() > 120 || arrow.isOnGround())
{
arrow.remove();
arrowIterator.remove();
}
//Particle
else
{
UtilParticle.PlayParticle(ParticleType.LARGE_SMOKE, arrow.getLocation(), 0, 0, 0, 0, 1,
ViewDist.MAX, UtilServer.getPlayers());
2014-11-14 04:14:31 +01:00
}
}
}
public GameTeam getWitherTeam()
{
if (Manager.GetGame() == null)
return null;
return Manager.GetGame().GetTeam(ChatColor.RED);
}
}