mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2026-01-04 15:31:38 +00:00
Add default integration region visualisation command, whereami current region list at location command
This commit is contained in:
@@ -66,7 +66,7 @@ allprojects {
|
||||
|
||||
dependencies {
|
||||
implementation("com.convallyria.languagy:api:3.0.1")
|
||||
compileOnly("org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT")
|
||||
compileOnly("org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package net.islandearth.rpgregions.api.integrations.rpgregions.region;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CuboidRegion extends RPGRegionsRegion {
|
||||
@@ -12,13 +17,29 @@ public class CuboidRegion extends RPGRegionsRegion {
|
||||
super(name, world);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Location getFirstCorner() {
|
||||
return getPoints().get(0);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Location getSecondCorner() {
|
||||
return getPoints().get(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addPoint(final Location location) {
|
||||
if (this.getPoints().size() == 2) return false;
|
||||
return super.addPoint(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWithinBounds(Location location) {
|
||||
if (!this.isWithinWorldBounds(location.getWorld())) return false;
|
||||
final List<Location> points = getPoints();
|
||||
if (points.size() < 2) return false;
|
||||
Location first = points.get(0);
|
||||
Location second = points.get(1);
|
||||
if (points.size() != 2) return false;
|
||||
Location first = getFirstCorner();
|
||||
Location second = getSecondCorner();
|
||||
final double x1 = first.getX();
|
||||
final double x2 = second.getX();
|
||||
final double y1 = first.getY();
|
||||
@@ -29,4 +50,47 @@ public class CuboidRegion extends RPGRegionsRegion {
|
||||
Vector max = new Vector(Math.max(x1, x2), Math.max(y1, y2), Math.max(z1, z2));
|
||||
return location.toVector().isInAABB(min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visualise(Player player) {
|
||||
final Location firstCorner = getFirstCorner();
|
||||
final Location secondCorner = getSecondCorner();
|
||||
if (firstCorner == null || secondCorner == null) {
|
||||
player.sendMessage(ChatColor.RED + "This region is incomplete, so only the existing corners shall be visualised.");
|
||||
if (firstCorner != null) player.sendBlockChange(firstCorner, Material.YELLOW_STAINED_GLASS.createBlockData());
|
||||
if (secondCorner != null) player.sendBlockChange(secondCorner, Material.YELLOW_STAINED_GLASS.createBlockData());
|
||||
return;
|
||||
}
|
||||
|
||||
for (Location location : getHollowCube(firstCorner, secondCorner)) {
|
||||
player.sendBlockChange(location, Material.GREEN_STAINED_GLASS.createBlockData());
|
||||
}
|
||||
}
|
||||
|
||||
public List<Location> getHollowCube(Location corner1, Location corner2) {
|
||||
List<Location> result = new ArrayList<>();
|
||||
World world = corner1.getWorld();
|
||||
double minX = Math.min(corner1.getX(), corner2.getX());
|
||||
double minY = Math.min(corner1.getY(), corner2.getY());
|
||||
double minZ = Math.min(corner1.getZ(), corner2.getZ());
|
||||
double maxX = Math.max(corner1.getX(), corner2.getX());
|
||||
double maxY = Math.max(corner1.getY(), corner2.getY());
|
||||
double maxZ = Math.max(corner1.getZ(), corner2.getZ());
|
||||
|
||||
for (double x = minX; x <= maxX; x += 1) {
|
||||
for (double y = minY; y <= maxY; y += 1) {
|
||||
for (double z = minZ; z <= maxZ; z += 1) {
|
||||
int components = 0;
|
||||
if (x == minX || x == maxX) components++;
|
||||
if (y == minY || y == maxY) components++;
|
||||
if (z == minZ || z == maxZ) components++;
|
||||
if (components >= 2) {
|
||||
result.add(new Location(world, x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package net.islandearth.rpgregions.api.integrations.rpgregions.region;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
@@ -26,4 +28,12 @@ public class PolyRegion extends RPGRegionsRegion {
|
||||
Polygon polygon = new Polygon(xPoints.stream().mapToInt(Integer::intValue).toArray(), yPoints.stream().mapToInt(Integer::intValue).toArray(), xPoints.size());
|
||||
return polygon.contains(location.getX(), location.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visualise(Player player) {
|
||||
//TODO make this better somehow?
|
||||
for (Location point : getPoints()) {
|
||||
player.sendBlockChange(point, Material.GREEN_STAINED_GLASS.createBlockData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ public abstract class RPGRegionsRegion {
|
||||
return points;
|
||||
}
|
||||
|
||||
public void addPoint(final Location location) {
|
||||
this.points.add(location);
|
||||
public boolean addPoint(final Location location) {
|
||||
return this.points.add(location);
|
||||
}
|
||||
|
||||
public void removePoint(final Location location) {
|
||||
@@ -64,6 +64,8 @@ public abstract class RPGRegionsRegion {
|
||||
|
||||
public abstract boolean isWithinBounds(final Location location);
|
||||
|
||||
public abstract void visualise(Player player);
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{name=" + name + ", priority=" + priority + ", points=" + points + "}";
|
||||
|
||||
@@ -21,6 +21,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -116,8 +118,11 @@ public class RPGRegionsIntegrationCommand extends BaseCommand {
|
||||
@co.aikar.commands.annotation.Optional Double z) {
|
||||
System.out.println("world: " + world + ", x:" + x + ", y:" + y + ", z:" + z);
|
||||
if (sender instanceof Player player && x == null && y == null && z == null) {
|
||||
region.addPoint(player.getLocation());
|
||||
player.sendMessage(ChatColor.GREEN + "Added point to " + region.getName() + ".");
|
||||
if (!region.addPoint(player.getLocation())) {
|
||||
player.sendMessage(ChatColor.RED + "Could not add a point to that region because it exceeds the size for its type.");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.GREEN + "Added point to " + region.getName() + ".");
|
||||
}
|
||||
} else {
|
||||
if (world == null || x == null || y == null || z == null) {
|
||||
sender.sendMessage(ChatColor.RED + "You need to specify the world, x, y, z of the point.");
|
||||
@@ -149,6 +154,32 @@ public class RPGRegionsIntegrationCommand extends BaseCommand {
|
||||
sender.sendMessage(ChatColor.GREEN + "Set region '" + region.getName() + "' world to '" + world.getName() + "'.");
|
||||
}
|
||||
|
||||
@Subcommand("visualise")
|
||||
@CommandCompletion("@integration-regions")
|
||||
public void onVisualise(final Player sender, final RPGRegionsRegion region) {
|
||||
region.visualise(sender);
|
||||
}
|
||||
|
||||
@Subcommand("whereami")
|
||||
public void onWhereAmI(final Player sender) {
|
||||
final RPGRegionsIntegration manager = (RPGRegionsIntegration) plugin.getManagers().getIntegrationManager();
|
||||
List<RPGRegionsRegion> regions = new ArrayList<>();
|
||||
for (RPGRegionsRegion region : manager.getRegions()) {
|
||||
if (region.isWithinBounds(sender)) {
|
||||
regions.add(region);
|
||||
}
|
||||
}
|
||||
|
||||
if (regions.isEmpty()) {
|
||||
sender.sendMessage(ChatColor.RED + "You are not currently inside any region.");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.GREEN + "You are currently inside these regions:");
|
||||
for (RPGRegionsRegion region : regions) {
|
||||
sender.sendMessage(ChatColor.GREEN + " - " + region.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subcommand("migrate")
|
||||
@CommandCompletion("@worlds")
|
||||
public void onMigrate(final CommandSender sender, final String worldName) {
|
||||
|
||||
@@ -261,7 +261,7 @@ public class DiscoveryGUI extends RPGRegionsGUI {
|
||||
if (configuredRegion.getWorld() == null || !finalRequirements) {
|
||||
Translations.CANNOT_TELEPORT.send(player);
|
||||
} else if (eco != null && eco.getBalance(player) < teleportCost) {
|
||||
Translations.NO_MONEY.send(player);
|
||||
Translations.TELEPORT_NO_MONEY.send(player);
|
||||
} else {
|
||||
if (configuredRegion.getLocation() != null) {
|
||||
PaperLib.teleportAsync(player, configuredRegion.getLocation());
|
||||
|
||||
@@ -177,7 +177,7 @@ public class RegionListener implements Listener {
|
||||
if (!discovered) {
|
||||
List<String> discoveredTitle = configuredRegion.getDiscoveredTitle(player);
|
||||
List<String> discoveredSubtitle = configuredRegion.getDiscoveredSubtitle(player);
|
||||
plugin.debug("Region is not discovered, sending discovery titles! " + discoveredTitle + ":" + discoveredSubtitle);
|
||||
plugin.debug("Sending 'player has already discovered region' titles! " + discoveredTitle + ":" + discoveredSubtitle);
|
||||
new TitleAnimator(player,
|
||||
plugin,
|
||||
discoveredTitle,
|
||||
@@ -188,7 +188,7 @@ public class RegionListener implements Listener {
|
||||
|
||||
List<String> title = configuredRegion.getTitle(player);
|
||||
List<String> subtitle = configuredRegion.getSubtitle(player);
|
||||
plugin.debug("Region is discovered, sending discovery titles! " + title + ":" + subtitle);
|
||||
plugin.debug("Sending 'player has just discovered region' titles! " + title + ":" + subtitle);
|
||||
new TitleAnimator(player,
|
||||
plugin,
|
||||
title,
|
||||
|
||||
Reference in New Issue
Block a user