Skip to content

Commit 02a65c8

Browse files
authored
fix: use PlotPlayer#getCurrentPlot across commands to allow /<command> <id> usage (#4738)
* fix: use PlotPlayer#getCurrentPlot across commands to allow /<command> <id> usage - fixes #4526 - supersedes #4675 * cleanup
1 parent 8a5fa26 commit 02a65c8

25 files changed

+55
-85
lines changed

Core/src/main/java/com/plotsquared/core/command/Alias.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.plotsquared.core.PlotSquared;
2222
import com.plotsquared.core.configuration.Settings;
2323
import com.plotsquared.core.configuration.caption.TranslatableCaption;
24-
import com.plotsquared.core.location.Location;
2524
import com.plotsquared.core.permissions.Permission;
2625
import com.plotsquared.core.player.PlotPlayer;
2726
import com.plotsquared.core.plot.Plot;
@@ -58,8 +57,7 @@ public boolean onCommand(PlotPlayer<?> player, String[] args) {
5857
return false;
5958
}
6059

61-
Location location = player.getLocation();
62-
Plot plot = location.getPlotAbs();
60+
Plot plot = player.getCurrentPlot();
6361
if (plot == null) {
6462
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
6563
return false;

Core/src/main/java/com/plotsquared/core/command/Buy.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.inject.Inject;
2222
import com.plotsquared.core.PlotSquared;
23+
import com.plotsquared.core.configuration.Settings;
2324
import com.plotsquared.core.configuration.caption.TranslatableCaption;
2425
import com.plotsquared.core.events.PlayerBuyPlotEvent;
2526
import com.plotsquared.core.events.Result;
@@ -84,8 +85,9 @@ public CompletableFuture<Boolean> execute(
8485
checkTrue(plot.hasOwner(), TranslatableCaption.of("info.plot_unowned"));
8586
checkTrue(!plot.isOwner(player.getUUID()), TranslatableCaption.of("economy.cannot_buy_own"));
8687
Set<Plot> plots = plot.getConnectedPlots();
88+
int plotCount = Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(plot.getWorldName());
8789
checkTrue(
88-
player.getPlotCount() + plots.size() <= player.getAllowedPlots(),
90+
plotCount + plots.size() <= player.getAllowedPlots(),
8991
TranslatableCaption.of("permission.cant_claim_more_plots"),
9092
TagResolver.resolver("amount", Tag.inserting(Component.text(player.getAllowedPlots())))
9193
);

Core/src/main/java/com/plotsquared/core/command/Claim.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.plotsquared.core.events.PlotMergeEvent;
2727
import com.plotsquared.core.events.Result;
2828
import com.plotsquared.core.location.Direction;
29-
import com.plotsquared.core.location.Location;
3029
import com.plotsquared.core.permissions.Permission;
3130
import com.plotsquared.core.player.MetaDataAccess;
3231
import com.plotsquared.core.player.PlayerMetaDataKeys;
@@ -72,8 +71,7 @@ public boolean onCommand(final PlotPlayer<?> player, String[] args) {
7271
if (args.length >= 1) {
7372
schematic = args[0];
7473
}
75-
Location location = player.getLocation();
76-
Plot plot = location.getPlotAbs();
74+
Plot plot = player.getCurrentPlot();
7775
if (plot == null) {
7876
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
7977
return false;
@@ -90,7 +88,7 @@ public boolean onCommand(final PlotPlayer<?> player, String[] args) {
9088
boolean force = event.getEventResult() == Result.FORCE;
9189
int currentPlots = Settings.Limit.GLOBAL ?
9290
player.getPlotCount() :
93-
player.getPlotCount(location.getWorldName());
91+
player.getPlotCount(plot.getWorldName());
9492

9593
final PlotArea area = plot.getArea();
9694

Core/src/main/java/com/plotsquared/core/command/Continue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public boolean onCommand(PlotPlayer<?> player, String[] args) {
6868
return false;
6969
}
7070
int size = plot.getConnectedPlots().size();
71-
if (!Settings.Done.COUNTS_TOWARDS_LIMIT && (player.getAllowedPlots()
72-
< player.getPlotCount() + size)) {
71+
int plotCount = Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(plot.getWorldName());
72+
if (!Settings.Done.COUNTS_TOWARDS_LIMIT && (player.getAllowedPlots() < plotCount + size)) {
7373
player.sendMessage(
7474
TranslatableCaption.of("permission.cant_claim_more_plots"),
7575
TagResolver.resolver("amount", Tag.inserting(Component.text(player.getAllowedPlots())))

Core/src/main/java/com/plotsquared/core/command/Copy.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package com.plotsquared.core.command;
2020

2121
import com.plotsquared.core.configuration.caption.TranslatableCaption;
22-
import com.plotsquared.core.location.Location;
2322
import com.plotsquared.core.permissions.Permission;
2423
import com.plotsquared.core.player.PlotPlayer;
2524
import com.plotsquared.core.plot.Plot;
@@ -37,8 +36,7 @@ public class Copy extends SubCommand {
3736

3837
@Override
3938
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
40-
Location location = player.getLocation();
41-
Plot plot1 = location.getPlotAbs();
39+
Plot plot1 = player.getCurrentPlot();
4240
if (plot1 == null) {
4341
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
4442
return false;

Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.plotsquared.core.configuration.caption.TranslatableCaption;
2323
import com.plotsquared.core.generator.HybridPlotWorld;
2424
import com.plotsquared.core.generator.HybridUtils;
25-
import com.plotsquared.core.location.Location;
2625
import com.plotsquared.core.player.PlotPlayer;
2726
import com.plotsquared.core.plot.Plot;
2827
import net.kyori.adventure.text.Component;
@@ -47,8 +46,7 @@ public CreateRoadSchematic(final @NonNull HybridUtils hybridUtils) {
4746

4847
@Override
4948
public boolean onCommand(PlotPlayer<?> player, String[] args) {
50-
Location location = player.getLocation();
51-
Plot plot = location.getPlotAbs();
49+
Plot plot = player.getCurrentPlot();
5250
if (plot == null) {
5351
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
5452
return false;
@@ -57,7 +55,7 @@ public boolean onCommand(PlotPlayer<?> player, String[] args) {
5755
player.sendMessage(TranslatableCaption.of("schematics.schematic_too_large"));
5856
return false;
5957
}
60-
if (!(location.getPlotArea() instanceof HybridPlotWorld)) {
58+
if (!(plot.getArea() instanceof HybridPlotWorld)) {
6159
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
6260
}
6361
this.hybridUtils.setupRoadSchematic(plot);

Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.plotsquared.core.configuration.caption.TranslatableCaption;
2323
import com.plotsquared.core.generator.HybridPlotManager;
2424
import com.plotsquared.core.generator.HybridUtils;
25-
import com.plotsquared.core.location.Location;
2625
import com.plotsquared.core.player.PlotPlayer;
2726
import com.plotsquared.core.plot.Plot;
2827
import com.plotsquared.core.plot.PlotArea;
@@ -57,8 +56,7 @@ public DebugRoadRegen(final @NonNull HybridUtils hybridUtils) {
5756

5857
@Override
5958
public boolean onCommand(PlotPlayer<?> player, String[] args) {
60-
Location location = player.getLocation();
61-
Plot plot = location.getPlotAbs();
59+
Plot plot = player.getCurrentPlot();
6260
if (args.length < 1) {
6361
player.sendMessage(
6462
TranslatableCaption.of("commandconfig.command_syntax"),
@@ -92,8 +90,7 @@ public boolean onCommand(PlotPlayer<?> player, String[] args) {
9290
}
9391

9492
public boolean regenPlot(PlotPlayer<?> player) {
95-
Location location = player.getLocation();
96-
PlotArea area = location.getPlotArea();
93+
PlotArea area = player.getCurrentPlot().getArea();
9794
if (area == null) {
9895
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
9996
return false;
@@ -148,8 +145,7 @@ public boolean regenRegion(PlotPlayer<?> player, String[] args) {
148145
return false;
149146
}
150147

151-
Location location = player.getLocation();
152-
PlotArea area = location.getPlotArea();
148+
PlotArea area = player.getCurrentPlot().getArea();
153149
if (area == null) {
154150
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
155151
}

Core/src/main/java/com/plotsquared/core/command/Delete.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.plotsquared.core.configuration.caption.TranslatableCaption;
2424
import com.plotsquared.core.events.Result;
2525
import com.plotsquared.core.events.TeleportCause;
26-
import com.plotsquared.core.location.Location;
2726
import com.plotsquared.core.permissions.Permission;
2827
import com.plotsquared.core.player.PlotPlayer;
2928
import com.plotsquared.core.plot.Plot;
@@ -61,8 +60,7 @@ public Delete(
6160

6261
@Override
6362
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
64-
Location location = player.getLocation();
65-
final Plot plot = location.getPlotAbs();
63+
final Plot plot = player.getCurrentPlot();
6664
if (plot == null) {
6765
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
6866
return false;
@@ -92,7 +90,7 @@ public boolean onCommand(final PlotPlayer<?> player, String[] args) {
9290
final java.util.Set<Plot> plots = plot.getConnectedPlots();
9391
final int currentPlots = Settings.Limit.GLOBAL ?
9492
player.getPlotCount() :
95-
player.getPlotCount(location.getWorldName());
93+
player.getPlotCount(plot.getWorldName());
9694
Runnable run = () -> {
9795
if (plot.getRunning() > 0) {
9896
player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));

Core/src/main/java/com/plotsquared/core/command/Deny.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ public Deny(
7070
@Override
7171
public boolean onCommand(PlotPlayer<?> player, String[] args) {
7272

73-
Location location = player.getLocation();
74-
final Plot plot = location.getPlotAbs();
73+
final Plot plot = player.getCurrentPlot();
7574
if (plot == null) {
7675
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
7776
return false;

Core/src/main/java/com/plotsquared/core/command/Done.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.plotsquared.core.events.PlotFlagAddEvent;
2727
import com.plotsquared.core.events.Result;
2828
import com.plotsquared.core.generator.HybridUtils;
29-
import com.plotsquared.core.location.Location;
3029
import com.plotsquared.core.permissions.Permission;
3130
import com.plotsquared.core.player.PlotPlayer;
3231
import com.plotsquared.core.plot.Plot;
@@ -61,8 +60,7 @@ public Done(
6160

6261
@Override
6362
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
64-
Location location = player.getLocation();
65-
final Plot plot = location.getPlotAbs();
63+
final Plot plot = player.getCurrentPlot();
6664
if ((plot == null) || !plot.hasOwner()) {
6765
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
6866
return false;

0 commit comments

Comments
 (0)