Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: modify some methods #276

Merged
merged 6 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/main/java/minevalley/core/api/gui/InventoryGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
public interface InventoryGui {

/**
* Gets a copy of the underlying inventory of this GUI.
* Gets the underlying inventory of this GUI.
*
* @return a copy of the underlying inventory of this GUI
* @return the underlying inventory of this GUI
*/
@Nonnull
@Contract(pure = true)
Expand Down Expand Up @@ -180,14 +180,14 @@ default InventoryGui setItem(@Nonnegative int slot, @Nonnull InterfaceItem item,
InventoryGui onClickSlot(@Nonnegative int slot, @Nonnull BiConsumer<OnlineUser, InventoryClickEvent> onClick) throws IllegalArgumentException;

/**
* Adds a callback to be called when this GUI is closed.
* Removes the callback for the specified slot.
*
* @param callback the callback to call
* @param slot the slot to remove the callback for
* @return this GUI
* @throws IllegalArgumentException if the slot is out of bounds
*/
@Nonnull
@Contract("_ -> this")
InventoryGui onClose(@Nullable Consumer<OnlineUser> callback);
InventoryGui removeSlotCallback(@Nonnegative int slot) throws IllegalArgumentException;

/**
* Adds a callback to be called when this GUI is closed.
Expand All @@ -197,7 +197,7 @@ default InventoryGui setItem(@Nonnegative int slot, @Nonnull InterfaceItem item,
*/
@Nonnull
@Contract("_ -> this")
InventoryGui onClose(@Nullable BiConsumer<OnlineUser, Inventory> callback);
InventoryGui onClose(@Nullable Consumer<OnlineUser> callback);

/**
* Adds a callback to be called when the close button is clicked.
Expand Down Expand Up @@ -235,17 +235,14 @@ default InventoryGui setItem(@Nonnegative int slot, @Nonnull InterfaceItem item,

/**
* Updates the title of this GUI.
* This will send a packet to all viewers to update the title.
* <p>
* <b>Note:</b> calling this method only updates the title for users that already opened this GUI. If you want to update the title for upcoming users, set the {@code updateInventory} parameter to true.
*
* @param title the new title
* @param updateInventory whether to update the inventory
* @param title the new title
* @return this GUI
* @throws IllegalArgumentException if the title is null
*/
@Nonnull
@Contract(pure = true)
InventoryGui updateTitle(@Nonnull Component title, boolean updateInventory) throws IllegalArgumentException;
InventoryGui updateTitle(@Nonnull Component title) throws IllegalArgumentException;

/**
* Opens this GUI for the specified player.
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/minevalley/core/api/gui/MultiPageGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ MultiPageGui setPageDependantItem(@Nonnegative int slot, @Nonnull Function<Integ
* @return the inventory of the specified page
* @throws IllegalArgumentException if the page is out of bounds
*/
@Nonnull
Inventory getInventory(@Nonnegative int page) throws IllegalArgumentException;

/**
Expand Down Expand Up @@ -111,8 +112,7 @@ MultiPageGui setPageDependantItem(@Nonnegative int slot, @Nonnull Function<Integ
* @return a copy of the underlying inventory of this GUI
*/
@Override
@Nonnull
default Inventory getInventory() {
default @Nonnull Inventory getInventory() {
return getInventory(0);
}

Expand All @@ -124,8 +124,8 @@ default Inventory getInventory() {
* @return nothing
*/
@Override
@Contract("_, _ -> fail")
default InventoryGui updateTitle(@Nonnull Component title, boolean updateInventory) {
@Contract("_ -> fail")
default @Nonnull InventoryGui updateTitle(@Nonnull Component title) {
throw new UnsupportedOperationException("This GUI does not support updating the title.");
}

Expand Down
Loading