diff --git a/src/main/java/org/spongepowered/api/util/nbt/ByteArrayTag.java b/src/main/java/org/spongepowered/api/util/nbt/ByteArrayTag.java new file mode 100644 index 00000000000..c2585c05ab1 --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/ByteArrayTag.java @@ -0,0 +1,38 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * NBT tag representing an array of bytes. + */ +public interface ByteArrayTag extends Tag { + + /** + * Gets the value of {@link ByteArrayTag}. + * + * @return The value of {@link ByteArrayTag} + */ + byte[] getValue(); +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/ByteTag.java b/src/main/java/org/spongepowered/api/util/nbt/ByteTag.java new file mode 100644 index 00000000000..b97a07f0600 --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/ByteTag.java @@ -0,0 +1,38 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * NBT tag representing a byte. + */ +public interface ByteTag extends Tag.Primitive { + + /** + * Gets the value of {@link ByteTag}. + * + * @return The value of {@link ByteTag} + */ + byte getValue(); +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/CompoundTag.java b/src/main/java/org/spongepowered/api/util/nbt/CompoundTag.java new file mode 100644 index 00000000000..5e984e81c13 --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/CompoundTag.java @@ -0,0 +1,263 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +import java.util.Set; + +/** + * NBT tag representing a map. + */ +public interface CompoundTag extends Tag { + + /** + * Returns all keys of {@link CompoundTag}. + * + * @return All keys of {@link CompoundTag} + */ + Set keys(); + + /** + * Checks if the {@link CompoundTag} contains a {@link Tag} with + * {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @return {@code True} if the {@link CompoundTag} contains a {@link Tag} + * with {@code key}, otherwise {@code false} + */ + boolean hasKey(String key); + + /** + * Checks if the {@link CompoundTag} contains a {@link Tag} of + * {@link TagType} with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @param type The expected type + * @return {@code True} if the {@link CompoundTag} contains a {@link Tag} + * of {@link TagType} with {@code key}, otherwise {@code false} + */ + boolean hasKey(String key, TagType type); + + /** + * Gets the {@link TagType} of {@link Tag} with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @return The {@link TagType} of {@link Tag} with {@code key} + */ + TagType getType(String key); + + /** + * Gets the boolean with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @return The boolean with {@code key} + */ + boolean getBoolean(String key); + + /** + * Sets {@code key} in {@link CompoundTag} to {@code value}. + * + * @param key The key to set in {@link CompoundTag} + * @param value The boolean to set + */ + void setBoolean(String key, boolean value); + + /** + * Gets the byte with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @return The byte with {@code key} + */ + byte getByte(String key); + + /** + * Sets {@code key} in {@link CompoundTag} to {@code value}. + * + * @param key The key to set in {@link CompoundTag} + * @param value The byte to set + */ + void setByte(String key, byte value); + + /** + * Gets the short with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @return The short with {@code key} + */ + short getShort(String key); + + /** + * Sets {@code key} in {@link CompoundTag} to {@code value}. + * + * @param key The key to set in {@link CompoundTag} + * @param value The short to set + */ + void setShort(String key, short value); + + /** + * Gets the integer with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @return The integer with {@code key} + */ + int getInteger(String key); + + /** + * Sets {@code key} in {@link CompoundTag} to {@code value}. + * + * @param key The key to set in {@link CompoundTag} + * @param value The int to set + */ + void setInteger(String key, int value); + + /** + * Gets the long with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @return The long with {@code key} + */ + long getLong(String key); + + /** + * Sets {@code key} in {@link CompoundTag} to {@code value}. + * + * @param key The key to set in {@link CompoundTag} + * @param value The long to set + */ + void setLong(String key, long value); + + /** + * Gets the float with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @return The float with {@code key} + */ + float getFloat(String key); + + /** + * Sets {@code key} in {@link CompoundTag} to {@code value}. + * + * @param key The key to set in {@link CompoundTag} + * @param value The float to set + */ + void setFloat(String key, float value); + + /** + * Gets the double with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @return The double with {@code key} + */ + double getDouble(String key); + + /** + * Sets {@code key} in {@link CompoundTag} to {@code value}. + * + * @param key The key to set in {@link CompoundTag} + * @param value The double to set + */ + void setDouble(String key, double value); + + /** + * Gets the array of bytes with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @return The array of bytes with {@code key} + */ + byte[] getByteArray(String key); + + /** + * Sets {@code key} in {@link CompoundTag} to {@code value}. + * + * @param key The key to set in {@link CompoundTag} + * @param value The array of bytes to set + */ + void setByteArray(String key, byte[] value); + + /** + * Gets the array of integers with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @return The array of integers with {@code key} + */ + int[] getIntArray(String key); + + /** + * Sets {@code key} in {@link CompoundTag} to {@code value}. + * + * @param key The key to set in {@link CompoundTag} + * @param value The array of integers to set + */ + void setIntArray(String key, int[] value); + + /** + * Gets the {@link ListTag} of {@link TagType} with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @param type The {@link TagType} of {@link ListTag} + * @return The {@link ListTag} of {@link TagType} with {@code key} + * + */ + ListTag getList(String key, TagType type); + + /** + * Sets {@code key} in {@link CompoundTag} to {@code list}. + * + * @param key The key to set in {@link CompoundTag} + * @param list The {@link ListTag} to set + */ + void setList(String key, ListTag list); + + /** + * Gets the {@link CompoundTag} with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @return The {@link CompoundTag} with {@code key} + */ + CompoundTag getCompound(String key); + + /** + * Sets {@code key} in {@link CompoundTag} to {@code compound}. + * + * @param key The key to set in {@link CompoundTag} + * @param compound The {@link CompountTag} to set + */ + void setCompound(String key, CompoundTag compound); + + /** + * Gets the {@link Tag} with {@code key}. + * + * @param key The key to get from {@link CompoundTag} + * @return The {@link Tag} with {@code key} + */ + Tag getTag(String key); + + /** + * Sets {@code key} in {@link CompoundTag} to {@code tag}. + * + * @param key The key to set in {@link CompoundTag} + * @param tag The {@link Tag} to set + */ + void setTag(String key, Tag tag); +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/DoubleTag.java b/src/main/java/org/spongepowered/api/util/nbt/DoubleTag.java new file mode 100644 index 00000000000..0d40bdee3b5 --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/DoubleTag.java @@ -0,0 +1,38 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * NBT tag representing a double. + */ +public interface DoubleTag extends Tag.Primitive { + + /** + * Gets the value of {@link DoubleTag}. + * + * @return The value of {@link DoubleTag} + */ + double getValue(); +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/EndTag.java b/src/main/java/org/spongepowered/api/util/nbt/EndTag.java new file mode 100644 index 00000000000..90dca2bad60 --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/EndTag.java @@ -0,0 +1,32 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * NBT tag representing an end. + */ +public interface EndTag extends Tag { + +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/FloatTag.java b/src/main/java/org/spongepowered/api/util/nbt/FloatTag.java new file mode 100644 index 00000000000..bdcbae9dc08 --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/FloatTag.java @@ -0,0 +1,38 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * NBT tag representing a float. + */ +public interface FloatTag extends Tag.Primitive { + + /** + * Gets the value of {@link FloatTag}. + * + * @return The value of {@link FloatTag} + */ + float getValue(); +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/IntArrayTag.java b/src/main/java/org/spongepowered/api/util/nbt/IntArrayTag.java new file mode 100644 index 00000000000..9070b06e081 --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/IntArrayTag.java @@ -0,0 +1,38 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * NBT tag representing an array of integers. + */ +public interface IntArrayTag extends Tag { + + /** + * Gets the value of {@link IntArrayTag}. + * + * @return The value of {@link IntArrayTag} + */ + int[] getValue(); +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/IntTag.java b/src/main/java/org/spongepowered/api/util/nbt/IntTag.java new file mode 100644 index 00000000000..c4406e56e6a --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/IntTag.java @@ -0,0 +1,38 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * NBT tag representing an int. + */ +public interface IntTag extends Tag.Primitive { + + /** + * Gets the value of {@link IntTag}. + * + * @return The value of {@link IntTag} + */ + int getValue(); +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/ListTag.java b/src/main/java/org/spongepowered/api/util/nbt/ListTag.java new file mode 100644 index 00000000000..1a9c93ad04b --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/ListTag.java @@ -0,0 +1,157 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * NBT tag representing a list. + */ +public interface ListTag extends Tag { + + /** + * Returns the count of tags in {@link ListTag}. + * + * @return The count of tags in {@link ListTag} + */ + int count(); + + /** + * Gets the {@link TagType} of {@link Tag}s in {@link ListTag}. + * + * @return The {@link TagType} of {@link Tag}s in {@link ListTag} + */ + TagType getListType(); + + /** + * Gets the byte at {@code index}. + * + * @param index The index to get from {@link ListTag} + * @return The byte at {@code index} + */ + byte getByte(int index); + + /** + * Gets the short at {@code index}. + * + * @param index The index to get from {@link ListTag} + * @return The short at {@code index} + */ + short getShort(int index); + + /** + * Gets the integer at {@code index}. + * + * @param index The index to get from {@link ListTag} + * @return The integer at {@code index} + */ + int getInteger(int index); + + /** + * Gets the long at {@code index}. + * + * @param index The index to get from {@link ListTag} + * @return The long at {@code index} + */ + long getLong(int index); + + /** + * Gets the float at {@code index}. + * + * @param index The index to get from {@link ListTag} + * @return The float at {@code index} + */ + float getFloat(int index); + + /** + * Gets the double at {@code index}. + * + * @param index The index to get from {@link ListTag} + * @return The double at {@code index} + */ + double getDouble(int index); + + /** + * Gets the String at {@code index}. + * + * @param index The index to get from {@link ListTag} + * @return The String at {@code index} + */ + String getString(int index); + + /** + * Gets the array of bytes at {@code index}. + * + * @param index The index to get from {@link ListTag} + * @return The array of bytes at {@code index} + */ + byte[] getByteArray(int index); + + /** + * Gets the array of integers at {@code index}. + * + * @param index The index to get from {@link ListTag} + * @return The array of integers at {@code index} + */ + int[] getIntArray(int index); + + /** + * Gets the {@link ListTag} of {@link TagType} at {@code index}. + * + * @param index The index to get from {@link ListTag} + * @param type The {@link TagType} of {@link ListTag} + * @return The {@link ListTag} of {@link TagType} at {@code index} + * + */ + ListTag getList(int index, TagType type); + + /** + * Gets the {@link CompoundTag} at {@code index}. + * + * @param index The index to get from {@link ListTag} + * @return The {@link CompoundTag} at {@code index} + */ + CompoundTag getCompound(int index); + + /** + * Appends the {@link Tag} to {@code ListTag}. + * + * @param tag The {@link Tag} to append + */ + void append(Tag tag); + + /** + * Inserts the {@link Tag} at {@code index} in {@code ListTag}. + * + * @param index The index to insert at {@link ListTag} + * @param tag The {@link Tag} to insert + */ + void insert(int index, Tag tag); + + /** + * Removes the {@link Tag} at {@code index} of {@code ListTag}. + * + * @param index The index to remove from {@link ListTag} + */ + void remove(int index); +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/LongTag.java b/src/main/java/org/spongepowered/api/util/nbt/LongTag.java new file mode 100644 index 00000000000..adc07ed5019 --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/LongTag.java @@ -0,0 +1,38 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * NBT tag representing a long. + */ +public interface LongTag extends Tag.Primitive { + + /** + * Gets the value of {@link LongTag}. + * + * @return The value of {@link LongTag} + */ + long getValue(); +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/ShortTag.java b/src/main/java/org/spongepowered/api/util/nbt/ShortTag.java new file mode 100644 index 00000000000..232633232a9 --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/ShortTag.java @@ -0,0 +1,38 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * NBT tag representing a short. + */ +public interface ShortTag extends Tag.Primitive { + + /** + * Gets the value of {@link ShortTag}. + * + * @return The value of {@link ShortTag} + */ + short getValue(); +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/StringTag.java b/src/main/java/org/spongepowered/api/util/nbt/StringTag.java new file mode 100644 index 00000000000..30ebebc2e50 --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/StringTag.java @@ -0,0 +1,38 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * NBT tag representing a string. + */ +public interface StringTag extends Tag { + + /** + * Gets the value of {@link StringTag}. + * + * @return The value of {@link StringTag} + */ + String getValue(); +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/Tag.java b/src/main/java/org/spongepowered/api/util/nbt/Tag.java new file mode 100644 index 00000000000..e604d548b33 --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/Tag.java @@ -0,0 +1,83 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * Base for every NBT tag. + */ +public interface Tag extends Cloneable { + + /** + * Gets the {@link TagType} of {@link Tag}. + * + * @return The {@link TagType} of {@link Tag} + */ + TagType getType(); + + public static interface Primitive extends Tag { + + /** + * Returns the value of {@link Tag} as byte. + * + * @return The value of {@link Tag} as byte + */ + byte asByte(); + + /** + * Returns the value of {@link Tag} as short. + * + * @return The value of {@link Tag} as short + */ + short asShort(); + + /** + * Returns the value of {@link Tag} as int. + * + * @return The value of {@link Tag} as int + */ + int asInteger(); + + /** + * Returns the value of {@link Tag} as long. + * + * @return The value of {@link Tag} as long + */ + long asLong(); + + /** + * Returns the value of {@link Tag} as float. + * + * @return The value of {@link Tag} as float + */ + float asFloat(); + + /** + * Returns the value of {@link Tag} as double. + * + * @return The value of {@link Tag} as double + */ + double asDouble(); + } +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/TagFactory.java b/src/main/java/org/spongepowered/api/util/nbt/TagFactory.java new file mode 100644 index 00000000000..a5e57ac9f1f --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/TagFactory.java @@ -0,0 +1,109 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * Factory for {@link Tag}s. + */ +public interface TagFactory { + + /** + * Creates a new {@link ByteTag} with {@code value}. + * + * @param value + * @return The new {@link ByteTag} + */ + ByteTag newByte(byte value); + + /** + * Creates a new {@link ShortTag} with {@code value}. + * + * @param value + * @return The new {@link ShortTag} + */ + ShortTag newShort(byte value); + + /** + * Creates a new {@link IntTag} with {@code value}. + * + * @param value + * @return The new {@link IntTag} + */ + IntTag newInteger(int value); + + /** + * Creates a new {@link LongTag} with {@code value}. + * + * @param value + * @return The new {@link LongTag} + */ + LongTag newLong(long value); + + /** + * Creates a new {@link FloatTag} with {@code value}. + * + * @param value + * @return The new {@link FloatTag} + */ + FloatTag newFloat(float value); + + /** + * Creates a new {@link DoubleTag} with {@code value}. + * + * @param value + * @return The new {@link DoubleTag} + */ + DoubleTag newDouble(double value); + + /** + * Creates a new {@link ByteArrayTag} with {@code value}. + * + * @param value + * @return The new {@link ByteArrayTag} + */ + ByteArrayTag newByteArray(byte[] value); + + /** + * Creates a new {@link IntArrayTag} with {@code value}. + * + * @param value + * @return The new {@link IntArrayTag} + */ + IntArrayTag newIntArray(int[] value); + + /** + * Creates a new {@link ListTag}. + * + * @return A new {@link ListTag} + */ + ListTag newList(); + + /** + * Creates a new {@link CompoundTag}. + * + * @return A new {@link CompoundTag} + */ + CompoundTag newCompound(); +} diff --git a/src/main/java/org/spongepowered/api/util/nbt/TagType.java b/src/main/java/org/spongepowered/api/util/nbt/TagType.java new file mode 100644 index 00000000000..57a7e07a1cd --- /dev/null +++ b/src/main/java/org/spongepowered/api/util/nbt/TagType.java @@ -0,0 +1,45 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered.org + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.util.nbt; + +/** + * Enum for NBT tag types. + */ +public enum TagType { + + BYTE, + DOUBLE, + END, + FLOAT, + INT, + LONG, + SHORT, + STRING, + BYTEARRAY, + INTARRAY, + LIST, + COMPOUND, + PRIMITIVE +}