Clean up debug info

This commit is contained in:
dfsek 2020-10-01 18:22:38 -07:00
parent 576365b688
commit e36e5f390c
15 changed files with 68 additions and 53 deletions

View File

@ -0,0 +1,23 @@
package com.dfsek.terra;
import com.dfsek.terra.config.base.ConfigUtil;
import org.bukkit.plugin.java.JavaPlugin;
public class Debug {
public static JavaPlugin main;
public static void setMain(JavaPlugin main) {
Debug.main = main;
}
public static void info(String message) {
if(ConfigUtil.debug) main.getLogger().info(message);
}
public static void warn(String message) {
if(ConfigUtil.debug) main.getLogger().warning(message);
}
public static void error(String message) {
if(ConfigUtil.debug) main.getLogger().severe(message);
}
}

View File

@ -34,6 +34,7 @@ public class Terra extends JavaPlugin {
@Override
public void onEnable() {
instance = this;
Debug.setMain(this);
ConfigUtil.loadConfig(this);
PluginCommand command = getCommand("terra");

View File

@ -35,7 +35,7 @@ public enum TerraTree implements Tree {
this.permutations = number;
this.validSpawns = validSpawns;
for(int i = 0; i < number; i++) {
Bukkit.getLogger().info("[Terra] Loading tree " + directory + i + " to memory.");
Debug.info("[Terra] Loading tree " + directory + i + " to memory.");
loadedStructures.put(directory+i, NMSStructure.getAsTag(TerraTree.class.getResourceAsStream(directory + i + ".nbt")));
}
}

View File

@ -7,6 +7,7 @@ import com.dfsek.terra.biome.UserDefinedGrid;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.exception.NotFoundException;
import com.dfsek.terra.config.genconfig.BiomeGridConfig;
import com.dfsek.terra.generation.TerraChunkGenerator;
import org.bukkit.Bukkit;
@ -16,13 +17,12 @@ import java.util.HashMap;
import java.util.Map;
public class TerraWorld {
private static Map<World, TerraWorld> map = new HashMap<>();
private static final Map<World, TerraWorld> map = new HashMap<>();
private final TerraBiomeGrid grid;
private final BiomeZone zone;
private final TerraConfig config;
private final WorldConfig worldConfig;
private static final Object lock = new Object();
public TerraWorld(World w) {
private TerraWorld(World w) {
worldConfig = new WorldConfig(w, Terra.getInstance());
config = worldConfig.getConfig();
UserDefinedGrid[] definedGrids = new UserDefinedGrid[config.biomeList.size()];
@ -37,12 +37,12 @@ public class TerraWorld {
Terra.getInstance().getLogger().info("Loaded single-biome grid " + partName);
} else {
BiomeGridConfig g = config.getBiomeGrid(partName);
Bukkit.getLogger().info(g.getID());
Debug.info(g.getID());
definedGrids[i] = g.getGrid(w, worldConfig);
}
} catch(NullPointerException e) {
if(ConfigUtil.debug) e.printStackTrace();
Bukkit.getLogger().severe("No such BiomeGrid " + partName);
Bukkit.getLogger().severe("No suck BiomeGrid " + partName);
}
}
zone = new BiomeZone(w, worldConfig, definedGrids);
@ -50,10 +50,8 @@ public class TerraWorld {
}
public static TerraWorld getWorld(World w) {
synchronized(lock) {
return map.computeIfAbsent(w, TerraWorld::new);
}
}
public TerraBiomeGrid getGrid() {
return grid;

View File

@ -19,12 +19,12 @@ import java.util.stream.Stream;
public class ConfigLoader {
public static <T extends TerraConfigObject> Map<String, T> load(JavaPlugin main, Path file, TerraConfig config, Class<T> clazz) {
long l = System.nanoTime();
Map<String, T> configs = new HashMap<>();
file.toFile().mkdirs();
List<String> ids = new ArrayList<>();
try (Stream<Path> paths = Files.walk(file)) {
paths
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
paths.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
.forEach(path -> {
try {
Constructor<T> c = clazz.getConstructor(File.class, TerraConfig.class);
@ -42,6 +42,7 @@ public class ConfigLoader {
main.getLogger().severe("Correct this before proceeding!");
}
});
main.getLogger().info("\nLoaded " + configs.size() + " " + clazz.getSimpleName() + "(s) in " + (System.nanoTime() - l) / 1000000D + "ms.\n");
} catch(IOException e) {
e.printStackTrace();
}

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.config;
import com.dfsek.terra.Debug;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.exception.ConfigException;
@ -24,6 +25,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.util.stream.Collectors;
public class TerraConfig extends YamlConfiguration {
@ -52,8 +54,10 @@ public class TerraConfig extends YamlConfiguration {
public boolean perturbPaletteOnly;
public TerraConfig(JavaPlugin main, File file) throws IOException, InvalidConfigurationException {
long l = System.nanoTime();
load(new File(file, "config.yml"));
dataFolder = file;
Logger logger = main.getLogger();
if(!contains("id")) throw new ConfigException("No ID specified!", "null");
this.id = getString("id");
@ -87,6 +91,7 @@ public class TerraConfig extends YamlConfiguration {
biomeList = getStringList("grids");
configs.put(id, this);
logger.info("\n\nLoaded config \"" + getID() + "\" in " + (System.nanoTime() - l)/1000000D + "ms\n\n\n");
}
public Map<String, AbstractBiomeConfig> getAbstractBiomes() {
@ -140,9 +145,6 @@ public class TerraConfig extends YamlConfiguration {
for(BiomeConfig biome : biomes.values()) {
if(biome.getBiome().equals(b)) return biome;
}
for(BiomeConfig biome : biomes.values()) {
Bukkit.getLogger().info(biome.getID() + ":" + biome.hashCode() + " : " + b.getID() + ":" + b.hashCode());
}
throw new IllegalArgumentException("No BiomeConfig for provided biome.");
}
@ -186,7 +188,7 @@ public class TerraConfig extends YamlConfiguration {
}
public BiomeGridConfig getBiomeGrid(String id) {
Bukkit.getLogger().info(id + ", " + grids.get(id).getID());
Debug.info(id + ", " + grids.get(id).getID());
return grids.get(id);
}
}

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.Debug;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.exception.NotFoundException;
@ -75,7 +76,7 @@ public class BiomeConfig extends TerraConfigObject {
try {
abstractBiome = config.getAbstractBiomes().get(getString("extends"));
extending = true;
Bukkit.getLogger().info("Extending biome " + getString("extends"));
Debug.info("Extending biome " + getString("extends"));
} catch(NullPointerException e) {
throw new ConfigException("No abstract biome with ID " + getString("extends") + " found.", getID());
}
@ -87,7 +88,7 @@ public class BiomeConfig extends TerraConfigObject {
try {
if(extending && abstractBiome.getPaletteData() != null && ! contains("palette")) {
paletteData = abstractBiome.getPaletteData();
Bukkit.getLogger().info("Using super palette");
Debug.info("Using super palette");
} else paletteData = getMapList("palette");
} catch(NullPointerException e) {
paletteData = null;
@ -123,7 +124,7 @@ public class BiomeConfig extends TerraConfigObject {
try {
if(extending && abstractBiome.getCarvingData() != null && ! contains("carving")) {
carvingData = abstractBiome.getCarvingData();
Bukkit.getLogger().info("Using super carvers");
Debug.info("Using super carvers");
} else carvingData = getMapList("carving");
} catch(NullPointerException e) {
carvingData = null;
@ -135,7 +136,7 @@ public class BiomeConfig extends TerraConfigObject {
for(Map.Entry<?, ?> entry : e.entrySet()) {
try {
CarverConfig c = getConfig().getCarver((String) entry.getKey());
Bukkit.getLogger().info("Got carver " + c + ". Adding with weight " + entry.getValue());
Debug.info("Got carver " + c + ". Adding with weight " + entry.getValue());
carvers.put(c, (Integer) entry.getValue());
} catch(ClassCastException ex) {
throw new ConfigException("Unable to parse Carver configuration! Check YAML syntax.", getID());
@ -187,7 +188,7 @@ public class BiomeConfig extends TerraConfigObject {
try {
if(extending && abstractBiome.getFloraData() != null && ! contains("flora")) {
floraData = abstractBiome.getFloraData();
Bukkit.getLogger().info("Using super flora (" + flora.size() + " entries, " + floraChance + " % chance)");
Debug.info("Using super flora (" + flora.size() + " entries, " + floraChance + " % chance)");
} else floraData = Objects.requireNonNull(getConfigurationSection("flora")).getValues(false);
} catch(NullPointerException e) {
floraData = null;
@ -199,13 +200,13 @@ public class BiomeConfig extends TerraConfigObject {
Map<?, ?> val = ((ConfigurationSection) e.getValue()).getValues(false);
Map<?, ?> y = ((ConfigurationSection) val.get("y")).getValues(false);
try {
Bukkit.getLogger().info("[Terra] Adding " + e.getKey() + " to biome's flora list with weight " + e.getValue());
Debug.info("Adding " + e.getKey() + " to biome's flora list with weight " + e.getValue());
Flora floraObj = FloraType.valueOf(e.getKey());
flora.add(floraObj, (Integer) val.get("weight"));
floraHeights.put(floraObj, new Range((Integer) y.get("min"), (Integer) y.get("max")));
} catch(IllegalArgumentException ex) {
try {
Bukkit.getLogger().info("[Terra] Is custom flora: true");
Debug.info("[Terra] Is custom flora: true");
Flora floraCustom = getConfig().getFlora(e.getKey());
flora.add(floraCustom, (Integer) val.get("weight"));
floraHeights.put(floraCustom, new Range((Integer) y.get("min"), (Integer) y.get("max")));
@ -226,7 +227,7 @@ public class BiomeConfig extends TerraConfigObject {
try {
if(extending && abstractBiome.getTreeData() != null && ! contains("trees")) {
treeData = abstractBiome.getTreeData();
Bukkit.getLogger().info("Using super trees");
Debug.info("Using super trees");
} else treeData = Objects.requireNonNull(getConfigurationSection("trees")).getValues(false);
} catch(NullPointerException e) {
treeData = null;
@ -263,7 +264,7 @@ public class BiomeConfig extends TerraConfigObject {
try {
if(extending && abstractBiome.getOreData() != null && ! contains("ores")) {
oreData = abstractBiome.getOreData();
Bukkit.getLogger().info("Using super ores");
Debug.info("Using super ores");
} else oreData = Objects.requireNonNull(getConfigurationSection("ores")).getValues(false);
} catch(NullPointerException e) {
oreData = null;
@ -309,7 +310,7 @@ public class BiomeConfig extends TerraConfigObject {
if(abstractBiome.shouldUseStairs()) {
stairs = abstractBiome.getStairs();
}
Bukkit.getLogger().info("Using super slabs");
Debug.info("Using super slabs");
} else {
slabs = BiomeConfigUtil.getSlabPalettes(getMapList("slabs.palettes"), this);
if(contains("slabs.stair-palettes") && getBoolean("slabs.use-stairs-if-available", false)) {
@ -322,7 +323,7 @@ public class BiomeConfig extends TerraConfigObject {
Iterator i = l.getCollection().iterator();
while(i.hasNext()) {
Stairs s = (Stairs) ((ProbabilityCollection.ProbabilitySetElement<BlockData>) i.next()).getObject();
Bukkit.getLogger().info("Stair added: " + s.getAsString());
Debug.info("Stair added: " + s.getAsString());
}
}
@ -331,7 +332,7 @@ public class BiomeConfig extends TerraConfigObject {
throw new ConfigException("Materials in stair config must be stairs.", getID());
}
}
Bukkit.getLogger().info("[Terra] Slabs: " + slabs.size());
Debug.info("[Terra] Slabs: " + slabs.size());
}
// Structure stuff

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.Debug;
import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.TerraConfigObject;
import com.dfsek.terra.config.exception.NotFoundException;
@ -25,7 +26,7 @@ public class BiomeConfigUtil {
try {
if(((String) entry.getValue()).startsWith("BLOCK:")) {
try {
Bukkit.getLogger().info("Adding slab palette with single material " + entry.getKey());
Debug.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 ConfigException("Invalid BlockData in slab configuration: " + ex.getMessage(), config.getID());
@ -44,7 +45,7 @@ public class BiomeConfigUtil {
}
}
}
Bukkit.getLogger().info("Adding " + paletteMap.size() + " slab palettes...");
Debug.info("Adding " + paletteMap.size() + " slab palettes...");
return paletteMap;
}
}

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.Debug;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.TerraConfigObject;
@ -70,10 +71,10 @@ public class CarverConfig extends TerraConfigObject {
Set<Material> l = new HashSet<>();
for(String s : (List<String>) e.getValue()) {
l.add(Bukkit.createBlockData(s).getMaterial());
Bukkit.getLogger().info("Added " + s + " to shift-able blocks");
Debug.info("Added " + s + " to shift-able blocks");
}
shift.put(Bukkit.createBlockData(e.getKey()).getMaterial(), l);
Bukkit.getLogger().info("Added " + e.getKey() + " as master block");
Debug.info("Added " + e.getKey() + " as master block");
}
replaceIsBlacklistInner = getBoolean("palette.inner.replace-blacklist", false);
@ -108,10 +109,10 @@ public class CarverConfig extends TerraConfigObject {
ProbabilityCollection<BlockData> layer = new ProbabilityCollection<>();
for(Map.Entry<String, Integer> type : ((Map<String, Integer>) m.get("materials")).entrySet()) {
layer.add(Bukkit.createBlockData(type.getKey()), type.getValue());
Bukkit.getLogger().info("Added " + type.getKey() + " with probability " + type.getValue());
Debug.info("Added " + type.getKey() + " with probability " + type.getValue());
}
result.put((Integer) m.get("y"), layer);
Bukkit.getLogger().info("Added at level " + m.get("y"));
Debug.info("Added at level " + m.get("y"));
} catch(ClassCastException e) {
throw new ConfigException("Unable to parse Carver Palette configuration! Check YAML syntax:" + e.getMessage(), getID());
}

View File

@ -4,7 +4,6 @@ import com.dfsek.terra.config.TerraConfig;
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;
import org.bukkit.Material;
@ -19,10 +18,7 @@ import org.polydev.gaea.world.palette.RandomPalette;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.Debug;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.TerraConfigObject;
import com.dfsek.terra.config.exception.ConfigException;
@ -60,7 +61,7 @@ public class PaletteConfig extends TerraConfigObject {
}
p.add(layer, (Integer) m.get("layers"));
} else {
Bukkit.getLogger().info("One-block palette layer!");
Debug.info("One-block palette layer!");
String data = "null";
for(Map.Entry<?, ?> e: map.get(0).entrySet()) {
data = (String) e.getKey();

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.generation;
import com.dfsek.terra.Debug;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.TerraBiomeGrid;
@ -152,7 +153,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
for(Map.Entry<World, PopulationManager> e : popMap.entrySet()) {
try {
e.getValue().saveBlocks(e.getKey());
Bukkit.getLogger().info("[Terra] Saved data for world " + e.getKey().getName());
Debug.info("[Terra] Saved data for world " + e.getKey().getName());
} catch(IOException ioException) {
ioException.printStackTrace();
}

View File

@ -5,25 +5,17 @@ import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.genconfig.BiomeConfig;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.biome.Biome;
import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.population.GaeaBlockPopulator;
import org.polydev.gaea.profiler.ProfileFuture;
import org.polydev.gaea.world.Flora;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
public class FloraPopulator extends GaeaBlockPopulator {
@Override

View File

@ -42,13 +42,9 @@ public class StructurePopulator extends BlockPopulator {
spawn.setY(y);
for(StructureSpawnRequirement s : struc.getSpawns()) {
if(! s.isValidSpawn(spawn)) continue main;
if(!b.equals(grid.getBiome(spawn.clone().add(s.getX(), s.getY(), s.getZ()), GenerationPhase.POPULATE))) {
Bukkit.getLogger().info("PREVENTED invalid spawn at " + spawn);
continue structure;
}
if(!b.equals(grid.getBiome(spawn.clone().add(s.getX(), s.getY(), s.getZ()), GenerationPhase.POPULATE))) continue structure;
}
double horizontal = struc.getStructureInfo().getMaxHorizontal();
Bukkit.getLogger().info("Valid spawn at " + spawn);
if(Math.abs((cx + 8) - spawn.getBlockX()) <= horizontal && Math.abs((cz + 8) - spawn.getBlockZ()) <= horizontal) {
try(ProfileFuture ignore = TerraProfiler.fromWorld(world).measure("StructurePasteTime")) {
struc.paste(spawn, chunk, GaeaStructure.Rotation.fromDegrees(r2.nextInt(4) * 90), Collections.emptyList());

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.structure;
import com.dfsek.terra.Debug;
import org.polydev.gaea.math.Range;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
@ -240,7 +241,7 @@ public class GaeaStructure implements Serializable {
intersectZ = new Range(zOr, zOr+16).sub(origin.getBlockZ() - structureInfo.getCenterZ());
if(intersectX == null || intersectZ == null) return;
executeForBlocksInRange(intersectX, getRange(Axis.Y), intersectZ, block -> pasteBlock(block, origin, r, m), r, m);
Bukkit.getLogger().info(intersectX.toString() + " : " + intersectZ.toString());
Debug.info(intersectX.toString() + " : " + intersectZ.toString());
}
/**