Skip to content

Commit 743f305

Browse files
committed
Some work
1 parent 2b02e5a commit 743f305

6 files changed

Lines changed: 175 additions & 181 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import systems.kscott.randomspawnplus.RandomSpawnPlus;
1010
import systems.kscott.randomspawnplus.util.MessageUtil;
1111
import org.bukkit.command.CommandSender;
12+
import org.bukkit.configuration.file.FileConfiguration;
1213
import org.bukkit.plugin.Plugin;
1314

1415
import java.io.File;
@@ -24,7 +25,7 @@ public class Config {
2425
private static final String CURRENT_REGION = Locale.getDefault().getCountry().toUpperCase(Locale.ROOT);
2526
private static final String GLOBAL_CONFIG_FILE_NAME = "config.yml";
2627
private static final String LANG_CONFIG_FILE_NAME = "lang.yml";
27-
private static final String SPAWN_STORAGE_FILE_NAME = "spawns.yml";
28+
public static final String SPAWN_STORAGE_FILE_NAME = "spawns.yml"; // public since used in other classes
2829

2930
private static ConfigLocale configLocale;
3031
private static GlobalConfig globalConfig;
@@ -107,7 +108,7 @@ private static void loadLangConfig(File pluginFolder, boolean init) throws Excep
107108
private static void loadSpawnStorage(File pluginFolder, boolean init) throws Exception {
108109
spawnStorage = new SpawnStorage(pluginFolder, SPAWN_STORAGE_FILE_NAME, init);
109110

110-
spawnStorage.saveConfig();
111+
spawnStorage.saveConfig(pluginFolder);
111112
}
112113

113114
public static void createDirectory(File dir) throws IOException {
@@ -134,6 +135,10 @@ public static LangConfig getLangConfig() {
134135
return langConfig;
135136
}
136137

138+
public static SpawnStorage getSpawnStorage() {
139+
return spawnStorage;
140+
}
141+
137142
public static void getLastConfigVersion(String lastConfigVer) {
138143
// If last is null, then it means the plugin is fist loaded, fallback to current config version
139144
if (lastConfigVer == null) lastConfigVer = currConfigVer;
Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
11
package systems.kscott.randomspawnplus.config;
22

3-
import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
3+
import systems.kscott.randomspawnplus.RandomSpawnPlus;
4+
5+
import org.bukkit.configuration.InvalidConfigurationException;
6+
import org.bukkit.configuration.file.FileConfiguration;
7+
import org.bukkit.configuration.file.YamlConfiguration;
48

59
import java.io.File;
10+
import java.io.IOException;
11+
import java.nio.file.Paths;
612

713
public class SpawnStorage {
814

9-
private static ConfigFile configFile;
15+
private FileConfiguration config;
16+
private final String configFileName;
1017

1118
public SpawnStorage(File pluginFolder, String configFileName, boolean init) throws Exception {
12-
configFile = ConfigFile.loadConfig(new File(pluginFolder, configFileName));
19+
this.configFileName = configFileName;
1320

1421
// Init value for config keys
15-
initConfig();
22+
reloadConfig();
23+
}
24+
25+
public FileConfiguration get() {
26+
return config;
27+
}
28+
29+
public void reloadConfig() throws IOException, InvalidConfigurationException {
30+
File customConfigFile = createFile();
31+
config = new YamlConfiguration();
32+
33+
config.load(customConfigFile);
1634
}
1735

18-
private void initConfig() {
36+
public void saveConfig(File pluginFolder) throws IOException {
37+
// TODO: Check here, better way?
38+
String path = Paths.get(pluginFolder.getAbsolutePath(), configFileName).toString();
39+
config.save(path);
1940
}
2041

21-
public void saveConfig() throws Exception {
22-
configFile.save();
42+
private File createFile() {
43+
File customConfigFile = new File(RandomSpawnPlus.getInstance().getDataFolder(), configFileName);
44+
if (!customConfigFile.exists() || customConfigFile.getParentFile().mkdirs()) {
45+
RandomSpawnPlus.getInstance().saveResource(configFileName, false);
46+
}
47+
return customConfigFile;
2348
}
2449
}

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

Lines changed: 0 additions & 97 deletions
This file was deleted.

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
import org.bukkit.Material;
44

5-
import java.util.ArrayList;
5+
import java.util.Set;
66

77
public class SpawnData {
88

9-
private static ArrayList<Material> unsafeBlocks;
9+
private static Set<Material> unsafeBlocks;
10+
11+
public static Set<Material> getUnsafeBlocks() {
12+
return unsafeBlocks;
13+
}
14+
15+
public static void setUnsafeBlocks(Set<Material> blocks) {
16+
unsafeBlocks = blocks;
17+
}
1018
}

0 commit comments

Comments
 (0)