Skip to content

Commit d147b78

Browse files
Im-FranTheProgramSrc
authored andcommitted
SettingsGUI and Improvements
+ Added SettingsGUI and its defaults Setting Panes * Working on migration to replace vars with placeholders in Translations * General fixes and improvements
1 parent 7f01c44 commit d147b78

12 files changed

Lines changed: 272 additions & 29 deletions

File tree

dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>xyz.theprogramsrc</groupId>
55
<artifactId>SuperCoreAPI</artifactId>
66
<name>SuperCoreAPI</name>
7-
<version>4.11.0_BETA8</version>
7+
<version>4.11.0_BETA12</version>
88
<build>
99
<sourceDirectory>src/main/java</sourceDirectory>
1010
<defaultGoal>clean package</defaultGoal>

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>4.11.0_BETA8</version>
9+
<version>4.11.0_BETA12</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SuperCoreAPI</name>

src/main/java/xyz/theprogramsrc/supercoreapi/SuperPlugin.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import xyz.theprogramsrc.supercoreapi.global.data.PluginDataStorage;
44
import xyz.theprogramsrc.supercoreapi.global.dependencies.DependencyManager;
5+
import xyz.theprogramsrc.supercoreapi.global.translations.TranslationDownloader;
56
import xyz.theprogramsrc.supercoreapi.global.translations.TranslationManager;
67
import xyz.theprogramsrc.supercoreapi.global.translations.TranslationPack;
78

@@ -206,4 +207,26 @@ default void debug(String message){
206207
this.sendConsoleMessage("&b&l[" + this.getPluginName() + " DEBUG]&r: " + message);
207208
}
208209
}
210+
211+
/**
212+
* Configures the plugin to automatically
213+
* download the plugin translations from GitHub
214+
*/
215+
default void setupGithubTranslationDownloader(String githubUser, String githubRepo, String folder){
216+
this.getPluginDataStorage().add("TranslationDownloader", true);
217+
if(this.getPluginDataStorage().getBoolean("TranslationDownloader")){
218+
TranslationDownloader.downloadFromGitHub(this, githubUser, githubRepo, folder);
219+
}
220+
}
221+
222+
/**
223+
* Configures the plugin to automatically
224+
* download the plugin translations from GitHub
225+
*/
226+
default void setupRawTranslationDownloader(String url, String filename){
227+
this.getPluginDataStorage().add("TranslationDownloader", true);
228+
if(this.getPluginDataStorage().getBoolean("TranslationDownloader")){
229+
TranslationDownloader.downloadTranslation(this, url, filename);
230+
}
231+
}
209232
}

src/main/java/xyz/theprogramsrc/supercoreapi/global/files/JsonConfig.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,26 @@ public void set(String key, String value){
138138
this.save();
139139
}
140140

141+
/**
142+
* Used to insert data into the file
143+
* @param key Key of the value to store
144+
* @param value Boolean to save
145+
*/
146+
public void set(String key, Boolean value){
147+
this.json.addProperty(key, value);
148+
this.save();
149+
}
150+
151+
/**
152+
* Used to insert data into the file
153+
* @param key Key of the value to store
154+
* @param value Number to save
155+
*/
156+
public void set(String key, Number value){
157+
this.json.addProperty(key, value);
158+
this.save();
159+
}
160+
141161
/**
142162
* Used to add data if not exists into the file
143163
* If you want to replace data use {@link #set(String, String)}
@@ -148,6 +168,28 @@ public void add(String key, String value){
148168
if(!this.contains(key)) this.set(key, value);
149169
}
150170

171+
172+
/**
173+
* Used to add data if not exists into the file
174+
* If you want to replace data use {@link #set(String, Boolean)}
175+
* @param key Key of the value to store
176+
* @param value Object to save
177+
*/
178+
public void add(String key, Boolean value){
179+
if(!this.contains(key)) this.set(key, value);
180+
}
181+
182+
183+
/**
184+
* Used to add data if not exists into the file
185+
* If you want to replace data use {@link #set(String, Number)}
186+
* @param key Key of the value to store
187+
* @param value Object to save
188+
*/
189+
public void add(String key, Number value){
190+
if(!this.contains(key)) this.set(key, value);
191+
}
192+
151193
/**
152194
* Used to get a json element from the file
153195
* @param key Key of the element to request
@@ -211,7 +253,46 @@ public boolean getBoolean(String key){
211253
return this.get(key).getAsBoolean();
212254
}
213255

256+
/**
257+
* Used to request a {@link Number} from the json file
258+
* @param key Key of the requested {@link Number}
259+
* @return {@link Number} stored in the key inside the file
260+
*/
261+
public Number getNumber(String key){
262+
return this.get(key).getAsNumber();
263+
}
214264

