From 4ca03426b097f4923e892995f29d704d1ce7a788 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Mon, 12 Jul 2021 20:42:17 +0100 Subject: [PATCH] Expand resource pack API --- patches/api/Complete-resource-pack-API.patch | 64 +++++++++++++++++++ .../server/Complete-resource-pack-API.patch | 25 +++++++- 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/patches/api/Complete-resource-pack-API.patch b/patches/api/Complete-resource-pack-API.patch index 7e42da643e..b5fdb01635 100644 --- a/patches/api/Complete-resource-pack-API.patch +++ b/patches/api/Complete-resource-pack-API.patch @@ -55,6 +55,70 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + void setResourcePack(@NotNull String url, @NotNull String hash); + + /** ++ * 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. ++ */ ++ void setResourcePack(@NotNull String url, @NotNull String hash, boolean 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 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. ++ */ ++ void setResourcePack(@NotNull String url, @NotNull String hash, boolean required, net.kyori.adventure.text.Component resourcePackPrompt); ++ /** + * @return the most recent resource pack status received from the player, + * or null if no status has ever been received from this player. + */ diff --git a/patches/server/Complete-resource-pack-API.patch b/patches/server/Complete-resource-pack-API.patch index fda921c869..c9f335393b 100644 --- a/patches/server/Complete-resource-pack-API.patch +++ b/patches/server/Complete-resource-pack-API.patch @@ -26,6 +26,14 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/ index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +@@ -0,0 +0,0 @@ import org.bukkit.metadata.MetadataValue; + import org.bukkit.plugin.Plugin; + import org.bukkit.plugin.messaging.StandardMessenger; + import org.bukkit.scoreboard.Scoreboard; ++import org.jetbrains.annotations.NotNull; + + import net.md_5.bungee.api.chat.BaseComponent; // Spigot + @@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player { private double health = 20; private boolean scaledHealth = false; @@ -43,10 +51,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } + + @Override -+ public void setResourcePack(String url, String hash) { ++ public void setResourcePack(@NotNull String url, @NotNull String hash) { ++ this.setResourcePack(url, hash, false, null); ++ } ++ ++ @Override ++ public void setResourcePack(@NotNull String url, @NotNull String hash, boolean required) { ++ this.setResourcePack(url, hash, required, null); ++ } ++ ++ @Override ++ public void setResourcePack(@NotNull String url, @NotNull String hash, boolean required, net.kyori.adventure.text.Component resourcePackPrompt) { + Validate.notNull(url, "Resource pack URL cannot be null"); + Validate.notNull(hash, "Hash cannot be null"); -+ this.getHandle().sendTexturePack(url, hash, false, new net.minecraft.network.chat.TextComponent("")); ++ net.minecraft.network.chat.Component promptComponent = resourcePackPrompt != null ? ++ io.papermc.paper.adventure.PaperAdventure.asVanilla(resourcePackPrompt) : ++ new net.minecraft.network.chat.TextComponent(""); ++ this.getHandle().sendTexturePack(url, hash, required, promptComponent); + } + + @Override