summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/NBTTagCompound.java
blob: 0b9beb7d7f5cb50698e8d2215015b4e4db8ffdee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
package net.minecraft.server;

import java.io.DataInput;
import java.io.DataOutput;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.Callable;

public class NBTTagCompound extends NBTBase {

    private Map map = new HashMap();

    public NBTTagCompound() {
        super("");
    }

    public NBTTagCompound(String s) {
        super(s);
    }

    void write(DataOutput dataoutput) {
        Iterator iterator = this.map.values().iterator();

        while (iterator.hasNext()) {
            NBTBase nbtbase = (NBTBase) iterator.next();

            NBTBase.a(nbtbase, dataoutput);
        }

        // CraftBukkit start
        try {
            dataoutput.writeByte(0);
        } catch (java.io.IOException ex) {
            ex.printStackTrace();
        }
    }

    public void remove(String name) {
        map.remove(name);
    }
    // CraftBukkit end

    void load(DataInput datainput) {
        this.map.clear();

        NBTBase nbtbase;

        while ((nbtbase = NBTBase.b(datainput)).getTypeId() != 0) {
            this.map.put(nbtbase.getName(), nbtbase);
        }
    }

    public Collection c() {
        return this.map.values();
    }

    public byte getTypeId() {
        return (byte) 10;
    }

    public void set(String s, NBTBase nbtbase) {
        this.map.put(s, nbtbase.setName(s));
    }

    public void setByte(String s, byte b0) {
        this.map.put(s, new NBTTagByte(s, b0));
    }

    public void setShort(String s, short short1) {
        this.map.put(s, new NBTTagShort(s, short1));
    }

    public void setInt(String s, int i) {
        this.map.put(s, new NBTTagInt(s, i));
    }

    public void setLong(String s, long i) {
        this.map.put(s, new NBTTagLong(s, i));
    }

    public void setFloat(String s, float f) {
        this.map.put(s, new NBTTagFloat(s, f));
    }

    public void setDouble(String s, double d0) {
        this.map.put(s, new NBTTagDouble(s, d0));
    }

    public void setString(String s, String s1) {
        this.map.put(s, new NBTTagString(s, s1));
    }

    public void setByteArray(String s, byte[] abyte) {
        this.map.put(s, new NBTTagByteArray(s, abyte));
    }

    public void setIntArray(String s, int[] aint) {
        this.map.put(s, new NBTTagIntArray(s, aint));
    }

    public void setCompound(String s, NBTTagCompound nbttagcompound) {
        this.map.put(s, nbttagcompound.setName(s));
    }

    public void setBoolean(String s, boolean flag) {
        this.setByte(s, (byte) (flag ? 1 : 0));
    }

    public NBTBase get(String s) {
        return (NBTBase) this.map.get(s);
    }

    public boolean hasKey(String s) {
        return this.map.containsKey(s);
    }

    public byte getByte(String s) {
        try {
            return !this.map.containsKey(s) ? 0 : ((NBTTagByte) this.map.get(s)).data;
        } catch (ClassCastException classcastexception) {
            throw new ReportedException(this.a(s, 1, classcastexception));
        }
    }

    public short getShort(String s) {
        try {
            return !this.map.containsKey(s) ? 0 : ((NBTTagShort) this.map.get(s)).data;
        } catch (ClassCastException classcastexception) {
            throw new ReportedException(this.a(s, 2, classcastexception));
        }
    }

    public int getInt(String s) {
        try {
            return !this.map.containsKey(s) ? 0 : ((NBTTagInt) this.map.get(s)).data;
        } catch (ClassCastException classcastexception) {
            throw new ReportedException(this.a(s, 3, classcastexception));
        }
    }

    public long getLong(String s) {
        try {
            return !this.map.containsKey(s) ? 0L : ((NBTTagLong) this.map.get(s)).data;
        } catch (ClassCastException classcastexception) {
            throw new ReportedException(this.a(s, 4, classcastexception));
        }
    }

