Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. public static Miecz loadFromFile(YamlConfiguration yml, String path) {
  2.  
  3. /*
  4. * SETTING BELOW IS ALLOCATED TO ITEMSTACK DATA
  5. */
  6.  
  7. String itemName = "not set";
  8. if(yml.isSet(path+".itemName")) itemName = yml.getString(path+".itemName");
  9.  
  10. Material material = Material.BARRIER;
  11. if(yml.isSet(path+".material")) {
  12. material = Material.matchMaterial(yml.getString(path+".material"));
  13. }
  14. Short materialID = 0;
  15. if(yml.isSet(path+".matID")) {
  16. materialID = (short) yml.getInt(path+".matID");
  17. }
  18.  
  19. Color color = null;
  20. if(yml.isSet(path+".color")) {
  21. String[] split = yml.getString(path+".color").split("-");
  22. Integer B = 0,G = 0,R = 0;
  23. try {
  24. R = Integer.parseInt(split[0]);
  25. G = Integer.parseInt(split[1]);
  26. B = Integer.parseInt(split[2]);
  27. }catch(NumberFormatException exception) {
  28. Bukkit.getLogger().log(java.util.logging.Level.WARNING, "An error occured while loading Miecz from path" + path + ", wrong color given - "+yml.getString(path+".color")+", RGB values should be split by '-'");
  29. }
  30. color = Color.fromBGR(B, G, R);
  31. }
  32.  
  33. /*
  34. * SETTING BELOW IS ALLOCATED TO NBT DATA
  35. */
  36.  
  37. Double[][] phyDamage = new Double[2][2];
  38. if(yml.isSet(path+".physicalDamage")) {
  39. String split[] = yml.getString(path+".physicalDamage").split("-");
  40. try {
  41. phyDamage[0][0] = Double.parseDouble(split[0]);
  42. phyDamage[0][1] = Double.parseDouble(split[1]);
  43. phyDamage[1][0] = Double.parseDouble(split[2]);
  44. phyDamage[1][1] = Double.parseDouble(split[3]);
  45. }catch(NumberFormatException exc) {
  46. phyDamage[0][0] = -1.0;
  47. Bukkit.getLogger().log(java.util.logging.Level.WARNING, "An error occured while loading Miecz from path" + path + ", wrong physical damage given - "+yml.getString(path+".physicalDamage")+", damage values should be split by '-'");
  48. }
  49. } else {
  50. // NOT SET
  51. phyDamage[0][0] = -1.0;
  52. }
  53.  
  54. Double[][] magDamage = new Double[2][2];
  55. if(yml.isSet(path+".magicalDamage")) {
  56. String split[] = yml.getString(path+"magicalDamage").split("-");
  57. try {
  58. magDamage[0][0] = Double.parseDouble(split[0]);
  59. magDamage[0][1] = Double.parseDouble(split[1]);
  60. magDamage[1][0] = Double.parseDouble(split[2]);
  61. magDamage[1][1] = Double.parseDouble(split[3]);
  62. }catch(NumberFormatException exc) {
  63. Bukkit.getLogger().log(java.util.logging.Level.WARNING, "An error occured while loading Miecz from path" + path + ", wrong magical damage given - "+yml.getString(path+".magicalDamage")+", damage values should be split by '-'");
  64. magDamage[0][0] = -1.0;
  65. }
  66. } else {
  67. // NOT SET
  68. magDamage[0][0] = -1.0;
  69. }
  70.  
  71. Integer minLevel = -1;
  72. if(yml.isSet(path+".levelNeeded")) {
  73. try {
  74. minLevel = Integer.parseInt(yml.getString(path+".levelNeeded"));
  75. }catch(NumberFormatException exc) {
  76. minLevel = -1;
  77. Bukkit.getLogger().log(java.util.logging.Level.WARNING, "An error occured while loading Miecz from path" + path + ", wrong level given - "+yml.getString(path+".levelNeeded")+", level values should be a number");
  78. }
  79. } else {
  80. // NOT SET
  81. minLevel = -1;
  82. }
  83.  
  84. Double[] critChance = new Double[2];
  85. if(yml.isSet(path+".critChance")) {
  86. String split[] = yml.getString(path+".critChance").split("-");
  87. try {
  88. critChance[0] = Double.parseDouble(split[0]);
  89. critChance[1] = Double.parseDouble(split[1]);
  90. }catch(NumberFormatException exc) {
  91. Bukkit.getLogger().log(java.util.logging.Level.WARNING, "An error occured while loading Miecz from path" + path + ", wrong crit chance given - "+yml.getString(path+".critChance")+", crit chance values should be a number");
  92. critChance[0] = -1.0;
  93. }
  94. } else {
  95. // NOT SET
  96. critChance[0] = -1.0;
  97. }
  98.  
  99. Integer[] bonusSlots = new Integer[2];
  100. if(yml.isSet(path+".bonusSlots")) {
  101. String[] split = yml.getString(path+".bonusSlots").split("-");
  102. try {
  103. bonusSlots[0] = Integer.parseInt(split[0]);
  104. bonusSlots[1] = Integer.parseInt(split[1]);
  105. }catch(NumberFormatException exception) {
  106. Bukkit.getLogger().log(java.util.logging.Level.WARNING, "An error occured while loading Miecz from path" + path + ", wrong bonus slots given - "+yml.getString(path+".bonusSlots")+", bonus slots values should be a number");
  107. bonusSlots[0] = -1;
  108. }
  109. } else {
  110. // NOT SET
  111. bonusSlots[0] = -1;
  112. }
  113.  
  114. Integer[] runeSlots = new Integer[2];
  115. if(yml.isSet(path+".runeSlots")) {
  116. String[] split = yml.getString(path+".runeSlots").split("-");
  117. try {
  118. runeSlots[0] = Integer.parseInt(split[0]);
  119. runeSlots[1] = Integer.parseInt(split[1]);
  120. }catch(NumberFormatException exception) {
  121. Bukkit.getLogger().log(java.util.logging.Level.WARNING, "An error occured while loading Miecz from path" + path + ", wrong rune slots given - "+yml.getString(path+".runeSlots")+", rune slots values should be a number");
  122. runeSlots[0] = -1;
  123. }
  124. } else {
  125. // NOT SET
  126. runeSlots[0] = -1;
  127. }
  128.  
  129. List<String> opis = new ArrayList<>();
  130. if(yml.isSet(path+".opis")) {
  131. for(String s : yml.getStringList(path+".opis")) {
  132. opis.add(ChatColor.translateAlternateColorCodes('&', s));
  133. }
  134. }
  135. Integer startingUpgradeLevel = -1;
  136. if(yml.isSet(path+".startingUpgrade")) {
  137. try {
  138. startingUpgradeLevel = Integer.parseInt(yml.getString(path+".startingUpgrade"));
  139. }catch(NumberFormatException exception) {
  140. Bukkit.getLogger().log(java.util.logging.Level.WARNING, "An error occured while loading Miecz from path" + path + ", wrong starting upgrade level given - "+yml.getString(path+".startingUpgraed")+", starting upgrade level values should be a number");
  141. startingUpgradeLevel = -1;
  142. }
  143. }
  144.  
  145. Integer price = 0;
  146. if(yml.isSet(path+".price")) {
  147. try {
  148. price = Integer.parseInt(yml.getString(path+".price"));
  149. }catch(NumberFormatException exception) {
  150. Bukkit.getLogger().log(java.util.logging.Level.WARNING, "An error occured while loading Miecz from path" + path + ", wrong price given - "+yml.getString(path+".price")+", price should be a number");
  151. price = 0;
  152. }
  153. } else Bukkit.getLogger().log(Level.WARNING, "No price given for "+path+", price should ALWAYS be set!");
  154. ItemRarity rarity = ItemRarity.NOTSET;
  155. if(yml.isSet(path+".rarity")) {
  156. rarity = ItemRarity.valueOf(yml.getString(path+".rarity").toUpperCase());
  157. } else Bukkit.getLogger().log(Level.WARNING, "No rarity given for "+path+", rarity should ALWAYS be set!");
  158. return new Miecz(itemName, material, materialID, color, phyDamage, magDamage, minLevel, critChance, bonusSlots, runeSlots, opis, startingUpgradeLevel, rarity, price);
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement