From c7f96e3a782beac6870e14ffcfaa9c50caaa2992 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sun, 24 Aug 2025 14:10:22 +0100 Subject: [PATCH] fix: use PlotPlayer#getCurrentPlot across commands to allow / usage - fixes #4526 - supersedes #4675 --- .../java/com/plotsquared/core/command/Alias.java | 4 +--- .../java/com/plotsquared/core/command/Buy.java | 4 +++- .../java/com/plotsquared/core/command/Claim.java | 6 ++---- .../com/plotsquared/core/command/Continue.java | 4 ++-- .../java/com/plotsquared/core/command/Copy.java | 4 +--- .../core/command/CreateRoadSchematic.java | 6 ++---- .../plotsquared/core/command/DebugRoadRegen.java | 10 +++------- .../com/plotsquared/core/command/Delete.java | 5 ++--- .../java/com/plotsquared/core/command/Deny.java | 3 +-- .../java/com/plotsquared/core/command/Done.java | 3 +-- .../com/plotsquared/core/command/Download.java | 2 +- .../plotsquared/core/command/FlagCommand.java | 16 +++++++--------- .../java/com/plotsquared/core/command/Kick.java | 8 +++----- .../com/plotsquared/core/command/ListCmd.java | 4 ++-- .../java/com/plotsquared/core/command/Load.java | 2 +- .../com/plotsquared/core/command/Middle.java | 3 +-- .../java/com/plotsquared/core/command/Move.java | 4 +--- .../java/com/plotsquared/core/command/Music.java | 3 +-- .../com/plotsquared/core/command/Remove.java | 6 ++---- .../plotsquared/core/command/SchematicCmd.java | 7 ++----- .../java/com/plotsquared/core/command/Set.java | 2 +- .../com/plotsquared/core/command/SetCommand.java | 4 +--- .../java/com/plotsquared/core/command/Swap.java | 9 +++++---- .../com/plotsquared/core/command/Unlink.java | 4 +--- .../com/plotsquared/core/player/PlotPlayer.java | 11 ++++++++--- 25 files changed, 55 insertions(+), 79 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/Alias.java b/Core/src/main/java/com/plotsquared/core/command/Alias.java index a52e47ef2..51250b361 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Alias.java +++ b/Core/src/main/java/com/plotsquared/core/command/Alias.java @@ -21,7 +21,6 @@ package com.plotsquared.core.command; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.TranslatableCaption; -import com.plotsquared.core.location.Location; import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -58,8 +57,7 @@ public class Alias extends SubCommand { return false; } - Location location = player.getLocation(); - Plot plot = location.getPlotAbs(); + Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Buy.java b/Core/src/main/java/com/plotsquared/core/command/Buy.java index d8f63530a..2ab5f0361 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Buy.java +++ b/Core/src/main/java/com/plotsquared/core/command/Buy.java @@ -20,6 +20,7 @@ package com.plotsquared.core.command; import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.events.PlayerBuyPlotEvent; import com.plotsquared.core.events.Result; @@ -84,8 +85,9 @@ public class Buy extends Command { checkTrue(plot.hasOwner(), TranslatableCaption.of("info.plot_unowned")); checkTrue(!plot.isOwner(player.getUUID()), TranslatableCaption.of("economy.cannot_buy_own")); Set plots = plot.getConnectedPlots(); + int plotCount = Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(plot.getWorldName()); checkTrue( - player.getPlotCount() + plots.size() <= player.getAllowedPlots(), + plotCount + plots.size() <= player.getAllowedPlots(), TranslatableCaption.of("permission.cant_claim_more_plots"), TagResolver.resolver("amount", Tag.inserting(Component.text(player.getAllowedPlots()))) ); diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java index c118d4cb0..422347449 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Claim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java @@ -26,7 +26,6 @@ import com.plotsquared.core.events.PlayerClaimPlotEvent; import com.plotsquared.core.events.PlotMergeEvent; import com.plotsquared.core.events.Result; import com.plotsquared.core.location.Direction; -import com.plotsquared.core.location.Location; import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.MetaDataAccess; import com.plotsquared.core.player.PlayerMetaDataKeys; @@ -72,8 +71,7 @@ public class Claim extends SubCommand { if (args.length >= 1) { schematic = args[0]; } - Location location = player.getLocation(); - Plot plot = location.getPlotAbs(); + Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; @@ -90,7 +88,7 @@ public class Claim extends SubCommand { boolean force = event.getEventResult() == Result.FORCE; int currentPlots = Settings.Limit.GLOBAL ? player.getPlotCount() : - player.getPlotCount(location.getWorldName()); + player.getPlotCount(plot.getWorldName()); final PlotArea area = plot.getArea(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Continue.java b/Core/src/main/java/com/plotsquared/core/command/Continue.java index 1929b12c3..62898b725 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Continue.java +++ b/Core/src/main/java/com/plotsquared/core/command/Continue.java @@ -68,8 +68,8 @@ public class Continue extends SubCommand { return false; } int size = plot.getConnectedPlots().size(); - if (!Settings.Done.COUNTS_TOWARDS_LIMIT && (player.getAllowedPlots() - < player.getPlotCount() + size)) { + int plotCount = Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(plot.getWorldName()); + if (!Settings.Done.COUNTS_TOWARDS_LIMIT && (player.getAllowedPlots() < plotCount + size)) { player.sendMessage( TranslatableCaption.of("permission.cant_claim_more_plots"), TagResolver.resolver("amount", Tag.inserting(Component.text(player.getAllowedPlots()))) diff --git a/Core/src/main/java/com/plotsquared/core/command/Copy.java b/Core/src/main/java/com/plotsquared/core/command/Copy.java index f281a4c4b..0b5b64b44 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Copy.java +++ b/Core/src/main/java/com/plotsquared/core/command/Copy.java @@ -19,7 +19,6 @@ package com.plotsquared.core.command; import com.plotsquared.core.configuration.caption.TranslatableCaption; -import com.plotsquared.core.location.Location; import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -37,8 +36,7 @@ public class Copy extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { - Location location = player.getLocation(); - Plot plot1 = location.getPlotAbs(); + Plot plot1 = player.getCurrentPlot(); if (plot1 == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java b/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java index e4b6d0d38..41bdd8a4e 100644 --- a/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java +++ b/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java @@ -22,7 +22,6 @@ import com.google.inject.Inject; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.generator.HybridPlotWorld; import com.plotsquared.core.generator.HybridUtils; -import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import net.kyori.adventure.text.Component; @@ -47,8 +46,7 @@ public class CreateRoadSchematic extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { - Location location = player.getLocation(); - Plot plot = location.getPlotAbs(); + Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; @@ -57,7 +55,7 @@ public class CreateRoadSchematic extends SubCommand { player.sendMessage(TranslatableCaption.of("schematics.schematic_too_large")); return false; } - if (!(location.getPlotArea() instanceof HybridPlotWorld)) { + if (!(plot.getArea() instanceof HybridPlotWorld)) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); } this.hybridUtils.setupRoadSchematic(plot); diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java b/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java index df6bd11d6..678dfd33a 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java @@ -22,7 +22,6 @@ import com.google.inject.Inject; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.generator.HybridPlotManager; import com.plotsquared.core.generator.HybridUtils; -import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; @@ -57,8 +56,7 @@ public class DebugRoadRegen extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { - Location location = player.getLocation(); - Plot plot = location.getPlotAbs(); + Plot plot = player.getCurrentPlot(); if (args.length < 1) { player.sendMessage( TranslatableCaption.of("commandconfig.command_syntax"), @@ -92,8 +90,7 @@ public class DebugRoadRegen extends SubCommand { } public boolean regenPlot(PlotPlayer player) { - Location location = player.getLocation(); - PlotArea area = location.getPlotArea(); + PlotArea area = player.getCurrentPlot().getArea(); if (area == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); return false; @@ -148,8 +145,7 @@ public class DebugRoadRegen extends SubCommand { return false; } - Location location = player.getLocation(); - PlotArea area = location.getPlotArea(); + PlotArea area = player.getCurrentPlot().getArea(); if (area == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Delete.java b/Core/src/main/java/com/plotsquared/core/command/Delete.java index 6784f9e5f..080e9b426 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Delete.java +++ b/Core/src/main/java/com/plotsquared/core/command/Delete.java @@ -61,8 +61,7 @@ public class Delete extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { - Location location = player.getLocation(); - final Plot plot = location.getPlotAbs(); + final Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; @@ -92,7 +91,7 @@ public class Delete extends SubCommand { final java.util.Set plots = plot.getConnectedPlots(); final int currentPlots = Settings.Limit.GLOBAL ? player.getPlotCount() : - player.getPlotCount(location.getWorldName()); + player.getPlotCount(plot.getWorldName()); Runnable run = () -> { if (plot.getRunning() > 0) { player.sendMessage(TranslatableCaption.of("errors.wait_for_timer")); diff --git a/Core/src/main/java/com/plotsquared/core/command/Deny.java b/Core/src/main/java/com/plotsquared/core/command/Deny.java index 56e7c2c8a..8d7365f6e 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Deny.java +++ b/Core/src/main/java/com/plotsquared/core/command/Deny.java @@ -70,8 +70,7 @@ public class Deny extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { - Location location = player.getLocation(); - final Plot plot = location.getPlotAbs(); + final Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Done.java b/Core/src/main/java/com/plotsquared/core/command/Done.java index b8b091b85..0e641b2d3 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Done.java +++ b/Core/src/main/java/com/plotsquared/core/command/Done.java @@ -61,8 +61,7 @@ public class Done extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { - Location location = player.getLocation(); - final Plot plot = location.getPlotAbs(); + final Plot plot = player.getCurrentPlot(); if ((plot == null) || !plot.hasOwner()) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Download.java b/Core/src/main/java/com/plotsquared/core/command/Download.java index 5897112ba..167f465ca 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Download.java +++ b/Core/src/main/java/com/plotsquared/core/command/Download.java @@ -73,7 +73,7 @@ public class Download extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { - String world = player.getLocation().getWorldName(); + String world = player.getCurrentPlot().getWorldName(); if (!this.plotAreaManager.hasPlotArea(world)) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java index 7987bfb03..4406bf176 100644 --- a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java @@ -27,7 +27,6 @@ import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.events.PlotFlagAddEvent; import com.plotsquared.core.events.PlotFlagRemoveEvent; import com.plotsquared.core.events.Result; -import com.plotsquared.core.location.Location; import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -179,8 +178,7 @@ public final class FlagCommand extends Command { * @return {@code true} if the player is allowed to modify the flags at their current location */ private static boolean checkRequirements(final @NonNull PlotPlayer player) { - final Location location = player.getLocation(); - final Plot plot = location.getPlotAbs(); + final Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; @@ -344,7 +342,7 @@ public final class FlagCommand extends Command { if (plotFlag == null) { return; } - Plot plot = player.getLocation().getPlotAbs(); + Plot plot = player.getCurrentPlot(); PlotFlagAddEvent event = eventDispatcher.callFlagAdd(plotFlag, plot); if (event.getEventResult() == Result.DENY) { player.sendMessage( @@ -409,7 +407,7 @@ public final class FlagCommand extends Command { if (plotFlag == null) { return; } - Plot plot = player.getLocation().getPlotAbs(); + Plot plot = player.getCurrentPlot(); PlotFlagAddEvent event = eventDispatcher.callFlagAdd(plotFlag, plot); if (event.getEventResult() == Result.DENY) { player.sendMessage( @@ -419,7 +417,7 @@ public final class FlagCommand extends Command { return; } boolean force = event.getEventResult() == Result.FORCE; - final PlotFlag localFlag = player.getLocation().getPlotAbs().getFlagContainer() + final PlotFlag localFlag = player.getCurrentPlot().getFlagContainer() .getFlag(event.getFlag().getClass()); if (!force) { for (String entry : args[1].split(",")) { @@ -444,7 +442,7 @@ public final class FlagCommand extends Command { return; } boolean result = - player.getLocation().getPlotAbs().setFlag(localFlag.merge(parsed.getValue())); + player.getCurrentPlot().setFlag(localFlag.merge(parsed.getValue())); if (!result) { player.sendMessage(TranslatableCaption.of("flag.flag_not_added")); return; @@ -484,7 +482,7 @@ public final class FlagCommand extends Command { if (flag == null) { return; } - final Plot plot = player.getLocation().getPlotAbs(); + final Plot plot = player.getCurrentPlot(); final PlotFlag flagWithOldValue = plot.getFlagContainer().getFlag(flag.getClass()); PlotFlagRemoveEvent event = eventDispatcher.callFlagRemove(flag, plot); if (event.getEventResult() == Result.DENY) { @@ -687,7 +685,7 @@ public final class FlagCommand extends Command { .build() ); // Default value - final String defaultValue = player.getLocation().getPlotArea().getFlagContainer() + final String defaultValue = player.getCurrentPlot().getArea().getFlagContainer() .getFlagErased(plotFlag.getClass()).toString(); player.sendMessage( TranslatableCaption.of("flag.flag_info_default_value"), diff --git a/Core/src/main/java/com/plotsquared/core/command/Kick.java b/Core/src/main/java/com/plotsquared/core/command/Kick.java index 5c9d07fc1..ced145fa5 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Kick.java +++ b/Core/src/main/java/com/plotsquared/core/command/Kick.java @@ -65,8 +65,7 @@ public class Kick extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { - Location location = player.getLocation(); - Plot plot = location.getPlot(); + Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; @@ -124,7 +123,7 @@ public class Kick extends SubCommand { ); return; } - Location spawn = this.worldUtil.getSpawn(location.getWorldName()); + Location spawn = this.worldUtil.getSpawn(plot.getWorldName()); player2.sendMessage(TranslatableCaption.of("kick.you_got_kicked")); if (plot.equals(spawn.getPlot())) { Location newSpawn = this.worldUtil.getSpawn(this.plotAreaManager.getAllWorlds()[0]); @@ -148,8 +147,7 @@ public class Kick extends SubCommand { @Override public Collection tab(final PlotPlayer player, final String[] args, final boolean space) { - Location location = player.getLocation(); - Plot plot = location.getPlotAbs(); + Plot plot = player.getCurrentPlot(); if (plot == null) { return Collections.emptyList(); } diff --git a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java index 144380447..2766721ff 100644 --- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java @@ -150,8 +150,8 @@ public class ListCmd extends SubCommand { page = 0; } - String world = player.getLocation().getWorldName(); - PlotArea area = player.getApplicablePlotArea(); + String world = player.getCurrentPlot().getWorldName(); + PlotArea area = player.getCurrentPlot().getArea(); String arg = args[0].toLowerCase(); final boolean[] sort = new boolean[]{true}; diff --git a/Core/src/main/java/com/plotsquared/core/command/Load.java b/Core/src/main/java/com/plotsquared/core/command/Load.java index 14c700d4c..cf4936211 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Load.java +++ b/Core/src/main/java/com/plotsquared/core/command/Load.java @@ -68,7 +68,7 @@ public class Load extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, final String[] args) { - final String world = player.getLocation().getWorldName(); + final String world = player.getCurrentPlot().getWorldName(); if (!this.plotAreaManager.hasPlotArea(world)) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Middle.java b/Core/src/main/java/com/plotsquared/core/command/Middle.java index 24212cd44..8b37e1916 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Middle.java +++ b/Core/src/main/java/com/plotsquared/core/command/Middle.java @@ -36,8 +36,7 @@ public class Middle extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] arguments) { - Location location = player.getLocation(); - Plot plot = location.getPlot(); + Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Move.java b/Core/src/main/java/com/plotsquared/core/command/Move.java index 161d12991..cbd6c074d 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Move.java +++ b/Core/src/main/java/com/plotsquared/core/command/Move.java @@ -20,7 +20,6 @@ package com.plotsquared.core.command; import com.google.inject.Inject; import com.plotsquared.core.configuration.caption.TranslatableCaption; -import com.plotsquared.core.location.Location; import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -55,8 +54,7 @@ public class Move extends SubCommand { RunnableVal3 confirm, RunnableVal2 whenDone ) { - Location location = player.getLocation(); - Plot plot1 = location.getPlotAbs(); + Plot plot1 = player.getCurrentPlot(); if (plot1 == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return CompletableFuture.completedFuture(false); diff --git a/Core/src/main/java/com/plotsquared/core/command/Music.java b/Core/src/main/java/com/plotsquared/core/command/Music.java index 075917cec..3932c7934 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Music.java +++ b/Core/src/main/java/com/plotsquared/core/command/Music.java @@ -74,8 +74,7 @@ public class Music extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { - Location location = player.getLocation(); - final Plot plot = location.getPlotAbs(); + final Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Remove.java b/Core/src/main/java/com/plotsquared/core/command/Remove.java index 287145df5..e24b9e052 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Remove.java +++ b/Core/src/main/java/com/plotsquared/core/command/Remove.java @@ -56,8 +56,7 @@ public class Remove extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { - Location location = player.getLocation(); - Plot plot = location.getPlotAbs(); + Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; @@ -132,8 +131,7 @@ public class Remove extends SubCommand { @Override public Collection tab(final PlotPlayer player, final String[] args, final boolean space) { - Location location = player.getLocation(); - Plot plot = location.getPlotAbs(); + Plot plot = player.getCurrentPlot(); if (plot == null) { return Collections.emptyList(); } diff --git a/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java b/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java index a92f06c5a..38c75beea 100644 --- a/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java @@ -22,7 +22,6 @@ import com.google.common.collect.Lists; import com.google.inject.Inject; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.TranslatableCaption; -import com.plotsquared.core.location.Location; import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.PlotPlayer; @@ -102,8 +101,7 @@ public class SchematicCmd extends SubCommand { ); break; } - Location loc = player.getLocation(); - final Plot plot = loc.getPlotAbs(); + final Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; @@ -247,8 +245,7 @@ public class SchematicCmd extends SubCommand { player.sendMessage(TranslatableCaption.of("error.task_in_process")); return false; } - Location location = player.getLocation(); - Plot plot = location.getPlotAbs(); + Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Set.java b/Core/src/main/java/com/plotsquared/core/command/Set.java index 1b39a9dc5..52c32c997 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Set.java +++ b/Core/src/main/java/com/plotsquared/core/command/Set.java @@ -78,7 +78,7 @@ public class Set extends SubCommand { @Override public boolean set(PlotPlayer player, final Plot plot, String value) { - final PlotArea plotArea = player.getLocation().getPlotArea(); + final PlotArea plotArea = player.getCurrentPlot().getArea(); if (plotArea == null) { return false; } diff --git a/Core/src/main/java/com/plotsquared/core/command/SetCommand.java b/Core/src/main/java/com/plotsquared/core/command/SetCommand.java index 49794ec4b..9a05207bb 100644 --- a/Core/src/main/java/com/plotsquared/core/command/SetCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/SetCommand.java @@ -19,7 +19,6 @@ package com.plotsquared.core.command; import com.plotsquared.core.configuration.caption.TranslatableCaption; -import com.plotsquared.core.location.Location; import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -32,8 +31,7 @@ public abstract class SetCommand extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { - Location location = player.getLocation(); - Plot plot = location.getPlotAbs(); + Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Swap.java b/Core/src/main/java/com/plotsquared/core/command/Swap.java index e56def26f..4492dc0e3 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Swap.java +++ b/Core/src/main/java/com/plotsquared/core/command/Swap.java @@ -44,8 +44,7 @@ public class Swap extends SubCommand { RunnableVal3 confirm, RunnableVal2 whenDone ) { - Location location = player.getLocation(); - Plot plot1 = location.getPlotAbs(); + Plot plot1 = player.getCurrentPlot(); if (plot1 == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return CompletableFuture.completedFuture(false); @@ -79,8 +78,10 @@ public class Swap extends SubCommand { String p1 = plot1.toString(); String p2 = plot2.toString(); - return plot1.getPlotModificationManager().move(plot2, player, () -> { - }, true).thenApply(result -> { + return plot1.getPlotModificationManager().move( + plot2, player, () -> { + }, true + ).thenApply(result -> { if (result) { player.sendMessage( TranslatableCaption.of("swap.swap_success"), diff --git a/Core/src/main/java/com/plotsquared/core/command/Unlink.java b/Core/src/main/java/com/plotsquared/core/command/Unlink.java index 72c620fb7..22f5b34df 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Unlink.java +++ b/Core/src/main/java/com/plotsquared/core/command/Unlink.java @@ -22,7 +22,6 @@ import com.google.inject.Inject; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.events.PlotUnlinkEvent; import com.plotsquared.core.events.Result; -import com.plotsquared.core.location.Location; import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -51,8 +50,7 @@ public class Unlink extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { - Location location = player.getLocation(); - final Plot plot = location.getPlotAbs(); + final Plot plot = player.getCurrentPlot(); if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); return false; diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index f4bcd1943..875785781 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -290,6 +290,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer, * * @return the plot the player is standing on or null if standing on a road or not in a {@link PlotArea} */ + @Nullable public Plot getCurrentPlot() { try (final MetaDataAccess lastPlotAccess = this.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) { @@ -319,7 +320,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer, */ public int getPlotCount() { if (!Settings.Limit.GLOBAL) { - return getPlotCount(getLocation().getWorldName()); + return getPlotCount(getCurrentPlot().getWorldName()); } final AtomicInteger count = new AtomicInteger(0); final UUID uuid = getUUID(); @@ -339,7 +340,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer, public int getClusterCount() { if (!Settings.Limit.GLOBAL) { - return getClusterCount(getLocation().getWorldName()); + return getClusterCount(getCurrentPlot().getWorldName()); } final AtomicInteger count = new AtomicInteger(0); this.plotAreaManager.forEachPlotArea(value -> { @@ -408,7 +409,11 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer, } public PlotArea getApplicablePlotArea() { - return this.plotAreaManager.getApplicablePlotArea(getLocation()); + Plot plot = getCurrentPlot(); + if (plot == null) { + return this.plotAreaManager.getApplicablePlotArea(getLocation()); + } + return plot.getArea(); } @Override