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);
}
Aggregations