Search in sources :

Example 1 with MapAnimatedImage

use of net.aufdemrand.denizen.utilities.maps.MapAnimatedImage 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)

Aggregations

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 MapRenderer (org.bukkit.map.MapRenderer)1 MapView (org.bukkit.map.MapView)1