All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minestom.server.inventory.InventoryClickHandler Maven / Gradle / Ivy

There is a newer version: 7320437640
Show newest version
package net.minestom.server.inventory;

import net.minestom.server.entity.Player;
import net.minestom.server.event.EventDispatcher;
import net.minestom.server.event.inventory.InventoryClickEvent;
import net.minestom.server.inventory.click.ClickType;
import net.minestom.server.item.ItemStack;
import org.jetbrains.annotations.NotNull;

/**
 * Represents an inventory which can receive click input.
 * All methods returning boolean returns true if the action is successful, false otherwise.
 * 

* See https://wiki.vg/Protocol#Click_Window for more information. */ public sealed interface InventoryClickHandler permits AbstractInventory { /** * Called when a {@link Player} left click in the inventory. Can also be to drop the cursor item * * @param player the player who clicked * @param slot the slot number * @return true if the click hasn't been cancelled, false otherwise */ boolean leftClick(@NotNull Player player, int slot); /** * Called when a {@link Player} right click in the inventory. Can also be to drop the cursor item * * @param player the player who clicked * @param slot the slot number * @return true if the click hasn't been cancelled, false otherwise */ boolean rightClick(@NotNull Player player, int slot); /** * Called when a {@link Player} shift click in the inventory * * @param player the player who clicked * @param slot the slot number * @return true if the click hasn't been cancelled, false otherwise */ boolean shiftClick(@NotNull Player player, int slot); // shift + left/right click have the same behavior /** * Called when a {@link Player} held click in the inventory * * @param player the player who clicked * @param slot the slot number * @param key the held slot (0-8) pressed * @return true if the click hasn't been cancelled, false otherwise */ boolean changeHeld(@NotNull Player player, int slot, int key); boolean middleClick(@NotNull Player player, int slot); /** * Called when a {@link Player} press the drop button * * @param player the player who clicked * @param all * @param slot the slot number * @param button -999 if clicking outside, normal if he is not * @return true if the drop hasn't been cancelled, false otherwise */ boolean drop(@NotNull Player player, boolean all, int slot, int button); boolean dragging(@NotNull Player player, int slot, int button); /** * Called when a {@link Player} double click in the inventory * * @param player the player who clicked * @param slot the slot number * @return true if the click hasn't been cancelled, false otherwise */ boolean doubleClick(@NotNull Player player, int slot); default void callClickEvent(@NotNull Player player, Inventory inventory, int slot, @NotNull ClickType clickType, @NotNull ItemStack clicked, @NotNull ItemStack cursor) { EventDispatcher.call(new InventoryClickEvent(inventory, player, slot, clickType, clicked, cursor)); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy