// @returns Element(Boolean)
// @description
// Returns true if the NPC has a nickname.
// -->
if (attribute.startsWith("has_nickname")) {
NPC citizen = getCitizen();
return new Element(citizen.hasTrait(NicknameTrait.class) && citizen.getTrait(NicknameTrait.class).hasNickname())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <n@npc.name.nickname>
// @returns Element
// @description
// returns the NPC's display name.
// -->
if (attribute.startsWith("name.nickname"))
return new Element(getCitizen().hasTrait(NicknameTrait.class) ? getCitizen().getTrait(NicknameTrait.class)
.getNickname() : getName()).getAttribute(attribute.fulfill(2));
// <--[tag]
// @attribute <n@npc.name>
// @returns Element
// @description
// returns the name of the NPC.
// -->
if (attribute.startsWith("name"))
return new Element(getName())
.getAttribute(attribute.fulfill(1));
// <--[tag]
// @attribute <n@npc.list_traits>
// @returns dList
// @description
// Returns a list of all of the NPC's traits.
// -->
if (attribute.startsWith("list_traits")) {
List<String> list = new ArrayList<String>();
for (Trait trait : getCitizen().getTraits())
list.add(trait.getName());
return new dList(list).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <n@npc.has_trait[<trait>]>
// @returns Element(Boolean)
// @description
// Returns whether the NPC has a specified trait.
// -->
if (attribute.startsWith("has_trait")) {
if (attribute.hasContext(1)) {
Class<? extends Trait> trait = CitizensAPI.getTraitFactory().getTraitClass(attribute.getContext(1));
if (trait != null)
return new Element(getCitizen().hasTrait(trait))
.getAttribute(attribute.fulfill(1));
}
}
// <--[tag]
// @attribute <n@npc.has_trigger[<trigger>]>
// @returns Element(Boolean)
// @description
// Returns whether the NPC has a specified trigger.
// -->
if (attribute.startsWith("has_trigger")
&& attribute.hasContext(1)) {
if (!getCitizen().hasTrait(TriggerTrait.class))
return Element.FALSE.getAttribute(attribute.fulfill(1));
TriggerTrait trait = getCitizen().getTrait(TriggerTrait.class);
return new Element(trait.hasTrigger(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <n@npc.anchor.list>
// @returns dList
// @description
// returns a list of anchor names currently assigned to the NPC.
// -->
if (attribute.startsWith("anchor.list")
|| attribute.startsWith("anchors.list")) {
List<String> list = new ArrayList<String>();
for (Anchor anchor : getCitizen().getTrait(Anchors.class).getAnchors())
list.add(anchor.getName());
return new dList(list).getAttribute(attribute.fulfill(2));
}
// <--[tag]
// @attribute <n@npc.has_anchors>
// @returns Element(Boolean)
// @description
// returns whether the NPC has anchors assigned.
// -->
if (attribute.startsWith("has_anchors")) {
return (new Element(getCitizen().getTrait(Anchors.class).getAnchors().size() > 0))
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <n@npc.anchor[<name>]>
// @returns dLocation
// @description
// returns the location associated with the specified anchor, or null if it doesn't exist.
// -->
if (attribute.startsWith("anchor")) {
if (attribute.hasContext(1)
&& getCitizen().getTrait(Anchors.class).getAnchor(attribute.getContext(1)) != null)
return new dLocation(getCitizen().getTrait(Anchors.class)
.getAnchor(attribute.getContext(1)).getLocation())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <n@npc.has_flag[<flag_name>]>
// @returns Element(Boolean)
// @description
// returns true if the NPC has the specified flag, otherwise returns false.
// -->
if (attribute.startsWith("has_flag")) {
String flag_name;
if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
else return null;
return new Element(FlagManager.npcHasFlag(this, flag_name)).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <n@npc.flag[<flag_name>]>
// @returns Flag dList
// @description
// returns the specified flag from the NPC.
// -->
if (attribute.startsWith("flag")) {
String flag_name;
if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
else return null;
if (attribute.getAttribute(2).equalsIgnoreCase("is_expired")
|| attribute.startsWith("isexpired"))
return new Element(!FlagManager.npcHasFlag(this, flag_name))
.getAttribute(attribute.fulfill(2));
if (attribute.getAttribute(2).equalsIgnoreCase("size") && !FlagManager.npcHasFlag(this, flag_name))
return new Element(0).getAttribute(attribute.fulfill(2));
if (FlagManager.npcHasFlag(this, flag_name))
return new dList(DenizenAPI.getCurrentInstance().flagManager()
.getNPCFlag(getId(), flag_name))
.getAttribute(attribute.fulfill(1));
return new Element(identify()).getAttribute(attribute);
}
// <--[tag]
// @attribute <n@npc.list_flags[(regex:)<search>]>
// @returns dList
// @description
// Returns a list of an NPC's flag names, with an optional search for
// names containing a certain pattern.
// -->
if (attribute.startsWith("list_flags")) {
dList allFlags = new dList(DenizenAPI.getCurrentInstance().flagManager().listNPCFlags(getId()));
dList searchFlags = null;
if (!allFlags.isEmpty() && attribute.hasContext(1)) {
searchFlags = new dList();
String search = attribute.getContext(1).toLowerCase();
if (search.startsWith("regex:")) {
try {
Pattern pattern = Pattern.compile(search.substring(6));
for (String flag : allFlags)
if (pattern.matcher(flag).matches())
searchFlags.add(flag);
} catch (Exception e) {
dB.echoError(e);
}
}
else {
for (String flag : allFlags)
if (flag.toLowerCase().contains(search))
searchFlags.add(flag);
}
}
return searchFlags == null ? allFlags.getAttribute(attribute.fulfill(1))
: searchFlags.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <n@npc.constant[<constant_name>]>
// @returns Element
// @description
// returns the specified constant from the NPC.
// -->
if (attribute.startsWith("constant")) {
if (attribute.hasContext(1)) {
if (getCitizen().hasTrait(ConstantsTrait.class)
&& getCitizen().getTrait(ConstantsTrait.class).getConstant(attribute.getContext(1)) != null) {
return new Element(getCitizen().getTrait(ConstantsTrait.class)
.getConstant(attribute.getContext(1))).getAttribute(attribute.fulfill(1));
}
else {
return null;
}
}
}
// <--[tag]
// @attribute <n@npc.has_pose[<name>]>
// @returns Element(Boolean)
// @description
// Returns true if the NPC has the specified pose, otherwise returns false.
// -->
if (attribute.startsWith("has_pose")) {
if (attribute.hasContext(1))
return new Element(getCitizen().getTrait(Poses.class).hasPose(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
else
return null;
}
// <--[tag]
// @attribute <n@npc.get_pose[<name>]>
// @returns dLocation
// @description
// Returns the pose as a dLocation with x, y, and z set to 0, and the world set to the first
// possible available world Bukkit knows about.
// -->
if (attribute.startsWith("get_pose")) {
if (attribute.hasContext(1)) {
Pose pose = getCitizen().getTrait(Poses.class).getPose(attribute.getContext(1));
return new dLocation(org.bukkit.Bukkit.getWorlds().get(0), 0, 0 ,0, pose.getYaw(), pose.getPitch())
.getAttribute(attribute.fulfill(1));
}
else
return null;
}
// <--[tag]
// @attribute <n@npc.is_engaged>
// @returns Element(Boolean)
// @description
// returns whether the NPC is currently engaged.
// See <@link command Engage>
// -->
if (attribute.startsWith("engaged") || attribute.startsWith("is_engaged"))
return new Element(isEngaged()).getAttribute(attribute.fulfill(1));
// <--[tag]
// @attribute <n@npc.id>
// @returns Element(Number)
// @description
// returns the NPC's ID number.
// -->
if (attribute.startsWith("id"))
return new Element(getId()).getAttribute(attribute.fulfill(1));
// <--[tag]
// @attribute <n@npc.owner>
// @returns dPlayer/Element
// @description
// returns the owner of the NPC as a dPlayer if it's a player, otherwise as just the name.
// -->
if (attribute.startsWith("owner")) {
if (dPlayer.matches(getOwner())) {
return dPlayer.valueOf(getOwner()).getAttribute(attribute.fulfill(1));
}
else return new Element(getOwner()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <n@npc.has_skin>
// @returns Element
// @description
// returns whether the NPC has a custom skinskin.
// -->
if (attribute.startsWith("has_skin"))
return new Element(getCitizen().data().has(NPC.PLAYER_SKIN_UUID_METADATA)).getAttribute(attribute.fulfill(1));
// <--[tag]
// @attribute <n@npc.skin>
// @returns Element
// @description
// returns the NPC's custom skin, if any.
// -->
if (attribute.startsWith("skin")) {
if (getCitizen().data().has(NPC.PLAYER_SKIN_UUID_METADATA))
return new Element(getCitizen().data().get(NPC.PLAYER_SKIN_UUID_METADATA).toString()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <n@npc.inventory>
// @returns dInventory
// @description
// Returns the dInventory of the NPC.
// -->
if (attribute.startsWith("inventory"))
return getDenizenInventory().getAttribute(attribute.fulfill(1));
// <--[tag]
// @attribute <n@npc.is_spawned>
// @returns Element(Boolean)
// @description
// returns whether the NPC is spawned.
// -->
if (attribute.startsWith("is_spawned"))
return new Element(isSpawned()).getAttribute(attribute.fulfill(1));
// <--[tag]
// @attribute <n@npc.is_protected>
// @returns Element(Boolean)
// @description
// Returns whether the NPC is protected.
// -->
if (attribute.startsWith("is_protected"))
return new Element(getCitizen().isProtected()).getAttribute(attribute.fulfill(1));
// <--[tag]
// @attribute <n@npc.lookclose>
// @returns Element(Boolean)
// @description
// Returns the NPC's "lookclose" value.
// -->
if (attribute.startsWith("lookclose")) {
NPC citizen = 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.getTrait(LookClose.class).toString();
lookclose = lookclose.substring(10, lookclose.length() - 1);
return new Element(Boolean.valueOf(lookclose)).getAttribute(attribute.fulfill(1));
}
return Element.FALSE.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <n@npc.location.previous_location>
// @returns dLocation
// @description
// returns the NPC's previous navigated location.
// -->
if (attribute.startsWith("location.previous_location"))
return (NPCTags.previousLocations.containsKey(getId())
? NPCTags.previousLocations.get(getId()).getAttribute(attribute.fulfill(2))
: null);
// <--[tag]
// @attribute <n@npc.teleport_on_stuck>
// @returns dLocation
// @mechanism dNPC.teleport_on_stuck
// @description
// returns whether the NPC teleports when it is stuck.
// -->
if (attribute.startsWith("teleport_on_stuck"))
return new Element(getNavigator().getDefaultParameters().stuckAction() == TeleportStuckAction.INSTANCE)
.getAttribute(attribute.fulfill(1));
// <--[tag]
// @attribute <n@npc.has_script>
// @returns Element(Boolean)
// @description
// Returns true if the NPC has an assignment script.
// -->
if (attribute.startsWith("has_script")) {
NPC citizen = getCitizen();
return new Element(citizen.hasTrait(AssignmentTrait.class) && citizen.getTrait(AssignmentTrait.class).hasAssignment())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <n@npc.script>
// @returns dScript
// @description
// returns the NPC's assigned script.
// -->
if (attribute.startsWith("script")) {
NPC citizen = getCitizen();
if (!citizen.hasTrait(AssignmentTrait.class) || !citizen.getTrait(AssignmentTrait.class).hasAssignment()) {
return null;
}
else {
return new dScript(citizen.getTrait(AssignmentTrait.class).getAssignment().getName())
.getAttribute(attribute.fulfill(1));
}
}
// <--[tag]