Skip to content

Commit 75a25ce

Browse files
committed
only reopen inventory for Menu#setTitle if menu is open
1 parent fb27953 commit 75a25ce

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

  • core/src/main/java/net/j4c0b3y/api/menu

core/src/main/java/net/j4c0b3y/api/menu/Menu.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ public void open() {
180180
}, async);
181181
}
182182

183+
/**
184+
* Updates the inventory's title while open.
185+
*
186+
* @param title The new title.
187+
*/
183188
public void setTitle(String title) {
184189
this.title = title;
185190

@@ -190,10 +195,14 @@ public void setTitle(String title) {
190195
inventory.setContents(this.inventory.getContents());
191196
this.inventory = inventory;
192197

193-
// Open the new inventory for the player.
194-
handler.schedule(() ->
195-
player.openInventory(this.inventory)
196-
);
198+
handler.ifOpen(player, menu -> {
199+
if (menu != this) return;
200+
201+
// Open the new inventory for the player.
202+
handler.schedule(() ->
203+
player.openInventory(this.inventory)
204+
);
205+
});
197206
}
198207

199208
/**

0 commit comments

Comments
 (0)