PaperMC/patches/server-remapped/added-PlayerTradeEvent.patch
MiniDigger | Martin 95d25d98e8 Move patches around
2021-06-11 14:02:28 +02:00

75 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -0,0 +0,0 @@ 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;
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/npc/AbstractVillager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/AbstractVillager.java
@@ -0,0 +0,0 @@ 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 {
@@ -0,0 +0,0 @@ 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() {