use of org.bukkit.persistence.PersistentDataContainer in project Denizen-For-Bukkit by DenizenScript.
the class LocationFlagSearchHelper method getFlaggedLocations.
public static void getFlaggedLocations(Chunk chunk, String flagName, Consumer<Location> handleLocation) {
int subKeyIndex = flagName.indexOf('.');
String fullPath = null;
if (subKeyIndex != -1) {
fullPath = flagName;
flagName = flagName.substring(0, subKeyIndex);
}
PersistentDataContainer container = chunk.getPersistentDataContainer();
Location ref = new Location(chunk.getWorld(), 0, 0, 0);
for (NamespacedKey key : container.getKeys()) {
if (key.getNamespace().equals("denizen") && key.getKey().startsWith("flag_tracker_") && key.getKey().endsWith(flagName)) {
List<String> split = CoreUtilities.split(key.getKey(), '_', 6);
if (split.size() == 6 && split.get(5).equals(flagName)) {
ref.setX(Integer.parseInt(split.get(2)));
ref.setY(Integer.parseInt(split.get(3)));
ref.setZ(Integer.parseInt(split.get(4)));
if (fullPath == null || new LocationTag(ref).getFlagTracker().hasFlag(fullPath)) {
handleLocation.accept(ref);
}
}
}
}
}
Aggregations