From 0a6d869f3c9a97e13107d64099f27b73414799ab Mon Sep 17 00:00:00 2001 From: Aikar Date: Tue, 16 Jul 2013 21:26:50 -0400 Subject: [PATCH] Add MetadataStoreBase.removeAll(Plugin) So that on reload, metadata will be cleared diff --git a/src/main/java/org/bukkit/metadata/MetadataStoreBase.java b/src/main/java/org/bukkit/metadata/MetadataStoreBase.java index b3d85d973..0e8cd85c7 100644 --- a/src/main/java/org/bukkit/metadata/MetadataStoreBase.java +++ b/src/main/java/org/bukkit/metadata/MetadataStoreBase.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; // Paper import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -130,6 +131,26 @@ public abstract class MetadataStoreBase { } } + /** + * Removes all metadata in the metadata store that originates from the + * given plugin. + * + * @param owningPlugin the plugin requesting the invalidation. + * @throws IllegalArgumentException If plugin is null + */ + public void removeAll(@NotNull Plugin owningPlugin) { + Validate.notNull(owningPlugin, "Plugin cannot be null"); + for (Iterator> iterator = metadataMap.values().iterator(); iterator.hasNext(); ) { + Map values = iterator.next(); + if (values.containsKey(owningPlugin)) { + values.remove(owningPlugin); + } + if (values.isEmpty()) { + iterator.remove(); + } + } + } + /** * Creates a unique name for the object receiving metadata by combining * unique data from the subject with a metadataKey. -- 2.21.0