More deferred requireNonNull message creation
This commit is contained in:
@ -83,14 +83,12 @@ public final class NamespacedKey implements net.kyori.adventure.key.Key, com.des
|
||||
* @see #NamespacedKey(Plugin, String)
|
||||
*/
|
||||
public NamespacedKey(@NotNull String namespace, @NotNull String key) {
|
||||
Preconditions.checkArgument(namespace != null && isValidNamespace(namespace), "Invalid namespace. Must be [a-z0-9._-]: %s", namespace);
|
||||
Preconditions.checkArgument(key != null && isValidKey(key), "Invalid key. Must be [a-z0-9/._-]: %s", key);
|
||||
|
||||
Preconditions.checkArgument(namespace != null, "Namespace cannot be null");
|
||||
Preconditions.checkArgument(key != null, "Key cannot be null");
|
||||
this.namespace = namespace;
|
||||
this.key = key;
|
||||
|
||||
String string = toString();
|
||||
Preconditions.checkArgument(string.length() <= Short.MAX_VALUE, "NamespacedKey must be less than 32768 characters", string); // Paper - Fix improper length validation
|
||||
this.validate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,16 +106,17 @@ public final class NamespacedKey implements net.kyori.adventure.key.Key, com.des
|
||||
public NamespacedKey(@NotNull Plugin plugin, @NotNull String key) {
|
||||
Preconditions.checkArgument(plugin != null, "Plugin cannot be null");
|
||||
Preconditions.checkArgument(key != null, "Key cannot be null");
|
||||
|
||||
this.namespace = plugin.getName().toLowerCase(Locale.ROOT);
|
||||
this.key = key.toLowerCase(Locale.ROOT);
|
||||
|
||||
// Check validity after normalization
|
||||
this.validate();
|
||||
}
|
||||
|
||||
private void validate() {
|
||||
Preconditions.checkArgument(this.namespace.length() + 1 + this.key.length() <= Short.MAX_VALUE, "NamespacedKey must be less than 32768 characters");
|
||||
Preconditions.checkArgument(isValidNamespace(this.namespace), "Invalid namespace. Must be [a-z0-9._-]: %s", this.namespace);
|
||||
Preconditions.checkArgument(isValidKey(this.key), "Invalid key. Must be [a-z0-9/._-]: %s", this.key);
|
||||
|
||||
String string = toString();
|
||||
Preconditions.checkArgument(string.length() <= Short.MAX_VALUE, "NamespacedKey must be less than 32768 characters", string); // Paper - Fix improper length validation
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@ -64,7 +64,7 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
||||
@SuppressWarnings("removal")
|
||||
@Deprecated(forRemoval = true, since = "1.21.4")
|
||||
private static <A extends Keyed> Registry<A> legacyRegistryFor(final Class<A> clazz) {
|
||||
return Objects.requireNonNull(RegistryAccess.registryAccess().getRegistry(clazz), "No registry present for " + clazz.getSimpleName() + ". This is a bug.");
|
||||
return Objects.requireNonNull(RegistryAccess.registryAccess().getRegistry(clazz), () -> "No registry present for " + clazz.getSimpleName() + ". This is a bug.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -57,7 +57,7 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
|
||||
*/
|
||||
@org.jetbrains.annotations.Contract(value = "_, _ -> new", pure = true)
|
||||
public static @NotNull ItemStack of(final @NotNull Material type, final int amount) {
|
||||
Preconditions.checkArgument(type.asItemType() != null, type + " isn't an item");
|
||||
Preconditions.checkArgument(type.asItemType() != null, "%s isn't an item", type);
|
||||
Preconditions.checkArgument(amount > 0, "amount must be greater than 0");
|
||||
return java.util.Objects.requireNonNull(type.asItemType(), type + " is not an item").createItemStack(amount); // Paper - delegate
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user