From 07fdc94dd8ed06d34953dd52860379ef855b11fe Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 31 Dec 2021 15:46:08 +0100 Subject: [PATCH] Account for mutability of plot objects when sending move/swap success messages (#3414) Fixes #3337 --- .../main/java/com/plotsquared/core/command/Move.java | 8 ++++++-- .../main/java/com/plotsquared/core/command/Swap.java | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) 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 85dd26fb3..c0e9d3a7b 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Move.java +++ b/Core/src/main/java/com/plotsquared/core/command/Move.java @@ -105,13 +105,17 @@ public class Move extends SubCommand { 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, () -> { }, false).thenApply(result -> { if (result) { player.sendMessage( TranslatableCaption.of("move.move_success"), - Template.of("origin", plot1.toString()), - Template.of("target", plot2.toString()) + Template.of("origin", p1), + Template.of("target", p2) ); return true; } else { 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 3003226ec..ea63a358e 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Swap.java +++ b/Core/src/main/java/com/plotsquared/core/command/Swap.java @@ -82,11 +82,17 @@ public class Swap extends SubCommand { 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, () -> { }, true).thenApply(result -> { if (result) { - player.sendMessage(TranslatableCaption.of("swap.swap_success"), Template.of("origin", String.valueOf(plot1)), - Template.of("target", String.valueOf(plot2)) + player.sendMessage( + TranslatableCaption.of("swap.swap_success"), + Template.of("origin", p1), + Template.of("target", p2) ); return true; } else {