PaperMC/patches/api/0417-API-for-updating-recipes-on-clients.patch
Nassim Jahnke 71c84c8132
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD

CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor

Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00

169 lines
6.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sat, 21 Aug 2021 17:25:54 -0700
Subject: [PATCH] API for updating recipes on clients
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 63a4f5cc3f2e8fbff47543de76e42a79996dbe81..b82260cdee74a82b78c103467f7e2888ba4d06c1 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -990,6 +990,26 @@ public final class Bukkit {
server.reloadData();
}
+ // Paper start - update reloadable data
+ /**
+ * Updates all advancement, tag, and recipe data for all connected clients.
+ * Useful for updating clients to new advancements/recipes/tags.
+ * @see #updateRecipes()
+ */
+ public static void updateResources() {
+ server.updateResources();
+ }
+
+ /**
+ * Updates recipe data and the recipe book for all connected clients. Useful for
+ * updating clients to new recipes.
+ * @see #updateResources()
+ */
+ public static void updateRecipes() {
+ server.updateRecipes();
+ }
+ // Paper end - update reloadable data
+
/**
* Returns the primary logger associated with this server instance.
*
@@ -1044,6 +1064,20 @@ public final class Bukkit {
return server.addRecipe(recipe);
}
+ // Paper start - method to send recipes immediately
+ /**
+ * Adds a recipe to the crafting manager.
+ *
+ * @param recipe the recipe to add
+ * @param resendRecipes true to update the client with the full set of recipes
+ * @return true if the recipe was added, false if it wasn't for some reason
+ */
+ @Contract("null, _ -> false")
+ public static boolean addRecipe(@Nullable Recipe recipe, boolean resendRecipes) {
+ return server.addRecipe(recipe, resendRecipes);
+ }
+ // Paper end - method to send recipes immediately
+
/**
* Get a list of all recipes for a given item. The stack size is ignored
* in comparisons. If the durability is -1, it will match any data value.
@@ -1235,6 +1269,24 @@ public final class Bukkit {
return server.removeRecipe(key);
}
+ // Paper start - method to resend recipes
+ /**
+ * Remove a recipe from the server.
+ * <p>
+ * <b>Note that removing a recipe may cause permanent loss of data
+ * associated with that recipe (eg whether it has been discovered by
+ * players).</b>
+ *
+ * @param key NamespacedKey of recipe to remove.
+ * @param resendRecipes true to update all clients on the new recipe list.
+ * Will only update if a recipe was actually removed
+ * @return True if recipe was removed
+ */
+ public static boolean removeRecipe(@NotNull NamespacedKey key, boolean resendRecipes) {
+ return server.removeRecipe(key, resendRecipes);
+ }
+ // Paper end - method to resend recipes
+
/**
* Gets a list of command aliases defined in the server properties.
*
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index f819de247080d58803a2851a4cab28d2b3765495..f18f5db804053e072134508ef38252391895549a 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -836,6 +836,22 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
public void reloadData();
+ // Paper start - update reloadable data
+ /**
+ * Updates all advancement, tag, and recipe data to all connected clients.
+ * Useful for updating clients to new advancements/recipes/tags.
+ * @see #updateRecipes()
+ */
+ void updateResources();
+
+ /**
+ * Updates recipe data and the recipe book to each player. Useful for
+ * updating clients to new recipes.
+ * @see #updateResources()
+ */
+ void updateRecipes();
+ // Paper end - update reloadable data
+
/**
* Returns the primary logger associated with this server instance.
*
@@ -871,15 +887,34 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
public boolean dispatchCommand(@NotNull CommandSender sender, @NotNull String commandLine) throws CommandException;
/**
- * Adds a recipe to the crafting manager.
+ * Adds a recipe to the crafting manager. Recipes added with
+ * this method won't be sent to the client automatically. Use
+ * {@link #updateRecipes()} or {@link #updateResources()} to
+ * update clients to new recipes added.
+ * <p>
+ * Player's still have to discover recipes via {@link Player#discoverRecipe(NamespacedKey)}
+ * before seeing them in their recipe book.
*
* @param recipe the recipe to add
* @return true if the recipe was added, false if it wasn't for some
* reason
+ * @see #addRecipe(Recipe, boolean)
*/
@Contract("null -> false")
public boolean addRecipe(@Nullable Recipe recipe);
+ // Paper start - method to send recipes immediately
+ /**
+ * Adds a recipe to the crafting manager.
+ *
+ * @param recipe the recipe to add
+ * @param resendRecipes true to update the client with the full set of recipes
+ * @return true if the recipe was added, false if it wasn't for some reason
+ */
+ @Contract("null, _ -> false")
+ boolean addRecipe(@Nullable Recipe recipe, boolean resendRecipes);
+ // Paper end - method to send recipes immediately
+
/**
* Get a list of all recipes for a given item. The stack size is ignored
* in comparisons. If the durability is -1, it will match any data value.
@@ -1048,6 +1083,22 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
public boolean removeRecipe(@NotNull NamespacedKey key);
+ // Paper start - method to resend recipes
+ /**
+ * Remove a recipe from the server.
+ * <p>
+ * <b>Note that removing a recipe may cause permanent loss of data
+ * associated with that recipe (eg whether it has been discovered by
+ * players).</b>
+ *
+ * @param key NamespacedKey of recipe to remove.
+ * @param resendRecipes true to update all clients on the new recipe list.
+ * Will only update if a recipe was actually removed
+ * @return True if recipe was removed
+ */
+ boolean removeRecipe(@NotNull NamespacedKey key, boolean resendRecipes);
+ // Paper end - method to resend recipes
+
/**
* Gets a list of command aliases defined in the server properties.
*