From 21f0492860d5357828cdc564d5b9f68ea05cecf5 Mon Sep 17 00:00:00 2001 From: Leander <47365075+Le4nderS@users.noreply.github.com> Date: Sat, 7 Oct 2023 17:50:33 +0200 Subject: [PATCH] closes #15 --- .../terraplusminus/commands/TpllCommand.java | 48 +++++++++++++------ .../gen/RealWorldGenerator.java | 13 +++-- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/main/java/de/btegermany/terraplusminus/commands/TpllCommand.java b/src/main/java/de/btegermany/terraplusminus/commands/TpllCommand.java index d8d2a8a..48f0cbb 100644 --- a/src/main/java/de/btegermany/terraplusminus/commands/TpllCommand.java +++ b/src/main/java/de/btegermany/terraplusminus/commands/TpllCommand.java @@ -4,9 +4,11 @@ import com.google.common.io.ByteStreams; import de.btegermany.terraplusminus.Terraplusminus; import de.btegermany.terraplusminus.data.TerraConnector; +import de.btegermany.terraplusminus.gen.RealWorldGenerator; import de.btegermany.terraplusminus.utils.ConfigurationHelper; import io.papermc.lib.PaperLib; import net.buildtheearth.terraminusminus.generator.EarthGeneratorSettings; +import net.buildtheearth.terraminusminus.projection.GeographicProjection; import net.buildtheearth.terraminusminus.projection.OutOfProjectionBoundsException; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -15,13 +17,15 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.generator.ChunkGenerator; import org.jetbrains.annotations.NotNull; import java.util.logging.Level; -public class TpllCommand implements CommandExecutor { +import static org.bukkit.ChatColor.RED; + - private final EarthGeneratorSettings bteGeneratorSettings = EarthGeneratorSettings.parse(EarthGeneratorSettings.BTE_DEFAULT_SETTINGS); +public class TpllCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { @@ -106,7 +110,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command if (player.hasPermission("t+-.tpll")) { World tpWorld = player.getWorld(); - int xOffset = Terraplusminus.config.getInt("terrain_offset.x"); + int yOffset = 0; if (Terraplusminus.config.getBoolean("linked_worlds.enabled") && Terraplusminus.config.getString("linked_worlds.method").equalsIgnoreCase("MULTIVERSE")) { String lastServerName = ConfigurationHelper.getLastServerName("world"); @@ -121,28 +125,42 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command Bukkit.getLogger().log(Level.SEVERE, "[T+-] Could not parse y-offset from config"); } } else { - Terraplusminus.config.getInt("terrain_offset.y"); + yOffset = Terraplusminus.config.getInt("terrain_offset.y"); } + + + int xOffset = Terraplusminus.config.getInt("terrain_offset.x"); int zOffset = Terraplusminus.config.getInt("terrain_offset.z"); - Double minLat = Terraplusminus.config.getDouble("min_latitude"); - Double maxLat = Terraplusminus.config.getDouble("max_latitude"); - Double minLon = Terraplusminus.config.getDouble("min_longitude"); - Double maxLon = Terraplusminus.config.getDouble("max_longitude"); + double minLat = Terraplusminus.config.getDouble("min_latitude"); + double maxLat = Terraplusminus.config.getDouble("max_latitude"); + double minLon = Terraplusminus.config.getDouble("min_longitude"); + double maxLon = Terraplusminus.config.getDouble("max_longitude"); double[] coordinates = new double[2]; coordinates[1] = Double.parseDouble(args[0].replace(",", "").replace("°", "")); coordinates[0] = Double.parseDouble(args[1].replace("°", "")); - double[] mcCoordinates = new double[0]; + ChunkGenerator generator = player.getWorld().getGenerator(); + if (!(generator instanceof RealWorldGenerator)) { + commandSender.sendMessage(RED + "Must be in a Terra 1 to 1 world!"); + return true; + } + RealWorldGenerator terraGenerator = (RealWorldGenerator) generator; + EarthGeneratorSettings generatorSettings = terraGenerator.getSettings(); + GeographicProjection projection = generatorSettings.projection(); + // int yOffset = terraGenerator.getYOffset(); does not work anymore because i need the offsets for all worlds + + double[] mcCoordinates; try { - mcCoordinates = bteGeneratorSettings.projection().fromGeo(coordinates[0], coordinates[1]); + mcCoordinates = projection.fromGeo(coordinates[0], coordinates[1]); } catch (OutOfProjectionBoundsException e) { - e.printStackTrace(); + commandSender.sendMessage(RED + "Location is not within projection bounds"); + return true; } if (minLat != 0 && maxLat != 0 && minLon != 0 && maxLon != 0 && !player.hasPermission("t+-.admin")) { if (coordinates[1] < minLat || coordinates[0] < minLon || coordinates[1] > maxLat || coordinates[0] > maxLon) { - player.sendMessage(Terraplusminus.config.getString("prefix") + "§cYou cannot tpll to these coordinates, because this area is being worked on by another build team."); + player.sendMessage(Terraplusminus.config.getString("prefix") + RED + "You cannot tpll to these coordinates, because this area is being worked on by another build team."); return true; } } @@ -217,13 +235,13 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command return true; } } - Location location = new Location(tpWorld, mcCoordinates[0] + xOffset, height, mcCoordinates[1] + zOffset, player.getLocation().getYaw(), player.getLocation().getPitch()); + Location location = new Location(tpWorld, mcCoordinates[0], height, mcCoordinates[1], player.getLocation().getYaw(), player.getLocation().getPitch()); if (PaperLib.isChunkGenerated(location)) { if (args.length >= 3) { - location = new Location(tpWorld, mcCoordinates[0] + xOffset, height, mcCoordinates[1] + zOffset, player.getLocation().getYaw(), player.getLocation().getPitch()); + location = new Location(tpWorld, mcCoordinates[0], height, mcCoordinates[1], player.getLocation().getYaw(), player.getLocation().getPitch()); } else { - location = new Location(tpWorld, mcCoordinates[0] + xOffset, tpWorld.getHighestBlockYAt((int) mcCoordinates[0] + xOffset, (int) mcCoordinates[1] + zOffset) + 1, mcCoordinates[1] + zOffset, player.getLocation().getYaw(), player.getLocation().getPitch()); + location = new Location(tpWorld, mcCoordinates[0], tpWorld.getHighestBlockYAt((int) mcCoordinates[0], (int) mcCoordinates[1]) + 1, mcCoordinates[1], player.getLocation().getYaw(), player.getLocation().getPitch()); } } else { player.sendMessage(Terraplusminus.config.getString("prefix") + "§7Location is generating. Please wait a moment..."); diff --git a/src/main/java/de/btegermany/terraplusminus/gen/RealWorldGenerator.java b/src/main/java/de/btegermany/terraplusminus/gen/RealWorldGenerator.java index d12c3b3..2f13cc1 100644 --- a/src/main/java/de/btegermany/terraplusminus/gen/RealWorldGenerator.java +++ b/src/main/java/de/btegermany/terraplusminus/gen/RealWorldGenerator.java @@ -5,6 +5,7 @@ import de.btegermany.terraplusminus.Terraplusminus; import de.btegermany.terraplusminus.gen.tree.TreePopulator; import de.btegermany.terraplusminus.utils.ConfigurationHelper; +import lombok.Getter; import net.buildtheearth.terraminusminus.generator.CachedChunkData; import net.buildtheearth.terraminusminus.generator.ChunkDataLoader; import net.buildtheearth.terraminusminus.generator.EarthGeneratorSettings; @@ -38,12 +39,16 @@ public class RealWorldGenerator extends ChunkGenerator { + + @Getter + private final EarthGeneratorSettings settings; + @Getter + private final int yOffset; private Location spawnLocation = null; - public LoadingCache> cache; + private final LoadingCache> cache; private final CustomBiomeProvider customBiomeProvider; - private final int yOffset; private final Material surfaceMaterial; private final Map materialMapping; @@ -71,13 +76,13 @@ public RealWorldGenerator(int yOffset) { this.yOffset = yOffset; } - settings = settings.withProjection(projection); + this.settings = settings.withProjection(projection); this.customBiomeProvider = new CustomBiomeProvider(); this.cache = CacheBuilder.newBuilder() .expireAfterAccess(5L, TimeUnit.MINUTES) .softValues() - .build(new ChunkDataLoader(settings)); + .build(new ChunkDataLoader(this.settings)); this.surfaceMaterial = ConfigurationHelper.getMaterial(Terraplusminus.config, "surface_material", GRASS_BLOCK); this.materialMapping = Map.of(