    public float getFloat(String s) {
        try {
            return !this.map.containsKey(s) ? 0.0F : ((NBTTagFloat) this.map.get(s)).data;
        } catch (ClassCastException classcastexception) {
            throw new ReportedException(this.a(s, 5, classcastexception));
        }
    }

    public double getDouble(String s) {
        try {
            return !this.map.containsKey(s) ? 0.0D : ((NBTTagDouble) this.map.get(s)).data;
        } catch (ClassCastException classcastexception) {
            throw new ReportedException(this.a(s, 6, classcastexception));
        }
    }

    public String getString(String s) {
        try {
            return !this.map.containsKey(s) ? "" : ((NBTTagString) this.map.get(s)).data;
        } catch (ClassCastException classcastexception) {
            throw new ReportedException(this.a(s, 8, classcastexception));
        }
    }

    public byte[] getByteArray(String s) {
        try {
            return !this.map.containsKey(s) ? new byte[0] : ((NBTTagByteArray) this.map.get(s)).data;
        } catch (ClassCastException classcastexception) {
            throw new ReportedException(this.a(s, 7, classcastexception));
        }
    }

    public int[] getIntArray(String s) {
        try {
            return !this.map.containsKey(s) ? new int[0] : ((NBTTagIntArray) this.map.get(s)).data;
        } catch (ClassCastException classcastexception) {
            throw new ReportedException(this.a(s, 11, classcastexception));
        }
    }

    public NBTTagCompound getCompound(String s) {
        try {
            return !this.map.containsKey(s) ? new NBTTagCompound(s) : (NBTTagCompound) this.map.get(s);
        } catch (ClassCastException classcastexception) {
            throw new ReportedException(this.a(s, 10, classcastexception));
        }
    }

    public NBTTagList getList(String s) {
        try {
            return !this.map.containsKey(s) ? new NBTTagList(s) : (NBTTagList) this.map.get(s);
        } catch (ClassCastException classcastexception) {
            throw new ReportedException(this.a(s, 9, classcastexception));
        }
    }

    public boolean getBoolean(String s) {
        return this.getByte(s) != 0;
    }

    public void o(String s) {
        this.map.remove(s);
    }

    public String toString() {
        return "" + this.map.size() + " entries";
    }

    public boolean d() {
        return this.map.isEmpty();
    }

    private CrashReport a(String s, int i, ClassCastException classcastexception) {
        CrashReport crashreport = CrashReport.a(classcastexception, "Reading NBT data");
        CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Corrupt NBT tag", 1);

        crashreportsystemdetails.a("Tag type found", (Callable) (new CrashReportCorruptNBTTag(this, s)));
        crashreportsystemdetails.a("Tag type expected", (Callable) (new CrashReportCorruptNBTTag2(this, i)));
        crashreportsystemdetails.a("Tag name", s);
        if (this.getName() != null && this.getName().length() > 0) {
            crashreportsystemdetails.a("Tag parent", this.getName());
        }

        return crashreport;
    }

    public NBTBase clone() {
        NBTTagCompound nbttagcompound = new NBTTagCompound(this.getName());
        Iterator iterator = this.map.keySet().iterator();

        while (iterator.hasNext()) {
            String s = (String) iterator.next();

            nbttagcompound.set(s, ((NBTBase) this.map.get(s)).clone());
        }

        return nbttagcompound;
    }

    public boolean equals(Object object) {
        if (super.equals(object)) {
            NBTTagCompound nbttagcompound = (NBTTagCompound) object;

            return this.map.entrySet().equals(nbttagcompound.map.entrySet());
        } else {
            return false;
        }
    }

    public int hashCode() {
        return super.hashCode() ^ this.map.hashCode();
    }

    static Map a(NBTTagCompound nbttagcompound) {
        return nbttagcompound.map;
    }
}