From d2622a477bab7453ee0cd60128914aef5426aabb Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Tue, 16 Jan 2024 00:47:52 +0100 Subject: [PATCH] Add a registerAll method to register a collection of resource packs easily --- .../event/bedrock/SessionLoadResourcePacksEvent.java | 9 +++++++++ .../lifecycle/GeyserDefineResourcePacksEvent.java | 10 ++++++++++ .../type/GeyserDefineResourcePacksEventImpl.java | 12 ++++++++++++ .../type/SessionLoadResourcePacksEventImpl.java | 12 ++++++++++++ 4 files changed, 43 insertions(+) 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 71f9e9a0d..127a1ee8b 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 @@ -30,6 +30,7 @@ import org.geysermc.geyser.api.connection.GeyserConnection; import org.geysermc.geyser.api.event.connection.ConnectionEvent; import org.geysermc.geyser.api.pack.ResourcePack; +import java.util.Collection; import java.util.List; import java.util.UUID; @@ -57,6 +58,14 @@ public abstract class SessionLoadResourcePacksEvent extends ConnectionEvent { */ public abstract boolean register(@NonNull ResourcePack resourcePack); + /** + * 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); + /** * 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 b62ddb8cc..b5cb59001 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 @@ -29,6 +29,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.event.Event; import org.geysermc.geyser.api.pack.ResourcePack; +import java.util.Collection; import java.util.List; import java.util.UUID; @@ -53,6 +54,15 @@ public abstract class GeyserDefineResourcePacksEvent implements Event { */ public abstract boolean register(@NonNull ResourcePack resourcePack); + /** + * 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); + + /** * Unregisters a {@link ResourcePack} from being sent to clients. * 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 2fae61b54..2775b80db 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 @@ -30,6 +30,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineResourcePacksEvent; import org.geysermc.geyser.api.pack.ResourcePack; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.UUID; @@ -58,6 +59,17 @@ public class GeyserDefineResourcePacksEventImpl extends GeyserDefineResourcePack return true; } + @Override + public boolean registerAll(@NonNull Collection resourcePacks) { + boolean successful = true; + for (ResourcePack pack : resourcePacks) { + if (!this.register(pack)) { + successful = false; + } + } + return successful; + } + @Override public boolean unregister(@NonNull UUID uuid) { return packs.remove(uuid.toString()) != null; 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 e66396d6a..4e71e6b13 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 @@ -31,6 +31,7 @@ import org.geysermc.geyser.api.event.bedrock.SessionLoadResourcePacksEvent; import org.geysermc.geyser.api.pack.ResourcePack; import org.geysermc.geyser.session.GeyserSession; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.UUID; @@ -59,6 +60,17 @@ public class SessionLoadResourcePacksEventImpl extends SessionLoadResourcePacksE return true; } + @Override + public boolean registerAll(@NonNull Collection resourcePacks) { + boolean successful = true; + for (ResourcePack pack : resourcePacks) { + if (!this.register(pack)) { + successful = false; + } + } + return successful; + } + @Override public boolean unregister(@NonNull UUID uuid) { return packs.remove(uuid.toString()) != null;