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 7febbd43e3..d6546a9254 100644 --- a/paper-api/src/main/java/org/bukkit/metadata/MetadataStoreBase.java +++ b/paper-api/src/main/java/org/bukkit/metadata/MetadataStoreBase.java @@ -7,7 +7,6 @@ import java.util.*; public abstract class MetadataStoreBase { private Map> metadataMap = new HashMap>(); - private WeakHashMap> disambiguationCache = new WeakHashMap>(); /** * Adds a metadata value to an object. Each metadata value is owned by a specific{@link Plugin}. @@ -28,7 +27,7 @@ public abstract class MetadataStoreBase { 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); + String key = disambiguate(subject, metadataKey); if (!metadataMap.containsKey(key)) { metadataMap.put(key, new ArrayList()); } @@ -55,7 +54,7 @@ public abstract class MetadataStoreBase { * @see MetadataStore#getMetadata(Object, String) */ public synchronized List getMetadata(T subject, String metadataKey) { - String key = cachedDisambiguate(subject, metadataKey); + String key = disambiguate(subject, metadataKey); if (metadataMap.containsKey(key)) { return Collections.unmodifiableList(metadataMap.get(key)); } else { @@ -71,7 +70,7 @@ public abstract class MetadataStoreBase { * @return the existence of the metadataKey within subject. */ public synchronized boolean hasMetadata(T subject, String metadataKey) { - String key = cachedDisambiguate(subject, metadataKey); + String key = disambiguate(subject, metadataKey); return metadataMap.containsKey(key); } @@ -86,7 +85,7 @@ public abstract class MetadataStoreBase { */ public synchronized void removeMetadata(T subject, String metadataKey, Plugin owningPlugin) { Validate.notNull(owningPlugin, "Plugin cannot be null"); - String key = cachedDisambiguate(subject, metadataKey); + String key = disambiguate(subject, metadataKey); List metadataList = metadataMap.get(key); if (metadataList == null) return; for (int i = 0; i < metadataList.size(); i++) { @@ -118,29 +117,6 @@ public abstract class MetadataStoreBase { } } - /** - * Caches the results of calls to {@link MetadataStoreBase#disambiguate(Object, String)} in a {@link WeakHashMap}. Doing so maintains a - * canonical list - * of disambiguation strings for objects in memory. When those objects are garbage collected, the disambiguation string - * in the list is aggressively garbage collected as well. - * - * @param subject The object for which this key is being generated. - * @param metadataKey The name identifying the metadata value. - * @return a unique metadata key for the given subject. - */ - private String cachedDisambiguate(T subject, String metadataKey) { - if (disambiguationCache.containsKey(subject) && disambiguationCache.get(subject).containsKey(metadataKey)) { - return disambiguationCache.get(subject).get(metadataKey); - } else { - if (!disambiguationCache.containsKey(subject)) { - disambiguationCache.put(subject, new HashMap()); - } - String disambiguation = disambiguate(subject, metadataKey); - disambiguationCache.get(subject).put(metadataKey, disambiguation); - return disambiguation; - } - } - /** * Creates a unique name for the object receiving metadata by combining unique data from the subject with a metadataKey. * The name created must be globally unique for the given object and any two equivalent objects must generate the