Skip to content

Commit

Permalink
Added the ability to add leather armor pieces that are colored to men…
Browse files Browse the repository at this point in the history
…us (#955) (#1086)
  • Loading branch information
OmerBenGera committed Apr 30, 2022
1 parent 9303944 commit ce02e14
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/bgsoftware/superiorskyblock/utils/FileUtils.java
Expand Up @@ -161,6 +161,19 @@ public static TemplateItem getItemStack(String fileName, ConfigurationSection se
itemBuilder.withCustomModel(section.getInt("customModel"));
}

if (section.contains("leatherColor")) {
String leatherColor = section.getString("leatherColor");
if (leatherColor.startsWith("#"))
leatherColor = leatherColor.substring(1);

try {
itemBuilder.withLeatherColor(Integer.parseInt(leatherColor, 16));
} catch (IllegalArgumentException error) {
SuperiorSkyblockPlugin.log("&c[" + fileName + "] Couldn't convert " + leatherColor + " into a color, skipping...");
PluginDebugger.debug(error);
}
}

return templateItem;
}

Expand Down
Expand Up @@ -7,6 +7,7 @@
import com.bgsoftware.superiorskyblock.utils.ServerVersion;
import com.bgsoftware.superiorskyblock.utils.legacy.Materials;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
Expand All @@ -15,6 +16,7 @@
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SpawnEggMeta;
import org.bukkit.potion.PotionEffect;
Expand Down Expand Up @@ -242,6 +244,14 @@ public ItemBuilder withCustomModel(int customModel) {
return this;
}

public ItemBuilder withLeatherColor(int leatherColor) {
if (itemMeta instanceof LeatherArmorMeta) {
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemMeta;
leatherArmorMeta.setColor(Color.fromRGB(leatherColor));
}
return this;
}

@Nullable
public ItemMeta getItemMeta() {
return itemMeta;
Expand Down

0 comments on commit ce02e14

Please sign in to comment.