From d2134c22d789184d05f16f01955470ca7aa5e97a Mon Sep 17 00:00:00 2001 From: Rubix327 Date: Thu, 2 Jun 2022 23:47:04 +0300 Subject: [PATCH] Upgraded to Foundation v6 - menus advancements --- .../java/org/mineacademy/fo/ItemUtil.java | 7 ----- .../java/org/mineacademy/fo/menu/Menu.java | 27 ------------------- .../fo/menu/MenuContainerChances.java | 14 +++++----- .../org/mineacademy/fo/menu/MenuPagged.java | 24 ++++++++--------- .../mineacademy/fo/menu/MenuQuantitable.java | 9 +++---- .../org/mineacademy/fo/menu/MenuTools.java | 9 +++---- .../mineacademy/fo/menu/button/Button.java | 7 +++-- 7 files changed, 28 insertions(+), 69 deletions(-) diff --git a/src/main/java/org/mineacademy/fo/ItemUtil.java b/src/main/java/org/mineacademy/fo/ItemUtil.java index 56d54e9ca..6802d1298 100644 --- a/src/main/java/org/mineacademy/fo/ItemUtil.java +++ b/src/main/java/org/mineacademy/fo/ItemUtil.java @@ -1,9 +1,6 @@ package org.mineacademy.fo; -import java.util.ArrayList; -import java.util.List; - import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -21,9 +18,6 @@ import org.mineacademy.fo.remain.CompMaterial; import org.mineacademy.fo.remain.nbt.NBTItem; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import lombok.NonNull; import java.util.ArrayList; import java.util.List; @@ -221,7 +215,6 @@ else if (firstHas && !secondHas || !firstHas && secondHas) return firstNbt.getString(key).equals(secondNbt.getString(key)); } -} /** * Get the amount of the given item in the player's inventory. diff --git a/src/main/java/org/mineacademy/fo/menu/Menu.java b/src/main/java/org/mineacademy/fo/menu/Menu.java index 4dd228871..50ab974df 100644 --- a/src/main/java/org/mineacademy/fo/menu/Menu.java +++ b/src/main/java/org/mineacademy/fo/menu/Menu.java @@ -3,14 +3,6 @@ import lombok.Getter; import lombok.NonNull; import lombok.Setter; -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.Nullable; - import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryAction; @@ -30,9 +22,6 @@ import org.mineacademy.fo.menu.button.Button; import org.mineacademy.fo.menu.button.Button.DummyButton; import org.mineacademy.fo.menu.button.annotation.Position; -import org.mineacademy.fo.menu.button.ButtonReturnBack; -import org.mineacademy.fo.menu.button.StartPosition; -import org.mineacademy.fo.menu.button.annotation.Position; import org.mineacademy.fo.menu.model.InventoryDrawer; import org.mineacademy.fo.menu.model.ItemCreator; import org.mineacademy.fo.menu.model.MenuClickLocation; @@ -48,9 +37,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import lombok.Getter; -import lombok.NonNull; -import lombok.Setter; /** * The core class of Menu. Represents a simple menu. @@ -817,19 +803,6 @@ protected String[] getInfo() { return null; } - /** - * Set the menu's description - * - *

- * Used to create an info bottom in bottom left corner, see - * {@link Button#makeInfo(String...)} - * - * @param info the info to set - */ - protected final void setInfo(final String... info) { - this.info = info; - } - /** * Get the viewer that this instance of this menu is associated with * diff --git a/src/main/java/org/mineacademy/fo/menu/MenuContainerChances.java b/src/main/java/org/mineacademy/fo/menu/MenuContainerChances.java index 2815492c7..4a786b6d0 100644 --- a/src/main/java/org/mineacademy/fo/menu/MenuContainerChances.java +++ b/src/main/java/org/mineacademy/fo/menu/MenuContainerChances.java @@ -1,5 +1,9 @@ package org.mineacademy.fo.menu; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryAction; @@ -17,11 +21,6 @@ import org.mineacademy.fo.model.Tuple; import org.mineacademy.fo.remain.CompMaterial; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; - /** * A menu that lets players put items into the container and save them. * @@ -69,7 +68,6 @@ protected MenuContainerChances(Menu parent) { * Create a new menu that can edit chances of the items you put inside. * * @param parent - * @param startMode * @param returnMakesNewInstance */ protected MenuContainerChances(Menu parent, boolean returnMakesNewInstance) { @@ -84,7 +82,7 @@ protected MenuContainerChances(Menu parent, boolean returnMakesNewInstance) { * Change the menu mode and refresh its content. */ @Override - public void onClickedInMenu(Player player, Menu menu, ClickType click) { + public void onClickedInMenu(Player player, AdvancedMenu menu, ClickType click) { final MenuContainerChances instance = MenuContainerChances.this; // Call event to properly save data without us having to restart the menu completely @@ -229,7 +227,7 @@ public final boolean isActionAllowed(final MenuClickLocation location, final int * Return true for the slots you want players to be able to edit. * By default we enable them to edit anything above the bottom bar. * - * This is called from {@link #isActionAllowed(MenuClickLocation, int, ItemStack, ItemStack)} and + * This is called from {@link #isActionAllowed(MenuClickLocation, int, ItemStack, ItemStack, InventoryAction)} and * by defaults forwards the call to {@link #canEditItem(int)} * * @param location diff --git a/src/main/java/org/mineacademy/fo/menu/MenuPagged.java b/src/main/java/org/mineacademy/fo/menu/MenuPagged.java index af947b062..b30029706 100644 --- a/src/main/java/org/mineacademy/fo/menu/MenuPagged.java +++ b/src/main/java/org/mineacademy/fo/menu/MenuPagged.java @@ -1,12 +1,9 @@ package org.mineacademy.fo.menu; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.Nullable; - +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; +import lombok.val; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryAction; @@ -22,10 +19,11 @@ import org.mineacademy.fo.remain.CompMaterial; import org.mineacademy.fo.settings.SimpleLocalization; -import lombok.Getter; -import lombok.NonNull; -import lombok.Setter; -import lombok.val; +import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * An advanced menu listing items with automatic page support @@ -258,7 +256,7 @@ public Button formPreviousButton() { final boolean canGo = MenuPagged.this.currentPage > 1; @Override - public void onClickedInMenu(final Player player, final Menu menu, final ClickType click) { + public void onClickedInMenu(final Player player, final AdvancedMenu menu, final ClickType click) { if (this.canGo) { MenuPagged.this.currentPage = MathUtil.range(MenuPagged.this.currentPage - 1, 1, MenuPagged.this.pages.size()); @@ -289,7 +287,7 @@ public Button formNextButton() { final boolean canGo = MenuPagged.this.currentPage < MenuPagged.this.pages.size(); @Override - public void onClickedInMenu(final Player player, final Menu menu, final ClickType click) { + public void onClickedInMenu(final Player player, final AdvancedMenu menu, final ClickType click) { if (this.canGo) { MenuPagged.this.currentPage = MathUtil.range(MenuPagged.this.currentPage + 1, 1, MenuPagged.this.pages.size()); diff --git a/src/main/java/org/mineacademy/fo/menu/MenuQuantitable.java b/src/main/java/org/mineacademy/fo/menu/MenuQuantitable.java index eb4331acc..686a1baea 100644 --- a/src/main/java/org/mineacademy/fo/menu/MenuQuantitable.java +++ b/src/main/java/org/mineacademy/fo/menu/MenuQuantitable.java @@ -1,8 +1,6 @@ package org.mineacademy.fo.menu; -import java.util.Arrays; -import java.util.List; - +import lombok.NonNull; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; @@ -14,7 +12,8 @@ import org.mineacademy.fo.model.Replacer; import org.mineacademy.fo.remain.CompMaterial; -import lombok.NonNull; +import java.util.Arrays; +import java.util.List; /** * Advanced menu concept allowing to change quality of an item by more than 1 on @@ -90,7 +89,7 @@ default Button getQuantityButton(Menu menu) { return new Button() { @Override - public final void onClickedInMenu(Player player, Menu clickedMenu, ClickType clickType) { + public final void onClickedInMenu(Player player, AdvancedMenu clickedMenu, ClickType clickType) { final MenuQuantity nextQuantity = clickType == ClickType.LEFT ? MenuQuantitable.this.getQuantity().previous(MenuQuantitable.this.allowDecimalQuantities()) : MenuQuantitable.this.getQuantity().next(MenuQuantitable.this.allowDecimalQuantities()); Valid.checkNotNull(nextQuantity, "Next quantity cannot be null. Current: " + MenuQuantitable.this.getQuantity() + " Click: " + clickType); diff --git a/src/main/java/org/mineacademy/fo/menu/MenuTools.java b/src/main/java/org/mineacademy/fo/menu/MenuTools.java index 8737ae7e2..39c9fbed7 100644 --- a/src/main/java/org/mineacademy/fo/menu/MenuTools.java +++ b/src/main/java/org/mineacademy/fo/menu/MenuTools.java @@ -1,8 +1,5 @@ package org.mineacademy.fo.menu; -import java.util.ArrayList; -import java.util.List; - import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -16,6 +13,9 @@ import org.mineacademy.fo.plugin.SimplePlugin; import org.mineacademy.fo.settings.SimpleLocalization; +import java.util.ArrayList; +import java.util.List; + /** * A standardized menu to display a list of tools player can toggle to get in * his inventory @@ -53,7 +53,7 @@ protected MenuTools(final Menu parent) { /** * Attempts to automatically compile a set of tools Accepts an array containing - * {@link Button}, {@link ItemStack} or enter 0 for air. + * {@link org.mineacademy.fo.menu.button.Button}, {@link ItemStack} or enter 0 for air. * * @return the array of items in this menu */ @@ -133,7 +133,6 @@ private final ToggleableTool findTool(final ItemStack item) { return null; } - @Override protected int getInfoButtonPosition() { return this.getSize() - 1; } diff --git a/src/main/java/org/mineacademy/fo/menu/button/Button.java b/src/main/java/org/mineacademy/fo/menu/button/Button.java index 63a011bcb..1f025ae18 100644 --- a/src/main/java/org/mineacademy/fo/menu/button/Button.java +++ b/src/main/java/org/mineacademy/fo/menu/button/Button.java @@ -229,7 +229,7 @@ public static final Button makeBoolean(ItemCreator creator, Supplier ge return new Button() { @Override - public void onClickedInMenu(Player player, Menu menu, ClickType click) { + public void onClickedInMenu(Player player, AdvancedMenu menu, ClickType click) { final boolean has = getter.get(); setter.accept(!has); @@ -283,7 +283,7 @@ public static Button makeIntegerPrompt(ItemCreator item, String question, String return new Button() { @Override - public void onClickedInMenu(Player player, Menu menu, ClickType click) { + public void onClickedInMenu(Player player, AdvancedMenu menu, ClickType click) { new SimplePrompt() { @Override @@ -355,7 +355,6 @@ public static Button makeDecimalPrompt(ItemCreator item, String question, Ranged * * @param item * @param question - * @param successAction */ public static Button makeDecimalPrompt(ItemCreator item, String question, String menuTitle, RangedValue minMaxRange, @Nullable Supplier getter, Consumer setter) { return new Button() { @@ -432,7 +431,7 @@ public static Button makeStringPrompt(ItemCreator creator, String question, @Nul return new Button() { @Override - public void onClickedInMenu(Player player, Menu menu, ClickType click) { + public void onClickedInMenu(Player player, AdvancedMenu menu, ClickType click) { new SimpleStringPrompt(question) { @Override