From 72d13195dd9900feb7cfeefaea19701c88d3e64b Mon Sep 17 00:00:00 2001 From: Rubix327 Date: Sat, 28 May 2022 23:41:02 +0300 Subject: [PATCH] Changed Menu to AdvancedMenu in onClicked event. Added new Logger methods. --- src/main/java/org/mineacademy/fo/Logger.java | 42 +++- .../org/mineacademy/fo/menu/AdvancedMenu.java | 18 +- .../fo/menu/AdvancedMenuPagged.java | 4 +- .../org/mineacademy/fo/menu/MenuPagged.java | 4 +- .../mineacademy/fo/menu/MenuQuantitable.java | 2 +- .../mineacademy/fo/menu/button/Button.java | 72 ++++--- .../fo/menu/button/ButtonConversation.java | 7 +- .../fo/menu/button/ButtonMenu.java | 151 -------------- .../fo/menu/button/ButtonRemove.java | 196 ------------------ .../fo/menu/button/ButtonReturnBack.java | 76 ------- 10 files changed, 93 insertions(+), 479 deletions(-) delete mode 100644 src/main/java/org/mineacademy/fo/menu/button/ButtonMenu.java delete mode 100644 src/main/java/org/mineacademy/fo/menu/button/ButtonRemove.java delete mode 100644 src/main/java/org/mineacademy/fo/menu/button/ButtonReturnBack.java diff --git a/src/main/java/org/mineacademy/fo/Logger.java b/src/main/java/org/mineacademy/fo/Logger.java index 0b1b715ee..1aa0ccf4d 100644 --- a/src/main/java/org/mineacademy/fo/Logger.java +++ b/src/main/java/org/mineacademy/fo/Logger.java @@ -1,5 +1,7 @@ package org.mineacademy.fo; +import lombok.Getter; +import lombok.Setter; import org.mineacademy.fo.exception.CommandException; /** @@ -8,25 +10,51 @@ * */ public class Logger { - public static String LOG_PREFIX = ""; + @Getter @Setter + public static String logPrefix = ""; /** * Log an info message to the console. * @param s the message */ - public static void info(Object s){ Common.log(LOG_PREFIX + s); } + public static void info(Object s){ Common.log(logPrefix + s); } + + /** + * Log an info message without a prefix. + * @param s the message + */ + public static void infoNoPrefix(Object s){ + Common.logNoPrefix(s.toString()); + } + + /** + * See {@link Common#logFramed} + * @param s the message + */ + public static void infoFramed(Object s){ + Common.logFramed(logPrefix + s); + } + + /** + * See {@link Common#logF} + * @param s the message + * @param args replacements + */ + public static void infoF(Object s, Object... args){ + Common.logF(s.toString(), args); + } /** * Log a warning to the console. * @param s the warning message */ public static void warning(Object s){ - Common.warning("&e" + LOG_PREFIX + s); + Common.warning("&e" + logPrefix + s); } /** @@ -34,7 +62,7 @@ public static void warning(Object s){ * @param s the error message */ public static void error(Object s){ - Common.error(new CommandException(), "&6" + LOG_PREFIX + s); + Common.error(new CommandException(), "&6" + logPrefix + s); } /** @@ -43,7 +71,7 @@ public static void error(Object s){ * @param s the message */ public static void error(Throwable t, Object s){ - Common.error(t, "&6" + LOG_PREFIX + s); + Common.error(t, "&6" + logPrefix + s); } /** @@ -52,7 +80,7 @@ public static void error(Throwable t, Object s){ * @return colorized prefixed message */ public static String get(String s){ - return Common.colorize(LOG_PREFIX + s); + return Common.colorize(logPrefix + s); } } diff --git a/src/main/java/org/mineacademy/fo/menu/AdvancedMenu.java b/src/main/java/org/mineacademy/fo/menu/AdvancedMenu.java index 0d0c6897b..5deb342ca 100644 --- a/src/main/java/org/mineacademy/fo/menu/AdvancedMenu.java +++ b/src/main/java/org/mineacademy/fo/menu/AdvancedMenu.java @@ -151,7 +151,7 @@ protected Button getReturnBackButton(){ protected Button getReturnBackButton(@NotNull ItemStack item){ return new Button() { @Override - public void onClickedInMenu(Player player, Menu menu, ClickType click) { + public void onClickedInMenu(Player player, AdvancedMenu menu, ClickType click) { newInstanceOf(player, parentMenu).display(); } @@ -179,7 +179,7 @@ protected Button getRefreshButton(){ protected Button getRefreshButton(@NotNull ItemStack item){ return new Button() { @Override - public void onClickedInMenu(Player player, Menu menu, ClickType click) { + public void onClickedInMenu(Player player, AdvancedMenu menu, ClickType click) { SoundUtil.Play.POP(player); refreshMenu(); } @@ -207,7 +207,7 @@ protected Button getMenuButton(Class to){ protected Button getMenuButton(ItemStack item, Class to){ return new Button() { @Override - public void onClickedInMenu(Player player, Menu menu, ClickType click) { + public void onClickedInMenu(Player player, AdvancedMenu menu, ClickType click) { newInstanceOf(player, to).display(); } @@ -245,7 +245,7 @@ private AdvancedMenu newInstanceOf(Player player, Class protected Button getToolButton(Tool tool){ return new Button() { @Override - public void onClickedInMenu(Player player, Menu menu, ClickType click) { + public void onClickedInMenu(Player player, AdvancedMenu menu, ClickType click) { if (!player.getInventory().contains(tool.getItem())){ SoundUtil.Play.POP_HIGH(player); player.getInventory().addItem(tool.getItem()); @@ -298,13 +298,14 @@ protected Button getInfoButton(){ /** * Get the button that shows info about the menu. * By default, does nothing when clicked, but you can override it and add your behavior. - * This button gets its info from {@link #getInfoLore()}. So you can override it and set your custom information. + * This button gets its info from {@link #getInfoName()} and {@link #getInfoLore()}. + * So you can override them and set your custom name and lore. * @return the button */ protected Button getInfoButton(ItemStack item){ return new Button() { @Override - public void onClickedInMenu(Player player, Menu menu, ClickType click) { + public void onClickedInMenu(Player player, AdvancedMenu menu, ClickType click) { } @Override @@ -381,6 +382,11 @@ protected final void setLockedSlots(String figure){ } } + @Override + protected void onButtonClick(Player player, int slot, InventoryAction action, ClickType click, Button button) { + super.onButtonClick(player, slot, action, click, button); + } + @Override protected void onMenuClick(Player player, int slot, InventoryAction action, ClickType click, ItemStack cursor, ItemStack clicked, boolean cancelled) { if (getButtons().containsKey(slot)){ diff --git a/src/main/java/org/mineacademy/fo/menu/AdvancedMenuPagged.java b/src/main/java/org/mineacademy/fo/menu/AdvancedMenuPagged.java index 142394ee7..d46c5caf6 100644 --- a/src/main/java/org/mineacademy/fo/menu/AdvancedMenuPagged.java +++ b/src/main/java/org/mineacademy/fo/menu/AdvancedMenuPagged.java @@ -158,7 +158,7 @@ private void setElementsItems(){ private Button formPreviousButton(ItemStack itemStack){ return new Button() { @Override - public void onClickedInMenu(Player player, Menu menu, ClickType click) { + public void onClickedInMenu(Player player, AdvancedMenu menu, ClickType click) { if (currentPage <= 1) { CompSound.VILLAGER_NO.play(getViewer()); return; @@ -182,7 +182,7 @@ public ItemStack getItem() { private Button formNextButton(ItemStack itemStack){ return new Button() { @Override - public void onClickedInMenu(Player player, Menu menu, ClickType click) { + public void onClickedInMenu(Player player, AdvancedMenu menu, ClickType click) { if (currentPage >= getMaxPage()) { CompSound.VILLAGER_NO.play(getViewer()); return; diff --git a/src/main/java/org/mineacademy/fo/menu/MenuPagged.java b/src/main/java/org/mineacademy/fo/menu/MenuPagged.java index 8643e5e4f..58db7f59f 100644 --- a/src/main/java/org/mineacademy/fo/menu/MenuPagged.java +++ b/src/main/java/org/mineacademy/fo/menu/MenuPagged.java @@ -199,7 +199,7 @@ public Button formPreviousButton() { final boolean canGo = currentPage > 1; @Override - public void onClickedInMenu(final Player pl, final Menu menu, final ClickType click) { + public void onClickedInMenu(final Player pl, final AdvancedMenu menu, final ClickType click) { if (canGo) { currentPage = MathUtil.range(currentPage - 1, 1, pages.size()); @@ -230,7 +230,7 @@ public Button formNextButton() { final boolean canGo = currentPage < pages.size(); @Override - public void onClickedInMenu(final Player pl, final Menu menu, final ClickType click) { + public void onClickedInMenu(final Player pl, final AdvancedMenu menu, final ClickType click) { if (canGo) { currentPage = MathUtil.range(currentPage + 1, 1, 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 377eba1a4..a133f4856 100644 --- a/src/main/java/org/mineacademy/fo/menu/MenuQuantitable.java +++ b/src/main/java/org/mineacademy/fo/menu/MenuQuantitable.java @@ -55,7 +55,7 @@ default Button getEditQuantityButton(Menu menu) { return new Button() { @Override - public final void onClickedInMenu(Player pl, Menu clickedMenu, ClickType click) { + public final void onClickedInMenu(Player pl, AdvancedMenu clickedMenu, ClickType click) { setQuantity(click == ClickType.LEFT ? getQuantity().previous() : getQuantity().next()); menu.redraw(); 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 75600393b..b3d7deb5b 100644 --- a/src/main/java/org/mineacademy/fo/menu/button/Button.java +++ b/src/main/java/org/mineacademy/fo/menu/button/Button.java @@ -1,23 +1,23 @@ package org.mineacademy.fo.menu.button; -import java.util.ArrayList; -import java.util.List; -import java.util.function.BiConsumer; -import java.util.function.Consumer; - +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.inventory.ItemStack; import org.mineacademy.fo.conversation.SimpleDecimalPrompt; +import org.mineacademy.fo.menu.AdvancedMenu; import org.mineacademy.fo.menu.Menu; import org.mineacademy.fo.menu.model.ItemCreator; import org.mineacademy.fo.remain.CompMaterial; import org.mineacademy.fo.settings.SimpleLocalization; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; +import java.util.ArrayList; +import java.util.List; +import java.util.function.BiConsumer; +import java.util.function.Consumer; /** * Represents a clickable button in menu @@ -42,26 +42,6 @@ public abstract class Button { // Button functions // ---------------------------------------------------------------- - /** - * Called automatically from the button is clicked - * - * @param player - * @param menu - * @param click - */ - public abstract void onClickedInMenu(Player player, Menu menu, ClickType click); - - /** - * The item representing this button. Tip: Use {@link ItemCreator} to create it. - * - * @return the item for this button - */ - public abstract ItemStack getItem(); - - // ---------------------------------------------------------------- - // Static methods - // ---------------------------------------------------------------- - /** * Creates a new Nether Star button has no action on clicking * and it is used purely to display informative text. @@ -102,6 +82,10 @@ public static final DummyButton makeDummy(final ItemCreator.ItemCreatorBuilder b return makeDummy(builder.build()); } + // ---------------------------------------------------------------- + // Static methods + // ---------------------------------------------------------------- + /** * Creates a dummy button that does nothing when clicked * @@ -141,7 +125,7 @@ public ItemStack getItem() { } @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) { onClickFunction.accept(player); } }; @@ -163,7 +147,7 @@ public ItemStack getItem() { } @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) { onClickFunction.accept(player); } }; @@ -188,7 +172,7 @@ public ItemStack getItem() { } @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) { onClickFunction.accept(player, click); } }; @@ -209,12 +193,32 @@ public ItemStack getItem() { } @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) { SimpleDecimalPrompt.show(player, question, successAction); } }; } + /** + * Called automatically when the button is clicked + * + * @deprecated use {@link #onClickedInMenu(Player, AdvancedMenu, ClickType)} + */ + @Deprecated + public void onClickedInMenu(Player player, Menu menu, ClickType click){}; + + /** + * Called automatically when the button is clicked + */ + public abstract void onClickedInMenu(Player player, AdvancedMenu menu, ClickType click); + + /** + * The item representing this button. Tip: Use {@link ItemCreator} to create it. + * + * @return the item for this button + */ + public abstract ItemStack getItem(); + @Override public final String toString() { final ItemStack item = getItem(); @@ -242,7 +246,7 @@ public static final class DummyButton extends Button { * Do nothing when clicked */ @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) { } } } diff --git a/src/main/java/org/mineacademy/fo/menu/button/ButtonConversation.java b/src/main/java/org/mineacademy/fo/menu/button/ButtonConversation.java index 42ce1f8b8..9a7f2b73f 100644 --- a/src/main/java/org/mineacademy/fo/menu/button/ButtonConversation.java +++ b/src/main/java/org/mineacademy/fo/menu/button/ButtonConversation.java @@ -1,17 +1,16 @@ package org.mineacademy.fo.menu.button; +import lombok.Getter; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; import org.mineacademy.fo.Valid; import org.mineacademy.fo.conversation.SimpleConversation; import org.mineacademy.fo.conversation.SimplePrompt; -import org.mineacademy.fo.menu.Menu; +import org.mineacademy.fo.menu.AdvancedMenu; import org.mineacademy.fo.menu.model.ItemCreator; import org.mineacademy.fo.remain.CompMaterial; -import lombok.Getter; - /** * A button that runs a server conversation */ @@ -104,7 +103,7 @@ private ButtonConversation(SimpleConversation conversation, SimplePrompt prompt, } @Override - public void onClickedInMenu(Player player, Menu menu, ClickType click) { + public void onClickedInMenu(Player player, AdvancedMenu menu, ClickType click) { Valid.checkBoolean(conversation != null || prompt != null, "Conversation and prompt cannot be null!"); if (conversation != null) { diff --git a/src/main/java/org/mineacademy/fo/menu/button/ButtonMenu.java b/src/main/java/org/mineacademy/fo/menu/button/ButtonMenu.java deleted file mode 100644 index 28537a6c1..000000000 --- a/src/main/java/org/mineacademy/fo/menu/button/ButtonMenu.java +++ /dev/null @@ -1,151 +0,0 @@ -package org.mineacademy.fo.menu.button; - -import lombok.Getter; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.ItemStack; -import org.mineacademy.fo.ReflectionUtil; -import org.mineacademy.fo.Valid; -import org.mineacademy.fo.menu.Menu; -import org.mineacademy.fo.menu.model.ItemCreator; -import org.mineacademy.fo.remain.CompMaterial; - -import java.util.concurrent.Callable; - -/** - * A button that opens another menu - */ -@Deprecated -public final class ButtonMenu extends Button { - - /** - * Sometimes you need to allocate data when you create the button, - * but these data are not yet available when you make new instance of this button - *

- * Use this helper to set them right before showing the button - */ - private final Callable

menuLateBind; - - /** - * The menu this button opens - */ - private final Menu menuToOpen; - - /** - * The icon of this button - */ - @Getter - private final ItemStack item; - - /** - * Create a new instanceof using {@link Menu#newInstance()} when showing the menu? - */ - private final boolean newInstance; - - /** - * Create a new button that triggers another menu - * - * @param menuClass - * @param material - * @param name - * @param lore - */ - public ButtonMenu(final Class menuClass, final CompMaterial material, final String name, final String... lore) { - this(null, () -> ReflectionUtil.instantiate(menuClass), ItemCreator.of(material, name, lore).hideTags(true).build().make(), false); - } - - /** - * Create a new button that triggers another menu - * - * @param menuLateBind - * @param item - */ - public ButtonMenu(final Callable menuLateBind, final ItemCreator.ItemCreatorBuilder item) { - this(null, menuLateBind, item.hideTags(true).build().make(), false); - } - - /** - * Create a new button that triggers another menu - * - * @param menuLateBind - * @param item - */ - public ButtonMenu(final Callable menuLateBind, final ItemStack item) { - this(null, menuLateBind, item, false); - } - - /** - * Create a new button that triggers another menu - * - * @param menu - * @param material - * @param name - * @param lore - */ - public ButtonMenu(final Menu menu, final CompMaterial material, final String name, final String... lore) { - this(menu, ItemCreator.of(material, name, lore)); - } - - /** - * Create a new button that triggers another menu - * - * @param menu - * @param item - */ - public ButtonMenu(final Menu menu, final ItemCreator.ItemCreatorBuilder item) { - this(menu, null, item.hideTags(true).build().make(), false); - } - - /** - * Create a new button that triggers another menu - * - * @param menu - * @param item - */ - public ButtonMenu(final Menu menu, final ItemStack item) { - this(menu, null, item, false); - } - - public ButtonMenu(final Menu menu, final ItemStack item, final boolean newInstance) { - this(menu, null, item, newInstance); - } - - // Private constructor - private ButtonMenu(final Menu menuToOpen, final Callable menuLateBind, final ItemStack item, final boolean newInstance) { - this.menuToOpen = menuToOpen; - this.menuLateBind = menuLateBind; - this.item = item; - this.newInstance = newInstance; - } - - /** - * Automatically display another menu when the button is clicked - */ - @Override - public void onClickedInMenu(final Player pl, final Menu menu, final ClickType click) { - if (menuLateBind != null) { - Menu menuToOpen = null; - - try { - menuToOpen = menuLateBind.call(); - } catch (final Exception ex) { - ex.printStackTrace(); - - return; - } - - if (newInstance) - menuToOpen = menuToOpen.newInstance(); - - menuToOpen.displayTo(pl); - - } else { - Valid.checkNotNull(menuToOpen, "Report / ButtonTrigger requires either 'late bind menu' or normal menu to be set!"); - - if (newInstance) - menuToOpen.newInstance().displayTo(pl); - else - menuToOpen.displayTo(pl); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/mineacademy/fo/menu/button/ButtonRemove.java b/src/main/java/org/mineacademy/fo/menu/button/ButtonRemove.java deleted file mode 100644 index 27b10a6f0..000000000 --- a/src/main/java/org/mineacademy/fo/menu/button/ButtonRemove.java +++ /dev/null @@ -1,196 +0,0 @@ -package org.mineacademy.fo.menu.button; - -import java.util.Arrays; - -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.ItemStack; -import org.mineacademy.fo.Common; -import org.mineacademy.fo.menu.Menu; -import org.mineacademy.fo.menu.model.ItemCreator; -import org.mineacademy.fo.remain.CompColor; -import org.mineacademy.fo.remain.CompItemFlag; -import org.mineacademy.fo.remain.CompMaterial; -import org.mineacademy.fo.settings.SimpleLocalization; - -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - -/** - * Represents a standardized remove button that opens the remove confirmation dialog. - *

- * Typically we use this to remove an arena, class, upgrade etc. - */ -@Deprecated -@RequiredArgsConstructor -public class ButtonRemove extends Button { - - /** - * The parent menu - */ - private final Menu parentMenu; - - /** - * The type of the object to remove, for example class, upgrade, arena - */ - private final String toRemoveType; - - /** - * The name of the object to remove, for example "Warrior" for class - */ - private final String toRemoveName; - - /** - * The action that triggers when the object is removed - */ - private final ButtonRemoveAction removeAction; - - /** - * The icon for this button - */ - @Override - public ItemStack getItem() { - return ItemCreator - - .of(CompMaterial.LAVA_BUCKET) - .name("&4&lRemove " + toRemoveName) - - .lores(Arrays.asList( - "&r", - "&7The selected " + toRemoveType + " will", - "&7be removed permanently.")) - - .flag(CompItemFlag.HIDE_ATTRIBUTES) - .build().make(); - } - - public ItemStack getRemoveConfirmItem() { - return ItemCreator - - .ofWool(CompColor.RED) - .name("&6&lRemove " + toRemoveName) - - .lores(Arrays.asList( - "&r", - "&7Confirm that this " + toRemoveType + " will", - "&7be removed permanently.", - "&cCannot be undone.")) - - .flag(CompItemFlag.HIDE_ATTRIBUTES) - .build().make(); - } - - public String getMenuTitle() { - return "&0Confirm removal"; - } - - /** - * Open the confirm dialog when clicked - */ - @Override - public void onClickedInMenu(final Player pl, final Menu menu, final ClickType click) { - new MenuDialogRemove(parentMenu, new RemoveConfirmButton()).displayTo(pl); - } - - /** - * The button that when clicked, actually removes the object - */ - @RequiredArgsConstructor(access = AccessLevel.PRIVATE) - final class RemoveConfirmButton extends Button { - - @Override - public ItemStack getItem() { - return getRemoveConfirmItem(); - } - - /** - * Remove the object using {@link ButtonRemove#removeAction} - */ - @Override - public void onClickedInMenu(final Player player, final Menu menu, final ClickType click) { - player.closeInventory(); - removeAction.remove(toRemoveName); - - Common.tell(player, SimpleLocalization.Menu.ITEM_DELETED.replace("{item}", (!toRemoveType.isEmpty() ? toRemoveType + " " : "") + toRemoveName)); - } - } - - /** - * Fires the action to remove the object - */ - - @FunctionalInterface - public interface ButtonRemoveAction { - - /** - * Remove the object - * - * @param object the object's name, for example "Warrior" for class - */ - void remove(String object); - } - - /** - * A prepared menu to allow two-step object removal with a confirmation step - */ - final class MenuDialogRemove extends Menu { - - /** - * The confirmation button that triggers the removal - */ - private final Button confirmButton; - - /** - * The return button - */ - private final Button returnButton; - - /** - * Create a new confirmation remove dialog - * - * @param parentMenu the parent menu - * @param confirmButton the remove button - */ - public MenuDialogRemove(final Menu parentMenu, final RemoveConfirmButton confirmButton) { - super(parentMenu); - - this.confirmButton = confirmButton; - returnButton = new ButtonReturnBack(parentMenu); - - setSize(9 * 3); - setTitle(getMenuTitle()); - } - - /** - * Returns the proper item at the correct slot - * - * @param slot the slot - * @return the item or null - */ - @Override - public ItemStack getItemAt(final int slot) { - if (slot == 9 + 3) - return confirmButton.getItem(); - - if (slot == 9 + 5) - return returnButton.getItem(); - - return null; - } - - /** - * Do not add twice return buttons - * - * @see org.mineacademy.fo.menu.Menu#addReturnButton() - */ - @Override - protected boolean addReturnButton() { - return false; - } - - @Override - protected String[] getInfo() { - return null; - } - } -} \ No newline at end of file diff --git a/src/main/java/org/mineacademy/fo/menu/button/ButtonReturnBack.java b/src/main/java/org/mineacademy/fo/menu/button/ButtonReturnBack.java deleted file mode 100644 index 9d815f72c..000000000 --- a/src/main/java/org/mineacademy/fo/menu/button/ButtonReturnBack.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.mineacademy.fo.menu.button; - -import lombok.*; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.ItemStack; -import org.mineacademy.fo.menu.Menu; -import org.mineacademy.fo.menu.model.ItemCreator; -import org.mineacademy.fo.remain.CompMaterial; -import org.mineacademy.fo.settings.SimpleLocalization; - -import java.util.Arrays; -import java.util.List; - -/** - * Represents a standardized button that will return back to the parent menu - */ -@Deprecated -@RequiredArgsConstructor -@AllArgsConstructor -public final class ButtonReturnBack extends Button { - - /** - * The material for this button, door by default - */ - @Getter - @Setter - private static CompMaterial material = CompMaterial.OAK_DOOR; - - /** - * The title of this button - */ - @Getter - @Setter - private static String title = SimpleLocalization.Menu.BUTTON_RETURN_TITLE; - - /** - * The lore of this button - */ - @Getter - @Setter - private static List lore = Arrays.asList(SimpleLocalization.Menu.BUTTON_RETURN_LORE); - - /** - * The parent menu - */ - @NonNull - private final Menu parentMenu; - - /** - * Should we make a new instance of the parent menu? - *

- * False by default. - */ - private boolean makeNewInstance = false; - - /** - * The icon for this button - */ - @Override - public ItemStack getItem() { - return ItemCreator.of(material).name(title).lores(lore).build().make(); - } - - /** - * Open the parent menu when clicked - */ - @Override - public void onClickedInMenu(Player pl, Menu menu, ClickType click) { - if (makeNewInstance) - parentMenu.newInstance().displayTo(pl); - - else - parentMenu.displayTo(pl); - } -} \ No newline at end of file