From 1105e102842d30468250641dc1cf445f1dc0dfb9 Mon Sep 17 00:00:00 2001 From: William Blake Galbreath Date: Tue, 17 Aug 2021 17:45:55 -0500 Subject: [PATCH] Add force and prompt parameters to resource pack api --- ...ompt-parameters-to-resource-pack-api.patch | 100 ++++++++++++++++++ ...ompt-parameters-to-resource-pack-api.patch | 44 ++++++++ 2 files changed, 144 insertions(+) create mode 100644 patches/api/0047-Add-force-and-prompt-parameters-to-resource-pack-api.patch create mode 100644 patches/server/0248-Add-force-and-prompt-parameters-to-resource-pack-api.patch diff --git a/patches/api/0047-Add-force-and-prompt-parameters-to-resource-pack-api.patch b/patches/api/0047-Add-force-and-prompt-parameters-to-resource-pack-api.patch new file mode 100644 index 000000000..ecfd28bbd --- /dev/null +++ b/patches/api/0047-Add-force-and-prompt-parameters-to-resource-pack-api.patch @@ -0,0 +1,100 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Blake Galbreath +Date: Tue, 17 Aug 2021 17:39:14 -0500 +Subject: [PATCH] Add force and prompt parameters to resource pack api + + +diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java +index 8f132156ca772c651648de5333152e1b50adecb8..42c9911885b1323032cc14c737c562695692744c 100644 +--- a/src/main/java/org/bukkit/entity/Player.java ++++ b/src/main/java/org/bukkit/entity/Player.java +@@ -1490,6 +1490,89 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM + */ + public void setResourcePack(@NotNull String url, @NotNull byte[] hash); + ++ // Purpur start ++ ++ /** ++ * 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 a ++ * resource pack with the same hash in the past it will not download but ++ * directly apply the cached pack. 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 The sha1 hash sum of the resource pack file which is used ++ * to apply a cached version of the pack directly without downloading ++ * if it is available. Hast to be 20 bytes long! ++ * @param force If true, players will get kicked from the server if the ++ * resource pack is denied. ++ * @param prompt The server message added to the resource pack prompt. ++ * @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. ++ * @throws IllegalArgumentException Thrown if the hash is null. ++ * @throws IllegalArgumentException Thrown if the hash is not 20 bytes ++ * long. ++ */ ++ void setResourcePack(@NotNull String url, @NotNull byte[] hash, boolean force, String prompt); ++ ++ /** ++ * 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 a ++ * resource pack with the same hash in the past it will not download but ++ * directly apply the cached pack. 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 The sha1 hash sum of the resource pack file which is used ++ * to apply a cached version of the pack directly without downloading ++ * if it is available. Hast to be 20 bytes long! ++ * @param force If true, players will get kicked from the server if the ++ * resource pack is denied. ++ * @param prompt The server message added to the resource pack prompt. ++ * @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. ++ * @throws IllegalArgumentException Thrown if the hash is null. ++ * @throws IllegalArgumentException Thrown if the hash is not 20 bytes ++ * long. ++ */ ++ void setResourcePack(String url, byte[] hash, boolean force, net.kyori.adventure.text.Component prompt); ++ // Purpur end ++ + /** + * Gets the Scoreboard displayed to this player + * diff --git a/patches/server/0248-Add-force-and-prompt-parameters-to-resource-pack-api.patch b/patches/server/0248-Add-force-and-prompt-parameters-to-resource-pack-api.patch new file mode 100644 index 000000000..d74454433 --- /dev/null +++ b/patches/server/0248-Add-force-and-prompt-parameters-to-resource-pack-api.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Blake Galbreath +Date: Tue, 17 Aug 2021 17:39:21 -0500 +Subject: [PATCH] Add force and prompt parameters to resource pack api + + +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +index 98751b195e5bea9ef89e1432fba54d6823036818..c0e14be91996628be0e69ae0ec5dd0b785b9e11f 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +@@ -25,6 +25,8 @@ import java.util.WeakHashMap; + import java.util.logging.Level; + import java.util.logging.Logger; + import javax.annotation.Nullable; ++ ++import io.papermc.paper.adventure.PaperAdventure; + import net.minecraft.Util; + import net.minecraft.advancements.AdvancementProgress; + import net.minecraft.core.BlockPos; +@@ -1750,11 +1752,23 @@ public class CraftPlayer extends CraftHumanEntity implements Player { + + @Override + public void setResourcePack(String url, byte[] hash) { ++ // Purpur start ++ this.setResourcePack(url, hash, false, (net.kyori.adventure.text.Component) null); ++ } ++ ++ @Override ++ public void setResourcePack(String url, byte[] hash, boolean force, String prompt) { ++ this.setResourcePack(url, hash, force, io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(prompt)); ++ } ++ ++ @Override ++ public void setResourcePack(String url, byte[] hash, boolean force, net.kyori.adventure.text.Component prompt) { ++ // Purpur end + Validate.notNull(url, "Resource pack URL cannot be null"); + Validate.notNull(hash, "Resource pack hash cannot be null"); + Validate.isTrue(hash.length == 20, "Resource pack hash should be 20 bytes long but was " + hash.length); + +- this.getHandle().sendTexturePack(url, BaseEncoding.base16().lowerCase().encode(hash), false, null); ++ this.getHandle().sendTexturePack(url, BaseEncoding.base16().lowerCase().encode(hash), force, prompt == null ? null : io.papermc.paper.adventure.PaperAdventure.asVanilla(prompt)); // Purpur + } + + public void addChannel(String channel) {