From ecfabc25c73a1e8fcd969e27252da292b334bd49 Mon Sep 17 00:00:00 2001 From: Jedediah Smith Date: Sat, 4 Apr 2015 22:59:54 -0400 Subject: [PATCH] Complete resource pack API --- .../main/java/org/bukkit/entity/Player.java | 174 ++++++++++++++++++ .../player/PlayerResourcePackStatusEvent.java | 10 + 2 files changed, 184 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/entity/Player.java b/paper-api/src/main/java/org/bukkit/entity/Player.java index 01fcff92da..cb758b5907 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Player.java +++ b/paper-api/src/main/java/org/bukkit/entity/Player.java @@ -2252,6 +2252,180 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM void setResourcePack(@NotNull UUID uuid, @NotNull String url, byte @Nullable [] hash, net.kyori.adventure.text.@Nullable Component prompt, boolean force); // Paper end + // Paper start - more resource pack API + /** + * Request that the player's client download and switch resource packs. + *

+ * The player's client will download the new resource pack asynchronously + * in the background, and will automatically switch to it once the + * download is complete. If the client has downloaded and cached the same + * resource pack in the past, it will perform a quick timestamp check + * over the network to determine if the resource pack has changed and + * needs to be downloaded again. When this request is sent for the very + * first time from a given server, the client will first display a + * confirmation GUI to the player before proceeding with the download. + *

+ * Notes: + *

+ * + * @param url The URL from which the client will download the resource + * pack. The string must contain only US-ASCII characters and should + * be encoded as per RFC 1738. + * @param hash A 40 character hexadecimal and lowercase SHA-1 digest of + * the resource pack file. + * @throws IllegalArgumentException Thrown if the URL is null. + * @throws IllegalArgumentException Thrown if the URL is too long. The + * length restriction is an implementation specific arbitrary value. + */ + default void setResourcePack(final @NotNull String url, final @NotNull String hash) { + this.setResourcePack(url, hash, false); + } + + /** + * Request that the player's client download and switch resource packs. + *

+ * The player's client will download the new resource pack asynchronously + * in the background, and will automatically switch to it once the + * download is complete. If the client has downloaded and cached the same + * resource pack in the past, it will perform a quick timestamp check + * over the network to determine if the resource pack has changed and + * needs to be downloaded again. When this request is sent for the very + * first time from a given server, the client will first display a + * confirmation GUI to the player before proceeding with the download. + *

+ * Notes: + *

+ * + * @param url The URL from which the client will download the resource + * pack. The string must contain only US-ASCII characters and should + * be encoded as per RFC 1738. + * @param hash A 40 character hexadecimal and lowercase SHA-1 digest of + * the resource pack file. + * @param required Marks if the resource pack should be required by the client + * @throws IllegalArgumentException Thrown if the URL is null. + * @throws IllegalArgumentException Thrown if the URL is too long. The + * length restriction is an implementation specific arbitrary value. + */ + default void setResourcePack(final @NotNull String url, final @NotNull String hash, final boolean required) { + this.setResourcePack(url, hash, required, null); + } + + /** + * Request that the player's client download and switch resource packs. + *

+ * The player's client will download the new resource pack asynchronously + * in the background, and will automatically switch to it once the + * download is complete. If the client has downloaded and cached the same + * resource pack in the past, it will perform a quick timestamp check + * over the network to determine if the resource pack has changed and + * needs to be downloaded again. When this request is sent for the very + * first time from a given server, the client will first display a + * confirmation GUI to the player before proceeding with the download. + *

+ * Notes: + *

+ * + * @param url The URL from which the client will download the resource + * pack. The string must contain only US-ASCII characters and should + * be encoded as per RFC 1738. + * @param hash A 40 character hexadecimal and lowercase SHA-1 digest of + * the resource pack file. + * @param required Marks if the resource pack should be required by the client + * @param resourcePackPrompt A Prompt to be displayed in the client request + * @throws IllegalArgumentException Thrown if the URL is null. + * @throws IllegalArgumentException Thrown if the URL is too long. The + * length restriction is an implementation specific arbitrary value. + */ + default void setResourcePack(final @NotNull String url, final @NotNull String hash, final boolean required, final net.kyori.adventure.text.@Nullable Component resourcePackPrompt) { + this.setResourcePack(UUID.nameUUIDFromBytes(url.getBytes(java.nio.charset.StandardCharsets.UTF_8)), url, hash, resourcePackPrompt, required); + } + + /** + * Request that the player's client download and switch resource packs. + *

+ * The player's client will download the new resource pack asynchronously + * in the background, and will automatically switch to it once the + * download is complete. If the client has downloaded and cached the same + * resource pack in the past, it will perform a quick timestamp check + * over the network to determine if the resource pack has changed and + * needs to be downloaded again. When this request is sent for the very + * first time from a given server, the client will first display a + * confirmation GUI to the player before proceeding with the download. + *

+ * Notes: + *

+ * + * @param uuid Unique resource pack ID. + * @param url The URL from which the client will download the resource + * pack. The string must contain only US-ASCII characters and should + * be encoded as per RFC 1738. + * @param hash A 40 character hexadecimal and lowercase SHA-1 digest of + * the resource pack file. + * @param resourcePackPrompt A Prompt to be displayed in the client request + * @param required Marks if the resource pack should be required by the client + * @throws IllegalArgumentException Thrown if the URL is null. + * @throws IllegalArgumentException Thrown if the URL is too long. The + * length restriction is an implementation specific arbitrary value. + */ + default void setResourcePack(final @NotNull UUID uuid, final @NotNull String url, final @NotNull String hash, final net.kyori.adventure.text.@Nullable Component resourcePackPrompt, final boolean required) { + this.sendResourcePacks(net.kyori.adventure.resource.ResourcePackRequest.resourcePackRequest() + .required(required) + .replace(true) + .prompt(resourcePackPrompt) + .packs(net.kyori.adventure.resource.ResourcePackInfo.resourcePackInfo(uuid, java.net.URI.create(url), hash)) + ); + } + + /** + * Gets the most recent resource pack status from the player. + * + * @return the most recent status or null + */ + org.bukkit.event.player.PlayerResourcePackStatusEvent.@Nullable Status getResourcePackStatus(); + + /** + * Gets the most recent pack hash from the player. + * + * @return the most recent hash or null + * @deprecated This is no longer sent from the client and will always be null + */ + @Deprecated(forRemoval = true, since = "1.13.2") + @org.jetbrains.annotations.Contract("-> null") + default @Nullable String getResourcePackHash() { + return null; + } + + /** + * Gets if the last resource pack status from the player + * was {@link org.bukkit.event.player.PlayerResourcePackStatusEvent.Status#SUCCESSFULLY_LOADED}. + * + * @return true if last status was successfully loaded + */ + default boolean hasResourcePack() { + return this.getResourcePackStatus() == org.bukkit.event.player.PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED; + } + // Paper end - more resource pack API + /** * Request that the player's client download and include another resource pack. *

diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerResourcePackStatusEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerResourcePackStatusEvent.java index e2c4f9a045..e4c32b21ab 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerResourcePackStatusEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerResourcePackStatusEvent.java @@ -21,6 +21,16 @@ public class PlayerResourcePackStatusEvent extends PlayerEvent { this.status = resourcePackStatus; } + // Paper start - add hash (not used anymore) + /** + * @deprecated Hash does not seem to ever be set + */ + @Deprecated(forRemoval = true) + public String getHash() { + return null; + } + // Paper end + /** * Gets the unique ID of this pack. *