diff --git a/src/com/justbru00/timingsystem/bluemap/TimingSystemBlueMapPlugin.java b/src/com/justbru00/timingsystem/bluemap/TimingSystemBlueMapPlugin.java index 3e968de..695e9cb 100644 --- a/src/com/justbru00/timingsystem/bluemap/TimingSystemBlueMapPlugin.java +++ b/src/com/justbru00/timingsystem/bluemap/TimingSystemBlueMapPlugin.java @@ -10,6 +10,7 @@ import com.justbru00.timingsystem.bluemap.utils.Messager; import com.justbru00.timingsystem.bluemap.bstats.BStats; +import com.justbru00.timingsystem.bluemap.configuration.ConfigurationManager; import de.bluecolored.bluemap.api.BlueMapAPI; import de.bluecolored.bluemap.api.BlueMapMap; @@ -44,7 +45,8 @@ public class TimingSystemBlueMapPlugin extends JavaPlugin { private static TimingSystemBlueMapPlugin instance; private static final int BSTATS_PLUGIN_ID = 18483; private static final String[] TIMING_SYSTEM_SUPPORTED_VERSIONS = {"1.2", "1.3"}; - + + public static String PLUGIN_VERSION = null; public static ConsoleCommandSender clogger = Bukkit.getServer().getConsoleSender(); public static Logger log = Bukkit.getLogger(); @@ -60,7 +62,18 @@ public void onDisable() { @Override public void onEnable() { instance = this; - Messager.msgConsole("&6Starting TimingSystemBlueMap " + getDescription().getVersion() + "..."); + + PLUGIN_VERSION = TimingSystemBlueMapPlugin.getInstance().getDescription().getVersion(); + Messager.msgConsole("&6Starting TimingSystemBlueMap " + PLUGIN_VERSION + "..."); + + saveDefaultConfig(); + + if (ConfigurationManager.doesConfigYmlNeedUpdated()) { + Messager.msgConsole("&c[WARN] The config.yml file version is incorrect. TimingSystemBlueMap v" + PLUGIN_VERSION + + " expects a config.yml version of " + ConfigurationManager.CONFIG_VERSION + + ". Attempting to add missing values to the config file."); + ConfigurationManager.updateConfigYml(); + } Plugin timingSystem = Bukkit.getPluginManager().getPlugin("TimingSystem"); if (timingSystem == null) { @@ -79,7 +92,7 @@ public void onEnable() { } if (!supportedVersion) { - Messager.msgConsole("&cTimingSystemBlueMap version " + getDescription().getVersion() + " doesn't support TimingSystem version " + Messager.msgConsole("&cTimingSystemBlueMap version " + PLUGIN_VERSION + " doesn't support TimingSystem version " + timingSystemVersion + ". The add-on will attempt to run as normal, but you may encounter issues."); } } @@ -93,6 +106,13 @@ public void onEnable() { MarkerSet markerSet = MarkerSet.builder().label("TimingSystem Track Locations").toggleable(true).build(); for (Track track : TimingSystemAPI.getTracks()) { + // ISSUE #1 + if (TimingSystemBlueMapPlugin.getInstance().getConfig().getBoolean("poi_markers.tracks.spawn_locations.hide_closed_tracks")) { + if (!track.isOpen()) { + continue; + } + } // END ISSUE #1 + double x = track.getSpawnLocation().getX(); double y = track.getSpawnLocation().getY(); double z = track.getSpawnLocation().getZ(); diff --git a/src/com/justbru00/timingsystem/bluemap/configuration/ConfigUpdater.java b/src/com/justbru00/timingsystem/bluemap/configuration/ConfigUpdater.java new file mode 100644 index 0000000..b4f625b --- /dev/null +++ b/src/com/justbru00/timingsystem/bluemap/configuration/ConfigUpdater.java @@ -0,0 +1,97 @@ +package com.justbru00.timingsystem.bluemap.configuration; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.configuration.file.FileConfiguration; + +import com.justbru00.timingsystem.bluemap.TimingSystemBlueMapPlugin; +import com.justbru00.timingsystem.bluemap.utils.Messager; + +/** + * TimingSystemBlueMap - This plugin will display track spawn locations as poi markers on bluemap. + * Copyright (C) 2023 Justin "JustBru00" Brubaker + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * @author Justin Brubaker + * + */ +public class ConfigUpdater { + private static FileConfiguration config; + + public static void updateConfigYml() { + int currentConfigVersion = ConfigurationManager.CONFIG_VERSION; + if (config == null) { + config = TimingSystemBlueMapPlugin.getInstance().getConfig(); + } + + if (config.getInt("config_version") != 0) { + if (config.getInt("config_version") == currentConfigVersion) { + // The config version is up to date. + } else { + config.set("config_version", currentConfigVersion); + TimingSystemBlueMapPlugin.getInstance().saveConfig(); + } + } else { + // Config value cannot be found. + config.set("config_version", currentConfigVersion); + TimingSystemBlueMapPlugin.getInstance().saveConfig(); + } + + // Add values if they are missing + updateConfigYmlBoolean("poi_markers.tracks.spawn_locations.hide_closed_tracks", false); + } + + private static void updateConfigYmlInteger(String path, int updatedValue) { + if (!config.isSet(path)) { + // Path doesn't exist. + config.set(path, updatedValue); + Messager.msgConsole("[ConfigUpdater] Added " + path + " to config.yml."); + TimingSystemBlueMapPlugin.getInstance().saveConfig(); + } + } + + private static void updateConfigYmlString(String path, String updatedValue) { + if (!config.isSet(path)) { + // Path doesn't exist. + config.set(path, updatedValue); + Messager.msgConsole("[ConfigUpdater] Added " + path + " to config.yml."); + TimingSystemBlueMapPlugin.getInstance().saveConfig(); + } + } + + private static void updateConfigYmlBoolean(String path, boolean updatedValue) { + if (!config.isSet(path)) { + // Path doesn't exist. + config.set(path, updatedValue); + Messager.msgConsole("[ConfigUpdater] Added " + path + " to config.yml."); + TimingSystemBlueMapPlugin.getInstance().saveConfig(); + } + } + + private static void updateConfigYmlStringList(String path, String... updatedValue) { + if (!config.isSet(path)) { + // Path doesn't exist. + List stringList = new ArrayList(); + for (String s : updatedValue) { + stringList.add(s); + } + + config.set(path, stringList); + Messager.msgConsole("[ConfigUpdater] Added " + path + " to config.yml."); + TimingSystemBlueMapPlugin.getInstance().saveConfig(); + } + } +} diff --git a/src/com/justbru00/timingsystem/bluemap/configuration/ConfigurationManager.java b/src/com/justbru00/timingsystem/bluemap/configuration/ConfigurationManager.java new file mode 100644 index 0000000..9830ba7 --- /dev/null +++ b/src/com/justbru00/timingsystem/bluemap/configuration/ConfigurationManager.java @@ -0,0 +1,53 @@ +package com.justbru00.timingsystem.bluemap.configuration; + +import org.bukkit.configuration.file.FileConfiguration; + +import com.justbru00.timingsystem.bluemap.TimingSystemBlueMapPlugin; + +/** + * TimingSystemBlueMap - This plugin will display track spawn locations as poi markers on bluemap. + * Copyright (C) 2023 Justin "JustBru00" Brubaker + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * @author Justin Brubaker + * + */ +public class ConfigurationManager { + + public static final int CONFIG_VERSION = 1; + private static FileConfiguration config = null; + + /** + * Checks the config version number vs the one this version has. + * @return True if it needs updated, false if it doesn't. + */ + public static boolean doesConfigYmlNeedUpdated() { + if (config == null) { + config = TimingSystemBlueMapPlugin.getInstance().getConfig(); + } + + return config.getInt("config_version") < CONFIG_VERSION; + } + + /** + * Adds any new config values to the config.yml file if the config_version value doesn't match the value of this version of EpicRename. + * These must be set manually in the {@link ConfigUpdater}. + * Doesn't touch old values. + */ + public static void updateConfigYml() { + ConfigUpdater.updateConfigYml(); + } + +} diff --git a/src/config.yml b/src/config.yml new file mode 100644 index 0000000..668625b --- /dev/null +++ b/src/config.yml @@ -0,0 +1,7 @@ +# TimingSystemBlueMap created by JustBru00. This file was generated by 0.0.2 +config_version: 1 + +poi_markers: + tracks: + spawn_locations: + hide_closed_tracks: false \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml index 316a6d6..fbac066 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ name: TimingSystemBlueMap -version: 0.0.1 +version: 0.0.2-RC1 authors: [Justin Brubaker (JustBru00)] softdepend: [TimingSystem,BlueMap] main: com.justbru00.timingsystem.bluemap.TimingSystemBlueMapPlugin