Skip to content

Commit

Permalink
object/argument update towards 0.9 release
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed May 23, 2013
1 parent 6a8166d commit 51a980c
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/arguments/aH.java
Expand Up @@ -121,7 +121,7 @@ public <T extends dScriptArgument> T asType(Class<? extends dScriptArgument> cla

dScriptArgument arg = null;
try {
arg = (dScriptArgument) clazz.getMethod("valueOf", dScriptArgument.class)
arg = (dScriptArgument) clazz.getMethod("valueOf", clazz)
.invoke(null, value);

return (T) clazz.cast(arg).setPrefix(prefix);
Expand Down
37 changes: 29 additions & 8 deletions src/main/java/net/aufdemrand/denizen/arguments/dEntity.java
Expand Up @@ -83,7 +83,7 @@ public static void remove(String id) {
* @return a dEntity, or null
*/
@ObjectFetcher("e")
public static dScriptArgument valueOf(String string) {
public static dEntity valueOf(String string) {
if (string == null) return null;

///////
Expand Down Expand Up @@ -142,6 +142,14 @@ else if (isSaved(m.group(3)))
}
}

////////
// Match Custom Entity

if (ScriptRegistry.containsScript(m.group(1), EntityScriptContainer.class)) {
// Construct a new custom unspawned entity from script
return ScriptRegistry.getScriptContainerAs(m.group(1), EntityScriptContainer.class).getEntityFrom();
}

////////
// Match Entity_Type

Expand All @@ -153,15 +161,28 @@ else if (isSaved(m.group(3)))
return new dEntity(type);
}

////////
// Match Custom Entity
return null;
}

if (ScriptRegistry.containsScript(m.group(1), EntityScriptContainer.class)) {
// Construct a new custom unspawned entity from script
return ScriptRegistry.getScriptContainerAs(m.group(1), EntityScriptContainer.class).getEntityFrom();
}

return null;
public static boolean matches(String arg) {

final Pattern entity_by_id =
Pattern.compile("((n@|e@|p@)(.+))",
Pattern.CASE_INSENSITIVE);
Matcher m;
m = entity_by_id.matcher(arg);
if (m.matches()) return true;

arg = arg.replace("e@", "");

if (ScriptRegistry.containsScript(m.group(1), EntityScriptContainer.class))
return true;

for (EntityType type : EntityType.values())
if (type.name().equalsIgnoreCase(arg)) return true;

return false;
}


Expand Down
25 changes: 24 additions & 1 deletion src/main/java/net/aufdemrand/denizen/arguments/dItem.java
Expand Up @@ -2,6 +2,7 @@

import net.aufdemrand.denizen.interfaces.dScriptArgument;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.scripts.containers.core.EntityScriptContainer;
import net.aufdemrand.denizen.scripts.containers.core.ItemScriptContainer;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.utilities.debugging.dB;
Expand All @@ -12,6 +13,7 @@
import org.bukkit.World;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;

Expand Down Expand Up @@ -71,7 +73,7 @@ public static void remove(String id) {
*
*/
@ObjectFetcher("i")
public static dScriptArgument valueOf(String string) {
public static dItem valueOf(String string) {
if (string == null) return null;
Matcher m;

Expand Down Expand Up @@ -159,6 +161,27 @@ public static dScriptArgument valueOf(String string) {
}


public static boolean matches(String arg) {

final Pattern entity_by_id =
Pattern.compile("((n@|e@|p@)(.+))",
Pattern.CASE_INSENSITIVE);
Matcher m;
m = entity_by_id.matcher(arg);
if (m.matches()) return true;

arg = arg.replace("e@", "");

if (ScriptRegistry.containsScript(m.group(1), EntityScriptContainer.class))
return true;

for (EntityType type : EntityType.values())
if (type.name().equalsIgnoreCase(arg)) return true;

return false;
}


///////////////
// Constructors
/////////////
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/net/aufdemrand/denizen/arguments/dList.java
Expand Up @@ -16,7 +16,7 @@
public class dList extends ArrayList<String> implements dScriptArgument {

@ObjectFetcher("li, fl")
public static dScriptArgument valueOf(String string) {
public static dList valueOf(String string) {
if (string == null) return null;

///////
Expand Down Expand Up @@ -59,6 +59,24 @@ public static dScriptArgument valueOf(String string) {
}


public static boolean matches(String arg) {

// Make sure string matches what this interpreter can accept.
final Pattern flag_by_id =
Pattern.compile("(fl\\[((?:p@|n@)(.+?))\\]@|fl@)(.+)",
Pattern.CASE_INSENSITIVE);

Matcher m;
m = flag_by_id.matcher(arg);

if (m.matches()) return true;

if (arg.contains("|")) return true;

return false;
}


/////////////
// Constructors
//////////
Expand Down
46 changes: 27 additions & 19 deletions src/main/java/net/aufdemrand/denizen/arguments/dLocation.java
Expand Up @@ -11,6 +11,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class dLocation extends org.bukkit.Location implements dScriptArgument {

Expand Down Expand Up @@ -88,27 +90,29 @@ public static void _saveLocations() {
* @return a Location, or null if incorrectly formatted
*
*/
public static dScriptArgument valueOf(String string) {
public static dLocation valueOf(String string) {
if (string == null) return null;
// Strip prefix (ie. location:...)
if (string.split(":").length > 1)
string = string.split(":", 2)[1];

////////
// Match @object format for saved dLocations
Matcher m;

final Pattern item_by_saved = Pattern.compile("(l@)(.+)");
m = item_by_saved.matcher(string);

if (m.matches())
return getSaved(m.group(2));


////////
// Match location formats

// Split values
String[] split = string.split(",");

if (split.length == 5)
// If 5 values, contains an id with standard dScript location format
try {
return new dLocation(Bukkit.getWorld(split[4]),
Double.valueOf(split[1]),
Double.valueOf(split[2]),
Double.valueOf(split[3])).rememberAs(split[0]);
} catch(Exception e) {
return null;
}

else if (split.length == 4)
// If 4 values, standard id-less dScript location format
if (split.length == 4)
// If 4 values, standard dScript location format
// x,y,z,world
try {
return new dLocation(Bukkit.getWorld(split[3]),
Double.valueOf(split[0]),
Expand All @@ -120,7 +124,8 @@ else if (split.length == 4)


else if (split.length == 6)
// If 6 values, id-less location with pitch/yaw
// If 6 values, location with pitch/yaw
// x,y,z,yaw,pitch,world
try {
return new dLocation(Bukkit.getWorld(split[4]),
Double.valueOf(split[1]),
Expand All @@ -130,10 +135,13 @@ else if (split.length == 6)
return null;
}


return null;
}

public static dScriptArgument fetchAsArg(String arg) {
return valueOf(arg);
}

/**
* Turns a Bukkit Location into a Location, which has some helpful methods
* for working with dScript.
Expand Down
Expand Up @@ -8,17 +8,17 @@
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.util.PlayerAnimation;
import net.minecraft.server.v1_5_R2.EntityFishingHook;
import net.minecraft.server.v1_5_R2.EntityHuman;
import net.minecraft.server.v1_5_R2.EntityItem;
import net.minecraft.server.v1_5_R2.Item;
import net.minecraft.server.v1_5_R2.ItemStack;
import net.minecraft.server.v1_5_R2.MathHelper;
import net.minecraft.server.v1_5_R2.WorldServer;
import net.minecraft.server.v1_5_R3.EntityFishingHook;
import net.minecraft.server.v1_5_R3.EntityHuman;
import net.minecraft.server.v1_5_R3.EntityItem;
import net.minecraft.server.v1_5_R3.Item;
import net.minecraft.server.v1_5_R3.ItemStack;
import net.minecraft.server.v1_5_R3.MathHelper;
import net.minecraft.server.v1_5_R3.WorldServer;

import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_5_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_5_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.util.Vector;
Expand Down
Expand Up @@ -10,12 +10,12 @@
import net.citizensnpcs.api.event.NPCDeathEvent;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.minecraft.server.v1_5_R2.EntityHuman;
import net.minecraft.server.v1_5_R3.EntityHuman;

import org.bukkit.Bukkit;
import org.bukkit.EntityEffect;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftLivingEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
Expand Down

0 comments on commit 51a980c

Please sign in to comment.