Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Miecz loadFromFile(YamlConfiguration yml, String path) {
- /*
- * SETTING BELOW IS ALLOCATED TO ITEMSTACK DATA
- */
- String itemName = "not set";
- if(yml.isSet(path+".itemName")) itemName = yml.getString(path+".itemName");
- Material material = Material.BARRIER;
- if(yml.isSet(path+".material")) {
- material = Material.matchMaterial(yml.getString(path+".material"));
- }
- Short materialID = 0;
- if(yml.isSet(path+".matID")) {
- materialID = (short) yml.getInt(path+".matID");
- }
- Color color = null;
- if(yml.isSet(path+".color")) {
- String[] split = yml.getString(path+".color").split("-");
- Integer B = 0,G = 0,R = 0;
- try {
- R = Integer.parseInt(split[0]);
- G = Integer.parseInt(split[1]);
- B = Integer.parseInt(split[2]);
- }catch(NumberFormatException exception) {
- 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 '-'");
- }
- color = Color.fromBGR(B, G, R);
- }
- /*
- * SETTING BELOW IS ALLOCATED TO NBT DATA
- */
- Double[][] phyDamage = new Double[2][2];
- if(yml.isSet(path+".physicalDamage")) {
- String split[] = yml.getString(path+".physicalDamage").split("-");
- try {
- phyDamage[0][0] = Double.parseDouble(split[0]);
- phyDamage[0][1] = Double.parseDouble(split[1]);
- phyDamage[1][0] = Double.parseDouble(split[2]);
- phyDamage[1][1] = Double.parseDouble(split[3]);
- }catch(NumberFormatException exc) {
- phyDamage[0][0] = -1.0;
- 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 '-'");
- }
- } else {
- // NOT SET
- phyDamage[0][0] = -1.0;
- }
- Double[][] magDamage = new Double[2][2];
- if(yml.isSet(path+".magicalDamage")) {
- String split[] = yml.getString(path+"magicalDamage").split("-");
- try {
- magDamage[0][0] = Double.parseDouble(split[0]);
- magDamage[0][1] = Double.parseDouble(split[1]);
- magDamage[1][0] = Double.parseDouble(split[2]);
- magDamage[1][1] = Double.parseDouble(split[3]);
- }catch(NumberFormatException exc) {
- 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 '-'");
- magDamage[0][0] = -1.0;
- }
- } else {
- // NOT SET
- magDamage[0][0] = -1.0;
- }
- Integer minLevel = -1;
- if(yml.isSet(path+".levelNeeded")) {
- try {
- minLevel = Integer.parseInt(yml.getString(path+".levelNeeded"));
- }catch(NumberFormatException exc) {
- minLevel = -1;
- 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");
- }
- } else {
- // NOT SET
- minLevel = -1;
- }
- Double[] critChance = new Double[2];
- if(yml.isSet(path+".critChance")) {
- String split[] = yml.getString(path+".critChance").split("-");
- try {
- critChance[0] = Double.parseDouble(split[0]);
- critChance[1] = Double.parseDouble(split[1]);
- }catch(NumberFormatException exc) {
- 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");
- critChance[0] = -1.0;
- }
- } else {
- // NOT SET
- critChance[0] = -1.0;
- }
- Integer[] bonusSlots = new Integer[2];
- if(yml.isSet(path+".bonusSlots")) {
- String[] split = yml.getString(path+".bonusSlots").split("-");
- try {
- bonusSlots[0] = Integer.parseInt(split[0]);
- bonusSlots[1] = Integer.parseInt(split[1]);
- }catch(NumberFormatException exception) {
- 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");
- bonusSlots[0] = -1;
- }
- } else {
- // NOT SET
- bonusSlots[0] = -1;
- }
- Integer[] runeSlots = new Integer[2];
- if(yml.isSet(path+".runeSlots")) {
- String[] split = yml.getString(path+".runeSlots").split("-");
- try {
- runeSlots[0] = Integer.parseInt(split[0]);
- runeSlots[1] = Integer.parseInt(split[1]);
- }catch(NumberFormatException exception) {
- 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");
- runeSlots[0] = -1;
- }
- } else {
- // NOT SET
- runeSlots[0] = -1;
- }
- List<String> opis = new ArrayList<>();
- if(yml.isSet(path+".opis")) {
- for(String s : yml.getStringList(path+".opis")) {
- opis.add(ChatColor.translateAlternateColorCodes('&', s));
- }
- }
- Integer startingUpgradeLevel = -1;
- if(yml.isSet(path+".startingUpgrade")) {
- try {
- startingUpgradeLevel = Integer.parseInt(yml.getString(path+".startingUpgrade"));
- }catch(NumberFormatException exception) {
- 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");
- startingUpgradeLevel = -1;
- }
- }
- Integer price = 0;
- if(yml.isSet(path+".price")) {
- try {
- price = Integer.parseInt(yml.getString(path+".price"));
- }catch(NumberFormatException exception) {
- 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");
- price = 0;
- }
- } else Bukkit.getLogger().log(Level.WARNING, "No price given for "+path+", price should ALWAYS be set!");
- ItemRarity rarity = ItemRarity.NOTSET;
- if(yml.isSet(path+".rarity")) {
- rarity = ItemRarity.valueOf(yml.getString(path+".rarity").toUpperCase());
- } else Bukkit.getLogger().log(Level.WARNING, "No rarity given for "+path+", rarity should ALWAYS be set!");
- return new Miecz(itemName, material, materialID, color, phyDamage, magDamage, minLevel, critChance, bonusSlots, runeSlots, opis, startingUpgradeLevel, rarity, price);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement