Skip to content

Commit

Permalink
Issue with the inventory closing (#73)
Browse files Browse the repository at this point in the history
* need to close inventory after one ticks to prevent issues with inventories

* Update InventoryGui.java

typo and forget to delay the reopening

Co-authored-by: valentin <valentin.jabre@gmail.com>
Co-authored-by: Amaury Carrade <amaury@carrade.eu>
  • Loading branch information
3 people authored Apr 11, 2021
1 parent c64b5d7 commit 7ccbeef
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/java/fr/zcraft/quartzlib/components/gui/InventoryGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public abstract class InventoryGui extends GuiBase {
* Returns if the given event affects the GUI's inventory.
*
* @param event The event to test
* @return true if any of the event's slots is in the GUI's inventory,
* false otherwise.
* @return true if any of the event's slots is in the GUI's inventory, false otherwise.
*/
protected static boolean affectsGui(final InventoryDragEvent event) {
for (int slot : event.getRawSlots()) {
Expand Down Expand Up @@ -194,8 +193,12 @@ public void update() {
// Reopening the inventory
// FIXME This probably resets the player' mouse cursor position to the center of the GUI in 1.13.
if (isOpen()) {
player.closeInventory();
player.openInventory(inventory);
RunTask.nextTick(() -> {
player.closeInventory();
RunTask.nextTick(() -> {
player.openInventory(inventory);
});
});
}
}
}
Expand All @@ -204,6 +207,7 @@ public void update() {

/**
* Gets the size of the inventory.
*
* @return The size of the inventory.
*/
protected final int getSize() {
Expand Down Expand Up @@ -238,6 +242,7 @@ protected final void setHeight(final int height) {

/**
* Returns the title of the inventory.
*
* @return The title of the inventory.
*/
protected String getTitle() {
Expand All @@ -259,6 +264,7 @@ protected void setTitle(String title) {

/**
* Gets the underlying inventory, or null if the Gui has not been opened yet.
*
* @return The underlying inventory, or null if the Gui has not been opened yet.
*/
public Inventory getInventory() {
Expand Down

0 comments on commit 7ccbeef

Please sign in to comment.