Skip to content

Commit

Permalink
map command minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 23, 2020
1 parent 261ed90 commit faa27a0
Showing 1 changed file with 1 addition and 14 deletions.
Expand Up @@ -34,7 +34,7 @@ public MapCommand() {
// @Name Map
// @Syntax map [<#>/new:<world>] [reset:<location> (scale:<value>) (tracking)/image:<file> (resize)/script:<script>] (x:<#>) (y:<#>)
// @Required 2
// @Maximum 5
// @Maximum 7
// @Short Modifies a new or existing map by adding images or text.
// @Group item
//
Expand Down Expand Up @@ -80,9 +80,7 @@ public MapCommand() {

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (Argument arg : scriptEntry.getProcessedArgs()) {

if (!scriptEntry.hasObject("new")
&& arg.matchesPrefix("new")
&& arg.matchesArgumentType(WorldTag.class)) {
Expand Down Expand Up @@ -149,26 +147,21 @@ else if (!scriptEntry.hasObject("map-id")
}

}

if (!scriptEntry.hasObject("map-id") && !scriptEntry.hasObject("new")) {
throw new InvalidArgumentsException("Must specify a map ID or create a new map!");
}

if (!scriptEntry.hasObject("reset")
&& !scriptEntry.hasObject("reset-loc")
&& !scriptEntry.hasObject("image")
&& !scriptEntry.hasObject("script")) {
throw new InvalidArgumentsException("Must specify a valid action to perform!");
}

scriptEntry.defaultObject("reset", new ElementTag(false)).defaultObject("resize", new ElementTag(false))
.defaultObject("x-value", new ElementTag(0)).defaultObject("y-value", new ElementTag(0));

}

@Override
public void execute(ScriptEntry scriptEntry) {

ElementTag id = scriptEntry.getElement("map-id");
WorldTag create = scriptEntry.getObjectTag("new");
ElementTag reset = scriptEntry.getElement("reset");
Expand All @@ -182,16 +175,12 @@ public void execute(ScriptEntry scriptEntry) {
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 != 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;
if (create != null) {
map = Bukkit.getServer().createMap(create.getWorld());
Expand All @@ -208,7 +197,6 @@ else if (id != null) {
Debug.echoError("The map command failed somehow! Report this to a developer!");
return;
}

if (reset.asBoolean()) {
if (tracking != null) {
map.setTrackingPosition(true);
Expand Down Expand Up @@ -246,6 +234,5 @@ else if (script != null) {
}
}
}

}
}

0 comments on commit faa27a0

Please sign in to comment.