Mineplex2018-withcommit/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/WindBlade.java

59 lines
1.4 KiB
Java
Raw Normal View History

package mineplex.game.clans.items.legendaries;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.util.Vector;
public class WindBlade extends LegendaryItem
{
public static final double FLIGHT_VELOCITY = 0.25d;
public static final int MAX_FLIGHT_TIME = 80; // Max flight of 80 ticks
private long _flightTime; // Time (in ticks) since last touching ground and flying
public WindBlade()
{
super("Wind Blade", "Activate flying ability to take flight for 80 ticks before landing!", Material.STICK); // TODO: Configurable?
_flightTime = 0;
}
@Override
public void update(Player wielder)
{
Entity entity = (Entity) wielder;
// Check if player is attempting to fly and activate
if (isHoldingRightClick() && canPropel())
{
propelPlayer(wielder);
}
// Check if player has touched down
if (entity.isOnGround())
{
_flightTime = 0;
}
}
private void propelPlayer(Player player)
{
_flightTime++;
Vector direction = player.getLocation().getDirection().normalize();
direction.multiply(FLIGHT_VELOCITY); // Set velocity magnitude
player.setVelocity(direction);
}
private boolean canPropel()
{
return _flightTime <= MAX_FLIGHT_TIME;
}
}