/src/TownyDataSource.java

https://github.com/Theino/Towny-Obsidian · Java · 91 lines · 50 code · 11 blank · 30 comment · 0 complexity · e6e62713d1f6d7176b737d85545313bf MD5 · raw file

  1. import java.util.logging.Logger;
  2. //import java.io.*;
  3. public abstract class TownyDataSource {
  4. protected static final Logger log = Logger.getLogger("Minecraft");
  5. //private final String newLine = System.getProperty("line.separator");
  6. public TownyWorld world;
  7. public void initialize(TownyWorld world) {
  8. this.world = world;
  9. }
  10. public boolean loadAll() {
  11. return (
  12. loadNationList() &&
  13. loadTownList() &&
  14. loadResidentList() &&
  15. loadTownBlocks() &&
  16. loadNations() &&
  17. loadTowns() &&
  18. loadResidents()
  19. );
  20. }
  21. public boolean saveAll() {
  22. //saveXml();
  23. return (
  24. saveNationList() &&
  25. saveTownList() &&
  26. saveResidentList() &&
  27. saveTownBlocks() &&
  28. saveNations() &&
  29. saveTowns() &&
  30. saveResidents()
  31. );
  32. }
  33. abstract public boolean loadResidentList();
  34. abstract public boolean loadTownList();
  35. abstract public boolean loadNationList();
  36. abstract public boolean saveResidentList();
  37. abstract public boolean saveTownList();
  38. abstract public boolean saveNationList();
  39. abstract public boolean loadResidents();
  40. abstract public boolean loadTowns();
  41. abstract public boolean loadNations();
  42. abstract public boolean saveResidents();
  43. abstract public boolean saveTowns();
  44. abstract public boolean saveNations();
  45. abstract public boolean loadResident(Resident resdient);
  46. abstract public boolean loadTown(Town town);
  47. abstract public boolean loadNation(Nation nation);
  48. abstract public boolean saveResident(Resident resdient);
  49. abstract public boolean saveTown(Town town);
  50. abstract public boolean saveNation(Nation nation);
  51. abstract public boolean loadTownBlocks();
  52. abstract public boolean saveTownBlocks();
  53. /*public void saveXml() {
  54. try {
  55. BufferedWriter fout = new BufferedWriter(new FileWriter(TownyProperties.flatFileFolder + "/data/world.xml"));
  56. fout.write("<?xml version=\"1.0\" ?>" + newLine);
  57. fout.write("<world>" + newLine);
  58. for (Nation nation : world.nations.values()) {
  59. fout.write(" <nation name=\""+nation.name+"\">" + newLine);
  60. for (Town town : nation.towns) {
  61. fout.write(" <town name=\""+town.name+"\" mayor=\""+town.mayor.name+"\">" + newLine);
  62. fout.write(" <residents>" + newLine);
  63. for (Resident resident: town.residents)
  64. fout.write(" <resident name=\""+resident.name+"\" />" + newLine);
  65. fout.write(" </residents>" + newLine);
  66. fout.write(" <townblocks>" + newLine);
  67. for (TownBlock townblock : world.getTownBlocks(town))
  68. fout.write(" <townblock x=\""+Long.toString(townblock.x)+"\" z=\""+Long.toString(townblock.z)+"\" owner=\""+(townblock.resident == null ? "" : townblock.resident.name) + "\" />" + newLine);
  69. fout.write(" </townblocks>" + newLine);
  70. fout.write(" </town>" + newLine);
  71. }
  72. fout.write(" </nation>" + newLine);
  73. }
  74. fout.write("</world>" + newLine);
  75. fout.close();
  76. } catch (Exception e) {
  77. log.log(Level.SEVERE, "Exception while saving town blocks xml file", e);
  78. }
  79. }*/
  80. }