mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-28 03:57:50 +01:00
Use java 17 toList()
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
ad75e942aa
commit
0f2ad33e52
@ -8,7 +8,6 @@ import net.minestom.server.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Utility class to access Adventure audiences.
|
||||
@ -61,7 +60,7 @@ public class Audiences {
|
||||
* @return all players matching the predicate
|
||||
*/
|
||||
public static @NotNull Audience players(@NotNull Predicate<Player> filter) {
|
||||
return PacketGroupingAudience.of(MinecraftServer.getConnectionManager().getOnlinePlayers().stream().filter(filter).collect(Collectors.toList()));
|
||||
return PacketGroupingAudience.of(MinecraftServer.getConnectionManager().getOnlinePlayers().stream().filter(filter).toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,6 @@ import java.util.Collections;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
/**
|
||||
@ -39,7 +38,7 @@ class IterableAudienceProvider implements AudienceProvider<Iterable<? extends Au
|
||||
|
||||
@Override
|
||||
public @NotNull Iterable<? extends Audience> players(@NotNull Predicate<Player> filter) {
|
||||
return MinecraftServer.getConnectionManager().getOnlinePlayers().stream().filter(filter).collect(Collectors.toList());
|
||||
return MinecraftServer.getConnectionManager().getOnlinePlayers().stream().filter(filter).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,7 +63,7 @@ class IterableAudienceProvider implements AudienceProvider<Iterable<? extends Au
|
||||
|
||||
@Override
|
||||
public @NotNull Iterable<? extends Audience> custom(@NotNull Key key, Predicate<Audience> filter) {
|
||||
return StreamSupport.stream(this.registry.of(key).spliterator(), false).filter(filter).collect(Collectors.toList());
|
||||
return StreamSupport.stream(this.registry.of(key).spliterator(), false).filter(filter).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,7 +73,7 @@ class IterableAudienceProvider implements AudienceProvider<Iterable<? extends Au
|
||||
|
||||
@Override
|
||||
public @NotNull Iterable<? extends Audience> all(@NotNull Predicate<Audience> filter) {
|
||||
return StreamSupport.stream(this.all().spliterator(), false).filter(filter).collect(Collectors.toList());
|
||||
return StreamSupport.stream(this.all().spliterator(), false).filter(filter).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,7 +7,6 @@ import net.minestom.server.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* A provider of audiences. For complex returns, this instance is backed by
|
||||
@ -43,7 +42,7 @@ class SingleAudienceProvider implements AudienceProvider<Audience> {
|
||||
|
||||
@Override
|
||||
public @NotNull Audience players(@NotNull Predicate<Player> filter) {
|
||||
return PacketGroupingAudience.of(MinecraftServer.getConnectionManager().getOnlinePlayers().stream().filter(filter).collect(Collectors.toList()));
|
||||
return PacketGroupingAudience.of(MinecraftServer.getConnectionManager().getOnlinePlayers().stream().filter(filter).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Manages all boss bars known to this Minestom instance. Although this class can be used
|
||||
@ -76,8 +75,7 @@ public class BossBarManager {
|
||||
*/
|
||||
public void addBossBar(@NotNull Collection<Player> players, @NotNull BossBar bar) {
|
||||
BossBarHolder holder = this.getOrCreateHandler(bar);
|
||||
Collection<Player> addedPlayers = players.stream().filter(holder::addViewer).collect(Collectors.toList());
|
||||
|
||||
Collection<Player> addedPlayers = players.stream().filter(holder::addViewer).toList();
|
||||
if (!addedPlayers.isEmpty()) {
|
||||
PacketUtils.sendGroupedPacket(addedPlayers, holder.createAddPacket());
|
||||
}
|
||||
@ -91,10 +89,8 @@ public class BossBarManager {
|
||||
*/
|
||||
public void removeBossBar(@NotNull Collection<Player> players, @NotNull BossBar bar) {
|
||||
BossBarHolder holder = this.bars.get(bar);
|
||||
|
||||
if (holder != null) {
|
||||
Collection<Player> removedPlayers = players.stream().filter(holder::removeViewer).collect(Collectors.toList());
|
||||
|
||||
Collection<Player> removedPlayers = players.stream().filter(holder::removeViewer).toList();
|
||||
if (!removedPlayers.isEmpty()) {
|
||||
PacketUtils.sendGroupedPacket(removedPlayers, holder.createRemovePacket());
|
||||
}
|
||||
@ -108,10 +104,8 @@ public class BossBarManager {
|
||||
*/
|
||||
public void destroyBossBar(@NotNull BossBar bossBar) {
|
||||
BossBarHolder holder = this.bars.remove(bossBar);
|
||||
|
||||
if (holder != null) {
|
||||
PacketUtils.sendGroupedPacket(holder.players, holder.createRemovePacket());
|
||||
|
||||
for (Player player : holder.players) {
|
||||
this.removePlayer(player, holder);
|
||||
}
|
||||
@ -127,7 +121,6 @@ public class BossBarManager {
|
||||
*/
|
||||
public void removeAllBossBars(@NotNull Player player) {
|
||||
Set<BossBarHolder> holders = this.playerBars.remove(player.getUuid());
|
||||
|
||||
if (holders != null) {
|
||||
for (BossBarHolder holder : holders) {
|
||||
holder.removeViewer(player);
|
||||
@ -143,12 +136,8 @@ public class BossBarManager {
|
||||
*/
|
||||
public @NotNull Collection<BossBar> getPlayerBossBars(@NotNull Player player) {
|
||||
Collection<BossBarHolder> holders = this.playerBars.get(player.getUuid());
|
||||
|
||||
if (holders == null) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return holders.stream().map(holder -> holder.bar).toList();
|
||||
}
|
||||
return holders != null ?
|
||||
holders.stream().map(holder -> holder.bar).toList() : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,12 +148,8 @@ public class BossBarManager {
|
||||
*/
|
||||
public @NotNull Collection<Player> getBossBarViewers(@NotNull BossBar bossBar) {
|
||||
BossBarHolder holder = this.bars.get(bossBar);
|
||||
|
||||
if (holder == null) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return Collections.unmodifiableCollection(holder.players);
|
||||
}
|
||||
return holder != null ?
|
||||
Collections.unmodifiableCollection(holder.players) : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,10 +168,8 @@ public class BossBarManager {
|
||||
|
||||
private void removePlayer(Player player, BossBarHolder holder) {
|
||||
Set<BossBarHolder> holders = this.playerBars.get(player.getUuid());
|
||||
|
||||
if (holders != null) {
|
||||
holders.remove(holder);
|
||||
|
||||
if (holders.isEmpty()) {
|
||||
this.playerBars.remove(player.getUuid());
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Manager used to register {@link Command commands}.
|
||||
@ -315,7 +314,7 @@ public final class CommandManager {
|
||||
Map<IndexedArgument, List<DeclareCommandsPacket.Node[]>> storedArgumentsNodes = new HashMap<>();
|
||||
|
||||
// Sort syntaxes by argument count. Brigadier requires it.
|
||||
syntaxes = syntaxes.stream().sorted(Comparator.comparingInt(o -> -o.getArguments().length)).collect(Collectors.toList());
|
||||
syntaxes = syntaxes.stream().sorted(Comparator.comparingInt(o -> -o.getArguments().length)).toList();
|
||||
for (CommandSyntax syntax : syntaxes) {
|
||||
final CommandCondition commandCondition = syntax.getCommandCondition();
|
||||
if (commandCondition != null && !commandCondition.canUse(sender, null)) {
|
||||
|
@ -9,7 +9,6 @@ import net.minestom.server.utils.binary.Writeable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* A full query response containing a dynamic set of responses.
|
||||
@ -36,7 +35,7 @@ public class FullQueryResponse implements Writeable {
|
||||
this.players = MinecraftServer.getConnectionManager().getOnlinePlayers()
|
||||
.stream()
|
||||
.map(player -> PLAIN.serialize(player.getName()))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
// TODO
|
||||
|
||||
@ -150,7 +149,7 @@ public class EntityFinder {
|
||||
final int maxDistance = distance.getMaximum();
|
||||
result = result.stream()
|
||||
.filter(entity -> MathUtils.isBetween(entity.getDistance(pos), minDistance, maxDistance))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
|
||||
// Diff X/Y/Z
|
||||
@ -173,14 +172,14 @@ public class EntityFinder {
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}).collect(Collectors.toList());
|
||||
}).toList();
|
||||
}
|
||||
|
||||
// Entity type
|
||||
if (!entityTypes.isEmpty()) {
|
||||
result = result.stream()
|
||||
.filter(entity -> filterToggleableMap(entity.getEntityType(), entityTypes))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
|
||||
// GameMode
|
||||
@ -188,7 +187,7 @@ public class EntityFinder {
|
||||
result = result.stream()
|
||||
.filter(Player.class::isInstance)
|
||||
.filter(entity -> filterToggleableMap(((Player) entity).getGameMode(), gameModes))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
|
||||
// Level
|
||||
@ -198,7 +197,7 @@ public class EntityFinder {
|
||||
result = result.stream()
|
||||
.filter(Player.class::isInstance)
|
||||
.filter(entity -> MathUtils.isBetween(((Player) entity).getLevel(), minLevel, maxLevel))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
|
||||
// Name
|
||||
@ -206,14 +205,14 @@ public class EntityFinder {
|
||||
result = result.stream()
|
||||
.filter(Player.class::isInstance)
|
||||
.filter(entity -> filterToggleableMap(((Player) entity).getUsername(), names))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
|
||||
// UUID
|
||||
if (!uuids.isEmpty()) {
|
||||
result = result.stream()
|
||||
.filter(entity -> filterToggleableMap(entity.getUuid(), uuids))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
@ -232,7 +231,7 @@ public class EntityFinder {
|
||||
1 : 0;
|
||||
})
|
||||
.limit(limit != null ? limit : Integer.MAX_VALUE)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
|
||||
if (entitySort == EntitySort.RANDOM) {
|
||||
Collections.shuffle(result);
|
||||
|
@ -7,7 +7,6 @@ import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.instance.Instance;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DimensionCommand extends Command {
|
||||
|
||||
@ -18,7 +17,7 @@ public class DimensionCommand extends Command {
|
||||
addSyntax((sender, context) -> {
|
||||
final Player player = sender.asPlayer();
|
||||
final Instance instance = player.getInstance();
|
||||
final var instances = MinecraftServer.getInstanceManager().getInstances().stream().filter(instance1 -> !instance1.equals(instance)).collect(Collectors.toList());
|
||||
final var instances = MinecraftServer.getInstanceManager().getInstances().stream().filter(instance1 -> !instance1.equals(instance)).toList();
|
||||
if (instances.isEmpty()) {
|
||||
player.sendMessage("No instance available");
|
||||
return;
|
||||
|
@ -8,7 +8,6 @@ import net.minestom.server.command.builder.CommandContext;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlayersCommand extends Command {
|
||||
|
||||
@ -27,7 +26,7 @@ public class PlayersCommand extends Command {
|
||||
sender.sendMessage(Component.text(player.getUsername()));
|
||||
}
|
||||
} else {
|
||||
for (final Player player : players.stream().limit(limit).collect(Collectors.toList())) {
|
||||
for (final Player player : players.stream().limit(limit).toList()) {
|
||||
sender.sendMessage(Component.text(player.getUsername()));
|
||||
}
|
||||
sender.sendMessage(Component.text("..."));
|
||||
|
Loading…
Reference in New Issue
Block a user