2121import xyz .theprogramsrc .supercoreapi .spigot .guis .objects .GUIRows ;
2222import xyz .theprogramsrc .supercoreapi .spigot .utils .xseries .XMaterial ;
2323
24+ import java .util .ArrayList ;
2425import java .util .HashMap ;
26+ import java .util .List ;
2527import java .util .Map ;
2628import java .util .concurrent .atomic .AtomicReference ;
2729
@@ -31,6 +33,7 @@ public abstract class GUI extends SpigotModule {
3133 private final HashMap <String , String > placeholders ;
3234 private final Player player ;
3335 private HashMap <Integer , GUIButton > buttons ;
36+ private List <GUIButton > extraButtons ;
3437
3538 /**
3639 * Creates a new GUI
@@ -42,6 +45,7 @@ public GUI(SpigotPlugin plugin, Player player){
4245 this .player = player ;
4346 this .placeholders = new HashMap <>();
4447 this .buttons = new HashMap <>();
48+ this .extraButtons = new ArrayList <>();
4549 }
4650
4751 /**
@@ -107,17 +111,17 @@ public void clear(){
107111 public void addButton (GUIButton guiButton ){
108112 if (guiButton .getSlot () == -1 ){
109113 if (this .inventory != null ){
110- this .buttons . put ( this .inventory .firstEmpty (), guiButton );
114+ this .extraButtons . add ( guiButton . setSlot ( this .inventory .firstEmpty ()) );
111115 }else {
112116 for (int i = 0 ; i < this .getRows ().getSize (); ++i ){
113117 if (!this .buttons .containsKey (i )){
114- this .buttons . put ( i , guiButton );
118+ this .extraButtons . add ( guiButton . setSlot ( i ) );
115119 return ;
116120 }
117121 }
118122 }
119123 }else {
120- this .buttons . put ( guiButton . getSlot (), guiButton );
124+ this .extraButtons . add ( guiButton );
121125 }
122126 }
123127
@@ -127,6 +131,7 @@ public void addButton(GUIButton guiButton){
127131 */
128132 public void remButton (int slot ){
129133 this .buttons .remove (slot );
134+ this .extraButtons .removeIf (b -> b .getSlot () == slot );
130135 }
131136
132137 /**
@@ -311,8 +316,10 @@ protected void onEvent(GUIEvent event){}
311316 private void loadGUIItemsAndSyncItems (){
312317 if (this .inventory != null ){
313318 this .buttons = new HashMap <>();
314- GUIButton [] buttons = this .getButtons ();
315- if (buttons == null ) return ;
319+ List <GUIButton > buttons = new ArrayList <>();
320+ GUIButton [] array = this .getButtons ();
321+ if (array != null ) buttons .addAll (Utils .toList (array ));
322+ buttons .addAll (this .extraButtons );
316323 for (GUIButton b : buttons ) {
317324 int slot = b .getSlot ();
318325 if (slot == -1 ) {
0 commit comments