From 1dc7eadf800fac39cc1470e5c51ca07b245b8988 Mon Sep 17 00:00:00 2001 From: rmichela Date: Wed, 28 Mar 2012 01:41:33 -0400 Subject: [Bleeding] Removing the last metadata item for a key now sets hasMetadata(key) to false. Addresses BUKKIT-1380 --- src/main/java/org/bukkit/metadata/MetadataStoreBase.java | 3 +++ src/test/java/org/bukkit/metadata/MetadataStoreTest.java | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/org/bukkit/metadata/MetadataStoreBase.java b/src/main/java/org/bukkit/metadata/MetadataStoreBase.java index 3a40ae7d..9bbe3647 100644 --- a/src/main/java/org/bukkit/metadata/MetadataStoreBase.java +++ b/src/main/java/org/bukkit/metadata/MetadataStoreBase.java @@ -86,6 +86,9 @@ public abstract class MetadataStoreBase { for (int i = 0; i < metadataList.size(); i++) { if (metadataList.get(i).getOwningPlugin().equals(owningPlugin)) { metadataList.remove(i); + if (metadataList.isEmpty()) { + metadataMap.remove(key); + } } } } diff --git a/src/test/java/org/bukkit/metadata/MetadataStoreTest.java b/src/test/java/org/bukkit/metadata/MetadataStoreTest.java index f35d5be4..30f03686 100644 --- a/src/test/java/org/bukkit/metadata/MetadataStoreTest.java +++ b/src/test/java/org/bukkit/metadata/MetadataStoreTest.java @@ -96,6 +96,15 @@ public class MetadataStoreTest { assertEquals(20, subject.getMetadata("subject", "key").get(0).value()); } + @Test + public void testMetadataRemoveLast() { + subject.setMetadata("subject", "key", new FixedMetadataValue(pluginX, 10)); + subject.removeMetadata("subject", "key", pluginX); + + assertFalse(subject.hasMetadata("subject", "key")); + assertEquals(0, subject.getMetadata("subject", "key").size()); + } + @Test public void testMetadataRemoveForNonExistingPlugin() { subject.setMetadata("subject", "key", new FixedMetadataValue(pluginX, 10)); -- cgit v1.2.3