Class MerchantGui
java.lang.Object
com.github.stefvanschie.inventoryframework.gui.type.util.Gui
com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui
com.github.stefvanschie.inventoryframework.gui.type.MerchantGui
Represents a gui in the form of a merchant.
- Since:
- 0.10.0
-
Field Summary
Fields inherited from class com.github.stefvanschie.inventoryframework.gui.type.util.Gui
humanEntityCache, inventory, onBottomClick, onBottomDrag, onClose, onGlobalClick, onGlobalDrag, onOutsideClick, onTopClick, onTopDrag, plugin -
Constructor Summary
ConstructorsConstructorDescriptionMerchantGui(@NotNull com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder title) Creates a merchant gui with the given title.MerchantGui(@NotNull com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder title, @NotNull Plugin plugin) Constructs a new merchant gui for the givenplugin.MerchantGui(@NotNull String title) Creates a merchant gui with the given title.MerchantGui(@NotNull String title, @NotNull Plugin plugin) Constructs a new merchant gui for the givenplugin. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTrade(@NotNull MerchantRecipe recipe) Adds a trade to this gui.voidaddTrade(@NotNull MerchantRecipe recipe, int discount) Adds a trade to this gui.voidcallOnTradeSelect(@NotNull TradeSelectEvent event) Calls the consumer (if it's not null) that was specified usingsetOnTradeSelect(Consumer), so the consumer that should be called whenever a trade is selected in this gui.voidclick(@NotNull InventoryClickEvent event) This should delegate the provided inventory click event to the right pane, which can then handle this click event further.@NotNull Guicopy()Makes a copy of this gui and returns it.@NotNull InventoryComponentGets the inventory component representing the input@NotNull InventoryComponentGets the inventory component representing the player inventoryintGets the count ofHumanEntityinstances that are currently viewing this GUI.@NotNull List<HumanEntity>Gets a mutable snapshot of the currentHumanEntityviewers of this GUI.voidhandleClose(@NotNull HumanEntity humanEntity) Handles a human entity closing this gui.protected voidinitializeOrThrow(@NotNull Object instance, @NotNull Element element) Initializes standard fields from a Gui from a given input stream.booleanGets whether the player inventory is currently in use.static @Nullable MerchantGuiload(@NotNull Object instance, @NotNull InputStream inputStream) Loads a merchant gui from an XML file.static @Nullable MerchantGuiload(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) Loads a merchant gui from an XML file.static @NotNull MerchantGuiLoads a merchant gui from the specified element, applying code references to the provided instance.static @NotNull MerchantGuiLoads a merchant gui from the specified element, applying code references to the provided instance.voidsetExperience(int experience) Sets the experience of this merchant gui.voidsetLevel(int level) Sets the level of this merchant gui.voidsetOnTradeSelect(@Nullable Consumer<? super TradeSelectEvent> onTradeSelect) Set the consumer that should be called whenever a trade is selected in this gui.voidshow(@NotNull HumanEntity humanEntity) Shows a gui to a playerMethods inherited from class com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui
getTitle, getTitleHolder, isDirty, markChanges, setTitle, setTitleMethods inherited from class com.github.stefvanschie.inventoryframework.gui.type.util.Gui
addInventory, callCallback, callOnBottomClick, callOnBottomDrag, callOnClose, callOnGlobalClick, callOnGlobalDrag, callOnOutsideClick, callOnTopClick, callOnTopDrag, getGui, getHumanEntityCache, isUpdating, loadPane, loadPane, registerGui, registerGui, registerPane, registerPane, registerProperty, setOnBottomClick, setOnBottomDrag, setOnClose, setOnGlobalClick, setOnGlobalDrag, setOnOutsideClick, setOnTopClick, setOnTopDrag, update
-
Constructor Details
-
MerchantGui
Creates a merchant gui with the given title.- Parameters:
title- the title- Since:
- 0.10.0
-
MerchantGui
public MerchantGui(@NotNull @NotNull com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder title) Creates a merchant gui with the given title.- Parameters:
title- the title- Since:
- 0.10.0
-
MerchantGui
Constructs a new merchant gui for the givenplugin.- Parameters:
title- the title/name of this gui.plugin- the owning plugin of this gui- Since:
- 0.10.8
- See Also:
-
MerchantGui
public MerchantGui(@NotNull @NotNull com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder title, @NotNull @NotNull Plugin plugin) Constructs a new merchant gui for the givenplugin.- Parameters:
title- the title/name of this gui.plugin- the owning plugin of this gui- Since:
- 0.10.8
- See Also:
-
-
Method Details
-
setOnTradeSelect
Set the consumer that should be called whenever a trade is selected in this gui.- Parameters:
onTradeSelect- the consumer that gets called
-
callOnTradeSelect
Calls the consumer (if it's not null) that was specified usingsetOnTradeSelect(Consumer), so the consumer that should be called whenever a trade is selected in this gui. Catches and logs all exceptions the consumer might throw.- Parameters:
event- the event to handle
-
initializeOrThrow
protected void initializeOrThrow(@NotNull @NotNull Object instance, @NotNull @NotNull Element element) Description copied from class:GuiInitializes standard fields from a Gui from a given input stream. Throws aRuntimeExceptioninstead of returning null in case of a failure.- Overrides:
initializeOrThrowin classGui- Parameters:
instance- the class instance for all reflection lookupselement- the gui element- See Also:
-
show
Description copied from class:GuiShows a gui to a player -
copy
Description copied from class:GuiMakes a copy of this gui and returns it. This makes a deep copy of the gui. This entails that the underlying panes will be copied as per theirPane.copy()and miscellaneous data will be copied. The copy of this gui, will however have no viewers even if this gui currently has viewers. With this, cache data for viewers will also be non-existent for the copied gui. The original owning plugin of the gui is preserved, but the plugin will not be deeply copied. The returned gui will never be reference equal to the current gui. -
click
Description copied from class:GuiThis should delegate the provided inventory click event to the right pane, which can then handle this click event further. This should not call any internal click handlers, since those will already have been activated. -
addTrade
Adds a trade to this gui. The specified discount is the difference between the old price and the new price. For example, if a price was decreased from five to two, the discount would be three.- Parameters:
recipe- the recipe to adddiscount- the discount- Since:
- 0.10.1
-
setExperience
public void setExperience(int experience) Sets the experience of this merchant gui. Setting the experience will make the experience bar visible, even if the amount of experience is zero. Note that if the level of this merchant gui has not been set viasetLevel(int)that the experience will always show as zero even when set to something else. Experience must be greater than or equal to zero. Attempting to set the experience to below zero will throw anIllegalArgumentException.- Parameters:
experience- the experience to set- Throws:
IllegalArgumentException- when the experience is below zero- Since:
- 0.10.1
-
setLevel
public void setLevel(int level) Sets the level of this merchant gui. This is a value between one and five and will visibly change the gui by appending the level of the villager to the title. These are displayed as "Novice", "Apprentice", "Journeyman", "Expert" and "Master" respectively (when the player's locale is set to English). When an argument is supplied that is not within one and five, anIllegalArgumentExceptionwill be thrown.- Parameters:
level- the numeric level- Throws:
IllegalArgumentException- when the level is not between one and five- Since:
- 0.10.1
-
addTrade
Adds a trade to this gui. This will not set a discount on the trade. For specifiying discounts, seeaddTrade(MerchantRecipe, int).- Parameters:
recipe- the recipe to add- Since:
- 0.10.0
-
handleClose
Handles a human entity closing this gui.- Parameters:
humanEntity- the human entity who's closing this gui- Since:
- 0.10.0
-
isPlayerInventoryUsed
public boolean isPlayerInventoryUsed()Description copied from class:GuiGets whether the player inventory is currently in use. This means whether the player inventory currently has an item in it.- Specified by:
isPlayerInventoryUsedin classGui- Returns:
- true if the player inventory is occupied, false otherwise
-
getViewerCount
@Contract(pure=true) public int getViewerCount()Description copied from class:GuiGets the count ofHumanEntityinstances that are currently viewing this GUI.- Specified by:
getViewerCountin classGui- Returns:
- the count of viewers
-
getViewers
Description copied from class:GuiGets a mutable snapshot of the currentHumanEntityviewers of this GUI. This is a snapshot (copy) and not a view, therefore modifications aren't visible.- Specified by:
getViewersin classGui- Returns:
- a snapshot of the current viewers
- See Also:
-
getInputComponent
Gets the inventory component representing the input- Returns:
- the input component
- Since:
- 0.10.0
-
getPlayerInventoryComponent
Gets the inventory component representing the player inventory- Returns:
- the player inventory component
- Since:
- 0.10.0
-
load
@Nullable @Contract(pure=true) public static @Nullable MerchantGui load(@NotNull @NotNull Object instance, @NotNull @NotNull InputStream inputStream, @NotNull @NotNull Plugin plugin) Loads a merchant gui from an XML file.- Parameters:
instance- the instance on which to reference fields and methodsinputStream- the input stream containing the XML dataplugin- the plugin that will be the owner of the created gui- Returns:
- the loaded merchant gui
- Since:
- 0.10.8
- See Also:
-
load
@NotNull @Contract(pure=true) public static @NotNull MerchantGui load(@NotNull @NotNull Object instance, @NotNull @NotNull Element element, @NotNull @NotNull Plugin plugin) Loads a merchant gui from the specified element, applying code references to the provided instance.- Parameters:
instance- the instance on which to reference fields and methodselement- the element to load the gui fromplugin- the plugin that will be the owner of the created gui- Returns:
- the loaded merchant gui
- Since:
- 0.10.8
- See Also:
-
load
@Nullable @Contract(pure=true) public static @Nullable MerchantGui load(@NotNull @NotNull Object instance, @NotNull @NotNull InputStream inputStream) Loads a merchant gui from an XML file.- Parameters:
instance- the instance on which to reference fields and methodsinputStream- the input stream containing the XML data- Returns:
- the loaded merchant gui
- Since:
- 0.10.0
-
load
@NotNull @Contract(pure=true) public static @NotNull MerchantGui load(@NotNull @NotNull Object instance, @NotNull @NotNull Element element) Loads a merchant gui from the specified element, applying code references to the provided instance.- Parameters:
instance- the instance on which to reference fields and methodselement- the element to load the gui from- Returns:
- the loaded merchant gui
- Since:
- 0.10.0
-