From e9b09df87cba85ef719ff280047ecae476188386 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 25 Dec 2021 10:14:12 +1100 Subject: [PATCH] SPIGOT-5766: Updates related to the villager trading changes introduced in MC 1.14. * The VillagerReplenishTradeEvent is now called whenever a villager restocks one of its trades. Previously, it was called in some (but not all) cases in which a villager updates the special price values of its merchant recipes. * VillagerReplenishTradeEvent#get/setBonus have been deprecated and #setBonus has no effect anymore. The way villagers restock their trades has changed in MC 1.14: Instead of adjusting the max uses of their trades, they reset their uses to 0. #getBonus returns the value of MerchantRecipe#getUses now. * Updated various outdated and inaccurate javadoc in MerchantRecipe. By: blablubbabc --- .../entity/VillagerReplenishTradeEvent.java | 27 ++++++----- .../org/bukkit/inventory/MerchantRecipe.java | 45 +++++++------------ 2 files changed, 30 insertions(+), 42 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/event/entity/VillagerReplenishTradeEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/VillagerReplenishTradeEvent.java index 36bfe05f2a..c6d849af00 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/VillagerReplenishTradeEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/VillagerReplenishTradeEvent.java @@ -1,16 +1,18 @@ package org.bukkit.event.entity; import org.bukkit.entity.AbstractVillager; +import org.bukkit.entity.Villager; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; import org.bukkit.inventory.MerchantRecipe; import org.jetbrains.annotations.NotNull; /** - * Called when a villager's trade's maximum uses is increased, due to a player's - * trade. - * - * @see MerchantRecipe#getMaxUses() + * Called when a {@link Villager} is about to restock one of its trades. + *

+ * If this event passes, the villager will reset the + * {@link MerchantRecipe#getUses() uses} of the affected {@link #getRecipe() + * MerchantRecipe} to 0. */ public class VillagerReplenishTradeEvent extends EntityEvent implements Cancellable { @@ -18,12 +20,10 @@ public class VillagerReplenishTradeEvent extends EntityEvent implements Cancella private boolean cancelled; // private MerchantRecipe recipe; - private int bonus; - public VillagerReplenishTradeEvent(@NotNull AbstractVillager what, @NotNull MerchantRecipe recipe, int bonus) { + public VillagerReplenishTradeEvent(@NotNull AbstractVillager what, @NotNull MerchantRecipe recipe) { super(what); this.recipe = recipe; - this.bonus = bonus; } /** @@ -46,23 +46,26 @@ public class VillagerReplenishTradeEvent extends EntityEvent implements Cancella } /** - * Get the bonus uses added. The maximum uses of the recipe will be - * increased by this number. + * Get the bonus uses added. * * @return the extra uses added + * @deprecated MC 1.14 has changed how villagers restock their trades. Use + * {@link MerchantRecipe#getUses()}. */ + @Deprecated public int getBonus() { - return bonus; + return recipe.getUses(); } /** * Set the bonus uses added. * * @param bonus the extra uses added - * @see VillagerReplenishTradeEvent#getBonus() + * @deprecated MC 1.14 has changed how villagers restock their trades. This + * has no effect anymore. */ + @Deprecated public void setBonus(int bonus) { - this.bonus = bonus; } @Override diff --git a/paper-api/src/main/java/org/bukkit/inventory/MerchantRecipe.java b/paper-api/src/main/java/org/bukkit/inventory/MerchantRecipe.java index 620a4df816..d33b66facf 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/MerchantRecipe.java +++ b/paper-api/src/main/java/org/bukkit/inventory/MerchantRecipe.java @@ -4,7 +4,7 @@ import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.List; import org.bukkit.Material; -import org.bukkit.event.entity.VillagerReplenishTradeEvent; +import org.bukkit.entity.Villager; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.NumberConversions; import org.jetbrains.annotations.NotNull; @@ -12,16 +12,16 @@ import org.jetbrains.annotations.Nullable; /** * Represents a merchant's trade. - * + *

* Trades can take one or two ingredients, and provide one result. The * ingredients' ItemStack amounts are respected in the trade. - *
- * A trade has a limited number of uses, after which the trade can no longer be - * used, unless the player uses a different trade, which will cause its maximum - * uses to increase. - *
+ *

+ * A trade has a maximum number of uses. A {@link Villager} may periodically + * replenish its trades by resetting the {@link #getUses uses} of its merchant + * recipes to 0, allowing them to be used again. + *

* A trade may or may not reward experience for being completed. - *
+ *

* During trades, the {@link MerchantRecipe} dynamically adjusts the amount of * its first ingredient based on the following criteria: *