chore/feat: don't query full plot list twice

This commit is contained in:
Pierre Maurice Schwang 2025-02-22 21:31:25 +01:00
parent d9a46635fd
commit 60f81c4732
No known key found for this signature in database
GPG Key ID: 37E613079F3E5BB9

View File

@ -69,11 +69,7 @@ public class Visit extends Command {
final @NonNull PlotPlayer<?> player, final @NonNull PlotQuery query, final PlotArea sortByArea,
final RunnableVal3<Command, Runnable, Runnable> confirm, final RunnableVal2<Command, CommandResult> whenDone, int page
) {
// We get the query once,
// then we get it another time further on
final List<Plot> unsorted = query.asList();
if (unsorted.size() > 1) {
if (query.hasMinimumMatches(2)) {
query.whereBasePlot();
}
@ -261,12 +257,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 && (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) {
return;
}
if (uuid == null){
// player not found, so we assume it's an alias if no page was provided
if (finalPage == Integer.MIN_VALUE) {
this.visit(
@ -283,18 +276,17 @@ public class Visit extends Command {
TagResolver.resolver("value", Tag.inserting(Component.text(finalArgs[0])))
);
}
} else {
this.visit(
player,
Settings.Teleport.VISIT_MERGED_OWNERS
? PlotQuery.newQuery().ownersInclude(uuid).whereBasePlot()
: PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(),
null,
confirm,
whenDone,
finalPage
);
return;
}
final PlotQuery query = Settings.Teleport.VISIT_MERGED_OWNERS
? PlotQuery.newQuery().ownersInclude(uuid)
: PlotQuery.newQuery().ownedBy(uuid);
if (!query.anyMatch()) {
// It was a valid UUID but the player has no plots
player.sendMessage(TranslatableCaption.of("errors.player_no_plots"));
return;
}
this.visit(player, query.whereBasePlot(), null, confirm, whenDone, finalPage);
});
} else {
// Try to parse a plot