Add multiple triggers per stack
This commit is contained in:
1 parent
cca27ebc8c
commit
53b1949bd8
1 file changed
+17
-8
@@ -13,28 +13,37 @@ public class Responses {
|
||||
public static void update() {
|
||||
RESPONSES = new ArrayList<>();
|
||||
|
||||
ArrayList<String> MESSAGE = (ArrayList<String>) List.of("&8[&4ProAntiTab&8] &cThis argument is not allowed!");
|
||||
ArrayList<String> MESSAGE = new ArrayList<>(List.of("&8[&4ProAntiTab&8] &cThis argument is not allowed!"));
|
||||
DEFAULT_MESSAGE = (List<String>) SubArgsAddon.getConfiguration().getOrSet("default-message", MESSAGE);
|
||||
|
||||
SubArgsAddon.getConfiguration().getKeys(true).stream().filter(key -> !key.equals("default-message")).forEach(key -> {
|
||||
Response response = new Response(key);
|
||||
RESPONSES.add(response);
|
||||
if(!key.contains(".")) {
|
||||
Response response = new Response(key);
|
||||
RESPONSES.add(response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static List<String> getResponse(String input) {
|
||||
final Optional<Response> optionalResponse = RESPONSES.stream().filter(response -> response.trigger.endsWith(" *") ? input.startsWith(StringUtils.replace(response.trigger, " *", "")) : input.equals(response.trigger)).findFirst();
|
||||
final String finalInput = input.startsWith("/") ? StringUtils.replaceFirst(input, "/", "") : input;
|
||||
|
||||
final Optional<Response> optionalResponse = RESPONSES.stream().filter(response -> {
|
||||
for (String trigger : response.triggers)
|
||||
if(trigger.endsWith("*") ? finalInput.startsWith(StringUtils.replace(trigger, "*", "")) : finalInput.equals(trigger))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}).findFirst();
|
||||
return optionalResponse.isPresent() ? optionalResponse.get().message : DEFAULT_MESSAGE;
|
||||
}
|
||||
|
||||
private static class Response {
|
||||
|
||||
private final String trigger;
|
||||
private final List<String> message;
|
||||
private final List<String> triggers, message;
|
||||
|
||||
public Response(final String key) {
|
||||
this.trigger = (String) SubArgsAddon.getConfiguration().get(key + ".trigger");
|
||||
this.message = (List<String>) SubArgsAddon.getConfiguration().getOrSet(key + ".response", SubArgsAddon.BLOCKED_MESSAGE);
|
||||
this.triggers = (List<String>) SubArgsAddon.getConfiguration().get(key + ".triggers");
|
||||
this.message = (List<String>) SubArgsAddon.getConfiguration().getOrSet(key + ".message", SubArgsAddon.BLOCKED_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user