Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ repositories {
maven { url = uri("https://jitpack.io") }

maven("https://repo.bluecolored.de/releases")

maven {
url = uri("https://repo.essentialsx.net/releases/")
}
}

dependencies {
Expand Down Expand Up @@ -91,6 +95,9 @@ dependencies {
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit") { isTransitive = false }
compileOnly(libs.paper.api)
compileOnly(libs.bluemap.api)
compileOnly("net.essentialsx:EssentialsX:2.19.0") {
isTransitive = false
}
}

val versionDetails: groovy.lang.Closure<com.palantir.gradle.gitversion.VersionDetails> by extra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.buildtheearth.buildteamtools.modules.network.model.BuildTeam;
import net.buildtheearth.buildteamtools.utils.io.ConfigPaths;
import net.buildtheearth.buildteamtools.utils.io.ConfigUtil;
import net.buildtheearth.model.GeographicalCoordinate;
import net.buildtheearth.model.MinecraftCoordinate;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
Expand Down Expand Up @@ -151,7 +150,7 @@ private void registerWarpsForWorld(BlueMapAPI api, @NotNull WarpGroup warpGroup,
private void addWarpMarker(@NotNull MarkerSet markerSet, @NotNull Warp warp) {
// Convert geographic coordinates to Minecraft world coordinates
try {
MinecraftCoordinate coordinate = Projection.toMinecraft(new GeographicalCoordinate(warp.getLat(), warp.getLon()));
MinecraftCoordinate coordinate = Projection.toMinecraft(warp.getCoordinate());

// Create a POI marker for the warp
POIMarker marker = POIMarker.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,28 @@ public void processQueueForPlayer(@NonNull Player player) {
* Sends a plugin message with a tpll request to the target server and sends the player there.
*
* @param player The player to send to the new server.
* @param coordinates The coordinates to send the player to on join.
* @param coordinate The coordinate to send the player to on join.
* @param targetServerName The server to send the player to.
*/
public void tpllPlayer(@NotNull Player player, double @NotNull [] coordinates, String targetServerName) {
public void tpllPlayer(@NotNull Player player, @NotNull GeographicalCoordinate coordinate, String targetServerName) {
ChatHelper.logDebug("Starting universal tpll teleportation for %s to %s.", player.getDisplayName(), targetServerName);
// Send a plugin message to the target server which adds the tpll to the queue
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("TPLL");
out.writeUTF(targetServerName);
out.writeUTF(player.getUniqueId().toString());
out.writeUTF(String.valueOf(coordinates[0]));
out.writeUTF(String.valueOf(coordinates[1]));
out.writeUTF(String.valueOf(coordinate.latitude()));
out.writeUTF(String.valueOf(coordinate.longitude()));
player.sendPluginMessage(BuildTeamTools.getInstance(), "btt:buildteam", out.toByteArray());

// Switch the player to the target server
ChatHelper.logDebug("Teleported player to the target server.");
}

public void tpllPlayerTransfer(@NotNull Player player, double @NotNull [] coordinates, String ip) {
public void tpllPlayerTransfer(@NotNull Player player, @NotNull GeographicalCoordinate coordinate, String ip) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeDouble(coordinates[0]);
out.writeDouble(coordinates[1]);
out.writeDouble(coordinate.latitude());
out.writeDouble(coordinate.longitude());
player.storeCookie(TPLL_COOKIE_KEY, out.toByteArray());
NavUtils.transferPlayer(player, ip);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.buildtheearth.buildteamtools.modules.network.api.OpenStreetMapAPI;
import net.buildtheearth.buildteamtools.modules.network.model.BuildTeam;
import net.buildtheearth.buildteamtools.modules.network.model.Region;
import net.buildtheearth.model.GeographicalCoordinate;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
Expand All @@ -27,9 +28,7 @@ public class TpllListener implements Listener {
// Proxy manager to handle network-related operations
private final NetworkModule networkModule = NetworkModule.getInstance();

// Latitude and longitude coordinates for teleportation
private double lon;
private double lat;
private GeographicalCoordinate coordinate;

// Target server name for teleportation
private BuildTeam targetBuildTeam;
Expand All @@ -42,7 +41,7 @@ public void onTpll(PlayerCommandPreprocessEvent event) {
// Check if the command is a TPLL command
if (!isTpllCommand(event)) return;

ChatHelper.logDebug("Intercepted TPLL command wit lat and lon: %s %s", lat, lon);
ChatHelper.logDebug("Intercepted TPLL command wit lat and lon: %s %s", coordinate.latitude(), coordinate.longitude());

// Check if teleportation interception is required
shouldIntercept().thenAcceptAsync(shouldIntercept -> {
Expand All @@ -51,11 +50,11 @@ public void onTpll(PlayerCommandPreprocessEvent event) {
var type = NavUtils.determineSwitchPossibilityOrMsgPlayerIfNone(event.getPlayer(), targetBuildTeam);
if (type != null) {
if (type == NavUtils.NavSwitchType.NETWORK) {
NavigationModule.getInstance().getTpllComponent().tpllPlayer(event.getPlayer(),
new double[]{lat, lon}, targetBuildTeam.getServerName());
NavigationModule.getInstance().getTpllComponent().tpllPlayer(event.getPlayer(), coordinate,
targetBuildTeam.getServerName());
} else if (type == NavUtils.NavSwitchType.TRANSFER) {
NavigationModule.getInstance().getTpllComponent().tpllPlayerTransfer(event.getPlayer(),
new double[]{lat, lon}, targetBuildTeam.getIP());
NavigationModule.getInstance().getTpllComponent().tpllPlayerTransfer(event.getPlayer(), coordinate,
targetBuildTeam.getIP());
}
event.setCancelled(true);
}
Expand Down Expand Up @@ -89,8 +88,7 @@ private boolean isTpllCommand(@NotNull PlayerCommandPreprocessEvent event) {
return false;
}

this.lat = oLat;
this.lon = oLon;
coordinate = new GeographicalCoordinate(oLat, oLon);
return true;
}

Expand All @@ -100,7 +98,7 @@ private boolean isTpllCommand(@NotNull PlayerCommandPreprocessEvent event) {
* @return A CompletableFuture representing whether teleportation interception is required.
*/
private @NotNull CompletableFuture<Boolean> shouldIntercept() {
return OpenStreetMapAPI.getCountryFromLocationAsync(new double[]{lat, lon})
return OpenStreetMapAPI.getCountryFromLocationAsync(coordinate)
.thenComposeAsync(address -> {
if (address == null) return CompletableFuture.completedFuture(false);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.buildtheearth.buildteamtools.modules.navigation.components.warps;

import net.buildtheearth.buildteamtools.modules.navigation.components.warps.migrators.EssentialsWarpMigrator;
import net.buildtheearth.buildteamtools.modules.navigation.components.warps.migrators.IWarpMigrator;
import net.buildtheearth.buildteamtools.modules.navigation.components.warps.model.MigrationResult;
import net.buildtheearth.buildteamtools.modules.navigation.components.warps.model.WarpMigrationSource;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.NonNull;

import java.util.concurrent.CompletableFuture;

public class WarpMigrator {

private final IWarpMigrator migrator;

@Contract(pure = true)
public WarpMigrator(@NonNull WarpMigrationSource source) {
this.migrator = switch (source) {
case ESSENTIALS -> new EssentialsWarpMigrator();
};
}

public CompletableFuture<MigrationResult> migrate(Player player) {
return migrator.migrate(player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -64,7 +65,8 @@ public void addWarpToQueue(@NotNull ByteArrayDataInput in, Player player) {
return;
}

Location targetWarpLocation = NavUtils.getLocationFromCoordinatesYawPitch(new GeographicalCoordinate(warp.getLat(), warp.getLon()), warp.getYaw(), warp.getPitch());
Location targetWarpLocation = NavUtils.getLocationFromCoordinatesYawPitch(warp.getCoordinate(), warp.getYaw(),
warp.getPitch());
targetWarpLocation.setY(warp.getY());
targetWarpLocation.setWorld(Bukkit.getWorld(warp.getWorldName()));

Expand Down Expand Up @@ -106,7 +108,7 @@ public void warpPlayer(Player player, @NotNull Warp warp) {
BuildTeam currentTeam = NetworkModule.getInstance().getBuildTeam();
if (currentTeam != null && warp.getWarpGroup().getBuildTeam().getID().equals(currentTeam.getID())) {
ChatHelper.logDebug("Warping player %s to warp %s", player.getName(), warp.getName());
Location loc = NavUtils.getLocationFromCoordinatesYawPitch(new GeographicalCoordinate(warp.getLat(), warp.getLon()), warp.getYaw(), warp.getPitch());
Location loc = NavUtils.getLocationFromCoordinatesYawPitch(warp.getCoordinate(), warp.getYaw(), warp.getPitch());

if (loc.getWorld() == null) {
World world = Bukkit.getWorld(warp.getWorldName()) == null ? player.getWorld() : Bukkit.getWorld(warp.getWorldName());
Expand Down Expand Up @@ -169,7 +171,7 @@ public static void createWarp(@NonNull Player creator, WarpGroup group) {
GeographicalCoordinate coordinate = Projection.toGeo(new MinecraftCoordinate(location.getX(), location.getZ()));

//Get the country belonging to the coordinates
CompletableFuture<String[]> future = OpenStreetMapAPI.getCountryFromLocationAsync(new double[]{coordinate.latitude(), coordinate.longitude()});
CompletableFuture<String[]> future = OpenStreetMapAPI.getCountryFromLocationAsync(coordinate);

future.thenAccept(result -> {
String regionName = result[0];
Expand All @@ -187,7 +189,8 @@ public static void createWarp(@NonNull Player creator, WarpGroup group) {
String name = creator.getName() + "'s Warp";

// Create an instance of the warp POJO
Warp warp = new Warp(group, name, countryCodeCCA2, "cca2", null, null, null, location.getWorld().getName(), coordinate.latitude(), coordinate.longitude(), location.getY(), location.getYaw(), location.getPitch(), false);
Warp warp = new Warp(group, name, countryCodeCCA2, "cca2", null, null, null, location.getWorld().getName(),
coordinate, location.getY(), location.getYaw(), location.getPitch(), false);

Bukkit.getScheduler().runTask(BuildTeamTools.getInstance(), () ->
new WarpEditMenu(creator, warp, false, true));
Expand All @@ -203,6 +206,43 @@ public static void createWarp(@NonNull Player creator, WarpGroup group) {
}
}

/**
* Creates a warp at the given location.
*/
public static void createWarp(@NonNull Location location, String name, WarpGroup group, Player creator) throws OutOfProjectionBoundsException {
GeographicalCoordinate coordinates = Projection.toGeo(new MinecraftCoordinate(location.getX(), location.getZ()));

//Get the country belonging to the coordinates
CompletableFuture<String[]> future = OpenStreetMapAPI.getCountryFromLocationAsync(coordinates);

future.thenAccept(result -> {
String regionName = result[0];
String countryCodeCCA2 = result[1].toUpperCase();

BuildTeamTools.getInstance().getComponentLogger().debug("Creating warp at {}", location);

//Check if the team owns this region/country
boolean ownsRegion = NetworkModule.getInstance().ownsRegion(regionName, countryCodeCCA2);

if (!ownsRegion) {
creator.sendMessage(ChatHelper.getErrorString("Warp %s cannot be created. This team does not own the country %s" +
" (Country code %s)!", name, regionName, countryCodeCCA2));
return;
}

// Create an instance of the warp POJO
Warp warp = new Warp(group, name, countryCodeCCA2, "cca2", null, null, null, location.getWorld().getName(),
coordinates, location.getY(), location.getYaw(), location.getPitch(), false);

Objects.requireNonNull(NetworkModule.getInstance().getBuildTeam()).createWarp(creator, warp, true);
}).exceptionally(e -> {
BuildTeamTools.getInstance().getComponentLogger().error("An error occurred while creating the warp!", e);
Throwable cause = e.getCause() != null ? e.getCause() : e;
creator.sendMessage(ChatHelper.getErrorString("Failed to create warp %s: %s", name, cause.getMessage()));
return null;
});
}


public void createWarpGroup(@NotNull Player creator) {
// Create a default name for the warp
Expand Down
Loading
Loading