2013-10-26 02:34:05 +02:00
|
|
|
package nautilus.game.arcade.kit.perks;
|
|
|
|
|
2013-10-26 10:01:26 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
2013-10-26 02:34:05 +02:00
|
|
|
|
2014-08-21 09:07:54 +02:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
2013-10-26 02:34:05 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2013-10-26 10:01:26 +02:00
|
|
|
import org.bukkit.entity.Projectile;
|
2013-10-26 02:34:05 +02:00
|
|
|
import org.bukkit.entity.ThrownPotion;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.block.Action;
|
2013-10-26 10:01:26 +02:00
|
|
|
import org.bukkit.event.entity.ProjectileHitEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
2013-10-26 02:34:05 +02:00
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
|
|
|
|
import mineplex.core.common.util.C;
|
|
|
|
import mineplex.core.common.util.F;
|
|
|
|
import mineplex.core.common.util.UtilAction;
|
|
|
|
import mineplex.core.common.util.UtilBlock;
|
2013-10-26 10:01:26 +02:00
|
|
|
import mineplex.core.common.util.UtilEnt;
|
|
|
|
import mineplex.core.common.util.UtilMath;
|
|
|
|
import mineplex.core.common.util.UtilParticle;
|
|
|
|
import mineplex.core.common.util.UtilParticle.ParticleType;
|
2013-10-26 02:34:05 +02:00
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
|
|
|
import mineplex.core.recharge.Recharge;
|
2013-10-26 10:01:26 +02:00
|
|
|
import mineplex.core.updater.UpdateType;
|
|
|
|
import mineplex.core.updater.event.UpdateEvent;
|
2013-12-24 09:14:40 +01:00
|
|
|
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
2013-10-26 02:34:05 +02:00
|
|
|
import nautilus.game.arcade.kit.Perk;
|
|
|
|
|
|
|
|
public class PerkWitchPotion extends Perk
|
|
|
|
{
|
2013-10-26 10:01:26 +02:00
|
|
|
private ArrayList<Projectile> _proj = new ArrayList<Projectile>();
|
|
|
|
|
2013-10-26 02:34:05 +02:00
|
|
|
public PerkWitchPotion()
|
|
|
|
{
|
2013-10-26 17:37:11 +02:00
|
|
|
super("Daze Potion", new String[]
|
2013-10-26 02:34:05 +02:00
|
|
|
{
|
2013-10-26 17:37:11 +02:00
|
|
|
C.cYellow + "Right-Click" + C.cGray + " to use " + C.cGreen + "Daze Potion"
|
2013-10-26 02:34:05 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Activate(PlayerInteractEvent event)
|
|
|
|
{
|
|
|
|
if (event.isCancelled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (UtilBlock.usable(event.getClickedBlock()))
|
|
|
|
return;
|
|
|
|
|
2013-10-26 10:01:26 +02:00
|
|
|
if (!event.getPlayer().getItemInHand().getType().toString().contains("_AXE"))
|
2013-10-26 02:34:05 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
if (!Kit.HasKit(player))
|
|
|
|
return;
|
|
|
|
|
2014-04-03 06:48:58 +02:00
|
|
|
if (!Recharge.Instance.use(player, GetName(), 2000, true, true))
|
2013-10-26 02:34:05 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
//Start
|
|
|
|
ThrownPotion potion = player.launchProjectile(ThrownPotion.class);
|
2013-10-26 10:01:26 +02:00
|
|
|
UtilAction.velocity(potion, player.getLocation().getDirection(), 1, false, 0, 0.2, 10, false);
|
|
|
|
|
|
|
|
_proj.add(potion);
|
2013-10-26 02:34:05 +02:00
|
|
|
|
|
|
|
//Inform
|
|
|
|
UtilPlayer.message(player, F.main("Skill", "You used " + F.skill(GetName()) + "."));
|
|
|
|
}
|
2013-10-26 10:01:26 +02:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Hit(ProjectileHitEvent event)
|
|
|
|
{
|
|
|
|
if (!_proj.remove(event.getEntity()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (Player player : Manager.GetGame().GetPlayers(true))
|
|
|
|
{
|
|
|
|
if (player.equals(event.getEntity().getShooter()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (UtilMath.offset(player.getLocation().add(0,1,0), event.getEntity().getLocation()) > 3)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//Damage Event
|
2014-08-21 09:07:54 +02:00
|
|
|
Manager.GetDamage().NewDamageEvent(player, (LivingEntity)event.getEntity().getShooter(), null,
|
2013-12-24 09:14:40 +01:00
|
|
|
DamageCause.CUSTOM, 5, true, true, false,
|
2014-08-21 09:07:54 +02:00
|
|
|
UtilEnt.getName((LivingEntity)event.getEntity().getShooter()), GetName());
|
2013-10-26 10:01:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Update(UpdateEvent event)
|
|
|
|
{
|
|
|
|
if (event.getType() != UpdateType.TICK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Iterator<Projectile> potionIterator = _proj.iterator();
|
|
|
|
|
|
|
|
while (potionIterator.hasNext())
|
|
|
|
{
|
|
|
|
Projectile proj = potionIterator.next();
|
|
|
|
|
|
|
|
if (!proj.isValid())
|
|
|
|
{
|
|
|
|
potionIterator.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-01-18 02:34:24 +01:00
|
|
|
UtilParticle.PlayParticle(ParticleType.MOB_SPELL, proj.getLocation(), 0, 0, 0, 0, 1);
|
2013-10-26 10:01:26 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-24 09:14:40 +01:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Knockback(CustomDamageEvent event)
|
|
|
|
{
|
|
|
|
if (event.GetReason() == null || !event.GetReason().contains(GetName()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
event.AddKnockback(GetName(), 2);
|
|
|
|
}
|
2013-10-26 02:34:05 +02:00
|
|
|
}
|