Advertisement
jayhillx

StatsEvents 01

Sep 12th, 2021
1,038
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.88 KB | None | 0 0
  1. @SubscribeEvent
  2.     public void onDeath(LivingDeathEvent event) {
  3.         LivingEntity entity = event.getEntityLiving();
  4.         Entity causeEntity = event.getSource().getEntity();
  5.         DamageSource source = event.getSource();
  6.  
  7.         /** Sets Cause. */
  8.         String cause = null;
  9.         if (entity instanceof PlayerEntity) {
  10.             PlayerEntity player = (PlayerEntity)entity;
  11.  
  12.             if (causeEntity instanceof LivingEntity) {
  13.                 if (causeEntity instanceof PlayerEntity) {
  14.                     if (causeEntity == player) {
  15.                         cause = "Yourself";
  16.                     } else {
  17.                         cause = ((PlayerEntity)causeEntity).getName().getString();
  18.                     }
  19.                 } else {
  20.                     cause = ((LivingEntity)causeEntity).getName().getString();
  21.                 }
  22.             } else {
  23.                 if (source == DamageSource.IN_FIRE) {
  24.                     cause = "Flames";
  25.                 } else if (source == DamageSource.LIGHTNING_BOLT) {
  26.                     cause = "Lightning";
  27.                 } else if (source == DamageSource.ON_FIRE) {
  28.                     cause = "Burning";
  29.                 } else if (source == DamageSource.LAVA) {
  30.                     cause = "Lava";
  31.                 } else if (source == DamageSource.HOT_FLOOR) {
  32.                     cause = "Magma";
  33.                 } else if (source == DamageSource.IN_WALL) {
  34.                     cause = "Suffocation";
  35.                 } else if (source == DamageSource.CRAMMING) {
  36.                     cause = "Cramming";
  37.                 } else if (source == DamageSource.DROWN) {
  38.                     cause = "Drowning";
  39.                 } else if (source == DamageSource.STARVE) {
  40.                     cause = "Starvation";
  41.                 } else if (source == DamageSource.CACTUS) {
  42.                     cause = "Cactus";
  43.                 } else if (source == DamageSource.FALL) {
  44.                     cause = "Falling";
  45.                 } else if (source == DamageSource.FLY_INTO_WALL) {
  46.                     cause = "Kinetic Energy";
  47.                 } else if (source == DamageSource.OUT_OF_WORLD) {
  48.                     cause = "Void";
  49.                 } else if (source == DamageSource.MAGIC) {
  50.                     cause = "Magic";
  51.                 } else if (source == DamageSource.WITHER) {
  52.                     cause = "Wither";
  53.                 } else if (source == DamageSource.ANVIL) {
  54.                     cause = "Falling Anvil";
  55.                 } else if (source == DamageSource.FALLING_BLOCK) {
  56.                     cause = "Falling Block";
  57.                 } else if (source == DamageSource.DRAGON_BREATH) {
  58.                     cause = "Dragon Breath";
  59.                 } else if (source == DamageSource.SWEET_BERRY_BUSH) {
  60.                     cause = "Berry Bush";
  61.                 } else if (source.isExplosion()) {
  62.                     cause = "Explosion";
  63.                 } else {
  64.                     cause = "Something";
  65.                 }
  66.             }
  67.  
  68.             String finalCause = cause;
  69.             player.getCapability(HealthCapability.HEALTH_CAPABILITY).ifPresent(health -> {
  70.                 player.getCapability(StatsCapability.STATS_CAPABILITY).ifPresent(stats -> {
  71.                     int hearts = (int) (health.getMaxHealth() - 2) / 2;
  72.  
  73.                     if (hearts >= 1 && hearts <= 10) {
  74.                         String[] causeArray = stats.getCause();
  75.                         causeArray[hearts - 1] = finalCause;
  76.                         stats.setCause(causeArray);
  77.                     }
  78.  
  79.                     player.getCapability(TimeCapability.TIME_CAPABILITY).ifPresent(time -> {
  80.                         if (hearts >= 1 && hearts <= 10) {
  81.                             String[] timeArray = stats.getTime();
  82.  
  83.                             if (time.getTime() == 1) {
  84.                                 timeArray[hearts - 1] = "1 second";
  85.                             } else if (time.getTime() < 60) {
  86.                                 timeArray[hearts - 1] = time.getTime() + " seconds";
  87.                             } else if (time.getTime() >= 60 && time.getTime() < 120) {
  88.                                 timeArray[hearts - 1] = "1 minute";
  89.                             } else if (time.getTime() >= 120 && time.getTime() < 3600) {
  90.                                 timeArray[hearts - 1] = time.getTime() / 60 + " minutes";
  91.                             } else if (time.getTime() >= 3600 && time.getTime() < 7200) {
  92.                                 timeArray[hearts - 1] = "1 hour";
  93.                             } else {
  94.                                 timeArray[hearts - 1] = time.getTime() / 3600 + " hours";
  95.                             }
  96.  
  97.                             stats.setTime(timeArray);
  98.                             time.setTime(0);
  99.                         }
  100.                     });
  101.                 });
  102.             });
  103.         }
  104.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement