From e764cdd436d1e09dd9c00c793760996a12c7fba5 Mon Sep 17 00:00:00 2001 From: LogGits Date: Sun, 7 Oct 2018 13:25:30 +1000 Subject: [PATCH 1/3] Adds an Item field to GUI Adds the ability to add the item name instead of using id and data. (Please test this before pulling to verify its functionality) Resolves #233 --- .../gamingmesh/jobs/config/ConfigManager.java | 136 +++++++++++++----- 1 file changed, 100 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index 13c10423..7ed4f62d 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -546,42 +546,106 @@ public class ConfigManager { } // Gui item - ItemStack GUIitem = CMIMaterial.GREEN_WOOL.newItemStack(); - if (jobSection.contains("Gui")) { - ConfigurationSection guiSection = jobSection.getConfigurationSection("Gui"); - if (guiSection.contains("Id") && guiSection.contains("Data") && guiSection.isInt("Id") && guiSection.isInt("Data")) { - GUIitem = CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack(); - if (guiSection.contains("Enchantments")) { - List enchants = guiSection.getStringList("Enchantments"); - if (enchants.size() > 0) { - for (String str4 : enchants) { - String[] id = str4.split(":"); - if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) { - EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) GUIitem.getItemMeta(); - enchantMeta.addStoredEnchant(Enchantment.getByName(id[0]), Integer.parseInt(id[1]), true); - GUIitem.setItemMeta(enchantMeta); - } else { - GUIitem.addUnsafeEnchantment(Enchantment.getByName(id[0]), Integer.parseInt(id[1])); - } - } - } - } - } else if (guiSection.contains("CustomSkull")) { - String skullOwner = guiSection.getString("CustomSkull"); - GUIitem = CMIMaterial.PLAYER_HEAD.newItemStack(); - SkullMeta skullMeta = (SkullMeta) GUIitem.getItemMeta(); - if (skullOwner.length() == 36) { - try { - OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner)); - skullMeta.setOwner(offPlayer.getName()); - } catch (Exception e) { - } - } else - skullMeta.setOwner(skullOwner); - GUIitem.setItemMeta(skullMeta); - } else - Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid Gui property. Please fix this if you want to use it!"); - } + ItemStack GUIitem = CMIMaterial.GREEN_WOOL.newItemStack(); + if (jobSection.contains("Gui")) { + ConfigurationSection guiSection = jobSection.getConfigurationSection("Gui"); + if (guiSection.contains("Item") && guiSection.isString("Item")) { + String item = guiSection.getString("Item"); + String type = null; + String subType = ""; + String meta = ""; + int id = 0; + + if (item.contains("-")) { + // uses subType + subType = ":" + item.split("-")[1]; + meta = item.split("-")[1]; + item = item.split("-")[0]; + } + + CMIMaterial material = CMIMaterial.get(item + (subType)); + + if (material == null) material = CMIMaterial.get(item.replace(" ", "_").toUpperCase()); + + if (material == null) { + // try integer method + Integer matId = null; + try { + matId = Integer.valueOf(item); + } catch (NumberFormatException e) { + } + if (matId != null) { + material = CMIMaterial.get(matId); + if (material != null) { + Jobs.getPluginLogger() + .warning("Job " + jobName + " is using GUI item ID: " + item + "!"); + Jobs.getPluginLogger() + .warning("Please use the Material name instead: " + material.toString() + "!"); + } + } + } + GUIitem = material.newItemStack(); + if (guiSection.contains("Enchantments")) { + List enchants = guiSection.getStringList("Enchantments"); + if (enchants.size() > 0) { + for (String str4 : enchants) { + String[] enchantid = str4.split(":"); + if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) { + EnchantmentStorageMeta enchantMeta = + (EnchantmentStorageMeta) GUIitem.getItemMeta(); + enchantMeta.addStoredEnchant( + Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1]), true); + GUIitem.setItemMeta(enchantMeta); + } else { + GUIitem.addUnsafeEnchantment( + Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1])); + } + } + } + } + } else if (guiSection.contains("Id") + && guiSection.contains("Data") + && guiSection.isInt("Id") + && guiSection.isInt("Data")) { + GUIitem = + CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack(); + if (guiSection.contains("Enchantments")) { + List enchants = guiSection.getStringList("Enchantments"); + if (enchants.size() > 0) { + for (String str4 : enchants) { + String[] id = str4.split(":"); + if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) { + EnchantmentStorageMeta enchantMeta = + (EnchantmentStorageMeta) GUIitem.getItemMeta(); + enchantMeta.addStoredEnchant( + Enchantment.getByName(id[0]), Integer.parseInt(id[1]), true); + GUIitem.setItemMeta(enchantMeta); + } else { + GUIitem.addUnsafeEnchantment( + Enchantment.getByName(id[0]), Integer.parseInt(id[1])); + } + } + } + } + } else if (guiSection.contains("CustomSkull")) { + String skullOwner = guiSection.getString("CustomSkull"); + GUIitem = CMIMaterial.PLAYER_HEAD.newItemStack(); + SkullMeta skullMeta = (SkullMeta) GUIitem.getItemMeta(); + if (skullOwner.length() == 36) { + try { + OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner)); + skullMeta.setOwner(offPlayer.getName()); + } catch (Exception e) { + } + } else skullMeta.setOwner(skullOwner); + GUIitem.setItemMeta(skullMeta); + } else + Jobs.getPluginLogger() + .warning( + "Job " + + jobKey + + " has an invalid Gui property. Please fix this if you want to use it!"); + } // Permissions ArrayList jobPermissions = new ArrayList<>(); From fa0c45dc1bbf3a7e0971a7464643e83ac3b69280 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Mon, 8 Oct 2018 16:46:52 +0200 Subject: [PATCH 2/3] Update ConfigManager.java --- .../gamingmesh/jobs/config/ConfigManager.java | 193 +++++++++--------- 1 file changed, 96 insertions(+), 97 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index 7ed4f62d..95e18e81 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -545,107 +545,106 @@ public class ConfigManager { } } - // Gui item - ItemStack GUIitem = CMIMaterial.GREEN_WOOL.newItemStack(); - if (jobSection.contains("Gui")) { - ConfigurationSection guiSection = jobSection.getConfigurationSection("Gui"); - if (guiSection.contains("Item") && guiSection.isString("Item")) { - String item = guiSection.getString("Item"); - String type = null; - String subType = ""; - String meta = ""; - int id = 0; + // Gui item + ItemStack GUIitem = CMIMaterial.GREEN_WOOL.newItemStack(); + if (jobSection.contains("Gui")) { + ConfigurationSection guiSection = jobSection.getConfigurationSection("Gui"); + if (guiSection.contains("Item") && guiSection.isString("Item")) { + String item = guiSection.getString("Item"); + String subType = ""; + @SuppressWarnings("unused") + String meta = ""; - if (item.contains("-")) { - // uses subType - subType = ":" + item.split("-")[1]; - meta = item.split("-")[1]; - item = item.split("-")[0]; - } + if (item.contains("-")) { + // uses subType + subType = ":" + item.split("-")[1]; + meta = item.split("-")[1]; + item = item.split("-")[0]; + } - CMIMaterial material = CMIMaterial.get(item + (subType)); + CMIMaterial material = CMIMaterial.get(item + (subType)); - if (material == null) material = CMIMaterial.get(item.replace(" ", "_").toUpperCase()); + if (material == null) + material = CMIMaterial.get(item.replace(" ", "_").toUpperCase()); - if (material == null) { - // try integer method - Integer matId = null; - try { - matId = Integer.valueOf(item); - } catch (NumberFormatException e) { - } - if (matId != null) { - material = CMIMaterial.get(matId); - if (material != null) { - Jobs.getPluginLogger() - .warning("Job " + jobName + " is using GUI item ID: " + item + "!"); - Jobs.getPluginLogger() - .warning("Please use the Material name instead: " + material.toString() + "!"); - } - } - } - GUIitem = material.newItemStack(); - if (guiSection.contains("Enchantments")) { - List enchants = guiSection.getStringList("Enchantments"); - if (enchants.size() > 0) { - for (String str4 : enchants) { - String[] enchantid = str4.split(":"); - if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) { - EnchantmentStorageMeta enchantMeta = - (EnchantmentStorageMeta) GUIitem.getItemMeta(); - enchantMeta.addStoredEnchant( - Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1]), true); - GUIitem.setItemMeta(enchantMeta); - } else { - GUIitem.addUnsafeEnchantment( - Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1])); - } - } - } - } - } else if (guiSection.contains("Id") - && guiSection.contains("Data") - && guiSection.isInt("Id") - && guiSection.isInt("Data")) { - GUIitem = - CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack(); - if (guiSection.contains("Enchantments")) { - List enchants = guiSection.getStringList("Enchantments"); - if (enchants.size() > 0) { - for (String str4 : enchants) { - String[] id = str4.split(":"); - if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) { - EnchantmentStorageMeta enchantMeta = - (EnchantmentStorageMeta) GUIitem.getItemMeta(); - enchantMeta.addStoredEnchant( - Enchantment.getByName(id[0]), Integer.parseInt(id[1]), true); - GUIitem.setItemMeta(enchantMeta); - } else { - GUIitem.addUnsafeEnchantment( - Enchantment.getByName(id[0]), Integer.parseInt(id[1])); - } - } - } - } - } else if (guiSection.contains("CustomSkull")) { - String skullOwner = guiSection.getString("CustomSkull"); - GUIitem = CMIMaterial.PLAYER_HEAD.newItemStack(); - SkullMeta skullMeta = (SkullMeta) GUIitem.getItemMeta(); - if (skullOwner.length() == 36) { - try { - OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner)); - skullMeta.setOwner(offPlayer.getName()); - } catch (Exception e) { - } - } else skullMeta.setOwner(skullOwner); - GUIitem.setItemMeta(skullMeta); - } else - Jobs.getPluginLogger() - .warning( - "Job " - + jobKey - + " has an invalid Gui property. Please fix this if you want to use it!"); - } + if (material == null) { + // try integer method + Integer matId = null; + try { + matId = Integer.valueOf(item); + } catch (NumberFormatException e) { + } + if (matId != null) { + material = CMIMaterial.get(matId); + if (material != null) { + Jobs.getPluginLogger().warning("Job " + jobName + " is using GUI item ID: " + item + "!"); + Jobs.getPluginLogger().warning("Please use the Material name instead: " + material.toString() + "!"); + } + } + } + GUIitem = material.newItemStack(); + if (guiSection.contains("Enchantments")) { + List enchants = guiSection.getStringList("Enchantments"); + if (enchants.size() > 0) { + for (String str4 : enchants) { + String[] enchantid = str4.split(":"); + if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) { + EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) GUIitem.getItemMeta(); + enchantMeta.addStoredEnchant(Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1]), true); + GUIitem.setItemMeta(enchantMeta); + } else { + GUIitem.addUnsafeEnchantment(Enchantment.getByName(enchantid[0]), Integer.parseInt(enchantid[1])); + } + } + } + } else if (guiSection.contains("CustomSkull")) { + String skullOwner = guiSection.getString("CustomSkull"); + GUIitem = CMIMaterial.PLAYER_HEAD.newItemStack(); + SkullMeta skullMeta = (SkullMeta) GUIitem.getItemMeta(); + if (skullOwner.length() == 36) { + try { + OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner)); + skullMeta.setOwner(offPlayer.getName()); + } catch (Exception e) { + } + } else + skullMeta.setOwner(skullOwner); + GUIitem.setItemMeta(skullMeta); + } else + Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid Gui property. Please fix this if you want to use it!"); + } else if (guiSection.contains("Id") && guiSection.contains("Data") && guiSection.isInt("Id") && guiSection.isInt("Data")) { + GUIitem = CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack(); + if (guiSection.contains("Enchantments")) { + List enchants = guiSection.getStringList("Enchantments"); + if (enchants.size() > 0) { + for (String str4 : enchants) { + String[] id = str4.split(":"); + if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) { + EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) GUIitem.getItemMeta(); + enchantMeta.addStoredEnchant(Enchantment.getByName(id[0]), Integer.parseInt(id[1]), true); + GUIitem.setItemMeta(enchantMeta); + } else { + GUIitem.addUnsafeEnchantment(Enchantment.getByName(id[0]), Integer.parseInt(id[1])); + } + } + } + } else if (guiSection.contains("CustomSkull")) { + String skullOwner = guiSection.getString("CustomSkull"); + GUIitem = CMIMaterial.PLAYER_HEAD.newItemStack(); + SkullMeta skullMeta = (SkullMeta) GUIitem.getItemMeta(); + if (skullOwner.length() == 36) { + try { + OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner)); + skullMeta.setOwner(offPlayer.getName()); + } catch (Exception e) { + } + } else + skullMeta.setOwner(skullOwner); + GUIitem.setItemMeta(skullMeta); + } else + Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid Gui property. Please fix this if you want to use it!"); + } + } // Permissions ArrayList jobPermissions = new ArrayList<>(); From 5950d64506f699645b70419b58cf00beae7f54d1 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Mon, 8 Oct 2018 16:47:35 +0200 Subject: [PATCH 3/3] Update jobConfig.yml --- src/main/resources/jobConfig.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/resources/jobConfig.yml b/src/main/resources/jobConfig.yml index e9c7a759..abe843b3 100644 --- a/src/main/resources/jobConfig.yml +++ b/src/main/resources/jobConfig.yml @@ -79,10 +79,13 @@ Jobs: rejoinCooldown: 10 # GUI icon information when using GUI function Gui: + # name of the block + Item: LOG:2 + # If you want to use this instaed of Item name. # id of block - Id: 17 + # Id: 17 # data of block, usually its 0, but in example Diorite will have id of 1 and data of 3 - Data: 2 + # Data: 2 # enchants in the item Enchantments: - 'DURABILITY:1' @@ -2459,4 +2462,4 @@ Jobs: experience-progression-equation: baseexperience-(baseexperience*((numjobs-1) *0.01)) Kill: Player: - income: 7.5 \ No newline at end of file + income: 7.5