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(); Player p = (Player) event.getEntity();
MVWorld w = this.plugin.getWorldManager().getMVWorld(p.getWorld().getName()); MVWorld w = this.plugin.getWorldManager().getMVWorld(p.getWorld().getName());
if(w != null && !w.getHunger()) { if(w != null && !w.getHunger()) {
// If the world has hunger set to false, do not let the level change // If the world has hunger set to false, do not let the level go down
event.setFoodLevel(20); 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 fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
MVWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName()); MVWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
event.setCancelled(checkWorldPermissions(fromWorld, toWorld, event.getPlayer())); event.setCancelled(checkWorldPermissions(fromWorld, toWorld, event.getPlayer()));
if (toWorld != null && !toWorld.getHunger() && fromWorld != null && fromWorld.getHunger() && !event.isCancelled()) { // Dunno If I like these... @fernferret
// If to has hunger, and from doesn't, save the hunger // if (toWorld != null && !toWorld.getHunger() && fromWorld != null && fromWorld.getHunger() && !event.isCancelled()) {
this.plugin.getPlayerSession(event.getPlayer()).setCachedHunger(); // // 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 // else if (toWorld != null && toWorld.getHunger() && fromWorld != null && !fromWorld.getHunger() && !event.isCancelled()) {
event.getPlayer().setFoodLevel(this.plugin.getPlayerSession(event.getPlayer()).getCachedHunger()); // // If from has hunger, and to doesn't, restore the hunger
} // event.getPlayer().setFoodLevel(this.plugin.getPlayerSession(event.getPlayer()).getCachedHunger());
// }
} }
@Override @Override