Skip to content

Commit

Permalink
Store layoutIcons slots into a single line rather than a List of inte…
Browse files Browse the repository at this point in the history
…gers
  • Loading branch information
EverNife committed Apr 17, 2023
1 parent bbed7e0 commit a8d6f3d
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ public static <T extends LayoutBase> T loadLayout(Plugin plugin, Config config,
if (background == false || !hasAnyBackgroundAtStart){
//When a background, it will only save Defaults if there is already no existing Background LayoutIcon on the config

if (!permission.isEmpty()){
itemSection.setDefaultValue("Permission", permission);
}

List<String> slotsAsString = new ArrayList<>();
for (int i : slot) {
slotsAsString.add(String.valueOf(i));
}
itemSection.setDefaultValue("Slot", slotsAsString);

if (!permission.isEmpty()){
itemSection.setDefaultValue("Permission", permission);
if (!itemSection.contains("Slot")){
itemSection.setDefaultValue("Slot", slotsAsString.stream().collect(Collectors.joining(",","[","]"))); //Store slots like "[1,2,3,4,5]"
}

FCItemBuilder itemBuilder = FCItemFactory.from(layoutIcon.getItemStack());
Expand Down Expand Up @@ -161,10 +163,20 @@ public static <T extends LayoutBase> T loadLayout(Plugin plugin, Config config,

try {
if (itemSection.contains("Slot")){
slot = itemSection.getStringList("Slot")
.stream()
.mapToInt(value -> Integer.valueOf(value))
.toArray();
if (itemSection.getValue("Slot") instanceof String){
slot = Arrays.stream(itemSection.getString("Slot")
.replace("[", "")
.replace("]", "")
.split(","))
.mapToInt(value -> Integer.valueOf(value.trim()))
.toArray()
;
}else {
slot = itemSection.getStringList("Slot")
.stream()
.mapToInt(value -> Integer.valueOf(value.trim()))
.toArray();
}
}

permission = itemSection.getString("Permission", permission);
Expand Down

0 comments on commit a8d6f3d

Please sign in to comment.