package wtf.beatrice.nounspicker; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import wtf.beatrice.nounspicker.commands.NounsCommand; import wtf.beatrice.nounspicker.objects.PAPIManager; import wtf.beatrice.nounspicker.utils.ConsoleLogger; import wtf.beatrice.nounspicker.utils.DatabaseManager; import wtf.beatrice.nounspicker.utils.FileManager; import java.io.File; public class NounsPicker extends JavaPlugin { private static NounsPicker instance; private PluginManager pluginManager; private final ConsoleLogger logger = new ConsoleLogger(getClass()); @Override public void onEnable() { logger.log("Loading plugin!"); pluginManager = getServer().getPluginManager(); instance = this; // register PlaceholderAPI if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { new PAPIManager(this).register(); logger.log("PlaceholderAPI integration loaded!"); } else { logger.err("Missing PlaceholderAPI! The plugin cannot continue."); disable(); return; } logger.log("Registering commands..."); getCommand("nouns").setExecutor(new NounsCommand(this)); logger.log("Commands registered!"); logger.log("Checking files..."); FileManager fileManager = new FileManager(this); if (!fileManager.routineCheck()) { logger.err("Error during routine file check! The plugin will halt."); disable(); return; } logger.log("Files checked!"); logger.log("Connecting to database..."); String dbFilePath = getDataFolder().getAbsolutePath() + File.separator + "db.sqlite"; DatabaseManager dbManager = new DatabaseManager(dbFilePath); if(dbManager.initialize()) { logger.log("Database connection initialized!"); } else { logger.err("Error initializing database connection!"); } logger.log("Plugin loaded!"); } public static NounsPicker getInstance() { return instance; } private void disable() { pluginManager.disablePlugin(this); } }