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

65 lines
1.4 KiB
Java
Raw Normal View History

package mineplex.game.clans.items.legendaries;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTextBottom;
public class WindBlade extends LegendaryItem
{
public static final double FLIGHT_VELOCITY = 0.75d;
public static final int MAX_FLIGHT_TIME = 80; // Max flight of 80 ticks
private double _power;
public WindBlade()
{
super("Wind Blade", "Activate flying ability to take flight for 80 ticks before landing!", Material.RECORD_8); // TODO:
// Configurable?
}
@Override
public void update(Player wielder)
{
// Check if player is attempting to fly and activate
if (isHoldingRightClick() && canPropel())
{
removePower(.88);
propelPlayer(wielder);
}
if (wielder.isOnGround())
{
addPower(0.33);
}
UtilTextBottom.displayProgress(_power / 80, wielder);
}
private void propelPlayer(Player player)
{
Vector direction = player.getLocation().getDirection().normalize();
direction.multiply(FLIGHT_VELOCITY);
player.setVelocity(direction);
player.setFallDistance(0f);
}
private boolean canPropel()
{
return _power > 0;
}
private void addPower(double power)
{
_power = UtilMath.clamp(_power + power, 0, 80);
}
private void removePower(double power)
{
_power = UtilMath.clamp(_power - power, 0, 80);
}
}