|
19 | 19 |
|
20 | 20 | package com.sk89q.jnbt;
|
21 | 21 |
|
22 |
| -import net.kyori.adventure.nbt.BinaryTag; |
23 |
| -import net.kyori.adventure.nbt.ByteArrayBinaryTag; |
24 |
| -import net.kyori.adventure.nbt.ByteBinaryTag; |
25 |
| -import net.kyori.adventure.nbt.CompoundBinaryTag; |
26 |
| -import net.kyori.adventure.nbt.DoubleBinaryTag; |
27 |
| -import net.kyori.adventure.nbt.EndBinaryTag; |
28 |
| -import net.kyori.adventure.nbt.FloatBinaryTag; |
29 |
| -import net.kyori.adventure.nbt.IntArrayBinaryTag; |
30 |
| -import net.kyori.adventure.nbt.IntBinaryTag; |
31 |
| -import net.kyori.adventure.nbt.ListBinaryTag; |
32 |
| -import net.kyori.adventure.nbt.LongArrayBinaryTag; |
33 |
| -import net.kyori.adventure.nbt.LongBinaryTag; |
34 |
| -import net.kyori.adventure.nbt.ShortBinaryTag; |
35 |
| -import net.kyori.adventure.nbt.StringBinaryTag; |
36 |
| - |
37 |
| -import java.util.ArrayList; |
38 |
| -import java.util.Arrays; |
39 |
| -import java.util.HashMap; |
40 |
| -import java.util.List; |
41 |
| -import java.util.Map; |
42 |
| -import java.util.Set; |
43 |
| - |
| 22 | +import com.sk89q.worldedit.util.nbt.BinaryTag; |
| 23 | +import com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag; |
| 24 | +import com.sk89q.worldedit.util.nbt.ByteBinaryTag; |
| 25 | +import com.sk89q.worldedit.util.nbt.CompoundBinaryTag; |
| 26 | +import com.sk89q.worldedit.util.nbt.DoubleBinaryTag; |
| 27 | +import com.sk89q.worldedit.util.nbt.EndBinaryTag; |
| 28 | +import com.sk89q.worldedit.util.nbt.FloatBinaryTag; |
| 29 | +import com.sk89q.worldedit.util.nbt.IntArrayBinaryTag; |
| 30 | +import com.sk89q.worldedit.util.nbt.IntBinaryTag; |
| 31 | +import com.sk89q.worldedit.util.nbt.ListBinaryTag; |
| 32 | +import com.sk89q.worldedit.util.nbt.LongArrayBinaryTag; |
| 33 | +import com.sk89q.worldedit.util.nbt.LongBinaryTag; |
| 34 | +import com.sk89q.worldedit.util.nbt.ShortBinaryTag; |
| 35 | +import com.sk89q.worldedit.util.nbt.StringBinaryTag; |
| 36 | + |
| 37 | +/** |
| 38 | + * @deprecated JNBT is being removed in WE8. |
| 39 | + */ |
| 40 | +@Deprecated |
44 | 41 | public class AdventureNBTConverter {
|
45 | 42 |
|
46 | 43 | private AdventureNBTConverter() {
|
@@ -77,162 +74,135 @@ public static BinaryTag toAdventure(Tag tag) {
|
77 | 74 | }
|
78 | 75 | }
|
79 | 76 |
|
80 |
| - public static IntArrayBinaryTag toAdventure(IntArrayTag tag) { |
81 |
| - int[] value = tag.getValue(); |
82 |
| - return IntArrayBinaryTag.of(Arrays.copyOf(value, value.length)); |
| 77 | + private static DoubleBinaryTag toAdventure(DoubleTag tag) { |
| 78 | + return tag.toAdventure(); |
83 | 79 | }
|
84 | 80 |
|
85 |
| - public static ListBinaryTag toAdventure(ListTag tag) { |
86 |
| - ListBinaryTag.Builder<BinaryTag> builder = ListBinaryTag.builder(); |
87 |
| - for (Tag child : tag.getValue()) { |
88 |
| - if (child instanceof EndTag) { |
89 |
| - continue; |
90 |
| - } |
91 |
| - builder.add(toAdventure(child)); |
92 |
| - } |
93 |
| - return builder.build(); |
| 81 | + private static ShortBinaryTag toAdventure(ShortTag tag) { |
| 82 | + return tag.toAdventure(); |
94 | 83 | }
|
95 | 84 |
|
96 |
| - public static LongBinaryTag toAdventure(LongTag tag) { |
97 |
| - return LongBinaryTag.of(tag.getValue()); |
| 85 | + private static FloatBinaryTag toAdventure(FloatTag tag) { |
| 86 | + return tag.toAdventure(); |
98 | 87 | }
|
99 | 88 |
|
100 |
| - public static LongArrayBinaryTag toAdventure(LongArrayTag tag) { |
101 |
| - return LongArrayBinaryTag.of(tag.getValue().clone()); |
| 89 | + private static ByteArrayBinaryTag toAdventure(ByteArrayTag tag) { |
| 90 | + return tag.toAdventure(); |
102 | 91 | }
|
103 | 92 |
|
104 |
| - public static StringBinaryTag toAdventure(StringTag tag) { |
105 |
| - return StringBinaryTag.of(tag.getValue()); |
| 93 | + private static ByteBinaryTag toAdventure(ByteTag tag) { |
| 94 | + return tag.toAdventure(); |
106 | 95 | }
|
107 | 96 |
|
108 |
| - public static IntBinaryTag toAdventure(IntTag tag) { |
109 |
| - return IntBinaryTag.of(tag.getValue()); |
| 97 | + private static IntBinaryTag toAdventure(IntTag tag) { |
| 98 | + return tag.toAdventure(); |
110 | 99 | }
|
111 | 100 |
|
112 |
| - public static ByteBinaryTag toAdventure(ByteTag tag) { |
113 |
| - return ByteBinaryTag.of(tag.getValue()); |
| 101 | + private static StringBinaryTag toAdventure(StringTag tag) { |
| 102 | + return tag.toAdventure(); |
114 | 103 | }
|
115 | 104 |
|
116 |
| - public static ByteArrayBinaryTag toAdventure(ByteArrayTag tag) { |
117 |
| - return ByteArrayBinaryTag.of(tag.getValue().clone()); |
| 105 | + private static LongArrayBinaryTag toAdventure(LongArrayTag tag) { |
| 106 | + return tag.toAdventure(); |
118 | 107 | }
|
119 | 108 |
|
120 |
| - public static CompoundBinaryTag toAdventure(CompoundTag tag) { |
121 |
| - CompoundBinaryTag.Builder builder = CompoundBinaryTag.builder(); |
122 |
| - for (Map.Entry<String, Tag> child : tag.getValue().entrySet()) { |
123 |
| - builder.put(child.getKey(), toAdventure(child.getValue())); |
124 |
| - } |
125 |
| - return builder.build(); |
| 109 | + private static LongBinaryTag toAdventure(LongTag tag) { |
| 110 | + return tag.toAdventure(); |
126 | 111 | }
|
127 | 112 |
|
128 |
| - public static FloatBinaryTag toAdventure(FloatTag tag) { |
129 |
| - return FloatBinaryTag.of(tag.getValue()); |
| 113 | + private static IntArrayBinaryTag toAdventure(IntArrayTag tag) { |
| 114 | + return tag.toAdventure(); |
130 | 115 | }
|
131 | 116 |
|
132 |
| - public static ShortBinaryTag toAdventure(ShortTag tag) { |
133 |
| - return ShortBinaryTag.of(tag.getValue()); |
| 117 | + public static ListBinaryTag toAdventure(ListTag tag) { |
| 118 | + return tag.toAdventure(); |
134 | 119 | }
|
135 | 120 |
|
136 |
| - public static DoubleBinaryTag toAdventure(DoubleTag tag) { |
137 |
| - return DoubleBinaryTag.of(tag.getValue()); |
| 121 | + public static CompoundBinaryTag toAdventure(CompoundTag tag) { |
| 122 | + return tag.toAdventure(); |
138 | 123 | }
|
139 | 124 |
|
140 | 125 | public static Tag fromAdventure(BinaryTag other) {
|
141 | 126 | if (other instanceof IntArrayBinaryTag) {
|
142 |
| - return AdventureNBTConverter.fromAdventure((IntArrayBinaryTag) other); |
| 127 | + return fromAdventure((IntArrayBinaryTag) other); |
143 | 128 | } else if (other instanceof ListBinaryTag) {
|
144 |
| - return AdventureNBTConverter.fromAdventure((ListBinaryTag) other); |
| 129 | + return fromAdventure((ListBinaryTag) other); |
145 | 130 | } else if (other instanceof EndBinaryTag) {
|
146 |
| - return AdventureNBTConverter.fromAdventure((EndBinaryTag) other); |
| 131 | + return fromAdventure(); |
147 | 132 | } else if (other instanceof LongBinaryTag) {
|
148 |
| - return AdventureNBTConverter.fromAdventure((LongBinaryTag) other); |
| 133 | + return fromAdventure((LongBinaryTag) other); |
149 | 134 | } else if (other instanceof LongArrayBinaryTag) {
|
150 |
| - return AdventureNBTConverter.fromAdventure((LongArrayBinaryTag) other); |
| 135 | + return fromAdventure((LongArrayBinaryTag) other); |
151 | 136 | } else if (other instanceof StringBinaryTag) {
|
152 |
| - return AdventureNBTConverter.fromAdventure((StringBinaryTag) other); |
| 137 | + return fromAdventure((StringBinaryTag) other); |
153 | 138 | } else if (other instanceof IntBinaryTag) {
|
154 |
| - return AdventureNBTConverter.fromAdventure((IntBinaryTag) other); |
| 139 | + return fromAdventure((IntBinaryTag) other); |
155 | 140 | } else if (other instanceof ByteBinaryTag) {
|
156 |
| - return AdventureNBTConverter.fromAdventure((ByteBinaryTag) other); |
| 141 | + return fromAdventure((ByteBinaryTag) other); |
157 | 142 | } else if (other instanceof ByteArrayBinaryTag) {
|
158 |
| - return AdventureNBTConverter.fromAdventure((ByteArrayBinaryTag) other); |
| 143 | + return fromAdventure((ByteArrayBinaryTag) other); |
159 | 144 | } else if (other instanceof CompoundBinaryTag) {
|
160 |
| - return AdventureNBTConverter.fromAdventure((CompoundBinaryTag) other); |
| 145 | + return fromAdventure((CompoundBinaryTag) other); |
161 | 146 | } else if (other instanceof FloatBinaryTag) {
|
162 |
| - return AdventureNBTConverter.fromAdventure((FloatBinaryTag) other); |
| 147 | + return fromAdventure((FloatBinaryTag) other); |
163 | 148 | } else if (other instanceof ShortBinaryTag) {
|
164 |
| - return AdventureNBTConverter.fromAdventure((ShortBinaryTag) other); |
| 149 | + return fromAdventure((ShortBinaryTag) other); |
165 | 150 | } else if (other instanceof DoubleBinaryTag) {
|
166 | 151 | return fromAdventure((DoubleBinaryTag) other);
|
167 | 152 | } else {
|
168 | 153 | throw new IllegalArgumentException("Can't convert other of type " + other.getClass().getCanonicalName());
|
169 | 154 | }
|
170 | 155 | }
|
171 | 156 |
|
172 |
| - public static IntArrayTag fromAdventure(IntArrayBinaryTag other) { |
173 |
| - int[] value = other.value(); |
174 |
| - return new IntArrayTag(Arrays.copyOf(value, value.length)); |
| 157 | + public static DoubleTag fromAdventure(DoubleBinaryTag other) { |
| 158 | + return new DoubleTag(other); |
175 | 159 | }
|
176 | 160 |
|
177 |
| - public static ListTag fromAdventure(ListBinaryTag other) { |
178 |
| - List<Tag> list = new ArrayList<>(); |
179 |
| - Class<? extends Tag> listClass = StringTag.class; |
180 |
| - int tags = other.size(); |
181 |
| - for (int i = 0; i < tags; i++) { |
182 |
| - Tag child = fromAdventure(other.get(0)); |
183 |
| - list.add(child); |
184 |
| - listClass = child.getClass(); |
185 |
| - } |
186 |
| - return new ListTag(listClass, list); |
| 161 | + public static ShortTag fromAdventure(ShortBinaryTag other) { |
| 162 | + return new ShortTag(other); |
187 | 163 | }
|
188 | 164 |
|
189 |
| - public static EndTag fromAdventure(EndBinaryTag other) { |
190 |
| - return new EndTag(); |
| 165 | + public static FloatTag fromAdventure(FloatBinaryTag other) { |
| 166 | + return new FloatTag(other); |
191 | 167 | }
|
192 | 168 |
|
193 |
| - public static LongTag fromAdventure(LongBinaryTag other) { |
194 |
| - return new LongTag(other.value()); |
| 169 | + public static CompoundTag fromAdventure(CompoundBinaryTag other) { |
| 170 | + return new CompoundTag(other); |
195 | 171 | }
|
196 | 172 |
|
197 |
| - public static LongArrayTag fromAdventure(LongArrayBinaryTag other) { |
198 |
| - return new LongArrayTag(other.value().clone()); |
| 173 | + public static ByteArrayTag fromAdventure(ByteArrayBinaryTag other) { |
| 174 | + return new ByteArrayTag(other); |
199 | 175 | }
|
200 | 176 |
|
201 |
| - public static StringTag fromAdventure(StringBinaryTag other) { |
202 |
| - return new StringTag(other.value()); |
| 177 | + public static ByteTag fromAdventure(ByteBinaryTag other) { |
| 178 | + return new ByteTag(other); |
203 | 179 | }
|
204 | 180 |
|
205 | 181 | public static IntTag fromAdventure(IntBinaryTag other) {
|
206 |
| - return new IntTag(other.value()); |
| 182 | + return new IntTag(other); |
207 | 183 | }
|
208 | 184 |
|
209 |
| - public static ByteTag fromAdventure(ByteBinaryTag other) { |
210 |
| - return new ByteTag(other.value()); |
| 185 | + public static StringTag fromAdventure(StringBinaryTag other) { |
| 186 | + return new StringTag(other); |
211 | 187 | }
|
212 | 188 |
|
213 |
| - public static ByteArrayTag fromAdventure(ByteArrayBinaryTag other) { |
214 |
| - return new ByteArrayTag(other.value().clone()); |
| 189 | + public static LongArrayTag fromAdventure(LongArrayBinaryTag other) { |
| 190 | + return new LongArrayTag(other); |
215 | 191 | }
|
216 | 192 |
|
217 |
| - public static CompoundTag fromAdventure(CompoundBinaryTag other) { |
218 |
| - Set<String> tags = other.keySet(); |
219 |
| - Map<String, Tag> map = new HashMap<>(); |
220 |
| - for (String tagName : tags) { |
221 |
| - map.put(tagName, fromAdventure(other.get(tagName))); |
222 |
| - } |
223 |
| - return new CompoundTag(map); |
| 193 | + public static LongTag fromAdventure(LongBinaryTag other) { |
| 194 | + return new LongTag(other); |
224 | 195 | }
|
225 | 196 |
|
226 |
| - public static FloatTag fromAdventure(FloatBinaryTag other) { |
227 |
| - return new FloatTag(other.value()); |
| 197 | + public static EndTag fromAdventure() { |
| 198 | + return new EndTag(); |
228 | 199 | }
|
229 | 200 |
|
230 |
| - public static ShortTag fromAdventure(ShortBinaryTag other) { |
231 |
| - return new ShortTag(other.value()); |
| 201 | + public static ListTag fromAdventure(ListBinaryTag other) { |
| 202 | + return new ListTag(other); |
232 | 203 | }
|
233 | 204 |
|
234 |
| - public static DoubleTag fromAdventure(DoubleBinaryTag other) { |
235 |
| - return new DoubleTag(other.value()); |
| 205 | + public static IntArrayTag fromAdventure(IntArrayBinaryTag other) { |
| 206 | + return new IntArrayTag(other); |
236 | 207 | }
|
237 |
| - |
238 | 208 | }
|
0 commit comments