Skip to content

Commit b3bee56

Browse files
author
Francisco Solis
authored
Fixes & New Gui System (#14)
* Now the SettingsStorage#getPrefix method will add a new space at the end of the prefix. * Now GuiModel has an option to fill all the empty slots with an entry * Now GuiModel has an option to fill certain slots with an entry * Fixes SettingsGui not showing settings selector
1 parent dcd4a47 commit b3bee56

File tree

5 files changed

+78
-6
lines changed

5 files changed

+78
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## v5.2.1 Changelog
2+
```
3+
* Now the SettingsStorage#getPrefix method will add a new space at the end of the prefix.
4+
* Now GuiModel has an option to fill all the empty slots with an entry
5+
* Now GuiModel has an option to fill certain slots with an entry
6+
* Fixes SettingsGui not showing settings selector
7+
```
8+
19
## v5.2.0 Changelog
210
```
311
* New Gui System (`xyz.thepogramsrc.superocreapi.spigot.gui.Gui`)

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>5.2.0</version>
9+
<version>5.2.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SuperCoreAPI</name>

src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/objets/GuiModel.java

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import java.util.LinkedHashMap;
44

5+
import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule;
6+
57
/**
68
* Representation of the Gui Model
79
* @since 5.2.0
810
*/
9-
public class GuiModel {
11+
public class GuiModel extends SpigotModule{
1012

1113
private GuiTitle title;
1214
private GuiRows rows;
@@ -46,6 +48,9 @@ public LinkedHashMap<Integer, GuiEntry> getButtons() {
4648
return buttons;
4749
}
4850

51+
/**
52+
* Clear the buttons from the Gui
53+
*/
4954
public void clearButtons(){
5055
this.buttons.clear();
5156
}
@@ -72,6 +77,47 @@ public void addButton(GuiEntry entry){
7277
}
7378
}
7479

80+
/**
81+
* Fills all the empty slots with the given entry
82+
* @param entry The entry of the button to add to all the empty slots
83+
* @since 5.2.1
84+
*/
85+
public void fillEmptySlotsWithEntry(GuiEntry entry){
86+
for(int i = 0; i < this.rows.size; i++){
87+
if(!this.buttons.containsKey(i)){
88+
this.setButton(i, entry);
89+
}
90+
}
91+
}
92+
93+
/**
94+
* Fills the empty slots with the empty item.
95+
* See {@link xyz.theprogramsrc.supercoreapi.spigot.items.PreloadedItems#emptyItem}
96+
* @since 5.2.1
97+
*/
98+
public void fillEmptySlots(){
99+
this.fillEmptySlotsWithEntry(new GuiEntry(this.getPreloadedItems().emptyItem()));
100+
}
75101

76-
102+
/**
103+
* Fills the specified slots with the specified entry.
104+
* @param entry The entry of the button to add to the given slots
105+
* @param slots The slots to fill
106+
* @since 5.2.1
107+
*/
108+
109+
public void fillWithEntry(GuiEntry entry, int[] slots){
110+
for(int slot : slots){
111+
this.setButton(slot, entry);
112+
}
113+
}
114+
115+
/**
116+
* Fills the specified slots with an empty item.
117+
* @param slots The slots to fill with the empty item
118+
* @since 5.2.1
119+
*/
120+
public void fillWithEmptyItem(int[] slots){
121+
this.fillWithEntry(new GuiEntry(this.getPreloadedItems().emptyItem()), slots);
122+
}
77123
}

src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/precreated/settings/SettingsGui.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,24 @@ public void onBuild(GuiModel model) {
7575
}
7676
});
7777
}else{
78+
SettingPane pane = this.settingPanes[current];
79+
int[] paneContainerSlots = pane.getContainerSlots();
80+
GuiEntry[] paneEntries = pane.getButtons();
81+
for(int i = 0; i < paneContainerSlots.length; i++){
82+
int slot = paneContainerSlots[i];
83+
if(i < paneEntries.length){
84+
model.setButton(slot, paneEntries[i]);
85+
}else{
86+
if(pane.showItemsForEmpty()){
87+
model.setButton(slot, new GuiEntry(this.getPreloadedItems().emptyItem()));
88+
}
89+
}
90+
}
7891

92+
model.setButton(0, new GuiEntry(this.getPreloadedItems().getBackItem(), a -> {
93+
this.current = -1;
94+
this.open();
95+
}));
7996
}
8097
}
8198

src/main/java/xyz/theprogramsrc/supercoreapi/spigot/storage/SettingsStorage.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class SettingsStorage extends SpigotModule {
1414
@Override
1515
public void onLoad() {
1616
this.cfg = new YMLConfig(this.getPluginFolder(), "Settings.yml");
17-
this.defaultPrefix = "&9" + this.getPluginName() + "»&r";
17+
this.defaultPrefix = "&9" + this.getPluginName() + "»&r ";
1818
if(this.plugin.isFirstStart()){
1919
this.loadDefaults();
2020
}
@@ -41,15 +41,16 @@ public void setLanguage(String language) {
4141
* @return the prefix
4242
*/
4343
public String getPrefix(){
44-
return this.cfg.getString("Prefix", this.defaultPrefix);
44+
String prefix = this.cfg.getString("Prefix", this.defaultPrefix);
45+
return prefix.endsWith(" ") ? prefix : (prefix + " ");
4546
}
4647

4748
/**
4849
* Gets the language of the plugin
4950
* @return the language
5051
*/
5152
public String getLanguage() {
52-
return this.cfg.getString("Language", "en_US");
53+
return this.cfg.getString("Language", "en");
5354
}
5455

5556
private void loadDefaults(){

0 commit comments

Comments
 (0)