Problem whith: InventoryIO.loadFromTextfile() #24


  • New
  • Defect
Open
Assigned to _ForgeUser7442508
  • _ForgeUser9951113 created this issue Aug 20, 2014

    Hello!

    I had some concerns in the save, I looked at the code and I rectified this which go much better:

    package net.sradonia.bukkit.alphachest;

    public class InventoryIO {

        public static Inventory loadFromTextfile(File file) throws IOException {
            final Inventory inventory = Bukkit.getServer().createInventory(null, 6 * 9);

            final BufferedReader in = new BufferedReader(new FileReader(file));

            String line;
            int slot = 0;
            while ((line = in.readLine()) != null) {
                if (!line.equals("")) {
                    final String[] parts = line.split(":");
                    try {
                int type = Integer.parseInt(parts[0]);
                Material mat = Material.getMaterial(parts[0]);   //--------------      Material mat ...
                int amount = Integer.parseInt(parts[1]);
                short damage = Short.parseShort(parts[2]);
                if (type != 0) {
                    inventory.setItem(slot, new ItemStack(mat, amount, damage));  //-------     Material  mat

                                                            //   @SuppressWarnings("deprecation") with type
                }
            } catch (NumberFormatException e) {
        }
      ++slot;
             }
         }
        in.close();
        return inventory;
        }

    tanks sowerdb :)

  • _ForgeUser9951113 added the tags New Defect Aug 20, 2014
  • _ForgeUser9951113 edited description Aug 20, 2014
  • _ForgeUser9951113 edited description Aug 20, 2014

To post a comment, please login or register a new account.