Optimise some streams.

This commit is contained in:
benwoo1110 2020-12-21 20:03:08 +08:00
parent a783f773b3
commit a05d4581f6
3 changed files with 12 additions and 5 deletions

View File

@ -48,14 +48,17 @@ public class MVCommandCompletions extends PaperCommandCompletions {
private Collection<String> suggestDestinations(@NotNull BukkitCommandCompletionContext context) {
//TODO: There is one empty dest need to remove.
return this.plugin.getDestFactory().getIdentifiers().stream()
return this.plugin.getDestFactory().getIdentifiers().parallelStream()
.unordered()
.filter(id -> !id.isEmpty())
.map(id -> id + ":")
.collect(Collectors.toList());
}
@NotNull
private Collection<String> suggestMVWorlds(@NotNull BukkitCommandCompletionContext context) {
return this.worldManager.getMVWorlds().stream()
return this.worldManager.getMVWorlds().parallelStream()
.unordered()
.map(MultiverseWorld::getName)
.collect(Collectors.toList());
}
@ -69,11 +72,13 @@ public class MVCommandCompletions extends PaperCommandCompletions {
private Collection<String> suggestPotentialWorlds(@NotNull BukkitCommandCompletionContext context) {
//TODO: Should be more efficient
//TODO: this should be in WorldManager API
List<String> knownWorlds = this.worldManager.getMVWorlds().stream()
List<String> knownWorlds = this.worldManager.getMVWorlds().parallelStream()
.unordered()
.map(MultiverseWorld::getName)
.collect(Collectors.toList());
return Arrays.stream(this.plugin.getServer().getWorldContainer().listFiles())
return Arrays.stream(this.plugin.getServer().getWorldContainer().listFiles()).parallel()
.unordered()
.filter(File::isDirectory)
.filter(file -> !knownWorlds.contains(file.getName()))
.map(File::getName)

View File

@ -204,7 +204,8 @@ public class MVCommandContexts extends PaperCommandContexts {
List<Player> matchedPlayers;
try {
matchedPlayers = this.plugin.getServer().selectEntities(sender, playerIdentifier).stream()
matchedPlayers = this.plugin.getServer().selectEntities(sender, playerIdentifier).parallelStream()
.unordered()
.filter(e -> e instanceof Player)
.map(e -> ((Player) e))
.collect(Collectors.toList());

View File

@ -241,6 +241,7 @@ public class PageDisplay {
private void doEndPadding() {
IntStream.range(0, contentLinesPerPage - contentToShowIndex.size())
.unordered()
.mapToObj(i -> " ")
.forEach(sender::sendMessage);
}