use of org.spongepowered.api.text.selector.Argument in project SpongeCommon by SpongePowered.
the class SpongeSelectorFactory method parseRawSelector.
@Override
public Selector parseRawSelector(String selector) {
checkArgument(selector.startsWith("@"), "Invalid selector %s", selector);
// If multi-character types are possible, this handles it
int argListIndex = selector.indexOf('[');
if (argListIndex < 0) {
argListIndex = selector.length();
} else {
int end = selector.indexOf(']');
checkArgument(end > argListIndex && selector.charAt(end - 1) != ',', "Invalid selector %s", selector);
}
String typeStr = selector.substring(1, argListIndex);
checkArgument(idToType.containsKey(typeStr), "No type known as '%s'", typeStr);
SelectorType type = idToType.get(typeStr);
try {
Map<String, String> rawMap;
if (argListIndex == selector.length()) {
rawMap = ImmutableMap.of();
} else {
rawMap = EntitySelector.getArgumentMap(selector.substring(argListIndex + 1, selector.length() - 1));
}
Map<ArgumentType<?>, Argument<?>> arguments = parseArguments(rawMap);
return new SpongeSelector(type, ImmutableMap.copyOf(arguments));
} catch (Exception e) {
throw new IllegalArgumentException("Invalid selector " + selector, e);
}
}
Aggregations