Account for mutability of plot objects when sending move/swap success messages (#3414)

Fixes #3337
This commit is contained in:
Jordan 2021-12-31 15:46:08 +01:00 committed by GitHub
parent b501a81e21
commit 07fdc94dd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -105,13 +105,17 @@ public class Move extends SubCommand {
return CompletableFuture.completedFuture(false); return CompletableFuture.completedFuture(false);
} }
// Set strings here as the plot objects are mutable (the PlotID changes after being moved).
String p1 = plot1.toString();
String p2 = plot2.toString();
return plot1.getPlotModificationManager().move(plot2, player, () -> { return plot1.getPlotModificationManager().move(plot2, player, () -> {
}, false).thenApply(result -> { }, false).thenApply(result -> {
if (result) { if (result) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("move.move_success"), TranslatableCaption.of("move.move_success"),
Template.of("origin", plot1.toString()), Template.of("origin", p1),
Template.of("target", plot2.toString()) Template.of("target", p2)
); );
return true; return true;
} else { } else {

View File

@ -82,11 +82,17 @@ public class Swap extends SubCommand {
return CompletableFuture.completedFuture(false); return CompletableFuture.completedFuture(false);
} }
// Set strings here as the plot objects are mutable (the PlotID changes after being moved).
String p1 = plot1.toString();
String p2 = plot2.toString();
return plot1.getPlotModificationManager().move(plot2, player, () -> { return plot1.getPlotModificationManager().move(plot2, player, () -> {
}, true).thenApply(result -> { }, true).thenApply(result -> {
if (result) { if (result) {
player.sendMessage(TranslatableCaption.of("swap.swap_success"), Template.of("origin", String.valueOf(plot1)), player.sendMessage(
Template.of("target", String.valueOf(plot2)) TranslatableCaption.of("swap.swap_success"),
Template.of("origin", p1),
Template.of("target", p2)
); );
return true; return true;
} else { } else {