@@ -26,12 +26,12 @@ public class WindowManager implements Listener {
2626
2727 private static WindowManager instance ;
2828
29- private final Map <Inventory , AbstractWindow > windows = new HashMap <>();
30- private final Map <Player , AbstractWindow > openWindows = new HashMap <>();
29+ private final Map <Inventory , AbstractWindow > windowsByInventory = new HashMap <>();
30+ private final Map <Player , AbstractWindow > windowsByPlayer = new HashMap <>();
3131
3232 private WindowManager () {
3333 Bukkit .getPluginManager ().registerEvents (this , InvUI .getInstance ().getPlugin ());
34- InvUI .getInstance ().addDisableHandler (() -> new HashSet <>(windows .values ()).forEach (window -> window . remove ( true ) ));
34+ InvUI .getInstance ().addDisableHandler (() -> new HashSet <>(windowsByPlayer .values ()).forEach (AbstractWindow :: close ));
3535 }
3636
3737 /**
@@ -50,7 +50,7 @@ public static WindowManager getInstance() {
5050 * @param window The {@link AbstractWindow} to add
5151 */
5252 public void addWindow (AbstractWindow window ) {
53- windows .put (window .getInventories ()[0 ], window );
53+ windowsByInventory .put (window .getInventories ()[0 ], window );
5454 }
5555
5656 /**
@@ -60,7 +60,7 @@ public void addWindow(AbstractWindow window) {
6060 * @param window The {@link AbstractWindow} to remove
6161 */
6262 public void removeWindow (AbstractWindow window ) {
63- windows .remove (window .getInventories ()[0 ]);
63+ windowsByInventory .remove (window .getInventories ()[0 ]);
6464 }
6565
6666 /**
@@ -71,7 +71,7 @@ public void removeWindow(AbstractWindow window) {
7171 */
7272 @ Nullable
7373 public Window getWindow (Inventory inventory ) {
74- return windows .get (inventory );
74+ return windowsByInventory .get (inventory );
7575 }
7676
7777 /**
@@ -82,25 +82,25 @@ public Window getWindow(Inventory inventory) {
8282 */
8383 @ Nullable
8484 public Window getOpenWindow (Player player ) {
85- return openWindows .get (player );
85+ return windowsByPlayer .get (player );
8686 }
8787
8888 /**
89- * Gets a set of all registered {@link Window Windows}.
89+ * Gets a set of all open {@link Window Windows}.
9090 *
9191 * @return A set of all {@link Window Windows}
9292 */
9393 public Set <Window > getWindows () {
94- return new HashSet <>(windows .values ());
94+ return new HashSet <>(windowsByInventory .values ());
9595 }
9696
9797 /**
98- * Gets a set of all currently opened {@link Window Windows}.
99- *
100- * @return A set of all opened {@link Window Windows}
98+ * Gets a set of all open {@link Window Windows}.
99+ * @deprecated Use {@link #getWindows()} instead
101100 */
101+ @ Deprecated
102102 public Set <Window > getOpenWindows () {
103- return new HashSet <>( openWindows . values () );
103+ return getWindows ( );
104104 }
105105
106106 @ EventHandler
@@ -127,15 +127,15 @@ private void handleInventoryClose(InventoryCloseEvent event) {
127127 window .handleCloseEvent (player );
128128 }
129129
130- openWindows .remove (player );
130+ windowsByPlayer .remove (player );
131131 }
132132
133133 @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
134134 private void handleInventoryOpen (InventoryOpenEvent event ) {
135135 AbstractWindow window = (AbstractWindow ) getWindow (event .getInventory ());
136136 if (window != null ) {
137137 window .handleOpenEvent (event );
138- openWindows .put ((Player ) event .getPlayer (), window );
138+ windowsByPlayer .put ((Player ) event .getPlayer (), window );
139139 }
140140 }
141141
@@ -145,7 +145,7 @@ private void handlePlayerQuit(PlayerQuitEvent event) {
145145 AbstractWindow window = (AbstractWindow ) getOpenWindow (player );
146146 if (window != null ) {
147147 window .handleCloseEvent (player );
148- openWindows .remove (player );
148+ windowsByPlayer .remove (player );
149149 }
150150 }
151151
0 commit comments