PageRenderTime 562ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/moCreatures/server/core/sources/net/minecraft/src/PlayerNBTManager.java

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