Advertisement
jayhillx

BindingEvents

Jun 9th, 2021
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. @SubscribeEvent
  2. public void onPlayerDeath(LivingDeathEvent event) {
  3. Entity entity = event.getEntity();
  4.  
  5. if (entity instanceof PlayerEntity) {
  6. PlayerEntity player = (PlayerEntity)entity;
  7.  
  8. for (ServerPlayerEntity serverPlayerEntity : player.getServer().getPlayerList().getPlayers()) {
  9.  
  10. if (player.getCapability(BindingCapabilities.LIFE_BOUND_CAPABILITY).orElse(null).isBound()) {
  11. IBoundCapability bound = player.getCapability(BindingCapabilities.LIFE_BOUND_CAPABILITY).orElse(null);
  12.  
  13. /** Stops a loop of bound players from dying. */
  14. if (event.getSource() == ModDamageSource.LIFE_BINDING) {
  15. serverPlayerEntity.removePotionEffect(LifeBindingPotion.LIFE_DAMAGING_EFFECT.get());
  16. }
  17.  
  18. /** Adds potion effect to bound player. */
  19. player.getServer().getPlayerList().getPlayerByUUID(bound.getUUID()).addPotionEffect(new EffectInstance(LifeBindingPotion.LIFE_DAMAGING_EFFECT.get(), 300));
  20. /** Removes potion from player who had died/triggered the event. */
  21. player.removePotionEffect(LifeBindingPotion.LIFE_DAMAGING_EFFECT.get());
  22. }
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement