Search in sources :

Example 1 with ChestAction

use of com.massivecraft.massivecore.chestgui.ChestAction in project MassiveCore by MassiveCraft.

the class EngineMassiveCoreChestGui method onClick.

// -------------------------------------------- //
// LISTENER
// -------------------------------------------- //
@EventHandler(priority = EventPriority.LOW)
public void onClick(InventoryClickEvent event) {
    // If this inventory ...
    Inventory inventory = event.getInventory();
    if (inventory == null)
        return;
    // ... is a gui ...
    ChestGui gui = ChestGui.get(inventory);
    if (gui == null)
        return;
    // ... then cancel the event ...
    event.setCancelled(true);
    event.setResult(Result.DENY);
    // ... warn on bottom inventory ...
    if (InventoryUtil.isBottomInventory(event)) {
        // ... only if its not allowed.
        if (gui.isBottomInventoryAllowed()) {
            event.setCancelled(false);
            event.setResult(Result.DEFAULT);
        } else {
            MixinMessage.get().msgOne(event.getWhoClicked(), "<b>Exit the GUI to edit your items.");
        }
        return;
    }
    // ... and if this slot index ...
    int index = event.getSlot();
    // ... has an action ...
    ChestAction action = gui.getAction(index);
    if (action == null)
        return;
    // ... set last action ...
    gui.setLastAction(action);
    // ... then play click sound ...
    SoundEffect sound = gui.getSoundClick();
    if (sound != null)
        sound.run(event.getWhoClicked());
    // ... close the GUI ...
    if (gui.isAutoclosing())
        event.getView().close();
    // ... and use that action.
    action.onClick(event);
}
Also used : ChestGui(com.massivecraft.massivecore.chestgui.ChestGui) SoundEffect(com.massivecraft.massivecore.SoundEffect) ChestAction(com.massivecraft.massivecore.chestgui.ChestAction) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Aggregations

SoundEffect (com.massivecraft.massivecore.SoundEffect)1 ChestAction (com.massivecraft.massivecore.chestgui.ChestAction)1 ChestGui (com.massivecraft.massivecore.chestgui.ChestGui)1 EventHandler (org.bukkit.event.EventHandler)1 Inventory (org.bukkit.inventory.Inventory)1