Skip to content

Commit

Permalink
0.100.4.11:
Browse files Browse the repository at this point in the history
  - Fix regressions in health regen task on MC versions under 1.21.3.
  • Loading branch information
LlmDl committed Nov 5, 2024
1 parent 531848c commit 5168fa9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Towny/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<artifactId>towny</artifactId>
<packaging>jar</packaging>
<version>0.100.4.10</version>
<version>0.100.4.11</version>

<licenses>
<license>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.palmergames.bukkit.towny.object.TownBlock;

import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.Server;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Player;
Expand All @@ -17,10 +16,10 @@
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.TownBlockType;
import com.palmergames.bukkit.towny.utils.CombatUtil;
import com.palmergames.bukkit.towny.utils.MinecraftVersion;
import com.palmergames.bukkit.util.BukkitTools;

public class HealthRegenTimerTask extends TownyTimerTask {
private static final Attribute MAX_HEALTH = Registry.ATTRIBUTE.get(NamespacedKey.minecraft("max_health"));

static {
TownySettings.addReloadListener(NamespacedKey.fromString("towny:health-regen-task"), () -> TownyTimerHandler.toggleHealthRegen(TownySettings.hasHealthRegen()));
Expand Down Expand Up @@ -79,7 +78,7 @@ private void evaluateHealth(Player player) {
// Heal 1 HP while in town.
final double currentHP = player.getHealth();
final double futureHP = currentHP + 1;
final double maxHP = player.getAttribute(MAX_HEALTH).getValue();
final double maxHP = player.getAttribute(getMaxHealthAttribute()).getValue();

// Shrink gained to fit below the maxHP.
final double gained = futureHP > maxHP ? 1.0 - (futureHP - maxHP) : 1.0;
Expand All @@ -97,4 +96,12 @@ private void tryIncreaseHealth(Player player, double currentHealth, double maxHe

player.setHealth(Math.min(maxHealth, event.getAmount() + currentHealth));
}

@SuppressWarnings("deprecation")
private Attribute getMaxHealthAttribute() {
if (MinecraftVersion.CURRENT_VERSION.isNewerThanOrEquals(MinecraftVersion.MINECRAFT_1_21_3))
return Attribute.MAX_HEALTH;
else
return Attribute.valueOf("GENERIC_MAX_HEALTH");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private MinecraftVersion() {}
public static final Version MINECRAFT_1_20_3 = Version.fromString("1.20.3");
public static final Version MINECRAFT_1_20_5 = Version.fromString("1.20.5");
public static final Version MINECRAFT_1_21 = Version.fromString("1.21");
public static final Version MINECRAFT_1_21_3 = Version.fromString("1.21.3");

public static final Version CURRENT_VERSION = Version.fromString(Bukkit.getBukkitVersion());
public static final Version OLDEST_VERSION_SUPPORTED = MINECRAFT_1_19_1;
Expand Down
4 changes: 3 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10123,4 +10123,6 @@ v0.92.0.11:
- Closes #7664.
- New Config Option: economy.daily_taxes.per_outpost_cost
- Default: 0.0
- An optional price that a town must pay for each outpost they own. This number is added to the town upkeep before any other upkeep modifiers are applied to the Town's upkeep costs.
- An optional price that a town must pay for each outpost they own. This number is added to the town upkeep before any other upkeep modifiers are applied to the Town's upkeep costs.
0.100.4.11:
- Fix regressions in health regen task on MC versions under 1.21.3.

0 comments on commit 5168fa9

Please sign in to comment.