Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package net.minecraft.server;
2
3import java.io.*;
4import java.util.*;
5
6public class WorldMapCollection {
7
8 private IDataManager a;
9 private Map b = new HashMap();
10 private List c = new ArrayList();
11 private Map d = new HashMap();
12
13 public WorldMapCollection(IDataManager idatamanager) {
14 this.a = idatamanager;
15 this.b();
16 }
17
18 public WorldMapBase a(Class oclass, String s) {
19 WorldMapBase worldmapbase = (WorldMapBase) this.b.get(s);
20
21 if (worldmapbase != null) {
22 return worldmapbase;
23 } else {
24 if (this.a != null) {
25 try {
26 File file1 = this.a.b(s);
27
28 if (file1 != null && file1.exists()) {
29 try {
30 worldmapbase = (WorldMapBase) oclass.getConstructor(new Class[] { String.class }).newInstance(new Object[] { s });
31 } catch (Exception exception) {
32 throw new RuntimeException("Failed to instantiate " + oclass.toString(), exception);
33 }
34
35 FileInputStream fileinputstream = new FileInputStream(file1);
36 NBTTagCompound nbttagcompound = CompressedStreamTools.a((InputStream) fileinputstream);
37
38 fileinputstream.close();
39 worldmapbase.a(nbttagcompound.k("data"));
40 }
41 } catch (Exception exception1) {
42 exception1.printStackTrace();
43 }
44 }
45
46 if (worldmapbase != null) {
47 this.b.put(s, worldmapbase);
48 this.c.add(worldmapbase);
49 }
50
51 return worldmapbase;
52 }
53 }
54
55 public void a(String s, WorldMapBase worldmapbase) {
56 if (worldmapbase == null) {
57 throw new RuntimeException("Can\'t set null data");
58 } else {
59 if (this.b.containsKey(s)) {
60 this.c.remove(this.b.remove(s));
61 }
62
63 this.b.put(s, worldmapbase);
64 this.c.add(worldmapbase);
65 }
66 }
67
68 public void a() {
69 for (int i = 0; i < this.c.size(); ++i) {
70 WorldMapBase worldmapbase = (WorldMapBase) this.c.get(i);
71
72 if (worldmapbase.b()) {
73 this.a(worldmapbase);
74 worldmapbase.a(false);
75 }
76 }
77 }
78
79 private void a(WorldMapBase worldmapbase) {
80 if (this.a != null) {
81 try {
82 File file1 = this.a.b(worldmapbase.a);
83
84 if (file1 != null) {
85 NBTTagCompound nbttagcompound = new NBTTagCompound();
86
87 worldmapbase.b(nbttagcompound);
88 NBTTagCompound nbttagcompound1 = new NBTTagCompound();
89
90 nbttagcompound1.a("data", nbttagcompound);
91 FileOutputStream fileoutputstream = new FileOutputStream(file1);
92
93 CompressedStreamTools.a(nbttagcompound1, (OutputStream) fileoutputstream);
94 fileoutputstream.close();
95 }
96 } catch (Exception exception) {
97 exception.printStackTrace();
98 }
99 }
100 }
101
102 private void b() {
103 try {
104 this.d.clear();
105 if (this.a == null) {
106 return;
107 }
108
109 File file1 = this.a.b("idcounts");
110
111 if (file1 != null && file1.exists()) {
112 DataInputStream datainputstream = new DataInputStream(new FileInputStream(file1));
113 NBTTagCompound nbttagcompound = CompressedStreamTools.a((DataInput) datainputstream);
114
115 datainputstream.close();
116 Iterator iterator = nbttagcompound.c().iterator();
117
118 while (iterator.hasNext()) {
119 NBTBase nbtbase = (NBTBase) iterator.next();
120
121 if (nbtbase instanceof NBTTagShort) {
122 NBTTagShort nbttagshort = (NBTTagShort) nbtbase;
123 String s = nbttagshort.b();
124 short short1 = nbttagshort.a;
125
126 this.d.put(s, Short.valueOf(short1));
127 }
128 }
129 }
130 } catch (Exception exception) {
131 exception.printStackTrace();
132 }
133 }
134
135 public int a(String s) {
136 Short oshort = (Short) this.d.get(s);
137
138 if (oshort == null) {
139 oshort = Short.valueOf((short) 0);
140 } else {
141 oshort = Short.valueOf((short) (oshort.shortValue() + 1));
142 }
143
144 this.d.put(s, oshort);
145 if (this.a == null) {
146 return oshort.shortValue();
147 } else {
148 try {
149 File file1 = this.a.b("idcounts");
150
151 if (file1 != null) {
152 NBTTagCompound nbttagcompound = new NBTTagCompound();
153 Iterator iterator = this.d.keySet().iterator();
154
155 while (iterator.hasNext()) {
156 String s1 = (String) iterator.next();
157 short short1 = ((Short) this.d.get(s1)).shortValue();
158
159 nbttagcompound.a(s1, short1);
160 }
161
162 DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(file1));
163
164 CompressedStreamTools.a(nbttagcompound, (DataOutput) dataoutputstream);
165 dataoutputstream.close();
166 }
167 } catch (Exception exception) {
168 exception.printStackTrace();
169 }
170
171 return oshort.shortValue();
172 }
173 }
174}