Add TradeSelectEvent

By: Coleman Yantis <diamonddagger590@gmail.com>
This commit is contained in:
Bukkit/Spigot 2019-04-28 12:36:23 +10:00
parent 82854b7bd7
commit b91a465a3f
2 changed files with 71 additions and 0 deletions

View file

@ -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.
* <p>
* 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;
}
}

View file

@ -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();
}