Don't set the hunger, only cancel the events

This commit is contained in:
Eric Stokes 2011-09-22 19:47:14 -06:00
parent 268b272f4d
commit 65dce752d4
2 changed files with 13 additions and 10 deletions

View File

@ -45,8 +45,10 @@ public class MVEntityListener extends EntityListener {
Player p = (Player) event.getEntity();
MVWorld w = this.plugin.getWorldManager().getMVWorld(p.getWorld().getName());
if(w != null && !w.getHunger()) {
// If the world has hunger set to false, do not let the level change
event.setFoodLevel(20);
// If the world has hunger set to false, do not let the level go down
if(event.getFoodLevel() < ((Player) event.getEntity()).getFoodLevel()) {
event.setCancelled(true);
}
}
}
}

View File

@ -132,14 +132,15 @@ public class MVPlayerListener extends PlayerListener {
MVWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
MVWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
event.setCancelled(checkWorldPermissions(fromWorld, toWorld, event.getPlayer()));
if (toWorld != null && !toWorld.getHunger() && fromWorld != null && fromWorld.getHunger() && !event.isCancelled()) {
// If to has hunger, and from doesn't, save the hunger
this.plugin.getPlayerSession(event.getPlayer()).setCachedHunger();
}
else if (toWorld != null && toWorld.getHunger() && fromWorld != null && !fromWorld.getHunger() && !event.isCancelled()) {
// If from has hunger, and to doesn't, restore the hunger
event.getPlayer().setFoodLevel(this.plugin.getPlayerSession(event.getPlayer()).getCachedHunger());
}
// Dunno If I like these... @fernferret
// if (toWorld != null && !toWorld.getHunger() && fromWorld != null && fromWorld.getHunger() && !event.isCancelled()) {
// // If to has hunger, and from doesn't, save the hunger
// this.plugin.getPlayerSession(event.getPlayer()).setCachedHunger();
// }
// else if (toWorld != null && toWorld.getHunger() && fromWorld != null && !fromWorld.getHunger() && !event.isCancelled()) {
// // If from has hunger, and to doesn't, restore the hunger
// event.getPlayer().setFoodLevel(this.plugin.getPlayerSession(event.getPlayer()).getCachedHunger());
// }
}
@Override