Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Jun 16, 2013
1 parent 93e57d4 commit f9c1aa3
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 19 deletions.
28 changes: 26 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/Element.java
Expand Up @@ -131,11 +131,35 @@ public String getAttribute(Attribute attribute) {

if (attribute.startsWith("aslist")
|| attribute.startsWith("as_list"))
return new dList(element).getAttribute(attribute.fulfill(1));
return dList.valueOf(element).getAttribute(attribute.fulfill(1));

if (attribute.startsWith("asentity")
|| attribute.startsWith("as_entity"))
return new dEntity(element).getAttribute(attribute.fulfill(1));
return dEntity.valueOf(element).getAttribute(attribute.fulfill(1));

if (attribute.startsWith("aslocation")
|| attribute.startsWith("as_location"))
return dLocation.valueOf(element).getAttribute(attribute.fulfill(1));

if (attribute.startsWith("asplayer")
|| attribute.startsWith("as_player"))
return dPlayer.valueOf(element).getAttribute(attribute.fulfill(1));

if (attribute.startsWith("asnpc")
|| attribute.startsWith("as_npc"))
return dNPC.valueOf(element).getAttribute(attribute.fulfill(1));

if (attribute.startsWith("asitem")
|| attribute.startsWith("as_item"))
return dItem.valueOf(element).getAttribute(attribute.fulfill(1));

if (attribute.startsWith("asscript")
|| attribute.startsWith("as_script"))
return dScript.valueOf(element).getAttribute(attribute.fulfill(1));

if (attribute.startsWith("asduration")
|| attribute.startsWith("as_duration"))
return Duration.valueOf(element).getAttribute(attribute.fulfill(1));

if (attribute.startsWith("substring")) { // substring[2,8]
int beginning_index = Integer.valueOf(attribute.getContext(1).split(",")[0]) - 1;
Expand Down
21 changes: 6 additions & 15 deletions src/main/java/net/aufdemrand/denizen/objects/aH.java
Expand Up @@ -491,22 +491,13 @@ public static boolean matchesDuration(String arg) {
return Duration.matches(arg);
}

@Deprecated
public static boolean matchesEntityType(String arg) {
final Pattern matchesEntityPtrn = Pattern.compile("entity:(.+)", Pattern.CASE_INSENSITIVE);
Matcher m = matchesEntityPtrn.matcher(arg);
if (m.matches()) {
String group = m.group(1).toUpperCase();
// Check against valid EntityTypes using Bukkit's EntityType enum
for (EntityType validEntity : EntityType.values())
if (group.equals(validEntity.name()))
return true;
}
// Check for valid prefix, warn about value.
if (arg.toUpperCase().startsWith("entity:"))
dB.echoError("While parsing '" + arg + "', Denizen has run into a problem. While the " +
"prefix is correct, the value is not valid. Perhaps a replaceable Tag has failed " +
"to fill in a valid EntityType, or the EntityType you provided is not correct?");
arg = arg.replace("duration:", "");

// Check against valid EntityTypes using Bukkit's EntityType enum
for (EntityType validEntity : EntityType.values())
if (arg.equalsIgnoreCase(validEntity.name()))
return true;
return false;
}

Expand Down
85 changes: 84 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dNPC.java
Expand Up @@ -16,6 +16,7 @@
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.trait.Owner;
import net.minecraft.server.v1_5_R3.EntityLiving;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftLivingEntity;
import org.bukkit.entity.EntityType;
Expand Down Expand Up @@ -220,6 +221,88 @@ public dNPC setPrefix(String prefix) {

@Override
public String getAttribute(Attribute attribute) {
return null; //To change body of implemented methods use File | Settings | File Templates.

if (type.equals("NAME")) {
event.setReplaced(ChatColor.stripColor(n.getName()));
if (subType.equals("NICKNAME")) {
if (n.getCitizen().hasTrait(NicknameTrait.class))
event.setReplaced(n.getCitizen().getTrait(NicknameTrait.class).getNickname());
}

} else if (type.equals("HEALTH")) {

if (subType.equals("MAX"))
event.setReplaced(String.valueOf(n.getHealthTrait().getMaxhealth()));
else
event.setReplaced(String.valueOf(n.getHealthTrait().getHealth()));

} else if (type.equals("TYPE")) {
if (subType.equals("FORMATTED"))
event.setReplaced(String.valueOf(n.getEntityType().name().toLowerCase().replace('_', ' ')));
else
event.setReplaced(String.valueOf(n.getEntityType().name()));

} else if (type.equals("ID")) {
event.setReplaced(String.valueOf(n.getId()));

} else if (type.equals("OWNER")) {
event.setReplaced(String.valueOf(n.getOwner()));

} else if (type.equals("LOCATION")) {
dLocation loc = n.getLocation();
event.setReplaced(loc.getX()
+ "," + loc.getY()
+ "," + loc.getZ()
+ "," + n.getWorld().getName());
if (subType.equals("BLOCK"))
event.setReplaced(loc.getBlockX()
+ "," + loc.getBlockY()
+ "," + loc.getBlockZ()
+ "," + n.getWorld().getName());
else if (subType.equals("FORMATTED"))
event.setReplaced("X '" + loc.getX()
+ "', Y '" + loc.getY()
+ "', Z '" + loc.getZ()
+ "', in world '" + n.getWorld().getName() + "'");
else if (subType.equals("X"))
event.setReplaced(String.valueOf(n.getLocation().getX()));
else if (subType.equals("Y"))
event.setReplaced(String.valueOf(n.getLocation().getY()));
else if (subType.equals("Z"))
event.setReplaced(String.valueOf(n.getLocation().getZ()));
else if (subType.equals("STANDING_ON"))
event.setReplaced(loc.add(0, -1, 0).getBlock().getType().name());
else if (subType.equals("STANDING_ON_DISPLAY"))
event.setReplaced(n.getLocation().add(0, -1, 0).getBlock().getType().name().toLowerCase().replace('_', ' '));
else if (subType.equals("WORLD_SPAWN"))
event.setReplaced(n.getWorld().getSpawnLocation().getX()
+ "," + n.getWorld().getSpawnLocation().getY()
+ "," + n.getWorld().getSpawnLocation().getZ()
+ "," + n.getWorld().getName());
else if (subType.equals("WORLD"))
event.setReplaced(n.getWorld().getName());
else if (subType.equals("PREVIOUS_LOCATION"))
if (previousLocations.containsKey(n.getId()))
event.setReplaced(previousLocations.get(n.getId()).identify());

} else if (type.equals("NAVIGATOR")) {
if (subType.equals("IS_NAVIGATING"))
event.setReplaced(Boolean.toString(n.getNavigator().isNavigating()));
else if (subType.equals("SPEED"))
event.setReplaced(String.valueOf(n.getNavigator().getLocalParameters().speedModifier()));
else if (subType.equals("AVOID_WATER"))
event.setReplaced(Boolean.toString(n.getNavigator().getLocalParameters().avoidWater()));
else if (subType.equals("TARGET_LOCATION")) {
dLocation loc = new dLocation(n.getNavigator().getTargetAsLocation());
if (loc != null) event.setReplaced(loc.identify());
} else if (subType.equals("IS_FIGHTING")) {
event.setReplaced(String.valueOf(event.getNPC().getNavigator().getEntityTarget().isAggressive()));
} else if (subType.equals("TARGET_TYPE")) {
event.setReplaced(event.getNPC().getNavigator().getTargetType().toString());
}

}


}
}
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -165,7 +165,7 @@ public String toString() {

@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) return null;
if (attribute == null) return "null";

dB.log("getAttribute: " + getType() + " ---> " + attribute.attributes.toString());

Expand Down

0 comments on commit f9c1aa3

Please sign in to comment.