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
This commit is contained in:
Jordan 2022-01-05 21:21:48 +01:00 committed by GitHub
parent 0c76d08b10
commit 7cc38b5fa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 19 deletions

View File

@ -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<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
if (args.length == 1) {

View File

@ -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));
}
}

View File

@ -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,