Files
src
pom.xml
Code
36 4,210
src/main/java/com/recipelimiter/RecipeLimiter.java
package com.recipelimiter;

import com.recipelimiter.command.RecipeLimiterCommand;
import com.recipelimiter.config.ConfigManager;
import com.recipelimiter.config.MessageManager;
import com.recipelimiter.database.Database;
import com.recipelimiter.database.SQLiteDatabase;
import com.recipelimiter.database.YamlDatabase;
import com.recipelimiter.inventory.gui.GUIListener;
import com.recipelimiter.inventory.InventoryGUI;
import com.recipelimiter.inventory.gui.GUIManager;
import com.recipelimiter.listener.CraftListener;
import com.recipelimiter.manager.RuleManager;
import com.recipelimiter.model.CraftRule;
import com.recipelimiter.placeholder.RecipeLimiterExpansion;

import java.util.List;
import lombok.Getter;
import org.bukkit.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;

@Getter
public final class RecipeLimiter extends JavaPlugin {

    private static RecipeLimiter instance;

    private ConfigManager configManager;
    private MessageManager messageManager;
    private GUIManager guiManager;
    private RuleManager ruleManager;
    private Database database;

    @Override
    public void onEnable() {
        instance = this;

        saveDefaultConfig();
        saveResource("messages.yml", false);

        this.configManager = new ConfigManager(this);
        this.messageManager = new MessageManager(this);

        // Initialize managers
        this.ruleManager = new RuleManager(this);

        // Initialize database
        String storageType = getConfig().getString("storage-type", "sqlite");
        if (storageType.equalsIgnoreCase("yaml")) {
            this.database = new YamlDatabase(this);
        } else {
            this.database = new SQLiteDatabase(this);
        }
        this.database.initialize();
        List<CraftRule> loadedRules = this.database.loadRules();
        if (loadedRules != null) {
            loadedRules.forEach(ruleManager::addRule);
        }

        this.guiManager = new GUIManager();
        InventoryGUI.setGuiManager(guiManager);

        // Register listeners
        Bukkit.getPluginManager().registerEvents(new GUIListener(guiManager), this);
        Bukkit.getPluginManager().registerEvents(new CraftListener(this), this);

        // Register command
        RecipeLimiterCommand command = new RecipeLimiterCommand(this);
        Bukkit.getPluginManager().registerEvents(command, this);

        // Register PlaceholderAPI expansion if available
        if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
            new RecipeLimiterExpansion(this).register();
            getLogger().info("PlaceholderAPI expansion registered!");
        }

        printStartupBanner();
    }

    @Override
    public void onDisable() {
        if (database != null) {
            database.saveRules(ruleManager.getRules());
            database.close();
        }
        printShutdownBanner();
        instance = null;
    }

    public static RecipeLimiter getInstance() {
        return instance;
    }

    private void printStartupBanner() {
        String version = getDescription().getVersion();
        getLogger().info("");
        getLogger().info(ChatColor.GOLD + "============================================================");
        getLogger().info(ChatColor.GOLD + "                     " + ChatColor.AQUA + "RecipeLimiter v" + version);
        getLogger().info(ChatColor.GOLD + "============================================================");
        getLogger().info("");
        getLogger().info(ChatColor.GREEN + "Developer      : " + ChatColor.WHITE + "RTX FAHIM");
        getLogger().info(ChatColor.GREEN + "Plugin         : " + ChatColor.WHITE + "RecipeLimiter");
        getLogger().info(ChatColor.GREEN + "Version        : " + ChatColor.WHITE + version);
        getLogger().info(ChatColor.GREEN + "API            : " + ChatColor.WHITE + "Paper 1.21+");
        getLogger().info(ChatColor.GREEN + "Storage        : " + ChatColor.WHITE + "SQLite");
        getLogger().info(ChatColor.GREEN + "INVENTORY GUI            : " + ChatColor.GREEN + "Loaded Successfully");
        getLogger().info(ChatColor.GREEN + "Database       : " + ChatColor.GREEN + "Connected Successfully");
        getLogger().info(ChatColor.GREEN + "Rule System    : " + ChatColor.GREEN + "Loaded Successfully");
        getLogger().info(ChatColor.GREEN + "Status         : " + ChatColor.GREEN + "Plugin Enabled Successfully");
        getLogger().info("");
        getLogger().info(ChatColor.YELLOW + "YouTube Community:");
        getLogger().info(ChatColor.AQUA + "https://youtube.com/@rtx_fahim?si=jrRMa-PdUazd4D4E");
        getLogger().info("");
        getLogger().info(ChatColor.YELLOW + "Discord Community:");
        getLogger().info(ChatColor.AQUA + "https://discord.gg/PsTMr4S43E");
        getLogger().info("");
        getLogger().info(ChatColor.LIGHT_PURPLE + "Thank you for using RecipeLimiter!");
        getLogger().info(ChatColor.LIGHT_PURPLE + "Developed with " + ChatColor.RED + "❤" + ChatColor.LIGHT_PURPLE + " by RTX FAHIM");
        getLogger().info("");
        getLogger().info(ChatColor.GOLD + "============================================================");
    }

    private void printShutdownBanner() {
        getLogger().info("");
        getLogger().info(ChatColor.GOLD + "============================================================");
        getLogger().info(ChatColor.RED + "RecipeLimiter has been disabled successfully.");
        getLogger().info("");
        getLogger().info(ChatColor.GREEN + "Developer:");
        getLogger().info(ChatColor.WHITE + "RTX FAHIM");
        getLogger().info("");
        getLogger().info(ChatColor.GREEN + "YouTube:");
        getLogger().info(ChatColor.AQUA + "https://youtube.com/@rtx_fahim?si=jrRMa-PdUazd4D4E");
        getLogger().info("");
        getLogger().info(ChatColor.GREEN + "Discord:");
        getLogger().info(ChatColor.AQUA + "https://discord.gg/PsTMr4S43E");
        getLogger().info("");
        getLogger().info(ChatColor.LIGHT_PURPLE + "Thank you for using RecipeLimiter.");
        getLogger().info(ChatColor.GOLD + "============================================================");
    }

    public void reload() {
        reloadConfig();
        messageManager.reload();
        ruleManager.getRules().clear();
        List<CraftRule> loadedRules = database.loadRules();
        if (loadedRules != null) {
            loadedRules.forEach(ruleManager::addRule);
        }
    }
}