use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class CuboidTag method registerTags.
// ///////////////////
// ObjectTag Tag Management
// ///////////////////
public static void registerTags() {
AbstractFlagTracker.registerFlagHandlers(tagProcessor);
AreaContainmentObject.registerTags(CuboidTag.class, tagProcessor);
// <--[tag]
// @attribute <CuboidTag.random>
// @returns LocationTag
// @description
// Returns a random block location within the cuboid.
// (Note: random selection will not be fairly weighted for multi-member cuboids).
// -->
tagProcessor.registerTag(LocationTag.class, "random", (attribute, cuboid) -> {
LocationPair pair = cuboid.pairs.get(CoreUtilities.getRandom().nextInt(cuboid.pairs.size()));
Vector range = pair.high.toVector().subtract(pair.low.toVector()).add(new Vector(1, 1, 1));
range.setX(CoreUtilities.getRandom().nextInt(range.getBlockX()));
range.setY(CoreUtilities.getRandom().nextInt(range.getBlockY()));
range.setZ(CoreUtilities.getRandom().nextInt(range.getBlockZ()));
LocationTag out = pair.low.clone();
out.add(range);
return out;
});
// <--[tag]
// @attribute <CuboidTag.members_size>
// @returns ElementTag(Number)
// @description
// Returns the number of cuboids defined in the CuboidTag.
// -->
tagProcessor.registerTag(ElementTag.class, "members_size", (attribute, cuboid) -> {
return new ElementTag(cuboid.pairs.size());
});
// <--[tag]
// @attribute <CuboidTag.outline>
// @returns ListTag(LocationTag)
// @description
// Returns each block location on the outline of the CuboidTag.
// -->
tagProcessor.registerTag(ListTag.class, "outline", (attribute, cuboid) -> {
return cuboid.getOutline();
}, "get_outline");
// <--[tag]
// @attribute <CuboidTag.outline_2d[<#.#>]>
// @returns ListTag(LocationTag)
// @description
// Returns a list of block locations along the 2D outline of this CuboidTag, at the specified Y level.
// -->
tagProcessor.registerTag(ListTag.class, "outline_2d", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
attribute.echoError("CuboidTag.outline_2d[...] tag must have an input.");
return null;
}
double y = attribute.getDoubleParam();
return cuboid.getOutline2D(y);
});
// <--[tag]
// @attribute <CuboidTag.intersects[<cuboid>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether this cuboid and another intersect.
// -->
tagProcessor.registerTag(ElementTag.class, "intersects", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.intersects[...] must have a value.");
return null;
}
CuboidTag cub2 = attribute.paramAsType(CuboidTag.class);
if (cub2 != null) {
boolean intersects = false;
whole_loop: for (LocationPair pair : cuboid.pairs) {
for (LocationPair pair2 : cub2.pairs) {
if (!pair.low.getWorld().getName().equalsIgnoreCase(pair2.low.getWorld().getName())) {
return new ElementTag("false");
}
if (pair2.low.getX() <= pair.high.getX() && pair2.low.getY() <= pair.high.getY() && pair2.low.getZ() <= pair.high.getZ() && pair2.high.getX() >= pair.low.getX() && pair2.high.getY() >= pair.low.getY() && pair2.high.getZ() >= pair.low.getZ()) {
intersects = true;
break whole_loop;
}
}
}
return new ElementTag(intersects);
}
return null;
});
// <--[tag]
// @attribute <CuboidTag.list_members>
// @returns ListTag(CuboidTag)
// @description
// Returns a list of all sub-cuboids in this CuboidTag (for cuboids that contain multiple sub-cuboids).
// -->
tagProcessor.registerTag(ListTag.class, "list_members", (attribute, cuboid) -> {
List<LocationPair> pairs = cuboid.pairs;
ListTag list = new ListTag();
for (LocationPair pair : pairs) {
list.addObject(new CuboidTag(pair.low.clone(), pair.high.clone()));
}
return list;
});
// <--[tag]
// @attribute <CuboidTag.get[<index>]>
// @returns CuboidTag
// @description
// Returns a cuboid representing the one component of this cuboid (for cuboids that contain multiple sub-cuboids).
// -->
tagProcessor.registerTag(CuboidTag.class, "get", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.get[...] must have a value.");
return null;
} else {
int member = attribute.getIntParam();
if (member < 1) {
member = 1;
}
if (member > cuboid.pairs.size()) {
member = cuboid.pairs.size();
}
LocationPair pair = cuboid.pairs.get(member - 1);
return new CuboidTag(pair.low.clone(), pair.high.clone());
}
}, "member", "get_member");
// <--[tag]
// @attribute <CuboidTag.set[<cuboid>].at[<index>]>
// @returns CuboidTag
// @mechanism CuboidTag.set_member
// @description
// Returns a modified copy of this cuboid, with the specific sub-cuboid index changed to hold the input cuboid.
// -->
tagProcessor.registerTag(CuboidTag.class, "set", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.set[...] must have a value.");
return null;
} else {
CuboidTag subCuboid = attribute.paramAsType(CuboidTag.class);
if (!attribute.startsWith("at", 2)) {
attribute.echoError("The tag CuboidTag.set[...] must be followed by an 'at'.");
return null;
}
if (!attribute.hasContext(2)) {
attribute.echoError("The tag CuboidTag.set[...].at[...] must have an 'at' value.");
return null;
}
int member = attribute.getIntContext(2);
if (member < 1) {
member = 1;
}
if (member > cuboid.pairs.size()) {
member = cuboid.pairs.size();
}
attribute.fulfill(1);
LocationPair pair = subCuboid.pairs.get(0);
CuboidTag cloned = cuboid.clone();
cloned.pairs.set(member - 1, new LocationPair(pair.low.clone(), pair.high.clone()));
return cloned;
}
});
// <--[tag]
// @attribute <CuboidTag.add_member[<cuboid>|...]>
// @returns CuboidTag
// @mechanism CuboidTag.add_member
// @description
// Returns a modified copy of this cuboid, with the input cuboid(s) added at the end.
// -->
tagProcessor.registerTag(CuboidTag.class, "add_member", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.add_member[...] must have a value.");
return null;
}
cuboid = cuboid.clone();
int member = cuboid.pairs.size() + 1;
ObjectTag param = attribute.getParamObject();
// -->
if (attribute.startsWith("at", 2)) {
if (!attribute.hasContext(2)) {
attribute.echoError("The tag CuboidTag.add_member[...].at[...] must have an 'at' value.");
return null;
}
member = attribute.getIntContext(2);
attribute.fulfill(1);
}
if (member < 1) {
member = 1;
}
if (member > cuboid.pairs.size() + 1) {
member = cuboid.pairs.size() + 1;
}
if (!(param instanceof CuboidTag) && param.toString().startsWith("li@")) {
// Old cuboid identity used '|' symbol, so require 'li@' to be a list
for (CuboidTag subCuboid : param.asType(ListTag.class, attribute.context).filter(CuboidTag.class, attribute.context)) {
LocationPair pair = subCuboid.pairs.get(0);
cuboid.pairs.add(member - 1, new LocationPair(pair.low.clone(), pair.high.clone()));
member++;
}
} else {
CuboidTag subCuboid = param.asType(CuboidTag.class, attribute.context);
LocationPair pair = subCuboid.pairs.get(0);
cuboid.pairs.add(member - 1, new LocationPair(pair.low.clone(), pair.high.clone()));
}
return cuboid;
});
// <--[tag]
// @attribute <CuboidTag.remove_member[<#>]>
// @returns CuboidTag
// @mechanism CuboidTag.remove_member
// @description
// Returns a modified copy of this cuboid, with member at the input index removed.
// -->
tagProcessor.registerTag(CuboidTag.class, "remove_member", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.remove_member[...] must have a value.");
return null;
}
cuboid = cuboid.clone();
int member = attribute.getIntParam();
if (member < 1) {
member = 1;
}
if (member > cuboid.pairs.size() + 1) {
member = cuboid.pairs.size() + 1;
}
cuboid.pairs.remove(member - 1);
return cuboid;
});
// <--[tag]
// @attribute <CuboidTag.center>
// @returns LocationTag
// @description
// Returns the location of the exact center of the cuboid.
// Not valid for multi-member CuboidTags.
// -->
tagProcessor.registerTag(LocationTag.class, "center", (attribute, cuboid) -> {
LocationPair pair;
if (!attribute.hasParam()) {
pair = cuboid.pairs.get(0);
} else {
// legacy
int member = attribute.getIntParam();
if (member < 1) {
member = 1;
}
if (member > cuboid.pairs.size()) {
member = cuboid.pairs.size();
}
pair = cuboid.pairs.get(member - 1);
}
LocationTag base = pair.high.clone().add(pair.low).add(1.0, 1.0, 1.0);
base.setX(base.getX() / 2.0);
base.setY(base.getY() / 2.0);
base.setZ(base.getZ() / 2.0);
return base;
});
// <--[tag]
// @attribute <CuboidTag.volume>
// @returns ElementTag(Number)
// @description
// Returns the volume of the cuboid.
// Effectively equivalent to: (size.x * size.y * size.z).
// Not valid for multi-member CuboidTags.
// -->
tagProcessor.registerTag(ElementTag.class, "volume", (attribute, cuboid) -> {
LocationPair pair = cuboid.pairs.get(0);
Location base = pair.high.clone().subtract(pair.low.clone()).add(1, 1, 1);
return new ElementTag(base.getX() * base.getY() * base.getZ());
});
// <--[tag]
// @attribute <CuboidTag.size>
// @returns LocationTag
// @description
// Returns the size of the cuboid.
// Effectively equivalent to: (max - min) + (1,1,1)
// Not valid for multi-member CuboidTags.
// -->
tagProcessor.registerTag(LocationTag.class, "size", (attribute, cuboid) -> {
LocationPair pair;
if (!attribute.hasParam()) {
pair = cuboid.pairs.get(0);
} else {
// legacy
int member = attribute.getIntParam();
if (member < 1) {
member = 1;
}
if (member > cuboid.pairs.size()) {
member = cuboid.pairs.size();
}
pair = cuboid.pairs.get(member - 1);
}
Location base = pair.high.clone().subtract(pair.low.clone()).add(1, 1, 1);
return new LocationTag(base);
});
// <--[tag]
// @attribute <CuboidTag.max>
// @returns LocationTag
// @description
// Returns the highest-numbered (maximum) corner location.
// Not valid for multi-member CuboidTags.
// -->
tagProcessor.registerTag(LocationTag.class, "max", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
return cuboid.pairs.get(0).high;
} else {
// legacy
int member = attribute.getIntParam();
if (member < 1) {
member = 1;
}
if (member > cuboid.pairs.size()) {
member = cuboid.pairs.size();
}
return cuboid.pairs.get(member - 1).high;
}
});
// <--[tag]
// @attribute <CuboidTag.min>
// @returns LocationTag
// @description
// Returns the lowest-numbered (minimum) corner location.
// Not valid for multi-member CuboidTags.
// -->
tagProcessor.registerTag(LocationTag.class, "min", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
return cuboid.pairs.get(0).low;
} else {
// legacy
int member = attribute.getIntParam();
if (member < 1) {
member = 1;
}
if (member > cuboid.pairs.size()) {
member = cuboid.pairs.size();
}
return cuboid.pairs.get(member - 1).low;
}
});
// <--[tag]
// @attribute <CuboidTag.corners>
// @returns ListTag(LocationTag)
// @description
// Returns all 8 corners of the cuboid.
// The 4 low corners, then the 4 high corners.
// In order X-Z-, X+Z-, X-Z+, X+Z+
// If the object is a multi-member cuboid, returns corners for all members in sequence.
// -->
tagProcessor.registerTag(ListTag.class, "corners", (attribute, cuboid) -> {
ListTag output = new ListTag();
for (LocationPair pair : cuboid.pairs) {
output.addObject(new LocationTag(pair.low.getX(), pair.low.getY(), pair.low.getZ(), pair.low.getWorldName()));
output.addObject(new LocationTag(pair.high.getX(), pair.low.getY(), pair.low.getZ(), pair.low.getWorldName()));
output.addObject(new LocationTag(pair.low.getX(), pair.low.getY(), pair.high.getZ(), pair.low.getWorldName()));
output.addObject(new LocationTag(pair.high.getX(), pair.low.getY(), pair.high.getZ(), pair.low.getWorldName()));
output.addObject(new LocationTag(pair.low.getX(), pair.high.getY(), pair.low.getZ(), pair.low.getWorldName()));
output.addObject(new LocationTag(pair.high.getX(), pair.high.getY(), pair.low.getZ(), pair.low.getWorldName()));
output.addObject(new LocationTag(pair.low.getX(), pair.high.getY(), pair.high.getZ(), pair.low.getWorldName()));
output.addObject(new LocationTag(pair.high.getX(), pair.high.getY(), pair.high.getZ(), pair.low.getWorldName()));
}
return output;
});
// <--[tag]
// @attribute <CuboidTag.shift[<vector>]>
// @returns CuboidTag
// @description
// Returns a copy of this cuboid, with all members shifted by the given vector LocationTag.
// For example, a cuboid from 5,5,5 to 10,10,10, shifted 100,0,100, would return a cuboid from 105,5,105 to 110,10,110.
// -->
tagProcessor.registerTag(CuboidTag.class, "shift", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.shift[...] must have a value.");
return null;
}
LocationTag vector = attribute.paramAsType(LocationTag.class);
if (vector != null) {
return cuboid.shifted(vector);
}
return null;
});
// <--[tag]
// @attribute <CuboidTag.include[<location>/<cuboid>]>
// @returns CuboidTag
// @description
// Expands the first member of the CuboidTag to contain the given location (or entire cuboid), and returns the expanded cuboid.
// -->
tagProcessor.registerTag(CuboidTag.class, "include", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.include[...] must have a value.");
return null;
}
CuboidTag newCuboid = CuboidTag.valueOf(attribute.getParam(), CoreUtilities.noDebugContext);
if (newCuboid != null) {
return cuboid.including(newCuboid.getLow(0)).including(newCuboid.getHigh(0));
}
LocationTag loc = attribute.paramAsType(LocationTag.class);
if (loc != null) {
return cuboid.including(loc);
}
return null;
});
// <--[tag]
// @attribute <CuboidTag.include_x[<number>]>
// @returns CuboidTag
// @description
// Expands the first member of the CuboidTag to contain the given X value, and returns the expanded cuboid.
// -->
tagProcessor.registerTag(CuboidTag.class, "include_x", (attribute, cuboid) -> {
cuboid = cuboid.clone();
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.include_x[...] must have a value.");
return null;
}
double x = attribute.getDoubleParam();
if (x < cuboid.pairs.get(0).low.getX()) {
cuboid.pairs.get(0).low = new LocationTag(cuboid.pairs.get(0).low.getWorld(), x, cuboid.pairs.get(0).low.getY(), cuboid.pairs.get(0).low.getZ());
}
if (x > cuboid.pairs.get(0).high.getX()) {
cuboid.pairs.get(0).high = new LocationTag(cuboid.pairs.get(0).high.getWorld(), x, cuboid.pairs.get(0).high.getY(), cuboid.pairs.get(0).high.getZ());
}
return cuboid;
});
// <--[tag]
// @attribute <CuboidTag.include_y[<number>]>
// @returns CuboidTag
// @description
// Expands the first member of the CuboidTag to contain the given Y value, and returns the expanded cuboid.
// -->
tagProcessor.registerTag(CuboidTag.class, "include_y", (attribute, cuboid) -> {
cuboid = cuboid.clone();
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.include_y[...] must have a value.");
return null;
}
double y = attribute.getDoubleParam();
if (y < cuboid.pairs.get(0).low.getY()) {
cuboid.pairs.get(0).low = new LocationTag(cuboid.pairs.get(0).low.getWorld(), cuboid.pairs.get(0).low.getX(), y, cuboid.pairs.get(0).low.getZ());
}
if (y > cuboid.pairs.get(0).high.getY()) {
cuboid.pairs.get(0).high = new LocationTag(cuboid.pairs.get(0).high.getWorld(), cuboid.pairs.get(0).high.getX(), y, cuboid.pairs.get(0).high.getZ());
}
return cuboid;
});
// <--[tag]
// @attribute <CuboidTag.include_z[<number>]>
// @returns CuboidTag
// @description
// Expands the first member of the CuboidTag to contain the given Z value, and returns the expanded cuboid.
// -->
tagProcessor.registerTag(CuboidTag.class, "include_z", (attribute, cuboid) -> {
cuboid = cuboid.clone();
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.include_z[...] must have a value.");
return null;
}
double z = attribute.getDoubleParam();
if (z < cuboid.pairs.get(0).low.getZ()) {
cuboid.pairs.get(0).low = new LocationTag(cuboid.pairs.get(0).low.getWorld(), cuboid.pairs.get(0).low.getX(), cuboid.pairs.get(0).low.getY(), z);
}
if (z > cuboid.pairs.get(0).high.getZ()) {
cuboid.pairs.get(0).high = new LocationTag(cuboid.pairs.get(0).high.getWorld(), cuboid.pairs.get(0).high.getX(), cuboid.pairs.get(0).high.getY(), z);
}
return cuboid;
});
// <--[tag]
// @attribute <CuboidTag.with_min[<location>]>
// @returns CuboidTag
// @description
// Changes the cuboid to have the given minimum location, and returns the changed cuboid.
// If values in the new min are higher than the existing max, the output max will contain the new min values,
// and the output min will contain the old max values.
// Note that this is equivalent to constructing a cuboid with the input value and the original cuboids max value.
// Not valid for multi-member CuboidTags.
// -->
tagProcessor.registerTag(CuboidTag.class, "with_min", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.with_min[...] must have a value.");
return null;
}
LocationTag location = attribute.paramAsType(LocationTag.class);
return new CuboidTag(location, cuboid.pairs.get(0).high);
});
// <--[tag]
// @attribute <CuboidTag.with_max[<location>]>
// @returns CuboidTag
// @description
// Changes the cuboid to have the given maximum location, and returns the changed cuboid.
// If values in the new max are lower than the existing min, the output min will contain the new max values,
// and the output max will contain the old min values.
// Note that this is equivalent to constructing a cuboid with the input value and the original cuboids min value.
// Not valid for multi-member CuboidTags.
// -->
tagProcessor.registerTag(CuboidTag.class, "with_max", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.with_max[...] must have a value.");
return null;
}
LocationTag location = attribute.paramAsType(LocationTag.class);
return new CuboidTag(location, cuboid.pairs.get(0).low);
});
// <--[tag]
// @attribute <CuboidTag.expand[<location>]>
// @returns CuboidTag
// @description
// Expands the cuboid by the given amount, and returns the changed cuboid.
// This will decrease the min coordinates by the given vector location, and increase the max coordinates by it.
// Supplying a negative input will therefore contract the cuboid.
// Note that you can also specify a single number to expand all coordinates by the same amount (equivalent to specifying a location that is that value on X, Y, and Z).
// Not valid for multi-member CuboidTags.
// -->
tagProcessor.registerTag(CuboidTag.class, "expand", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.expand[...] must have a value.");
return null;
}
Vector expandBy;
if (ArgumentHelper.matchesInteger(attribute.getParam())) {
int val = attribute.getIntParam();
expandBy = new Vector(val, val, val);
} else {
expandBy = attribute.paramAsType(LocationTag.class).toVector();
}
LocationPair pair = cuboid.pairs.get(0);
return new CuboidTag(pair.low.clone().subtract(expandBy), pair.high.clone().add(expandBy));
});
// <--[tag]
// @attribute <CuboidTag.expand_one_side[<location>]>
// @returns CuboidTag
// @description
// Expands the cuboid by the given amount in just one direction, and returns the changed cuboid.
// If a coordinate is positive, it will expand the high value. If it is negative, it will expand the low value.
// Note that you can also specify a single number to expand all coordinates by the same amount (equivalent to specifying a location that is that value on X, Y, and Z).
// Inverted by <@link tag CuboidTag.shrink_one_side>
// Not valid for multi-member CuboidTags.
// -->
tagProcessor.registerTag(CuboidTag.class, "expand_one_side", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.expand_one_side[...] must have a value.");
return null;
}
Vector expandBy;
if (ArgumentHelper.matchesInteger(attribute.getParam())) {
int val = attribute.getIntParam();
expandBy = new Vector(val, val, val);
} else {
expandBy = attribute.paramAsType(LocationTag.class).toVector();
}
LocationPair pair = cuboid.pairs.get(0);
LocationTag low = pair.low.clone();
LocationTag high = pair.high.clone();
if (expandBy.getBlockX() < 0) {
low.setX(low.getBlockX() + expandBy.getBlockX());
} else {
high.setX(high.getBlockX() + expandBy.getBlockX());
}
if (expandBy.getBlockY() < 0) {
low.setY(low.getBlockY() + expandBy.getBlockY());
} else {
high.setY(high.getBlockY() + expandBy.getBlockY());
}
if (expandBy.getBlockZ() < 0) {
low.setZ(low.getBlockZ() + expandBy.getBlockZ());
} else {
high.setZ(high.getBlockZ() + expandBy.getBlockZ());
}
return new CuboidTag(low, high);
});
// <--[tag]
// @attribute <CuboidTag.shrink_one_side[<location>]>
// @returns CuboidTag
// @description
// Shrinks the cuboid by the given amount in just one direction, and returns the changed cuboid.
// If a coordinate is positive, it will shrink the high value. If it is negative, it will shrink the low value.
// Note that you can also specify a single number to expand all coordinates by the same amount (equivalent to specifying a location that is that value on X, Y, and Z).
// Inverted by <@link tag CuboidTag.expand_one_side>
// Not valid for multi-member CuboidTags.
// If you shrink past the limits of the cuboid's size, the cuboid will flip and start expanding the opposite direction.
// -->
tagProcessor.registerTag(CuboidTag.class, "shrink_one_side", (attribute, cuboid) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag CuboidTag.shrink_one_side[...] must have a value.");
return null;
}
Vector expandBy;
if (ArgumentHelper.matchesInteger(attribute.getParam())) {
int val = attribute.getIntParam();
expandBy = new Vector(val, val, val);
} else {
expandBy = attribute.paramAsType(LocationTag.class).toVector();
}
LocationPair pair = cuboid.pairs.get(0);
LocationTag low = pair.low.clone();
LocationTag high = pair.high.clone();
if (expandBy.getBlockX() < 0) {
low.setX(low.getBlockX() - expandBy.getBlockX());
} else {
high.setX(high.getBlockX() - expandBy.getBlockX());
}
if (expandBy.getBlockY() < 0) {
low.setY(low.getBlockY() - expandBy.getBlockY());
} else {
high.setY(high.getBlockY() - expandBy.getBlockY());
}
if (expandBy.getBlockZ() < 0) {
low.setZ(low.getBlockZ() - expandBy.getBlockZ());
} else {
high.setZ(high.getBlockZ() - expandBy.getBlockZ());
}
return new CuboidTag(low, high);
});
// <--[tag]
// @attribute <CuboidTag.chunks>
// @returns ListTag(ChunkTag)
// @description
// Gets a list of all chunks entirely within the CuboidTag (ignoring the Y axis).
// -->
tagProcessor.registerTag(ListTag.class, "chunks", (attribute, cuboid) -> {
ListTag chunks = new ListTag();
for (LocationPair pair : cuboid.pairs) {
int minY = pair.low.getBlockY();
ChunkTag minChunk = new ChunkTag(pair.low);
int minX = minChunk.getX();
int minZ = minChunk.getZ();
if (!cuboid.isInsideCuboid(new Location(cuboid.getWorld().getWorld(), minChunk.getX() * 16, minY, minChunk.getZ() * 16))) {
minX++;
minZ++;
}
ChunkTag maxChunk = new ChunkTag(pair.high);
int maxX = maxChunk.getX();
int maxZ = maxChunk.getZ();
if (cuboid.isInsideCuboid(new Location(cuboid.getWorld().getWorld(), maxChunk.getX() * 16 + 15, minY, maxChunk.getZ() * 16 + 15))) {
maxX++;
maxZ++;
}
for (int x = minX; x < maxX; x++) {
for (int z = minZ; z < maxZ; z++) {
chunks.addObject(new ChunkTag(cuboid.getWorld(), x, z));
}
}
}
return chunks.deduplicate();
}, "list_chunks");
// <--[tag]
// @attribute <CuboidTag.partial_chunks>
// @returns ListTag(ChunkTag)
// @description
// Gets a list of all chunks partially or entirely within the CuboidTag.
// -->
tagProcessor.registerTag(ListTag.class, "partial_chunks", (attribute, cuboid) -> {
ListTag chunks = new ListTag();
for (LocationPair pair : cuboid.pairs) {
ChunkTag minChunk = new ChunkTag(pair.low);
ChunkTag maxChunk = new ChunkTag(pair.high);
for (int x = minChunk.getX(); x <= maxChunk.getX(); x++) {
for (int z = minChunk.getZ(); z <= maxChunk.getZ(); z++) {
chunks.addObject(new ChunkTag(cuboid.getWorld(), x, z));
}
}
}
return chunks;
}, "list_partial_chunks");
// <--[tag]
// @attribute <CuboidTag.note_name>
// @returns ElementTag
// @description
// Gets the name of a noted CuboidTag. If the cuboid isn't noted, this is null.
// -->
tagProcessor.registerTag(ElementTag.class, "note_name", (attribute, cuboid) -> {
String noteName = NoteManager.getSavedId(cuboid);
if (noteName == null) {
return null;
}
return new ElementTag(noteName);
}, "notable_name");
tagProcessor.registerTag(ElementTag.class, "full", (attribute, cuboid) -> {
Deprecations.cuboidFullTag.warn(attribute.context);
return new ElementTag(cuboid.identifyFull());
});
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class BiomeTag method registerTags.
public static void registerTags() {
AbstractFlagTracker.registerFlagHandlers(tagProcessor);
// <--[tag]
// @attribute <BiomeTag.downfall_type>
// @returns ElementTag
// @mechanism BiomeTag.downfall_type
// @description
// Returns this biome's downfall type for when a world has weather.
// This can be RAIN, SNOW, or NONE.
// -->
tagProcessor.registerTag(ElementTag.class, "downfall_type", (attribute, object) -> {
return new ElementTag(CoreUtilities.toLowerCase(object.biome.getDownfallType().name()));
});
// <--[tag]
// @attribute <BiomeTag.name>
// @returns ElementTag
// @description
// Returns this biome's name.
// -->
tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
return new ElementTag(CoreUtilities.toLowerCase(object.biome.getName()));
});
// <--[tag]
// @attribute <BiomeTag.humidity>
// @returns ElementTag(Decimal)
// @mechanism BiomeTag.humidity
// @description
// Returns the humidity of this biome.
// -->
tagProcessor.registerTag(ElementTag.class, "humidity", (attribute, object) -> {
return new ElementTag(object.biome.getHumidity());
});
// <--[tag]
// @attribute <BiomeTag.temperature>
// @returns ElementTag(Decimal)
// @mechanism BiomeTag.temperature
// @description
// Returns the temperature of this biome.
// -->
tagProcessor.registerTag(ElementTag.class, "temperature", (attribute, object) -> {
return new ElementTag(object.biome.getTemperature());
});
// <--[tag]
// @attribute <BiomeTag.spawnable_entities[(<type>)]>
// @returns ListTag(EntityTag)
// @description
// Returns all entities that spawn naturally in this biome.
// Optionally specify a type as: AMBIENT, CREATURES, MONSTERS, WATER, or ALL.
// (By default, will be "ALL").
//
// -->
tagProcessor.registerTag(ListTag.class, "spawnable_entities", (attribute, object) -> {
List<EntityType> entityTypes;
if (attribute.startsWith("ambient", 2)) {
Deprecations.biomeSpawnableTag.warn(attribute.context);
attribute.fulfill(1);
entityTypes = object.biome.getAmbientEntities();
} else if (attribute.startsWith("creatures", 2)) {
Deprecations.biomeSpawnableTag.warn(attribute.context);
attribute.fulfill(1);
entityTypes = object.biome.getCreatureEntities();
} else if (attribute.startsWith("monsters", 2)) {
Deprecations.biomeSpawnableTag.warn(attribute.context);
attribute.fulfill(1);
entityTypes = object.biome.getMonsterEntities();
} else if (attribute.startsWith("water", 2)) {
Deprecations.biomeSpawnableTag.warn(attribute.context);
attribute.fulfill(1);
entityTypes = object.biome.getWaterEntities();
} else {
String type = attribute.hasParam() ? CoreUtilities.toLowerCase(attribute.getParam()) : "all";
switch(type) {
case "ambient":
entityTypes = object.biome.getAmbientEntities();
break;
case "creatures":
entityTypes = object.biome.getCreatureEntities();
break;
case "monsters":
entityTypes = object.biome.getMonsterEntities();
break;
case "water":
entityTypes = object.biome.getWaterEntities();
break;
default:
entityTypes = object.biome.getAllEntities();
break;
}
}
ListTag list = new ListTag();
for (EntityType entityType : entityTypes) {
list.add(entityType.name());
}
return list;
});
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ColorTag method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <ColorTag.hex>
// @returns ElementTag
// @description
// Returns a hex code formatting of this color, like '#ff00ff'.
// -->
tagProcessor.registerTag(ElementTag.class, "hex", (attribute, object) -> {
return new ElementTag("#" + CoreUtilities.hexEncode(new byte[] { (byte) object.color.getRed(), (byte) object.color.getGreen(), (byte) object.color.getBlue() }));
});
// <--[tag]
// @attribute <ColorTag.red>
// @returns ElementTag(Number)
// @description
// Returns the red value of this color (0 to 255).
// -->
tagProcessor.registerTag(ElementTag.class, "red", (attribute, object) -> {
return new ElementTag(object.color.getRed());
});
// <--[tag]
// @attribute <ColorTag.green>
// @returns ElementTag(Number)
// @description
// Returns the green value of this color (0 to 255).
// -->
tagProcessor.registerTag(ElementTag.class, "green", (attribute, object) -> {
return new ElementTag(object.color.getGreen());
});
// <--[tag]
// @attribute <ColorTag.blue>
// @returns ElementTag(Number)
// @description
// Returns the blue value of this color (0 to 255).
// -->
tagProcessor.registerTag(ElementTag.class, "blue", (attribute, object) -> {
return new ElementTag(object.color.getBlue());
});
// <--[tag]
// @attribute <ColorTag.rgb>
// @returns ElementTag
// @description
// Returns the RGB value of this color.
// EG, 255,0,255
// -->
tagProcessor.registerTag(ElementTag.class, "rgb", (attribute, object) -> {
Color color = object.color;
return new ElementTag(color.getRed() + "," + color.getGreen() + "," + color.getBlue());
});
// <--[tag]
// @attribute <ColorTag.hue>
// @returns ElementTag(Number)
// @description
// Returns the hue value of this color (0 to 255).
// -->
tagProcessor.registerTag(ElementTag.class, "hue", (attribute, object) -> {
return new ElementTag(object.toHSB()[0]);
});
// <--[tag]
// @attribute <ColorTag.saturation>
// @returns ElementTag(Number)
// @description
// Returns the saturation value of this color (0 to 255).
// -->
tagProcessor.registerTag(ElementTag.class, "saturation", (attribute, object) -> {
return new ElementTag(object.toHSB()[1]);
});
// <--[tag]
// @attribute <ColorTag.brightness>
// @returns ElementTag(Number)
// @description
// Returns the brightness value of this color (0 to 255).
// -->
tagProcessor.registerTag(ElementTag.class, "brightness", (attribute, object) -> {
return new ElementTag(object.toHSB()[2]);
});
// <--[tag]
// @attribute <ColorTag.hsv>
// @returns ElementTag
// @description
// Returns the HSV value of this color.
// EG, 100,100,255
// -->
tagProcessor.registerTag(ElementTag.class, "hsv", (attribute, object) -> {
int[] HSV = object.toHSB();
return new ElementTag(HSV[0] + "," + HSV[1] + "," + HSV[2]);
});
// <--[tag]
// @attribute <ColorTag.with_red[<red>]>
// @returns ColorTag
// @description
// Returns a copy of this color object with a different red value (0 to 255).
// -->
tagProcessor.registerTag(ColorTag.class, "with_red", (attribute, object) -> {
return new ColorTag(object.color.setRed(attribute.getIntParam()));
});
// <--[tag]
// @attribute <ColorTag.with_green[<green>]>
// @returns ColorTag
// @description
// Returns a copy of this color object with a different green value (0 to 255).
// -->
tagProcessor.registerTag(ColorTag.class, "with_green", (attribute, object) -> {
return new ColorTag(object.color.setGreen(attribute.getIntParam()));
});
// <--[tag]
// @attribute <ColorTag.with_blue[<blue>]>
// @returns ColorTag
// @description
// Returns a copy of this color object with a different blue value (0 to 255).
// -->
tagProcessor.registerTag(ColorTag.class, "with_blue", (attribute, object) -> {
return new ColorTag(object.color.setBlue(attribute.getIntParam()));
});
// <--[tag]
// @attribute <ColorTag.with_hue[<hue>]>
// @returns ColorTag
// @description
// Returns a copy of this color object with a different hue value (0 to 255).
// -->
tagProcessor.registerTag(ColorTag.class, "with_hue", (attribute, object) -> {
int[] HSB = object.toHSB();
HSB[0] = attribute.getIntParam();
return fromHSB(HSB);
});
// <--[tag]
// @attribute <ColorTag.with_saturation[<saturation>]>
// @returns ColorTag
// @description
// Returns a copy of this color object with a different saturation value (0 to 255).
// -->
tagProcessor.registerTag(ColorTag.class, "with_saturation", (attribute, object) -> {
int[] HSB = object.toHSB();
HSB[1] = attribute.getIntParam();
return fromHSB(HSB);
});
// <--[tag]
// @attribute <ColorTag.with_brightness[<brightness>]>
// @returns ColorTag
// @description
// Returns a copy of this color object with a different brightness value (0 to 255).
// -->
tagProcessor.registerTag(ColorTag.class, "with_brightness", (attribute, object) -> {
int[] HSB = object.toHSB();
HSB[2] = attribute.getIntParam();
return fromHSB(HSB);
});
// <--[tag]
// @attribute <ColorTag.name>
// @returns ElementTag
// @description
// Returns the name of this color (or red,green,blue if none).
// -->
tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
return new ElementTag(object.identify().substring(3));
});
// <--[tag]
// @attribute <ColorTag.mix[<color>]>
// @returns ColorTag
// @description
// Returns the color that results if you mix this color with another.
// -->
tagProcessor.registerTag(ColorTag.class, "mix", (attribute, object) -> {
if (!attribute.hasParam()) {
Debug.echoError("The tag ListTag.insert[...] must have a value.");
return null;
}
ColorTag mixed_with = attribute.paramAsType(ColorTag.class);
if (mixed_with != null) {
return new ColorTag(object.color.mixColors(mixed_with.getColor()));
} else {
Debug.echoError("'" + attribute.getParam() + "' is not a valid color!");
return null;
}
});
// <--[tag]
// @attribute <ColorTag.to_particle_offset>
// @returns LocationTag
// @description
// Returns the color as a particle offset, for use with <@link command playeffect>.
// -->
tagProcessor.registerTag(LocationTag.class, "to_particle_offset", (attribute, object) -> {
Color valid = object.color;
if (valid.asRGB() == 0) {
valid = Color.fromRGB(1, 0, 0);
}
return new LocationTag(null, valid.getRed() / 255F, valid.getGreen() / 255F, valid.getBlue() / 255F);
});
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class EllipsoidTag method registerTags.
public static void registerTags() {
AbstractFlagTracker.registerFlagHandlers(tagProcessor);
AreaContainmentObject.registerTags(EllipsoidTag.class, tagProcessor);
// <--[tag]
// @attribute <EllipsoidTag.random>
// @returns LocationTag
// @description
// Returns a random decimal location within the ellipsoid.
// Note that distribution of results will not be completely even.
// -->
tagProcessor.registerTag(LocationTag.class, "random", (attribute, object) -> {
// This is an awkward hack to try to weight towards the center a bit (to counteract the weight-away-from-center that would otherwise happen).
double y = (Math.sqrt(CoreUtilities.getRandom().nextDouble()) * 2 - 1) * object.size.getY();
Vector result = new Vector();
result.setY(y);
double yProg = Math.abs(y) / object.size.getY();
double subWidth = Math.sqrt(1.0 - yProg * yProg);
double maxX = object.size.getX() * subWidth;
double maxZ = object.size.getZ() * subWidth;
result.setX(maxX * (CoreUtilities.getRandom().nextDouble() * 2 - 1));
result.setZ(maxZ * (CoreUtilities.getRandom().nextDouble() * 2 - 1));
LocationTag out = object.center.clone();
out.add(result);
return out;
});
// <--[tag]
// @attribute <EllipsoidTag.location>
// @returns LocationTag
// @description
// Returns the location of the ellipsoid.
// -->
tagProcessor.registerTag(LocationTag.class, "location", (attribute, object) -> {
return object.center;
});
// <--[tag]
// @attribute <EllipsoidTag.size>
// @returns LocationTag
// @description
// Returns the size of the ellipsoid.
// -->
tagProcessor.registerTag(LocationTag.class, "size", (attribute, object) -> {
return object.size;
});
// <--[tag]
// @attribute <EllipsoidTag.add[<location>]>
// @returns EllipsoidTag
// @description
// Returns a copy of this ellipsoid, shifted by the input location.
// -->
tagProcessor.registerTag(EllipsoidTag.class, "add", (attribute, object) -> {
if (!attribute.hasParam()) {
attribute.echoError("ellipsoid.add[...] tag must have an input.");
return null;
}
return new EllipsoidTag(object.center.clone().add(attribute.paramAsType(LocationTag.class)), object.size.clone());
});
// <--[tag]
// @attribute <EllipsoidTag.include[<location>]>
// @returns EllipsoidTag
// @description
// Returns a copy of this ellipsoid, with the size value adapted to include the specified world location.
// -->
tagProcessor.registerTag(EllipsoidTag.class, "include", (attribute, object) -> {
if (!attribute.hasParam()) {
attribute.echoError("ellipsoid.include[...] tag must have an input.");
return null;
}
LocationTag target = attribute.paramAsType(LocationTag.class);
if (object.contains(target)) {
return object;
}
LocationTag size = object.size.clone();
Vector relative = target.toVector().subtract(object.center.toVector());
// Cuboid minimum expansion
size.setX(Math.max(size.getX(), Math.abs(relative.getX())));
size.setY(Math.max(size.getY(), Math.abs(relative.getY())));
size.setZ(Math.max(size.getZ(), Math.abs(relative.getZ())));
EllipsoidTag result = new EllipsoidTag(object.center.clone(), new LocationTag(size));
if (result.contains(target)) {
return result;
}
double sizeLen = size.length();
// Ellipsoid additional expand
while (!result.contains(target)) {
// I gave up on figuring out the math for this, so here's an awful loop-hack
double projX = (relative.getX() * relative.getX()) / (size.getX() * size.getX());
double projY = (relative.getY() * relative.getY()) / (size.getY() * size.getY());
double projZ = (relative.getZ() * relative.getZ()) / (size.getZ() * size.getZ());
double scale = Math.max(projX + projY + projZ, sizeLen * 0.01);
if (projX >= projY && projX >= projZ) {
size.setX(size.getX() + scale);
} else if (projY >= projX && projY >= projZ) {
size.setY(size.getY() + scale);
} else if (projZ >= projX && projZ >= projY) {
size.setZ(size.getZ() + scale);
} else {
size = size.add(scale, scale, scale);
}
result.size = size;
}
return result;
});
// <--[tag]
// @attribute <EllipsoidTag.with_location[<location>]>
// @returns EllipsoidTag
// @description
// Returns a copy of this ellipsoid, set to the specified location.
// -->
tagProcessor.registerTag(EllipsoidTag.class, "with_location", (attribute, object) -> {
if (!attribute.hasParam()) {
attribute.echoError("ellipsoid.with_location[...] tag must have an input.");
return null;
}
return new EllipsoidTag(attribute.paramAsType(LocationTag.class), object.size.clone());
});
// <--[tag]
// @attribute <EllipsoidTag.with_size[<location>]>
// @returns EllipsoidTag
// @description
// Returns a copy of this ellipsoid, set to the specified size.
// -->
tagProcessor.registerTag(EllipsoidTag.class, "with_size", (attribute, object) -> {
if (!attribute.hasParam()) {
attribute.echoError("ellipsoid.with_size[...] tag must have an input.");
return null;
}
return new EllipsoidTag(object.center.clone(), attribute.paramAsType(LocationTag.class));
});
// <--[tag]
// @attribute <EllipsoidTag.chunks>
// @returns ListTag(ChunkTag)
// @description
// Returns a list of all chunks that this ellipsoid touches at all (note that no valid ellipsoid tag can ever totally contain a chunk, due to vertical limits and roundness).
// -->
tagProcessor.registerTag(ListTag.class, "chunks", (attribute, object) -> {
ListTag chunks = new ListTag();
double minPossibleX = object.center.getX() - object.size.getX();
double minPossibleZ = object.center.getZ() - object.size.getZ();
double maxPossibleX = object.center.getX() + object.size.getX();
double maxPossibleZ = object.center.getZ() + object.size.getZ();
int minChunkX = (int) Math.floor(minPossibleX / 16);
int minChunkZ = (int) Math.floor(minPossibleZ / 16);
int maxChunkX = (int) Math.ceil(maxPossibleX / 16);
int maxChunkZ = (int) Math.ceil(maxPossibleZ / 16);
ChunkTag testChunk = new ChunkTag(object.center);
for (int x = minChunkX; x <= maxChunkX; x++) {
testChunk.chunkX = x;
for (int z = minChunkZ; z <= maxChunkZ; z++) {
testChunk.chunkZ = z;
if (object.intersects(testChunk)) {
chunks.addObject(new ChunkTag(testChunk.world, testChunk.chunkX, testChunk.chunkZ));
}
}
}
return chunks;
});
// <--[tag]
// @attribute <EllipsoidTag.note_name>
// @returns ElementTag
// @description
// Gets the name of a noted EllipsoidTag. If the ellipsoid isn't noted, this is null.
// -->
tagProcessor.registerTag(ElementTag.class, "note_name", (attribute, ellipsoid) -> {
String noteName = NoteManager.getSavedId(ellipsoid);
if (noteName == null) {
return null;
}
return new ElementTag(noteName);
});
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class DenizenNPCHelper method despawn.
// <--[action]
// @Actions
// despawn
// @Triggers when the NPC is despawned.
// This can be because a command was issued, or a chunk has been unloaded.
//
// @Context
// None
// -->
/**
* Fires a world script event and then NPC action when the NPC despawns.
*
* @param event NPCDespawnEvent
*/
@EventHandler
public void despawn(NPCDespawnEvent event) {
NPCTag npc = new NPCTag(event.getNPC());
if (npc.isValid()) {
EntityDespawnScriptEvent.instance.entity = new EntityTag(event.getNPC().getEntity());
EntityDespawnScriptEvent.instance.cause = new ElementTag("CITIZENS");
EntityDespawnScriptEvent.instance.fire(event);
npc.action("despawn", null);
}
}
Aggregations