working WorldConfig impl

This commit is contained in:
dfsek
2021-03-01 15:20:09 -07:00
parent 5a6b7ac4c1
commit a28f3fa660
44 changed files with 246 additions and 180 deletions

View File

@@ -92,7 +92,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
boolean succeed = registry.loadAll(this);
Map<World, TerraWorld> newMap = new HashMap<>();
worldMap.forEach((world, tw) -> {
((BukkitChunkGeneratorWrapper) world.getGenerator().getHandle()).getHandle().getCache().clear();
tw.getConfig().getSamplerCache().clear();
String packID = tw.getConfig().getTemplate().getID();
newMap.put(world, new TerraWorld(world, registry.get(packID), this));
});
@@ -218,7 +218,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
if(!registry.contains(id)) throw new IllegalArgumentException("No such config pack \"" + id + "\"");
ConfigPack pack = registry.get(id);
worlds.put(worldName, pack);
return new DefaultChunkGenerator3D(registry.get(id), this, pack.getSamplerCache());
return new DefaultChunkGenerator3D(registry.get(id), this);
}));
}

View File

@@ -6,6 +6,7 @@ import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.config.pack.WorldConfig;
import com.dfsek.terra.config.templates.BiomeTemplate;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.population.items.TerraStructure;
@@ -15,6 +16,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@@ -27,10 +29,10 @@ public class BiomeInfoCommand extends WorldCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
String id = args[0];
ConfigPack cfg = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig();
WorldConfig cfg = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig();
UserDefinedBiome b;
try {
b = (UserDefinedBiome) cfg.getBiome(id);
b = (UserDefinedBiome) cfg.getBiomeRegistry().get(id);
} catch(IllegalArgumentException | NullPointerException e) {
LangUtil.send("command.biome.invalid", new BukkitCommandSender(sender), id);
return true;
@@ -74,7 +76,9 @@ public class BiomeInfoCommand extends WorldCommand {
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
if(!(sender instanceof Player) || !TerraWorld.isTerraWorld(BukkitAdapter.adapt(((Player) sender).getWorld())))
return Collections.emptyList();
List<String> ids = getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getBiomeIDs();
List<String> ids = new ArrayList<>();
getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getBiomeRegistry().forEach((id, biome) -> ids.add(id));
if(args.length == 1)
return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());
return Collections.emptyList();

View File

@@ -21,6 +21,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@@ -44,7 +45,7 @@ public class BiomeLocateCommand extends WorldCommand {
}
TerraBiome b;
try {
b = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getBiome(id);
b = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getBiomeRegistry().get(id);
} catch(IllegalArgumentException | NullPointerException e) {
LangUtil.send("command.biome.invalid", BukkitAdapter.adapt(sender), id);
return true;
@@ -84,7 +85,9 @@ public class BiomeLocateCommand extends WorldCommand {
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
if(!(sender instanceof Player) || !TerraWorld.isTerraWorld(BukkitAdapter.adapt(((Player) sender).getWorld())))
return Collections.emptyList();
List<String> ids = getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getBiomeIDs();
List<String> ids = new ArrayList<>();
getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getBiomeRegistry().forEach((id, biome) -> ids.add(id));
if(args.length == 1)
return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());
return Collections.emptyList();

View File

@@ -21,6 +21,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@@ -46,7 +47,7 @@ public class LocateCommand extends WorldCommand {
}
TerraStructure s;
try {
s = Objects.requireNonNull(getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getStructure(id));
s = Objects.requireNonNull(getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getStructureRegistry().get(id));
} catch(IllegalArgumentException | NullPointerException e) {
LangUtil.send("command.structure.invalid", BukkitAdapter.adapt(sender), id);
return true;
@@ -90,7 +91,9 @@ public class LocateCommand extends WorldCommand {
if(!(sender instanceof Player) || !(TerraWorld.isTerraWorld(BukkitAdapter.adapt(((Player) sender).getWorld()))))
return Collections.emptyList();
List<String> ids = getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getStructureIDs();
List<String> ids = new ArrayList<>();
getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getStructureRegistry().forEach((id, struct) -> ids.add(id));
if(args.length == 1)
return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());

View File

@@ -34,7 +34,7 @@ public class SpawnCommand extends WorldCommand implements DebugCommand {
int z = p.getBlockZ();
Position dummy = new Position(0, 0);
com.dfsek.terra.api.platform.world.World w = BukkitAdapter.adapt(world);
String check = new CheckFunction(getMain(), new NumericConstant(0, dummy), new NumericConstant(0, dummy), new NumericConstant(0, dummy), getMain().getWorld(w).getConfig().getSamplerCache(), dummy).apply(new TerraImplementationArguments(new StructureBuffer(
String check = new CheckFunction(getMain(), new NumericConstant(0, dummy), new NumericConstant(0, dummy), new NumericConstant(0, dummy), dummy).apply(new TerraImplementationArguments(new StructureBuffer(
new com.dfsek.terra.api.math.vector.Location(w, x, y, z)
), Rotation.NONE, new FastRandom(), 0), new HashMap<>());

View File

@@ -9,6 +9,7 @@ import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.config.pack.WorldConfig;
import com.dfsek.terra.world.TerraWorld;
import org.bukkit.Material;
import org.bukkit.TreeType;
@@ -46,7 +47,7 @@ public class CommonListener implements Listener {
World bukkit = BukkitAdapter.adapt(e.getWorld());
if(!TerraWorld.isTerraWorld(bukkit)) return;
TerraWorld tw = main.getWorld(bukkit);
ConfigPack c = tw.getConfig();
WorldConfig c = tw.getConfig();
if(c.getTemplate().isDisableSaplings()) return;
e.setCancelled(true);
Block block = e.getLocation().getBlock();

View File

@@ -23,7 +23,7 @@ public class PaperListener implements Listener {
String name = "minecraft:" + e.getType().getName();
main.getDebugLogger().info("Overriding structure location for \"" + name + "\"");
TerraWorld tw = main.getWorld(BukkitAdapter.adapt(e.getWorld()));
TerraStructure config = tw.getConfig().getStructure(tw.getConfig().getTemplate().getLocatable().get(name));
TerraStructure config = tw.getConfig().getStructureRegistry().get(tw.getConfig().getTemplate().getLocatable().get(name));
if(config != null) {
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getOrigin()), 0, 500, location -> {
if(location != null)

View File

@@ -37,7 +37,7 @@ public class SpigotListener implements Listener {
if(!TerraWorld.isTerraWorld(BukkitAdapter.adapt(e.getEntity().getWorld()))) return;
TerraWorld tw = main.getWorld(BukkitAdapter.adapt(e.getEntity().getWorld()));
EnderSignal signal = (EnderSignal) entity;
TerraStructure config = tw.getConfig().getStructure(tw.getConfig().getTemplate().getLocatable().get("STRONGHOLD"));
TerraStructure config = tw.getConfig().getStructureRegistry().get(tw.getConfig().getTemplate().getLocatable().get("STRONGHOLD"));
if(config != null) {
main.getDebugLogger().info("Overriding Ender Signal...");
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getLocation()), 0, 500, location -> {