use of me.dreamerzero.chatregulator.ChatRegulator in project ChatRegulator by 4drian3d.
the class TestsUtils method createRegulator.
public static ChatRegulator createRegulator() {
ProxyServer proxy = createProxy();
Logger logger = LoggerFactory.getLogger(TestsUtils.class);
Path path = Path.of("build", "reports", "tests", "test");
return new ChatRegulator(proxy, logger, path, null) {
@Override
public IFormatter getFormatter() {
return new NormalFormatter();
}
};
}
use of me.dreamerzero.chatregulator.ChatRegulator in project ChatRegulator by 4drian3d.
the class CommandUtils method executeCommand.
/**
* This will check if it is possible to execute the
* configured commands when it detects that the limit
* of a violation has been exceeded.
* @param type the {@link InfractionType}
* @param infractor the {@link InfractionPlayer} involved
* @param plugin the plugin
*/
public static void executeCommand(@NotNull final InfractionType type, @NotNull final InfractionPlayer infractor, @NotNull final ChatRegulator plugin) {
final Player player = Objects.requireNonNull(infractor).getPlayer();
if (player == null) {
return;
}
final CommandsConfig config = ((Executable) type.getConfig().get()).getCommandsConfig();
if (config.executeCommand() && infractor.getViolations().getCount(type) % config.violationsRequired() == 0) {
final String servername = player.getCurrentServer().map(sv -> sv.getServerInfo().getName()).orElse("");
config.getCommandsToExecute().forEach(cmd -> {
final String command = cmd.replace("<player>", infractor.username()).replace("<server>", servername);
plugin.getProxy().getCommandManager().executeAsync(plugin.getProxy().getConsoleCommandSource(), command).handleAsync((status, ex) -> {
if (ex != null) {
plugin.getLogger().warn("Error executing command", ex);
} else if (!status.booleanValue()) {
plugin.getLogger().warn("Error executing command {}", command);
}
return null;
});
});
}
}
Aggregations