Paper/Remapped-Spigot-Server-Patches/0619-added-PlayerTradeEvent.patch
2021-06-11 13:56:17 +02:00

76 lines
3.8 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/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 40ab66f888f30a5506e3aa96a4b32485452e8978..87dd6c012bf1ca6a1e8df44dc0957c4c67d02adc 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -91,7 +91,7 @@ import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason;
public abstract class Mob extends LivingEntity {
private static final EntityDataAccessor<Byte> DATA_MOB_FLAGS_ID = SynchedEntityData.defineId(Mob.class, EntityDataSerializers.BYTE);
- public int ambientSoundTime;
+ public int ambientSoundTime;public void setAmbientSoundTime(int time) { this.ambientSoundTime = time; } // Paper - OBFHELPER
protected int xpReward;
protected LookControl lookControl;
protected MoveControl moveControl;
@@ -293,6 +293,7 @@ public abstract class Mob extends LivingEntity {
this.entityData.define(Mob.DATA_MOB_FLAGS_ID, (byte) 0);
}
+ public int getAmbientSoundInterval() { return getAmbientSoundInterval(); } // Paper - OBFHELPER
public int getAmbientSoundInterval() {
return 80;
}
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 335000713279b7964c5172937483678c671bfed1..d31b773f8aff09c9f214662aa3aa0c904119e12c 100644
--- a/src/main/java/net/minecraft/world/entity/npc/AbstractVillager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/AbstractVillager.java
@@ -37,6 +37,9 @@ import org.bukkit.craftbukkit.inventory.CraftMerchant;
import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe;
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
// CraftBukkit end
+// Paper start
+import io.papermc.paper.event.player.PlayerTradeEvent;
+// Paper end
public abstract class AbstractVillager extends AgableMob implements Npc, Merchant {
@@ -133,16 +136,27 @@ public abstract class AbstractVillager extends AgableMob implements Npc, Merchan
@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());
+ PlayerTradeEvent event = new 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.setAmbientSoundTime(-getAmbientSoundInterval());
+ if (event.isRewardingExp()) this.rewardTradeXp(recipe);
+ CriteriaTriggers.TRADE.trigger((ServerPlayer) this.tradingPlayer, this, recipe.getResult());
+ }
+ } else {
+ offer.increaseUses();
+ this.setAmbientSoundTime(-getAmbientSoundInterval());
+ this.rewardTradeXp(offer);
}
-
+ // Paper end
}
- protected abstract void rewardTradeXp(MerchantOffer offer);
+ protected abstract void rewardTradeXp(MerchantOffer offer); public void rewardTradeXp(MerchantOffer merchantrecipe) { this.rewardTradeXp(merchantrecipe); } // Paper - OBFHELPER
@Override
public boolean showProgressBar() {