mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-07 11:20:09 +01:00
Prevent corrupted item stack from crashing the server
This commit is contained in:
parent
1e30283733
commit
72d941bc74
@ -13,8 +13,9 @@ public class CreativeInventoryActionListener {
|
||||
if (player.getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
|
||||
final ItemStack item = packet.item;
|
||||
short slot = packet.slot;
|
||||
final ItemStack item = packet.item;
|
||||
|
||||
if (slot != -1) {
|
||||
// Set item
|
||||
slot = (short) PlayerInventoryUtils.convertSlot(slot, PlayerInventoryUtils.OFFSET);
|
||||
|
@ -94,7 +94,7 @@ public final class NBTUtils {
|
||||
nbt.set(listName, enchantList);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
public static ItemStack readItemStack(@NotNull BinaryReader reader) {
|
||||
final boolean present = reader.readBoolean();
|
||||
|
||||
|
@ -137,8 +137,16 @@ public class BinaryReader extends InputStream {
|
||||
return new UUID(most, least);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to read an {@link ItemStack}.
|
||||
*
|
||||
* @return the read item
|
||||
* @throws NullPointerException if the item could not get read
|
||||
*/
|
||||
public ItemStack readSlot() {
|
||||
return NBTUtils.readItemStack(this);
|
||||
final ItemStack itemStack = NBTUtils.readItemStack(this);
|
||||
Check.notNull(itemStack, "#readSlot returned null, probably because the buffer was corrupted");
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public JsonMessage readJsonMessage(int maxLength) {
|
||||
|
Loading…
Reference in New Issue
Block a user