Fix for inventory window id generation (#1292)

This commit is contained in:
Konstantin Shandurenko 2022-07-30 19:54:10 +03:00 committed by GitHub
parent edbef66f8e
commit 89a09f326e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -58,7 +58,11 @@ public non-sealed class Inventory extends AbstractInventory implements Viewable
}
private static byte generateId() {
return (byte) Math.abs((byte) ID_COUNTER.incrementAndGet());
final byte id = (byte) Math.abs((byte) ID_COUNTER.incrementAndGet());
if (id == 0) { // zero is player's inventory id
return generateId();
}
return id;
}
/**

View File

@ -75,4 +75,12 @@ public class InventoryTest {
assertTrue(inventory.addItemStack(ItemStack.of(Material.ANDESITE, 32), TransactionOption.ALL_OR_NOTHING));
assertFalse(inventory.addItemStack(ItemStack.of(Material.BLUE_CONCRETE, 32), TransactionOption.ALL_OR_NOTHING));
}
@Test
public void testIds() {
for (int i = 0; i <= 256; ++i) {
final Inventory inventory = new Inventory(InventoryType.CHEST_1_ROW, "title");
assertTrue(inventory.getWindowId() != 0);
}
}
}