[Bleeding] Removing the last metadata item for a key now sets hasMetadata(key) to false. Addresses BUKKIT-1380

By: rmichela <deltahat@gmail.com>
This commit is contained in:
Bukkit/Spigot 2012-03-28 01:41:33 -04:00
parent 853f14f0dc
commit cc95e9f5ef
2 changed files with 12 additions and 0 deletions

View File

@ -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);
}
}
}
}

View File

@ -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));