Paper/patches/server/0574-added-PlayerTradeEvent.patch
Shane Freeder aa52bf9e33
Remove "Implement-Chunk-Priority-Urgency-System-for-Chunks" (Fixes #5980)
Mojang made some changes to priorities in 1.17 and it seems that these changes
conflict with the changes made in this patch, which in some cases appears to
cause excessive rescheduling of tasks.

This, however, is not confirmed as such but seems to be the behavior that we're
seeing to cause this issue, if mojang has adopted the changes we suggested,
then a good chunk of this patch may be unneeded, but, this needs a much better
look than I'm currently able to do
2021-08-14 14:55:55 +01:00

41 lines
2.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 2 Jul 2020 16:12:10 -0700
Subject: [PATCH] added PlayerTradeEvent
diff --git a/src/main/java/net/minecraft/world/entity/npc/AbstractVillager.java b/src/main/java/net/minecraft/world/entity/npc/AbstractVillager.java
index 4a7b657265cbbc91ae85409abb3db29cfc555a2c..e59a77c80a1bbe62aaa61bd4792d21b12c895a5c 100644
--- a/src/main/java/net/minecraft/world/entity/npc/AbstractVillager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/AbstractVillager.java
@@ -140,13 +140,24 @@ public abstract class AbstractVillager extends AgeableMob implements InventoryCa
@Override
public void notifyTrade(MerchantOffer offer) {
- offer.increaseUses();
- this.ambientSoundTime = -this.getAmbientSoundInterval();
- this.rewardTradeXp(offer);
+ // Paper - moved down
+ // Paper start
if (this.tradingPlayer instanceof ServerPlayer) {
- CriteriaTriggers.TRADE.trigger((ServerPlayer) this.tradingPlayer, this, offer.getResult());
+ io.papermc.paper.event.player.PlayerTradeEvent event = new io.papermc.paper.event.player.PlayerTradeEvent(((ServerPlayer) this.tradingPlayer).getBukkitEntity(), (org.bukkit.entity.AbstractVillager) this.getBukkitEntity(), offer.asBukkit(), true, true);
+ event.callEvent();
+ if (!event.isCancelled()) {
+ MerchantOffer recipe = CraftMerchantRecipe.fromBukkit(event.getTrade()).toMinecraft();
+ if (event.willIncreaseTradeUses()) recipe.increaseUses();
+ this.ambientSoundTime = -this.getAmbientSoundInterval();
+ if (event.isRewardingExp()) this.rewardTradeXp(recipe);
+ CriteriaTriggers.TRADE.trigger((ServerPlayer) this.tradingPlayer, this, recipe.getResult());
+ }
+ } else {
+ offer.increaseUses();
+ this.ambientSoundTime = -getAmbientSoundInterval();
+ this.rewardTradeXp(offer);
}
-
+ // Paper end
}
protected abstract void rewardTradeXp(MerchantOffer offer);