-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Config to Enable/Disable Spawning of Oddion and Man O War. Closes #…
…182 Signed-off-by: Joseph T. McQuigg <[email protected]>
- Loading branch information
Showing
7 changed files
with
64 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
41 changes: 41 additions & 0 deletions
41
Common/src/main/java/net/potionstudios/biomeswevegone/config/ConfigLoader.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,41 @@ | ||
package net.potionstudios.biomeswevegone.config; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
|
||
import net.potionstudios.biomeswevegone.PlatformHandler; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* Makes or loads a config file | ||
* @see Gson | ||
* @author Joseph T. McQuigg | ||
*/ | ||
public class ConfigLoader { | ||
/** The Gson instance for the Config Loader. */ | ||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); | ||
|
||
/** | ||
* Loads or Creates a config file | ||
* | ||
* @param clazz The class of the config file. | ||
* @return The config file. | ||
*/ | ||
public static <T> T loadConfig(@NotNull Class<T> clazz, String name) { | ||
try { | ||
Path configPath = PlatformHandler.PLATFORM_HANDLER.configPath().resolve(name + ".json"); | ||
T value = clazz.getConstructor().newInstance(); | ||
|
||
if (Files.notExists(configPath)) Files.createDirectories(configPath.getParent()); | ||
else if (Files.exists(configPath)) value = GSON.fromJson(Files.newBufferedReader(configPath), clazz); | ||
|
||
Files.writeString(configPath, GSON.toJson(value)); | ||
return value; | ||
} catch (Exception e) { | ||
throw new RuntimeException("Failed to load config.", e); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Common/src/main/java/net/potionstudios/biomeswevegone/config/configs/BWGMobSpawnConfig.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,15 @@ | ||
package net.potionstudios.biomeswevegone.config.configs; | ||
|
||
import net.potionstudios.biomeswevegone.config.ConfigLoader; | ||
|
||
public class BWGMobSpawnConfig { | ||
|
||
public static final BWGSpawnConfig INSTANCE = ConfigLoader.loadConfig(BWGMobSpawnConfig.class, "mob_spawn").spawn; | ||
|
||
public BWGSpawnConfig spawn = new BWGSpawnConfig(); | ||
|
||
public static class BWGSpawnConfig { | ||
public boolean man_o_war = true; | ||
public boolean oddion = true; | ||
} | ||
} |
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
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
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
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