Problem with ChestMenu

Discussion in 'Plugin Development' started by men8, Apr 5, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    men8

    Today I've got source code that I can edit to match my servers preferences, but I've got problem with this task. Default action of the plugin is read things from yml file and create from it chest menu. Normally it works really good but I want to add 4 more variables to display different item, name and lore if player don't have specific permission. Normally I would check permission like test.test but in this case I must check this perm from yml. Here is the code:

    Code:java
    1. /**
    2.   * @param Player
    3.   * @return the icon, or null if there were errors.
    4.   */
    5. @SuppressWarnings("deprecation")
    6. public Icon loadIconFromConfigurationSection(ConfigurationSection node, String filename) {
    7. String cmd = node.getString("COMMAND");
    8. String name = node.getString("NAME");
    9. String name1 = node.getString("NAME-OFF");//new variable
    10. List<String> description = node.getStringList("LORE");
    11. List<String> description1 = node.getStringList("LORE-OFF");//new variable
    12. String itemString = node.getString("ID");
    13. String itemString1 = node.getString("ID-OFF");//new variable
    14. short data = (short) node.getInt("DATA-VALUE");
    15. short data1 = (short) node.getInt("DATA-VALUE-OFF");//new variable
    16. double price = node.getDouble("PRICE");
    17. int amount = node.getInt("AMOUNT");
    18. String enchString = node.getString("ENCHANTMENT");
    19. boolean keepOpen = node.getBoolean("KEEP-OPEN");
    20. String perm = node.getString("PERMISSION");
    21. String requiredItem = node.getString("REQUIRED-ITEM");
    22. String color = node.getString("COLOR");
    23.  
    24.  
    25. int itemId = 7;
    26. if (p.hasPermission(perm)) //in this place I try to check permission
    27. {
    28. if (itemString == null) {
    29. itemString = "BEDROCK";
    30. ErrorLogger.addError("The item \"" + node.getName() + "\" in the file \"" + filename + "\" has no ID.");
    31. if (description != null) description.add("§cID not set.");
    32. }
    33.  
    34. try {
    35. ItemStackReader reader = new ItemStackReader(itemString);
    36. itemId = reader.getMaterial().getId();
    37. if (reader.hasDataValue()) data = reader.getDataValue();
    38. if (reader.hasAmount()) amount = reader.getAmount();
    39. } catch (ItemFormatException ex) {
    40. if (description != null) description.add("§cInvalid ID.");
    41. ErrorLogger.addError("The item \"" + node.getName() + "\" in the file \"" + filename + "\" has an invalid ID. " + ex.getError());
    42. if (filename.equals("items.yml")) return null;
    43. }
    44.  
    45. Icon icon = new Icon(Material.getMaterial(itemId));
    46.  
    47. if (price < 0.0) ErrorLogger.addError("The item \"" + node.getName() + "\" in the file \"" + filename + "\" has a negative PRICE.");
    48. else icon.setPrice(price);
    49.  
    50. if (InventoryUtil.isLeatherArmor(Material.getMaterial(itemId)) && color != null) {
    51. LeatherArmorMeta armorMeta = (LeatherArmorMeta) icon.stack.getItemMeta();
    52. try {
    53. armorMeta.setColor(InventoryUtil.readArmorColor(color));
    54. icon.stack.setItemMeta(armorMeta);
    55. } catch (ArmorColorException ex) {
    56. ErrorLogger.addError("The armor \"" + node.getName() + "\" in the file \"" + filename + "\" has an invalid COLOR: " + ex.getError());
    57. }
    58. }
    59.  
    60. icon.setRequiredItem(requiredItem);
    61. icon.setDurability(data);
    62. icon.setAmount(amount);
    63. icon.setNameAndLore(name, description);
    64. icon.setCommands(Command.arrayFromString(cmd));
    65. icon.setKeepOpen(keepOpen);
    66. icon.setPermission(perm);
    67. icon.addEnchantmentBundleArray(Utils.getEnchantmentsBundleFromString(enchString, node.getName(), filename));
    68. return icon;
    69. }
    70. else
    71. {
    72. if (itemString1 == null) {
    73. itemString1 = "BEDROCK";
    74. ErrorLogger.addError("The item \"" + node.getName() + "\" in the file \"" + filename + "\" has no ID.");
    75. if (description != null) description.add("§cID not set.");
    76. }
    77.  
    78. try {
    79. ItemStackReader reader = new ItemStackReader(itemString1);
    80. itemId = reader.getMaterial().getId();
    81. if (reader.hasDataValue()) data = reader.getDataValue();
    82. if (reader.hasAmount()) amount = reader.getAmount();
    83. } catch (ItemFormatException ex) {
    84. if (description != null) description.add("§cInvalid ID.");
    85. ErrorLogger.addError("The item \"" + node.getName() + "\" in the file \"" + filename + "\" has an invalid ID. " + ex.getError());
    86. if (filename.equals("items.yml")) return null;
    87. }
    88.  
    89. Icon icon = new Icon(Material.getMaterial(itemId));
    90.  
    91. if (price < 0.0) ErrorLogger.addError("The item \"" + node.getName() + "\" in the file \"" + filename + "\" has a negative PRICE.");
    92. else icon.setPrice(price);
    93.  
    94. if (InventoryUtil.isLeatherArmor(Material.getMaterial(itemId)) && color != null) {
    95. LeatherArmorMeta armorMeta = (LeatherArmorMeta) icon.stack.getItemMeta();
    96. try {
    97. armorMeta.setColor(InventoryUtil.readArmorColor(color));
    98. icon.stack.setItemMeta(armorMeta);
    99. } catch (ArmorColorException ex) {
    100. ErrorLogger.addError("The armor \"" + node.getName() + "\" in the file \"" + filename + "\" has an invalid COLOR: " + ex.getError());
    101. }
    102. }
    103.  
    104. icon.setRequiredItem(requiredItem);
    105. icon.setDurability(data1);
    106. icon.setAmount(amount);
    107. icon.setNameAndLore(name1, description1);
    108. icon.setCommands(Command.arrayFromString(cmd));
    109. icon.setKeepOpen(keepOpen);
    110. icon.setPermission(perm);
    111. icon.addEnchantmentBundleArray(Utils.getEnchantmentsBundleFromString(enchString, node.getName(), filename));
    112. return icon;
    113. }
    114.  
    115.  
    116. }

    please help me

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page