Skip to content
Merged
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
63 changes: 12 additions & 51 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,25 @@ plugins {

repositories {
mavenCentral()
//mavenLocal() // NEVER use in Production/Commits!
maven {
url = uri("https://repo.papermc.io/repository/maven-public/")
}

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

maven {
url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
}

maven {
url = uri("https://mvn.alps-bte.com/repository/alps-bte/")
}

maven {
url = uri("https://repo.onarandombox.com/content/groups/public/")
}

maven {
url = uri("https://repo.codemc.io/repository/maven-snapshots/")
}
// mavenLocal() // NEVER use in Production/Commits!
maven("https://repo.papermc.io/repository/maven-public/")

maven {
url = uri("https://repo.codemc.io/repository/maven-public/")
}
maven("https://maven.buildtheearth.net/releases") // BuildTheEarth Projection

maven {
url = uri("https://jitpack.io")
}

maven {
url = uri("https://repo.dmulloy2.net/repository/public/")
}
maven("https://mvn.alps-bte.com/repository/alps-bte/") // AlpsLib

maven {
url = uri("https://maven.daporkchop.net/")
}
maven("https://maven.enginehub.org/repo/") // WorldEdit

maven {
url = uri("https://download.java.net/maven/2")
}
maven("https://mvn.wesjd.net/") // Anvilgui

maven {
url = uri("https://maven.enginehub.org/repo/")
}
maven("https://repo.bluecolored.de/releases") // BlueMap

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

maven("https://repo.bluecolored.de/releases")
// Alps Lib Geo - can be removed once https://github.com/AlpsBTE/Alps-Lib/pull/17 is merged & version is set to 1.0.0
maven("https://mvn.alps-bte.com/repository/alps-bte-snapshots/")

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

dependencies {
Expand All @@ -74,6 +34,7 @@ dependencies {
implementation(libs.alpslib.utils) {
exclude(group = "com.github.cryptomorin", module = "XSeries")
}
implementation(libs.alpslib.geo)
implementation(libs.alpsbte.canvas)
implementation(libs.xseries)
implementation(libs.anvilgui)
Expand Down
5 changes: 4 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ alpslib-io = "1.2.5"
alpslib-libpsterra = "1.1.4"
# https://mvn.alps-bte.com/service/rest/repository/browse/alps-bte/com/alpsbte/alpslib/alpslib-utils/
alpslib-utils = "1.4.6"
# https://mvn.alps-bte.com/service/rest/repository/browse/alps-bte/com/alpsbte/alpslib/alpslib-geo/
alpslib-geo = "1.0.0-SNAPSHOT"
# https://github.com/WesJD/AnvilGUI https://mvn.wesjd.net/
anvilgui = "1.10.13-SNAPSHOT"
# Ref: https://github.com/BlueMap-Minecraft/BlueMapAPI
Expand All @@ -35,7 +37,7 @@ okhttp-jvm = "5.4.0"
# @pin 26.1+ required Java 25 - # https://artifactory.papermc.io/ui/native/universe/io/papermc/paper/paper-api/
paper-api = "1.21.11-R0.1-SNAPSHOT"
# https://github.com/CryptoMorin/XSeries/releases
xseries = "13.8.0"
xseries = "13.7.0"
#
# Plugins
# https://github.com/palantir/gradle-git-version/releases
Expand All @@ -49,6 +51,7 @@ shadow = "9.4.2"
alpsbte-canvas = { module = "com.alpsbte:canvas", version.ref = "alpsbte-canvas" }
alpslib-io = { module = "com.alpsbte.alpslib:alpslib-io", version.ref = "alpslib-io" }
alpslib-utils = { module = "com.alpsbte.alpslib:alpslib-utils", version.ref = "alpslib-utils" }
alpslib-geo = { module = "com.alpsbte.alpslib:alpslib-geo", version.ref = "alpslib-geo" }
anvilgui = { module = "net.wesjd:anvilgui", version.ref = "anvilgui" }
bluemap-api = { module = "de.bluecolored:bluemap-api", version.ref = "bluemap-api" }
bstats-bukkit = { module = "org.bstats:bstats-bukkit", version.ref = "bstats" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.buildtheearth.buildteamtools.modules.navigation.components.warps.model.WarpGroup;
import net.buildtheearth.buildteamtools.modules.network.NetworkModule;
import net.buildtheearth.buildteamtools.modules.network.model.BuildTeam;
import net.buildtheearth.buildteamtools.modules.network.model.Region;
import net.buildtheearth.model.GeographicalCoordinate;
import net.buildtheearth.model.MinecraftCoordinate;
import net.md_5.bungee.api.chat.ClickEvent;
Expand All @@ -21,8 +22,10 @@
import org.bukkit.UnsafeValues;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NonNull;

@UtilityClass
public class NavUtils {
Expand Down Expand Up @@ -95,32 +98,34 @@ public static void sendNoIpMessage(@NotNull Player player, String buildteam) {
@NotNull BuildTeam targetBuildTeam) {
if (targetBuildTeam.isConnected() && targetBuildTeam.getServerName() != null && NetworkModule.getInstance().getBuildTeam() != null && NetworkModule.getInstance().getBuildTeam().isConnected()) {
return NavSwitchType.NETWORK;
} else if (targetBuildTeam.getIP() != null) {
if (isTransferCapable(player, targetBuildTeam)) {
return NavSwitchType.TRANSFER;
} else {
sendNotConnectedMessage(player, targetBuildTeam.getIP(), targetBuildTeam.getName());
return null;
}
} else {
}

if (targetBuildTeam.getIP() == null) {
sendNoIpMessage(player, targetBuildTeam.getName());
return null;
}

if (isTransferCapable(player, targetBuildTeam)) {
return NavSwitchType.TRANSFER;
}

sendNotConnectedMessage(player, targetBuildTeam.getIP(), targetBuildTeam.getName());
return null;
}

public enum NavSwitchType {
TRANSFER, NETWORK
}

public static void switchToTeam(BuildTeam team, Player clickPlayer) {
var type = NavUtils.determineSwitchPossibilityOrMsgPlayerIfNone(clickPlayer, team);

if (type != null) {
if (type == NavUtils.NavSwitchType.NETWORK) {
NavUtils.sendPlayerToConnectedServer(clickPlayer, team.getServerName());
} else if (type == NavUtils.NavSwitchType.TRANSFER) {
NavUtils.transferPlayer(clickPlayer, team.getIP());
}
NavSwitchType type = determineSwitchPossibilityOrMsgPlayerIfNone(clickPlayer, team);
if (type == null) {
return;
}

switch (type) {
case NETWORK -> sendPlayerToConnectedServer(clickPlayer, team.getServerName());
case TRANSFER -> transferPlayer(clickPlayer, team.getIP());
}
}

Expand All @@ -146,7 +151,8 @@ public static void switchToTeam(BuildTeam team, Player clickPlayer) {
* @param pitch Player's pitch
* @return A bukkit location matching the coordinates, yaw and pitch specified. Height is terrain elevation +2.
*/
public static Location getLocationFromCoordinatesYawPitch(GeographicalCoordinate coordinate, float yaw, float pitch) {
@Contract("_, _, _ -> new")
public static @NonNull Location getLocationFromCoordinatesYawPitch(GeographicalCoordinate coordinate, float yaw, float pitch) {
try {
MinecraftCoordinate mcCoord = Projection.toMinecraft(coordinate);

Expand Down Expand Up @@ -177,7 +183,33 @@ public static Location getLocationFromCoordinatesYawPitch(GeographicalCoordinate
* @param coordinate Latitude and longitude of the location
* @return A bukkit location matching the coordinates. Height is terrain elevation +2.
*/
public static Location getLocationFromCoordinates(GeographicalCoordinate coordinate) {
@Contract("_ -> new")
public static @NonNull Location getLocationFromCoordinates(GeographicalCoordinate coordinate) {
return getLocationFromCoordinatesYawPitch(coordinate, 0, 0);
}

/**
* Returns the CCA2 code of the country of the given country name.
*/
public static String getCCA2FromCountryName(String countryName, Player clickPlayer) {
Region region = findRegionByName(countryName);
if (region != null) {
return region.getCountryCodeCca2();
}

clickPlayer.sendMessage(ChatHelper.getErrorString("Could not find the country of the location! Please report that"));
return "";
}

private static @Nullable Region findRegionByName(String countryName) {
BuildTeam buildTeam = NetworkModule.getInstance().getBuildTeam();
if (buildTeam == null) {
return null;
}

return buildTeam.getRegions().stream()
.filter(region -> region.getName().equals(countryName))
.findFirst()
.orElse(null);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.buildtheearth.buildteamtools.modules.navigation;

import com.alpsbte.alpslib.geo.rgc.RgcHandler;
import com.alpsbte.alpslib.utils.ChatHelper;
import lombok.Getter;
import net.buildtheearth.buildteamtools.BuildTeamTools;
import net.buildtheearth.buildteamtools.modules.Module;
Expand All @@ -22,6 +24,19 @@
import net.buildtheearth.buildteamtools.utils.io.ConfigPaths;
import net.buildtheearth.buildteamtools.utils.io.ConfigUtil;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NonNull;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;

/**
* Manages all things related to universal tpll
Expand All @@ -37,7 +52,9 @@ public class NavigationModule extends Module {
private TpllComponent tpllComponent;
@Getter
private BluemapComponent bluemapComponent;

@Getter
@Nullable
private RgcHandler rgcHandler = null;
Comment thread
Zoriot marked this conversation as resolved.

private static NavigationModule instance = null;

Expand All @@ -61,21 +78,85 @@ public void enable() {
navigatorComponent = new NavigatorComponent();
tpllComponent = new TpllComponent();

// Check if BlueMap plugin is enabled and config allows BlueMap integration
boolean bluemapConfigEnabled = BuildTeamTools.getInstance().getConfig(ConfigUtil.NAVIGATION)
.getBoolean(ConfigPaths.Navigation.BLUEMAP_ENABLED, true);

if (Bukkit.getPluginManager().isPluginEnabled("BlueMap") && bluemapConfigEnabled) {
bluemapComponent = new BluemapComponent();
}
var navConfig = BuildTeamTools.getInstance().getConfig(ConfigUtil.NAVIGATION);
Comment thread
Zoriot marked this conversation as resolved.
initializeRgcHandler(navConfig);
initializeBluemapComponent(navConfig);

if (BuildTeamTools.getInstance().getConfig(ConfigUtil.NAVIGATION).getBoolean(ConfigPaths.Navigation.NAVIGATOR_ITEM_ENABLED, false)) {
if (navConfig.getBoolean(ConfigPaths.Navigation.NAVIGATOR_ITEM_ENABLED, false)) {
registerListeners(new NavigatorJoinListener(), new NavigatorOpenListener());
}

super.enable();
}

private void initializeRgcHandler(@NonNull FileConfiguration navConfig) {
if (!navConfig.getBoolean(ConfigPaths.Navigation.RGC_LOCAL_DB_ENABLED, false)) {
return;
}

File rgcFile = resolveRgcDatabaseFile(navConfig);
ChatHelper.logDebug("Reverse Geocode local database support is enabled. Checking for local database file at: %s", rgcFile.getAbsolutePath());

if (rgcFile.exists()) {
rgcHandler = createRgcHandler(rgcFile);
return;
}

downloadRgcDatabaseAsync(rgcFile, navConfig);
}

private @NonNull File resolveRgcDatabaseFile(@NonNull FileConfiguration navConfig) {
String path = navConfig.getString(ConfigPaths.Navigation.RGC_LOCAL_DB_PATH, "bs.file");
return BuildTeamTools.getInstance().getDataPath()
.resolve("modules/navigation")
.resolve(path)
.toFile();
}

@Contract("_ -> new")
private @NonNull RgcHandler createRgcHandler(File rgcFile) {
return new RgcHandler(rgcFile, BuildTeamTools.getInstance().getSLF4JLogger(), false);
}

private void downloadRgcDatabaseAsync(File rgcFile, FileConfiguration navConfig) {
BuildTeamTools.getInstance().getComponentLogger().info(
"Reverse Geocode local database is enabled but the file does not exist at the specified path, installing it from the configured url.");
Bukkit.getScheduler().runTaskAsynchronously(BuildTeamTools.getInstance(), () -> {
try {
downloadRgcDatabase(rgcFile, navConfig);
Bukkit.getScheduler().runTask(BuildTeamTools.getInstance(), () -> {
rgcHandler = createRgcHandler(rgcFile);
BuildTeamTools.getInstance().getComponentLogger().info(
"Successfully downloaded Reverse Geocode local database and enabled local database support for Reverse Geocoding.");
});
} catch (Exception e) {
BuildTeamTools.getInstance().getComponentLogger().error(
"Failed to download Reverse Geocode local database from the configured url, disabling local database support for Reverse Geocoding.", e);
navConfig.set(ConfigPaths.Navigation.RGC_LOCAL_DB_ENABLED, false);
}
});
}

private void downloadRgcDatabase(@NonNull File rgcFile, FileConfiguration navConfig) throws IOException {
if (!rgcFile.getParentFile().mkdirs()) {
BuildTeamTools.getInstance().getComponentLogger().warn(
"Failed to create parent directories for Reverse Geocode local database file. Make sure the plugin has the necessary permissions to create directories and files in the plugin data folder.");
}
URL url = URI.create(navConfig.getString(ConfigPaths.Navigation.RGC_LOCAL_DB_UPDATE_URL, "")).toURL();
try (ReadableByteChannel readableByteChannel = Channels.newChannel(url.openStream());
FileOutputStream fileOutputStream = new FileOutputStream(rgcFile)) {
FileChannel fileChannel = fileOutputStream.getChannel();
fileChannel.transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
}
}

private void initializeBluemapComponent(@NonNull FileConfiguration navConfig) {
boolean bluemapConfigEnabled = navConfig.getBoolean(ConfigPaths.Navigation.BLUEMAP_ENABLED, true);
if (Bukkit.getPluginManager().isPluginEnabled("BlueMap") && bluemapConfigEnabled) {
bluemapComponent = new BluemapComponent();
}
}

@Override
public void registerCommands() {
registerCommand("warp", new WarpCommand());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ public static void createWarp(@NonNull Player creator, WarpGroup group) {
String regionName = result[0];
String countryCodeCCA2 = result[1].toUpperCase();

if (countryCodeCCA2.isEmpty()) countryCodeCCA2 = NavUtils.getCCA2FromCountryName(regionName, creator);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.buildtheearth.OutOfProjectionBoundsException;
import net.buildtheearth.Projection;
import net.buildtheearth.buildteamtools.BuildTeamTools;
import net.buildtheearth.buildteamtools.modules.navigation.NavUtils;
import net.buildtheearth.buildteamtools.modules.navigation.components.warps.model.Warp;
import net.buildtheearth.buildteamtools.modules.network.NetworkModule;
import net.buildtheearth.buildteamtools.modules.network.api.OpenStreetMapAPI;
Expand Down Expand Up @@ -152,6 +153,9 @@ protected void setItemClickEventsAsync() {
String regionName = result[0];
String countryCodeCCA2 = result[1].toUpperCase();

if (countryCodeCCA2.isEmpty())
countryCodeCCA2 = NavUtils.getCCA2FromCountryName(regionName, clickPlayer);

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

Expand Down
Loading
Loading