package com.github.krzysiek944.mscrole; import com.github.krzysiek944.mscrole.commands.MscroleAdminCommand; import com.github.krzysiek944.mscrole.commands.MscroleCommand; import com.github.krzysiek944.mscrole.listeners.GuiListener; import com.github.krzysiek944.mscrole.listeners.PlayerJoinListener; import com.github.krzysiek944.mscrole.services.CurrencyManager; import com.github.krzysiek944.mscrole.services.ShopManager; import com.github.krzysiek944.mscrole.utils.DataManager; import com.github.krzysiek944.mscrole.utils.ShopDataManager; import com.github.krzysiek944.mscrole.utils.MessageManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.ChatColor; import java.util.logging.Logger; import java.io.File; public class MSCROLE extends JavaPlugin { private static MSCROLE instance; private CurrencyManager currencyManager; private DataManager dataManager; private ShopManager shopManager; private ShopDataManager shopDataManager; private MessageManager messageManager; private Logger logger = Logger.getLogger("Minecraft"); @Override public void onEnable() { instance = this; saveDefaultConfig(); this.dataManager = new DataManager(); this.dataManager.saveDefaultConfig(); this.currencyManager = new CurrencyManager(dataManager); this.shopDataManager = new ShopDataManager(); this.shopDataManager.saveDefaultConfig(); this.shopManager = new ShopManager(shopDataManager); this.messageManager = new MessageManager(this); getServer().getPluginManager().registerEvents(new PlayerJoinListener(this), this); getServer().getPluginManager().registerEvents(new GuiListener(), this); getCommand("mscroll").setExecutor(new MscroleCommand()); getCommand("mscrolladmin").setExecutor(new MscroleAdminCommand()); getLogger().info("Plugin MSCROLE został włączony!"); } @Override public void onDisable() { getLogger().info("Plugin MSCROLE został wyłączony!"); } public String getPrefix() { return ChatColor.translateAlternateColorCodes('&', getConfig().getString("prefix")); } public static MSCROLE getInstance() { return instance; } public CurrencyManager getCurrencyManager() { return currencyManager; } public DataManager getDataManager() { return dataManager; } public ShopManager getShopManager() { return shopManager; } public ShopDataManager getShopDataManager() { return shopDataManager; } public MessageManager getMessageManager() { return messageManager; } public void logToFile(String message) { try { File dataFolder = getDataFolder(); if (!dataFolder.exists()) { dataFolder.mkdir(); } File logFile = new File(getDataFolder(), "logs/currency.log"); if (!logFile.exists()) { logFile.getParentFile().mkdirs(); logFile.createNewFile(); } java.nio.file.Files.write(logFile.toPath(), (new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()) + " " + message + "\n").getBytes(), java.nio.file.StandardOpenOption.APPEND); } catch (java.io.IOException e) { e.printStackTrace(); } } }