java.lang.Object
me.remigio07.chatplugin.api.server.gui.Icon

public class Icon extends Object
Represents an icon inside of a GUI.
  • Field Details

    • ICON_ID_PATTERN

      public static final Pattern ICON_ID_PATTERN
      Pattern representing the allowed icon IDs.

      Regex: "^[a-zA-Z0-9-_]{2,36}$"

      See Also:
  • Constructor Details

    • Icon

      public Icon(Icon icon)
      Constructs a new icon specifying another icon's values.

      Note: changes made to that icon's lists, maps and leather armor color will be reflected to this icon and vice versa.

      Parameters:
      icon - Icon to copy
    • Icon

      public Icon(String id, IconType type, MaterialAdapter material, ValueContainer<Short> amount, short damage, boolean keepOpen, boolean glowing, int position)
      Constructs a new icon specifying only the essential options and assuming the others as their default values.

      Note: GUIManager.createIcon(Configuration, String) is capable of reading icons from Configurations. Use this constructor just to obtain custom icons via code.

      Parameters:
      id - Icon's ID
      type - Icon's type
      material - Icon's material
      amount - Icon's items' amount [1 - 64]
      damage - Icon's items' damage [0 - max durability]
      keepOpen - Whether the GUI will remain open on click
      glowing - Whether the glowing effect should be applied
      position - Icon's position [0 - (InventoryAdapter.getSize() - 1)]
      Throws:
      IllegalArgumentException - If specified ID !isValidIconID(String)
    • Icon

      public Icon(String id, IconType type, MaterialAdapter material, ValueContainer<Short> amount, short damage, boolean keepOpen, boolean glowing, int position, String skullOwner, String skullTextureURL, Color leatherArmorColor, List<String> commands, List<ItemFlagAdapter> itemFlags, Map<Language,String> displayNames, Map<Language,List<String>> lores, Map<EnchantmentAdapter,Integer> enchantments)
      Constructs a new icon specifying all the available options.

      Note: GUIManager.createIcon(Configuration, String) is capable of reading icons from Configurations. Use this constructor just to obtain custom icons via code.

      It is recommended to use thread-safe collections.

      Parameters:
      id - Icon's ID
      type - Icon's type
      material - Icon's material
      amount - Icon's items' amount [1 - 64]
      damage - Icon's items' damage [0 - max durability]
      keepOpen - Whether the GUI will remain open on click
      glowing - Whether the glowing effect should be applied
      position - Icon's position [0 - (InventoryAdapter.getSize() - 1)]
      skullOwner - Icon's skull's owner
      skullTextureURL - Icon's skull's texture's URL
      leatherArmorColor - Icon's leather armor's color
      commands - Icon's commands executed on click
      itemFlags - Icon's item flags
      displayNames - Icon's display names
      lores - Icon's lores
      enchantments - Icon's enchantments
      Throws:
      IllegalArgumentException - If specified ID !isValidIconID(String)
  • Method Details

    • getID

      public String getID()
      Gets this icon's ID.
      Returns:
      Icon's ID
    • getType

      public IconType getType()
      Gets this icon's type.
      Returns:
      Icon's type
    • getMaterial

      public MaterialAdapter getMaterial()
      Gets this icon's material.
      Returns:
      Icon's material
    • setMaterial

      public Icon setMaterial(MaterialAdapter material)
      Sets this icon's material.
      Parameters:
      material - Icon's material
      Returns:
      This icon
    • getAmount

      public ValueContainer<Short> getAmount()
      Gets this icon's items' amount.
      Returns:
      Icon's items' amount [1 - 64]
    • setAmount

      public Icon setAmount(ValueContainer<Short> amount)
      Sets this icon's items' amount.
      Parameters:
      amount - Icon's items' amount [1 - 64]
      Returns:
      This icon
    • getDamage

      public short getDamage()
      Gets this icon's items' damage.
      Returns:
      Icon's items' damage [0 - max durability]
    • setDamage

      public Icon setDamage(short damage)
      Sets this icon's items' damage.
      Parameters:
      damage - Icon's items' damage [0 - max durability]
      Returns:
      This icon
    • isKeepOpen

      public boolean isKeepOpen()
      Checks if the GUI should be kept open when this icon is clicked.
      Returns:
      Whether the GUI will remain open on click
    • setKeepOpen

      public Icon setKeepOpen(boolean keepOpen)
      Sets if the GUI should be kept open when this icon is clicked.
      Parameters:
      keepOpen - Whether the GUI will remain open on click
      Returns:
      This icon
    • isGlowing

      public boolean isGlowing()
      Checks if the glowing effect should be applied to this icon.
      Returns:
      Whether the glowing effect should be applied
    • setGlowing

      public Icon setGlowing(boolean glowing)
      Sets if the glowing effect should be applied to this icon.
      Parameters:
      glowing - Whether the glowing effect should be applied
      Returns:
      This icon
    • getPosition

      public int getPosition()
      Gets this icon's position in the GUI's inventory.
      Returns:
      Icon's position [0 - (InventoryAdapter.getSize() - 1)]
    • setPosition

      public Icon setPosition(int position)
      Sets this icon's position in the GUI's inventory.
      Parameters:
      position - Icon's position [0 - (InventoryAdapter.getSize() - 1)]
      Returns:
      This icon
    • getSkullOwner

      public String getSkullOwner()
      Gets this icon's skull's owner.

      Will return null if the skull's owner has not been specified.

      Returns:
      Icon's skull's owner
    • setSkullOwner

      public Icon setSkullOwner(String skullOwner)
      Sets this icon's skull's owner.

      You can specify null to remove the skull's owner.

      Parameters:
      skullOwner - Icon's skull's owner
      Returns:
      This icon
    • getSkullTextureURL

      public String getSkullTextureURL()
      Gets this icon's skull's texture's URL.

      Will return null if the skull's texture's URL has not been specified.

      Returns:
      Icon's skull's texture's URL
    • setSkullTextureURL

      public Icon setSkullTextureURL(String skullTextureURL)
      Sets this icon's skull's texture's URL.

      You can specify null to remove the skull's texture's URL.

      Parameters:
      skullTextureURL - Icon's skull's texture's URL
      Returns:
      This icon
    • getLeatherArmorColor

      public Color getLeatherArmorColor()
      Gets this icon's leather armor's color.

      Will return null if the leather armor's color has not been specified.

      Returns:
      Icon's leather armor's color
    • setLeatherArmorColor

      public Icon setLeatherArmorColor(Color leatherArmorColor)
      Sets this icon's leather armor's color.

      If you need to reset the color to the default value, specify null and the following hex code will be applied: "#A06540".

      Parameters:
      leatherArmorColor - Icon's leather armor's color
      Returns:
      This icon
    • getCommands

      public List<String> getCommands()
      Gets the commands that will be executed when this icon is clicked.

      You may modify the returned list.

      Returns:
      Icon's commands
    • setCommands

      public Icon setCommands(List<String> commands)
      Sets the commands that will be executed when this icon is clicked.
      Parameters:
      commands - Icon's commands
      Returns:
      This icon
    • getItemFlags

      public List<ItemFlagAdapter> getItemFlags()
      Gets this icon's item flags.

      You may modify the returned list.

      Returns:
      Icon's item flags
    • setItemFlags

      public Icon setItemFlags(List<ItemFlagAdapter> itemFlags)
      Sets this icon's item flags.
      Parameters:
      itemFlags - Icon's item flags
      Returns:
      This icon
    • getDisplayNames

      public Map<Language,String> getDisplayNames()
      Gets this icon's display names.

      You may modify the returned map.

      Returns:
      Icon's display names
    • setDisplayNames

      public Icon setDisplayNames(Map<Language,String> displayNames)
      Sets this icon's display names.
      Parameters:
      displayNames - Icon's display names
      Returns:
      This icon
    • getLores

      public Map<Language,List<String>> getLores()
      Gets this icon's lores.

      You may modify the returned map.

      Returns:
      Icon's lores
    • setLores

      public Icon setLores(Map<Language,List<String>> lores)
      Sets this icon's lores.
      Parameters:
      lores - Icon's lores
      Returns:
      This icon
    • getEnchantments

      public Map<EnchantmentAdapter,Integer> getEnchantments()
      Gets this icon's enchantments.

      You may modify the returned map.

      Returns:
      Icon's enchantments
    • setEnchantments

      public Icon setEnchantments(Map<EnchantmentAdapter,Integer> enchantments)
      Sets this icon's enchantments.
      Parameters:
      enchantments - Icon's enchantments
      Returns:
      This icon
    • toItemStackAdapter

      public ItemStackAdapter toItemStackAdapter(GUI gui, Language language)
      Generates an item stack for the specified language using this icon's values and translating placeholders using formatPlaceholders(String, GUI, Language, boolean) and formatPlaceholders(List, GUI, Language, boolean) translating colors when necessary.

      This method takes no time to execute but it does not consider getSkullOwner(). To change a player head icon skull's owner use updateSkullOwner(ItemStackAdapter, GUI, Language).

      Note: getSkullTextureURL() is considered because it takes no time to set.

      Parameters:
      gui - GUI containing this icon
      language - Language used to translate the placeholders
      Returns:
      New item stack
    • updateSkullOwner

      public CompletableFuture<ItemStackAdapter> updateSkullOwner(ItemStackAdapter itemStack, GUI gui, Language language)
      Sets the skull's owner for the specified item stack if it is a player head.

      When the future is completed, you need to manually set the icon to the inventory using InventoryAdapter.setItem(ItemStackAdapter, int) to update it.

      The future will be completed instantly in the following cases:

      Otherwise it will take some time to fetch the skin.
      Parameters:
      itemStack - Original item stack
      gui - GUI containing this icon
      language - Language used to translate the placeholders
      Returns:
      New item stack
      See Also:
    • formatPlaceholders

      public String formatPlaceholders(String input, GUI gui, Language language, boolean translateColors)
      Translates an input string containing placeholders for the specified GUI and language using GUI.getStringPlaceholdersTranslator().
      Parameters:
      input - Input containing placeholders
      gui - GUI containing this icon
      language - Language used to translate the placeholders
      translateColors - Whether to ChatColor.translate(String) the output
      Returns:
      Translated placeholders
    • formatPlaceholders

      public List<String> formatPlaceholders(List<String> input, GUI gui, Language language, boolean translateColors)
      Translates an input string list containing placeholders for the specified GUI and language using GUI.getStringListPlaceholdersTranslator().
      Parameters:
      input - Input containing placeholders
      gui - GUI containing this icon
      language - Language used to translate the placeholders
      translateColors - Whether to ChatColor.translate(String) the output
      Returns:
      Translated placeholders
    • isValidIconID

      public static boolean isValidIconID(String iconID)
      Checks if the specified String is a valid icon ID.
      Parameters:
      iconID - Icon ID to check
      Returns:
      Whether the specified icon ID is valid
      See Also:
    • calcIconPosition

      public static int calcIconPosition(int x, int y)
      Calculates an icon's position using its X and Y coordinates.
      Parameters:
      x - Icon's X coordinate [1 - 9]
      y - Icon's Y coordinate [1 - (InventoryAdapter.getSize() / 9)]
      Returns:
      Icon's position [0 - (InventoryAdapter.getSize() - 1)]
      See Also:
    • calcIconCoords

      public static int[] calcIconCoords(int position)
      Calculates an icon's X and Y coordinates using its position.
      Parameters:
      position - Icon's position [0 - (InventoryAdapter.getSize() - 1)]
      Returns:
      Icon's X and Y coordinates
      See Also: