Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions src/main/java/com/bgsoftware/wildstacker/utils/files/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,49 +63,61 @@ public static InputStream getResource(String resourcePath) {
}

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

String materialName = section.getString("type");
Material type;
short data;

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

ItemBuilder itemBuilder = new ItemBuilder(type, data);

if (section.contains("name"))
itemBuilder.withName(ChatColor.translateAlternateColorCodes('&', section.getString("name")));
if (section.isInt("amount"))
itemBuilder.withAmount(section.getInt("amount"));

if (section.contains("lore"))
if (section.isString("name"))
itemBuilder.withName(section.getString("name"));

if (section.isList("lore"))
itemBuilder.withLore(section.getStringList("lore"));

if (section.contains("enchants")) {
for (String _enchantment : section.getConfigurationSection("enchants").getKeys(false)) {
if (section.isConfigurationSection("enchants")) {
for (String enchantName : section.getConfigurationSection("enchants").getKeys(false)) {
Enchantment enchantment;

try {
enchantment = Enchantment.getByName(_enchantment);
} catch (Exception ex) {
WildStackerPlugin.log("&c[" + fileName + "] Couldn't convert " + section.getCurrentPath() + ".enchants." + _enchantment + " into an enchantment, skipping...");
enchantment = Enchantment.getByName(enchantName);
} catch (IllegalArgumentException e) {
WildStackerPlugin.log("&c[" + fileName + "] Couldn't convert '" + enchantName +
"' into an enchantment in '" + section.getCurrentPath() + ".enchants', skipping...");
continue;
}

itemBuilder.withEnchant(enchantment, section.getInt("enchants." + _enchantment));
itemBuilder.withEnchant(enchantment, section.getInt("enchants." + enchantName));
}
}

if (section.contains("flags")) {
for (String flag : section.getStringList("flags"))
itemBuilder.withFlags(ItemFlag.valueOf(flag));
if (section.isList("flags")) {
for (String flagName : section.getStringList("flags")) {
try {
itemBuilder.withFlags(ItemFlag.valueOf(flagName));
} catch (IllegalArgumentException e) {
WildStackerPlugin.log("&c[" + fileName + "] Couldn't convert '" + flagName +
"' into an item flag in '" + section.getCurrentPath() + ".flags', skipping...");
}
}
}

if (section.contains("skull"))
if (section.isString("skull"))
itemBuilder.asSkullOf(section.getString("skull"));

return itemBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public ItemBuilder(Material type, int damage) {
itemMeta = itemStack.getItemMeta();
}

public ItemBuilder withAmount(int amount) {
itemStack.setAmount(amount);
return this;
}

public ItemBuilder withName(String name) {
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
return this;
Expand Down Expand Up @@ -145,13 +150,13 @@ public ItemBuilder asSkullOf(String texture) {
return this;
}

public ItemStack build() {
return build(1);
public ItemStack build(int amount) {
itemStack.setAmount(amount);
return build();
}

public ItemStack build(int amount) {
public ItemStack build() {
itemStack.setItemMeta(itemMeta);
itemStack.setAmount(amount);
return texture == null ? itemStack : plugin.getNMSAdapter().getPlayerSkull(itemStack, texture);
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/menus/spawner-amounts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ items:
name: '&aAdd +1'
'%':
type: LIME_STAINED_GLASS_PANE
amount: 16
deposit: 16
name: '&aAdd +16'
'^':
type: LIME_STAINED_GLASS_PANE
amount: 64
deposit: 64
name: '&aAdd +64'
'*':
Expand All @@ -54,9 +56,11 @@ items:
name: '&cRemove -1'
'-':
type: RED_STAINED_GLASS_PANE
amount: 16
withdraw: 16
name: '&cRemove -16'
'+':
type: RED_STAINED_GLASS_PANE
amount: 64
withdraw: 64
name: '&cRemove -64'
4 changes: 4 additions & 0 deletions src/main/resources/menus/spawner-amounts_legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ items:
'%':
type: STAINED_GLASS_PANE
data: 5
amount: 16
deposit: 16
name: '&aAdd +16'
'^':
type: STAINED_GLASS_PANE
data: 5
amount: 64
deposit: 64
name: '&aAdd +64'
'*':
Expand All @@ -62,10 +64,12 @@ items:
'-':
type: STAINED_GLASS_PANE
data: 14
amount: 16
withdraw: 16
name: '&cRemove -16'
'+':
type: STAINED_GLASS_PANE
data: 14
amount: 64
withdraw: 64
name: '&cRemove -64'