From b7dbd08d831ea117da57db92e95fddee9acc17fb Mon Sep 17 00:00:00 2001 From: montlikadani Date: Fri, 2 Apr 2021 17:04:19 +0200 Subject: [PATCH] Added option to set leather colors for boosted items Closes #1080 --- .../gamingmesh/jobs/CMILib/CMIMaterial.java | 4 ++-- .../com/gamingmesh/jobs/ItemBoostManager.java | 20 ++++++++++++++++++- .../com/gamingmesh/jobs/Signs/SignUtil.java | 2 +- .../jobs/config/GeneralConfigManager.java | 2 +- .../gamingmesh/jobs/config/ShopManager.java | 2 +- .../com/gamingmesh/jobs/config/YmlMaker.java | 17 +++------------- .../gamingmesh/jobs/container/JobItems.java | 17 +++++++++++++--- .../blockOwnerShip/BlockOwnerShip.java | 8 ++++++-- 8 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java b/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java index 8bfcfc6e..d63ac44c 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java @@ -2059,11 +2059,11 @@ public enum CMIMaterial { } public boolean isValidItem() { - return !equals(CMIMaterial.NONE) && !isAir() && getMaterial() != null; + return this != CMIMaterial.NONE && !isAir() && getMaterial() != null; } public boolean isNone() { - return equals(CMIMaterial.NONE); + return this == CMIMaterial.NONE; } public static boolean isAir(Material mat) { diff --git a/src/main/java/com/gamingmesh/jobs/ItemBoostManager.java b/src/main/java/com/gamingmesh/jobs/ItemBoostManager.java index a959f224..3d7a2c53 100644 --- a/src/main/java/com/gamingmesh/jobs/ItemBoostManager.java +++ b/src/main/java/com/gamingmesh/jobs/ItemBoostManager.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import org.bukkit.Color; import org.bukkit.enchantments.Enchantment; import com.gamingmesh.jobs.CMILib.CMIChatColor; @@ -89,6 +90,8 @@ public class ItemBoostManager { cfg.addComment("exampleBoost.enchants", "(Optional) Item custom enchants", "All enchantment names can be found https://hub.spigotmc.org/javadocs/spigot/org/bukkit/enchantments/Enchantment.html"); cfg.get("exampleBoost.enchants", Arrays.asList("FIRE_ASPECT=1", "DAMAGE_ALL=1")); + cfg.addComment("exampleBoost.leather-color", "(Optional) Leather armour colors (0-255)"); + cfg.get("exampleBoost.leather-color", "82,34,125"); cfg.addComment("exampleBoost.moneyBoost", "[Required] Money boost: 1.1 is equals 10% more income when 0.9 is equals 10% less from base income"); for (CurrencyType oneC : CurrencyType.values()) { cfg.get("exampleBoost." + oneC.toString().toLowerCase() + "Boost", 1D); @@ -167,7 +170,22 @@ public class ItemBoostManager { String name = cfg.getC().isString(one + ".name") ? cfg.get(one + ".name", "") : null; String node = one.toLowerCase(); - JobItems item = new JobItems(node, mat, 1, name, lore, enchants, b, jobs); + Color leatherColor = null; + if (cfg.getC().isString(one + ".leather-color")) { + String[] split = cfg.getC().getString(one + ".leather-color").split(",", 3); + if (split.length != 0) { + int red = Integer.parseInt(split[0]); + int green = split.length > 0 ? Integer.parseInt(split[1]) : 0; + int blue = split.length > 1 ? Integer.parseInt(split[2]) : 0; + + try { + leatherColor = Color.fromRGB(red, green, blue); + } catch (IllegalArgumentException e) { + } + } + } + + JobItems item = new JobItems(node, mat, 1, name, lore, enchants, b, jobs, null, leatherColor); if (cfg.getC().isInt(one + ".levelFrom")) item.setFromLevel(cfg.get(one + ".levelFrom", 0)); diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java index 186b5b58..1208759e 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java @@ -73,7 +73,7 @@ public class SignUtil { signsByType.put(identifier, old); } - public void LoadSigns() { + public void loadSigns() { if (!Jobs.getGCManager().SignsEnabled) return; diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index 84c05411..6af9ae29 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -265,7 +265,7 @@ public class GeneralConfigManager { // Item/Block/mobs name list Jobs.getNameTranslatorManager().load(); // signs information - Jobs.getSignUtil().LoadSigns(); + Jobs.getSignUtil().loadSigns(); // Shop Jobs.getShopManager().load(); } diff --git a/src/main/java/com/gamingmesh/jobs/config/ShopManager.java b/src/main/java/com/gamingmesh/jobs/config/ShopManager.java index 09a4fb98..8d39ba6b 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ShopManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ShopManager.java @@ -460,7 +460,7 @@ public class ShopManager { } items.add(new JobItems(node, id == null ? CMIMaterial.STONE : CMIMaterial.get(id), amount, name, lore, - enchants, new BoostMultiplier(), new ArrayList(), potionData)); + enchants, new BoostMultiplier(), new ArrayList(), potionData, null)); } sItem.setitems(items); } diff --git a/src/main/java/com/gamingmesh/jobs/config/YmlMaker.java b/src/main/java/com/gamingmesh/jobs/config/YmlMaker.java index 5dd8d22f..9e0712d0 100644 --- a/src/main/java/com/gamingmesh/jobs/config/YmlMaker.java +++ b/src/main/java/com/gamingmesh/jobs/config/YmlMaker.java @@ -2,7 +2,6 @@ package com.gamingmesh.jobs.config; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; @@ -35,21 +34,11 @@ public class YmlMaker { } public void reloadConfig() { - InputStreamReader f = null; - try { - f = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8); - } catch (FileNotFoundException e1) { - e1.printStackTrace(); - } - - if (f == null) { + if (!exists()) return; - } - configuration = YamlConfiguration.loadConfiguration(f); - - try { - f.close(); + try (InputStreamReader reader = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8)) { + configuration = YamlConfiguration.loadConfiguration(reader); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobItems.java b/src/main/java/com/gamingmesh/jobs/container/JobItems.java index 85e4a189..fb48679e 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobItems.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobItems.java @@ -24,11 +24,13 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.bukkit.Color; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.potion.PotionEffectType; @@ -45,6 +47,7 @@ public class JobItems { private ItemStack item; private Object potion; + private Color leatherColor; private final Map enchants = new HashMap<>(); private BoostMultiplier boostMultiplier = new BoostMultiplier(); @@ -55,11 +58,11 @@ public class JobItems { private int untilLevel = Integer.MAX_VALUE; public JobItems(String node, CMIMaterial mat, int amount, String name, List lore, Map enchants, BoostMultiplier boostMultiplier, List jobs) { - this(node, mat, amount, name, lore, enchants, boostMultiplier, jobs, null); + this(node, mat, amount, name, lore, enchants, boostMultiplier, jobs, null, null); } public JobItems(String node, CMIMaterial mat, int amount, String name, List lore, Map enchants, BoostMultiplier boostMultiplier, List jobs, - Object potion) { + Object potion, Color leatherColor) { if (mat == null) { mat = CMIMaterial.STONE; } @@ -77,7 +80,7 @@ public class JobItems { setJobs(jobs); ItemMeta meta = (item = mat.newItemStack()).getItemMeta(); - if (CMIMaterial.isPotion(mat.getMaterial()) && potion != null && meta instanceof PotionMeta) { + if (potion != null && CMIMaterial.isPotion(mat.getMaterial()) && meta instanceof PotionMeta) { PotionMeta potionMeta = (PotionMeta) meta; if (Version.isCurrentEqualOrHigher(Version.v1_10_R1) && potion instanceof org.bukkit.potion.PotionData) { @@ -90,6 +93,10 @@ public class JobItems { } meta = potionMeta; + } else if (leatherColor != null && CMIMaterial.isLeatherArmor(mat.getMaterial()) && meta instanceof LeatherArmorMeta) { + LeatherArmorMeta armorMeta = (LeatherArmorMeta) meta; + armorMeta.setColor(this.leatherColor = leatherColor); + meta = armorMeta; } if (meta != null) { @@ -146,6 +153,10 @@ public class JobItems { } meta = potionMeta; + } else if (leatherColor != null && CMIMaterial.isLeatherArmor(item.getType()) && meta instanceof LeatherArmorMeta) { + LeatherArmorMeta armorMeta = (LeatherArmorMeta) meta; + armorMeta.setColor(leatherColor); + meta = armorMeta; } if (meta.hasDisplayName()) diff --git a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java index fd068908..d6b522bf 100644 --- a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java +++ b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java @@ -185,11 +185,15 @@ public class BlockOwnerShip { : type == BlockTypes.BLAST_FURNACE ? "BlastFurnace" : type == BlockTypes.BREWING_STAND ? "Brewing" : type == BlockTypes.SMOKER ? "Smoker" : ""); - if (isReassignDisabled() || !f.getConfig().isConfigurationSection(path)) + if (isReassignDisabled()) return; - int total = 0; ConfigurationSection section = f.getConfig().getConfigurationSection(path); + if (section == null) { + return; + } + + int total = 0; for (String one : section.getKeys(false)) { String value = section.getString(one); List ls = new ArrayList<>();