Skip to content

Commit 1250d3b

Browse files
committed
Update spawn storage save & Logger
1 parent bb89097 commit 1250d3b

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

Common/src/main/java/systems/kscott/randomspawnplus/RandomSpawnPlus.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020

2121
public final class RandomSpawnPlus extends JavaPlugin {
2222

23+
public static final Logger LOGGER = LogManager.getLogger(RandomSpawnPlus.class.getSimpleName());
24+
2325
private static RandomSpawnPlus INSTANCE;
2426
private static HookInstance hookInstance;
25-
public static final Logger LOGGER = LogManager.getLogger(RandomSpawnPlus.class.getSimpleName());
27+
2628
private BukkitAudiences adventure;
2729
public FoliaLib foliaLib = new FoliaLib(this);
2830

@@ -57,7 +59,11 @@ public void onDisable() {
5759
this.adventure = null;
5860
}
5961

60-
//SpawnCacher.getInstance().save();
62+
try {
63+
Config.getSpawnStorage().saveConfig();
64+
} catch (IOException e) {
65+
LOGGER.error("Failed to save " + Config.SPAWN_STORAGE_FILE_NAME + "!", e);
66+
}
6167
}
6268

6369
private void registerEvents() {

Common/src/main/java/systems/kscott/randomspawnplus/config/Config.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
public class Config {
2323

24-
public static final Logger LOGGER = LogManager.getLogger(Config.class.getSimpleName());
2524
private static final String CURRENT_REGION = Locale.getDefault().getCountry().toUpperCase(Locale.ROOT);
2625
private static final String GLOBAL_CONFIG_FILE_NAME = "config.yml";
2726
private static final String LANG_CONFIG_FILE_NAME = "lang.yml";
@@ -49,13 +48,13 @@ public class Config {
4948
loadGlobalConfig(pluginFolder, false);
5049
} catch (Exception e) {
5150
MessageUtil.broadcastCommandMessage(sender, Component.text("Failed to reload " + GLOBAL_CONFIG_FILE_NAME + ". See error in console!", NamedTextColor.RED));
52-
LOGGER.error(e);
51+
RandomSpawnPlus.LOGGER.error(e);
5352
}
5453
try {
5554
loadLangConfig(pluginFolder, false);
5655
} catch (Exception e) {
5756
MessageUtil.broadcastCommandMessage(sender, Component.text("Failed to reload " + LANG_CONFIG_FILE_NAME + ". See error in console!", NamedTextColor.RED));
58-
LOGGER.error(e);
57+
RandomSpawnPlus.LOGGER.error(e);
5958
}
6059

6160
final String success = String.format("Successfully reloaded config in %sms.", (System.nanoTime() - begin) / 1_000_000);
@@ -65,32 +64,32 @@ public class Config {
6564

6665
public static void loadConfig(Plugin instance) {
6766
long begin = System.nanoTime();
68-
LOGGER.info("Loading config...");
67+
RandomSpawnPlus.LOGGER.info("Loading config...");
6968

7069
final File pluginFolder = instance.getDataFolder();
7170

7271
try {
7372
createDirectory(pluginFolder);
7473
} catch (Exception e) {
75-
LOGGER.error("Failed to create <{}> plugin folder!", pluginFolder.getAbsolutePath(), e);
74+
RandomSpawnPlus.LOGGER.error("Failed to create <{}> plugin folder!", pluginFolder.getAbsolutePath(), e);
7675
}
7776
try {
7877
loadGlobalConfig(pluginFolder, true);
7978
} catch (Exception e) {
80-
LOGGER.error("Failed to load " + GLOBAL_CONFIG_FILE_NAME + "!", e);
79+
RandomSpawnPlus.LOGGER.error("Failed to load " + GLOBAL_CONFIG_FILE_NAME + "!", e);
8180
}
8281
try {
8382
loadLangConfig(pluginFolder, true);
8483
} catch (Exception e) {
85-
LOGGER.error("Failed to load " + LANG_CONFIG_FILE_NAME + "!", e);
84+
RandomSpawnPlus.LOGGER.error("Failed to load " + LANG_CONFIG_FILE_NAME + "!", e);
8685
}
8786
try {
8887
loadSpawnStorage(pluginFolder, true);
8988
} catch (Exception e) {
90-
LOGGER.error("Failed to load " + SPAWN_STORAGE_FILE_NAME + "!", e);
89+
RandomSpawnPlus.LOGGER.error("Failed to load " + SPAWN_STORAGE_FILE_NAME + "!", e);
9190
}
9291

93-
LOGGER.info("Successfully loaded config in {}ms.", (System.nanoTime() - begin) / 1_000_000);
92+
RandomSpawnPlus.LOGGER.info("Successfully loaded config in {}ms.", (System.nanoTime() - begin) / 1_000_000);
9493
}
9594

9695
private static void loadGlobalConfig(File pluginFolder, boolean init) throws Exception {
@@ -108,7 +107,7 @@ private static void loadLangConfig(File pluginFolder, boolean init) throws Excep
108107
private static void loadSpawnStorage(File pluginFolder, boolean init) throws Exception {
109108
spawnStorage = new SpawnStorage(pluginFolder, SPAWN_STORAGE_FILE_NAME, init);
110109

111-
spawnStorage.saveConfig(pluginFolder);
110+
spawnStorage.saveConfig();
112111
}
113112

114113
public static void createDirectory(File dir) throws IOException {

Common/src/main/java/systems/kscott/randomspawnplus/config/SpawnStorage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public void reloadConfig() throws IOException, InvalidConfigurationException {
3333
config.load(customConfigFile);
3434
}
3535

36-
public void saveConfig(File pluginFolder) throws IOException {
36+
public void saveConfig() throws IOException {
3737
// TODO: Check here, better way?
38-
String path = Paths.get(pluginFolder.getAbsolutePath(), configFileName).toString();
38+
String path = Paths.get(RandomSpawnPlus.getInstance().getDataFolder().getAbsolutePath(), configFileName).toString();
3939
config.save(path);
4040
}
4141

Common/src/main/java/systems/kscott/randomspawnplus/spawn/SpawnFinder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ public static void deleteSpawn(Location location) {
221221
cachedSpawns.removeIf(locationString -> Locations.serializeString(location).equals(locationString));
222222
Config.getSpawnStorage().get().set("spawns", cachedSpawns);
223223
try {
224-
Config.getSpawnStorage().saveConfig(RandomSpawnPlus.getInstance().getDataFolder());
224+
Config.getSpawnStorage().saveConfig();
225225
} catch (IOException e) {
226-
Config.LOGGER.error("Failed to save " + Config.SPAWN_STORAGE_FILE_NAME + "!", e);
226+
RandomSpawnPlus.LOGGER.error("Failed to save " + Config.SPAWN_STORAGE_FILE_NAME + "!", e);
227227
}
228228
}
229229

0 commit comments

Comments
 (0)