packagenl.rpsonline.remcodemah.alarmmessage;importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.File;importjava.io.FileReader;importjava.io.FileWriter;importjava.io.IOException;importjava.util.Iterator;importorg.bukkit.Bukkit;importorg.bukkit.Location;importorg.bukkit.World;publicclassData{staticFilefile=newFile("plugins/AlarmMessage/data");staticFilefolder=newFile("plugins/AlarmMessage/");publicstaticAlarmMessageplugin;@SuppressWarnings("unused")publicstaticbooleanLoad(){// check if file exists;if(!file.exists()){try{folder.mkdirs();file.createNewFile();}catch(IOExceptione){returnfalse;}returntrue;}// Read data!;try{BufferedReaderin=newBufferedReader(newFileReader(file));Stringstring;while((string=in.readLine())!=null){if(string!=null){AlarmMessagelog=newAlarmMessage();log.logger.info("[AlarmMessage] Reading file");stringToHashMap(string);}}in.close();}catch(IOExceptione){AlarmMessagecore=newAlarmMessage();core.logger.warning("Can not Load the File.");returnfalse;}BufferedReaderin;returntrue;}// Save data!;@SuppressWarnings("unused")publicstaticbooleanSave(){if(!file.exists()){try{folder.mkdirs();file.createNewFile();}catch(IOExceptione){returnfalse;}}try{BufferedWriterout=newBufferedWriter(newFileWriter(file));BufferedReaderin=newBufferedReader(newFileReader(file));Iterator<Location>iterator=AlarmMessage.hm.keySet().iterator();while(iterator.hasNext()){Locationlocation=iterator.next();Stringline234=AlarmMessage.hm.get(location);out.write(LocationToString(location));out.write(" - "+line234);out.newLine();}out.close();}catch(IOExceptione){returnfalse;}BufferedWriterout;returntrue;}privatestaticvoidstringToHashMap(Stringstring){String[] split = string.split(" - ");
try {
World world = Bukkit.getWorld(split[0]);
double x = Double.parseDouble(split[1]);
double y = Double.parseDouble(split[2]);
double z = Double.parseDouble(split[3]);
Location location = new Location (world, x, y, z);
String tekst = split[4];
AlarmMessage.hm.put(location, tekst);
} catch (Exception e) {
AlarmMessage lugin = new AlarmMessage();
lugin.logger.warning("Error Converting File");
lugin.logger.warning("Make shure that it look like (World - Double x - Double y - Double z - String)");
lugin.logger.info("World is just a name, Doubles are cordinates, String is tekst");
lugin.logger.info("If the file looks correct and you get the error please make a ticket, and attach your file");
}
}
private static String LocationToString(Location location) {
String world = location.getWorld().getName().trim();
double x = location.getX();
double y = location.getY();
double z = location.getZ();
String sx = Double.toString(x);
String sy = Double.toString(y);
String sz = Double.toString(z);
String tekst = world + " - " + sx + " - " + sy + " - " + sz;
return tekst;
}
}
-
View User Profile
-
Send Message
Posted Apr 6, 2012I Know the page is not good outlined but if you copy your page in Eclipse there is no problem
-
View User Profile
-
Send Message
Posted Apr 7, 2012Uhm, als er een @Suppresswarning("unused") is, betekent dat dat je dat stuk niet gebruikt... is dat hier het geval?