1- package com .cosimo .utilities .menu . manager ;
1+ package com .cosimo .utilities .menu ;
22
3- import com .cosimo .utilities .menu .IMenu ;
43import com .google .common .base .Preconditions ;
54import lombok .NonNull ;
65import org .bukkit .Bukkit ;
2423import java .util .logging .Level ;
2524
2625/**
27- * A {@link Listener} that filters {@link org.bukkit.event.inventory.InventoryEvent}s to registered {@link Inventory}
28- * {@link IMenu}s. Menu inventory listening is delegated and centralised in one {@link MenuManager} because of the
29- * assumption that constantly registering and unregistering new {@link Listener}s for each {@link IMenu} is slow.
26+ * A {@link Listener} that filters and dispatches {@link org.bukkit.event.inventory.InventoryEvent}s to registered
27+ * {@link Inventory} {@link IMenu}s. Menu inventory listening is delegated and centralised in one {@link MenuManager}
28+ * because of the assumption that constantly registering and unregistering new {@link Listener}s for each {@link IMenu}
29+ * is slow.
3030 *
3131 * <p><strong>Note:</strong> {@link IMenu}s should be unregistered from their {@link MenuManager} when they're
3232 * not in use anymore, such as when the last viewer closes an {@link IMenu}. The unfollowing of this rule will cause a
3535 * <p><strong>Warning:</strong> {@link IMenu}s in multiple {@link MenuManager} instances may cause
3636 * duplicate event handler calls.
3737 *
38- * @param <E> {@link IMenu} subclass restriction that's always expected to be received or added to this
39- * {@link MenuManager}
4038 * @author CosimoTiger
4139 */
42- public class MenuManager < E extends IMenu > implements Listener {
40+ public class MenuManager implements Listener {
4341
4442 // TODO: WeakHashMap? Inventories might be referenced only by their Bukkit viewers.
4543 // WeakHashMap<Inventory, WeakReference<IMenu>> = new WeakHashMap<>(4);
4644 /**
4745 * Stores {@link IMenu} associations to their {@link Inventory} instances for quick access.
4846 */
49- private final Map <Inventory , E > menus ;
47+ private final Map <Inventory , IMenu > menus ;
5048 private final Plugin provider ;
5149
5250 /**
@@ -57,7 +55,7 @@ public class MenuManager<E extends IMenu> implements Listener {
5755 * @throws IllegalArgumentException If the {@link Plugin} argument is null
5856 * @throws IllegalStateException If the {@link Plugin} argument is not enabled
5957 */
60- protected MenuManager (@ NonNull Plugin provider , @ NonNull Map <Inventory , E > mapImpl ) {
58+ protected MenuManager (@ NonNull Plugin provider , @ NonNull Map <Inventory , IMenu > mapImpl ) {
6159 Preconditions .checkState (provider .isEnabled (), "Plugin provider argument can't be disabled" );
6260 Bukkit .getPluginManager ().registerEvents (this , this .provider = provider );
6361 this .menus = mapImpl ;
@@ -82,7 +80,7 @@ public MenuManager(@NonNull Plugin provider) {
8280 * @throws IllegalArgumentException If the {@link Inventory} argument is null
8381 */
8482 @ NonNull
85- public Optional <E > unregisterMenu (@ NonNull Inventory inventory ) {
83+ public Optional <IMenu > unregisterMenu (@ NonNull Inventory inventory ) {
8684 return Optional .ofNullable (this .menus .remove (inventory ));
8785 }
8886
@@ -94,7 +92,7 @@ public Optional<E> unregisterMenu(@NonNull Inventory inventory) {
9492 * @throws IllegalArgumentException If the {@link IMenu} argument is null
9593 */
9694 @ NonNull
97- public Optional <E > unregisterMenu (@ NonNull E menu ) {
95+ public Optional <IMenu > unregisterMenu (@ NonNull IMenu menu ) {
9896 return Optional .ofNullable (this .menus .remove (menu .getInventory ()));
9997 }
10098
@@ -107,7 +105,7 @@ public Optional<E> unregisterMenu(@NonNull E menu) {
107105 * @throws IllegalArgumentException If the {@link IMenu} argument is null
108106 */
109107 @ NonNull
110- public Optional <E > registerMenu (@ NonNull E menu ) {
108+ public Optional <IMenu > registerMenu (@ NonNull IMenu menu ) {
111109 return Optional .ofNullable (this .menus .put (menu .getInventory (), menu ));
112110 }
113111
@@ -120,7 +118,7 @@ public Optional<E> registerMenu(@NonNull E menu) {
120118 * @return This instance, useful for chaining
121119 */
122120 @ NonNull
123- public MenuManager < E > closeMenus () {
121+ public MenuManager closeMenus () {
124122 /*
125123 * Closing each menu calls an InventoryCloseEvent which may unregister a menu from the MenuManager Map of menus.
126124 * Therefore, a ConcurrentModificationException needs to be avoided using an Iterator.
@@ -141,7 +139,7 @@ public MenuManager<E> closeMenus() {
141139 * @throws IllegalArgumentException If the {@link Inventory} argument is null
142140 */
143141 @ NonNull
144- public Optional <E > getMenu (@ NonNull Inventory inventory ) {
142+ public Optional <IMenu > getMenu (@ NonNull Inventory inventory ) {
145143 return Optional .ofNullable (this .menus .get (inventory ));
146144 }
147145
@@ -154,7 +152,7 @@ public Optional<E> getMenu(@NonNull Inventory inventory) {
154152 * @throws IllegalArgumentException If the viewer argument is null
155153 */
156154 @ NonNull
157- public Optional <E > getMenu (@ NonNull HumanEntity viewer ) {
155+ public Optional <IMenu > getMenu (@ NonNull HumanEntity viewer ) {
158156 return this .getMenu (viewer .getOpenInventory ().getTopInventory ());
159157 }
160158
@@ -166,7 +164,7 @@ public Optional<E> getMenu(@NonNull HumanEntity viewer) {
166164 */
167165 @ NonNull
168166 @ UnmodifiableView
169- public Map <Inventory , E > getMap () {
167+ public Map <Inventory , IMenu > getMap () {
170168 return Collections .unmodifiableMap (this .menus );
171169 }
172170
0 commit comments