@Mod( name = Market.MODNAME, modid = Market.MODID, version = Market.MODVERSION, acceptableRemoteVersions = "*") public class Market { public static final String MODNAME = "MinecraftMarket"; public static final String MODID = "minecraftmarket"; public static final String MODVERSION = "1.0"; @Getter @Setter private Long interval; @Getter @Setter private String shopCommand; @Getter @Setter private boolean isBoardEnabled; @Getter @Setter private boolean isSignEnabled; @Getter @Setter private boolean isGuiEnabled; @Getter @Setter private static Market plugin; @Getter @Setter private CommandTask commandTask; @Getter @Setter private SignUpdate signUpdate; @Getter @Setter private String color; @Getter private Logger logger = LogManager.getLogger("Minecraft Market"); @Getter private File dataFolder = new File("./config/MinecraftMarket/"); @Getter private YAMLConfigurationLoader config = YAMLConfigurationLoader.builder().setFile(new File(dataFolder, "config.yml")).build(); @Mod.EventHandler public void onDisable(FMLServerStoppingEvent event) { stopTasks(); } @Mod.EventHandler public void onEnable(FMLServerStartingEvent event) { plugin = this; try { saveDefaultSettings(); registerEvents(); reload(); startTasks(); registerCommands(event); } catch (Exception e) { Log.log(e); } } public void reload() { try { Settings.get().reloadConfig(); Settings.get().reloadLanguageConfig(); loadConfigOptions(); if (authApi()) { startGUI(); startSignTasks(); } } catch (Exception e) { Log.log(e); } } private void loadConfigOptions() throws IOException { Chat.get().SetupDefaultLanguage(); ConfigurationNode config = this.getConfig().load(); Api.setApi(ConfigHelper.getString(config, "ApiKey", "Apikey here")); this.interval = Math.max(ConfigHelper.getLong(config, "Interval", 90L), 10L); this.isGuiEnabled = ConfigHelper.getBoolean(config, "Enabled-GUI", false); // TODO forge this.shopCommand = ConfigHelper.getString(config, "Shop-Command", "shop"); this.isSignEnabled = ConfigHelper.getBoolean(config, "Enabled-signs", true); this.color = ConfigHelper.getString(config, "Color", "&0"); Log.setDebugging(ConfigHelper.getBoolean(config, "Debug", false)); } private void registerEvents() { // getServer().getPluginManager().registerEvents(new ShopListener(), this); MinecraftForge.EVENT_BUS.register(new SignListener()); FMLCommonHandler.instance().bus().register(new SchedulerTick()); // getServer().getPluginManager().registerEvents(new RecentListener(), this); } private boolean authApi() { if (Api.authAPI(Api.getKey())) { getLogger().info("Using API Key: " + Api.getKey()); return true; } else { getLogger().warn("Invalid API Key! Use \"/MM APIKEY <APIKEY>\" to setup your APIKEY"); return false; } } private void startGUI() { if (isGuiEnabled) { Scheduler.server().schedule(new ShopTask(), 20L); } } private void runCommandChecker() { commandTask = new CommandTask(interval * 20L); Scheduler.server().execute(commandTask); // commandTask.runTaskTimerAsynchronously(this, 600L, interval * 20L); } private void startSignTasks() { if (isSignEnabled()) { Signs.getSigns().setup(); signUpdate = new SignUpdate(); // TODO forge // signUpdate.startSignTask(); } } private void startTasks() { runCommandChecker(); } private void registerCommands(FMLServerStartingEvent event) { event.registerServerCommand(new Commands()); event.registerServerCommand(new ShopCommand()); } private void saveDefaultSettings() { Settings.get().LoadSettings(); } private void stopTasks() { try { // signUpdate.cancel(); // getServer().getScheduler().cancelTasks(this); } catch (Exception e) { Log.log(e); } } public void reloadConfig() { config = YAMLConfigurationLoader.builder().setFile(new File(dataFolder, "config.yml")).build(); } }
public void reloadConfig() { config = YAMLConfigurationLoader.builder().setFile(new File(dataFolder, "config.yml")).build(); }