Search in sources :

Example 1 with MapRenderer

use of org.bukkit.map.MapRenderer in project Denizen-For-Bukkit by DenizenScript.

the class MapCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element id = scriptEntry.getElement("map-id");
    dWorld create = scriptEntry.getdObject("new");
    Element reset = scriptEntry.getElement("reset");
    dLocation resetLoc = scriptEntry.getdObject("reset-loc");
    Element image = scriptEntry.getElement("image");
    dScript script = scriptEntry.getdObject("script");
    Element resize = scriptEntry.getElement("resize");
    Element width = scriptEntry.getElement("width");
    Element height = scriptEntry.getElement("height");
    Element x = scriptEntry.getElement("x-value");
    Element y = scriptEntry.getElement("y-value");
    dB.report(scriptEntry, getName(), (id != null ? id.debug() : "") + (create != null ? create.debug() : "") + reset.debug() + (resetLoc != null ? resetLoc.debug() : "") + (image != null ? image.debug() : "") + (script != null ? script.debug() : "") + resize.debug() + (width != null ? width.debug() : "") + (height != null ? height.debug() : "") + x.debug() + y.debug());
    MapView map = null;
    if (create != null) {
        map = Bukkit.getServer().createMap(create.getWorld());
        scriptEntry.addObject("created_map", new Element(map.getId()));
    } else if (id != null) {
        map = Bukkit.getServer().getMap((short) id.asInt());
        if (map == null) {
            throw new CommandExecutionException("No map found for ID '" + id.asInt() + "'!");
        }
    } else {
        throw new CommandExecutionException("The map command failed somehow! Report this to a developer!");
    }
    if (reset.asBoolean()) {
        List<MapRenderer> oldRenderers = DenizenMapManager.removeDenizenRenderers(map);
        for (MapRenderer renderer : oldRenderers) {
            map.addRenderer(renderer);
        }
        if (resetLoc != null) {
            map.setCenterX(resetLoc.getBlockX());
            map.setCenterZ(resetLoc.getBlockZ());
            map.setWorld(resetLoc.getWorld());
        }
    } else if (script != null) {
        DenizenMapManager.removeDenizenRenderers(map);
        ((MapScriptContainer) script.getContainer()).applyTo(map);
    } else {
        DenizenMapRenderer dmr = DenizenMapManager.getDenizenRenderer(map);
        if (image != null) {
            int wide = width != null ? width.asInt() : resize.asBoolean() ? 128 : 0;
            int high = height != null ? height.asInt() : resize.asBoolean() ? 128 : 0;
            if (CoreUtilities.toLowerCase(image.asString()).endsWith(".gif")) {
                dmr.addObject(new MapAnimatedImage(x.asString(), y.asString(), "true", false, image.asString(), wide, high));
            } else {
                dmr.addObject(new MapImage(x.asString(), y.asString(), "true", false, image.asString(), wide, high));
            }
        }
    }
}
Also used : MapImage(net.aufdemrand.denizen.utilities.maps.MapImage) MapAnimatedImage(net.aufdemrand.denizen.utilities.maps.MapAnimatedImage) net.aufdemrand.denizencore.objects.dScript(net.aufdemrand.denizencore.objects.dScript) DenizenMapRenderer(net.aufdemrand.denizen.utilities.maps.DenizenMapRenderer) MapRenderer(org.bukkit.map.MapRenderer) Element(net.aufdemrand.denizencore.objects.Element) MapView(org.bukkit.map.MapView) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException) DenizenMapRenderer(net.aufdemrand.denizen.utilities.maps.DenizenMapRenderer) net.aufdemrand.denizen.objects.dWorld(net.aufdemrand.denizen.objects.dWorld) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 2 with MapRenderer

use of org.bukkit.map.MapRenderer in project Denizen-For-Bukkit by DenizenScript.

the class DenizenMapManager method removeDenizenRenderers.

public static List<MapRenderer> removeDenizenRenderers(MapView map) {
    List<MapRenderer> oldRenderers = new ArrayList<MapRenderer>();
    for (MapRenderer renderer : map.getRenderers()) {
        if (renderer instanceof DenizenMapRenderer) {
            map.removeRenderer(renderer);
            oldRenderers.addAll(((DenizenMapRenderer) renderer).getOldRenderers());
            ((DenizenMapRenderer) renderer).deactivate();
            mapRenderers.remove(map.getId());
        }
    }
    return oldRenderers;
}
Also used : MapRenderer(org.bukkit.map.MapRenderer)

Example 3 with MapRenderer

use of org.bukkit.map.MapRenderer 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)

Example 4 with MapRenderer

use of org.bukkit.map.MapRenderer in project Denizen-For-Bukkit by DenizenScript.

the class DenizenMapManager method setMap.

public static void setMap(MapView map, DenizenMapRenderer denizenMapRenderer) {
    List<MapRenderer> oldRenderers = map.getRenderers();
    for (MapRenderer renderer : oldRenderers) {
        map.removeRenderer(renderer);
    }
    map.addRenderer(denizenMapRenderer);
    mapRenderers.put(map.getId(), denizenMapRenderer);
}
Also used : MapRenderer(org.bukkit.map.MapRenderer)

Aggregations

MapRenderer (org.bukkit.map.MapRenderer)4 MapView (org.bukkit.map.MapView)2 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)1 net.aufdemrand.denizen.objects.dWorld (net.aufdemrand.denizen.objects.dWorld)1 DenizenMapRenderer (net.aufdemrand.denizen.utilities.maps.DenizenMapRenderer)1 MapAnimatedImage (net.aufdemrand.denizen.utilities.maps.MapAnimatedImage)1 MapImage (net.aufdemrand.denizen.utilities.maps.MapImage)1 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)1 Element (net.aufdemrand.denizencore.objects.Element)1 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)1 NaturalOrderComparator (net.aufdemrand.denizencore.utilities.NaturalOrderComparator)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1