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

69 lines
1.8 KiB
Java
Raw Normal View History

2015-11-26 03:49:01 +01:00
package mineplex.game.clans.items.legendaries;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
2015-11-25 02:32:05 +01:00
public class HyperAxe extends LegendaryItem
{
2015-11-26 03:49:01 +01:00
public static final long ATTACK_RATE_DURATION = 200;
private static ValueDistribution amountGen = generateDistribution(0, 3); // [1, 4] speed amount
private static ValueDistribution durationGen = generateDistribution(80, 320); // [4, 16] seconds speed duration
private int _speedAmount;
private int _speedDuration;
private long _lastAttack;
public long timeSinceLastAttack() { return System.currentTimeMillis() - _lastAttack; }
2015-11-25 02:32:05 +01:00
public HyperAxe()
{
2015-11-26 05:24:07 +01:00
super("Hyper Axe", "Increased attack speed!", Material.RECORD_3);
_speedAmount = amountGen.generateIntValue();
_speedDuration = durationGen.generateIntValue();
_lastAttack = 0;
}
@Override
public void update(Player wielder)
{
if (isHoldingRightClick() && canBuff())
{
buffPlayer(wielder);
2015-11-26 03:49:01 +01:00
_lastAttack = System.currentTimeMillis();
}
}
@Override
public void onAttack(CustomDamageEvent event, Player wielder)
{
if (timeSinceLastAttack() >= ATTACK_RATE_DURATION)
{
event.SetIgnoreRate(true);
2015-11-26 03:49:01 +01:00
// log("Ignoring rate!");
2015-11-26 05:21:30 +01:00
event.AddMod("Hyper Axe", 1);
2015-11-26 03:49:01 +01:00
}
else
{
event.SetCancelled("Hyper Axe Cooldown");
}
}
private void buffPlayer(Player wielder)
{
// Give player speed buff
wielder.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, _speedDuration, _speedAmount));
log("Buffing");
}
private boolean canBuff()
{
return true; // TODO: Implement cooldown? (None specified in docs, sounds OP)
}
}