Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Allow API users to set ResourcePackOption's, add a GeyserDefineResourcePacksEvent #4978

Open
wants to merge 74 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
68516a8
Initial stab at implementing 1.20.30's new CDN feature for resource p…
onebeastchris Oct 10, 2023
02d6473
Small tweaks: record formatting/javadocs
onebeastchris Oct 10, 2023
dbfc153
- Don't require configuring the packId, just the link instead
onebeastchris Oct 10, 2023
f74d36a
Remove forRemoval
onebeastchris Oct 10, 2023
94f2ea9
Rename cdn-resource-packs to resource-pack-urls, fix test, remove dup…
onebeastchris Oct 10, 2023
fd69b0c
Rename CDN entry list
onebeastchris Oct 10, 2023
c0227d3
Move loading cdn entries to separate function
onebeastchris Oct 11, 2023
b9c5bdd
Remove CDNEntry; those do not work as expected.
onebeastchris Oct 17, 2023
27c1562
remove outdated javadocs
onebeastchris Oct 17, 2023
5d06edd
Fallback system - download the pack to serve the client in case cdn f…
onebeastchris Oct 18, 2023
880de2d
Ensure GeyserUrlPackCodec.create returns a ResourcePack with the URL …
onebeastchris Oct 18, 2023
76a62ab
Check downloaded resource packs, yeet cdn naming scheme
onebeastchris Oct 18, 2023
3670914
start on proper url checking (application type/size)
onebeastchris Oct 24, 2023
498a415
Change fallback system
onebeastchris Nov 9, 2023
0004f5b
Testing: Don't require `application/zip` or `size` or weird zip forma…
onebeastchris Nov 9, 2023
cdd2aba
Merge remote-tracking branch 'upstream/master' into rp
onebeastchris Nov 9, 2023
15b8b93
We need to ensure no invalid packs end up being loaded - otherwise, c…
onebeastchris Nov 9, 2023
d4f0d8a
Re-add debug: Apparently, not just `application/zip` works....???
onebeastchris Nov 10, 2023
0ac91eb
Merge remote-tracking branch 'upstream/master' into rp
onebeastchris Dec 21, 2023
626189f
remove debug, ensure we fully check failed packs, merge master
onebeastchris Dec 21, 2023
f121299
More robust downloading/caching
onebeastchris Dec 22, 2023
303327a
oops
onebeastchris Dec 22, 2023
d2622a4
Add a registerAll method to register a collection of resource packs e…
onebeastchris Jan 15, 2024
4d99250
Merge remote-tracking branch 'upstream/master' into rp
onebeastchris Jan 25, 2024
2e776c4
Allow null content key
onebeastchris Jan 26, 2024
a4fa2e6
Merge remote-tracking branch 'upstream/master' into rp
onebeastchris Feb 16, 2024
b8fa18a
start: don't try to delete broken packs while we are still delivering…
onebeastchris Feb 19, 2024
c6511a0
update to "new" pack requirements
onebeastchris Feb 22, 2024
507a79e
Merge remote-tracking branch 'refs/remotes/upstream/master' into rp
onebeastchris Jun 19, 2024
86f6458
Code cleanup, less futures, more exceptions when needed
onebeastchris Jun 19, 2024
6053b7d
Yeet unused, update optionalpack link
onebeastchris Jun 19, 2024
2683b59
Minor cleanup
onebeastchris Jun 20, 2024
ba78dba
Add url codec creation method with no content key, remove boolean ret…
onebeastchris Jun 20, 2024
f56c182
Merge branch 'master' into rp
onebeastchris Jun 20, 2024
de54a5b
Ensure packs actually load
onebeastchris Jun 20, 2024
86f1389
Merge remote-tracking branch 'origin/rp' into rp
onebeastchris Jun 20, 2024
27659d0
Add device type to debug to be able to isolate platform specific requ…
onebeastchris Jun 24, 2024
9241957
Automatically download newer pack versions from urls, properly get ri…
onebeastchris Jun 25, 2024
3638d4d
Merge branch 'master' into rp
onebeastchris Jun 25, 2024
8b87c08
Fix typo's
onebeastchris Jun 25, 2024
b6d404e
Merge remote-tracking branch 'origin/rp' into rp
onebeastchris Jun 25, 2024
e214fbe
javadoc typos, log application type as info for now
onebeastchris Jun 27, 2024
1608746
Warn about content-type being null/not application/zip
onebeastchris Jul 1, 2024
f116382
Proper warning about version/uuid changes
onebeastchris Jul 3, 2024
5b52769
Merge branch 'master' into rp
onebeastchris Jul 3, 2024
5649574
Merge branch 'master' into rp
onebeastchris Jul 6, 2024
61f5294
Merge branch 'master' into rp
onebeastchris Jul 9, 2024
226bf38
Merge branch 'master' into rp
onebeastchris Jul 13, 2024
bddd9ac
Merge branch 'master' into rp
onebeastchris Jul 21, 2024
b43e2db
Merge branch 'master' into rp
onebeastchris Aug 2, 2024
6133487
Feature: Subpack loading
onebeastchris Aug 11, 2024
0f8d729
Also expose the settings of a resource pack, as shown on https://lear…
onebeastchris Aug 11, 2024
87829c9
minor fixes
onebeastchris Aug 11, 2024
20e4919
Merge branch 'GeyserMC:master' into rp
onebeastchris Aug 11, 2024
033d2d6
Attempt at making a proper builder for resource pack options (content…
onebeastchris Aug 12, 2024
c316d09
further optimizations, disconnects clients on odd responses
onebeastchris Aug 12, 2024
a868ced
attempt at implementing resource pack order specifying
onebeastchris Aug 12, 2024
250a9b4
Check for duplicate options, other fixes
onebeastchris Aug 12, 2024
fb4e42d
Ensure we don't modify default options
onebeastchris Aug 19, 2024
6c5a05a
Remove options taking a ResourcePack, use uuids
onebeastchris Aug 20, 2024
9279c70
Merge remote-tracking branch 'refs/remotes/origin/rp' into subpacks-r…
onebeastchris Aug 20, 2024
c13f928
Merge remote resource packs, change the default pack option system
onebeastchris Aug 20, 2024
1867c6d
one more change
onebeastchris Aug 20, 2024
139976a
revert bad changes
onebeastchris Aug 20, 2024
ca55d9f
Merge remote-tracking branch 'refs/remotes/upstream/master' into subp…
onebeastchris Aug 20, 2024
e1f86a8
merge master
onebeastchris Aug 20, 2024
3160537
Add UrlFallbackOption
onebeastchris Aug 21, 2024
1faaea7
Merge remote-tracking branch 'refs/remotes/upstream/master' into subp…
onebeastchris Aug 21, 2024
18776a8
Address reviews
onebeastchris Aug 22, 2024
19954a2
Add option#(uuid, type) method to api, add logger.debug(message, obje…
onebeastchris Aug 22, 2024
3bf5da1
smol cleanup: don't register packs if their options failed to registe…
onebeastchris Sep 18, 2024
936c716
Some more cleanup, address Konica's review comments on old PR
onebeastchris Sep 19, 2024
6d4ae96
Merge remote-tracking branch 'refs/remotes/upstream/master' into subp…
onebeastchris Sep 19, 2024
739de66
update comment
onebeastchris Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
package org.geysermc.geyser.api.event.bedrock;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.connection.GeyserConnection;
import org.geysermc.geyser.api.event.connection.ConnectionEvent;
import org.geysermc.geyser.api.pack.ResourcePack;
import org.geysermc.geyser.api.pack.option.ResourcePackOption;

import java.util.Collection;
import java.util.List;
import java.util.UUID;

Expand All @@ -42,7 +45,7 @@ public SessionLoadResourcePacksEvent(@NonNull GeyserConnection connection) {
}

/**
* Gets an unmodifiable list of {@link ResourcePack}s that will be sent to the client.
* Gets an unmodifiable list of {@link ResourcePack}'s that will be sent to the client.
*
* @return an unmodifiable list of resource packs that will be sent to the client.
*/
Expand All @@ -51,11 +54,49 @@ public SessionLoadResourcePacksEvent(@NonNull GeyserConnection connection) {
/**
* Registers a {@link ResourcePack} to be sent to the client.
*
* @param pack a resource pack that will be sent to the client
* @return true if the resource pack was added successfully,
* or false if already present
*/
public abstract boolean register(@NonNull ResourcePack pack);

/**
* Registers a {@link ResourcePack} to be sent to the client, alongside
* specific options.
*
* @param resourcePack a resource pack that will be sent to the client.
* @param options {@link ResourcePackOption}'s that specify how clients load the pack
* @return true if the resource pack was added successfully,
* or false if already present
*/
public abstract boolean register(@NonNull ResourcePack resourcePack);
public abstract boolean register(@NonNull ResourcePack resourcePack, @Nullable ResourcePackOption<?>... options);

/**
* Sets {@link ResourcePackOption}'s for a resource pack
*
* @param uuid the resource pack uuid to register the options for
* @param options the options to register for the pack
* @throws IllegalArgumentException if the pack is not registered.
*/
public abstract void registerOptions(@NonNull UUID uuid, @NonNull ResourcePackOption<?>... options);

/**
* Returns the subpack options set for a specific resource pack uuid.
* These are not modifiable.
*
* @param uuid the resource pack for which the options are set
* @return a list of {@link ResourcePackOption}
*/
public abstract Collection<ResourcePackOption<?>> options(@NonNull UUID uuid);

/**
* Returns the current option, or null, for a given ResourcePackOption type.
*
* @param uuid the resource pack for which the option type is set
* @param type the {@link ResourcePackOption.Type} of the option to query
* @throws IllegalArgumentException if the pack is not registered.
*/
public abstract @Nullable ResourcePackOption<?> option(@NonNull UUID uuid, ResourcePackOption.@NonNull Type type);

/**
* Unregisters a resource pack from being sent to the client.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.api.event.lifecycle;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.event.Event;
import org.geysermc.geyser.api.pack.ResourcePack;
import org.geysermc.geyser.api.pack.option.ResourcePackOption;

import java.util.Collection;
import java.util.List;
import java.util.UUID;

/**
* Called when {@link ResourcePack}'s are loaded within Geyser.
*/
public abstract class GeyserDefineResourcePacksEvent implements Event {

/**
* Gets an unmodifiable list of {@link ResourcePack}'s that will be sent to clients.
*
* @return an unmodifiable list of resource packs that will be sent to clients.
*/
public abstract @NonNull List<ResourcePack> resourcePacks();

/**
* Registers a {@link ResourcePack} to be sent to the client, optionally alongside
* {@link ResourcePackOption} options specifying how it will be applied on clients.
*
* @param pack a resource pack that will be sent to the client.
* @param options {@link ResourcePackOption}'s that specify how clients load the pack
* @return true if the resource pack was added successfully,
* or false if already present
*/
public abstract boolean register(@NonNull ResourcePack pack, @Nullable ResourcePackOption<?>... options);

/**
* Sets {@link ResourcePackOption}'s for a resource pack
*
* @param uuid the resource pack uuid to register the options for
* @param options the options to register for the pack
* @throws IllegalArgumentException if the pack is not registered.
*/
public abstract void registerOptions(@NonNull UUID uuid, @NonNull ResourcePackOption<?>... options);

/**
* Returns the subpack options set for a specific resource pack uuid.
* These are not modifiable.
*
* @param uuid the resource pack uuid for which the options are set
* @return a list of {@link ResourcePackOption}
*/
public abstract Collection<ResourcePackOption<?>> options(@NonNull UUID uuid);

/**
* Returns the current option, or null, for a given ResourcePackOption type.
*
* @param uuid the resource pack for which the option type is set
* @param type the {@link ResourcePackOption.Type} of the option to query
* @throws IllegalArgumentException if the pack is not registered.
*/
public abstract @Nullable ResourcePackOption<?> option(@NonNull UUID uuid, ResourcePackOption.@NonNull Type type);

/**
* Unregisters a {@link ResourcePack} from being sent to clients.
*
* @param uuid the uuid of the resource pack to remove.
* @return true whether the resource pack was removed successfully.
*/
public abstract boolean unregister(@NonNull UUID uuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
import java.util.List;

/**
* Called when resource packs are loaded within Geyser.
*
* @param resourcePacks a mutable list of the currently listed resource packs
* @deprecated Use {@link GeyserDefineResourcePacksEvent} instead.
*/
@Deprecated(forRemoval = true)
public record GeyserLoadResourcePacksEvent(@NonNull List<Path> resourcePacks) implements Event {
}
34 changes: 30 additions & 4 deletions api/src/main/java/org/geysermc/geyser/api/pack/PackCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,21 @@ public abstract class PackCodec {
public abstract long size();

/**
* Serializes the given resource pack into a byte buffer.
* Use {@link #serialize()} instead.
*/
@Deprecated
@NonNull
public SeekableByteChannel serialize(@NonNull ResourcePack resourcePack) throws IOException {
return serialize();
};

/**
* Serializes the given codec into a byte buffer.
*
* @param resourcePack the resource pack to serialize
* @return the serialized resource pack
*/
@NonNull
public abstract SeekableByteChannel serialize(@NonNull ResourcePack resourcePack) throws IOException;
public abstract SeekableByteChannel serialize() throws IOException;

/**
* Creates a new resource pack from this codec.
Expand All @@ -69,14 +77,32 @@ public abstract class PackCodec {
@NonNull
protected abstract ResourcePack create();

/**
* Creates a new resource pack builder from this codec.
*
* @return the new resource pack builder
*/
protected abstract ResourcePack.@NonNull Builder createBuilder();

/**
* Creates a new pack provider from the given path.
*
* @param path the path to create the pack provider from
* @return the new pack provider
*/
@NonNull
public static PackCodec path(@NonNull Path path) {
public static PathPackCodec path(@NonNull Path path) {
return GeyserApi.api().provider(PathPackCodec.class, path);
}

/**
* Creates a new pack provider from the given url.
*
* @param url the url to create the pack provider from
* @return the new pack provider
*/
@NonNull
public static UrlPackCodec url(@NonNull String url) {
return GeyserApi.api().provider(UrlPackCodec.class, url);
}
}
56 changes: 56 additions & 0 deletions api/src/main/java/org/geysermc/geyser/api/pack/ResourcePack.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
package org.geysermc.geyser.api.pack;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.GeyserApi;

import java.util.UUID;

/**
* Represents a resource pack sent to Bedrock clients
Expand Down Expand Up @@ -59,6 +62,14 @@ public interface ResourcePack {
@NonNull
String contentKey();

/**
* @return the resource pack uuid. Shortcut for getting the UUID from the header.
*/
@NonNull
default UUID uuid() {
return manifest().header().uuid();
}

/**
* Creates a resource pack with the given {@link PackCodec}.
*
Expand All @@ -69,4 +80,49 @@ public interface ResourcePack {
static ResourcePack create(@NonNull PackCodec codec) {
return codec.create();
}

/**
* Returns a {@link Builder} for a resource pack.
* It can be used to set a content key.
*
* @param codec the {@link PackCodec} to base the builder on
* @return a {@link Builder} to build a resource pack.
*/
static Builder builder(@NonNull PackCodec codec) {
return GeyserApi.api().provider(Builder.class, codec);
}

/**
* A builder for a resource pack. It allows providing a content key manually.
*/
interface Builder {

/**
* @return the {@link ResourcePackManifest} of this resource pack
*/
ResourcePackManifest manifest();

/**
* @return the {@link PackCodec} of this resource pack
*/
PackCodec codec();

/**
* @return the current content key, or an empty string if not set
*/
String contentKey();

/**
* Sets a content key for this resource pack.
*
* @param contentKey the content key
* @return this builder
*/
Builder contentKey(@NonNull String contentKey);

/**
* @return the resource pack
*/
ResourcePack build();
}
}
Loading