From a5c85a7e5d7827855fedaabb268955141be54934 Mon Sep 17 00:00:00 2001 From: dfsek Date: Thu, 1 Oct 2020 10:33:55 -0700 Subject: [PATCH] Implement new config exceptions, general config cleanup --- src/main/java/com/dfsek/terra/Terra.java | 2 +- .../java/com/dfsek/terra/biome/BiomeZone.java | 2 +- .../com/dfsek/terra/biome/TerraBiomeGrid.java | 4 +- .../dfsek/terra/biome/UserDefinedGrid.java | 4 +- .../dfsek/terra/command/ReloadCommand.java | 2 +- .../command/image/gui/RawGUICommand.java | 4 +- .../command/image/gui/StepGUICommand.java | 4 +- .../com/dfsek/terra/command/type/Command.java | 43 ++++++++++++ .../terra/command/type/PlayerCommand.java | 27 ++++++++ .../terra/command/type/WorldCommand.java | 28 ++++++++ .../com/dfsek/terra/config/ConfigLoader.java | 3 +- .../terra/config/{ => base}/ConfigUtil.java | 21 +++++- .../terra/config/{ => base}/WorldConfig.java | 2 +- .../config/exception/ConfigException.java | 21 ++++++ .../config/exception/NotFoundException.java | 10 +++ .../config/genconfig/AbstractBiomeConfig.java | 16 +---- .../terra/config/genconfig/BiomeConfig.java | 41 ++++++------ .../config/genconfig/BiomeConfigUtil.java | 8 ++- .../config/genconfig/BiomeGridConfig.java | 19 +++--- .../terra/config/genconfig/CarverConfig.java | 65 +++++-------------- .../terra/config/genconfig/FloraConfig.java | 34 +++------- .../terra/config/genconfig/OreConfig.java | 24 ++++--- .../terra/config/genconfig/PaletteConfig.java | 6 +- .../config/genconfig/StructureConfig.java | 13 ++-- .../com/dfsek/terra/image/DebugFrame.java | 2 +- .../com/dfsek/terra/image/ImageLoader.java | 6 +- .../terra/image/WorldImageGenerator.java | 1 - .../dfsek/terra/population/CavePopulator.java | 3 +- 28 files changed, 249 insertions(+), 166 deletions(-) rename src/main/java/com/dfsek/terra/config/{ => base}/ConfigUtil.java (71%) rename src/main/java/com/dfsek/terra/config/{ => base}/WorldConfig.java (99%) create mode 100644 src/main/java/com/dfsek/terra/config/exception/ConfigException.java create mode 100644 src/main/java/com/dfsek/terra/config/exception/NotFoundException.java diff --git a/src/main/java/com/dfsek/terra/Terra.java b/src/main/java/com/dfsek/terra/Terra.java index 3f5d3b989..37ad1e225 100644 --- a/src/main/java/com/dfsek/terra/Terra.java +++ b/src/main/java/com/dfsek/terra/Terra.java @@ -1,7 +1,7 @@ package com.dfsek.terra; import com.dfsek.terra.command.TerraCommand; -import com.dfsek.terra.config.ConfigUtil; +import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.generation.TerraChunkGenerator; import com.mojang.brigadier.tree.LiteralCommandNode; import me.lucko.commodore.Commodore; diff --git a/src/main/java/com/dfsek/terra/biome/BiomeZone.java b/src/main/java/com/dfsek/terra/biome/BiomeZone.java index 18bb3ffe9..ad2e29f18 100644 --- a/src/main/java/com/dfsek/terra/biome/BiomeZone.java +++ b/src/main/java/com/dfsek/terra/biome/BiomeZone.java @@ -1,6 +1,6 @@ package com.dfsek.terra.biome; -import com.dfsek.terra.config.WorldConfig; +import com.dfsek.terra.config.base.WorldConfig; import com.dfsek.terra.image.ImageLoader; import org.bukkit.World; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/dfsek/terra/biome/TerraBiomeGrid.java b/src/main/java/com/dfsek/terra/biome/TerraBiomeGrid.java index 0c267043c..ff54b7b82 100644 --- a/src/main/java/com/dfsek/terra/biome/TerraBiomeGrid.java +++ b/src/main/java/com/dfsek/terra/biome/TerraBiomeGrid.java @@ -1,7 +1,7 @@ package com.dfsek.terra.biome; -import com.dfsek.terra.config.ConfigUtil; -import com.dfsek.terra.config.WorldConfig; +import com.dfsek.terra.config.base.ConfigUtil; +import com.dfsek.terra.config.base.WorldConfig; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; diff --git a/src/main/java/com/dfsek/terra/biome/UserDefinedGrid.java b/src/main/java/com/dfsek/terra/biome/UserDefinedGrid.java index 1f851da47..03bd96afa 100644 --- a/src/main/java/com/dfsek/terra/biome/UserDefinedGrid.java +++ b/src/main/java/com/dfsek/terra/biome/UserDefinedGrid.java @@ -1,7 +1,6 @@ package com.dfsek.terra.biome; -import com.dfsek.terra.config.WorldConfig; -import com.dfsek.terra.config.genconfig.BiomeGridConfig; +import com.dfsek.terra.config.base.WorldConfig; import com.dfsek.terra.image.ImageLoader; import org.bukkit.Location; import org.bukkit.World; @@ -9,7 +8,6 @@ import org.polydev.gaea.biome.Biome; import org.polydev.gaea.biome.BiomeGrid; import org.polydev.gaea.biome.NormalizationUtil; import org.polydev.gaea.generation.GenerationPhase; -import org.polydev.gaea.math.Interpolator; public class UserDefinedGrid extends BiomeGrid { private final ImageLoader imageLoader; diff --git a/src/main/java/com/dfsek/terra/command/ReloadCommand.java b/src/main/java/com/dfsek/terra/command/ReloadCommand.java index 54963a014..e71e556c7 100644 --- a/src/main/java/com/dfsek/terra/command/ReloadCommand.java +++ b/src/main/java/com/dfsek/terra/command/ReloadCommand.java @@ -2,7 +2,7 @@ package com.dfsek.terra.command; import com.dfsek.terra.Terra; import com.dfsek.terra.command.type.Command; -import com.dfsek.terra.config.ConfigUtil; +import com.dfsek.terra.config.base.ConfigUtil; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/dfsek/terra/command/image/gui/RawGUICommand.java b/src/main/java/com/dfsek/terra/command/image/gui/RawGUICommand.java index 3081c85d5..c6c057eed 100644 --- a/src/main/java/com/dfsek/terra/command/image/gui/RawGUICommand.java +++ b/src/main/java/com/dfsek/terra/command/image/gui/RawGUICommand.java @@ -1,8 +1,8 @@ package com.dfsek.terra.command.image.gui; import com.dfsek.terra.command.type.WorldCommand; -import com.dfsek.terra.config.ConfigUtil; -import com.dfsek.terra.config.WorldConfig; +import com.dfsek.terra.config.base.ConfigUtil; +import com.dfsek.terra.config.base.WorldConfig; import com.dfsek.terra.image.ImageLoader; import org.bukkit.World; import org.bukkit.command.Command; diff --git a/src/main/java/com/dfsek/terra/command/image/gui/StepGUICommand.java b/src/main/java/com/dfsek/terra/command/image/gui/StepGUICommand.java index 661855a04..7abd0f2a7 100644 --- a/src/main/java/com/dfsek/terra/command/image/gui/StepGUICommand.java +++ b/src/main/java/com/dfsek/terra/command/image/gui/StepGUICommand.java @@ -1,8 +1,8 @@ package com.dfsek.terra.command.image.gui; import com.dfsek.terra.command.type.WorldCommand; -import com.dfsek.terra.config.ConfigUtil; -import com.dfsek.terra.config.WorldConfig; +import com.dfsek.terra.config.base.ConfigUtil; +import com.dfsek.terra.config.base.WorldConfig; import com.dfsek.terra.image.ImageLoader; import org.bukkit.World; import org.bukkit.command.Command; diff --git a/src/main/java/com/dfsek/terra/command/type/Command.java b/src/main/java/com/dfsek/terra/command/type/Command.java index bb5889d32..5c36a598f 100644 --- a/src/main/java/com/dfsek/terra/command/type/Command.java +++ b/src/main/java/com/dfsek/terra/command/type/Command.java @@ -6,11 +6,54 @@ import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.List; +/** + * Represents a command or subcommand, can be nested via getSubCommands. + */ public abstract class Command { + /** + * Gets the name of the command/subcommand + * @return Name of command + */ public abstract String getName(); + + /** + * Gets a list of subcommands + * @return List of subcommands + */ public abstract List getSubCommands(); + + /** + * Executes the given command, returning its success. + *
+ * If false is returned, then the "usage" plugin.yml entry for this command + * (if defined) will be sent to the player. + * + * @param sender Source of the command + * @param command Command which was executed + * @param label Alias of the command which was used + * @param args Passed command arguments + * @return true if a valid command, otherwise false + */ public abstract boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args); + + /** + * Gets the number of arguments + * @return Number of arguments + */ public abstract int arguments(); + + /** + * Executes the given command, invoking subcommands if applicable and returning its success. + *
+ * If false is returned, then the "usage" plugin.yml entry for this command + * (if defined) will be sent to the player. + * + * @param sender Source of the command + * @param command Command which was executed + * @param label Alias of the command which was used + * @param args Passed command arguments + * @return true if a valid command, otherwise false + */ public final boolean execute(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args) { if(args.length > 0) { for(Command c : getSubCommands()) { diff --git a/src/main/java/com/dfsek/terra/command/type/PlayerCommand.java b/src/main/java/com/dfsek/terra/command/type/PlayerCommand.java index d84aff6cd..a6d741a7c 100644 --- a/src/main/java/com/dfsek/terra/command/type/PlayerCommand.java +++ b/src/main/java/com/dfsek/terra/command/type/PlayerCommand.java @@ -4,7 +4,22 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +/** + * A command that may only be executed by a player. If executor is not a player, a message will be displayed and no action will be performed. + */ public abstract class PlayerCommand extends Command { + /** + * Executes the given command, returning its success. + *
+ * If false is returned, then the "usage" plugin.yml entry for this command + * (if defined) will be sent to the player. + * + * @param sender Source of the command + * @param command Command which was executed + * @param label Alias of the command which was used + * @param args Passed command arguments + * @return true if a valid command, otherwise false + */ @Override public boolean onCommand(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) { if(!(sender instanceof Player)) { @@ -14,5 +29,17 @@ public abstract class PlayerCommand extends Command { Player p = (Player) sender; return onCommand(p, command, label, args); } + /** + * Executes the given command, returning its success. + *
+ * If false is returned, then the "usage" plugin.yml entry for this command + * (if defined) will be sent to the player. + * + * @param sender Player that executed command + * @param command Command which was executed + * @param label Alias of the command which was used + * @param args Passed command arguments + * @return true if a valid command, otherwise false + */ public abstract boolean onCommand(@NotNull Player sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args); } diff --git a/src/main/java/com/dfsek/terra/command/type/WorldCommand.java b/src/main/java/com/dfsek/terra/command/type/WorldCommand.java index 7a983588a..3275640da 100644 --- a/src/main/java/com/dfsek/terra/command/type/WorldCommand.java +++ b/src/main/java/com/dfsek/terra/command/type/WorldCommand.java @@ -6,7 +6,22 @@ import org.bukkit.command.Command; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +/** + * A command that must be executed by a player, in a Terra world. + */ public abstract class WorldCommand extends PlayerCommand { + /** + * Executes the given command, returning its success. + *
+ * If false is returned, then the "usage" plugin.yml entry for this command + * (if defined) will be sent to the player. + * + * @param sender Source of the command + * @param command Command which was executed + * @param label Alias of the command which was used + * @param args Passed command arguments + * @return true if a valid command, otherwise false + */ @Override public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if(sender.getWorld().getGenerator() instanceof TerraChunkGenerator) { @@ -17,5 +32,18 @@ public abstract class WorldCommand extends PlayerCommand { return true; } + /** + * Executes the given command, returning its success. + *
+ * If false is returned, then the "usage" plugin.yml entry for this command + * (if defined) will be sent to the player. + * + * @param sender Player that executed command + * @param command Command which was executed + * @param label Alias of the command which was used + * @param args Passed command arguments + * @param world World in which command was executed + * @return true if a valid command, otherwise false + */ public abstract boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world); } diff --git a/src/main/java/com/dfsek/terra/config/ConfigLoader.java b/src/main/java/com/dfsek/terra/config/ConfigLoader.java index db641b9f6..50263cf99 100644 --- a/src/main/java/com/dfsek/terra/config/ConfigLoader.java +++ b/src/main/java/com/dfsek/terra/config/ConfigLoader.java @@ -1,5 +1,6 @@ package com.dfsek.terra.config; +import com.dfsek.terra.config.base.ConfigUtil; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import org.polydev.gaea.commons.io.FilenameUtils; @@ -11,9 +12,7 @@ import java.lang.reflect.InvocationTargetException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.stream.Stream; public class ConfigLoader { diff --git a/src/main/java/com/dfsek/terra/config/ConfigUtil.java b/src/main/java/com/dfsek/terra/config/base/ConfigUtil.java similarity index 71% rename from src/main/java/com/dfsek/terra/config/ConfigUtil.java rename to src/main/java/com/dfsek/terra/config/base/ConfigUtil.java index 4da1f6015..29a75e4e3 100644 --- a/src/main/java/com/dfsek/terra/config/ConfigUtil.java +++ b/src/main/java/com/dfsek/terra/config/base/ConfigUtil.java @@ -1,7 +1,9 @@ -package com.dfsek.terra.config; +package com.dfsek.terra.config.base; import com.dfsek.terra.biome.BiomeZone; import com.dfsek.terra.biome.TerraBiomeGrid; +import com.dfsek.terra.config.ConfigLoader; +import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.genconfig.AbstractBiomeConfig; import com.dfsek.terra.config.genconfig.BiomeConfig; import com.dfsek.terra.config.genconfig.BiomeGridConfig; @@ -10,13 +12,18 @@ import com.dfsek.terra.config.genconfig.FloraConfig; import com.dfsek.terra.config.genconfig.OreConfig; import com.dfsek.terra.config.genconfig.PaletteConfig; import com.dfsek.terra.config.genconfig.StructureConfig; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.time.Duration; +import java.util.HashSet; import java.util.List; import java.util.Objects; +import java.util.Set; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -59,4 +66,16 @@ public class ConfigUtil { public static > List getElements(List st, Class clazz) { return st.stream().map((s) -> E.valueOf(clazz, s)).collect(Collectors.toList()); } + public static Set toBlockData(List list, String phase, String id) throws InvalidConfigurationException { + Set bl = new HashSet<>(); + for(String s : list) { + try { + if(bl.contains(Bukkit.createBlockData(s).getMaterial())) Bukkit.getLogger().warning("Duplicate material in " + phase + " list: " + s); + bl.add(Bukkit.createBlockData(s).getMaterial()); + } catch(NullPointerException | IllegalArgumentException e) { + throw new ConfigException("Could not load BlockData data for \"" + s + "\"", id); + } + } + return bl; + } } diff --git a/src/main/java/com/dfsek/terra/config/WorldConfig.java b/src/main/java/com/dfsek/terra/config/base/WorldConfig.java similarity index 99% rename from src/main/java/com/dfsek/terra/config/WorldConfig.java rename to src/main/java/com/dfsek/terra/config/base/WorldConfig.java index 61394b706..f3bed28ab 100644 --- a/src/main/java/com/dfsek/terra/config/WorldConfig.java +++ b/src/main/java/com/dfsek/terra/config/base/WorldConfig.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.config; +package com.dfsek.terra.config.base; import com.dfsek.terra.Terra; import com.dfsek.terra.biome.UserDefinedBiome; diff --git a/src/main/java/com/dfsek/terra/config/exception/ConfigException.java b/src/main/java/com/dfsek/terra/config/exception/ConfigException.java new file mode 100644 index 000000000..d24b165b2 --- /dev/null +++ b/src/main/java/com/dfsek/terra/config/exception/ConfigException.java @@ -0,0 +1,21 @@ +package com.dfsek.terra.config.exception; + +import org.bukkit.configuration.InvalidConfigurationException; + +/** + * Thrown when a config item is not valid. + */ +public class ConfigException extends InvalidConfigurationException { + private final String message; + private final String id; + public ConfigException(String message, String id) { + this.message = message; + this.id = id; + } + + @Override + public String getMessage() { + String ex = getStackTrace()[0].getClassName(); + return "Configuration error for " + ex.substring(ex.lastIndexOf(".")+1) + " with ID \"" + id + "\": \n\n" + message; + } +} diff --git a/src/main/java/com/dfsek/terra/config/exception/NotFoundException.java b/src/main/java/com/dfsek/terra/config/exception/NotFoundException.java new file mode 100644 index 000000000..88c1f4124 --- /dev/null +++ b/src/main/java/com/dfsek/terra/config/exception/NotFoundException.java @@ -0,0 +1,10 @@ +package com.dfsek.terra.config.exception; + +/** + * Thrown when a required config item is not found. + */ +public class NotFoundException extends ConfigException { + public NotFoundException(String item, String itemName, String id) { + super(item + " \"" + itemName + "\" cannot be found!", id); + } +} diff --git a/src/main/java/com/dfsek/terra/config/genconfig/AbstractBiomeConfig.java b/src/main/java/com/dfsek/terra/config/genconfig/AbstractBiomeConfig.java index d919a0f98..6fb289de9 100644 --- a/src/main/java/com/dfsek/terra/config/genconfig/AbstractBiomeConfig.java +++ b/src/main/java/com/dfsek/terra/config/genconfig/AbstractBiomeConfig.java @@ -1,21 +1,11 @@ package com.dfsek.terra.config.genconfig; -import org.polydev.gaea.math.Range; -import com.dfsek.terra.TerraTree; -import com.dfsek.terra.config.ConfigUtil; +import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.TerraConfigObject; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.data.BlockData; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; -import org.polydev.gaea.math.ProbabilityCollection; -import org.polydev.gaea.tree.Tree; -import org.polydev.gaea.tree.TreeType; -import org.polydev.gaea.world.Flora; -import org.polydev.gaea.world.FloraType; import org.polydev.gaea.world.palette.Palette; -import org.polydev.gaea.world.palette.RandomPalette; import java.io.File; import java.io.IOException; @@ -23,8 +13,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Random; -import java.util.TreeMap; public class AbstractBiomeConfig extends TerraConfigObject { private static final Map biomes = new HashMap<>(); @@ -56,7 +44,7 @@ public class AbstractBiomeConfig extends TerraConfigObject { @Override public void init() throws InvalidConfigurationException { - if(!contains("id")) throw new InvalidConfigurationException("Abstract Biome ID unspecified!"); + if(!contains("id")) throw new ConfigException("Abstract Biome ID unspecified!", "null"); this.biomeID = getString("id"); if(contains("carving")) carvingData = getMapList("carving"); diff --git a/src/main/java/com/dfsek/terra/config/genconfig/BiomeConfig.java b/src/main/java/com/dfsek/terra/config/genconfig/BiomeConfig.java index ed72d9a54..d156694da 100644 --- a/src/main/java/com/dfsek/terra/config/genconfig/BiomeConfig.java +++ b/src/main/java/com/dfsek/terra/config/genconfig/BiomeConfig.java @@ -1,12 +1,14 @@ package com.dfsek.terra.config.genconfig; +import com.dfsek.terra.config.exception.ConfigException; +import com.dfsek.terra.config.exception.NotFoundException; import org.polydev.gaea.math.Range; import com.dfsek.terra.TerraTree; import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.generation.UserDefinedDecorator; import com.dfsek.terra.generation.UserDefinedGenerator; import com.dfsek.terra.carving.UserDefinedCarver; -import com.dfsek.terra.config.ConfigUtil; +import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.TerraConfigObject; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -63,9 +65,8 @@ public class BiomeConfig extends TerraConfigObject { @Override @SuppressWarnings("unchecked, rawtypes") public void init() throws InvalidConfigurationException { - if(!contains("id")) throw new InvalidConfigurationException("Biome ID unspecified!"); + if(!contains("id")) throw new ConfigException("Biome ID unspecified!", "null"); this.biomeID = getString("id"); - if(!contains("noise-equation") && !contains("extends")) throw new InvalidConfigurationException("Biomes must either include noise equation or extend biome containing an equation."); AbstractBiomeConfig abstractBiome = null; // Whether an abstract biome is to be extended. Default to false. @@ -77,7 +78,7 @@ public class BiomeConfig extends TerraConfigObject { extending = true; Bukkit.getLogger().info("Extending biome " + getString("extends")); } catch(NullPointerException e) { - throw new InvalidConfigurationException("No abstract biome, " +getString("extends") + ", found."); + throw new ConfigException("No abstract biome with ID " + getString("extends") + " found.", getID()); } } @@ -101,22 +102,22 @@ public class BiomeConfig extends TerraConfigObject { try { paletteMap.put((Integer) entry.getValue(), new RandomPalette(new Random(0)).add(new ProbabilityCollection().add(Bukkit.createBlockData(((String) entry.getKey()).substring(6)), 1), 1)); } catch(IllegalArgumentException ex) { - throw new InvalidConfigurationException("SEVERE configuration error for Palettes in biome ID: " + biomeID + ". BlockData " + entry.getKey() + " is invalid!"); + throw new ConfigException("BlockData " + entry.getKey() + " is invalid! (Palettes)", getID()); } } else { try { paletteMap.put((Integer) entry.getValue(), PaletteConfig.fromID((String) entry.getKey()).getPalette()); } catch(NullPointerException ex) { - throw new InvalidConfigurationException("SEVERE configuration error for Palettes in biome ID: " + biomeID + "\n\nPalette " + entry.getKey() + " cannot be found!"); + throw new NotFoundException("Palette", (String) entry.getKey(), getID()); } } } catch(ClassCastException ex) { - throw new InvalidConfigurationException("SEVERE configuration error for Palettes in biome ID: " + biomeID); + throw new ConfigException("Unable to parse Palette configuration! Check YAML syntax.", getID()); } } } - } else throw new InvalidConfigurationException("No palette specified in biome or super biome."); + } else throw new ConfigException("No Palette specified in biome or super biome.", getID()); // Check if carving should be handled by super biome. List> carvingData; @@ -138,9 +139,9 @@ public class BiomeConfig extends TerraConfigObject { Bukkit.getLogger().info("Got carver " + c + ". Adding with weight " + entry.getValue()); carvers.put(c, (Integer) entry.getValue()); } catch(ClassCastException ex) { - throw new InvalidConfigurationException("SEVERE configuration error for Carvers in biome ID: " + biomeID); + throw new ConfigException("Unable to parse Carver configuration! Check YAML syntax.", getID()); } catch(NullPointerException ex) { - throw new InvalidConfigurationException("SEVERE configuration error for Carvers in biome ID: " + biomeID + "\n\n" + "No such carver " + entry.getKey()); + throw new NotFoundException("carver", (String) entry.getKey(), getID()); } } } @@ -210,13 +211,13 @@ public class BiomeConfig extends TerraConfigObject { flora.add(floraCustom, (Integer) val.get("weight")); floraHeights.put(floraCustom, new Range((Integer) y.get("min"), (Integer) y.get("max"))); } catch(NullPointerException ex2) { - throw new InvalidConfigurationException("SEVERE configuration error for flora in biome ID " + getID() + "\n\nFlora with ID " + e.getKey() + " cannot be found!"); + throw new NotFoundException("Flora", e.getKey(), getID()); } } } } catch(ClassCastException e) { if(ConfigUtil.debug) e.printStackTrace(); - throw new InvalidConfigurationException("SEVERE configuration error for flora in biome ID " + getID()); + throw new ConfigException("Unable to parse Flora configuration! Check YAML syntax.", getID()); } } else flora = new ProbabilityCollection<>(); @@ -242,7 +243,7 @@ public class BiomeConfig extends TerraConfigObject { } else trees = new ProbabilityCollection<>(); //Make sure equation is non-null - if(eq == null) throw new InvalidConfigurationException("Noise equation must be specified in biome or super biome."); + if(eq == null || eq.equals("")) throw new ConfigException("Could not find noise equation! Biomes must include a noise equation, or extend an abstract biome with one.", getID()); // Create decorator for this config. UserDefinedDecorator dec = new UserDefinedDecorator(flora, trees, floraChance, treeChance, treeDensity); @@ -250,10 +251,10 @@ public class BiomeConfig extends TerraConfigObject { // Get Vanilla biome, throw exception if it is invalid/unspecified. org.bukkit.block.Biome vanillaBiome; try { - if(!contains("vanilla")) throw new InvalidConfigurationException("Vanilla Biome unspecified!"); + if(!contains("vanilla")) throw new ConfigException("Vanilla Biome unspecified!", getID()); vanillaBiome = org.bukkit.block.Biome.valueOf(getString("vanilla")); } catch(IllegalArgumentException e) { - throw new InvalidConfigurationException("Invalid Vanilla biome: " + getString("vanilla")); + throw new ConfigException("Invalid Vanilla biome: \"" + getString("vanilla") + "\"", getID()); } // Check if ores should be handled by super biome. @@ -290,13 +291,13 @@ public class BiomeConfig extends TerraConfigObject { try { ocean = new RandomPalette(new Random(0)).add(new ProbabilityCollection().add(Bukkit.createBlockData(oceanPalette.substring(6)), 1), 1); } catch(IllegalArgumentException ex) { - throw new InvalidConfigurationException("SEVERE configuration error for Ocean Palette in biome ID: " + biomeID + ". BlockData " + oceanPalette + " is invalid!"); + throw new ConfigException("BlockData \"" + oceanPalette + "\" is invalid! (Ocean Palette)", getID()); } } else { try { ocean = PaletteConfig.fromID(oceanPalette).getPalette(); } catch(NullPointerException ex) { - throw new InvalidConfigurationException("SEVERE configuration error for Ocean Palette in biome ID: " + biomeID + "\n\nPalette " + oceanPalette + " cannot be found!"); + throw new NotFoundException("Palette", oceanPalette, getID()); } } } else ocean = oceanDefault; @@ -328,7 +329,7 @@ public class BiomeConfig extends TerraConfigObject { } } catch(ClassCastException e) { if(ConfigUtil.debug) e.printStackTrace(); - throw new InvalidConfigurationException("Material in stair config is not stair."); + throw new ConfigException("Materials in stair config must be stairs.", getID()); } } Bukkit.getLogger().info("[Terra] Slabs: " + slabs.size()); @@ -343,7 +344,7 @@ public class BiomeConfig extends TerraConfigObject { try { structures.add(Objects.requireNonNull(StructureConfig.fromID(s))); } catch(NullPointerException e) { - throw new InvalidConfigurationException("No such structure " + s); + throw new NotFoundException("Structure", s, getID()); } } @@ -352,7 +353,7 @@ public class BiomeConfig extends TerraConfigObject { this.biome = new UserDefinedBiome(vanillaBiome, dec, new UserDefinedGenerator(eq, Collections.emptyList(), paletteMap), biomeID); } catch(ParseException e) { e.printStackTrace(); - throw new IllegalArgumentException("Unable to parse noise equation!"); + throw new ConfigException("Unable to parse noise equation!", getID()); } biomes.put(biomeID, this); } diff --git a/src/main/java/com/dfsek/terra/config/genconfig/BiomeConfigUtil.java b/src/main/java/com/dfsek/terra/config/genconfig/BiomeConfigUtil.java index 7522834ab..0162f99b3 100644 --- a/src/main/java/com/dfsek/terra/config/genconfig/BiomeConfigUtil.java +++ b/src/main/java/com/dfsek/terra/config/genconfig/BiomeConfigUtil.java @@ -1,6 +1,8 @@ package com.dfsek.terra.config.genconfig; +import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.TerraConfigObject; +import com.dfsek.terra.config.exception.NotFoundException; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.data.BlockData; @@ -26,7 +28,7 @@ public class BiomeConfigUtil { Bukkit.getLogger().info("Adding slab palette with single material " + entry.getKey()); paletteMap.put(Bukkit.createBlockData((String) entry.getKey()).getMaterial(), new RandomPalette(new Random(0)).add(new ProbabilityCollection().add(Bukkit.createBlockData(((String) entry.getValue()).substring(6)), 1), 1)); } catch(IllegalArgumentException ex) { - throw new InvalidConfigurationException("SEVERE configuration error for Slab Palettes in biome " + config.getID() + ": " + ex.getMessage()); + throw new ConfigException("Invalid BlockData in slab configuration: " + ex.getMessage(), config.getID()); } } else { try { @@ -34,11 +36,11 @@ public class BiomeConfigUtil { if(p.getSize() != 1) throw new InvalidConfigurationException("Slab palette must hold only one layer. Palette " + entry.getValue() + " is too large/small"); paletteMap.put(Bukkit.createBlockData((String) entry.getKey()).getMaterial(), p); } catch(NullPointerException ex) { - throw new InvalidConfigurationException("SEVERE configuration error for Slab Palettes in biome " + config.getID() + "\n\nPalette " + entry.getValue() + " cannot be found!"); + throw new NotFoundException("Slab Palette", (String) entry.getValue(), config.getID()); } } } catch(ClassCastException ex) { - throw new InvalidConfigurationException("SEVERE configuration error for Slab Palettes in biome " + config.getID()); + throw new ConfigException("Unable to parse Slab Palette configuration! Check YAML syntax.", config.getID()); } } } diff --git a/src/main/java/com/dfsek/terra/config/genconfig/BiomeGridConfig.java b/src/main/java/com/dfsek/terra/config/genconfig/BiomeGridConfig.java index f42b410fa..41d12de74 100644 --- a/src/main/java/com/dfsek/terra/config/genconfig/BiomeGridConfig.java +++ b/src/main/java/com/dfsek/terra/config/genconfig/BiomeGridConfig.java @@ -2,12 +2,12 @@ package com.dfsek.terra.config.genconfig; import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedGrid; -import com.dfsek.terra.config.ConfigLoader; import com.dfsek.terra.config.TerraConfigObject; -import com.dfsek.terra.config.WorldConfig; +import com.dfsek.terra.config.base.WorldConfig; +import com.dfsek.terra.config.exception.ConfigException; +import com.dfsek.terra.config.exception.NotFoundException; import org.bukkit.World; import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.io.IOException; @@ -29,11 +29,12 @@ public class BiomeGridConfig extends TerraConfigObject { } @Override + @SuppressWarnings("unchecked") public void init() throws InvalidConfigurationException { isEnabled = false; - if(!contains("id")) throw new InvalidConfigurationException("Grid ID unspecified!"); + if(!contains("id")) throw new ConfigException("Grid ID unspecified!", "null"); this.gridID = getString("id"); - if(!contains("grid")) throw new InvalidConfigurationException("Grid not found!"); + if(!contains("grid")) throw new ConfigException("Grid key not found!", getID()); this.sizeX = Objects.requireNonNull(getList("grid")).size(); this.sizeZ = ((List>) getList("grid")).get(0).size(); gridRaw = new UserDefinedBiome[sizeX][sizeZ]; @@ -41,14 +42,14 @@ public class BiomeGridConfig extends TerraConfigObject { for(int x = 0; x < sizeX; x++) { for(int z = 0; z < sizeZ; z++) { try { - gridRaw[x][z] = BiomeConfig.fromID(((List>) getList("grid")).get(x).get(z)).getBiome(); + gridRaw[x][z] = BiomeConfig.fromID(((List>) Objects.requireNonNull(getList("grid"))).get(x).get(z)).getBiome(); } catch(NullPointerException e) { - throw new InvalidConfigurationException("SEVERE configuration error for BiomeGrid ID: " + getID() + "\n\nNo such biome " + ((List>) getList("grid")).get(x).get(z)); + throw new NotFoundException("Biome",((List>) Objects.requireNonNull(getList("grid"))).get(x).get(z), getID()); } } } - } catch(ClassCastException e) { - throw new InvalidConfigurationException("Malformed grid!"); + } catch(ClassCastException |NullPointerException e) { + throw new ConfigException("Malformed grid! Ensure all dimensions are correct.", getID()); } isEnabled = true; biomeGrids.put(gridID, this); diff --git a/src/main/java/com/dfsek/terra/config/genconfig/CarverConfig.java b/src/main/java/com/dfsek/terra/config/genconfig/CarverConfig.java index 962b8721e..03824f1cd 100644 --- a/src/main/java/com/dfsek/terra/config/genconfig/CarverConfig.java +++ b/src/main/java/com/dfsek/terra/config/genconfig/CarverConfig.java @@ -1,5 +1,7 @@ package com.dfsek.terra.config.genconfig; +import com.dfsek.terra.config.base.ConfigUtil; +import com.dfsek.terra.config.exception.ConfigException; import org.polydev.gaea.math.Range; import com.dfsek.terra.carving.UserDefinedCarver; import com.dfsek.terra.config.TerraConfigObject; @@ -52,6 +54,9 @@ public class CarverConfig extends TerraConfigObject { @Override public void init() throws InvalidConfigurationException { + if(!contains("id")) throw new ConfigException("No ID specified for Carver!", "null"); + id = getString("id"); + inner = getBlocks("palette.inner.blocks"); outer = getBlocks("palette.outer.blocks"); @@ -60,53 +65,16 @@ public class CarverConfig extends TerraConfigObject { bottom = getBlocks("palette.bottom.blocks"); - replaceableInner = new HashSet<>(); - replaceableOuter = new HashSet<>(); - replaceableTop = new HashSet<>(); - replaceableBottom = new HashSet<>(); + replaceableInner = ConfigUtil.toBlockData(getStringList("palette.inner.replace"), "replaceable inner", getID()); - for(String s : getStringList("palette.inner.replace")) { - try { - if(replaceableInner.contains(Bukkit.createBlockData(s).getMaterial())) Bukkit.getLogger().warning("Duplicate material in replaceable list: " + s); - replaceableInner.add(Bukkit.createBlockData(s).getMaterial()); - } catch(NullPointerException | IllegalArgumentException e) { - throw new InvalidConfigurationException("Could not load data for " + s); - } - } - for(String s : getStringList("palette.outer.replace")) { - try { - if(replaceableOuter.contains(Bukkit.createBlockData(s).getMaterial())) Bukkit.getLogger().warning("Duplicate material in replaceable list: " + s); - replaceableOuter.add(Bukkit.createBlockData(s).getMaterial()); - } catch(NullPointerException | IllegalArgumentException e) { - throw new InvalidConfigurationException("Could not load data for " + s); - } - } - for(String s : getStringList("palette.top.replace")) { - try { - if(replaceableTop.contains(Bukkit.createBlockData(s).getMaterial())) Bukkit.getLogger().warning("Duplicate material in replaceable list: " + s); - replaceableTop.add(Bukkit.createBlockData(s).getMaterial()); - } catch(NullPointerException | IllegalArgumentException e) { - throw new InvalidConfigurationException("Could not load data for " + s); - } - } - for(String s : getStringList("palette.bottom.replace")) { - try { - if(replaceableBottom.contains(Bukkit.createBlockData(s).getMaterial())) Bukkit.getLogger().warning("Duplicate material in replaceable list: " + s); - replaceableBottom.add(Bukkit.createBlockData(s).getMaterial()); - } catch(NullPointerException | IllegalArgumentException e) { - throw new InvalidConfigurationException("Could not load data for " + s); - } - } + replaceableOuter = ConfigUtil.toBlockData(getStringList("palette.outer.replace"), "replaceable outer", getID()); + + replaceableTop = ConfigUtil.toBlockData(getStringList("palette.top.replace"), "replaceable top", getID()); + + replaceableBottom = ConfigUtil.toBlockData(getStringList("palette.bottom.replace"), "replaceable bottom", getID()); + + update = ConfigUtil.toBlockData(getStringList("update"), "update", getID()); - update = new HashSet<>(); - for(String s : getStringList("update")) { - try { - if(update.contains(Bukkit.createBlockData(s).getMaterial())) Bukkit.getLogger().warning("Duplicate material in update list: " + s); - update.add(Bukkit.createBlockData(s).getMaterial()); - } catch(NullPointerException | IllegalArgumentException e) { - throw new InvalidConfigurationException("Could not load data for " + s); - } - } shift = new HashMap<>(); for(Map.Entry e : getConfigurationSection("shift").getValues(false).entrySet()) { Set l = new HashSet<>(); @@ -129,14 +97,13 @@ public class CarverConfig extends TerraConfigObject { Range length = new Range(getInt("length.min"), getInt("length.max")); Range radius = new Range(getInt("start.radius.min"), getInt("start.radius.max")); Range height = new Range(getInt("start.height.min"), getInt("start.height.max")); - id = getString("id"); - if(id == null) throw new InvalidConfigurationException("No ID specified for Carver!"); + carver = new UserDefinedCarver(height, radius, length, start, mutate, radiusMultiplier, id.hashCode(), getInt("cut.top", 0), getInt("cut.bottom", 0)); caveConfig.put(id, this); } private Map> getBlocks(String key) throws InvalidConfigurationException { - if(!contains(key)) throw new InvalidConfigurationException("Missing Carver Palette!"); + if(!contains(key)) throw new ConfigException("Missing Carver Palette!", getID()); Map> result = new TreeMap<>(); for(Map m : getMapList(key)) { try { @@ -148,7 +115,7 @@ public class CarverConfig extends TerraConfigObject { result.put((Integer) m.get("y"), layer); Bukkit.getLogger().info("Added at level " + m.get("y")); } catch(ClassCastException e) { - throw new InvalidConfigurationException("SEVERE configuration error for Carver Palette: \n\n" + e.getMessage()); + throw new ConfigException("Unable to parse Carver Palette configuration! Check YAML syntax:" + e.getMessage(), getID()); } } return result; diff --git a/src/main/java/com/dfsek/terra/config/genconfig/FloraConfig.java b/src/main/java/com/dfsek/terra/config/genconfig/FloraConfig.java index acd3f5714..76a7fe322 100644 --- a/src/main/java/com/dfsek/terra/config/genconfig/FloraConfig.java +++ b/src/main/java/com/dfsek/terra/config/genconfig/FloraConfig.java @@ -1,6 +1,8 @@ package com.dfsek.terra.config.genconfig; import com.dfsek.terra.config.TerraConfigObject; +import com.dfsek.terra.config.base.ConfigUtil; +import com.dfsek.terra.config.exception.ConfigException; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; @@ -37,36 +39,18 @@ public class FloraConfig extends TerraConfigObject implements Flora { @Override public void init() throws InvalidConfigurationException { - if(!contains("blocks")) throw new InvalidConfigurationException("No blocks defined in custom flora!"); - if(!contains("id")) throw new InvalidConfigurationException("Flora ID unspecified!"); - if(!contains("name")) throw new InvalidConfigurationException("Flora name unspecified!"); - if(!contains("spawnable")) throw new InvalidConfigurationException("Flora spawnable blocks unspecified!"); + if(!contains("id")) throw new ConfigException("Flora ID unspecified!", "null"); + this.id = getString("id"); + if(!contains("blocks")) throw new ConfigException("No blocks defined in custom flora!", getID()); + if(!contains("spawnable")) throw new ConfigException("Flora spawnable blocks unspecified!", getID()); - spawnable = new HashSet<>(); - replaceable = new HashSet<>(); - - try { - for(String s : getStringList("spawnable")) { - spawnable.add(Bukkit.createBlockData(s).getMaterial()); - } - Bukkit.getLogger().info("[Terra] Added " + spawnable.size() + " items to spawnable list."); - } catch(IllegalArgumentException e) { - throw new InvalidConfigurationException("Invalid material ID in spawnable list: " + e.getMessage()); - } - try { - for(String s : getStringList("replaceable")) { - replaceable.add(Bukkit.createBlockData(s).getMaterial()); - } - Bukkit.getLogger().info("[Terra] Added " + spawnable.size() + " items to replaceable list."); - } catch(IllegalArgumentException e) { - throw new InvalidConfigurationException("Invalid material ID in replaceable list: " + e.getMessage()); - } + spawnable = ConfigUtil.toBlockData(getStringList("spawnable"), "spawnable", getID()); + replaceable = ConfigUtil.toBlockData(getStringList("replaceable"), "replaceable", getID()); Palette p = new RandomPalette<>(new Random(getInt("seed", 4))); floraPalette = PaletteConfig.getPalette(getMapList("blocks"), p); - if(!contains("id")) throw new InvalidConfigurationException("Flora ID unspecified!"); - this.id = getString("id"); + floraConfig.put(id, this); } diff --git a/src/main/java/com/dfsek/terra/config/genconfig/OreConfig.java b/src/main/java/com/dfsek/terra/config/genconfig/OreConfig.java index 96ad689ee..272a01110 100644 --- a/src/main/java/com/dfsek/terra/config/genconfig/OreConfig.java +++ b/src/main/java/com/dfsek/terra/config/genconfig/OreConfig.java @@ -1,7 +1,8 @@ package com.dfsek.terra.config.genconfig; -import com.dfsek.terra.config.ConfigUtil; +import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.TerraConfigObject; +import com.dfsek.terra.config.exception.ConfigException; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -18,6 +19,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Random; +import java.util.Set; public class OreConfig extends TerraConfigObject { private static final Map ores = new HashMap<>(); @@ -27,33 +29,29 @@ public class OreConfig extends TerraConfigObject { private double deform; private double deformFrequency; private String id; - List replaceable; + Set replaceable; public OreConfig(File file) throws IOException, InvalidConfigurationException { super(file); } @Override public void init() throws InvalidConfigurationException { - if(!contains("material")) throw new InvalidConfigurationException("Ore material not found!"); - if(!contains("deform")) throw new InvalidConfigurationException("Ore vein deformation not found!"); - if(!contains("id")) throw new InvalidConfigurationException("Ore ID not found!"); - if(!contains("replace")) throw new InvalidConfigurationException("Ore replaceable materials not found!"); + if(!contains("id")) throw new ConfigException("Ore ID not found!", "null"); + this.id = getString("id"); + if(!contains("material")) throw new ConfigException("Ore material not found!", getID()); + if(!contains("deform")) throw new ConfigException("Ore vein deformation not found!", getID()); + if(!contains("replace")) throw new ConfigException("Ore replaceable materials not found!", getID()); min = getInt("radius.min", 1); max = getInt("radius.max", 1); deform = getDouble("deform"); deformFrequency = getDouble("deform-frequency"); - this.id = getString("id"); - try { - replaceable = ConfigUtil.getElements(getStringList("replace"), Material.class); - } catch(IllegalArgumentException e) { - throw new InvalidConfigurationException("Invalid material ID in replace list: " + e.getMessage()); - } + replaceable = ConfigUtil.toBlockData(getStringList("replace"), "replaceable", getID()); try { oreData = Bukkit.createBlockData(Objects.requireNonNull(getString("material"))); } catch(NullPointerException | IllegalArgumentException e) { - throw new InvalidConfigurationException("Invalid ore material: " + getString("material")); + throw new ConfigException("Invalid ore material: " + getString("material"), getID()); } ores.put(id, this); } diff --git a/src/main/java/com/dfsek/terra/config/genconfig/PaletteConfig.java b/src/main/java/com/dfsek/terra/config/genconfig/PaletteConfig.java index 03490166e..0d7eafc71 100644 --- a/src/main/java/com/dfsek/terra/config/genconfig/PaletteConfig.java +++ b/src/main/java/com/dfsek/terra/config/genconfig/PaletteConfig.java @@ -1,6 +1,7 @@ package com.dfsek.terra.config.genconfig; import com.dfsek.terra.config.TerraConfigObject; +import com.dfsek.terra.config.exception.ConfigException; import org.bukkit.Bukkit; import org.bukkit.block.data.BlockData; import org.bukkit.configuration.InvalidConfigurationException; @@ -28,6 +29,8 @@ public class PaletteConfig extends TerraConfigObject { @Override public void init() throws InvalidConfigurationException { + if(!contains("id")) throw new ConfigException("Palette ID unspecified!", "null"); + this.paletteID = getString("id"); Palette pal; if(getBoolean("simplex", false)) { useNoise = true; @@ -38,8 +41,6 @@ public class PaletteConfig extends TerraConfigObject { pal = new SimplexPalette<>(pNoise); } else pal = new RandomPalette<>(new Random(getInt("seed", 3))); palette = getPalette(getMapList("blocks"), pal); - if(!contains("id")) throw new InvalidConfigurationException("Palette ID unspecified!"); - this.paletteID = getString("id"); palettes.put(paletteID, this); } @@ -72,7 +73,6 @@ public class PaletteConfig extends TerraConfigObject { } p.add(Bukkit.createBlockData(data), (Integer) m.get("layers")); } - } catch(ClassCastException e) { throw new InvalidConfigurationException("SEVERE configuration error for Palette: \n\n" + e.getMessage()); } diff --git a/src/main/java/com/dfsek/terra/config/genconfig/StructureConfig.java b/src/main/java/com/dfsek/terra/config/genconfig/StructureConfig.java index 7965424f9..61c9407cf 100644 --- a/src/main/java/com/dfsek/terra/config/genconfig/StructureConfig.java +++ b/src/main/java/com/dfsek/terra/config/genconfig/StructureConfig.java @@ -1,8 +1,10 @@ package com.dfsek.terra.config.genconfig; +import com.dfsek.terra.config.exception.ConfigException; +import com.dfsek.terra.config.exception.NotFoundException; import org.polydev.gaea.math.Range; import com.dfsek.terra.Terra; -import com.dfsek.terra.config.ConfigUtil; +import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.TerraConfigObject; import com.dfsek.terra.population.StructurePopulator; import com.dfsek.terra.structure.GaeaStructure; @@ -29,6 +31,8 @@ public class StructureConfig extends TerraConfigObject { @Override public void init() throws InvalidConfigurationException { + if(!contains("id")) throw new ConfigException("No ID specified!", "null"); + id = getString("id"); try { File file = new File(Terra.getInstance().getDataFolder() + File.separator + "config" + File.separator + "structures" + File.separator + "data", Objects.requireNonNull(getString("file"))); structure = GaeaStructure.load(file); @@ -36,17 +40,16 @@ public class StructureConfig extends TerraConfigObject { if(ConfigUtil.debug) { e.printStackTrace(); } - throw new InvalidConfigurationException("Unable to locate structure: " + getString("file")); + throw new NotFoundException("Structure", getString("file"), getID()); } - if(!contains("id")) throw new InvalidConfigurationException("No ID specified!"); - id = getString("id"); + spawn = new GridSpawn(getInt("spawn.width", 500), getInt("spawn.padding", 100)); searchStart = new Range(getInt("spawn.start.min", 72), getInt("spawn.start.max", 72)); bound = new Range(getInt("spawn.bound.min", 48), getInt("spawn.bound.max", 72)); try { type = StructurePopulator.SearchType.valueOf(getString("spawn.search", "DOWN")); } catch(IllegalArgumentException e) { - throw new InvalidConfigurationException("Invalid search type, " + getString("spawn.search")); + throw new ConfigException("Invalid search type, " + getString("spawn.search"), getID()); } configs.put(id, this); } diff --git a/src/main/java/com/dfsek/terra/image/DebugFrame.java b/src/main/java/com/dfsek/terra/image/DebugFrame.java index 0756e8be5..28da754a2 100644 --- a/src/main/java/com/dfsek/terra/image/DebugFrame.java +++ b/src/main/java/com/dfsek/terra/image/DebugFrame.java @@ -3,7 +3,7 @@ package com.dfsek.terra.image; import com.dfsek.terra.generation.TerraChunkGenerator; import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.UserDefinedBiome; -import com.dfsek.terra.config.WorldConfig; +import com.dfsek.terra.config.base.WorldConfig; import com.dfsek.terra.config.genconfig.BiomeConfig; import org.bukkit.Bukkit; import org.bukkit.entity.Player; diff --git a/src/main/java/com/dfsek/terra/image/ImageLoader.java b/src/main/java/com/dfsek/terra/image/ImageLoader.java index 5b2f0a438..c66938df4 100644 --- a/src/main/java/com/dfsek/terra/image/ImageLoader.java +++ b/src/main/java/com/dfsek/terra/image/ImageLoader.java @@ -2,9 +2,7 @@ package com.dfsek.terra.image; import com.dfsek.terra.biome.BiomeZone; import com.dfsek.terra.biome.TerraBiomeGrid; -import com.dfsek.terra.config.ConfigUtil; -import com.dfsek.terra.config.genconfig.BiomeConfig; -import org.bukkit.Location; +import com.dfsek.terra.config.base.ConfigUtil; import org.bukkit.World; import org.polydev.gaea.biome.NormalizationUtil; @@ -12,8 +10,6 @@ import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import javax.imageio.ImageIO; diff --git a/src/main/java/com/dfsek/terra/image/WorldImageGenerator.java b/src/main/java/com/dfsek/terra/image/WorldImageGenerator.java index 82c1c1c21..8e371ba7a 100644 --- a/src/main/java/com/dfsek/terra/image/WorldImageGenerator.java +++ b/src/main/java/com/dfsek/terra/image/WorldImageGenerator.java @@ -2,7 +2,6 @@ package com.dfsek.terra.image; import com.dfsek.terra.biome.BiomeZone; import com.dfsek.terra.biome.TerraBiomeGrid; -import com.dfsek.terra.config.WorldConfig; import org.bukkit.World; import org.polydev.gaea.biome.NormalizationUtil; diff --git a/src/main/java/com/dfsek/terra/population/CavePopulator.java b/src/main/java/com/dfsek/terra/population/CavePopulator.java index 15f3b63a8..715478f17 100644 --- a/src/main/java/com/dfsek/terra/population/CavePopulator.java +++ b/src/main/java/com/dfsek/terra/population/CavePopulator.java @@ -1,7 +1,7 @@ package com.dfsek.terra.population; import com.dfsek.terra.TerraProfiler; -import com.dfsek.terra.config.ConfigUtil; +import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.genconfig.CarverConfig; import org.bukkit.Chunk; import org.bukkit.Location; @@ -17,7 +17,6 @@ import org.polydev.gaea.world.carving.CarvingData; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set;