Skip to content

Commit ef9387c

Browse files
author
TheProgramSrc
committed
ChangeLog:
• Added option to keep GUI opened (Not tested yet)
1 parent 88e4396 commit ef9387c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
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.2.1</version>
9+
<version>3.2.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SuperCoreAPI</name>

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ public String getCenteredTitle() {
121121
return result.append(title).toString();
122122
}
123123

124+
/**
125+
* Used to know if the GUI can be closed
126+
* @return true if can be closed, otherwise false
127+
*/
128+
public boolean canCloseGUI(){
129+
return true;
130+
}
131+
124132
/**
125133
* Adds a placeholder to the GUI (used on the title)
126134
* @param key The key of the placeholder
@@ -193,9 +201,13 @@ public void onClose(InventoryCloseEvent event){
193201
if(this.inventory != null){
194202
if(event.getInventory().equals(this.inventory)){
195203
if(event.getPlayer().equals(this.player)){
196-
this.getSpigotTasks().runTask(()->{
197-
HandlerList.unregisterAll(this);
198-
this.inventory = null;
204+
this.getSpigotTasks().runTaskLater(5L,()->{
205+
if(this.canCloseGUI()){
206+
HandlerList.unregisterAll(this);
207+
this.inventory = null;
208+
}else{
209+
this.open();
210+
}
199211
});
200212
}
201213
}
@@ -292,4 +304,5 @@ protected void onEvent(GUIEvent event){}
292304
* @return the buttons to place inside the GUI
293305
*/
294306
protected abstract GUIButton[] getButtons();
307+
295308
}

0 commit comments

Comments
 (0)