265+
/**
266+
* Toggle a boolean value using the specified {@code key}
267+
* @param key the key of the path to toggle the boolean
268+
* @return the new value
269+
*/
270+
public boolean toggle(String key){
271+
boolean b = !this.getBoolean(key);
272+
this.set(key, b);
273+
return b;
274+
}
215275

276+
/**
277+
* Increases the value of an Integer object by 1 in the file
278+
* @param key the key of the Integer object
279+
* @return the new value
280+
*/
281+
public int incr(String key){
282+
int i = this.getInt(key)+1;
283+
this.set(key, i);
284+
return i;
285+
}
286+
287+
/**
288+
* Decreases the value of an Integer object by 1 in the file
289+
* @param key the key of the Integer object
290+
* @return the new value
291+
*/
292+
public int decr(String key){
293+
int i = this.getInt(key)-1;
294+
this.set(key, i);
295+
return i;
296+
}
216297

217298
}

src/main/java/xyz/theprogramsrc/supercoreapi/global/translations/Base.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public enum Base implements TranslationPack{
2626
CONSOLE("Console"),
2727
CONFIRM("Confirm"),
2828
DECLINE("Decline"),
29+
GENERAL("General"),
2930

3031
/* MESSAGES */
3132
NO_PERMISSION("&cYou dont have permission."),
@@ -52,24 +53,27 @@ public enum Base implements TranslationPack{
5253
SETTINGS_EDITOR_NAME("&aSettings Editor"),
5354
SETTINGS_EDITOR_DESCRIPTION("&7Click to edit some settings"),
5455

56+
SETTINGS_GENERAL_NAME("&aGeneral Settings"),
57+
SETTINGS_GENERAL_DESCRIPTION("&7Click to edit general settings"),
58+
5559
LANGUAGE_SELECTOR_NAME("&aLanguages"),
5660
LANGUAGE_SELECTOR_DESCRIPTION("&7Click to select a new Language."),
5761

62+
GENERAL_SET_PREFIX_NAME("&aSet Prefix"),
63+
GENERAL_SET_PREFIX_DESCRIPTION("&7Current Prefix: &r{Prefix}"),
64+
65+
GENERAL_TOGGLE_TRANSLATION_DOWNLOADER_NAME("&aToggle Translation Downloader"),
66+
GENERAL_TOGGLE_TRANSLATION_DOWNLOADER_DESCRIPTION("&7Current Status: &9{Status}"),
67+
5868
LANGUAGE_SELECT_DESCRIPTION("&7Click to select&a {Language}&7 as the current language."),
5969
LANGUAGE_SELECTED_DESCRIPTION("&a{Language}&7 is selected as the current language."),
6070

6171
SETTINGS_TOGGLE_UPDATER_NAME("&aToggle Updater"),
6272
SETTINGS_TOGGLE_UPDATER_DESCRIPTION("&7Current Status: &9{Status}"),
6373

64-
SETTINGS_TOGGLE_TRANSLATION_DOWNLOADER_NAME("&aToggle Translation Downloader"),
65-
SETTINGS_TOGGLE_TRANSLATION_DOWNLOADER_DESCRIPTION("&7Current Status: &9{Status}"),
66-
6774
SETTINGS_TOGGLE_SQL_NAME("&aToggle SQL"),
6875
SETTINGS_TOGGLE_SQL_DESCRIPTION("&7Current Status: &9{Status}"),
6976

70-
SET_PREFIX_NAME("&aSet Prefix"),
71-
SET_PREFIX_DESCRIPTION("&7Current Prefix: &r{Prefix}"),
72-
7377
MATERIAL_SELECTOR_TITLE("&7Select a Material"),
7478
MATERIAL_SELECTOR_ITEM_NAME("&a{Material}"),
7579
MATERIAL_SELECTOR_ITEM_DESCRIPTION("&7Click to select &a{Material}"),

src/main/java/xyz/theprogramsrc/supercoreapi/spigot/commands/SpigotCommand.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ private void onResult(CommandSender sender, CommandResult result){
5858
}else if(result == CommandResult.NO_ACCESS){
5959
sender.sendMessage(this.spigotPlugin.getSuperUtils().color(Base.NO_ACCESS.toString()));
6060
}else if(result == CommandResult.NOT_SUPPORTED){
61-
if(sender instanceof Player){
62-
sender.sendMessage(this.spigotPlugin.getSuperUtils().color(Base.NOT_SUPPORTED.options().placeholder("{Supported}", Base.CONSOLE.toString()).toString()));
63-
}else{
64-
sender.sendMessage(this.spigotPlugin.getSuperUtils().color(Base.NOT_SUPPORTED.options().placeholder("{Supported}", Base.PLAYERS.toString()).toString()));
65-
}
61+
String supported = (sender instanceof Player ? Base.CONSOLE : Base.PLAYERS).toString();
62+
sender.sendMessage(
63+
this.spigotPlugin.getSuperUtils().color(
64+
Base.NOT_SUPPORTED
65+
.options()
66+
.placeholder("{Supported}", supported)
67+
.vars(supported) // Remove on future updates
68+
.get()
69+
)
70+
);
6671
}else if(result == CommandResult.INVALID_ARGS){
6772
sender.sendMessage(this.spigotPlugin.getSuperUtils().color(Base.INVALID_ARGUMENTS.toString()));
6873
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public boolean canCloseGUI(){
227227
* @return true if the title must be centered, otherwise false
228228
*/
229229
public boolean isTitleCentered(){
230-
return true;
230+
return false;
231231
}
232232

233233
/**

src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/precreated/settings/CustomSettingPane.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package xyz.theprogramsrc.supercoreapi.spigot.guis.precreated.settings;
22

3-
import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule;
43
import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton;
5-
import xyz.theprogramsrc.supercoreapi.spigot.guis.objects.GUIRows;
6-
import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem;
74

85
import java.util.LinkedList;
96

@@ -16,15 +13,8 @@ public abstract class CustomSettingPane<OBJ> extends SettingPane {
1613
@Override
1714
public GUIButton[] getButtons() {
1815
LinkedList<GUIButton> buttons = new LinkedList<>();
19-
int[] available = this.getContainerSlots();
20-
OBJ[] objs = this.getObjects();
21-
for(int i = 0; i < available.length; ++i){
22-
int slot = available[i];
23-
if(i < objs.length){
24-
buttons.add(this.getButton(objs[i]).setSlot(slot));
25-
}else{
26-
buttons.add(new GUIButton(slot, this.getPreloadedItems().emptyItem()));
27-
}
16+
for(OBJ obj : this.getObjects()){
17+
buttons.add(this.getButton(obj));
2818
}
2919
return buttons.toArray(new GUIButton[0]);
3020
}

src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/precreated/settings/SettingPane.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,42 @@
77

88
public abstract class SettingPane extends SpigotModule {
99

10+
/**
11+
* Gets the name to display in the setting title
12+
* @return the name to show in the title
13+
*/
1014
public abstract String getDisplayName();
1115

16+
/**
17+
* Gets the item to display in the setting selector gui
18+
* @return the item to display
19+
*/
1220
public abstract SimpleItem getDisplayItem();
1321

22+
/**
23+
* Gets the available buttons to show in the gui
24+
* @return the available buttons to show
25+
*/
1426
public abstract GUIButton[] getButtons();
1527

28+
/**
29+
* If this is true when a container slot is empty this will
30+
* show a white stained glass pane, otherwise the slot will
31+
* be empty.
32+
* @return true to show item in an empty slot container, false to leave empty
33+
*/
34+
public boolean showItemsForEmpty(){
35+
return false;
36+
}
37+
1638
public GUIRows getRows(){
1739
return GUIRows.SIX;
1840
}
1941

42+
/**
43+
* Available slots to use in the Setting pane
44+
* @return the available slots to use in the setting pane
45+
*/
2046
public int[] getContainerSlots(){
2147
return new int[]{
2248
19, 20, 21, 22, 23, 24, 25,

src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/precreated/settings/SettingsGUI.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ protected String getTitle() {
6060
@Override
6161
protected GUIButton[] getButtons() {
6262
LinkedList<GUIButton> buttons = new LinkedList<>();
63+
this.clearButtons();
6364
if(this.current == -1){
6465
buttons.add(new GUIButton(0, this.getPreloadedItems().getBackItem(), this::onBack));
6566

@@ -76,13 +77,24 @@ protected GUIButton[] getButtons() {
7677
}
7778
}
7879
}else{
80+
SettingPane pane = this.settingPanes[current];
81+
int[] _containerSlots = pane.getContainerSlots();
82+
GUIButton[] paneButtons = pane.getButtons();
83+
for(int i = 0; i < _containerSlots.length; ++i){
84+
int slot = _containerSlots[i];
85+
if(i < paneButtons.length){
86+
buttons.add(paneButtons[i].setSlot(slot));
87+
}else{
88+
if(pane.showItemsForEmpty()){
89+
buttons.add(new GUIButton(slot, this.getPreloadedItems().emptyItem()));
90+
}
91+
}
92+
}
7993
buttons.add(new GUIButton(0, this.getPreloadedItems().getBackItem(), a-> {
8094
this.current = -1;
8195
this.open();
8296
}));
83-
buttons.addAll(Utils.toList(this.settingPanes[current].getButtons()));
8497
}
85-
8698
return buttons.toArray(new GUIButton[0]);
8799
}
88100

0 commit comments

Comments
 (0)