From 13e5d38277b55a8a44b74a04859315b2790108dd Mon Sep 17 00:00:00 2001 From: Connor Monahan Date: Sun, 16 Jul 2017 19:41:07 -0400 Subject: [PATCH] Fix #840, keep health in bounds with attributes --- war/pom.xml | 14 +++++++- .../main/java/com/tommytony/war/Warzone.java | 32 +++++++++++++------ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/war/pom.xml b/war/pom.xml index 7c8e5cf..a6ef0b7 100644 --- a/war/pom.xml +++ b/war/pom.xml @@ -54,6 +54,12 @@ HEAD https://github.com/taoneill/war + + + cma-repo + ftp://ftp.cmastudios.me/srv/ftp/maven + + @@ -93,6 +99,12 @@ + + + org.apache.maven.wagon + wagon-ftp + + true @@ -117,7 +129,7 @@ org.bukkit bukkit - 1.9.4-R0.1-SNAPSHOT + 1.12-R0.1-SNAPSHOT org.kitteh diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 2cb6a2d..4ee73af 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -26,6 +26,9 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.World; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeInstance; +import org.bukkit.attribute.AttributeModifier; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Arrow; @@ -445,14 +448,26 @@ public class Warzone { } private void handleRespawn(final Team team, final Player player) { + // first, wipe inventory to disable attribute modifications + this.preventItemHackingThroughOpenedInventory(player); + player.getInventory().clear(); + + // clear potion effects + PotionEffectHelper.clearPotionEffects(player); + // Fill hp player.setRemainingAir(player.getMaximumAir()); - player.setMaxHealth(20); - player.setHealth(player.getMaxHealth()); + AttributeInstance ai = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); + for (AttributeModifier mod : ai.getModifiers()) { + ai.removeModifier(mod); + } + ai.setBaseValue(20.0); + player.setHealth(ai.getValue()); player.setFoodLevel(20); player.setSaturation(team.getTeamConfig().resolveInt(TeamConfig.SATURATION)); player.setExhaustion(0); player.setFallDistance(0); + player.setFireTicks(0); War.war.getServer().getScheduler().runTaskLater(War.war, new Runnable() { @Override @@ -463,24 +478,20 @@ public class Warzone { }, 1L); - this.preventItemHackingThroughOpenedInventory(player); - + player.setLevel(0); player.setExp(0); player.setAllowFlight(false); player.setFlying(false); - player.getInventory().clear(); - + this.setKillCount(player.getName(), 0); if (player.getGameMode() != GameMode.SURVIVAL) { // Players are always in survival mode in warzones player.setGameMode(GameMode.SURVIVAL); } - - // clear potion effects - PotionEffectHelper.clearPotionEffects(player); + String potionEffect = team.getTeamConfig().resolveString(TeamConfig.APPLYPOTION); if (!potionEffect.isEmpty()) { @@ -628,7 +639,8 @@ public class Warzone { this.playerInvFromInventoryStash(playerInv, originalState); player.setGameMode(originalState.getGamemode()); - player.setHealth(Math.max(Math.min(originalState.getHealth(), 20.0D), 0.0D)); + double maxH = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + player.setHealth(Math.max(Math.min(originalState.getHealth(), maxH), 0.0D)); player.setExhaustion(originalState.getExhaustion()); player.setSaturation(originalState.getSaturation()); player.setFoodLevel(originalState.getFoodLevel());