Add Javadoc to the API
This commit is contained in:
parent
ca9f45810a
commit
1eb72078aa
|
@ -6,9 +6,19 @@
|
|||
package me.filoghost.chestcommands.api;
|
||||
|
||||
import me.filoghost.chestcommands.api.internal.BackendAPI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The main entry point for the Chest Commands API.
|
||||
* <p>
|
||||
* To create a menu, start by looking at {@link Menu#create(Plugin, String, int)} and {@link
|
||||
* ConfigurableIcon#create(Material)}.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public class ChestCommandsAPI {
|
||||
|
||||
|
||||
|
@ -16,41 +26,80 @@ public class ChestCommandsAPI {
|
|||
|
||||
|
||||
/**
|
||||
* The API version is increased every time the API is modified.
|
||||
* You can use it to require a minimum version, as features may
|
||||
* be added (rarely removed) in future versions.
|
||||
* Returns the API version number, which is increased every time the API changes. This number is used to check if a
|
||||
* certain method or class (which may have been added later) is present or not.
|
||||
* <p>
|
||||
* All public API classes and methods are documented with the Javadoc tag {@code @since}, indicating in which API
|
||||
* version that element was introduced.
|
||||
* <p>
|
||||
* You can use it to require a minimum version, as features may be added (rarely removed) in future versions. The
|
||||
* first version of the API is 1.
|
||||
*
|
||||
* @return the API version
|
||||
* @return the current API version
|
||||
* @since 1
|
||||
*/
|
||||
public static int getAPIVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
public static void registerPlaceholder(Plugin plugin, String identifier, PlaceholderReplacer placeholderReplacer) {
|
||||
/**
|
||||
* Registers a placeholder that will be replaced by a custom value provided by the given placeholder replacer, which
|
||||
* may be different for each player.
|
||||
* <p>
|
||||
* Placeholders can be used in some parts of {@link ConfigurableIcon}, most notably the name and the lore, but they
|
||||
* are disabled by default. The method {@link ConfigurableIcon#setPlaceholdersEnabled(boolean)} must be invoked on
|
||||
* each icon which should have placeholders enabled.
|
||||
* <p>
|
||||
* Menus loaded by Chest Commands from the menus folder always display placeholders, including those registered
|
||||
* through this method.
|
||||
* <p>
|
||||
* The identifier is automatically converted to the appropriate placeholder format. For example, given the
|
||||
* identifier "test", the callback would be invoked to replace the the following placeholders:
|
||||
* <ul>
|
||||
* <li>{test}
|
||||
* <li>{test: 123}
|
||||
* <li>{test: hello world}
|
||||
* </ul>
|
||||
*
|
||||
* @param plugin the plugin registering the placeholder
|
||||
* @param identifier the identifier of the placeholder, which can only contain letters, digits and
|
||||
* underscores
|
||||
* @param placeholderReplacer the callback that returns the displayed value
|
||||
* @see PlaceholderReplacer#getReplacement(Player, String)
|
||||
* @since 1
|
||||
*/
|
||||
public static void registerPlaceholder(@NotNull Plugin plugin,
|
||||
@NotNull String identifier,
|
||||
@NotNull PlaceholderReplacer placeholderReplacer) {
|
||||
BackendAPI.getImplementation().registerPlaceholder(plugin, identifier, placeholderReplacer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a menu with a given file name was loaded by the plugin.
|
||||
* Returns if a menu with a given file name exists and was loaded successfully by Chest Commands from the menus
|
||||
* folder.
|
||||
*
|
||||
* @return if the menu was found
|
||||
* @param menuFileName the file name of the menu to check
|
||||
* @return true if the menu exists, false otherwise
|
||||
* @since 1
|
||||
*/
|
||||
public static boolean pluginMenuExists(String menuFileName) {
|
||||
public static boolean pluginMenuExists(@NotNull String menuFileName) {
|
||||
return BackendAPI.getImplementation().pluginMenuExists(menuFileName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Opens a menu loaded by ChestCommands to a player.
|
||||
* NOTE: this method ignores permissions.
|
||||
* Opens a menu loaded by Chest Commands from the menus folder.
|
||||
* <p>
|
||||
* <b>WARNING</b>: this method opens the menu without checking the permissions of the player.
|
||||
*
|
||||
* @param player the player that will see the menu
|
||||
* @param menuFileName the file name of the menu to open (with the .yml extension)
|
||||
* @return if the menu was found and opened
|
||||
* @param player the player that will see the menu
|
||||
* @param menuFileName the file name of the menu to open
|
||||
* @return true if the menu was found and opened successfully, false otherwise
|
||||
* @since 1
|
||||
*/
|
||||
public static boolean openPluginMenu(Player player, String menuFileName) {
|
||||
public static boolean openPluginMenu(@NotNull Player player, @NotNull String menuFileName) {
|
||||
return BackendAPI.getImplementation().openPluginMenu(player, menuFileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,14 +6,24 @@
|
|||
package me.filoghost.chestcommands.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Callback to handle a player clicking on an icon.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ClickHandler {
|
||||
|
||||
/**
|
||||
* @param player the player that clicked on the inventory
|
||||
* @return true if the inventory should be closed, false otherwise
|
||||
* Called when a player clicks on an icon associated with this handler.
|
||||
*
|
||||
* @param menuView the menu view inside which the icon was clicked
|
||||
* @param clicker the player that clicked an icon (identical to {@link MenuView#getViewer()})
|
||||
* @return the result of this interaction: whether the menu should be closed or kept open
|
||||
* @since 1
|
||||
*/
|
||||
ClickResult onClick(MenuView menuView, Player player);
|
||||
@NotNull ClickResult onClick(@NotNull MenuView menuView, @NotNull Player clicker);
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,25 @@
|
|||
*/
|
||||
package me.filoghost.chestcommands.api;
|
||||
|
||||
/**
|
||||
* Enum of possible actions applied to a menu view after a player clicks on an icon.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public enum ClickResult {
|
||||
|
||||
/**
|
||||
* Keeps the menu view open.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
KEEP_OPEN,
|
||||
|
||||
/**
|
||||
* Closes the menu view.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
CLOSE
|
||||
|
||||
}
|
||||
|
|
|
@ -6,15 +6,46 @@
|
|||
package me.filoghost.chestcommands.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Common interface extended by other interfaces, represents a simplified {@link Icon} with a settable click handler.
|
||||
* <p>
|
||||
* This interface exists to avoid having to implement {@link Icon#onClick(MenuView, Player)} via subclassing.
|
||||
*
|
||||
* @see ConfigurableIcon
|
||||
* @see StaticIcon
|
||||
* @since 1
|
||||
*/
|
||||
public interface ClickableIcon extends Icon {
|
||||
|
||||
void setClickHandler(ClickHandler clickHandler);
|
||||
/**
|
||||
* Sets the click handler for this icon.
|
||||
*
|
||||
* @param clickHandler the new click handler, null to remove
|
||||
* @since 1
|
||||
*/
|
||||
void setClickHandler(@Nullable ClickHandler clickHandler);
|
||||
|
||||
ClickHandler getClickHandler();
|
||||
/**
|
||||
* Returns the current click handler.
|
||||
*
|
||||
* @return the current click handler, null if absent
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable ClickHandler getClickHandler();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* This default implementation delegates the click event to the current click handler. This method should not be
|
||||
* overridden.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
@Override
|
||||
default ClickResult onClick(MenuView menuView, Player clicker) {
|
||||
default @NotNull ClickResult onClick(@NotNull MenuView menuView, @NotNull Player clicker) {
|
||||
if (getClickHandler() != null) {
|
||||
return getClickHandler().onClick(menuView, clicker);
|
||||
} else {
|
||||
|
|
|
@ -5,73 +5,295 @@
|
|||
*/
|
||||
package me.filoghost.chestcommands.api;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import me.filoghost.chestcommands.api.internal.BackendAPI;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* An {@link Icon} that displays an {@link ItemStack} based on its configurable properties.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface ConfigurableIcon extends ClickableIcon {
|
||||
|
||||
static ConfigurableIcon create(Material material) {
|
||||
|
||||
/**
|
||||
* Creates a new configurable icon with a given material.
|
||||
*
|
||||
* @param material the material
|
||||
* @return the created icon
|
||||
* @since 1
|
||||
*/
|
||||
static @NotNull ConfigurableIcon create(@NotNull Material material) {
|
||||
return BackendAPI.getImplementation().createConfigurableIcon(material);
|
||||
}
|
||||
|
||||
void setMaterial(Material material);
|
||||
|
||||
Material getMaterial();
|
||||
/**
|
||||
* Sets the material of the displayed item.
|
||||
*
|
||||
* @param material the new material
|
||||
* @see ItemStack#setType(Material)
|
||||
* @since 1
|
||||
*/
|
||||
void setMaterial(@NotNull Material material);
|
||||
|
||||
/**
|
||||
* Returns the material of the displayed item.
|
||||
*
|
||||
* @return the current material
|
||||
* @see ItemStack#getType()
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull Material getMaterial();
|
||||
|
||||
/**
|
||||
* Sets the amount of the displayed item.
|
||||
*
|
||||
* @param amount the new amount
|
||||
* @see ItemStack#setAmount(int)
|
||||
* @since 1
|
||||
*/
|
||||
void setAmount(int amount);
|
||||
|
||||
/**
|
||||
* Returns the amount of the displayed item.
|
||||
*
|
||||
* @return the current amount
|
||||
* @see ItemStack#getAmount()
|
||||
* @since 1
|
||||
*/
|
||||
int getAmount();
|
||||
|
||||
/**
|
||||
* Sets the durability of the displayed item.
|
||||
*
|
||||
* @param durability the new durability
|
||||
* @see ItemStack#setDurability(short)
|
||||
* @since 1
|
||||
*/
|
||||
void setDurability(short durability);
|
||||
|
||||
/**
|
||||
* Returns the durability of the displayed item.
|
||||
*
|
||||
* @return the current durability
|
||||
* @see ItemStack#getDurability()
|
||||
* @since 1
|
||||
*/
|
||||
short getDurability();
|
||||
|
||||
void setNBTData(String nbtData);
|
||||
/**
|
||||
* Sets the NBT data of the displayed item. When creating the displayed item, all other options have higher priority
|
||||
* and override NBT values (for example, {@link ConfigurableIcon#setName(String)} overrides the name inside NBT
|
||||
* data).
|
||||
*
|
||||
* @param nbtData the new NBT data as JSON string, null to remove
|
||||
* @throws IllegalArgumentException if the NBT data is not valid
|
||||
* @since 1
|
||||
*/
|
||||
void setNBTData(@Nullable String nbtData);
|
||||
|
||||
String getNBTData();
|
||||
/**
|
||||
* Returns the NBT data of the displayed item.
|
||||
*
|
||||
* @return the current NBT data as JSON string, null if absent
|
||||
* @see ConfigurableIcon#setNBTData(String)
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable String getNBTData();
|
||||
|
||||
void setName(String name);
|
||||
|
||||
String getName();
|
||||
/**
|
||||
* Sets the name, which is the first line in the tooltip of the displayed item. Can contain colors.
|
||||
*
|
||||
* @param name the new name, null to remove
|
||||
* @since 1
|
||||
*/
|
||||
void setName(@Nullable String name);
|
||||
|
||||
void setLore(String... lore);
|
||||
/**
|
||||
* Returns the name.
|
||||
*
|
||||
* @return the current name, null if absent
|
||||
* @see ConfigurableIcon#setName(String)
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable String getName();
|
||||
|
||||
void setLore(List<String> lore);
|
||||
/**
|
||||
* Sets the lore, which is the lines below the name in the tooltip of the displayed item. Can contain colors.
|
||||
*
|
||||
* @param lore the new lore as list of lines, null to remove
|
||||
* @since 1
|
||||
*/
|
||||
void setLore(@Nullable List<String> lore);
|
||||
|
||||
List<String> getLore();
|
||||
/**
|
||||
* Sets the lore.
|
||||
*
|
||||
* @param lore the new lore as array of lines, null to remove
|
||||
* @see ConfigurableIcon#setLore(List)
|
||||
* @since 1
|
||||
*/
|
||||
void setLore(@Nullable String... lore);
|
||||
|
||||
void setEnchantments(Map<Enchantment, Integer> enchantments);
|
||||
/**
|
||||
* Returns the lore.
|
||||
*
|
||||
* @return the current lore, null if absent
|
||||
* @see ConfigurableIcon#setLore(List)
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable List<String> getLore();
|
||||
|
||||
Map<Enchantment, Integer> getEnchantments();
|
||||
/**
|
||||
* Sets the enchantments of the displayed item, removing existing ones.
|
||||
*
|
||||
* @param enchantments the new enchantments, as map of enchantment and level, null to remove all enchantments
|
||||
* @since 1
|
||||
*/
|
||||
void setEnchantments(@Nullable Map<Enchantment, Integer> enchantments);
|
||||
|
||||
void addEnchantment(Enchantment enchantment);
|
||||
/**
|
||||
* Returns the enchantments of the displayed item.
|
||||
*
|
||||
* @return the current enchantments, as map of enchantment and level, null if absent
|
||||
* @see ConfigurableIcon#setEnchantments(Map)
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable Map<Enchantment, Integer> getEnchantments();
|
||||
|
||||
void addEnchantment(Enchantment enchantment, Integer level);
|
||||
/**
|
||||
* Adds a level 1 enchantment to the displayed item.
|
||||
*
|
||||
* @param enchantment the enchantment to add
|
||||
* @since 1
|
||||
*/
|
||||
void addEnchantment(@NotNull Enchantment enchantment);
|
||||
|
||||
void removeEnchantment(Enchantment enchantment);
|
||||
/**
|
||||
* Adds an enchantment to the displayed item.
|
||||
*
|
||||
* @param enchantment the enchantment to add
|
||||
* @param level the level of the enchantment
|
||||
* @since 1
|
||||
*/
|
||||
void addEnchantment(@NotNull Enchantment enchantment, int level);
|
||||
|
||||
Color getLeatherColor();
|
||||
/**
|
||||
* Removes an enchantment from the displayed item.
|
||||
*
|
||||
* @param enchantment the enchantment to remove
|
||||
* @since 1
|
||||
*/
|
||||
void removeEnchantment(@NotNull Enchantment enchantment);
|
||||
|
||||
void setLeatherColor(Color leatherColor);
|
||||
/**
|
||||
* Sets the leather color of the displayed leather armor.
|
||||
* <p>
|
||||
* This value is ignored if the material is not a leather armor piece.
|
||||
*
|
||||
* @param leatherColor the new leather color, null to remove
|
||||
* @since 1
|
||||
*/
|
||||
void setLeatherColor(@Nullable Color leatherColor);
|
||||
|
||||
String getSkullOwner();
|
||||
/**
|
||||
* Returns the leather color of the displayed item.
|
||||
*
|
||||
* @return the current leather color, null if absent
|
||||
* @see ConfigurableIcon#setLeatherColor(Color)
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable Color getLeatherColor();
|
||||
|
||||
void setSkullOwner(String skullOwner);
|
||||
/**
|
||||
* Sets the skull owner of the displayed player head.
|
||||
* <p>
|
||||
* This value is ignored if the material is not a player head.
|
||||
*
|
||||
* @param skullOwner the new skull owner, null to remove
|
||||
* @since 1
|
||||
*/
|
||||
void setSkullOwner(@Nullable String skullOwner);
|
||||
|
||||
DyeColor getBannerColor();
|
||||
/**
|
||||
* Returns the skull owner.
|
||||
*
|
||||
* @return the current skull owner, null if absent
|
||||
* @see ConfigurableIcon#setSkullOwner(String)
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable String getSkullOwner();
|
||||
|
||||
void setBannerColor(DyeColor bannerColor);
|
||||
/**
|
||||
* Sets the color of the displayed banner. <b>Only used before Minecraft 1.13.</b>
|
||||
* <p>
|
||||
* This value is ignored if the material is not a banner.
|
||||
*
|
||||
* @param bannerColor the new banner color, null to remove
|
||||
* @since 1
|
||||
*/
|
||||
void setBannerColor(@Nullable DyeColor bannerColor);
|
||||
|
||||
List<Pattern> getBannerPatterns();
|
||||
/**
|
||||
* Returns the banner color.
|
||||
*
|
||||
* @return the current banner color, null if absent
|
||||
* @see ConfigurableIcon#setBannerColor(DyeColor)
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable DyeColor getBannerColor();
|
||||
|
||||
void setBannerPatterns(List<Pattern> bannerPatterns);
|
||||
/**
|
||||
* Sets the patterns of the displayed banner.
|
||||
* <p>
|
||||
* This value is ignored if the material is not a banner.
|
||||
*
|
||||
* @param bannerPatterns the new banner patterns list, null to remove
|
||||
* @since 1
|
||||
*/
|
||||
void setBannerPatterns(@Nullable List<Pattern> bannerPatterns);
|
||||
|
||||
/**
|
||||
* Sets the patterns of the displayed banner.
|
||||
*
|
||||
* @param bannerPatterns the new banner patterns array, null to remove
|
||||
* @see ConfigurableIcon#setBannerPatterns(Pattern...)
|
||||
* @since 1
|
||||
*/
|
||||
void setBannerPatterns(@Nullable Pattern... bannerPatterns);
|
||||
|
||||
/**
|
||||
* Returns the patterns of the displayed banner.
|
||||
*
|
||||
* @return the current banner patterns, null if absent
|
||||
* @see ConfigurableIcon#setBannerPatterns(List)
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable List<Pattern> getBannerPatterns();
|
||||
|
||||
/**
|
||||
* Sets if placeholders should be enabled.
|
||||
*
|
||||
* @param enabled true if the placeholders should be enabled, false otherwise
|
||||
* @since 1
|
||||
*/
|
||||
void setPlaceholdersEnabled(boolean enabled);
|
||||
|
||||
/**
|
||||
* Returns if placeholders are currently enabled. By default they are not enabled.
|
||||
*
|
||||
* @return true if placeholders are currently enabled, false otherwise
|
||||
* @since 1
|
||||
*/
|
||||
boolean isPlaceholdersEnabled();
|
||||
|
||||
}
|
||||
|
|
|
@ -5,13 +5,40 @@
|
|||
*/
|
||||
package me.filoghost.chestcommands.api;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Icons are the elements contained in a {@link Menu}, rendered as {@link ItemStack} when presented to a player.
|
||||
* <p>
|
||||
* Although this interface can be implemented with custom classes, it is recommended to use the provided constructors:
|
||||
* {@link ConfigurableIcon#create(Material)} and {@link StaticIcon#create(ItemStack)}.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface Icon {
|
||||
|
||||
ItemStack render(Player viewer);
|
||||
/**
|
||||
* Creates an item stack to be displayed inside the menu. This method is called when a {@link MenuView} is opened or
|
||||
* refreshed by calling {@link MenuView#refresh()}.
|
||||
*
|
||||
* @param viewer the player viewing the menu
|
||||
* @return the item stack to display
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable ItemStack render(@NotNull Player viewer);
|
||||
|
||||
ClickResult onClick(MenuView menuView, Player clicker);
|
||||
/**
|
||||
* Called when a player clicks on the icon.
|
||||
*
|
||||
* @param menuView the menu view associated with the player that clicked an icon
|
||||
* @param clicker the player that clicked an icon
|
||||
* @return the result of the interaction: whether the menu should be closed or kept open
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull ClickResult onClick(@NotNull MenuView menuView, @NotNull Player clicker);
|
||||
|
||||
}
|
|
@ -8,31 +8,99 @@ package me.filoghost.chestcommands.api;
|
|||
import me.filoghost.chestcommands.api.internal.BackendAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Menus are containers of {@link Icon}s that can be displayed to players as unmodifiable inventories.
|
||||
* <p>
|
||||
* It is not recommended to implement this interface, use the provided constructor {@link Menu#create(Plugin, String,
|
||||
* int)}.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface Menu {
|
||||
|
||||
static Menu create(Plugin owner, String title, int rowCount) {
|
||||
/**
|
||||
* Creates a new menu.
|
||||
*
|
||||
* @param owner the plugin creating the menu
|
||||
* @param title title of the menu that will be displayed in the inventory
|
||||
* @param rowCount number of rows in the menu (the number of columns is always 9, currently)
|
||||
* @return the created menu
|
||||
* @since 1
|
||||
*/
|
||||
static @NotNull Menu create(@NotNull Plugin owner, @NotNull String title, int rowCount) {
|
||||
return BackendAPI.getImplementation().createMenu(owner, title, rowCount);
|
||||
}
|
||||
|
||||
void setIcon(int row, int column, Icon icon);
|
||||
/**
|
||||
* Sets the icon in a given position, overriding the previous one if present.
|
||||
*
|
||||
* @param row the row position
|
||||
* @param column the column position
|
||||
* @param icon the new icon, null to remove the current one
|
||||
* @since 1
|
||||
*/
|
||||
void setIcon(int row, int column, @Nullable Icon icon);
|
||||
|
||||
Icon getIcon(int row, int column);
|
||||
/**
|
||||
* Returns the icon in a given position.
|
||||
*
|
||||
* @param row the row position
|
||||
* @param column the column position
|
||||
* @return the icon at the give position, null if absent
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable Icon getIcon(int row, int column);
|
||||
|
||||
String getTitle();
|
||||
/**
|
||||
* Returns the title of the displayed inventory.
|
||||
*
|
||||
* @return the title
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull String getTitle();
|
||||
|
||||
/**
|
||||
* Returns the amount of rows of the displayed inventory.
|
||||
*
|
||||
* @return the amount of rows
|
||||
* @since 1
|
||||
*/
|
||||
int getRowCount();
|
||||
|
||||
/**
|
||||
* Returns the amount of columns of the displayed inventory.
|
||||
*
|
||||
* @return the amount of columns
|
||||
* @since 1
|
||||
*/
|
||||
int getColumnCount();
|
||||
|
||||
/**
|
||||
* Opens a view of the current menu configuration.
|
||||
* Updating the menu doesn't automatically update all the views.
|
||||
* Displays the menu to a player, creating a rendering of this menu and its icons.
|
||||
* <p>
|
||||
* If icons are added, removed or changed after the menu is displayed to a player, the view is not updated
|
||||
* automatically and you may want to invoke {@link Menu#refreshOpenMenuViews()}.
|
||||
*
|
||||
* @param player the player to which the menu will be displayed
|
||||
* @return the newly created view for the player
|
||||
* @since 1
|
||||
*/
|
||||
MenuView open(Player player);
|
||||
@NotNull MenuView open(@NotNull Player player);
|
||||
|
||||
void refreshMenuViews();
|
||||
/**
|
||||
* Refreshes all the menu views currently open and visible by players, reflecting the changes in the icons of this
|
||||
* menu and updating placeholders.
|
||||
* <p>
|
||||
* This method should be called after adding, removing or changing one or more icons to update the open menu views
|
||||
* of players.
|
||||
* <p>
|
||||
* This method invokes {@link MenuView#refresh()} on each open view created by this menu.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
void refreshOpenMenuViews();
|
||||
|
||||
}
|
|
@ -6,13 +6,49 @@
|
|||
package me.filoghost.chestcommands.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A menu view is a rendering of a menu and its icons, made of an {@link Inventory} and {@link ItemStack}s, which can be
|
||||
* displayed to a player. Modifying the menu doesn't automatically refresh all the views.
|
||||
* <p>
|
||||
* Each menu view is linked only to one player, since icons may contain player-relative placeholders.
|
||||
* <p>
|
||||
* A new view is created each time a menu is displayed to a player with {@link Menu#open(Player)}.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface MenuView {
|
||||
|
||||
/**
|
||||
* Refreshes the current view by re-rendering icons, reflecting the changes in the menu and updating placeholders.
|
||||
* <p>
|
||||
* For example, this method should be called inside a {@link ClickHandler} if it changes the amount of money of the
|
||||
* player and you want to refresh the money placeholder instantly.
|
||||
* <p>
|
||||
* Note that {@link ClickHandler} exposes the menu view being interacted with, so you don't need to refresh all the
|
||||
* views of a menu through {@link Menu#refreshOpenMenuViews()}.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
void refresh();
|
||||
|
||||
Player getViewer();
|
||||
/**
|
||||
* Returns the player linked to this view.
|
||||
*
|
||||
* @return the player
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull Player getViewer();
|
||||
|
||||
Menu getMenu();
|
||||
/**
|
||||
* Returns the menu that generated this view.
|
||||
*
|
||||
* @return the menu
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull Menu getMenu();
|
||||
|
||||
}
|
||||
|
|
|
@ -6,9 +6,34 @@
|
|||
package me.filoghost.chestcommands.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Callback to provide a placeholder replacement.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PlaceholderReplacer {
|
||||
|
||||
String getReplacement(Player player, String argument);
|
||||
/**
|
||||
* Callback for providing a placeholder replacement, given a player and the argument of the placeholder (if
|
||||
* present).
|
||||
* <p>
|
||||
* For example, the placeholder {test} has a null argument and the placeholder {test: hello world} has the string
|
||||
* argument "hello world".
|
||||
* <p>
|
||||
* If this method returns null, the placeholder is not replaced. It is preferred to return a descriptive error
|
||||
* message rather than returning null.
|
||||
*
|
||||
* @param player the player viewing the placeholder
|
||||
* @param argument the argument inside the placeholder, if present
|
||||
* @return the placeholder replacement, null to not replace
|
||||
* @see ChestCommandsAPI#registerPlaceholder(Plugin, String, PlaceholderReplacer)
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable String getReplacement(@NotNull Player player, @Nullable String argument);
|
||||
|
||||
}
|
||||
|
|
|
@ -7,15 +7,40 @@ package me.filoghost.chestcommands.api;
|
|||
|
||||
import me.filoghost.chestcommands.api.internal.BackendAPI;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* An {@link Icon} which statically displays a given {@link ItemStack}.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface StaticIcon extends ClickableIcon {
|
||||
|
||||
static StaticIcon create(ItemStack itemStack) {
|
||||
|
||||
/**
|
||||
* Creates a new static icon with the given item stack.
|
||||
*
|
||||
* @param itemStack the item stack to display
|
||||
* @return the created icon
|
||||
* @since 1
|
||||
*/
|
||||
static @NotNull StaticIcon create(@NotNull ItemStack itemStack) {
|
||||
return BackendAPI.getImplementation().createStaticIcon(itemStack);
|
||||
}
|
||||
|
||||
ItemStack getItemStack();
|
||||
/**
|
||||
* Sets the item stack to display.
|
||||
*
|
||||
* @param itemStack the new displayed item stack
|
||||
* @since 1
|
||||
*/
|
||||
void setItemStack(@NotNull ItemStack itemStack);
|
||||
|
||||
void setItemStack(ItemStack itemStack);
|
||||
/**
|
||||
* Returns the displayed item stack.
|
||||
*
|
||||
* @return the current displayed item stack
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull ItemStack getItemStack();
|
||||
|
||||
}
|
||||
|
|
|
@ -14,34 +14,42 @@ import org.bukkit.Material;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Do not use this class: it is intended only for internal use and may change at any time.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public abstract class BackendAPI {
|
||||
|
||||
private static BackendAPI implementation;
|
||||
|
||||
public static void setImplementation(BackendAPI implementation) {
|
||||
public static void setImplementation(@NotNull BackendAPI implementation) {
|
||||
Preconditions.notNull(implementation, "implementation");
|
||||
Preconditions.checkState(BackendAPI.implementation == null, "implementation already set");
|
||||
|
||||
BackendAPI.implementation = implementation;
|
||||
}
|
||||
|
||||
public static BackendAPI getImplementation() {
|
||||
public static @NotNull BackendAPI getImplementation() {
|
||||
Preconditions.checkState(implementation != null, "no implementation set");
|
||||
|
||||
return implementation;
|
||||
}
|
||||
|
||||
public abstract boolean pluginMenuExists(String menuFileName);
|
||||
public abstract boolean pluginMenuExists(@NotNull String menuFileName);
|
||||
|
||||
public abstract boolean openPluginMenu(Player player, String menuFileName);
|
||||
public abstract boolean openPluginMenu(@NotNull Player player, @NotNull String menuFileName);
|
||||
|
||||
public abstract Menu createMenu(Plugin owner, String title, int rows);
|
||||
public abstract @NotNull Menu createMenu(@NotNull Plugin owner, @NotNull String title, int rows);
|
||||
|
||||
public abstract ConfigurableIcon createConfigurableIcon(Material material);
|
||||
public abstract @NotNull ConfigurableIcon createConfigurableIcon(@NotNull Material material);
|
||||
|
||||
public abstract StaticIcon createStaticIcon(ItemStack itemStack);
|
||||
public abstract @NotNull StaticIcon createStaticIcon(@NotNull ItemStack itemStack);
|
||||
|
||||
public abstract void registerPlaceholder(Plugin plugin, String identifier, PlaceholderReplacer placeholderReplacer);
|
||||
public abstract void registerPlaceholder(@NotNull Plugin plugin,
|
||||
@NotNull String identifier,
|
||||
@NotNull PlaceholderReplacer placeholderReplacer);
|
||||
|
||||
}
|
||||
|
|
|
@ -134,6 +134,10 @@
|
|||
<module name="SingleLineJavadoc"/>
|
||||
<module name="SummaryJavadoc"/>
|
||||
|
||||
<!-- Javadoc for API -->
|
||||
<module name="MissingJavadocMethod"/>
|
||||
<module name="MissingJavadocType"/>
|
||||
|
||||
<!-- Miscellaneous -->
|
||||
<module name="ArrayTypeStyle"/>
|
||||
<module name="AvoidEscapedUnicodeCharacters"/>
|
||||
|
|
|
@ -4,5 +4,10 @@
|
|||
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
|
||||
|
||||
<suppressions>
|
||||
<suppress checks="Header|EqualsHashCode" files="[\\/]me[\\/]filoghost[\\/]chestcommands[\\/]util[\\/]nbt[\\/].+\.java"/>
|
||||
<suppress
|
||||
checks="Header|EqualsHashCode"
|
||||
files="[\\/]me[\\/]filoghost[\\/]chestcommands[\\/]util[\\/]nbt[\\/].+\.java"/>
|
||||
<suppress
|
||||
checks="MissingJavadocMethod|MissingJavadocType"
|
||||
files="[\\/]me[\\/]filoghost[\\/]chestcommands[\\/](?!api[\\/](?!internal[\\/])).+\.java"/>
|
||||
</suppressions>
|
|
@ -125,6 +125,7 @@ public class CommandHandler extends MultiCommandManager {
|
|||
@MinArgs(1)
|
||||
@UsageArgs("<menu> [player]")
|
||||
@DisplayPriority(1)
|
||||
@SuppressWarnings("deprecation")
|
||||
public void open(CommandSender sender, String[] args) throws CommandException {
|
||||
Player target;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ public class Settings implements MappedConfig {
|
|||
public static boolean update_notifications = true;
|
||||
public static int anti_click_spam_delay = 200;
|
||||
|
||||
@Override
|
||||
public List<String> getHeader() {
|
||||
return Arrays.asList(
|
||||
"ChestCommands main configuration file.",
|
||||
|
|
|
@ -164,7 +164,7 @@ public abstract class BaseConfigurableIcon implements Icon {
|
|||
addEnchantment(enchantment, 1);
|
||||
}
|
||||
|
||||
public void addEnchantment(Enchantment enchantment, Integer level) {
|
||||
public void addEnchantment(Enchantment enchantment, int level) {
|
||||
if (enchantments == null) {
|
||||
enchantments = new HashMap<>();
|
||||
}
|
||||
|
@ -220,6 +220,10 @@ public abstract class BaseConfigurableIcon implements Icon {
|
|||
cachedRendering = null;
|
||||
}
|
||||
|
||||
public boolean isPlaceholdersEnabled() {
|
||||
return placeholdersEnabled;
|
||||
}
|
||||
|
||||
public void setPlaceholdersEnabled(boolean placeholdersEnabled) {
|
||||
this.placeholdersEnabled = placeholdersEnabled;
|
||||
cachedRendering = null;
|
||||
|
|
|
@ -68,7 +68,7 @@ public abstract class BaseMenu implements Menu {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void refreshMenuViews() {
|
||||
public void refreshOpenMenuViews() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
DefaultMenuView menuView = MenuManager.getOpenMenuView(player);
|
||||
if (menuView != null && menuView.getMenu() == this) {
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
*/
|
||||
package me.filoghost.chestcommands.parsing.icon;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import me.filoghost.chestcommands.attribute.ActionsAttribute;
|
||||
import me.filoghost.chestcommands.attribute.AmountAttribute;
|
||||
import me.filoghost.chestcommands.attribute.AttributeErrorHandler;
|
||||
|
@ -34,6 +32,9 @@ import me.filoghost.fcommons.config.ConfigValue;
|
|||
import me.filoghost.fcommons.config.ConfigValueType;
|
||||
import me.filoghost.fcommons.config.exception.ConfigValueException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum AttributeType {
|
||||
|
||||
POSITION_X("POSITION-X", ConfigValueType.INTEGER, PositionAttribute::new),
|
||||
|
|
23
pom.xml
23
pom.xml
|
@ -129,6 +129,15 @@
|
|||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>20.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
|
||||
|
@ -148,6 +157,20 @@
|
|||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<sourceFileIncludes>
|
||||
<include>**/chestcommands/api/**/*.java</include>
|
||||
</sourceFileIncludes>
|
||||
<sourceFileExcludes>
|
||||
<exclude>**/chestcommands/api/internal/**/*.java</exclude>
|
||||
</sourceFileExcludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
|
|
Loading…
Reference in New Issue