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