mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 00:21:26 +01:00
Do not send CloseWindowPacket if inventory was reopened during closing (#1218)
This commit is contained in:
parent
4feac211c7
commit
de5a396c15
@ -1446,6 +1446,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (openInventory == getOpenInventory()) {
|
||||||
CloseWindowPacket closeWindowPacket;
|
CloseWindowPacket closeWindowPacket;
|
||||||
if (openInventory == null) {
|
if (openInventory == null) {
|
||||||
closeWindowPacket = new CloseWindowPacket((byte) 0);
|
closeWindowPacket = new CloseWindowPacket((byte) 0);
|
||||||
@ -1458,6 +1459,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
inventory.update();
|
inventory.update();
|
||||||
this.didCloseInventory = true;
|
this.didCloseInventory = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used internally to prevent an inventory click to be processed
|
* Used internally to prevent an inventory click to be processed
|
||||||
|
@ -4,7 +4,7 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.minestom.server.api.Env;
|
import net.minestom.server.api.Env;
|
||||||
import net.minestom.server.api.EnvTest;
|
import net.minestom.server.api.EnvTest;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.entity.EquipmentSlot;
|
import net.minestom.server.event.item.ItemDropEvent;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.item.Material;
|
import net.minestom.server.item.Material;
|
||||||
import net.minestom.server.network.packet.server.play.EntityEquipmentPacket;
|
import net.minestom.server.network.packet.server.play.EntityEquipmentPacket;
|
||||||
@ -12,9 +12,7 @@ import net.minestom.server.network.packet.server.play.SetSlotPacket;
|
|||||||
import net.minestom.server.network.packet.server.play.WindowItemsPacket;
|
import net.minestom.server.network.packet.server.play.WindowItemsPacket;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Map;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
@EnvTest
|
@EnvTest
|
||||||
public class InventoryIntegrationTest {
|
public class InventoryIntegrationTest {
|
||||||
@ -112,4 +110,39 @@ public class InventoryIntegrationTest {
|
|||||||
equipmentTracker.assertEmpty();
|
equipmentTracker.assertEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void closeInventoryTest(Env env) {
|
||||||
|
var instance = env.createFlatInstance();
|
||||||
|
var connection = env.createConnection();
|
||||||
|
var player = connection.connect(instance, new Pos(0, 42, 0)).join();
|
||||||
|
final var inventory = new Inventory(InventoryType.CHEST_1_ROW, "title");
|
||||||
|
player.openInventory(inventory);
|
||||||
|
assertSame(inventory, player.getOpenInventory());
|
||||||
|
player.closeInventory();
|
||||||
|
assertNull(player.getOpenInventory());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void openInventoryOnItemDropFromInventoryClosingTest(Env env) {
|
||||||
|
var instance = env.createFlatInstance();
|
||||||
|
var connection = env.createConnection();
|
||||||
|
var player = connection.connect(instance, new Pos(0, 42, 0)).join();
|
||||||
|
var listener = env.listen(ItemDropEvent.class);
|
||||||
|
final var firstInventory = new Inventory(InventoryType.CHEST_1_ROW, "title");
|
||||||
|
player.openInventory(firstInventory);
|
||||||
|
assertSame(firstInventory, player.getOpenInventory());
|
||||||
|
firstInventory.setCursorItem(player, ItemStack.of(Material.STONE));
|
||||||
|
|
||||||
|
listener.followup();
|
||||||
|
player.closeInventory();
|
||||||
|
assertNull(player.getOpenInventory());
|
||||||
|
|
||||||
|
player.openInventory(firstInventory);
|
||||||
|
firstInventory.setCursorItem(player, ItemStack.of(Material.STONE));
|
||||||
|
final var secondInventory = new Inventory(InventoryType.CHEST_1_ROW, "title");
|
||||||
|
listener.followup(event -> event.getPlayer().openInventory(secondInventory));
|
||||||
|
player.closeInventory();
|
||||||
|
assertSame(secondInventory, player.getOpenInventory());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user