package me.otisdiver.otisarena.event;

import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;

import me.otisdiver.otisarena.OtisArena;

public class LobbyGuard extends EasyListener {
    
    private final String lobbyName;
    
    /** LobbyGuard stops human damage in the lobby.
     * 
     * @param main instance of JavaPlugin
     */
    public LobbyGuard(OtisArena main) {
        super(main);
        lobbyName = main.getGame().getLobby();
    }
    
    // Event handlers
    
    @EventHandler(priority = EventPriority.LOW)
    public void onHunger(FoodLevelChangeEvent e) {
        if (inLobby(e.getEntity())) cancel(e);
    }
    
    @EventHandler(priority = EventPriority.LOW)
    public void onDamage(EntityDamageEvent e) {
        if (inLobby(e.getEntity())) cancel(e);
    }
    
    @EventHandler(priority = EventPriority.LOW)
    public void onDrop(PlayerDropItemEvent e) {
        if (inLobby(e.getPlayer())) cancel(e);
    }
    
    @EventHandler(priority = EventPriority.LOW)
    public void onInvEdit(InventoryClickEvent e) {
        if (inLobby(e.getWhoClicked())) cancel(e);
    }
    
    // Super lazy shortcut methods
    
    private boolean inLobby(Entity p) {
        return p.getWorld().getName().equals(lobbyName);
    }
    
    private void cancel(Cancellable e) {
        e.setCancelled(true);
    }
    
}

@@ -28,24 +28,52 @@
 ena.event;%0A%0A
+import org.bukkit.GameMode;%0A
 import org.b
@@ -1377,32 +1377,33 @@
 ) %7B%0A        if (
+!
 inLobby(e.getWho
@@ -1409,24 +1409,104 @@
 oClicked()))
+ return;%0A        if (!e.getWhoClicked().getGameMode().equals(GameMode.CREATIVE))
  cancel(e);%0A

update - allow inventory edits in creative mode