Skip to content

Commit df499b9

Browse files
author
TheProgramSrc
committed
Change Log:
• Bug Fix
1 parent 3b45c00 commit df499b9

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>xyz.theprogramsrc</groupId>
88
<artifactId>SuperCoreAPI</artifactId>
9-
<version>3.6.0</version>
9+
<version>3.6.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SuperCoreAPI</name>

src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/GUI.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import xyz.theprogramsrc.supercoreapi.spigot.guis.objects.GUIRows;
2222
import xyz.theprogramsrc.supercoreapi.spigot.utils.xseries.XMaterial;
2323

24+
import java.util.ArrayList;
2425
import java.util.HashMap;
26+
import java.util.List;
2527
import java.util.Map;
2628
import 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

Comments
 (0)