diff options
author | Senmori <thesenmori@gmail.com> | 2018-07-20 13:14:30 -0400 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-07-21 10:09:32 +1000 |
commit | 2ba30dddd4acb3bd789b4e487ed0647984576e8c (patch) | |
tree | b1d651123bc949384500a6baf47c0e25ec217a86 /src/main/java/org | |
parent | ac92f0355a7bf319d51b78837f8e7a3889b6c549 (diff) | |
download | bukkit-2ba30dddd4acb3bd789b4e487ed0647984576e8c.tar bukkit-2ba30dddd4acb3bd789b4e487ed0647984576e8c.tar.gz bukkit-2ba30dddd4acb3bd789b4e487ed0647984576e8c.tar.lz bukkit-2ba30dddd4acb3bd789b4e487ed0647984576e8c.tar.xz bukkit-2ba30dddd4acb3bd789b4e487ed0647984576e8c.zip |
Clarify NamespacedKey error messages.
Add new tests for NamespacedKeys.
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/NamespacedKey.java | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/main/java/org/bukkit/NamespacedKey.java b/src/main/java/org/bukkit/NamespacedKey.java index 1ed8f7e4..43239f84 100644 --- a/src/main/java/org/bukkit/NamespacedKey.java +++ b/src/main/java/org/bukkit/NamespacedKey.java @@ -44,8 +44,8 @@ public final class NamespacedKey { */ @Deprecated public NamespacedKey(String namespace, String key) { - Preconditions.checkArgument(namespace != null && VALID_NAMESPACE.matcher(namespace).matches(), "namespace"); - Preconditions.checkArgument(key != null && VALID_KEY.matcher(key).matches(), "key"); + Preconditions.checkArgument(namespace != null && VALID_NAMESPACE.matcher(namespace).matches(), "Invalid namespace. Must be [a-z0-9._-]: %s", namespace); + Preconditions.checkArgument(key != null && VALID_KEY.matcher(key).matches(), "Invalid key. Must be [a-z0-9/._-]: %s", key); this.namespace = namespace; this.key = key; @@ -56,20 +56,26 @@ public final class NamespacedKey { /** * Create a key in the plugin's namespace. + * <p> + * Namespaces may only contain lowercase alphanumeric characters, periods, + * underscores, and hyphens. + * <p> + * Keys may only contain lowercase alphanumeric characters, periods, + * underscores, hyphens, and forward slashes. * * @param plugin the plugin to use for the namespace * @param key the key to create */ public NamespacedKey(Plugin plugin, String key) { - Preconditions.checkArgument(plugin != null, "plugin"); - Preconditions.checkArgument(key != null, "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().toLowerCase(Locale.ROOT); // Check validity after normalization - Preconditions.checkArgument(VALID_NAMESPACE.matcher(this.namespace).matches(), "namespace"); - Preconditions.checkArgument(VALID_KEY.matcher(this.key).matches(), "key"); + Preconditions.checkArgument(VALID_NAMESPACE.matcher(this.namespace).matches(), "Invalid namespace. Must be [a-z0-9._-]: %s", this.namespace); + Preconditions.checkArgument(VALID_KEY.matcher(this.key).matches(), "Invalid key. Must be [a-z0-9/._-]: %s", this.key); String string = toString(); Preconditions.checkArgument(string.length() < 256, "NamespacedKey must be less than 256 characters (%s)", string); |