Prevent corrupted item stack from crashing the server

This commit is contained in:
themode 2020-11-13 03:39:00 +01:00
parent 1e30283733
commit 72d941bc74
3 changed files with 12 additions and 3 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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) {