Skip to content

Commit

Permalink
Update off hand items when closing a gui
Browse files Browse the repository at this point in the history
Due to what appears to be a client issue, the client rejects off hand modifications from the server when an inventory is opened, which causes #95. To slightly mitigate this in the mean time, the off hand will be updated when a gui is closed.
  • Loading branch information
stefvanschie committed Dec 26, 2020
1 parent 33bd598 commit ebc041e
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,14 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) {
return;
}

HumanEntity humanEntity = event.getPlayer();
PlayerInventory playerInventory = humanEntity.getInventory();

//due to a client issue off-hand items appear as ghost items, this updates the off-hand correctly client-side
playerInventory.setItemInOffHand(playerInventory.getItemInOffHand());

if (gui.isUpdating()) {
gui.getHumanEntityCache().restoreAndForget(event.getPlayer());
gui.getHumanEntityCache().restoreAndForget(humanEntity);

if (gui.getViewerCount() == 1) {
activeGuiInstances.remove(gui);
Expand All @@ -305,8 +311,6 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) {

//this is a hack to remove items correctly when players press the x button in a beacon
Bukkit.getScheduler().runTask(JavaPlugin.getProvidingPlugin(getClass()), () -> {
HumanEntity humanEntity = event.getPlayer();

if (humanEntity.getOpenInventory().getTopInventory() instanceof PlayerInventory) {
humanEntity.closeInventory();
}
Expand Down

0 comments on commit ebc041e

Please sign in to comment.