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

125 lines
3.2 KiB
Java
Raw Normal View History

2013-08-29 08:20:36 +02:00
package nautilus.game.arcade.kit.perks;
import java.util.HashSet;
import java.util.Iterator;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.kit.Perk;
public class PerkRopedArrow extends Perk
{
private HashSet<Entity> _arrows = new HashSet<Entity>();
2013-08-29 08:20:36 +02:00
private String _name;
private double _power;
private long _recharge;
2013-08-29 08:20:36 +02:00
public PerkRopedArrow(String name, double power, long recharge)
{
super(name, new String[]
{
C.cYellow + "Left-Click" + C.cGray + " with Bow to " + C.cGreen + name
});
2013-08-29 08:20:36 +02:00
_name = name;
_power = power;
_recharge = recharge;
}
@EventHandler
public void Fire(PlayerInteractEvent event)
{
if (event.getAction() != Action.LEFT_CLICK_AIR && event.getAction() != Action.LEFT_CLICK_BLOCK)
return;
if (event.getPlayer().getItemInHand() == null)
return;
2013-08-29 08:20:36 +02:00
if (event.getPlayer().getItemInHand().getType() != Material.BOW)
return;
2013-08-29 08:20:36 +02:00
Player player = event.getPlayer();
2013-08-29 08:20:36 +02:00
if (!Kit.HasKit(player))
return;
2013-08-29 08:20:36 +02:00
if (!Recharge.Instance.use(player, _name, _recharge, true))
return;
//Arrow
2013-08-29 08:20:36 +02:00
Arrow arrow = player.launchProjectile(Arrow.class);
arrow.setVelocity(player.getLocation().getDirection().multiply(2.4 * _power));
_arrows.add(arrow);
//Leash
//Bat bat = player.getWorld().spawn(player.getEyeLocation(), Bat.class);
//bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100000, 100000));
//bat.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100000, 100000));
2013-08-29 08:20:36 +02:00
//bat.setLeashHolder(arrow);
2013-08-29 08:20:36 +02:00
//Inform
UtilPlayer.message(player, F.main("Game", "You fired " + F.skill(_name) + "."));
}
2013-08-29 08:20:36 +02:00
@EventHandler
public void Hit(ProjectileHitEvent event)
{
if (!_arrows.remove(event.getEntity()))
return;
Projectile proj = event.getEntity();
if (proj.getShooter() == null)
return;
if (!(proj.getShooter() instanceof Player))
return;
Vector vec = UtilAlg.getTrajectory(proj.getShooter(), proj);
double mult = (proj.getVelocity().length() / 3d);
2013-08-29 08:20:36 +02:00
//Action
UtilAction.velocity(proj.getShooter(), vec,
0.4 + mult * _power, false, 0, 0.6 * mult * _power, 1.2 * mult * _power, true);
//Effect
proj.getWorld().playSound(proj.getLocation(), Sound.ARROW_HIT, 2.5f, 0.5f);
}
@EventHandler
public void Clean(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
2013-08-29 08:20:36 +02:00
for (Iterator<Entity> arrowIterator = _arrows.iterator(); arrowIterator.hasNext();)
{
Entity arrow = arrowIterator.next();
2013-08-29 08:20:36 +02:00
if (!arrow.isValid())
arrowIterator.remove();
}
}
}