ElgarL / Towny

Towny Advanced plugin for Bukkit @ http://palmergames.com/towny/
http://palmergames.com/towny/
75 stars 92 forks source link

Player maxHealth under 20 causes IllegalArgumentExceptions #100

Closed spathizilla closed 10 years ago

spathizilla commented 11 years ago

Spigot build 934 Towny 0.83.0.0

If a player's maximum health is set to under 20, the plugin will spit out IllegalArgumentExceptions when the configuration is set to heal people in their towns. This is caused by the code looking for a player health value of 20 and does not take into account this can be adjusted.

Line 59 on HealthRegenTimerTask:

int currentHP = player.getHealth(); if (currentHP < 20) { player.setHealth(++currentHP);

If the player's max health is say 10 the plugin will try to do player.setHealth(11) which is out of bounds for the server configuration.

The hardcoding of 20 should be changed to player.getMaxHealth()

The same thing would apply to any health values above 20 but the plugin would simply stop healing them at 20.

spathizilla commented 11 years ago

Oopsy, forgot the exception too:

2013-06-18 21:29:09 [WARNING] [Towny] Task #29 for Towny v0.83.0.0 generated an exception java.lang.IllegalArgumentException: Health must be between 0 and 11 at org.bukkit.craftbukkit.v1_5_R3.entity.CraftLivingEntity.setHealth(CraftLivingEntity.java:73) at com.palmergames.bukkit.towny.tasks.HealthRegenTimerTask.incHealth(Unknown Source) at com.palmergames.bukkit.towny.tasks.HealthRegenTimerTask.run(Unknown Source) at org.bukkit.craftbukkit.v1_5_R3.scheduler.CraftTask.run(CraftTask.java:58) at org.bukkit.craftbukkit.v1_5_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:344) at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:509) at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:227) at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:472) at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:404) at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)

ElgarL commented 10 years ago

Fixed