Skip to content

Commit

Permalink
Upgraded to Foundation v6 - menus advancements
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubix327 committed Jun 2, 2022
1 parent aeaa5ca commit d2134c2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 69 deletions.
7 changes: 0 additions & 7 deletions src/main/java/org/mineacademy/fo/ItemUtil.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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.
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/org/mineacademy/fo/menu/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -817,19 +803,6 @@ protected String[] getInfo() {
return null;
}

/**
* Set the menu's description
*
* <p>
* 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
*
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/mineacademy/fo/menu/MenuContainerChances.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/org/mineacademy/fo/menu/MenuPagged.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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());

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/mineacademy/fo/menu/MenuQuantitable.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/mineacademy/fo/menu/MenuTools.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -133,7 +133,6 @@ private final ToggleableTool findTool(final ItemStack item) {
return null;
}

@Override
protected int getInfoButtonPosition() {
return this.getSize() - 1;
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/mineacademy/fo/menu/button/Button.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public static final Button makeBoolean(ItemCreator creator, Supplier<Boolean> 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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Object> getter, Consumer<Double> setter) {
return new Button() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d2134c2

Please sign in to comment.