Skip to content

Commit

Permalink
Fixes & New Gui System (#14)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Im-Fran authored Aug 28, 2021
1 parent dcd4a47 commit b3bee56
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## v5.2.1 Changelog
```
* 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
```

## v5.2.0 Changelog
```
* New Gui System (`xyz.thepogramsrc.superocreapi.spigot.gui.Gui`)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>xyz.theprogramsrc</groupId>
<artifactId>SuperCoreAPI</artifactId>
<version>5.2.0</version>
<version>5.2.1</version>
<packaging>jar</packaging>

<name>SuperCoreAPI</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import java.util.LinkedHashMap;

import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule;

/**
* Representation of the Gui Model
* @since 5.2.0
*/
public class GuiModel {
public class GuiModel extends SpigotModule{

private GuiTitle title;
private GuiRows rows;
Expand Down Expand Up @@ -46,6 +48,9 @@ public LinkedHashMap<Integer, GuiEntry> getButtons() {
return buttons;
}

/**
* Clear the buttons from the Gui
*/
public void clearButtons(){
this.buttons.clear();
}
Expand All @@ -72,6 +77,47 @@ public void addButton(GuiEntry entry){
}
}

/**
* Fills all the empty slots with the given entry
* @param entry The entry of the button to add to all the empty slots
* @since 5.2.1
*/
public void fillEmptySlotsWithEntry(GuiEntry entry){
for(int i = 0; i < this.rows.size; i++){
if(!this.buttons.containsKey(i)){
this.setButton(i, entry);
}
}
}

/**
* Fills the empty slots with the empty item.
* See {@link xyz.theprogramsrc.supercoreapi.spigot.items.PreloadedItems#emptyItem}
* @since 5.2.1
*/
public void fillEmptySlots(){
this.fillEmptySlotsWithEntry(new GuiEntry(this.getPreloadedItems().emptyItem()));
}


/**
* Fills the specified slots with the specified entry.
* @param entry The entry of the button to add to the given slots
* @param slots The slots to fill
* @since 5.2.1
*/

public void fillWithEntry(GuiEntry entry, int[] slots){
for(int slot : slots){
this.setButton(slot, entry);
}
}

/**
* Fills the specified slots with an empty item.
* @param slots The slots to fill with the empty item
* @since 5.2.1
*/
public void fillWithEmptyItem(int[] slots){
this.fillWithEntry(new GuiEntry(this.getPreloadedItems().emptyItem()), slots);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,24 @@ public void onBuild(GuiModel model) {
}
});
}else{
SettingPane pane = this.settingPanes[current];
int[] paneContainerSlots = pane.getContainerSlots();
GuiEntry[] paneEntries = pane.getButtons();
for(int i = 0; i < paneContainerSlots.length; i++){
int slot = paneContainerSlots[i];
if(i < paneEntries.length){
model.setButton(slot, paneEntries[i]);
}else{
if(pane.showItemsForEmpty()){
model.setButton(slot, new GuiEntry(this.getPreloadedItems().emptyItem()));
}
}
}

model.setButton(0, new GuiEntry(this.getPreloadedItems().getBackItem(), a -> {
this.current = -1;
this.open();
}));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class SettingsStorage extends SpigotModule {
@Override
public void onLoad() {
this.cfg = new YMLConfig(this.getPluginFolder(), "Settings.yml");
this.defaultPrefix = "&9" + this.getPluginName() + "»&r";
this.defaultPrefix = "&9" + this.getPluginName() + "»&r ";
if(this.plugin.isFirstStart()){
this.loadDefaults();
}
Expand All @@ -41,15 +41,16 @@ public void setLanguage(String language) {
* @return the prefix
*/
public String getPrefix(){
return this.cfg.getString("Prefix", this.defaultPrefix);
String prefix = this.cfg.getString("Prefix", this.defaultPrefix);
return prefix.endsWith(" ") ? prefix : (prefix + " ");
}

/**
* Gets the language of the plugin
* @return the language
*/
public String getLanguage() {
return this.cfg.getString("Language", "en_US");
return this.cfg.getString("Language", "en");
}

private void loadDefaults(){
Expand Down

0 comments on commit b3bee56

Please sign in to comment.