mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-29 03:21:20 +01:00
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:
parent
4398c781c5
commit
e0e4207a4d
@ -121,6 +121,10 @@ private void processHeal(ApplicableRegionSet applicable, Player player,
|
|||||||
if (minHealth == null) minHealth = 0;
|
if (minHealth == null) minHealth = 0;
|
||||||
if (maxHealth == null) maxHealth = 20;
|
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) {
|
if (player.getHealth() >= maxHealth && healAmount > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -158,6 +162,10 @@ private void processFeed(ApplicableRegionSet applicable, Player player,
|
|||||||
if (minHunger == null) minHunger = 0;
|
if (minHunger == null) minHunger = 0;
|
||||||
if (maxHunger == null) maxHunger = 20;
|
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) {
|
if (player.getFoodLevel() >= maxHunger && feedAmount > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user