Skip to content

Commit e2c5c66

Browse files
committed
Removed not needed constructors
I also made all connecting to 1 constructor. Make it more easy work with the code and reduce the risk for create bugs.
1 parent d71a6aa commit e2c5c66

File tree

1 file changed

+18
-59
lines changed

1 file changed

+18
-59
lines changed

src/main/java/org/brokenarrow/menu/library/MenuHolder.java

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.bukkit.event.inventory.InventoryType;
1010
import org.bukkit.inventory.Inventory;
1111
import org.bukkit.inventory.ItemStack;
12-
import org.bukkit.plugin.Plugin;
1312

1413
import java.util.ArrayList;
1514
import java.util.List;
@@ -25,62 +24,11 @@
2524

2625
public class MenuHolder extends CreateMenus {
2726

28-
/**
29-
* Create menu instance.
30-
*
31-
* @param plugin your main class.
32-
* @param inventorySize size if menu.
33-
* @deprecated plugin and inventorySize will be removed, recplaced with method with out.
34-
*/
35-
public MenuHolder(final Plugin plugin, final int inventorySize) {
36-
super(plugin, inventorySize);
37-
}
38-
39-
/**
40-
* Create menu instance.
41-
*
42-
* @param plugin Your main class.
43-
* @param fillSlots Witch slots you want fill with items.
44-
* @param fillItems List of items you want parse inside gui on one or several pages.
45-
* @deprecated plugin and inventorySize will be removed, recplaced with method with out.
46-
*/
47-
48-
public MenuHolder(final Plugin plugin, final List<Integer> fillSlots, final List<?> fillItems) {
49-
super(plugin, fillSlots, fillItems);
50-
}
51-
52-
/**
53-
* Create menu instance.
54-
*
55-
* @param plugin your main class.
56-
* @param inventorySize size if menu.
57-
* @param shallCacheItems if it shall cache items and slots in this class, other case use {@link CreateMenus#getMenuButtonsCache()} to cache it own class.
58-
* @deprecated plugin and inventorySize will be removed, recplaced with method with out.
59-
*/
60-
61-
public MenuHolder(final Plugin plugin, final int inventorySize, final boolean shallCacheItems) {
62-
super(plugin, inventorySize, shallCacheItems);
63-
}
64-
65-
/**
66-
* Create menu instance.
67-
*
68-
* @param plugin Your main class.
69-
* @param fillSlots Witch slots you want fill with items.
70-
* @param fillItems List of items you want parse inside gui.
71-
* @param shallCacheItems if it shall cache items and slots in this class, other case use {@link CreateMenus#getMenuButtonsCache()} to cache it own class.
72-
* @deprecated plugin and inventorySize will be removed, recplaced with method with out.
73-
*/
74-
75-
public MenuHolder(final Plugin plugin, final List<Integer> fillSlots, final List<?> fillItems, final boolean shallCacheItems) {
76-
super(plugin, fillSlots, fillItems, shallCacheItems);
77-
}
78-
7927
/**
8028
* Create menu instance. With out any aguments. Recomend you set al lest inventory/menu size.
8129
*/
8230
public MenuHolder() {
83-
super();
31+
this(null, null, false);
8432
}
8533

8634
/**
@@ -91,7 +39,7 @@ public MenuHolder() {
9139
*/
9240

9341
public MenuHolder(final List<?> fillItems) {
94-
super(fillItems);
42+
this(null, fillItems, false);
9543
}
9644

9745
/**
@@ -100,7 +48,7 @@ public MenuHolder(final List<?> fillItems) {
10048
* @param shallCacheItems if it shall cache items and slots in this class, other case use {@link CreateMenus#getMenuButtonsCache()} to cache it own class.
10149
*/
10250
public MenuHolder(final boolean shallCacheItems) {
103-
super(shallCacheItems);
51+
this(null, null, shallCacheItems);
10452
}
10553

10654
/**
@@ -110,7 +58,7 @@ public MenuHolder(final boolean shallCacheItems) {
11058
* @param fillItems List of items you want parse inside gui on one or several pages.
11159
*/
11260
public MenuHolder(final List<Integer> fillSlots, final List<?> fillItems) {
113-
super(fillSlots, fillItems);
61+
this(fillSlots, fillItems, false);
11462
}
11563

11664
/**
@@ -325,7 +273,7 @@ public void setAllowShiftClick(final boolean allowShiftClick) {
325273
* @return true if it could set the page.
326274
*/
327275
public boolean setPage(final int page) {
328-
if (!this.getAddedButtonsCache().containsKey(page))
276+
if (!this.containsPage(page))
329277
return false;
330278

331279
this.pageNumber = page;
@@ -368,7 +316,7 @@ public void nextPage() {
368316
* @param menuButton the current button.
369317
*/
370318
public void updateButton(final MenuButton menuButton) {
371-
final Map<Integer, MenuData> menuDataMap = getMenuData(getPageNumber());
319+
final Map<Integer, MenuData> menuDataMap = getMenuButtons(getPageNumber());
372320
final Set<Integer> buttonSlots = this.getButtonSlots(menuButton);
373321
if (!buttonSlots.isEmpty()) {
374322
for (final int slot : buttonSlots) {
@@ -384,7 +332,7 @@ public void updateButton(final MenuButton menuButton) {
384332
this.getMenu().setItem(buttonSlot, itemStack);
385333
menuDataMap.put(getSlotFromCache(buttonSlot), new MenuData(itemStack, menuButton, ""));
386334
}
387-
this.getAddedButtonsCache().put(this.getPageNumber(), menuDataMap);
335+
this.putAddedButtonsCache(this.getPageNumber(), menuDataMap);
388336
}
389337

390338
/**
@@ -439,6 +387,17 @@ public void setIgnoreValidCheck(final boolean ignoreValidCheck) {
439387
this.ignoreValidCheck = ignoreValidCheck;
440388
}
441389

390+
/**
391+
* Get if several players to look inside the current inventory. If it's zero
392+
* then is only one player currently looking inside the inventory.
393+
*
394+
* @return amount of players curently looking in the inventory.
395+
*/
396+
@Override
397+
public int getAmountOfViewers() {
398+
return (int) this.getMenu().getViewers().stream().filter(entity -> entity instanceof Player).count() - 1;
399+
}
400+
442401
/**
443402
* Turn off this option if you not want it to auto fill in curent page.
444403
* This option will be set to true automatic.

0 commit comments

Comments
 (0)