Files
src
build.gradle
manifest.kod
settings.gradle
Code
27 2,108
src/main/java/com/ndgaming/ndlogin/NDLoginPlugin.java
package com.ndgaming.ndlogin;
import com.ndgaming.ndlogin.api.NDLoginAPI;
import com.ndgaming.ndlogin.auth.AuthenticationManager;
import com.ndgaming.ndlogin.command.AuthCommand;
import com.ndgaming.ndlogin.command.NDLoginCommand;
import com.ndgaming.ndlogin.config.PluginConfig;
import com.ndgaming.ndlogin.database.DatabaseManager;
import com.ndgaming.ndlogin.listener.AuthListener;
import com.ndgaming.ndlogin.service.FloodgateService;
import com.ndgaming.ndlogin.service.MessageService;
import com.ndgaming.ndlogin.service.SoundService;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public final class NDLoginPlugin extends JavaPlugin {
private PluginConfig pluginConfig;
private MessageService messageService;
private SoundService soundService;
private DatabaseManager databaseManager;
private AuthenticationManager authenticationManager;
private NDLoginAPI api;
@Override
public void onEnable() {
saveDefaultConfig();
saveResource("settings.yml", false);
saveResource("messages.yml", false);
saveResource("sounds.yml", false);
saveResource("database.yml", false);
this.pluginConfig = new PluginConfig(this);
this.messageService = new MessageService(this);
this.soundService = new SoundService(this);
this.databaseManager = new DatabaseManager(this, pluginConfig);
this.authenticationManager = new AuthenticationManager(
this,
pluginConfig,
messageService,
soundService,
databaseManager,
new FloodgateService()
);
this.api = new NDLoginAPI(authenticationManager);
Bukkit.getPluginManager().registerEvents(new AuthListener(authenticationManager, pluginConfig), this);
getCommand("register").setExecutor(new AuthCommand(authenticationManager, false));
getCommand("login").setExecutor(new AuthCommand(authenticationManager, true));
getCommand("ndlogin").setExecutor(new NDLoginCommand(this, authenticationManager));
databaseManager.initialize().whenComplete((ignored, throwable) -> {
if (throwable != null) {
getLogger().severe("Database initialization failed: " + throwable.getMessage());
} else {
getLogger().info("Database initialized.");
}
});
Bukkit.getScheduler().runTaskTimer(this, authenticationManager::tick, 20L, 20L);
getLogger().info("NDLogin Premium enabled.");
}
@Override
public void onDisable() {
if (authenticationManager != null) {
authenticationManager.shutdown();
}
if (databaseManager != null) {
databaseManager.close();
}
if (messageService != null) {
messageService.close();
}
}
public void reloadPlugin() {
reloadConfig();
pluginConfig.reload();
messageService.reload();
soundService.reload();
}
public PluginConfig getPluginConfig() {
return pluginConfig;
}
public MessageService getMessageService() {
return messageService;
}
public AuthenticationManager getAuthenticationManager() {
return authenticationManager;
}
public NDLoginAPI getApi() {
return api;
}
}