use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class PluginTag method registerTags.
public static void registerTags() {
AbstractFlagTracker.registerFlagHandlers(tagProcessor);
// <--[tag]
// @attribute <PluginTag.name>
// @returns ElementTag
// @description
// Gets the name of this plugin.
// -->
tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
return new ElementTag(object.plugin.getName());
});
// <--[tag]
// @attribute <PluginTag.version>
// @returns ElementTag
// @description
// Gets the version for the plugin specified.
// -->
tagProcessor.registerTag(ElementTag.class, "version", (attribute, object) -> {
return new ElementTag(object.plugin.getDescription().getVersion());
});
// <--[tag]
// @attribute <PluginTag.description>
// @returns ElementTag
// @description
// Gets the description for the plugin specified.
// -->
tagProcessor.registerTag(ElementTag.class, "description", (attribute, object) -> {
return new ElementTag(object.plugin.getDescription().getDescription());
});
// <--[tag]
// @attribute <PluginTag.authors>
// @returns ListTag
// @description
// Gets the list of authors for the plugin specified.
// -->
tagProcessor.registerTag(ListTag.class, "authors", (attribute, object) -> {
return new ListTag(object.plugin.getDescription().getAuthors());
});
// <--[tag]
// @attribute <PluginTag.depends>
// @returns ListTag
// @description
// Gets the list of hard dependencies for the plugin specified.
// -->
tagProcessor.registerTag(ListTag.class, "depends", (attribute, object) -> {
return new ListTag(object.plugin.getDescription().getDepend());
});
// <--[tag]
// @attribute <PluginTag.soft_depends>
// @returns ListTag
// @description
// Gets the list of soft dependencies for the plugin specified.
// -->
tagProcessor.registerTag(ListTag.class, "soft_depends", (attribute, object) -> {
return new ListTag(object.plugin.getDescription().getSoftDepend());
});
// <--[tag]
// @attribute <PluginTag.commands>
// @returns MapTag(MapTag)
// @description
// Gets a map of commands registered this plugin registers by default.
// Note that dynamically registered commands won't show up (for example, command scripts won't be listed under Denizen).
// Map key is command name, map value is a sub-mapping with keys:
// description (ElementTag), usage (ElementTag), permission (ElementTag), aliases (ListTag)
// Not all keys will be present.
// For example, <plugin[denizen].commands.get[ex]> will return a MapTag with:
// [description=Executes a Denizen script command.;usage=/ex (-q) <Denizen script command> (arguments);permission=denizen.ex]
// -->
tagProcessor.registerTag(MapTag.class, "commands", (attribute, object) -> {
Map<String, Map<String, Object>> commands = object.plugin.getDescription().getCommands();
MapTag output = new MapTag();
if (commands == null || commands.isEmpty()) {
return output;
}
for (Map.Entry<String, Map<String, Object>> command : commands.entrySet()) {
MapTag dataMap = new MapTag();
if (command.getValue().containsKey("description")) {
dataMap.putObject("description", new ElementTag(command.getValue().get("description").toString(), true));
}
if (command.getValue().containsKey("usage")) {
dataMap.putObject("usage", new ElementTag(command.getValue().get("usage").toString(), true));
}
if (command.getValue().containsKey("permission")) {
dataMap.putObject("permission", new ElementTag(command.getValue().get("permission").toString(), true));
}
if (command.getValue().containsKey("aliases")) {
Object obj = command.getValue().get("aliases");
if (obj instanceof List) {
ListTag aliases = new ListTag();
for (Object entry : (List) obj) {
aliases.addObject(new ElementTag(String.valueOf(entry), true));
}
dataMap.putObject("aliases", aliases);
}
}
output.putObject(command.getKey(), dataMap);
}
return output;
});
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class BukkitListProperties method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <ListTag.formatted>
// @returns ElementTag
// @description
// Returns the list in a human-readable format.
// Note that this will parse the values within the list to be human-readable as well when possible.
// EG, a list of "<npc>|<player>|potato" will return "GuardNPC, bob, and potato".
// The exact formatting rules that will be followed are not guaranteed, other than that it will be a semi-clean human-readable format.
// -->
PropertyParser.<BukkitListProperties, ElementTag>registerTag(ElementTag.class, "formatted", (attribute, listObj) -> {
ListTag list = listObj.list;
if (list.isEmpty()) {
return new ElementTag("");
}
StringBuilder output = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
ObjectTag object = list.getObject(i);
String val = object.toString();
boolean handled = false;
if (val.startsWith("p@")) {
PlayerTag gotten = object.asType(PlayerTag.class, attribute.context);
if (gotten != null) {
output.append(gotten.getName());
handled = true;
}
}
if (val.startsWith("e@") || val.startsWith("n@")) {
EntityTag gotten = object.asType(EntityTag.class, attribute.context);
if (gotten != null) {
if (gotten.isValid()) {
output.append(gotten.getName());
} else {
output.append(gotten.getEntityType().getName());
}
handled = true;
}
}
if (val.startsWith("i@")) {
ItemTag item = object.asType(ItemTag.class, attribute.context);
if (item != null) {
output.append(item.formattedName());
handled = true;
}
}
if (val.startsWith("m@")) {
MaterialTag material = object.asType(MaterialTag.class, attribute.context);
if (material != null) {
output.append(material.name());
handled = true;
}
}
if (!handled) {
if (object instanceof ElementTag) {
output.append(val.replaceAll("\\w+@", ""));
} else {
output.append(ChatColor.stripColor(Debug.cleanTextForDebugOutput(object.debuggable())));
}
}
if (i == list.size() - 2) {
output.append(i == 0 ? " and " : ", and ");
} else {
output.append(", ");
}
}
return new ElementTag(output.toString().substring(0, output.length() - 2));
});
// <--[tag]
// @attribute <ListTag.to_polygon>
// @returns PolygonTag
// @description
// Converts a list of locations to a PolygonTag.
// The Y-Min and Y-Max values will be assigned based the range of Y values in the locations given.
// -->
PropertyParser.<BukkitListProperties, PolygonTag>registerTag(PolygonTag.class, "to_polygon", (attribute, listObj) -> {
List<LocationTag> locations = listObj.list.filter(LocationTag.class, attribute.context);
if (locations == null || locations.isEmpty()) {
return null;
}
if (locations.size() > Settings.blockTagsMaxBlocks()) {
return null;
}
PolygonTag polygon = new PolygonTag(new WorldTag(locations.get(0).getWorldName()));
polygon.yMin = locations.get(0).getY();
polygon.yMax = polygon.yMin;
for (LocationTag location : locations) {
polygon.yMin = Math.min(polygon.yMin, location.getY());
polygon.yMax = Math.max(polygon.yMax, location.getY());
polygon.corners.add(new PolygonTag.Corner(location.getX(), location.getZ()));
}
polygon.recalculateBox();
return polygon;
});
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class BukkitScriptProperties method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <ScriptTag.cooled_down[<player>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether the script is currently cooled down for the player. Any global
// cooldown present on the script will also be taken into account. Not specifying a player will result in
// using the attached player available in the script entry. Not having a valid player will result in 'null'.
// -->
PropertyParser.<BukkitScriptProperties, ElementTag>registerTag(ElementTag.class, "cooled_down", (attribute, script) -> {
PlayerTag player = (attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer());
if (player != null && player.isValid()) {
return new ElementTag(CooldownCommand.checkCooldown(player, script.script.getContainer().getName()));
} else {
return null;
}
});
// <--[tag]
// @attribute <ScriptTag.cooldown[<player>]>
// @returns DurationTag
// @description
// Returns the time left for the player to cooldown for the script.
// -->
PropertyParser.<BukkitScriptProperties, DurationTag>registerTag(DurationTag.class, "cooldown", (attribute, script) -> {
PlayerTag player = (attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer());
return CooldownCommand.getCooldownDuration(player, script.script.getName());
});
// <--[tag]
// @attribute <ScriptTag.step[(<player>)]>
// @returns ElementTag
// @description
// Returns the name of a script step that the player is currently on.
// Must be an INTERACT script.
// -->
PropertyParser.<BukkitScriptProperties, ElementTag>registerTag(ElementTag.class, "step", (attribute, script) -> {
PlayerTag player = attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer();
if (player != null && player.isValid()) {
return new ElementTag(InteractScriptHelper.getCurrentStep(player, script.script.getContainer().getName()));
} else {
return null;
}
});
// <--[tag]
// @attribute <ScriptTag.step_expiration[(<player>)]>
// @returns TimeTag
// @description
// Returns the time that an interact script step expires at, if applied by <@link command zap> with a duration limit.
// -->
PropertyParser.<BukkitScriptProperties, TimeTag>registerTag(TimeTag.class, "step_expiration", (attribute, script) -> {
PlayerTag player = attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer();
if (player != null && player.isValid()) {
return InteractScriptHelper.getStepExpiration(player, script.script.getContainer().getName());
} else {
return null;
}
});
// <--[tag]
// @attribute <ScriptTag.default_step>
// @returns ElementTag
// @description
// Returns the name of the default step of an interact script.
// -->
PropertyParser.<BukkitScriptProperties, ElementTag>registerStaticTag(ElementTag.class, "default_step", (attribute, script) -> {
String step = ((InteractScriptContainer) script.script.getContainer()).getDefaultStepName();
return new ElementTag(step);
});
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityAttributeBaseValues method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <EntityTag.has_attribute[<attribute>]>
// @returns ElementTag(Boolean)
// @group properties
// @description
// Returns whether the entity has the named attribute.
// Valid attribute names are listed at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/attribute/Attribute.html>
// See also <@link language attribute modifiers>.
// -->
PropertyParser.<EntityAttributeBaseValues, ElementTag>registerTag(ElementTag.class, "has_attribute", (attribute, object) -> {
if (!(attribute.hasParam() && attribute.getParamElement().matchesEnum(Attribute.class))) {
attribute.echoError("Invalid entity.has_attribute[...] input: must be a valid attribute name.");
return null;
}
Attribute attr = Attribute.valueOf(attribute.getParam().toUpperCase());
return new ElementTag(object.getAttributable().getAttribute(attr) != null);
});
// <--[tag]
// @attribute <EntityTag.attribute_value[<attribute>]>
// @returns ElementTag(Decimal)
// @mechanism EntityTag.attribute_base_values
// @group properties
// @description
// Returns the final calculated value of the named attribute for the entity.
// See also <@link tag EntityTag.has_attribute>.
// Valid attribute names are listed at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/attribute/Attribute.html>
// See also <@link language attribute modifiers>.
// -->
PropertyParser.<EntityAttributeBaseValues, ElementTag>registerTag(ElementTag.class, "attribute_value", (attribute, object) -> {
if (!(attribute.hasParam() && attribute.getParamElement().matchesEnum(Attribute.class))) {
attribute.echoError("Invalid entity.attribute_value[...] input: must be a valid attribute name.");
return null;
}
Attribute attr = Attribute.valueOf(attribute.getParam().toUpperCase());
AttributeInstance instance = object.getAttributable().getAttribute(attr);
if (instance == null) {
attribute.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + object.entity.getBukkitEntityType().name());
return null;
}
return new ElementTag(instance.getValue());
});
// <--[tag]
// @attribute <EntityTag.attribute_base_value[<attribute>]>
// @returns ElementTag(Decimal)
// @mechanism EntityTag.attribute_base_values
// @group properties
// @description
// Returns the base value of the named attribute for the entity.
// See also <@link tag EntityTag.has_attribute>.
// Valid attribute names are listed at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/attribute/Attribute.html>
// See also <@link language attribute modifiers>.
// -->
PropertyParser.<EntityAttributeBaseValues, ElementTag>registerTag(ElementTag.class, "attribute_base_value", (attribute, object) -> {
if (!(attribute.hasParam() && attribute.getParamElement().matchesEnum(Attribute.class))) {
attribute.echoError("Invalid entity.attribute_base_value[...] input: must be a valid attribute name.");
return null;
}
Attribute attr = Attribute.valueOf(attribute.getParam().toUpperCase());
AttributeInstance instance = object.getAttributable().getAttribute(attr);
if (instance == null) {
attribute.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + object.entity.getBukkitEntityType().name());
return null;
}
return new ElementTag(instance.getBaseValue());
});
// <--[tag]
// @attribute <EntityTag.attribute_default_value[<attribute>]>
// @returns ElementTag(Decimal)
// @mechanism EntityTag.attribute_base_values
// @group properties
// @description
// Returns the default value of the named attribute for the entity.
// See also <@link tag EntityTag.has_attribute>.
// Valid attribute names are listed at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/attribute/Attribute.html>
// See also <@link language attribute modifiers>.
// -->
PropertyParser.<EntityAttributeBaseValues, ElementTag>registerTag(ElementTag.class, "attribute_default_value", (attribute, object) -> {
if (!(attribute.hasParam() && attribute.getParamElement().matchesEnum(Attribute.class))) {
attribute.echoError("Invalid entity.attribute_default_value[...] input: must be a valid attribute name.");
return null;
}
Attribute attr = Attribute.valueOf(attribute.getParam().toUpperCase());
AttributeInstance instance = object.getAttributable().getAttribute(attr);
if (instance == null) {
attribute.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + object.entity.getBukkitEntityType().name());
return null;
}
return new ElementTag(instance.getDefaultValue());
});
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class PolygonTag method registerTags.
public static void registerTags() {
AbstractFlagTracker.registerFlagHandlers(tagProcessor);
AreaContainmentObject.registerTags(PolygonTag.class, tagProcessor);
// <--[tag]
// @attribute <PolygonTag.max_y>
// @returns ElementTag(Decimal)
// @description
// Returns the maximum Y level for this polygon.
// -->
tagProcessor.registerTag(ElementTag.class, "max_y", (attribute, polygon) -> {
return new ElementTag(polygon.yMax);
});
// <--[tag]
// @attribute <PolygonTag.min_y>
// @returns ElementTag(Decimal)
// @description
// Returns the minimum Y level for this polygon.
// -->
tagProcessor.registerTag(ElementTag.class, "min_y", (attribute, polygon) -> {
return new ElementTag(polygon.yMin);
});
// <--[tag]
// @attribute <PolygonTag.note_name>
// @returns ElementTag
// @description
// Gets the name of a noted PolygonTag. If the polygon isn't noted, this is null.
// -->
tagProcessor.registerTag(ElementTag.class, "note_name", (attribute, polygon) -> {
String noteName = NoteManager.getSavedId(polygon);
if (noteName == null) {
return null;
}
return new ElementTag(noteName);
});
// <--[tag]
// @attribute <PolygonTag.corners>
// @returns ListTag(LocationTag)
// @description
// Returns a list of the polygon's corners, as locations with Y coordinate set to the y-min value.
// -->
tagProcessor.registerTag(ListTag.class, "corners", (attribute, polygon) -> {
ListTag list = new ListTag();
for (Corner corner : polygon.corners) {
list.addObject(new LocationTag(corner.x, polygon.yMin, corner.z, polygon.world.getName()));
}
return list;
});
// <--[tag]
// @attribute <PolygonTag.shift[<vector>]>
// @returns PolygonTag
// @description
// Returns a copy of the polygon, with all coordinates shifted by the given location-vector.
// -->
tagProcessor.registerTag(PolygonTag.class, "shift", (attribute, polygon) -> {
if (!attribute.hasParam()) {
attribute.echoError("PolygonTag.shift[...] tag must have an input.");
return null;
}
LocationTag shift = attribute.paramAsType(LocationTag.class);
PolygonTag toReturn = polygon.clone();
toReturn.yMin += shift.getY();
toReturn.yMax += shift.getY();
for (Corner corner : toReturn.corners) {
corner.x += shift.getX();
corner.z += shift.getZ();
}
toReturn.boxMin.x += shift.getX();
toReturn.boxMin.z += shift.getZ();
toReturn.boxMax.x += shift.getX();
toReturn.boxMax.z += shift.getZ();
return toReturn;
});
// <--[tag]
// @attribute <PolygonTag.with_corner[<location>]>
// @returns PolygonTag
// @mechanism PolygonTag.add_corner
// @description
// Returns a copy of the polygon, with the specified corner added to the end of the corner list.
// -->
tagProcessor.registerTag(PolygonTag.class, "with_corner", (attribute, polygon) -> {
if (!attribute.hasParam()) {
attribute.echoError("PolygonTag.with_corner[...] tag must have an input.");
return null;
}
LocationTag corner = attribute.paramAsType(LocationTag.class);
PolygonTag toReturn = polygon.clone();
Corner added = new Corner(corner.getX(), corner.getZ());
toReturn.corners.add(added);
toReturn.recalculateToFit(added);
return toReturn;
});
// <--[tag]
// @attribute <PolygonTag.with_y_min[<#.#>]>
// @returns PolygonTag
// @description
// Returns a copy of the polygon, with the specified minimum-Y value.
// -->
tagProcessor.registerTag(PolygonTag.class, "with_y_min", (attribute, polygon) -> {
if (!attribute.hasParam()) {
attribute.echoError("PolygonTag.with_y_min[...] tag must have an input.");
return null;
}
PolygonTag toReturn = polygon.clone();
toReturn.yMin = attribute.getDoubleParam();
return toReturn;
});
// <--[tag]
// @attribute <PolygonTag.with_y_max[<#.#>]>
// @returns PolygonTag
// @description
// Returns a copy of the polygon, with the specified maximum-Y value.
// -->
tagProcessor.registerTag(PolygonTag.class, "with_y_max", (attribute, polygon) -> {
if (!attribute.hasParam()) {
attribute.echoError("PolygonTag.with_y_max[...] tag must have an input.");
return null;
}
PolygonTag toReturn = polygon.clone();
toReturn.yMax = attribute.getDoubleParam();
return toReturn;
});
// <--[tag]
// @attribute <PolygonTag.include_y[<#.#>]>
// @returns PolygonTag
// @description
// Returns a copy of the polygon, with the specified Y value included as part of the Y range (expanding the Y-min or Y-max as needed).
// -->
tagProcessor.registerTag(PolygonTag.class, "include_y", (attribute, polygon) -> {
if (!attribute.hasParam()) {
attribute.echoError("PolygonTag.include_y[...] tag must have an input.");
return null;
}
PolygonTag toReturn = polygon.clone();
double y = attribute.getDoubleParam();
toReturn.yMin = Math.min(y, toReturn.yMin);
toReturn.yMax = Math.max(y, toReturn.yMax);
return toReturn;
});
// <--[tag]
// @attribute <PolygonTag.outline_2d[<#.#>]>
// @returns ListTag(LocationTag)
// @description
// Returns a list of locations along the 2D outline of this polygon, at the specified Y level (roughly a block-width of separation between each).
// -->
tagProcessor.registerTag(ListTag.class, "outline_2d", (attribute, polygon) -> {
if (!attribute.hasParam()) {
attribute.echoError("PolygonTag.outline_2d[...] tag must have an input.");
return null;
}
double y = attribute.getDoubleParam();
ListTag output = new ListTag();
polygon.addOutline2D(y, output);
return output;
});
// <--[tag]
// @attribute <PolygonTag.outline>
// @returns ListTag(LocationTag)
// @description
// Returns a list of locations along the 3D outline of this polygon (roughly a block-width of separation between each).
// -->
tagProcessor.registerTag(ListTag.class, "outline", (attribute, polygon) -> {
return polygon.getOutline();
});
}
Aggregations