From 18776a8000c34249c36bd9bfd5798e231d62e89a Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Thu, 22 Aug 2024 19:57:46 +0200 Subject: [PATCH] Address reviews --- .../geyser/configuration/GeyserConfiguration.java | 3 --- .../configuration/GeyserJacksonConfiguration.java | 3 --- .../type/GeyserDefineResourcePacksEventImpl.java | 3 +-- .../type/SessionLoadResourcePacksEventImpl.java | 11 ++++------- .../org/geysermc/geyser/pack/ResourcePackHolder.java | 5 +++++ .../geyser/registry/loader/ResourcePackLoader.java | 12 +++++++----- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/configuration/GeyserConfiguration.java b/core/src/main/java/org/geysermc/geyser/configuration/GeyserConfiguration.java index 543dedf92..88bb98171 100644 --- a/core/src/main/java/org/geysermc/geyser/configuration/GeyserConfiguration.java +++ b/core/src/main/java/org/geysermc/geyser/configuration/GeyserConfiguration.java @@ -96,9 +96,6 @@ public interface GeyserConfiguration { boolean isForceResourcePacks(); - // TODO configurate - till then, api only - //List getResourcePackUrls(); - @SuppressWarnings("BooleanMethodIsAlwaysInverted") boolean isXboxAchievementsEnabled(); diff --git a/core/src/main/java/org/geysermc/geyser/configuration/GeyserJacksonConfiguration.java b/core/src/main/java/org/geysermc/geyser/configuration/GeyserJacksonConfiguration.java index 6b609cb1a..81ac824e4 100644 --- a/core/src/main/java/org/geysermc/geyser/configuration/GeyserJacksonConfiguration.java +++ b/core/src/main/java/org/geysermc/geyser/configuration/GeyserJacksonConfiguration.java @@ -136,9 +136,6 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration @JsonProperty("force-resource-packs") private boolean forceResourcePacks = true; -// @JsonProperty("resource-pack-urls") -// private List resourcePackUrls = new ArrayList<>(); - @JsonProperty("xbox-achievements-enabled") private boolean xboxAchievementsEnabled = false; diff --git a/core/src/main/java/org/geysermc/geyser/event/type/GeyserDefineResourcePacksEventImpl.java b/core/src/main/java/org/geysermc/geyser/event/type/GeyserDefineResourcePacksEventImpl.java index adec6e0d5..4906dc928 100644 --- a/core/src/main/java/org/geysermc/geyser/event/type/GeyserDefineResourcePacksEventImpl.java +++ b/core/src/main/java/org/geysermc/geyser/event/type/GeyserDefineResourcePacksEventImpl.java @@ -39,7 +39,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.UUID; -import java.util.stream.Collectors; @Getter public class GeyserDefineResourcePacksEventImpl extends GeyserDefineResourcePacksEvent { @@ -51,7 +50,7 @@ public class GeyserDefineResourcePacksEventImpl extends GeyserDefineResourcePack @Override public @NonNull List resourcePacks() { - return packs.values().stream().map(ResourcePackHolder::pack).collect(Collectors.toUnmodifiableList()); + return packs.values().stream().map(ResourcePackHolder::resourcePack).toList(); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/event/type/SessionLoadResourcePacksEventImpl.java b/core/src/main/java/org/geysermc/geyser/event/type/SessionLoadResourcePacksEventImpl.java index c81adfb08..ba8acdd20 100644 --- a/core/src/main/java/org/geysermc/geyser/event/type/SessionLoadResourcePacksEventImpl.java +++ b/core/src/main/java/org/geysermc/geyser/event/type/SessionLoadResourcePacksEventImpl.java @@ -51,9 +51,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.TreeSet; import java.util.UUID; -import java.util.stream.Collectors; public class SessionLoadResourcePacksEventImpl extends SessionLoadResourcePacksEvent { @@ -69,7 +67,7 @@ public class SessionLoadResourcePacksEventImpl extends SessionLoadResourcePacksE @Override public @NonNull List resourcePacks() { - return packs.values().stream().map(ResourcePackHolder::pack).collect(Collectors.toUnmodifiableList()); + return packs.values().stream().map(ResourcePackHolder::resourcePack).toList(); } @Override @@ -138,13 +136,12 @@ public class SessionLoadResourcePacksEventImpl extends SessionLoadResourcePacksE // Methods used internally for e.g. ordered packs, or resource pack entries public List orderedPacks() { - TreeSet> sortedPacks = packs.values().stream() + return packs.values().stream() // Map each ResourcePack to a pair of (GeyserResourcePack, Priority) .map(holder -> new AbstractMap.SimpleEntry<>(holder.pack(), priority(holder.pack()))) // Sort by priority in ascending order - .collect(Collectors.toCollection(() -> new TreeSet<>(Map.Entry.comparingByValue(Comparator.naturalOrder())))); - - return sortedPacks.stream() + .sorted(Map.Entry.comparingByValue(Comparator.naturalOrder())) + // Map the sorted entries to ResourcePackStackPacket.Entry .map(entry -> { ResourcePackManifest.Header header = entry.getKey().manifest().header(); return new ResourcePackStackPacket.Entry( diff --git a/core/src/main/java/org/geysermc/geyser/pack/ResourcePackHolder.java b/core/src/main/java/org/geysermc/geyser/pack/ResourcePackHolder.java index 20463fab8..2eb7e5b97 100644 --- a/core/src/main/java/org/geysermc/geyser/pack/ResourcePackHolder.java +++ b/core/src/main/java/org/geysermc/geyser/pack/ResourcePackHolder.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.pack; import org.checkerframework.checker.nullness.qual.NonNull; +import org.geysermc.geyser.api.pack.ResourcePack; import org.geysermc.geyser.pack.option.OptionHolder; public record ResourcePackHolder( @@ -36,4 +37,8 @@ public record ResourcePackHolder( public static ResourcePackHolder of(GeyserResourcePack pack) { return new ResourcePackHolder(pack, new OptionHolder()); } + + public ResourcePack resourcePack() { + return this.pack; + } } diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ResourcePackLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ResourcePackLoader.java index 4a78069b4..0c338b26b 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ResourcePackLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ResourcePackLoader.java @@ -130,11 +130,16 @@ public class ResourcePackLoader implements RegistryLoader