mirror of
https://github.com/TotalFreedomMC/TF-PlotSquared.git
synced 2024-12-23 00:15:06 +00:00
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:
parent
3b7057ad4f
commit
6c6c2b57a1
3 changed files with 30 additions and 14 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Command> completePlayers(@NotNull final String input,
|
||||
@NotNull final List<String> existing) {
|
||||
List<String> players = cachedCompletionValues.getIfPresent("players");
|
||||
if (players == null) {
|
||||
final Collection<UUIDMapping> mappings =
|
||||
PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately();
|
||||
players = new ArrayList<>(mappings.size());
|
||||
for (final UUIDMapping mapping : mappings) {
|
||||
players.add(mapping.getUsername());
|
||||
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();
|
||||
players = new ArrayList<>(mappings.size());
|
||||
for (final UUIDMapping mapping : mappings) {
|
||||
players.add(mapping.getUsername());
|
||||
}
|
||||
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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue