Hi! I would save a specific Block, and load it on restart - but there is a problem. It's saved correctly, but not loaded correctly My Code: Code: public void save(){ for(Location l : plugin.getB()){ Data dd = plugin.getData(l); try { BufferedWriter out = new BufferedWriter(new FileWriter(new File(plugin.getDataFolder(), "data.dat"))); out.write( new StringBuilder() .append(l.getWorld().getName()).append(",").append(l.getX()).append(",").append(l.getY()).append(",").append(l.getZ()) .append(";") .append(dd.getID()).append("#").append(dd.getAmount()).append("#").append(dd.getData()).toString()); out.newLine(); out.close(); }catch(Exception e){ e.printStackTrace(); } } } public void load(){ try{ BufferedReader br = new BufferedReader(new FileReader(new File(plugin.getDataFolder(), "data.dat"))); String line = ""; while((line = br.readLine()) != null){ World w = Bukkit.getWorld(line.split(",")[0]); double x = Double.valueOf(line.split(",")[1]); double y = Double.valueOf(line.split(",")[2]); double z = Double.valueOf(line.split(",")[3]); Location loc = new Location(w, x,y,z); Data dd = new Data(Integer.valueOf(line.split(";")[1].split("#")[0]), Integer.valueOf(line.split(";")[1].split("#")[1]), Byte.valueOf(line.split(";")[1].split("#")[2])); plugin.blocks.put(loc, dd); } br.close(); }catch(Exception e){ } } load is called in the enable method, save in the disable method.
YamlConfiguration maybe ;3? The conversion String-Location would be like Code:java public Location strToLoc(String loc) throws IllegalArgumentException{ String parts = loc.split(",", 4); if(parts.length != 4) { throw new IllegalArgumentException("String representation was not valid"); } World w = Bukkit.getWorld(parts[0]); if(w == null) { throw new IllegalArgumentException("World not found"); } try { int x = Integer.parseInt(parts[1]); int y = Integer.parseInt(parts[2]); int z = Integer.parseInt(parts[3]); return new Location(w,x,y,z); } catch(NumberFormatException ex) { throw new IllegalArgumentException("x, y or z was not a valid integer"); }} And Location to String Code:java public String locToStr(Location loc){ StringBuilder sb = new StringBuilder(loc.getWorld().getName()); sb.append(",").append(loc.getBlockX()); sb.append(",").append(loc.getBlockY()); sb.append(",").append(loc.getBlockZ()); return sb.toString();}
fireblast709 Thanks! But the Problem is, that its not just an location - its a location wirh 3other values, and i dont know why its not working Anyway, i try it