Files
src
manifest.kod
pom.xml
Code
18 1,297
src/main/java/com/kodari/secureauth/SecureAuth.java
package com.kodari.secureauth;
import com.kodari.secureauth.auth.AuthManager;
import com.kodari.secureauth.auth.AuthService;
import com.kodari.secureauth.auth.PasswordPolicy;
import com.kodari.secureauth.command.AuthAdminCommand;
import com.kodari.secureauth.command.ChangePasswordCommand;
import com.kodari.secureauth.command.LoginCommand;
import com.kodari.secureauth.command.LogoutCommand;
import com.kodari.secureauth.command.RegisterCommand;
import com.kodari.secureauth.listener.AuthListener;
import com.kodari.secureauth.storage.AuthDatabase;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
public final class SecureAuth extends JavaPlugin {
private AuthService authService;
private AuthManager authManager;
private PasswordPolicy passwordPolicy;
@Override
public void onEnable() {
saveDefaultConfig();
try {
AuthDatabase database = new AuthDatabase(this);
database.initialize();
authService = new AuthService(database);
} catch (IOException | java.sql.SQLException exception) {
getLogger().log(Level.SEVERE, "Could not initialize the authentication database.", exception);
Bukkit.getPluginManager().disablePlugin(this);
return;
}
authManager = new AuthManager(this);
passwordPolicy = new PasswordPolicy(this);
Bukkit.getPluginManager().registerEvents(new AuthListener(this), this);
registerCommands();
}
@Override
public void onDisable() {
if (authService != null) {
try {
authService.shutdown();
} catch (InterruptedException exception) {
Thread.currentThread().interrupt();
getLogger().log(Level.WARNING, "Interrupted while closing the authentication database.", exception);
}
}
}
private void registerCommands() {
setExecutor("register", new RegisterCommand(this));
setExecutor("login", new LoginCommand(this));
setExecutor("changepassword", new ChangePasswordCommand(this));
setExecutor("logout", new LogoutCommand(this));
setExecutor("auth", new AuthAdminCommand(this));
}
private void setExecutor(String commandName, org.bukkit.command.CommandExecutor executor) {
PluginCommand command = getCommand(commandName);
if (command != null) {
command.setExecutor(executor);
}
}
public AuthService getAuthService() {
return authService;
}
public AuthManager getAuthManager() {
return authManager;
}
public PasswordPolicy getPasswordPolicy() {
return passwordPolicy;
}
public void logDatabaseError(Throwable exception) {
getLogger().log(Level.SEVERE, "An authentication database operation failed.", exception);
}
}