summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/NBTTagCompound.java
blob: cd264824a59c6d916426e3ea79649be4f238263c (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
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;

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) {
        return !this.map.containsKey(s) ? 0 : ((NBTTagByte) this.map.get(s)).data;
    }

    public short getShort(String s) {
        return !this.map.containsKey(s) ? 0 : ((NBTTagShort) this.map.get(s)).data;
    }

    public int getInt(String s) {
        return !this.map.containsKey(s) ? 0 : ((NBTTagInt) this.map.get(s)).data;
    }

    public long getLong(String s) {
        return !this.map.containsKey(s) ? 0L : ((NBTTagLong) this.map.get(s)).data;
    }

    public float getFloat(String s) {
        return !this.map.containsKey(s) ? 0.0F : ((NBTTagFloat) this.map.get(s)).data;
    }

    public double getDouble(String s) {
        return !this.map.containsKey(s) ? 0.0D : ((NBTTagDouble) this.map.get(s)).data;
    }

    public String getString(String s) {
        return !this.map.containsKey(s) ? "" : ((NBTTagString) this.map.get(s)).data;
    }

    public byte[] getByteArray(String s) {
        return !this.map.containsKey(s) ? new byte[0] : ((NBTTagByteArray) this.map.get(s)).data;
    }

    public int[] getIntArray(String s) {
        return !this.map.containsKey(s) ? new int[0] : ((NBTTagIntArray) this.map.get(s)).data;
    }

    public NBTTagCompound getCompound(String s) {
        return !this.map.containsKey(s) ? new NBTTagCompound(s) : (NBTTagCompound) this.map.get(s);
    }

    public NBTTagList getList(String s) {
        return !this.map.containsKey(s) ? new NBTTagList(s) : (NBTTagList) this.map.get(s);
    }

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

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

    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();
    }
}