use of com.denizenscript.denizen.utilities.maps.DenizenMapRenderer 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;
}
}
Aggregations