From 7cc38b5fa80d03e84d5b78e5f6cba07a8c75fb8f Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 5 Jan 2022 21:21:48 +0100 Subject: [PATCH] Fix: use ownersInclude instead of ownedBy where required (#3419) * Fix: use ownersInclude instead of ownedBy where required - Also account for multiple plot owners in Cluster player removal - Add whereBasePlot to avoid merged plots listing multiple times if required - Only use ownersInclude in visit if enabled in config - Fixes #3143 * Remove static import --- .../com/plotsquared/core/command/Cluster.java | 34 +++++++++++-------- .../com/plotsquared/core/command/ListCmd.java | 5 +-- .../com/plotsquared/core/command/Visit.java | 10 ++++-- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/Cluster.java b/Core/src/main/java/com/plotsquared/core/command/Cluster.java index 7c3cafe62..4eebd5c3e 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Cluster.java +++ b/Core/src/main/java/com/plotsquared/core/command/Cluster.java @@ -559,13 +559,7 @@ public class Cluster extends SubCommand { Template.of("cluster", cluster.getName()) ); } - for (final Plot plot : PlotQuery.newQuery().inWorld(player2.getLocation() - .getWorldName()).ownedBy(uuid)) { - PlotCluster current = plot.getCluster(); - if (current != null && current.equals(cluster)) { - plot.unclaim(); - } - } + removePlayerPlots(cluster, uuid, player2.getLocation().getWorldName()); player.sendMessage(TranslatableCaption.of("cluster.cluster_kicked_user")); } } @@ -628,13 +622,7 @@ public class Cluster extends SubCommand { TranslatableCaption.of("cluster.cluster_removed"), Template.of("cluster", cluster.getName()) ); - for (final Plot plot : PlotQuery.newQuery().inWorld(player.getLocation().getWorldName()) - .ownedBy(uuid)) { - PlotCluster current = plot.getCluster(); - if (current != null && current.equals(cluster)) { - plot.unclaim(); - } - } + removePlayerPlots(cluster, uuid, player.getLocation().getWorldName()); return true; } case "members": { @@ -866,6 +854,24 @@ public class Cluster extends SubCommand { return false; } + private void removePlayerPlots(final PlotCluster cluster, final UUID uuid, final String world) { + for (final Plot plot : PlotQuery.newQuery().inWorld(world).ownedBy(uuid)) { + PlotCluster current = plot.getCluster(); + if (current != null && current.equals(cluster)) { + if (plot.getOwners().size() == 1) { + plot.unclaim(); + } else { + for (UUID newOwner : plot.getOwners()) { + if (!newOwner.equals(uuid)) { + plot.setOwner(newOwner); + break; + } + } + } + } + } + } + @Override public Collection tab(final PlotPlayer player, final String[] args, final boolean space) { if (args.length == 1) { 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 3d5849b04..e6a2ae91d 100644 --- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java @@ -203,7 +203,7 @@ public class ListCmd extends SubCommand { sort[0] = false; plotConsumer.accept(PlotQuery .newQuery() - .ownedBy(player) + .ownersInclude(player) .whereBasePlot() .withSortingStrategy(SortingStrategy.SORT_BY_TEMP)); } @@ -397,7 +397,8 @@ public class ListCmd extends SubCommand { sort[0] = false; plotConsumer.accept(PlotQuery .newQuery() - .ownedBy(uuid) + .ownersInclude(uuid) + .whereBasePlot() .withSortingStrategy(SortingStrategy.SORT_BY_TEMP)); } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Visit.java b/Core/src/main/java/com/plotsquared/core/command/Visit.java index ec756a1a3..853704ce4 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Visit.java +++ b/Core/src/main/java/com/plotsquared/core/command/Visit.java @@ -236,7 +236,7 @@ public class Visit extends Command { final UUID uuid = uuids.toArray(new UUID[0])[0]; PlotQuery query = PlotQuery.newQuery(); if (Settings.Teleport.VISIT_MERGED_OWNERS) { - query.ownersInclude(uuid); + query.whereBasePlot().ownersInclude(uuid); } else { query.whereBasePlot().ownedBy(uuid); } @@ -273,7 +273,9 @@ public class Visit extends Command { if (throwable instanceof TimeoutException) { // The request timed out player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout")); - } else if (uuid != null && !PlotQuery.newQuery().ownedBy(uuid).anyMatch()) { + } else if (uuid != null && (Settings.Teleport.VISIT_MERGED_OWNERS + ? !PlotQuery.newQuery().ownersInclude(uuid).anyMatch() + : !PlotQuery.newQuery().ownedBy(uuid).anyMatch())) { // It was a valid UUID but the player has no plots player.sendMessage(TranslatableCaption.of("errors.player_no_plots")); } else if (uuid == null) { @@ -296,7 +298,9 @@ public class Visit extends Command { } else { this.visit( player, - PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(), + Settings.Teleport.VISIT_MERGED_OWNERS + ? PlotQuery.newQuery().ownersInclude(uuid).whereBasePlot() + : PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(), null, confirm, whenDone,