Class TradeWindowHolder
java.lang.Object
Kyu.GuiAPI_Redone.Window.Openable
Kyu.GuiAPI_Redone.Window.WindowImpl.TradeWindow.TradeWindowHolder
-
Field Summary
Fields inherited from class Kyu.GuiAPI_Redone.Window.Openable
disableClickEvent, gui, isIgnoreCloseEvent, onClose, preventClose, unregisterOnClose
-
Constructor Summary
ConstructorsConstructorDescriptionTradeWindowHolder
(GUI gui, org.bukkit.entity.Player partner, String title) A new Holder (or Manager) for the Trade between 2 PlayersTradeWindowHolder
(GUI gui, org.bukkit.entity.Player partner, String titleMain, String titlePartner) SeeTradeWindowHolder(GUI, Player, String)
but this allows seperate window titles -
Method Summary
Modifier and TypeMethodDescriptionvoid
addTradeItem
(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack item) Adds a trade to the items, gives an error to the player if his trade space is full.void
close
(boolean canceled) Closes the windows, unregisters theTradeWindowListener
, callsgetOnCancel()
orgetOnFinish()
and handles the items if the trade was canceledvoid
Completes the trade, exchanges items and callsclose(boolean)
afterwards.void
Sets both parties to "not ready"boolean[]
getArePartiesReady
(org.bukkit.entity.Player p) Returns whether or not the players are ready with the first entry always being if the player supplied is ready, then the other partyorg.bukkit.inventory.ItemStack
void
handlePlayerClose
(org.bukkit.entity.Player p) Acts as if the player has canceled the trade, callsclose(boolean)
afterwardsvoid
open()
Opens the windowsvoid
removeTradeItem
(org.bukkit.entity.Player p, GuiItem item) Removes an item from the trade and returns it to the players inventory.void
Sends a message to both playersvoid
setInventoryFullError
(String inventoryFullError) The error shown when someones inventory is fullvoid
setOnCancel
(Consumer<Void> onCancel) Set a function that shall be executed when the trade has been canceled.void
setOnFinish
(Consumer<Void> onFinish) Set a function that shall be executed when the trade has been completed.void
Set the spacer separating the two sides of the trade windowvoid
void
setToolbar
(TradeToolbar toolbar) Sets a newTradeToolbar
, keep in mind that the toolbar itself has customization as well so you don't need to set a complete new onevoid
setTradeCanceledError
(String tradeCanceledError) The error shown when someone cancels the tradevoid
setTradeWindowFullError
(String tradeWindowFullError) The error shown when the space for Trade Items is fullvoid
toggleReady
(org.bukkit.entity.Player p) Changes the supplied players ready status, if both parties are ready, the trade will be completedMethods inherited from class Kyu.GuiAPI_Redone.Window.Openable
getGui, getOnClose, isDisableClickEvent, isIgnoreCloseEvent, isPreventClose, isUnregisterOnClose, setDisableClickEvent, setIgnoreCloseEvent, setOnClose, setPreventClose, setUnregisterOnClose
-
Constructor Details
-
TradeWindowHolder
A new Holder (or Manager) for the Trade between 2 Players- Parameters:
gui
- TheGUI
the windows belong topartner
- the partner of the trade, the other player will beGUI.getHolder()
title
- Title of both windows, will be color translated
-
TradeWindowHolder
public TradeWindowHolder(GUI gui, org.bukkit.entity.Player partner, String titleMain, String titlePartner) SeeTradeWindowHolder(GUI, Player, String)
but this allows seperate window titles- Parameters:
gui
-partner
-titleMain
-titlePartner
-
-
-
Method Details
-
open
public void open()Opens the windows -
close
public void close(boolean canceled) Closes the windows, unregisters theTradeWindowListener
, callsgetOnCancel()
orgetOnFinish()
and handles the items if the trade was canceled- Parameters:
canceled
- Whether or not the trade should be seen as canceled
-
handlePlayerClose
public void handlePlayerClose(org.bukkit.entity.Player p) Acts as if the player has canceled the trade, callsclose(boolean)
afterwards- Parameters:
p
- The player who canceled the trade
-
finishTrade
public void finishTrade()Completes the trade, exchanges items and callsclose(boolean)
afterwards. -
addTradeItem
public void addTradeItem(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack item) Adds a trade to the items, gives an error to the player if his trade space is full. Automatically callsforceUnready()
- Parameters:
p
- Player that the item is fromitem
- the item
-
removeTradeItem
Removes an item from the trade and returns it to the players inventory. Automatically callsforceUnready()
- Parameters:
p
- Player that the item belongs toitem
- the item
-
getTradeItems
- Returns:
- the
TradeItems
class responsesible for handling the trade items
-
setToolbar
Sets a newTradeToolbar
, keep in mind that the toolbar itself has customization as well so you don't need to set a complete new one- Parameters:
toolbar
- the toolbar
-
getToolbar
- Returns:
- the currently used
TradeToolbar
-
getSpacerItem
public org.bukkit.inventory.ItemStack getSpacerItem()- Returns:
- the item currently used as a spacer between the 2 trade offers
-
setSpacer
Set the spacer separating the two sides of the trade window- Parameters:
item
- item of the spacername
- name of the spacer, will be color translated
-
setSpacer
- Parameters:
mat
-name
-
-
getArePartiesReady
public boolean[] getArePartiesReady(org.bukkit.entity.Player p) Returns whether or not the players are ready with the first entry always being if the player supplied is ready, then the other party- Parameters:
p
- Player whose ready status should be first in the array- Returns:
- boolean[] of length 2 with the first element being whether or not he supplied player is ready, then the other party
-
toggleReady
public void toggleReady(org.bukkit.entity.Player p) Changes the supplied players ready status, if both parties are ready, the trade will be completed- Parameters:
p
- The player to change
-
forceUnready
public void forceUnready()Sets both parties to "not ready" -
sendInfo
Sends a message to both players- Parameters:
message
- the message to send
-
setTradeCanceledError
The error shown when someone cancels the trade- Parameters:
tradeCanceledError
- The error, supports '%p' for the playername who canceled. Will be color translated
-
setInventoryFullError
The error shown when someones inventory is full- Parameters:
inventoryFullError
- The error, supports '%p' for the playername whose inventory is full. Will be color translated
-
setTradeWindowFullError
The error shown when the space for Trade Items is full- Parameters:
tradeWindowFullError
- The error. Will be color translated
-
getTradeWindowFullError
- Returns:
- The error shown when the space for Trade Items is full
-
getInventoryFullError
- Returns:
- The error shown when someones inventory is full
-
getTradeCanceledError
- Returns:
- The error shown when someone cancels the trade
-
setOnCancel
Set a function that shall be executed when the trade has been canceled. This will prevent the listeners from being unregistered automatically, so you have to callGUI.unregisterListener()
yourself to clean up- Parameters:
onCancel
- The function to call
-
setOnFinish
Set a function that shall be executed when the trade has been completed. This will prevent the listeners from being unregistered automatically, so you have to callGUI.unregisterListener()
yourself to clean up- Parameters:
onFinish
- the function to call
-
getOnCancel
- Returns:
- Function called when the trade has been canceled
-
getOnFinish
- Returns:
- Function called when the trade has been completed
-