use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ActionHandler method doAction.
public ListTag doAction(String actionName, NPCTag npc, PlayerTag player, AssignmentScriptContainer assignment, Map<String, ObjectTag> context) {
if (context == null) {
context = new HashMap<>();
}
if (assignment == null) {
return null;
}
if (!assignment.containsScriptSection("actions.on " + actionName)) {
return null;
}
Debug.report(assignment, "Action", ArgumentHelper.debugObj("Type", "On " + actionName), npc, assignment.getAsScriptArg(), player);
// Fetch script from Actions
List<ScriptEntry> script = assignment.getEntries(new BukkitScriptEntryData(player, npc), "actions.on " + actionName);
if (script.isEmpty()) {
return null;
}
Debug.echoDebug(assignment, DebugElement.Header, "Building action 'On " + actionName.toUpperCase() + "' for " + npc.toString());
// Add entries and context to the queue
ScriptQueue queue = new InstantQueue(assignment.getName());
queue.addEntries(script);
ContextSource.SimpleMap src = new ContextSource.SimpleMap();
src.contexts = context;
src.contexts.put("event_header", new ElementTag(actionName));
queue.setContextSource(src);
// Start the queue!
queue.start();
return queue.determinations;
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class LocationTag method parsePointsAroundArgs.
public static double[] parsePointsAroundArgs(Attribute attribute) {
if (!attribute.hasParam()) {
return null;
}
MapTag inputMap = attribute.paramAsType(MapTag.class);
if (inputMap == null) {
return null;
}
ObjectTag radiusObj = inputMap.getObject("radius");
ObjectTag pointsObj = inputMap.getObject("points");
if (radiusObj == null || pointsObj == null) {
return null;
}
ElementTag radiusElement = radiusObj.asElement();
ElementTag amountElement = pointsObj.asElement();
if (radiusElement == null || amountElement == null) {
return null;
}
double radius = radiusElement.asDouble();
int amount = amountElement.asInt();
if (amount < 1) {
attribute.echoError("Invalid amount of points! There must be at least 1 point.");
return null;
}
return new double[] { radius, amount };
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class NPCTag method registerTags.
public static void registerTags() {
AbstractFlagTracker.registerFlagHandlers(tagProcessor);
// Defined in EntityTag
tagProcessor.registerTag(ElementTag.class, "is_npc", (attribute, object) -> {
return new ElementTag(true);
});
// Defined in EntityTag
tagProcessor.registerTag(ObjectTag.class, "location", (attribute, object) -> {
if (attribute.startsWith("previous_location", 2)) {
attribute.fulfill(1);
Deprecations.npcPreviousLocationTag.warn(attribute.context);
return NPCTagBase.previousLocations.get(object.getId());
}
if (object.isSpawned()) {
return new EntityTag(object).doLocationTag(attribute);
}
return object.getLocation();
});
// <--[tag]
// @attribute <NPCTag.previous_location>
// @returns LocationTag
// @description
// Returns the NPC's previous navigated location.
// -->
tagProcessor.registerTag(LocationTag.class, "previous_location", (attribute, object) -> {
return NPCTagBase.previousLocations.get(object.getId());
});
// Defined in EntityTag
tagProcessor.registerTag(LocationTag.class, "eye_location", (attribute, object) -> {
return object.getEyeLocation();
});
// <--[tag]
// @attribute <NPCTag.has_nickname>
// @returns ElementTag(Boolean)
// @description
// Returns true if the NPC has a nickname.
// -->
tagProcessor.registerTag(ElementTag.class, "has_nickname", (attribute, object) -> {
NPC citizen = object.getCitizen();
return new ElementTag(citizen.hasTrait(NicknameTrait.class) && citizen.getOrAddTrait(NicknameTrait.class).hasNickname());
});
// <--[tag]
// @attribute <NPCTag.is_sitting>
// @returns ElementTag(Boolean)
// @description
// Returns true if the NPC is sitting. Relates to <@link command sit>.
// -->
tagProcessor.registerTag(ElementTag.class, "is_sitting", (attribute, object) -> {
NPC citizen = object.getCitizen();
return new ElementTag(citizen.hasTrait(SittingTrait.class) && citizen.getOrAddTrait(SittingTrait.class).isSitting());
});
// <--[tag]
// @attribute <NPCTag.is_sleeping>
// @returns ElementTag(Boolean)
// @description
// Returns true if the NPC is sleeping. Relates to <@link command sleep>.
// -->
tagProcessor.registerTag(ElementTag.class, "is_sleeping", (attribute, object) -> {
NPC citizen = object.getCitizen();
return new ElementTag(citizen.hasTrait(SleepingTrait.class) && citizen.getOrAddTrait(SleepingTrait.class).isSleeping());
});
// <--[tag]
// @attribute <NPCTag.nickname>
// @returns ElementTag
// @description
// Returns the NPC's display name, as set by the Nickname trait (or the default NPC name).
// -->
tagProcessor.registerTag(ElementTag.class, "nickname", (attribute, object) -> {
return new ElementTag(object.getCitizen().hasTrait(NicknameTrait.class) ? object.getCitizen().getOrAddTrait(NicknameTrait.class).getNickname() : object.getName());
});
// Documented in EntityTag
tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
if (attribute.startsWith("nickname", 2)) {
Deprecations.npcNicknameTag.warn(attribute.context);
attribute.fulfill(1);
return new ElementTag(object.getCitizen().hasTrait(NicknameTrait.class) ? object.getCitizen().getOrAddTrait(NicknameTrait.class).getNickname() : object.getName());
}
return new ElementTag(object.getName());
});
// <--[tag]
// @attribute <NPCTag.traits>
// @returns ListTag
// @description
// Returns a list of all of the NPC's traits.
// -->
tagProcessor.registerTag(ListTag.class, "traits", (attribute, object) -> {
List<String> list = new ArrayList<>();
for (Trait trait : object.getCitizen().getTraits()) {
list.add(trait.getName());
}
return new ListTag(list);
}, "list_traits");
// <--[tag]
// @attribute <NPCTag.has_trait[<trait>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC has a specified trait.
// -->
tagProcessor.registerTag(ElementTag.class, "has_trait", (attribute, object) -> {
if (attribute.hasParam()) {
Class<? extends Trait> trait = CitizensAPI.getTraitFactory().getTraitClass(attribute.getParam());
if (trait != null) {
return new ElementTag(object.getCitizen().hasTrait(trait));
}
}
return null;
});
// <--[tag]
// @attribute <NPCTag.pushable>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is pushable.
// -->
tagProcessor.registerTag(ElementTag.class, "pushable", (attribute, object) -> {
return new ElementTag(object.getPushableTrait().isPushable());
}, "is_pushable");
// <--[tag]
// @attribute <NPCTag.has_trigger[<trigger>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC has a specified trigger.
// -->
tagProcessor.registerTag(ElementTag.class, "has_trigger", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
if (!object.getCitizen().hasTrait(TriggerTrait.class)) {
return new ElementTag(false);
}
TriggerTrait trait = object.getCitizen().getOrAddTrait(TriggerTrait.class);
return new ElementTag(trait.hasTrigger(attribute.getParam()));
});
// <--[tag]
// @attribute <NPCTag.has_anchors>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC has anchors assigned.
// -->
tagProcessor.registerTag(ElementTag.class, "has_anchors", (attribute, object) -> {
return (new ElementTag(object.getCitizen().getOrAddTrait(Anchors.class).getAnchors().size() > 0));
});
// <--[tag]
// @attribute <NPCTag.list_anchors>
// @returns ListTag
// @description
// Returns a list of anchor names currently assigned to the NPC.
// -->
tagProcessor.registerTag(ListTag.class, "list_anchors", (attribute, object) -> {
ListTag list = new ListTag();
for (Anchor anchor : object.getCitizen().getOrAddTrait(Anchors.class).getAnchors()) {
list.add(anchor.getName());
}
return list;
});
// <--[tag]
// @attribute <NPCTag.anchor[<name>]>
// @returns LocationTag
// @description
// Returns the location associated with the specified anchor, or null if it doesn't exist.
// -->
tagProcessor.registerTag(ObjectTag.class, "anchor", (attribute, object) -> {
Anchors trait = object.getCitizen().getOrAddTrait(Anchors.class);
if (attribute.hasParam()) {
Anchor anchor = trait.getAnchor(attribute.getParam());
if (anchor != null) {
return new LocationTag(anchor.getLocation());
} else {
attribute.echoError("NPC Anchor '" + attribute.getParam() + "' is not defined.");
return null;
}
} else if (attribute.startsWith("list", 2)) {
attribute.fulfill(1);
Deprecations.npcAnchorListTag.warn(attribute.context);
ListTag list = new ListTag();
for (Anchor anchor : trait.getAnchors()) {
list.add(anchor.getName());
}
return list;
} else {
attribute.echoError("npc.anchor[...] tag must have an input.");
}
return null;
}, "anchors");
// <--[tag]
// @attribute <NPCTag.constant[<constant_name>]>
// @returns ElementTag
// @description
// Returns the specified constant from the NPC.
// -->
tagProcessor.registerTag(ElementTag.class, "constant", (attribute, object) -> {
if (attribute.hasParam()) {
if (object.getCitizen().hasTrait(ConstantsTrait.class) && object.getCitizen().getOrAddTrait(ConstantsTrait.class).getConstant(attribute.getParam()) != null) {
return new ElementTag(object.getCitizen().getOrAddTrait(ConstantsTrait.class).getConstant(attribute.getParam()));
} else {
return null;
}
}
return null;
});
// <--[tag]
// @attribute <NPCTag.has_pose[<name>]>
// @returns ElementTag(Boolean)
// @description
// Returns true if the NPC has the specified pose, otherwise returns false.
// -->
tagProcessor.registerTag(ElementTag.class, "has_pose", (attribute, object) -> {
if (attribute.hasParam()) {
return new ElementTag(object.getCitizen().getOrAddTrait(Poses.class).hasPose(attribute.getParam()));
} else {
return null;
}
});
// <--[tag]
// @attribute <NPCTag.pose[<name>]>
// @returns LocationTag
// @description
// Returns the pose as a LocationTag with x, y, and z set to 0, and the world set to the first
// possible available world Bukkit knows about.
// -->
tagProcessor.registerTag(LocationTag.class, "pose", (attribute, object) -> {
if (attribute.hasParam()) {
Pose pose = object.getCitizen().getOrAddTrait(Poses.class).getPose(attribute.getParam());
return new LocationTag(org.bukkit.Bukkit.getWorlds().get(0), 0, 0, 0, pose.getYaw(), pose.getPitch());
} else {
return null;
}
}, "get_pose");
// <--[tag]
// @attribute <NPCTag.name_hologram_npc>
// @returns NPCTag
// @description
// Returns the NPCTag of a hologram attached to this NPC as its nameplate (if any).
// Note that this can regenerate at any time.
// -->
tagProcessor.registerTag(ObjectTag.class, "name_hologram_npc", (attribute, object) -> {
if (!object.getCitizen().hasTrait(HologramTrait.class)) {
return null;
}
HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
Entity entity = hologram.getNameEntity();
if (entity == null) {
return null;
}
return new EntityTag(entity).getDenizenObject();
});
// <--[tag]
// @attribute <NPCTag.hologram_npcs>
// @returns ListTag(NPCTag)
// @description
// Returns the list of hologram NPCs attached to an NPC (if any).
// Note that these can regenerate at any time.
// -->
tagProcessor.registerTag(ListTag.class, "hologram_npcs", (attribute, object) -> {
if (!object.getCitizen().hasTrait(HologramTrait.class)) {
return null;
}
HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
Collection<ArmorStand> stands = hologram.getHologramEntities();
if (stands == null || stands.isEmpty()) {
return null;
}
ListTag output = new ListTag();
for (ArmorStand stand : stands) {
output.addObject(new EntityTag(stand).getDenizenObject());
}
return output;
});
// <--[tag]
// @attribute <NPCTag.hologram_lines>
// @returns ListTag
// @mechanism NPCTag.hologram_lines
// @description
// Returns the list of hologram lines attached to an NPC.
// -->
tagProcessor.registerTag(ListTag.class, "hologram_lines", (attribute, object) -> {
if (!object.getCitizen().hasTrait(HologramTrait.class)) {
return null;
}
HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
return new ListTag(hologram.getLines());
});
// <--[tag]
// @attribute <NPCTag.hologram_direction>
// @returns ElementTag
// @mechanism NPCTag.hologram_direction
// @description
// Returns the direction of an NPC's hologram as "BOTTOM_UP" or "TOP_DOWN".
// -->
tagProcessor.registerTag(ElementTag.class, "hologram_direction", (attribute, object) -> {
if (!object.getCitizen().hasTrait(HologramTrait.class)) {
return null;
}
HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
return new ElementTag(hologram.getDirection().name());
});
// <--[tag]
// @attribute <NPCTag.hologram_line_height>
// @returns ElementTag(Decimal)
// @mechanism NPCTag.hologram_line_height
// @description
// Returns the line height for an NPC's hologram. Can be -1, indicating a default value should be used.
// -->
tagProcessor.registerTag(ElementTag.class, "hologram_line_height", (attribute, object) -> {
if (!object.getCitizen().hasTrait(HologramTrait.class)) {
return null;
}
HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
return new ElementTag(hologram.getLineHeight());
});
// <--[tag]
// @attribute <NPCTag.is_sneaking>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is currently sneaking. Only works for player-type NPCs.
// -->
tagProcessor.registerTag(ElementTag.class, "is_sneaking", (attribute, object) -> {
if (!object.isSpawned() && object.getEntity() instanceof Player) {
return null;
}
return new ElementTag(((Player) object.getEntity()).isSneaking());
});
// <--[tag]
// @attribute <NPCTag.engaged[(<player>)]>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is currently engaged.
// See <@link command engage>
// -->
tagProcessor.registerTag(ElementTag.class, "engaged", (attribute, object) -> {
return new ElementTag(EngageCommand.getEngaged(object.getCitizen(), attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : null));
}, "is_engaged");
// <--[tag]
// @attribute <NPCTag.invulnerable>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is currently invulnerable.
// See <@link command vulnerable>
// -->
tagProcessor.registerTag(ElementTag.class, "invulnerable", (attribute, object) -> {
return new ElementTag(object.getCitizen().data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
}, "vulnerable");
// <--[tag]
// @attribute <NPCTag.id>
// @returns ElementTag(Number)
// @description
// Returns the NPC's ID number.
// -->
tagProcessor.registerTag(ElementTag.class, "id", (attribute, object) -> {
return new ElementTag(object.getId());
});
// <--[tag]
// @attribute <NPCTag.owner>
// @returns PlayerTag
// @mechanism NPCTag.owner
// @description
// Returns the owner of the NPC as a PlayerTag, if any.
// -->
tagProcessor.registerTag(ObjectTag.class, "owner", (attribute, object) -> {
UUID owner = object.getOwner();
if (owner == null) {
return null;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(owner);
if (player.isOnline() || player.hasPlayedBefore()) {
return new PlayerTag(player);
}
return null;
});
// <--[tag]
// @attribute <NPCTag.has_skin>
// @returns ElementTag(Boolean)
// @mechanism NPCTag.skin
// @description
// Returns whether the NPC has a custom skin.
// -->
tagProcessor.registerTag(ElementTag.class, "has_skin", (attribute, object) -> {
return new ElementTag(object.getCitizen().hasTrait(SkinTrait.class) && object.getCitizen().getOrAddTrait(SkinTrait.class).getSkinName() != null);
});
// <--[tag]
// @attribute <NPCTag.skin_blob>
// @returns ElementTag
// @mechanism NPCTag.skin_blob
// @description
// Returns the NPC's custom skin blob, if any.
// In the format: "texture;signature" (two values separated by a semicolon).
// See also <@link language Player Entity Skins (Skin Blobs)>.
// -->
tagProcessor.registerTag(ElementTag.class, "skin_blob", (attribute, object) -> {
if (object.getCitizen().hasTrait(SkinTrait.class)) {
SkinTrait skin = object.getCitizen().getOrAddTrait(SkinTrait.class);
String tex = skin.getTexture();
String sign = "";
if (skin.getSignature() != null) {
sign = ";" + skin.getSignature();
}
return new ElementTag(tex + sign);
}
return null;
});
// <--[tag]
// @attribute <NPCTag.skull_skin>
// @returns ElementTag
// @description
// Returns the NPC's current skin blob, formatted for input to a Player Skull item.
// In the format: "UUID|Texture" (two values separated by pipes).
// See also <@link language Player Entity Skins (Skin Blobs)>.
// -->
tagProcessor.registerTag(ElementTag.class, "skull_skin", (attribute, object) -> {
if (!object.getCitizen().hasTrait(SkinTrait.class)) {
return null;
}
SkinTrait skin = object.getCitizen().getOrAddTrait(SkinTrait.class);
return new ElementTag(skin.getSkinName() + "|" + skin.getTexture());
});
// <--[tag]
// @attribute <NPCTag.skin>
// @returns ElementTag
// @mechanism NPCTag.skin
// @description
// Returns the NPC's custom skin, if any.
// -->
tagProcessor.registerTag(ElementTag.class, "skin", (attribute, object) -> {
if (object.getCitizen().hasTrait(SkinTrait.class)) {
return new ElementTag(object.getCitizen().getOrAddTrait(SkinTrait.class).getSkinName());
}
return null;
});
// <--[tag]
// @attribute <NPCTag.auto_update_skin>
// @returns ElementTag(Boolean)
// @mechanism NPCTag.auto_update_skin
// @description
// Returns whether the NPC is set to automatically update skins from name.
// -->
tagProcessor.registerTag(ElementTag.class, "auto_update_skin", (attribute, object) -> {
if (object.getCitizen().hasTrait(SkinTrait.class)) {
return new ElementTag(object.getCitizen().getOrAddTrait(SkinTrait.class).shouldUpdateSkins());
}
return null;
});
// <--[tag]
// @attribute <NPCTag.inventory>
// @returns InventoryTag
// @description
// Returns the InventoryTag of the NPC.
// -->
tagProcessor.registerTag(InventoryTag.class, "inventory", (attribute, object) -> {
return object.getDenizenInventory();
});
// <--[tag]
// @attribute <NPCTag.is_spawned>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is spawned.
// -->
tagProcessor.registerTag(ElementTag.class, "is_spawned", (attribute, object) -> {
return new ElementTag(object.isSpawned());
});
// <--[tag]
// @attribute <NPCTag.is_protected>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is protected.
// -->
tagProcessor.registerTag(ElementTag.class, "is_protected", (attribute, object) -> {
return new ElementTag(object.getCitizen().isProtected());
});
// <--[tag]
// @attribute <NPCTag.lookclose>
// @returns ElementTag(Boolean)
// @mechanism NPCTag.lookclose
// @description
// Returns whether the NPC has lookclose enabled.
// -->
tagProcessor.registerTag(ElementTag.class, "lookclose", (attribute, object) -> {
NPC citizen = object.getCitizen();
if (citizen.hasTrait(LookClose.class)) {
// There is no method to check if the NPC has LookClose enabled...
// LookClose.toString() returns "LookClose{" + enabled + "}"
String lookclose = citizen.getOrAddTrait(LookClose.class).toString();
lookclose = lookclose.substring(10, lookclose.length() - 1);
return new ElementTag(Boolean.valueOf(lookclose));
}
return new ElementTag(false);
});
// <--[tag]
// @attribute <NPCTag.controllable>
// @returns ElementTag(Boolean)
// @mechanism NPCTag.controllable
// @description
// Returns whether the NPC has controllable enabled.
// -->
tagProcessor.registerTag(ElementTag.class, "controllable", (attribute, object) -> {
if (object.getCitizen().hasTrait(Controllable.class)) {
return new ElementTag(object.getCitizen().getOrAddTrait(Controllable.class).isEnabled());
}
return new ElementTag(false);
});
// <--[tag]
// @attribute <NPCTag.targetable>
// @returns ElementTag(Boolean)
// @mechanism NPCTag.targetable
// @description
// Returns whether the NPC is targetable.
// -->
tagProcessor.registerTag(ElementTag.class, "targetable", (attribute, object) -> {
boolean targetable = object.getCitizen().data().get(NPC.TARGETABLE_METADATA, object.getCitizen().data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
return new ElementTag(targetable);
});
// <--[tag]
// @attribute <NPCTag.teleport_on_stuck>
// @returns ElementTag(Boolean)
// @mechanism NPCTag.teleport_on_stuck
// @description
// Returns whether the NPC teleports when it is stuck.
// -->
tagProcessor.registerTag(ElementTag.class, "teleport_on_stuck", (attribute, object) -> {
return new ElementTag(object.getNavigator().getDefaultParameters().stuckAction() == TeleportStuckAction.INSTANCE);
});
tagProcessor.registerTag(ElementTag.class, "has_script", (attribute, object) -> {
Deprecations.hasScriptTags.warn(attribute.context);
NPC citizen = object.getCitizen();
return new ElementTag(citizen.hasTrait(AssignmentTrait.class));
});
// <--[tag]
// @attribute <NPCTag.script>
// @returns ScriptTag
// @deprecated Use 'NPCTag.scripts' (plural) instead.
// @description
// Deprecated variant of <@link tag NPCTag.scripts>.
// -->
tagProcessor.registerTag(ScriptTag.class, "script", (attribute, object) -> {
Deprecations.npcScriptSingle.warn(attribute.context);
NPC citizen = object.getCitizen();
if (!citizen.hasTrait(AssignmentTrait.class)) {
return null;
} else {
for (AssignmentScriptContainer container : citizen.getOrAddTrait(AssignmentTrait.class).containerCache) {
if (container != null) {
return new ScriptTag(container);
}
}
return null;
}
});
// <--[tag]
// @attribute <NPCTag.scripts>
// @returns ListTag(ScriptTag)
// @description
// Returns a list of all assignment scripts on the NPC. Returns null if none.
// -->
tagProcessor.registerTag(ListTag.class, "scripts", (attribute, object) -> {
NPC citizen = object.getCitizen();
if (!citizen.hasTrait(AssignmentTrait.class)) {
return null;
} else {
ListTag result = new ListTag();
for (AssignmentScriptContainer container : citizen.getOrAddTrait(AssignmentTrait.class).containerCache) {
if (container != null) {
result.addObject(new ScriptTag(container));
}
}
return result;
}
});
// <--[tag]
// @attribute <NPCTag.distance_margin>
// @returns ElementTag(Decimal)
// @mechanism NPCTag.distance_margin
// @description
// Returns the NPC's current pathfinding distance margin. That is, how close it needs to get to its destination (in block-lengths).
// -->
tagProcessor.registerTag(ElementTag.class, "distance_margin", (attribute, object) -> {
return new ElementTag(object.getNavigator().getDefaultParameters().distanceMargin());
});
// <--[tag]
// @attribute <NPCTag.path_distance_margin>
// @returns ElementTag(Decimal)
// @mechanism NPCTag.path_distance_margin
// @description
// Returns the NPC's current pathfinding distance margin. That is, how close it needs to get to individual points along its path.
// -->
tagProcessor.registerTag(ElementTag.class, "path_distance_margin", (attribute, object) -> {
return new ElementTag(object.getNavigator().getDefaultParameters().pathDistanceMargin());
});
// <--[tag]
// @attribute <NPCTag.is_navigating>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is currently navigating.
// -->
tagProcessor.registerTag(ElementTag.class, "is_navigating", (attribute, object) -> {
return new ElementTag(object.getNavigator().isNavigating());
});
// <--[tag]
// @attribute <NPCTag.speed>
// @returns ElementTag(Decimal)
// @mechanism NPCTag.speed
// @description
// Returns the current speed of the NPC.
// -->
tagProcessor.registerTag(ElementTag.class, "speed", (attribute, object) -> {
return new ElementTag(object.getNavigator().getLocalParameters().speed());
});
// <--[tag]
// @attribute <NPCTag.range>
// @returns ElementTag(Decimal)
// @mechanism NPCTag.range
// @description
// Returns the NPC's current maximum pathfinding range.
// -->
tagProcessor.registerTag(ElementTag.class, "range", (attribute, object) -> {
return new ElementTag(object.getNavigator().getLocalParameters().range());
});
// <--[tag]
// @attribute <NPCTag.attack_range>
// @returns ElementTag(Decimal)
// @mechanism NPCTag.attack_range
// @description
// Returns the NPC's current navigator attack range limit.
// -->
tagProcessor.registerTag(ElementTag.class, "attack_range", (attribute, object) -> {
return new ElementTag(object.getNavigator().getLocalParameters().attackRange());
});
// <--[tag]
// @attribute <NPCTag.attack_strategy>
// @returns ElementTag
// @description
// Returns the NPC's current navigator attack strategy.
// Not related to Sentinel combat.
// -->
tagProcessor.registerTag(ElementTag.class, "attack_strategy", (attribute, object) -> {
return new ElementTag(object.getNavigator().getLocalParameters().attackStrategy().toString());
});
// <--[tag]
// @attribute <NPCTag.speed_modifier>
// @returns ElementTag(Decimal)
// @description
// Returns the NPC's current movement speed modifier (a multiplier applied over their base speed).
// -->
tagProcessor.registerTag(ElementTag.class, "speed_modifier", (attribute, object) -> {
return new ElementTag(object.getNavigator().getLocalParameters().speedModifier());
});
// <--[tag]
// @attribute <NPCTag.base_speed>
// @returns ElementTag(Decimal)
// @description
// Returns the NPC's base navigation speed.
// -->
tagProcessor.registerTag(ElementTag.class, "base_speed", (attribute, object) -> {
return new ElementTag(object.getNavigator().getLocalParameters().baseSpeed());
});
// <--[tag]
// @attribute <NPCTag.avoid_water>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC will avoid water.
// -->
tagProcessor.registerTag(ElementTag.class, "avoid_water", (attribute, object) -> {
return new ElementTag(object.getNavigator().getLocalParameters().avoidWater());
});
// <--[tag]
// @attribute <NPCTag.target_location>
// @returns LocationTag
// @description
// Returns the location the NPC is currently navigating towards (if any).
// -->
tagProcessor.registerTag(LocationTag.class, "target_location", (attribute, object) -> {
if (object.getNavigator().getTargetAsLocation() == null) {
return null;
}
return new LocationTag(object.getNavigator().getTargetAsLocation());
});
// <--[tag]
// @attribute <NPCTag.navigator_look_at>
// @returns LocationTag
// @mechanism NPCTag.navigator_look_at
// @description
// Returns the location the NPC will currently look at while moving, if any.
// -->
tagProcessor.registerTag(LocationTag.class, "navigator_look_at", (attribute, object) -> {
if (object.getNavigator().getLocalParameters().lookAtFunction() == null) {
return null;
}
Location res = object.getNavigator().getLocalParameters().lookAtFunction().apply(object.getNavigator());
if (res == null) {
return null;
}
return new LocationTag(res);
});
// <--[tag]
// @attribute <NPCTag.is_fighting>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is currently targeting an entity for the Citizens internal punching pathfinder.
// Not compatible with Sentinel.
// -->
tagProcessor.registerTag(ElementTag.class, "is_fighting", (attribute, object) -> {
return new ElementTag(object.getNavigator().getEntityTarget() != null && object.getNavigator().getEntityTarget().isAggressive());
});
// <--[tag]
// @attribute <NPCTag.target_type>
// @returns ElementTag
// @description
// Returns the entity type of the NPC's current navigation target (if any).
// -->
tagProcessor.registerTag(ElementTag.class, "target_type", (attribute, object) -> {
if (object.getNavigator().getTargetType() == null) {
return null;
}
return new ElementTag(object.getNavigator().getTargetType().toString());
});
// <--[tag]
// @attribute <NPCTag.target_entity>
// @returns EntityTag
// @description
// Returns the entity being targeted by the NPC's current navigation (if any).
// -->
tagProcessor.registerTag(EntityTag.class, "target_entity", (attribute, object) -> {
if (object.getNavigator().getEntityTarget() == null || object.getNavigator().getEntityTarget().getTarget() == null) {
return null;
}
return new EntityTag(object.getNavigator().getEntityTarget().getTarget());
});
// <--[tag]
// @attribute <NPCTag.registry_name>
// @returns ElementTag
// @description
// Returns the name of the registry this NPC came from.
// -->
tagProcessor.registerTag(ElementTag.class, "registry_name", (attribute, object) -> {
return new ElementTag(object.getCitizen().getOwningRegistry().getName());
});
// <--[tag]
// @attribute <NPCTag.citizens_data[<key>]>
// @returns ElementTag
// @description
// Returns the value of a Citizens NPC metadata key.
// -->
tagProcessor.registerTag(ElementTag.class, "citizens_data", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
Object val = object.getCitizen().data().get(attribute.getParam());
if (val == null) {
return null;
}
return new ElementTag(val.toString());
});
// <--[tag]
// @attribute <NPCTag.citizens_data_keys>
// @returns ListTag
// @description
// Returns a list of Citizens NPC metadata keys.
// -->
tagProcessor.registerTag(ListTag.class, "citizens_data_keys", (attribute, object) -> {
DataKey holder = new MemoryDataKey();
object.getCitizen().data().saveTo(holder);
ListTag result = new ListTag();
for (DataKey key : holder.getSubKeys()) {
result.addObject(new ElementTag(key.name(), true));
}
return result;
});
tagProcessor.registerTag(NPCTag.class, "navigator", (attribute, object) -> {
Deprecations.oldNPCNavigator.warn(attribute.context);
return object;
});
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityAttributeModifiers method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("attribute_modifiers") && mechanism.requireObject(MapTag.class)) {
try {
MapTag input = mechanism.valueAsType(MapTag.class);
Attributable ent = getAttributable();
for (Map.Entry<StringHolder, ObjectTag> subValue : input.map.entrySet()) {
Attribute attr = Attribute.valueOf(subValue.getKey().str.toUpperCase());
AttributeInstance instance = ent.getAttribute(attr);
if (instance == null) {
mechanism.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + entity.getBukkitEntityType().name());
continue;
}
for (AttributeModifier modifier : instance.getModifiers()) {
instance.removeModifier(modifier);
}
for (ObjectTag listValue : CoreUtilities.objectToList(subValue.getValue(), mechanism.context)) {
instance.addModifier(modiferForMap(attr, listValue.asType(MapTag.class, mechanism.context)));
}
}
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
// -->
if (mechanism.matches("add_attribute_modifiers") && mechanism.requireObject(MapTag.class)) {
try {
MapTag input = mechanism.valueAsType(MapTag.class);
Attributable ent = getAttributable();
for (Map.Entry<StringHolder, ObjectTag> subValue : input.map.entrySet()) {
Attribute attr = Attribute.valueOf(subValue.getKey().str.toUpperCase());
AttributeInstance instance = ent.getAttribute(attr);
if (instance == null) {
mechanism.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + entity.getBukkitEntityType().name());
continue;
}
for (ObjectTag listValue : CoreUtilities.objectToList(subValue.getValue(), mechanism.context)) {
instance.addModifier(modiferForMap(attr, listValue.asType(MapTag.class, mechanism.context)));
}
}
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
// -->
if (mechanism.matches("remove_attribute_modifiers") && mechanism.requireObject(ListTag.class)) {
ArrayList<String> inputList = new ArrayList<>(mechanism.valueAsType(ListTag.class));
Attributable ent = getAttributable();
for (String toRemove : new ArrayList<>(inputList)) {
if (new ElementTag(toRemove).matchesEnum(Attribute.class)) {
inputList.remove(toRemove);
Attribute attr = Attribute.valueOf(toRemove.toUpperCase());
AttributeInstance instance = ent.getAttribute(attr);
if (instance == null) {
mechanism.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + entity.getBukkitEntityType().name());
continue;
}
for (AttributeModifier modifier : instance.getModifiers()) {
instance.removeModifier(modifier);
}
}
}
for (String toRemove : inputList) {
UUID id = UUID.fromString(toRemove);
for (Attribute attr : Attribute.values()) {
AttributeInstance instance = ent.getAttribute(attr);
if (instance == null) {
continue;
}
for (AttributeModifier modifer : instance.getModifiers()) {
if (modifer.getUniqueId().equals(id)) {
instance.removeModifier(modifer);
break;
}
}
}
}
}
if (mechanism.matches("attributes") && mechanism.hasValue()) {
Deprecations.legacyAttributeProperties.warn(mechanism.context);
Attributable ent = getAttributable();
ListTag list = mechanism.valueAsType(ListTag.class);
for (String str : list) {
List<String> subList = CoreUtilities.split(str, '/');
Attribute attr = Attribute.valueOf(EscapeTagBase.unEscape(subList.get(0)).toUpperCase());
AttributeInstance instance = ent.getAttribute(attr);
if (instance == null) {
mechanism.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + entity.getBukkitEntityType().name());
continue;
}
instance.setBaseValue(Double.parseDouble(subList.get(1)));
for (AttributeModifier modifier : instance.getModifiers()) {
instance.removeModifier(modifier);
}
for (int x = 2; x < subList.size(); x += 4) {
String slot = subList.get(x + 3).toUpperCase();
AttributeModifier modifier = new AttributeModifier(UUID.randomUUID(), EscapeTagBase.unEscape(subList.get(x)), Double.parseDouble(subList.get(x + 1)), AttributeModifier.Operation.valueOf(subList.get(x + 2).toUpperCase()), slot.equals("ANY") ? null : EquipmentSlot.valueOf(slot));
instance.addModifier(modifier);
}
}
}
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityAttributeModifiers method mapify.
public static MapTag mapify(AttributeModifier modifier) {
MapTag result = new MapTag();
result.putObject("name", new ElementTag(modifier.getName()));
result.putObject("amount", new ElementTag(modifier.getAmount()));
result.putObject("operation", new ElementTag(modifier.getOperation().name()));
result.putObject("slot", new ElementTag(modifier.getSlot() == null ? "any" : modifier.getSlot().name()));
result.putObject("id", new ElementTag(modifier.getUniqueId().toString()));
return result;
}
Aggregations