Skip to content

Commit

Permalink
Map command: 'text' arg
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 3, 2022
1 parent 62147d9 commit 8ff902b
Showing 1 changed file with 15 additions and 12 deletions.
Expand Up @@ -2,11 +2,8 @@

import com.denizenscript.denizen.objects.ColorTag;
import com.denizenscript.denizen.scripts.containers.core.MapScriptContainer;
import com.denizenscript.denizen.utilities.maps.*;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.maps.DenizenMapManager;
import com.denizenscript.denizen.utilities.maps.DenizenMapRenderer;
import com.denizenscript.denizen.utilities.maps.MapDot;
import com.denizenscript.denizen.utilities.maps.MapImage;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.WorldTag;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
Expand All @@ -26,25 +23,25 @@ public class MapCommand extends AbstractCommand {

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

// <--[command]
// @Name Map
// @Syntax map [<#>/new:<world>] (reset:<location>) (scale:<value>) (tracking) (image:<file>) (resize) (script:<script>) (dot:<color>) (radius:<#>) (x:<#>) (y:<#>)
// @Syntax map [<#>/new:<world>] (reset:<location>) (scale:<value>) (tracking) (image:<file>) (resize) (script:<script>) (dot:<color>) (radius:<#>) (x:<#>) (y:<#>) (text:<text>)
// @Required 2
// @Maximum 9
// @Maximum 10
// @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.
//
// You must specify at least one of 'reset', 'script', 'image'. You can specify multiple at once if you prefer.
// You must specify at least one of 'reset', 'script', 'image', 'dot', 'text'. 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'.
Expand Down Expand Up @@ -117,6 +114,7 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag y = scriptEntry.argForPrefixAsElement("y", "0");
ColorTag dot = scriptEntry.argForPrefix("dot", ColorTag.class, true);
ElementTag radius = scriptEntry.argForPrefixAsElement("radius", null);
ElementTag text = scriptEntry.argForPrefixAsElement("text", null);
if (!x.isFloat() || !y.isFloat()) {
throw new InvalidArgumentsRuntimeException("Invalid X or Y value!");
}
Expand All @@ -126,11 +124,11 @@ public void execute(ScriptEntry scriptEntry) {
if (create == null && id == null) {
throw new InvalidArgumentsRuntimeException("Must specify a map ID or create a new map!");
}
if (resetLoc == null && image == null && script == null && dot == null) {
if (resetLoc == null && image == null && script == null && dot == null && text == null) {
throw new InvalidArgumentsRuntimeException("Must specify a valid action to perform!");
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), id, create, resetLoc, image, script, dot, radius, scale, db("resize", resize), db("tracking", tracking), width, height, x, y);
Debug.report(scriptEntry, getName(), id, create, resetLoc, image, script, dot, radius, scale, db("resize", resize), db("tracking", tracking), width, height, x, y, text);
}
MapView map;
if (create != null) {
Expand Down Expand Up @@ -177,5 +175,10 @@ public void execute(ScriptEntry scriptEntry) {
dmr.addObject(new MapDot(x.asString(), y.asString(), "true", false, radius == null ? "1" : radius.toString(), dot.toString()));
dmr.hasChanged = true;
}
if (text != null) {
DenizenMapRenderer dmr = DenizenMapManager.getDenizenRenderer(map);
dmr.addObject(new MapText(x.asString(), y.asString(), "true", false, text.asString(), null));
dmr.hasChanged = true;
}
}
}

0 comments on commit 8ff902b

Please sign in to comment.