Implement new config exceptions, general config cleanup

This commit is contained in:
dfsek 2020-10-01 10:33:55 -07:00
parent 88067a04c8
commit a5c85a7e5d
28 changed files with 249 additions and 166 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<Command> getSubCommands();
/**
* Executes the given command, returning its success.
* <br>
* 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.
* <br>
* 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()) {

View File

@ -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.
* <br>
* 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.
* <br>
* 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);
}

View File

@ -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.
* <br>
* 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.
* <br>
* 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);
}

View File

@ -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 {

View File

@ -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 <E extends Enum<E>> List<E> getElements(List<String> st, Class<E> clazz) {
return st.stream().map((s) -> E.valueOf(clazz, s)).collect(Collectors.toList());
}
public static Set<Material> toBlockData(List<String> list, String phase, String id) throws InvalidConfigurationException {
Set<Material> 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;
}
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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<String, AbstractBiomeConfig> 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");

View File

@ -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<BlockData>(new Random(0)).add(new ProbabilityCollection<BlockData>().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<Map<?, ?>> 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<BlockData>(new Random(0)).add(new ProbabilityCollection<BlockData>().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);
}

View File

@ -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<BlockData>(new Random(0)).add(new ProbabilityCollection<BlockData>().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());
}
}
}

View File

@ -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<List<String>>) 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<List<String>>) getList("grid")).get(x).get(z)).getBiome();
gridRaw[x][z] = BiomeConfig.fromID(((List<List<String>>) 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<List<String>>) getList("grid")).get(x).get(z));
throw new NotFoundException("Biome",((List<List<String>>) 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);

View File

@ -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<String, Object> e : getConfigurationSection("shift").getValues(false).entrySet()) {
Set<Material> 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<Integer, ProbabilityCollection<BlockData>> 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<Integer, ProbabilityCollection<BlockData>> 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;

View File

@ -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<BlockData> 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);
}

View File

@ -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<String, OreConfig> ores = new HashMap<>();
@ -27,33 +29,29 @@ public class OreConfig extends TerraConfigObject {
private double deform;
private double deformFrequency;
private String id;
List<Material> replaceable;
Set<Material> 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);
}

View File

@ -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<BlockData> 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());
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;