Search in sources :

Example 1 with MapImage

use of com.denizenscript.denizen.utilities.maps.MapImage in project Denizen-For-Bukkit by DenizenScript.

the class MapCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag id = scriptEntry.getElement("map-id");
    WorldTag create = scriptEntry.getObjectTag("new");
    ElementTag reset = scriptEntry.getElement("reset");
    LocationTag resetLoc = scriptEntry.getObjectTag("reset-loc");
    ElementTag image = scriptEntry.getElement("image");
    ScriptTag script = scriptEntry.getObjectTag("script");
    ElementTag resize = scriptEntry.getElement("resize");
    ElementTag width = scriptEntry.getElement("width");
    ElementTag height = scriptEntry.getElement("height");
    ElementTag scale = scriptEntry.getElement("scale");
    ElementTag tracking = scriptEntry.getElement("tracking");
    ElementTag x = scriptEntry.getElement("x-value");
    ElementTag y = scriptEntry.getElement("y-value");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), id, create, reset, resetLoc, image, script, resize, width, height, x, y);
    }
    MapView map;
    if (create != null) {
        map = Bukkit.getServer().createMap(create.getWorld());
        scriptEntry.addObject("created_map", new ElementTag(map.getId()));
        Debug.echoDebug(scriptEntry, "Created map with id " + map.getId() + ".");
    } else if (id != null) {
        map = Bukkit.getServer().getMap((short) id.asInt());
        if (map == null) {
            Debug.echoError("No map found for ID '" + id.asInt() + "'!");
            return;
        }
    } else {
        // not possible
        return;
    }
    if (reset.asBoolean()) {
        if (tracking != null) {
            map.setTrackingPosition(true);
        }
        if (scale != null) {
            map.setScale(MapView.Scale.valueOf(scale.asString().toUpperCase()));
        }
        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());
        }
    }
    if (script != null) {
        DenizenMapManager.removeDenizenRenderers(map);
        ((MapScriptContainer) script.getContainer()).applyTo(map);
    }
    if (image != null) {
        DenizenMapRenderer dmr = DenizenMapManager.getDenizenRenderer(map);
        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.autoUpdate = true;
        }
        dmr.addObject(new MapImage(dmr, x.asString(), y.asString(), "true", false, image.asString(), wide, high));
        dmr.hasChanged = true;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MapImage(com.denizenscript.denizen.utilities.maps.MapImage) DenizenMapRenderer(com.denizenscript.denizen.utilities.maps.DenizenMapRenderer) MapRenderer(org.bukkit.map.MapRenderer) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) MapView(org.bukkit.map.MapView) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) WorldTag(com.denizenscript.denizen.objects.WorldTag) DenizenMapRenderer(com.denizenscript.denizen.utilities.maps.DenizenMapRenderer) MapScriptContainer(com.denizenscript.denizen.scripts.containers.core.MapScriptContainer)

Aggregations

LocationTag (com.denizenscript.denizen.objects.LocationTag)1 WorldTag (com.denizenscript.denizen.objects.WorldTag)1 MapScriptContainer (com.denizenscript.denizen.scripts.containers.core.MapScriptContainer)1 DenizenMapRenderer (com.denizenscript.denizen.utilities.maps.DenizenMapRenderer)1 MapImage (com.denizenscript.denizen.utilities.maps.MapImage)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)1 MapRenderer (org.bukkit.map.MapRenderer)1 MapView (org.bukkit.map.MapView)1