Add PlayerTradeEvent and PlayerPurchaseEvent
Co-authored-by: Alexander <protonull@protonmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user