Advertisement
LuaTenshi

Damage with EntityQueue

May 31st, 2020
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. package red.mirai.miraicombat.events;
  2.  
  3. import ...;
  4.  
  5. public class DamageApplicationEvent implements Listener {
  6.     //ConcurrentLinkedQueue<Entity> entityQueue = new ConcurrentLinkedQueue<>();
  7.     public static LoadingCache<UUID, Entity> entityQueue = CacheBuilder.newBuilder()
  8.             .maximumSize( 256 )
  9.             .expireAfterWrite( 3L, TimeUnit.MINUTES )
  10.             .build( CacheLoader.from( ( key ) -> null ) );
  11.  
  12.     @EventHandler( priority = EventPriority.HIGH )
  13.     public void onPlayerDamageEvent( EntityDamageByEntityEvent event ) {
  14.         Entity attacker = event.getDamager();
  15.         Entity target = event.getEntity();
  16.         UUID targetID = target.getUniqueId();
  17.  
  18.         final double damage = event.getFinalDamage();
  19.  
  20.         //if ( !entityQueue.contains( target ) ) {
  21.         if ( entityQueue.getUnchecked( targetID ) != null ) {
  22.             DamageCalc applyDamage = new DamageCalc();
  23.             //entityQueue.add( target );
  24.             entityQueue.put( targetID, target );
  25.  
  26.             applyDamage.init( attacker, target, damage, (apply, newDamage) -> {
  27.                 if ( apply ) {
  28.                     double bonusDamage = ( newDamage - damage );
  29.                     Damageable dmgTarget = (Damageable) target;
  30.                     dmgTarget.damage( bonusDamage, attacker );
  31.                 }
  32.                 //entityQueue.remove( target );
  33.                 entityQueue.invalidate( targetID );
  34.             } );
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement