Search in sources :

Example 1 with NaturalOrderComparator

use of net.aufdemrand.denizencore.utilities.NaturalOrderComparator in project Denizen-For-Bukkit by DenizenScript.

the class MapScriptContainer method applyTo.

public void applyTo(MapView mapView) {
    DenizenMapRenderer renderer = new DenizenMapRenderer(mapView.getRenderers(), aH.getBooleanFrom(getString("AUTO UPDATE", "true")));
    boolean debug = true;
    if (contains("DEBUG")) {
        debug = aH.getBooleanFrom(getString("DEBUG"));
    }
    if (contains("OBJECTS")) {
        YamlConfiguration objectsSection = getConfigurationSection("OBJECTS");
        List<StringHolder> objectKeys1 = new ArrayList<StringHolder>(objectsSection.getKeys(false));
        List<String> objectKeys = new ArrayList<String>(objectKeys1.size());
        for (StringHolder sh : objectKeys1) {
            objectKeys.add(sh.str);
        }
        Collections.sort(objectKeys, new NaturalOrderComparator());
        for (String objectKey : objectKeys) {
            YamlConfiguration objectSection = objectsSection.getConfigurationSection(objectKey);
            if (!objectSection.contains("TYPE")) {
                dB.echoError("Map script '" + getName() + "' has an object without a specified type!");
                return;
            }
            String type = objectSection.getString("TYPE").toUpperCase();
            String x = objectSection.getString("X", "0");
            String y = objectSection.getString("Y", "0");
            String visible = objectSection.getString("VISIBLE", "true");
            if (type.equals("IMAGE")) {
                if (!objectSection.contains("IMAGE")) {
                    dB.echoError("Map script '" + getName() + "'s image '" + objectKey + "' has no specified image location!");
                    return;
                }
                String image = objectSection.getString("IMAGE");
                int width = aH.getIntegerFrom(objectSection.getString("WIDTH", "0"));
                int height = aH.getIntegerFrom(objectSection.getString("HEIGHT", "0"));
                if (CoreUtilities.toLowerCase(image).endsWith(".gif")) {
                    renderer.addObject(new MapAnimatedImage(x, y, visible, debug, image, width, height));
                } else {
                    renderer.addObject(new MapImage(x, y, visible, debug, image, width, height));
                }
            } else if (type.equals("TEXT")) {
                if (!objectSection.contains("TEXT")) {
                    dB.echoError("Map script '" + getName() + "'s text object '" + objectKey + "' has no specified text!");
                    return;
                }
                String text = objectSection.getString("TEXT");
                renderer.addObject(new MapText(x, y, visible, debug, text));
            } else if (type.equals("CURSOR")) {
                if (!objectSection.contains("CURSOR")) {
                    dB.echoError("Map script '" + getName() + "'s cursor '" + objectKey + "' has no specified cursor type!");
                    return;
                }
                String cursor = objectSection.getString("CURSOR");
                if (cursor == null) {
                    dB.echoError("Map script '" + getName() + "'s cursor '" + objectKey + "' is missing a cursor type!");
                    return;
                }
                renderer.addObject(new MapCursor(x, y, visible, debug, objectSection.getString("DIRECTION", "0"), cursor));
            } else if (type.equals("DOT")) {
                renderer.addObject(new MapDot(x, y, visible, debug, objectSection.getString("RADIUS", "1"), objectSection.getString("COLOR", "black")));
            }
        }
    }
    DenizenMapManager.setMap(mapView, renderer);
}
Also used : ArrayList(java.util.ArrayList) YamlConfiguration(net.aufdemrand.denizencore.utilities.YamlConfiguration) NaturalOrderComparator(net.aufdemrand.denizencore.utilities.NaturalOrderComparator) StringHolder(net.aufdemrand.denizencore.utilities.text.StringHolder)

Example 2 with NaturalOrderComparator

use of net.aufdemrand.denizencore.utilities.NaturalOrderComparator in project Denizen-For-Bukkit by DenizenScript.

the class DenizenMapManager method reloadMaps.

