use of com.denizenscript.denizencore.utilities.NaturalOrderComparator in project Denizen-For-Bukkit by DenizenScript.
the class MapScriptContainer method applyTo.
// <--[language]
// @name Map Script Containers
// @group Script Container System
// @description
// Map scripts allow you define custom in-game map items, for usage with the map command.
//
// The following is the format for the container.
//
// <code>
// # The name of the map script is used by the map command.
// Map_Script_Name:
//
// type: map
//
// # Whether to display the original map below the custom values. Defaults to true.
// # | Some map scripts should have this key!
// original: true/false
//
// # Whether to constantly update things. Defaults to true.
// # | Some map scripts should have this key!
// auto update: true
//
// # Whether this map script renders uniquely per-player. Defaults to true.
// # | Some map scripts should have this key!
// contextual: true
//
// # Lists all contained objects.
// # | Most map scripts should have this key!
// objects:
//
// # The first object...
// 1:
// # Specify the object type
// # Type can be IMAGE, TEXT, CURSOR, or DOT.
// type: image
// # Specify an HTTP url or file path within Denizen/images/ for the image. Supports animated .gif!
// image: my_image.png
// # Optionally add width/height numbers.
// width: 128
// height: 128
//
// 2:
// type: text
// # Specify any text to display. Color codes not permitted (unless you know how to format CraftMapCanvas byte-ID color codes).
// text: Hello <player.name>
// # Specify the color of the text as any valid ColorTag.
// color: red
// # Specify a tag to show or hide custom content! Valid for all objects.
// # Note that all inputs other than 'type' for all objects support tags that will be dynamically reparsed per-player each time the map updates.
// visible: <player.name.contains[bob].not>
//
// 3:
// type: cursor
// # Specify a cursor type
// cursor: red_marker
// # Optionally, specify a cursor direction. '180' seems to display as up-right usually.
// direction: 180
// # Supported on all objects: x/y positions, and whether to use worldly or map coordinates.
// x: 5
// # If 'world_coordinates' is set to 'true', the 'y' value corresponds to the 'z' value of a location.
// y: 5
// # If true: uses world coordinates. If false: uses map local coordinates. (Defaults to false).
// world_coordinates: false
// # If true: when the object goes past the edge, will stay in view at the corner. If false: disappears past the edge (defaults to false).
// show_past_edge: false
//
// 4:
// type: dot
// # Specify the radius of the dot.
// radius: 1
// # Specify the color of the dot as any valid ColorTag.
// color: red
//
// </code>
//
// A list of cursor types is available through <@link tag server.map_cursor_types>.
//
// -->
public void applyTo(MapView mapView) {
boolean contextual = getString("contextual", "true").equalsIgnoreCase("true");
DenizenMapRenderer renderer = new DenizenMapRenderer(mapView.getRenderers(), getString("auto update", "true").equalsIgnoreCase("true"), contextual);
if (contains("original", String.class)) {
renderer.displayOriginal = getString("original").equalsIgnoreCase("true");
}
if (contains("objects", Map.class)) {
YamlConfiguration objectsSection = getConfigurationSection("objects");
List<StringHolder> objectKeys1 = new ArrayList<>(objectsSection.getKeys(false));
List<String> objectKeys = new ArrayList<>(objectKeys1.size());
for (StringHolder sh : objectKeys1) {
objectKeys.add(sh.str);
}
objectKeys.sort(new NaturalOrderComparator());
for (String objectKey : objectKeys) {
YamlConfiguration objectSection = objectsSection.getConfigurationSection(objectKey);
if (!objectSection.contains("type")) {
Debug.echoError("Map script '" + getName() + "' has an object without a specified type!");
return;
}
String type = CoreUtilities.toLowerCase(objectSection.getString("type"));
String x = objectSection.getString("x", "0");
String y = objectSection.getString("y", "0");
String visible = objectSection.getString("visible", "true");
MapObject added = null;
switch(type) {
case "image":
if (!objectSection.contains("image")) {
Debug.echoError("Map script '" + getName() + "'s image '" + objectKey + "' has no specified image location!");
return;
}
String image = objectSection.getString("image");
int width = Integer.parseInt(objectSection.getString("width", "0"));
int height = Integer.parseInt(objectSection.getString("height", "0"));
added = new MapImage(renderer, x, y, visible, shouldDebug(), image, width, height);
break;
case "text":
if (!objectSection.contains("text")) {
Debug.echoError("Map script '" + getName() + "'s text object '" + objectKey + "' has no specified text!");
return;
}
String text = objectSection.getString("text");
added = new MapText(x, y, visible, shouldDebug(), text, objectSection.getString("color", "black"));
break;
case "cursor":
if (!objectSection.contains("cursor")) {
Debug.echoError("Map script '" + getName() + "'s cursor '" + objectKey + "' has no specified cursor type!");
return;
}
String cursor = objectSection.getString("cursor");
if (cursor == null) {
Debug.echoError("Map script '" + getName() + "'s cursor '" + objectKey + "' is missing a cursor type!");
return;
}
added = new MapCursor(x, y, visible, shouldDebug(), objectSection.getString("direction", "0"), cursor);
break;
case "dot":
added = new MapDot(x, y, visible, shouldDebug(), objectSection.getString("radius", "1"), objectSection.getString("color", "black"));
break;
default:
Debug.echoError("Weird map data!");
break;
}
if (added != null) {
renderer.addObject(added);
if (objectSection.contains("world_coordinates") && objectSection.getString("world_coordinates", "false").equalsIgnoreCase("true")) {
added.worldCoordinates = true;
}
added.showPastEdge = CoreUtilities.equalsIgnoreCase(objectSection.getString("show_past_edge", "false"), "true");
}
}
}
DenizenMapManager.setMap(mapView, renderer);
}
use of com.denizenscript.denizencore.utilities.NaturalOrderComparator in project Denizen-For-Bukkit by DenizenScript.
the class DenizenMapManager method reloadMaps.
public static void reloadMaps() {
Map<Integer, List<MapRenderer>> oldMapRenderers = new HashMap<>();
for (Map.Entry<Integer, 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)) {
int mapId = Integer.valueOf(key);
// TODO: ??? (deprecated short method)
MapView mapView = Bukkit.getServer().getMap((short) mapId);
if (mapView == null) {
Debug.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);
}
}
boolean contextual = mapsSection.getBoolean(key + ".contextual", true);
DenizenMapRenderer renderer = new DenizenMapRenderer(oldRenderers, mapsSection.getBoolean(key + ".auto update", false), contextual);
renderer.displayOriginal = mapsSection.getBoolean(key + ".original", true);
List<String> objects = new ArrayList<>(objectsData.getKeys(false));
objects.sort(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.getString(objectKey + ".debug", "false").equalsIgnoreCase("true");
MapObject object = null;
switch(type) {
case "CURSOR":
object = new MapCursor(xTag, yTag, visibilityTag, debug, objectsData.getString(objectKey + ".direction"), objectsData.getString(objectKey + ".cursor"));
break;
case "IMAGE":
String file = objectsData.getString(objectKey + ".image");
int width = objectsData.getInt(objectKey + ".width", 0);
int height = objectsData.getInt(objectKey + ".height", 0);
object = new MapImage(renderer, xTag, yTag, visibilityTag, debug, file, width, height);
break;
case "TEXT":
object = new MapText(xTag, yTag, visibilityTag, debug, objectsData.getString(objectKey + ".text"), objectsData.getString(objectKey + ".color"));
break;
case "DOT":
object = new MapDot(xTag, yTag, visibilityTag, debug, objectsData.getString(objectKey + ".radius"), objectsData.getString(objectKey + ".color"));
break;
}
if (object != null) {
object.worldCoordinates = objectsData.getString(objectKey + ".world_coordinates", "false").equalsIgnoreCase("true");
object.showPastEdge = objectsData.getString(objectKey + ".show_past_edge", "false").equalsIgnoreCase("true");
renderer.addObject(object);
}
}
mapView.addRenderer(renderer);
mapRenderers.put(mapId, renderer);
}
for (Map.Entry<Integer, List<MapRenderer>> entry : oldMapRenderers.entrySet()) {
int id = entry.getKey();
if (!mapRenderers.containsKey(id)) {
// TODO: ??? (deprecated short method)
MapView mapView = Bukkit.getServer().getMap((short) 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", "."));
}
}
Aggregations