Skip to content

Commit

Permalink
Allow dLists in player.target
Browse files Browse the repository at this point in the history
This will allow direct input of a dList (li@x|y) in the player.target
tag

Also cleaning the meta a little as always

Also lighten an error in InventoryCommand
  • Loading branch information
mcmonkey4eva committed Dec 12, 2013
1 parent 6772480 commit 9f8a8c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
27 changes: 15 additions & 12 deletions src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -313,7 +313,7 @@ public String getAttribute(Attribute attribute) {
}

// <--[tag]
// @attribute <p@player.flag[flag_name]>
// @attribute <p@player.flag[<flag_name>]>
// @returns Flag dList
// @description
// returns the specified flag from the player.
Expand All @@ -337,7 +337,7 @@ public String getAttribute(Attribute attribute) {
}

// <--[tag]
// @attribute <p@player.has_flag[flag_name]>
// @attribute <p@player.has_flag[<flag_name>]>
// @returns Element(Boolean)
// @description
// returns true if the Player has the specified flag, otherwise returns false.
Expand Down Expand Up @@ -415,25 +415,25 @@ public String getAttribute(Attribute attribute) {
/////////////////

// <--[tag]
// @attribute <p@player.target[npc/<entity>/<entity.type>|..]>
// @attribute <p@player.target[(<entity>|...)]>
// @returns dEntity
// @description
// Returns the entity that the player is looking at, within a maximum range of 50 blocks,
// or null if the player is not looking at an entity.
// The player can use a list of entities or entity types to filter the possible targets.
// Optionally, specify a list of entities, entity types, or 'npc' to only count those targets.
// -->

if (attribute.startsWith("target")) {
int range = 50;
int attribs = 1;

// <--[tag]
// @attribute <p@player.target[npc/<entity>/<entity.type>|..].within[#]>
// @attribute <p@player.target[(<entity>|...)].within[(<#>)]>
// @returns dEntity
// @description
// Returns the entity that the player is looking at within the specified range limit,
// or null if the player is not looking at an entity.
// The player can use a list of entities or entity types to filter the possible targets.
// Optionally, specify a list of entities, entity types, or 'npc' to only count those targets.
if (attribute.getAttribute(2).startsWith("within") &&
attribute.hasContext(2) &&
aH.matchesInteger(attribute.getContext(2))) {
Expand All @@ -445,17 +445,20 @@ public String getAttribute(Attribute attribute) {
ArrayList<LivingEntity> possibleTargets = new ArrayList<LivingEntity>();
for (Entity entity : entities) {
if (entity instanceof LivingEntity) {

// if we have a context for entity types, check the entity
if (attribute.hasContext(1)) {
for (String ent : attribute.getContext(1).split("\\|")) {
String context = attribute.getContext(1);
if (context.toLowerCase().startsWith("li@"))
context = context.substring(3);
for (String ent: context.split("\\|")) {
boolean valid = false;

if (ent.equalsIgnoreCase("npc") && CitizensAPI.getNPCRegistry().isNPC(entity)) {
valid = true;
}
else if (dEntity.matches(ent)) {
// only accept generic entities that are not npcs
// only accept generic entities that are not NPCs
if (dEntity.valueOf(ent).isGeneric()) {
if (!CitizensAPI.getNPCRegistry().isNPC(entity)) {
valid = true;
Expand Down Expand Up @@ -851,7 +854,7 @@ else if (attribute.getAttribute(2).startsWith("world"))
}

// <--[tag]
// @attribute <p@player.in_group[group_name]>
// @attribute <p@player.in_group[<group_name>]>
// @returns Element(Boolean)
// @description
// returns whether the player is in the specified group.
Expand All @@ -866,7 +869,7 @@ else if (attribute.getAttribute(2).startsWith("world"))
String group = attribute.getContext(1);

// <--[tag]
// @attribute <p@player.in_group[group_name].global>
// @attribute <p@player.in_group[<group_name>].global>
// @returns Element(Boolean)
// @description
// returns whether the player has the group with no regard to the
Expand All @@ -885,7 +888,7 @@ else if (attribute.getAttribute(2).startsWith("world"))
.getAttribute(attribute.fulfill(2));

// <--[tag]
// @attribute <p@player.in_group[group_name].world>
// @attribute <p@player.in_group[<group_name>].world>
// @returns Element(Boolean)
// @description
// returns whether the player has the group in regards to the
Expand Down
Expand Up @@ -142,7 +142,7 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
// If this is a player inventory, update it
case UPDATE:
if (!destination.update())
throw new CommandExecutionException("Only player inventories can be force-updated!");
dB.echoError("Only player inventories can be force-updated!");
break;

}
Expand Down
Expand Up @@ -122,7 +122,7 @@ public void serverTags(ReplaceableTagEvent event) {
new Attribute(event.raw_tag, event.getScriptEntry()).fulfill(1);

// <--[tag]
// @attribute <server.has_flag[flag_name]>
// @attribute <server.has_flag[<flag_name>]>
// @returns Element(boolean)
// @description
// returns true if the Player has the specified flag, otherwise returns false.
Expand Down

0 comments on commit 9f8a8c6

Please sign in to comment.