mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01: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
@ -318,6 +318,9 @@ public class PaperListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onAsyncTabCompletion(final AsyncTabCompleteEvent event) {
|
@EventHandler public void onAsyncTabCompletion(final AsyncTabCompleteEvent event) {
|
||||||
|
if (!Settings.Paper_Components.ASYNC_TAB_COMPLETION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
String buffer = event.getBuffer();
|
String buffer = event.getBuffer();
|
||||||
if (!(event.getSender() instanceof Player)) {
|
if (!(event.getSender() instanceof Player)) {
|
||||||
return;
|
return;
|
||||||
|
@ -238,7 +238,6 @@ public class Settings extends Config {
|
|||||||
@Comment("Force using lowercase UUIDs") public static boolean FORCE_LOWERCASE = false;
|
@Comment("Force using lowercase UUIDs") public static boolean FORCE_LOWERCASE = false;
|
||||||
@Comment("Use a database to store UUID/name info") public static boolean
|
@Comment("Use a database to store UUID/name info") public static boolean
|
||||||
USE_SQLUUIDHANDLER = false;
|
USE_SQLUUIDHANDLER = false;
|
||||||
@Ignore public static boolean NATIVE_UUID_PROVIDER = false;
|
|
||||||
@Comment("How many UUIDs that may be stored in the cache")
|
@Comment("How many UUIDs that may be stored in the cache")
|
||||||
public static int UUID_CACHE_SIZE = 100000;
|
public static int UUID_CACHE_SIZE = 100000;
|
||||||
@Comment("Rate limit (per 10 minutes) for background UUID fetching from the Mojang API")
|
@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;
|
public static boolean CREATURE_SPAWN = true;
|
||||||
@Comment("Check the tile entity limit on block placement")
|
@Comment("Check the tile entity limit on block placement")
|
||||||
public static boolean TILE_ENTITY_CHECK = true;
|
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")
|
@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("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 =
|
@Comment("Commands are used to interact with the plugin") public static boolean COMMANDS =
|
||||||
true;
|
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
|
@Comment("Whether we should notify you about updates or not.") public static boolean
|
||||||
UPDATE_NOTIFICATIONS = true;
|
UPDATE_NOTIFICATIONS = true;
|
||||||
@Comment("Stores user metadata in a database") public static boolean PERSISTENT_META = 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;
|
public static boolean EXTERNAL_PLACEHOLDERS = true;
|
||||||
@Comment("Make road regeneration persistent across restarts") public static boolean
|
@Comment("Make road regeneration persistent across restarts") public static boolean
|
||||||
PERSISTENT_ROAD_REGEN = false;
|
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")
|
@Comment("Plot component preset GUI")
|
||||||
public static boolean COMPONENT_PRESETS = true;
|
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.Command;
|
||||||
import com.plotsquared.core.command.CommandCategory;
|
import com.plotsquared.core.command.CommandCategory;
|
||||||
import com.plotsquared.core.command.RequiredType;
|
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 com.plotsquared.core.uuid.UUIDMapping;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -61,15 +63,24 @@ public class TabCompletions {
|
|||||||
*/
|
*/
|
||||||
@NotNull public List<Command> completePlayers(@NotNull final String input,
|
@NotNull public List<Command> completePlayers(@NotNull final String input,
|
||||||
@NotNull final List<String> existing) {
|
@NotNull final List<String> existing) {
|
||||||
List<String> players = cachedCompletionValues.getIfPresent("players");
|
List<String> players;
|
||||||
if (players == null) {
|
if (Settings.Enabled_Components.EXTENDED_USERNAME_COMPLETION) {
|
||||||
final Collection<UUIDMapping> mappings =
|
players = cachedCompletionValues.getIfPresent("players");
|
||||||
PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately();
|
if (players == null) {
|
||||||
players = new ArrayList<>(mappings.size());
|
final Collection<UUIDMapping> mappings =
|
||||||
for (final UUIDMapping mapping : mappings) {
|
PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately();
|
||||||
players.add(mapping.getUsername());
|
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);
|
final String processedInput = input.toLowerCase(Locale.ENGLISH);
|
||||||
return players.stream()
|
return players.stream()
|
||||||
@ -77,7 +88,10 @@ public class TabCompletions {
|
|||||||
.filter(player -> !existing.contains(player)).map(
|
.filter(player -> !existing.contains(player)).map(
|
||||||
player -> new Command(null, false, player, "", RequiredType.NONE,
|
player -> new Command(null, false, player, "", RequiredType.NONE,
|
||||||
CommandCategory.INFO) {
|
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 New Issue
Block a user