Add PlayerTradeEvent and PlayerPurchaseEvent

Co-authored-by: Alexander <protonull@protonmail.com>
This commit is contained in:
Jake Potrebic
2020-07-02 16:12:10 -07:00
parent 46c2fbfb74
commit 597ce940a4
6 changed files with 206 additions and 7 deletions

View File

@@ -76,10 +76,25 @@ public class CraftMerchantCustom implements CraftMerchant {
return this.trades;
}
// Paper start - Add PlayerTradeEvent and PlayerPurchaseEvent
@Override
public void processTrade(MerchantOffer merchantRecipe, @javax.annotation.Nullable io.papermc.paper.event.player.PlayerPurchaseEvent event) { // The MerchantRecipe passed in here is the one set by the PlayerPurchaseEvent
/** Based on {@link net.minecraft.world.entity.npc.AbstractVillager#processTrade(MerchantOffer, io.papermc.paper.event.player.PlayerPurchaseEvent)} */
if (getTradingPlayer() instanceof net.minecraft.server.level.ServerPlayer) {
if (event == null || event.willIncreaseTradeUses()) {
merchantRecipe.increaseUses();
}
if (event == null || event.isRewardingExp()) {
this.tradingPlayer.level().addFreshEntity(new net.minecraft.world.entity.ExperienceOrb(this.tradingPlayer.level(), this.tradingPlayer.getX(), this.tradingPlayer.getY(), this.tradingPlayer.getZ(), merchantRecipe.getXp(), org.bukkit.entity.ExperienceOrb.SpawnReason.VILLAGER_TRADE, this.tradingPlayer, null));
}
}
this.notifyTrade(merchantRecipe);
}
// Paper end - Add PlayerTradeEvent and PlayerPurchaseEvent
@Override
public void notifyTrade(MerchantOffer offer) {
// increase recipe's uses
offer.increaseUses();
// offer.increaseUses(); // Paper - Add PlayerTradeEvent and PlayerPurchaseEvent; handled above in processTrade
}
@Override