From d49530f9c40ebfa002fdbdd814e324a6cc9aee8a Mon Sep 17 00:00:00 2001 From: Wesley Smith Date: Fri, 21 May 2021 08:25:09 +1000 Subject: [PATCH] #845: Remove unnecessary calls to Class#getSimpleName in PDC --- .../CraftPersistentDataTypeRegistry.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataTypeRegistry.java b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataTypeRegistry.java index da08325dd..3eedbfd8b 100644 --- a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataTypeRegistry.java +++ b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataTypeRegistry.java @@ -19,7 +19,6 @@ import net.minecraft.nbt.NBTTagLong; import net.minecraft.nbt.NBTTagLongArray; import net.minecraft.nbt.NBTTagShort; import net.minecraft.nbt.NBTTagString; -import org.apache.commons.lang3.Validate; import org.bukkit.persistence.PersistentDataContainer; /** @@ -57,7 +56,9 @@ public final class CraftPersistentDataTypeRegistry { * extractor function */ T extract(NBTBase base) { - Validate.isInstanceOf(nbtBaseType, base, "The provided NBTBase was of the type %s. Expected type %s", base.getClass().getSimpleName(), nbtBaseType.getSimpleName()); + if (!nbtBaseType.isInstance(base)) { + throw new IllegalArgumentException(String.format("The provided NBTBase was of the type %s. Expected type %s", base.getClass().getSimpleName(), nbtBaseType.getSimpleName())); + } return this.extractor.apply(nbtBaseType.cast(base)); } @@ -73,7 +74,9 @@ public final class CraftPersistentDataTypeRegistry { * function */ Z build(Object value) { - Validate.isInstanceOf(primitiveType, value, "The provided value was of the type %s. Expected type %s", value.getClass().getSimpleName(), primitiveType.getSimpleName()); + if (!primitiveType.isInstance(value)) { + throw new IllegalArgumentException(String.format("The provided value was of the type %s. Expected type %s", value.getClass().getSimpleName(), primitiveType.getSimpleName())); + } return this.builder.apply(primitiveType.cast(value)); } @@ -247,10 +250,14 @@ public final class CraftPersistentDataTypeRegistry { */ public T extract(Class type, NBTBase tag) throws ClassCastException, IllegalArgumentException { TagAdapter adapter = this.adapters.computeIfAbsent(type, CREATE_ADAPTER); - Validate.isTrue(adapter.isInstance(tag), "`The found tag instance cannot store %s as it is a %s", type.getSimpleName(), tag.getClass().getSimpleName()); + if (!adapter.isInstance(tag)) { + throw new IllegalArgumentException(String.format("`The found tag instance cannot store %s as it is a %s", type.getSimpleName(), tag.getClass().getSimpleName())); + } Object foundValue = adapter.extract(tag); - Validate.isInstanceOf(type, foundValue, "The found object is of the type %s. Expected type %s", foundValue.getClass().getSimpleName(), type.getSimpleName()); + if (!type.isInstance(foundValue)) { + throw new IllegalArgumentException(String.format("The found object is of the type %s. Expected type %s", foundValue.getClass().getSimpleName(), type.getSimpleName())); + } return type.cast(foundValue); } }