e3eae200ae
SSM: added knight SSM: added placeholder for wither skel
125 lines
3.2 KiB
Java
125 lines
3.2 KiB
Java
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>();
|
|
|
|
private String _name;
|
|
private double _power;
|
|
private long _recharge;
|
|
|
|
public PerkRopedArrow(String name, double power, long recharge)
|
|
{
|
|
super(name, new String[]
|
|
{
|
|
C.cYellow + "Left-Click" + C.cGray + " with Bow to " + C.cGreen + name
|
|
});
|
|
|
|
_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;
|
|
|
|
if (event.getPlayer().getItemInHand().getType() != Material.BOW)
|
|
return;
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
if (!Kit.HasKit(player))
|
|
return;
|
|
|
|
if (!Recharge.Instance.use(player, _name, _recharge, true))
|
|
return;
|
|
|
|
//Arrow
|
|
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));
|
|
|
|
//bat.setLeashHolder(arrow);
|
|
|
|
//Inform
|
|
UtilPlayer.message(player, F.main("Game", "You fired " + F.skill(_name) + "."));
|
|
}
|
|
|
|
@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);
|
|
|
|
//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;
|
|
|
|
for (Iterator<Entity> arrowIterator = _arrows.iterator(); arrowIterator.hasNext();)
|
|
{
|
|
Entity arrow = arrowIterator.next();
|
|
|
|
if (!arrow.isValid())
|
|
arrowIterator.remove();
|
|
}
|
|
}
|
|
}
|