Class TradeWindowHolder

java.lang.Object
Kyu.GuiAPI_Redone.Window.Openable
Kyu.GuiAPI_Redone.Window.WindowImpl.TradeWindow.TradeWindowHolder

public class TradeWindowHolder extends Openable
  • Constructor Details

    • TradeWindowHolder

      public TradeWindowHolder(GUI gui, org.bukkit.entity.Player partner, String title)
      A new Holder (or Manager) for the Trade between 2 Players
      Parameters:
      gui - The GUI the windows belong to
      partner - the partner of the trade, the other player will be GUI.getHolder()
      title - Title of both windows, will be color translated
    • TradeWindowHolder

      public TradeWindowHolder(GUI gui, org.bukkit.entity.Player partner, String titleMain, String titlePartner)
      See TradeWindowHolder(GUI, Player, String) but this allows seperate window titles
      Parameters:
      gui -
      partner -
      titleMain -
      titlePartner -
  • Method Details

    • open

      public void open()
      Opens the windows
      Specified by:
      open in class Openable
    • close

      public void close(boolean canceled)
      Closes the windows, unregisters the TradeWindowListener, calls getOnCancel() or getOnFinish() 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, calls close(boolean) afterwards
      Parameters:
      p - The player who canceled the trade
    • finishTrade

      public void finishTrade()
      Completes the trade, exchanges items and calls close(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 calls forceUnready()
      Parameters:
      p - Player that the item is from
      item - the item
    • removeTradeItem

      public void removeTradeItem(org.bukkit.entity.Player p, GuiItem item)
      Removes an item from the trade and returns it to the players inventory. Automatically calls forceUnready()
      Parameters:
      p - Player that the item belongs to
      item - the item
    • getTradeItems

      public TradeItems getTradeItems()
      Returns:
      the TradeItems class responsesible for handling the trade items
    • setToolbar

      public void setToolbar(TradeToolbar toolbar)
      Sets a new TradeToolbar, 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

      public TradeToolbar 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

      public void setSpacer(org.bukkit.inventory.ItemStack item, String name)
      Set the spacer separating the two sides of the trade window
      Parameters:
      item - item of the spacer
      name - name of the spacer, will be color translated
    • setSpacer

      public void setSpacer(org.bukkit.Material mat, String name)
      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

      public void sendInfo(String message)
      Sends a message to both players
      Parameters:
      message - the message to send
    • setTradeCanceledError

      public void setTradeCanceledError(String tradeCanceledError)
      The error shown when someone cancels the trade
      Parameters:
      tradeCanceledError - The error, supports '%p' for the playername who canceled. Will be color translated
    • setInventoryFullError

      public void setInventoryFullError(String inventoryFullError)
      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

      public void setTradeWindowFullError(String tradeWindowFullError)
      The error shown when the space for Trade Items is full
      Parameters:
      tradeWindowFullError - The error. Will be color translated
    • getTradeWindowFullError

      public String getTradeWindowFullError()
      Returns:
      The error shown when the space for Trade Items is full
    • getInventoryFullError

      public String getInventoryFullError()
      Returns:
      The error shown when someones inventory is full
    • getTradeCanceledError

      public String getTradeCanceledError()
      Returns:
      The error shown when someone cancels the trade
    • setOnCancel

      public void setOnCancel(Consumer<Void> onCancel)
      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 call GUI.unregisterListener() yourself to clean up
      Parameters:
      onCancel - The function to call
    • setOnFinish

      public void setOnFinish(Consumer<Void> onFinish)
      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 call GUI.unregisterListener() yourself to clean up
      Parameters:
      onFinish - the function to call
    • getOnCancel

      public Consumer<Void> getOnCancel()
      Returns:
      Function called when the trade has been canceled
    • getOnFinish

      public Consumer<Void> getOnFinish()
      Returns:
      Function called when the trade has been completed