Search in sources :

Example 1 with PersistentDataContainer

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);
                }
            }
        }
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) NamespacedKey(org.bukkit.NamespacedKey) PersistentDataContainer(org.bukkit.persistence.PersistentDataContainer) Location(org.bukkit.Location)

Aggregations

LocationTag (com.denizenscript.denizen.objects.LocationTag)1 Location (org.bukkit.Location)1 NamespacedKey (org.bukkit.NamespacedKey)1 PersistentDataContainer (org.bukkit.persistence.PersistentDataContainer)1