diff options
author | rmichela <deltahat@gmail.com> | 2012-03-28 01:41:33 -0400 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-03-28 19:21:57 -0400 |
commit | 1dc7eadf800fac39cc1470e5c51ca07b245b8988 (patch) | |
tree | 0b90871cca04452e9af527bc3cba7b4877f3cdcc | |
parent | e9064329e60a5076286f078471b9324175f8f9b7 (diff) | |
download | bukkit-1dc7eadf800fac39cc1470e5c51ca07b245b8988.tar bukkit-1dc7eadf800fac39cc1470e5c51ca07b245b8988.tar.gz bukkit-1dc7eadf800fac39cc1470e5c51ca07b245b8988.tar.lz bukkit-1dc7eadf800fac39cc1470e5c51ca07b245b8988.tar.xz bukkit-1dc7eadf800fac39cc1470e5c51ca07b245b8988.zip |
[Bleeding] Removing the last metadata item for a key now sets hasMetadata(key) to false. Addresses BUKKIT-1380
-rw-r--r-- | src/main/java/org/bukkit/metadata/MetadataStoreBase.java | 3 | ||||
-rw-r--r-- | src/test/java/org/bukkit/metadata/MetadataStoreTest.java | 9 |
2 files changed, 12 insertions, 0 deletions
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<T> { 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 @@ -97,6 +97,15 @@ public class MetadataStoreTest { } @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)); subject.removeMetadata("subject", "key", pluginY); |