aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-API-Patches/0032-Add-MetadataStoreBase.removeAll-Plugin.patch
blob: 29e4e6a524d1a04e82f49b495ec1e7df95e54016 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From 1a59075c01dbe0d53bd6fbfd94ccb1ef6a047a6a Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
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 64c0f0a7..6da6abd8 100644
--- a/src/main/java/org/bukkit/metadata/MetadataStoreBase.java
+++ b/src/main/java/org/bukkit/metadata/MetadataStoreBase.java
@@ -125,6 +125,26 @@ public abstract class MetadataStoreBase<T> {
     }
 
     /**
+     * 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(Plugin owningPlugin) {
+        Validate.notNull(owningPlugin, "Plugin cannot be null");
+        for (Iterator<Map<Plugin, MetadataValue>> iterator = metadataMap.values().iterator(); iterator.hasNext(); ) {
+            Map<Plugin, MetadataValue> 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.
      * <p>
-- 
2.12.2