mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-01 05:58:00 +01:00
Drop cursor item when closing inventory
This commit is contained in:
parent
47ca22c3d1
commit
dff29a4717
@ -942,12 +942,25 @@ public class Player extends LivingEntity {
|
||||
*/
|
||||
public void closeInventory() {
|
||||
Inventory openInventory = getOpenInventory();
|
||||
|
||||
// Drop cursor item when closing inventory
|
||||
ItemStack cursorItem;
|
||||
if (openInventory == null) {
|
||||
cursorItem = getInventory().getCursorItem();
|
||||
getInventory().setCursorItem(ItemStack.getAirItem());
|
||||
} else {
|
||||
cursorItem = openInventory.getCursorItem(this);
|
||||
}
|
||||
if (!cursorItem.isAir()) {
|
||||
dropItem(cursorItem);
|
||||
}
|
||||
|
||||
CloseWindowPacket closeWindowPacket = new CloseWindowPacket();
|
||||
if (openInventory == null) {
|
||||
closeWindowPacket.windowId = 0;
|
||||
} else {
|
||||
closeWindowPacket.windowId = openInventory.getWindowId();
|
||||
openInventory.removeViewer(this);
|
||||
openInventory.removeViewer(this); // Clear cache
|
||||
refreshOpenInventory(null);
|
||||
}
|
||||
playerConnection.sendPacket(closeWindowPacket);
|
||||
|
@ -127,6 +127,8 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
@Override
|
||||
public void removeViewer(Player player) {
|
||||
this.viewers.remove(player);
|
||||
this.cursorPlayersItem.remove(player);
|
||||
this.clickProcessor.clearCache(player);
|
||||
}
|
||||
|
||||
public ItemStack getCursorItem(Player player) {
|
||||
|
@ -532,4 +532,9 @@ public class InventoryClickProcessor {
|
||||
player.callEvent(InventoryClickEvent.class, inventoryClickEvent);
|
||||
}
|
||||
|
||||
public void clearCache(Player player) {
|
||||
this.leftDraggingMap.remove(player);
|
||||
this.rightDraggingMap.remove(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -153,18 +153,20 @@ public class StorageFolder {
|
||||
* @param key the specified cached data key
|
||||
*/
|
||||
public void saveAndRemoveCachedData(String key) {
|
||||
SerializableData serializableData = cachedData.get(key);
|
||||
if (serializableData == null)
|
||||
return;
|
||||
synchronized (cachedData) {
|
||||
SerializableData serializableData = cachedData.get(key);
|
||||
if (serializableData == null)
|
||||
return;
|
||||
|
||||
try {
|
||||
set(key, serializableData.getSerializedData());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
set(key, serializableData.getSerializedData());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Remove from map
|
||||
this.cachedData.remove(key);
|
||||
}
|
||||
|
||||
// Remove from map
|
||||
this.cachedData.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user