mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24:23 +01:00
Extract nullable stream to new util class.
This commit is contained in:
parent
d664cabb1a
commit
d8913ed245
2 changed files with 20 additions and 12 deletions
|
@ -26,6 +26,7 @@ import com.voxelmodpack.hdskins.skins.ServerType;
|
||||||
import com.voxelmodpack.hdskins.skins.SkinServer;
|
import com.voxelmodpack.hdskins.skins.SkinServer;
|
||||||
import com.voxelmodpack.hdskins.skins.ValhallaSkinServer;
|
import com.voxelmodpack.hdskins.skins.ValhallaSkinServer;
|
||||||
import com.voxelmodpack.hdskins.util.CallableFutures;
|
import com.voxelmodpack.hdskins.util.CallableFutures;
|
||||||
|
import com.voxelmodpack.hdskins.util.MoreStreams;
|
||||||
import com.voxelmodpack.hdskins.util.PlayerUtil;
|
import com.voxelmodpack.hdskins.util.PlayerUtil;
|
||||||
import com.voxelmodpack.hdskins.util.ProfileTextureUtil;
|
import com.voxelmodpack.hdskins.util.ProfileTextureUtil;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -288,7 +289,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Stream<NetworkPlayerInfo> getNPCs(Minecraft mc) {
|
private Stream<NetworkPlayerInfo> getNPCs(Minecraft mc) {
|
||||||
return nullableStream(mc.world)
|
return MoreStreams.ofNullable(mc.world)
|
||||||
.flatMap(w -> w.playerEntities.stream())
|
.flatMap(w -> w.playerEntities.stream())
|
||||||
.filter(AbstractClientPlayer.class::isInstance)
|
.filter(AbstractClientPlayer.class::isInstance)
|
||||||
.map(AbstractClientPlayer.class::cast)
|
.map(AbstractClientPlayer.class::cast)
|
||||||
|
@ -296,14 +297,10 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Stream<NetworkPlayerInfo> getPlayers(Minecraft mc) {
|
private Stream<NetworkPlayerInfo> getPlayers(Minecraft mc) {
|
||||||
return nullableStream(mc.getConnection())
|
return MoreStreams.ofNullable(mc.getConnection())
|
||||||
.flatMap(a -> a.getPlayerInfoMap().stream());
|
.flatMap(a -> a.getPlayerInfoMap().stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> Stream<T> nullableStream(@Nullable T t) {
|
|
||||||
return t == null ? Stream.empty() : Stream.of(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void parseSkin(GameProfile profile, Type type, ResourceLocation resource, MinecraftProfileTexture texture) {
|
public void parseSkin(GameProfile profile, Type type, ResourceLocation resource, MinecraftProfileTexture texture) {
|
||||||
|
|
||||||
CallableFutures.scheduleTask(() -> {
|
CallableFutures.scheduleTask(() -> {
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.voxelmodpack.hdskins.util;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class MoreStreams {
|
||||||
|
|
||||||
|
public static <T> Stream<T> ofNullable(@Nullable T t) {
|
||||||
|
return t == null ? Stream.empty() : Stream.of(t);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue