Skip to content

Commit

Permalink
Update ChunkTag, AreaContainmentObject and ColorTag tag param u…
Browse files Browse the repository at this point in the history
…sage. (#2364)

* Update tag param usage for `ChunkTag`

Contributes to issue #2355.

* Update tag param usage for `AreaContainmentObject`

Contributes to issue #2355.

* Update tag param usage for `<ColorTag.mix[]>`

Contributes to issue #2355.

* Remove `null` checks in a few `AreaContainmentObject` tags.

New tag processing makes sure the parameter is valid as pointed out by @tal5!

* Remove `null` check in `<ColorTag.mix[]>`
  • Loading branch information
BreadcrumbIsTaken committed Aug 28, 2022
1 parent 8dac5d0 commit 16e64a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,7 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @description
// Returns a boolean indicating whether the specified location is inside this area.
// -->
processor.registerTag(ElementTag.class, "contains", (attribute, area) -> {
if (!attribute.hasParam()) {
return null;
}
LocationTag loc = attribute.paramAsType(LocationTag.class);
if (loc == null) {
return null;
}
processor.registerTag(ElementTag.class, LocationTag.class, "contains", (attribute, area, loc) -> {
return new ElementTag(area.doesContainLocation(loc));
}, "contains_location");

Expand Down Expand Up @@ -253,11 +246,8 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// Gets a list of all block locations with a specified flag within the area.
// Searches the internal flag lists, rather than through all possible blocks.
// -->
processor.registerTag(ListTag.class, "blocks_flagged", (attribute, area) -> {
if (!attribute.hasParam()) {
return null;
}
return area.getBlocksFlagged(CoreUtilities.toLowerCase(attribute.getParam()), attribute);
processor.registerTag(ListTag.class, ElementTag.class, "blocks_flagged", (attribute, area, flagName) -> {
return area.getBlocksFlagged(CoreUtilities.toLowerCase(flagName.toString()), attribute);
});

// <--[tag]
Expand All @@ -276,14 +266,7 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @description
// Returns whether this area is fully inside another cuboid.
// -->
processor.registerTag(ElementTag.class, "is_within", (attribute, area) -> {
if (!attribute.hasParam()) {
return null;
}
CuboidTag cub2 = attribute.paramAsType(CuboidTag.class);
if (cub2 == null) {
return null;
}
processor.registerTag(ElementTag.class, CuboidTag.class, "is_within", (attribute, area, cub2) -> {
CuboidTag cuboid = area instanceof CuboidTag ? (CuboidTag) area : area.getCuboidBoundary();
if (cub2 != null) {
boolean contains = true;
Expand Down Expand Up @@ -319,14 +302,7 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @description
// Returns a copy of the area, with the specified world.
// -->
processor.registerTag(type, "with_world", (attribute, area) -> {
if (!attribute.hasParam()) {
return null;
}
WorldTag world = attribute.paramAsType(WorldTag.class);
if (world == null) {
return null;
}
processor.registerTag(type, WorldTag.class, "with_world", (attribute, area, world) -> {
return (T) area.withWorld(world);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,8 @@ public static void registerTags() {
// @description
// Returns the chunk with the specified coordinates added to it.
// -->
tagProcessor.registerTag(ChunkTag.class, "add", (attribute, object) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag ChunkTag.add[<#>,<#>] must have a value.");
return null;
}
List<String> coords = CoreUtilities.split(attribute.getParam(), ',');
tagProcessor.registerTag(ChunkTag.class, ElementTag.class, "add", (attribute, object, addCoords) -> {
List<String> coords = CoreUtilities.split(addCoords.toString(), ',');
if (coords.size() < 2) {
attribute.echoError("The tag ChunkTag.add[<#>,<#>] requires two values!");
return null;
Expand All @@ -317,12 +313,8 @@ public static void registerTags() {
// @description
// Returns the chunk with the specified coordinates subtracted from it.
// -->
tagProcessor.registerTag(ChunkTag.class, "sub", (attribute, object) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag ChunkTag.add[<#>,<#>] must have a value.");
return null;
}
List<String> coords = CoreUtilities.split(attribute.getParam(), ',');
tagProcessor.registerTag(ChunkTag.class, ElementTag.class, "sub", (attribute, object, subCoords) -> {
List<String> coords = CoreUtilities.split(subCoords.toString(), ',');
if (coords.size() < 2) {
attribute.echoError("The tag ChunkTag.sub[<#>,<#>] requires two values!");
return null;
Expand Down Expand Up @@ -644,16 +636,12 @@ public static void registerTags() {
// Gets a list of all block locations with a specified flag within the CuboidTag.
// Searches the internal flag lists, rather than through all possible blocks.
// -->
tagProcessor.registerTag(ListTag.class, "blocks_flagged", (attribute, object) -> {
if (!attribute.hasParam()) {
attribute.echoError("ChunkTag.blocks_flagged[...] must have an input value.");
return null;
}
tagProcessor.registerTag(ListTag.class, ElementTag.class, "blocks_flagged", (attribute, object, flagNameInput) -> {
Chunk chunk = object.getChunkForTag(attribute);
if (chunk == null) {
return null;
}
String flagName = CoreUtilities.toLowerCase(attribute.getParam());
String flagName = CoreUtilities.toLowerCase(flagNameInput.toString());
ListTag blocks = new ListTag();
LocationFlagSearchHelper.getFlaggedLocations(chunk, flagName, (loc) -> {
blocks.addObject(new LocationTag(loc));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,8 @@ public static void registerTags() {
// @description
// Returns the color that results if you mix this color with another.
// -->
tagProcessor.registerTag(ColorTag.class, "mix", (attribute, object) -> { // Temporarily non-static because the input could be 'random'
ColorTag mixed_with = attribute.paramAsType(ColorTag.class);
if (mixed_with != null) {
return new ColorTag(object.mixWith(mixed_with));
}
else {
Debug.echoError("'" + attribute.getParam() + "' is not a valid color!");
return null;
}
tagProcessor.registerTag(ColorTag.class, ColorTag.class, "mix", (attribute, object, mixWith) -> { // Temporarily non-static because the input could be 'random'
return new ColorTag(object.mixWith(mixWith));
});

// <--[tag]
Expand Down

0 comments on commit 16e64a5

Please sign in to comment.