Skip to content

Commit

Permalink
Add some 'language' meta.
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Sep 18, 2013
1 parent d336a0c commit 23bd387
Show file tree
Hide file tree
Showing 7 changed files with 382 additions and 49 deletions.
10 changes: 5 additions & 5 deletions src/main/java/net/aufdemrand/denizen/CommandHandler.java
Expand Up @@ -891,17 +891,17 @@ public void scripts(CommandContext args, CommandSender sender, NPC npc) throws C
ScriptContainer scriptContainer = ScriptRegistry.getScriptContainer(script);
// If a --type has been specified...
if (type != null) {
if (scriptContainer.getType().equalsIgnoreCase(type))
if (scriptContainer.getContainerType().equalsIgnoreCase(type))
if (filter != null) {
if (script.contains(filter.toUpperCase()))
paginator.addLine("<a>" + scriptContainer.getType().substring(0, 4) + " <b>" + script);
paginator.addLine("<a>" + scriptContainer.getContainerType().substring(0, 4) + " <b>" + script);
}
else paginator.addLine("<a>" + scriptContainer.getType().substring(0, 4) + " <b>" + script);
else paginator.addLine("<a>" + scriptContainer.getContainerType().substring(0, 4) + " <b>" + script);
// If a --filter has been specified...
} else if (filter != null) {
if (script.contains(filter.toUpperCase()))
paginator.addLine("<a>" + scriptContainer.getType().substring(0, 4) + " <b>" + script);
} else paginator.addLine("<a>" + scriptContainer.getType().substring(0, 4) + " <b>" + script);
paginator.addLine("<a>" + scriptContainer.getContainerType().substring(0, 4) + " <b>" + script);
} else paginator.addLine("<a>" + scriptContainer.getContainerType().substring(0, 4) + " <b>" + script);
}
// Send the contents of the Paginator to the Player (or Console)
if (!paginator.sendPage(sender, args.getInteger(1, 1)))
Expand Down
53 changes: 52 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/aH.java
Expand Up @@ -11,6 +11,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
* The dScript Argument Helper will aid you in parsing and formatting arguments from a
* dScript argument string (such as those found in a ScriptEntry.getArguments() method).
Expand All @@ -20,16 +21,43 @@
*/
public class aH {


////////////////////
// Patterns and Enumerations
/////////////////

public enum PrimitiveType { Float, Double, Integer, Boolean, String, Word, Percentage }

final static Pattern floatPrimitive =
Pattern.compile("^[-+]?[0-9]+[.]?[0-9]*([eE][-+]?[0-9]+)?$");

// <--[language]
// @name number
// @description
// Many arguments in Denizen require the use of a 'number', or 'double'. Sometimes referred to as #.# or <number>,
// this kind of hint can generally be filled with any reasonable positive or negative number with or without a
// decimal point. Numbers can be verified with the 'if' commands' 'matches' functionality.
// For example: - if <number> matches double ... will return true if <number> is a valid number.
//
// Denizen uses the regular expression pattern (-)?(?:(?:\d+)|)(?:(?:\.\d+)|) for number matching.
// -->
final static Pattern doublePrimitive =
Pattern.compile("(-)?(?:(?:\\d+)|)(?:(?:\\.\\d+)|)");

// <--[language]
// @name percentage
// @description
// Promotes the usage of a 'percentage' format to be used in applicable arguments. The 'percentage' in Denizen is
// much like the 'number', except arguments which utilize percentages instead of numbers can also include a %.
// Percentage arguments can generally be filled with any reasonable positive or negative number with or without a
// decimal point and/or percentage sign. Argument hints and other usages will typically refer to a percentage as
// #.#% or <percentage>. Percentages can be verified with the 'if' commands' 'matches' functionality.
// For example: - if <percentage> matches percentage ... will return true if <percentage> is a valid percentage.
//
// Denizen uses the regular expression pattern (?:(?:\d+)|)(?:(?:\.\d+)|)(%)? for percentage matching.
// -->
final static Pattern percentagePrimitive =
Pattern.compile("(?:(?:\\d+)|)(?:(?:\\.\\d+)|)(%|)");
Pattern.compile("(?:(?:\\d+)|)(?:(?:\\.\\d+)|)(%)?");

final static Pattern integerPrimitive =
Pattern.compile("(-)?\\d+");
Expand All @@ -40,6 +68,11 @@ public enum PrimitiveType { Float, Double, Integer, Boolean, String, Word, Perce
final static Pattern wordPrimitive =
Pattern.compile("\\w+");


////////////////////
// Argument Object
//////////////////

public static class Argument {
public String raw_value;
String prefix = null;
Expand All @@ -64,14 +97,17 @@ public Argument(String string) {
// dB.log("Constructed Argument: " + prefix + ":" + value);
}


public static Argument valueOf(String string) {
return new Argument(string);
}


public boolean startsWith(String string) {
return value.toLowerCase().startsWith(string.toLowerCase());
}


public boolean hasPrefix() {
return has_prefix;
}
Expand All @@ -82,6 +118,7 @@ public Argument getPrefix() {
return valueOf(prefix);
}


public boolean matches(String values) {
for (String value : values.split(","))
if (value.trim().equalsIgnoreCase(this.value))
Expand All @@ -90,14 +127,17 @@ public boolean matches(String values) {
return false;
}


public void replaceValue(String string) {
value = string;
}


public String getValue() {
return value;
}


public boolean matchesEnum(Enum[] values) {
for (Enum value : values)
if (value.name().replace("_", "").equalsIgnoreCase(this.value.replace("_", "")))
Expand All @@ -106,6 +146,7 @@ public boolean matchesEnum(Enum[] values) {
return false;
}


public boolean matchesPrefix(String values) {
if (!hasPrefix()) return false;
for (String value : values.split(","))
Expand All @@ -115,6 +156,7 @@ public boolean matchesPrefix(String values) {
return false;
}


public boolean matchesPrimitive(PrimitiveType argumentType) {
if (value == null) return false;

Expand Down Expand Up @@ -144,6 +186,7 @@ public boolean matchesPrimitive(PrimitiveType argumentType) {
return false;
}


public boolean matchesArgumentType(Class<? extends dObject> dClass) {

try {
Expand All @@ -155,6 +198,7 @@ public boolean matchesArgumentType(Class<? extends dObject> dClass) {
return false;
}


// Check if this argument matches a dList of a certain dObject
public boolean matchesArgumentList(Class<? extends dObject> dClass) {

Expand All @@ -163,6 +207,7 @@ public boolean matchesArgumentList(Class<? extends dObject> dClass) {
return list.filter(dClass) != null;
}


public Element asElement() {
return new Element(prefix, value);
}
Expand Down Expand Up @@ -193,6 +238,12 @@ public <T extends dObject> T asType(Class<? extends dObject> clazz) {
}



/////////////////
// Static Methods
///////////////


/**
* Turns a list of string arguments (separated by buildArgs) into Argument
* Objects for easy matching and dObject creation throughout Denizen.
Expand Down

0 comments on commit 23bd387

Please sign in to comment.