Apply a cap to the health and hunger flags to prevent possible exceptions

If a player's health or hunger is set to higher than its respective maximum CraftBukkit will throw exceptions.
This commit is contained in:
Dark Arc 2013-01-16 14:48:39 -05:00
parent 4398c781c5
commit e0e4207a4d

View File

@ -121,6 +121,10 @@ private void processHeal(ApplicableRegionSet applicable, Player player,
if (minHealth == null) minHealth = 0;
if (maxHealth == null) maxHealth = 20;
// Apply a cap to prevent possible exceptions
minHealth = Math.min(player.getMaxHealth(), minHealth);
maxHealth = Math.min(player.getMaxHealth(), maxHealth);
if (player.getHealth() >= maxHealth && healAmount > 0) {
return;
}
@ -158,6 +162,10 @@ private void processFeed(ApplicableRegionSet applicable, Player player,
if (minHunger == null) minHunger = 0;
if (maxHunger == null) maxHunger = 20;
// Apply a cap to prevent possible exceptions
minHunger = Math.min(20, minHunger);
maxHunger = Math.min(20, maxHunger);
if (player.getFoodLevel() >= maxHunger && feedAmount > 0) {
return;
}