improve BukkitAdapter, fix LocateCommand

This commit is contained in:
dfsek
2021-01-01 16:05:42 -07:00
parent 61c93b47ca
commit 556584f9f5
22 changed files with 64 additions and 54 deletions
@@ -2,7 +2,7 @@ package com.dfsek.terra.bukkit;
import com.dfsek.terra.api.Player; import com.dfsek.terra.api.Player;
import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.bukkit.world.BukkitWorld; import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class BukkitPlayer implements Player { public class BukkitPlayer implements Player {
private final org.bukkit.entity.Player delegate; private final org.bukkit.entity.Player delegate;
@@ -19,6 +19,6 @@ public class BukkitPlayer implements Player {
@Override @Override
public Location getLocation() { public Location getLocation() {
org.bukkit.Location bukkit = delegate.getLocation(); org.bukkit.Location bukkit = delegate.getLocation();
return new Location(new BukkitWorld(bukkit.getWorld()), bukkit.getX(), bukkit.getY(), bukkit.getZ()); return new Location(BukkitAdapter.adapt(bukkit.getWorld()), bukkit.getX(), bukkit.getY(), bukkit.getZ());
} }
} }
@@ -121,7 +121,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
c.setExecutor(command); c.setExecutor(command);
c.setTabCompleter(command); c.setTabCompleter(command);
LocateCommand locate = new LocateCommand(command, false); LocateCommand locate = new LocateCommand(command);
PluginCommand locatePl = Objects.requireNonNull(getCommand("locate")); PluginCommand locatePl = Objects.requireNonNull(getCommand("locate"));
locatePl.setExecutor(locate); // Override locate command. Once Paper accepts StructureLocateEvent this will be unneeded on Paper implementations. locatePl.setExecutor(locate); // Override locate command. Once Paper accepts StructureLocateEvent this will be unneeded on Paper implementations.
locatePl.setTabCompleter(locate); locatePl.setTabCompleter(locate);
@@ -3,7 +3,7 @@ package com.dfsek.terra.bukkit.command.command.biome;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitWorld; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.carving.UserDefinedCarver; import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.base.ConfigPack; import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
@@ -27,7 +27,7 @@ public class BiomeInfoCommand extends WorldCommand {
@Override @Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
String id = args[0]; String id = args[0];
ConfigPack cfg = getMain().getWorld(new BukkitWorld(world)).getConfig(); ConfigPack cfg = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig();
UserDefinedBiome b; UserDefinedBiome b;
try { try {
b = cfg.getBiome(id); b = cfg.getBiome(id);
@@ -5,7 +5,7 @@ import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.BukkitPlayer; import com.dfsek.terra.bukkit.BukkitPlayer;
import com.dfsek.terra.bukkit.command.PlayerCommand; import com.dfsek.terra.bukkit.command.PlayerCommand;
import com.dfsek.terra.bukkit.world.BukkitWorld; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.procgen.voxel.DeformedSphere; import com.dfsek.terra.procgen.voxel.DeformedSphere;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -50,7 +50,7 @@ public class DeformedSphereCommand extends PlayerCommand {
n.setFrequency(freq); n.setFrequency(freq);
DeformedSphere sphere = new DeformedSphere(new BukkitPlayer(sender).getLocation().toVector(), radius, deform, n); DeformedSphere sphere = new DeformedSphere(new BukkitPlayer(sender).getLocation().toVector(), radius, deform, n);
for(Vector3 v : sphere.getGeometry()) { for(Vector3 v : sphere.getGeometry()) {
v.toLocation(new BukkitWorld(sender.getWorld())).getBlock().setBlockData(getMain().getWorldHandle().createBlockData("minecraft:stone"), false); v.toLocation(BukkitAdapter.adapt(sender.getWorld())).getBlock().setBlockData(getMain().getWorldHandle().createBlockData("minecraft:stone"), false);
} }
return true; return true;
} }
@@ -4,7 +4,7 @@ import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.BukkitPlayer; import com.dfsek.terra.bukkit.BukkitPlayer;
import com.dfsek.terra.bukkit.command.PlayerCommand; import com.dfsek.terra.bukkit.command.PlayerCommand;
import com.dfsek.terra.bukkit.world.BukkitWorld; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.procgen.voxel.Sphere; import com.dfsek.terra.procgen.voxel.Sphere;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -31,7 +31,7 @@ public class SphereCommand extends PlayerCommand {
} }
Sphere sphere = new Sphere(new BukkitPlayer(sender).getLocation().toVector(), radius); Sphere sphere = new Sphere(new BukkitPlayer(sender).getLocation().toVector(), radius);
for(Vector3 v : sphere.getGeometry()) { for(Vector3 v : sphere.getGeometry()) {
v.toLocation(new BukkitWorld(sender.getWorld())).getBlock().setBlockData(getMain().getWorldHandle().createBlockData("minecraft:stone"), false); v.toLocation(BukkitAdapter.adapt(sender.getWorld())).getBlock().setBlockData(getMain().getWorldHandle().createBlockData("minecraft:stone"), false);
} }
return true; return true;
} }
@@ -5,7 +5,7 @@ import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.PlayerCommand; import com.dfsek.terra.bukkit.command.PlayerCommand;
import com.dfsek.terra.bukkit.structure.WorldEditUtil; import com.dfsek.terra.bukkit.structure.WorldEditUtil;
import com.dfsek.terra.bukkit.util.BukkitConversions; import com.dfsek.terra.bukkit.util.BukkitConversions;
import com.dfsek.terra.bukkit.world.BukkitWorld; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.procgen.voxel.Tube; import com.dfsek.terra.procgen.voxel.Tube;
import org.bukkit.Location; import org.bukkit.Location;
@@ -35,7 +35,7 @@ public class TubeCommand extends PlayerCommand {
} }
Tube tube = new Tube(BukkitConversions.toTerraVector(l[0].toVector()), BukkitConversions.toTerraVector(l[1].toVector()), radius); Tube tube = new Tube(BukkitConversions.toTerraVector(l[0].toVector()), BukkitConversions.toTerraVector(l[1].toVector()), radius);
for(Vector3 v : tube.getGeometry()) { for(Vector3 v : tube.getGeometry()) {
v.toLocation(new BukkitWorld(sender.getWorld())).getBlock().setBlockData(getMain().getWorldHandle().createBlockData("minecraft:stone"), false); v.toLocation(BukkitAdapter.adapt(sender.getWorld())).getBlock().setBlockData(getMain().getWorldHandle().createBlockData("minecraft:stone"), false);
} }
return true; return true;
} }
@@ -2,7 +2,7 @@ package com.dfsek.terra.bukkit.command.command.profile;
import com.dfsek.terra.api.profiler.WorldProfiler; import com.dfsek.terra.api.profiler.WorldProfiler;
import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitWorld; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -19,7 +19,7 @@ public class QueryCommand extends WorldCommand {
@Override @Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = getMain().getWorld(new BukkitWorld(world)).getProfiler(); WorldProfiler profile = getMain().getWorld(BukkitAdapter.adapt(world)).getProfiler();
sender.sendMessage(profile.getResultsFormatted()); sender.sendMessage(profile.getResultsFormatted());
return true; return true;
} }
@@ -3,7 +3,7 @@ package com.dfsek.terra.bukkit.command.command.profile;
import com.dfsek.terra.api.profiler.WorldProfiler; import com.dfsek.terra.api.profiler.WorldProfiler;
import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitWorld; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -21,7 +21,7 @@ public class ResetCommand extends WorldCommand {
@Override @Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = getMain().getWorld(new BukkitWorld(world)).getProfiler(); WorldProfiler profile = getMain().getWorld(BukkitAdapter.adapt(world)).getProfiler();
profile.reset(); profile.reset();
LangUtil.send("command.profile.reset", new BukkitCommandSender(sender)); LangUtil.send("command.profile.reset", new BukkitCommandSender(sender));
return true; return true;
@@ -3,7 +3,7 @@ package com.dfsek.terra.bukkit.command.command.profile;
import com.dfsek.terra.api.profiler.WorldProfiler; import com.dfsek.terra.api.profiler.WorldProfiler;
import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitWorld; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -21,7 +21,7 @@ public class StartCommand extends WorldCommand {
@Override @Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = getMain().getWorld(new BukkitWorld(world)).getProfiler(); WorldProfiler profile = getMain().getWorld(BukkitAdapter.adapt(world)).getProfiler();
profile.setProfiling(true); profile.setProfiling(true);
LangUtil.send("command.profile.start", new BukkitCommandSender(sender)); LangUtil.send("command.profile.start", new BukkitCommandSender(sender));
return true; return true;
@@ -3,7 +3,7 @@ package com.dfsek.terra.bukkit.command.command.profile;
import com.dfsek.terra.api.profiler.WorldProfiler; import com.dfsek.terra.api.profiler.WorldProfiler;
import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitWorld; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -21,7 +21,7 @@ public class StopCommand extends WorldCommand {
@Override @Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = getMain().getWorld(new BukkitWorld(world)).getProfiler(); WorldProfiler profile = getMain().getWorld(BukkitAdapter.adapt(world)).getProfiler();
profile.setProfiling(false); profile.setProfiling(false);
LangUtil.send("command.profile.stop", new BukkitCommandSender(sender)); LangUtil.send("command.profile.stop", new BukkitCommandSender(sender));
return true; return true;
@@ -1,12 +1,12 @@
package com.dfsek.terra.bukkit.command.command.structure; package com.dfsek.terra.bukkit.command.command.structure;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.async.AsyncStructureFinder; import com.dfsek.terra.async.AsyncStructureFinder;
import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.TerraBukkitPlugin; import com.dfsek.terra.bukkit.TerraBukkitPlugin;
import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.bukkit.world.BukkitWorld;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.generation.items.TerraStructure; import com.dfsek.terra.generation.items.TerraStructure;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
@@ -25,13 +25,12 @@ import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors;
public class LocateCommand extends WorldCommand { public class LocateCommand extends WorldCommand {
private final boolean tp;
public LocateCommand(com.dfsek.terra.bukkit.command.Command parent, boolean tp) { public LocateCommand(com.dfsek.terra.bukkit.command.Command parent) {
super(parent); super(parent);
this.tp = tp;
} }
@SuppressWarnings("DuplicatedCode") @SuppressWarnings("DuplicatedCode")
@@ -48,12 +47,12 @@ public class LocateCommand extends WorldCommand {
} }
TerraStructure s; TerraStructure s;
try { try {
s = Objects.requireNonNull(getMain().getWorld(new BukkitWorld(world)).getConfig().getStructure(id)); s = Objects.requireNonNull(getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getStructure(id));
} catch(IllegalArgumentException | NullPointerException e) { } catch(IllegalArgumentException | NullPointerException e) {
//LangUtil.send("command.structure.invalid", sender, id); LangUtil.send("command.structure.invalid", new BukkitCommandSender(sender), id);
return true; return true;
} }
Bukkit.getScheduler().runTaskAsynchronously((TerraBukkitPlugin) getMain(), new AsyncStructureFinder(getMain().getWorld(new BukkitWorld(world)).getGrid(), s, BukkitAdapter.adapt(sender.getLocation()), 0, maxRadius, (location) -> { Bukkit.getScheduler().runTaskAsynchronously((TerraBukkitPlugin) getMain(), new AsyncStructureFinder(getMain().getWorld(BukkitAdapter.adapt(world)).getGrid(), s, BukkitAdapter.adapt(sender.getLocation()), 0, maxRadius, (location) -> {
if(sender.isOnline()) { if(sender.isOnline()) {
if(location != null) { if(location != null) {
ComponentBuilder cm = new ComponentBuilder(String.format("The nearest %s is at ", id.toLowerCase())) ComponentBuilder cm = new ComponentBuilder(String.format("The nearest %s is at ", id.toLowerCase()))
@@ -74,7 +73,7 @@ public class LocateCommand extends WorldCommand {
@Override @Override
public String getName() { public String getName() {
return tp ? "teleport" : "locate"; return "locate";
} }
@Override @Override
@@ -89,15 +88,13 @@ public class LocateCommand extends WorldCommand {
@Override @Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
/* if(!(sender instanceof Player) || !(TerraWorld.isTerraWorld(BukkitAdapter.adapt(((Player) sender).getWorld()))))
if(!(sender instanceof Player) || !(((Player) sender).getWorld().getGenerator() instanceof TerraChunkGenerator))
return Collections.emptyList(); return Collections.emptyList();
List<String> ids = ((TerraBukkitPlugin) getMain()).getWorld(((Player) sender).getWorld()).getConfig().getStructureIDs(); List<String> ids = getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getStructureIDs();
if(args.length == 1) if(args.length == 1)
return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList()); return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());
*/
return Collections.emptyList(); return Collections.emptyList();
} }
} }
@@ -8,7 +8,7 @@ import com.dfsek.terra.api.structures.tokenizer.Position;
import com.dfsek.terra.api.util.FastRandom; import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.bukkit.command.DebugCommand; import com.dfsek.terra.bukkit.command.DebugCommand;
import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitWorld; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -31,7 +31,7 @@ public class SpawnCommand extends WorldCommand implements DebugCommand {
int y = p.getBlockY(); int y = p.getBlockY();
int z = p.getBlockZ(); int z = p.getBlockZ();
Position dummy = new Position(0, 0); Position dummy = new Position(0, 0);
com.dfsek.terra.api.platform.world.World w = new BukkitWorld(world); 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().getCheckCache(), dummy).apply(new StructureBuffer( String check = new CheckFunction(getMain(), new NumericConstant(0, dummy), new NumericConstant(0, dummy), new NumericConstant(0, dummy), getMain().getWorld(w).getConfig().getCheckCache(), dummy).apply(new StructureBuffer(
new com.dfsek.terra.api.math.vector.Location(w, x, y, z) new com.dfsek.terra.api.math.vector.Location(w, x, y, z)
), Rotation.NONE, new FastRandom(), 0); ), Rotation.NONE, new FastRandom(), 0);
@@ -31,7 +31,7 @@ public class StructureCommand extends PlayerCommand {
@Override @Override
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() { public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
return Arrays.asList(new ExportCommand(this), new LoadCommand(this), new LocateCommand(this, false), new LocateCommand(this, true), new SpawnCommand(this)); return Arrays.asList(new ExportCommand(this), new LoadCommand(this), new LocateCommand(this), new SpawnCommand(this));
} }
@Override @Override
@@ -6,7 +6,6 @@ import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.bukkit.command.DebugCommand; import com.dfsek.terra.bukkit.command.DebugCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.bukkit.world.BukkitChunk; import com.dfsek.terra.bukkit.world.BukkitChunk;
import com.dfsek.terra.bukkit.world.BukkitWorld;
import com.dfsek.terra.util.PopulationUtil; import com.dfsek.terra.util.PopulationUtil;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -28,12 +27,12 @@ public class LoadFullCommand extends LoadCommand 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) {
TerraWorld terraWorld = getMain().getWorld(new BukkitWorld(sender.getWorld())); TerraWorld terraWorld = getMain().getWorld(BukkitAdapter.adapt(sender.getWorld()));
long t = System.nanoTime(); long t = System.nanoTime();
FastRandom chunk = PopulationUtil.getRandom(new BukkitChunk(sender.getLocation().getChunk())); FastRandom chunk = PopulationUtil.getRandom(new BukkitChunk(sender.getLocation().getChunk()));
if(this.chunk) { if(this.chunk) {
terraWorld.getConfig().getScriptRegistry().get(args[0]).execute(BukkitAdapter.adapt(sender.getLocation()), new BukkitChunk(sender.getLocation().getChunk()), chunk, Rotation.fromDegrees(90 * chunk.nextInt(4))); terraWorld.getConfig().getScriptRegistry().get(args[0]).execute(BukkitAdapter.adapt(sender.getLocation()), BukkitAdapter.adapt(sender.getLocation().getChunk()), chunk, Rotation.fromDegrees(90 * chunk.nextInt(4)));
} else { } else {
terraWorld.getConfig().getScriptRegistry().get(args[0]).execute(BukkitAdapter.adapt(sender.getLocation()), chunk, Rotation.fromDegrees(90 * chunk.nextInt(4))); terraWorld.getConfig().getScriptRegistry().get(args[0]).execute(BukkitAdapter.adapt(sender.getLocation()), chunk, Rotation.fromDegrees(90 * chunk.nextInt(4)));
} }
@@ -5,8 +5,6 @@ import com.dfsek.terra.api.structures.structure.Rotation;
import com.dfsek.terra.api.util.FastRandom; import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.bukkit.command.DebugCommand; import com.dfsek.terra.bukkit.command.DebugCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.bukkit.world.BukkitChunk;
import com.dfsek.terra.bukkit.world.BukkitWorld;
import com.dfsek.terra.util.PopulationUtil; import com.dfsek.terra.util.PopulationUtil;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -36,9 +34,9 @@ public class LoadRawCommand extends LoadCommand implements DebugCommand {
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) {
TerraWorld terraWorld = getMain().getWorld(new BukkitWorld(sender.getWorld())); TerraWorld terraWorld = getMain().getWorld(BukkitAdapter.adapt(sender.getWorld()));
long t = System.nanoTime(); long t = System.nanoTime();
FastRandom chunk = PopulationUtil.getRandom(new BukkitChunk(sender.getLocation().getChunk())); FastRandom chunk = PopulationUtil.getRandom(BukkitAdapter.adapt(sender.getLocation().getChunk()));
boolean success = terraWorld.getConfig().getScriptRegistry().get(args[0]).execute(BukkitAdapter.adapt(sender.getLocation()), chunk, Rotation.fromDegrees(90 * chunk.nextInt(4))); boolean success = terraWorld.getConfig().getScriptRegistry().get(args[0]).execute(BukkitAdapter.adapt(sender.getLocation()), chunk, Rotation.fromDegrees(90 * chunk.nextInt(4)));
long l = System.nanoTime() - t; long l = System.nanoTime() - t;
@@ -66,7 +64,7 @@ public class LoadRawCommand extends LoadCommand 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 getStructureNames(new BukkitWorld(((Player) commandSender).getWorld())).stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList()); return getStructureNames(BukkitAdapter.adapt(((Player) commandSender).getWorld())).stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());
} }
return Collections.emptyList(); return Collections.emptyList();
} }
@@ -5,8 +5,8 @@ import com.dfsek.terra.api.platform.generator.GeneratorWrapper;
import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
import com.dfsek.terra.api.world.generation.population.PopulationManager; import com.dfsek.terra.api.world.generation.population.PopulationManager;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.bukkit.world.BukkitBiomeGrid; import com.dfsek.terra.bukkit.world.BukkitBiomeGrid;
import com.dfsek.terra.bukkit.world.BukkitWorld;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.debug.Debug; import com.dfsek.terra.debug.Debug;
import com.dfsek.terra.generation.MasterChunkGenerator; import com.dfsek.terra.generation.MasterChunkGenerator;
@@ -82,7 +82,7 @@ public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements Gener
@Override @Override
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome) { public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome) {
BukkitWorld bukkitWorld = new BukkitWorld(world); com.dfsek.terra.api.platform.world.World bukkitWorld = BukkitAdapter.adapt(world);
if(needsLoad) load(bukkitWorld); // Load population data for world. if(needsLoad) load(bukkitWorld); // Load population data for world.
delegate.generateBiomes(bukkitWorld, random, x, z, new BukkitBiomeGrid(biome)); delegate.generateBiomes(bukkitWorld, random, x, z, new BukkitBiomeGrid(biome));
return (ChunkData) delegate.generateChunkData(bukkitWorld, random, x, z, new BukkitChunkGenerator.BukkitChunkData(createChunkData(world))).getHandle(); return (ChunkData) delegate.generateChunkData(bukkitWorld, random, x, z, new BukkitChunkGenerator.BukkitChunkData(createChunkData(world))).getHandle();
@@ -1,8 +1,7 @@
package com.dfsek.terra.bukkit.generator; package com.dfsek.terra.bukkit.generator;
import com.dfsek.terra.api.world.generation.TerraBlockPopulator; import com.dfsek.terra.api.world.generation.TerraBlockPopulator;
import com.dfsek.terra.bukkit.world.BukkitChunk; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.bukkit.world.BukkitWorld;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
@@ -19,6 +18,6 @@ public class BukkitPopulatorWrapper extends BlockPopulator {
@Override @Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk source) { public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk source) {
delegate.populate(new BukkitWorld(world), random, new BukkitChunk(source)); delegate.populate(BukkitAdapter.adapt(world), random, BukkitAdapter.adapt(source));
} }
} }
@@ -8,7 +8,7 @@ import com.dfsek.terra.api.transform.MapTransform;
import com.dfsek.terra.api.transform.Transformer; import com.dfsek.terra.api.transform.Transformer;
import com.dfsek.terra.api.util.FastRandom; import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.bukkit.world.BukkitWorld; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.base.ConfigPack; import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.debug.Debug; import com.dfsek.terra.debug.Debug;
import com.dfsek.terra.registry.TreeRegistry; import com.dfsek.terra.registry.TreeRegistry;
@@ -43,7 +43,7 @@ public class EventListener implements Listener {
@EventHandler @EventHandler
public void onSaplingGrow(StructureGrowEvent e) { public void onSaplingGrow(StructureGrowEvent e) {
World bukkit = new BukkitWorld(e.getWorld()); World bukkit = BukkitAdapter.adapt(e.getWorld());
if(!TerraWorld.isTerraWorld(bukkit)) return; if(!TerraWorld.isTerraWorld(bukkit)) return;
TerraWorld tw = main.getWorld(bukkit); TerraWorld tw = main.getWorld(bukkit);
ConfigPack c = tw.getConfig(); ConfigPack c = tw.getConfig();
@@ -8,6 +8,8 @@ import com.dfsek.terra.api.platform.block.data.Rail;
import com.dfsek.terra.api.platform.block.data.RedstoneWire; import com.dfsek.terra.api.platform.block.data.RedstoneWire;
import com.dfsek.terra.api.platform.block.data.Slab; import com.dfsek.terra.api.platform.block.data.Slab;
import com.dfsek.terra.api.platform.block.data.Stairs; import com.dfsek.terra.api.platform.block.data.Stairs;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.platform.world.World;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.data.type.Wall; import org.bukkit.block.data.type.Wall;
@@ -325,6 +327,22 @@ public final class BukkitAdapter {
} }
public static com.dfsek.terra.api.math.vector.Location adapt(Location location) { public static com.dfsek.terra.api.math.vector.Location adapt(Location location) {
return new com.dfsek.terra.api.math.vector.Location(new BukkitWorld(location.getWorld()), location.getX(), location.getY(), location.getZ()); return new com.dfsek.terra.api.math.vector.Location(adapt(location.getWorld()), location.getX(), location.getY(), location.getZ());
}
public static World adapt(org.bukkit.World world) {
return new BukkitWorld(world);
}
public static org.bukkit.World adapt(World world) {
return (org.bukkit.World) world.getHandle();
}
public static Chunk adapt(org.bukkit.Chunk chunk) {
return new BukkitChunk(chunk);
}
public static org.bukkit.Chunk adapt(Chunk chunk) {
return (org.bukkit.Chunk) chunk.getHandle();
} }
} }
@@ -24,7 +24,7 @@ public class BukkitChunk implements Chunk {
@Override @Override
public World getWorld() { public World getWorld() {
return new BukkitWorld(delegate.getWorld()); return BukkitAdapter.adapt(delegate.getWorld());
} }
@Override @Override
@@ -55,7 +55,7 @@ public class BukkitWorld implements World {
@Override @Override
public Chunk getChunkAt(int x, int z) { public Chunk getChunkAt(int x, int z) {
return new BukkitChunk(delegate.getChunkAt(x, z)); return BukkitAdapter.adapt(delegate.getChunkAt(x, z));
} }
@Override @Override
@@ -7,7 +7,6 @@ import com.dfsek.terra.api.platform.block.BlockFace;
import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.block.state.BlockState; import com.dfsek.terra.api.platform.block.state.BlockState;
import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.bukkit.world.BukkitWorld;
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData; import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData;
import com.dfsek.terra.bukkit.world.block.state.BukkitBlockState; import com.dfsek.terra.bukkit.world.block.state.BukkitBlockState;
@@ -50,7 +49,7 @@ public class BukkitBlock implements Block {
@Override @Override
public Location getLocation() { public Location getLocation() {
return new Location(new BukkitWorld(delegate.getWorld()), delegate.getX(), delegate.getY(), delegate.getZ()); return BukkitAdapter.adapt(delegate.getLocation());
} }
@Override @Override