diff --git a/paper-api/src/main/java/org/bukkit/metadata/MetadataStore.java b/paper-api/src/main/java/org/bukkit/metadata/MetadataStore.java index 0adfa7a006..273a273f1a 100644 --- a/paper-api/src/main/java/org/bukkit/metadata/MetadataStore.java +++ b/paper-api/src/main/java/org/bukkit/metadata/MetadataStore.java @@ -11,6 +11,7 @@ public interface MetadataStore { * @param subject The object receiving the metadata. * @param metadataKey A unique key to identify this metadata. * @param newMetadataValue The metadata value to apply. + * @throws IllegalArgumentException If value is null, or the owning plugin is null */ public void setMetadata(T subject, String metadataKey, MetadataValue newMetadataValue); @@ -39,6 +40,7 @@ public interface MetadataStore { * @param subject the object to remove the metadata from. * @param metadataKey the unique metadata key identifying the metadata to remove. * @param owningPlugin the plugin attempting to remove a metadata item. + * @throws IllegalArgumentException If plugin is null */ public void removeMetadata(T subject, String metadataKey, Plugin owningPlugin); @@ -47,6 +49,7 @@ public interface MetadataStore { * each invalidated metadata item to be recalculated the next time it is accessed. * * @param owningPlugin the plugin requesting the invalidation. + * @throws IllegalArgumentException If plugin is null */ public void invalidateAll(Plugin owningPlugin); } diff --git a/paper-api/src/main/java/org/bukkit/metadata/MetadataStoreBase.java b/paper-api/src/main/java/org/bukkit/metadata/MetadataStoreBase.java index 9bbe364706..7febbd43e3 100644 --- a/paper-api/src/main/java/org/bukkit/metadata/MetadataStoreBase.java +++ b/paper-api/src/main/java/org/bukkit/metadata/MetadataStoreBase.java @@ -1,5 +1,6 @@ package org.bukkit.metadata; +import org.apache.commons.lang.Validate; import org.bukkit.plugin.Plugin; import java.util.*; @@ -22,8 +23,11 @@ public abstract class MetadataStoreBase { * @param metadataKey A unique key to identify this metadata. * @param newMetadataValue The metadata value to apply. * @see MetadataStore#setMetadata(Object, String, MetadataValue) + * @throws IllegalArgumentException If value is null, or the owning plugin is null */ public synchronized void setMetadata(T subject, String metadataKey, MetadataValue newMetadataValue) { + Validate.notNull(newMetadataValue, "Value cannot be null"); + Validate.notNull(newMetadataValue.getOwningPlugin(), "Plugin cannot be null"); String key = cachedDisambiguate(subject, metadataKey); if (!metadataMap.containsKey(key)) { metadataMap.put(key, new ArrayList()); @@ -78,8 +82,10 @@ public abstract class MetadataStoreBase { * @param metadataKey the unique metadata key identifying the metadata to remove. * @param owningPlugin the plugin attempting to remove a metadata item. * @see MetadataStore#removeMetadata(Object, String, org.bukkit.plugin.Plugin) + * @throws IllegalArgumentException If plugin is null */ public synchronized void removeMetadata(T subject, String metadataKey, Plugin owningPlugin) { + Validate.notNull(owningPlugin, "Plugin cannot be null"); String key = cachedDisambiguate(subject, metadataKey); List metadataList = metadataMap.get(key); if (metadataList == null) return; @@ -99,12 +105,10 @@ public abstract class MetadataStoreBase { * * @param owningPlugin the plugin requesting the invalidation. * @see MetadataStore#invalidateAll(org.bukkit.plugin.Plugin) + * @throws IllegalArgumentException If plugin is null */ public synchronized void invalidateAll(Plugin owningPlugin) { - if (owningPlugin == null) { - throw new IllegalArgumentException("owningPlugin cannot be null"); - } - + Validate.notNull(owningPlugin, "Plugin cannot be null"); for (List values : metadataMap.values()) { for (MetadataValue value : values) { if (value.getOwningPlugin().equals(owningPlugin)) { diff --git a/paper-api/src/main/java/org/bukkit/metadata/MetadataValue.java b/paper-api/src/main/java/org/bukkit/metadata/MetadataValue.java index 761d1ac959..deec40fb35 100644 --- a/paper-api/src/main/java/org/bukkit/metadata/MetadataValue.java +++ b/paper-api/src/main/java/org/bukkit/metadata/MetadataValue.java @@ -62,7 +62,7 @@ public interface MetadataValue { /** * Returns the {@link Plugin} that created this metadata item. * - * @return the plugin that owns this metadata value. + * @return the plugin that owns this metadata value. This should never be null. */ public Plugin getOwningPlugin(); diff --git a/paper-api/src/main/java/org/bukkit/metadata/Metadatable.java b/paper-api/src/main/java/org/bukkit/metadata/Metadatable.java index 956a1960fb..41711be805 100644 --- a/paper-api/src/main/java/org/bukkit/metadata/Metadatable.java +++ b/paper-api/src/main/java/org/bukkit/metadata/Metadatable.java @@ -13,6 +13,7 @@ public interface Metadatable { * * @param metadataKey A unique key to identify this metadata. * @param newMetadataValue The metadata value to apply. + * @throws IllegalArgumentException If value is null, or the owning plugin is null */ public void setMetadata(String metadataKey, MetadataValue newMetadataValue); @@ -37,6 +38,7 @@ public interface Metadatable { * * @param metadataKey the unique metadata key identifying the metadata to remove. * @param owningPlugin This plugin's metadata value will be removed. All other values will be left untouched. + * @throws IllegalArgumentException If plugin is null */ public void removeMetadata(String metadataKey, Plugin owningPlugin); }