Added food level support to godmode and /heal

This commit is contained in:
zml2008 2011-10-15 23:51:28 -07:00
parent 920860c298
commit e492b30178
2 changed files with 13 additions and 0 deletions

View File

@ -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

View File

@ -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)) {