Files
src
BEDROCK_SETUP.md
manifest.kod
pom.xml
Code
11 1,600
src/main/java/com/kksauthme/KKSAuthMe.java
package com.kksauthme;
import com.kksauthme.command.AuthCommands;
import com.kksauthme.database.AuthDatabase;
import com.kksauthme.listener.AuthListener;
import com.kksauthme.security.AuthManager;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Objects;
public final class KKSAuthMe extends JavaPlugin {
private AuthDatabase database;
private AuthManager authManager;
@Override
public void onEnable() {
saveDefaultConfig();
if (!validateSecurityMode()) {
Bukkit.getPluginManager().disablePlugin(this);
return;
}
if (getConfig().getBoolean("bedrock.enabled", true)
&& getConfig().getBoolean("bedrock.floodgate-integration", true)
&& !Bukkit.getPluginManager().isPluginEnabled("floodgate")) {
getLogger().warning("Bedrock Floodgate integration is enabled, but Floodgate is not installed or enabled. Bedrock players will not be detected; install Geyser and Floodgate as described in BEDROCK_SETUP.md.");
}
if (getConfig().getBoolean("debug.log-passwords", false) || getConfig().getBoolean("debug.log-ips", false)) {
getLogger().warning("Password/IP logging is not supported and will never be enabled.");
}
if (getConfig().getBoolean("cracked-accounts.enabled", false) && getServer().getOnlineMode()) {
getLogger().warning("Cracked-account authentication is unavailable while online-mode=true; Mojang authentication remains mandatory.");
}
database = new AuthDatabase(this);
authManager = new AuthManager(this, database);
AuthCommands commands = new AuthCommands(this, authManager, database);
Objects.requireNonNull(getCommand("register")).setExecutor(commands);
Objects.requireNonNull(getCommand("login")).setExecutor(commands);
Objects.requireNonNull(getCommand("unregister")).setExecutor(commands);
Objects.requireNonNull(getCommand("kksauthme")).setExecutor(commands);
Bukkit.getPluginManager().registerEvents(new AuthListener(this, authManager), this);
database.ready().whenComplete((ignored, error) -> {
if (error != null) {
getLogger().severe("The authentication database could not be initialized. Check the configured database and restart.");
Bukkit.getScheduler().runTask(this, () -> Bukkit.getPluginManager().disablePlugin(this));
}
});
debug("Plugin enabled; authentication mode=" + (getServer().getOnlineMode() ? "online" : "offline"));
}
@Override
public void onDisable() {
if (authManager != null) {
authManager.shutdown();
}
if (database != null) {
database.close();
}
}
public boolean validateSecurityMode() {
boolean onlineMode = getServer().getOnlineMode();
boolean premiumProtection = getConfig().getBoolean("premium.enabled", true);
boolean requireOnlineMode = getConfig().getBoolean("premium.require-online-mode", true);
boolean crackedEnabled = getConfig().getBoolean("cracked-accounts.enabled", false);
if (premiumProtection && (!requireOnlineMode || !onlineMode)) {
getLogger().severe("Premium protection requires premium.require-online-mode=true and Paper online-mode=true. Refusing to start in offline mode.");
getLogger().severe("A username or offline UUID cannot prove Premium ownership. Do not expose an offline-mode backend as a substitute for verified authentication.");
return false;
}
if (!onlineMode && !crackedEnabled) {
getLogger().severe("This server is in offline mode but cracked-account authentication is disabled. Refusing to start without verified authentication.");
return false;
}
return true;
}
public AuthManager getAuthManager() {
return authManager;
}
public void debug(String message) {
if (getConfig().getBoolean("debug.enabled", false)) {
getLogger().info("[debug] " + message);
}
}
}