Skip to content

Commit

Permalink
tweak and improve Map command and Map script container
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 13, 2021
1 parent fa441bf commit a294cd7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
Expand Up @@ -24,25 +24,30 @@ public class MapCommand extends AbstractCommand {

public MapCommand() {
setName("map");
setSyntax("map [<#>/new:<world>] [reset:<location> (scale:<value>) (tracking)/image:<file> (resize)/script:<script>] (x:<#>) (y:<#>)");
setSyntax("map [<#>/new:<world>] (reset:<location>) (scale:<value>) (tracking) (image:<file>) (resize) (script:<script>) (x:<#>) (y:<#>)");
setRequiredArguments(2, 7);
isProcedural = false;
}

// <--[command]
// @Name Map
// @Syntax map [<#>/new:<world>] [reset:<location> (scale:<value>) (tracking)/image:<file> (resize)/script:<script>] (x:<#>) (y:<#>)
// @Syntax map [<#>/new:<world>] (reset:<location>) (scale:<value>) (tracking) (image:<file>) (resize) (script:<script>) (x:<#>) (y:<#>)
// @Required 2
// @Maximum 7
// @Short Modifies a new or existing map by adding images or text.
// @Group item
//
// @Description
// This command modifies an existing map, or creates a new one. Using this will override existing
// non-Denizen map renderers with Denizen's custom map renderer.
// This command modifies an existing map, or creates a new one. Using this will override existing non-Denizen map renderers with Denizen's custom map renderer.
//
// You must specify at least one of 'reset', 'script', or 'image'. You can specify multiple at once if you prefer.
//
// When using 'reset', you can specify optionally 'scale' and/or 'tracking'.
// When using 'image' you can optionally specify 'resize'.
//
// You can reset this at any time by using the 'reset:<location>' argument, which will remove all
// images and texts on the map and show the default world map at the specified location.
// You can also specify 'reset' without a location.
//
// The 'scale' argument takes input of one of the values listed here:
// <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/map/MapView.Scale.html>
Expand Down Expand Up @@ -190,8 +195,7 @@ else if (id != null) {
return;
}
}
else {
Debug.echoError("The map command failed somehow! Report this to a developer!");
else { // not possible
return;
}
if (reset.asBoolean()) {
Expand All @@ -211,20 +215,18 @@ else if (id != null) {
map.setWorld(resetLoc.getWorld());
}
}
else if (script != null) {
if (script != null) {
DenizenMapManager.removeDenizenRenderers(map);
((MapScriptContainer) script.getContainer()).applyTo(map);
}
else {
if (image != null) {
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.autoUpdate = true;
}
dmr.addObject(new MapImage(x.asString(), y.asString(), "true", false, image.asString(), wide, high));
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(x.asString(), y.asString(), "true", false, image.asString(), wide, high));
}
}
}
Expand Up @@ -37,11 +37,7 @@ public MapScriptContainer(YamlConfiguration configurationSection, String scriptC
// # | Some map scripts should have this key!
// original: true/false
//
// # The 'custom name' can be anything you wish. Use color tags to make colored custom names.
// # | Some map scripts should have this key!
// display name: custom name
//
// # Whether to constantly update things.
// # Whether to constantly update things. Defaults to true.
// # | Some map scripts should have this key!
// auto update: true
//
Expand All @@ -52,16 +48,18 @@ public MapScriptContainer(YamlConfiguration configurationSection, String scriptC
// # 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.
//
// 2:
// type: text
// # Specify any text, with tags.
// # Specify any text to display.
// text: Hello <player.name>
// # 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:
Expand All @@ -70,8 +68,18 @@ public MapScriptContainer(YamlConfiguration configurationSection, String scriptC
// cursor: red_marker
// # 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
//
// 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>.
Expand All @@ -80,13 +88,9 @@ public MapScriptContainer(YamlConfiguration configurationSection, String scriptC

public void applyTo(MapView mapView) {
DenizenMapRenderer renderer = new DenizenMapRenderer(mapView.getRenderers(), getString("auto update", "true").equalsIgnoreCase("true"));
boolean debug = true;
if (contains("original")) {
renderer.displayOriginal = getString("original").equalsIgnoreCase("true");
}
if (contains("debug")) {
debug = getString("debug").equalsIgnoreCase("true");
}
if (contains("objects")) {
YamlConfiguration objectsSection = getConfigurationSection("objects");
List<StringHolder> objectKeys1 = new ArrayList<>(objectsSection.getKeys(false));
Expand All @@ -105,7 +109,7 @@ public void applyTo(MapView mapView) {
String x = objectSection.getString("x", "0");
String y = objectSection.getString("y", "0");
String visible = objectSection.getString("visible", "true");
boolean worldC = objectSection.contains("world_coordinates") && objectSection.getString("world_coordinates", "false").equalsIgnoreCase("true");
MapObject added = null;
switch (type) {
case "image":
if (!objectSection.contains("image")) {
Expand All @@ -116,7 +120,7 @@ public void applyTo(MapView mapView) {
String image = objectSection.getString("image");
int width = Integer.parseInt(objectSection.getString("width", "0"));
int height = Integer.parseInt(objectSection.getString("height", "0"));
renderer.addObject(new MapImage(x, y, visible, debug, image, width, height));
added = new MapImage(x, y, visible, shouldDebug(), image, width, height);
break;
case "text":
if (!objectSection.contains("text")) {
Expand All @@ -125,7 +129,7 @@ public void applyTo(MapView mapView) {
return;
}
String text = objectSection.getString("text");
renderer.addObject(new MapText(x, y, visible, debug, text));
added = new MapText(x, y, visible, shouldDebug(), text);
break;
case "cursor":
if (!objectSection.contains("cursor")) {
Expand All @@ -139,18 +143,20 @@ public void applyTo(MapView mapView) {
+ "' is missing a cursor type!");
return;
}
renderer.addObject(new MapCursor(x, y, visible, debug, objectSection.getString("direction", "0"), cursor));
added = new MapCursor(x, y, visible, shouldDebug(), objectSection.getString("direction", "0"), cursor);
break;
case "dot":
renderer.addObject(new MapDot(x, y, visible, debug, objectSection.getString("radius", "1"),
objectSection.getString("color", "black")));
added = new MapDot(x, y, visible, shouldDebug(), objectSection.getString("radius", "1"), objectSection.getString("color", "black"));
break;
default:
Debug.echoError("Weird map data!");
break;
}
if (worldC && renderer.mapObjects.size() > 0) {
renderer.mapObjects.get(renderer.mapObjects.size() - 1).worldCoordinates = true;
if (added != null) {
renderer.addObject(added);
if (objectSection.contains("world_coordinates") && objectSection.getString("world_coordinates", "false").equalsIgnoreCase("true")) {
added.worldCoordinates = true;
}
}
}
}
Expand Down

0 comments on commit a294cd7

Please sign in to comment.