From 6c6c2b57a127e8a88eb25995fbc805a994d4eefa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sat, 23 May 2020 17:20:09 +0200 Subject: [PATCH] Add options to disable tab completion and extend username completion, also limit the total number of username suggestions to 200 per request --- .../bukkit/listener/PaperListener.java | 3 ++ .../core/configuration/Settings.java | 9 +++--- .../plotsquared/core/util/TabCompletions.java | 32 +++++++++++++------ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java index 925798a8a..ec5384ab5 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java @@ -318,6 +318,9 @@ public class PaperListener implements Listener { } @EventHandler public void onAsyncTabCompletion(final AsyncTabCompleteEvent event) { + if (!Settings.Paper_Components.ASYNC_TAB_COMPLETION) { + return; + } String buffer = event.getBuffer(); if (!(event.getSender() instanceof Player)) { return; diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java index f295c465f..0c2e30be9 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -238,7 +238,6 @@ public class Settings extends Config { @Comment("Force using lowercase UUIDs") public static boolean FORCE_LOWERCASE = false; @Comment("Use a database to store UUID/name info") public static boolean USE_SQLUUIDHANDLER = false; - @Ignore public static boolean NATIVE_UUID_PROVIDER = false; @Comment("How many UUIDs that may be stored in the cache") public static int UUID_CACHE_SIZE = 100000; @Comment("Rate limit (per 10 minutes) for background UUID fetching from the Mojang API") @@ -497,6 +496,8 @@ public class Settings extends Config { public static boolean CREATURE_SPAWN = true; @Comment("Check the tile entity limit on block placement") public static boolean TILE_ENTITY_CHECK = true; + @Comment("Use Paper's async tab completion") + public static boolean ASYNC_TAB_COMPLETION; } @Comment("Settings relating to PlotSquared's GlobalBlockQueue") @@ -514,8 +515,6 @@ public class Settings extends Config { @Comment("Events are needed to track a lot of things") public static boolean EVENTS = true; @Comment("Commands are used to interact with the plugin") public static boolean COMMANDS = true; - @Comment("The UUID cacher is used to resolve player names") public static boolean - UUID_CACHE = true; @Comment("Whether we should notify you about updates or not.") public static boolean UPDATE_NOTIFICATIONS = true; @Comment("Stores user metadata in a database") public static boolean PERSISTENT_META = true; @@ -544,10 +543,10 @@ public class Settings extends Config { public static boolean EXTERNAL_PLACEHOLDERS = true; @Comment("Make road regeneration persistent across restarts") public static boolean PERSISTENT_ROAD_REGEN = false; - @Comment("Try to guess plot owners from sign data. This may decrease server performance") - public static boolean GUESS_PLOT_OWNER = false; @Comment("Plot component preset GUI") public static boolean COMPONENT_PRESETS = true; + @Comment("Use UUID cache to complete usernames") + public static boolean EXTENDED_USERNAME_COMPLETION = true; } } diff --git a/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java b/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java index 0c1dbf4df..0369ad730 100644 --- a/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java +++ b/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java @@ -31,6 +31,8 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.command.Command; import com.plotsquared.core.command.CommandCategory; import com.plotsquared.core.command.RequiredType; +import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.uuid.UUIDMapping; import lombok.experimental.UtilityClass; import org.jetbrains.annotations.NotNull; @@ -61,15 +63,24 @@ public class TabCompletions { */ @NotNull public List completePlayers(@NotNull final String input, @NotNull final List existing) { - List players = cachedCompletionValues.getIfPresent("players"); - if (players == null) { - final Collection mappings = - PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately(); - players = new ArrayList<>(mappings.size()); - for (final UUIDMapping mapping : mappings) { - players.add(mapping.getUsername()); + List players; + if (Settings.Enabled_Components.EXTENDED_USERNAME_COMPLETION) { + players = cachedCompletionValues.getIfPresent("players"); + if (players == null) { + final Collection mappings = + PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately(); + players = new ArrayList<>(mappings.size()); + for (final UUIDMapping mapping : mappings) { + players.add(mapping.getUsername()); + } + cachedCompletionValues.put("players", players); + } + } else { + final Collection onlinePlayers = PlotSquared.imp().getPlayerManager().getPlayers(); + players = new ArrayList<>(onlinePlayers.size()); + for (final PlotPlayer player : onlinePlayers) { + players.add(player.getName()); } - cachedCompletionValues.put("players", players); } final String processedInput = input.toLowerCase(Locale.ENGLISH); return players.stream() @@ -77,7 +88,10 @@ public class TabCompletions { .filter(player -> !existing.contains(player)).map( player -> new Command(null, false, player, "", RequiredType.NONE, CommandCategory.INFO) { - }).collect(Collectors.toList()); + }) + /* If there are more than 200 suggestions, just send the first 200 */ + .limit(200) + .collect(Collectors.toList()); } /**