use of com.velocitypowered.api.plugin.Plugin in project AntiVPN by funkemunky.
the class VelocityPlugin method onInit.
@Subscribe
public void onInit(ProxyInitializeEvent event) {
INSTANCE = this;
logger.info("Loading config...");
config = new Config();
// Loading plugin
logger.info("Starting AntiVPN services...");
AntiVPN.start(new VelocityConfig(), new VelocityListener(), new VelocityPlayerExecutor(), configDir.toFile());
if (AntiVPN.getInstance().getConfig().metrics()) {
logger.info("Starting metrics...");
Metrics metrics = metricsFactory.make(this, 12791);
}
logger.info("Registering commands...");
for (Command command : AntiVPN.getInstance().getCommands()) {
server.getCommandManager().register(server.getCommandManager().metaBuilder(command.name()).aliases(command.aliases()).build(), (SimpleCommand) invocation -> {
CommandSource sender = invocation.source();
if (!invocation.source().hasPermission("antivpn.command.*") && !invocation.source().hasPermission(command.permission())) {
invocation.source().sendMessage(Component.text("No permission").toBuilder().color(TextColor.color(255, 0, 0)).build());
return;
}
val children = command.children();
String[] args = invocation.arguments();
if (children.length > 0 && args.length > 0) {
for (Command child : children) {
if (child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases()).anyMatch(alias -> alias.equalsIgnoreCase(args[0]))) {
if (!sender.hasPermission("antivpn.command.*") && !sender.hasPermission(child.permission())) {
invocation.source().sendMessage(Component.text("No permission").toBuilder().color(TextColor.color(255, 0, 0)).build());
return;
}
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build().deserialize(child.execute(new VelocityCommandExecutor(sender), IntStream.range(0, args.length - 1).mapToObj(i -> args[i + 1]).toArray(String[]::new))));
return;
}
}
}
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build().deserialize(command.execute(new VelocityCommandExecutor(sender), args)));
});
}
}
use of com.velocitypowered.api.plugin.Plugin in project LimboAuth by Elytrium.
the class LimboAuth method reload.
@SuppressWarnings("SwitchStatementWithTooFewBranches")
public void reload() throws Exception {
Settings.IMP.reload(new File(this.dataDirectory.toFile().getAbsoluteFile(), "config.yml"));
if (this.floodgateApi == null && !Settings.IMP.MAIN.FLOODGATE_NEED_AUTH) {
throw new IllegalStateException("If you don't need to auth floodgate players please install floodgate plugin.");
}
if (Settings.IMP.MAIN.CHECK_PASSWORD_STRENGTH) {
this.unsafePasswords.clear();
Path unsafePasswordsPath = Paths.get(this.dataDirectory.toFile().getAbsolutePath(), Settings.IMP.MAIN.UNSAFE_PASSWORDS_FILE);
if (!unsafePasswordsPath.toFile().exists()) {
Files.copy(Objects.requireNonNull(this.getClass().getResourceAsStream("/unsafe_passwords.txt")), unsafePasswordsPath);
}
this.unsafePasswords.addAll(Files.lines(unsafePasswordsPath).collect(Collectors.toSet()));
}
this.cachedAuthChecks.clear();
Settings.DATABASE dbConfig = Settings.IMP.DATABASE;
// requireNonNull prevents the shade plugin from excluding the drivers in minimized jar.
switch(dbConfig.STORAGE_TYPE.toLowerCase(Locale.ROOT)) {
case "h2":
{
Objects.requireNonNull(org.h2.Driver.class);
Objects.requireNonNull(org.h2.engine.Engine.class);
this.connectionSource = new JdbcPooledConnectionSource("jdbc:h2:" + this.dataDirectory.toFile().getAbsoluteFile() + "/limboauth");
break;
}
case "mysql":
{
Objects.requireNonNull(com.mysql.cj.jdbc.Driver.class);
Objects.requireNonNull(com.mysql.cj.conf.url.SingleConnectionUrl.class);
this.connectionSource = new JdbcPooledConnectionSource("jdbc:mysql://" + dbConfig.HOSTNAME + "/" + dbConfig.DATABASE + dbConfig.CONNECTION_PARAMETERS, dbConfig.USER, dbConfig.PASSWORD);
break;
}
case "postgresql":
{
Objects.requireNonNull(org.postgresql.Driver.class);
this.connectionSource = new JdbcPooledConnectionSource("jdbc:postgresql://" + dbConfig.HOSTNAME + "/" + dbConfig.DATABASE + dbConfig.CONNECTION_PARAMETERS, dbConfig.USER, dbConfig.PASSWORD);
break;
}
default:
{
this.getLogger().error("WRONG DATABASE TYPE.");
this.server.shutdown();
return;
}
}
TableUtils.createTableIfNotExists(this.connectionSource, RegisteredPlayer.class);
this.playerDao = DaoManager.createDao(this.connectionSource, RegisteredPlayer.class);
this.nicknameValidationPattern = Pattern.compile(Settings.IMP.MAIN.ALLOWED_NICKNAME_REGEX);
this.migrateDb(this.playerDao);
CommandManager manager = this.server.getCommandManager();
manager.unregister("unregister");
manager.unregister("premium");
manager.unregister("forceunregister");
manager.unregister("changepassword");
manager.unregister("forcechangepassword");
manager.unregister("destroysession");
manager.unregister("2fa");
manager.unregister("limboauth");
manager.register("unregister", new UnregisterCommand(this, this.playerDao), "unreg");
manager.register("premium", new PremiumCommand(this, this.playerDao));
manager.register("forceunregister", new ForceUnregisterCommand(this, this.server, this.playerDao), "forceunreg");
manager.register("changepassword", new ChangePasswordCommand(this.playerDao), "changepass");
manager.register("forcechangepassword", new ForceChangePasswordCommand(this.server, this.playerDao), "forcechangepass");
manager.register("destroysession", new DestroySessionCommand(this));
if (Settings.IMP.MAIN.ENABLE_TOTP) {
manager.register("2fa", new TotpCommand(this.playerDao), "totp");
}
manager.register("limboauth", new LimboAuthCommand(this), "la", "auth", "lauth");
Settings.MAIN.AUTH_COORDS authCoords = Settings.IMP.MAIN.AUTH_COORDS;
VirtualWorld authWorld = this.factory.createVirtualWorld(Dimension.valueOf(Settings.IMP.MAIN.DIMENSION), authCoords.X, authCoords.Y, authCoords.Z, (float) authCoords.YAW, (float) authCoords.PITCH);
if (Settings.IMP.MAIN.LOAD_WORLD) {
try {
Path path = this.dataDirectory.resolve(Settings.IMP.MAIN.WORLD_FILE_PATH);
WorldFile file;
switch(Settings.IMP.MAIN.WORLD_FILE_TYPE) {
case "schematic":
{
file = new SchematicFile(path);
break;
}
default:
{
this.getLogger().error("Incorrect world file type.");
this.server.shutdown();
return;
}
}
Settings.MAIN.WORLD_COORDS coords = Settings.IMP.MAIN.WORLD_COORDS;
file.toWorld(this.factory, authWorld, coords.X, coords.Y, coords.Z);
} catch (IOException e) {
e.printStackTrace();
}
}
this.authServer = this.factory.createLimbo(authWorld).setName("LimboAuth").registerCommand(new AuthCommandMeta(this, this.filterCommands(Settings.IMP.MAIN.REGISTER_COMMAND)), new AuthCommand()).registerCommand(new AuthCommandMeta(this, this.filterCommands(Settings.IMP.MAIN.LOGIN_COMMAND)), new AuthCommand()).registerCommand(new AuthCommandMeta(this, this.filterCommands(Settings.IMP.MAIN.TOTP_COMMAND)), new AuthCommand());
this.server.getEventManager().unregisterListeners(this);
this.server.getEventManager().register(this, new AuthListener(this, this.playerDao, this.floodgateApi));
Executors.newScheduledThreadPool(1, task -> new Thread(task, "purge-cache")).scheduleAtFixedRate(() -> this.checkCache(this.cachedAuthChecks, Settings.IMP.MAIN.PURGE_CACHE_MILLIS), Settings.IMP.MAIN.PURGE_CACHE_MILLIS, Settings.IMP.MAIN.PURGE_CACHE_MILLIS, TimeUnit.MILLISECONDS);
this.server.getEventManager().fireAndForget(new AuthPluginReloadEvent());
}
Aggregations