diff --git a/src/main/java/net/aufdemrand/denizen/objects/aH.java b/src/main/java/net/aufdemrand/denizen/objects/aH.java index 62477c191d..34d46f0a48 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/aH.java +++ b/src/main/java/net/aufdemrand/denizen/objects/aH.java @@ -98,13 +98,6 @@ public String getValue() { return value; } - public String getPrefixAndValue() { - if (has_prefix) - return prefix + ":" + value; - else - return value; - } - public boolean matchesEnum(Enum[] values) { for (Enum value : values) if (value.name().replace("_", "").equalsIgnoreCase(this.value.replace("_", ""))) @@ -114,8 +107,9 @@ public boolean matchesEnum(Enum[] values) { } public boolean matchesPrefix(String values) { + if (!hasPrefix()) return false; for (String value : values.split(",")) - if (value.trim().equalsIgnoreCase((prefix != null ? prefix : this.value))) + if (value.trim().equalsIgnoreCase(prefix)) return true; return false; diff --git a/src/main/java/net/aufdemrand/denizen/objects/dEntity.java b/src/main/java/net/aufdemrand/denizen/objects/dEntity.java index 8b0736b263..63dab62db7 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dEntity.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dEntity.java @@ -118,15 +118,16 @@ public static dEntity valueOf(String string) { // Choose a random entity type if "RANDOM" is used if (string.equalsIgnoreCase("RANDOM")) { + EntityType randomType = null; // When selecting a random entity type, ignore invalid or inappropriate ones - while (randomType == null || randomType.name().matches("^(COMPLEX_PART|DROPPED_ITEM|ENDER_CRYSTAL" + - "|ENDER_DRAGON|FISHING_HOOK|ITEM_FRAME|LIGHTNING|PAINTING" + - "|PLAYER|UNKNOWN|WEATHER|WITHER|WITHER_SKULL)$")) + while (randomType == null || + randomType.name().matches("^(COMPLEX_PART|DROPPED_ITEM|ENDER_CRYSTAL|ENDER_DRAGON|FISHING_HOOK|ITEM_FRAME|LIGHTNING|PAINTING|PLAYER|UNKNOWN|WEATHER|WITHER|WITHER_SKULL)$")) { + randomType = EntityType.values()[Utilities.getRandom().nextInt(EntityType.values().length)]; + } - // Return the entity return new dEntity(randomType, "RANDOM"); } @@ -135,10 +136,12 @@ public static dEntity valueOf(String string) { // Make sure string matches what this interpreter can accept. + Matcher m; m = entity_by_id.matcher(string); if (m.matches()) { + String entityGroup = m.group(1).toUpperCase(); // NPC entity @@ -146,7 +149,7 @@ public static dEntity valueOf(String string) { NPC returnable = CitizensAPI.getNPCRegistry() .getById(Integer.valueOf(m.group(2))); - if (returnable != null) return new dEntity(returnable); + if (returnable != null) return new dEntity(returnable.getBukkitEntity()); else dB.echoError("Invalid NPC! '" + entityGroup + "' could not be found. Has it been despawned or killed?"); } @@ -262,16 +265,6 @@ public static boolean matches(String arg) { // CONSTRUCTORS ////////////////// - dNPC built_from_npc = null; - - public dEntity(NPC npc) { - if (npc != null) { - built_from_npc = dNPC.mirrorCitizensNPC(npc); - this.entity = npc.getBukkitEntity(); - this.entity_type = (npc.getBukkitEntity() != null ? npc.getBukkitEntity().getType() : null); - } else dB.echoError("NPC referenced for dEntity is null!"); - } - public dEntity(Entity entity) { if (entity != null) { this.entity = entity; @@ -341,7 +334,7 @@ public boolean isLivingEntity() { public NPC getNPC() { - return built_from_npc.getCitizen(); + return CitizensAPI.getNPCRegistry().getNPC(getBukkitEntity()); } /** @@ -351,10 +344,11 @@ public NPC getNPC() { */ public boolean isNPC() { - if (built_from_npc != null) return true; - else return false; + if (CitizensAPI.getNPCRegistry().isNPC(getBukkitEntity())) + return true; + return false; } - + /** * Get the Player corresponding to this entity * @@ -362,6 +356,7 @@ public boolean isNPC() { */ public Player getPlayer() { + return (Player) getBukkitEntity(); } @@ -390,7 +385,7 @@ public boolean isGeneric() { return true; return false; } - + /** * Get the location of this entity * @@ -402,10 +397,10 @@ public dLocation getLocation() { if (!isGeneric()) { return new dLocation(getBukkitEntity().getLocation()); } - + return null; } - + /** * Get the eye location of this entity * @@ -417,23 +412,16 @@ public dLocation getEyeLocation() { if (!isGeneric() && isLivingEntity()) { return new dLocation(getLivingEntity().getEyeLocation()); } - + return null; } - + public void spawnAt(Location location) { // If the entity is already spawned, teleport it. if (entity != null && isUnique()) entity.teleport(location); - else if (built_from_npc != null) { - built_from_npc.getCitizen().teleport(location, TeleportCause.COMMAND); - entity_type = built_from_npc.getEntityType(); - entity = built_from_npc.getEntity(); - } - else { if (entity_type != null) { - if (despawned_entity != null) { // If entity had a custom_script, use the script to rebuild the base entity. if (despawned_entity.custom_script != null) @@ -453,7 +441,7 @@ else if (built_from_npc != null) { org.bukkit.entity.Entity ent = null; if (entity_type.name().matches("PLAYER")) { - + NPC npc = CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, data1); npc.spawn(location); } @@ -499,9 +487,9 @@ else if (entity_type.name().matches("FALLING_BLOCK")) { ent = location.getWorld().spawnEntity(location, entity_type); entity = ent; - + if (entity_type.name().matches("PIG_ZOMBIE")) { - + // Give pig zombies golden swords by default, unless data2 specifies // a different weapon if (dItem.matches(data1) == false) { @@ -512,7 +500,7 @@ else if (entity_type.name().matches("FALLING_BLOCK")) { .setItemInHand(dItem.valueOf(data1).getItemStack()); } else if (entity_type.name().matches("SKELETON")) { - + // Give skeletons bows by default, unless data2 specifies // a different weapon if (dItem.matches(data2) == false) { @@ -634,10 +622,10 @@ public void target(LivingEntity target) { // If the target is not null, cast it to an NMS EntityLiving // as well for one of the two methods below EntityLiving nmsTarget = target != null ? ((CraftLivingEntity) target).getHandle() - : null; - + : null; + ((CraftCreature) entity).getHandle(). - setGoalTarget(nmsTarget); + setGoalTarget(nmsTarget); ((CraftCreature) entity).getHandle(). setGoalTarget(((CraftLivingEntity) target).getHandle()); @@ -753,17 +741,19 @@ public int comparesTo(dEntity entity) { @Override public String identify() { - // Check if entity is a NPC or Player - if (built_from_npc != null) - return "n@" + getNPC().getId(); - - if (getBukkitEntity() != null && getBukkitEntity() instanceof Player) - return "p@" + ((Player) getBukkitEntity()).getName(); + // Check if entity is a Player or NPC + if (getBukkitEntity() != null) { + if (isNPC()) + return "n@" + getNPC().getId(); + else if (getBukkitEntity() instanceof Player) + return "p@" + ((Player) getBukkitEntity()).getName(); + } // Check if entity is a 'saved entity' if (isSaved(this)) return "e@" + getSaved(this); + else if (isSpawned()) return "e@" + getBukkitEntity().getEntityId(); @@ -796,12 +786,12 @@ public String getAttribute(Attribute attribute) { dB.echoDebug("dEntity has returned null."); return "null"; } - + // <-- // -> dEntity // Returns the dEntity of the entity. // --> - + // <-- // -> dEntity // If the entity is in a vehicle, returns the vehicle as a @@ -887,7 +877,7 @@ public String getAttribute(Attribute attribute) { if (attribute.startsWith("eye_location")) return new dLocation(getEyeLocation()) .getAttribute(attribute.fulfill(1)); - + // <-- // -> dLocation // Returns the dLocation of the entity. @@ -1062,7 +1052,7 @@ else if ((float) getLivingEntity().getHealth() / maxHealth < 1) for (org.bukkit.potion.PotionEffect effect : getLivingEntity().getActivePotionEffects()) if (effect.getType().equals(org.bukkit.potion.PotionType.valueOf(attribute.getContext(1)))) returnElement = true; - else if (!getLivingEntity().getActivePotionEffects().isEmpty()) returnElement = true; + else if (!getLivingEntity().getActivePotionEffects().isEmpty()) returnElement = true; return new Element(returnElement).getAttribute(attribute.fulfill(1)); } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java index 462c445113..a87eb7e09d 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java @@ -102,7 +102,7 @@ public boolean execute(ScriptEntry scriptEntry) { continue; } - m = definition_pattern.matcher(arg.getValue()); + m = definition_pattern.matcher(arg.raw_value); sb = new StringBuffer(); while (m.find()) { if (scriptEntry.getResidingQueue().hasContext(m.group(1).toLowerCase())) @@ -138,7 +138,7 @@ else if (arg.matchesPrefix("npc, npcid") && !if_ignore) { dB.echoDebug("...replacing the linked NPC."); String value = TagManager.tag(scriptEntry.getPlayer(), scriptEntry.getNPC(), arg.getValue(), false); dNPC npc = dNPC.valueOf(arg.getValue()); - if (!npc.isValid()) { + if (npc == null || !npc.isValid()) { dB.echoError(value + " is an invalid NPC!"); return false; } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/FlagCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/FlagCommand.java index 1bc2a7776f..51a5c11ba7 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/FlagCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/FlagCommand.java @@ -76,6 +76,7 @@ else if (!scriptEntry.hasObject("action") // Check for flag_name:value/action else if (!scriptEntry.hasObject("action") && arg.raw_value.split(":", 3).length == 2) { + String[] flagArgs = arg.raw_value.split(":", 2); scriptEntry.addObject("flag_name", new Element(flagArgs[0].toUpperCase()));