@@ -77,6 +77,7 @@ public class Menu implements IMenu, RandomAccess, Serializable {
77
77
protected int rows = 1 , size ;
78
78
79
79
protected ItemData data ;
80
+
80
81
protected ItemResponse [] slotActions ;
81
82
82
83
@ Getter
@@ -109,7 +110,6 @@ public class Menu implements IMenu, RandomAccess, Serializable {
109
110
this .title = title ;
110
111
this .size = rows * 9 ;
111
112
this .data = new ItemData (this );
112
- this .slotActions = new ItemResponse [size ];
113
113
this .inventory = this .title .toInventory (this , size );
114
114
}
115
115
@@ -119,20 +119,23 @@ public class Menu implements IMenu, RandomAccess, Serializable {
119
119
this .title = title ;
120
120
this .size = type .getLimit ();
121
121
this .data = new ItemData (this );
122
- this .slotActions = new ItemResponse [size ];
123
122
this .inventory = this .title .toInventory (this , type .getType ());
124
123
}
125
124
125
+ public ItemResponse [] getSlotActions () {
126
+ return (slotActions == null ) ? (slotActions = new ItemResponse [size ]) : slotActions ;
127
+ }
128
+
129
+ public boolean hasSlotActions () { return slotActions != null ; }
130
+
126
131
public MenuFiller getFiller () { return defaultFiller ; }
127
132
128
133
public <T extends MenuFiller > T getFiller (@ NotNull Class <T > value ) { return value .cast (defaultFiller ); }
129
134
130
135
@ NotNull
131
136
public MenuIterator iterator () { return new MenuIterator (IterationDirection .HORIZONTAL , this ); }
132
137
133
- public MenuIterator iterator (IterationDirection direction ) {
134
- return new MenuIterator (direction , this );
135
- }
138
+ public MenuIterator iterator (IterationDirection direction ) {return new MenuIterator (direction , this ); }
136
139
137
140
public MenuIterator iterator (int startingRow , int startingCol , IterationDirection direction ) {
138
141
return new MenuIterator (startingRow , startingCol , direction , this );
@@ -144,9 +147,7 @@ public MenuIterator iterator(int startingRow, int startingCol, IterationDirectio
144
147
145
148
public void forEach (Consumer <? super MenuItem > action ) { data .forEach (action ); }
146
149
147
- public List <HumanEntity > getViewers () {
148
- return inventory .getViewers ();
149
- }
150
+ public List <HumanEntity > getViewers () { return inventory .getViewers (); }
150
151
151
152
public boolean addItem (@ NotNull final ItemStack ... items ) {
152
153
return (changed = data .addItem (items ));
@@ -216,20 +217,16 @@ public Optional<MenuItem> get(Predicate<MenuItem> itemDescription) {
216
217
return Optional .ofNullable (getItem (itemDescription ));
217
218
}
218
219
219
- public void addSlotAction (int slot , ItemResponse response ) {
220
- slotActions [slot ] = response ;
221
- }
222
-
223
- public void addSlotAction (@ NotNull Slot slot , ItemResponse response ) {
224
- if (slot .isValid ()) slotActions [slot .slot ] = response ;
225
- }
226
-
227
- public void removeSlotAction (int slot , ItemResponse response ) {
220
+ public void setSlotAction (int slot , ItemResponse response ) {
221
+ ItemResponse [] slotActions = getSlotActions ();
228
222
slotActions [slot ] = response ;
229
223
}
230
224
231
- public void removeSlotAction (@ NotNull Slot slot , ItemResponse response ) {
232
- if (slot .isValid ()) slotActions [slot .slot ] = response ;
225
+ public void setSlotAction (@ NotNull Slot position , ItemResponse response ) {
226
+ if (position .isValid ()) {
227
+ ItemResponse [] slotActions = getSlotActions ();
228
+ slotActions [position .slot ] = response ;
229
+ }
233
230
}
234
231
235
232
public @ Nullable MenuItem getItem (Predicate <MenuItem > itemDescription ) {
@@ -321,21 +318,14 @@ public void open(@NotNull HumanEntity entity) {
321
318
}
322
319
323
320
public void close (@ NotNull final HumanEntity player ) {
324
- if (!inventory .equals (player .getOpenInventory ().getTopInventory ())) return ;
325
- SCHEDULER .runTaskLater (plugin , player ::closeInventory , 2L );
321
+ SCHEDULER .runTaskLater (plugin , player ::closeInventory , 1L );
326
322
}
327
323
328
- public boolean addModifier (Modifier modifier ) {
329
- return modifiers .add (modifier );
330
- }
324
+ public boolean addModifier (Modifier modifier ) { return modifiers .add (modifier ); }
331
325
332
- public boolean removeModifier (Modifier modifier ) {
333
- return modifiers .remove (modifier );
334
- }
326
+ public boolean removeModifier (Modifier modifier ) { return modifiers .remove (modifier ); }
335
327
336
- public boolean addAllModifiers () {
337
- return modifiers .addAll (Modifier .ALL );
338
- }
328
+ public boolean addAllModifiers () { return modifiers .addAll (Modifier .ALL ); }
339
329
340
330
public void removeAllModifiers () {
341
331
Modifier .ALL .forEach (modifiers ::remove );
0 commit comments