|
| 1 | +/* |
| 2 | + * WorldEdit, a Minecraft world manipulation toolkit |
| 3 | + * Copyright (C) sk89q <http://www.sk89q.com> |
| 4 | + * Copyright (C) WorldEdit team and contributors |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +package com.sk89q.jnbt; |
| 21 | + |
| 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 | + * Converts between JNBT and Adventure-NBT classes. |
| 39 | + * |
| 40 | + * @deprecated JNBT is being removed in WE8. |
| 41 | + */ |
| 42 | +@Deprecated |
| 43 | +public class AdventureNBTConverter { |
| 44 | + |
| 45 | + private AdventureNBTConverter() { |
| 46 | + |
| 47 | + } |
| 48 | + |
| 49 | + public static BinaryTag toAdventure(Tag tag) { |
| 50 | + if (tag instanceof IntArrayTag) { |
| 51 | + return toAdventure((IntArrayTag) tag); |
| 52 | + } else if (tag instanceof ListTag) { |
| 53 | + return toAdventure((ListTag) tag); |
| 54 | + } else if (tag instanceof LongTag) { |
| 55 | + return toAdventure((LongTag) tag); |
| 56 | + } else if (tag instanceof LongArrayTag) { |
| 57 | + return toAdventure((LongArrayTag) tag); |
| 58 | + } else if (tag instanceof StringTag) { |
| 59 | + return toAdventure((StringTag) tag); |
| 60 | + } else if (tag instanceof IntTag) { |
| 61 | + return toAdventure((IntTag) tag); |
| 62 | + } else if (tag instanceof ByteTag) { |
| 63 | + return toAdventure((ByteTag) tag); |
| 64 | + } else if (tag instanceof ByteArrayTag) { |
| 65 | + return toAdventure((ByteArrayTag) tag); |
| 66 | + } else if (tag instanceof CompoundTag) { |
| 67 | + return toAdventure((CompoundTag) tag); |
| 68 | + } else if (tag instanceof FloatTag) { |
| 69 | + return toAdventure((FloatTag) tag); |
| 70 | + } else if (tag instanceof ShortTag) { |
| 71 | + return toAdventure((ShortTag) tag); |
| 72 | + } else if (tag instanceof DoubleTag) { |
| 73 | + return toAdventure((DoubleTag) tag); |
| 74 | + } else { |
| 75 | + throw new IllegalArgumentException("Can't convert tag of type " + tag.getClass().getCanonicalName()); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + private static DoubleBinaryTag toAdventure(DoubleTag tag) { |
| 80 | + return tag.toAdventure(); |
| 81 | + } |
| 82 | + |
| 83 | + private static ShortBinaryTag toAdventure(ShortTag tag) { |
| 84 | + return tag.toAdventure(); |
| 85 | + } |
| 86 | + |
| 87 | + private static FloatBinaryTag toAdventure(FloatTag tag) { |
| 88 | + return tag.toAdventure(); |
| 89 | + } |
| 90 | + |
| 91 | + private static ByteArrayBinaryTag toAdventure(ByteArrayTag tag) { |
| 92 | + return tag.toAdventure(); |
| 93 | + } |
| 94 | + |
| 95 | + private static ByteBinaryTag toAdventure(ByteTag tag) { |
| 96 | + return tag.toAdventure(); |
| 97 | + } |
| 98 | + |
| 99 | + private static IntBinaryTag toAdventure(IntTag tag) { |
| 100 | + return tag.toAdventure(); |
| 101 | + } |
| 102 | + |
| 103 | + private static StringBinaryTag toAdventure(StringTag tag) { |
| 104 | + return tag.toAdventure(); |
| 105 | + } |
| 106 | + |
| 107 | + private static LongArrayBinaryTag toAdventure(LongArrayTag tag) { |
| 108 | + return tag.toAdventure(); |
| 109 | + } |
| 110 | + |
| 111 | + private static LongBinaryTag toAdventure(LongTag tag) { |
| 112 | + return tag.toAdventure(); |
| 113 | + } |
| 114 | + |
| 115 | + private static IntArrayBinaryTag toAdventure(IntArrayTag tag) { |
| 116 | + return tag.toAdventure(); |
| 117 | + } |
| 118 | + |
| 119 | + public static ListBinaryTag toAdventure(ListTag tag) { |
| 120 | + return tag.toAdventure(); |
| 121 | + } |
| 122 | + |
| 123 | + public static CompoundBinaryTag toAdventure(CompoundTag tag) { |
| 124 | + return tag.toAdventure(); |
| 125 | + } |
| 126 | + |
| 127 | + public static Tag fromAdventure(BinaryTag other) { |
| 128 | + if (other instanceof IntArrayBinaryTag) { |
| 129 | + return fromAdventure((IntArrayBinaryTag) other); |
| 130 | + } else if (other instanceof ListBinaryTag) { |
| 131 | + return fromAdventure((ListBinaryTag) other); |
| 132 | + } else if (other instanceof EndBinaryTag) { |
| 133 | + return fromAdventure(); |
| 134 | + } else if (other instanceof LongBinaryTag) { |
| 135 | + return fromAdventure((LongBinaryTag) other); |
| 136 | + } else if (other instanceof LongArrayBinaryTag) { |
| 137 | + return fromAdventure((LongArrayBinaryTag) other); |
| 138 | + } else if (other instanceof StringBinaryTag) { |
| 139 | + return fromAdventure((StringBinaryTag) other); |
| 140 | + } else if (other instanceof IntBinaryTag) { |
| 141 | + return fromAdventure((IntBinaryTag) other); |
| 142 | + } else if (other instanceof ByteBinaryTag) { |
| 143 | + return fromAdventure((ByteBinaryTag) other); |
| 144 | + } else if (other instanceof ByteArrayBinaryTag) { |
| 145 | + return fromAdventure((ByteArrayBinaryTag) other); |
| 146 | + } else if (other instanceof CompoundBinaryTag) { |
| 147 | + return fromAdventure((CompoundBinaryTag) other); |
| 148 | + } else if (other instanceof FloatBinaryTag) { |
| 149 | + return fromAdventure((FloatBinaryTag) other); |
| 150 | + } else if (other instanceof ShortBinaryTag) { |
| 151 | + return fromAdventure((ShortBinaryTag) other); |
| 152 | + } else if (other instanceof DoubleBinaryTag) { |
| 153 | + return fromAdventure((DoubleBinaryTag) other); |
| 154 | + } else { |
| 155 | + throw new IllegalArgumentException("Can't convert other of type " + other.getClass().getCanonicalName()); |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + public static DoubleTag fromAdventure(DoubleBinaryTag other) { |
| 160 | + return new DoubleTag(other); |
| 161 | + } |
| 162 | + |
| 163 | + public static ShortTag fromAdventure(ShortBinaryTag other) { |
| 164 | + return new ShortTag(other); |
| 165 | + } |
| 166 | + |
| 167 | + public static FloatTag fromAdventure(FloatBinaryTag other) { |
| 168 | + return new FloatTag(other); |
| 169 | + } |
| 170 | + |
| 171 | + public static CompoundTag fromAdventure(CompoundBinaryTag other) { |
| 172 | + return new CompoundTag(other); |
| 173 | + } |
| 174 | + |
| 175 | + public static ByteArrayTag fromAdventure(ByteArrayBinaryTag other) { |
| 176 | + return new ByteArrayTag(other); |
| 177 | + } |
| 178 | + |
| 179 | + public static ByteTag fromAdventure(ByteBinaryTag other) { |
| 180 | + return new ByteTag(other); |
| 181 | + } |
| 182 | + |
| 183 | + public static IntTag fromAdventure(IntBinaryTag other) { |
| 184 | + return new IntTag(other); |
| 185 | + } |
| 186 | + |
| 187 | + public static StringTag fromAdventure(StringBinaryTag other) { |
| 188 | + return new StringTag(other); |
| 189 | + } |
| 190 | + |
| 191 | + public static LongArrayTag fromAdventure(LongArrayBinaryTag other) { |
| 192 | + return new LongArrayTag(other); |
| 193 | + } |
| 194 | + |
| 195 | + public static LongTag fromAdventure(LongBinaryTag other) { |
| 196 | + return new LongTag(other); |
| 197 | + } |
| 198 | + |
| 199 | + public static EndTag fromAdventure() { |
| 200 | + return new EndTag(); |
| 201 | + } |
| 202 | + |
| 203 | + public static ListTag fromAdventure(ListBinaryTag other) { |
| 204 | + return new ListTag(other); |
| 205 | + } |
| 206 | + |
| 207 | + public static IntArrayTag fromAdventure(IntArrayBinaryTag other) { |
| 208 | + return new IntArrayTag(other); |
| 209 | + } |
| 210 | +} |
0 commit comments