Paper/nms-patches/EntityVillagerAbstract.patch
2019-04-28 12:35:37 +10:00

52 lines
2.1 KiB
Diff

--- a/net/minecraft/server/EntityVillagerAbstract.java
+++ b/net/minecraft/server/EntityVillagerAbstract.java
@@ -4,14 +4,29 @@
import java.util.Iterator;
import java.util.Set;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.inventory.CraftMerchant;
+import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe;
+import org.bukkit.entity.AbstractVillager;
+import org.bukkit.event.entity.VillagerAcquireTradeEvent;
+// CraftBukkit end
public abstract class EntityVillagerAbstract extends EntityAgeable implements NPC, IMerchant {
+ // CraftBukkit start
+ private CraftMerchant craftMerchant;
+
+ @Override
+ public CraftMerchant getCraftMerchant() {
+ return (craftMerchant == null) ? craftMerchant = new CraftMerchant(this) : craftMerchant;
+ }
+ // CraftBukkit end
@Nullable
private EntityHuman tradingPlayer;
@Nullable
protected MerchantRecipeList trades;
- private final InventorySubcontainer inventory = new InventorySubcontainer(8);
+ private final InventorySubcontainer inventory = new InventorySubcontainer(8, (org.bukkit.craftbukkit.entity.CraftAbstractVillager) this.getBukkitEntity()); // CraftBukkit add argument
private int bC;
public EntityVillagerAbstract(EntityTypes<? extends EntityVillagerAbstract> entitytypes, World world) {
@@ -198,7 +213,16 @@
MerchantRecipe merchantrecipe = villagertrades_imerchantrecipeoption.a(this, this.random);
if (merchantrecipe != null) {
- merchantrecipelist.add(merchantrecipe);
+ // CraftBukkit start
+ VillagerAcquireTradeEvent event = new VillagerAcquireTradeEvent((AbstractVillager) getBukkitEntity(), merchantrecipe.asBukkit());
+ // Suppress during worldgen
+ if (this.valid) {
+ Bukkit.getPluginManager().callEvent(event);
+ }
+ if (!event.isCancelled()) {
+ merchantrecipelist.add(CraftMerchantRecipe.fromBukkit(event.getRecipe()).toMinecraft());
+ }
+ // CraftBukkit end
}
}