PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/mcp/temp/src/minecraft_server/net/minecraft/src/SaveHandler.java

https://bitbucket.org/vkorolik/twoleanfour-client
Java | 261 lines | 233 code | 21 blank | 7 comment | 15 complexity | d8e029b3ab6ccc781aeff0dcf19282f0 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 fieldsfirst
  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. // IPlayerFileData, ISaveHandler, MinecraftException, CompressedStreamTools,
  10. // NBTTagCompound, WorldInfo, EntityPlayer, WorldProvider,
  11. // IChunkLoader
  12. public class SaveHandler
  13. implements IPlayerFileData, ISaveHandler
  14. {
  15. private static final Logger field_1003_a = Logger.getLogger("Minecraft");
  16. private final File field_22099_b;
  17. private final File field_1002_b;
  18. private final File field_28112_d;
  19. private final long field_22100_d = System.currentTimeMillis();
  20. private final String field_40258_f;
  21. public SaveHandler(File p_i142_1_, String p_i142_2_, boolean p_i142_3_)
  22. {
  23. field_22099_b = new File(p_i142_1_, p_i142_2_);
  24. field_22099_b.mkdirs();
  25. field_1002_b = new File(field_22099_b, "players");
  26. field_28112_d = new File(field_22099_b, "data");
  27. field_28112_d.mkdirs();
  28. field_40258_f = p_i142_2_;
  29. if(p_i142_3_)
  30. {
  31. field_1002_b.mkdirs();
  32. }
  33. func_22098_f();
  34. }
  35. private void func_22098_f()
  36. {
  37. try
  38. {
  39. File file = new File(field_22099_b, "session.lock");
  40. DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(file));
  41. try
  42. {
  43. dataoutputstream.writeLong(field_22100_d);
  44. }
  45. finally
  46. {
  47. dataoutputstream.close();
  48. }
  49. }
  50. catch(IOException ioexception)
  51. {
  52. ioexception.printStackTrace();
  53. throw new RuntimeException("Failed to check session lock, aborting");
  54. }
  55. }
  56. protected File func_22097_a()
  57. {
  58. return field_22099_b;
  59. }
  60. public void func_22091_b()
  61. {
  62. try
  63. {
  64. File file = new File(field_22099_b, "session.lock");
  65. DataInputStream datainputstream = new DataInputStream(new FileInputStream(file));
  66. try
  67. {
  68. if(datainputstream.readLong() != field_22100_d)
  69. {
  70. throw new MinecraftException("The save is being accessed from another location, aborting");
  71. }
  72. }
  73. finally
  74. {
  75. datainputstream.close();
  76. }
  77. }
  78. catch(IOException ioexception)
  79. {
  80. throw new MinecraftException("Failed to check session lock, aborting");
  81. }
  82. }
  83. public IChunkLoader func_22092_a(WorldProvider p_22092_1_)
  84. {
  85. throw new RuntimeException("Old Chunk Storage is no longer supported.");
  86. }
  87. public WorldInfo func_22096_c()
  88. {
  89. File file = new File(field_22099_b, "level.dat");
  90. if(file.exists())
  91. {
  92. try
  93. {
  94. NBTTagCompound nbttagcompound = CompressedStreamTools.func_770_a(new FileInputStream(file));
  95. NBTTagCompound nbttagcompound2 = nbttagcompound.func_397_j("Data");
  96. return new WorldInfo(nbttagcompound2);
  97. }
  98. catch(Exception exception)
  99. {
  100. exception.printStackTrace();
  101. }
  102. }
  103. file = new File(field_22099_b, "level.dat_old");
  104. if(file.exists())
  105. {
  106. try
  107. {
  108. NBTTagCompound nbttagcompound1 = CompressedStreamTools.func_770_a(new FileInputStream(file));
  109. NBTTagCompound nbttagcompound3 = nbttagcompound1.func_397_j("Data");
  110. return new WorldInfo(nbttagcompound3);
  111. }
  112. catch(Exception exception1)
  113. {
  114. exception1.printStackTrace();
  115. }
  116. }
  117. return null;
  118. }
  119. public void func_22095_a(WorldInfo p_22095_1_, List p_22095_2_)
  120. {
  121. NBTTagCompound nbttagcompound = p_22095_1_.func_22183_a(p_22095_2_);
  122. NBTTagCompound nbttagcompound1 = new NBTTagCompound();
  123. nbttagcompound1.func_399_a("Data", nbttagcompound);
  124. try
  125. {
  126. File file = new File(field_22099_b, "level.dat_new");
  127. File file1 = new File(field_22099_b, "level.dat_old");
  128. File file2 = new File(field_22099_b, "level.dat");
  129. CompressedStreamTools.func_769_a(nbttagcompound1, new FileOutputStream(file));
  130. if(file1.exists())
  131. {
  132. file1.delete();
  133. }
  134. file2.renameTo(file1);
  135. if(file2.exists())
  136. {
  137. file2.delete();
  138. }
  139. file.renameTo(file2);
  140. if(file.exists())
  141. {
  142. file.delete();
  143. }
  144. }
  145. catch(Exception exception)
  146. {
  147. exception.printStackTrace();
  148. }
  149. }
  150. public void func_22094_a(WorldInfo p_22094_1_)
  151. {
  152. NBTTagCompound nbttagcompound = p_22094_1_.func_22185_a();
  153. NBTTagCompound nbttagcompound1 = new NBTTagCompound();
  154. nbttagcompound1.func_399_a("Data", nbttagcompound);
  155. try
  156. {
  157. File file = new File(field_22099_b, "level.dat_new");
  158. File file1 = new File(field_22099_b, "level.dat_old");
  159. File file2 = new File(field_22099_b, "level.dat");
  160. CompressedStreamTools.func_769_a(nbttagcompound1, new FileOutputStream(file));
  161. if(file1.exists())
  162. {
  163. file1.delete();
  164. }
  165. file2.renameTo(file1);
  166. if(file2.exists())
  167. {
  168. file2.delete();
  169. }
  170. file.renameTo(file2);
  171. if(file.exists())
  172. {
  173. file.delete();
  174. }
  175. }
  176. catch(Exception exception)
  177. {
  178. exception.printStackTrace();
  179. }
  180. }
  181. public void func_726_a(EntityPlayer p_726_1_)
  182. {
  183. try
  184. {
  185. NBTTagCompound nbttagcompound = new NBTTagCompound();
  186. p_726_1_.func_98_d(nbttagcompound);
  187. File file = new File(field_1002_b, "_tmp_.dat");
  188. File file1 = new File(field_1002_b, (new StringBuilder()).append(p_726_1_.field_409_aq).append(".dat").toString());
  189. CompressedStreamTools.func_769_a(nbttagcompound, new FileOutputStream(file));
  190. if(file1.exists())
  191. {
  192. file1.delete();
  193. }
  194. file.renameTo(file1);
  195. }
  196. catch(Exception exception)
  197. {
  198. field_1003_a.warning((new StringBuilder()).append("Failed to save player data for ").append(p_726_1_.field_409_aq).toString());
  199. }
  200. }
  201. public void func_725_b(EntityPlayer p_725_1_)
  202. {
  203. NBTTagCompound nbttagcompound = func_25074_a(p_725_1_.field_409_aq);
  204. if(nbttagcompound != null)
  205. {
  206. p_725_1_.func_100_e(nbttagcompound);
  207. }
  208. }
  209. public NBTTagCompound func_25074_a(String p_25074_1_)
  210. {
  211. try
  212. {
  213. File file = new File(field_1002_b, (new StringBuilder()).append(p_25074_1_).append(".dat").toString());
  214. if(file.exists())
  215. {
  216. return CompressedStreamTools.func_770_a(new FileInputStream(file));
  217. }
  218. }
  219. catch(Exception exception)
  220. {
  221. field_1003_a.warning((new StringBuilder()).append("Failed to load player data for ").append(p_25074_1_).toString());
  222. }
  223. return null;
  224. }
  225. public IPlayerFileData func_22090_d()
  226. {
  227. return this;
  228. }
  229. public String[] func_52007_g()
  230. {
  231. return field_1002_b.list();
  232. }
  233. public void func_22093_e()
  234. {
  235. }
  236. public File func_28111_b(String p_28111_1_)
  237. {
  238. return new File(field_28112_d, (new StringBuilder()).append(p_28111_1_).append(".dat").toString());
  239. }
  240. }