From 0000000000000000000000000000000000000000 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 diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java index f9a39faf656af1cd5e16513bab21afa6ab972556..1ec40d90b697af5759c5cd0bc8c2c3e76f8491eb 100644 --- a/src/main/java/org/bukkit/entity/Player.java +++ b/src/main/java/org/bukkit/entity/Player.java @@ -2100,6 +2100,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) + @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 remove a resource pack sent by the * server. diff --git a/src/main/java/org/bukkit/event/player/PlayerResourcePackStatusEvent.java b/src/main/java/org/bukkit/event/player/PlayerResourcePackStatusEvent.java index e2c4f9a0456cef345772d57b4d9c6e7d9598dd53..e4c32b21ab013703a6a1b07a1ad564d914ebe83f 100644 --- a/src/main/java/org/bukkit/event/player/PlayerResourcePackStatusEvent.java +++ b/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. *