use of io.github.darkkronicle.advancedchatbox.chat.AdvancedSuggestions in project AdvancedChatBox by DarkKronicle.
the class ShortcutSuggestor method suggest.
@Override
public Optional<List<AdvancedSuggestions>> suggest(String string) {
if (!string.contains(":")) {
return Optional.empty();
}
ArrayList<AdvancedSuggestions> suggest = new ArrayList<>();
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
if (c != ':') {
continue;
}
int start = i;
int end;
while (true) {
i++;
if (i >= string.length()) {
end = i;
break;
}
char n = string.charAt(i);
if (n == ' ') {
end = i;
break;
} else if (n == ':') {
i--;
end = i + 1;
break;
}
}
if (end - start < 1) {
break;
}
StringRange range = new StringRange(start, end);
suggest.add(new AdvancedSuggestions(range, getSuggestions(string.substring(start + 1, end), range)));
}
return Optional.of(suggest);
}
use of io.github.darkkronicle.advancedchatbox.chat.AdvancedSuggestions in project AdvancedChatBox by DarkKronicle.
the class CalculatorSuggestor method suggest.
@Override
public Optional<List<AdvancedSuggestions>> suggest(String text) {
if (!text.contains("[") || !text.contains("]")) {
return Optional.empty();
}
List<StringMatch> matches = SearchUtils.findMatches(text, BRACKET_REGEX, FindType.REGEX).orElse(null);
if (matches == null) {
return Optional.empty();
}
int last = -1;
ArrayList<AdvancedSuggestions> suggest = new ArrayList<>();
for (StringMatch m : matches) {
if (m.start < last || m.end - m.start < 1) {
// Don't want overlapping matches (just in case) or too small
continue;
}
last = m.end;
String string = m.match.substring(1, m.match.length() - 1);
Expression expression = new Expression(string);
double val = expression.calculate();
String message = NAN;
if (!Double.isNaN(val)) {
message = String.valueOf(val);
}
StringRange range = new StringRange(m.start, m.end);
suggest.add(new AdvancedSuggestions(range, new ArrayList<>(Collections.singleton(new AdvancedSuggestion(range, message)))));
}
if (suggest.isEmpty()) {
return Optional.empty();
}
return Optional.of(suggest);
}
use of io.github.darkkronicle.advancedchatbox.chat.AdvancedSuggestions in project AdvancedChatBox by DarkKronicle.
the class SpellCheckSuggestor method suggest.
@Override
public Optional<List<AdvancedSuggestions>> suggest(String text) {
ArrayList<AdvancedSuggestions> suggestions = new ArrayList<>();
try {
List<RuleMatch> matches = lt.check(text);
for (RuleMatch match : matches) {
int fromPos = match.getFromPos();
int toPos = match.getToPos();
StringRange range = new StringRange(fromPos, toPos);
suggestions.add(new AdvancedSuggestions(range, convertSuggestions(match, range)));
}
} catch (Exception e) {
e.printStackTrace();
return Optional.empty();
}
return Optional.of(suggestions);
}
Aggregations