Skip to content

Commit

Permalink
Added the ability to add "source" field for items, so items will be p…
Browse files Browse the repository at this point in the history
…arsed from this source-path
  • Loading branch information
OmerBenGera committed Apr 21, 2022
1 parent 2efc8de commit 685c9b5
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/main/java/com/bgsoftware/superiorskyblock/utils/FileUtils.java
Expand Up @@ -56,22 +56,37 @@ private FileUtils() {

@Nullable
public static TemplateItem getItemStack(String fileName, ConfigurationSection section) {
if (section == null || !section.contains("type"))
if (section == null)
return null;

Material type;
short data;
TemplateItem templateItem;

try {
type = Material.valueOf(section.getString("type"));
data = (short) section.getInt("data");
} catch (IllegalArgumentException ex) {
SuperiorSkyblockPlugin.log("&c[" + fileName + "] Couldn't convert " + section.getCurrentPath() + " into an itemstack. Check type & data sections!");
PluginDebugger.debug(ex);
return null;
String sourceItem = section.getString("source");
if (sourceItem != null) {
templateItem = getItemStack(fileName, section.getRoot().getConfigurationSection(sourceItem));

if (templateItem == null)
return null;
} else {
if (!section.contains("type"))
return null;

Material type;
short data;

try {
type = Material.valueOf(section.getString("type"));
data = (short) section.getInt("data");
} catch (IllegalArgumentException ex) {
SuperiorSkyblockPlugin.log("&c[" + fileName + "] Couldn't convert " + section.getCurrentPath() + " into an itemstack. Check type & data sections!");
PluginDebugger.debug(ex);
return null;
}

templateItem = new TemplateItem(new ItemBuilder(type, data));
}

ItemBuilder itemBuilder = new ItemBuilder(type, data);
ItemBuilder itemBuilder = templateItem.getEditableBuilder();

if (section.contains("name"))
itemBuilder.withName(Formatters.COLOR_FORMATTER.format(section.getString("name")));
Expand Down Expand Up @@ -148,7 +163,7 @@ public static TemplateItem getItemStack(String fileName, ConfigurationSection se
itemBuilder.withCustomModel(section.getInt("customModel"));
}

return new TemplateItem(itemBuilder);
return templateItem;
}

@Nullable
Expand Down

0 comments on commit 685c9b5

Please sign in to comment.