use of io.github.darkkronicle.advancedchatbox.chat.AdvancedSuggestion in project AdvancedChatBox by DarkKronicle.
the class PlayerSuggestor method suggestCurrentWord.
@Override
public Optional<List<AdvancedSuggestion>> suggestCurrentWord(String text, StringRange range) {
List<AdvancedSuggestion> newSuggestions = new ArrayList<>();
Collection<String> names = getPlayerNames();
for (String name : names) {
if (text.equals("") || name.toLowerCase().startsWith(text.toLowerCase())) {
newSuggestions.add(new AdvancedSuggestion(range, name));
}
}
return Optional.of(newSuggestions);
}
use of io.github.darkkronicle.advancedchatbox.chat.AdvancedSuggestion 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.AdvancedSuggestion in project AdvancedChatBox by DarkKronicle.
the class ShortcutSuggestor method getSuggestions.
private List<AdvancedSuggestion> getSuggestions(String current, StringRange range) {
ArrayList<AdvancedSuggestion> suggestions = new ArrayList<>();
for (Shortcut shortcut : shortcuts) {
if (current.length() == 0 || shortcut.name.toLowerCase().startsWith(current.toLowerCase())) {
FluidText text = new FluidText();
text.append(new RawText(shortcut.name, Style.EMPTY));
suggestions.add(new AdvancedSuggestion(range, shortcut.replace, text, new RawText(shortcut.replace, Style.EMPTY)));
}
}
return suggestions;
}
Aggregations