From 88ddbe5ac6ac5aa0f18ade50aa376b25546fb058 Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Sat, 20 Jul 2019 21:40:24 +0200 Subject: [PATCH] Lock food level for players in the lobby or spectator area. There is no reason why food should be a thing in the lobby or spectator area. This commit effectively disables it for players in those places/states, while retaining the in-arena conditional logic based on the config-file setting. Fixes #514 --- changelog.md | 1 + .../garbagemule/MobArena/ArenaListener.java | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 1c170ee..7642acc 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,7 @@ These changes will (most likely) be included in the next version. ## [Unreleased] +- Food levels no longer deplete for players in the lobby and spectator area. ## [0.103.2] - 2019-04-23 - MobArena no longer touches the `flySpeed` player attribute when players join an arena. This should fix issues where a crash would result in players being "locked in the air" when trying to fly outside of the arena. It also introduces compatibility with plugins that use flight to augment player abilities. diff --git a/src/main/java/com/garbagemule/MobArena/ArenaListener.java b/src/main/java/com/garbagemule/MobArena/ArenaListener.java index deb8e51..aa8a64b 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaListener.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaListener.java @@ -949,15 +949,22 @@ public class ArenaListener } public void onFoodLevelChange(FoodLevelChangeEvent event) { - if (!arena.isRunning()) + if (!(event.getEntity() instanceof Player)) { return; + } - if (!(event.getEntity() instanceof Player) || !arena.inArena((Player) event.getEntity())) - return; + Player p = (Player) event.getEntity(); - // If the food level is locked, cancel all changes. - if (lockFoodLevel) - event.setCancelled(true); + if (arena.isRunning()) { + if (lockFoodLevel) { + event.setCancelled(true); + } + } else { + // Always locked in lobby/spec + if (arena.inLobby(p) || arena.inSpec(p)) { + event.setCancelled(true); + } + } } public void onPlayerAnimation(PlayerAnimationEvent event) {