From 5c24a9bc4436ef16a6ec2f6c1417ca646c3cf96e Mon Sep 17 00:00:00 2001 From: mathiascode Date: Thu, 27 Feb 2020 16:30:18 +0200 Subject: [PATCH] Attempt to fix max health issues --- .../extras/modules/player/PlayerDamage.java | 16 ++++------------ .../extras/modules/server/ServerCommand.java | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerDamage.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerDamage.java index 2caeac5..32a8f9c 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerDamage.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerDamage.java @@ -3,27 +3,19 @@ package pw.kaboom.extras.modules.player; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; - -import org.bukkit.attribute.Attribute; -import org.bukkit.attribute.AttributeInstance; - import org.bukkit.block.Block; import org.bukkit.block.BlockFace; - import org.bukkit.entity.EntityType; import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; - import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; - import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.PlayerDeathEvent; - import org.bukkit.inventory.ItemStack; public final class PlayerDamage implements Listener { @@ -56,10 +48,10 @@ public final class PlayerDamage implements Listener { } } + @SuppressWarnings("deprecation") @EventHandler void onPlayerDeath(final PlayerDeathEvent event) { final Player player = event.getEntity(); - final AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { onlinePlayer.sendMessage(event.getDeathMessage()); @@ -79,7 +71,7 @@ public final class PlayerDamage implements Listener { xp.setExperience(event.getDroppedExp()); } - maxHealth.setBaseValue(20); + player.setMaxHealth(20); player.setHealth(20); if (player.getBedSpawnLocation() != null) { @@ -100,9 +92,9 @@ public final class PlayerDamage implements Listener { } } } catch (Exception exception) { - maxHealth.setBaseValue(Double.POSITIVE_INFINITY); + player.setMaxHealth(Double.POSITIVE_INFINITY); player.setHealth(20); - maxHealth.setBaseValue(20); + player.setMaxHealth(20); } player.setExp(event.getNewExp()); diff --git a/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java b/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java index 4bfdf21..9e215f1 100644 --- a/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java +++ b/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java @@ -123,7 +123,7 @@ public final class ServerCommand implements Listener { if (sender instanceof BlockCommandSender) { final CommandBlock commandBlock = (CommandBlock) ((BlockCommandSender) sender).getBlock().getState(); - + commandBlock.setCommand(""); commandBlock.update(); }