diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java index 2aa77487..c01035ca 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java @@ -57,6 +57,7 @@ import org.bukkit.event.entity.EntityListener; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.PigZapEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; @@ -115,6 +116,7 @@ public void registerEvents() { registerEvent("ENDERMAN_PICKUP", Priority.High); registerEvent("ENDERMAN_PLACE", Priority.High); registerEvent("ENTITY_DEATH", Priority.High); + registerEvent("FOOD_LEVEL_CHANGE", Priority.High); } /** @@ -856,6 +858,16 @@ public void onEndermanPlace(EndermanPlaceEvent event) { } } + @Override + public void onFoodLevelChange(FoodLevelChangeEvent event) { + if (event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + if (event.getFoodLevel() < player.getFoodLevel() && isInvincible(player)) { + event.setCancelled(true); + } + } + } + /** * Check if a player is invincible, via either god mode or region flag. If * the region denies invincibility, the player must have an extra permission diff --git a/src/main/java/com/sk89q/worldguard/bukkit/commands/GeneralCommands.java b/src/main/java/com/sk89q/worldguard/bukkit/commands/GeneralCommands.java index 23047fcd..23b6d6a3 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/commands/GeneralCommands.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/commands/GeneralCommands.java @@ -154,6 +154,7 @@ public static void heal(CommandContext args, WorldGuardPlugin plugin, for (Player player : targets) { player.setHealth(20); + player.setFoodLevel(20); // Tell the user if (player.equals(sender)) {