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

75 lines
1.9 KiB
Java

package mineplex.game.clans.items.legendaries;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import mineplex.game.clans.items.CustomItem;
import mineplex.game.clans.items.generation.ValueDistribution;
public class LegendaryItem extends CustomItem
{
public final long BLOCK_COOLDOWN = 200l; // Right clicking activates right click for 200ms
private long _lastBlock; // Timestamp of last block from wielder
public long timeSinceLastBlock() { return System.currentTimeMillis() - _lastBlock; }
public LegendaryItem()
{
_lastBlock = 0l;
}
public void update(Player wielder)
{
// Leave implementation to potential subtypes
}
public void onAttack(EntityDamageByEntityEvent event, Player wielder)
{
// Leave implementation to potential subtypes
}
@Override
public void onAttack(EntityDamageByEntityEvent event)
{
if (event.getDamager() instanceof Player)
{
Player wielder = (Player) event.getDamager();
onAttack(event, wielder);
}
super.onAttack(event);
}
public void onInteract(PlayerInteractEvent event)
{
Action action = event.getAction();
if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK)
{
_lastBlock = System.currentTimeMillis();
}
super.onInteract(event);
}
public boolean isHoldingRightClick()
{
return timeSinceLastBlock() <= BLOCK_COOLDOWN;
}
/**
* @param minValue - the minimum value for attribute value range
* @param maxValue - the maximum value for attribute value range
* @return newly instantiated {@link ValueDistribution} for attribute values in range [{@code minValue}. {@code maxValue}].
*/
public static ValueDistribution generateDistribution(double minValue, double maxValue)
{
return new ValueDistribution(minValue, maxValue);
}
}