mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-15 15:16:46 +01:00
Fix inventory id overflow
This commit is contained in:
parent
c57e35c58a
commit
97f2f3f06c
@ -19,7 +19,6 @@ import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Represents an inventory which can be viewed by a collection of {@link Player}.
|
||||
@ -30,7 +29,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
public class Inventory extends AbstractInventory implements Viewable {
|
||||
|
||||
// incremented each time an inventory is created (used in the window packets)
|
||||
private static final AtomicInteger LAST_INVENTORY_ID = new AtomicInteger();
|
||||
private static byte LAST_INVENTORY_ID = 1;
|
||||
|
||||
// the id of this inventory
|
||||
private final byte id;
|
||||
@ -60,11 +59,13 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
this(inventoryType, Component.text(title));
|
||||
}
|
||||
|
||||
private static byte generateId() {
|
||||
byte newInventoryId = (byte) LAST_INVENTORY_ID.incrementAndGet();
|
||||
if (newInventoryId == Byte.MAX_VALUE)
|
||||
newInventoryId = 1;
|
||||
return newInventoryId;
|
||||
private static synchronized byte generateId() {
|
||||
if (LAST_INVENTORY_ID != Byte.MAX_VALUE) {
|
||||
return ++LAST_INVENTORY_ID;
|
||||
} else {
|
||||
LAST_INVENTORY_ID = 1;
|
||||
return LAST_INVENTORY_ID;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user