mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-16 21:21:22 +01:00
Potentially fix cursor ghost item when opening a new inventory
This commit is contained in:
parent
b662e331f0
commit
4eaa15477b
@ -1928,9 +1928,9 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
InventoryOpenEvent inventoryOpenEvent = new InventoryOpenEvent(inventory, this);
|
||||
|
||||
callCancellableEvent(InventoryOpenEvent.class, inventoryOpenEvent, () -> {
|
||||
|
||||
if (getOpenInventory() != null) {
|
||||
getOpenInventory().removeViewer(this);
|
||||
Inventory openInventory = getOpenInventory();
|
||||
if (openInventory != null) {
|
||||
openInventory.removeViewer(this);
|
||||
}
|
||||
|
||||
Inventory newInventory = inventoryOpenEvent.getInventory();
|
||||
|
@ -174,7 +174,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
@Override
|
||||
public boolean removeViewer(@NotNull Player player) {
|
||||
final boolean result = this.viewers.remove(player);
|
||||
this.cursorPlayersItem.remove(player);
|
||||
setCursorItem(player, ItemStack.AIR);
|
||||
this.clickProcessor.clearCache(player);
|
||||
return result;
|
||||
}
|
||||
@ -198,18 +198,19 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
* @param cursorItem the new player cursor item
|
||||
*/
|
||||
public void setCursorItem(@NotNull Player player, @NotNull ItemStack cursorItem) {
|
||||
if (!isViewer(player))
|
||||
return;
|
||||
|
||||
final ItemStack currentCursorItem = cursorPlayersItem.get(player);
|
||||
final boolean similar = currentCursorItem != null && currentCursorItem.isSimilar(cursorItem);
|
||||
final ItemStack currentCursorItem = cursorPlayersItem.getOrDefault(player, ItemStack.AIR);
|
||||
final boolean similar = currentCursorItem.isSimilar(cursorItem);
|
||||
|
||||
if (!similar) {
|
||||
final SetSlotPacket setSlotPacket = SetSlotPacket.createCursorPacket(cursorItem);
|
||||
player.getPlayerConnection().sendPacket(setSlotPacket);
|
||||
}
|
||||
|
||||
this.cursorPlayersItem.put(player, cursorItem);
|
||||
if (!cursorItem.isAir()) {
|
||||
this.cursorPlayersItem.put(player, cursorItem);
|
||||
} else {
|
||||
this.cursorPlayersItem.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user