2020-07-03 01:14:36 +02:00
|
|
|
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/server/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java
|
2021-02-06 01:00:18 +01:00
|
|
|
index 73ceb0f14610fe1d4d55542dad957b1fdf9f8e04..eb5c3a1f0d9ff665631caf5bf579e83d1ed25e4f 100644
|
2020-07-03 01:14:36 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
|
|
|
|
@@ -25,7 +25,7 @@ import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason;
|
|
|
|
public abstract class EntityInsentient extends EntityLiving {
|
|
|
|
|
|
|
|
private static final DataWatcherObject<Byte> 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;
|
|
|
|
@@ -227,6 +227,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/server/EntityVillagerAbstract.java b/src/main/java/net/minecraft/server/EntityVillagerAbstract.java
|
2021-03-09 00:12:31 +01:00
|
|
|
index 4620c36d568da12092a2f7cb067cbf7fd20bee94..e0cc45a7494cd6f06169b64ee8ffc16aa1932f8f 100644
|
2020-07-03 01:14:36 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityVillagerAbstract.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityVillagerAbstract.java
|
2021-03-09 00:12:31 +01:00
|
|
|
@@ -12,6 +12,9 @@ import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe;
|
2020-07-03 01:14:36 +02:00
|
|
|
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 {
|
|
|
|
|
2021-03-09 00:12:31 +01:00
|
|
|
@@ -108,16 +111,27 @@ public abstract class EntityVillagerAbstract extends EntityAgeable implements NP
|
2020-07-03 01:14:36 +02:00
|
|
|
|
|
|
|
@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() {
|