From b90051303555db62d030cf995ff46b917d4e6a37 Mon Sep 17 00:00:00 2001 From: Parker Hawke Date: Fri, 26 Jun 2020 10:49:28 +1000 Subject: [PATCH] #671: Implement PersistentDataContainer#getKeys() --- .../CraftPersistentDataContainer.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java index 6c6540dd3d..58e2db5da1 100644 --- a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java +++ b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java @@ -1,9 +1,11 @@ package org.bukkit.craftbukkit.persistence; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; +import java.util.Set; import net.minecraft.server.NBTBase; import net.minecraft.server.NBTTagCompound; import org.apache.commons.lang.Validate; @@ -70,6 +72,20 @@ public final class CraftPersistentDataContainer implements PersistentDataContain return z != null ? z : defaultValue; } + @Override + public Set getKeys() { + Set keys = new HashSet<>(); + + this.customDataTags.keySet().forEach(key -> { + String[] keyData = key.split(":", 2); + if (keyData.length == 2) { + keys.add(new NamespacedKey(keyData[0], keyData[1])); + } + }); + + return keys; + } + @Override public void remove(NamespacedKey key) { Validate.notNull(key, "The provided key for the custom value was null");