From bd7c1d88b1262eaba4a37a96774332e8aec4608c Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 10 Feb 2021 15:06:34 -0800 Subject: [PATCH] Merchant#getRecipes should return an immutable list (#5183) This fixes a confusing issue where doing 'merchant.setRecipes(merchant.getRecipes());' would clear the merchants recipes, as the implementation of getRecipes is guavas Lists.transform wrapped in Collections.unmodifiableList, and the implementation of setRecipes clears the backing list before adding the elements of the provided list to the backing list. The javadoc for the getRecipes method says 'an immutable list of trades', so this patch makes the javadoc correct. --- ...ipes-should-return-an-immutable-list.patch | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Spigot-Server-Patches/0674-Merchant-getRecipes-should-return-an-immutable-list.patch diff --git a/Spigot-Server-Patches/0674-Merchant-getRecipes-should-return-an-immutable-list.patch b/Spigot-Server-Patches/0674-Merchant-getRecipes-should-return-an-immutable-list.patch new file mode 100644 index 0000000000..396542d64a --- /dev/null +++ b/Spigot-Server-Patches/0674-Merchant-getRecipes-should-return-an-immutable-list.patch @@ -0,0 +1,19 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: jmp +Date: Wed, 10 Feb 2021 14:53:36 -0800 +Subject: [PATCH] Merchant#getRecipes should return an immutable list + + +diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchant.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchant.java +index 50bc720d4268804f53b204091c9e8f0c17d8dd23..7159d73ac5c3ef881d9635d64e82847ac3731e22 100644 +--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchant.java ++++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchant.java +@@ -25,7 +25,7 @@ public class CraftMerchant implements Merchant { + + @Override + public List getRecipes() { +- return Collections.unmodifiableList(Lists.transform(merchant.getOffers(), new Function() { ++ return com.google.common.collect.ImmutableList.copyOf(Lists.transform(merchant.getOffers(), new Function() { // Paper - javadoc says 'an immutable list of trades' - not 'an unmodifiable view of a list of trades'. fixes issue with setRecipes(getRecipes()) + @Override + public MerchantRecipe apply(net.minecraft.server.MerchantRecipe recipe) { + return recipe.asBukkit();