public static void reloadMaps() {
    Map<Short, List<MapRenderer>> oldMapRenderers = new HashMap<Short, List<MapRenderer>>();
    for (Map.Entry<Short, DenizenMapRenderer> entry : mapRenderers.entrySet()) {
        DenizenMapRenderer renderer = entry.getValue();
        oldMapRenderers.put(entry.getKey(), renderer.getOldRenderers());
        renderer.deactivate();
    }
    mapRenderers.clear();
    downloadedByUrl.clear();
    mapsConfig = YamlConfiguration.loadConfiguration(mapsFile);
    ConfigurationSection mapsSection = mapsConfig.getConfigurationSection("MAPS");
    if (mapsSection == null) {
        return;
    }
    for (String key : mapsSection.getKeys(false)) {
        short mapId = Short.valueOf(key);
        MapView mapView = Bukkit.getServer().getMap(mapId);
        if (mapView == null) {
            dB.echoError("Map #" + key + " does not exist. Has it been removed? Deleting from maps.yml...");
            mapsSection.set(key, null);
            continue;
        }
        ConfigurationSection objectsData = mapsSection.getConfigurationSection(key + ".objects");
        List<MapRenderer> oldRenderers;
        if (oldMapRenderers.containsKey(mapId)) {
            oldRenderers = oldMapRenderers.get(mapId);
        } else {
            oldRenderers = mapView.getRenderers();
            for (MapRenderer oldRenderer : oldRenderers) {
                mapView.removeRenderer(oldRenderer);
            }
        }
        DenizenMapRenderer renderer = new DenizenMapRenderer(oldRenderers, mapsSection.getBoolean(key + ".auto update", false));
        List<String> objects = new ArrayList<String>(objectsData.getKeys(false));
        Collections.sort(objects, new NaturalOrderComparator());
        for (String objectKey : objects) {
            String type = objectsData.getString(objectKey + ".type").toUpperCase();
            String xTag = objectsData.getString(objectKey + ".x");
            String yTag = objectsData.getString(objectKey + ".y");
            String visibilityTag = objectsData.getString(objectKey + ".visibility");
            boolean debug = objectsData.getBoolean(objectKey + ".debug");
            MapObject object = null;
            if (type.equals("CURSOR")) {
                object = new MapCursor(xTag, yTag, visibilityTag, debug, objectsData.getString(objectKey + ".direction"), objectsData.getString(objectKey + ".cursor"));
            } else if (type.equals("IMAGE")) {
                String file = objectsData.getString(objectKey + ".image");
                int width = objectsData.getInt(objectKey + ".width", 0);
                int height = objectsData.getInt(objectKey + ".height", 0);
                if (CoreUtilities.toLowerCase(file).endsWith(".gif")) {
                    object = new MapAnimatedImage(xTag, yTag, visibilityTag, debug, file, width, height);
                } else {
                    object = new MapImage(xTag, yTag, visibilityTag, debug, file, width, height);
                }
            } else if (type.equals("TEXT")) {
                object = new MapText(xTag, yTag, visibilityTag, debug, objectsData.getString(objectKey + ".text"));
            }
            if (object != null) {
                renderer.addObject(object);
            }
        }
        mapView.addRenderer(renderer);
        mapRenderers.put(mapId, renderer);
    }
    for (Map.Entry<Short, List<MapRenderer>> entry : oldMapRenderers.entrySet()) {
        short id = entry.getKey();
        if (!mapRenderers.containsKey(id)) {
            MapView mapView = Bukkit.getServer().getMap(id);
            if (mapView != null) {
                for (MapRenderer renderer : entry.getValue()) {
                    mapView.addRenderer(renderer);
                }
            }
        // If it's null, the server no longer has the map - don't do anything about it
        }
    }
    ConfigurationSection downloadedImages = mapsConfig.getConfigurationSection("DOWNLOADED");
    if (downloadedImages == null) {
        return;
    }
    for (String image : downloadedImages.getKeys(false)) {
        downloadedByUrl.put(CoreUtilities.toLowerCase(downloadedImages.getString(image)), image.replace("DOT", "."));
    }
}
Also used : NaturalOrderComparator(net.aufdemrand.denizencore.utilities.NaturalOrderComparator) MapRenderer(org.bukkit.map.MapRenderer) MapView(org.bukkit.map.MapView) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

NaturalOrderComparator (net.aufdemrand.denizencore.utilities.NaturalOrderComparator)2 ArrayList (java.util.ArrayList)1 YamlConfiguration (net.aufdemrand.denizencore.utilities.YamlConfiguration)1 StringHolder (net.aufdemrand.denizencore.utilities.text.StringHolder)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 MapRenderer (org.bukkit.map.MapRenderer)1 MapView (org.bukkit.map.MapView)1