Fix reload command, use generator IDs

This commit is contained in:
dfsek 2020-10-11 23:35:46 -07:00
parent 534b83e36b
commit ef16143565
5 changed files with 24 additions and 22 deletions

View File

@ -54,15 +54,11 @@ public class Terra extends GaeaPlugin {
@Override @Override
public @Nullable ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) { public @Nullable ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) {
if(!loadedWorlds.contains(worldName)) TerraWorld.loadWorld(new WorldConfig(worldName, this)); if(!loadedWorlds.contains(worldName)) TerraWorld.loadWorld(new WorldConfig(worldName, id, this));
loadedWorlds.add(worldName); // Ensure world config is only loaded once for world. loadedWorlds.add(worldName); // Ensure world config is only loaded once for world.
return new TerraChunkGenerator(); return new TerraChunkGenerator();
} }
public static void invalidate() {
loadedWorlds.clear();
}
@Override @Override
public boolean isDebug() { public boolean isDebug() {
return ConfigUtil.debug; return ConfigUtil.debug;

View File

@ -106,7 +106,9 @@ public class TerraWorld {
public static synchronized void invalidate() { public static synchronized void invalidate() {
map.clear(); map.clear();
loaded.clear(); for(WorldConfig config : loaded.values()) {
config.load(); // Reload all stored WorldConfigs
}
} }
public static int numWorlds() { public static int numWorlds() {

View File

@ -45,7 +45,6 @@ public final class ConfigUtil {
logger.info("Loading config values"); logger.info("Loading config values");
ConfigPack.loadAll(main); ConfigPack.loadAll(main);
Terra.invalidate();
TerraWorld.invalidate(); TerraWorld.invalidate();
} }

View File

@ -10,6 +10,7 @@ import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.polydev.gaea.GaeaPlugin;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -31,18 +32,27 @@ public class WorldConfig {
private ConfigPack tConfig; private ConfigPack tConfig;
private final String worldID; private final String worldID;
private final String configID;
private final GaeaPlugin main;
public WorldConfig(String w, JavaPlugin main) { public WorldConfig(String w, String configID, GaeaPlugin main) {
long start = System.nanoTime();
this.worldID = w; this.worldID = w;
LangUtil.log("world-config.load", Level.INFO, w); this.configID = configID;
this.main = main;
load();
}
public void load() {
long start = System.nanoTime();
LangUtil.log("world-config.load", Level.INFO, worldID);
FileConfiguration config = new YamlConfiguration(); FileConfiguration config = new YamlConfiguration();
try { // Load/create world config file try { // Load/create world config file
File configFile = new File(main.getDataFolder() + File.separator + "worlds", w + ".yml"); if(configID == null || configID.equals("")) throw new ConfigException("Config pack unspecified in bukkit.yml!", worldID);
File configFile = new File(main.getDataFolder() + File.separator + "worlds", worldID + ".yml");
if(! configFile.exists()) { if(! configFile.exists()) {
configFile.getParentFile().mkdirs(); configFile.getParentFile().mkdirs();
LangUtil.log("world-config.not-found", Level.WARNING, w); LangUtil.log("world-config.not-found", Level.WARNING, worldID);
FileUtils.copyInputStreamToFile(Objects.requireNonNull(main.getResource("world.yml")), configFile); FileUtils.copyInputStreamToFile(Objects.requireNonNull(main.getResource("world.yml")), configFile);
} }
config.load(configFile); config.load(configFile);
@ -50,12 +60,9 @@ public class WorldConfig {
// Get values from config. // Get values from config.
fromImage = config.getBoolean("image.enable", false); fromImage = config.getBoolean("image.enable", false);
String packID = config.getString("config"); tConfig = ConfigPack.fromID(configID);
if(tConfig == null) throw new ConfigException("No such config pack: \"" + configID + "\"", worldID);
tConfig = ConfigPack.fromID(packID);
if(tConfig == null) throw new ConfigException("No such config pack: \"" + packID + "\"", worldID);
// Load image stuff // Load image stuff
try { try {
@ -69,7 +76,7 @@ public class WorldConfig {
if(fromImage) { if(fromImage) {
try { try {
imageLoader = new ImageLoader(new File(Objects.requireNonNull(config.getString("image.file"))), ImageLoader.Align.valueOf(config.getString("image.align", "center").toUpperCase())); imageLoader = new ImageLoader(new File(Objects.requireNonNull(config.getString("image.file"))), ImageLoader.Align.valueOf(config.getString("image.align", "center").toUpperCase()));
LangUtil.log("world-config.using-image", Level.INFO, w); LangUtil.log("world-config.using-image", Level.INFO, worldID);
} catch(IOException | NullPointerException e) { } catch(IOException | NullPointerException e) {
e.printStackTrace(); e.printStackTrace();
fromImage = false; fromImage = false;
@ -79,13 +86,12 @@ public class WorldConfig {
throw new InvalidConfigurationException(e.getCause()); throw new InvalidConfigurationException(e.getCause());
} }
Bukkit.getLogger().info("Loaded " + tConfig.biomeList.size() + " BiomeGrids from list."); Bukkit.getLogger().info("Loaded " + tConfig.biomeList.size() + " BiomeGrids from list.");
} catch(IOException | InvalidConfigurationException e) { } catch(IOException | InvalidConfigurationException e) {
e.printStackTrace(); e.printStackTrace();
LangUtil.log("world-config.error", Level.SEVERE, w); LangUtil.log("world-config.error", Level.SEVERE, worldID);
throw new IllegalStateException("Unable to proceed due to fatal configuration error."); throw new IllegalStateException("Unable to proceed due to fatal configuration error.");
} }
LangUtil.log("world-config.done", Level.INFO, w, String.valueOf(((double) (System.nanoTime() - start)) / 1000000)); LangUtil.log("world-config.done", Level.INFO, worldID, String.valueOf(((double) (System.nanoTime() - start)) / 1000000));
} }
public String getWorldID() { public String getWorldID() {

View File

@ -7,7 +7,6 @@ disable:
command: command:
debug-only: "This command must be used with debug mode enabled!" debug-only: "This command must be used with debug mode enabled!"
player-only: "This command is for players only!" player-only: "This command is for players only!"
terra-world: "This command must be executed in a Terra world!"
invalid: "Invalid command. (Expected %1$s arguments, found %2$s)." invalid: "Invalid command. (Expected %1$s arguments, found %2$s)."
players-only: "Command is for players only." players-only: "Command is for players only."
world: "This command must be executed in a Terra world!" world: "This command must be executed in a Terra world!"