Add options to disable tab completion and extend username completion, also limit the total number of username suggestions to 200 per request

This commit is contained in:
Alexander Söderberg 2020-05-23 17:20:09 +02:00
parent 3b7057ad4f
commit 6c6c2b57a1
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
3 changed files with 30 additions and 14 deletions

View file

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

View file

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

View file

@ -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,7 +63,9 @@ public class TabCompletions {
*/
@NotNull public List<Command> completePlayers(@NotNull final String input,
@NotNull final List<String> existing) {
List<String> players = cachedCompletionValues.getIfPresent("players");
List<String> players;
if (Settings.Enabled_Components.EXTENDED_USERNAME_COMPLETION) {
players = cachedCompletionValues.getIfPresent("players");
if (players == null) {
final Collection<UUIDMapping> mappings =
PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately();
@ -71,13 +75,23 @@ public class TabCompletions {
}
cachedCompletionValues.put("players", players);
}
} else {
final Collection<? extends PlotPlayer> onlinePlayers = PlotSquared.imp().getPlayerManager().getPlayers();
players = new ArrayList<>(onlinePlayers.size());
for (final PlotPlayer player : onlinePlayers) {
players.add(player.getName());
}
}
final String processedInput = input.toLowerCase(Locale.ENGLISH);
return players.stream()
.filter(player -> player.toLowerCase(Locale.ENGLISH).startsWith(processedInput))
.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());
}
/**