Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Resolved Detection of items with brackets in name fails

Author of MaxiBots
Joined
Dec 3, 2013
Messages
6,774
Inventory.newQuery().names("Guam potion (unf)").results().first() returns null
Inventory.newQuery().names("Guam potion \\(unf\\)").results().first() finds the correct item

@Cloud
 
Joined
Dec 10, 2014
Messages
3,255
Seems like the names(String...) is converting the Strings to Patterns but doesn't escape the brackets :/

Edit: Which means this might be occurring in the other queries as well
 
Engineer
Joined
Jul 28, 2013
Messages
2,776
For the next release, does this check out to you?
Code:
public static Pattern getPatternForExactString(final String string) {
String pattern = "^";
for (char c : string.toCharArray()) {
if (c == '(' || c == ')' || c == '^' || c == '$'|| c == '.' || c == '*' || c == '?' || c == '|'|| c == '[' || c == '{') {
pattern += "\\";
}
pattern += c;
}
pattern += "$";
return Pattern.compile(pattern);
}
 
Joined
Dec 10, 2014
Messages
3,255
For the next release, does this check out to you?
Code:
public static Pattern getPatternForExactString(final String string) {
String pattern = "^";
for (char c : string.toCharArray()) {
if (c == '(' || c == ')' || c == '^' || c == '$'|| c == '.' || c == '*' || c == '?' || c == '|'|| c == '[' || c == '{') {
pattern += "\\";
}
pattern += c;
}
pattern += "$";
return Pattern.compile(pattern);
}
What about the closing braces and brackets?
 
Discretion is advised
Joined
Jan 2, 2014
Messages
306
You could use IDs instead of names anyway since SpriteItem IDs dont change
 
Top