From ba78dbaf349b388516bb87c962ca2f1c8c44649c Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Thu, 20 Jun 2024 12:28:08 +0200 Subject: [PATCH] Add url codec creation method with no content key, remove boolean return to registerAll, fix typo --- .../event/bedrock/SessionLoadResourcePacksEvent.java | 3 +-- .../lifecycle/GeyserDefineResourcePacksEvent.java | 3 +-- .../java/org/geysermc/geyser/api/pack/PackCodec.java | 11 +++++++++++ .../type/GeyserDefineResourcePacksEventImpl.java | 10 ++-------- .../event/type/SessionLoadResourcePacksEventImpl.java | 10 ++-------- .../geyser/network/UpstreamPacketHandler.java | 10 +++++----- 6 files changed, 22 insertions(+), 25 deletions(-) diff --git a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionLoadResourcePacksEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionLoadResourcePacksEvent.java index 127a1ee8b..6c92628d9 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionLoadResourcePacksEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionLoadResourcePacksEvent.java @@ -62,9 +62,8 @@ public abstract class SessionLoadResourcePacksEvent extends ConnectionEvent { * Registers a collection of {@link ResourcePack} to be sent to clients. * * @param resourcePacks collection of resourcePack's that will be sent to clients. - * @return true if resource packs were added successfully, false if at least one failed */ - public abstract boolean registerAll(@NonNull Collection resourcePacks); + public abstract void registerAll(@NonNull Collection resourcePacks); /** * Unregisters a {@link ResourcePack} from being sent to the client. diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineResourcePacksEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineResourcePacksEvent.java index b5cb59001..378aa417e 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineResourcePacksEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineResourcePacksEvent.java @@ -58,9 +58,8 @@ public abstract class GeyserDefineResourcePacksEvent implements Event { * Registers a collection of {@link ResourcePack} to be sent to clients. * * @param resourcePacks collection of resourcePack's that will be sent to clients. - * @return true if resource packs were added successfully, false if at least one failed */ - public abstract boolean registerAll(@NonNull Collection resourcePacks); + public abstract void registerAll(@NonNull Collection resourcePacks); /** diff --git a/api/src/main/java/org/geysermc/geyser/api/pack/PackCodec.java b/api/src/main/java/org/geysermc/geyser/api/pack/PackCodec.java index 7c123b624..6d298f410 100644 --- a/api/src/main/java/org/geysermc/geyser/api/pack/PackCodec.java +++ b/api/src/main/java/org/geysermc/geyser/api/pack/PackCodec.java @@ -81,6 +81,17 @@ public abstract class PackCodec { return GeyserApi.api().provider(PathPackCodec.class, path); } + /** + * Creates a new pack provider from the given url with no content key. + * + * @param url the url to create the pack provider from + * @return the new pack provider + */ + @NonNull + public static PackCodec url(@NonNull String url) { + return url(url, null); + } + /** * Creates a new pack provider from the given url and content key. * 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 2775b80db..04060d46c 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 @@ -60,14 +60,8 @@ public class GeyserDefineResourcePacksEventImpl extends GeyserDefineResourcePack } @Override - public boolean registerAll(@NonNull Collection resourcePacks) { - boolean successful = true; - for (ResourcePack pack : resourcePacks) { - if (!this.register(pack)) { - successful = false; - } - } - return successful; + public void registerAll(@NonNull Collection resourcePacks) { + resourcePacks.forEach(this::register); } @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 4e71e6b13..505c551e5 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 @@ -61,14 +61,8 @@ public class SessionLoadResourcePacksEventImpl extends SessionLoadResourcePacksE } @Override - public boolean registerAll(@NonNull Collection resourcePacks) { - boolean successful = true; - for (ResourcePack pack : resourcePacks) { - if (!this.register(pack)) { - successful = false; - } - } - return successful; + public void registerAll(@NonNull Collection resourcePacks) { + resourcePacks.forEach(this::register); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index ca8c6cd11..db55a543a 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -70,7 +70,7 @@ import java.util.OptionalInt; public class UpstreamPacketHandler extends LoggingPacketHandler { private boolean networkSettingsRequested = false; - private final Deque packsToSent = new ArrayDeque<>(); + private final Deque packsToSend = new ArrayDeque<>(); private final CompressionStrategy compressionStrategy; private SessionLoadResourcePacksEventImpl resourcePackLoadEvent; @@ -227,8 +227,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.network.connect", session.getAuthData().name())); } case SEND_PACKS -> { - packsToSent.addAll(packet.getPackIds()); - sendPackDataInfo(packsToSent.pop()); + packsToSend.addAll(packet.getPackIds()); + sendPackDataInfo(packsToSend.pop()); } case HAVE_ALL_PACKS -> { ResourcePackStackPacket stackPacket = new ResourcePackStackPacket(); @@ -329,8 +329,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { session.sendUpstreamPacket(data); // Check if it is the last chunk and send next pack in queue when available. - if (remainingSize <= GeyserResourcePack.CHUNK_SIZE && !packsToSent.isEmpty()) { - sendPackDataInfo(packsToSent.pop()); + if (remainingSize <= GeyserResourcePack.CHUNK_SIZE && !packsToSend.isEmpty()) { + sendPackDataInfo(packsToSend.pop()); } return PacketSignal.HANDLED;