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
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ dependencies {
implementation(libs.com.googlecode.json.simple)
implementation(libs.bstats.bukkit)
implementation(platform(libs.fawe.bom))
implementation("net.buildtheearth:projection:1.0.3")

compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Core")
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit") { isTransitive = false }
compileOnly(libs.io.papermc.paper.paper.api)
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/net/buildtheearth/buildteamtools/BuildTeamTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import net.buildtheearth.buildteamtools.modules.network.NetworkModule;
import net.buildtheearth.buildteamtools.modules.plotsystem.PlotSystemModule;
import net.buildtheearth.buildteamtools.modules.stats.StatsModule;
import net.buildtheearth.buildteamtools.utils.io.ConfigPaths;
import net.buildtheearth.buildteamtools.utils.io.ConfigUtil;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
Expand All @@ -32,6 +35,7 @@ public class BuildTeamTools extends JavaPlugin {
@Getter
private static BuildTeamTools instance = null;

private World earthWorld;

@Override
public void onEnable() {
Expand Down Expand Up @@ -88,4 +92,16 @@ public void setDebug(boolean debug) {
this.debug = debug;
ChatHelper.DEBUG = debug;
}

public World getEarthWorld() {
if (earthWorld != null)
return earthWorld;

String worldName = BuildTeamTools.getInstance().getConfig().getString(ConfigPaths.EARTH_WORLD);
if (worldName == null || worldName.isEmpty())
return null;

earthWorld = Bukkit.getWorld(worldName);
return earthWorld;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import net.buildtheearth.buildteamtools.modules.generator.components.house.HouseFlag;
import net.buildtheearth.buildteamtools.modules.generator.components.house.HouseSettings;
import net.buildtheearth.buildteamtools.modules.generator.model.Settings;
import net.buildtheearth.buildteamtools.utils.CustomHeads;
import net.buildtheearth.buildteamtools.utils.MenuItems;
import net.buildtheearth.buildteamtools.utils.heads.HeadColor;
import net.buildtheearth.buildteamtools.utils.heads.HeadFactory;
import net.buildtheearth.buildteamtools.utils.heads.HeadTexture;
import net.buildtheearth.buildteamtools.utils.menus.AbstractMenu;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -47,15 +49,15 @@ protected void setPreviewItems() {
this.windowHeight = (int) house.getPlayerSettings().get(uuid).getValues().get(HouseFlag.WINDOW_HEIGHT);
this.windowDistance = (int) house.getPlayerSettings().get(uuid).getValues().get(HouseFlag.WINDOW_DISTANCE);

createCounter(CustomHeads.SliderColor.WHITE, FLOOR_COUNT_SLOT, "Number of Floors", floorCount, 1, 10, "Floors");
createCounter(CustomHeads.SliderColor.LIGHT_GRAY, FLOOR_HEIGHT_SLOT, "Floors Height", floorHeight, 1, 10, "Blocks");
createCounter(CustomHeads.SliderColor.WHITE, BASE_HEIGHT_SLOT, "Basement Height", baseHeight, 0, 10, "Blocks");
createCounter(CustomHeads.SliderColor.WHITE, WINDOW_WIDTH_SLOT, "Window Width", windowWidth, 1, 5, "Blocks");
createCounter(CustomHeads.SliderColor.LIGHT_GRAY, WINDOW_HEIGHT_SLOT, "Window Height", windowHeight, 1, 5, "Blocks");
createCounter(CustomHeads.SliderColor.WHITE, WINDOW_DISTANCE_SLOT, "Window Distance", windowDistance, 1, 6, "Blocks");
createCounter(HeadColor.WHITE, FLOOR_COUNT_SLOT, "Number of Floors", floorCount, 1, 10, "Floors");
createCounter(HeadColor.LIGHT_GRAY, FLOOR_HEIGHT_SLOT, "Floors Height", floorHeight, 1, 10, "Blocks");
createCounter(HeadColor.WHITE, BASE_HEIGHT_SLOT, "Basement Height", baseHeight, 0, 10, "Blocks");
createCounter(HeadColor.WHITE, WINDOW_WIDTH_SLOT, "Window Width", windowWidth, 1, 5, "Blocks");
createCounter(HeadColor.LIGHT_GRAY, WINDOW_HEIGHT_SLOT, "Window Height", windowHeight, 1, 5, "Blocks");
createCounter(HeadColor.WHITE, WINDOW_DISTANCE_SLOT, "Window Distance", windowDistance, 1, 6, "Blocks");


getMenu().getSlot(NEXT_ITEM_SLOT).setItem(CustomHeads.getCheckmarkItem("§eNext"));
getMenu().getSlot(NEXT_ITEM_SLOT).setItem(HeadFactory.head(HeadTexture.CHECKMARK, "§eNext"));
setBackItem(BACK_ITEM_SLOT, new BaseColorMenu(getMenuPlayer(), false));

super.setPreviewItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import com.cryptomorin.xseries.XMaterial;
import de.micromata.opengis.kml.v_2_2_0.Coordinate;
import net.buildtheearth.buildteamtools.BuildTeamTools;
import net.buildtheearth.buildteamtools.modules.navigation.NavUtils;
import net.buildtheearth.buildteamtools.utils.BlockLocation;
import net.buildtheearth.buildteamtools.utils.GeometricUtils;
import net.buildtheearth.buildteamtools.utils.LineRasterization;
import net.buildtheearth.buildteamtools.utils.PolygonTools;
import net.buildtheearth.model.GeographicalCoordinate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -516,7 +517,7 @@ public boolean undoCommand(Player player) {
* <p>
* This method:
* <ol>
* <li>Converts lat/lon to Minecraft X/Z using {@link GeometricUtils#getLocationFromCoordinates(double[])}</li>
* <li>Converts lat/lon to Minecraft X/Z using </li>
* <li>Applies the KML altitude offset (Google Earth altitudes are relative to ground)</li>
* </ol>
* <p>
Expand All @@ -527,7 +528,7 @@ public boolean undoCommand(Player player) {
* @return A Bukkit Location with X/Z from projection and Y adjusted for altitude
*/
private @NonNull Location getLocationFromCoordinates(double[] coordinates, double altitudeFromKML) {
Location mcLocation = GeometricUtils.getLocationFromCoordinates(coordinates);
Location mcLocation = NavUtils.getLocationFromCoordinates(new GeographicalCoordinate(coordinates[0], coordinates[1]));
//add altitude from kml (altitude from Google Earth is always relative to ground)
//note: the "-2" is only neccesary because
// getLocationFromCoordinates returns terrain altitude + 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import net.buildtheearth.buildteamtools.modules.generator.components.road.RoadFlag;
import net.buildtheearth.buildteamtools.modules.generator.components.road.RoadSettings;
import net.buildtheearth.buildteamtools.modules.generator.model.Settings;
import net.buildtheearth.buildteamtools.utils.CustomHeads;
import net.buildtheearth.buildteamtools.utils.ListUtil;
import net.buildtheearth.buildteamtools.utils.MenuItems;
import net.buildtheearth.buildteamtools.utils.heads.HeadColor;
import net.buildtheearth.buildteamtools.utils.heads.HeadFactory;
import net.buildtheearth.buildteamtools.utils.heads.HeadTexture;
import net.buildtheearth.buildteamtools.utils.menus.AbstractMenu;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -63,17 +65,17 @@ protected void setPreviewItems() {
if (roadSlab.length == 0)
roadSlab = new XMaterial[]{XMaterial.BARRIER};

createCounter(CustomHeads.SliderColor.WHITE, LANE_COUNT_SLOT, "Number of Lanes", laneCount, 1, 10, "Lanes");
createCounter(CustomHeads.SliderColor.LIGHT_GRAY, LANE_WIDTH_SLOT, "Lane Width", laneWidth, 1, 30, "Blocks");
createCounter(CustomHeads.SliderColor.WHITE, SIDEWALK_WIDTH_SLOT, "Sidewalk Width", sidewalkWidth, 1, 30, "Blocks");
createCounter(CustomHeads.SliderColor.LIGHT_GRAY, STREET_LAMP_DISTANCE_SLOT, "Street Lamp Distance", streetLampDistance, 5, 500, "Blocks");
createCounter(HeadColor.WHITE, LANE_COUNT_SLOT, "Number of Lanes", laneCount, 1, 10, "Lanes");
createCounter(HeadColor.LIGHT_GRAY, LANE_WIDTH_SLOT, "Lane Width", laneWidth, 1, 30, "Blocks");
createCounter(HeadColor.WHITE, SIDEWALK_WIDTH_SLOT, "Sidewalk Width", sidewalkWidth, 1, 30, "Blocks");
createCounter(HeadColor.LIGHT_GRAY, STREET_LAMP_DISTANCE_SLOT, "Street Lamp Distance", streetLampDistance, 5, 500, "Blocks");

setChoiceItems(CustomHeads.SliderColor.WHITE, MARKINGS_MATERIAL_SLOT, "Line Markings Color", markingsMaterial.parseItem());
setChoiceItems(CustomHeads.SliderColor.LIGHT_GRAY, ROAD_SLAB_SLOT, "Road Elevation Slab", roadSlab[0].parseItem());
setChoiceItems(CustomHeads.SliderColor.WHITE, SIDEWALK_SLAB_SLOT, "Sidewalk Elevation Slab", sidewalkSlab[0].parseItem());
setChoiceItems(CustomHeads.SliderColor.LIGHT_GRAY, STREET_LAMP_TYPE_SLOT, "Street Lamp Type", streetLampType);
setChoiceItems(HeadColor.WHITE, MARKINGS_MATERIAL_SLOT, "Line Markings Color", markingsMaterial.parseItem());
setChoiceItems(HeadColor.LIGHT_GRAY, ROAD_SLAB_SLOT, "Road Elevation Slab", roadSlab[0].parseItem());
setChoiceItems(HeadColor.WHITE, SIDEWALK_SLAB_SLOT, "Sidewalk Elevation Slab", sidewalkSlab[0].parseItem());
setChoiceItems(HeadColor.LIGHT_GRAY, STREET_LAMP_TYPE_SLOT, "Street Lamp Type", streetLampType);

getMenu().getSlot(NEXT_ITEM_SLOT).setItem(CustomHeads.getCheckmarkItem("§eNext"));
getMenu().getSlot(NEXT_ITEM_SLOT).setItem(HeadFactory.head(HeadTexture.CHECKMARK, "§eNext"));

setBackItem(BACK_ITEM_SLOT, new SidewalkColorMenu(getMenuPlayer(), false));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import lombok.experimental.UtilityClass;
import net.buildtheearth.OutOfProjectionBoundsException;
import net.buildtheearth.Projection;
import net.buildtheearth.buildteamtools.BuildTeamTools;
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.model.GeographicalCoordinate;
import net.buildtheearth.model.MinecraftCoordinate;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.UnsafeValues;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -117,4 +123,54 @@ public static void switchToTeam(BuildTeam team, Player clickPlayer) {
// Create an "other" Warp Group for warps that don't belong to a warp group
return new WarpGroup(team, "Other", "Other warps", -1, null);
}

/**
* Creates a minecraft location object for the specified coordinates, yaw and pitch from the BTE projection.
* Height is extracted from the world.
* <p>
* Note: Height returned is actually terrain elevation +2. This is because this method internally uses
* Bukkits @see World::getHighestBlockYAt() already returns elevation+1, and this method deliberately
* adds one to the location elevation on top.
* </p>
* The world is extracted from the server config's "earth world". If no earth world is specified then the height defaults to 64
* and the world is nullified.
Comment thread
kyanvde marked this conversation as resolved.
*
* @param coordinate Latitude and longitude of the location
* @param yaw Player's yaw
* @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) {
try {
MinecraftCoordinate mcCoord = Projection.toMinecraft(coordinate);

World earthWorld = BuildTeamTools.getInstance().getEarthWorld();
int y = 64;

if (earthWorld != null)
y = earthWorld.getHighestBlockYAt(mcCoord.blockX(), mcCoord.blockZ()) + 1;

return new Location(earthWorld, mcCoord.x(), y, mcCoord.z(), yaw, pitch);
} catch (OutOfProjectionBoundsException e) {
throw new RuntimeException(e);
}
}

/**
* Creates a minecraft location object for the specified coordinates from the BTE projection.
* Height is extracted from the world.
* <p>
* Note: Height returned is actually terrain elevation +2. This is because this method internally uses
* Bukkits @see World::getHighestBlockYAt() already returns elevation+1, and this method deliberately
* adds one to the location elevation on top.
* </p>
* The world is extracted from the server config's "earth world". If no earth world is specified then the height defaults to 64
* and the world is nullified.
*
* @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) {
return getLocationFromCoordinatesYawPitch(coordinate, 0, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
import de.bluecolored.bluemap.api.BlueMapMap;
import de.bluecolored.bluemap.api.markers.MarkerSet;
import de.bluecolored.bluemap.api.markers.POIMarker;
import net.buildtheearth.OutOfProjectionBoundsException;
import net.buildtheearth.Projection;
import net.buildtheearth.buildteamtools.BuildTeamTools;
import net.buildtheearth.buildteamtools.modules.ModuleComponent;
import net.buildtheearth.buildteamtools.modules.navigation.components.warps.model.Warp;
import net.buildtheearth.buildteamtools.modules.navigation.components.warps.model.WarpGroup;
import net.buildtheearth.buildteamtools.modules.network.NetworkModule;
import net.buildtheearth.buildteamtools.utils.geo.CoordinateConversion;
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;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -145,16 +148,23 @@ private void registerWarpsForWorld(BlueMapAPI api, @NotNull WarpGroup warpGroup,
*/
private void addWarpMarker(@NotNull MarkerSet markerSet, @NotNull Warp warp) {
// Convert geographic coordinates to Minecraft world coordinates
double[] xz = CoordinateConversion.convertFromGeo(warp.getLat(), warp.getLon());

// Create a POI marker for the warp
POIMarker marker = POIMarker.builder()
.label(warp.getName())
.position(new Vector3d(xz[0], warp.getY(), xz[1]))
.build();

// Add marker to the marker set
markerSet.getMarkers().put(warp.getId().toString(), marker);
try {
MinecraftCoordinate coordinate = Projection.toMinecraft(new GeographicalCoordinate(warp.getLat(), warp.getLon()));

// Create a POI marker for the warp
POIMarker marker = POIMarker.builder()
.label(warp.getName())
.position(new Vector3d(coordinate.x(), warp.getY(), coordinate.z()))
.build();

// Add marker to the marker set
markerSet.getMarkers().put(warp.getId().toString(), marker);
} catch (OutOfProjectionBoundsException e) {
BuildTeamTools.getInstance().getComponentLogger().warn(Component.text(
"Warp '" + warp.getName() + "' (" + warp.getId() + ") is out of projection bounds. Skipping BlueMap marker registration for this warp.",
NamedTextColor.YELLOW
));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.buildtheearth.buildteamtools.modules.ModuleComponent;
import net.buildtheearth.buildteamtools.modules.navigation.NavUtils;
import net.buildtheearth.buildteamtools.modules.network.NetworkModule;
import net.buildtheearth.buildteamtools.utils.GeometricUtils;
import net.buildtheearth.model.GeographicalCoordinate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
Expand Down Expand Up @@ -47,11 +47,11 @@ public void addTpllToQueue(ByteArrayDataInput in, Player player) {
//Extracts the coordinates from the plugin message
double targetLatitude = Double.parseDouble(in.readUTF());
double targetLongitude = Double.parseDouble(in.readUTF());
double[] coordinates = new double[]{targetLatitude, targetLongitude};

ChatHelper.logDebug("The coordinates of the tpll event are: %s %s", targetLatitude, targetLongitude);

// Creates a bukkit location for this tpll target
Location targetTpllLocation = GeometricUtils.getLocationFromCoordinates(coordinates);
Location targetTpllLocation = NavUtils.getLocationFromCoordinates(new GeographicalCoordinate(targetLatitude, targetLongitude));
ChatHelper.logDebug("Created a bukkit location for this event");
// Location may contain a null world, this is checked for when the tpll event needs to be run
// so that the player can be informed that the earth world was not specified
Expand Down
Loading
Loading