mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
"borrowing" some jnbt code
This commit is contained in:
parent
1c4100a612
commit
47d26531aa
@ -9,7 +9,7 @@
|
|||||||
<classpathentry kind="lib" path="C:/Users/Jesse Boyd/Desktop/plugins/bukkit-1.7.9-R0.3.jar"/>
|
<classpathentry kind="lib" path="C:/Users/Jesse Boyd/Desktop/plugins/bukkit-1.7.9-R0.3.jar"/>
|
||||||
<classpathentry kind="lib" path="C:/Users/Jesse Boyd/Desktop/plugins/Vault-1.4.1.jar"/>
|
<classpathentry kind="lib" path="C:/Users/Jesse Boyd/Desktop/plugins/Vault-1.4.1.jar"/>
|
||||||
<classpathentry kind="lib" path="C:/Users/Jesse Boyd/Desktop/plugins/worldguard-6.0.0-beta-02.jar"/>
|
<classpathentry kind="lib" path="C:/Users/Jesse Boyd/Desktop/plugins/worldguard-6.0.0-beta-02.jar"/>
|
||||||
<classpathentry kind="lib" path="C:/Users/Jesse Boyd/Desktop/plugins/WorldEdit.jar"/>
|
|
||||||
<classpathentry kind="lib" path="C:/Users/Jesse Boyd/Desktop/plugins/PlotMe.jar"/>
|
<classpathentry kind="lib" path="C:/Users/Jesse Boyd/Desktop/plugins/PlotMe.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Jesse Boyd/Desktop/plugins/WorldEdit.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -1,54 +1,46 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNBT License
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* All rights reserved.
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* this list of conditions and the following disclaimer.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>TAG_Byte_Array</code> tag.
|
* The {@code TAG_Byte_Array} tag.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class ByteArrayTag extends Tag {
|
public final class ByteArrayTag extends Tag {
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final byte[] value;
|
private final byte[] value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag with an empty name.
|
||||||
|
*
|
||||||
|
* @param value the value of the tag
|
||||||
|
*/
|
||||||
|
public ByteArrayTag(byte[] value) {
|
||||||
|
super();
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
* @param name The name.
|
*
|
||||||
* @param value The value.
|
* @param name the name of the tag
|
||||||
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public ByteArrayTag(String name, byte[] value) {
|
public ByteArrayTag(String name, byte[] value) {
|
||||||
super(name);
|
super(name);
|
||||||
@ -75,7 +67,7 @@ public final class ByteArrayTag extends Tag {
|
|||||||
if (name != null && !name.equals("")) {
|
if (name != null && !name.equals("")) {
|
||||||
append = "(\"" + this.getName() + "\")";
|
append = "(\"" + this.getName() + "\")";
|
||||||
}
|
}
|
||||||
return "TAG_Byte_Array" + append + ": " + hex.toString();
|
return "TAG_Byte_Array" + append + ": " + hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,54 +1,46 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNBT License
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* All rights reserved.
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* this list of conditions and the following disclaimer.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>TAG_Byte</code> tag.
|
* The {@code TAG_Byte} tag.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class ByteTag extends Tag {
|
public final class ByteTag extends Tag {
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final byte value;
|
private final byte value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag with an empty name.
|
||||||
|
*
|
||||||
|
* @param value the value of the tag
|
||||||
|
*/
|
||||||
|
public ByteTag(byte value) {
|
||||||
|
super();
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
* @param name The name.
|
*
|
||||||
* @param value The value.
|
* @param name the name of the tag
|
||||||
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public ByteTag(String name, byte value) {
|
public ByteTag(String name, byte value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -1,68 +1,422 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNBT License
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* All rights reserved.
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* this list of conditions and the following disclaimer.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>TAG_Compound</code> tag.
|
* The {@code TAG_Compound} tag.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class CompoundTag extends Tag {
|
public final class CompoundTag extends Tag {
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final Map<String, Tag> value;
|
private final Map<String, Tag> value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag with an empty name.
|
||||||
|
*
|
||||||
|
* @param value the value of the tag
|
||||||
|
*/
|
||||||
|
public CompoundTag(Map<String, Tag> value) {
|
||||||
|
super();
|
||||||
|
this.value = Collections.unmodifiableMap(value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
* @param name The name.
|
*
|
||||||
* @param value The value.
|
* @param name the name of the tag
|
||||||
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public CompoundTag(String name, Map<String, Tag> value) {
|
public CompoundTag(String name, Map<String, Tag> value) {
|
||||||
super(name);
|
super(name);
|
||||||
this.value = Collections.unmodifiableMap(value);
|
this.value = Collections.unmodifiableMap(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this compound tag contains the given key.
|
||||||
|
*
|
||||||
|
* @param key the given key
|
||||||
|
* @return true if the tag contains the given key
|
||||||
|
*/
|
||||||
|
public boolean containsKey(String key) {
|
||||||
|
return value.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Tag> getValue() {
|
public Map<String, Tag> getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a new compound tag with the given values.
|
||||||
|
*
|
||||||
|
* @param value the value
|
||||||
|
* @return the new compound tag
|
||||||
|
*/
|
||||||
|
public CompoundTag setValue(Map<String, Tag> value) {
|
||||||
|
return new CompoundTag(getName(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a compound tag builder.
|
||||||
|
*
|
||||||
|
* @return the builder
|
||||||
|
*/
|
||||||
|
public CompoundTagBuilder createBuilder() {
|
||||||
|
return new CompoundTagBuilder(new HashMap<String, Tag>(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a byte array named with the given key.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not a byte array tag,
|
||||||
|
* then an empty byte array will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return a byte array
|
||||||
|
*/
|
||||||
|
public byte[] getByteArray(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof ByteArrayTag) {
|
||||||
|
return ((ByteArrayTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a byte named with the given key.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not a byte tag,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return a byte
|
||||||
|
*/
|
||||||
|
public byte getByte(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof ByteTag) {
|
||||||
|
return ((ByteTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return (byte) 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a double named with the given key.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not a double tag,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return a double
|
||||||
|
*/
|
||||||
|
public double getDouble(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof DoubleTag) {
|
||||||
|
return ((DoubleTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a double named with the given key, even if it's another
|
||||||
|
* type of number.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not a number,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return a double
|
||||||
|
*/
|
||||||
|
public double asDouble(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof ByteTag) {
|
||||||
|
return ((ByteTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof ShortTag) {
|
||||||
|
return ((ShortTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof IntTag) {
|
||||||
|
return ((IntTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof LongTag) {
|
||||||
|
return ((LongTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof FloatTag) {
|
||||||
|
return ((FloatTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof DoubleTag) {
|
||||||
|
return ((DoubleTag) tag).getValue();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a float named with the given key.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not a float tag,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return a float
|
||||||
|
*/
|
||||||
|
public float getFloat(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof FloatTag) {
|
||||||
|
return ((FloatTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a {@code int[]} named with the given key.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not an int array tag,
|
||||||
|
* then an empty array will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return an int array
|
||||||
|
*/
|
||||||
|
public int[] getIntArray(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof IntArrayTag) {
|
||||||
|
return ((IntArrayTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return new int[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an int named with the given key.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not an int tag,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return an int
|
||||||
|
*/
|
||||||
|
public int getInt(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof IntTag) {
|
||||||
|
return ((IntTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an int named with the given key, even if it's another
|
||||||
|
* type of number.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not a number,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return an int
|
||||||
|
*/
|
||||||
|
public int asInt(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof ByteTag) {
|
||||||
|
return ((ByteTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof ShortTag) {
|
||||||
|
return ((ShortTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof IntTag) {
|
||||||
|
return ((IntTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof LongTag) {
|
||||||
|
return ((LongTag) tag).getValue().intValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof FloatTag) {
|
||||||
|
return ((FloatTag) tag).getValue().intValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof DoubleTag) {
|
||||||
|
return ((DoubleTag) tag).getValue().intValue();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of tags named with the given key.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not a list tag,
|
||||||
|
* then an empty list will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return a list of tags
|
||||||
|
*/
|
||||||
|
public List<Tag> getList(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof ListTag) {
|
||||||
|
return ((ListTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a {@code TagList} named with the given key.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not a list tag,
|
||||||
|
* then an empty tag list will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return a tag list instance
|
||||||
|
*/
|
||||||
|
public ListTag getListTag(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof ListTag) {
|
||||||
|
return (ListTag) tag;
|
||||||
|
} else {
|
||||||
|
return new ListTag(key, StringTag.class, Collections.<Tag>emptyList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of tags named with the given key.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not a list tag,
|
||||||
|
* then an empty list will be returned. If the given key references
|
||||||
|
* a list but the list of of a different type, then an empty
|
||||||
|
* list will also be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param listType the class of the contained type
|
||||||
|
* @return a list of tags
|
||||||
|
* @param <T> the type of list
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T extends Tag> List<T> getList(String key, Class<T> listType) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof ListTag) {
|
||||||
|
ListTag listTag = (ListTag) tag;
|
||||||
|
if (listTag.getType().equals(listType)) {
|
||||||
|
return (List<T>) listTag.getValue();
|
||||||
|
} else {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a long named with the given key.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not a long tag,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return a long
|
||||||
|
*/
|
||||||
|
public long getLong(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof LongTag) {
|
||||||
|
return ((LongTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a long named with the given key, even if it's another
|
||||||
|
* type of number.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not a number,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return a long
|
||||||
|
*/
|
||||||
|
public long asLong(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof ByteTag) {
|
||||||
|
return ((ByteTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof ShortTag) {
|
||||||
|
return ((ShortTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof IntTag) {
|
||||||
|
return ((IntTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof LongTag) {
|
||||||
|
return ((LongTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof FloatTag) {
|
||||||
|
return ((FloatTag) tag).getValue().longValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof DoubleTag) {
|
||||||
|
return ((DoubleTag) tag).getValue().longValue();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a short named with the given key.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not a short tag,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return a short
|
||||||
|
*/
|
||||||
|
public short getShort(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof ShortTag) {
|
||||||
|
return ((ShortTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a string named with the given key.
|
||||||
|
*
|
||||||
|
* <p>If the key does not exist or its value is not a string tag,
|
||||||
|
* then {@code ""} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return a string
|
||||||
|
*/
|
||||||
|
public String getString(String key) {
|
||||||
|
Tag tag = value.get(key);
|
||||||
|
if (tag instanceof StringTag) {
|
||||||
|
return ((StringTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String name = getName();
|
String name = getName();
|
||||||
@ -71,9 +425,9 @@ public final class CompoundTag extends Tag {
|
|||||||
append = "(\"" + this.getName() + "\")";
|
append = "(\"" + this.getName() + "\")";
|
||||||
}
|
}
|
||||||
StringBuilder bldr = new StringBuilder();
|
StringBuilder bldr = new StringBuilder();
|
||||||
bldr.append("TAG_Compound" + append + ": " + value.size() + " entries\r\n{\r\n");
|
bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n");
|
||||||
for (Map.Entry<String, Tag> entry : value.entrySet()) {
|
for (Map.Entry<String, Tag> entry : value.entrySet()) {
|
||||||
bldr.append(" " + entry.getValue().toString().replaceAll("\r\n", "\r\n ") + "\r\n");
|
bldr.append(" ").append(entry.getValue().toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
|
||||||
}
|
}
|
||||||
bldr.append("}");
|
bldr.append("}");
|
||||||
return bldr.toString();
|
return bldr.toString();
|
||||||
|
@ -0,0 +1,214 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helps create compound tags.
|
||||||
|
*/
|
||||||
|
public class CompoundTagBuilder {
|
||||||
|
|
||||||
|
private final Map<String, Tag> entries;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance.
|
||||||
|
*/
|
||||||
|
CompoundTagBuilder() {
|
||||||
|
this.entries = new HashMap<String, Tag>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance and use the given map (which will be modified).
|
||||||
|
*
|
||||||
|
* @param value the value
|
||||||
|
*/
|
||||||
|
CompoundTagBuilder(Map<String, Tag> value) {
|
||||||
|
checkNotNull(value);
|
||||||
|
this.entries = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given key and tag into the compound tag.
|
||||||
|
*
|
||||||
|
* @param key they key
|
||||||
|
* @param value the value
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public CompoundTagBuilder put(String key, Tag value) {
|
||||||
|
checkNotNull(key);
|
||||||
|
checkNotNull(value);
|
||||||
|
entries.put(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given key and value into the compound tag as a
|
||||||
|
* {@code ByteArrayTag}.
|
||||||
|
*
|
||||||
|
* @param key they key
|
||||||
|
* @param value the value
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public CompoundTagBuilder putByteArray(String key, byte[] value) {
|
||||||
|
return put(key, new ByteArrayTag(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given key and value into the compound tag as a
|
||||||
|
* {@code ByteTag}.
|
||||||
|
*
|
||||||
|
* @param key they key
|
||||||
|
* @param value the value
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public CompoundTagBuilder putByte(String key, byte value) {
|
||||||
|
return put(key, new ByteTag(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given key and value into the compound tag as a
|
||||||
|
* {@code DoubleTag}.
|
||||||
|
*
|
||||||
|
* @param key they key
|
||||||
|
* @param value the value
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public CompoundTagBuilder putDouble(String key, double value) {
|
||||||
|
return put(key, new DoubleTag(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given key and value into the compound tag as a
|
||||||
|
* {@code FloatTag}.
|
||||||
|
*
|
||||||
|
* @param key they key
|
||||||
|
* @param value the value
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public CompoundTagBuilder putFloat(String key, float value) {
|
||||||
|
return put(key, new FloatTag(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given key and value into the compound tag as a
|
||||||
|
* {@code IntArrayTag}.
|
||||||
|
*
|
||||||
|
* @param key they key
|
||||||
|
* @param value the value
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public CompoundTagBuilder putIntArray(String key, int[] value) {
|
||||||
|
return put(key, new IntArrayTag(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given key and value into the compound tag as an {@code IntTag}.
|
||||||
|
*
|
||||||
|
* @param key they key
|
||||||
|
* @param value the value
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public CompoundTagBuilder putInt(String key, int value) {
|
||||||
|
return put(key, new IntTag(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given key and value into the compound tag as a
|
||||||
|
* {@code LongTag}.
|
||||||
|
*
|
||||||
|
* @param key they key
|
||||||
|
* @param value the value
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public CompoundTagBuilder putLong(String key, long value) {
|
||||||
|
return put(key, new LongTag(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given key and value into the compound tag as a
|
||||||
|
* {@code ShortTag}.
|
||||||
|
*
|
||||||
|
* @param key they key
|
||||||
|
* @param value the value
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public CompoundTagBuilder putShort(String key, short value) {
|
||||||
|
return put(key, new ShortTag(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given key and value into the compound tag as a
|
||||||
|
* {@code StringTag}.
|
||||||
|
*
|
||||||
|
* @param key they key
|
||||||
|
* @param value the value
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public CompoundTagBuilder putString(String key, String value) {
|
||||||
|
return put(key, new StringTag(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put all the entries from the given map into this map.
|
||||||
|
*
|
||||||
|
* @param value the map of tags
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public CompoundTagBuilder putAll(Map<String, ? extends Tag> value) {
|
||||||
|
checkNotNull(value);
|
||||||
|
for (Map.Entry<String, ? extends Tag> entry : value.entrySet()) {
|
||||||
|
put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build an unnamed compound tag with this builder's entries.
|
||||||
|
*
|
||||||
|
* @return the new compound tag
|
||||||
|
*/
|
||||||
|
public CompoundTag build() {
|
||||||
|
return new CompoundTag(new HashMap<String, Tag>(entries));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a new compound tag with this builder's entries.
|
||||||
|
*
|
||||||
|
* @param name the name of the tag
|
||||||
|
* @return the created compound tag
|
||||||
|
*/
|
||||||
|
public CompoundTag build(String name) {
|
||||||
|
return new CompoundTag(name, new HashMap<String, Tag>(entries));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new builder instance.
|
||||||
|
*
|
||||||
|
* @return a new builder
|
||||||
|
*/
|
||||||
|
public static CompoundTagBuilder create() {
|
||||||
|
return new CompoundTagBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,54 +1,47 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNBT License
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* All rights reserved.
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* this list of conditions and the following disclaimer.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>TAG_Double</code> tag.
|
* The {@code TAG_Double} tag.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class DoubleTag extends Tag {
|
public final class DoubleTag extends Tag {
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final double value;
|
private final double value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag with an empty name.
|
||||||
|
*
|
||||||
|
* @param value the value of the tag
|
||||||
|
*/
|
||||||
|
public DoubleTag(double value) {
|
||||||
|
super();
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
* @param name The name.
|
*
|
||||||
* @param value The value.
|
* @param name the name of the tag
|
||||||
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public DoubleTag(String name, double value) {
|
public DoubleTag(String name, double value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -1,42 +1,26 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNBT License
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* All rights reserved.
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* this list of conditions and the following disclaimer.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>TAG_End</code> tag.
|
* The {@code TAG_End} tag.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class EndTag extends Tag {
|
public final class EndTag extends Tag {
|
||||||
|
|
||||||
@ -44,7 +28,7 @@ public final class EndTag extends Tag {
|
|||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*/
|
*/
|
||||||
public EndTag() {
|
public EndTag() {
|
||||||
super("");
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,54 +1,46 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNBT License
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* All rights reserved.
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* this list of conditions and the following disclaimer.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>TAG_Float</code> tag.
|
* The {@code TAG_Float} tag.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class FloatTag extends Tag {
|
public final class FloatTag extends Tag {
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final float value;
|
private final float value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag with an empty name.
|
||||||
|
*
|
||||||
|
* @param value the value of the tag
|
||||||
|
*/
|
||||||
|
public FloatTag(float value) {
|
||||||
|
super();
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
* @param name The name.
|
*
|
||||||
* @param value The value.
|
* @param name the name of the tag
|
||||||
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public FloatTag(String name, float value) {
|
public FloatTag(String name, float value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@code TAG_Int_Array} tag.
|
||||||
|
*/
|
||||||
|
public final class IntArrayTag extends Tag {
|
||||||
|
|
||||||
|
private final int[] value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag with an empty name.
|
||||||
|
*
|
||||||
|
* @param value the value of the tag
|
||||||
|
*/
|
||||||
|
public IntArrayTag(int[] value) {
|
||||||
|
super();
|
||||||
|
checkNotNull(value);
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag.
|
||||||
|
*
|
||||||
|
* @param name the name of the tag
|
||||||
|
* @param value the value of the tag
|
||||||
|
*/
|
||||||
|
public IntArrayTag(String name, int[] value) {
|
||||||
|
super(name);
|
||||||
|
checkNotNull(value);
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder hex = new StringBuilder();
|
||||||
|
for (int b : value) {
|
||||||
|
String hexDigits = Integer.toHexString(b).toUpperCase();
|
||||||
|
if (hexDigits.length() == 1) {
|
||||||
|
hex.append("0");
|
||||||
|
}
|
||||||
|
hex.append(hexDigits).append(" ");
|
||||||
|
}
|
||||||
|
String name = getName();
|
||||||
|
String append = "";
|
||||||
|
if (name != null && !name.equals("")) {
|
||||||
|
append = "(\"" + this.getName() + "\")";
|
||||||
|
}
|
||||||
|
return "TAG_Int_Array" + append + ": " + hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,54 +1,46 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNBT License
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* All rights reserved.
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* this list of conditions and the following disclaimer.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>TAG_Int</code> tag.
|
* The {@code TAG_Int} tag.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class IntTag extends Tag {
|
public final class IntTag extends Tag {
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final int value;
|
private final int value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag with an empty name.
|
||||||
|
*
|
||||||
|
* @param value the value of the tag
|
||||||
|
*/
|
||||||
|
public IntTag(int value) {
|
||||||
|
super();
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
* @param name The name.
|
*
|
||||||
* @param value The value.
|
* @param name the name of the tag
|
||||||
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public IntTag(String name, int value) {
|
public IntTag(String name, int value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -1,72 +1,69 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNBT License
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* All rights reserved.
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* this list of conditions and the following disclaimer.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>TAG_List</code> tag.
|
* The {@code TAG_List} tag.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class ListTag extends Tag {
|
public final class ListTag extends Tag {
|
||||||
|
|
||||||
/**
|
|
||||||
* The type.
|
|
||||||
*/
|
|
||||||
private final Class<? extends Tag> type;
|
private final Class<? extends Tag> type;
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final List<Tag> value;
|
private final List<Tag> value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag with an empty name.
|
||||||
* @param name The name.
|
*
|
||||||
* @param type The type of item in the list.
|
* @param type the type of tag
|
||||||
* @param value The value.
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public ListTag(String name, Class<? extends Tag> type, List<Tag> value) {
|
public ListTag(Class<? extends Tag> type, List<? extends Tag> value) {
|
||||||
|
super();
|
||||||
|
checkNotNull(value);
|
||||||
|
this.type = type;
|
||||||
|
this.value = Collections.unmodifiableList(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag.
|
||||||
|
*
|
||||||
|
* @param name the name of the tag
|
||||||
|
* @param type the type of tag
|
||||||
|
* @param value the value of the tag
|
||||||
|
*/
|
||||||
|
public ListTag(String name, Class<? extends Tag> type, List<? extends Tag> value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
checkNotNull(value);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.value = Collections.unmodifiableList(value);
|
this.value = Collections.unmodifiableList(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the type of item in this list.
|
* Gets the type of item in this list.
|
||||||
|
*
|
||||||
* @return The type of item in this list.
|
* @return The type of item in this list.
|
||||||
*/
|
*/
|
||||||
public Class<? extends Tag> getType() {
|
public Class<? extends Tag> getType() {
|
||||||
@ -78,6 +75,362 @@ public final class ListTag extends Tag {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new list tag with this tag's name and type.
|
||||||
|
*
|
||||||
|
* @param list the new list
|
||||||
|
* @return a new list tag
|
||||||
|
*/
|
||||||
|
public ListTag setValue(List<Tag> list) {
|
||||||
|
return new ListTag(getName(), getType(), list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tag if it exists at the given index.
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return the tag or null
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Tag getIfExists(int index) {
|
||||||
|
try {
|
||||||
|
return value.get(index);
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a byte array named with the given index.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not a byte array tag,
|
||||||
|
* then an empty byte array will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return a byte array
|
||||||
|
*/
|
||||||
|
public byte[] getByteArray(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof ByteArrayTag) {
|
||||||
|
return ((ByteArrayTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a byte named with the given index.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not a byte tag,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return a byte
|
||||||
|
*/
|
||||||
|
public byte getByte(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof ByteTag) {
|
||||||
|
return ((ByteTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return (byte) 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a double named with the given index.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not a double tag,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return a double
|
||||||
|
*/
|
||||||
|
public double getDouble(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof DoubleTag) {
|
||||||
|
return ((DoubleTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a double named with the given index, even if it's another
|
||||||
|
* type of number.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not a number,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return a double
|
||||||
|
*/
|
||||||
|
public double asDouble(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof ByteTag) {
|
||||||
|
return ((ByteTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof ShortTag) {
|
||||||
|
return ((ShortTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof IntTag) {
|
||||||
|
return ((IntTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof LongTag) {
|
||||||
|
return ((LongTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof FloatTag) {
|
||||||
|
return ((FloatTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof DoubleTag) {
|
||||||
|
return ((DoubleTag) tag).getValue();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a float named with the given index.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not a float tag,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return a float
|
||||||
|
*/
|
||||||
|
public float getFloat(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof FloatTag) {
|
||||||
|
return ((FloatTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a {@code int[]} named with the given index.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not an int array tag,
|
||||||
|
* then an empty array will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return an int array
|
||||||
|
*/
|
||||||
|
public int[] getIntArray(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof IntArrayTag) {
|
||||||
|
return ((IntArrayTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return new int[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an int named with the given index.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not an int tag,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return an int
|
||||||
|
*/
|
||||||
|
public int getInt(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof IntTag) {
|
||||||
|
return ((IntTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an int named with the given index, even if it's another
|
||||||
|
* type of number.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not a number,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return an int
|
||||||
|
*/
|
||||||
|
public int asInt(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof ByteTag) {
|
||||||
|
return ((ByteTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof ShortTag) {
|
||||||
|
return ((ShortTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof IntTag) {
|
||||||
|
return ((IntTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof LongTag) {
|
||||||
|
return ((LongTag) tag).getValue().intValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof FloatTag) {
|
||||||
|
return ((FloatTag) tag).getValue().intValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof DoubleTag) {
|
||||||
|
return ((DoubleTag) tag).getValue().intValue();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of tags named with the given index.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not a list tag,
|
||||||
|
* then an empty list will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return a list of tags
|
||||||
|
*/
|
||||||
|
public List<Tag> getList(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof ListTag) {
|
||||||
|
return ((ListTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a {@code TagList} named with the given index.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not a list tag,
|
||||||
|
* then an empty tag list will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return a tag list instance
|
||||||
|
*/
|
||||||
|
public ListTag getListTag(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof ListTag) {
|
||||||
|
return (ListTag) tag;
|
||||||
|
} else {
|
||||||
|
return new ListTag(StringTag.class, Collections.<Tag>emptyList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of tags named with the given index.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not a list tag,
|
||||||
|
* then an empty list will be returned. If the given index references
|
||||||
|
* a list but the list of of a different type, then an empty
|
||||||
|
* list will also be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @param listType the class of the contained type
|
||||||
|
* @return a list of tags
|
||||||
|
* @param <T> the NBT type
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T extends Tag> List<T> getList(int index, Class<T> listType) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof ListTag) {
|
||||||
|
ListTag listTag = (ListTag) tag;
|
||||||
|
if (listTag.getType().equals(listType)) {
|
||||||
|
return (List<T>) listTag.getValue();
|
||||||
|
} else {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a long named with the given index.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not a long tag,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return a long
|
||||||
|
*/
|
||||||
|
public long getLong(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof LongTag) {
|
||||||
|
return ((LongTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a long named with the given index, even if it's another
|
||||||
|
* type of number.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not a number,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return a long
|
||||||
|
*/
|
||||||
|
public long asLong(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof ByteTag) {
|
||||||
|
return ((ByteTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof ShortTag) {
|
||||||
|
return ((ShortTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof IntTag) {
|
||||||
|
return ((IntTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof LongTag) {
|
||||||
|
return ((LongTag) tag).getValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof FloatTag) {
|
||||||
|
return ((FloatTag) tag).getValue().longValue();
|
||||||
|
|
||||||
|
} else if (tag instanceof DoubleTag) {
|
||||||
|
return ((DoubleTag) tag).getValue().longValue();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a short named with the given index.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not a short tag,
|
||||||
|
* then {@code 0} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return a short
|
||||||
|
*/
|
||||||
|
public short getShort(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof ShortTag) {
|
||||||
|
return ((ShortTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a string named with the given index.
|
||||||
|
*
|
||||||
|
* <p>If the index does not exist or its value is not a string tag,
|
||||||
|
* then {@code ""} will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param index the index
|
||||||
|
* @return a string
|
||||||
|
*/
|
||||||
|
public String getString(int index) {
|
||||||
|
Tag tag = getIfExists(index);
|
||||||
|
if (tag instanceof StringTag) {
|
||||||
|
return ((StringTag) tag).getValue();
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String name = getName();
|
String name = getName();
|
||||||
@ -86,9 +439,9 @@ public final class ListTag extends Tag {
|
|||||||
append = "(\"" + this.getName() + "\")";
|
append = "(\"" + this.getName() + "\")";
|
||||||
}
|
}
|
||||||
StringBuilder bldr = new StringBuilder();
|
StringBuilder bldr = new StringBuilder();
|
||||||
bldr.append("TAG_List" + append + ": " + value.size() + " entries of type " + NBTUtils.getTypeName(type) + "\r\n{\r\n");
|
bldr.append("TAG_List").append(append).append(": ").append(value.size()).append(" entries of type ").append(NBTUtils.getTypeName(type)).append("\r\n{\r\n");
|
||||||
for (Tag t : value) {
|
for (Tag t : value) {
|
||||||
bldr.append(" " + t.toString().replaceAll("\r\n", "\r\n ") + "\r\n");
|
bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
|
||||||
}
|
}
|
||||||
bldr.append("}");
|
bldr.append("}");
|
||||||
return bldr.toString();
|
return bldr.toString();
|
||||||
|
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helps create list tags.
|
||||||
|
*/
|
||||||
|
public class ListTagBuilder {
|
||||||
|
|
||||||
|
private final Class<? extends Tag> type;
|
||||||
|
private final List<Tag> entries;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance.
|
||||||
|
*
|
||||||
|
* @param type of tag contained in this list
|
||||||
|
*/
|
||||||
|
ListTagBuilder(Class<? extends Tag> type) {
|
||||||
|
checkNotNull(type);
|
||||||
|
this.type = type;
|
||||||
|
this.entries = new ArrayList<Tag>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the given tag.
|
||||||
|
*
|
||||||
|
* @param value the tag
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public ListTagBuilder add(Tag value) {
|
||||||
|
checkNotNull(value);
|
||||||
|
if (!type.isInstance(value)) {
|
||||||
|
throw new IllegalArgumentException(value.getClass().getCanonicalName() + " is not of expected type " + type.getCanonicalName());
|
||||||
|
}
|
||||||
|
entries.add(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add all the tags in the given list.
|
||||||
|
*
|
||||||
|
* @param value a list of tags
|
||||||
|
* @return this object
|
||||||
|
*/
|
||||||
|
public ListTagBuilder addAll(Collection<? extends Tag> value) {
|
||||||
|
checkNotNull(value);
|
||||||
|
for (Tag v : value) {
|
||||||
|
add(v);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build an unnamed list tag with this builder's entries.
|
||||||
|
*
|
||||||
|
* @return the new list tag
|
||||||
|
*/
|
||||||
|
public ListTag build() {
|
||||||
|
return new ListTag(type, new ArrayList<Tag>(entries));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a new list tag with this builder's entries.
|
||||||
|
*
|
||||||
|
* @param name the name of the tag
|
||||||
|
* @return the created list tag
|
||||||
|
*/
|
||||||
|
public ListTag build(String name) {
|
||||||
|
return new ListTag(name, type, new ArrayList<Tag>(entries));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new builder instance.
|
||||||
|
*
|
||||||
|
* @return a new builder
|
||||||
|
*/
|
||||||
|
public static ListTagBuilder create(Class<? extends Tag> type) {
|
||||||
|
return new ListTagBuilder(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new builder instance.
|
||||||
|
*
|
||||||
|
* @return a new builder
|
||||||
|
*/
|
||||||
|
public static <T extends Tag> ListTagBuilder createWith(T ... entries) {
|
||||||
|
checkNotNull(entries);
|
||||||
|
|
||||||
|
if (entries.length == 0) {
|
||||||
|
throw new IllegalArgumentException("This method needs an array of at least one entry");
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<? extends Tag> type = entries[0].getClass();
|
||||||
|
for (int i = 1; i < entries.length; i++) {
|
||||||
|
if (!type.isInstance(entries[i])) {
|
||||||
|
throw new IllegalArgumentException("An array of different tag types was provided");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ListTagBuilder builder = new ListTagBuilder(type);
|
||||||
|
builder.addAll(Arrays.asList(entries));
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,54 +1,47 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNBT License
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* All rights reserved.
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* this list of conditions and the following disclaimer.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>TAG_Long</code> tag.
|
* The {@code TAG_Long} tag.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class LongTag extends Tag {
|
public final class LongTag extends Tag {
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final long value;
|
private final long value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag with an empty name.
|
||||||
|
*
|
||||||
|
* @param value the value of the tag
|
||||||
|
*/
|
||||||
|
public LongTag(long value) {
|
||||||
|
super();
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
* @param name The name.
|
*
|
||||||
* @param value The value.
|
* @param name the name of the tag
|
||||||
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public LongTag(String name, long value) {
|
public LongTag(String name, long value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -1,66 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package com.intellectualcrafters.jnbt;
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
/*
|
|
||||||
* JNBT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class which holds constant values.
|
* A class which holds constant values.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class NBTConstants {
|
public final class NBTConstants {
|
||||||
|
|
||||||
/**
|
|
||||||
* The character set used by NBT (UTF-8).
|
|
||||||
*/
|
|
||||||
public static final Charset CHARSET = Charset.forName("UTF-8");
|
public static final Charset CHARSET = Charset.forName("UTF-8");
|
||||||
|
|
||||||
/**
|
public static final int TYPE_END = 0, TYPE_BYTE = 1, TYPE_SHORT = 2,
|
||||||
* Tag type constants.
|
TYPE_INT = 3, TYPE_LONG = 4, TYPE_FLOAT = 5, TYPE_DOUBLE = 6,
|
||||||
*/
|
TYPE_BYTE_ARRAY = 7, TYPE_STRING = 8, TYPE_LIST = 9,
|
||||||
public static final int TYPE_END = 0,
|
TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11;
|
||||||
TYPE_BYTE = 1,
|
|
||||||
TYPE_SHORT = 2,
|
|
||||||
TYPE_INT = 3,
|
|
||||||
TYPE_LONG = 4,
|
|
||||||
TYPE_FLOAT = 5,
|
|
||||||
TYPE_DOUBLE = 6,
|
|
||||||
TYPE_BYTE_ARRAY = 7,
|
|
||||||
TYPE_STRING = 8,
|
|
||||||
TYPE_LIST = 9,
|
|
||||||
TYPE_COMPOUND = 10;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default private constructor.
|
* Default private constructor.
|
||||||
@ -69,4 +40,42 @@ public final class NBTConstants {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a type ID to its corresponding {@link Tag} class.
|
||||||
|
*
|
||||||
|
* @param id type ID
|
||||||
|
* @return tag class
|
||||||
|
* @throws IllegalArgumentException thrown if the tag ID is not valid
|
||||||
|
*/
|
||||||
|
public static Class<? extends Tag> getClassFromType(int id) {
|
||||||
|
switch (id) {
|
||||||
|
case TYPE_END:
|
||||||
|
return EndTag.class;
|
||||||
|
case TYPE_BYTE:
|
||||||
|
return ByteTag.class;
|
||||||
|
case TYPE_SHORT:
|
||||||
|
return ShortTag.class;
|
||||||
|
case TYPE_INT:
|
||||||
|
return IntTag.class;
|
||||||
|
case TYPE_LONG:
|
||||||
|
return LongTag.class;
|
||||||
|
case TYPE_FLOAT:
|
||||||
|
return FloatTag.class;
|
||||||
|
case TYPE_DOUBLE:
|
||||||
|
return DoubleTag.class;
|
||||||
|
case TYPE_BYTE_ARRAY:
|
||||||
|
return ByteArrayTag.class;
|
||||||
|
case TYPE_STRING:
|
||||||
|
return StringTag.class;
|
||||||
|
case TYPE_LIST:
|
||||||
|
return ListTag.class;
|
||||||
|
case TYPE_COMPOUND:
|
||||||
|
return CompoundTag.class;
|
||||||
|
case TYPE_INT_ARRAY:
|
||||||
|
return IntArrayTag.class;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unknown tag type ID of " + id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,38 +1,24 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNBT License
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* All rights reserved.
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* this list of conditions and the following disclaimer.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -41,38 +27,34 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>This class reads <strong>NBT</strong>, or
|
* This class reads <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
||||||
* <strong>Named Binary Tag</strong> streams, and produces an object graph of
|
* streams, and produces an object graph of subclasses of the {@code Tag}
|
||||||
* subclasses of the <code>Tag</code> object.</p>
|
* object.
|
||||||
*
|
*
|
||||||
* <p>The NBT format was created by Markus Persson, and the specification may
|
* <p>The NBT format was created by Markus Persson, and the specification may be
|
||||||
* be found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
||||||
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class NBTInputStream implements Closeable {
|
public final class NBTInputStream implements Closeable {
|
||||||
|
|
||||||
/**
|
|
||||||
* The data input stream.
|
|
||||||
*/
|
|
||||||
private final DataInputStream is;
|
private final DataInputStream is;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <code>NBTInputStream</code>, which will source its data
|
* Creates a new {@code NBTInputStream}, which will source its data
|
||||||
* from the specified input stream.
|
* from the specified input stream.
|
||||||
* @param is The input stream.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param is the input stream
|
||||||
|
* @throws IOException if an I/O error occurs
|
||||||
*/
|
*/
|
||||||
public NBTInputStream(InputStream is) throws IOException {
|
public NBTInputStream(InputStream is) throws IOException {
|
||||||
this.is = new DataInputStream(new GZIPInputStream(is));
|
this.is = new DataInputStream(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads an NBT tag from the stream.
|
* Reads an NBT tag from the stream.
|
||||||
|
*
|
||||||
* @return The tag that was read.
|
* @return The tag that was read.
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
@ -82,7 +64,8 @@ public final class NBTInputStream implements Closeable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads an NBT from the stream.
|
* Reads an NBT from the stream.
|
||||||
* @param depth The depth of this tag.
|
*
|
||||||
|
* @param depth the depth of this tag
|
||||||
* @return The tag that was read.
|
* @return The tag that was read.
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
@ -104,17 +87,19 @@ public final class NBTInputStream implements Closeable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the payload of a tag, given the name and type.
|
* Reads the payload of a tag, given the name and type.
|
||||||
* @param type The type.
|
*
|
||||||
* @param name The name.
|
* @param type the type
|
||||||
* @param depth The depth.
|
* @param name the name
|
||||||
* @return The tag.
|
* @param depth the depth
|
||||||
|
* @return the tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private Tag readTagPayload(int type, String name, int depth) throws IOException {
|
private Tag readTagPayload(int type, String name, int depth) throws IOException {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case NBTConstants.TYPE_END:
|
case NBTConstants.TYPE_END:
|
||||||
if (depth == 0) {
|
if (depth == 0) {
|
||||||
throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
|
throw new IOException(
|
||||||
|
"TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
|
||||||
} else {
|
} else {
|
||||||
return new EndTag();
|
return new EndTag();
|
||||||
}
|
}
|
||||||
@ -145,7 +130,7 @@ public final class NBTInputStream implements Closeable {
|
|||||||
length = is.readInt();
|
length = is.readInt();
|
||||||
|
|
||||||
List<Tag> tagList = new ArrayList<Tag>();
|
List<Tag> tagList = new ArrayList<Tag>();
|
||||||
for(int i = 0; i < length; i++) {
|
for (int i = 0; i < length; ++i) {
|
||||||
Tag tag = readTagPayload(childType, "", depth + 1);
|
Tag tag = readTagPayload(childType, "", depth + 1);
|
||||||
if (tag instanceof EndTag) {
|
if (tag instanceof EndTag) {
|
||||||
throw new IOException("TAG_End not permitted in a list.");
|
throw new IOException("TAG_End not permitted in a list.");
|
||||||
@ -166,6 +151,13 @@ public final class NBTInputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new CompoundTag(name, tagMap);
|
return new CompoundTag(name, tagMap);
|
||||||
|
case NBTConstants.TYPE_INT_ARRAY:
|
||||||
|
length = is.readInt();
|
||||||
|
int[] data = new int[length];
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
data[i] = is.readInt();
|
||||||
|
}
|
||||||
|
return new IntArrayTag(name, data);
|
||||||
default:
|
default:
|
||||||
throw new IOException("Invalid tag type: " + type + ".");
|
throw new IOException("Invalid tag type: " + type + ".");
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package com.intellectualcrafters.jnbt;
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
@ -5,51 +24,14 @@ import java.io.DataOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* JNBT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>This class writes <strong>NBT</strong>, or
|
* This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
||||||
* <strong>Named Binary Tag</strong> <code>Tag</code> objects to an underlying
|
* {@code Tag} objects to an underlying {@code OutputStream}.
|
||||||
* <code>OutputStream</code>.</p>
|
|
||||||
*
|
*
|
||||||
* <p>The NBT format was created by Markus Persson, and the specification may
|
* <p>The NBT format was created by Markus Persson, and the specification may be
|
||||||
* be found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
||||||
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class NBTOutputStream implements Closeable {
|
public final class NBTOutputStream implements Closeable {
|
||||||
|
|
||||||
@ -59,19 +41,25 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
private final DataOutputStream os;
|
private final DataOutputStream os;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <code>NBTOutputStream</code>, which will write data to the
|
* Creates a new {@code NBTOutputStream}, which will write data to the
|
||||||
* specified underlying output stream.
|
* specified underlying output stream.
|
||||||
* @param os The output stream.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param os
|
||||||
|
* The output stream.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public NBTOutputStream(OutputStream os) throws IOException {
|
public NBTOutputStream(OutputStream os) throws IOException {
|
||||||
this.os = new DataOutputStream(new GZIPOutputStream(os));
|
this.os = new DataOutputStream(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a tag.
|
* Writes a tag.
|
||||||
* @param tag The tag to write.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param tag
|
||||||
|
* The tag to write.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public void writeTag(Tag tag) throws IOException {
|
public void writeTag(Tag tag) throws IOException {
|
||||||
int type = NBTUtils.getTypeCode(tag.getClass());
|
int type = NBTUtils.getTypeCode(tag.getClass());
|
||||||
@ -91,8 +79,11 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes tag payload.
|
* Writes tag payload.
|
||||||
* @param tag The tag.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param tag
|
||||||
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeTagPayload(Tag tag) throws IOException {
|
private void writeTagPayload(Tag tag) throws IOException {
|
||||||
int type = NBTUtils.getTypeCode(tag.getClass());
|
int type = NBTUtils.getTypeCode(tag.getClass());
|
||||||
@ -130,24 +121,33 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
case NBTConstants.TYPE_COMPOUND:
|
case NBTConstants.TYPE_COMPOUND:
|
||||||
writeCompoundTagPayload((CompoundTag) tag);
|
writeCompoundTagPayload((CompoundTag) tag);
|
||||||
break;
|
break;
|
||||||
|
case NBTConstants.TYPE_INT_ARRAY:
|
||||||
|
writeIntArrayTagPayload((IntArrayTag) tag);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IOException("Invalid tag type: " + type + ".");
|
throw new IOException("Invalid tag type: " + type + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Byte</code> tag.
|
* Writes a {@code TAG_Byte} tag.
|
||||||
* @param tag The tag.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param tag
|
||||||
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeByteTagPayload(ByteTag tag) throws IOException {
|
private void writeByteTagPayload(ByteTag tag) throws IOException {
|
||||||
os.writeByte(tag.getValue());
|
os.writeByte(tag.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Byte_Array</code> tag.
|
* Writes a {@code TAG_Byte_Array} tag.
|
||||||
* @param tag The tag.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param tag
|
||||||
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeByteArrayTagPayload(ByteArrayTag tag) throws IOException {
|
private void writeByteArrayTagPayload(ByteArrayTag tag) throws IOException {
|
||||||
byte[] bytes = tag.getValue();
|
byte[] bytes = tag.getValue();
|
||||||
@ -156,9 +156,12 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Compound</code> tag.
|
* Writes a {@code TAG_Compound} tag.
|
||||||
* @param tag The tag.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param tag
|
||||||
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeCompoundTagPayload(CompoundTag tag) throws IOException {
|
private void writeCompoundTagPayload(CompoundTag tag) throws IOException {
|
||||||
for (Tag childTag : tag.getValue().values()) {
|
for (Tag childTag : tag.getValue().values()) {
|
||||||
@ -168,9 +171,12 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_List</code> tag.
|
* Writes a {@code TAG_List} tag.
|
||||||
* @param tag The tag.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param tag
|
||||||
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeListTagPayload(ListTag tag) throws IOException {
|
private void writeListTagPayload(ListTag tag) throws IOException {
|
||||||
Class<? extends Tag> clazz = tag.getType();
|
Class<? extends Tag> clazz = tag.getType();
|
||||||
@ -179,15 +185,18 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
|
|
||||||
os.writeByte(NBTUtils.getTypeCode(clazz));
|
os.writeByte(NBTUtils.getTypeCode(clazz));
|
||||||
os.writeInt(size);
|
os.writeInt(size);
|
||||||
for(int i = 0; i < size; i++) {
|
for (Tag tag1 : tags) {
|
||||||
writeTagPayload(tags.get(i));
|
writeTagPayload(tag1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_String</code> tag.
|
* Writes a {@code TAG_String} tag.
|
||||||
* @param tag The tag.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param tag
|
||||||
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeStringTagPayload(StringTag tag) throws IOException {
|
private void writeStringTagPayload(StringTag tag) throws IOException {
|
||||||
byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
|
byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
|
||||||
@ -196,59 +205,82 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Double</code> tag.
|
* Writes a {@code TAG_Double} tag.
|
||||||
* @param tag The tag.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param tag
|
||||||
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeDoubleTagPayload(DoubleTag tag) throws IOException {
|
private void writeDoubleTagPayload(DoubleTag tag) throws IOException {
|
||||||
os.writeDouble(tag.getValue());
|
os.writeDouble(tag.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Float</code> tag.
|
* Writes a {@code TAG_Float} tag.
|
||||||
* @param tag The tag.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param tag
|
||||||
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeFloatTagPayload(FloatTag tag) throws IOException {
|
private void writeFloatTagPayload(FloatTag tag) throws IOException {
|
||||||
os.writeFloat(tag.getValue());
|
os.writeFloat(tag.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Long</code> tag.
|
* Writes a {@code TAG_Long} tag.
|
||||||
* @param tag The tag.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param tag
|
||||||
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeLongTagPayload(LongTag tag) throws IOException {
|
private void writeLongTagPayload(LongTag tag) throws IOException {
|
||||||
os.writeLong(tag.getValue());
|
os.writeLong(tag.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Int</code> tag.
|
* Writes a {@code TAG_Int} tag.
|
||||||
* @param tag The tag.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param tag
|
||||||
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeIntTagPayload(IntTag tag) throws IOException {
|
private void writeIntTagPayload(IntTag tag) throws IOException {
|
||||||
os.writeInt(tag.getValue());
|
os.writeInt(tag.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Short</code> tag.
|
* Writes a {@code TAG_Short} tag.
|
||||||
* @param tag The tag.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param tag
|
||||||
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeShortTagPayload(ShortTag tag) throws IOException {
|
private void writeShortTagPayload(ShortTag tag) throws IOException {
|
||||||
os.writeShort(tag.getValue());
|
os.writeShort(tag.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Empty</code> tag.
|
* Writes a {@code TAG_Empty} tag.
|
||||||
* @param tag The tag.
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @param tag the tag
|
||||||
*/
|
*/
|
||||||
private void writeEndTagPayload(EndTag tag) {
|
private void writeEndTagPayload(EndTag tag) {
|
||||||
/* empty */
|
/* empty */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException {
|
||||||
|
int[] data = tag.getValue();
|
||||||
|
os.writeInt(data.length);
|
||||||
|
for (int aData : data) {
|
||||||
|
os.writeInt(aData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
os.close();
|
os.close();
|
||||||
|
@ -1,48 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package com.intellectualcrafters.jnbt;
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
/*
|
import java.util.Map;
|
||||||
* JNBT License
|
|
||||||
*
|
import com.sun.media.sound.InvalidFormatException;
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
|
||||||
* All rights reserved.
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class which contains NBT-related utility methods.
|
* A class which contains NBT-related utility methods.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class NBTUtils {
|
public final class NBTUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default private constructor.
|
||||||
|
*/
|
||||||
|
private NBTUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the type name of a tag.
|
* Gets the type name of a tag.
|
||||||
* @param clazz The tag class.
|
*
|
||||||
|
* @param clazz the tag class
|
||||||
* @return The type name.
|
* @return The type name.
|
||||||
*/
|
*/
|
||||||
public static String getTypeName(Class<? extends Tag> clazz) {
|
public static String getTypeName(Class<? extends Tag> clazz) {
|
||||||
@ -68,14 +66,18 @@ public final class NBTUtils {
|
|||||||
return "TAG_Short";
|
return "TAG_Short";
|
||||||
} else if (clazz.equals(StringTag.class)) {
|
} else if (clazz.equals(StringTag.class)) {
|
||||||
return "TAG_String";
|
return "TAG_String";
|
||||||
|
} else if (clazz.equals(IntArrayTag.class)) {
|
||||||
|
return "TAG_Int_Array";
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
throw new IllegalArgumentException("Invalid tag classs ("
|
||||||
|
+ clazz.getName() + ").");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the type code of a tag class.
|
* Gets the type code of a tag class.
|
||||||
* @param clazz The tag class.
|
*
|
||||||
|
* @param clazz the tag class
|
||||||
* @return The type code.
|
* @return The type code.
|
||||||
* @throws IllegalArgumentException if the tag class is invalid.
|
* @throws IllegalArgumentException if the tag class is invalid.
|
||||||
*/
|
*/
|
||||||
@ -102,14 +104,18 @@ public final class NBTUtils {
|
|||||||
return NBTConstants.TYPE_SHORT;
|
return NBTConstants.TYPE_SHORT;
|
||||||
} else if (clazz.equals(StringTag.class)) {
|
} else if (clazz.equals(StringTag.class)) {
|
||||||
return NBTConstants.TYPE_STRING;
|
return NBTConstants.TYPE_STRING;
|
||||||
|
} else if (clazz.equals(IntArrayTag.class)) {
|
||||||
|
return NBTConstants.TYPE_INT_ARRAY;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
throw new IllegalArgumentException("Invalid tag classs ("
|
||||||
|
+ clazz.getName() + ").");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the class of a type of tag.
|
* Gets the class of a type of tag.
|
||||||
* @param type The type.
|
*
|
||||||
|
* @param type the type
|
||||||
* @return The class.
|
* @return The class.
|
||||||
* @throws IllegalArgumentException if the tag type is invalid.
|
* @throws IllegalArgumentException if the tag type is invalid.
|
||||||
*/
|
*/
|
||||||
@ -137,16 +143,32 @@ public final class NBTUtils {
|
|||||||
return ListTag.class;
|
return ListTag.class;
|
||||||
case NBTConstants.TYPE_COMPOUND:
|
case NBTConstants.TYPE_COMPOUND:
|
||||||
return CompoundTag.class;
|
return CompoundTag.class;
|
||||||
|
case NBTConstants.TYPE_INT_ARRAY:
|
||||||
|
return IntArrayTag.class;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Invalid tag type : " + type + ".");
|
throw new IllegalArgumentException("Invalid tag type : " + type
|
||||||
|
+ ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default private constructor.
|
* Get child tag of a NBT structure.
|
||||||
|
*
|
||||||
|
* @param items the map to read from
|
||||||
|
* @param key the key to look for
|
||||||
|
* @param expected the expected NBT class type
|
||||||
|
* @return child tag
|
||||||
|
* @throws InvalidFormatException
|
||||||
*/
|
*/
|
||||||
private NBTUtils() {
|
public static <T extends Tag> T getChildTag(Map<String, Tag> items, String key, Class<T> expected) throws InvalidFormatException {
|
||||||
|
if (!items.containsKey(key)) {
|
||||||
|
throw new InvalidFormatException("Missing a \"" + key + "\" tag");
|
||||||
|
}
|
||||||
|
Tag tag = items.get(key);
|
||||||
|
if (!expected.isInstance(tag)) {
|
||||||
|
throw new InvalidFormatException(key + " tag is not of tag type " + expected.getName());
|
||||||
|
}
|
||||||
|
return expected.cast(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,54 +1,46 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNBT License
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* All rights reserved.
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* this list of conditions and the following disclaimer.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>TAG_Short</code> tag.
|
* The {@code TAG_Short} tag.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class ShortTag extends Tag {
|
public final class ShortTag extends Tag {
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final short value;
|
private final short value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag with an empty name.
|
||||||
|
*
|
||||||
|
* @param value the value of the tag
|
||||||
|
*/
|
||||||
|
public ShortTag(short value) {
|
||||||
|
super();
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
* @param name The name.
|
*
|
||||||
* @param value The value.
|
* @param name the name of the tag
|
||||||
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public ShortTag(String name, short value) {
|
public ShortTag(String name, short value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -1,57 +1,53 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNBT License
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* All rights reserved.
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* this list of conditions and the following disclaimer.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>TAG_String</code> tag.
|
* The {@code TAG_String} tag.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class StringTag extends Tag {
|
public final class StringTag extends Tag {
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag with an empty name.
|
||||||
|
*
|
||||||
|
* @param value the value of the tag
|
||||||
|
*/
|
||||||
|
public StringTag(String value) {
|
||||||
|
super();
|
||||||
|
checkNotNull(value);
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
* @param name The name.
|
*
|
||||||
* @param value The value.
|
* @param name the name of the tag
|
||||||
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public StringTag(String name, String value) {
|
public StringTag(String name, String value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
checkNotNull(value);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,61 +1,54 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNBT License
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010 Graham Edgecombe
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* All rights reserved.
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* this list of conditions and the following disclaimer.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the JNBT team nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a single NBT tag.
|
* Represents a NBT tag.
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class Tag {
|
public abstract class Tag {
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of this tag.
|
|
||||||
*/
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag with the specified name.
|
* Create a new tag with an empty name.
|
||||||
* @param name The name.
|
|
||||||
*/
|
*/
|
||||||
public Tag(String name) {
|
Tag() {
|
||||||
|
this("");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag with the specified name.
|
||||||
|
*
|
||||||
|
* @param name the name
|
||||||
|
*/
|
||||||
|
Tag(String name) {
|
||||||
|
if (name == null) {
|
||||||
|
name = "";
|
||||||
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of this tag.
|
* Gets the name of this tag.
|
||||||
* @return The name of this tag.
|
*
|
||||||
|
* @return the name of this tag
|
||||||
*/
|
*/
|
||||||
public final String getName() {
|
public final String getName() {
|
||||||
return name;
|
return name;
|
||||||
@ -63,7 +56,8 @@ public abstract class Tag {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of this tag.
|
* Gets the value of this tag.
|
||||||
* @return The value of this tag.
|
*
|
||||||
|
* @return the value
|
||||||
*/
|
*/
|
||||||
public abstract Object getValue();
|
public abstract Object getValue();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user