|
2 | 2 |
|
3 | 3 | import com.github.stefvanschie.inventoryframework.gui.type.*; |
4 | 4 | import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; |
| 5 | +import com.github.stefvanschie.inventoryframework.util.DispatchUtil; |
| 6 | + |
5 | 7 | import org.bukkit.Bukkit; |
6 | 8 | import org.bukkit.entity.HumanEntity; |
7 | 9 | import org.bukkit.entity.Player; |
@@ -82,7 +84,7 @@ public void onInventoryClick(@NotNull InventoryClickEvent event) { |
82 | 84 | gui.click(event); |
83 | 85 |
|
84 | 86 | if (event.isCancelled()) { |
85 | | - Bukkit.getScheduler().runTask(this.plugin, () -> { |
| 87 | + DispatchUtil.runTaskFor(event.getWhoClicked(), this.plugin, () -> { |
86 | 88 | PlayerInventory playerInventory = event.getWhoClicked().getInventory(); |
87 | 89 |
|
88 | 90 | /* due to a client issue off-hand items appear as ghost items, this updates the off-hand correctly |
@@ -352,26 +354,31 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { |
352 | 354 | playerInventory.setItemInOffHand(playerInventory.getItemInOffHand()); |
353 | 355 |
|
354 | 356 | if (!gui.isUpdating()) { |
355 | | - gui.callOnClose(event); |
356 | | - |
357 | | - event.getInventory().clear(); //clear inventory to prevent items being put back |
358 | | - |
359 | | - gui.getHumanEntityCache().restoreAndForget(humanEntity); |
360 | | - |
361 | | - if (gui.getViewerCount() == 1) { |
362 | | - activeGuiInstances.remove(gui); |
363 | | - } |
364 | | - |
365 | | - if (gui instanceof AnvilGui) { |
366 | | - ((AnvilGui) gui).handleClose(humanEntity); |
367 | | - } else if (gui instanceof MerchantGui) { |
368 | | - ((MerchantGui) gui).handleClose(humanEntity); |
369 | | - } else if (gui instanceof ModernSmithingTableGui) { |
370 | | - ((ModernSmithingTableGui) gui).handleClose(humanEntity); |
371 | | - } |
372 | | - |
373 | | - //Bukkit doesn't like it if you open an inventory while the previous one is being closed |
374 | | - Bukkit.getScheduler().runTask(this.plugin, () -> gui.navigateToParent(humanEntity)); |
| 357 | + DispatchUtil.runTaskFor(humanEntity, this.plugin, () -> { |
| 358 | + gui.callOnClose(event); |
| 359 | + |
| 360 | + event.getInventory().clear(); //clear inventory to prevent items being put back |
| 361 | + |
| 362 | + }); |
| 363 | + |
| 364 | + DispatchUtil.runTaskFor(humanEntity, this.plugin, () -> { |
| 365 | + gui.getHumanEntityCache().restoreAndForget(humanEntity); |
| 366 | + |
| 367 | + if (gui.getViewerCount() == 1) { |
| 368 | + activeGuiInstances.remove(gui); |
| 369 | + } |
| 370 | + |
| 371 | + if (gui instanceof AnvilGui) { |
| 372 | + ((AnvilGui) gui).handleClose(humanEntity); |
| 373 | + } else if (gui instanceof MerchantGui) { |
| 374 | + ((MerchantGui) gui).handleClose(humanEntity); |
| 375 | + } else if (gui instanceof ModernSmithingTableGui) { |
| 376 | + ((ModernSmithingTableGui) gui).handleClose(humanEntity); |
| 377 | + } |
| 378 | + |
| 379 | + //Bukkit doesn't like it if you open an inventory while the previous one is being closed |
| 380 | + DispatchUtil.runTaskFor(humanEntity, this.plugin, () -> { gui.navigateToParent(humanEntity); }); |
| 381 | + }); |
375 | 382 | } |
376 | 383 | } |
377 | 384 |
|
|
0 commit comments