2015-05-16 18:58:58 +02:00
package mineplex.game.clans.items.legendaries ;
2015-05-25 20:22:06 +02:00
import org.bukkit.Material ;
2015-05-16 18:58:58 +02:00
import org.bukkit.entity.Player ;
import org.bukkit.event.block.Action ;
import org.bukkit.event.player.PlayerInteractEvent ;
2015-06-29 22:38:51 +02:00
import org.bukkit.potion.PotionEffect ;
import org.bukkit.potion.PotionEffectType ;
2015-05-16 18:58:58 +02:00
2016-01-06 23:32:36 +01:00
import mineplex.core.common.util.C ;
import mineplex.core.common.util.F ;
import mineplex.core.common.util.UtilServer ;
2015-05-16 18:58:58 +02:00
import mineplex.game.clans.items.CustomItem ;
import mineplex.game.clans.items.generation.ValueDistribution ;
2015-06-01 18:25:20 +02:00
import mineplex.minecraft.game.core.damage.CustomDamageEvent ;
2015-05-16 18:58:58 +02:00
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 ; }
2015-11-27 04:28:19 +01:00
public LegendaryItem ( String name , String [ ] description , Material material )
2015-05-25 20:22:06 +02:00
{
super ( name , description , material ) ;
2015-05-16 18:58:58 +02:00
_lastBlock = 0l ;
}
public void update ( Player wielder )
{
// Leave implementation to potential subtypes
}
2015-06-01 18:25:20 +02:00
public void onAttack ( CustomDamageEvent event , Player wielder )
2015-05-16 18:58:58 +02:00
{
// Leave implementation to potential subtypes
}
@Override
2015-06-01 18:25:20 +02:00
public void onAttack ( CustomDamageEvent event )
2015-05-16 18:58:58 +02:00
{
2015-06-01 18:25:20 +02:00
if ( event . GetDamagerPlayer ( true ) ! = null )
2015-05-16 18:58:58 +02:00
{
2015-06-01 18:25:20 +02:00
onAttack ( event , event . GetDamagerPlayer ( true ) ) ;
2015-05-16 18:58:58 +02:00
}
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 ( ) ;
}
2016-01-06 23:32:36 +01:00
if ( OriginalOwner = = null )
{
OriginalOwner = event . getPlayer ( ) . getUniqueId ( ) . toString ( ) ;
UtilServer . broadcast ( F . main ( " Clans " , F . elem ( event . getPlayer ( ) . getName ( ) ) + " has picked up " + F . vowelAN ( getDisplayName ( ) ) + " " + getDisplayName ( ) + C . mBody + " . " ) ) ;
}
2015-05-16 18:58:58 +02:00
super . onInteract ( event ) ;
}
public boolean isHoldingRightClick ( )
{
return timeSinceLastBlock ( ) < = BLOCK_COOLDOWN ;
}
2015-06-01 18:25:20 +02:00
protected void log ( String message )
{
System . out . println ( " [Custom Item - " + _displayName + " ] " + message ) ;
}
2015-05-16 18:58:58 +02:00
/ * *
* @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 ) ;
}
2015-06-29 22:38:51 +02:00
/ * *
* Add a { @link PotionEffect } to { @code player } with specified { @code type } , { @code amplifier } ( power ) and
* { @code tickDuration } of the effect .
* @param player - the player to receive the potion effect
* @param type - the type of potion to apply
* @param tickDuration - the duration ( in ticks ) to apply the potion for
* @param amplifier - the amplifier ( level / power , zero - based ) of the potion effect
* /
public static void grantPotionEffect ( Player player , PotionEffectType type , int tickDuration , int amplifier )
{
player . addPotionEffect ( new PotionEffect ( type , amplifier , tickDuration ) ) ;
}
2015-05-16 18:58:58 +02:00
}