diff --git a/paper-api/src/main/java/org/bukkit/event/inventory/TradeSelectEvent.java b/paper-api/src/main/java/org/bukkit/event/inventory/TradeSelectEvent.java new file mode 100644 index 0000000000..3bddf946d5 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/inventory/TradeSelectEvent.java @@ -0,0 +1,62 @@ +package org.bukkit.event.inventory; + +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.Merchant; +import org.bukkit.inventory.MerchantInventory; +import org.jetbrains.annotations.NotNull; + +/** + * This event is called whenever a player clicks a new trade on the trades + * sidebar. + *
+ * This event allows the user to get the index of the trade, letting them get + * the MerchantRecipe via the Merchant. + */ +public class TradeSelectEvent extends InventoryInteractEvent { + + private static final HandlerList handlers = new HandlerList(); + // + private final int index; + + public TradeSelectEvent(@NotNull InventoryView transaction, int newIndex) { + super(transaction); + this.index = newIndex; + } + + /** + * Used to get the index of the trade the player clicked on. + * + * @return The index of the trade clicked by the player + */ + public int getIndex() { + return index; + } + + @NotNull + @Override + public MerchantInventory getInventory() { + return (MerchantInventory) super.getInventory(); + } + + /** + * Get the Merchant involved. + * + * @return the Merchant + */ + @NotNull + public Merchant getMerchant() { + return getInventory().getMerchant(); + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/paper-api/src/main/java/org/bukkit/inventory/MerchantInventory.java b/paper-api/src/main/java/org/bukkit/inventory/MerchantInventory.java index edc67fecc2..8086356024 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/MerchantInventory.java +++ b/paper-api/src/main/java/org/bukkit/inventory/MerchantInventory.java @@ -1,5 +1,6 @@ package org.bukkit.inventory; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -30,4 +31,12 @@ public interface MerchantInventory extends Inventory { */ @Nullable MerchantRecipe getSelectedRecipe(); + + /** + * Gets the Merchant associated with this inventory. + * + * @return merchant + */ + @NotNull + Merchant getMerchant(); }