From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Thu, 2 Jul 2020 16:12:10 -0700 Subject: [PATCH] added PlayerTradeEvent diff --git a/src/main/java/net/minecraft/world/entity/EntityInsentient.java b/src/main/java/net/minecraft/world/entity/EntityInsentient.java index 54d72f211b964a42009eb4d07060a35e3b91017a..7e608cc9ff4a03a6b1eac5c74c072ac5febc38c3 100644 --- a/src/main/java/net/minecraft/world/entity/EntityInsentient.java +++ b/src/main/java/net/minecraft/world/entity/EntityInsentient.java @@ -90,7 +90,7 @@ import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason; public abstract class EntityInsentient extends EntityLiving { private static final DataWatcherObject b = DataWatcher.a(EntityInsentient.class, DataWatcherRegistry.a); - public int e; + public int e;public void setAmbientSoundTime(int time) { this.e = time; } // Paper - OBFHELPER protected int f; protected ControllerLook lookController; protected ControllerMove moveController; @@ -292,6 +292,7 @@ public abstract class EntityInsentient extends EntityLiving { this.datawatcher.register(EntityInsentient.b, (byte) 0); } + public int getAmbientSoundInterval() { return D(); } // Paper - OBFHELPER public int D() { return 80; } diff --git a/src/main/java/net/minecraft/world/entity/npc/EntityVillagerAbstract.java b/src/main/java/net/minecraft/world/entity/npc/EntityVillagerAbstract.java index 10067731e6289211cb11b2b368527a1c45603314..49821f0f26864c35be84a4a4288857a04668fbba 100644 --- a/src/main/java/net/minecraft/world/entity/npc/EntityVillagerAbstract.java +++ b/src/main/java/net/minecraft/world/entity/npc/EntityVillagerAbstract.java @@ -39,6 +39,9 @@ import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe; import org.bukkit.entity.AbstractVillager; import org.bukkit.event.entity.VillagerAcquireTradeEvent; // CraftBukkit end +// Paper start +import io.papermc.paper.event.player.PlayerTradeEvent; +// Paper end public abstract class EntityVillagerAbstract extends EntityAgeable implements NPC, IMerchant { @@ -135,16 +138,27 @@ public abstract class EntityVillagerAbstract extends EntityAgeable implements NP @Override public void a(MerchantRecipe merchantrecipe) { - merchantrecipe.increaseUses(); - this.e = -this.D(); - this.b(merchantrecipe); + // Paper - moved down + // Paper start if (this.tradingPlayer instanceof EntityPlayer) { - CriterionTriggers.s.a((EntityPlayer) this.tradingPlayer, this, merchantrecipe.getSellingItem()); + PlayerTradeEvent event = new PlayerTradeEvent(((EntityPlayer) this.tradingPlayer).getBukkitEntity(), (AbstractVillager) this.getBukkitEntity(), merchantrecipe.asBukkit(), true, true); + event.callEvent(); + if (!event.isCancelled()) { + MerchantRecipe recipe = CraftMerchantRecipe.fromBukkit(event.getTrade()).toMinecraft(); + if (event.willIncreaseTradeUses()) recipe.increaseUses(); + this.setAmbientSoundTime(-getAmbientSoundInterval()); + if (event.isRewardingExp()) this.rewardTradeXp(recipe); + CriterionTriggers.s.a((EntityPlayer) this.tradingPlayer, this, recipe.getSellingItem()); + } + } else { + merchantrecipe.increaseUses(); + this.setAmbientSoundTime(-getAmbientSoundInterval()); + this.rewardTradeXp(merchantrecipe); } - + // Paper end } - protected abstract void b(MerchantRecipe merchantrecipe); + protected abstract void b(MerchantRecipe merchantrecipe); public void rewardTradeXp(MerchantRecipe merchantrecipe) { this.b(merchantrecipe); } // Paper - OBFHELPER @Override public boolean isRegularVillager() {