diff --git a/API/src/main/java/fr/maxlego08/menu/api/ButtonManager.java b/API/src/main/java/fr/maxlego08/menu/api/ButtonManager.java index 8e13e8fb..bb76dda5 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/ButtonManager.java +++ b/API/src/main/java/fr/maxlego08/menu/api/ButtonManager.java @@ -5,12 +5,14 @@ import fr.maxlego08.menu.api.loader.ActionLoader; import fr.maxlego08.menu.api.loader.ButtonLoader; import fr.maxlego08.menu.api.loader.PermissibleLoader; +import fr.maxlego08.menu.api.pattern.ActionPattern; import fr.maxlego08.menu.api.requirement.Action; import fr.maxlego08.menu.api.requirement.Permissible; import fr.maxlego08.menu.api.requirement.Requirement; import fr.maxlego08.menu.api.utils.Loader; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.util.Collection; @@ -34,7 +36,7 @@ public interface ButtonManager { * * @param button The {@link ButtonLoader} instance to register. */ - void register(ButtonLoader button); + void register(@NotNull ButtonLoader button); /** * Unregisters an existing {@link ButtonLoader}, ceasing its button creation responsibilities. @@ -142,6 +144,8 @@ public interface ButtonManager { */ List loadActions(List> elements, String path, File file); + List loadActions(List> elements, String path, File file, @NotNull List defaultActions, boolean useSuccess, boolean stopOnEmpty); + /** * Converts a list of map elements from a configuration file into a list of {@link Action} objects. * @@ -154,6 +158,8 @@ public interface ButtonManager { */ List loadActions(YamlConfiguration configuration, String path, File file); + List loadActions(YamlConfiguration configuration, String path, File file, @NotNull List defaultActions, boolean useSuccess, boolean stopOnEmpty); + List loadRequirements(YamlConfiguration configuration, String path, File file) throws InventoryException; Requirement loadRequirement(YamlConfiguration configuration, String path, File file) throws InventoryException; diff --git a/API/src/main/java/fr/maxlego08/menu/api/button/Button.java b/API/src/main/java/fr/maxlego08/menu/api/button/Button.java index b6dbc099..7a29a046 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/button/Button.java +++ b/API/src/main/java/fr/maxlego08/menu/api/button/Button.java @@ -19,6 +19,9 @@ import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -51,10 +54,14 @@ public abstract class Button extends PlaceholderButton { private int priority; // only use for convert DeluxeMenus config to zmenu object private boolean isInPlayerInventory; + @Contract(pure = true) + @Nullable public String getName() { return this.buttonName; } + @Contract(pure = true) + @Nullable public MenuItemStack getItemStack() { return this.itemStack; } @@ -62,20 +69,20 @@ public MenuItemStack getItemStack() { /** * @param itemStack the itemStack to set */ - public Button setItemStack(MenuItemStack itemStack) { + @Contract("_ -> this") + public Button setItemStack(@Nullable MenuItemStack itemStack) { this.itemStack = itemStack; return this; } - public ItemStack getCustomItemStack(Player player) { + @Contract(pure = true) + @Nullable + public ItemStack getCustomItemStack(@NotNull Player player) { if (this.itemStack == null) return null; - ItemStack itemStack = this.itemStack.build(player, this.useCache); - if (this.playerHead != null && itemStack.getItemMeta() instanceof SkullMeta) { return this.plugin.getInventoryManager().postProcessSkullItemStack(itemStack, this, player); } - return itemStack; } @@ -86,6 +93,7 @@ public int getSlot() { /** * @param slot the slot to set */ + @Contract("_ -> this") public Button setSlot(int slot) { this.slots = new ArrayList<>(); this.slots.add(slot); @@ -96,6 +104,7 @@ public boolean isClickable() { return true; } + @Contract(pure = true) public boolean isPermanent() { return this.isPermanent; } @@ -103,42 +112,59 @@ public boolean isPermanent() { /** * @param isPermanent the isPermanent to set */ + @Contract("_ -> this") + @NotNull public Button setPermanent(boolean isPermanent) { this.isPermanent = isPermanent; return this; } + @Contract(pure = true) + @NotNull public List getMessages() { return this.messages; } - public Button setMessages(List messages) { + @Contract("_ -> this") + @NotNull + public Button setMessages(@NotNull List messages) { this.messages = messages; return this; } + @Contract(pure = true) public int getRealSlot(int inventorySize, int page) { int slot = getSlot(); return this.isPermanent() ? slot : slot - ((page - 1) * inventorySize); } + @Contract(pure = true) + @Nullable public SoundOption getSound() { return this.soundOption; } + @Contract(pure = true) public boolean hasSpecialRender() { return this.getSlots().size() > 1; } + @Contract(pure = true) + @Nullable public String getPlayerHead() { return this.playerHead; } - public Button setPlayerHead(String playerHead) { + /** + * @param playerHead the playerHead to set + */ + @Contract("_ -> this") + public Button setPlayerHead(@Nullable String playerHead) { this.playerHead = playerHead; return this; } + @Contract(pure = true) public void onRender(Player player, InventoryEngine inventoryEngine) { if (inventoryEngine.getPage() == this.getPage() || this.isPermanent()) { @@ -157,19 +183,46 @@ public void onRender(Player player, InventoryEngine inventoryEngine) { } } - public void onLeftClick(Player player, InventoryClickEvent event, InventoryEngine inventory, int slot) { + /** + * Called when the left mouse button is clicked + * @param player the player + * @param event the inventory click event + * @param inventory the inventory + * @param slot the slot + */ + public void onLeftClick(@NotNull Player player,@NotNull InventoryClickEvent event,@NotNull InventoryEngine inventory, int slot) { } - public void onRightClick(Player player, InventoryClickEvent event, InventoryEngine inventory, int slot) { + /** + * Called when the right mouse button is clicked + * @param player the player + * @param event the inventory click event + * @param inventory the inventory + * @param slot the slot + */ + public void onRightClick(@NotNull Player player,@NotNull InventoryClickEvent event,@NotNull InventoryEngine inventory, int slot) { } - public void onMiddleClick(Player player, InventoryClickEvent event, InventoryEngine inventory, int slot) { + /** + * Called when the middle mouse button is clicked + * @param player the player + * @param event the inventory click event + * @param inventory the inventory + * @param slot the slot + */ + public void onMiddleClick(@NotNull Player player,@NotNull InventoryClickEvent event,@NotNull InventoryEngine inventory, int slot) { } - public void onInventoryClose(Player player, InventoryEngine inventory) { + /** + * Called when the inventory is closed + * @param player the player + * @param inventory the inventory + */ + public void onInventoryClose(@NotNull Player player,@NotNull InventoryEngine inventory) { } - public void onClick(Player player, InventoryClickEvent event, InventoryEngine inventory, int slot, Placeholders placeholders) { + @Contract(pure = true) + public void onClick(@NotNull Player player,@NotNull InventoryClickEvent event,@NotNull InventoryEngine inventory, int slot,@NotNull Placeholders placeholders) { if (this.closeInventory()) { player.closeInventory(); } @@ -208,30 +261,43 @@ public void onClick(Player player, InventoryClickEvent event, InventoryEngine in this.execute(this.plugin, event.getClick(), placeholders, player); } - public void onInventoryOpen(Player player, InventoryEngine inventory, Placeholders placeholders) { + /** + * Called when the inventory is opened + * @param player the player + * @param inventory the inventory + * @param placeholders the placeholders + */ + public void onInventoryOpen(@NotNull Player player,@NotNull InventoryEngine inventory,@NotNull Placeholders placeholders) { } + @Contract(pure = true) public boolean closeInventory() { return this.closeInventory; } + @Contract("_ -> this") + @NotNull public Button setButtonName(String buttonName) { this.buttonName = buttonName; return this; } + @Contract("_ -> this") + @NotNull public Button setCloseInventory(boolean closeInventory) { this.closeInventory = closeInventory; return this; } + @Contract("_ -> this") + @NotNull public Button setSoundOption(SoundOption soundOption) { this.soundOption = soundOption; return this; } - + @Contract(pure = true) public OpenLink getOpenLink() { return this.openLink; } @@ -240,7 +306,7 @@ public void setOpenLink(OpenLink openLink) { this.openLink = openLink; } - + @Contract(pure = true) public boolean isUpdated() { return this.isUpdated; } @@ -249,7 +315,7 @@ public void setUpdated(boolean isUpdated) { this.isUpdated = isUpdated; } - + @Contract(pure = true) public boolean isRefreshOnClick() { return this.refreshOnClick; } @@ -258,20 +324,21 @@ public void setRefreshOnClick(boolean refreshOnClick) { this.refreshOnClick = refreshOnClick; } - + @Contract(pure = true) + @Nullable public List getData() { return this.datas; } - public void setDatas(List datas) { + public void setDatas(@Nullable List datas) { this.datas = datas; } - public void setPlugin(MenuPlugin plugin) { + public void setPlugin(@Nullable MenuPlugin plugin) { this.plugin = plugin; } - + @Contract(pure = true) public boolean updateOnClick() { return this.updateOnClick; } @@ -280,57 +347,87 @@ public void setUpdateOnClick(boolean updateOnClick) { this.updateOnClick = updateOnClick; } - + @Contract(pure = true) public List buildLore(Player player) { return this.itemStack.getLore(); } - + @Contract(pure = true) public String buildDisplayName(Player player) { return this.itemStack.getDisplayName(); } - public void onBackClick(Player player, InventoryClickEvent event, InventoryEngine inventory, List oldInventories, Inventory toInventory, int slot) { + /** + * Called when the back button is clicked + * @param player the player + * @param event the inventory click event + * @param inventory the inventory + * @param oldInventories the old inventories + * @param toInventory the to inventory + * @param slot the slot + */ + public void onBackClick(@NotNull Player player,@NotNull InventoryClickEvent event,@NotNull InventoryEngine inventory,@NotNull List oldInventories,@NotNull Inventory toInventory, int slot) { } + @Contract(pure = true) + @Nullable public List getClickRequirements() { return this.clickRequirements; } - public void setClickRequirements(List clickRequirements) { + public void setClickRequirements(@Nullable List clickRequirements) { this.clickRequirements = clickRequirements; } + @Contract(pure = true) + @Nullable public Requirement getViewRequirement() { return this.viewRequirement; } - public void setViewRequirement(Requirement viewRequirement) { + public void setViewRequirement(@Nullable Requirement viewRequirement) { this.viewRequirement = viewRequirement; } + @Contract(pure = true) + @Override public boolean hasPermission() { return this.viewRequirement != null || super.hasPermission(); } - public boolean checkPermission(Player player, InventoryEngine inventory, Placeholders placeholders) { + public boolean checkPermission(@NotNull Player player,@NotNull InventoryEngine inventory,@NotNull Placeholders placeholders) { return super.checkPermission(player, inventory, placeholders) && (this.viewRequirement == null || this.viewRequirement.execute(player, this, inventory, placeholders)); } + @Contract(pure = true) + @Nullable public List getActions() { return this.actions; } - public void setActions(List actions) { + public void setActions(@Nullable List actions) { this.actions = actions; } - public void onDrag(InventoryDragEvent event, Player player, InventoryEngine inventoryDefault) { + /** + * Called when the inventory is dragged + * @param event the inventory drag event + * @param player the player + * @param inventoryDefault the inventory engine + */ + public void onDrag(@NotNull InventoryDragEvent event,@NotNull Player player,@NotNull InventoryEngine inventoryDefault) { } - public void onInventoryClick(InventoryClickEvent event, Player player, InventoryEngine inventoryDefault) { + /** + * Called when the inventory is clicked + * @param event the inventory click event + * @param player the player + * @param inventoryDefault the inventory engine + */ + public void onInventoryClick(@NotNull InventoryClickEvent event,@NotNull Player player,@NotNull InventoryEngine inventoryDefault) { } + @Contract(pure = true) public boolean isUseCache() { return this.useCache; } @@ -339,49 +436,56 @@ public void setUseCache(boolean useCache) { this.useCache = useCache; } + @Contract(pure = true) + @Nullable public List getOptions() { return this.options; } - public void setOptions(List options) { + public void setOptions(@Nullable List options) { this.options = options; } + @Contract(pure = true) public boolean hasCustomRender() { return false; } + @Contract(pure = true) public boolean isUpdatedMasterButton() { return this.isMasterButtonUpdated; } public void setMasterButtonUpdated(boolean masterButtonUpdated) { - isMasterButtonUpdated = masterButtonUpdated; + this.isMasterButtonUpdated = masterButtonUpdated; } + @Contract(pure = true) public boolean isOpenAsync() { - return isOpenAsync; + return this.isOpenAsync; } public void setOpenAsync(boolean openAsync) { - isOpenAsync = openAsync; + this.isOpenAsync = openAsync; } - public boolean hasRefreshRequirement() { return this.refreshRequirement != null; } + @Contract(pure = true) + @Nullable public RefreshRequirement getRefreshRequirement() { - return refreshRequirement; + return this.refreshRequirement; } - public void setRefreshRequirement(RefreshRequirement refreshRequirement) { + public void setRefreshRequirement(@Nullable RefreshRequirement refreshRequirement) { this.refreshRequirement = refreshRequirement; } + @Contract(pure = true) public int getPriority() { - return priority; + return this.priority; } public void setPriority(int priority) { @@ -399,7 +503,7 @@ public void setPriority(int priority) { * itself * @param the type of the elements */ - protected void paginate(List elements, InventoryEngine inventory, BiConsumer consumer) { + protected void paginate(@NotNull List elements,@NotNull InventoryEngine inventory,@NotNull BiConsumer consumer) { Pagination pagination = new Pagination<>(); elements = pagination.paginate(elements, this.slots.size(), inventory.getPage()); @@ -410,12 +514,12 @@ protected void paginate(List elements, InventoryEngine inventory, BiConsu } } - /** * Returns whether this button is displayed in the player's inventory. * * @return true if this button is displayed in the player's inventory, false otherwise */ + @Contract(pure = true) public boolean isPlayerInventory() { return this.isInPlayerInventory; } @@ -438,6 +542,7 @@ public void setPlayerInventory(boolean inPlayerInventory) { * @param player the player to display the button for * @return the button to display */ + @Contract(pure = true, value = "_, _ -> this") public Button getDisplayButton(InventoryEngine inventoryEngine, Player player) { return this; } @@ -451,7 +556,7 @@ public Button getDisplayButton(InventoryEngine inventoryEngine, Player player) { * @param placeholders the placeholders to use * @return the built item stack */ - protected ItemStack buildAsOwner(Player player, OfflinePlayer owner, Placeholders placeholders) { + protected ItemStack buildAsOwner(@NotNull Player player,@NotNull OfflinePlayer owner,@NotNull Placeholders placeholders) { ItemStack itemStack = getItemStack().build(player, false, placeholders); SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta(); skullMeta.setOwningPlayer(owner); diff --git a/API/src/main/java/fr/maxlego08/menu/api/button/DefaultButtonValue.java b/API/src/main/java/fr/maxlego08/menu/api/button/DefaultButtonValue.java index ba9551d6..d723cbbd 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/button/DefaultButtonValue.java +++ b/API/src/main/java/fr/maxlego08/menu/api/button/DefaultButtonValue.java @@ -1,5 +1,9 @@ package fr.maxlego08.menu.api.button; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + import java.io.File; import java.util.ArrayList; import java.util.List; @@ -46,8 +50,9 @@ public DefaultButtonValue(int inventorySize, Map> matri * * @return The default slot value. */ + @Contract(pure = true) public int getSlot() { - return slot; + return this.slot; } /** @@ -64,8 +69,9 @@ public void setSlot(int slot) { * * @return The default page value. */ + @Contract(pure = true) public int getPage() { - return page; + return this.page; } /** @@ -82,8 +88,9 @@ public void setPage(int page) { * * @return The default list of slots. */ + @Contract(pure = true) public List getSlots() { - return slots; + return this.slots; } /** @@ -91,7 +98,7 @@ public List getSlots() { * * @param slots The default list of slots to set. */ - public void setSlots(List slots) { + public void setSlots(@NotNull List slots) { this.slots = slots; } @@ -100,8 +107,9 @@ public void setSlots(List slots) { * * @return The default isPermanent value. */ + @Contract(pure = true) public boolean isPermanent() { - return isPermanent; + return this.isPermanent; } /** @@ -110,7 +118,7 @@ public boolean isPermanent() { * @param permanent The default isPermanent value to set. */ public void setPermanent(boolean permanent) { - isPermanent = permanent; + this.isPermanent = permanent; } /** @@ -118,8 +126,9 @@ public void setPermanent(boolean permanent) { * * @return The default updateOnClick value. */ + @Contract(pure = true) public boolean isUpdateOnClick() { - return updateOnClick; + return this.updateOnClick; } /** @@ -136,8 +145,9 @@ public void setUpdateOnClick(boolean updateOnClick) { * * @return The default closeInventory value. */ + @Contract(pure = true) public boolean isCloseInventory() { - return closeInventory; + return this.closeInventory; } /** @@ -145,6 +155,7 @@ public boolean isCloseInventory() { * * @param closeInventory The default closeInventory value to set. */ + @Contract(pure = true) public void setCloseInventory(boolean closeInventory) { this.closeInventory = closeInventory; } @@ -154,8 +165,9 @@ public void setCloseInventory(boolean closeInventory) { * * @return The default update value. */ + @Contract(pure = true) public boolean isUpdate() { - return update; + return this.update; } /** @@ -172,8 +184,9 @@ public void setUpdate(boolean update) { * * @return The default refreshOnClick value. */ + @Contract(pure = true) public boolean isRefreshOnClick() { - return refreshOnClick; + return this.refreshOnClick; } /** @@ -190,8 +203,10 @@ public void setRefreshOnClick(boolean refreshOnClick) { * * @return The default playerHead value. */ + @Contract(pure = true) + @Nullable public String getPlayerHead() { - return playerHead; + return this.playerHead; } /** @@ -199,35 +214,41 @@ public String getPlayerHead() { * * @param playerHead The default playerHead value to set. */ - public void setPlayerHead(String playerHead) { + public void setPlayerHead(@Nullable String playerHead) { this.playerHead = playerHead; } + @Contract(pure = true) public boolean isUseCache() { - return useCache; + return this.useCache; } public void setUseCache(boolean useCache) { this.useCache = useCache; } + @Contract(pure = true) public boolean isUpdateMasterButton() { - return updateMasterButton; + return this.updateMasterButton; } public void setUpdateMasterButton(boolean updateMasterButton) { this.updateMasterButton = updateMasterButton; } + @Contract(pure = true) public int getInventorySize() { - return inventorySize; + return this.inventorySize; } + @Contract(pure = true) public Map> getMatrix() { - return matrix; + return this.matrix; } + @Contract(pure = true) + @Nullable public File getFile() { - return file; + return this.file; } } diff --git a/API/src/main/java/fr/maxlego08/menu/api/button/PaginateButton.java b/API/src/main/java/fr/maxlego08/menu/api/button/PaginateButton.java index 6344dad3..abecf384 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/button/PaginateButton.java +++ b/API/src/main/java/fr/maxlego08/menu/api/button/PaginateButton.java @@ -1,17 +1,21 @@ package fr.maxlego08.menu.api.button; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; public abstract class PaginateButton extends Button { - public abstract int getPaginationSize(Player player); + public abstract int getPaginationSize(@NotNull Player player); @Override + @Contract(pure = true) public boolean hasSpecialRender() { return true; } @Override + @Contract(pure = true) public boolean isPermanent() { return true; } diff --git a/API/src/main/java/fr/maxlego08/menu/api/button/PerformButton.java b/API/src/main/java/fr/maxlego08/menu/api/button/PerformButton.java index 80f0e9fd..2fa79a17 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/button/PerformButton.java +++ b/API/src/main/java/fr/maxlego08/menu/api/button/PerformButton.java @@ -2,12 +2,16 @@ import com.tcoded.folialib.impl.PlatformScheduler; import fr.maxlego08.menu.api.MenuPlugin; -import fr.maxlego08.menu.api.configuration.Config; +import fr.maxlego08.menu.api.configuration.Configuration; import fr.maxlego08.menu.api.utils.Placeholders; +import fr.maxlego08.menu.zcore.logger.Logger; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -23,6 +27,8 @@ public abstract class PerformButton extends SlotButton { private List consolePermissionCommands = new ArrayList<>(); private String consolePermission; + @Contract(pure = true) + @NotNull public List getCommands() { return this.commands; } @@ -30,10 +36,12 @@ public List getCommands() { /** * @param commands the commands to set */ - public void setCommands(List commands) { + public void setCommands(@NotNull List commands) { this.commands = commands; } + @Contract(pure = true) + @NotNull public List getLeftCommands() { return this.leftCommands; } @@ -41,10 +49,12 @@ public List getLeftCommands() { /** * @param leftCommands the left click commands to set */ - public void setLeftCommands(List leftCommands) { + public void setLeftCommands(@NotNull List leftCommands) { this.leftCommands = leftCommands; } + @Contract(pure = true) + @NotNull public List getRightCommands() { return this.rightCommands; } @@ -52,11 +62,12 @@ public List getRightCommands() { /** * @param rightCommands the right click commands to set */ - public void setRightCommands(List rightCommands) { + public void setRightCommands(@NotNull List rightCommands) { this.rightCommands = rightCommands; } - + @Contract(pure = true) + @NotNull public List getConsoleCommands() { return this.consoleCommands; } @@ -64,10 +75,12 @@ public List getConsoleCommands() { /** * @param consoleCommands the consoleCommands to set */ - public void setConsoleCommands(List consoleCommands) { + public void setConsoleCommands(@NotNull List consoleCommands) { this.consoleCommands = consoleCommands; } + @Contract(pure = true) + @NotNull public List getConsolePermissionCommands() { return this.consolePermissionCommands; } @@ -75,10 +88,12 @@ public List getConsolePermissionCommands() { /** * @param consolePermissionCommands the consolePermissionCommands to set */ - public void setConsolePermissionCommands(List consolePermissionCommands) { + public void setConsolePermissionCommands(@NotNull List consolePermissionCommands) { this.consolePermissionCommands = consolePermissionCommands; } + @Contract(pure = true) + @Nullable public String getConsolePermission() { return this.consolePermission; } @@ -86,10 +101,12 @@ public String getConsolePermission() { /** * @param consolePermission the consolePermission to set */ - public void setConsolePermission(String consolePermission) { + public void setConsolePermission(@Nullable String consolePermission) { this.consolePermission = consolePermission; } + @Contract(pure = true) + @NotNull public List getConsoleRightCommands() { return this.consoleRightCommands; } @@ -97,10 +114,12 @@ public List getConsoleRightCommands() { /** * @param consoleRightCommands the consoleRightCommands to set */ - public void setConsoleRightCommands(List consoleRightCommands) { + public void setConsoleRightCommands(@NotNull List consoleRightCommands) { this.consoleRightCommands = consoleRightCommands; } + @Contract(pure = true) + @NotNull public List getConsoleLeftCommands() { return this.consoleLeftCommands; } @@ -108,11 +127,12 @@ public List getConsoleLeftCommands() { /** * @param consoleLeftCommands the consoleLeftCommands to set */ - public void setConsoleLeftCommands(List consoleLeftCommands) { + public void setConsoleLeftCommands(@NotNull List consoleLeftCommands) { this.consoleLeftCommands = consoleLeftCommands; } - public void execute(MenuPlugin plugin, ClickType type, Placeholders placeholders, Player player) { + @Contract(pure = true) + public void execute(@NotNull MenuPlugin plugin, @NotNull ClickType type, @NotNull Placeholders placeholders, @NotNull Player player) { var scheduler = plugin.getScheduler(); if (type.isRightClick()) { @@ -142,14 +162,14 @@ public void execute(MenuPlugin plugin, ClickType type, Placeholders placeholders * @param scheduler the PlatformScheduler used to schedule the command executions * @param executor the CommandSender executing the commands */ - private void execute(MenuPlugin plugin, Player player, List strings, PlatformScheduler scheduler, Placeholders placeholders, CommandSender executor) { + @Contract(pure = true) + private void execute(@NotNull MenuPlugin plugin, @NotNull Player player, @NotNull List strings, @NotNull PlatformScheduler scheduler, @NotNull Placeholders placeholders, @NotNull CommandSender executor) { strings.forEach(command -> { command = placeholders.parse(command.replace("%player%", player.getName())); try { - if (executor instanceof Player && Config.enablePlayerCommandInChat) { + if (executor instanceof Player && Configuration.enablePlayerCommandInChat) { player.chat("/" + plugin.parse(player, command)); } else { - String finalCommand = command; Runnable runnable = () -> Bukkit.dispatchCommand(executor, plugin.parse(player, finalCommand)); if (plugin.isFolia()) { @@ -158,7 +178,10 @@ private void execute(MenuPlugin plugin, Player player, List strings, Pla } else runnable.run(); } } catch (Exception exception) { - exception.printStackTrace(); + if (Configuration.enableDebug){ + Logger.info("An error occurred while executing command: " + command); + exception.printStackTrace(); + } } }); } diff --git a/API/src/main/java/fr/maxlego08/menu/api/button/PermissibleButton.java b/API/src/main/java/fr/maxlego08/menu/api/button/PermissibleButton.java index 4c451fdc..8275cff3 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/button/PermissibleButton.java +++ b/API/src/main/java/fr/maxlego08/menu/api/button/PermissibleButton.java @@ -4,6 +4,9 @@ import fr.maxlego08.menu.api.requirement.permissible.PermissionPermissible; import fr.maxlego08.menu.api.utils.Placeholders; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -20,6 +23,8 @@ public abstract class PermissibleButton extends PerformButton { * * @return the button displayed when the current button does not have the required permissions */ + @Contract(pure = true) + @Nullable public Button getElseButton() { return this.elseButton; } @@ -29,7 +34,7 @@ public Button getElseButton() { * * @param elseButton the button displayed when the current button does not have the required permissions */ - public void setElseButton(Button elseButton) { + public void setElseButton(@Nullable Button elseButton) { this.elseButton = elseButton; } @@ -38,6 +43,7 @@ public void setElseButton(Button elseButton) { * * @return true if this button has any permissions, false otherwise */ + @Contract(pure = true) public boolean hasPermission() { return !this.permissions.isEmpty() || !this.orPermissions.isEmpty(); } @@ -47,6 +53,7 @@ public boolean hasPermission() { * * @return true if this button has an alternative button set using the "elseButton" method, false otherwise */ + @Contract(pure = true) public boolean hasElseButton() { return this.elseButton != null; } @@ -65,7 +72,8 @@ public boolean hasElseButton() { * @param placeholders the placeholders * @return true if the player has permission, false otherwise */ - public boolean checkPermission(Player player, InventoryEngine inventoryEngine, Placeholders placeholders) { + @Contract(pure = true) + public boolean checkPermission(@NotNull Player player, @NotNull InventoryEngine inventoryEngine, @NotNull Placeholders placeholders) { if (!this.orPermissions.isEmpty()) { for (PermissionPermissible permission : this.orPermissions) { @@ -95,6 +103,8 @@ public boolean checkPermission(Player player, InventoryEngine inventoryEngine, P * * @return the parent button of this button, or null if this button does not have a parent */ + @Contract(pure = true) + @Nullable public Button getParentButton() { return this.parentButton; } @@ -106,7 +116,7 @@ public Button getParentButton() { * * @param parentButton the parent button of this button */ - public void setParentButton(Button parentButton) { + public void setParentButton(@Nullable Button parentButton) { this.parentButton = parentButton; } @@ -117,6 +127,8 @@ public void setParentButton(Button parentButton) { * * @return the master parent button of this button */ + @Contract(pure = true) + @NotNull public Button getMasterParentButton() { Button button = this.getParentButton(); return button == null ? (Button) this : button.getMasterParentButton(); @@ -130,6 +142,8 @@ public Button getMasterParentButton() { * * @return the list of alternative permissions that can be used to satisfy the visibility requirement of this button */ + @Contract(pure = true) + @NotNull public List getOrPermission() { return this.orPermissions; } @@ -139,6 +153,8 @@ public List getOrPermission() { * * @return the list of permissions that must be met for this button to be visible */ + @Contract(pure = true) + @NotNull public List getPermissions() { return this.permissions; } @@ -150,7 +166,7 @@ public List getPermissions() { * * @param permissions the list of permissions that must be met for this button to be visible */ - public void setPermissions(List permissions) { + public void setPermissions(@NotNull List permissions) { this.permissions = permissions; } @@ -162,7 +178,7 @@ public void setPermissions(List permissions) { * * @param orPermissions the list of permissions that can be used to satisfy the visibility requirement of this button */ - public void setOrPermissions(List orPermissions) { + public void setOrPermissions(@NotNull List orPermissions) { this.orPermissions = orPermissions; } } diff --git a/API/src/main/java/fr/maxlego08/menu/api/button/PlaceholderButton.java b/API/src/main/java/fr/maxlego08/menu/api/button/PlaceholderButton.java index 75785225..3d8f8d01 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/button/PlaceholderButton.java +++ b/API/src/main/java/fr/maxlego08/menu/api/button/PlaceholderButton.java @@ -4,6 +4,8 @@ import fr.maxlego08.menu.api.requirement.permissible.PlaceholderPermissible; import fr.maxlego08.menu.api.utils.Placeholders; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; @@ -17,6 +19,8 @@ public abstract class PlaceholderButton extends PermissibleButton { * * @return the list of placeholders that must be met for this button to be visible */ + @Contract(pure = true) + @NotNull public List getPlaceholders() { return this.placeholders; } @@ -29,7 +33,7 @@ public List getPlaceholders() { * * @param placeholders the list of placeholders that must be met for this button to be visible */ - public void setPlaceholders(List placeholders) { + public void setPlaceholders(@NotNull List placeholders) { this.placeholders = placeholders; } @@ -38,6 +42,7 @@ public void setPlaceholders(List placeholders) { * * @return true if this button has any placeholders, false otherwise */ + @Contract(pure = true) public boolean hasPlaceHolder() { return this.placeholders != null && !this.placeholders.isEmpty(); } @@ -50,6 +55,7 @@ public boolean hasPlaceHolder() { * @return true if this button has any placeholders or permissions, false otherwise */ @Override + @Contract(pure = true) public boolean hasPermission() { return this.hasPlaceHolder() || super.hasPermission(); } @@ -70,7 +76,8 @@ public boolean hasPermission() { * @return true if the player has permission, false otherwise */ @Override - public boolean checkPermission(Player player, InventoryEngine inventoryEngine, Placeholders placeholders) { + @Contract(pure = true) + public boolean checkPermission(@NotNull Player player, @NotNull InventoryEngine inventoryEngine, @NotNull Placeholders placeholders) { // First check if player has permission if (!super.checkPermission(player, inventoryEngine, placeholders)) { return false; diff --git a/API/src/main/java/fr/maxlego08/menu/api/button/SlotButton.java b/API/src/main/java/fr/maxlego08/menu/api/button/SlotButton.java index 5cda31af..88afc5ef 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/button/SlotButton.java +++ b/API/src/main/java/fr/maxlego08/menu/api/button/SlotButton.java @@ -1,5 +1,8 @@ package fr.maxlego08.menu.api.button; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + import java.util.Collection; import java.util.List; @@ -13,6 +16,8 @@ public abstract class SlotButton { * * @return The list of slots used by this button. */ + @Contract(pure = true) + @NotNull public Collection getSlots() { return this.slots; } @@ -22,12 +27,13 @@ public Collection getSlots() { * * @param slots The list of slots to set. */ - public void setSlots(List slots) { + public void setSlots(@NotNull List slots) { this.slots = slots; } + @Contract(pure = true) public int getPage() { - return page; + return this.page; } /** diff --git a/API/src/main/java/fr/maxlego08/menu/api/button/dialogs/BodyButton.java b/API/src/main/java/fr/maxlego08/menu/api/button/dialogs/BodyButton.java index 9d48cd2d..251bc504 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/button/dialogs/BodyButton.java +++ b/API/src/main/java/fr/maxlego08/menu/api/button/dialogs/BodyButton.java @@ -2,6 +2,9 @@ import fr.maxlego08.menu.api.button.Button; import fr.maxlego08.menu.api.enums.DialogBodyType; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -14,78 +17,94 @@ public class BodyButton extends Button { private int height = 100; // Default height for items private boolean showDecorations = true; private boolean showTooltip = true; - private List descriptionMessages = new ArrayList<>(); + private @NotNull List descriptionMessages = new ArrayList<>(); private int descriptionWidth = 300; private int messageWidth = 300; + @Contract(pure = true) public DialogBodyType getBodyType() { - return bodyType; + return this.bodyType; } + @Contract("_ -> this") public BodyButton setBodyType(DialogBodyType bodyType) { this.bodyType = bodyType; return this; } + @Contract(pure = true) public int getWidth() { - return width; + return this.width; } + @Contract("_ -> this") public BodyButton setWidth(int width) { this.width = Math.max(1, Math.min(width, bodyType == DialogBodyType.ITEM ? 256 : 1024)); return this; } + @Contract(pure = true) public int getHeight() { - return height; + return this.height; } + @Contract("_ -> this") public BodyButton setHeight(int height) { this.height = Math.max(1, Math.min(height, 256)); return this; } + @Contract(pure = true) public boolean isShowDecorations() { - return showDecorations; + return this.showDecorations; } + @Contract("_ -> this") public BodyButton setShowDecorations(boolean showDecorations) { this.showDecorations = showDecorations; return this; } + @Contract(pure = true) public boolean isShowTooltip() { - return showTooltip; + return this.showTooltip; } + @Contract("_ -> this") public BodyButton setShowTooltip(boolean showTooltip) { this.showTooltip = showTooltip; return this; } + @Contract(pure = true) public List getDescriptionMessages() { - return descriptionMessages; + return this.descriptionMessages; } - public BodyButton setDescriptionMessages(List descriptionMessages) { + @Contract("_ -> this") + public BodyButton setDescriptionMessages(@Nullable List descriptionMessages) { this.descriptionMessages = descriptionMessages != null ? descriptionMessages : new ArrayList<>(); return this; } + @Contract(pure = true) public int getDescriptionWidth() { - return descriptionWidth; + return this.descriptionWidth; } + @Contract("_ -> this") public BodyButton setDescriptionWidth(int descriptionWidth) { this.descriptionWidth = Math.max(1, Math.min(descriptionWidth, 1024)); return this; } + @Contract(pure = true) public int getMessageWidth() { - return messageWidth; + return this.messageWidth; } + @Contract("_ -> this") public BodyButton setMessageWidth(int messageWidth) { this.messageWidth = Math.max(1, Math.min(messageWidth, 1024)); return this; diff --git a/API/src/main/java/fr/maxlego08/menu/api/button/dialogs/InputButton.java b/API/src/main/java/fr/maxlego08/menu/api/button/dialogs/InputButton.java index 70cbdc78..7b71dafd 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/button/dialogs/InputButton.java +++ b/API/src/main/java/fr/maxlego08/menu/api/button/dialogs/InputButton.java @@ -3,6 +3,9 @@ import fr.maxlego08.menu.api.button.Button; import fr.maxlego08.menu.api.enums.DialogInputType; import fr.maxlego08.menu.api.utils.dialogs.record.SingleOption; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Optional; @@ -43,198 +46,255 @@ public class InputButton extends Button { private Supplier initialValueRangeSupplier; private String labelFormat = "options.generic_value"; // Default label format - + @Contract(pure = true) public DialogInputType getInputType() { return inputType; } - public InputButton setInputType(DialogInputType inputType) { + @Contract("_ -> this") + public InputButton setInputType(@NotNull DialogInputType inputType) { this.inputType = inputType; return this; } + @Contract(pure = true) + @Nullable public String getLabel() { return label; } - public InputButton setLabel(String label) { + @Contract("_ -> this") + public InputButton setLabel(@Nullable String label) { this.label = label; return this; } + @Contract(pure = true) public boolean isLabelVisible() { return labelVisible; } + @Contract("_ -> this") public InputButton setLabelVisible(boolean labelVisible) { this.labelVisible = labelVisible; return this; } + @Contract(pure = true) public int getWidth() { return width; } + @Contract("_ -> this") public InputButton setWidth(int width) { this.width = width; return this; } + @Contract(pure = true) + @NotNull public String getDefaultText() { return defaultText; } - public InputButton setDefaultText(String defaultText) { + @Contract("_ -> this") + public InputButton setDefaultText(@NotNull String defaultText) { this.defaultText = defaultText; return this; } + @Contract(pure = true) public int getMaxLength() { return maxLength; } + @Contract("_ -> this") public InputButton setMaxLength(int maxLength) { this.maxLength = maxLength; return this; } + @Contract(pure = true) public int getMultilineMaxLines() { return multilineMaxLines; } + @Contract("_ -> this") public InputButton setMultilineMaxLines(int multilineMaxLines) { this.multilineMaxLines = multilineMaxLines; return this; } + @Contract(pure = true) public int getMultilineHeight() { return multilineHeight; } + @Contract("_ -> this") public InputButton setMultilineHeight(int multilineHeight) { this.multilineHeight = multilineHeight; return this; } + @Contract(pure = true) + @Nullable public List getSigleOptions() { return singleOptions; } - public InputButton setSigleOptions(List options) { + @Contract("_ -> this") + public InputButton setSigleOptions(@Nullable List options) { this.singleOptions = options; return this; } + @Contract(pure = true) + @NotNull public String getInitialValueBool() { return initialValueBool; } - public InputButton setInitialValueBool(String initialValueBool) { + @Contract("_ -> this") + public InputButton setInitialValueBool(@NotNull String initialValueBool) { this.initialValueBool = initialValueBool; return this; } + @Contract(pure = true) + @NotNull public String getTextTrue() { return textTrue; } - public InputButton setTextTrue(String textTrue) { + @Contract("_ -> this") + public InputButton setTextTrue(@NotNull String textTrue) { this.textTrue = textTrue; return this; } + @Contract(pure = true) + @NotNull public String getTextFalse() { return textFalse; } - public InputButton setTextFalse(String textFalse) { + @Contract("_ -> this") + public InputButton setTextFalse(@NotNull String textFalse) { this.textFalse = textFalse; return this; } + @Contract(pure = true) public float getStart() { return start; } + @Contract("_ -> this") public InputButton setStart(float start) { this.start = start; return this; } + @Contract(pure = true) public float getEnd() { return end; } + @Contract("_ -> this") public InputButton setEnd(float end) { this.end = end; return this; } + @Contract(pure = true) public float getStep() { return step; } + @Contract("_ -> this") public InputButton setStep(float step) { this.step = step; return this; } + @Contract(pure = true) + @NotNull public String getInitialValueRange() { return initialValueRange; } - public InputButton setInitialValueRange(String initialValueRange) { + @Contract("_ -> this") + public InputButton setInitialValueRange(@NotNull String initialValueRange) { this.initialValueRange = initialValueRange; return this; } + @Contract(pure = true) + @Nullable public String getKey() { return key; } - public InputButton setKey(String key) { + @Contract("_ -> this") + public InputButton setKey(@Nullable String key) { this.key = key; return this; } + @Contract(pure = true) + @NotNull public String getLabelFormat() { return labelFormat; } - public InputButton setLabelFormat(String labelFormat) { + + @Contract("_ -> this") + public InputButton setLabelFormat(@NotNull String labelFormat) { this.labelFormat = labelFormat; return this; } + + @Contract(pure = true) + @NotNull public Optional getInitialValueSupplier() { - if (this.initialValueSupplier != null) {; + if (this.initialValueSupplier != null) { return Optional.ofNullable(initialValueSupplier.get()); } return Optional.empty(); } - public InputButton setInitialValueSupplier(Supplier initialValueSupplier) { + + @Contract("_ -> this") + public InputButton setInitialValueSupplier(@Nullable Supplier initialValueSupplier) { this.initialValueSupplier = initialValueSupplier; return this; } + @Contract(pure = true) + @NotNull public Optional getInitialValueRangeSupplier() { - if (this.initialValueRangeSupplier != null) {; + if (this.initialValueRangeSupplier != null) { return Optional.ofNullable(initialValueRangeSupplier.get()); } return Optional.empty(); } - public InputButton setInitialValueRangeSupplier(Supplier initialValueRangeSupplier) { + @Contract("_ -> this") + public InputButton setInitialValueRangeSupplier(@Nullable Supplier initialValueRangeSupplier) { this.initialValueRangeSupplier = initialValueRangeSupplier; return this; } + + @Contract(pure = true) + @NotNull public Optional getDefaultTextSupplier() { - if (this.defaultTextSupplier != null) {; + if (this.defaultTextSupplier != null) { return Optional.ofNullable(defaultTextSupplier.get()); } return Optional.empty(); } - public InputButton setDefaultTextSupplier(Supplier defaultTextSupplier) { + + @Contract("_ -> this") + public InputButton setDefaultTextSupplier(@Nullable Supplier defaultTextSupplier) { this.defaultTextSupplier = defaultTextSupplier; return this; } } - diff --git a/API/src/main/java/fr/maxlego08/menu/api/checker/InventoryLoadRequirement.java b/API/src/main/java/fr/maxlego08/menu/api/checker/InventoryLoadRequirement.java index 4adb2062..88ceff39 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/checker/InventoryLoadRequirement.java +++ b/API/src/main/java/fr/maxlego08/menu/api/checker/InventoryLoadRequirement.java @@ -3,6 +3,8 @@ import fr.maxlego08.menu.api.Inventory; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.util.ArrayList; @@ -28,30 +30,39 @@ public InventoryLoadRequirement(Plugin plugin, YamlConfiguration configuration, } } + @Contract(pure = true) + @NotNull public File getFile() { - return file; + return this.file; } + @Contract(pure = true) + @NotNull public Plugin getPlugin() { - return plugin; + return this.plugin; } + @Contract(pure = true) + @NotNull public YamlConfiguration getConfiguration() { - return configuration; + return this.configuration; } + @Contract(pure = true) + @NotNull public Class getClassz() { - return classz; + return this.classz; } - public void addRequirement(InventoryRequirementType inventoryRequirementType, String name) { + public void addRequirement(@NotNull InventoryRequirementType inventoryRequirementType, @NotNull String name) { this.requirements.get(inventoryRequirementType).add(name); } - public void removeRequirement(InventoryRequirementType inventoryRequirementType, String name) { + public void removeRequirement(@NotNull InventoryRequirementType inventoryRequirementType, @NotNull String name) { this.requirements.get(inventoryRequirementType).removeIf(e -> e.equalsIgnoreCase(name)); } + @Contract(pure = true) public boolean canLoad() { for (List names : this.requirements.values()) { if (!names.isEmpty()) { @@ -61,11 +72,14 @@ public boolean canLoad() { return true; } + @Contract(pure = true) + @NotNull public Map> getRequirements() { - return requirements; + return this.requirements; } - + @Contract(pure = true) + @NotNull public String getDisplayError() { StringBuilder sb = new StringBuilder(); this.requirements.forEach((type, names) -> { @@ -79,13 +93,15 @@ public String getDisplayError() { } @Override + @Contract(pure = true) + @NotNull public String toString() { return "InventoryLoadRequirement{" + - "plugin=" + plugin + - ", configuration=" + configuration + - ", classz=" + classz + - ", file=" + file + - ", requirements=" + requirements + + "plugin=" + this.plugin + + ", configuration=" + this.configuration + + ", classz=" + this.classz + + ", file=" + this.file + + ", requirements=" + this.requirements + '}'; } } diff --git a/API/src/main/java/fr/maxlego08/menu/api/command/Command.java b/API/src/main/java/fr/maxlego08/menu/api/command/Command.java index 308b1e16..a5c081ad 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/command/Command.java +++ b/API/src/main/java/fr/maxlego08/menu/api/command/Command.java @@ -25,6 +25,13 @@ public interface Command { */ List aliases(); + /** + * Gets whether the console can use the command. + * + * @return {@code true} if the console can use the command, otherwise {@code false}. + */ + boolean consoleCanUse(); + /** * Gets the permission required to execute the command. * diff --git a/API/src/main/java/fr/maxlego08/menu/api/configuration/Config.java b/API/src/main/java/fr/maxlego08/menu/api/configuration/Config.java deleted file mode 100644 index 9260d5ec..00000000 --- a/API/src/main/java/fr/maxlego08/menu/api/configuration/Config.java +++ /dev/null @@ -1,477 +0,0 @@ -package fr.maxlego08.menu.api.configuration; - -import fr.maxlego08.menu.api.configuration.annotation.ConfigOption; -import fr.maxlego08.menu.api.configuration.annotation.ConfigUpdate; -import fr.maxlego08.menu.api.enums.DialogInputType; -import fr.maxlego08.menu.api.utils.OpGrantMethod; -import fr.maxlego08.menu.zcore.logger.Logger; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.event.inventory.ClickType; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class Config { - - // Enable debug, allows you to display errors in the console that would normally be hidden. - @ConfigOption( - key = "enableDebug", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable debug" - ) - public static boolean enableDebug = false; - - // Enable debug time, allows you to display the code execution time in nanosecond, perfect for testing the effectiveness of the plugin. - @ConfigOption( - key = "enableDebugTime", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable debug time" - ) - public static boolean enableDebugTime = false; - - // Enable an information message, allows you to view messages that tell you about an inventory or that an order has been successfully loaded. - @ConfigOption( - key = "enableInformationMessage", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable information message" - ) - public static boolean enableInformationMessage = true; - - // Enable save or load file log in console - @ConfigOption( - key = "enableLogStorageFile", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable log storage file" - ) - public static boolean enableLogStorageFile = false; - - // Skip update check - @ConfigOption( - key = "skipUpdateCheck", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Skip update check" - ) - public static boolean skipUpdateCheck = false; - - // Enable open message, default value for the command /zm open - @ConfigOption( - key = "enableOpenMessage", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable open message" - ) - public static boolean enableOpenMessage = true; - - // Enable mini message format, allows you to activate the mini message format, available from 1.17 onwards, more information here: https://docs.advntr.dev/minimessage/index.html - @ConfigOption( - key = "enableMiniMessageFormat", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable mini message format" - ) - public static boolean enableMiniMessageFormat = true; - - // Enable player command in chat, Allows you to ensure that when a player executes a command, they execute it from the chat and not from the console. If you have "fake" command, which are not saved in spigot you need to enable this option. - @ConfigOption( - key = "enablePlayerCommandInChat", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable player command in chat" - ) - public static boolean enablePlayerCommandInChat = false; - - // Allows you to use the FastEvent interface instead of bukkit events. You gain performance. To use FastEvent, please read the documentation. - @ConfigOption( - key = "enableFastEvent", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable FastEvent" - ) - public static boolean enableFastEvent = false; - - // Seconds save player data: The time in seconds for automatic backup of player data. - @ConfigOption( - key = "secondsSavePlayerData", - type = DialogInputType.NUMBER_RANGE, - label = "Seconds save player data", - startRange = 60, - endRange = 3600, - stepRange = 5 - ) - public static int secondsSavePlayerData = 600; - - // Seconds save player data: The time in seconds for automatic backup of inventories data. - @ConfigOption( - key = "secondsSavePlayerInventories", - type = DialogInputType.NUMBER_RANGE, - label = "Seconds save player inventories", - startRange = 60, - endRange = 3600, - stepRange = 5 - ) - public static int secondsSavePlayerInventories = 600; - - // Default menu name - public static String mainMenu = "example"; - - // Open main menu when swap item offhand key is press - @ConfigOption( - key = "useSwapItemOffHandKeyToOpenMainMenu", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Use swap item offhand key to open main menu" - ) - public static boolean useSwapItemOffHandKeyToOpenMainMenu = false; - - // Open main menu when swap item offhand key is press and sneak key - @ConfigOption( - key = "useSwapItemOffHandKeyToOpenMainMenuNeedsShift", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Use swap item offhand key to open main menu needs shift" - ) - public static boolean useSwapItemOffHandKeyToOpenMainMenuNeedsShift = false; - - // Load specific inventories - public static List specifyPathMenus = new ArrayList<>(); - - // Generate default configuration - @ConfigOption( - key = "generateDefaultFile", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Generate default file" - ) - public static boolean generateDefaultFile = true; - - // Does not take double click into account - @ConfigOption( - key = "disableDoubleClickEvent", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Disable double click event" - ) - public static boolean disableDoubleClickEvent = true; - - // Enable anti dupe - @ConfigOption( - key = "enableAntiDupe", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable anti dupe" - ) - public static boolean enableAntiDupe = true; - // Enable anti dupe discord notification - @ConfigOption( - key = "enableAntiDupeDiscordNotification", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable anti dupe discord notification" - ) - public static boolean enableAntiDupeDiscordNotification = false; - @ConfigOption( - key = "antiDupeDiscordWebhookUrl", - type = DialogInputType.TEXT, - label = "Anti dupe discord webhook url", - maxLength = 100 - ) - public static String antiDupeDiscordWebhookUrl = "https://discord.com/api/webhooks/"; - @ConfigOption( - key = "antiDupeMessage", - type = DialogInputType.TEXT, - label = "Anti dupe message", - maxLength = 200 - ) - public static String antiDupeMessage = "**%player%** use %amount% %itemname% which comes from zMenu. Removing it !"; - - public static List allClicksType = Arrays.asList(ClickType.MIDDLE, ClickType.RIGHT, ClickType.LEFT, ClickType.SHIFT_RIGHT, ClickType.SHIFT_LEFT); - // Enable cache itemstack in memory - @ConfigOption( - key = "enableCacheItemStack", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable cache item stack" - ) - public static boolean enableCacheItemStack = true; - - @ConfigOption( - key = "enableCooldownClick", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable cooldown click" - ) - - public static boolean enableCooldownClick = true; - @ConfigOption( - key = "cooldownClickMilliseconds", - type = DialogInputType.NUMBER_RANGE, - label = "Cooldown click milliseconds", - endRange = 1000, - stepRange = 10 - ) - - public static long cooldownClickMilliseconds = 100; - @ConfigOption( - key = "cachePlaceholderAPI", - type = DialogInputType.NUMBER_RANGE, - label = "Cache PlaceholderAPI", - endRange = 300, - stepRange = 5 - ) - public static long cachePlaceholderAPI = 20; - - @ConfigOption( - key = "enableCachePlaceholderAPI", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable cache PlaceholderAPI" - ) - public static boolean enableCachePlaceholderAPI = false; - @ConfigOption( - key = "enableDownloadCommand", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable download command" - ) - public static boolean enableDownloadCommand = false; - @ConfigOption( - key = "enablePlayerOpenInventoryLogs", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable player open inventory logs" - ) - public static boolean enablePlayerOpenInventoryLogs = true; - - @ConfigOption( - key = "enablePlayerCommandsAsOPAction", - type = DialogInputType.BOOLEAN, - trueText = "Enabled", - falseText = "Disabled", - label = "Enable player commands as OP action (requires server restart)" - ) - public static boolean enablePlayerCommandsAsOPAction = false; - - public static OpGrantMethod opGrantMethod = OpGrantMethod.ATTACHMENT; - - public static boolean enableToast = true; - @ConfigUpdate - public static boolean updated = false; - /** - * static Singleton instance. - */ - private static volatile Config instance; - - /** - * Private constructor for singleton. - */ - private Config() { - } - - /** - * Return a singleton instance of Config. - */ - public static Config getInstance() { - // Double lock for thread safety. - if (instance == null) { - synchronized (Config.class) { - if (instance == null) { - instance = new Config(); - } - } - } - return instance; - } - - public void load(FileConfiguration configuration) { - - enableDebug = configuration.getBoolean(ConfigPath.ENABLE_DEBUG.getPath()); - enableDebugTime = configuration.getBoolean(ConfigPath.ENABLE_DEBUG_TIME.getPath()); - enableInformationMessage = configuration.getBoolean(ConfigPath.ENABLE_INFORMATION_MESSAGE.getPath()); - enableLogStorageFile = configuration.getBoolean(ConfigPath.ENABLE_LOG_STORAGE_FILE.getPath()); - skipUpdateCheck = configuration.getBoolean(ConfigPath.SKIP_UPDATE_CHECK.getPath()); - enableOpenMessage = configuration.getBoolean(ConfigPath.ENABLE_OPEN_MESSAGE.getPath()); - enableMiniMessageFormat = configuration.getBoolean(ConfigPath.ENABLE_MINI_MESSAGE_FORMAT.getPath()); - enablePlayerCommandInChat = configuration.getBoolean(ConfigPath.ENABLE_PLAYER_COMMAND_IN_CHAT.getPath()); - enableFastEvent = configuration.getBoolean(ConfigPath.ENABLE_FAST_EVENT.getPath()); - - secondsSavePlayerData = configuration.getInt(ConfigPath.SECONDS_SAVE_PLAYER_DATA.getPath()); - secondsSavePlayerInventories = configuration.getInt(ConfigPath.SECONDS_SAVE_PLAYER_INVENTORIES.getPath()); - - mainMenu = configuration.getString(ConfigPath.MAIN_MENU.getPath()); - useSwapItemOffHandKeyToOpenMainMenu = configuration.getBoolean(ConfigPath.USE_SWAP_ITEM_OFF_HAND_KEY_TO_OPEN_MAIN_MENU.getPath()); - useSwapItemOffHandKeyToOpenMainMenuNeedsShift = configuration.getBoolean(ConfigPath.USE_SWAP_ITEM_OFF_HAND_KEY_TO_OPEN_MAIN_MENU_NEEDS_SHIFT.getPath()); - - specifyPathMenus = configuration.getStringList(ConfigPath.SPECIFY_PATH_MENUS.getPath()); - generateDefaultFile = configuration.getBoolean(ConfigPath.GENERATE_DEFAULT_FILE.getPath()); - disableDoubleClickEvent = configuration.getBoolean(ConfigPath.DISABLE_DOUBLE_CLICK_EVENT.getPath()); - - enableAntiDupe = configuration.getBoolean(ConfigPath.ENABLE_ANTI_DUPE.getPath()); - enableAntiDupeDiscordNotification = configuration.getBoolean(ConfigPath.ENABLE_ANTI_DUPE_DISCORD_NOTIFICATION.getPath()); - antiDupeDiscordWebhookUrl = configuration.getString(ConfigPath.ANTI_DUPE_DISCORD_WEBHOOK_URL.getPath()); - antiDupeMessage = configuration.getString(ConfigPath.ANTI_DUPE_MESSAGE.getPath()); - - List clickTypeStrings = configuration.getStringList(ConfigPath.ALL_CLICKS_TYPE.getPath()); - List clickTypes = new ArrayList<>(clickTypeStrings.size()); - for (String name : clickTypeStrings) { - try { - clickTypes.add(ClickType.valueOf(name)); - } catch (IllegalArgumentException e) { - Bukkit.getLogger().warning("[zMenu] Invalid click type in config: " + name); - } - } - allClicksType = clickTypes; - - enableCacheItemStack = configuration.getBoolean(ConfigPath.ENABLE_CACHE_ITEM_STACK.getPath()); - enableCooldownClick = configuration.getBoolean(ConfigPath.ENABLE_COOLDOWN_CLICK.getPath()); - cooldownClickMilliseconds = configuration.getLong(ConfigPath.COOLDOWN_CLICK_MILLISECONDS.getPath()); - - cachePlaceholderAPI = configuration.getLong(ConfigPath.CACHE_PLACEHOLDER_API.getPath()); - enableCachePlaceholderAPI = configuration.getBoolean(ConfigPath.ENABLE_CACHE_PLACEHOLDER_API.getPath()); - - enableDownloadCommand = configuration.getBoolean(ConfigPath.ENABLE_DOWNLOAD_COMMAND.getPath()); - enablePlayerOpenInventoryLogs = configuration.getBoolean(ConfigPath.ENABLE_PLAYER_OPEN_INVENTORY_LOGS.getPath()); - - enablePlayerCommandsAsOPAction = configuration.getBoolean(ConfigPath.ENABLE_PLAYER_COMMANDS_AS_OP_ACTION.getPath()); - try { - opGrantMethod = OpGrantMethod.valueOf(configuration.getString(ConfigPath.OP_GRANT_METHOD.getPath(), OpGrantMethod.ATTACHMENT.name()).toUpperCase()); - } catch (IllegalArgumentException e) { - Logger.info("Invalid op grant method in config, defaulting to ATTACHMENT."); - opGrantMethod = OpGrantMethod.ATTACHMENT; - } - enableToast = configuration.getBoolean(ConfigPath.ENABLE_TOAST.getPath(), true); - } - - public void save(FileConfiguration configuration, File file) { - if (!updated) { - return; - } - configuration.set(ConfigPath.ENABLE_DEBUG.getPath(), enableDebug); - configuration.set(ConfigPath.ENABLE_DEBUG_TIME.getPath(), enableDebugTime); - configuration.set(ConfigPath.ENABLE_INFORMATION_MESSAGE.getPath(), enableInformationMessage); - configuration.set(ConfigPath.ENABLE_LOG_STORAGE_FILE.getPath(), enableLogStorageFile); - configuration.set(ConfigPath.SKIP_UPDATE_CHECK.getPath(), skipUpdateCheck); - configuration.set(ConfigPath.ENABLE_OPEN_MESSAGE.getPath(), enableOpenMessage); - configuration.set(ConfigPath.ENABLE_MINI_MESSAGE_FORMAT.getPath(), enableMiniMessageFormat); - configuration.set(ConfigPath.ENABLE_PLAYER_COMMAND_IN_CHAT.getPath(), enablePlayerCommandInChat); - configuration.set(ConfigPath.ENABLE_FAST_EVENT.getPath(), enableFastEvent); - - configuration.set(ConfigPath.SECONDS_SAVE_PLAYER_DATA.getPath(), secondsSavePlayerData); - configuration.set(ConfigPath.SECONDS_SAVE_PLAYER_INVENTORIES.getPath(), secondsSavePlayerInventories); - - configuration.set(ConfigPath.MAIN_MENU.getPath(), mainMenu); - configuration.set(ConfigPath.USE_SWAP_ITEM_OFF_HAND_KEY_TO_OPEN_MAIN_MENU.getPath(), useSwapItemOffHandKeyToOpenMainMenu); - configuration.set(ConfigPath.USE_SWAP_ITEM_OFF_HAND_KEY_TO_OPEN_MAIN_MENU_NEEDS_SHIFT.getPath(), useSwapItemOffHandKeyToOpenMainMenuNeedsShift); - - configuration.set(ConfigPath.SPECIFY_PATH_MENUS.getPath(), specifyPathMenus); - configuration.set(ConfigPath.GENERATE_DEFAULT_FILE.getPath(), generateDefaultFile); - configuration.set(ConfigPath.DISABLE_DOUBLE_CLICK_EVENT.getPath(), disableDoubleClickEvent); - - configuration.set(ConfigPath.ENABLE_ANTI_DUPE.getPath(), enableAntiDupe); - configuration.set(ConfigPath.ENABLE_ANTI_DUPE_DISCORD_NOTIFICATION.getPath(), enableAntiDupeDiscordNotification); - configuration.set(ConfigPath.ANTI_DUPE_DISCORD_WEBHOOK_URL.getPath(), antiDupeDiscordWebhookUrl); - configuration.set(ConfigPath.ANTI_DUPE_MESSAGE.getPath(), antiDupeMessage); - - List clickTypeNames = new ArrayList<>(allClicksType.size()); - for (ClickType clickType : allClicksType) { - clickTypeNames.add(clickType.name()); - } - configuration.set(ConfigPath.ALL_CLICKS_TYPE.getPath(), clickTypeNames); - - configuration.set(ConfigPath.ENABLE_CACHE_ITEM_STACK.getPath(), enableCacheItemStack); - configuration.set(ConfigPath.ENABLE_COOLDOWN_CLICK.getPath(), enableCooldownClick); - configuration.set(ConfigPath.COOLDOWN_CLICK_MILLISECONDS.getPath(), cooldownClickMilliseconds); - configuration.set(ConfigPath.CACHE_PLACEHOLDER_API.getPath(), cachePlaceholderAPI); - configuration.set(ConfigPath.ENABLE_CACHE_PLACEHOLDER_API.getPath(), enableCachePlaceholderAPI); - configuration.set(ConfigPath.ENABLE_DOWNLOAD_COMMAND.getPath(), enableDownloadCommand); - configuration.set(ConfigPath.ENABLE_PLAYER_OPEN_INVENTORY_LOGS.getPath(), enablePlayerOpenInventoryLogs); - updated = false; - try { - configuration.save(file); - } catch (IOException e) { - Bukkit.getLogger().warning("[zMenu] Unable to save config file: " + e.getMessage()); - } - } - - private enum ConfigPath { - ENABLE_DEBUG("enable-debug"), - ENABLE_DEBUG_TIME("enable-debug-time"), - ENABLE_INFORMATION_MESSAGE("enable-information-message"), - ENABLE_LOG_STORAGE_FILE("enable-log-storage-file"), - SKIP_UPDATE_CHECK("skip-update-check"), - ENABLE_OPEN_MESSAGE("enable-open-message"), - ENABLE_MINI_MESSAGE_FORMAT("enable-mini-message-format"), - ENABLE_PLAYER_COMMAND_IN_CHAT("enable-player-command-in-chat"), - ENABLE_FAST_EVENT("enable-fast-event"), - - SECONDS_SAVE_PLAYER_DATA("seconds-save-player-data"), - SECONDS_SAVE_PLAYER_INVENTORIES("seconds-save-player-inventories"), - - MAIN_MENU("main-menu"), - USE_SWAP_ITEM_OFF_HAND_KEY_TO_OPEN_MAIN_MENU("use-swap-item-off-hand-key-to-open-main-menu"), - USE_SWAP_ITEM_OFF_HAND_KEY_TO_OPEN_MAIN_MENU_NEEDS_SHIFT("use-swap-item-off-hand-key-to-open-main-menu-needs-shift"), - - SPECIFY_PATH_MENUS("specify-path-menus"), - GENERATE_DEFAULT_FILE("generate-default-file"), - DISABLE_DOUBLE_CLICK_EVENT("disable-double-click-event"), - - ENABLE_ANTI_DUPE("enable-anti-dupe"), - ENABLE_ANTI_DUPE_DISCORD_NOTIFICATION("enable-anti-dupe-discord-notification"), - ANTI_DUPE_DISCORD_WEBHOOK_URL("anti-dupe-discord-webhook-url"), - ANTI_DUPE_MESSAGE("anti-dupe-message"), - - ALL_CLICKS_TYPE("all-clicks-type"), - - ENABLE_CACHE_ITEM_STACK("enable-cache-item-stack"), - ENABLE_COOLDOWN_CLICK("enable-cooldown-click"), - COOLDOWN_CLICK_MILLISECONDS("cooldown-click-milliseconds"), - - CACHE_PLACEHOLDER_API("cache-placeholder-api"), - ENABLE_CACHE_PLACEHOLDER_API("enable-cache-placeholder-api"), - - ENABLE_DOWNLOAD_COMMAND("enable-download-command"), - ENABLE_PLAYER_OPEN_INVENTORY_LOGS("enable-player-open-inventory-logs"), - - ENABLE_PLAYER_COMMANDS_AS_OP_ACTION("enable-player-commands-as-op-action"), - OP_GRANT_METHOD("op-grant-method"), - ENABLE_TOAST("enable-toast"); - - private final String path; - - ConfigPath(String path) { - this.path = path; - } - - public String getPath() { - return path; - } - } -} diff --git a/API/src/main/java/fr/maxlego08/menu/api/configuration/ConfigManagerInt.java b/API/src/main/java/fr/maxlego08/menu/api/configuration/ConfigManagerInt.java index fcda68b0..f408a641 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/configuration/ConfigManagerInt.java +++ b/API/src/main/java/fr/maxlego08/menu/api/configuration/ConfigManagerInt.java @@ -9,7 +9,7 @@ public interface ConfigManagerInt { void registerConfig(@NotNull ConfigDialogBuilder configDialogBuilder, @NotNull Class configClass, @NotNull Plugin plugin); - List getRegisteredConfigs(); - void openConfig(String pluginName, Player player); - void openConfig(Plugin plugin, Player player); + @NotNull List getRegisteredConfigs(); + void openConfig(@NotNull String pluginName,@NotNull Player player); + void openConfig(@NotNull Plugin plugin,@NotNull Player player); } diff --git a/API/src/main/java/fr/maxlego08/menu/api/configuration/Configuration.java b/API/src/main/java/fr/maxlego08/menu/api/configuration/Configuration.java new file mode 100644 index 00000000..89cc2bd8 --- /dev/null +++ b/API/src/main/java/fr/maxlego08/menu/api/configuration/Configuration.java @@ -0,0 +1,492 @@ +package fr.maxlego08.menu.api.configuration; + +import fr.maxlego08.menu.api.configuration.annotation.ConfigOption; +import fr.maxlego08.menu.api.configuration.annotation.ConfigUpdate; +import fr.maxlego08.menu.api.enums.DialogInputType; +import fr.maxlego08.menu.api.utils.OpGrantMethod; +import fr.maxlego08.menu.zcore.logger.Logger; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.event.inventory.ClickType; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Configuration { + + // Enable debug, allows you to display errors in the console that would normally be hidden. + @ConfigOption( + key = "enableDebug", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable debug" + ) + public static boolean enableDebug = false; + + // Enable debug time, allows you to display the code execution time in nanosecond, perfect for testing the effectiveness of the plugin. + @ConfigOption( + key = "enableDebugTime", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable debug time" + ) + public static boolean enableDebugTime = false; + + // Enable an information message, allows you to view messages that tell you about an inventory or that an order has been successfully loaded. + @ConfigOption( + key = "enableInformationMessage", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable information message" + ) + public static boolean enableInformationMessage = true; + + // Enable save or load file log in console + @ConfigOption( + key = "enableLogStorageFile", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable log storage file" + ) + public static boolean enableLogStorageFile = false; + + // Skip update check + @ConfigOption( + key = "skipUpdateCheck", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Skip update check" + ) + public static boolean skipUpdateCheck = false; + + // Enable open message, default value for the command /zm open + @ConfigOption( + key = "enableOpenMessage", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable open message" + ) + public static boolean enableOpenMessage = true; + + // Enable mini message format, allows you to activate the mini message format, available from 1.17 onwards, more information here: https://docs.advntr.dev/minimessage/index.html + @ConfigOption( + key = "enableMiniMessageFormat", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable mini message format" + ) + public static boolean enableMiniMessageFormat = true; + + // Enable player command in chat, Allows you to ensure that when a player executes a command, they execute it from the chat and not from the console. If you have "fake" command, which are not saved in spigot you need to enable this option. + @ConfigOption( + key = "enablePlayerCommandInChat", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable player command in chat" + ) + public static boolean enablePlayerCommandInChat = false; + + // Allows you to use the FastEvent interface instead of bukkit events. You gain performance. To use FastEvent, please read the documentation. + @ConfigOption( + key = "enableFastEvent", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable FastEvent" + ) + public static boolean enableFastEvent = false; + + // Seconds save player data: The time in seconds for automatic backup of player data. + @ConfigOption( + key = "secondsSavePlayerData", + type = DialogInputType.NUMBER_RANGE, + label = "Seconds save player data", + startRange = 60, + endRange = 3600, + stepRange = 5 + ) + public static int secondsSavePlayerData = 600; + + // Seconds save player data: The time in seconds for automatic backup of inventories data. + @ConfigOption( + key = "secondsSavePlayerInventories", + type = DialogInputType.NUMBER_RANGE, + label = "Seconds save player inventories", + startRange = 60, + endRange = 3600, + stepRange = 5 + ) + public static int secondsSavePlayerInventories = 600; + + // Default menu name + public static String mainMenu = "example"; + + // Open main menu when swap item offhand key is press + @ConfigOption( + key = "useSwapItemOffHandKeyToOpenMainMenu", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Use swap item offhand key to open main menu" + ) + public static boolean useSwapItemOffHandKeyToOpenMainMenu = false; + + // Open main menu when swap item offhand key is press and sneak key + @ConfigOption( + key = "useSwapItemOffHandKeyToOpenMainMenuNeedsShift", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Use swap item offhand key to open main menu needs shift" + ) + public static boolean useSwapItemOffHandKeyToOpenMainMenuNeedsShift = false; + + // Load specific inventories + public static List specifyPathMenus = new ArrayList<>(); + + // Generate default configuration + @ConfigOption( + key = "generateDefaultFile", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Generate default file" + ) + public static boolean generateDefaultFile = true; + + // Does not take double click into account + @ConfigOption( + key = "disableDoubleClickEvent", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Disable double click event" + ) + public static boolean disableDoubleClickEvent = true; + + // Enable anti dupe + @ConfigOption( + key = "enableAntiDupe", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable anti dupe" + ) + public static boolean enableAntiDupe = true; + // Enable anti dupe discord notification + @ConfigOption( + key = "enableAntiDupeDiscordNotification", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable anti dupe discord notification" + ) + public static boolean enableAntiDupeDiscordNotification = false; + @ConfigOption( + key = "antiDupeDiscordWebhookUrl", + type = DialogInputType.TEXT, + label = "Anti dupe discord webhook url", + maxLength = 100 + ) + public static String antiDupeDiscordWebhookUrl = "https://discord.com/api/webhooks/"; + @ConfigOption( + key = "antiDupeMessage", + type = DialogInputType.TEXT, + label = "Anti dupe message", + maxLength = 200 + ) + public static String antiDupeMessage = "**%player%** use %amount% %itemname% which comes from zMenu. Removing it !"; + + public static List allClicksType = Arrays.asList(ClickType.MIDDLE, ClickType.RIGHT, ClickType.LEFT, ClickType.SHIFT_RIGHT, ClickType.SHIFT_LEFT); + // Enable cache itemstack in memory + @ConfigOption( + key = "enableCacheItemStack", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable cache item stack" + ) + public static boolean enableCacheItemStack = true; + + @ConfigOption( + key = "enableCooldownClick", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable cooldown click" + ) + + public static boolean enableCooldownClick = true; + @ConfigOption( + key = "cooldownClickMilliseconds", + type = DialogInputType.NUMBER_RANGE, + label = "Cooldown click milliseconds", + endRange = 1000, + stepRange = 10 + ) + + public static long cooldownClickMilliseconds = 100; + @ConfigOption( + key = "cachePlaceholderAPI", + type = DialogInputType.NUMBER_RANGE, + label = "Cache PlaceholderAPI", + endRange = 300, + stepRange = 5 + ) + public static long cachePlaceholderAPI = 20; + + @ConfigOption( + key = "enableCachePlaceholderAPI", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable cache PlaceholderAPI" + ) + public static boolean enableCachePlaceholderAPI = false; + @ConfigOption( + key = "enableDownloadCommand", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable download command" + ) + public static boolean enableDownloadCommand = false; + @ConfigOption( + key = "enablePlayerOpenInventoryLogs", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable player open inventory logs" + ) + public static boolean enablePlayerOpenInventoryLogs = true; + + @ConfigOption( + key = "enablePlayerCommandsAsOPAction", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable player commands as OP action (requires server restart)" + ) + public static boolean enablePlayerCommandsAsOPAction = false; + + public static OpGrantMethod opGrantMethod = OpGrantMethod.ATTACHMENT; + + @ConfigOption( + key = "enableToast", + type = DialogInputType.BOOLEAN, + trueText = "Enabled", + falseText = "Disabled", + label = "Enable toast" + ) + public static boolean enableToast = true; + + @ConfigUpdate + public static boolean updated = false; + /** + * static Singleton instance. + */ + private static volatile Configuration instance; + + /** + * Private constructor for singleton. + */ + private Configuration() { + } + + /** + * Return a singleton instance of Configuration. + */ + public static Configuration getInstance() { + // Double lock for thread safety. + if (instance == null) { + synchronized (Configuration.class) { + if (instance == null) { + instance = new Configuration(); + } + } + } + return instance; + } + + public void load(@NotNull FileConfiguration fileConfiguration) { + + enableDebug = fileConfiguration.getBoolean(ConfigPath.ENABLE_DEBUG.getPath()); + enableDebugTime = fileConfiguration.getBoolean(ConfigPath.ENABLE_DEBUG_TIME.getPath()); + enableInformationMessage = fileConfiguration.getBoolean(ConfigPath.ENABLE_INFORMATION_MESSAGE.getPath()); + enableLogStorageFile = fileConfiguration.getBoolean(ConfigPath.ENABLE_LOG_STORAGE_FILE.getPath()); + skipUpdateCheck = fileConfiguration.getBoolean(ConfigPath.SKIP_UPDATE_CHECK.getPath()); + enableOpenMessage = fileConfiguration.getBoolean(ConfigPath.ENABLE_OPEN_MESSAGE.getPath()); + enableMiniMessageFormat = fileConfiguration.getBoolean(ConfigPath.ENABLE_MINI_MESSAGE_FORMAT.getPath()); + enablePlayerCommandInChat = fileConfiguration.getBoolean(ConfigPath.ENABLE_PLAYER_COMMAND_IN_CHAT.getPath()); + enableFastEvent = fileConfiguration.getBoolean(ConfigPath.ENABLE_FAST_EVENT.getPath()); + + secondsSavePlayerData = fileConfiguration.getInt(ConfigPath.SECONDS_SAVE_PLAYER_DATA.getPath()); + secondsSavePlayerInventories = fileConfiguration.getInt(ConfigPath.SECONDS_SAVE_PLAYER_INVENTORIES.getPath()); + + mainMenu = fileConfiguration.getString(ConfigPath.MAIN_MENU.getPath()); + useSwapItemOffHandKeyToOpenMainMenu = fileConfiguration.getBoolean(ConfigPath.USE_SWAP_ITEM_OFF_HAND_KEY_TO_OPEN_MAIN_MENU.getPath()); + useSwapItemOffHandKeyToOpenMainMenuNeedsShift = fileConfiguration.getBoolean(ConfigPath.USE_SWAP_ITEM_OFF_HAND_KEY_TO_OPEN_MAIN_MENU_NEEDS_SHIFT.getPath()); + + specifyPathMenus = fileConfiguration.getStringList(ConfigPath.SPECIFY_PATH_MENUS.getPath()); + generateDefaultFile = fileConfiguration.getBoolean(ConfigPath.GENERATE_DEFAULT_FILE.getPath()); + disableDoubleClickEvent = fileConfiguration.getBoolean(ConfigPath.DISABLE_DOUBLE_CLICK_EVENT.getPath()); + + enableAntiDupe = fileConfiguration.getBoolean(ConfigPath.ENABLE_ANTI_DUPE.getPath()); + enableAntiDupeDiscordNotification = fileConfiguration.getBoolean(ConfigPath.ENABLE_ANTI_DUPE_DISCORD_NOTIFICATION.getPath()); + antiDupeDiscordWebhookUrl = fileConfiguration.getString(ConfigPath.ANTI_DUPE_DISCORD_WEBHOOK_URL.getPath()); + antiDupeMessage = fileConfiguration.getString(ConfigPath.ANTI_DUPE_MESSAGE.getPath()); + + List clickTypeStrings = fileConfiguration.getStringList(ConfigPath.ALL_CLICKS_TYPE.getPath()); + List clickTypes = new ArrayList<>(clickTypeStrings.size()); + for (String name : clickTypeStrings) { + try { + clickTypes.add(ClickType.valueOf(name)); + } catch (IllegalArgumentException e) { + Bukkit.getLogger().warning("[zMenu] Invalid click type in config: " + name); + } + } + allClicksType = clickTypes; + + enableCacheItemStack = fileConfiguration.getBoolean(ConfigPath.ENABLE_CACHE_ITEM_STACK.getPath()); + enableCooldownClick = fileConfiguration.getBoolean(ConfigPath.ENABLE_COOLDOWN_CLICK.getPath()); + cooldownClickMilliseconds = fileConfiguration.getLong(ConfigPath.COOLDOWN_CLICK_MILLISECONDS.getPath()); + + cachePlaceholderAPI = fileConfiguration.getLong(ConfigPath.CACHE_PLACEHOLDER_API.getPath()); + enableCachePlaceholderAPI = fileConfiguration.getBoolean(ConfigPath.ENABLE_CACHE_PLACEHOLDER_API.getPath()); + + enableDownloadCommand = fileConfiguration.getBoolean(ConfigPath.ENABLE_DOWNLOAD_COMMAND.getPath()); + enablePlayerOpenInventoryLogs = fileConfiguration.getBoolean(ConfigPath.ENABLE_PLAYER_OPEN_INVENTORY_LOGS.getPath()); + + enablePlayerCommandsAsOPAction = fileConfiguration.getBoolean(ConfigPath.ENABLE_PLAYER_COMMANDS_AS_OP_ACTION.getPath()); + try { + opGrantMethod = OpGrantMethod.valueOf(fileConfiguration.getString(ConfigPath.OP_GRANT_METHOD.getPath(), OpGrantMethod.ATTACHMENT.name()).toUpperCase()); + } catch (IllegalArgumentException e) { + Logger.info("Invalid op grant method in config, defaulting to ATTACHMENT."); + opGrantMethod = OpGrantMethod.ATTACHMENT; + } + enableToast = fileConfiguration.getBoolean(ConfigPath.ENABLE_TOAST.getPath(), true); + } + + public void save(@NotNull FileConfiguration fileConfiguration,@NotNull File file) { + if (!updated) { + return; + } + fileConfiguration.set(ConfigPath.ENABLE_DEBUG.getPath(), enableDebug); + fileConfiguration.set(ConfigPath.ENABLE_DEBUG_TIME.getPath(), enableDebugTime); + fileConfiguration.set(ConfigPath.ENABLE_INFORMATION_MESSAGE.getPath(), enableInformationMessage); + fileConfiguration.set(ConfigPath.ENABLE_LOG_STORAGE_FILE.getPath(), enableLogStorageFile); + fileConfiguration.set(ConfigPath.SKIP_UPDATE_CHECK.getPath(), skipUpdateCheck); + fileConfiguration.set(ConfigPath.ENABLE_OPEN_MESSAGE.getPath(), enableOpenMessage); + fileConfiguration.set(ConfigPath.ENABLE_MINI_MESSAGE_FORMAT.getPath(), enableMiniMessageFormat); + fileConfiguration.set(ConfigPath.ENABLE_PLAYER_COMMAND_IN_CHAT.getPath(), enablePlayerCommandInChat); + fileConfiguration.set(ConfigPath.ENABLE_FAST_EVENT.getPath(), enableFastEvent); + + fileConfiguration.set(ConfigPath.SECONDS_SAVE_PLAYER_DATA.getPath(), secondsSavePlayerData); + fileConfiguration.set(ConfigPath.SECONDS_SAVE_PLAYER_INVENTORIES.getPath(), secondsSavePlayerInventories); + + fileConfiguration.set(ConfigPath.MAIN_MENU.getPath(), mainMenu); + fileConfiguration.set(ConfigPath.USE_SWAP_ITEM_OFF_HAND_KEY_TO_OPEN_MAIN_MENU.getPath(), useSwapItemOffHandKeyToOpenMainMenu); + fileConfiguration.set(ConfigPath.USE_SWAP_ITEM_OFF_HAND_KEY_TO_OPEN_MAIN_MENU_NEEDS_SHIFT.getPath(), useSwapItemOffHandKeyToOpenMainMenuNeedsShift); + + fileConfiguration.set(ConfigPath.SPECIFY_PATH_MENUS.getPath(), specifyPathMenus); + fileConfiguration.set(ConfigPath.GENERATE_DEFAULT_FILE.getPath(), generateDefaultFile); + fileConfiguration.set(ConfigPath.DISABLE_DOUBLE_CLICK_EVENT.getPath(), disableDoubleClickEvent); + + fileConfiguration.set(ConfigPath.ENABLE_ANTI_DUPE.getPath(), enableAntiDupe); + fileConfiguration.set(ConfigPath.ENABLE_ANTI_DUPE_DISCORD_NOTIFICATION.getPath(), enableAntiDupeDiscordNotification); + fileConfiguration.set(ConfigPath.ANTI_DUPE_DISCORD_WEBHOOK_URL.getPath(), antiDupeDiscordWebhookUrl); + fileConfiguration.set(ConfigPath.ANTI_DUPE_MESSAGE.getPath(), antiDupeMessage); + + List clickTypeNames = new ArrayList<>(allClicksType.size()); + for (ClickType clickType : allClicksType) { + clickTypeNames.add(clickType.name()); + } + fileConfiguration.set(ConfigPath.ALL_CLICKS_TYPE.getPath(), clickTypeNames); + + fileConfiguration.set(ConfigPath.ENABLE_CACHE_ITEM_STACK.getPath(), enableCacheItemStack); + fileConfiguration.set(ConfigPath.ENABLE_COOLDOWN_CLICK.getPath(), enableCooldownClick); + fileConfiguration.set(ConfigPath.COOLDOWN_CLICK_MILLISECONDS.getPath(), cooldownClickMilliseconds); + fileConfiguration.set(ConfigPath.CACHE_PLACEHOLDER_API.getPath(), cachePlaceholderAPI); + fileConfiguration.set(ConfigPath.ENABLE_CACHE_PLACEHOLDER_API.getPath(), enableCachePlaceholderAPI); + fileConfiguration.set(ConfigPath.ENABLE_DOWNLOAD_COMMAND.getPath(), enableDownloadCommand); + fileConfiguration.set(ConfigPath.ENABLE_PLAYER_OPEN_INVENTORY_LOGS.getPath(), enablePlayerOpenInventoryLogs); + fileConfiguration.set(ConfigPath.ENABLE_PLAYER_COMMANDS_AS_OP_ACTION.getPath(), enablePlayerCommandsAsOPAction); + fileConfiguration.set(ConfigPath.OP_GRANT_METHOD.getPath(), opGrantMethod.name()); + fileConfiguration.set(ConfigPath.ENABLE_TOAST.getPath(), enableToast); + updated = false; + try { + fileConfiguration.save(file); + } catch (IOException e) { + Bukkit.getLogger().warning("[zMenu] Unable to save config file: " + e.getMessage()); + } + } + + private enum ConfigPath { + ENABLE_DEBUG("enable-debug"), + ENABLE_DEBUG_TIME("enable-debug-time"), + ENABLE_INFORMATION_MESSAGE("enable-information-message"), + ENABLE_LOG_STORAGE_FILE("enable-log-storage-file"), + SKIP_UPDATE_CHECK("skip-update-check"), + ENABLE_OPEN_MESSAGE("enable-open-message"), + ENABLE_MINI_MESSAGE_FORMAT("enable-mini-message-format"), + ENABLE_PLAYER_COMMAND_IN_CHAT("enable-player-command-in-chat"), + ENABLE_FAST_EVENT("enable-fast-event"), + + SECONDS_SAVE_PLAYER_DATA("seconds-save-player-data"), + SECONDS_SAVE_PLAYER_INVENTORIES("seconds-save-player-inventories"), + + MAIN_MENU("main-menu"), + USE_SWAP_ITEM_OFF_HAND_KEY_TO_OPEN_MAIN_MENU("use-swap-item-off-hand-key-to-open-main-menu"), + USE_SWAP_ITEM_OFF_HAND_KEY_TO_OPEN_MAIN_MENU_NEEDS_SHIFT("use-swap-item-off-hand-key-to-open-main-menu-needs-shift"), + + SPECIFY_PATH_MENUS("specify-path-menus"), + GENERATE_DEFAULT_FILE("generate-default-file"), + DISABLE_DOUBLE_CLICK_EVENT("disable-double-click-event"), + + ENABLE_ANTI_DUPE("enable-anti-dupe"), + ENABLE_ANTI_DUPE_DISCORD_NOTIFICATION("enable-anti-dupe-discord-notification"), + ANTI_DUPE_DISCORD_WEBHOOK_URL("anti-dupe-discord-webhook-url"), + ANTI_DUPE_MESSAGE("anti-dupe-message"), + + ALL_CLICKS_TYPE("all-clicks-type"), + + ENABLE_CACHE_ITEM_STACK("enable-cache-item-stack"), + ENABLE_COOLDOWN_CLICK("enable-cooldown-click"), + COOLDOWN_CLICK_MILLISECONDS("cooldown-click-milliseconds"), + + CACHE_PLACEHOLDER_API("cache-placeholder-api"), + ENABLE_CACHE_PLACEHOLDER_API("enable-cache-placeholder-api"), + + ENABLE_DOWNLOAD_COMMAND("enable-download-command"), + ENABLE_PLAYER_OPEN_INVENTORY_LOGS("enable-player-open-inventory-logs"), + + ENABLE_PLAYER_COMMANDS_AS_OP_ACTION("enable-player-commands-as-op-action"), + OP_GRANT_METHOD("op-grant-method"), + ENABLE_TOAST("enable-toast"); + + private final String path; + + ConfigPath(@NotNull String path) { + this.path = path; + } + + @Contract(pure = true) + @NotNull + public String getPath() { + return this.path; + } + } +} diff --git a/API/src/main/java/fr/maxlego08/menu/api/configuration/annotation/ConfigOption.java b/API/src/main/java/fr/maxlego08/menu/api/configuration/annotation/ConfigOption.java index e3b88d1a..010f023c 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/configuration/annotation/ConfigOption.java +++ b/API/src/main/java/fr/maxlego08/menu/api/configuration/annotation/ConfigOption.java @@ -1,6 +1,7 @@ package fr.maxlego08.menu.api.configuration.annotation; import fr.maxlego08.menu.api.enums.DialogInputType; +import org.jetbrains.annotations.NotNull; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -10,8 +11,11 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface ConfigOption { + @NotNull String key() default ""; + @NotNull DialogInputType type() default DialogInputType.TEXT; + @NotNull String label() default ""; int width() default 200; boolean labelVisible() default true; @@ -22,7 +26,9 @@ int multilineHeight() default 0; // For boolean type + @NotNull String trueText() default "True"; + @NotNull String falseText() default "False"; // For number range type diff --git a/API/src/main/java/fr/maxlego08/menu/api/configuration/dialog/ConfigDialogBuilder.java b/API/src/main/java/fr/maxlego08/menu/api/configuration/dialog/ConfigDialogBuilder.java index ee1725fe..29623088 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/configuration/dialog/ConfigDialogBuilder.java +++ b/API/src/main/java/fr/maxlego08/menu/api/configuration/dialog/ConfigDialogBuilder.java @@ -1,5 +1,9 @@ package fr.maxlego08.menu.api.configuration.dialog; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +@SuppressWarnings("unused") public class ConfigDialogBuilder { private final String name; private final String externalTitle; @@ -18,92 +22,130 @@ public ConfigDialogBuilder(String name, String externalTitle) { this.externalTitle = externalTitle; } - public ConfigDialogBuilder yesText(String yesText) { + @Contract("_ -> this") + @NotNull + public ConfigDialogBuilder yesText(@NotNull String yesText) { this.yesText = yesText; return this; } - public ConfigDialogBuilder yesTooltip(String yesTooltip) { + @Contract("_ -> this") + @NotNull + public ConfigDialogBuilder yesTooltip(@NotNull String yesTooltip) { this.yesTooltip = yesTooltip; return this; } + @Contract("_ -> this") + @NotNull public ConfigDialogBuilder yesWidth(int yesWidth) { this.yesWidth = yesWidth; return this; } - public ConfigDialogBuilder noText(String noText) { + @Contract("_ -> this") + @NotNull + public ConfigDialogBuilder noText(@NotNull String noText) { this.noText = noText; return this; } - public ConfigDialogBuilder noTooltip(String noTooltip) { + @Contract("_ -> this") + @NotNull + public ConfigDialogBuilder noTooltip(@NotNull String noTooltip) { this.noTooltip = noTooltip; return this; } + @Contract("_ -> this") + @NotNull public ConfigDialogBuilder noWidth(int noWidth) { this.noWidth = noWidth; return this; } - public ConfigDialogBuilder booleanConfirmText(String booleanConfirmText) { + @Contract("_ -> this") + @NotNull + public ConfigDialogBuilder booleanConfirmText(@NotNull String booleanConfirmText) { this.booleanConfirmText = booleanConfirmText; return this; } - public ConfigDialogBuilder numberRangeConfirmText(String numberRangeConfirmText) { + @Contract("_ -> this") + @NotNull + public ConfigDialogBuilder numberRangeConfirmText(@NotNull String numberRangeConfirmText) { this.numberRangeConfirmText = numberRangeConfirmText; return this; } - public ConfigDialogBuilder textConfirmText(String textConfirmText) { + @Contract("_ -> this") + @NotNull + public ConfigDialogBuilder textConfirmText(@NotNull String textConfirmText) { this.textConfirmText = textConfirmText; return this; } + @Contract(pure = true) + @NotNull public String getName() { - return name; + return this.name; } + @Contract(pure = true) + @NotNull public String getExternalTitle() { - return externalTitle; + return this.externalTitle; } + @Contract(pure = true) + @NotNull public String getYesText() { - return yesText; + return this.yesText; } + @Contract(pure = true) + @NotNull public String getYesTooltip() { - return yesTooltip; + return this.yesTooltip; } + @Contract(pure = true) public int getYesWidth() { - return yesWidth; + return this.yesWidth; } + @Contract(pure = true) + @NotNull public String getNoText() { - return noText; + return this.noText; } + @Contract(pure = true) + @NotNull public String getNoTooltip() { - return noTooltip; + return this.noTooltip; } + @Contract(pure = true) public int getNoWidth() { - return noWidth; + return this.noWidth; } + @Contract(pure = true) + @NotNull public String getBooleanConfirmText() { - return booleanConfirmText; + return this.booleanConfirmText; } + @Contract(pure = true) + @NotNull public String getNumberRangeConfirmText() { - return numberRangeConfirmText; + return this.numberRangeConfirmText; } + @Contract(pure = true) + @NotNull public String getTextConfirmText() { - return textConfirmText; + return this.textConfirmText; } } diff --git a/API/src/main/java/fr/maxlego08/menu/api/dupe/DupeItem.java b/API/src/main/java/fr/maxlego08/menu/api/dupe/DupeItem.java index 1717373e..da9786f2 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/dupe/DupeItem.java +++ b/API/src/main/java/fr/maxlego08/menu/api/dupe/DupeItem.java @@ -2,7 +2,8 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; -public record DupeItem(ItemStack itemStack, Player player) { +public record DupeItem(@NotNull ItemStack itemStack,@NotNull Player player) { } diff --git a/API/src/main/java/fr/maxlego08/menu/api/dupe/DupeManager.java b/API/src/main/java/fr/maxlego08/menu/api/dupe/DupeManager.java index 688183ac..290db89f 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/dupe/DupeManager.java +++ b/API/src/main/java/fr/maxlego08/menu/api/dupe/DupeManager.java @@ -1,6 +1,7 @@ package fr.maxlego08.menu.api.dupe; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; public interface DupeManager { @@ -13,16 +14,17 @@ public interface DupeManager { * protect an item from dupe * * @param itemStack - * @return + * @return protected itemStack */ - ItemStack protectItem(ItemStack itemStack); + @NotNull + ItemStack protectItem(@NotNull ItemStack itemStack); /** * check if an item is a result of a dupe * - * @param itemStack - * @return + * @param itemStack the item to check + * @return true if the item is a dupe item */ - boolean isDupeItem(ItemStack itemStack); + boolean isDupeItem(@NotNull ItemStack itemStack); } diff --git a/API/src/main/java/fr/maxlego08/menu/api/enchantment/Enchantments.java b/API/src/main/java/fr/maxlego08/menu/api/enchantment/Enchantments.java index cee2aaae..706a005f 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/enchantment/Enchantments.java +++ b/API/src/main/java/fr/maxlego08/menu/api/enchantment/Enchantments.java @@ -1,5 +1,8 @@ package fr.maxlego08.menu.api.enchantment; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + import java.util.List; import java.util.Optional; @@ -15,7 +18,9 @@ public interface Enchantments { * @param enchantment the name of the enchantment * @return an {@link Optional} containing the enchantment if found, otherwise empty */ - Optional getEnchantments(String enchantment); + @Contract(pure = true) + @NotNull + Optional getEnchantments(@NotNull String enchantment); /** * Registers all custom enchantments within the plugin. @@ -27,5 +32,7 @@ public interface Enchantments { * * @return a list of enchantment names */ + @Contract(pure = true) + @NotNull List getEnchantments(); } diff --git a/API/src/main/java/fr/maxlego08/menu/api/enchantment/MenuEnchantment.java b/API/src/main/java/fr/maxlego08/menu/api/enchantment/MenuEnchantment.java index 2207896b..6212f22c 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/enchantment/MenuEnchantment.java +++ b/API/src/main/java/fr/maxlego08/menu/api/enchantment/MenuEnchantment.java @@ -1,6 +1,8 @@ package fr.maxlego08.menu.api.enchantment; import org.bukkit.enchantments.Enchantment; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -15,6 +17,8 @@ public interface MenuEnchantment { * * @return the {@link Enchantment} associated with this custom enchantment */ + @Contract(pure = true) + @NotNull Enchantment enchantment(); /** @@ -23,5 +27,7 @@ public interface MenuEnchantment { * * @return a list of aliases for the enchantment */ + @Contract(pure = true) + @NotNull List aliases(); } diff --git a/API/src/main/java/fr/maxlego08/menu/api/engine/BaseInventory.java b/API/src/main/java/fr/maxlego08/menu/api/engine/BaseInventory.java index e44cab43..41a2f399 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/engine/BaseInventory.java +++ b/API/src/main/java/fr/maxlego08/menu/api/engine/BaseInventory.java @@ -5,34 +5,57 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Map; public interface BaseInventory extends InventoryHolder { + @Contract(pure = true) + @Nullable MenuPlugin getPlugin(); + @Contract(pure = true) + @Nullable Player getPlayer(); + @Contract(pure = true) boolean isClose(); - ItemButton addItem(int slot, ItemStack itemStack); + @Contract("_, null -> null") + @Nullable + ItemButton addItem(int slot,@Nullable ItemStack itemStack); - ItemButton addItem(int slot, ItemStack itemStack, boolean enableAntiDupe); + @Contract("_, null,_ -> null") + @Nullable + ItemButton addItem(int slot,@Nullable ItemStack itemStack, boolean enableAntiDupe); - ItemButton addItem(boolean inPlayerInventory, int slot, ItemStack itemStack); + @Contract("_, _, null -> null") + @Nullable + ItemButton addItem(boolean inPlayerInventory, int slot,@Nullable ItemStack itemStack); - ItemButton addItem(boolean inPlayerInventory, int slot, ItemStack itemStack, boolean enableAntiDupe); + @Contract("_, _, null, _ -> null") + @Nullable + ItemButton addItem(boolean inPlayerInventory, int slot,@Nullable ItemStack itemStack, boolean enableAntiDupe); + @Contract(pure = true) + @Nullable String getGuiName(); + @Contract(pure = true) + @NotNull Inventory getSpigotInventory(); + @Contract(pure = true) @NotNull Inventory getInventory(); + @Contract(pure = true) + @Nullable Object[] getArgs(); + @Contract(pure = true) int getPage(); void removeItem(int slot); @@ -41,14 +64,20 @@ public interface BaseInventory extends InventoryHolder { void clearItem(); + @Contract(pure = true) + @NotNull Map getItems(); + @Contract(pure = true) + @NotNull Map getPlayerInventoryItems(); + @Contract(pure = true) boolean isDisableClick(); void setDisableClick(boolean disableClick); + @Contract(pure = true) boolean isDisablePlayerInventoryClick(); void setDisablePlayerInventoryClick(boolean disablePlayerInventoryClick); diff --git a/API/src/main/java/fr/maxlego08/menu/api/engine/InventoryEngine.java b/API/src/main/java/fr/maxlego08/menu/api/engine/InventoryEngine.java index 8635b4f4..67743151 100644 --- a/API/src/main/java/fr/maxlego08/menu/api/engine/InventoryEngine.java +++ b/API/src/main/java/fr/maxlego08/menu/api/engine/InventoryEngine.java @@ -2,26 +2,38 @@ import fr.maxlego08.menu.api.Inventory; import fr.maxlego08.menu.api.button.Button; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; public interface InventoryEngine extends BaseInventory { + @Contract(pure = true) + @NotNull List getOldInventories(); + @Contract(pure = true) + @NotNull List