mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Remove some Collections
usage
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
4a5736cc7c
commit
fc90fe8852
@ -14,7 +14,6 @@ import javax.lang.model.element.Modifier;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.StreamSupport;
|
||||
@ -134,7 +133,7 @@ public class DyeColorGenerator extends MinestomCodeGenerator {
|
||||
|
||||
// Write files to outputFolder
|
||||
writeFiles(
|
||||
Collections.singletonList(
|
||||
List.of(
|
||||
JavaFile.builder("net.minestom.server.color", dyeColorEnum.build())
|
||||
.indent(" ")
|
||||
.skipJavaLangImports(true)
|
||||
|
@ -14,7 +14,6 @@ import javax.lang.model.element.Modifier;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class VillagerProfessionGenerator extends MinestomCodeGenerator {
|
||||
@ -201,7 +200,7 @@ public final class VillagerProfessionGenerator extends MinestomCodeGenerator {
|
||||
|
||||
// Write files to outputFolder
|
||||
writeFiles(
|
||||
Collections.singletonList(
|
||||
List.of(
|
||||
JavaFile.builder("net.minestom.server.entity.metadata.villager", villagerProfessionClass.build())
|
||||
.indent(" ")
|
||||
.skipJavaLangImports(true)
|
||||
|
@ -14,7 +14,6 @@ import javax.lang.model.element.Modifier;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class VillagerTypeGenerator extends MinestomCodeGenerator {
|
||||
@ -153,7 +152,7 @@ public final class VillagerTypeGenerator extends MinestomCodeGenerator {
|
||||
|
||||
// Write files to outputFolder
|
||||
writeFiles(
|
||||
Collections.singletonList(
|
||||
List.of(
|
||||
JavaFile.builder("net.minestom.server.entity.metadata.villager", villagerTypeClass.build())
|
||||
.indent(" ")
|
||||
.skipJavaLangImports(true)
|
||||
|
@ -12,7 +12,7 @@ import javax.lang.model.element.Modifier;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class FluidGenerator extends MinestomCodeGenerator {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FluidGenerator.class);
|
||||
@ -132,7 +132,7 @@ public final class FluidGenerator extends MinestomCodeGenerator {
|
||||
|
||||
// Write files to outputFolder
|
||||
writeFiles(
|
||||
Collections.singletonList(
|
||||
List.of(
|
||||
JavaFile.builder("net.minestom.server.fluid", fluidClass.build())
|
||||
.indent(" ")
|
||||
.skipJavaLangImports(true)
|
||||
|
@ -10,7 +10,6 @@ import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.utils.entity.EntityFinder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static net.minestom.server.command.builder.arguments.ArgumentType.Integer;
|
||||
@ -32,7 +31,7 @@ public class GiveCommand extends Command {
|
||||
List<ItemStack> itemStacks;
|
||||
if (count <= 64) {
|
||||
itemStack = itemStack.withAmount(count);
|
||||
itemStacks = Collections.singletonList(itemStack);
|
||||
itemStacks = List.of(itemStack);
|
||||
} else {
|
||||
itemStacks = new ArrayList<>();
|
||||
while (count > 64) {
|
||||
|
@ -5,10 +5,7 @@ import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.key.Keyed;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
@ -94,7 +91,7 @@ public class AudienceRegistry {
|
||||
*/
|
||||
public @NotNull Iterable<? extends Audience> all() {
|
||||
if (this.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
return List.of();
|
||||
} else {
|
||||
return this.registry.values().stream().flatMap(Collection::stream).toList();
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ public class BossBarManager {
|
||||
public @NotNull Collection<BossBar> getPlayerBossBars(@NotNull Player player) {
|
||||
Collection<BossBarHolder> holders = this.playerBars.get(player.getUuid());
|
||||
return holders != null ?
|
||||
holders.stream().map(holder -> holder.bar).toList() : Collections.emptyList();
|
||||
holders.stream().map(holder -> holder.bar).toList() : List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -147,7 +147,7 @@ public class BossBarManager {
|
||||
public @NotNull Collection<Player> getBossBarViewers(@NotNull BossBar bossBar) {
|
||||
BossBarHolder holder = this.bars.get(bossBar);
|
||||
return holder != null ?
|
||||
Collections.unmodifiableCollection(holder.players) : Collections.emptyList();
|
||||
Collections.unmodifiableCollection(holder.players) : List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,7 +161,7 @@ public class Command {
|
||||
if (!hasOptional) {
|
||||
final CommandSyntax syntax = new CommandSyntax(commandCondition, executor, args);
|
||||
this.syntaxes.add(syntax);
|
||||
return Collections.singleton(syntax);
|
||||
return List.of(syntax);
|
||||
} else {
|
||||
List<CommandSyntax> optionalSyntaxes = new ArrayList<>();
|
||||
|
||||
@ -365,7 +365,7 @@ public class Command {
|
||||
addArguments.accept(node, arguments);
|
||||
arguments = new ArrayList<>();
|
||||
|
||||
node = findNode.apply(node, Collections.singleton(literal));
|
||||
node = findNode.apply(node, Set.of(literal));
|
||||
continue;
|
||||
} else if (argument instanceof ArgumentWord argumentWord) {
|
||||
if (argumentWord.hasRestrictions()) {
|
||||
|
@ -1637,7 +1637,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
||||
public List<Point> getLineOfSight(int maxDistance) {
|
||||
Instance instance = getInstance();
|
||||
if (instance == null) {
|
||||
return Collections.emptyList();
|
||||
return List.of();
|
||||
}
|
||||
|
||||
List<Point> blocks = new ArrayList<>();
|
||||
|
@ -1878,7 +1878,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
final PlayerSkin skin = this.skin;
|
||||
List<PlayerInfoPacket.AddPlayer.Property> prop = skin != null ?
|
||||
List.of(new PlayerInfoPacket.AddPlayer.Property("textures", skin.textures(), skin.signature())) :
|
||||
Collections.emptyList();
|
||||
List.of();
|
||||
return new PlayerInfoPacket(PlayerInfoPacket.Action.ADD_PLAYER,
|
||||
new PlayerInfoPacket.AddPlayer(getUuid(), getUsername(), prop, getGameMode(), getLatency(), displayName, null));
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ non-sealed class EventNodeImpl<T extends Event> implements EventNode<T> {
|
||||
@Override
|
||||
public <E extends T> @NotNull List<EventNode<E>> findChildren(@NotNull String name, Class<E> eventType) {
|
||||
synchronized (GLOBAL_CHILD_LOCK) {
|
||||
if (children.isEmpty()) return Collections.emptyList();
|
||||
if (children.isEmpty()) return List.of();
|
||||
List<EventNode<E>> result = new ArrayList<>();
|
||||
for (EventNode<T> child : children) {
|
||||
if (equals(child, name, eventType)) {
|
||||
|
@ -10,7 +10,7 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ -64,7 +64,7 @@ public interface BlockHandler {
|
||||
}
|
||||
|
||||
default @NotNull Collection<Tag<?>> getBlockEntityTags() {
|
||||
return Collections.emptyList();
|
||||
return List.of();
|
||||
}
|
||||
|
||||
default byte getBlockEntityAction() {
|
||||
|
@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public record ChatPreviewPacket(int queryId, @Nullable Component preview) implements ComponentHoldingServerPacket {
|
||||
@ -32,7 +32,7 @@ public record ChatPreviewPacket(int queryId, @Nullable Component preview) implem
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<Component> components() {
|
||||
return Collections.singleton(preview);
|
||||
return List.of(preview);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,7 +11,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
@ -49,7 +49,7 @@ public record PlayerChatMessagePacket(@NotNull Component signedContent, @Nullabl
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<Component> components() {
|
||||
return Collections.singleton(signedContent);
|
||||
return List.of(signedContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,7 +13,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
@ -75,7 +74,7 @@ public record TabCompletePacket(int transactionId, int start, int length,
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<Component> components() {
|
||||
return tooltip != null ? Collections.singletonList(tooltip) : List.of();
|
||||
return tooltip != null ? List.of(tooltip) : List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -129,11 +129,11 @@ public class EntityFinder {
|
||||
if (targetSelector == TargetSelector.MINESTOM_USERNAME) {
|
||||
Check.notNull(constantName, "The player name should not be null when searching for it");
|
||||
final Player player = MinecraftServer.getConnectionManager().getPlayer(constantName);
|
||||
return player != null ? Collections.singletonList(player) : Collections.emptyList();
|
||||
return player != null ? List.of(player) : List.of();
|
||||
} else if (targetSelector == TargetSelector.MINESTOM_UUID) {
|
||||
Check.notNull(constantUuid, "The UUID should not be null when searching for it");
|
||||
final Entity entity = Entity.getEntity(constantUuid);
|
||||
return entity != null ? Collections.singletonList(entity) : Collections.emptyList();
|
||||
return entity != null ? List.of(entity) : List.of();
|
||||
}
|
||||
|
||||
final Point pos = startPosition != null ? startPosition : (self != null ? self.getPosition() : Vec.ZERO);
|
||||
@ -221,7 +221,7 @@ public class EntityFinder {
|
||||
result = result.stream()
|
||||
.sorted((ent1, ent2) -> switch (entitySort) {
|
||||
case ARBITRARY, RANDOM ->
|
||||
// RANDOM is handled below
|
||||
// RANDOM is handled below
|
||||
1;
|
||||
case FURTHEST -> pos.distance(ent1.getPosition()) >
|
||||
pos.distance(ent2.getPosition()) ?
|
||||
@ -312,11 +312,11 @@ public class EntityFinder {
|
||||
if (targetSelector == TargetSelector.NEAREST_PLAYER) {
|
||||
return players.stream()
|
||||
.min(Comparator.comparingDouble(p -> p.getPosition().distance(startPosition)))
|
||||
.<List<Entity>>map(Collections::singletonList).orElse(Collections.emptyList());
|
||||
.<List<Entity>>map(Collections::singletonList).orElse(List.of());
|
||||
} else if (targetSelector == TargetSelector.RANDOM_PLAYER) {
|
||||
final int index = ThreadLocalRandom.current().nextInt(players.size());
|
||||
final Player player = players.stream().skip(index).findFirst().orElseThrow();
|
||||
return Collections.singletonList(player);
|
||||
return List.of(player);
|
||||
} else if (targetSelector == TargetSelector.ALL_PLAYERS) {
|
||||
return List.copyOf(players);
|
||||
} else if (targetSelector == TargetSelector.ALL_ENTITIES) {
|
||||
@ -331,7 +331,7 @@ public class EntityFinder {
|
||||
}
|
||||
return entities;
|
||||
} else if (targetSelector == TargetSelector.SELF) {
|
||||
return self != null ? Collections.singletonList(self) : Collections.emptyList();
|
||||
return self != null ? List.of(self) : List.of();
|
||||
}
|
||||
throw new IllegalStateException("Weird thing happened: " + targetSelector);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user