PageRenderTime 975ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/moCreatures/client/core/sources/net/minecraft/src/SaveHandler.java

https://code.google.com/p/minecraft-smp-mocreatures/
Java | 206 lines | 184 code | 15 blank | 7 comment | 12 complexity | 5a66dae8b4cd40821c82415f89580089 MD5 | raw file
  1. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  2. // Jad home page: http://www.kpdus.com/jad.html
  3. // Decompiler options: packimports(3) braces deadcode
  4. package net.minecraft.src;
  5. import java.io.*;
  6. import java.util.List;
  7. import java.util.logging.Logger;
  8. // Referenced classes of package net.minecraft.src:
  9. // ISaveHandler, MinecraftException, WorldProviderHell, ChunkLoader,
  10. // CompressedStreamTools, NBTTagCompound, WorldInfo, WorldProvider,
  11. // IChunkLoader
  12. public class SaveHandler
  13. implements ISaveHandler
  14. {
  15. public SaveHandler(File file, String s, boolean flag)
  16. {
  17. saveDirectory = new File(file, s);
  18. saveDirectory.mkdirs();
  19. playersDirectory = new File(saveDirectory, "players");
  20. field_28114_d = new File(saveDirectory, "data");
  21. field_28114_d.mkdirs();
  22. if(flag)
  23. {
  24. playersDirectory.mkdirs();
  25. }
  26. func_22154_d();
  27. }
  28. private void func_22154_d()
  29. {
  30. try
  31. {
  32. File file = new File(saveDirectory, "session.lock");
  33. DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(file));
  34. try
  35. {
  36. dataoutputstream.writeLong(now);
  37. }
  38. finally
  39. {
  40. dataoutputstream.close();
  41. }
  42. }
  43. catch(IOException ioexception)
  44. {
  45. ioexception.printStackTrace();
  46. throw new RuntimeException("Failed to check session lock, aborting");
  47. }
  48. }
  49. protected File getSaveDirectory()
  50. {
  51. return saveDirectory;
  52. }
  53. public void func_22150_b()
  54. {
  55. try
  56. {
  57. File file = new File(saveDirectory, "session.lock");
  58. DataInputStream datainputstream = new DataInputStream(new FileInputStream(file));
  59. try
  60. {
  61. if(datainputstream.readLong() != now)
  62. {
  63. throw new MinecraftException("The save is being accessed from another location, aborting");
  64. }
  65. }
  66. finally
  67. {
  68. datainputstream.close();
  69. }
  70. }
  71. catch(IOException ioexception)
  72. {
  73. throw new MinecraftException("Failed to check session lock, aborting");
  74. }
  75. }
  76. public IChunkLoader getChunkLoader(WorldProvider worldprovider)
  77. {
  78. if(worldprovider instanceof WorldProviderHell)
  79. {
  80. File file = new File(saveDirectory, "DIM-1");
  81. file.mkdirs();
  82. return new ChunkLoader(file, true);
  83. } else
  84. {
  85. return new ChunkLoader(saveDirectory, true);
  86. }
  87. }
  88. public WorldInfo loadWorldInfo()
  89. {
  90. File file = new File(saveDirectory, "level.dat");
  91. if(file.exists())
  92. {
  93. try
  94. {
  95. NBTTagCompound nbttagcompound = CompressedStreamTools.func_1138_a(new FileInputStream(file));
  96. NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Data");
  97. return new WorldInfo(nbttagcompound2);
  98. }
  99. catch(Exception exception)
  100. {
  101. exception.printStackTrace();
  102. }
  103. }
  104. file = new File(saveDirectory, "level.dat_old");
  105. if(file.exists())
  106. {
  107. try
  108. {
  109. NBTTagCompound nbttagcompound1 = CompressedStreamTools.func_1138_a(new FileInputStream(file));
  110. NBTTagCompound nbttagcompound3 = nbttagcompound1.getCompoundTag("Data");
  111. return new WorldInfo(nbttagcompound3);
  112. }
  113. catch(Exception exception1)
  114. {
  115. exception1.printStackTrace();
  116. }
  117. }
  118. return null;
  119. }
  120. public void saveWorldInfoAndPlayer(WorldInfo worldinfo, List list)
  121. {
  122. NBTTagCompound nbttagcompound = worldinfo.getNBTTagCompoundWithPlayer(list);
  123. NBTTagCompound nbttagcompound1 = new NBTTagCompound();
  124. nbttagcompound1.setTag("Data", nbttagcompound);
  125. try
  126. {
  127. File file = new File(saveDirectory, "level.dat_new");
  128. File file1 = new File(saveDirectory, "level.dat_old");
  129. File file2 = new File(saveDirectory, "level.dat");
  130. CompressedStreamTools.writeGzippedCompoundToOutputStream(nbttagcompound1, new FileOutputStream(file));
  131. if(file1.exists())
  132. {
  133. file1.delete();
  134. }
  135. file2.renameTo(file1);
  136. if(file2.exists())
  137. {
  138. file2.delete();
  139. }
  140. file.renameTo(file2);
  141. if(file.exists())
  142. {
  143. file.delete();
  144. }
  145. }
  146. catch(Exception exception)
  147. {
  148. exception.printStackTrace();
  149. }
  150. }
  151. public void saveWorldInfo(WorldInfo worldinfo)
  152. {
  153. NBTTagCompound nbttagcompound = worldinfo.getNBTTagCompound();
  154. NBTTagCompound nbttagcompound1 = new NBTTagCompound();
  155. nbttagcompound1.setTag("Data", nbttagcompound);
  156. try
  157. {
  158. File file = new File(saveDirectory, "level.dat_new");
  159. File file1 = new File(saveDirectory, "level.dat_old");
  160. File file2 = new File(saveDirectory, "level.dat");
  161. CompressedStreamTools.writeGzippedCompoundToOutputStream(nbttagcompound1, new FileOutputStream(file));
  162. if(file1.exists())
  163. {
  164. file1.delete();
  165. }
  166. file2.renameTo(file1);
  167. if(file2.exists())
  168. {
  169. file2.delete();
  170. }
  171. file.renameTo(file2);
  172. if(file.exists())
  173. {
  174. file.delete();
  175. }
  176. }
  177. catch(Exception exception)
  178. {
  179. exception.printStackTrace();
  180. }
  181. }
  182. public File func_28113_a(String s)
  183. {
  184. return new File(field_28114_d, (new StringBuilder()).append(s).append(".dat").toString());
  185. }
  186. private static final Logger logger = Logger.getLogger("Minecraft");
  187. private final File saveDirectory;
  188. private final File playersDirectory;
  189. private final File field_28114_d;
  190. private final long now = System.currentTimeMillis();
  191. }