Skip to content

Commit

Permalink
Fix Regex that broke use of special data values for items and mostly …
Browse files Browse the repository at this point in the history
…likely also mistreated innocent baby bunnies.
  • Loading branch information
davidcernat committed Jun 14, 2013
1 parent 3e57a76 commit 91c18ba
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions src/main/java/net/aufdemrand/denizen/utilities/arguments/dItem.java
Expand Up @@ -28,10 +28,7 @@ public class dItem implements dScriptArgument {
// TODO: Make prettier.. maybe an array of Patterns isn't even necessary anymore.
// Seperate them out instead?
final static Pattern[] getItemPtrn = {
Pattern.compile("(?:(?:.+?:)|)(\\d+):(\\d+)"),
Pattern.compile("(?:(?:.+?:)|)(\\d+)"),
Pattern.compile("(?:(?:.+?:)|)([a-zA-Z\\x5F]+?):(\\d+)"),
Pattern.compile("(?:(?:.+?:)|)([a-zA-Z\\x5F]+)"),
Pattern.compile("(?:item:)?(\\w+):?(\\d+)?"),
Pattern.compile("(?:(?:.+?:)|)item\\.(.+)", Pattern.CASE_INSENSITIVE),
Pattern.compile("(?:(?:.+?:)|)(.+)"),
};
Expand All @@ -56,47 +53,44 @@ public static dItem valueOf(String string, Player player, dNPC npc) {
dItem stack = null;

// Check if a saved item instance from NEW
m[0] = getItemPtrn[4].matcher(string);
m[0] = getItemPtrn[1].matcher(string);
if (m[0].matches()) {
// TODO: Finish NEW command.
}

// Check traditional item patterns.
m[0] = getItemPtrn[0].matcher(string);
m[1] = getItemPtrn[1].matcher(string);
m[2] = getItemPtrn[2].matcher(string);
m[3] = getItemPtrn[3].matcher(string);

try {
// Match 'ItemId:Data'
if (m[0].matches()) {
stack = new dItem(Integer.valueOf(m[0].group(1)));
stack.setDurability(Short.valueOf(m[0].group(2)));
return stack;

// Match 'ItemId'
} else if (m[1].matches()) {
stack = new dItem(Integer.valueOf(m[1].group(1)));
return stack;

// Match 'Material:Data'
} else if (m[2].matches()) {
stack = new dItem(Material.valueOf(m[2].group(1).toUpperCase()));
stack.setDurability(Short.valueOf(m[2].group(2)));
return stack;

// Match 'Material'
} else if (m[3].matches()) {
stack = new dItem(Material.valueOf(m[3].group(1).toUpperCase()));
return stack;
}
if (m[0].matches()) {
String material = m[0].group(1).toUpperCase();
String data = null;
if (m[0].groupCount() > 1) {
data = m[0].group(2);
}
if (aH.matchesInteger(material)) {
stack = new dItem(Integer.valueOf(material));
}
else {
stack = new dItem(Material.valueOf(material));
}
if (data != null) {
stack.setDurability(Short.valueOf(m[0].group(2)));
}
return stack;
}

} catch (Exception e) {
// Just a catch, might be an item script...
}

// Check custom item script
m[0] = getItemPtrn[5].matcher(string);
m[0] = getItemPtrn[2].matcher(string);
if (m[0].matches() && ScriptRegistry.containsScript(m[0].group(1), ItemScriptContainer.class)) {

dB.echoDebug("TEST!");
Expand Down

1 comment on commit 91c18ba

@spaceemotion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most "likely also mistreated innocent baby bunnies"
ehem NO ANIMALS WERE HARMED DURING THE CREATION OF THIS PROJECT

;D

Please sign in to comment.