Remove singleton getter

This commit is contained in:
dfsek
2020-12-06 02:47:14 -07:00
parent d946ea9b15
commit 1940309954
18 changed files with 71 additions and 62 deletions
+6 -10
View File
@@ -10,6 +10,7 @@ import com.dfsek.terra.generation.TerraChunkGenerator;
import com.dfsek.terra.listeners.EventListener; import com.dfsek.terra.listeners.EventListener;
import com.dfsek.terra.listeners.SpigotListener; import com.dfsek.terra.listeners.SpigotListener;
import com.dfsek.terra.registry.ConfigRegistry; import com.dfsek.terra.registry.ConfigRegistry;
import com.dfsek.terra.util.ConfigUtil;
import com.dfsek.terra.util.PaperUtil; import com.dfsek.terra.util.PaperUtil;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -27,23 +28,18 @@ import java.util.Objects;
public class Terra extends GaeaPlugin { public class Terra extends GaeaPlugin {
private static Terra instance;
private final Map<String, TerraChunkGenerator> generatorMap = new HashMap<>(); private final Map<String, TerraChunkGenerator> generatorMap = new HashMap<>();
public static Terra getInstance() {
return instance;
}
@Override @Override
public void onDisable() { public void onDisable() {
TerraChunkGenerator.saveAll(); TerraChunkGenerator.saveAll();
} }
@SuppressWarnings("deprecation")
@Override @Override
public void onEnable() { public void onEnable() {
Debug.setMain(this); // Set debug logger. Debug.setLogger(getLogger()); // Set debug logger.
instance = this; // Singleton B) ConfigUtil.setMain(this); // Set ConfigLoader's instance for use in some loaders
saveDefaultConfig(); saveDefaultConfig();
@@ -68,7 +64,7 @@ public class Terra extends GaeaPlugin {
long save = PluginConfig.getDataSaveInterval(); long save = PluginConfig.getDataSaveInterval();
Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, TerraChunkGenerator::saveAll, save, save); // Schedule population data saving Bukkit.getScheduler().runTaskTimerAsynchronously(this, TerraChunkGenerator::saveAll, save, save); // Schedule population data saving
Bukkit.getPluginManager().registerEvents(new EventListener(this), this); // Register master event listener Bukkit.getPluginManager().registerEvents(new EventListener(this), this); // Register master event listener
Bukkit.getPluginManager().registerEvents(new SpigotListener(this), this); // Register Spigot event listener, once Paper accepts StructureLocateEvent PR Spigot and Paper events will be separate. Bukkit.getPluginManager().registerEvents(new SpigotListener(this), this); // Register Spigot event listener, once Paper accepts StructureLocateEvent PR Spigot and Paper events will be separate.
@@ -81,7 +77,7 @@ public class Terra extends GaeaPlugin {
return generatorMap.computeIfAbsent(worldName, name -> { return generatorMap.computeIfAbsent(worldName, name -> {
WorldConfig c = new WorldConfig(worldName, id, this); WorldConfig c = new WorldConfig(worldName, id, this);
TerraWorld.loadWorld(c); TerraWorld.loadWorld(c);
return new TerraChunkGenerator(c.getConfig()); return new TerraChunkGenerator(c.getConfig(), this);
}); });
} }
@@ -5,6 +5,7 @@ import com.dfsek.terra.config.base.PluginConfig;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.GaeaPlugin;
import org.polydev.gaea.biome.Biome; import org.polydev.gaea.biome.Biome;
import org.polydev.gaea.generation.GenerationPhase; import org.polydev.gaea.generation.GenerationPhase;
@@ -15,8 +16,8 @@ import java.util.function.Consumer;
*/ */
public class AsyncBiomeFinder extends AsyncFeatureFinder<Biome> { public class AsyncBiomeFinder extends AsyncFeatureFinder<Biome> {
public AsyncBiomeFinder(TerraBiomeGrid grid, Biome target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback) { public AsyncBiomeFinder(TerraBiomeGrid grid, Biome target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback, GaeaPlugin main) {
super(grid, target, origin, startRadius, maxRadius, callback); super(grid, target, origin, startRadius, maxRadius, callback, main);
} }
/** /**
@@ -1,12 +1,12 @@
package com.dfsek.terra.async; package com.dfsek.terra.async;
import com.dfsek.terra.Terra;
import com.dfsek.terra.biome.grid.TerraBiomeGrid; import com.dfsek.terra.biome.grid.TerraBiomeGrid;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.GaeaPlugin;
import java.util.function.Consumer; import java.util.function.Consumer;
@@ -20,10 +20,12 @@ public abstract class AsyncFeatureFinder<T> implements Runnable {
protected final World world; protected final World world;
private final Consumer<Vector> callback; private final Consumer<Vector> callback;
protected int searchSize = 1; protected int searchSize = 1;
protected final GaeaPlugin main;
public AsyncFeatureFinder(TerraBiomeGrid grid, T target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback) { public AsyncFeatureFinder(TerraBiomeGrid grid, T target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback, GaeaPlugin main) {
this.grid = grid; this.grid = grid;
this.target = target; this.target = target;
this.main = main;
this.startRadius = startRadius; this.startRadius = startRadius;
this.maxRadius = maxRadius; this.maxRadius = maxRadius;
this.centerX = origin.getBlockX(); this.centerX = origin.getBlockX();
@@ -66,7 +68,7 @@ public abstract class AsyncFeatureFinder<T> implements Runnable {
toggle = !toggle; toggle = !toggle;
} }
Vector finalSpawn = found ? finalizeVector(new Vector(x, 0, z)) : null; Vector finalSpawn = found ? finalizeVector(new Vector(x, 0, z)) : null;
Bukkit.getScheduler().runTask(Terra.getInstance(), () -> callback.accept(finalSpawn)); Bukkit.getScheduler().runTask(main, () -> callback.accept(finalSpawn));
} }
@@ -10,6 +10,7 @@ import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.GaeaPlugin;
import org.polydev.gaea.util.FastRandom; import org.polydev.gaea.util.FastRandom;
import java.util.Random; import java.util.Random;
@@ -19,8 +20,8 @@ import java.util.function.Consumer;
* Runnable to locate structures asynchronously * Runnable to locate structures asynchronously
*/ */
public class AsyncStructureFinder extends AsyncFeatureFinder<TerraStructure> { public class AsyncStructureFinder extends AsyncFeatureFinder<TerraStructure> {
public AsyncStructureFinder(TerraBiomeGrid grid, TerraStructure target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback) { public AsyncStructureFinder(TerraBiomeGrid grid, TerraStructure target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback, GaeaPlugin main) {
super(grid, target, origin, startRadius, maxRadius, callback); super(grid, target, origin, startRadius, maxRadius, callback, main);
setSearchSize(target.getSpawn().getWidth() + 2 * target.getSpawn().getSeparation()); setSearchSize(target.getSpawn().getWidth() + 2 * target.getSpawn().getSeparation());
} }
@@ -1,6 +1,5 @@
package com.dfsek.terra.command.biome; package com.dfsek.terra.command.biome;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraWorld; import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.async.AsyncBiomeFinder; import com.dfsek.terra.async.AsyncBiomeFinder;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
@@ -45,15 +44,15 @@ public class BiomeLocateCommand extends WorldCommand {
LangUtil.send("command.biome.invalid", sender, id); LangUtil.send("command.biome.invalid", sender, id);
return true; return true;
} }
Bukkit.getScheduler().runTaskAsynchronously(Terra.getInstance(), new AsyncBiomeFinder(TerraWorld.getWorld(world).getGrid(), b, sender.getLocation().clone().multiply((1D / PluginConfig.getBiomeSearchResolution())), 0, maxRadius, location -> { Bukkit.getScheduler().runTaskAsynchronously(getMain(), new AsyncBiomeFinder(TerraWorld.getWorld(world).getGrid(), b, sender.getLocation().clone().multiply((1D / PluginConfig.getBiomeSearchResolution())), 0, maxRadius, location -> {
if(location != null) { if(location != null) {
LangUtil.send("command.biome.biome-found", sender, String.valueOf(location.getBlockX()), String.valueOf(location.getBlockZ())); LangUtil.send("command.biome.biome-found", sender, String.valueOf(location.getBlockX()), String.valueOf(location.getBlockZ()));
if(tp) { if(tp) {
Location l = new Location(sender.getWorld(), location.getX(), sender.getLocation().getY(), location.getZ()); Location l = new Location(sender.getWorld(), location.getX(), sender.getLocation().getY(), location.getZ());
Bukkit.getScheduler().runTask(Terra.getInstance(), () -> sender.teleport(l)); Bukkit.getScheduler().runTask(getMain(), () -> sender.teleport(l));
} }
} else LangUtil.send("command.biome.unable-to-locate", sender); } else LangUtil.send("command.biome.unable-to-locate", sender);
})); }, getMain()));
return true; return true;
} }
@@ -1,6 +1,5 @@
package com.dfsek.terra.command.image; package com.dfsek.terra.command.image;
import com.dfsek.terra.Terra;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.image.WorldImageGenerator; import com.dfsek.terra.image.WorldImageGenerator;
import org.bukkit.World; import org.bukkit.World;
@@ -24,7 +23,7 @@ public class RenderCommand extends WorldCommand {
try { try {
WorldImageGenerator g = new WorldImageGenerator(world, Integer.parseInt(args[0]), Integer.parseInt(args[1])); WorldImageGenerator g = new WorldImageGenerator(world, Integer.parseInt(args[0]), Integer.parseInt(args[1]));
g.drawWorld(sender.getLocation().getBlockX(), sender.getLocation().getBlockZ()); g.drawWorld(sender.getLocation().getBlockX(), sender.getLocation().getBlockZ());
File file = new File(Terra.getInstance().getDataFolder() + File.separator + "export" + File.separator + "map" + File.separator + "map_" + System.currentTimeMillis() + ".png"); File file = new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "map" + File.separator + "map_" + System.currentTimeMillis() + ".png");
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
file.mkdirs(); file.mkdirs();
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
@@ -1,6 +1,5 @@
package com.dfsek.terra.command.structure; package com.dfsek.terra.command.structure;
import com.dfsek.terra.Terra;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.structure.InitializationException; import com.dfsek.terra.structure.InitializationException;
import com.dfsek.terra.structure.Structure; import com.dfsek.terra.structure.Structure;
@@ -36,7 +35,7 @@ public class ExportCommand extends PlayerCommand {
return true; return true;
} }
try { try {
File file = new File(Terra.getInstance().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure"); File file = new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure");
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
@@ -1,6 +1,5 @@
package com.dfsek.terra.command.structure; package com.dfsek.terra.command.structure;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraWorld; import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.async.AsyncStructureFinder; import com.dfsek.terra.async.AsyncStructureFinder;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
@@ -45,18 +44,18 @@ public class LocateCommand extends WorldCommand {
LangUtil.send("command.structure.invalid", sender, id); LangUtil.send("command.structure.invalid", sender, id);
return true; return true;
} }
Bukkit.getScheduler().runTaskAsynchronously(Terra.getInstance(), new AsyncStructureFinder(TerraWorld.getWorld(world).getGrid(), s, sender.getLocation(), 0, maxRadius, (location) -> { Bukkit.getScheduler().runTaskAsynchronously(getMain(), new AsyncStructureFinder(TerraWorld.getWorld(world).getGrid(), s, sender.getLocation(), 0, maxRadius, (location) -> {
if(sender.isOnline()) { if(sender.isOnline()) {
if(location != null) { if(location != null) {
sender.sendMessage("Located structure at (" + location.getBlockX() + ", " + location.getBlockZ() + ")."); sender.sendMessage("Located structure at (" + location.getBlockX() + ", " + location.getBlockZ() + ").");
if(tp) { if(tp) {
int finalX = location.getBlockX(); int finalX = location.getBlockX();
int finalZ = location.getBlockZ(); int finalZ = location.getBlockZ();
Bukkit.getScheduler().runTask(Terra.getInstance(), () -> sender.teleport(new Location(sender.getWorld(), finalX, sender.getLocation().getY(), finalZ))); Bukkit.getScheduler().runTask(getMain(), () -> sender.teleport(new Location(sender.getWorld(), finalX, sender.getLocation().getY(), finalZ)));
} }
} else sender.sendMessage("Unable to locate structure. "); } else sender.sendMessage("Unable to locate structure. ");
} }
})); }, getMain()));
return true; return true;
} }
@@ -1,6 +1,5 @@
package com.dfsek.terra.command.structure.load; package com.dfsek.terra.command.structure.load;
import com.dfsek.terra.Terra;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -21,9 +20,9 @@ public class LoadCommand extends PlayerCommand implements DebugCommand {
super(parent); super(parent);
} }
public static List<String> getStructureNames() { public List<String> getStructureNames() {
List<String> names = new ArrayList<>(); List<String> names = new ArrayList<>();
File structureDir = new File(Terra.getInstance().getDataFolder() + File.separator + "export" + File.separator + "structures"); File structureDir = new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "structures");
if(!structureDir.exists()) return Collections.emptyList(); if(!structureDir.exists()) return Collections.emptyList();
Path structurePath = structureDir.toPath(); Path structurePath = structureDir.toPath();
@@ -1,6 +1,5 @@
package com.dfsek.terra.command.structure.load; package com.dfsek.terra.command.structure.load;
import com.dfsek.terra.Terra;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.structure.Rotation; import com.dfsek.terra.structure.Rotation;
import com.dfsek.terra.structure.Structure; import com.dfsek.terra.structure.Structure;
@@ -9,7 +8,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.command.DebugCommand; import org.polydev.gaea.command.DebugCommand;
import org.polydev.gaea.command.PlayerCommand;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -18,7 +16,7 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public class LoadFullCommand extends PlayerCommand implements DebugCommand { public class LoadFullCommand extends LoadCommand implements DebugCommand {
private final boolean chunk; private final boolean chunk;
public LoadFullCommand(org.polydev.gaea.command.Command parent, boolean chunk) { public LoadFullCommand(org.polydev.gaea.command.Command parent, boolean chunk) {
@@ -36,7 +34,7 @@ public class LoadFullCommand extends PlayerCommand implements DebugCommand {
LangUtil.send("command.structure.invalid-rotation", sender, args[1]); LangUtil.send("command.structure.invalid-rotation", sender, args[1]);
return true; return true;
} }
Structure struc = Structure.load(new File(Terra.getInstance().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure")); Structure struc = Structure.load(new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure"));
if(chunk) struc.paste(sender.getLocation(), sender.getLocation().getChunk(), r); if(chunk) struc.paste(sender.getLocation(), sender.getLocation().getChunk(), r);
else struc.paste(sender.getLocation(), r); else struc.paste(sender.getLocation(), r);
//sender.sendMessage(String.valueOf(struc.checkSpawns(sender.getLocation(), r))); //sender.sendMessage(String.valueOf(struc.checkSpawns(sender.getLocation(), r)));
@@ -66,7 +64,7 @@ public class LoadFullCommand extends PlayerCommand implements DebugCommand {
public List<String> getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] args) { public List<String> getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] args) {
switch(args.length) { switch(args.length) {
case 1: case 1:
return LoadCommand.getStructureNames().stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList()); return getStructureNames().stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());
case 2: case 2:
return Stream.of("0", "90", "180", "270").filter(string -> string.toUpperCase().startsWith(args[1].toUpperCase())).collect(Collectors.toList()); return Stream.of("0", "90", "180", "270").filter(string -> string.toUpperCase().startsWith(args[1].toUpperCase())).collect(Collectors.toList());
} }
@@ -1,6 +1,5 @@
package com.dfsek.terra.command.structure.load; package com.dfsek.terra.command.structure.load;
import com.dfsek.terra.Terra;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.structure.Structure; import com.dfsek.terra.structure.Structure;
import com.dfsek.terra.structure.StructureContainedBlock; import com.dfsek.terra.structure.StructureContainedBlock;
@@ -14,7 +13,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.command.DebugCommand; import org.polydev.gaea.command.DebugCommand;
import org.polydev.gaea.command.PlayerCommand;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -22,7 +20,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class LoadRawCommand extends PlayerCommand implements DebugCommand { public class LoadRawCommand extends LoadCommand implements DebugCommand {
public LoadRawCommand(org.polydev.gaea.command.Command parent) { public LoadRawCommand(org.polydev.gaea.command.Command parent) {
super(parent); super(parent);
} }
@@ -36,7 +34,7 @@ public class LoadRawCommand extends PlayerCommand implements DebugCommand {
@Override @Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
try { try {
Structure struc = Structure.load(new File(Terra.getInstance().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure")); Structure struc = Structure.load(new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure"));
StructureInfo info = struc.getStructureInfo(); StructureInfo info = struc.getStructureInfo();
int centerX = info.getCenterX(); int centerX = info.getCenterX();
int centerZ = info.getCenterZ(); int centerZ = info.getCenterZ();
@@ -106,7 +104,7 @@ public class LoadRawCommand extends PlayerCommand implements DebugCommand {
@Override @Override
public List<String> getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] args) { public List<String> getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] args) {
if(args.length == 1) { if(args.length == 1) {
return LoadCommand.getStructureNames().stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList()); return getStructureNames().stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());
} }
return Collections.emptyList(); return Collections.emptyList();
} }
@@ -31,7 +31,7 @@ public final class LangUtil {
Debug.error("Report this to Terra!"); Debug.error("Report this to Terra!");
} }
try { try {
language = new Language(new File(Terra.getInstance().getDataFolder(), "lang" + File.separator + langID + ".yml")); language = new Language(new File(main.getDataFolder(), "lang" + File.separator + langID + ".yml"));
} catch(InvalidConfigurationException | IOException e) { } catch(InvalidConfigurationException | IOException e) {
logger.severe("Unable to load language: " + langID); logger.severe("Unable to load language: " + langID);
e.printStackTrace(); e.printStackTrace();
@@ -5,6 +5,7 @@ import com.dfsek.tectonic.loading.ConfigLoader;
import com.dfsek.tectonic.loading.TypeLoader; import com.dfsek.tectonic.loading.TypeLoader;
import com.dfsek.terra.config.loaders.Types; import com.dfsek.terra.config.loaders.Types;
import com.dfsek.terra.generation.items.tree.TreeLayer; import com.dfsek.terra.generation.items.tree.TreeLayer;
import org.polydev.gaea.GaeaPlugin;
import org.polydev.gaea.math.FastNoiseLite; import org.polydev.gaea.math.FastNoiseLite;
import org.polydev.gaea.math.ProbabilityCollection; import org.polydev.gaea.math.ProbabilityCollection;
import org.polydev.gaea.math.Range; import org.polydev.gaea.math.Range;
@@ -15,6 +16,12 @@ import java.util.Map;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class TreeLayerLoader implements TypeLoader<TreeLayer> { public class TreeLayerLoader implements TypeLoader<TreeLayer> {
private final GaeaPlugin main;
public TreeLayerLoader(GaeaPlugin main) {
this.main = main;
}
@Override @Override
public TreeLayer load(Type type, Object o, ConfigLoader configLoader) throws LoadException { public TreeLayer load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
Map<String, Object> map = (Map<String, Object>) o; Map<String, Object> map = (Map<String, Object>) o;
@@ -26,9 +33,9 @@ public class TreeLayerLoader implements TypeLoader<TreeLayer> {
if(map.containsKey("simplex-frequency")) { if(map.containsKey("simplex-frequency")) {
FastNoiseLite noiseLite = new FastNoiseLite(); FastNoiseLite noiseLite = new FastNoiseLite();
noiseLite.setFrequency((Double) map.get("simplex-frequency")); noiseLite.setFrequency((Double) map.get("simplex-frequency"));
return new TreeLayer(density, range, items, noiseLite); return new TreeLayer(density, range, items, noiseLite, main);
} }
return new TreeLayer(density, range, items, null); return new TreeLayer(density, range, items, null, main);
} }
} }
@@ -1,25 +1,26 @@
package com.dfsek.terra.debug; package com.dfsek.terra.debug;
import com.dfsek.terra.config.base.PluginConfig; import com.dfsek.terra.config.base.PluginConfig;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.logging.Logger;
public class Debug { public class Debug {
public static JavaPlugin main; public static Logger logger;
public static void setMain(JavaPlugin main) { public static void setLogger(Logger logger) {
Debug.main = main; Debug.logger = logger;
} }
public static void info(String message) { public static void info(String message) {
if(PluginConfig.isDebug()) main.getLogger().info(message); if(PluginConfig.isDebug()) logger.info(message);
} }
public static void warn(String message) { public static void warn(String message) {
if(PluginConfig.isDebug()) main.getLogger().warning(message); if(PluginConfig.isDebug()) logger.warning(message);
} }
public static void error(String message) { public static void error(String message) {
if(PluginConfig.isDebug()) main.getLogger().severe(message); if(PluginConfig.isDebug()) logger.severe(message);
} }
public static void stack(Exception e) { public static void stack(Exception e) {
@@ -1,6 +1,5 @@
package com.dfsek.terra.generation; package com.dfsek.terra.generation;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld; import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
@@ -28,6 +27,7 @@ import org.bukkit.block.data.type.Stairs;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.GaeaPlugin;
import org.polydev.gaea.biome.Biome; import org.polydev.gaea.biome.Biome;
import org.polydev.gaea.generation.GaeaChunkGenerator; import org.polydev.gaea.generation.GaeaChunkGenerator;
import org.polydev.gaea.generation.GenerationPhase; import org.polydev.gaea.generation.GenerationPhase;
@@ -51,12 +51,13 @@ import java.util.logging.Level;
public class TerraChunkGenerator extends GaeaChunkGenerator { public class TerraChunkGenerator extends GaeaChunkGenerator {
private static final Map<World, PopulationManager> popMap = new HashMap<>(); private static final Map<World, PopulationManager> popMap = new HashMap<>();
private final PopulationManager popMan = new PopulationManager(Terra.getInstance()); private final PopulationManager popMan;
private final ConfigPack configPack; private final ConfigPack configPack;
private boolean needsLoad = true; private boolean needsLoad = true;
public TerraChunkGenerator(ConfigPack c) { public TerraChunkGenerator(ConfigPack c, GaeaPlugin main) {
super(ChunkInterpolator.InterpolationType.TRILINEAR); super(ChunkInterpolator.InterpolationType.TRILINEAR);
popMan = new PopulationManager(main);
this.configPack = c; this.configPack = c;
popMan.attach(new OrePopulator()); popMan.attach(new OrePopulator());
popMan.attach(new TreePopulator()); popMan.attach(new TreePopulator());
@@ -1,11 +1,11 @@
package com.dfsek.terra.generation.items.tree; package com.dfsek.terra.generation.items.tree;
import com.dfsek.terra.Terra;
import com.dfsek.terra.generation.items.PlaceableLayer; import com.dfsek.terra.generation.items.PlaceableLayer;
import com.dfsek.terra.procgen.math.Vector2; import com.dfsek.terra.procgen.math.Vector2;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.polydev.gaea.GaeaPlugin;
import org.polydev.gaea.math.FastNoiseLite; import org.polydev.gaea.math.FastNoiseLite;
import org.polydev.gaea.math.ProbabilityCollection; import org.polydev.gaea.math.ProbabilityCollection;
import org.polydev.gaea.math.Range; import org.polydev.gaea.math.Range;
@@ -15,9 +15,11 @@ import org.polydev.gaea.tree.TreeType;
import java.util.Random; import java.util.Random;
public class TreeLayer extends PlaceableLayer<Tree> { public class TreeLayer extends PlaceableLayer<Tree> {
private final GaeaPlugin main;
public TreeLayer(double density, Range level, ProbabilityCollection<Tree> layer, FastNoiseLite noise) { public TreeLayer(double density, Range level, ProbabilityCollection<Tree> layer, FastNoiseLite noise, GaeaPlugin main) {
super(density, level, layer, noise); super(density, level, layer, noise);
this.main = main;
} }
@Override @Override
@@ -28,8 +30,8 @@ public class TreeLayer extends PlaceableLayer<Tree> {
current = current.getRelative(BlockFace.DOWN); current = current.getRelative(BlockFace.DOWN);
if(item.getSpawnable().contains(current.getType())) { if(item.getSpawnable().contains(current.getType())) {
if(item instanceof TreeType && current.getRelative(BlockFace.UP).isEmpty()) if(item instanceof TreeType && current.getRelative(BlockFace.UP).isEmpty())
item.plant(current.getLocation().add(0, 1, 0), random, Terra.getInstance()); item.plant(current.getLocation().add(0, 1, 0), random, main);
else if(!(item instanceof TreeType)) item.plant(current.getLocation(), random, Terra.getInstance()); else if(!(item instanceof TreeType)) item.plant(current.getLocation(), random, main);
} }
} }
} }
@@ -21,7 +21,7 @@ import org.polydev.gaea.GaeaPlugin;
* Listener to load on Spigot servers, contains Villager crash prevention and hacky ender eye redirection. * Listener to load on Spigot servers, contains Villager crash prevention and hacky ender eye redirection.
* <p> * <p>
* (This is currently loaded on all servers; once Paper accepts the StructureLocateEvent PR this will only be loaded on servers without * (This is currently loaded on all servers; once Paper accepts the StructureLocateEvent PR this will only be loaded on servers without
* StructureLocateEvent. * StructureLocateEvent).
*/ */
public class SpigotListener implements Listener { public class SpigotListener implements Listener {
private final GaeaPlugin main; private final GaeaPlugin main;
@@ -43,7 +43,7 @@ public class SpigotListener implements Listener {
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getGrid(), config, e.getLocation(), 0, 500, location -> { AsyncStructureFinder finder = new AsyncStructureFinder(tw.getGrid(), config, e.getLocation(), 0, 500, location -> {
if(location != null) signal.setTargetLocation(location.toLocation(signal.getWorld())); if(location != null) signal.setTargetLocation(location.toLocation(signal.getWorld()));
Debug.info("Location: " + location); Debug.info("Location: " + location);
}); }, main);
finder.run(); // Do this synchronously so eye doesn't change direction several ticks after spawning. finder.run(); // Do this synchronously so eye doesn't change direction several ticks after spawning.
} else } else
main.getLogger().warning("No overrides are defined for Strongholds. Ender Signals will not work correctly."); main.getLogger().warning("No overrides are defined for Strongholds. Ender Signals will not work correctly.");
@@ -33,10 +33,17 @@ import org.bukkit.Material;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.polydev.gaea.GaeaPlugin;
import org.polydev.gaea.math.ProbabilityCollection; import org.polydev.gaea.math.ProbabilityCollection;
import org.polydev.gaea.math.Range; import org.polydev.gaea.math.Range;
public final class ConfigUtil { public final class ConfigUtil {
private static GaeaPlugin main;
public static void setMain(GaeaPlugin main) {
ConfigUtil.main = main;
}
/** /**
* Register all Terra loaders to a {@link TypeRegistry}. * Register all Terra loaders to a {@link TypeRegistry}.
* *
@@ -56,7 +63,7 @@ public final class ConfigUtil {
.registerLoader(Ore.Type.class, (t, o, l) -> Ore.Type.valueOf((String) o)) .registerLoader(Ore.Type.class, (t, o, l) -> Ore.Type.valueOf((String) o))
.registerLoader(OreConfig.class, new OreConfigLoader()) .registerLoader(OreConfig.class, new OreConfigLoader())
.registerLoader(NoiseBuilder.class, new NoiseBuilderLoader()) .registerLoader(NoiseBuilder.class, new NoiseBuilderLoader())
.registerLoader(TreeLayer.class, new TreeLayerLoader()) .registerLoader(TreeLayer.class, new TreeLayerLoader(main))
.registerLoader(MaterialSet.class, new MaterialSetLoader()) .registerLoader(MaterialSet.class, new MaterialSetLoader())
.registerLoader(OreHolder.class, new OreHolderLoader()) .registerLoader(OreHolder.class, new OreHolderLoader())
.registerLoader(Feature.class, new StructureFeatureLoader()) .registerLoader(Feature.class, new StructureFeatureLoader())