Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.Merchant;
import org.bukkit.inventory.MerchantRecipe;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
Expand All @@ -17,20 +18,31 @@ public class PlayerPurchaseEvent extends PlayerEvent implements Cancellable {

private static final HandlerList HANDLER_LIST = new HandlerList();

private final Merchant merchant;
private boolean rewardExp;
private boolean increaseTradeUses;
private MerchantRecipe trade;

private boolean cancelled;

@ApiStatus.Internal
public PlayerPurchaseEvent(final Player player, final MerchantRecipe trade, final boolean rewardExp, final boolean increaseTradeUses) {
public PlayerPurchaseEvent(final Player player, final Merchant merchant, final MerchantRecipe trade, final boolean rewardExp, final boolean increaseTradeUses) {
super(player);
this.merchant = merchant;
this.trade = trade;
this.rewardExp = rewardExp;
this.increaseTradeUses = increaseTradeUses;
}

/**
* Gets the merchant that the player is trading with
*
* @return the merchant
*/
public Merchant getMerchant() {
return merchant;
}

/**
* Gets the associated trade with this event
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@
@NullMarked
public class PlayerTradeEvent extends PlayerPurchaseEvent {

private final AbstractVillager villager;

@ApiStatus.Internal
public PlayerTradeEvent(final Player player, final AbstractVillager villager, final MerchantRecipe trade, final boolean rewardExp, final boolean increaseTradeUses) {
super(player, trade, rewardExp, increaseTradeUses);
this.villager = villager;
super(player, villager, trade, rewardExp, increaseTradeUses);
}

@Override
public AbstractVillager getMerchant() {
return (AbstractVillager) super.getMerchant();
}

/**
* Gets the Villager or Wandering trader associated with this event
*
* @return the villager or wandering trader
* @see #getMerchant()
*/
@ApiStatus.Obsolete
public AbstractVillager getVillager() {
return this.villager;
return getMerchant();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
+ if (activeOffer != null && player instanceof net.minecraft.server.level.ServerPlayer serverPlayer) {
+ if (this.merchant instanceof net.minecraft.world.entity.npc.AbstractVillager abstractVillager) {
+ event = new io.papermc.paper.event.player.PlayerTradeEvent(serverPlayer.getBukkitEntity(), (org.bukkit.entity.AbstractVillager) abstractVillager.getBukkitEntity(), activeOffer.asBukkit(), true, true);
+ } else if (this.merchant instanceof org.bukkit.craftbukkit.inventory.CraftMerchantCustom.MinecraftMerchant) {
+ event = new io.papermc.paper.event.player.PlayerPurchaseEvent(serverPlayer.getBukkitEntity(), activeOffer.asBukkit(), false, true);
+ } else if (this.merchant instanceof org.bukkit.craftbukkit.inventory.CraftMerchantCustom.MinecraftMerchant minecraftMerchant) {
+ event = new io.papermc.paper.event.player.PlayerPurchaseEvent(serverPlayer.getBukkitEntity(), minecraftMerchant.getCraftMerchant(), activeOffer.asBukkit(), false, true);
+ }
+ if (event != null) {
+ if (!event.callEvent()) {
Expand Down
Loading