-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #1 This hasn't been tested yet.
- Loading branch information
Showing
5 changed files
with
181 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/com/justbru00/timingsystem/bluemap/configuration/ConfigUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://www.gnu.org/licenses/>. | ||
* | ||
* @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<String> stringList = new ArrayList<String>(); | ||
for (String s : updatedValue) { | ||
stringList.add(s); | ||
} | ||
|
||
config.set(path, stringList); | ||
Messager.msgConsole("[ConfigUpdater] Added " + path + " to config.yml."); | ||
TimingSystemBlueMapPlugin.getInstance().saveConfig(); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/com/justbru00/timingsystem/bluemap/configuration/ConfigurationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://www.gnu.org/licenses/>. | ||
* | ||
* @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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters