Skip to content

Commit

Permalink
closes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
Le4nderS committed Oct 7, 2023
1 parent faf7c6f commit 21f0492
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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");
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ChunkPos, CompletableFuture<CachedChunkData>> cache;
private final LoadingCache<ChunkPos, CompletableFuture<CachedChunkData>> cache;
private final CustomBiomeProvider customBiomeProvider;

private final int yOffset;

private final Material surfaceMaterial;
private final Map<String, Material> materialMapping;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 21f0492

Please sign in to comment.