Advertisement
jayhillx

onPlayerDeath

Jun 11th, 2021
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 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. if (event.getSource() == ModDamageSource.causeBoundPlayer(player)) {
  14. BoundPlayersList.removeUsername(bound.getUUID());
  15. } else {
  16. BoundPlayersList.setUsername(bound.getUUID(), bound.getName());
  17. }
  18.  
  19. if (!player.world.isRemote) {
  20. /** Adds potion effect to bound player. */
  21. serverPlayerEntity.addPotionEffect(new EffectInstance(LifeBindingPotion.LIFE_DAMAGING_EFFECT.get(), 300));
  22. /** Removes potion from player who had died/triggered the event. */
  23. player.removePotionEffect(LifeBindingPotion.LIFE_DAMAGING_EFFECT.get());
  24. }
  25. }
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement