Skip to content

Commit

Permalink
better npc anchor tag errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 12, 2020
1 parent 16dd163 commit 5e1a484
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java
Expand Up @@ -594,20 +594,29 @@ public static void registerTags() {
// Returns the location associated with the specified anchor, or null if it doesn't exist.
// -->
registerTag("anchor", (attribute, object) -> {
if (attribute.hasContext(1)
&& object.getCitizen().getTrait(Anchors.class).getAnchor(attribute.getContext(1)) != null) {
return new LocationTag(object.getCitizen().getTrait(Anchors.class)
.getAnchor(attribute.getContext(1)).getLocation());
Anchors trait = object.getCitizen().getTrait(Anchors.class);
if (attribute.hasContext(1)) {
Anchor anchor = trait.getAnchor(attribute.getContext(1));
if (anchor != null) {
return new LocationTag(anchor.getLocation());
}
else {
attribute.echoError("NPC Anchor '" + attribute.getContext(1) + "' 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 : object.getCitizen().getTrait(Anchors.class).getAnchors()) {
for (Anchor anchor : trait.getAnchors()) {
list.add(anchor.getName());
}
return list;
}
else {
attribute.echoError("npc.anchor[...] tag must have an input.");
}
return null;
}, "anchors");

Expand Down

0 comments on commit 5e1a484

Please sign in to comment.