chore: unify checkstyle, fix violations, cleanup bin/
This commit is contained in:
parent
9c5e5bccae
commit
da9271b283
17 changed files with 363 additions and 67 deletions
|
|
@ -68,15 +68,50 @@ public final class FoxAuth {
|
|||
|
||||
try {
|
||||
discordBot = new Bot(new BotConfig() {
|
||||
@Override public String getDbType() { return cfg.getDbType(); }
|
||||
@Override public String getToken() { return token; }
|
||||
@Override public String getDbHost() { return cfg.getDbHost(); }
|
||||
@Override public int getDbPort() { return cfg.getDbPort(); }
|
||||
@Override public String getDbName() { return cfg.getDbName(); }
|
||||
@Override public String getDbUser() { return cfg.getDbUser(); }
|
||||
@Override public String getDbPassword() { return cfg.getDbPassword(); }
|
||||
@Override public int getAuthTimeoutSeconds() { return cfg.getAuthTimeoutSeconds(); }
|
||||
@Override public int getVerificationCodeLength() { return cfg.getVerificationCodeLength(); }
|
||||
@Override
|
||||
public String getDbType() {
|
||||
return cfg.getDbType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbHost() {
|
||||
return cfg.getDbHost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDbPort() {
|
||||
return cfg.getDbPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbName() {
|
||||
return cfg.getDbName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbUser() {
|
||||
return cfg.getDbUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbPassword() {
|
||||
return cfg.getDbPassword();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAuthTimeoutSeconds() {
|
||||
return cfg.getAuthTimeoutSeconds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVerificationCodeLength() {
|
||||
return cfg.getVerificationCodeLength();
|
||||
}
|
||||
});
|
||||
log.info("Discord bot started in embedded mode.");
|
||||
} catch (Exception e) {
|
||||
|
|
@ -86,8 +121,12 @@ public final class FoxAuth {
|
|||
|
||||
@Subscribe
|
||||
public void onShutdown(final ProxyShutdownEvent event) {
|
||||
if (discordBot != null) discordBot.shutdown();
|
||||
if (db != null) db.close();
|
||||
if (discordBot != null) {
|
||||
discordBot.shutdown();
|
||||
}
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
private Path getOrCreateConfig(final String fileName) throws IOException {
|
||||
|
|
@ -95,7 +134,9 @@ public final class FoxAuth {
|
|||
Path target = dataDir.resolve(fileName);
|
||||
if (Files.notExists(target)) {
|
||||
try (InputStream in = getClass().getResourceAsStream("/" + fileName)) {
|
||||
if (in == null) throw new IOException("Resource not found: " + fileName);
|
||||
if (in == null) {
|
||||
throw new IOException("Resource not found: " + fileName);
|
||||
}
|
||||
Files.copy(in, target);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,13 +23,33 @@ public final class MessageConfig {
|
|||
this.raw = raw;
|
||||
}
|
||||
|
||||
public Component header() { return text("first_login.header"); }
|
||||
public Component returningHeader() { return text("returning_login.header"); }
|
||||
public Component returningBody() { return text("returning_login.body"); }
|
||||
public Component returningTimeout() { return text("returning_login.timeout"); }
|
||||
public Component expiredHeader() { return text("expired.header"); }
|
||||
public Component expiredBody() { return text("expired.body"); }
|
||||
public Component success() { return text("success"); }
|
||||
public Component header() {
|
||||
return text("first_login.header");
|
||||
}
|
||||
|
||||
public Component returningHeader() {
|
||||
return text("returning_login.header");
|
||||
}
|
||||
|
||||
public Component returningBody() {
|
||||
return text("returning_login.body");
|
||||
}
|
||||
|
||||
public Component returningTimeout() {
|
||||
return text("returning_login.timeout");
|
||||
}
|
||||
|
||||
public Component expiredHeader() {
|
||||
return text("expired.header");
|
||||
}
|
||||
|
||||
public Component expiredBody() {
|
||||
return text("expired.body");
|
||||
}
|
||||
|
||||
public Component success() {
|
||||
return text("success");
|
||||
}
|
||||
|
||||
public Component code(final String code) {
|
||||
return parse("first_login.code", Map.of("code", code))
|
||||
|
|
@ -60,7 +80,9 @@ public final class MessageConfig {
|
|||
|
||||
private Component text(final String path, final Map<String, String> placeholders) {
|
||||
String rawStr = resolveRaw(path);
|
||||
if (rawStr == null) return Component.text('[' + path + ']');
|
||||
if (rawStr == null) {
|
||||
return Component.text('[' + path + ']');
|
||||
}
|
||||
return parse(rawStr, placeholders);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,18 +15,57 @@ public final class PluginCfg implements DbConfig {
|
|||
cfg = new YamlConfig(configPath);
|
||||
}
|
||||
|
||||
public String getMode() { return cfg.getRequired("mode", String.class); }
|
||||
public String getToken() { return cfg.get("token", ""); }
|
||||
public String getDiscordLink() { return cfg.get("discord_link", "discord.gg/ЗАМЕНИ_НА_СВОЙ"); }
|
||||
public String getMode() {
|
||||
return cfg.getRequired("mode", String.class);
|
||||
}
|
||||
|
||||
@Override public String getDbType() { return cfg.getRequired("db_type", String.class); }
|
||||
@Override public String getDbHost() { return cfg.getRequired("db_host", String.class); }
|
||||
@Override public int getDbPort() { return cfg.getRequired("db_port", Integer.class); }
|
||||
@Override public String getDbName() { return cfg.getRequired("db_name", String.class); }
|
||||
@Override public String getDbUser() { return cfg.getRequired("db_user", String.class); }
|
||||
@Override public String getDbPassword() { return cfg.getRequired("db_password", String.class); }
|
||||
@Override public int getAuthTimeoutSeconds() { return cfg.getRequired("auth_timeout_seconds", Integer.class); }
|
||||
@Override public int getVerificationCodeLength(){ return cfg.getRequired("verification_code_length",Integer.class); }
|
||||
public String getToken() {
|
||||
return cfg.get("token", "");
|
||||
}
|
||||
|
||||
public String getDiscordLink() {
|
||||
return cfg.get("discord_link", "discord.gg/ЗАМЕНИ_НА_СВОЙ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbType() {
|
||||
return cfg.getRequired("db_type", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbHost() {
|
||||
return cfg.getRequired("db_host", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDbPort() {
|
||||
return cfg.getRequired("db_port", Integer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbName() {
|
||||
return cfg.getRequired("db_name", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbUser() {
|
||||
return cfg.getRequired("db_user", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbPassword() {
|
||||
return cfg.getRequired("db_password", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAuthTimeoutSeconds() {
|
||||
return cfg.getRequired("auth_timeout_seconds", Integer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVerificationCodeLength() {
|
||||
return cfg.getRequired("verification_code_length", Integer.class);
|
||||
}
|
||||
|
||||
public MessageConfig getMessages() {
|
||||
Object msgs = cfg.get("messages", null);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,11 @@ import org.slf4j.Logger;
|
|||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class LoginListener {
|
||||
|
||||
|
|
@ -129,6 +133,8 @@ public final class LoginListener {
|
|||
|
||||
private void cancelKick(final String nick) {
|
||||
ScheduledFuture<?> f = pendingKicks.remove(nick);
|
||||
if (f != null) f.cancel(false);
|
||||
if (f != null) {
|
||||
f.cancel(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue