mirror of
https://github.com/Minestom/Minestom.git
synced 2024-06-25 22:14:53 +02:00
Fix inventory close regression
This commit is contained in:
parent
67e6686acc
commit
93421e1740
|
@ -183,7 +183,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||
protected PlayerInventory inventory;
|
||||
private Inventory openInventory;
|
||||
// Used internally to allow the closing of inventory within the inventory listener
|
||||
private boolean didCloseInventory;
|
||||
private boolean skipClosePacket;
|
||||
|
||||
private byte heldSlot;
|
||||
|
||||
|
@ -1729,11 +1729,11 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||
return openInventory;
|
||||
}
|
||||
|
||||
private void tryCloseInventory(boolean fromClient) {
|
||||
private void tryCloseInventory(boolean skipClosePacket) {
|
||||
var closedInventory = getOpenInventory();
|
||||
if (closedInventory == null) return;
|
||||
|
||||
didCloseInventory = fromClient;
|
||||
this.skipClosePacket = skipClosePacket;
|
||||
|
||||
if (closedInventory.removeViewer(this)) {
|
||||
if (closedInventory == getOpenInventory()) {
|
||||
|
@ -1752,7 +1752,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||
InventoryOpenEvent inventoryOpenEvent = new InventoryOpenEvent(inventory, this);
|
||||
|
||||
EventDispatcher.callCancellable(inventoryOpenEvent, () -> {
|
||||
tryCloseInventory(false);
|
||||
tryCloseInventory(true);
|
||||
|
||||
Inventory newInventory = inventoryOpenEvent.getInventory();
|
||||
if (newInventory.addViewer(this)) {
|
||||
|
@ -1777,27 +1777,23 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||
}
|
||||
|
||||
/**
|
||||
* Used internally to prevent an inventory click to be processed
|
||||
* when the inventory listeners closed the inventory.
|
||||
* <p>
|
||||
* Should only be used within an inventory listener (event or condition).
|
||||
*
|
||||
* @return true if the inventory has been closed, false otherwise
|
||||
* Used internally to determine when sending the close inventory packet should be skipped.
|
||||
*/
|
||||
public boolean didCloseInventory() {
|
||||
return didCloseInventory;
|
||||
public boolean skipClosePacket() {
|
||||
return skipClosePacket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used internally to reset the didCloseInventory field.
|
||||
* Used internally to reset the skipClosePacket field, which determines when sending the close inventory packet
|
||||
* should be skipped.
|
||||
* <p>
|
||||
* Shouldn't be used externally without proper understanding of its consequence.
|
||||
*
|
||||
* @param didCloseInventory the new didCloseInventory field
|
||||
* @param skipClosePacket the new skipClosePacket field
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void UNSAFE_changeDidCloseInventory(boolean didCloseInventory) {
|
||||
this.didCloseInventory = didCloseInventory;
|
||||
public void UNSAFE_changeSkipClosePacket(boolean skipClosePacket) {
|
||||
this.skipClosePacket = skipClosePacket;
|
||||
}
|
||||
|
||||
public int getNextTeleportId() {
|
||||
|
|
|
@ -79,8 +79,8 @@ sealed abstract class InventoryImpl implements Inventory permits ContainerInvent
|
|||
}
|
||||
|
||||
player.clickPreprocessor().clearCache();
|
||||
if (player.didCloseInventory()) {
|
||||
player.UNSAFE_changeDidCloseInventory(false);
|
||||
if (player.skipClosePacket()) {
|
||||
player.UNSAFE_changeSkipClosePacket(false);
|
||||
} else {
|
||||
player.sendPacket(new CloseWindowPacket(getWindowId()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user