From 796c2a42a3d181e0b251cbfec85129d0cf2f913e Mon Sep 17 00:00:00 2001 From: SamB440 Date: Fri, 17 Nov 2023 16:50:54 +0000 Subject: [PATCH] Add removepos command to integration --- .../rpgregions/region/RPGRegionsRegion.java | 4 +-- .../RPGRegionsIntegrationCommand.java | 32 ++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/api/integrations/rpgregions/region/RPGRegionsRegion.java b/rpgregions/src/main/java/net/islandearth/rpgregions/api/integrations/rpgregions/region/RPGRegionsRegion.java index c3ac67a..01719c3 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/api/integrations/rpgregions/region/RPGRegionsRegion.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/api/integrations/rpgregions/region/RPGRegionsRegion.java @@ -50,8 +50,8 @@ public abstract class RPGRegionsRegion { return this.points.add(location); } - public void removePoint(final Location location) { - this.points.remove(location); + public boolean removePoint(final Location location) { + return this.points.remove(location); } public boolean isWithinBounds(final Player player) { diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsIntegrationCommand.java b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsIntegrationCommand.java index dd42b3b..36ae608 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsIntegrationCommand.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsIntegrationCommand.java @@ -129,11 +129,41 @@ public class RPGRegionsIntegrationCommand { return; } - region.addPoint(location); + if (!region.addPoint(location)) { + sender.sendMessage(ChatColor.RED + "Could not add a point to that region because it exceeds the size for its type."); + return; + } sender.sendMessage(ChatColor.GREEN + "Added point to " + region.getName() + "."); } } + @CommandDescription("Removes a position from a region.") + @CommandMethod("rpgri|rpgrintegration removepos [location]") + public void onRemovePos(final CommandSender sender, + @Argument("region") final RPGRegionsRegion region, + @Argument("location") @Nullable Location location) { + if (sender instanceof Player player && location == null) { + for (Location point : region.getPoints()) { + if (point.distanceSquared(player.getLocation()) <= 2) { + player.sendMessage(ChatColor.GREEN + "Removed point from " + region.getName() + "."); + return; + } + } + player.sendMessage(ChatColor.RED + "Could not remove that point from the region because it does not exist."); + } else { + if (location == null) { + sender.sendMessage(ChatColor.RED + "You need to specify the world, x, y, z of the point."); + return; + } + + if (!region.removePoint(location)) { + sender.sendMessage(ChatColor.RED + "Could not remove a point from the region because it does not exist."); + return; + } + sender.sendMessage(ChatColor.GREEN + "Removed point from " + region.getName() + "."); + } + } + @CommandDescription("Sets the priority of a region. Higher priority regions override lower priority ones in the same location.") @CommandMethod("rpgri|rpgrintegration setpriority ") public void onSetPriority(final Player player,