diff --git a/api/src/main/java/com/github/retrooper/packetevents/util/adventure/AdventureNBTSerializer.java b/api/src/main/java/com/github/retrooper/packetevents/util/adventure/AdventureNBTSerializer.java index 5d448cbd78..65a22bcfb8 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/util/adventure/AdventureNBTSerializer.java +++ b/api/src/main/java/com/github/retrooper/packetevents/util/adventure/AdventureNBTSerializer.java @@ -346,7 +346,7 @@ public AdventureNBTSerializer(boolean downsampleColor) { } else { NBTReader child = hoverEvent.child("contents"); Key itemId = child.readUTF("id", Key::key); - Integer count = child.readInt("count", Function.identity()); + Integer count = child.readNumber("count", Number::intValue); int nonNullCount = count == null ? 1 : count; BinaryTagHolder tag = child.readUTF("tag", BinaryTagHolder::binaryTagHolder); @@ -598,36 +598,24 @@ public R readShort(String key, Function function) { return withTag(key, tag -> function.apply(requireType(tag, NBTType.SHORT).getAsShort())); } - public void useInt(String key, Consumer consumer) { - useTag(key, tag -> consumer.accept(requireType(tag, NBTType.INT).getAsInt())); - } - - public R readInt(String key, Function function) { - return withTag(key, tag -> function.apply(requireType(tag, NBTType.INT).getAsInt())); - } - - public void useLong(String key, Consumer consumer) { - useTag(key, tag -> consumer.accept(requireType(tag, NBTType.LONG).getAsLong())); - } - - public R readLong(String key, Function function) { - return withTag(key, tag -> function.apply(requireType(tag, NBTType.LONG).getAsLong())); - } - - public void useFloat(String key, Consumer consumer) { - useTag(key, tag -> consumer.accept(requireType(tag, NBTType.FLOAT).getAsFloat())); - } - - public R readFloat(String key, Function function) { - return withTag(key, tag -> function.apply(requireType(tag, NBTType.FLOAT).getAsFloat())); - } - - public void useDouble(String key, Consumer consumer) { - useTag(key, tag -> consumer.accept(requireType(tag, NBTType.DOUBLE).getAsDouble())); + public void useNumber(String key, Consumer consumer) { + useTag(key, tag -> { + if (tag instanceof NBTNumber) { + consumer.accept(((NBTNumber) tag).getAsNumber()); + } else { + throw new IllegalArgumentException("Expected number but got " + tag.getType()); + } + }); } - public R readDouble(String key, Function function) { - return withTag(key, tag -> function.apply(requireType(tag, NBTType.DOUBLE).getAsDouble())); + public R readNumber(String key, Function function) { + return withTag(key, tag -> { + if (tag instanceof NBTNumber) { + return function.apply(((NBTNumber) tag).getAsNumber()); + } else { + throw new IllegalArgumentException("Expected number but got " + tag.getType()); + } + }); } public void useUTF(String key, Consumer consumer) {