Skip to content

Commit

Permalink
Allow random entities in dEntity.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Jun 30, 2013
1 parent ff64c74 commit 55963e1
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -105,6 +105,21 @@ public static void remove(String id) {
public static dEntity valueOf(String string) {
if (string == null) return null;

// 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_DRAGON|FISHING_HOOK|ITEM_FRAME|LIGHTNING|PAINTING|PLAYER|UNKNOWN|WEATHER|WITHER)$") == true) {

randomType = EntityType.values()[Utilities.getRandom().nextInt(EntityType.values().length)];
}

return new dEntity(randomType, "RANDOM");
}

///////
// Match @object format

Expand Down Expand Up @@ -167,7 +182,7 @@ else if (isSaved(m.group(2)))

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

m = entity_with_data.matcher(string);

String data = null;
Expand All @@ -193,12 +208,15 @@ else if (isSaved(m.group(2)))


public static boolean matches(String arg) {

Matcher m;
m = entity_by_id.matcher(arg);
if (m.matches()) return true;

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

if (arg.equalsIgnoreCase("RANDOM"))
return true;

if (ScriptRegistry.containsScript(arg, EntityScriptContainer.class))
return true;
Expand Down

0 comments on commit 55963e1

Please sign in to comment.