1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
--- a/net/minecraft/world/entity/npc/AbstractVillager.java
+++ b/net/minecraft/world/entity/npc/AbstractVillager.java
@@ -34,9 +34,23 @@
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.pathfinder.BlockPathTypes;
import net.minecraft.world.phys.Vec3;
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.inventory.CraftMerchant;
+import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe;
+import org.bukkit.event.entity.VillagerAcquireTradeEvent;
+// CraftBukkit end
public abstract class AbstractVillager extends AgeableMob implements InventoryCarrier, Npc, Merchant {
+ // CraftBukkit start
+ private CraftMerchant craftMerchant;
+
+ @Override
+ public CraftMerchant getCraftMerchant() {
+ return (craftMerchant == null) ? craftMerchant = new CraftMerchant(this) : craftMerchant;
+ }
+ // CraftBukkit end
private static final EntityDataAccessor<Integer> DATA_UNHAPPY_COUNTER = SynchedEntityData.defineId(AbstractVillager.class, EntityDataSerializers.INT);
public static final int VILLAGER_SLOT_OFFSET = 300;
private static final int VILLAGER_INVENTORY_SIZE = 8;
@@ -44,7 +58,7 @@
private Player tradingPlayer;
@Nullable
protected MerchantOffers offers;
- private final SimpleContainer inventory = new SimpleContainer(8);
+ private final SimpleContainer inventory = new SimpleContainer(8, (org.bukkit.craftbukkit.entity.CraftAbstractVillager) this.getBukkitEntity()); // CraftBukkit add argument
public AbstractVillager(EntityType<? extends AbstractVillager> entitytype, Level level) {
super(entitytype, level);
@@ -252,8 +246,17 @@
while (j < i && !arraylist.isEmpty()) {
MerchantOffer merchantoffer = ((VillagerTrades.ItemListing) arraylist.remove(this.random.nextInt(arraylist.size()))).getOffer(this, this.random);
- if (merchantoffer != null) {
- merchantoffers.add(merchantoffer);
+ if (merchantrecipe != null) {
+ // CraftBukkit start
+ VillagerAcquireTradeEvent event = new VillagerAcquireTradeEvent((org.bukkit.entity.AbstractVillager) getBukkitEntity(), merchantrecipe.asBukkit());
+ // Suppress during worldgen
+ if (this.valid) {
+ Bukkit.getPluginManager().callEvent(event);
+ }
+ if (!event.isCancelled()) {
+ givenMerchantOffers.add(CraftMerchantRecipe.fromBukkit(event.getRecipe()).toMinecraft());
+ }
+ // CraftBukkit end
++j;
}
}
|