mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
Merge branch 'master' of git://github.com/drtshock/PlotSquared
Conflicts: PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java
This commit is contained in:
commit
7feddad853
@ -10,8 +10,7 @@ public final class ByteArrayTag extends Tag {
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public ByteArrayTag(final byte[] value) {
|
||||
super();
|
||||
@ -21,10 +20,8 @@ public final class ByteArrayTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param name the name of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public ByteArrayTag(final String name, final byte[] value) {
|
||||
super(name);
|
||||
|
@ -10,8 +10,7 @@ public final class ByteTag extends Tag {
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public ByteTag(final byte value) {
|
||||
super();
|
||||
@ -21,10 +20,8 @@ public final class ByteTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param name the name of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public ByteTag(final String name, final byte value) {
|
||||
super(name);
|
||||
|
@ -15,8 +15,7 @@ public final class CompoundTag extends Tag {
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public CompoundTag(final Map<String, Tag> value) {
|
||||
super();
|
||||
@ -26,10 +25,8 @@ public final class CompoundTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param name the name of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public CompoundTag(final String name, final Map<String, Tag> value) {
|
||||
super(name);
|
||||
@ -39,8 +36,8 @@ public final class CompoundTag extends Tag {
|
||||
/**
|
||||
* Returns whether this compound tag contains the given key.
|
||||
*
|
||||
* @param key
|
||||
* the given key
|
||||
* @param key the given key
|
||||
*
|
||||
* @return true if the tag contains the given key
|
||||
*/
|
||||
public boolean containsKey(final String key) {
|
||||
@ -55,8 +52,8 @@ public final class CompoundTag extends Tag {
|
||||
/**
|
||||
* Return a new compound tag with the given values.
|
||||
*
|
||||
* @param value
|
||||
* the value
|
||||
* @param value the value
|
||||
*
|
||||
* @return the new compound tag
|
||||
*/
|
||||
public CompoundTag setValue(final Map<String, Tag> value) {
|
||||
@ -73,82 +70,62 @@ public final class CompoundTag extends Tag {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a byte array named with the given key.
|
||||
* <p/>
|
||||
* <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>
|
||||
* Get a byte array named with the given key. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return a byte array
|
||||
*/
|
||||
public byte[] getByteArray(final String key) {
|
||||
final Tag tag = this.value.get(key);
|
||||
if (tag instanceof ByteArrayTag) {
|
||||
return ((ByteArrayTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a byte named with the given key.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the key does not exist or its value is not a byte tag, then {@code 0}
|
||||
* will be returned.
|
||||
* </p>
|
||||
* Get a byte named with the given key. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return a byte
|
||||
*/
|
||||
public byte getByte(final String key) {
|
||||
final Tag tag = this.value.get(key);
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return (byte) 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a double named with the given key.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the key does not exist or its value is not a double tag, then
|
||||
* {@code 0} will be returned.
|
||||
* </p>
|
||||
* Get a double named with the given key. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return a double
|
||||
*/
|
||||
public double getDouble(final String key) {
|
||||
final Tag tag = this.value.get(key);
|
||||
if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a double named with the given key, even if it's another
|
||||
* type of number.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the key does not exist or its value is not a number, then {@code 0}
|
||||
* will be returned.
|
||||
* </p>
|
||||
* Get a double named with the given key, even if it's another type of number. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return a double
|
||||
*/
|
||||
public double asDouble(final String key) {
|
||||
@ -156,109 +133,83 @@ public final class CompoundTag extends Tag {
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof ShortTag) {
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof IntTag) {
|
||||
} else if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof LongTag) {
|
||||
} else if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof FloatTag) {
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof DoubleTag) {
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue();
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a float named with the given key.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the key does not exist or its value is not a float tag, then {@code 0}
|
||||
* will be returned.
|
||||
* </p>
|
||||
* Get a float named with the given key. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return a float
|
||||
*/
|
||||
public float getFloat(final String key) {
|
||||
final Tag tag = this.value.get(key);
|
||||
if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@code int[]} named with the given key.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the key does not exist or its value is not an int array tag, then an
|
||||
* empty array will be returned.
|
||||
* </p>
|
||||
* Get a {@code int[]} named with the given key. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return an int array
|
||||
*/
|
||||
public int[] getIntArray(final String key) {
|
||||
final Tag tag = this.value.get(key);
|
||||
if (tag instanceof IntArrayTag) {
|
||||
return ((IntArrayTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an int named with the given key.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the key does not exist or its value is not an int tag, then {@code 0}
|
||||
* will be returned.
|
||||
* </p>
|
||||
* Get an int named with the given key. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return an int
|
||||
*/
|
||||
public int getInt(final String key) {
|
||||
final Tag tag = this.value.get(key);
|
||||
if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an int named with the given key, even if it's another
|
||||
* type of number.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the key does not exist or its value is not a number, then {@code 0}
|
||||
* will be returned.
|
||||
* </p>
|
||||
* Get an int named with the given key, even if it's another type of number. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return an int
|
||||
*/
|
||||
public int asInt(final String key) {
|
||||
@ -266,91 +217,69 @@ public final class CompoundTag extends Tag {
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof ShortTag) {
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof IntTag) {
|
||||
} else if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof LongTag) {
|
||||
} else if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue().intValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof FloatTag) {
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue().intValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof DoubleTag) {
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue().intValue();
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tags named with the given key.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the key does not exist or its value is not a list tag, then an empty
|
||||
* list will be returned.
|
||||
* </p>
|
||||
* Get a list of tags named with the given key. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return a list of tags
|
||||
*/
|
||||
public List<Tag> getList(final String key) {
|
||||
final Tag tag = this.value.get(key);
|
||||
if (tag instanceof ListTag) {
|
||||
return ((ListTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@code TagList} named with the given key.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the key does not exist or its value is not a list tag, then an empty
|
||||
* tag list will be returned.
|
||||
* </p>
|
||||
* Get a {@code TagList} named with the given key. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return a tag list instance
|
||||
*/
|
||||
public ListTag getListTag(final String key) {
|
||||
final Tag tag = this.value.get(key);
|
||||
if (tag instanceof ListTag) {
|
||||
return (ListTag) tag;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return new ListTag(key, StringTag.class, Collections.<Tag>emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tags named with the given key.
|
||||
* <p/>
|
||||
* <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>
|
||||
* Get a list of tags named with the given key. <p/> <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
|
||||
* @param <T> the type of list
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param listType
|
||||
* the class of the contained type
|
||||
* @param <T>
|
||||
* the type of list
|
||||
* @return a list of tags
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -360,49 +289,37 @@ public final class CompoundTag extends Tag {
|
||||
final ListTag listTag = (ListTag) tag;
|
||||
if (listTag.getType().equals(listType)) {
|
||||
return (List<T>) listTag.getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a long named with the given key.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the key does not exist or its value is not a long tag, then {@code 0}
|
||||
* will be returned.
|
||||
* </p>
|
||||
* Get a long named with the given key. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return a long
|
||||
*/
|
||||
public long getLong(final String key) {
|
||||
final Tag tag = this.value.get(key);
|
||||
if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a long named with the given key, even if it's another
|
||||
* type of number.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the key does not exist or its value is not a number, then {@code 0}
|
||||
* will be returned.
|
||||
* </p>
|
||||
* Get a long named with the given key, even if it's another type of number. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return a long
|
||||
*/
|
||||
public long asLong(final String key) {
|
||||
@ -410,72 +327,56 @@ public final class CompoundTag extends Tag {
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof ShortTag) {
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof IntTag) {
|
||||
} else if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof LongTag) {
|
||||
} else if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof FloatTag) {
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue().longValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof DoubleTag) {
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue().longValue();
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short named with the given key.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the key does not exist or its value is not a short tag, then {@code 0}
|
||||
* will be returned.
|
||||
* </p>
|
||||
* Get a short named with the given key. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return a short
|
||||
*/
|
||||
public short getShort(final String key) {
|
||||
final Tag tag = this.value.get(key);
|
||||
if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string named with the given key.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the key does not exist or its value is not a string tag, then
|
||||
* {@code ""} will be returned.
|
||||
* </p>
|
||||
* Get a string named with the given key. <p/> <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
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return a string
|
||||
*/
|
||||
public String getString(final String key) {
|
||||
final Tag tag = this.value.get(key);
|
||||
if (tag instanceof StringTag) {
|
||||
return ((StringTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.intellectualcrafters.jnbt;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Helps create compound tags.
|
||||
*/
|
||||
@ -22,8 +22,7 @@ public class CompoundTagBuilder {
|
||||
/**
|
||||
* Create a new instance and use the given map (which will be modified).
|
||||
*
|
||||
* @param value
|
||||
* the value
|
||||
* @param value the value
|
||||
*/
|
||||
CompoundTagBuilder(final Map<String, Tag> value) {
|
||||
checkNotNull(value);
|
||||
@ -42,10 +41,9 @@ public class CompoundTagBuilder {
|
||||
/**
|
||||
* Put the given key and tag into the compound tag.
|
||||
*
|
||||
* @param key
|
||||
* they key
|
||||
* @param value
|
||||
* the value
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder put(final String key, final Tag value) {
|
||||
@ -56,13 +54,11 @@ public class CompoundTagBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a
|
||||
* {@code ByteArrayTag}.
|
||||
* Put the given key and value into the compound tag as a {@code ByteArrayTag}.
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @param key
|
||||
* they key
|
||||
* @param value
|
||||
* the value
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putByteArray(final String key, final byte[] value) {
|
||||
@ -72,10 +68,9 @@ public class CompoundTagBuilder {
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a {@code ByteTag}.
|
||||
*
|
||||
* @param key
|
||||
* they key
|
||||
* @param value
|
||||
* the value
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putByte(final String key, final byte value) {
|
||||
@ -85,10 +80,9 @@ public class CompoundTagBuilder {
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a {@code DoubleTag}.
|
||||
*
|
||||
* @param key
|
||||
* they key
|
||||
* @param value
|
||||
* the value
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putDouble(final String key, final double value) {
|
||||
@ -98,10 +92,9 @@ public class CompoundTagBuilder {
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a {@code FloatTag}.
|
||||
*
|
||||
* @param key
|
||||
* they key
|
||||
* @param value
|
||||
* the value
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putFloat(final String key, final float value) {
|
||||
@ -109,13 +102,11 @@ public class CompoundTagBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a
|
||||
* {@code IntArrayTag}.
|
||||
* Put the given key and value into the compound tag as a {@code IntArrayTag}.
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @param key
|
||||
* they key
|
||||
* @param value
|
||||
* the value
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putIntArray(final String key, final int[] value) {
|
||||
@ -125,10 +116,9 @@ public class CompoundTagBuilder {
|
||||
/**
|
||||
* Put the given key and value into the compound tag as an {@code IntTag}.
|
||||
*
|
||||
* @param key
|
||||
* they key
|
||||
* @param value
|
||||
* the value
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putInt(final String key, final int value) {
|
||||
@ -138,10 +128,9 @@ public class CompoundTagBuilder {
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a {@code LongTag}.
|
||||
*
|
||||
* @param key
|
||||
* they key
|
||||
* @param value
|
||||
* the value
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putLong(final String key, final long value) {
|
||||
@ -151,10 +140,9 @@ public class CompoundTagBuilder {
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a {@code ShortTag}.
|
||||
*
|
||||
* @param key
|
||||
* they key
|
||||
* @param value
|
||||
* the value
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putShort(final String key, final short value) {
|
||||
@ -164,10 +152,9 @@ public class CompoundTagBuilder {
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a {@code StringTag}.
|
||||
*
|
||||
* @param key
|
||||
* they key
|
||||
* @param value
|
||||
* the value
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putString(final String key, final String value) {
|
||||
@ -177,8 +164,8 @@ public class CompoundTagBuilder {
|
||||
/**
|
||||
* Put all the entries from the given map into this map.
|
||||
*
|
||||
* @param value
|
||||
* the map of tags
|
||||
* @param value the map of tags
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putAll(final Map<String, ? extends Tag> value) {
|
||||
@ -201,8 +188,8 @@ public class CompoundTagBuilder {
|
||||
/**
|
||||
* Build a new compound tag with this builder's entries.
|
||||
*
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @param name the name of the tag
|
||||
*
|
||||
* @return the created compound tag
|
||||
*/
|
||||
public CompoundTag build(final String name) {
|
||||
|
@ -10,8 +10,7 @@ public final class DoubleTag extends Tag {
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public DoubleTag(final double value) {
|
||||
super();
|
||||
@ -21,10 +20,8 @@ public final class DoubleTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param name the name of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public DoubleTag(final String name, final double value) {
|
||||
super(name);
|
||||
|
@ -10,8 +10,7 @@ public final class FloatTag extends Tag {
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public FloatTag(final float value) {
|
||||
super();
|
||||
@ -21,10 +20,8 @@ public final class FloatTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param name the name of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public FloatTag(final String name, final float value) {
|
||||
super(name);
|
||||
|
@ -12,8 +12,7 @@ public final class IntArrayTag extends Tag {
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public IntArrayTag(final int[] value) {
|
||||
super();
|
||||
@ -24,10 +23,8 @@ public final class IntArrayTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param name the name of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public IntArrayTag(final String name, final int[] value) {
|
||||
super(name);
|
||||
|
@ -10,8 +10,7 @@ public final class IntTag extends Tag {
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public IntTag(final int value) {
|
||||
super();
|
||||
@ -21,10 +20,8 @@ public final class IntTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param name the name of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public IntTag(final String name, final int value) {
|
||||
super(name);
|
||||
|
@ -1,12 +1,11 @@
|
||||
package com.intellectualcrafters.jnbt;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* The {@code TAG_List} tag.
|
||||
@ -19,10 +18,8 @@ public final class ListTag extends Tag {
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param type
|
||||
* the type of tag
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param type the type of tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public ListTag(final Class<? extends Tag> type, final List<? extends Tag> value) {
|
||||
super();
|
||||
@ -34,12 +31,9 @@ public final class ListTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @param type
|
||||
* the type of tag
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param name the name of the tag
|
||||
* @param type the type of tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public ListTag(final String name, final Class<? extends Tag> type, final List<? extends Tag> value) {
|
||||
super(name);
|
||||
@ -65,8 +59,8 @@ public final class ListTag extends Tag {
|
||||
/**
|
||||
* Create a new list tag with this tag's name and type.
|
||||
*
|
||||
* @param list
|
||||
* the new list
|
||||
* @param list the new list
|
||||
*
|
||||
* @return a new list tag
|
||||
*/
|
||||
public ListTag setValue(final List<Tag> list) {
|
||||
@ -76,97 +70,76 @@ public final class ListTag extends Tag {
|
||||
/**
|
||||
* Get the tag if it exists at the given index.
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @param index the index
|
||||
*
|
||||
* @return the tag or null
|
||||
*/
|
||||
@Nullable
|
||||
public Tag getIfExists(final int index) {
|
||||
try {
|
||||
return this.value.get(index);
|
||||
}
|
||||
catch (final NoSuchElementException e) {
|
||||
} catch (final NoSuchElementException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a byte array named with the given index.
|
||||
* <p/>
|
||||
* <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>
|
||||
* Get a byte array named with the given index. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return a byte array
|
||||
*/
|
||||
public byte[] getByteArray(final int index) {
|
||||
final Tag tag = getIfExists(index);
|
||||
if (tag instanceof ByteArrayTag) {
|
||||
return ((ByteArrayTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a byte named with the given index.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the index does not exist or its value is not a byte tag, then
|
||||
* {@code 0} will be returned.
|
||||
* </p>
|
||||
* Get a byte named with the given index. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return a byte
|
||||
*/
|
||||
public byte getByte(final int index) {
|
||||
final Tag tag = getIfExists(index);
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return (byte) 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a double named with the given index.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the index does not exist or its value is not a double tag, then
|
||||
* {@code 0} will be returned.
|
||||
* </p>
|
||||
* Get a double named with the given index. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return a double
|
||||
*/
|
||||
public double getDouble(final int index) {
|
||||
final Tag tag = getIfExists(index);
|
||||
if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a double named with the given index, even if it's another
|
||||
* type of number.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the index does not exist or its value is not a number, then {@code 0}
|
||||
* will be returned.
|
||||
* </p>
|
||||
* Get a double named with the given index, even if it's another type of number. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return a double
|
||||
*/
|
||||
public double asDouble(final int index) {
|
||||
@ -174,109 +147,83 @@ public final class ListTag extends Tag {
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof ShortTag) {
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof IntTag) {
|
||||
} else if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof LongTag) {
|
||||
} else if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof FloatTag) {
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof DoubleTag) {
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue();
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a float named with the given index.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the index does not exist or its value is not a float tag, then
|
||||
* {@code 0} will be returned.
|
||||
* </p>
|
||||
* Get a float named with the given index. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return a float
|
||||
*/
|
||||
public float getFloat(final int index) {
|
||||
final Tag tag = getIfExists(index);
|
||||
if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@code int[]} named with the given index.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the index does not exist or its value is not an int array tag, then an
|
||||
* empty array will be returned.
|
||||
* </p>
|
||||
* Get a {@code int[]} named with the given index. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return an int array
|
||||
*/
|
||||
public int[] getIntArray(final int index) {
|
||||
final Tag tag = getIfExists(index);
|
||||
if (tag instanceof IntArrayTag) {
|
||||
return ((IntArrayTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an int named with the given index.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the index does not exist or its value is not an int tag, then
|
||||
* {@code 0} will be returned.
|
||||
* </p>
|
||||
* Get an int named with the given index. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return an int
|
||||
*/
|
||||
public int getInt(final int index) {
|
||||
final Tag tag = getIfExists(index);
|
||||
if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an int named with the given index, even if it's another
|
||||
* type of number.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the index does not exist or its value is not a number, then {@code 0}
|
||||
* will be returned.
|
||||
* </p>
|
||||
* Get an int named with the given index, even if it's another type of number. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return an int
|
||||
*/
|
||||
public int asInt(final int index) {
|
||||
@ -284,91 +231,69 @@ public final class ListTag extends Tag {
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof ShortTag) {
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof IntTag) {
|
||||
} else if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof LongTag) {
|
||||
} else if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue().intValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof FloatTag) {
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue().intValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof DoubleTag) {
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue().intValue();
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tags named with the given index.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the index does not exist or its value is not a list tag, then an empty
|
||||
* list will be returned.
|
||||
* </p>
|
||||
* Get a list of tags named with the given index. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return a list of tags
|
||||
*/
|
||||
public List<Tag> getList(final int index) {
|
||||
final Tag tag = getIfExists(index);
|
||||
if (tag instanceof ListTag) {
|
||||
return ((ListTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@code TagList} named with the given index.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the index does not exist or its value is not a list tag, then an empty
|
||||
* tag list will be returned.
|
||||
* </p>
|
||||
* Get a {@code TagList} named with the given index. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return a tag list instance
|
||||
*/
|
||||
public ListTag getListTag(final int index) {
|
||||
final Tag tag = getIfExists(index);
|
||||
if (tag instanceof ListTag) {
|
||||
return (ListTag) tag;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return new ListTag(StringTag.class, Collections.<Tag>emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tags named with the given index.
|
||||
* <p/>
|
||||
* <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>
|
||||
* Get a list of tags named with the given index. <p/> <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
|
||||
* @param <T> the NBT type
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @param listType
|
||||
* the class of the contained type
|
||||
* @param <T>
|
||||
* the NBT type
|
||||
* @return a list of tags
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -378,49 +303,37 @@ public final class ListTag extends Tag {
|
||||
final ListTag listTag = (ListTag) tag;
|
||||
if (listTag.getType().equals(listType)) {
|
||||
return (List<T>) listTag.getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a long named with the given index.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the index does not exist or its value is not a long tag, then
|
||||
* {@code 0} will be returned.
|
||||
* </p>
|
||||
* Get a long named with the given index. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return a long
|
||||
*/
|
||||
public long getLong(final int index) {
|
||||
final Tag tag = getIfExists(index);
|
||||
if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a long named with the given index, even if it's another
|
||||
* type of number.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the index does not exist or its value is not a number, then {@code 0}
|
||||
* will be returned.
|
||||
* </p>
|
||||
* Get a long named with the given index, even if it's another type of number. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return a long
|
||||
*/
|
||||
public long asLong(final int index) {
|
||||
@ -428,72 +341,56 @@ public final class ListTag extends Tag {
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof ShortTag) {
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof IntTag) {
|
||||
} else if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof LongTag) {
|
||||
} else if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof FloatTag) {
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue().longValue();
|
||||
|
||||
}
|
||||
else if (tag instanceof DoubleTag) {
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue().longValue();
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short named with the given index.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the index does not exist or its value is not a short tag, then
|
||||
* {@code 0} will be returned.
|
||||
* </p>
|
||||
* Get a short named with the given index. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return a short
|
||||
*/
|
||||
public short getShort(final int index) {
|
||||
final Tag tag = getIfExists(index);
|
||||
if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string named with the given index.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If the index does not exist or its value is not a string tag, then
|
||||
* {@code ""} will be returned.
|
||||
* </p>
|
||||
* Get a string named with the given index. <p/> <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
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return a string
|
||||
*/
|
||||
public String getString(final int index) {
|
||||
final Tag tag = getIfExists(index);
|
||||
if (tag instanceof StringTag) {
|
||||
return ((StringTag) tag).getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.intellectualcrafters.jnbt;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
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.
|
||||
*/
|
||||
@ -18,8 +18,7 @@ public class ListTagBuilder {
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param type
|
||||
* of tag contained in this list
|
||||
* @param type of tag contained in this list
|
||||
*/
|
||||
ListTagBuilder(final Class<? extends Tag> type) {
|
||||
checkNotNull(type);
|
||||
@ -64,8 +63,8 @@ public class ListTagBuilder {
|
||||
/**
|
||||
* Add the given tag.
|
||||
*
|
||||
* @param value
|
||||
* the tag
|
||||
* @param value the tag
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public ListTagBuilder add(final Tag value) {
|
||||
@ -80,8 +79,8 @@ public class ListTagBuilder {
|
||||
/**
|
||||
* Add all the tags in the given list.
|
||||
*
|
||||
* @param value
|
||||
* a list of tags
|
||||
* @param value a list of tags
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public ListTagBuilder addAll(final Collection<? extends Tag> value) {
|
||||
@ -104,8 +103,8 @@ public class ListTagBuilder {
|
||||
/**
|
||||
* Build a new list tag with this builder's entries.
|
||||
*
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @param name the name of the tag
|
||||
*
|
||||
* @return the created list tag
|
||||
*/
|
||||
public ListTag build(final String name) {
|
||||
|
@ -10,8 +10,7 @@ public final class LongTag extends Tag {
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public LongTag(final long value) {
|
||||
super();
|
||||
@ -21,10 +20,8 @@ public final class LongTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param name the name of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public LongTag(final String name, final long value) {
|
||||
super(name);
|
||||
|
@ -42,11 +42,11 @@ public final class NBTConstants {
|
||||
/**
|
||||
* Convert a type ID to its corresponding {@link Tag} class.
|
||||
*
|
||||
* @param id
|
||||
* type ID
|
||||
* @param id type ID
|
||||
*
|
||||
* @return tag class
|
||||
* @throws IllegalArgumentException
|
||||
* thrown if the tag ID is not valid
|
||||
*
|
||||
* @throws IllegalArgumentException thrown if the tag ID is not valid
|
||||
*/
|
||||
public static Class<? extends Tag> getClassFromType(final int id) {
|
||||
switch (id) {
|
||||
|
@ -10,28 +10,20 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class reads <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
||||
* streams, and produces an object graph of subclasses of the {@code Tag}
|
||||
* object.
|
||||
* <p/>
|
||||
* <p>
|
||||
* The NBT format was created by Markus Persson, and the specification may be
|
||||
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
||||
* http://www.minecraft.net/docs/NBT.txt</a>.
|
||||
* </p>
|
||||
* This class reads <strong>NBT</strong>, or <strong>Named Binary Tag</strong> streams, and produces an object graph of
|
||||
* subclasses of the {@code Tag} object. <p/> <p> The NBT format was created by Markus Persson, and the specification
|
||||
* may be found at <a href="http://www.minecraft.net/docs/NBT.txt"> http://www.minecraft.net/docs/NBT.txt</a>. </p>
|
||||
*/
|
||||
public final class NBTInputStream implements Closeable {
|
||||
|
||||
private final DataInputStream is;
|
||||
|
||||
/**
|
||||
* Creates a new {@code NBTInputStream}, which will source its data
|
||||
* from the specified input stream.
|
||||
* Creates a new {@code NBTInputStream}, which will source its data 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(final InputStream is) throws IOException {
|
||||
this.is = new DataInputStream(is);
|
||||
@ -41,8 +33,8 @@ public final class NBTInputStream implements Closeable {
|
||||
* Reads an NBT tag from the stream.
|
||||
*
|
||||
* @return The tag that was read.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public Tag readTag() throws IOException {
|
||||
return readTag(0);
|
||||
@ -51,11 +43,11 @@ public final class NBTInputStream implements Closeable {
|
||||
/**
|
||||
* 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.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private Tag readTag(final int depth) throws IOException {
|
||||
final int type = this.is.readByte() & 0xFF;
|
||||
@ -66,8 +58,7 @@ public final class NBTInputStream implements Closeable {
|
||||
final byte[] nameBytes = new byte[nameLength];
|
||||
this.is.readFully(nameBytes);
|
||||
name = new String(nameBytes, NBTConstants.CHARSET);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
name = "";
|
||||
}
|
||||
|
||||
@ -77,23 +68,20 @@ public final class NBTInputStream implements Closeable {
|
||||
/**
|
||||
* Reads the payload of a tag, given the name and type.
|
||||
*
|
||||
* @param type
|
||||
* the type
|
||||
* @param name
|
||||
* the name
|
||||
* @param depth
|
||||
* the depth
|
||||
* @param type the type
|
||||
* @param name the name
|
||||
* @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(final int type, final String name, final int depth) throws IOException {
|
||||
switch (type) {
|
||||
case NBTConstants.TYPE_END:
|
||||
if (depth == 0) {
|
||||
throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return new EndTag();
|
||||
}
|
||||
case NBTConstants.TYPE_BYTE:
|
||||
@ -138,8 +126,7 @@ public final class NBTInputStream implements Closeable {
|
||||
final Tag tag = readTag(depth + 1);
|
||||
if (tag instanceof EndTag) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
tagMap.put(tag.getName(), tag);
|
||||
}
|
||||
}
|
||||
|
@ -28,15 +28,9 @@ import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
||||
* <code>Tag</code> objects to an underlying <code>OutputStream</code>.
|
||||
* </p>
|
||||
* <p/>
|
||||
* <p>
|
||||
* The NBT format was created by Markus Persson, and the specification may be
|
||||
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
||||
* http://www.minecraft.net/docs/NBT.txt</a>.
|
||||
* <p> This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong> <code>Tag</code> objects to an
|
||||
* underlying <code>OutputStream</code>. </p> <p/> <p> The NBT format was created by Markus Persson, and the
|
||||
* specification may be found at <a href="http://www.minecraft.net/docs/NBT.txt"> http://www.minecraft.net/docs/NBT.txt</a>.
|
||||
* </p>
|
||||
*
|
||||
* @author Graham Edgecombe
|
||||
@ -49,13 +43,11 @@ public final class NBTOutputStream implements Closeable {
|
||||
private final DataOutputStream os;
|
||||
|
||||
/**
|
||||
* Creates a new <code>NBTOutputStream</code>, which will write data to the
|
||||
* specified underlying output stream.
|
||||
* Creates a new <code>NBTOutputStream</code>, which will write data to the 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(final OutputStream os) throws IOException {
|
||||
this.os = new DataOutputStream(os);
|
||||
@ -64,10 +56,9 @@ public final class NBTOutputStream implements Closeable {
|
||||
/**
|
||||
* 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(final Tag tag) throws IOException {
|
||||
final int type = NBTUtils.getTypeCode(tag.getClass());
|
||||
@ -88,10 +79,9 @@ public final class NBTOutputStream implements Closeable {
|
||||
/**
|
||||
* 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(final Tag tag) throws IOException {
|
||||
final int type = NBTUtils.getTypeCode(tag.getClass());
|
||||
@ -140,10 +130,9 @@ public final class NBTOutputStream implements Closeable {
|
||||
/**
|
||||
* Writes a <code>TAG_Byte</code> 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(final ByteTag tag) throws IOException {
|
||||
this.os.writeByte(tag.getValue());
|
||||
@ -152,10 +141,9 @@ public final class NBTOutputStream implements Closeable {
|
||||
/**
|
||||
* Writes a <code>TAG_Byte_Array</code> 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(final ByteArrayTag tag) throws IOException {
|
||||
final byte[] bytes = tag.getValue();
|
||||
@ -166,10 +154,9 @@ public final class NBTOutputStream implements Closeable {
|
||||
/**
|
||||
* Writes a <code>TAG_Compound</code> 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(final CompoundTag tag) throws IOException {
|
||||
for (final Tag childTag : tag.getValue().values()) {
|
||||
@ -181,10 +168,9 @@ public final class NBTOutputStream implements Closeable {
|
||||
/**
|
||||
* Writes a <code>TAG_List</code> 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(final ListTag tag) throws IOException {
|
||||
final Class<? extends Tag> clazz = tag.getType();
|
||||
@ -201,10 +187,9 @@ public final class NBTOutputStream implements Closeable {
|
||||
/**
|
||||
* Writes a <code>TAG_String</code> 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(final StringTag tag) throws IOException {
|
||||
final byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
|
||||
@ -215,10 +200,9 @@ public final class NBTOutputStream implements Closeable {
|
||||
/**
|
||||
* Writes a <code>TAG_Double</code> 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(final DoubleTag tag) throws IOException {
|
||||
this.os.writeDouble(tag.getValue());
|
||||
@ -227,10 +211,9 @@ public final class NBTOutputStream implements Closeable {
|
||||
/**
|
||||
* Writes a <code>TAG_Float</code> 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(final FloatTag tag) throws IOException {
|
||||
this.os.writeFloat(tag.getValue());
|
||||
@ -239,10 +222,9 @@ public final class NBTOutputStream implements Closeable {
|
||||
/**
|
||||
* Writes a <code>TAG_Long</code> 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(final LongTag tag) throws IOException {
|
||||
this.os.writeLong(tag.getValue());
|
||||
@ -251,10 +233,9 @@ public final class NBTOutputStream implements Closeable {
|
||||
/**
|
||||
* Writes a <code>TAG_Int</code> 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(final IntTag tag) throws IOException {
|
||||
this.os.writeInt(tag.getValue());
|
||||
@ -263,10 +244,9 @@ public final class NBTOutputStream implements Closeable {
|
||||
/**
|
||||
* Writes a <code>TAG_Short</code> 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(final ShortTag tag) throws IOException {
|
||||
this.os.writeShort(tag.getValue());
|
||||
@ -275,10 +255,9 @@ public final class NBTOutputStream implements Closeable {
|
||||
/**
|
||||
* Writes a <code>TAG_Empty</code> 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 writeEndTagPayload(final EndTag tag) {
|
||||
/* empty */
|
||||
|
@ -16,48 +16,36 @@ public final class NBTUtils {
|
||||
/**
|
||||
* Gets the type name of a tag.
|
||||
*
|
||||
* @param clazz
|
||||
* the tag class
|
||||
* @param clazz the tag class
|
||||
*
|
||||
* @return The type name.
|
||||
*/
|
||||
public static String getTypeName(final Class<? extends Tag> clazz) {
|
||||
if (clazz.equals(ByteArrayTag.class)) {
|
||||
return "TAG_Byte_Array";
|
||||
}
|
||||
else if (clazz.equals(ByteTag.class)) {
|
||||
} else if (clazz.equals(ByteTag.class)) {
|
||||
return "TAG_Byte";
|
||||
}
|
||||
else if (clazz.equals(CompoundTag.class)) {
|
||||
} else if (clazz.equals(CompoundTag.class)) {
|
||||
return "TAG_Compound";
|
||||
}
|
||||
else if (clazz.equals(DoubleTag.class)) {
|
||||
} else if (clazz.equals(DoubleTag.class)) {
|
||||
return "TAG_Double";
|
||||
}
|
||||
else if (clazz.equals(EndTag.class)) {
|
||||
} else if (clazz.equals(EndTag.class)) {
|
||||
return "TAG_End";
|
||||
}
|
||||
else if (clazz.equals(FloatTag.class)) {
|
||||
} else if (clazz.equals(FloatTag.class)) {
|
||||
return "TAG_Float";
|
||||
}
|
||||
else if (clazz.equals(IntTag.class)) {
|
||||
} else if (clazz.equals(IntTag.class)) {
|
||||
return "TAG_Int";
|
||||
}
|
||||
else if (clazz.equals(ListTag.class)) {
|
||||
} else if (clazz.equals(ListTag.class)) {
|
||||
return "TAG_List";
|
||||
}
|
||||
else if (clazz.equals(LongTag.class)) {
|
||||
} else if (clazz.equals(LongTag.class)) {
|
||||
return "TAG_Long";
|
||||
}
|
||||
else if (clazz.equals(ShortTag.class)) {
|
||||
} else if (clazz.equals(ShortTag.class)) {
|
||||
return "TAG_Short";
|
||||
}
|
||||
else if (clazz.equals(StringTag.class)) {
|
||||
} else if (clazz.equals(StringTag.class)) {
|
||||
return "TAG_String";
|
||||
}
|
||||
else if (clazz.equals(IntArrayTag.class)) {
|
||||
} else if (clazz.equals(IntArrayTag.class)) {
|
||||
return "TAG_Int_Array";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
||||
}
|
||||
}
|
||||
@ -65,50 +53,38 @@ public final class NBTUtils {
|
||||
/**
|
||||
* Gets the type code of a tag class.
|
||||
*
|
||||
* @param clazz
|
||||
* the tag class
|
||||
* @param clazz the tag class
|
||||
*
|
||||
* @return The type code.
|
||||
* @throws IllegalArgumentException
|
||||
* if the tag class is invalid.
|
||||
*
|
||||
* @throws IllegalArgumentException if the tag class is invalid.
|
||||
*/
|
||||
public static int getTypeCode(final Class<? extends Tag> clazz) {
|
||||
if (clazz.equals(ByteArrayTag.class)) {
|
||||
return NBTConstants.TYPE_BYTE_ARRAY;
|
||||
}
|
||||
else if (clazz.equals(ByteTag.class)) {
|
||||
} else if (clazz.equals(ByteTag.class)) {
|
||||
return NBTConstants.TYPE_BYTE;
|
||||
}
|
||||
else if (clazz.equals(CompoundTag.class)) {
|
||||
} else if (clazz.equals(CompoundTag.class)) {
|
||||
return NBTConstants.TYPE_COMPOUND;
|
||||
}
|
||||
else if (clazz.equals(DoubleTag.class)) {
|
||||
} else if (clazz.equals(DoubleTag.class)) {
|
||||
return NBTConstants.TYPE_DOUBLE;
|
||||
}
|
||||
else if (clazz.equals(EndTag.class)) {
|
||||
} else if (clazz.equals(EndTag.class)) {
|
||||
return NBTConstants.TYPE_END;
|
||||
}
|
||||
else if (clazz.equals(FloatTag.class)) {
|
||||
} else if (clazz.equals(FloatTag.class)) {
|
||||
return NBTConstants.TYPE_FLOAT;
|
||||
}
|
||||
else if (clazz.equals(IntTag.class)) {
|
||||
} else if (clazz.equals(IntTag.class)) {
|
||||
return NBTConstants.TYPE_INT;
|
||||
}
|
||||
else if (clazz.equals(ListTag.class)) {
|
||||
} else if (clazz.equals(ListTag.class)) {
|
||||
return NBTConstants.TYPE_LIST;
|
||||
}
|
||||
else if (clazz.equals(LongTag.class)) {
|
||||
} else if (clazz.equals(LongTag.class)) {
|
||||
return NBTConstants.TYPE_LONG;
|
||||
}
|
||||
else if (clazz.equals(ShortTag.class)) {
|
||||
} else if (clazz.equals(ShortTag.class)) {
|
||||
return NBTConstants.TYPE_SHORT;
|
||||
}
|
||||
else if (clazz.equals(StringTag.class)) {
|
||||
} else if (clazz.equals(StringTag.class)) {
|
||||
return NBTConstants.TYPE_STRING;
|
||||
}
|
||||
else if (clazz.equals(IntArrayTag.class)) {
|
||||
} else if (clazz.equals(IntArrayTag.class)) {
|
||||
return NBTConstants.TYPE_INT_ARRAY;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
||||
}
|
||||
}
|
||||
@ -116,11 +92,11 @@ public final class NBTUtils {
|
||||
/**
|
||||
* Gets the class of a type of tag.
|
||||
*
|
||||
* @param type
|
||||
* the type
|
||||
* @param type the type
|
||||
*
|
||||
* @return The class.
|
||||
* @throws IllegalArgumentException
|
||||
* if the tag type is invalid.
|
||||
*
|
||||
* @throws IllegalArgumentException if the tag type is invalid.
|
||||
*/
|
||||
public static Class<? extends Tag> getTypeClass(final int type) {
|
||||
switch (type) {
|
||||
@ -156,12 +132,10 @@ public final class NBTUtils {
|
||||
/**
|
||||
* 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
|
||||
* @param items the map to read from
|
||||
* @param key the key to look for
|
||||
* @param expected the expected NBT class type
|
||||
*
|
||||
* @return child tag
|
||||
*/
|
||||
public static <T extends Tag> T getChildTag(final Map<String, Tag> items, final String key, final Class<T> expected) throws IllegalArgumentException {
|
||||
|
@ -31,8 +31,7 @@ public final class ShortTag extends Tag {
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public ShortTag(final short value) {
|
||||
super();
|
||||
@ -42,10 +41,8 @@ public final class ShortTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param name the name of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public ShortTag(final String name, final short value) {
|
||||
super(name);
|
||||
|
@ -12,8 +12,7 @@ public final class StringTag extends Tag {
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public StringTag(final String value) {
|
||||
super();
|
||||
@ -24,10 +23,8 @@ public final class StringTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @param value
|
||||
* the value of the tag
|
||||
* @param name the name of the tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public StringTag(final String name, final String value) {
|
||||
super(name);
|
||||
|
@ -38,8 +38,7 @@ public abstract class Tag {
|
||||
/**
|
||||
* Creates the tag with the specified name.
|
||||
*
|
||||
* @param name
|
||||
* the name
|
||||
* @param name the name
|
||||
*/
|
||||
Tag(String name) {
|
||||
if (name == null) {
|
||||
|
@ -1,21 +1,18 @@
|
||||
package com.intellectualcrafters.json;
|
||||
|
||||
/**
|
||||
* This provides static methods to convert comma delimited text into a
|
||||
* JSONArray, and to covert a JSONArray into comma delimited text. Comma
|
||||
* delimited text is a very popular format for data interchange. It is
|
||||
* understood by most database, spreadsheet, and organizer programs.
|
||||
* This provides static methods to convert comma delimited text into a JSONArray, and to covert a JSONArray into comma
|
||||
* delimited text. Comma delimited text is a very popular format for data interchange. It is understood by most
|
||||
* database, spreadsheet, and organizer programs.
|
||||
* <p/>
|
||||
* Each row of text represents a row in a table or a data record. Each row ends
|
||||
* with a NEWLINE character. Each row contains one or more values. Values are
|
||||
* separated by commas. A value can contain any character except for comma,
|
||||
* Each row of text represents a row in a table or a data record. Each row ends with a NEWLINE character. Each row
|
||||
* contains one or more values. Values are separated by commas. A value can contain any character except for comma,
|
||||
* unless is is wrapped in single quotes or double quotes.
|
||||
* <p/>
|
||||
* The first row usually contains the names of the columns.
|
||||
* <p/>
|
||||
* A comma delimited list can be converted into a JSONArray of JSONObjects. The
|
||||
* names for the elements in the JSONObjects can be taken from the names in the
|
||||
* first row.
|
||||
* A comma delimited list can be converted into a JSONArray of JSONObjects. The names for the elements in the
|
||||
* JSONObjects can be taken from the names in the first row.
|
||||
*
|
||||
* @author JSON.org
|
||||
* @version 2014-05-03
|
||||
@ -23,14 +20,13 @@ package com.intellectualcrafters.json;
|
||||
public class CDL {
|
||||
|
||||
/**
|
||||
* Get the next value. The value can be wrapped in quotes. The value can
|
||||
* be empty.
|
||||
* Get the next value. The value can be wrapped in quotes. The value can be empty.
|
||||
*
|
||||
* @param x A JSONTokener of the source text.
|
||||
*
|
||||
* @param x
|
||||
* A JSONTokener of the source text.
|
||||
* @return The value string, or null if empty.
|
||||
* @throws JSONException
|
||||
* if the quoted string is badly formed.
|
||||
*
|
||||
* @throws JSONException if the quoted string is badly formed.
|
||||
*/
|
||||
private static String getValue(final JSONTokener x) throws JSONException {
|
||||
char c;
|
||||
@ -38,8 +34,7 @@ public class CDL {
|
||||
StringBuffer sb;
|
||||
do {
|
||||
c = x.next();
|
||||
}
|
||||
while ((c == ' ') || (c == '\t'));
|
||||
} while ((c == ' ') || (c == '\t'));
|
||||
switch (c) {
|
||||
case 0:
|
||||
return null;
|
||||
@ -70,9 +65,10 @@ public class CDL {
|
||||
/**
|
||||
* Produce a JSONArray of strings from a row of comma delimited values.
|
||||
*
|
||||
* @param x
|
||||
* A JSONTokener of the source text.
|
||||
* @param x A JSONTokener of the source text.
|
||||
*
|
||||
* @return A JSONArray of strings.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray rowToJSONArray(final JSONTokener x) throws JSONException {
|
||||
@ -100,17 +96,15 @@ public class CDL {
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a JSONObject from a row of comma delimited text, using a
|
||||
* parallel JSONArray of strings to provides the names of the elements.
|
||||
* Produce a JSONObject from a row of comma delimited text, using a parallel JSONArray of strings to provides the
|
||||
* names of the elements.
|
||||
*
|
||||
* @param names A JSONArray of names. This is commonly obtained from the first row of a comma delimited text file
|
||||
* using the rowToJSONArray method.
|
||||
* @param x A JSONTokener of the source text.
|
||||
*
|
||||
* @param names
|
||||
* A JSONArray of names. This is commonly obtained from the
|
||||
* first row of a comma delimited text file using the
|
||||
* rowToJSONArray
|
||||
* method.
|
||||
* @param x
|
||||
* A JSONTokener of the source text.
|
||||
* @return A JSONObject combining the names and values.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject rowToJSONObject(final JSONArray names, final JSONTokener x) throws JSONException {
|
||||
@ -119,12 +113,11 @@ public class CDL {
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a comma delimited text row from a JSONArray. Values containing
|
||||
* the comma character will be quoted. Troublesome characters may be
|
||||
* removed.
|
||||
* Produce a comma delimited text row from a JSONArray. Values containing the comma character will be quoted.
|
||||
* Troublesome characters may be removed.
|
||||
*
|
||||
* @param ja A JSONArray of strings.
|
||||
*
|
||||
* @param ja
|
||||
* A JSONArray of strings.
|
||||
* @return A string ending in NEWLINE.
|
||||
*/
|
||||
public static String rowToString(final JSONArray ja) {
|
||||
@ -146,8 +139,7 @@ public class CDL {
|
||||
}
|
||||
}
|
||||
sb.append('"');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sb.append(string);
|
||||
}
|
||||
}
|
||||
@ -157,12 +149,12 @@ public class CDL {
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a JSONArray of JSONObjects from a comma delimited text string,
|
||||
* using the first row as a source of names.
|
||||
* Produce a JSONArray of JSONObjects from a comma delimited text string, using the first row as a source of names.
|
||||
*
|
||||
* @param string The comma delimited text.
|
||||
*
|
||||
* @param string
|
||||
* The comma delimited text.
|
||||
* @return A JSONArray of JSONObjects.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(final String string) throws JSONException {
|
||||
@ -170,12 +162,12 @@ public class CDL {
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a JSONArray of JSONObjects from a comma delimited text string,
|
||||
* using the first row as a source of names.
|
||||
* Produce a JSONArray of JSONObjects from a comma delimited text string, using the first row as a source of names.
|
||||
*
|
||||
* @param x The JSONTokener containing the comma delimited text.
|
||||
*
|
||||
* @param x
|
||||
* The JSONTokener containing the comma delimited text.
|
||||
* @return A JSONArray of JSONObjects.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(final JSONTokener x) throws JSONException {
|
||||
@ -183,14 +175,14 @@ public class CDL {
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a JSONArray of JSONObjects from a comma delimited text string
|
||||
* using a supplied JSONArray as the source of element names.
|
||||
* Produce a JSONArray of JSONObjects from a comma delimited text string using a supplied JSONArray as the source of
|
||||
* element names.
|
||||
*
|
||||
* @param names A JSONArray of strings.
|
||||
* @param string The comma delimited text.
|
||||
*
|
||||
* @param names
|
||||
* A JSONArray of strings.
|
||||
* @param string
|
||||
* The comma delimited text.
|
||||
* @return A JSONArray of JSONObjects.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(final JSONArray names, final String string) throws JSONException {
|
||||
@ -198,14 +190,14 @@ public class CDL {
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a JSONArray of JSONObjects from a comma delimited text string
|
||||
* using a supplied JSONArray as the source of element names.
|
||||
* Produce a JSONArray of JSONObjects from a comma delimited text string using a supplied JSONArray as the source of
|
||||
* element names.
|
||||
*
|
||||
* @param names A JSONArray of strings.
|
||||
* @param x A JSONTokener of the source text.
|
||||
*
|
||||
* @param names
|
||||
* A JSONArray of strings.
|
||||
* @param x
|
||||
* A JSONTokener of the source text.
|
||||
* @return A JSONArray of JSONObjects.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(final JSONArray names, final JSONTokener x) throws JSONException {
|
||||
@ -227,13 +219,13 @@ public class CDL {
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a comma delimited text from a JSONArray of JSONObjects. The
|
||||
* first row will be a list of names obtained by inspecting the first
|
||||
* JSONObject.
|
||||
* Produce a comma delimited text from a JSONArray of JSONObjects. The first row will be a list of names obtained by
|
||||
* inspecting the first JSONObject.
|
||||
*
|
||||
* @param ja A JSONArray of JSONObjects.
|
||||
*
|
||||
* @param ja
|
||||
* A JSONArray of JSONObjects.
|
||||
* @return A comma delimited text.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(final JSONArray ja) throws JSONException {
|
||||
@ -248,15 +240,14 @@ public class CDL {
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a comma delimited text from a JSONArray of JSONObjects using
|
||||
* a provided list of names. The list of names is not included in the
|
||||
* output.
|
||||
* Produce a comma delimited text from a JSONArray of JSONObjects using a provided list of names. The list of names
|
||||
* is not included in the output.
|
||||
*
|
||||
* @param names A JSONArray of strings.
|
||||
* @param ja A JSONArray of JSONObjects.
|
||||
*
|
||||
* @param names
|
||||
* A JSONArray of strings.
|
||||
* @param ja
|
||||
* A JSONArray of JSONObjects.
|
||||
* @return A comma delimited text.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(final JSONArray names, final JSONArray ja) throws JSONException {
|
||||
|
@ -22,8 +22,8 @@
|
||||
package com.intellectualcrafters.json;
|
||||
|
||||
/**
|
||||
* Convert a web browser cookie specification to a JSONObject and back.
|
||||
* JSON and Cookies are both notations for name/value pairs.
|
||||
* Convert a web browser cookie specification to a JSONObject and back. JSON and Cookies are both notations for
|
||||
* name/value pairs.
|
||||
*
|
||||
* @author JSON.org
|
||||
* @version 2014-05-03
|
||||
@ -31,17 +31,14 @@ package com.intellectualcrafters.json;
|
||||
public class Cookie {
|
||||
|
||||
/**
|
||||
* Produce a copy of a string in which the characters '+', '%', '=', ';'
|
||||
* and control characters are replaced with "%hh". This is a gentle form
|
||||
* of URL encoding, attempting to cause as little distortion to the
|
||||
* string as possible. The characters '=' and ';' are meta characters in
|
||||
* cookies. By convention, they are escaped using the URL-encoding. This is
|
||||
* only a convention, not a standard. Often, cookies are expected to have
|
||||
* encoded values. We encode '=' and ';' because we must. We encode '%' and
|
||||
* '+' because they are meta characters in URL encoding.
|
||||
* Produce a copy of a string in which the characters '+', '%', '=', ';' and control characters are replaced with
|
||||
* "%hh". This is a gentle form of URL encoding, attempting to cause as little distortion to the string as possible.
|
||||
* The characters '=' and ';' are meta characters in cookies. By convention, they are escaped using the
|
||||
* URL-encoding. This is only a convention, not a standard. Often, cookies are expected to have encoded values. We
|
||||
* encode '=' and ';' because we must. We encode '%' and '+' because they are meta characters in URL encoding.
|
||||
*
|
||||
* @param string The source string.
|
||||
*
|
||||
* @param string
|
||||
* The source string.
|
||||
* @return The escaped result.
|
||||
*/
|
||||
public static String escape(final String string) {
|
||||
@ -55,8 +52,7 @@ public class Cookie {
|
||||
sb.append('%');
|
||||
sb.append(Character.forDigit((char) ((c >>> 4) & 0x0f), 16));
|
||||
sb.append(Character.forDigit((char) (c & 0x0f), 16));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
@ -64,20 +60,17 @@ public class Cookie {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a cookie specification string into a JSONObject. The string
|
||||
* will contain a name value pair separated by '='. The name and the value
|
||||
* will be unescaped, possibly converting '+' and '%' sequences. The
|
||||
* cookie properties may follow, separated by ';', also represented as
|
||||
* name=value (except the secure property, which does not have a value).
|
||||
* The name will be stored under the key "name", and the value will be
|
||||
* stored under the key "value". This method does not do checking or
|
||||
* validation of the parameters. It only converts the cookie string into
|
||||
* a JSONObject.
|
||||
* Convert a cookie specification string into a JSONObject. The string will contain a name value pair separated by
|
||||
* '='. The name and the value will be unescaped, possibly converting '+' and '%' sequences. The cookie properties
|
||||
* may follow, separated by ';', also represented as name=value (except the secure property, which does not have a
|
||||
* value). The name will be stored under the key "name", and the value will be stored under the key "value". This
|
||||
* method does not do checking or validation of the parameters. It only converts the cookie string into a
|
||||
* JSONObject.
|
||||
*
|
||||
* @param string The cookie specification string.
|
||||
*
|
||||
* @return A JSONObject containing "name", "value", and possibly other members.
|
||||
*
|
||||
* @param string
|
||||
* The cookie specification string.
|
||||
* @return A JSONObject containing "name", "value", and possibly other
|
||||
* members.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||
@ -94,12 +87,10 @@ public class Cookie {
|
||||
if (x.next() != '=') {
|
||||
if (name.equals("secure")) {
|
||||
value = Boolean.TRUE;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw x.syntaxError("Missing '=' in cookie parameter.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
value = unescape(x.nextTo(';'));
|
||||
x.next();
|
||||
}
|
||||
@ -109,15 +100,14 @@ public class Cookie {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a JSONObject into a cookie specification string. The JSONObject
|
||||
* must contain "name" and "value" members.
|
||||
* If the JSONObject contains "expires", "domain", "path", or "secure"
|
||||
* members, they will be appended to the cookie specification string.
|
||||
* All other members are ignored.
|
||||
* Convert a JSONObject into a cookie specification string. The JSONObject must contain "name" and "value" members.
|
||||
* If the JSONObject contains "expires", "domain", "path", or "secure" members, they will be appended to the cookie
|
||||
* specification string. All other members are ignored.
|
||||
*
|
||||
* @param jo A JSONObject
|
||||
*
|
||||
* @param jo
|
||||
* A JSONObject
|
||||
* @return A cookie specification string
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(final JSONObject jo) throws JSONException {
|
||||
@ -145,13 +135,11 @@ public class Cookie {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert <code>%</code><i>hh</i> sequences to single characters, and
|
||||
* convert plus to space.
|
||||
* Convert <code>%</code><i>hh</i> sequences to single characters, and convert plus to space.
|
||||
*
|
||||
* @param string
|
||||
* A string that may contain <code>+</code>
|
||||
* <small>(plus)</small> and <code>%</code><i>hh</i>
|
||||
* @param string A string that may contain <code>+</code> <small>(plus)</small> and <code>%</code><i>hh</i>
|
||||
* sequences.
|
||||
*
|
||||
* @return The unescaped string.
|
||||
*/
|
||||
public static String unescape(final String string) {
|
||||
@ -161,8 +149,7 @@ public class Cookie {
|
||||
char c = string.charAt(i);
|
||||
if (c == '+') {
|
||||
c = ' ';
|
||||
}
|
||||
else if ((c == '%') && ((i + 2) < length)) {
|
||||
} else if ((c == '%') && ((i + 2) < length)) {
|
||||
final int d = JSONTokener.dehexchar(string.charAt(i + 1));
|
||||
final int e = JSONTokener.dehexchar(string.charAt(i + 2));
|
||||
if ((d >= 0) && (e >= 0)) {
|
||||
|
@ -11,18 +11,17 @@ import java.util.Iterator;
|
||||
public class CookieList {
|
||||
|
||||
/**
|
||||
* Convert a cookie list into a JSONObject. A cookie list is a sequence
|
||||
* of name/value pairs. The names are separated from the values by '='.
|
||||
* The pairs are separated by ';'. The names and the values
|
||||
* will be unescaped, possibly converting '+' and '%' sequences.
|
||||
* Convert a cookie list into a JSONObject. A cookie list is a sequence of name/value pairs. The names are separated
|
||||
* from the values by '='. The pairs are separated by ';'. The names and the values will be unescaped, possibly
|
||||
* converting '+' and '%' sequences.
|
||||
* <p/>
|
||||
* To add a cookie to a cooklist,
|
||||
* cookielistJSONObject.put(cookieJSONObject.getString("name"),
|
||||
* To add a cookie to a cooklist, cookielistJSONObject.put(cookieJSONObject.getString("name"),
|
||||
* cookieJSONObject.getString("value"));
|
||||
*
|
||||
* @param string
|
||||
* A cookie list string
|
||||
* @param string A cookie list string
|
||||
*
|
||||
* @return A JSONObject
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||
@ -38,14 +37,14 @@ public class CookieList {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a JSONObject into a cookie list. A cookie list is a sequence
|
||||
* of name/value pairs. The names are separated from the values by '='.
|
||||
* The pairs are separated by ';'. The characters '%', '+', '=', and ';'
|
||||
* in the names and values are replaced by "%hh".
|
||||
* Convert a JSONObject into a cookie list. A cookie list is a sequence of name/value pairs. The names are separated
|
||||
* from the values by '='. The pairs are separated by ';'. The characters '%', '+', '=', and ';' in the names and
|
||||
* values are replaced by "%hh".
|
||||
*
|
||||
* @param jo A JSONObject
|
||||
*
|
||||
* @param jo
|
||||
* A JSONObject
|
||||
* @return A cookie list string
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(final JSONObject jo) throws JSONException {
|
||||
|
@ -37,10 +37,10 @@ public class HTTP {
|
||||
public static final String CRLF = "\r\n";
|
||||
|
||||
/**
|
||||
* Convert an HTTP header string into a JSONObject. It can be a request
|
||||
* header or a response header. A request header will contain
|
||||
* Convert an HTTP header string into a JSONObject. It can be a request header or a response header. A request
|
||||
* header will contain
|
||||
* <p/>
|
||||
* <p/>
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* Method: "POST" (for example),
|
||||
@ -51,7 +51,7 @@ public class HTTP {
|
||||
* <p/>
|
||||
* A response header will contain
|
||||
* <p/>
|
||||
*
|
||||
* <p/>
|
||||
* <pre>
|
||||
* {
|
||||
* "HTTP-Version": "HTTP/1.1" (for example),
|
||||
@ -60,10 +60,10 @@ public class HTTP {
|
||||
* }
|
||||
* </pre>
|
||||
* <p/>
|
||||
* In addition, the other parameters in the header will be captured, using
|
||||
* the HTTP field names as JSON names, so that
|
||||
* In addition, the other parameters in the header will be captured, using the HTTP field names as JSON names, so
|
||||
* that
|
||||
* <p/>
|
||||
* <p/>
|
||||
*
|
||||
* <pre>
|
||||
* Date: Sun, 26 May 2002 18:06:04 GMT
|
||||
* Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
|
||||
@ -72,7 +72,7 @@ public class HTTP {
|
||||
* <p/>
|
||||
* become
|
||||
* <p/>
|
||||
*
|
||||
* <p/>
|
||||
* <pre>
|
||||
* {...
|
||||
* Date: "Sun, 26 May 2002 18:06:04 GMT",
|
||||
@ -81,13 +81,12 @@ public class HTTP {
|
||||
* ...}
|
||||
* </pre>
|
||||
* <p/>
|
||||
* It does no further checking or conversion. It does not parse dates. It
|
||||
* does not do '%' transforms on URLs.
|
||||
* It does no further checking or conversion. It does not parse dates. It does not do '%' transforms on URLs.
|
||||
*
|
||||
* @param string An HTTP header string.
|
||||
*
|
||||
* @return A JSONObject containing the elements and attributes of the XML string.
|
||||
*
|
||||
* @param string
|
||||
* An HTTP header string.
|
||||
* @return A JSONObject containing the elements and attributes
|
||||
* of the XML string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||
@ -105,8 +104,7 @@ public class HTTP {
|
||||
jo.put("Reason-Phrase", x.nextTo('\0'));
|
||||
x.next();
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
// Request
|
||||
|
||||
@ -129,7 +127,7 @@ public class HTTP {
|
||||
/**
|
||||
* Convert a JSONObject into an HTTP header. A request header must contain
|
||||
* <p/>
|
||||
*
|
||||
* <p/>
|
||||
* <pre>
|
||||
* {
|
||||
* Method: "POST" (for example),
|
||||
@ -140,7 +138,7 @@ public class HTTP {
|
||||
* <p/>
|
||||
* A response header must contain
|
||||
* <p/>
|
||||
*
|
||||
* <p/>
|
||||
* <pre>
|
||||
* {
|
||||
* "HTTP-Version": "HTTP/1.1" (for example),
|
||||
@ -149,15 +147,13 @@ public class HTTP {
|
||||
* }
|
||||
* </pre>
|
||||
* <p/>
|
||||
* Any other members of the JSONObject will be output as HTTP fields. The
|
||||
* result will end with two CRLF pairs.
|
||||
* Any other members of the JSONObject will be output as HTTP fields. The result will end with two CRLF pairs.
|
||||
*
|
||||
* @param jo A JSONObject
|
||||
*
|
||||
* @param jo
|
||||
* A JSONObject
|
||||
* @return An HTTP header string.
|
||||
* @throws JSONException
|
||||
* if the object does not contain enough
|
||||
* information.
|
||||
*
|
||||
* @throws JSONException if the object does not contain enough information.
|
||||
*/
|
||||
public static String toString(final JSONObject jo) throws JSONException {
|
||||
final Iterator<String> keys = jo.keys();
|
||||
@ -169,8 +165,7 @@ public class HTTP {
|
||||
sb.append(jo.getString("Status-Code"));
|
||||
sb.append(' ');
|
||||
sb.append(jo.getString("Reason-Phrase"));
|
||||
}
|
||||
else if (jo.has("Method") && jo.has("Request-URI")) {
|
||||
} else if (jo.has("Method") && jo.has("Request-URI")) {
|
||||
sb.append(jo.getString("Method"));
|
||||
sb.append(' ');
|
||||
sb.append('"');
|
||||
@ -178,8 +173,7 @@ public class HTTP {
|
||||
sb.append('"');
|
||||
sb.append(' ');
|
||||
sb.append(jo.getString("HTTP-Version"));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new JSONException("Not enough material for an HTTP header.");
|
||||
}
|
||||
sb.append(CRLF);
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.intellectualcrafters.json;
|
||||
|
||||
/**
|
||||
* The HTTPTokener extends the JSONTokener to provide additional methods
|
||||
* for the parsing of HTTP headers.
|
||||
* The HTTPTokener extends the JSONTokener to provide additional methods for the parsing of HTTP headers.
|
||||
*
|
||||
* @author JSON.org
|
||||
* @version 2014-05-03
|
||||
@ -12,8 +11,7 @@ public class HTTPTokener extends JSONTokener {
|
||||
/**
|
||||
* Construct an HTTPTokener from a string.
|
||||
*
|
||||
* @param string
|
||||
* A source string.
|
||||
* @param string A source string.
|
||||
*/
|
||||
public HTTPTokener(final String string) {
|
||||
super(string);
|
||||
@ -23,6 +21,7 @@ public class HTTPTokener extends JSONTokener {
|
||||
* Get the next token or string. This is used in parsing HTTP headers.
|
||||
*
|
||||
* @return A String.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public String nextToken() throws JSONException {
|
||||
@ -31,8 +30,7 @@ public class HTTPTokener extends JSONTokener {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
do {
|
||||
c = next();
|
||||
}
|
||||
while (Character.isWhitespace(c));
|
||||
} while (Character.isWhitespace(c));
|
||||
if ((c == '"') || (c == '\'')) {
|
||||
q = c;
|
||||
for (; ; ) {
|
||||
|
@ -30,45 +30,29 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A JSONArray is an ordered sequence of values. Its external text form is a
|
||||
* string wrapped in square brackets with commas separating the values. The
|
||||
* internal form is an object having <code>get</code> and <code>opt</code>
|
||||
* methods for accessing the values by index, and <code>put</code> methods for
|
||||
* adding or replacing values. The values can be any of these types:
|
||||
* <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>,
|
||||
* <code>Number</code>, <code>String</code>, or the
|
||||
* <code>JSONObject.NULL object</code>.
|
||||
* A JSONArray is an ordered sequence of values. Its external text form is a string wrapped in square brackets with
|
||||
* commas separating the values. The internal form is an object having <code>get</code> and <code>opt</code> methods for
|
||||
* accessing the values by index, and <code>put</code> methods for adding or replacing values. The values can be any of
|
||||
* these types: <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>, <code>Number</code>,
|
||||
* <code>String</code>, or the <code>JSONObject.NULL object</code>.
|
||||
* <p/>
|
||||
* The constructor can convert a JSON text into a Java object. The
|
||||
* <code>toString</code> method converts to JSON text.
|
||||
* The constructor can convert a JSON text into a Java object. The <code>toString</code> method converts to JSON text.
|
||||
* <p/>
|
||||
* A <code>get</code> method returns a value if one can be found, and throws an
|
||||
* exception if one cannot be found. An <code>opt</code> method returns a
|
||||
* default value instead of throwing an exception, and so is useful for
|
||||
* obtaining optional values.
|
||||
* A <code>get</code> method returns a value if one can be found, and throws an exception if one cannot be found. An
|
||||
* <code>opt</code> method returns a default value instead of throwing an exception, and so is useful for obtaining
|
||||
* optional values.
|
||||
* <p/>
|
||||
* The generic <code>get()</code> and <code>opt()</code> methods return an
|
||||
* object which you can cast or query for type. There are also typed
|
||||
* <code>get</code> and <code>opt</code> methods that do type checking and type
|
||||
* coercion for you.
|
||||
* The generic <code>get()</code> and <code>opt()</code> methods return an object which you can cast or query for type.
|
||||
* There are also typed <code>get</code> and <code>opt</code> methods that do type checking and type coercion for you.
|
||||
* <p/>
|
||||
* The texts produced by the <code>toString</code> methods strictly conform to
|
||||
* JSON syntax rules. The constructors are more forgiving in the texts they will
|
||||
* accept:
|
||||
* <ul>
|
||||
* <li>An extra <code>,</code> <small>(comma)</small> may appear just
|
||||
* before the closing bracket.</li>
|
||||
* <li>The <code>null</code> value will be inserted when there is <code>,</code>
|
||||
* <small>(comma)</small> elision.</li>
|
||||
* <li>Strings may be quoted with <code>'</code> <small>(single
|
||||
* quote)</small>.</li>
|
||||
* <li>Strings do not need to be quoted at all if they do not begin with a quote
|
||||
* or single quote, and if they do not contain leading or trailing spaces, and
|
||||
* if they do not contain any of these characters:
|
||||
* <code>{ } [ ] / \ : , #</code> and if they do not look like numbers and if
|
||||
* they are not the reserved words <code>true</code>, <code>false</code>, or
|
||||
* <code>null</code>.</li>
|
||||
* </ul>
|
||||
* The texts produced by the <code>toString</code> methods strictly conform to JSON syntax rules. The constructors are
|
||||
* more forgiving in the texts they will accept: <ul> <li>An extra <code>,</code> <small>(comma)</small> may appear
|
||||
* just before the closing bracket.</li> <li>The <code>null</code> value will be inserted when there is <code>,</code>
|
||||
* <small>(comma)</small> elision.</li> <li>Strings may be quoted with <code>'</code> <small>(single
|
||||
* quote)</small>.</li> <li>Strings do not need to be quoted at all if they do not begin with a quote or single quote,
|
||||
* and if they do not contain leading or trailing spaces, and if they do not contain any of these characters: <code>{ }
|
||||
* [ ] / \ : , #</code> and if they do not look like numbers and if they are not the reserved words <code>true</code>,
|
||||
* <code>false</code>, or <code>null</code>.</li> </ul>
|
||||
*
|
||||
* @author JSON.org
|
||||
* @version 2014-05-03
|
||||
@ -90,10 +74,9 @@ public class JSONArray {
|
||||
/**
|
||||
* Construct a JSONArray from a JSONTokener.
|
||||
*
|
||||
* @param x
|
||||
* A JSONTokener
|
||||
* @throws JSONException
|
||||
* If there is a syntax error.
|
||||
* @param x A JSONTokener
|
||||
*
|
||||
* @throws JSONException If there is a syntax error.
|
||||
*/
|
||||
public JSONArray(final JSONTokener x) throws JSONException {
|
||||
this();
|
||||
@ -106,8 +89,7 @@ public class JSONArray {
|
||||
if (x.nextClean() == ',') {
|
||||
x.back();
|
||||
this.myArrayList.add(JSONObject.NULL);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
x.back();
|
||||
this.myArrayList.add(x.nextValue());
|
||||
}
|
||||
@ -130,12 +112,10 @@ public class JSONArray {
|
||||
/**
|
||||
* Construct a JSONArray from a source JSON text.
|
||||
*
|
||||
* @param source
|
||||
* A string that begins with <code>[</code> <small>(left
|
||||
* bracket)</small> and ends with <code>]</code>
|
||||
* <small>(right bracket)</small>.
|
||||
* @throws JSONException
|
||||
* If there is a syntax error.
|
||||
* @param source A string that begins with <code>[</code> <small>(left bracket)</small> and ends with
|
||||
* <code>]</code> <small>(right bracket)</small>.
|
||||
*
|
||||
* @throws JSONException If there is a syntax error.
|
||||
*/
|
||||
public JSONArray(final String source) throws JSONException {
|
||||
this(new JSONTokener(source));
|
||||
@ -144,8 +124,7 @@ public class JSONArray {
|
||||
/**
|
||||
* Construct a JSONArray from a Collection.
|
||||
*
|
||||
* @param collection
|
||||
* A Collection.
|
||||
* @param collection A Collection.
|
||||
*/
|
||||
public JSONArray(final Collection<Object> collection) {
|
||||
this.myArrayList = new ArrayList<Object>();
|
||||
@ -159,8 +138,7 @@ public class JSONArray {
|
||||
/**
|
||||
* Construct a JSONArray from an array
|
||||
*
|
||||
* @throws JSONException
|
||||
* If not an array.
|
||||
* @throws JSONException If not an array.
|
||||
*/
|
||||
public JSONArray(final Object array) throws JSONException {
|
||||
this();
|
||||
@ -169,8 +147,7 @@ public class JSONArray {
|
||||
for (int i = 0; i < length; i += 1) {
|
||||
this.put(JSONObject.wrap(Array.get(array, i)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new JSONException("JSONArray initial value should be a string or collection or array.");
|
||||
}
|
||||
}
|
||||
@ -178,11 +155,11 @@ public class JSONArray {
|
||||
/**
|
||||
* Get the object value associated with an index.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return An object value.
|
||||
* @throws JSONException
|
||||
* If there is no value for the index.
|
||||
*
|
||||
* @throws JSONException If there is no value for the index.
|
||||
*/
|
||||
public Object get(final int index) throws JSONException {
|
||||
final Object object = this.opt(index);
|
||||
@ -193,22 +170,19 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the boolean value associated with an index. The string values "true"
|
||||
* and "false" are converted to boolean.
|
||||
* Get the boolean value associated with an index. The string values "true" and "false" are converted to boolean.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @return The truth.
|
||||
* @throws JSONException
|
||||
* If there is no value for the index or if the value is not
|
||||
* convertible to boolean.
|
||||
*
|
||||
* @throws JSONException If there is no value for the index or if the value is not convertible to boolean.
|
||||
*/
|
||||
public boolean getBoolean(final int index) throws JSONException {
|
||||
final Object object = this.get(index);
|
||||
if (object.equals(Boolean.FALSE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("false"))) {
|
||||
return false;
|
||||
}
|
||||
else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) {
|
||||
} else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) {
|
||||
return true;
|
||||
}
|
||||
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
|
||||
@ -217,19 +191,17 @@ public class JSONArray {
|
||||
/**
|
||||
* Get the double value associated with an index.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return The value.
|
||||
* @throws JSONException
|
||||
* If the key is not found or if the value cannot be converted
|
||||
* to a number.
|
||||
*
|
||||
* @throws JSONException If the key is not found or if the value cannot be converted to a number.
|
||||
*/
|
||||
public double getDouble(final int index) throws JSONException {
|
||||
final Object object = this.get(index);
|
||||
try {
|
||||
return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||
}
|
||||
}
|
||||
@ -237,18 +209,17 @@ public class JSONArray {
|
||||
/**
|
||||
* Get the int value associated with an index.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return The value.
|
||||
* @throws JSONException
|
||||
* If the key is not found or if the value is not a number.
|
||||
*
|
||||
* @throws JSONException If the key is not found or if the value is not a number.
|
||||
*/
|
||||
public int getInt(final int index) throws JSONException {
|
||||
final Object object = this.get(index);
|
||||
try {
|
||||
return object instanceof Number ? ((Number) object).intValue() : Integer.parseInt((String) object);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||
}
|
||||
}
|
||||
@ -256,12 +227,11 @@ public class JSONArray {
|
||||
/**
|
||||
* Get the JSONArray associated with an index.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return A JSONArray value.
|
||||
* @throws JSONException
|
||||
* If there is no value for the index. or if the value is not a
|
||||
* JSONArray
|
||||
*
|
||||
* @throws JSONException If there is no value for the index. or if the value is not a JSONArray
|
||||
*/
|
||||
public JSONArray getJSONArray(final int index) throws JSONException {
|
||||
final Object object = this.get(index);
|
||||
@ -274,12 +244,11 @@ public class JSONArray {
|
||||
/**
|
||||
* Get the JSONObject associated with an index.
|
||||
*
|
||||
* @param index
|
||||
* subscript
|
||||
* @param index subscript
|
||||
*
|
||||
* @return A JSONObject value.
|
||||
* @throws JSONException
|
||||
* If there is no value for the index or if the value is not a
|
||||
* JSONObject
|
||||
*
|
||||
* @throws JSONException If there is no value for the index or if the value is not a JSONObject
|
||||
*/
|
||||
public JSONObject getJSONObject(final int index) throws JSONException {
|
||||
final Object object = this.get(index);
|
||||
@ -292,19 +261,17 @@ public class JSONArray {
|
||||
/**
|
||||
* Get the long value associated with an index.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return The value.
|
||||
* @throws JSONException
|
||||
* If the key is not found or if the value cannot be converted
|
||||
* to a number.
|
||||
*
|
||||
* @throws JSONException If the key is not found or if the value cannot be converted to a number.
|
||||
*/
|
||||
public long getLong(final int index) throws JSONException {
|
||||
final Object object = this.get(index);
|
||||
try {
|
||||
return object instanceof Number ? ((Number) object).longValue() : Long.parseLong((String) object);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||
}
|
||||
}
|
||||
@ -312,11 +279,11 @@ public class JSONArray {
|
||||
/**
|
||||
* Get the string associated with an index.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return A string value.
|
||||
* @throws JSONException
|
||||
* If there is no string value for the index.
|
||||
*
|
||||
* @throws JSONException If there is no string value for the index.
|
||||
*/
|
||||
public String getString(final int index) throws JSONException {
|
||||
final Object object = this.get(index);
|
||||
@ -329,8 +296,8 @@ public class JSONArray {
|
||||
/**
|
||||
* Determine if the value is null.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return true if the value at the index is null, or if there is no value.
|
||||
*/
|
||||
public boolean isNull(final int index) {
|
||||
@ -338,15 +305,14 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a string from the contents of this JSONArray. The
|
||||
* <code>separator</code> string is inserted between each element. Warning:
|
||||
* This method assumes that the data structure is acyclical.
|
||||
* Make a string from the contents of this JSONArray. The <code>separator</code> string is inserted between each
|
||||
* element. Warning: This method assumes that the data structure is acyclical.
|
||||
*
|
||||
* @param separator A string that will be inserted between the elements.
|
||||
*
|
||||
* @param separator
|
||||
* A string that will be inserted between the elements.
|
||||
* @return a string.
|
||||
* @throws JSONException
|
||||
* If the array contains an invalid number.
|
||||
*
|
||||
* @throws JSONException If the array contains an invalid number.
|
||||
*/
|
||||
public String join(final String separator) throws JSONException {
|
||||
final int len = this.length();
|
||||
@ -373,8 +339,8 @@ public class JSONArray {
|
||||
/**
|
||||
* Get the optional object value associated with an index.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return An object value, or null if there is no object at that index.
|
||||
*/
|
||||
public Object opt(final int index) {
|
||||
@ -382,12 +348,11 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional boolean value associated with an index. It returns false
|
||||
* if there is no value at that index, or if the value is not Boolean.TRUE
|
||||
* or the String "true".
|
||||
* Get the optional boolean value associated with an index. It returns false if there is no value at that index, or
|
||||
* if the value is not Boolean.TRUE or the String "true".
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @return The truth.
|
||||
*/
|
||||
public boolean optBoolean(final int index) {
|
||||
@ -395,32 +360,28 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional boolean value associated with an index. It returns the
|
||||
* defaultValue if there is no value at that index or if it is not a Boolean
|
||||
* or the String "true" or "false" (case insensitive).
|
||||
* Get the optional boolean value associated with an index. It returns the defaultValue if there is no value at that
|
||||
* index or if it is not a Boolean or the String "true" or "false" (case insensitive).
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @param defaultValue A boolean default.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @param defaultValue
|
||||
* A boolean default.
|
||||
* @return The truth.
|
||||
*/
|
||||
public boolean optBoolean(final int index, final boolean defaultValue) {
|
||||
try {
|
||||
return this.getBoolean(index);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional double value associated with an index. NaN is returned
|
||||
* if there is no value for the index, or if the value is not a number and
|
||||
* cannot be converted to a number.
|
||||
* Get the optional double value associated with an index. NaN is returned if there is no value for the index, or if
|
||||
* the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @return The value.
|
||||
*/
|
||||
public double optDouble(final int index) {
|
||||
@ -428,32 +389,28 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional double value associated with an index. The defaultValue
|
||||
* is returned if there is no value for the index, or if the value is not a
|
||||
* number and cannot be converted to a number.
|
||||
* Get the optional double value associated with an index. The defaultValue is returned if there is no value for the
|
||||
* index, or if the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index subscript
|
||||
* @param defaultValue The default value.
|
||||
*
|
||||
* @param index
|
||||
* subscript
|
||||
* @param defaultValue
|
||||
* The default value.
|
||||
* @return The value.
|
||||
*/
|
||||
public double optDouble(final int index, final double defaultValue) {
|
||||
try {
|
||||
return this.getDouble(index);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional int value associated with an index. Zero is returned if
|
||||
* there is no value for the index, or if the value is not a number and
|
||||
* cannot be converted to a number.
|
||||
* Get the optional int value associated with an index. Zero is returned if there is no value for the index, or if
|
||||
* the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @return The value.
|
||||
*/
|
||||
public int optInt(final int index) {
|
||||
@ -461,21 +418,18 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional int value associated with an index. The defaultValue is
|
||||
* returned if there is no value for the index, or if the value is not a
|
||||
* number and cannot be converted to a number.
|
||||
* Get the optional int value associated with an index. The defaultValue is returned if there is no value for the
|
||||
* index, or if the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @param defaultValue The default value.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @param defaultValue
|
||||
* The default value.
|
||||
* @return The value.
|
||||
*/
|
||||
public int optInt(final int index, final int defaultValue) {
|
||||
try {
|
||||
return this.getInt(index);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
@ -483,10 +437,9 @@ public class JSONArray {
|
||||
/**
|
||||
* Get the optional JSONArray associated with an index.
|
||||
*
|
||||
* @param index
|
||||
* subscript
|
||||
* @return A JSONArray value, or null if the index has no value, or if the
|
||||
* value is not a JSONArray.
|
||||
* @param index subscript
|
||||
*
|
||||
* @return A JSONArray value, or null if the index has no value, or if the value is not a JSONArray.
|
||||
*/
|
||||
public JSONArray optJSONArray(final int index) {
|
||||
final Object o = this.opt(index);
|
||||
@ -494,12 +447,11 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional JSONObject associated with an index. Null is returned if
|
||||
* the key is not found, or null if the index has no value, or if the value
|
||||
* is not a JSONObject.
|
||||
* Get the optional JSONObject associated with an index. Null is returned if the key is not found, or null if the
|
||||
* index has no value, or if the value is not a JSONObject.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @return A JSONObject value.
|
||||
*/
|
||||
public JSONObject optJSONObject(final int index) {
|
||||
@ -508,12 +460,11 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional long value associated with an index. Zero is returned if
|
||||
* there is no value for the index, or if the value is not a number and
|
||||
* cannot be converted to a number.
|
||||
* Get the optional long value associated with an index. Zero is returned if there is no value for the index, or if
|
||||
* the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @return The value.
|
||||
*/
|
||||
public long optLong(final int index) {
|
||||
@ -521,32 +472,28 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional long value associated with an index. The defaultValue is
|
||||
* returned if there is no value for the index, or if the value is not a
|
||||
* number and cannot be converted to a number.
|
||||
* Get the optional long value associated with an index. The defaultValue is returned if there is no value for the
|
||||
* index, or if the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @param defaultValue The default value.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @param defaultValue
|
||||
* The default value.
|
||||
* @return The value.
|
||||
*/
|
||||
public long optLong(final int index, final long defaultValue) {
|
||||
try {
|
||||
return this.getLong(index);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional string value associated with an index. It returns an
|
||||
* empty string if there is no value at that index. If the value is not a
|
||||
* string and is not null, then it is coverted to a string.
|
||||
* Get the optional string value associated with an index. It returns an empty string if there is no value at that
|
||||
* index. If the value is not a string and is not null, then it is coverted to a string.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @return A String value.
|
||||
*/
|
||||
public String optString(final int index) {
|
||||
@ -554,13 +501,11 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional string associated with an index. The defaultValue is
|
||||
* returned if the key is not found.
|
||||
* Get the optional string associated with an index. The defaultValue is returned if the key is not found.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @param defaultValue The default value.
|
||||
*
|
||||
* @param index
|
||||
* The index must be between 0 and length() - 1.
|
||||
* @param defaultValue
|
||||
* The default value.
|
||||
* @return A String value.
|
||||
*/
|
||||
public String optString(final int index, final String defaultValue) {
|
||||
@ -571,8 +516,8 @@ public class JSONArray {
|
||||
/**
|
||||
* Append a boolean value. This increases the array's length by one.
|
||||
*
|
||||
* @param value
|
||||
* A boolean value.
|
||||
* @param value A boolean value.
|
||||
*
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(final boolean value) {
|
||||
@ -581,11 +526,10 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a value in the JSONArray, where the value will be a JSONArray which
|
||||
* is produced from a Collection.
|
||||
* Put a value in the JSONArray, where the value will be a JSONArray which is produced from a Collection.
|
||||
*
|
||||
* @param value A Collection value.
|
||||
*
|
||||
* @param value
|
||||
* A Collection value.
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(final Collection<Object> value) {
|
||||
@ -596,11 +540,11 @@ public class JSONArray {
|
||||
/**
|
||||
* Append a double value. This increases the array's length by one.
|
||||
*
|
||||
* @param value
|
||||
* A double value.
|
||||
* @param value A double value.
|
||||
*
|
||||
* @return this.
|
||||
* @throws JSONException
|
||||
* if the value is not finite.
|
||||
*
|
||||
* @throws JSONException if the value is not finite.
|
||||
*/
|
||||
public JSONArray put(final double value) throws JSONException {
|
||||
final Double d = value;
|
||||
@ -612,8 +556,8 @@ public class JSONArray {
|
||||
/**
|
||||
* Append an int value. This increases the array's length by one.
|
||||
*
|
||||
* @param value
|
||||
* An int value.
|
||||
* @param value An int value.
|
||||
*
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(final int value) {
|
||||
@ -624,8 +568,8 @@ public class JSONArray {
|
||||
/**
|
||||
* Append an long value. This increases the array's length by one.
|
||||
*
|
||||
* @param value
|
||||
* A long value.
|
||||
* @param value A long value.
|
||||
*
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(final long value) {
|
||||
@ -634,11 +578,10 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a value in the JSONArray, where the value will be a JSONObject which
|
||||
* is produced from a Map.
|
||||
* Put a value in the JSONArray, where the value will be a JSONObject which is produced from a Map.
|
||||
*
|
||||
* @param value A Map value.
|
||||
*
|
||||
* @param value
|
||||
* A Map value.
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(final Map<String, Object> value) {
|
||||
@ -649,10 +592,9 @@ public class JSONArray {
|
||||
/**
|
||||
* Append an object value. This increases the array's length by one.
|
||||
*
|
||||
* @param value
|
||||
* An object value. The value should be a Boolean, Double,
|
||||
* Integer, JSONArray, JSONObject, Long, or String, or the
|
||||
* JSONObject.NULL object.
|
||||
* @param value An object value. The value should be a Boolean, Double, Integer, JSONArray, JSONObject, Long, or
|
||||
* String, or the JSONObject.NULL object.
|
||||
*
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(final Object value) {
|
||||
@ -661,17 +603,15 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Put or replace a boolean value in the JSONArray. If the index is greater
|
||||
* than the length of the JSONArray, then null elements will be added as
|
||||
* necessary to pad it out.
|
||||
* Put or replace a boolean value in the JSONArray. If the index is greater than the length of the JSONArray, then
|
||||
* null elements will be added as necessary to pad it out.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value A boolean value.
|
||||
*
|
||||
* @param index
|
||||
* The subscript.
|
||||
* @param value
|
||||
* A boolean value.
|
||||
* @return this.
|
||||
* @throws JSONException
|
||||
* If the index is negative.
|
||||
*
|
||||
* @throws JSONException If the index is negative.
|
||||
*/
|
||||
public JSONArray put(final int index, final boolean value) throws JSONException {
|
||||
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
|
||||
@ -679,16 +619,14 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a value in the JSONArray, where the value will be a JSONArray which
|
||||
* is produced from a Collection.
|
||||
* Put a value in the JSONArray, where the value will be a JSONArray which is produced from a Collection.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value A Collection value.
|
||||
*
|
||||
* @param index
|
||||
* The subscript.
|
||||
* @param value
|
||||
* A Collection value.
|
||||
* @return this.
|
||||
* @throws JSONException
|
||||
* If the index is negative or if the value is not finite.
|
||||
*
|
||||
* @throws JSONException If the index is negative or if the value is not finite.
|
||||
*/
|
||||
public JSONArray put(final int index, final Collection<Object> value) throws JSONException {
|
||||
this.put(index, new JSONArray(value));
|
||||
@ -696,17 +634,15 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Put or replace a double value. If the index is greater than the length of
|
||||
* the JSONArray, then null elements will be added as necessary to pad it
|
||||
* out.
|
||||
* Put or replace a double value. If the index is greater than the length of the JSONArray, then null elements will
|
||||
* be added as necessary to pad it out.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value A double value.
|
||||
*
|
||||
* @param index
|
||||
* The subscript.
|
||||
* @param value
|
||||
* A double value.
|
||||
* @return this.
|
||||
* @throws JSONException
|
||||
* If the index is negative or if the value is not finite.
|
||||
*
|
||||
* @throws JSONException If the index is negative or if the value is not finite.
|
||||
*/
|
||||
public JSONArray put(final int index, final double value) throws JSONException {
|
||||
this.put(index, new Double(value));
|
||||
@ -714,17 +650,15 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Put or replace an int value. If the index is greater than the length of
|
||||
* the JSONArray, then null elements will be added as necessary to pad it
|
||||
* out.
|
||||
* Put or replace an int value. If the index is greater than the length of the JSONArray, then null elements will be
|
||||
* added as necessary to pad it out.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value An int value.
|
||||
*
|
||||
* @param index
|
||||
* The subscript.
|
||||
* @param value
|
||||
* An int value.
|
||||
* @return this.
|
||||
* @throws JSONException
|
||||
* If the index is negative.
|
||||
*
|
||||
* @throws JSONException If the index is negative.
|
||||
*/
|
||||
public JSONArray put(final int index, final int value) throws JSONException {
|
||||
this.put(index, new Integer(value));
|
||||
@ -732,17 +666,15 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Put or replace a long value. If the index is greater than the length of
|
||||
* the JSONArray, then null elements will be added as necessary to pad it
|
||||
* out.
|
||||
* Put or replace a long value. If the index is greater than the length of the JSONArray, then null elements will be
|
||||
* added as necessary to pad it out.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value A long value.
|
||||
*
|
||||
* @param index
|
||||
* The subscript.
|
||||
* @param value
|
||||
* A long value.
|
||||
* @return this.
|
||||
* @throws JSONException
|
||||
* If the index is negative.
|
||||
*
|
||||
* @throws JSONException If the index is negative.
|
||||
*/
|
||||
public JSONArray put(final int index, final long value) throws JSONException {
|
||||
this.put(index, new Long(value));
|
||||
@ -750,17 +682,14 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a value in the JSONArray, where the value will be a JSONObject that
|
||||
* is produced from a Map.
|
||||
* Put a value in the JSONArray, where the value will be a JSONObject that is produced from a Map.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value The Map value.
|
||||
*
|
||||
* @param index
|
||||
* The subscript.
|
||||
* @param value
|
||||
* The Map value.
|
||||
* @return this.
|
||||
* @throws JSONException
|
||||
* If the index is negative or if the the value is an invalid
|
||||
* number.
|
||||
*
|
||||
* @throws JSONException If the index is negative or if the the value is an invalid number.
|
||||
*/
|
||||
public JSONArray put(final int index, final Map<String, Object> value) throws JSONException {
|
||||
this.put(index, new JSONObject(value));
|
||||
@ -768,20 +697,16 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Put or replace an object value in the JSONArray. If the index is greater
|
||||
* than the length of the JSONArray, then null elements will be added as
|
||||
* necessary to pad it out.
|
||||
* Put or replace an object value in the JSONArray. If the index is greater than the length of the JSONArray, then
|
||||
* null elements will be added as necessary to pad it out.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value The value to put into the array. The value should be a Boolean, Double, Integer, JSONArray,
|
||||
* JSONObject, Long, or String, or the JSONObject.NULL object.
|
||||
*
|
||||
* @param index
|
||||
* The subscript.
|
||||
* @param value
|
||||
* The value to put into the array. The value should be a
|
||||
* Boolean, Double, Integer, JSONArray, JSONObject, Long, or
|
||||
* String, or the JSONObject.NULL object.
|
||||
* @return this.
|
||||
* @throws JSONException
|
||||
* If the index is negative or if the the value is an invalid
|
||||
* number.
|
||||
*
|
||||
* @throws JSONException If the index is negative or if the the value is an invalid number.
|
||||
*/
|
||||
public JSONArray put(final int index, final Object value) throws JSONException {
|
||||
JSONObject.testValidity(value);
|
||||
@ -790,8 +715,7 @@ public class JSONArray {
|
||||
}
|
||||
if (index < this.length()) {
|
||||
this.myArrayList.set(index, value);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
while (index != this.length()) {
|
||||
this.put(JSONObject.NULL);
|
||||
}
|
||||
@ -803,21 +727,19 @@ public class JSONArray {
|
||||
/**
|
||||
* Remove an index and close the hole.
|
||||
*
|
||||
* @param index
|
||||
* The index of the element to be removed.
|
||||
* @return The value that was associated with the index, or null if there
|
||||
* was no value.
|
||||
* @param index The index of the element to be removed.
|
||||
*
|
||||
* @return The value that was associated with the index, or null if there was no value.
|
||||
*/
|
||||
public Object remove(final int index) {
|
||||
return (index >= 0) && (index < this.length()) ? this.myArrayList.remove(index) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if two JSONArrays are similar.
|
||||
* They must contain similar sequences.
|
||||
* Determine if two JSONArrays are similar. They must contain similar sequences.
|
||||
*
|
||||
* @param other The other JSONArray
|
||||
*
|
||||
* @param other
|
||||
* The other JSONArray
|
||||
* @return true if they are equal
|
||||
*/
|
||||
public boolean similar(final Object other) {
|
||||
@ -835,13 +757,11 @@ public class JSONArray {
|
||||
if (!((JSONObject) valueThis).similar(valueOther)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (valueThis instanceof JSONArray) {
|
||||
} else if (valueThis instanceof JSONArray) {
|
||||
if (!((JSONArray) valueThis).similar(valueOther)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!valueThis.equals(valueOther)) {
|
||||
} else if (!valueThis.equals(valueOther)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -849,16 +769,13 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a JSONObject by combining a JSONArray of names with the values of
|
||||
* this JSONArray.
|
||||
* Produce a JSONObject by combining a JSONArray of names with the values of this JSONArray.
|
||||
*
|
||||
* @param names
|
||||
* A JSONArray containing a list of key strings. These will be
|
||||
* paired with the values.
|
||||
* @return A JSONObject, or null if there are no names or if this JSONArray
|
||||
* has no values.
|
||||
* @throws JSONException
|
||||
* If any of the names are null.
|
||||
* @param names A JSONArray containing a list of key strings. These will be paired with the values.
|
||||
*
|
||||
* @return A JSONObject, or null if there are no names or if this JSONArray has no values.
|
||||
*
|
||||
* @throws JSONException If any of the names are null.
|
||||
*/
|
||||
public JSONObject toJSONObject(final JSONArray names) throws JSONException {
|
||||
if ((names == null) || (names.length() == 0) || (this.length() == 0)) {
|
||||
@ -872,36 +789,33 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a JSON text of this JSONArray. For compactness, no unnecessary
|
||||
* whitespace is added. If it is not possible to produce a syntactically
|
||||
* correct JSON text then null will be returned instead. This could occur if
|
||||
* the array contains an invalid number.
|
||||
* Make a JSON text of this JSONArray. For compactness, no unnecessary whitespace is added. If it is not possible to
|
||||
* produce a syntactically correct JSON text then null will be returned instead. This could occur if the array
|
||||
* contains an invalid number.
|
||||
* <p/>
|
||||
* Warning: This method assumes that the data structure is acyclical.
|
||||
*
|
||||
* @return a printable, displayable, transmittable representation of the
|
||||
* array.
|
||||
* @return a printable, displayable, transmittable representation of the array.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return this.toString(0);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a prettyprinted JSON text of this JSONArray. Warning: This method
|
||||
* assumes that the data structure is acyclical.
|
||||
* Make a prettyprinted JSON text of this JSONArray. Warning: This method assumes that the data structure is
|
||||
* acyclical.
|
||||
*
|
||||
* @param indentFactor The number of spaces to add to each level of indentation.
|
||||
*
|
||||
* @return a printable, displayable, transmittable representation of the object, beginning with
|
||||
* <code>[</code> <small>(left bracket)</small> and ending with <code>]</code> <small>(right
|
||||
* bracket)</small>.
|
||||
*
|
||||
* @param indentFactor
|
||||
* The number of spaces to add to each level of indentation.
|
||||
* @return a printable, displayable, transmittable representation of the
|
||||
* object, beginning with <code>[</code> <small>(left
|
||||
* bracket)</small> and ending with <code>]</code>
|
||||
* <small>(right bracket)</small>.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public String toString(final int indentFactor) throws JSONException {
|
||||
@ -912,12 +826,12 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the contents of the JSONArray as JSON text to a writer. For
|
||||
* compactness, no whitespace is added.
|
||||
* Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added.
|
||||
* <p/>
|
||||
* Warning: This method assumes that the data structure is acyclical.
|
||||
*
|
||||
* @return The writer.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public Writer write(final Writer writer) throws JSONException {
|
||||
@ -925,16 +839,15 @@ public class JSONArray {
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the contents of the JSONArray as JSON text to a writer. For
|
||||
* compactness, no whitespace is added.
|
||||
* Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added.
|
||||
* <p/>
|
||||
* Warning: This method assumes that the data structure is acyclical.
|
||||
*
|
||||
* @param indentFactor
|
||||
* The number of spaces to add to each level of indentation.
|
||||
* @param indent
|
||||
* The indention of the top level.
|
||||
* @param indentFactor The number of spaces to add to each level of indentation.
|
||||
* @param indent The indention of the top level.
|
||||
*
|
||||
* @return The writer.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
Writer write(final Writer writer, final int indentFactor, final int indent) throws JSONException {
|
||||
@ -945,8 +858,7 @@ public class JSONArray {
|
||||
|
||||
if (length == 1) {
|
||||
JSONObject.writeValue(writer, this.myArrayList.get(0), indentFactor, indent);
|
||||
}
|
||||
else if (length != 0) {
|
||||
} else if (length != 0) {
|
||||
final int newindent = indent + indentFactor;
|
||||
|
||||
for (int i = 0; i < length; i += 1) {
|
||||
@ -967,8 +879,7 @@ public class JSONArray {
|
||||
}
|
||||
writer.write(']');
|
||||
return writer;
|
||||
}
|
||||
catch (final IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new JSONException(e);
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,7 @@ public class JSONException extends RuntimeException {
|
||||
/**
|
||||
* Constructs a JSONException with an explanatory message.
|
||||
*
|
||||
* @param message
|
||||
* Detail about the reason for the exception.
|
||||
* @param message Detail about the reason for the exception.
|
||||
*/
|
||||
public JSONException(final String message) {
|
||||
super(message);
|
||||
@ -23,8 +22,7 @@ public class JSONException extends RuntimeException {
|
||||
/**
|
||||
* Constructs a new JSONException with the specified cause.
|
||||
*
|
||||
* @param cause
|
||||
* The cause.
|
||||
* @param cause The cause.
|
||||
*/
|
||||
public JSONException(final Throwable cause) {
|
||||
super(cause.getMessage());
|
||||
@ -32,11 +30,9 @@ public class JSONException extends RuntimeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cause of this exception or null if the cause is nonexistent
|
||||
* or unknown.
|
||||
* Returns the cause of this exception or null if the cause is nonexistent or unknown.
|
||||
*
|
||||
* @return the cause of this exception or null if the cause is nonexistent
|
||||
* or unknown.
|
||||
* @return the cause of this exception or null if the cause is nonexistent or unknown.
|
||||
*/
|
||||
@Override
|
||||
public Throwable getCause() {
|
||||
|
@ -3,9 +3,8 @@ package com.intellectualcrafters.json;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* This provides static methods to convert an XML text into a JSONArray or
|
||||
* JSONObject, and to covert a JSONArray or JSONObject into an XML text using
|
||||
* the JsonML transform.
|
||||
* This provides static methods to convert an XML text into a JSONArray or JSONObject, and to covert a JSONArray or
|
||||
* JSONObject into an XML text using the JsonML transform.
|
||||
*
|
||||
* @author JSON.org
|
||||
* @version 2014-05-03
|
||||
@ -15,14 +14,12 @@ public class JSONML {
|
||||
/**
|
||||
* Parse XML values and store them in a JSONArray.
|
||||
*
|
||||
* @param x
|
||||
* The XMLTokener containing the source string.
|
||||
* @param arrayForm
|
||||
* true if array form, false if object form.
|
||||
* @param ja
|
||||
* The JSONArray that is containing the current tag or null
|
||||
* if we are at the outermost level.
|
||||
* @param x The XMLTokener containing the source string.
|
||||
* @param arrayForm true if array form, false if object form.
|
||||
* @param ja The JSONArray that is containing the current tag or null if we are at the outermost level.
|
||||
*
|
||||
* @return A JSONArray if the value is the outermost tag, otherwise null.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
private static Object parse(final XMLTokener x, final boolean arrayForm, final JSONArray ja) throws JSONException {
|
||||
@ -61,8 +58,7 @@ public class JSONML {
|
||||
throw x.syntaxError("Misshaped close tag");
|
||||
}
|
||||
return token;
|
||||
}
|
||||
else if (token == XML.BANG) {
|
||||
} else if (token == XML.BANG) {
|
||||
|
||||
// <!
|
||||
|
||||
@ -70,53 +66,43 @@ public class JSONML {
|
||||
if (c == '-') {
|
||||
if (x.next() == '-') {
|
||||
x.skipPast("-->");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
x.back();
|
||||
}
|
||||
}
|
||||
else if (c == '[') {
|
||||
} else if (c == '[') {
|
||||
token = x.nextToken();
|
||||
if (token.equals("CDATA") && (x.next() == '[')) {
|
||||
if (ja != null) {
|
||||
ja.put(x.nextCDATA());
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw x.syntaxError("Expected 'CDATA['");
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
i = 1;
|
||||
do {
|
||||
token = x.nextMeta();
|
||||
if (token == null) {
|
||||
throw x.syntaxError("Missing '>' after '<!'.");
|
||||
}
|
||||
else if (token == XML.LT) {
|
||||
} else if (token == XML.LT) {
|
||||
i += 1;
|
||||
}
|
||||
else if (token == XML.GT) {
|
||||
} else if (token == XML.GT) {
|
||||
i -= 1;
|
||||
}
|
||||
} while (i > 0);
|
||||
}
|
||||
while (i > 0);
|
||||
}
|
||||
}
|
||||
else if (token == XML.QUEST) {
|
||||
} else if (token == XML.QUEST) {
|
||||
|
||||
// <?
|
||||
|
||||
x.skipPast("?>");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw x.syntaxError("Misshaped tag");
|
||||
}
|
||||
|
||||
// Open tag <
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!(token instanceof String)) {
|
||||
throw x.syntaxError("Bad tagName '" + token + "'.");
|
||||
}
|
||||
@ -128,8 +114,7 @@ public class JSONML {
|
||||
if (ja != null) {
|
||||
ja.put(newja);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
newjo.put("tagName", tagName);
|
||||
if (ja != null) {
|
||||
ja.put(newjo);
|
||||
@ -161,8 +146,7 @@ public class JSONML {
|
||||
}
|
||||
newjo.accumulate(attribute, XML.stringToValue((String) token));
|
||||
token = null;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
newjo.accumulate(attribute, "");
|
||||
}
|
||||
}
|
||||
@ -179,16 +163,14 @@ public class JSONML {
|
||||
if (ja == null) {
|
||||
if (arrayForm) {
|
||||
return newja;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return newjo;
|
||||
}
|
||||
}
|
||||
|
||||
// Content, between <...> and </...>
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (token != XML.GT) {
|
||||
throw x.syntaxError("Misshaped tag");
|
||||
}
|
||||
@ -204,16 +186,14 @@ public class JSONML {
|
||||
if (ja == null) {
|
||||
if (arrayForm) {
|
||||
return newja;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return newjo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (ja != null) {
|
||||
ja.put(token instanceof String ? XML.stringToValue((String) token) : token);
|
||||
}
|
||||
@ -222,17 +202,15 @@ public class JSONML {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a
|
||||
* JSONArray using the JsonML transform. Each XML tag is represented as
|
||||
* a JSONArray in which the first element is the tag name. If the tag has
|
||||
* attributes, then the second element will be JSONObject containing the
|
||||
* name/value pairs. If the tag contains children, then strings and
|
||||
* JSONArrays will represent the child tags.
|
||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONArray using the JsonML transform. Each
|
||||
* XML tag is represented as a JSONArray in which the first element is the tag name. If the tag has attributes, then
|
||||
* the second element will be JSONObject containing the name/value pairs. If the tag contains children, then strings
|
||||
* and JSONArrays will represent the child tags. Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
||||
*
|
||||
* @param string The source string.
|
||||
*
|
||||
* @param string
|
||||
* The source string.
|
||||
* @return A JSONArray containing the structured data from the XML string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(final String string) throws JSONException {
|
||||
@ -240,17 +218,16 @@ public class JSONML {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a
|
||||
* JSONArray using the JsonML transform. Each XML tag is represented as
|
||||
* a JSONArray in which the first element is the tag name. If the tag has
|
||||
* attributes, then the second element will be JSONObject containing the
|
||||
* name/value pairs. If the tag contains children, then strings and
|
||||
* JSONArrays will represent the child content and tags.
|
||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONArray using the JsonML transform. Each
|
||||
* XML tag is represented as a JSONArray in which the first element is the tag name. If the tag has attributes, then
|
||||
* the second element will be JSONObject containing the name/value pairs. If the tag contains children, then strings
|
||||
* and JSONArrays will represent the child content and tags. Comments, prologs, DTDs, and <code><[ [ ]]></code>
|
||||
* are ignored.
|
||||
*
|
||||
* @param x An XMLTokener.
|
||||
*
|
||||
* @param x
|
||||
* An XMLTokener.
|
||||
* @return A JSONArray containing the structured data from the XML string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(final XMLTokener x) throws JSONException {
|
||||
@ -258,18 +235,17 @@ public class JSONML {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a
|
||||
* JSONObject using the JsonML transform. Each XML tag is represented as
|
||||
* a JSONObject with a "tagName" property. If the tag has attributes, then
|
||||
* the attributes will be in the JSONObject as properties. If the tag
|
||||
* contains children, the object will have a "childNodes" property which
|
||||
* will be an array of strings and JsonML JSONObjects.
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML transform. Each
|
||||
* XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes
|
||||
* will be in the JSONObject as properties. If the tag contains children, the object will have a "childNodes"
|
||||
* property which will be an array of strings and JsonML JSONObjects.
|
||||
* <p/>
|
||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
||||
*
|
||||
* @param x
|
||||
* An XMLTokener of the XML source text.
|
||||
* @param x An XMLTokener of the XML source text.
|
||||
*
|
||||
* @return A JSONObject containing the structured data from the XML string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(final XMLTokener x) throws JSONException {
|
||||
@ -277,18 +253,17 @@ public class JSONML {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a
|
||||
* JSONObject using the JsonML transform. Each XML tag is represented as
|
||||
* a JSONObject with a "tagName" property. If the tag has attributes, then
|
||||
* the attributes will be in the JSONObject as properties. If the tag
|
||||
* contains children, the object will have a "childNodes" property which
|
||||
* will be an array of strings and JsonML JSONObjects.
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML transform. Each
|
||||
* XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes
|
||||
* will be in the JSONObject as properties. If the tag contains children, the object will have a "childNodes"
|
||||
* property which will be an array of strings and JsonML JSONObjects.
|
||||
* <p/>
|
||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
||||
*
|
||||
* @param string
|
||||
* The XML source text.
|
||||
* @param string The XML source text.
|
||||
*
|
||||
* @return A JSONObject containing the structured data from the XML string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||
@ -298,9 +273,10 @@ public class JSONML {
|
||||
/**
|
||||
* Reverse the JSONML transformation, making an XML text from a JSONArray.
|
||||
*
|
||||
* @param ja
|
||||
* A JSONArray.
|
||||
* @param ja A JSONArray.
|
||||
*
|
||||
* @return An XML string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(final JSONArray ja) throws JSONException {
|
||||
@ -343,8 +319,7 @@ public class JSONML {
|
||||
sb.append('"');
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
i = 1;
|
||||
}
|
||||
|
||||
@ -354,8 +329,7 @@ public class JSONML {
|
||||
if (i >= length) {
|
||||
sb.append('/');
|
||||
sb.append('>');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sb.append('>');
|
||||
do {
|
||||
object = ja.get(i);
|
||||
@ -363,16 +337,13 @@ public class JSONML {
|
||||
if (object != null) {
|
||||
if (object instanceof String) {
|
||||
sb.append(XML.escape(object.toString()));
|
||||
}
|
||||
else if (object instanceof JSONObject) {
|
||||
} else if (object instanceof JSONObject) {
|
||||
sb.append(toString((JSONObject) object));
|
||||
}
|
||||
else if (object instanceof JSONArray) {
|
||||
} else if (object instanceof JSONArray) {
|
||||
sb.append(toString((JSONArray) object));
|
||||
}
|
||||
}
|
||||
}
|
||||
while (i < length);
|
||||
} while (i < length);
|
||||
sb.append('<');
|
||||
sb.append('/');
|
||||
sb.append(tagName);
|
||||
@ -382,14 +353,14 @@ public class JSONML {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the JSONML transformation, making an XML text from a JSONObject.
|
||||
* The JSONObject must contain a "tagName" property. If it has children,
|
||||
* then it must have a "childNodes" property containing an array of objects.
|
||||
* The other properties are attributes with string values.
|
||||
* Reverse the JSONML transformation, making an XML text from a JSONObject. The JSONObject must contain a "tagName"
|
||||
* property. If it has children, then it must have a "childNodes" property containing an array of objects. The other
|
||||
* properties are attributes with string values.
|
||||
*
|
||||
* @param jo A JSONObject.
|
||||
*
|
||||
* @param jo
|
||||
* A JSONObject.
|
||||
* @return An XML string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(final JSONObject jo) throws JSONException {
|
||||
@ -439,8 +410,7 @@ public class JSONML {
|
||||
if (ja == null) {
|
||||
sb.append('/');
|
||||
sb.append('>');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sb.append('>');
|
||||
length = ja.length();
|
||||
for (i = 0; i < length; i += 1) {
|
||||
@ -448,14 +418,11 @@ public class JSONML {
|
||||
if (object != null) {
|
||||
if (object instanceof String) {
|
||||
sb.append(XML.escape(object.toString()));
|
||||
}
|
||||
else if (object instanceof JSONObject) {
|
||||
} else if (object instanceof JSONObject) {
|
||||
sb.append(toString((JSONObject) object));
|
||||
}
|
||||
else if (object instanceof JSONArray) {
|
||||
} else if (object instanceof JSONArray) {
|
||||
sb.append(toString((JSONArray) object));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sb.append(object.toString());
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,18 +1,14 @@
|
||||
package com.intellectualcrafters.json;
|
||||
|
||||
/**
|
||||
* The <code>JSONString</code> interface allows a <code>toJSONString()</code>
|
||||
* method so that a class can change the behavior of
|
||||
* <code>JSONObject.toString()</code>, <code>JSONArray.toString()</code>,
|
||||
* and <code>JSONWriter.value(</code>Object<code>)</code>. The
|
||||
* <code>toJSONString</code> method will be used instead of the default behavior
|
||||
* of using the Object's <code>toString()</code> method and quoting the result.
|
||||
* The <code>JSONString</code> interface allows a <code>toJSONString()</code> method so that a class can change the
|
||||
* behavior of <code>JSONObject.toString()</code>, <code>JSONArray.toString()</code>, and
|
||||
* <code>JSONWriter.value(</code>Object<code>)</code>. The <code>toJSONString</code> method will be used instead of the
|
||||
* default behavior of using the Object's <code>toString()</code> method and quoting the result.
|
||||
*/
|
||||
public interface JSONString {
|
||||
/**
|
||||
* The <code>toJSONString</code> method allows a class to produce its own
|
||||
* JSON
|
||||
* serialization.
|
||||
* The <code>toJSONString</code> method allows a class to produce its own JSON serialization.
|
||||
*
|
||||
* @return A strictly syntactically correct JSON text.
|
||||
*/
|
||||
|
@ -3,34 +3,30 @@ package com.intellectualcrafters.json;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* JSONStringer provides a quick and convenient way of producing JSON text.
|
||||
* The texts produced strictly conform to JSON syntax rules. No whitespace is
|
||||
* added, so the results are ready for transmission or storage. Each instance of
|
||||
* JSONStringer provides a quick and convenient way of producing JSON text. The texts produced strictly conform to JSON
|
||||
* syntax rules. No whitespace is added, so the results are ready for transmission or storage. Each instance of
|
||||
* JSONStringer can produce one JSON text.
|
||||
* <p/>
|
||||
* A JSONStringer instance provides a <code>value</code> method for appending
|
||||
* values to the text, and a <code>key</code> method for adding keys before
|
||||
* values in objects. There are <code>array</code> and <code>endArray</code>
|
||||
* methods that make and bound array values, and <code>object</code> and
|
||||
* <code>endObject</code> methods which make and bound object values. All of
|
||||
* these methods return the JSONWriter instance, permitting cascade style. For
|
||||
* example,
|
||||
* A JSONStringer instance provides a <code>value</code> method for appending values to the text, and a <code>key</code>
|
||||
* method for adding keys before values in objects. There are <code>array</code> and <code>endArray</code> methods that
|
||||
* make and bound array values, and <code>object</code> and <code>endObject</code> methods which make and bound object
|
||||
* values. All of these methods return the JSONWriter instance, permitting cascade style. For example,
|
||||
* <p/>
|
||||
* <p/>
|
||||
*
|
||||
* <pre>
|
||||
* myString = new JSONStringer().object().key("JSON").value("Hello, World!").endObject().toString();
|
||||
* myString = new JSONStringer().object().key("JSON").value("Hello,
|
||||
* World!").endObject().toString();
|
||||
* </pre>
|
||||
* <p/>
|
||||
* which produces the string
|
||||
* <p/>
|
||||
*
|
||||
* <p/>
|
||||
* <pre>
|
||||
* {"JSON":"Hello, World!"}
|
||||
* </pre>
|
||||
* <p/>
|
||||
* The first method called must be <code>array</code> or <code>object</code>.
|
||||
* There are no methods for adding commas or colons. JSONStringer adds them for
|
||||
* you. Objects and arrays can be nested up to 20 levels deep.
|
||||
* The first method called must be <code>array</code> or <code>object</code>. There are no methods for adding commas or
|
||||
* colons. JSONStringer adds them for you. Objects and arrays can be nested up to 20 levels deep.
|
||||
* <p/>
|
||||
* This can sometimes be easier than using a JSONObject to build a string.
|
||||
*
|
||||
@ -46,11 +42,9 @@ public class JSONStringer extends JSONWriter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the JSON text. This method is used to obtain the product of the
|
||||
* JSONStringer instance. It will return <code>null</code> if there was a
|
||||
* problem in the construction of the JSON text (such as the calls to
|
||||
* <code>array</code> were not properly balanced with calls to
|
||||
* <code>endArray</code>).
|
||||
* Return the JSON text. This method is used to obtain the product of the JSONStringer instance. It will return
|
||||
* <code>null</code> if there was a problem in the construction of the JSON text (such as the calls to
|
||||
* <code>array</code> were not properly balanced with calls to <code>endArray</code>).
|
||||
*
|
||||
* @return The JSON text.
|
||||
*/
|
||||
|
@ -1,16 +1,10 @@
|
||||
package com.intellectualcrafters.json;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* A JSONTokener takes a source string and extracts characters and tokens from
|
||||
* it. It is used by the JSONObject and JSONArray constructors to parse
|
||||
* JSON source strings.
|
||||
* A JSONTokener takes a source string and extracts characters and tokens from it. It is used by the JSONObject and
|
||||
* JSONArray constructors to parse JSON source strings.
|
||||
*
|
||||
* @author JSON.org
|
||||
* @version 2014-05-03
|
||||
@ -28,8 +22,7 @@ public class JSONTokener {
|
||||
/**
|
||||
* Construct a JSONTokener from a Reader.
|
||||
*
|
||||
* @param reader
|
||||
* A reader.
|
||||
* @param reader A reader.
|
||||
*/
|
||||
public JSONTokener(final Reader reader) {
|
||||
this.reader = reader.markSupported() ? reader : new BufferedReader(reader);
|
||||
@ -44,8 +37,7 @@ public class JSONTokener {
|
||||
/**
|
||||
* Construct a JSONTokener from an InputStream.
|
||||
*
|
||||
* @param inputStream
|
||||
* The source.
|
||||
* @param inputStream The source.
|
||||
*/
|
||||
public JSONTokener(final InputStream inputStream) throws JSONException {
|
||||
this(new InputStreamReader(inputStream));
|
||||
@ -54,8 +46,7 @@ public class JSONTokener {
|
||||
/**
|
||||
* Construct a JSONTokener from a string.
|
||||
*
|
||||
* @param s
|
||||
* A source string.
|
||||
* @param s A source string.
|
||||
*/
|
||||
public JSONTokener(final String s) {
|
||||
this(new StringReader(s));
|
||||
@ -64,9 +55,8 @@ public class JSONTokener {
|
||||
/**
|
||||
* Get the hex value of a character (base16).
|
||||
*
|
||||
* @param c
|
||||
* A character between '0' and '9' or between 'A' and 'F' or
|
||||
* between 'a' and 'f'.
|
||||
* @param c A character between '0' and '9' or between 'A' and 'F' or between 'a' and 'f'.
|
||||
*
|
||||
* @return An int between 0 and 15, or -1 if c was not a hex digit.
|
||||
*/
|
||||
public static int dehexchar(final char c) {
|
||||
@ -83,9 +73,8 @@ public class JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Back up one character. This provides a sort of lookahead capability,
|
||||
* so that you can test for a digit or letter before attempting to parse
|
||||
* the next number or identifier.
|
||||
* Back up one character. This provides a sort of lookahead capability, so that you can test for a digit or letter
|
||||
* before attempting to parse the next number or identifier.
|
||||
*/
|
||||
public void back() throws JSONException {
|
||||
if (this.usePrevious || (this.index <= 0)) {
|
||||
@ -102,8 +91,7 @@ public class JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the source string still contains characters that next()
|
||||
* can consume.
|
||||
* Determine if the source string still contains characters that next() can consume.
|
||||
*
|
||||
* @return true if not yet at the end of the source.
|
||||
*/
|
||||
@ -126,12 +114,10 @@ public class JSONTokener {
|
||||
if (this.usePrevious) {
|
||||
this.usePrevious = false;
|
||||
c = this.previous;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
try {
|
||||
c = this.reader.read();
|
||||
}
|
||||
catch (final IOException exception) {
|
||||
} catch (final IOException exception) {
|
||||
throw new JSONException(exception);
|
||||
}
|
||||
|
||||
@ -144,12 +130,10 @@ public class JSONTokener {
|
||||
if (this.previous == '\r') {
|
||||
this.line += 1;
|
||||
this.character = c == '\n' ? 0 : 1;
|
||||
}
|
||||
else if (c == '\n') {
|
||||
} else if (c == '\n') {
|
||||
this.line += 1;
|
||||
this.character = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.character += 1;
|
||||
}
|
||||
this.previous = (char) c;
|
||||
@ -157,14 +141,13 @@ public class JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Consume the next character, and check that it matches a specified
|
||||
* character.
|
||||
* Consume the next character, and check that it matches a specified character.
|
||||
*
|
||||
* @param c The character to match.
|
||||
*
|
||||
* @param c
|
||||
* The character to match.
|
||||
* @return The character.
|
||||
* @throws JSONException
|
||||
* if the character does not match.
|
||||
*
|
||||
* @throws JSONException if the character does not match.
|
||||
*/
|
||||
public char next(final char c) throws JSONException {
|
||||
final char n = this.next();
|
||||
@ -177,12 +160,11 @@ public class JSONTokener {
|
||||
/**
|
||||
* Get the next n characters.
|
||||
*
|
||||
* @param n
|
||||
* The number of characters to take.
|
||||
* @param n The number of characters to take.
|
||||
*
|
||||
* @return A string of n characters.
|
||||
* @throws JSONException
|
||||
* Substring bounds error if there are not
|
||||
* n characters remaining in the source string.
|
||||
*
|
||||
* @throws JSONException Substring bounds error if there are not n characters remaining in the source string.
|
||||
*/
|
||||
public String next(final int n) throws JSONException {
|
||||
if (n == 0) {
|
||||
@ -206,6 +188,7 @@ public class JSONTokener {
|
||||
* Get the next char in the string, skipping whitespace.
|
||||
*
|
||||
* @return A character, or 0 if there are no more characters.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public char nextClean() throws JSONException {
|
||||
@ -218,18 +201,15 @@ public class JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the characters up to the next close quote character.
|
||||
* Backslash processing is done. The formal JSON format does not
|
||||
* allow strings in single quotes, but an implementation is allowed to
|
||||
* accept them.
|
||||
* Return the characters up to the next close quote character. Backslash processing is done. The formal JSON format
|
||||
* does not allow strings in single quotes, but an implementation is allowed to accept them.
|
||||
*
|
||||
* @param quote
|
||||
* The quoting character, either <code>"</code>
|
||||
* <small>(double quote)</small> or <code>'</code>
|
||||
* @param quote The quoting character, either <code>"</code> <small>(double quote)</small> or <code>'</code>
|
||||
* <small>(single quote)</small>.
|
||||
*
|
||||
* @return A String.
|
||||
* @throws JSONException
|
||||
* Unterminated string.
|
||||
*
|
||||
* @throws JSONException Unterminated string.
|
||||
*/
|
||||
public String nextString(final char quote) throws JSONException {
|
||||
char c;
|
||||
@ -282,11 +262,10 @@ public class JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text up but not including the specified character or the
|
||||
* end of line, whichever comes first.
|
||||
* Get the text up but not including the specified character or the end of line, whichever comes first.
|
||||
*
|
||||
* @param delimiter A delimiter character.
|
||||
*
|
||||
* @param delimiter
|
||||
* A delimiter character.
|
||||
* @return A string.
|
||||
*/
|
||||
public String nextTo(final char delimiter) throws JSONException {
|
||||
@ -304,11 +283,11 @@ public class JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text up but not including one of the specified delimiter
|
||||
* characters or the end of line, whichever comes first.
|
||||
* Get the text up but not including one of the specified delimiter characters or the end of line, whichever comes
|
||||
* first.
|
||||
*
|
||||
* @param delimiters A set of delimiter characters.
|
||||
*
|
||||
* @param delimiters
|
||||
* A set of delimiter characters.
|
||||
* @return A string, trimmed.
|
||||
*/
|
||||
public String nextTo(final String delimiters) throws JSONException {
|
||||
@ -327,12 +306,12 @@ public class JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next value. The value can be a Boolean, Double, Integer,
|
||||
* JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
|
||||
* Get the next value. The value can be a Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
|
||||
* JSONObject.NULL object.
|
||||
*
|
||||
* @return An object.
|
||||
* @throws JSONException
|
||||
* If syntax error.
|
||||
*
|
||||
* @throws JSONException If syntax error.
|
||||
*/
|
||||
public Object nextValue() throws JSONException {
|
||||
char c = this.nextClean();
|
||||
@ -373,13 +352,12 @@ public class JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip characters until the next character is the requested character.
|
||||
* If the requested character is not found, no characters are skipped.
|
||||
* Skip characters until the next character is the requested character. If the requested character is not found, no
|
||||
* characters are skipped.
|
||||
*
|
||||
* @param to
|
||||
* A character to skip to.
|
||||
* @return The requested character, or zero if the requested character
|
||||
* is not found.
|
||||
* @param to A character to skip to.
|
||||
*
|
||||
* @return The requested character, or zero if the requested character is not found.
|
||||
*/
|
||||
public char skipTo(final char to) throws JSONException {
|
||||
char c;
|
||||
@ -397,10 +375,8 @@ public class JSONTokener {
|
||||
this.line = startLine;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
while (c != to);
|
||||
}
|
||||
catch (final IOException exception) {
|
||||
} while (c != to);
|
||||
} catch (final IOException exception) {
|
||||
throw new JSONException(exception);
|
||||
}
|
||||
this.back();
|
||||
@ -410,8 +386,8 @@ public class JSONTokener {
|
||||
/**
|
||||
* Make a JSONException to signal a syntax error.
|
||||
*
|
||||
* @param message
|
||||
* The error message.
|
||||
* @param message The error message.
|
||||
*
|
||||
* @return A JSONException object, suitable for throwing
|
||||
*/
|
||||
public JSONException syntaxError(final String message) {
|
||||
|
@ -4,34 +4,29 @@ import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* JSONWriter provides a quick and convenient way of producing JSON text.
|
||||
* The texts produced strictly conform to JSON syntax rules. No whitespace is
|
||||
* added, so the results are ready for transmission or storage. Each instance of
|
||||
* JSONWriter provides a quick and convenient way of producing JSON text. The texts produced strictly conform to JSON
|
||||
* syntax rules. No whitespace is added, so the results are ready for transmission or storage. Each instance of
|
||||
* JSONWriter can produce one JSON text.
|
||||
* <p/>
|
||||
* A JSONWriter instance provides a <code>value</code> method for appending
|
||||
* values to the text, and a <code>key</code> method for adding keys before
|
||||
* values in objects. There are <code>array</code> and <code>endArray</code>
|
||||
* methods that make and bound array values, and <code>object</code> and
|
||||
* <code>endObject</code> methods which make and bound object values. All of
|
||||
* these methods return the JSONWriter instance, permitting a cascade style. For
|
||||
* example,
|
||||
* A JSONWriter instance provides a <code>value</code> method for appending values to the text, and a <code>key</code>
|
||||
* method for adding keys before values in objects. There are <code>array</code> and <code>endArray</code> methods that
|
||||
* make and bound array values, and <code>object</code> and <code>endObject</code> methods which make and bound object
|
||||
* values. All of these methods return the JSONWriter instance, permitting a cascade style. For example,
|
||||
* <p/>
|
||||
* <p/>
|
||||
*
|
||||
* <pre>
|
||||
* new JSONWriter(myWriter).object().key("JSON").value("Hello, World!").endObject();
|
||||
* </pre>
|
||||
* <p/>
|
||||
* which writes
|
||||
* <p/>
|
||||
*
|
||||
* <p/>
|
||||
* <pre>
|
||||
* {"JSON":"Hello, World!"}
|
||||
* </pre>
|
||||
* <p/>
|
||||
* The first method called must be <code>array</code> or <code>object</code>.
|
||||
* There are no methods for adding commas or colons. JSONWriter adds them for
|
||||
* you. Objects and arrays can be nested up to 20 levels deep.
|
||||
* The first method called must be <code>array</code> or <code>object</code>. There are no methods for adding commas or
|
||||
* colons. JSONWriter adds them for you. Objects and arrays can be nested up to 20 levels deep.
|
||||
* <p/>
|
||||
* This can sometimes be easier than using a JSONObject to build a string.
|
||||
*
|
||||
@ -49,17 +44,11 @@ public class JSONWriter {
|
||||
*/
|
||||
private final JSONObject stack[];
|
||||
/**
|
||||
* The current mode. Values:
|
||||
* 'a' (array),
|
||||
* 'd' (done),
|
||||
* 'i' (initial),
|
||||
* 'k' (key),
|
||||
* 'o' (object).
|
||||
* The current mode. Values: 'a' (array), 'd' (done), 'i' (initial), 'k' (key), 'o' (object).
|
||||
*/
|
||||
protected char mode;
|
||||
/**
|
||||
* The comma flag determines if a comma should be output before the next
|
||||
* value.
|
||||
* The comma flag determines if a comma should be output before the next value.
|
||||
*/
|
||||
private boolean comma;
|
||||
/**
|
||||
@ -81,11 +70,11 @@ public class JSONWriter {
|
||||
/**
|
||||
* Append a value.
|
||||
*
|
||||
* @param string
|
||||
* A string value.
|
||||
* @param string A string value.
|
||||
*
|
||||
* @return this
|
||||
* @throws JSONException
|
||||
* If the value is out of sequence.
|
||||
*
|
||||
* @throws JSONException If the value is out of sequence.
|
||||
*/
|
||||
private JSONWriter append(final String string) throws JSONException {
|
||||
if (string == null) {
|
||||
@ -97,8 +86,7 @@ public class JSONWriter {
|
||||
this.writer.write(',');
|
||||
}
|
||||
this.writer.write(string);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new JSONException(e);
|
||||
}
|
||||
if (this.mode == 'o') {
|
||||
@ -111,16 +99,13 @@ public class JSONWriter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin appending a new array. All values until the balancing
|
||||
* <code>endArray</code> will be appended to this array. The
|
||||
* <code>endArray</code> method must be called to mark the array's end.
|
||||
* Begin appending a new array. All values until the balancing <code>endArray</code> will be appended to this array.
|
||||
* The <code>endArray</code> method must be called to mark the array's end.
|
||||
*
|
||||
* @return this
|
||||
* @throws JSONException
|
||||
* If the nesting is too deep, or if the object is
|
||||
* started in the wrong place (for example as a key or after the
|
||||
* end of the
|
||||
* outermost array or object).
|
||||
*
|
||||
* @throws JSONException If the nesting is too deep, or if the object is started in the wrong place (for example as
|
||||
* a key or after the end of the outermost array or object).
|
||||
*/
|
||||
public JSONWriter array() throws JSONException {
|
||||
if ((this.mode == 'i') || (this.mode == 'o') || (this.mode == 'a')) {
|
||||
@ -135,13 +120,12 @@ public class JSONWriter {
|
||||
/**
|
||||
* End something.
|
||||
*
|
||||
* @param mode
|
||||
* Mode
|
||||
* @param c
|
||||
* Closing character
|
||||
* @param mode Mode
|
||||
* @param c Closing character
|
||||
*
|
||||
* @return this
|
||||
* @throws JSONException
|
||||
* If unbalanced.
|
||||
*
|
||||
* @throws JSONException If unbalanced.
|
||||
*/
|
||||
private JSONWriter end(final char mode, final char c) throws JSONException {
|
||||
if (this.mode != mode) {
|
||||
@ -150,8 +134,7 @@ public class JSONWriter {
|
||||
this.pop(mode);
|
||||
try {
|
||||
this.writer.write(c);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new JSONException(e);
|
||||
}
|
||||
this.comma = true;
|
||||
@ -159,39 +142,37 @@ public class JSONWriter {
|
||||
}
|
||||
|
||||
/**
|
||||
* End an array. This method most be called to balance calls to
|
||||
* <code>array</code>.
|
||||
* End an array. This method most be called to balance calls to <code>array</code>.
|
||||
*
|
||||
* @return this
|
||||
* @throws JSONException
|
||||
* If incorrectly nested.
|
||||
*
|
||||
* @throws JSONException If incorrectly nested.
|
||||
*/
|
||||
public JSONWriter endArray() throws JSONException {
|
||||
return this.end('a', ']');
|
||||
}
|
||||
|
||||
/**
|
||||
* End an object. This method most be called to balance calls to
|
||||
* <code>object</code>.
|
||||
* End an object. This method most be called to balance calls to <code>object</code>.
|
||||
*
|
||||
* @return this
|
||||
* @throws JSONException
|
||||
* If incorrectly nested.
|
||||
*
|
||||
* @throws JSONException If incorrectly nested.
|
||||
*/
|
||||
public JSONWriter endObject() throws JSONException {
|
||||
return this.end('k', '}');
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a key. The key will be associated with the next value. In an
|
||||
* object, every value must be preceded by a key.
|
||||
* Append a key. The key will be associated with the next value. In an object, every value must be preceded by a
|
||||
* key.
|
||||
*
|
||||
* @param string A key string.
|
||||
*
|
||||
* @param string
|
||||
* A key string.
|
||||
* @return this
|
||||
* @throws JSONException
|
||||
* If the key is out of place. For example, keys
|
||||
* do not belong in arrays or if the key is null.
|
||||
*
|
||||
* @throws JSONException If the key is out of place. For example, keys do not belong in arrays or if the key is
|
||||
* null.
|
||||
*/
|
||||
public JSONWriter key(final String string) throws JSONException {
|
||||
if (string == null) {
|
||||
@ -208,8 +189,7 @@ public class JSONWriter {
|
||||
this.comma = false;
|
||||
this.mode = 'o';
|
||||
return this;
|
||||
}
|
||||
catch (final IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new JSONException(e);
|
||||
}
|
||||
}
|
||||
@ -217,16 +197,13 @@ public class JSONWriter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin appending a new object. All keys and values until the balancing
|
||||
* <code>endObject</code> will be appended to this object. The
|
||||
* <code>endObject</code> method must be called to mark the object's end.
|
||||
* Begin appending a new object. All keys and values until the balancing <code>endObject</code> will be appended to
|
||||
* this object. The <code>endObject</code> method must be called to mark the object's end.
|
||||
*
|
||||
* @return this
|
||||
* @throws JSONException
|
||||
* If the nesting is too deep, or if the object is
|
||||
* started in the wrong place (for example as a key or after the
|
||||
* end of the
|
||||
* outermost array or object).
|
||||
*
|
||||
* @throws JSONException If the nesting is too deep, or if the object is started in the wrong place (for example as
|
||||
* a key or after the end of the outermost array or object).
|
||||
*/
|
||||
public JSONWriter object() throws JSONException {
|
||||
if (this.mode == 'i') {
|
||||
@ -245,10 +222,9 @@ public class JSONWriter {
|
||||
/**
|
||||
* Pop an array or object scope.
|
||||
*
|
||||
* @param c
|
||||
* The scope to close.
|
||||
* @throws JSONException
|
||||
* If nesting is wrong.
|
||||
* @param c The scope to close.
|
||||
*
|
||||
* @throws JSONException If nesting is wrong.
|
||||
*/
|
||||
private void pop(final char c) throws JSONException {
|
||||
if (this.top <= 0) {
|
||||
@ -265,10 +241,9 @@ public class JSONWriter {
|
||||
/**
|
||||
* Push an array or object scope.
|
||||
*
|
||||
* @param jo
|
||||
* The scope to open.
|
||||
* @throws JSONException
|
||||
* If nesting is too deep.
|
||||
* @param jo The scope to open.
|
||||
*
|
||||
* @throws JSONException If nesting is too deep.
|
||||
*/
|
||||
private void push(final JSONObject jo) throws JSONException {
|
||||
if (this.top >= maxdepth) {
|
||||
@ -280,12 +255,12 @@ public class JSONWriter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Append either the value <code>true</code> or the value <code>false</code>
|
||||
* .
|
||||
* Append either the value <code>true</code> or the value <code>false</code> .
|
||||
*
|
||||
* @param b A boolean.
|
||||
*
|
||||
* @param b
|
||||
* A boolean.
|
||||
* @return this
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public JSONWriter value(final boolean b) throws JSONException {
|
||||
@ -295,11 +270,11 @@ public class JSONWriter {
|
||||
/**
|
||||
* Append a double value.
|
||||
*
|
||||
* @param d
|
||||
* A double.
|
||||
* @param d A double.
|
||||
*
|
||||
* @return this
|
||||
* @throws JSONException
|
||||
* If the number is not finite.
|
||||
*
|
||||
* @throws JSONException If the number is not finite.
|
||||
*/
|
||||
public JSONWriter value(final double d) throws JSONException {
|
||||
return this.value(new Double(d));
|
||||
@ -308,9 +283,10 @@ public class JSONWriter {
|
||||
/**
|
||||
* Append a long value.
|
||||
*
|
||||
* @param l
|
||||
* A long.
|
||||
* @param l A long.
|
||||
*
|
||||
* @return this
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public JSONWriter value(final long l) throws JSONException {
|
||||
@ -320,13 +296,12 @@ public class JSONWriter {
|
||||
/**
|
||||
* Append an object value.
|
||||
*
|
||||
* @param object
|
||||
* The object to append. It can be null, or a Boolean, Number,
|
||||
* String, JSONObject, or JSONArray, or an object that implements
|
||||
* JSONString.
|
||||
* @param object The object to append. It can be null, or a Boolean, Number, String, JSONObject, or JSONArray, or an
|
||||
* object that implements JSONString.
|
||||
*
|
||||
* @return this
|
||||
* @throws JSONException
|
||||
* If the value is out of sequence.
|
||||
*
|
||||
* @throws JSONException If the value is out of sequence.
|
||||
*/
|
||||
public JSONWriter value(final Object object) throws JSONException {
|
||||
return this.append(JSONObject.valueToString(object));
|
||||
|
@ -1,43 +1,35 @@
|
||||
package com.intellectualcrafters.json;
|
||||
|
||||
/**
|
||||
* Kim makes immutable eight bit Unicode strings. If the MSB of a byte is set,
|
||||
* then the next byte is a continuation byte. The last byte of a character
|
||||
* never has the MSB reset. Every byte that is not the last byte has the MSB
|
||||
* set. Kim stands for "Keep it minimal". A Unicode character is never longer
|
||||
* than 3 bytes. Every byte contributes 7 bits to the character. ASCII is
|
||||
* unmodified.
|
||||
* Kim makes immutable eight bit Unicode strings. If the MSB of a byte is set, then the next byte is a continuation
|
||||
* byte. The last byte of a character never has the MSB reset. Every byte that is not the last byte has the MSB set. Kim
|
||||
* stands for "Keep it minimal". A Unicode character is never longer than 3 bytes. Every byte contributes 7 bits to the
|
||||
* character. ASCII is unmodified.
|
||||
* <p/>
|
||||
* Kim UTF-8 one byte U+007F U+007F two bytes U+3FFF U+07FF three bytes U+10FFF
|
||||
* U+FFFF four bytes U+10FFFF
|
||||
* Kim UTF-8 one byte U+007F U+007F two bytes U+3FFF U+07FF three bytes U+10FFF U+FFFF four bytes U+10FFFF
|
||||
* <p/>
|
||||
* Characters in the ranges U+0800..U+3FFF and U+10000..U+10FFFF will be one
|
||||
* byte smaller when encoded in Kim compared to UTF-8.
|
||||
* Characters in the ranges U+0800..U+3FFF and U+10000..U+10FFFF will be one byte smaller when encoded in Kim compared
|
||||
* to UTF-8.
|
||||
* <p/>
|
||||
* Kim is beneficial when using scripts such as Old South Arabian, Aramaic,
|
||||
* Avestan, Balinese, Batak, Bopomofo, Buginese, Buhid, Carian, Cherokee,
|
||||
* Coptic, Cyrillic, Deseret, Egyptian Hieroglyphs, Ethiopic, Georgian,
|
||||
* Glagolitic, Gothic, Hangul Jamo, Hanunoo, Hiragana, Kanbun, Kaithi, Kannada,
|
||||
* Katakana, Kharoshthi, Khmer, Lao, Lepcha, Limbu, Lycian, Lydian, Malayalam,
|
||||
* Mandaic, Meroitic, Miao, Mongolian, Myanmar, New Tai Lue, Ol Chiki, Old
|
||||
* Turkic, Oriya, Osmanya, Pahlavi, Parthian, Phags-Pa, Phoenician, Samaritan,
|
||||
* Sharada, Sinhala, Sora Sompeng, Tagalog, Tagbanwa, Takri, Tai Le, Tai Tham,
|
||||
* Tamil, Telugu, Thai, Tibetan, Tifinagh, UCAS.
|
||||
* Kim is beneficial when using scripts such as Old South Arabian, Aramaic, Avestan, Balinese, Batak, Bopomofo,
|
||||
* Buginese, Buhid, Carian, Cherokee, Coptic, Cyrillic, Deseret, Egyptian Hieroglyphs, Ethiopic, Georgian, Glagolitic,
|
||||
* Gothic, Hangul Jamo, Hanunoo, Hiragana, Kanbun, Kaithi, Kannada, Katakana, Kharoshthi, Khmer, Lao, Lepcha, Limbu,
|
||||
* Lycian, Lydian, Malayalam, Mandaic, Meroitic, Miao, Mongolian, Myanmar, New Tai Lue, Ol Chiki, Old Turkic, Oriya,
|
||||
* Osmanya, Pahlavi, Parthian, Phags-Pa, Phoenician, Samaritan, Sharada, Sinhala, Sora Sompeng, Tagalog, Tagbanwa,
|
||||
* Takri, Tai Le, Tai Tham, Tamil, Telugu, Thai, Tibetan, Tifinagh, UCAS.
|
||||
* <p/>
|
||||
* A kim object can be constructed from an ordinary UTF-16 string, or from a
|
||||
* byte array. A kim object can produce a UTF-16 string.
|
||||
* A kim object can be constructed from an ordinary UTF-16 string, or from a byte array. A kim object can produce a
|
||||
* UTF-16 string.
|
||||
* <p/>
|
||||
* As with UTF-8, it is possible to detect character boundaries within a byte
|
||||
* sequence. UTF-8 is one of the world's great inventions. While Kim is more
|
||||
* efficient, it is not clear that it is worth the expense of transition.
|
||||
* As with UTF-8, it is possible to detect character boundaries within a byte sequence. UTF-8 is one of the world's
|
||||
* great inventions. While Kim is more efficient, it is not clear that it is worth the expense of transition.
|
||||
*
|
||||
* @version 2013-04-18
|
||||
*/
|
||||
public class Kim {
|
||||
|
||||
/**
|
||||
* The number of bytes in the kim. The number of bytes can be as much as
|
||||
* three times the number of characters.
|
||||
* The number of bytes in the kim. The number of bytes can be as much as three times the number of characters.
|
||||
*/
|
||||
public int length = 0;
|
||||
/**
|
||||
@ -56,12 +48,9 @@ public class Kim {
|
||||
/**
|
||||
* Make a kim from a portion of a byte array.
|
||||
*
|
||||
* @param bytes
|
||||
* A byte array.
|
||||
* @param from
|
||||
* The index of the first byte.
|
||||
* @param thru
|
||||
* The index of the last byte plus one.
|
||||
* @param bytes A byte array.
|
||||
* @param from The index of the first byte.
|
||||
* @param thru The index of the last byte plus one.
|
||||
*/
|
||||
public Kim(final byte[] bytes, final int from, final int thru) {
|
||||
|
||||
@ -88,25 +77,19 @@ public class Kim {
|
||||
/**
|
||||
* Make a kim from a byte array.
|
||||
*
|
||||
* @param bytes
|
||||
* The byte array.
|
||||
* @param length
|
||||
* The number of bytes.
|
||||
* @param bytes The byte array.
|
||||
* @param length The number of bytes.
|
||||
*/
|
||||
public Kim(final byte[] bytes, final int length) {
|
||||
this(bytes, 0, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a new kim from a substring of an existing kim. The coordinates are
|
||||
* in byte units, not character units.
|
||||
* Make a new kim from a substring of an existing kim. The coordinates are in byte units, not character units.
|
||||
*
|
||||
* @param kim
|
||||
* The source of bytes.
|
||||
* @param from
|
||||
* The point at which to take bytes.
|
||||
* @param thru
|
||||
* The point at which to stop taking bytes.
|
||||
* @param kim The source of bytes.
|
||||
* @param from The point at which to take bytes.
|
||||
* @param thru The point at which to stop taking bytes.
|
||||
*/
|
||||
public Kim(final Kim kim, final int from, final int thru) {
|
||||
this(kim.bytes, from, thru);
|
||||
@ -115,10 +98,9 @@ public class Kim {
|
||||
/**
|
||||
* Make a kim from a string.
|
||||
*
|
||||
* @param string
|
||||
* The string.
|
||||
* @throws JSONException
|
||||
* if surrogate pair mismatch.
|
||||
* @param string The string.
|
||||
*
|
||||
* @throws JSONException if surrogate pair mismatch.
|
||||
*/
|
||||
public Kim(final String string) throws JSONException {
|
||||
final int stringLength = string.length();
|
||||
@ -133,11 +115,9 @@ public class Kim {
|
||||
final int c = string.charAt(i);
|
||||
if (c <= 0x7F) {
|
||||
this.length += 1;
|
||||
}
|
||||
else if (c <= 0x3FFF) {
|
||||
} else if (c <= 0x3FFF) {
|
||||
this.length += 2;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ((c >= 0xD800) && (c <= 0xDFFF)) {
|
||||
i += 1;
|
||||
final int d = string.charAt(i);
|
||||
@ -164,8 +144,7 @@ public class Kim {
|
||||
sum += character;
|
||||
this.hashcode += sum;
|
||||
at += 1;
|
||||
}
|
||||
else if (character <= 0x3FFF) {
|
||||
} else if (character <= 0x3FFF) {
|
||||
b = 0x80 | (character >>> 7);
|
||||
this.bytes[at] = (byte) b;
|
||||
sum += b;
|
||||
@ -176,8 +155,7 @@ public class Kim {
|
||||
sum += b;
|
||||
this.hashcode += sum;
|
||||
at += 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ((character >= 0xD800) && (character <= 0xDBFF)) {
|
||||
i += 1;
|
||||
character = (((character & 0x3FF) << 10) | (string.charAt(i) & 0x3FF)) + 65536;
|
||||
@ -204,14 +182,13 @@ public class Kim {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of bytes needed to contain the character in Kim
|
||||
* format.
|
||||
* Returns the number of bytes needed to contain the character in Kim format.
|
||||
*
|
||||
* @param character a Unicode character between 0 and 0x10FFFF.
|
||||
*
|
||||
* @param character
|
||||
* a Unicode character between 0 and 0x10FFFF.
|
||||
* @return 1, 2, or 3
|
||||
* @throws JSONException
|
||||
* if the character is not representable in a kim.
|
||||
*
|
||||
* @throws JSONException if the character is not representable in a kim.
|
||||
*/
|
||||
public static int characterSize(final int character) throws JSONException {
|
||||
if ((character < 0) || (character > 0x10FFFF)) {
|
||||
@ -221,14 +198,12 @@ public class Kim {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the character at the specified index. The index refers to byte
|
||||
* values and ranges from 0 to length - 1. The index of the next character
|
||||
* is at index + Kim.characterSize(kim.characterAt(index)).
|
||||
* Returns the character at the specified index. The index refers to byte values and ranges from 0 to length - 1.
|
||||
* The index of the next character is at index + Kim.characterSize(kim.characterAt(index)).
|
||||
*
|
||||
* @param at
|
||||
* the index of the char value. The first character is at 0.
|
||||
* @throws JSONException
|
||||
* if at does not point to a valid character.
|
||||
* @param at the index of the char value. The first character is at 0.
|
||||
*
|
||||
* @throws JSONException if at does not point to a valid character.
|
||||
* @returns a Unicode character between 0 and 0x10FFFF.
|
||||
*/
|
||||
public int characterAt(final int at) throws JSONException {
|
||||
@ -243,8 +218,7 @@ public class Kim {
|
||||
if (character > 0x7F) {
|
||||
return character;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
final int c2 = get(at + 2);
|
||||
character = ((c & 0x7F) << 14) | ((c1 & 0x7F) << 7) | c2;
|
||||
if (((c2 & 0x80) == 0) && (character > 0x3FFF) && (character <= 0x10FFFF) && ((character < 0xD800) || (character > 0xDFFF))) {
|
||||
@ -257,10 +231,9 @@ public class Kim {
|
||||
/**
|
||||
* Copy the contents of this kim to a byte array.
|
||||
*
|
||||
* @param bytes
|
||||
* A byte array of sufficient size.
|
||||
* @param at
|
||||
* The position within the byte array to take the byes.
|
||||
* @param bytes A byte array of sufficient size.
|
||||
* @param at The position within the byte array to take the byes.
|
||||
*
|
||||
* @return The position immediately after the copy.
|
||||
*/
|
||||
public int copy(final byte[] bytes, final int at) {
|
||||
@ -269,13 +242,11 @@ public class Kim {
|
||||
}
|
||||
|
||||
/**
|
||||
* Two kim objects containing exactly the same bytes in the same order are
|
||||
* equal to each other.
|
||||
* Two kim objects containing exactly the same bytes in the same order are equal to each other.
|
||||
*
|
||||
* @param obj
|
||||
* the other kim with which to compare.
|
||||
* @returns true if this and obj are both kim objects containing identical
|
||||
* byte sequences.
|
||||
* @param obj the other kim with which to compare.
|
||||
*
|
||||
* @returns true if this and obj are both kim objects containing identical byte sequences.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
@ -295,11 +266,11 @@ public class Kim {
|
||||
/**
|
||||
* Get a byte from a kim.
|
||||
*
|
||||
* @param at
|
||||
* The position of the byte. The first byte is at 0.
|
||||
* @param at The position of the byte. The first byte is at 0.
|
||||
*
|
||||
* @return The byte.
|
||||
* @throws JSONException
|
||||
* if there is no byte at that position.
|
||||
*
|
||||
* @throws JSONException if there is no byte at that position.
|
||||
*/
|
||||
public int get(final int at) throws JSONException {
|
||||
if ((at < 0) || (at > this.length)) {
|
||||
@ -317,13 +288,12 @@ public class Kim {
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a UTF-16 String from this kim. The number of codepoints in the
|
||||
* string will not be greater than the number of bytes in the kim, although
|
||||
* it could be less.
|
||||
* Produce a UTF-16 String from this kim. The number of codepoints in the string will not be greater than the number
|
||||
* of bytes in the kim, although it could be less.
|
||||
*
|
||||
* @return The string. A kim memoizes its string representation.
|
||||
* @throws JSONException
|
||||
* if the kim is not valid.
|
||||
*
|
||||
* @throws JSONException if the kim is not valid.
|
||||
*/
|
||||
@Override
|
||||
public String toString() throws JSONException {
|
||||
@ -336,8 +306,7 @@ public class Kim {
|
||||
if (c < 0x10000) {
|
||||
chars[length] = (char) c;
|
||||
length += 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
chars[length] = (char) (0xD800 | ((c - 0x10000) >>> 10));
|
||||
length += 1;
|
||||
chars[length] = (char) (0xDC00 | (c & 0x03FF));
|
||||
|
@ -33,12 +33,12 @@ import java.util.Properties;
|
||||
*/
|
||||
public class Property {
|
||||
/**
|
||||
* Converts a property file object into a JSONObject. The property file
|
||||
* object is a table of name value pairs.
|
||||
* Converts a property file object into a JSONObject. The property file object is a table of name value pairs.
|
||||
*
|
||||
* @param properties java.util.Properties
|
||||
*
|
||||
* @param properties
|
||||
* java.util.Properties
|
||||
* @return JSONObject
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(final java.util.Properties properties) throws JSONException {
|
||||
@ -56,9 +56,10 @@ public class Property {
|
||||
/**
|
||||
* Converts the JSONObject into a property file object.
|
||||
*
|
||||
* @param jo
|
||||
* JSONObject
|
||||
* @param jo JSONObject
|
||||
*
|
||||
* @return java.util.Properties
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static Properties toProperties(final JSONObject jo) throws JSONException {
|
||||
|
@ -3,8 +3,7 @@ package com.intellectualcrafters.json;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* This provides static methods to convert an XML text into a JSONObject,
|
||||
* and to covert a JSONObject into an XML text.
|
||||
* This provides static methods to convert an XML text into a JSONObject, and to covert a JSONObject into an XML text.
|
||||
*
|
||||
* @author JSON.org
|
||||
* @version 2014-05-03
|
||||
@ -59,7 +58,7 @@ public class XML {
|
||||
/**
|
||||
* Replace special characters with XML escapes:
|
||||
* <p/>
|
||||
*
|
||||
* <p/>
|
||||
* <pre>
|
||||
* & <small>(ampersand)</small> is replaced by &amp;
|
||||
* < <small>(less than)</small> is replaced by &lt;
|
||||
@ -67,8 +66,8 @@ public class XML {
|
||||
* " <small>(double quote)</small> is replaced by &quot;
|
||||
* </pre>
|
||||
*
|
||||
* @param string
|
||||
* The string to be escaped.
|
||||
* @param string The string to be escaped.
|
||||
*
|
||||
* @return The escaped string.
|
||||
*/
|
||||
public static String escape(final String string) {
|
||||
@ -99,11 +98,10 @@ public class XML {
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw an exception if the string contains whitespace.
|
||||
* Whitespace is not allowed in tagNames and attributes.
|
||||
* Throw an exception if the string contains whitespace. Whitespace is not allowed in tagNames and attributes.
|
||||
*
|
||||
* @param string A string.
|
||||
*
|
||||
* @param string
|
||||
* A string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static void noSpace(final String string) throws JSONException {
|
||||
@ -122,13 +120,12 @@ public class XML {
|
||||
/**
|
||||
* Scan the content following the named tag, attaching it to the context.
|
||||
*
|
||||
* @param x
|
||||
* The XMLTokener containing the source string.
|
||||
* @param context
|
||||
* The JSONObject that will include the new material.
|
||||
* @param name
|
||||
* The tag name.
|
||||
* @param x The XMLTokener containing the source string.
|
||||
* @param context The JSONObject that will include the new material.
|
||||
* @param name The tag name.
|
||||
*
|
||||
* @return true if the close tag is processed.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
private static boolean parse(final XMLTokener x, final JSONObject context, final String name) throws JSONException {
|
||||
@ -161,8 +158,7 @@ public class XML {
|
||||
return false;
|
||||
}
|
||||
x.back();
|
||||
}
|
||||
else if (c == '[') {
|
||||
} else if (c == '[') {
|
||||
token = x.nextToken();
|
||||
if ("CDATA".equals(token)) {
|
||||
if (x.next() == '[') {
|
||||
@ -180,25 +176,20 @@ public class XML {
|
||||
token = x.nextMeta();
|
||||
if (token == null) {
|
||||
throw x.syntaxError("Missing '>' after '<!'.");
|
||||
}
|
||||
else if (token == LT) {
|
||||
} else if (token == LT) {
|
||||
i += 1;
|
||||
}
|
||||
else if (token == GT) {
|
||||
} else if (token == GT) {
|
||||
i -= 1;
|
||||
}
|
||||
}
|
||||
while (i > 0);
|
||||
} while (i > 0);
|
||||
return false;
|
||||
}
|
||||
else if (token == QUEST) {
|
||||
} else if (token == QUEST) {
|
||||
|
||||
// <?
|
||||
|
||||
x.skipPast("?>");
|
||||
return false;
|
||||
}
|
||||
else if (token == SLASH) {
|
||||
} else if (token == SLASH) {
|
||||
|
||||
// Close tag </
|
||||
|
||||
@ -214,14 +205,12 @@ public class XML {
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
else if (token instanceof Character) {
|
||||
} else if (token instanceof Character) {
|
||||
throw x.syntaxError("Misshaped tag");
|
||||
|
||||
// Open tag <
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
tagName = (String) token;
|
||||
token = null;
|
||||
jsonobject = new JSONObject();
|
||||
@ -242,30 +231,26 @@ public class XML {
|
||||
}
|
||||
jsonobject.accumulate(string, XML.stringToValue((String) token));
|
||||
token = null;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
jsonobject.accumulate(string, "");
|
||||
}
|
||||
|
||||
// Empty tag <.../>
|
||||
|
||||
}
|
||||
else if (token == SLASH) {
|
||||
} else if (token == SLASH) {
|
||||
if (x.nextToken() != GT) {
|
||||
throw x.syntaxError("Misshaped tag");
|
||||
}
|
||||
if (jsonobject.length() > 0) {
|
||||
context.accumulate(tagName, jsonobject);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
context.accumulate(tagName, "");
|
||||
}
|
||||
return false;
|
||||
|
||||
// Content, between <...> and </...>
|
||||
|
||||
}
|
||||
else if (token == GT) {
|
||||
} else if (token == GT) {
|
||||
for (; ; ) {
|
||||
token = x.nextContent();
|
||||
if (token == null) {
|
||||
@ -273,8 +258,7 @@ public class XML {
|
||||
throw x.syntaxError("Unclosed tag " + tagName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (token instanceof String) {
|
||||
} else if (token instanceof String) {
|
||||
string = (String) token;
|
||||
if (string.length() > 0) {
|
||||
jsonobject.accumulate("content", XML.stringToValue(string));
|
||||
@ -282,24 +266,20 @@ public class XML {
|
||||
|
||||
// Nested element
|
||||
|
||||
}
|
||||
else if (token == LT) {
|
||||
} else if (token == LT) {
|
||||
if (parse(x, jsonobject, tagName)) {
|
||||
if (jsonobject.length() == 0) {
|
||||
context.accumulate(tagName, "");
|
||||
}
|
||||
else if ((jsonobject.length() == 1) && (jsonobject.opt("content") != null)) {
|
||||
} else if ((jsonobject.length() == 1) && (jsonobject.opt("content") != null)) {
|
||||
context.accumulate(tagName, jsonobject.opt("content"));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
context.accumulate(tagName, jsonobject);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw x.syntaxError("Misshaped tag");
|
||||
}
|
||||
}
|
||||
@ -307,14 +287,12 @@ public class XML {
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to convert a string into a number, boolean, or null. If the string
|
||||
* can't be converted, return the string. This is much less ambitious than
|
||||
* JSONObject.stringToValue, especially because it does not attempt to
|
||||
* convert plus forms, octal forms, hex forms, or E forms lacking decimal
|
||||
* points.
|
||||
* Try to convert a string into a number, boolean, or null. If the string can't be converted, return the string.
|
||||
* This is much less ambitious than JSONObject.stringToValue, especially because it does not attempt to convert plus
|
||||
* forms, octal forms, hex forms, or E forms lacking decimal points.
|
||||
*
|
||||
* @param string A String.
|
||||
*
|
||||
* @param string
|
||||
* A String.
|
||||
* @return A simple JSON value.
|
||||
*/
|
||||
public static Object stringToValue(final String string) {
|
||||
@ -340,34 +318,30 @@ public class XML {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final Exception ignore) {
|
||||
} catch (final Exception ignore) {
|
||||
try {
|
||||
final Double value = new Double(string);
|
||||
if (value.toString().equals(string)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
catch (final Exception ignoreAlso) {
|
||||
} catch (final Exception ignoreAlso) {
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a
|
||||
* JSONObject. Some information may be lost in this transformation
|
||||
* because JSON is a data format and XML is a document format. XML uses
|
||||
* elements, attributes, and content text, while JSON uses unordered
|
||||
* collections of name/value pairs and arrays of values. JSON does not
|
||||
* does not like to distinguish between elements and attributes.
|
||||
* Sequences of similar elements are represented as JSONArrays. Content
|
||||
* text may be placed in a "content" member. Comments, prologs, DTDs, and
|
||||
* <code><[ [ ]]></code> are ignored.
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONObject. Some information may be lost in
|
||||
* this transformation because JSON is a data format and XML is a document format. XML uses elements, attributes,
|
||||
* and content text, while JSON uses unordered collections of name/value pairs and arrays of values. JSON does not
|
||||
* does not like to distinguish between elements and attributes. Sequences of similar elements are represented as
|
||||
* JSONArrays. Content text may be placed in a "content" member. Comments, prologs, DTDs, and <code><[ [
|
||||
* ]]></code> are ignored.
|
||||
*
|
||||
* @param string The source string.
|
||||
*
|
||||
* @param string
|
||||
* The source string.
|
||||
* @return A JSONObject containing the structured data from the XML string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||
@ -382,9 +356,10 @@ public class XML {
|
||||
/**
|
||||
* Convert a JSONObject into a well-formed, element-normal XML string.
|
||||
*
|
||||
* @param object
|
||||
* A JSONObject.
|
||||
* @param object A JSONObject.
|
||||
*
|
||||
* @return A string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(final Object object) throws JSONException {
|
||||
@ -394,11 +369,11 @@ public class XML {
|
||||
/**
|
||||
* Convert a JSONObject into a well-formed, element-normal XML string.
|
||||
*
|
||||
* @param object
|
||||
* A JSONObject.
|
||||
* @param tagName
|
||||
* The optional name of the enclosing tag.
|
||||
* @param object A JSONObject.
|
||||
* @param tagName The optional name of the enclosing tag.
|
||||
*
|
||||
* @return A string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(Object object, final String tagName) throws JSONException {
|
||||
@ -445,15 +420,13 @@ public class XML {
|
||||
}
|
||||
sb.append(escape(ja.get(i).toString()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sb.append(escape(value.toString()));
|
||||
}
|
||||
|
||||
// Emit an array of similar keys
|
||||
|
||||
}
|
||||
else if (value instanceof JSONArray) {
|
||||
} else if (value instanceof JSONArray) {
|
||||
ja = (JSONArray) value;
|
||||
length = ja.length();
|
||||
for (i = 0; i < length; i += 1) {
|
||||
@ -466,21 +439,18 @@ public class XML {
|
||||
sb.append("</");
|
||||
sb.append(key);
|
||||
sb.append('>');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sb.append(toString(value, key));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ("".equals(value)) {
|
||||
} else if ("".equals(value)) {
|
||||
sb.append('<');
|
||||
sb.append(key);
|
||||
sb.append("/>");
|
||||
|
||||
// Emit a new tag <k>
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sb.append(toString(value, key));
|
||||
}
|
||||
}
|
||||
@ -498,8 +468,7 @@ public class XML {
|
||||
// a place
|
||||
// where XML is lacking, synthesize an <array> element.
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (object.getClass().isArray()) {
|
||||
object = new JSONArray(object);
|
||||
}
|
||||
@ -510,8 +479,7 @@ public class XML {
|
||||
sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
string = (object == null) ? "null" : escape(object.toString());
|
||||
return (tagName == null) ? "\"" + string + "\"" : (string.length() == 0) ? "<" + tagName + "/>" : "<" + tagName + ">" + string + "</" + tagName + ">";
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.intellectualcrafters.json;
|
||||
|
||||
/**
|
||||
* The XMLTokener extends the JSONTokener to provide additional methods
|
||||
* for the parsing of XML texts.
|
||||
* The XMLTokener extends the JSONTokener to provide additional methods for the parsing of XML texts.
|
||||
*
|
||||
* @author JSON.org
|
||||
* @version 2014-05-03
|
||||
@ -10,8 +9,7 @@ package com.intellectualcrafters.json;
|
||||
public class XMLTokener extends JSONTokener {
|
||||
|
||||
/**
|
||||
* The table of entity values. It initially contains Character values for
|
||||
* amp, apos, gt, lt, quot.
|
||||
* The table of entity values. It initially contains Character values for amp, apos, gt, lt, quot.
|
||||
*/
|
||||
public static final java.util.HashMap<String, Character> entity;
|
||||
|
||||
@ -27,8 +25,7 @@ public class XMLTokener extends JSONTokener {
|
||||
/**
|
||||
* Construct an XMLTokener from a string.
|
||||
*
|
||||
* @param s
|
||||
* A source string.
|
||||
* @param s A source string.
|
||||
*/
|
||||
public XMLTokener(final String s) {
|
||||
super(s);
|
||||
@ -38,8 +35,8 @@ public class XMLTokener extends JSONTokener {
|
||||
* Get the text in the CDATA block.
|
||||
*
|
||||
* @return The string up to the <code>]]></code>.
|
||||
* @throws JSONException
|
||||
* If the <code>]]></code> is not found.
|
||||
*
|
||||
* @throws JSONException If the <code>]]></code> is not found.
|
||||
*/
|
||||
public String nextCDATA() throws JSONException {
|
||||
char c;
|
||||
@ -60,12 +57,11 @@ public class XMLTokener extends JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next XML outer token, trimming whitespace. There are two kinds
|
||||
* of tokens: the '<' character which begins a markup tag, and the content
|
||||
* text between markup tags.
|
||||
* Get the next XML outer token, trimming whitespace. There are two kinds of tokens: the '<' character which begins
|
||||
* a markup tag, and the content text between markup tags.
|
||||
*
|
||||
* @return A string, or a '<' Character, or null if there is no more source text.
|
||||
*
|
||||
* @return A string, or a '<' Character, or null if there is no more
|
||||
* source text.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public Object nextContent() throws JSONException {
|
||||
@ -73,8 +69,7 @@ public class XMLTokener extends JSONTokener {
|
||||
StringBuilder sb;
|
||||
do {
|
||||
c = next();
|
||||
}
|
||||
while (Character.isWhitespace(c));
|
||||
} while (Character.isWhitespace(c));
|
||||
if (c == 0) {
|
||||
return null;
|
||||
}
|
||||
@ -89,8 +84,7 @@ public class XMLTokener extends JSONTokener {
|
||||
}
|
||||
if (c == '&') {
|
||||
sb.append(nextEntity(c));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
c = next();
|
||||
@ -98,14 +92,14 @@ public class XMLTokener extends JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the next entity. These entities are translated to Characters:
|
||||
* <code>& ' > < "</code>.
|
||||
* Return the next entity. These entities are translated to Characters: <code>& ' > <
|
||||
* "</code>.
|
||||
*
|
||||
* @param ampersand An ampersand character.
|
||||
*
|
||||
* @param ampersand
|
||||
* An ampersand character.
|
||||
* @return A Character or an entity String if the entity is not recognized.
|
||||
* @throws JSONException
|
||||
* If missing ';' in XML entity.
|
||||
*
|
||||
* @throws JSONException If missing ';' in XML entity.
|
||||
*/
|
||||
public Object nextEntity(final char ampersand) throws JSONException {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
@ -113,11 +107,9 @@ public class XMLTokener extends JSONTokener {
|
||||
final char c = next();
|
||||
if (Character.isLetterOrDigit(c) || (c == '#')) {
|
||||
sb.append(Character.toLowerCase(c));
|
||||
}
|
||||
else if (c == ';') {
|
||||
} else if (c == ';') {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw syntaxError("Missing ';' in XML entity: &" + sb);
|
||||
}
|
||||
}
|
||||
@ -127,24 +119,19 @@ public class XMLTokener extends JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next XML meta token. This is used for skipping over <!...>
|
||||
* and <?...?> structures.
|
||||
* Returns the next XML meta token. This is used for skipping over <!...> and <?...?> structures.
|
||||
*
|
||||
* @return Syntax characters (<code>< > / = ! ?</code>) are returned as
|
||||
* Character, and strings and names are returned as Boolean. We
|
||||
* don't care
|
||||
* what the values actually are.
|
||||
* @throws JSONException
|
||||
* If a string is not properly closed or if the XML
|
||||
* is badly structured.
|
||||
* @return Syntax characters (<code>< > / = ! ?</code>) are returned as Character, and strings and names are
|
||||
* returned as Boolean. We don't care what the values actually are.
|
||||
*
|
||||
* @throws JSONException If a string is not properly closed or if the XML is badly structured.
|
||||
*/
|
||||
public Object nextMeta() throws JSONException {
|
||||
char c;
|
||||
char q;
|
||||
do {
|
||||
c = next();
|
||||
}
|
||||
while (Character.isWhitespace(c));
|
||||
} while (Character.isWhitespace(c));
|
||||
switch (c) {
|
||||
case 0:
|
||||
throw syntaxError("Misshaped meta tag");
|
||||
@ -196,14 +183,12 @@ public class XMLTokener extends JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next XML Token. These tokens are found inside of angle
|
||||
* brackets. It may be one of these characters: <code>/ > = ! ?</code> or it
|
||||
* may be a string wrapped in single quotes or double quotes, or it may be a
|
||||
* name.
|
||||
* Get the next XML Token. These tokens are found inside of angle brackets. It may be one of these characters:
|
||||
* <code>/ > = ! ?</code> or it may be a string wrapped in single quotes or double quotes, or it may be a name.
|
||||
*
|
||||
* @return a String or a Character.
|
||||
* @throws JSONException
|
||||
* If the XML is not well formed.
|
||||
*
|
||||
* @throws JSONException If the XML is not well formed.
|
||||
*/
|
||||
public Object nextToken() throws JSONException {
|
||||
char c;
|
||||
@ -211,8 +196,7 @@ public class XMLTokener extends JSONTokener {
|
||||
StringBuilder sb;
|
||||
do {
|
||||
c = next();
|
||||
}
|
||||
while (Character.isWhitespace(c));
|
||||
} while (Character.isWhitespace(c));
|
||||
switch (c) {
|
||||
case 0:
|
||||
throw syntaxError("Misshaped element");
|
||||
@ -245,8 +229,7 @@ public class XMLTokener extends JSONTokener {
|
||||
}
|
||||
if (c == '&') {
|
||||
sb.append(nextEntity(c));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
@ -283,12 +266,11 @@ public class XMLTokener extends JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip characters until past the requested string.
|
||||
* If it is not found, we are left at the end of the source with a result of
|
||||
* false.
|
||||
* Skip characters until past the requested string. If it is not found, we are left at the end of the source with a
|
||||
* result of false.
|
||||
*
|
||||
* @param to A string to skip past.
|
||||
*
|
||||
* @param to
|
||||
* A string to skip past.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public boolean skipPast(final String to) throws JSONException {
|
||||
|
@ -71,9 +71,8 @@ import java.util.concurrent.TimeUnit;
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PlotMain extends JavaPlugin {
|
||||
|
||||
@SuppressWarnings("unused") public class PlotMain extends JavaPlugin {
|
||||
private static PlotMain main = null;
|
||||
/**
|
||||
* Permission that allows for "everything"
|
||||
*/
|
||||
@ -86,6 +85,7 @@ public class PlotMain extends JavaPlugin {
|
||||
* Boolean Flags (material)
|
||||
*/
|
||||
public final static HashMap<Material, String> booleanFlags = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Initialize the material flags
|
||||
*/
|
||||
@ -103,6 +103,7 @@ public class PlotMain extends JavaPlugin {
|
||||
booleanFlags.put(Material.DISPENSER, "dispenser");
|
||||
booleanFlags.put(Material.DROPPER, "dropper");
|
||||
}
|
||||
|
||||
/**
|
||||
* All loaded plot worlds
|
||||
*/
|
||||
@ -155,10 +156,6 @@ public class PlotMain extends JavaPlugin {
|
||||
* Use Economy?
|
||||
*/
|
||||
public static boolean useEconomy = false;
|
||||
/**
|
||||
* The instance
|
||||
*/
|
||||
private static PlotMain main = null;
|
||||
/**
|
||||
* The UUID Saver
|
||||
*/
|
||||
@ -168,8 +165,7 @@ public class PlotMain extends JavaPlugin {
|
||||
*/
|
||||
private static MySQL mySQL;
|
||||
/**
|
||||
* List of all plots
|
||||
* DO NOT USE EXCEPT FOR DATABASE PURPOSES
|
||||
* List of all plots DO NOT USE EXCEPT FOR DATABASE PURPOSES
|
||||
*/
|
||||
private static LinkedHashMap<String, HashMap<PlotId, Plot>> plots;
|
||||
|
||||
@ -190,8 +186,7 @@ public class PlotMain extends JavaPlugin {
|
||||
public void run() {
|
||||
try {
|
||||
checkExpired(plugin, true);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -199,19 +194,19 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a range of permissions e.g. 'plots.plot.<0-100>'<br>
|
||||
* Returns highest integer in range.
|
||||
* Check a range of permissions e.g. 'plots.plot.<0-100>'<br> Returns highest integer in range.
|
||||
*
|
||||
* @param player to check
|
||||
* @param stub to check
|
||||
* @param range tp check
|
||||
*
|
||||
* @param player
|
||||
* to check
|
||||
* @param stub
|
||||
* to check
|
||||
* @param range
|
||||
* tp check
|
||||
* @return permitted range
|
||||
*/
|
||||
public static int hasPermissionRange(final Player player, final String stub, final int range) {
|
||||
if (player == null || player.isOp() || player.hasPermission(ADMIN_PERMISSION) || player.hasPermission(stub + ".*")) {
|
||||
if ((player == null) || player.isOp() || player.hasPermission(ADMIN_PERMISSION)) {
|
||||
return Byte.MAX_VALUE;
|
||||
}
|
||||
if (player.hasPermission(stub + ".*")) {
|
||||
return Byte.MAX_VALUE;
|
||||
}
|
||||
for (int i = range; i > 0; i--) {
|
||||
@ -223,14 +218,11 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a player for a permission<br>
|
||||
* - Op has all permissions <br>
|
||||
* - checks for '*' nodes
|
||||
* Check a player for a permission<br> - Op has all permissions <br> - checks for '*' nodes
|
||||
*
|
||||
* @param player to check
|
||||
* @param perms to check
|
||||
*
|
||||
* @param player
|
||||
* to check
|
||||
* @param perms
|
||||
* to check
|
||||
* @return true of player has permissions
|
||||
*/
|
||||
public static boolean hasPermissions(final Player player, final String[] perms) {
|
||||
@ -242,8 +234,7 @@ public class PlotMain extends JavaPlugin {
|
||||
boolean permitted = false;
|
||||
if (player.hasPermission(perm)) {
|
||||
permitted = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
final String[] nodes = perm.split("\\.");
|
||||
final StringBuilder n = new StringBuilder();
|
||||
for (int i = 0; i < (nodes.length - 1); i++) {
|
||||
@ -266,6 +257,7 @@ public class PlotMain extends JavaPlugin {
|
||||
* Get the uuid saver
|
||||
*
|
||||
* @return uuid saver
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.uuid.UUIDSaver;
|
||||
*/
|
||||
public static UUIDSaver getUUIDSaver() {
|
||||
@ -275,8 +267,8 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* Set the uuid saver
|
||||
*
|
||||
* @param saver
|
||||
* new saver
|
||||
* @param saver new saver
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.uuid.UUIDSaver
|
||||
*/
|
||||
public static void setUUIDSaver(final UUIDSaver saver) {
|
||||
@ -284,14 +276,11 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a player for a permission<br>
|
||||
* - Op has all permissions <br>
|
||||
* - checks for '*' nodes
|
||||
* Check a player for a permission<br> - Op has all permissions <br> - checks for '*' nodes
|
||||
*
|
||||
* @param player to check
|
||||
* @param perm to check
|
||||
*
|
||||
* @param player
|
||||
* to check
|
||||
* @param perm
|
||||
* to check
|
||||
* @return true if player has the permission
|
||||
*/
|
||||
public static boolean hasPermission(final Player player, final String perm) {
|
||||
@ -340,8 +329,8 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* player
|
||||
* @param player player
|
||||
*
|
||||
* @return Set Containing the players plots
|
||||
*/
|
||||
public static Set<Plot> getPlots(final Player player) {
|
||||
@ -360,15 +349,14 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* plot world
|
||||
* @param player
|
||||
* plot owner
|
||||
* @param world plot world
|
||||
* @param player plot owner
|
||||
*
|
||||
* @return players plots
|
||||
*/
|
||||
public static Set<Plot> getPlots(final World world, final Player player) {
|
||||
final UUID uuid = UUIDHandler.getUUID(player);
|
||||
final List<Plot> myplots = new ArrayList<>();
|
||||
final ArrayList<Plot> myplots = new ArrayList<>();
|
||||
for (final Plot plot : getPlots(world).values()) {
|
||||
if (plot.hasOwner()) {
|
||||
if (plot.getOwner().equals(uuid)) {
|
||||
@ -382,8 +370,8 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* Get plots for the specified world
|
||||
*
|
||||
* @param world
|
||||
* A world, in which you want to search for plots
|
||||
* @param world A world, in which you want to search for plots
|
||||
*
|
||||
* @return HashMap containing Plot IDs and Plot Objects
|
||||
*/
|
||||
public static HashMap<PlotId, Plot> getPlots(final String world) {
|
||||
@ -394,8 +382,8 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* plot world
|
||||
* @param world plot world
|
||||
*
|
||||
* @return plots in world
|
||||
*/
|
||||
public static HashMap<PlotId, Plot> getPlots(final World world) {
|
||||
@ -422,8 +410,8 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* plotworld(?)
|
||||
* @param world plotworld(?)
|
||||
*
|
||||
* @return true if the world is a plotworld
|
||||
*/
|
||||
public static boolean isPlotWorld(final World world) {
|
||||
@ -431,8 +419,8 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* plotworld(?)
|
||||
* @param world plotworld(?)
|
||||
*
|
||||
* @return true if the world is a plotworld
|
||||
*/
|
||||
public static boolean isPlotWorld(final String world) {
|
||||
@ -440,8 +428,8 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* World to get manager for
|
||||
* @param world World to get manager for
|
||||
*
|
||||
* @return manager for world
|
||||
*/
|
||||
public static PlotManager getPlotManager(final World world) {
|
||||
@ -452,8 +440,8 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* world
|
||||
* @param world world
|
||||
*
|
||||
* @return PlotManager
|
||||
*/
|
||||
public static PlotManager getPlotManager(final String world) {
|
||||
@ -464,8 +452,8 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* to search
|
||||
* @param world to search
|
||||
*
|
||||
* @return PlotWorld object
|
||||
*/
|
||||
public static PlotWorld getWorldSettings(final World world) {
|
||||
@ -476,8 +464,8 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* to search
|
||||
* @param world to search
|
||||
*
|
||||
* @return PlotWorld object
|
||||
*/
|
||||
public static PlotWorld getWorldSettings(final String world) {
|
||||
@ -488,8 +476,8 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* world to search
|
||||
* @param world world to search
|
||||
*
|
||||
* @return set containing the plots for a world
|
||||
*/
|
||||
public static Plot[] getWorldPlots(final World world) {
|
||||
@ -500,12 +488,10 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* Remove a plot
|
||||
*
|
||||
* @param world
|
||||
* The Plot World
|
||||
* @param id
|
||||
* The Plot ID
|
||||
* @param callEvent
|
||||
* Whether or not to call the PlotDeleteEvent
|
||||
* @param world The Plot World
|
||||
* @param id The Plot ID
|
||||
* @param callEvent Whether or not to call the PlotDeleteEvent
|
||||
*
|
||||
* @return true if successful, false if not
|
||||
*/
|
||||
public static boolean removePlot(final String world, final PlotId id, final boolean callEvent) {
|
||||
@ -524,8 +510,7 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* Replace the plot object with an updated version
|
||||
*
|
||||
* @param plot
|
||||
* plot object
|
||||
* @param plot plot object
|
||||
*/
|
||||
public static void updatePlot(final Plot plot) {
|
||||
final String world = plot.world;
|
||||
@ -537,30 +522,16 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: <b>Implement better system The whole point of this system is to
|
||||
* recycle old plots</b> <br>
|
||||
* So why not just allow users to claim old plots, and try to hide the fact
|
||||
* that the are owned. <br>
|
||||
* <br>
|
||||
* Reduce amount of expired plots: <br>
|
||||
* - On /plot <br>
|
||||
* auto<br>
|
||||
* - allow claiming of old plot, clear it so the user doesn't know<br>
|
||||
* - On /plot info,<br>
|
||||
* - show that the plot is expired and allowed to be claimed Have the task
|
||||
* run less often:<br>
|
||||
* - Run the task when there are very little, or no players online (great
|
||||
* for small servers)<br>
|
||||
* - Run the task at startup (also only useful for small servers)<br>
|
||||
* Also, in terms of faster code:<br>
|
||||
* - Have an array of plots, sorted by expiry time.<br>
|
||||
* - Add new plots to the end.<br>
|
||||
* - The task then only needs to go through the first few plots
|
||||
* TODO: <b>Implement better system The whole point of this system is to recycle old plots</b> <br> So why not just
|
||||
* allow users to claim old plots, and try to hide the fact that the are owned. <br> <br> Reduce amount of expired
|
||||
* plots: <br> - On /plot <br> auto<br> - allow claiming of old plot, clear it so the user doesn't know<br> - On
|
||||
* /plot info,<br> - show that the plot is expired and allowed to be claimed Have the task run less often:<br> - Run
|
||||
* the task when there are very little, or no players online (great for small servers)<br> - Run the task at startup
|
||||
* (also only useful for small servers)<br> Also, in terms of faster code:<br> - Have an array of plots, sorted by
|
||||
* expiry time.<br> - Add new plots to the end.<br> - The task then only needs to go through the first few plots
|
||||
*
|
||||
* @param plugin
|
||||
* Plugin
|
||||
* @param async
|
||||
* Call async?
|
||||
* @param plugin Plugin
|
||||
* @param async Call async?
|
||||
*/
|
||||
private static void checkExpired(final JavaPlugin plugin, final boolean async) {
|
||||
if (async) {
|
||||
@ -586,8 +557,7 @@ public class PlotMain extends JavaPlugin {
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
toDeletePlot.add(plot);
|
||||
}
|
||||
}
|
||||
@ -606,8 +576,7 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (final String world : getPlotWorldsString()) {
|
||||
if (PlotMain.plots.containsKey(world)) {
|
||||
for (final Plot plot : PlotMain.plots.get(world).values()) {
|
||||
@ -616,8 +585,7 @@ public class PlotMain extends JavaPlugin {
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
DBFunc.delete(world, plot);
|
||||
}
|
||||
}
|
||||
@ -648,42 +616,23 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* Send a message to the console.
|
||||
*
|
||||
* @param string
|
||||
* message
|
||||
* @param string message
|
||||
*/
|
||||
public static void sendConsoleSenderMessage(final String string) {
|
||||
if (getMain().getServer().getConsoleSender() == null) {
|
||||
System.out.println(ChatColor.stripColor(ConsoleColors.fromString(string)));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
getMain().getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', string));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a formatted message
|
||||
* <p/>
|
||||
* Replaced {0}, {1}...
|
||||
*
|
||||
* @param string To be formatted
|
||||
* @param objs To replace with (using #toString())
|
||||
*/
|
||||
public static void sendConsoleSenderMessagef(String string, final Object... objs) {
|
||||
for (int i = 0; i < objs.length; i++) {
|
||||
string = string.replace("{" + i + "}", objs[i].toString());
|
||||
}
|
||||
sendConsoleSenderMessage(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player to a plot
|
||||
*
|
||||
* @param player
|
||||
* Player to teleport
|
||||
* @param from
|
||||
* Previous Location
|
||||
* @param plot
|
||||
* Plot to teleport to
|
||||
* @param player Player to teleport
|
||||
* @param from Previous Location
|
||||
* @param plot Plot to teleport to
|
||||
*
|
||||
* @return true if successful
|
||||
*/
|
||||
public static boolean teleportPlayer(final Player player, final Location from, final Plot plot) {
|
||||
@ -704,8 +653,7 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* Send a message to the console
|
||||
*
|
||||
* @param c
|
||||
* message
|
||||
* @param c message
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static void sendConsoleSenderMessage(final C c) {
|
||||
@ -715,8 +663,7 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* Broadcast publicly
|
||||
*
|
||||
* @param c
|
||||
* message
|
||||
* @param c message
|
||||
*/
|
||||
public static void Broadcast(final C c) {
|
||||
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + c.s()));
|
||||
@ -734,8 +681,7 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* Broadcast a message to all admins
|
||||
*
|
||||
* @param c
|
||||
* message
|
||||
* @param c message
|
||||
*/
|
||||
public static void BroadcastWithPerms(final C c) {
|
||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||
@ -758,8 +704,8 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* Ge the last played time
|
||||
*
|
||||
* @param uuid
|
||||
* UUID for the player
|
||||
* @param uuid UUID for the player
|
||||
*
|
||||
* @return last play time as a long
|
||||
*/
|
||||
public static long getLastPlayed(final UUID uuid) {
|
||||
@ -791,8 +737,7 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
setupConfig();
|
||||
}
|
||||
catch (final Exception err_trans) {
|
||||
} catch (final Exception err_trans) {
|
||||
Logger.add(LogLevel.DANGER, "Failed to save settings.yml");
|
||||
System.out.println("Failed to save settings.yml");
|
||||
}
|
||||
@ -805,16 +750,14 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
storage = YamlConfiguration.loadConfiguration(storageFile);
|
||||
setupStorage();
|
||||
}
|
||||
catch (final Exception err_trans) {
|
||||
} catch (final Exception err_trans) {
|
||||
Logger.add(LogLevel.DANGER, "Failed to save storage.yml");
|
||||
System.out.println("Failed to save storage.yml");
|
||||
}
|
||||
try {
|
||||
config.save(configFile);
|
||||
storage.save(storageFile);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
} catch (final IOException e) {
|
||||
Logger.add(LogLevel.DANGER, "Configuration file saving failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -848,22 +791,11 @@ public class PlotMain extends JavaPlugin {
|
||||
settings.put("Schematics Save Path", "" + Settings.SCHEMATIC_SAVE_PATH);
|
||||
settings.put("API Location", "" + Settings.API_URL);
|
||||
for (final Entry<String, String> setting : settings.entrySet()) {
|
||||
sendConsoleSenderMessagef("{0} &cKey: &6{1}&c, Value: &c{2}", C.PREFIX, setting.getKey(), setting.getValue());
|
||||
sendConsoleSenderMessage(C.PREFIX.s() + String.format("&cKey: &6%s&c, Value: &6%s", setting.getKey(), setting.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance
|
||||
*
|
||||
* @return instance
|
||||
*/
|
||||
public static PlotMain getInstance() {
|
||||
if (main == null)
|
||||
throw new UnsupportedOperationException("Cannot retrieve the PlotMain instance before it's created");
|
||||
return main;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill all entities on roads
|
||||
*/
|
||||
@ -881,7 +813,7 @@ public class PlotMain extends JavaPlugin {
|
||||
public void run() {
|
||||
if (this.ticked > 36_000L) {
|
||||
this.ticked = 0l;
|
||||
sendConsoleSenderMessagef("{0} KillAllEntities has been running for 60 minutes. Errors: {1}", C.PREFIX, this.error);
|
||||
sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities has been running for 60 minutes. Errors: " + this.error);
|
||||
this.error = 0l;
|
||||
}
|
||||
for (final String w : getPlotWorlds()) {
|
||||
@ -960,11 +892,9 @@ public class PlotMain extends JavaPlugin {
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final Throwable e) {
|
||||
} catch (final Throwable e) {
|
||||
++this.error;
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
++this.ticked;
|
||||
}
|
||||
}
|
||||
@ -1032,8 +962,7 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* Create a plotworld config section
|
||||
*
|
||||
* @param plotworld
|
||||
* World to create the section for
|
||||
* @param plotworld World to create the section for
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static void createConfiguration(final PlotWorld plotworld) {
|
||||
@ -1051,8 +980,7 @@ public class PlotMain extends JavaPlugin {
|
||||
|
||||
try {
|
||||
config.save(PlotMain.configFile);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
} catch (final IOException e) {
|
||||
PlotMain.sendConsoleSenderMessage("&c[Warning] PlotSquared failed to save the configuration&7 (settings.yml may differ from the one in memory)\n - To force a save from console use /plots save");
|
||||
}
|
||||
}
|
||||
@ -1088,15 +1016,13 @@ public class PlotMain extends JavaPlugin {
|
||||
|
||||
try {
|
||||
config.save(configFile);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Now add it
|
||||
addPlotWorld(world, plotWorld, plotManager);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (worlds.contains(world)) {
|
||||
sendConsoleSenderMessage("&cWorld '" + world + "' in settings.yml is not using PlotSquared generator!");
|
||||
|
||||
@ -1112,8 +1038,7 @@ public class PlotMain extends JavaPlugin {
|
||||
|
||||
try {
|
||||
config.save(configFile);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@ -1124,13 +1049,11 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an external world as a recognized PlotSquared world - The PlotWorld
|
||||
* class created is based off the configuration in the settings.yml - Do not
|
||||
* use this method unless the required world is preconfigured in the
|
||||
* Adds an external world as a recognized PlotSquared world - The PlotWorld class created is based off the
|
||||
* configuration in the settings.yml - Do not use this method unless the required world is preconfigured in the
|
||||
* settings.yml
|
||||
*
|
||||
* @param world
|
||||
* to load
|
||||
* @param world to load
|
||||
*/
|
||||
public static void loadWorld(final World world) {
|
||||
if (world == null) {
|
||||
@ -1190,17 +1113,14 @@ public class PlotMain extends JavaPlugin {
|
||||
seconds = 1;
|
||||
try {
|
||||
amount = Integer.parseInt(values[0]);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
try {
|
||||
amount = Integer.parseInt(values[0]);
|
||||
seconds = Integer.parseInt(values[1]);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1327,8 +1247,7 @@ public class PlotMain extends JavaPlugin {
|
||||
public String parseValue(final String value) {
|
||||
try {
|
||||
return Long.parseLong(value) + "";
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1366,12 +1285,9 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* Add a Plot world
|
||||
*
|
||||
* @param world
|
||||
* World to add
|
||||
* @param plotworld
|
||||
* PlotWorld Object
|
||||
* @param manager
|
||||
* Plot Manager for the new world
|
||||
* @param world World to add
|
||||
* @param plotworld PlotWorld Object
|
||||
* @param manager Plot Manager for the new world
|
||||
*/
|
||||
public static void addPlotWorld(final String world, final PlotWorld plotworld, final PlotManager manager) {
|
||||
worlds.put(world, plotworld);
|
||||
@ -1384,8 +1300,7 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* Remove a plot world
|
||||
*
|
||||
* @param world
|
||||
* World to remove
|
||||
* @param world World to remove
|
||||
*/
|
||||
public static void removePlotWorld(final String world) {
|
||||
plots.remove(world);
|
||||
@ -1405,22 +1320,20 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* Set all plots
|
||||
*
|
||||
* @param plots
|
||||
* New Plot HashMap
|
||||
* @param plots New Plot LinkedHashMap
|
||||
*/
|
||||
public static void setAllPlotsRaw(final HashMap<String, HashMap<PlotId, Plot>> plots) {
|
||||
PlotMain.plots = new LinkedHashMap<>(plots);
|
||||
// PlotMain.plots.putAll(plots);
|
||||
public static void setAllPlotsRaw(final LinkedHashMap<String, HashMap<PlotId, Plot>> plots) {
|
||||
PlotMain.plots = plots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all plots
|
||||
*
|
||||
* @param plots
|
||||
* New Plot LinkedHashMap
|
||||
* @param plots New Plot HashMap
|
||||
*/
|
||||
public static void setAllPlotsRaw(final LinkedHashMap<String, HashMap<PlotId, Plot>> plots) {
|
||||
PlotMain.plots = plots;
|
||||
public static void setAllPlotsRaw(final HashMap<String, HashMap<PlotId, Plot>> plots) {
|
||||
PlotMain.plots = new LinkedHashMap<>(plots);
|
||||
// PlotMain.plots.putAll(plots);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1448,8 +1361,7 @@ public class PlotMain extends JavaPlugin {
|
||||
writer.write("Created at: " + new Date().toString() + "\n\n\n");
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
catch (final IOException e) {
|
||||
} catch (final IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -1476,8 +1388,7 @@ public class PlotMain extends JavaPlugin {
|
||||
sendConsoleSenderMessage(C.PREFIX.s() + "&cURL: &6https://java.com/en/download/index.jsp");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
else if (getJavaVersion() < 1.8) {
|
||||
} else if (getJavaVersion() < 1.8) {
|
||||
sendConsoleSenderMessage(C.PREFIX.s() + "&cIt's really recommended to run Java 1.8, as it increases performance");
|
||||
}
|
||||
// Setup configuration
|
||||
@ -1488,12 +1399,10 @@ public class PlotMain extends JavaPlugin {
|
||||
final Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
sendConsoleSenderMessage(C.PREFIX.s() + "&6Metrics enabled.");
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to load up metrics.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// We should at least make them feel bad.
|
||||
sendConsoleSenderMessage("Using metrics will allow us to improve the plugin\nPlease consider it :)");
|
||||
}
|
||||
@ -1521,8 +1430,7 @@ public class PlotMain extends JavaPlugin {
|
||||
ResultSet res = meta.getTables(null, null, Settings.DB.PREFIX + "plot", null);
|
||||
if (!res.next()) {
|
||||
DBFunc.createTables("mysql", true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (final String table : tables) {
|
||||
res = meta.getTables(null, null, Settings.DB.PREFIX + table, null);
|
||||
if (!res.next()) {
|
||||
@ -1532,8 +1440,7 @@ public class PlotMain extends JavaPlugin {
|
||||
// We should not repeat our self :P
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
Logger.add(LogLevel.DANGER, "MySQL connection failed.");
|
||||
sendConsoleSenderMessage("&c[Plots] MySQL is not setup correctly. The plugin will disable itself.");
|
||||
if ((config == null) || config.getBoolean("debug")) {
|
||||
@ -1551,8 +1458,7 @@ public class PlotMain extends JavaPlugin {
|
||||
else if (Settings.DB.USE_MONGO) {
|
||||
// DBFunc.dbManager = new MongoManager();
|
||||
sendConsoleSenderMessage(C.PREFIX.s() + "MongoDB is not yet implemented");
|
||||
}
|
||||
else if (Settings.DB.USE_SQLITE) {
|
||||
} else if (Settings.DB.USE_SQLITE) {
|
||||
try {
|
||||
connection = new SQLite(this, Settings.DB.SQLITE_DB + ".db").openConnection();
|
||||
{
|
||||
@ -1561,8 +1467,7 @@ public class PlotMain extends JavaPlugin {
|
||||
ResultSet res = meta.getTables(null, null, Settings.DB.PREFIX + "plot", null);
|
||||
if (!res.next()) {
|
||||
DBFunc.createTables("sqlite", true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (final String table : tables) {
|
||||
res = meta.getTables(null, null, Settings.DB.PREFIX + table, null);
|
||||
if (!res.next()) {
|
||||
@ -1571,8 +1476,7 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
Logger.add(LogLevel.DANGER, "SQLite connection failed");
|
||||
sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to open SQLite connection. The plugin will disable itself.");
|
||||
sendConsoleSenderMessage("&9==== Here is an ugly stacktrace, if you are interested in those things ===");
|
||||
@ -1581,8 +1485,7 @@ public class PlotMain extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
plots = DBFunc.getPlots();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Logger.add(LogLevel.DANGER, "No storage type is set.");
|
||||
sendConsoleSenderMessage(C.PREFIX + "&cNo storage type is set!");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
@ -1595,8 +1498,7 @@ public class PlotMain extends JavaPlugin {
|
||||
if (getServer().getPluginManager().getPlugin("PlotMe") != null) {
|
||||
try {
|
||||
new PlotMeConverter(this).runAsync();
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -1636,8 +1538,7 @@ public class PlotMain extends JavaPlugin {
|
||||
PlotMain.sendConsoleSenderMessage("&cThis version of WorldEdit does not support PlotSquared.");
|
||||
PlotMain.sendConsoleSenderMessage("&cPlease use WorldEdit 6+");
|
||||
PlotMain.sendConsoleSenderMessage("&c - http://builds.enginehub.org/job/worldedit");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
getServer().getPluginManager().registerEvents(new WorldEditListener(), this);
|
||||
}
|
||||
}
|
||||
@ -1671,16 +1572,14 @@ public class PlotMain extends JavaPlugin {
|
||||
try {
|
||||
new SetBlockFast();
|
||||
PlotHelper.canSetFast = true;
|
||||
}
|
||||
catch (final Throwable e) {
|
||||
} catch (final Throwable e) {
|
||||
PlotHelper.canSetFast = false;
|
||||
}
|
||||
|
||||
try {
|
||||
new SendChunk();
|
||||
PlotHelper.canSendChunk = true;
|
||||
}
|
||||
catch (final Throwable e) {
|
||||
} catch (final Throwable e) {
|
||||
PlotHelper.canSendChunk = false;
|
||||
}
|
||||
}
|
||||
@ -1694,6 +1593,7 @@ public class PlotMain extends JavaPlugin {
|
||||
UUIDHandler.uuidWrapper = new OfflineUUIDWrapper();
|
||||
}
|
||||
setUUIDSaver(new PlotUUIDSaver());
|
||||
// Looks really cool xD
|
||||
getUUIDSaver().globalPopulate();
|
||||
}
|
||||
// Now we're finished :D
|
||||
@ -1709,8 +1609,7 @@ public class PlotMain extends JavaPlugin {
|
||||
final public void onDisable() {
|
||||
try {
|
||||
C.saveTranslations();
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
sendConsoleSenderMessage("Failed to save translations");
|
||||
Logger.add(LogLevel.DANGER, "Failed to save translations");
|
||||
e.printStackTrace();
|
||||
@ -1718,15 +1617,13 @@ public class PlotMain extends JavaPlugin {
|
||||
Logger.add(LogLevel.GENERAL, "Logger disabled");
|
||||
try {
|
||||
Logger.write();
|
||||
}
|
||||
catch (final IOException e1) {
|
||||
} catch (final IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
connection.close();
|
||||
mySQL.closeConnection();
|
||||
}
|
||||
catch (NullPointerException | SQLException e) {
|
||||
} catch (NullPointerException | SQLException e) {
|
||||
if (connection != null) {
|
||||
Logger.add(LogLevel.DANGER, "Could not close mysql connection");
|
||||
}
|
||||
|
@ -21,16 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||
import com.intellectualcrafters.plot.commands.SubCommand;
|
||||
@ -41,29 +31,31 @@ import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.PlotSquaredException;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* PlotSquared API
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*
|
||||
* @version API 2.0
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PlotAPI {
|
||||
@SuppressWarnings("unused") public class PlotAPI {
|
||||
|
||||
/**
|
||||
* Permission that allows for admin access,
|
||||
* this permission node will allow the player
|
||||
* to use any part of the plugin, without limitations.
|
||||
* Permission that allows for admin access, this permission node will allow the player to use any part of the
|
||||
* plugin, without limitations.
|
||||
*/
|
||||
public static final String ADMIN_PERMISSION = "plots.admin";
|
||||
|
||||
@ -78,7 +70,7 @@ public class PlotAPI {
|
||||
|
||||
/**
|
||||
* Player Functions
|
||||
*
|
||||
* <p/>
|
||||
* General functions involving players, and plot worlds
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions
|
||||
@ -87,7 +79,7 @@ public class PlotAPI {
|
||||
|
||||
/**
|
||||
* Flag Manager
|
||||
*
|
||||
* <p/>
|
||||
* The manager which handles all flags
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.flag.FlagManager
|
||||
@ -96,7 +88,7 @@ public class PlotAPI {
|
||||
|
||||
/**
|
||||
* Schematic Handler
|
||||
*
|
||||
* <p/>
|
||||
* The handler which is used to create, and paste, schematics
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.SchematicHandler
|
||||
@ -112,7 +104,7 @@ public class PlotAPI {
|
||||
|
||||
/**
|
||||
* PlotMain instance
|
||||
*
|
||||
* <p/>
|
||||
* This is the instance that allows for most methods to be used.
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PlotMain
|
||||
@ -120,13 +112,12 @@ public class PlotAPI {
|
||||
private final PlotMain plotMain;
|
||||
|
||||
/**
|
||||
* Constructor. Insert any Plugin.
|
||||
* (Optimally the plugin that is accessing the method)
|
||||
* Constructor. Insert any Plugin. (Optimally the plugin that is accessing the method)
|
||||
*
|
||||
* @param plugin
|
||||
* Plugin used to access this method
|
||||
* @throws com.intellectualcrafters.plot.util.PlotSquaredException
|
||||
* if the program fails to fetch the PlotMain instance
|
||||
* @param plugin Plugin used to access this method
|
||||
*
|
||||
* @throws com.intellectualcrafters.plot.util.PlotSquaredException if the program fails to fetch the PlotMain
|
||||
* instance
|
||||
* @see com.intellectualcrafters.plot.PlotMain
|
||||
*/
|
||||
public PlotAPI(@NotNull final JavaPlugin plugin) {
|
||||
@ -140,6 +131,7 @@ public class PlotAPI {
|
||||
* Get all plots
|
||||
*
|
||||
* @return all plots
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PlotMain#getPlots()
|
||||
*/
|
||||
public Set<Plot> getAllPlots() {
|
||||
@ -149,8 +141,8 @@ public class PlotAPI {
|
||||
/**
|
||||
* Return all plots for a player
|
||||
*
|
||||
* @param player
|
||||
* Player, whose plots to search for
|
||||
* @param player Player, whose plots to search for
|
||||
*
|
||||
* @return all plots that a player owns
|
||||
*/
|
||||
public Set<Plot> getPlayerPlots(@NotNull final Player player) {
|
||||
@ -160,14 +152,11 @@ public class PlotAPI {
|
||||
/**
|
||||
* Add a plot world
|
||||
*
|
||||
* @param world
|
||||
* World Name
|
||||
* @param plotWorld
|
||||
* Plot World Object
|
||||
* @param manager
|
||||
* World Manager
|
||||
* @see com.intellectualcrafters.plot.PlotMain#addPlotWorld(String,
|
||||
* com.intellectualcrafters.plot.object.PlotWorld,
|
||||
* @param world World Name
|
||||
* @param plotWorld Plot World Object
|
||||
* @param manager World Manager
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PlotMain#addPlotWorld(String, com.intellectualcrafters.plot.object.PlotWorld,
|
||||
* com.intellectualcrafters.plot.object.PlotManager)
|
||||
*/
|
||||
public void addPlotWorld(@NotNull final String world, @NotNull final PlotWorld plotWorld, @NotNull final PlotManager manager) {
|
||||
@ -176,6 +165,7 @@ public class PlotAPI {
|
||||
|
||||
/**
|
||||
* @return main configuration
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PlotMain#config
|
||||
*/
|
||||
public YamlConfiguration getConfig() {
|
||||
@ -184,6 +174,7 @@ public class PlotAPI {
|
||||
|
||||
/**
|
||||
* @return storage configuration
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PlotMain#storage
|
||||
*/
|
||||
public YamlConfiguration getStorage() {
|
||||
@ -191,11 +182,11 @@ public class PlotAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the main class for this plugin <br>
|
||||
* - Contains a lot of fields and methods - not very well organized <br>
|
||||
* Get the main class for this plugin <br> - Contains a lot of fields and methods - not very well organized <br>
|
||||
* Only use this if you really need it
|
||||
*
|
||||
* @return PlotMain PlotSquared Main Class
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PlotMain
|
||||
*/
|
||||
public PlotMain getMain() {
|
||||
@ -206,6 +197,7 @@ public class PlotAPI {
|
||||
* PlotHelper class contains useful methods relating to plots.
|
||||
*
|
||||
* @return PlotHelper
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.PlotHelper
|
||||
*/
|
||||
public PlotHelper getPlotHelper() {
|
||||
@ -213,10 +205,10 @@ public class PlotAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* PlayerFunctions class contains useful methods relating to players - Some
|
||||
* player/plot methods are here as well
|
||||
* PlayerFunctions class contains useful methods relating to players - Some player/plot methods are here as well
|
||||
*
|
||||
* @return PlayerFunctions
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions
|
||||
*/
|
||||
public PlayerFunctions getPlayerFunctions() {
|
||||
@ -227,6 +219,7 @@ public class PlotAPI {
|
||||
* FlagManager class contains methods relating to plot flags
|
||||
*
|
||||
* @return FlagManager
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.flag.FlagManager
|
||||
*/
|
||||
public FlagManager getFlagManager() {
|
||||
@ -237,6 +230,7 @@ public class PlotAPI {
|
||||
* SchematicHandler class contains methods related to pasting schematics
|
||||
*
|
||||
* @return SchematicHandler
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.SchematicHandler
|
||||
*/
|
||||
public SchematicHandler getSchematicHandler() {
|
||||
@ -247,6 +241,7 @@ public class PlotAPI {
|
||||
* C class contains all the captions from the translations.yml file.
|
||||
*
|
||||
* @return C
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.config.C
|
||||
*/
|
||||
public C getCaptions() {
|
||||
@ -254,12 +249,12 @@ public class PlotAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot manager for a world. - Most of these methods can be accessed
|
||||
* through the PlotHelper
|
||||
* Get the plot manager for a world. - Most of these methods can be accessed through the PlotHelper
|
||||
*
|
||||
* @param world Which manager to get
|
||||
*
|
||||
* @param world
|
||||
* Which manager to get
|
||||
* @return PlotManager
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.object.PlotManager
|
||||
* @see PlotMain#getPlotManager(org.bukkit.World)
|
||||
*/
|
||||
@ -268,12 +263,13 @@ public class PlotAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot manager for a world. - Contains useful low level methods for
|
||||
* plot merging, clearing, and tessellation
|
||||
* Get the plot manager for a world. - Contains useful low level methods for plot merging, clearing, and
|
||||
* tessellation
|
||||
*
|
||||
* @param world Plot World
|
||||
*
|
||||
* @param world
|
||||
* Plot World
|
||||
* @return PlotManager
|
||||
*
|
||||
* @see PlotMain#getPlotManager(String)
|
||||
* @see com.intellectualcrafters.plot.object.PlotManager
|
||||
*/
|
||||
@ -282,14 +278,13 @@ public class PlotAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings for a world (settings bundled in PlotWorld class) - You
|
||||
* will need to downcast for the specific settings a Generator has. e.g.
|
||||
* DefaultPlotWorld class implements PlotWorld
|
||||
* Get the settings for a world (settings bundled in PlotWorld class) - You will need to downcast for the specific
|
||||
* settings a Generator has. e.g. DefaultPlotWorld class implements PlotWorld
|
||||
*
|
||||
* @param world (to get settings of)
|
||||
*
|
||||
* @return PlotWorld class for that world ! will return null if not a plot world world
|
||||
*
|
||||
* @param world
|
||||
* (to get settings of)
|
||||
* @return PlotWorld class for that world ! will return null if not a plot
|
||||
* world world
|
||||
* @see PlotMain#getWorldSettings(org.bukkit.World)
|
||||
* @see com.intellectualcrafters.plot.object.PlotWorld
|
||||
*/
|
||||
@ -300,10 +295,10 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get the settings for a world (settings bundled in PlotWorld class)
|
||||
*
|
||||
* @param world
|
||||
* (to get settings of)
|
||||
* @return PlotWorld class for that world ! will return null if not a plot
|
||||
* world world
|
||||
* @param world (to get settings of)
|
||||
*
|
||||
* @return PlotWorld class for that world ! will return null if not a plot world world
|
||||
*
|
||||
* @see PlotMain#getWorldSettings(String)
|
||||
* @see com.intellectualcrafters.plot.object.PlotWorld
|
||||
*/
|
||||
@ -314,10 +309,9 @@ public class PlotAPI {
|
||||
/**
|
||||
* Send a message to a player.
|
||||
*
|
||||
* @param player
|
||||
* Player that will receive the message
|
||||
* @param c
|
||||
* (Caption)
|
||||
* @param player Player that will receive the message
|
||||
* @param c (Caption)
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player,
|
||||
* com.intellectualcrafters.plot.config.C, String...)
|
||||
*/
|
||||
@ -328,12 +322,10 @@ public class PlotAPI {
|
||||
/**
|
||||
* Send a message to a player. - Supports color codes
|
||||
*
|
||||
* @param player
|
||||
* Player that will receive the message
|
||||
* @param string
|
||||
* The message
|
||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player,
|
||||
* String)
|
||||
* @param player Player that will receive the message
|
||||
* @param string The message
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player, String)
|
||||
*/
|
||||
public void sendMessage(@NotNull final Player player, @NotNull final String string) {
|
||||
PlayerFunctions.sendMessage(player, string);
|
||||
@ -342,8 +334,8 @@ public class PlotAPI {
|
||||
/**
|
||||
* Send a message to the console. - Supports color codes
|
||||
*
|
||||
* @param msg
|
||||
* Message that should be sent to the console
|
||||
* @param msg Message that should be sent to the console
|
||||
*
|
||||
* @see PlotMain#sendConsoleSenderMessage(String)
|
||||
*/
|
||||
public void sendConsoleMessage(@NotNull final String msg) {
|
||||
@ -353,8 +345,8 @@ public class PlotAPI {
|
||||
/**
|
||||
* Send a message to the console
|
||||
*
|
||||
* @param c
|
||||
* (Caption)
|
||||
* @param c (Caption)
|
||||
*
|
||||
* @see #sendConsoleMessage(String)
|
||||
* @see com.intellectualcrafters.plot.config.C
|
||||
*/
|
||||
@ -365,8 +357,8 @@ public class PlotAPI {
|
||||
/**
|
||||
* Register a flag for use in plots
|
||||
*
|
||||
* @param flag
|
||||
* Flag that should be registered
|
||||
* @param flag Flag that should be registered
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag)
|
||||
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
||||
*/
|
||||
@ -378,6 +370,7 @@ public class PlotAPI {
|
||||
* get all the currently registered flags
|
||||
*
|
||||
* @return array of Flag[]
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.flag.FlagManager#getFlags()
|
||||
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
||||
*/
|
||||
@ -388,15 +381,13 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get a plot based on the ID
|
||||
*
|
||||
* @param world
|
||||
* World in which the plot is located
|
||||
* @param x
|
||||
* Plot Location X Co-ord
|
||||
* @param z
|
||||
* Plot Location Z Co-ord
|
||||
* @param world World in which the plot is located
|
||||
* @param x Plot Location X Co-ord
|
||||
* @param z Plot Location Z Co-ord
|
||||
*
|
||||
* @return plot, null if ID is wrong
|
||||
* @see PlotHelper#getPlot(org.bukkit.World,
|
||||
* com.intellectualcrafters.plot.object.PlotId)
|
||||
*
|
||||
* @see PlotHelper#getPlot(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
public Plot getPlot(@NotNull final World world, final int x, final int z) {
|
||||
@ -406,9 +397,10 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get a plot based on the location
|
||||
*
|
||||
* @param l
|
||||
* The location that you want to to retrieve the plot from
|
||||
* @param l The location that you want to to retrieve the plot from
|
||||
*
|
||||
* @return plot if found, otherwise it creates a temporary plot-
|
||||
*
|
||||
* @see PlotHelper#getCurrentPlot(org.bukkit.Location)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
@ -419,9 +411,10 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get a plot based on the player location
|
||||
*
|
||||
* @param player
|
||||
* Get the current plot for the player location
|
||||
* @param player Get the current plot for the player location
|
||||
*
|
||||
* @return plot if found, otherwise it creates a temporary plot
|
||||
*
|
||||
* @see #getPlot(org.bukkit.Location)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
@ -432,9 +425,10 @@ public class PlotAPI {
|
||||
/**
|
||||
* Check whether or not a player has a plot
|
||||
*
|
||||
* @param player
|
||||
* Player that you want to check for
|
||||
* @param player Player that you want to check for
|
||||
*
|
||||
* @return true if player has a plot, false if not.
|
||||
*
|
||||
* @see #getPlots(org.bukkit.World, org.bukkit.entity.Player, boolean)
|
||||
*/
|
||||
public boolean hasPlot(@NotNull final World world, @NotNull final Player player) {
|
||||
@ -444,10 +438,9 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get all plots for the player
|
||||
*
|
||||
* @param plr
|
||||
* to search for
|
||||
* @param just_owner
|
||||
* should we just search for owner? Or with rights?
|
||||
* @param plr to search for
|
||||
* @param just_owner should we just search for owner? Or with rights?
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
public Plot[] getPlots(@NotNull final World world, @NotNull final Player plr, final boolean just_owner) {
|
||||
@ -457,8 +450,7 @@ public class PlotAPI {
|
||||
if ((plot.owner != null) && (plot.owner == UUIDHandler.getUUID(plr))) {
|
||||
pPlots.add(plot);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (plot.hasRights(plr)) {
|
||||
pPlots.add(plot);
|
||||
}
|
||||
@ -470,9 +462,10 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get all plots for the world
|
||||
*
|
||||
* @param world
|
||||
* to get plots of
|
||||
* @param world to get plots of
|
||||
*
|
||||
* @return Plot[] - array of plot objects in world
|
||||
*
|
||||
* @see PlotMain#getWorldPlots(org.bukkit.World)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
@ -484,6 +477,7 @@ public class PlotAPI {
|
||||
* Get all plot worlds
|
||||
*
|
||||
* @return World[] - array of plot worlds
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PlotMain#getPlotWorlds()
|
||||
*/
|
||||
public String[] getPlotWorlds() {
|
||||
@ -493,9 +487,10 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get if plot world
|
||||
*
|
||||
* @param world
|
||||
* (to check if plot world)
|
||||
* @param world (to check if plot world)
|
||||
*
|
||||
* @return boolean (if plot world or not)
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PlotMain#isPlotWorld(org.bukkit.World)
|
||||
*/
|
||||
public boolean isPlotWorld(@NotNull final World world) {
|
||||
@ -505,9 +500,10 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get plot locations
|
||||
*
|
||||
* @param p
|
||||
* Plot that you want to get the locations for
|
||||
* @param p Plot that you want to get the locations for
|
||||
*
|
||||
* @return [0] = bottomLc, [1] = topLoc, [2] = home
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotBottomLoc(org.bukkit.World,
|
||||
* com.intellectualcrafters.plot.object.PlotId)
|
||||
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotTopLoc(org.bukkit.World,
|
||||
@ -525,9 +521,10 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get home location
|
||||
*
|
||||
* @param p
|
||||
* Plot that you want to get the location for
|
||||
* @param p Plot that you want to get the location for
|
||||
*
|
||||
* @return plot bottom location
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World,
|
||||
* com.intellectualcrafters.plot.object.Plot)
|
||||
* @see com.intellectualcrafters.plot.object.PlotHomePosition
|
||||
@ -540,9 +537,10 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get Bottom Location (min, min, min)
|
||||
*
|
||||
* @param p
|
||||
* Plot that you want to get the location for
|
||||
* @param p Plot that you want to get the location for
|
||||
*
|
||||
* @return plot bottom location
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotBottomLoc(org.bukkit.World,
|
||||
* com.intellectualcrafters.plot.object.PlotId)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
@ -555,11 +553,11 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get Top Location (max, max, max)
|
||||
*
|
||||
* @param p
|
||||
* Plot that you want to get the location for
|
||||
* @param p Plot that you want to get the location for
|
||||
*
|
||||
* @return plot top location
|
||||
* @see PlotHelper#getPlotTopLoc(org.bukkit.World,
|
||||
* com.intellectualcrafters.plot.object.PlotId)
|
||||
*
|
||||
* @see PlotHelper#getPlotTopLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
public Location getTopLocation(@NotNull final Plot p) {
|
||||
@ -570,9 +568,10 @@ public class PlotAPI {
|
||||
/**
|
||||
* Check whether or not a player is in a plot
|
||||
*
|
||||
* @param player
|
||||
* who we're checking for
|
||||
* @param player who we're checking for
|
||||
*
|
||||
* @return true if the player is in a plot, false if not-
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#isInPlot(org.bukkit.entity.Player)
|
||||
*/
|
||||
public boolean isInPlot(@NotNull final Player player) {
|
||||
@ -582,8 +581,8 @@ public class PlotAPI {
|
||||
/**
|
||||
* Register a subcommand
|
||||
*
|
||||
* @param c
|
||||
* SubCommand, that we want to register
|
||||
* @param c SubCommand, that we want to register
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.commands.MainCommand#subCommands
|
||||
* @see com.intellectualcrafters.plot.commands.SubCommand
|
||||
*/
|
||||
@ -595,6 +594,7 @@ public class PlotAPI {
|
||||
* Get the plotMain class
|
||||
*
|
||||
* @return PlotMain Class
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PlotMain
|
||||
*/
|
||||
public PlotMain getPlotMain() {
|
||||
@ -604,11 +604,11 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get the player plot count
|
||||
*
|
||||
* @param world
|
||||
* Specify the world we want to select the plots from
|
||||
* @param player
|
||||
* Player, for whom we're getting the plot count
|
||||
* @param world Specify the world we want to select the plots from
|
||||
* @param player Player, for whom we're getting the plot count
|
||||
*
|
||||
* @return the number of plots the player has
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#getPlayerPlotCount(org.bukkit.World,
|
||||
* org.bukkit.entity.Player)
|
||||
*/
|
||||
@ -619,11 +619,11 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get a collection containing the players plots
|
||||
*
|
||||
* @param world
|
||||
* Specify the world we want to select the plots from
|
||||
* @param player
|
||||
* Player, for whom we're getting the plots
|
||||
* @param world Specify the world we want to select the plots from
|
||||
* @param player Player, for whom we're getting the plots
|
||||
*
|
||||
* @return a set containing the players plots
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#getPlayerPlots(org.bukkit.World,
|
||||
* org.bukkit.entity.Player)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
@ -635,10 +635,10 @@ public class PlotAPI {
|
||||
/**
|
||||
* Get the numbers of plots, which the player is able to build in
|
||||
*
|
||||
* @param player
|
||||
* Player, for whom we're getting the plots (trusted, helper and
|
||||
* owner)
|
||||
* @param player Player, for whom we're getting the plots (trusted, helper and owner)
|
||||
*
|
||||
* @return the number of allowed plots
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#getAllowedPlots(org.bukkit.entity.Player)
|
||||
*/
|
||||
public int getAllowedPlots(@NotNull final Player player) {
|
||||
|
@ -21,12 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
@ -38,9 +32,12 @@ import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Auto extends SubCommand {
|
||||
@SuppressWarnings("deprecation") public class Auto extends SubCommand {
|
||||
public static PlotId lastPlot = new PlotId(0, 0);
|
||||
|
||||
public Auto() {
|
||||
@ -53,20 +50,16 @@ public class Auto extends SubCommand {
|
||||
if (absX > absY) {
|
||||
if (id.x > 0) {
|
||||
return new PlotId(id.x, id.y + 1);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return new PlotId(id.x, id.y - 1);
|
||||
}
|
||||
}
|
||||
else if (absY > absX) {
|
||||
} else if (absY > absX) {
|
||||
if (id.y > 0) {
|
||||
return new PlotId(id.x - 1, id.y);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return new PlotId(id.x + 1, id.y);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (id.x.equals(id.y) && (id.x > 0)) {
|
||||
return new PlotId(id.x, id.y + step);
|
||||
}
|
||||
@ -89,12 +82,10 @@ public class Auto extends SubCommand {
|
||||
String schematic = "";
|
||||
if (PlotMain.getPlotWorlds().length == 1) {
|
||||
world = Bukkit.getWorld(PlotMain.getPlotWorlds()[0]);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (PlotMain.isPlotWorld(plr.getWorld())) {
|
||||
world = plr.getWorld();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
@ -114,8 +105,7 @@ public class Auto extends SubCommand {
|
||||
if (args.length > 1) {
|
||||
schematic = args[1];
|
||||
}
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
size_x = 1;
|
||||
size_z = 1;
|
||||
schematic = args[0];
|
||||
@ -123,8 +113,7 @@ public class Auto extends SubCommand {
|
||||
// "&cError: Invalid size (X,Y)");
|
||||
// return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
schematic = args[0];
|
||||
// PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
|
||||
// return false;
|
||||
@ -139,8 +128,7 @@ public class Auto extends SubCommand {
|
||||
if ((diff + (size_x * size_z)) >= 0) {
|
||||
if (diff < 0) {
|
||||
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff - 1) + "");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||
}
|
||||
return false;
|
||||
@ -188,8 +176,7 @@ public class Auto extends SubCommand {
|
||||
}
|
||||
Auto.lastPlot = getNextPlot(Auto.lastPlot, 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
boolean lastPlot = true;
|
||||
while (!br) {
|
||||
final PlotId start = getNextPlot(Auto.lastPlot, 1);
|
||||
@ -199,8 +186,7 @@ public class Auto extends SubCommand {
|
||||
}
|
||||
if ((PlotMain.getPlots(world).get(start) != null) && (PlotMain.getPlots(world).get(start).owner != null)) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
lastPlot = false;
|
||||
}
|
||||
System.out.print("UNOWNED: " + start);
|
||||
|
@ -1,10 +1,9 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created 2014-11-09 for PlotSquared
|
||||
|
@ -21,11 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
@ -39,6 +34,9 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.SetBlockFast;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
@ -71,8 +69,7 @@ public class Claim extends SubCommand {
|
||||
SchematicHandler.Schematic sch;
|
||||
if (schematic.equals("")) {
|
||||
sch = SchematicHandler.getSchematic(world.SCHEMATIC_FILE);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sch = SchematicHandler.getSchematic(schematic);
|
||||
if (sch == null) {
|
||||
sch = SchematicHandler.getSchematic(world.SCHEMATIC_FILE);
|
||||
|
@ -21,9 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
@ -31,6 +28,8 @@ import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Clear extends SubCommand {
|
||||
|
||||
@ -44,23 +43,19 @@ public class Clear extends SubCommand {
|
||||
// Is console
|
||||
if (args.length < 2) {
|
||||
PlotMain.sendConsoleSenderMessage("You need to specify two arguments: ID (0;0) & World (world)");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
final PlotId id = PlotId.fromString(args[0]);
|
||||
final String world = args[1];
|
||||
if (id == null) {
|
||||
PlotMain.sendConsoleSenderMessage("Invalid Plot ID: " + args[0]);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!PlotMain.isPlotWorld(world)) {
|
||||
PlotMain.sendConsoleSenderMessage("Invalid plot world: " + world);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
final Plot plot = PlotHelper.getPlot(Bukkit.getWorld(world), id);
|
||||
if (plot == null) {
|
||||
PlotMain.sendConsoleSenderMessage("Could not find plot " + args[0] + " in world " + world);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
plot.clear(null, false);
|
||||
PlotMain.sendConsoleSenderMessage("Plot " + plot.getId().toString() + " cleared.");
|
||||
}
|
||||
|
@ -21,14 +21,13 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import static com.intellectualcrafters.plot.object.PlotSelection.currentSelection;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotSelection;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import static com.intellectualcrafters.plot.object.PlotSelection.currentSelection;
|
||||
|
||||
public class Clipboard extends SubCommand {
|
||||
|
||||
|
@ -177,8 +177,7 @@ public enum Command {
|
||||
private final CommandPermission permission;
|
||||
|
||||
/**
|
||||
* @param command
|
||||
* Command "name" (/plot [cmd])
|
||||
* @param command Command "name" (/plot [cmd])
|
||||
*/
|
||||
Command(final String command) {
|
||||
this.command = command;
|
||||
@ -187,10 +186,8 @@ public enum Command {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param command
|
||||
* Command "name" (/plot [cmd])
|
||||
* @param permission
|
||||
* Command Permission Node
|
||||
* @param command Command "name" (/plot [cmd])
|
||||
* @param permission Command Permission Node
|
||||
*/
|
||||
Command(final String command, final CommandPermission permission) {
|
||||
this.command = command;
|
||||
@ -199,10 +196,8 @@ public enum Command {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param command
|
||||
* Command "name" (/plot [cmd])
|
||||
* @param alias
|
||||
* Command Alias
|
||||
* @param command Command "name" (/plot [cmd])
|
||||
* @param alias Command Alias
|
||||
*/
|
||||
Command(final String command, final String alias) {
|
||||
this.command = command;
|
||||
@ -211,12 +206,9 @@ public enum Command {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param command
|
||||
* Command "name" (/plot [cmd])
|
||||
* @param alias
|
||||
* Command Alias
|
||||
* @param permission
|
||||
* Required Permission Node
|
||||
* @param command Command "name" (/plot [cmd])
|
||||
* @param alias Command Alias
|
||||
* @param permission Required Permission Node
|
||||
*/
|
||||
Command(final String command, final String alias, final CommandPermission permission) {
|
||||
this.command = command;
|
||||
@ -240,6 +232,7 @@ public enum Command {
|
||||
|
||||
/**
|
||||
* @return permission object
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.commands.CommandPermission
|
||||
*/
|
||||
public CommandPermission getPermission() {
|
||||
|
@ -21,9 +21,8 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-08-03.
|
||||
@ -38,16 +37,15 @@ public class CommandPermission {
|
||||
public final String permission;
|
||||
|
||||
/**
|
||||
* @param permission
|
||||
* Command Permission
|
||||
* @param permission Command Permission
|
||||
*/
|
||||
public CommandPermission(final String permission) {
|
||||
this.permission = permission.toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* Does the player have the permission?
|
||||
* @param player Does the player have the permission?
|
||||
*
|
||||
* @return true of player has the required permission node
|
||||
*/
|
||||
public boolean hasPermission(final Player player) {
|
||||
|
@ -21,18 +21,17 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotComment;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Comment extends SubCommand {
|
||||
|
||||
@ -62,8 +61,7 @@ public class Comment extends SubCommand {
|
||||
DBFunc.setComment(plr.getWorld().getName(), plot, comment);
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return sendMessage(plr, C.NO_PERMISSION, "plots.comment." + args[0].toLowerCase());
|
||||
}
|
||||
}
|
||||
|
@ -21,14 +21,13 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotSelection;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Copy extends SubCommand {
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created 2014-11-09 for PlotSquared
|
||||
|
@ -1,15 +1,5 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.database.MySQL;
|
||||
import com.intellectualcrafters.plot.database.SQLManager;
|
||||
@ -17,6 +7,15 @@ import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created 2014-11-15 for PlotSquared
|
||||
@ -34,13 +33,11 @@ public class Database extends SubCommand {
|
||||
private static boolean sendMessageU(final UUID uuid, final String msg) {
|
||||
if (uuid == null) {
|
||||
PlotMain.sendConsoleSenderMessage(msg);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
final Player p = UUIDHandler.uuidWrapper.getPlayer(uuid);
|
||||
if ((p != null) && p.isOnline()) {
|
||||
return PlayerFunctions.sendMessage(p, msg);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return sendMessageU(null, msg);
|
||||
}
|
||||
}
|
||||
@ -61,15 +58,13 @@ public class Database extends SubCommand {
|
||||
manager.createPlots(ps);
|
||||
manager.createAllSettingsAndHelpers(ps);
|
||||
sendMessageU(requester, "&6Database conversion finished");
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
sendMessageU(requester, "Failed to insert plot objects, see stacktrace for info");
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
c.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -103,8 +98,7 @@ public class Database extends SubCommand {
|
||||
if (n.isClosed()) {
|
||||
return sendMessage(plr, "Failed to open connection");
|
||||
}
|
||||
}
|
||||
catch (SQLException | ClassNotFoundException e) {
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return sendMessage(plr, "Failed to open connection, read stacktrace for info");
|
||||
}
|
||||
@ -114,8 +108,7 @@ public class Database extends SubCommand {
|
||||
ResultSet set = meta.getTables(null, null, prefix + "plot", null);
|
||||
if (!set.next()) {
|
||||
manager.createTables("mysql", true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (final String s : this.tables) {
|
||||
set = meta.getTables(null, null, prefix + s, null);
|
||||
if (!set.next()) {
|
||||
@ -123,8 +116,7 @@ public class Database extends SubCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
return sendMessage(plr, "Could not create the required tables and/or load the database") && sendMessage(plr, "Please see the stacktrace for more information");
|
||||
}
|
||||
@ -149,8 +141,7 @@ public class Database extends SubCommand {
|
||||
private boolean sendMessage(final Player player, final String msg) {
|
||||
if (player == null) {
|
||||
PlotMain.sendConsoleSenderMessage(msg);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(player, msg);
|
||||
}
|
||||
return true;
|
||||
|
@ -21,16 +21,15 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.util.Lag;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.RUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Debug extends SubCommand {
|
||||
|
||||
|
@ -21,9 +21,16 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
@ -32,20 +39,8 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
@ -95,8 +90,7 @@ public class DebugClaimTest extends SubCommand {
|
||||
|
||||
min = new PlotId(Integer.parseInt(split1[0]), Integer.parseInt(split1[1]));
|
||||
max = new PlotId(Integer.parseInt(split2[0]), Integer.parseInt(split2[1]));
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return !PlayerFunctions.sendMessage(null, "&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X,Y are the plot coords\nThe conversion will only check the plots in the selected area.");
|
||||
}
|
||||
PlayerFunctions.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
|
||||
@ -154,8 +148,7 @@ public class DebugClaimTest extends SubCommand {
|
||||
plot.owner = uuid;
|
||||
plot.hasChanged = true;
|
||||
plots.add(plot);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
|
||||
}
|
||||
}
|
||||
@ -174,13 +167,11 @@ public class DebugClaimTest extends SubCommand {
|
||||
|
||||
PlayerFunctions.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(null, "No plots were found for the given search.");
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused.");
|
||||
}
|
||||
return true;
|
||||
|
@ -21,13 +21,12 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
@ -45,14 +44,12 @@ public class DebugLoadTest extends SubCommand {
|
||||
final Field fPlots = PlotMain.class.getDeclaredField("plots");
|
||||
fPlots.setAccessible(true);
|
||||
fPlots.set(null, DBFunc.getPlots());
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
PlotMain.sendConsoleSenderMessage("&3===FAILED&3===");
|
||||
e.printStackTrace();
|
||||
PlotMain.sendConsoleSenderMessage("&3===END OF STACKTRACE===");
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused.");
|
||||
}
|
||||
return true;
|
||||
|
@ -21,14 +21,13 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
@ -46,8 +45,7 @@ public class DebugSaveTest extends SubCommand {
|
||||
plots.addAll(PlotMain.getPlots());
|
||||
DBFunc.createPlots(plots);
|
||||
DBFunc.createAllSettingsAndHelpers(plots);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused.");
|
||||
}
|
||||
return true;
|
||||
|
@ -21,16 +21,14 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Delete extends SubCommand {
|
||||
|
||||
@ -67,8 +65,7 @@ public class Delete extends SubCommand {
|
||||
if ((Math.abs(plot.id.x) <= Math.abs(Auto.lastPlot.x)) && (Math.abs(plot.id.y) <= Math.abs(Auto.lastPlot.y))) {
|
||||
Auto.lastPlot = plot.id;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, "Plot deletion has been denied.");
|
||||
}
|
||||
return true;
|
||||
|
@ -21,12 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
@ -34,9 +28,13 @@ import com.intellectualcrafters.plot.events.PlayerPlotDeniedEvent;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Denied extends SubCommand {
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("deprecation") public class Denied extends SubCommand {
|
||||
|
||||
public Denied() {
|
||||
super(Command.DENIED, "Manage plot helpers", "denied {add|remove} {player}", CommandCategory.ACTIONS, true);
|
||||
@ -62,8 +60,7 @@ public class Denied extends SubCommand {
|
||||
if (args[1].equalsIgnoreCase("*")) {
|
||||
uuid = DBFunc.everyone;
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
uuid = UUIDHandler.getUUID(args[1]);
|
||||
}
|
||||
if (!plot.denied.contains(uuid)) {
|
||||
@ -88,8 +85,7 @@ public class Denied extends SubCommand {
|
||||
DBFunc.setDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
||||
final PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, true);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
|
||||
return false;
|
||||
}
|
||||
@ -103,8 +99,7 @@ public class Denied extends SubCommand {
|
||||
}
|
||||
PlayerFunctions.sendMessage(plr, C.DENIED_ADDED);
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("remove")) {
|
||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
||||
if (args[1].equalsIgnoreCase("*")) {
|
||||
final UUID uuid = DBFunc.everyone;
|
||||
if (!plot.denied.contains(uuid)) {
|
||||
@ -134,8 +129,7 @@ public class Denied extends SubCommand {
|
||||
final PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, false);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
PlayerFunctions.sendMessage(plr, C.DENIED_REMOVED);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.DENIED_NEED_ARGUMENT);
|
||||
return true;
|
||||
}
|
||||
|
@ -21,12 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
@ -34,9 +28,13 @@ import com.intellectualcrafters.plot.events.PlayerPlotHelperEvent;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Helpers extends SubCommand {
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("deprecation") public class Helpers extends SubCommand {
|
||||
|
||||
public Helpers() {
|
||||
super(Command.HELPERS, "Manage plot helpers", "helpers {add|remove} {player}", CommandCategory.ACTIONS, true);
|
||||
@ -61,8 +59,7 @@ public class Helpers extends SubCommand {
|
||||
UUID uuid;
|
||||
if (args[1].equalsIgnoreCase("*")) {
|
||||
uuid = DBFunc.everyone;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
uuid = UUIDHandler.getUUID(args[1]);
|
||||
}
|
||||
if (!plot.helpers.contains(uuid)) {
|
||||
@ -87,15 +84,13 @@ public class Helpers extends SubCommand {
|
||||
DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
||||
final PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, true);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
|
||||
return false;
|
||||
}
|
||||
PlayerFunctions.sendMessage(plr, C.HELPER_ADDED);
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("remove")) {
|
||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
||||
if (args[1].equalsIgnoreCase("*")) {
|
||||
final UUID uuid = DBFunc.everyone;
|
||||
if (!plot.helpers.contains(uuid)) {
|
||||
@ -126,8 +121,7 @@ public class Helpers extends SubCommand {
|
||||
final PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, false);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
PlayerFunctions.sendMessage(plr, C.HELPER_REMOVED);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
|
||||
return true;
|
||||
}
|
||||
|
@ -21,12 +21,11 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
@ -52,16 +51,14 @@ public class Home extends SubCommand {
|
||||
if (plots.length == 1) {
|
||||
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[0]);
|
||||
return true;
|
||||
}
|
||||
else if (plots.length > 1) {
|
||||
} else if (plots.length > 1) {
|
||||
if (args.length < 1) {
|
||||
args = new String[]{"1"};
|
||||
}
|
||||
int id = 0;
|
||||
try {
|
||||
id = Integer.parseInt(args[0]);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
Plot temp;
|
||||
if ((temp = isAlias(args[0])) != null) {
|
||||
if (temp.hasOwner()) {
|
||||
@ -82,8 +79,7 @@ public class Home extends SubCommand {
|
||||
}
|
||||
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[id - 1]);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.NO_PLOTS);
|
||||
return true;
|
||||
}
|
||||
|
@ -21,20 +21,19 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotComment;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Inbox extends SubCommand {
|
||||
|
||||
@ -58,17 +57,13 @@ public class Inbox extends SubCommand {
|
||||
final UUID uuid = plr.getUniqueId();
|
||||
if (PlotMain.hasPermission(plr, "plots.admin")) {
|
||||
tier = 0;
|
||||
}
|
||||
else if (plot.owner == uuid) {
|
||||
} else if (plot.owner == uuid) {
|
||||
tier = 1;
|
||||
}
|
||||
else if (plot.helpers.contains(uuid)) {
|
||||
} else if (plot.helpers.contains(uuid)) {
|
||||
tier = 2;
|
||||
}
|
||||
else if (plot.trusted.contains(uuid)) {
|
||||
} else if (plot.trusted.contains(uuid)) {
|
||||
tier = 3;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
tier = 4;
|
||||
}
|
||||
|
||||
@ -77,8 +72,7 @@ public class Inbox extends SubCommand {
|
||||
case "admin":
|
||||
if (tier <= 0) {
|
||||
tier = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
||||
return false;
|
||||
}
|
||||
@ -86,8 +80,7 @@ public class Inbox extends SubCommand {
|
||||
case "owner":
|
||||
if (tier <= 1) {
|
||||
tier = 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
||||
return false;
|
||||
}
|
||||
@ -95,8 +88,7 @@ public class Inbox extends SubCommand {
|
||||
case "helper":
|
||||
if (tier <= 2) {
|
||||
tier = 2;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
||||
return false;
|
||||
}
|
||||
@ -104,8 +96,7 @@ public class Inbox extends SubCommand {
|
||||
case "trusted":
|
||||
if (tier <= 3) {
|
||||
tier = 3;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
||||
return false;
|
||||
}
|
||||
@ -113,8 +104,7 @@ public class Inbox extends SubCommand {
|
||||
case "everyone":
|
||||
if (tier <= 4) {
|
||||
tier = 4;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
||||
return false;
|
||||
}
|
||||
@ -151,8 +141,7 @@ public class Inbox extends SubCommand {
|
||||
plot.settings.removeComment(comment);
|
||||
PlayerFunctions.sendMessage(plr, C.COMMENT_REMOVED, "1 comment");
|
||||
return;
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
PlayerFunctions.sendMessage(plr, "&cInvalid index:\n/plot inbox [tier] [clear][:#]");
|
||||
return;
|
||||
}
|
||||
@ -162,8 +151,7 @@ public class Inbox extends SubCommand {
|
||||
}
|
||||
plot.settings.removeComments(comments);
|
||||
PlayerFunctions.sendMessage(plr, C.COMMENT_REMOVED, "all comments in that category");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
final List<String> recipients = Arrays.asList("A", "O", "H", "T", "E");
|
||||
int count = 1;
|
||||
final StringBuilder message = new StringBuilder();
|
||||
|
@ -21,16 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
@ -41,12 +31,20 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@SuppressWarnings({ "unused", "deprecated", "javadoc" })
|
||||
public class Info extends SubCommand {
|
||||
@SuppressWarnings({"unused", "deprecated", "javadoc"}) public class Info extends SubCommand {
|
||||
|
||||
public Info() {
|
||||
super(Command.INFO, "Display plot info", "info", CommandCategory.INFO, false);
|
||||
@ -63,8 +61,7 @@ public class Info extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
plot = PlayerFunctions.getCurrentPlot(player);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (args.length < 2) {
|
||||
PlayerFunctions.sendMessage(null, C.INFO_SYNTAX_CONSOLE);
|
||||
return false;
|
||||
@ -85,12 +82,10 @@ public class Info extends SubCommand {
|
||||
world = Bukkit.getWorld(args[0]);
|
||||
if (args.length == 3) {
|
||||
args = new String[]{args[2]};
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
args = new String[0];
|
||||
}
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
PlayerFunctions.sendMessage(player, C.INFO_SYNTAX_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
@ -215,8 +210,7 @@ public class Info extends SubCommand {
|
||||
for (int x = 0; x < l.size(); x++) {
|
||||
if ((x + 1) == l.size()) {
|
||||
list.append(c.replace("%user%", getPlayerName(l.get(x))).replace(",", ""));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
list.append(c.replace("%user%", getPlayerName(l.get(x))));
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -30,6 +28,8 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Inventory extends SubCommand {
|
||||
|
||||
public Inventory() {
|
||||
|
@ -21,16 +21,14 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@SuppressWarnings({ "unused", "deprecation", "javadoc" })
|
||||
public class Kick extends SubCommand {
|
||||
@SuppressWarnings({"unused", "deprecation", "javadoc"}) public class Kick extends SubCommand {
|
||||
|
||||
public Kick() {
|
||||
super(Command.KICK, "Kick a player from your plot", "kick", CommandCategory.ACTIONS, true);
|
||||
|
@ -21,10 +21,10 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -32,10 +32,9 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* PlotMain command class
|
||||
@ -152,8 +151,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
String arg2;
|
||||
if (args.length > 2) {
|
||||
arg2 = args[2];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
arg2 = "1";
|
||||
}
|
||||
|
||||
@ -175,8 +173,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', help.toString()));
|
||||
// return PlayerFunctions.sendMessage(player, help.toString());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (final SubCommand command : subCommands) {
|
||||
if (command.cmd.equalsIgnoreCase(args[0]) || command.alias.contains(args[0].toLowerCase())) {
|
||||
final String[] arguments = new String[args.length - 1];
|
||||
@ -184,12 +181,10 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
if (command.permission.hasPermission(player)) {
|
||||
if ((player != null) || !command.isPlayer) {
|
||||
return command.execute(player, arguments);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return !PlayerFunctions.sendMessage(null, C.IS_CONSOLE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return no_permission(player, command.permission.permission.toLowerCase());
|
||||
}
|
||||
}
|
||||
@ -234,8 +229,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
if (cmd.permission.hasPermission(player)) {
|
||||
if (cmd.cmd.startsWith(arg)) {
|
||||
tabOptions.add(cmd.cmd);
|
||||
}
|
||||
else if (cmd.alias.get(0).startsWith(arg)) {
|
||||
} else if (cmd.alias.get(0).startsWith(arg)) {
|
||||
tabOptions.add(cmd.alias.get(0));
|
||||
}
|
||||
}
|
||||
|
@ -21,15 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.events.PlotMergeEvent;
|
||||
@ -39,6 +30,13 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.SetBlockFast;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
|
@ -21,18 +21,17 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MusicSubcommand extends SubCommand {
|
||||
public MusicSubcommand() {
|
||||
|
@ -1,10 +1,9 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created 2014-11-09 for PlotSquared
|
||||
|
@ -21,14 +21,13 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotSelection;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Paste extends SubCommand {
|
||||
|
||||
@ -62,8 +61,7 @@ public class Paste extends SubCommand {
|
||||
}
|
||||
selection.paste(plr.getWorld(), plot);
|
||||
sendMessage(plr, C.PASTED);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sendMessage(plr, C.NO_CLIPBOARD);
|
||||
return false;
|
||||
}
|
||||
|
@ -21,16 +21,14 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@SuppressWarnings({ "unused", "deprecated", "javadoc" })
|
||||
public class Purge extends SubCommand {
|
||||
@SuppressWarnings({"unused", "deprecated", "javadoc"}) public class Purge extends SubCommand {
|
||||
|
||||
public Purge() {
|
||||
super("purge", "plots.admin", "Purge all plots for a world", "purge", "", CommandCategory.DEBUG, false);
|
||||
@ -60,8 +58,7 @@ public class Purge extends SubCommand {
|
||||
DBFunc.purge(world, id);
|
||||
PlayerFunctions.sendMessage(null, "&aPurge of '" + args[0] + "' was successful!");
|
||||
return true;
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
}
|
||||
}
|
||||
@ -77,8 +74,7 @@ public class Purge extends SubCommand {
|
||||
DBFunc.purge(args[0]);
|
||||
PlayerFunctions.sendMessage(plr, (C.PURGE_SUCCESS));
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, "This is a dangerous command, if you are sure, use /plot purge {world} -o");
|
||||
return false;
|
||||
}
|
||||
|
@ -21,15 +21,13 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@SuppressWarnings({ "unused", "deprecated", "javadoc" })
|
||||
public class Rate extends SubCommand {
|
||||
@SuppressWarnings({"unused", "deprecated", "javadoc"}) public class Rate extends SubCommand {
|
||||
|
||||
/*
|
||||
* String cmd, String permission, String description, String usage, String
|
||||
@ -79,8 +77,7 @@ public class Rate extends SubCommand {
|
||||
boolean rated = true;
|
||||
try {
|
||||
DBFunc.getRatings(plot);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
rated = false;
|
||||
}
|
||||
|
||||
@ -90,8 +87,7 @@ public class Rate extends SubCommand {
|
||||
final boolean success = true;
|
||||
if (success) {
|
||||
sendMessage(plr, C.RATING_APPLIED, plot.getId().toString());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sendMessage(plr, C.COMMAND_WENT_WRONG);
|
||||
}
|
||||
return true;
|
||||
|
@ -21,12 +21,11 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Reload extends SubCommand {
|
||||
|
||||
@ -47,8 +46,7 @@ public class Reload extends SubCommand {
|
||||
plotworld.loadDefaultConfiguration(PlotMain.config.getConfigurationSection("worlds." + pw));
|
||||
}
|
||||
PlotMain.BroadcastWithPerms(C.RELOADED_CONFIGS);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
PlayerFunctions.sendMessage(plr, C.RELOAD_FAILED);
|
||||
}
|
||||
return true;
|
||||
|
@ -21,28 +21,23 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
|
||||
import com.intellectualcrafters.plot.util.SetBlockFast;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Schematic extends SubCommand {
|
||||
|
||||
@ -119,8 +114,7 @@ public class Schematic extends SubCommand {
|
||||
final Location loc = plr.getLocation();
|
||||
x = Math.min(length2 - dem.getX(), loc.getBlockX() - bot.getBlockX());
|
||||
z = Math.min(length2 - dem.getZ(), loc.getBlockZ() - bot.getBlockZ());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
x = 0;
|
||||
z = 0;
|
||||
}
|
||||
@ -237,8 +231,7 @@ public class Schematic extends SubCommand {
|
||||
final String owner = o == null ? "unknown" : o;
|
||||
if (sch == null) {
|
||||
PlayerFunctions.sendMessage(null, "&7 - Skipped plot &c" + plot.id);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -246,8 +239,7 @@ public class Schematic extends SubCommand {
|
||||
final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + worldname + "," + owner + ".schematic");
|
||||
if (!result) {
|
||||
PlayerFunctions.sendMessage(null, "&7 - Failed to save &c" + plot.id);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(null, "&7 - &aExport success: " + plot.id);
|
||||
}
|
||||
}
|
||||
@ -281,8 +273,7 @@ public class Schematic extends SubCommand {
|
||||
}
|
||||
p2 = myplot;
|
||||
world = plr.getWorld().getName();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (args.length == 3) {
|
||||
try {
|
||||
world = args[0];
|
||||
@ -293,13 +284,11 @@ public class Schematic extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
p2 = PlotMain.getPlots(world).get(i);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
PlayerFunctions.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
@ -326,8 +315,7 @@ public class Schematic extends SubCommand {
|
||||
final String owner = o == null ? "unknown" : o;
|
||||
if (sch == null) {
|
||||
PlayerFunctions.sendMessage(plr, "&7 - Skipped plot &c" + plot.id);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -335,8 +323,7 @@ public class Schematic extends SubCommand {
|
||||
final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + world + "," + owner.trim() + ".schematic");
|
||||
if (!result) {
|
||||
PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c" + plot.id);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, "&7 - &aExport success: " + plot.id);
|
||||
}
|
||||
}
|
||||
|
@ -21,17 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
@ -48,6 +37,16 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
@ -100,8 +99,7 @@ public class Set extends SubCommand {
|
||||
if (PlotMain.worldGuardListener != null) {
|
||||
if (message.equals("")) {
|
||||
message = StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
message += "," + StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6");
|
||||
}
|
||||
}
|
||||
@ -113,8 +111,7 @@ public class Set extends SubCommand {
|
||||
|
||||
try {
|
||||
af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
af = new AbstractFlag(args[1].toLowerCase());
|
||||
}
|
||||
|
||||
@ -183,8 +180,7 @@ public class Set extends SubCommand {
|
||||
PlayerFunctions.sendMessage(plr, C.FLAG_ADDED);
|
||||
PlotListener.plotEntry(plr, plot);
|
||||
return true;
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
PlayerFunctions.sendMessage(plr, "&c" + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
@ -275,8 +271,7 @@ public class Set extends SubCommand {
|
||||
Material material;
|
||||
try {
|
||||
material = getMaterial(args[1], PlotWorld.BLOCKS);
|
||||
}
|
||||
catch (final NullPointerException e) {
|
||||
} catch (final NullPointerException e) {
|
||||
material = null;
|
||||
}
|
||||
/*
|
||||
@ -296,8 +291,7 @@ public class Set extends SubCommand {
|
||||
if (args.length > 2) {
|
||||
try {
|
||||
data = (byte) Integer.parseInt(args[2]);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
|
||||
return true;
|
||||
}
|
||||
@ -317,8 +311,7 @@ public class Set extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
//
|
||||
@SuppressWarnings("unchecked")
|
||||
final ArrayList<Material> materials = (ArrayList<Material>) ((ArrayList<Material>) PlotWorld.BLOCKS).clone();
|
||||
@SuppressWarnings("unchecked") final ArrayList<Material> materials = (ArrayList<Material>) ((ArrayList<Material>) PlotWorld.BLOCKS).clone();
|
||||
materials.add(Material.AIR);
|
||||
//
|
||||
final String[] strings = args[1].split(",");
|
||||
@ -352,13 +345,11 @@ public class Set extends SubCommand {
|
||||
if (ss.length == 1) {
|
||||
|
||||
blocks[index] = new PlotBlock((short) m.getId(), (byte) 0);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
byte b;
|
||||
try {
|
||||
b = (byte) Integer.parseInt(ss[1]);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
|
||||
return true;
|
||||
}
|
||||
@ -402,8 +393,7 @@ public class Set extends SubCommand {
|
||||
if (args.length > 2) {
|
||||
try {
|
||||
data = (byte) Integer.parseInt(args[2]);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
|
||||
return true;
|
||||
}
|
||||
@ -415,8 +405,7 @@ public class Set extends SubCommand {
|
||||
AbstractFlag af;
|
||||
try {
|
||||
af = new AbstractFlag(args[0].toLowerCase());
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
af = new AbstractFlag("");
|
||||
}
|
||||
if (FlagManager.getFlags().contains(af)) {
|
||||
|
@ -21,12 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
@ -35,9 +29,13 @@ import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class SetOwner extends SubCommand {
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("deprecation") public class SetOwner extends SubCommand {
|
||||
|
||||
public SetOwner() {
|
||||
super("setowner", "plots.admin", "Set the plot owner", "setowner {player}", "so", CommandCategory.ACTIONS, true);
|
||||
|
@ -21,11 +21,13 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.generator.DefaultPlotWorld;
|
||||
import com.intellectualcrafters.plot.object.PlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@ -35,13 +37,10 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.generator.DefaultPlotWorld;
|
||||
import com.intellectualcrafters.plot.object.PlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created 2014-09-26 for PlotSquared
|
||||
@ -62,8 +61,7 @@ public class Setup extends SubCommand implements Listener {
|
||||
|
||||
if (plr == null) {
|
||||
plrname = "";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
plrname = plr.getName();
|
||||
}
|
||||
|
||||
@ -77,20 +75,17 @@ public class Setup extends SubCommand implements Listener {
|
||||
}
|
||||
try {
|
||||
PlotMain.config.save(PlotMain.configFile);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Creating the worlds
|
||||
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal -g " + object.plugin);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.plugin);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
if (plugin.isEnabled()) {
|
||||
if (plugin.getDefaultWorldGenerator("world", "") != null) {
|
||||
@ -120,8 +115,7 @@ public class Setup extends SubCommand implements Listener {
|
||||
if (args.length < 1) {
|
||||
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (args[0].equalsIgnoreCase("cancel")) {
|
||||
setupMap.remove(plrname);
|
||||
PlayerFunctions.sendMessage(plr, "&cCancelled setup.");
|
||||
@ -133,8 +127,7 @@ public class Setup extends SubCommand implements Listener {
|
||||
step = object.step[object.current];
|
||||
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||
return true;
|
||||
}
|
||||
@ -151,15 +144,13 @@ public class Setup extends SubCommand implements Listener {
|
||||
step = object.step[object.current];
|
||||
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sendMessage(plr, C.SETUP_INVALID_ARG, args[0], step.getConstant());
|
||||
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (args.length < 1) {
|
||||
sendMessage(plr, C.SETUP_MISSING_WORLD);
|
||||
return true;
|
||||
@ -202,8 +193,7 @@ public class Setup extends SubCommand implements Listener {
|
||||
PlotWorld plotworld;
|
||||
if (generator instanceof PlotGenerator) {
|
||||
plotworld = ((PlotGenerator) generator).getNewPlotWorld(world);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
plotworld = new DefaultPlotWorld(world);
|
||||
}
|
||||
|
||||
|
@ -21,21 +21,19 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* SubCommand class
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public abstract class SubCommand {
|
||||
@SuppressWarnings({"deprecation", "unused"}) public abstract class SubCommand {
|
||||
|
||||
/**
|
||||
* Command
|
||||
@ -67,18 +65,12 @@ public abstract class SubCommand {
|
||||
public final boolean isPlayer;
|
||||
|
||||
/**
|
||||
* @param cmd
|
||||
* Command /plot {cmd} <-- That!
|
||||
* @param permission
|
||||
* Permission Node
|
||||
* @param description
|
||||
* Simple description
|
||||
* @param usage
|
||||
* Usage description: /plot command {args...}
|
||||
* @param alias
|
||||
* Command alias
|
||||
* @param category
|
||||
* CommandCategory. Pick whichever is closest to what you want.
|
||||
* @param cmd Command /plot {cmd} <-- That!
|
||||
* @param permission Permission Node
|
||||
* @param description Simple description
|
||||
* @param usage Usage description: /plot command {args...}
|
||||
* @param alias Command alias
|
||||
* @param category CommandCategory. Pick whichever is closest to what you want.
|
||||
*/
|
||||
public SubCommand(final String cmd, final String permission, final String description, final String usage, final String alias, final CommandCategory category, final boolean isPlayer) {
|
||||
this.cmd = cmd;
|
||||
@ -92,18 +84,12 @@ public abstract class SubCommand {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cmd
|
||||
* Command /plot {cmd} <-- That!
|
||||
* @param permission
|
||||
* Permission Node
|
||||
* @param description
|
||||
* Simple description
|
||||
* @param usage
|
||||
* Usage description: /plot command {args...}
|
||||
* @param aliases
|
||||
* Command aliases
|
||||
* @param category
|
||||
* CommandCategory. Pick whichever is closest to what you want.
|
||||
* @param cmd Command /plot {cmd} <-- That!
|
||||
* @param permission Permission Node
|
||||
* @param description Simple description
|
||||
* @param usage Usage description: /plot command {args...}
|
||||
* @param aliases Command aliases
|
||||
* @param category CommandCategory. Pick whichever is closest to what you want.
|
||||
*/
|
||||
public SubCommand(final String cmd, final String permission, final String description, final String usage, final CommandCategory category, final boolean isPlayer, final String... aliases) {
|
||||
this.cmd = cmd;
|
||||
@ -117,14 +103,10 @@ public abstract class SubCommand {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param command
|
||||
* Command /plot {cmd} <-- That!
|
||||
* @param description
|
||||
* Simple description
|
||||
* @param usage
|
||||
* Usage description: /plot command {args...}
|
||||
* @param category
|
||||
* CommandCategory. Pick whichever closests to what you want.
|
||||
* @param command Command /plot {cmd} <-- That!
|
||||
* @param description Simple description
|
||||
* @param usage Usage description: /plot command {args...}
|
||||
* @param category CommandCategory. Pick whichever closests to what you want.
|
||||
*/
|
||||
public SubCommand(final Command command, final String description, final String usage, final CommandCategory category, final boolean isPlayer) {
|
||||
this.cmd = command.getCommand();
|
||||
@ -140,10 +122,9 @@ public abstract class SubCommand {
|
||||
/**
|
||||
* Execute.
|
||||
*
|
||||
* @param plr
|
||||
* executor
|
||||
* @param args
|
||||
* arguments
|
||||
* @param plr executor
|
||||
* @param args arguments
|
||||
*
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
public abstract boolean execute(final Player plr, final String... args);
|
||||
@ -151,8 +132,7 @@ public abstract class SubCommand {
|
||||
/**
|
||||
* Execute the command as console
|
||||
*
|
||||
* @param args
|
||||
* Arguments
|
||||
* @param args Arguments
|
||||
*/
|
||||
public void executeConsole(final String... args) {
|
||||
this.execute(null, args);
|
||||
@ -161,12 +141,10 @@ public abstract class SubCommand {
|
||||
/**
|
||||
* Send a message
|
||||
*
|
||||
* @param plr
|
||||
* Player who will receive the mssage
|
||||
* @param c
|
||||
* Caption
|
||||
* @param args
|
||||
* Arguments (%s's)
|
||||
* @param plr Player who will receive the mssage
|
||||
* @param c Caption
|
||||
* @param args Arguments (%s's)
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player,
|
||||
* com.intellectualcrafters.plot.config.C, String...)
|
||||
*/
|
||||
@ -221,8 +199,7 @@ public abstract class SubCommand {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name
|
||||
* readable name
|
||||
* @param name readable name
|
||||
*/
|
||||
CommandCategory(final String name) {
|
||||
this.name = name;
|
||||
|
@ -21,9 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
@ -32,6 +29,8 @@ import com.intellectualcrafters.plot.object.PlotSelection;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.SetBlockFast;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
@ -74,8 +73,7 @@ public class Swap extends SubCommand {
|
||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE, plotid.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
PlayerFunctions.sendMessage(plr, C.SWAP_SYNTAX);
|
||||
return false;
|
||||
|
@ -21,17 +21,16 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
@ -70,8 +69,7 @@ public class TP extends SubCommand {
|
||||
plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1]));
|
||||
PlotMain.teleportPlayer(plr, plr.getLocation(), PlotHelper.getPlot(world, plotid));
|
||||
return true;
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
}
|
||||
return false;
|
||||
@ -86,8 +84,7 @@ public class TP extends SubCommand {
|
||||
}
|
||||
a = split[0];
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
final Player player = Bukkit.getPlayer(a);
|
||||
@SuppressWarnings("deprecation") final Player player = Bukkit.getPlayer(a);
|
||||
if (player != null) {
|
||||
final java.util.Set<Plot> plotMainPlots = PlotMain.getPlots(world, player);
|
||||
final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]);
|
||||
|
@ -21,12 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
@ -34,9 +28,13 @@ import com.intellectualcrafters.plot.events.PlayerPlotTrustedEvent;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Trusted extends SubCommand {
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("deprecation") public class Trusted extends SubCommand {
|
||||
|
||||
public Trusted() {
|
||||
super(Command.TRUSTED, "Manage trusted users for a plot", "trusted {add|remove} {player}", CommandCategory.ACTIONS, true);
|
||||
@ -62,8 +60,7 @@ public class Trusted extends SubCommand {
|
||||
if (args[1].equalsIgnoreCase("*")) {
|
||||
uuid = DBFunc.everyone;
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
uuid = UUIDHandler.getUUID(args[1]);
|
||||
}
|
||||
if (!plot.trusted.contains(uuid)) {
|
||||
@ -88,15 +85,13 @@ public class Trusted extends SubCommand {
|
||||
DBFunc.setTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
||||
final PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, true);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
|
||||
return false;
|
||||
}
|
||||
PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED);
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("remove")) {
|
||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
||||
if (args[1].equalsIgnoreCase("*")) {
|
||||
final UUID uuid = DBFunc.everyone;
|
||||
if (!plot.trusted.contains(uuid)) {
|
||||
@ -127,8 +122,7 @@ public class Trusted extends SubCommand {
|
||||
final PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, false);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
PlayerFunctions.sendMessage(plr, C.TRUSTED_REMOVED);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
|
||||
return true;
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created 2014-11-09 for PlotSquared
|
||||
|
@ -21,16 +21,14 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Unclaim extends SubCommand {
|
||||
|
||||
@ -52,7 +50,7 @@ public class Unclaim extends SubCommand {
|
||||
}
|
||||
assert plot != null;
|
||||
final PlotWorld pWorld = PlotMain.getWorldSettings(plot.getWorld());
|
||||
if (PlotMain.useEconomy && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.getOwner().equals(plr.getUniqueId())) {
|
||||
if (PlotMain.useEconomy && pWorld.USE_ECONOMY) {
|
||||
final double c = pWorld.SELL_PRICE;
|
||||
if (c > 0d) {
|
||||
final Economy economy = PlotMain.economy;
|
||||
@ -66,11 +64,9 @@ public class Unclaim extends SubCommand {
|
||||
if ((Math.abs(plot.id.x) <= Math.abs(Auto.lastPlot.x)) && (Math.abs(plot.id.y) <= Math.abs(Auto.lastPlot.y))) {
|
||||
Auto.lastPlot = plot.id;
|
||||
}
|
||||
} else {
|
||||
PlayerFunctions.sendMessage(plr, "Plot removal has been denied.");
|
||||
}
|
||||
else {
|
||||
PlayerFunctions.sendMessage(plr, "Plot unclaim has been denied.");
|
||||
}
|
||||
PlayerFunctions.sendMessage(plr, C.UNCLAIM_SUCCESS);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -21,12 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
@ -39,6 +33,11 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.SetBlockFast;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
@ -126,13 +125,11 @@ public class Unlink extends SubCommand {
|
||||
if (PlotHelper.canSetFast) {
|
||||
SetBlockFast.update(plr);
|
||||
}
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
// execute(final Player plr, final String... args) {
|
||||
try {
|
||||
PlotMain.sendConsoleSenderMessage("Error on: " + getClass().getMethod("execute", Player.class, String[].class).toGenericString() + ":119, when trying to use \"SetBlockFast#update\"");
|
||||
}
|
||||
catch (final Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -21,16 +21,15 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Visit extends SubCommand {
|
||||
public Visit() {
|
||||
@ -68,8 +67,7 @@ public class Visit extends SubCommand {
|
||||
int i;
|
||||
try {
|
||||
i = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return sendMessage(plr, C.NOT_VALID_NUMBER);
|
||||
}
|
||||
if ((i < 0) || (i >= plots.size())) {
|
||||
|
@ -21,12 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
@ -34,6 +28,11 @@ import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
@ -62,8 +61,7 @@ public class list extends SubCommand {
|
||||
builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s());
|
||||
if (plr != null) {
|
||||
builder.append(getArgumentList(new String[]{"mine", "shared", "world", "all"}));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
builder.append(getArgumentList(new String[]{"all"}));
|
||||
}
|
||||
PlayerFunctions.sendMessage(plr, builder.toString());
|
||||
@ -84,8 +82,7 @@ public class list extends SubCommand {
|
||||
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "You have").replaceAll("%num%", idx + "").replaceAll("%plot%", idx == 1 ? "plot" : "plots"));
|
||||
PlayerFunctions.sendMessage(plr, string.toString());
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("shared") && (plr != null)) {
|
||||
} else if (args[0].equalsIgnoreCase("shared") && (plr != null)) {
|
||||
final StringBuilder string = new StringBuilder();
|
||||
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")).append("\n");
|
||||
for (final Plot p : PlotMain.getPlotsSorted()) {
|
||||
@ -96,8 +93,7 @@ public class list extends SubCommand {
|
||||
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There are").replaceAll("%num%", PlotMain.getPlotsSorted().size() + "").replaceAll("%plot%", PlotMain.getPlotsSorted().size() == 1 ? "plot" : "plots"));
|
||||
PlayerFunctions.sendMessage(plr, string.toString());
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("all")) {
|
||||
} else if (args[0].equalsIgnoreCase("all")) {
|
||||
// Current page
|
||||
int page = 0;
|
||||
|
||||
@ -109,8 +105,7 @@ public class list extends SubCommand {
|
||||
if (page < 0) {
|
||||
page = 0;
|
||||
}
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
page = 0;
|
||||
}
|
||||
}
|
||||
@ -145,8 +140,7 @@ public class list extends SubCommand {
|
||||
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", PlotMain.getPlotsSorted().size() + "").replaceAll("%plot%", PlotMain.getPlotsSorted().size() == 1 ? "plot" : "plots"));
|
||||
PlayerFunctions.sendMessage(plr, string.toString());
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("world") && (plr != null)) {
|
||||
} else if (args[0].equalsIgnoreCase("world") && (plr != null)) {
|
||||
final StringBuilder string = new StringBuilder();
|
||||
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")).append("\n");
|
||||
final HashMap<PlotId, Plot> plots = PlotMain.getPlots(plr.getWorld());
|
||||
@ -156,8 +150,7 @@ public class list extends SubCommand {
|
||||
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", plots.values().size() + "").replaceAll("%plot%", plots.values().size() == 1 ? "plot" : "plots"));
|
||||
PlayerFunctions.sendMessage(plr, string.toString());
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// execute(plr);
|
||||
sendMessage(plr, C.DID_YOU_MEAN, new StringComparison(args[0], new String[]{"mine", "shared", "world", "all"}).getBestMatch());
|
||||
return false;
|
||||
|
@ -21,19 +21,18 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
|
||||
public class plugin extends SubCommand {
|
||||
|
||||
public static String downloads, version;
|
||||
@ -48,8 +47,7 @@ public class plugin extends SubCommand {
|
||||
public void run() {
|
||||
try {
|
||||
downloads = convertToNumericString(getInfo("https://intellectualsites.com/spigot_api.php?method=downloads&url=http://www.spigotmc.org/resources/plotsquared.1177/"), false);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
downloads = "unknown";
|
||||
}
|
||||
}
|
||||
@ -59,8 +57,7 @@ public class plugin extends SubCommand {
|
||||
public void run() {
|
||||
try {
|
||||
version = convertToNumericString(getInfo("https://intellectualsites.com/spigot_api.php?method=version&resource=1177"), true);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
// Let's just ignore this, most likely error 500...
|
||||
version = "unknown";
|
||||
}
|
||||
@ -73,8 +70,7 @@ public class plugin extends SubCommand {
|
||||
for (final char c : str.toCharArray()) {
|
||||
if (Character.isDigit(c)) {
|
||||
builder.append(c);
|
||||
}
|
||||
else if (dividers && ((c == ',') || (c == '.') || (c == '-') || (c == '_'))) {
|
||||
} else if (dividers && ((c == ',') || (c == '.') || (c == '-') || (c == '_'))) {
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
|
@ -421,8 +421,7 @@ public enum C {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param d
|
||||
* default
|
||||
* @param d default
|
||||
*/
|
||||
C(final String d) {
|
||||
this.d = d;
|
||||
@ -481,6 +480,7 @@ public enum C {
|
||||
|
||||
/**
|
||||
* @return translated and color decoded
|
||||
*
|
||||
* @see org.bukkit.ChatColor#translateAlternateColorCodes(char, String)
|
||||
*/
|
||||
public String translated() {
|
||||
|
@ -21,20 +21,18 @@
|
||||
|
||||
package com.intellectualcrafters.plot.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Main Configuration Utility
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class Configuration {
|
||||
@SuppressWarnings("unused") public class Configuration {
|
||||
|
||||
public static final SettingValue STRING = new SettingValue("STRING") {
|
||||
@Override
|
||||
@ -66,8 +64,7 @@ public class Configuration {
|
||||
try {
|
||||
Integer.parseInt(string);
|
||||
return true;
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -84,8 +81,7 @@ public class Configuration {
|
||||
try {
|
||||
Boolean.parseBoolean(string);
|
||||
return true;
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -102,8 +98,7 @@ public class Configuration {
|
||||
try {
|
||||
Double.parseDouble(string);
|
||||
return true;
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -120,8 +115,7 @@ public class Configuration {
|
||||
try {
|
||||
Biome.valueOf(string.toUpperCase());
|
||||
return true;
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -150,13 +144,11 @@ public class Configuration {
|
||||
final String[] split = string.split(":");
|
||||
Short.parseShort(split[0]);
|
||||
Short.parseShort(split[1]);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Short.parseShort(string);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -166,8 +158,7 @@ public class Configuration {
|
||||
if (string.contains(":")) {
|
||||
final String[] split = string.split(":");
|
||||
return new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return new PlotBlock(Short.parseShort(string), (byte) 0);
|
||||
}
|
||||
}
|
||||
@ -191,14 +182,12 @@ public class Configuration {
|
||||
final String[] split = block.split(":");
|
||||
Short.parseShort(split[0]);
|
||||
Short.parseShort(split[1]);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Short.parseShort(block);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -220,8 +209,7 @@ public class Configuration {
|
||||
if (value < min) {
|
||||
min = value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
counts[i] = 1;
|
||||
if (1 < min) {
|
||||
min = 1;
|
||||
@ -230,8 +218,7 @@ public class Configuration {
|
||||
if (blocks[i].contains(":")) {
|
||||
final String[] split = blocks[i].split(":");
|
||||
values[i] = new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
values[i] = new PlotBlock(Short.parseShort(blocks[i]), (byte) 0);
|
||||
}
|
||||
}
|
||||
@ -272,8 +259,7 @@ public class Configuration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create your own SettingValue object to make the management of plotworld
|
||||
* configuration easier
|
||||
* Create your own SettingValue object to make the management of plotworld configuration easier
|
||||
*/
|
||||
public static abstract class SettingValue {
|
||||
private final String type;
|
||||
|
@ -21,11 +21,10 @@
|
||||
|
||||
package com.intellectualcrafters.plot.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.intellectualcrafters.plot.config.Configuration.SettingValue;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.config.Configuration.SettingValue;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Configuration Node
|
||||
@ -55,8 +54,7 @@ public class ConfigurationNode {
|
||||
try {
|
||||
final Object result = this.type.parseString(string);
|
||||
return result != null;
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -21,19 +21,18 @@
|
||||
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotComment;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotComment;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
@ -50,73 +49,62 @@ public interface AbstractDB {
|
||||
/**
|
||||
* Set Plot owner
|
||||
*
|
||||
* @param plot
|
||||
* Plot in which the owner should be set
|
||||
* @param uuid
|
||||
* The uuid of the new owner
|
||||
* @param plot Plot in which the owner should be set
|
||||
* @param uuid The uuid of the new owner
|
||||
*/
|
||||
public void setOwner(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
* Create all settings, and create default helpers, trusted + denied lists
|
||||
*
|
||||
* @param plots
|
||||
* Plots for which the default table entries should be created
|
||||
* @param plots Plots for which the default table entries should be created
|
||||
*/
|
||||
public void createAllSettingsAndHelpers(final ArrayList<Plot> plots);
|
||||
|
||||
/**
|
||||
* Create a plot
|
||||
*
|
||||
* @param plots
|
||||
* Plots that should be created
|
||||
* @param plots Plots that should be created
|
||||
*/
|
||||
public void createPlots(final ArrayList<Plot> plots);
|
||||
|
||||
/**
|
||||
* Create a plot
|
||||
*
|
||||
* @param plot
|
||||
* That should be created
|
||||
* @param plot That should be created
|
||||
*/
|
||||
public void createPlot(final Plot plot);
|
||||
|
||||
/**
|
||||
* Create tables
|
||||
*
|
||||
* @param database
|
||||
* Database in which the tables will be created
|
||||
* @param database Database in which the tables will be created
|
||||
*
|
||||
* @throws SQLException
|
||||
* If the database manager is unable to create the tables
|
||||
* @throws SQLException If the database manager is unable to create the tables
|
||||
*/
|
||||
public void createTables(final String database, final boolean add_constraint) throws Exception;
|
||||
|
||||
/**
|
||||
* Delete a plot
|
||||
*
|
||||
* @param plot
|
||||
* Plot that should be deleted
|
||||
* @param plot Plot that should be deleted
|
||||
*/
|
||||
public void delete(final String world, final Plot plot);
|
||||
|
||||
/**
|
||||
* Create plot settings
|
||||
*
|
||||
* @param id
|
||||
* Plot Entry ID
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param id Plot Entry ID
|
||||
* @param plot Plot Object
|
||||
*/
|
||||
public void createPlotSettings(final int id, final Plot plot);
|
||||
|
||||
/**
|
||||
* Get the table entry ID
|
||||
*
|
||||
* @param world
|
||||
* Which the plot is located in
|
||||
* @param id2
|
||||
* Plot ID
|
||||
* @param world Which the plot is located in
|
||||
* @param id2 Plot ID
|
||||
*
|
||||
* @return Integer = Plot Entry Id
|
||||
*/
|
||||
public int getId(final String world, final PlotId id2);
|
||||
@ -129,125 +117,100 @@ public interface AbstractDB {
|
||||
/**
|
||||
* Set the merged status for a plot
|
||||
*
|
||||
* @param world
|
||||
* World in which the plot is located
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param merged
|
||||
* boolean[]
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param merged boolean[]
|
||||
*/
|
||||
public void setMerged(final String world, final Plot plot, final boolean[] merged);
|
||||
|
||||
/**
|
||||
* Set plot flags
|
||||
*
|
||||
* @param world
|
||||
* World in which the plot is located
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param flags
|
||||
* flags to set (flag[])
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param flags flags to set (flag[])
|
||||
*/
|
||||
public void setFlags(final String world, final Plot plot, final Flag[] flags);
|
||||
|
||||
/**
|
||||
* Set the plot alias
|
||||
*
|
||||
* @param plot
|
||||
* Plot for which the alias should be set
|
||||
* @param alias
|
||||
* Plot Alias
|
||||
* @param plot Plot for which the alias should be set
|
||||
* @param alias Plot Alias
|
||||
*/
|
||||
public void setAlias(final String world, final Plot plot, final String alias);
|
||||
|
||||
/**
|
||||
* Purgle a plot
|
||||
*
|
||||
* @param world
|
||||
* World in which the plot is located
|
||||
* @param id
|
||||
* Plot ID
|
||||
* @param world World in which the plot is located
|
||||
* @param id Plot ID
|
||||
*/
|
||||
public void purge(final String world, final PlotId id);
|
||||
|
||||
/**
|
||||
* Purge a whole world
|
||||
*
|
||||
* @param world
|
||||
* World in which the plots should be purged
|
||||
* @param world World in which the plots should be purged
|
||||
*/
|
||||
public void purge(final String world);
|
||||
|
||||
/**
|
||||
* Set Plot Home Position
|
||||
*
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param position
|
||||
* Plot Home Position
|
||||
* @param plot Plot Object
|
||||
* @param position Plot Home Position
|
||||
*/
|
||||
public void setPosition(final String world, final Plot plot, final String position);
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* Plot Entry ID
|
||||
* @param id Plot Entry ID
|
||||
*
|
||||
* @return Plot Settings
|
||||
*/
|
||||
public HashMap<String, Object> getSettings(final int id);
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param player
|
||||
* Player that should be removed
|
||||
* @param plot Plot Object
|
||||
* @param player Player that should be removed
|
||||
*/
|
||||
public void removeHelper(final String world, final Plot plot, final OfflinePlayer player);
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param player
|
||||
* Player that should be removed
|
||||
* @param plot Plot Object
|
||||
* @param player Player that should be removed
|
||||
*/
|
||||
public void removeTrusted(final String world, final Plot plot, final OfflinePlayer player);
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param player
|
||||
* Player that should be removed
|
||||
* @param plot Plot Object
|
||||
* @param player Player that should be removed
|
||||
*/
|
||||
public void setHelper(final String world, final Plot plot, final OfflinePlayer player);
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param player
|
||||
* Player that should be added
|
||||
* @param plot Plot Object
|
||||
* @param player Player that should be added
|
||||
*/
|
||||
public void setTrusted(final String world, final Plot plot, final OfflinePlayer player);
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param player
|
||||
* Player that should be added
|
||||
* @param plot Plot Object
|
||||
* @param player Player that should be added
|
||||
*/
|
||||
public void removeDenied(final String world, final Plot plot, final OfflinePlayer player);
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param player
|
||||
* Player that should be added
|
||||
* @param plot Plot Object
|
||||
* @param player Player that should be added
|
||||
*/
|
||||
public void setDenied(final String world, final Plot plot, final OfflinePlayer player);
|
||||
|
||||
/**
|
||||
* Get Plots ratings
|
||||
*
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param plot Plot Object
|
||||
*
|
||||
* @return Plot Ratings (pre-calculated)
|
||||
*/
|
||||
public double getRatings(final Plot plot);
|
||||
@ -255,36 +218,28 @@ public interface AbstractDB {
|
||||
/**
|
||||
* Remove a plot comment
|
||||
*
|
||||
* @param world
|
||||
* World in which the plot is located
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param comment
|
||||
* Comment to remove
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param comment Comment to remove
|
||||
*/
|
||||
public void removeComment(final String world, final Plot plot, final PlotComment comment);
|
||||
|
||||
/**
|
||||
* Set a plot comment
|
||||
*
|
||||
* @param world
|
||||
* World in which the plot is located
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param comment
|
||||
* Comment to add
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param comment Comment to add
|
||||
*/
|
||||
public void setComment(final String world, final Plot plot, final PlotComment comment);
|
||||
|
||||
/**
|
||||
* Get Plot Comments
|
||||
*
|
||||
* @param world
|
||||
* World in which the plot is located
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param tier
|
||||
* Comment Tier
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param tier Comment Tier
|
||||
*
|
||||
* @return Plot Comments within the specified tier
|
||||
*/
|
||||
public ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier);
|
||||
|
@ -21,17 +21,16 @@
|
||||
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotComment;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* DB Functions
|
||||
@ -53,10 +52,8 @@ public class DBFunc {
|
||||
/**
|
||||
* Set the owner of a plot
|
||||
*
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param uuid
|
||||
* New Owner
|
||||
* @param plot Plot Object
|
||||
* @param uuid New Owner
|
||||
*/
|
||||
public static void setOwner(final Plot plot, final UUID uuid) {
|
||||
dbManager.setOwner(plot, uuid);
|
||||
@ -65,8 +62,7 @@ public class DBFunc {
|
||||
/**
|
||||
* Create all settings + (helpers, denied, trusted)
|
||||
*
|
||||
* @param plots
|
||||
* List containing all plot objects
|
||||
* @param plots List containing all plot objects
|
||||
*/
|
||||
public static void createAllSettingsAndHelpers(final ArrayList<Plot> plots) {
|
||||
dbManager.createAllSettingsAndHelpers(plots);
|
||||
@ -75,8 +71,7 @@ public class DBFunc {
|
||||
/**
|
||||
* Create all plots
|
||||
*
|
||||
* @param plots
|
||||
* A list containing plot objects
|
||||
* @param plots A list containing plot objects
|
||||
*/
|
||||
public static void createPlots(final ArrayList<Plot> plots) {
|
||||
dbManager.createPlots(plots);
|
||||
@ -85,8 +80,7 @@ public class DBFunc {
|
||||
/**
|
||||
* Create a plot
|
||||
*
|
||||
* @param plot
|
||||
* Plot to create
|
||||
* @param plot Plot to create
|
||||
*/
|
||||
public static void createPlot(final Plot plot) {
|
||||
dbManager.createPlot(plot);
|
||||
@ -104,8 +98,7 @@ public class DBFunc {
|
||||
/**
|
||||
* Delete a plot
|
||||
*
|
||||
* @param plot
|
||||
* Plot to delete
|
||||
* @param plot Plot to delete
|
||||
*/
|
||||
public static void delete(final String world, final Plot plot) {
|
||||
dbManager.delete(world, plot);
|
||||
@ -114,10 +107,8 @@ public class DBFunc {
|
||||
/**
|
||||
* Create plot settings
|
||||
*
|
||||
* @param id
|
||||
* Plot ID
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param id Plot ID
|
||||
* @param plot Plot Object
|
||||
*/
|
||||
public static void createPlotSettings(final int id, final Plot plot) {
|
||||
dbManager.createPlotSettings(id, plot);
|
||||
@ -126,10 +117,9 @@ public class DBFunc {
|
||||
/**
|
||||
* Get a plot id
|
||||
*
|
||||
* @param world
|
||||
* World
|
||||
* @param id2
|
||||
* Plot ID
|
||||
* @param world World
|
||||
* @param id2 Plot ID
|
||||
*
|
||||
* @return ID
|
||||
*/
|
||||
/*
|
||||
@ -187,6 +177,7 @@ public class DBFunc {
|
||||
|
||||
/**
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static HashMap<String, Object> getSettings(final int id) {
|
||||
|
@ -21,15 +21,14 @@
|
||||
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Abstract Database class, serves as a base for any connection method (MySQL,
|
||||
* SQLite, etc.)
|
||||
* Abstract Database class, serves as a base for any connection method (MySQL, SQLite, etc.)
|
||||
*
|
||||
* @author -_Husky_-
|
||||
* @author tips48
|
||||
@ -44,8 +43,7 @@ public abstract class Database {
|
||||
/**
|
||||
* Creates a new Database
|
||||
*
|
||||
* @param plugin
|
||||
* Plugin instance
|
||||
* @param plugin Plugin instance
|
||||
*/
|
||||
protected Database(final Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -55,10 +53,9 @@ public abstract class Database {
|
||||
* Opens a connection with the database
|
||||
*
|
||||
* @return Opened connection
|
||||
* @throws SQLException
|
||||
* if the connection can not be opened
|
||||
* @throws ClassNotFoundException
|
||||
* if the driver cannot be found
|
||||
*
|
||||
* @throws SQLException if the connection can not be opened
|
||||
* @throws ClassNotFoundException if the driver cannot be found
|
||||
*/
|
||||
public abstract Connection openConnection() throws SQLException, ClassNotFoundException;
|
||||
|
||||
@ -66,8 +63,8 @@ public abstract class Database {
|
||||
* Checks if a connection is open with the database
|
||||
*
|
||||
* @return true if the connection is open
|
||||
* @throws SQLException
|
||||
* if the connection cannot be checked
|
||||
*
|
||||
* @throws SQLException if the connection cannot be checked
|
||||
*/
|
||||
public abstract boolean checkConnection() throws SQLException;
|
||||
|
||||
@ -82,37 +79,33 @@ public abstract class Database {
|
||||
* Closes the connection with the database
|
||||
*
|
||||
* @return true if successful
|
||||
* @throws SQLException
|
||||
* if the connection cannot be closed
|
||||
*
|
||||
* @throws SQLException if the connection cannot be closed
|
||||
*/
|
||||
public abstract boolean closeConnection() throws SQLException;
|
||||
|
||||
/**
|
||||
* Executes a SQL Query<br>
|
||||
* If the connection is closed, it will be opened
|
||||
* Executes a SQL Query<br> If the connection is closed, it will be opened
|
||||
*
|
||||
* @param query Query to be run
|
||||
*
|
||||
* @param query
|
||||
* Query to be run
|
||||
* @return the results of the query
|
||||
* @throws SQLException
|
||||
* If the query cannot be executed
|
||||
* @throws ClassNotFoundException
|
||||
* If the driver cannot be found; see {@link #openConnection()}
|
||||
*
|
||||
* @throws SQLException If the query cannot be executed
|
||||
* @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()}
|
||||
*/
|
||||
public abstract ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException;
|
||||
|
||||
/**
|
||||
* Executes an Update SQL Query<br>
|
||||
* See {@link java.sql.Statement#executeUpdate(String)}<br>
|
||||
* If the connection is closed, it will be opened
|
||||
* Executes an Update SQL Query<br> See {@link java.sql.Statement#executeUpdate(String)}<br> If the connection is
|
||||
* closed, it will be opened
|
||||
*
|
||||
* @param query Query to be run
|
||||
*
|
||||
* @param query
|
||||
* Query to be run
|
||||
* @return Result Code, see {@link java.sql.Statement#executeUpdate(String)}
|
||||
* @throws SQLException
|
||||
* If the query cannot be executed
|
||||
* @throws ClassNotFoundException
|
||||
* If the driver cannot be found; see {@link #openConnection()}
|
||||
*
|
||||
* @throws SQLException If the query cannot be executed
|
||||
* @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()}
|
||||
*/
|
||||
public abstract int updateSQL(final String query) throws SQLException, ClassNotFoundException;
|
||||
}
|
||||
|
@ -21,14 +21,10 @@
|
||||
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* Connects to and uses a MySQL database
|
||||
*
|
||||
@ -47,18 +43,12 @@ public class MySQL extends Database {
|
||||
/**
|
||||
* Creates a new MySQL instance
|
||||
*
|
||||
* @param plugin
|
||||
* Plugin instance
|
||||
* @param hostname
|
||||
* Name of the host
|
||||
* @param port
|
||||
* Port number
|
||||
* @param database
|
||||
* Database name
|
||||
* @param username
|
||||
* Username
|
||||
* @param password
|
||||
* Password
|
||||
* @param plugin Plugin instance
|
||||
* @param hostname Name of the host
|
||||
* @param port Port number
|
||||
* @param database Database name
|
||||
* @param username Username
|
||||
* @param password Password
|
||||
*/
|
||||
public MySQL(final Plugin plugin, final String hostname, final String port, final String database, final String username, final String password) {
|
||||
super(plugin);
|
||||
|
@ -21,22 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
@ -46,6 +30,15 @@ import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.worldcretornica.plotme.PlayerList;
|
||||
import com.worldcretornica.plotme.Plot;
|
||||
import com.worldcretornica.plotme.PlotManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created 2014-08-17 for PlotSquared
|
||||
@ -63,8 +56,7 @@ public class PlotMeConverter {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plugin
|
||||
* Plugin Used to run the converter
|
||||
* @param plugin Plugin Used to run the converter
|
||||
*/
|
||||
public PlotMeConverter(final PlotMain plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -127,8 +119,7 @@ public class PlotMeConverter {
|
||||
|
||||
final Boolean auto_link = plotConfig.getBoolean("worlds." + world.getName() + ".AutoLinkPlots"); //
|
||||
PlotMain.config.set("worlds." + world.getName() + ".plot.auto_merge", auto_link);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
sendMessage("&c-- &lFailed to save configuration for world '" + world.getName() + "'\nThis will need to be done using the setup command, or manually");
|
||||
}
|
||||
|
||||
@ -173,13 +164,11 @@ public class PlotMeConverter {
|
||||
psDenied.add(set.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (final String user : plot.getAllowed().split(",")) {
|
||||
if (user.equals("*")) {
|
||||
psAdded.add(DBFunc.everyone);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
final UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8));
|
||||
psAdded.add(uuid);
|
||||
}
|
||||
@ -188,19 +177,16 @@ public class PlotMeConverter {
|
||||
for (final String user : plot.getDenied().split(",")) {
|
||||
if (user.equals("*")) {
|
||||
psDenied.add(DBFunc.everyone);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
final UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8));
|
||||
psDenied.add(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final Throwable e) {
|
||||
} catch (final Throwable e) {
|
||||
// Okay, this is evil.
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final Throwable e) {
|
||||
} catch (final Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
final PlotId id = new PlotId(Integer.parseInt(plot.id.split(";")[0]), Integer.parseInt(plot.id.split(";")[1]));
|
||||
@ -209,8 +195,7 @@ public class PlotMeConverter {
|
||||
pl = new com.intellectualcrafters.plot.object.Plot(id, plot.getOwnerId(), psAdded, psTrusted, psDenied,
|
||||
|
||||
"", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[]{false, false, false, false});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
final String owner = plot.getOwner();
|
||||
pl = new com.intellectualcrafters.plot.object.Plot(id, UUID.nameUUIDFromBytes(("OfflinePlayer:" + owner).getBytes(Charsets.UTF_8)), psAdded, psTrusted, psDenied,
|
||||
|
||||
@ -220,8 +205,7 @@ public class PlotMeConverter {
|
||||
if (pl != null) {
|
||||
if (!PlotMain.getPlots(world).containsKey(id)) {
|
||||
createdPlots.add(pl);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
duplicate++;
|
||||
}
|
||||
}
|
||||
@ -240,8 +224,7 @@ public class PlotMeConverter {
|
||||
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Saving configuration...");
|
||||
try {
|
||||
PlotMain.config.save(PlotMain.configFile);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
} catch (final IOException e) {
|
||||
PlotMain.sendConsoleSenderMessage(" - &cFailed to save configuration.");
|
||||
}
|
||||
|
||||
@ -250,8 +233,7 @@ public class PlotMeConverter {
|
||||
|
||||
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||
MV = true;
|
||||
}
|
||||
else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||
} else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||
MW = true;
|
||||
}
|
||||
|
||||
@ -266,26 +248,22 @@ public class PlotMeConverter {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + worldname);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch (final InterruptedException ex) {
|
||||
} catch (final InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// load
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + worldname + " normal -g PlotSquared");
|
||||
}
|
||||
else if (MW) {
|
||||
} else if (MW) {
|
||||
// unload
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + worldname);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch (final InterruptedException ex) {
|
||||
} catch (final InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// load
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + worldname + " plugin:PlotSquared");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Bukkit.getServer().unloadWorld(world, true);
|
||||
final World myworld = WorldCreator.name(worldname).generator(new WorldGenerator(worldname)).createWorld();
|
||||
myworld.save();
|
||||
|
@ -21,24 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
@ -49,6 +31,13 @@ import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.Logger;
|
||||
import com.intellectualcrafters.plot.util.Logger.LogLevel;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
@ -69,10 +58,8 @@ public class SQLManager implements AbstractDB {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param c
|
||||
* connection
|
||||
* @param p
|
||||
* prefix
|
||||
* @param c connection
|
||||
* @param p prefix
|
||||
*/
|
||||
public SQLManager(final Connection c, final String p) {
|
||||
// Private final
|
||||
@ -96,8 +83,7 @@ public class SQLManager implements AbstractDB {
|
||||
public void run() {
|
||||
try {
|
||||
SQLManager.this.connection = PlotMain.getMySQL().forceConnection();
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -127,10 +113,8 @@ public class SQLManager implements AbstractDB {
|
||||
/**
|
||||
* Set Plot owner
|
||||
*
|
||||
* @param plot
|
||||
* Plot Object
|
||||
* @param uuid
|
||||
* Owner UUID
|
||||
* @param plot Plot Object
|
||||
* @param uuid Owner UUID
|
||||
*/
|
||||
@Override
|
||||
public void setOwner(final Plot plot, final UUID uuid) {
|
||||
@ -144,8 +128,7 @@ public class SQLManager implements AbstractDB {
|
||||
statement.setInt(3, plot.id.y);
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.DANGER, "Could not set owner for plot " + plot.id);
|
||||
}
|
||||
@ -175,8 +158,7 @@ public class SQLManager implements AbstractDB {
|
||||
}
|
||||
stored.get(world).put(new PlotId(idx, idz), id);
|
||||
}
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@ -209,8 +191,7 @@ public class SQLManager implements AbstractDB {
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@ -239,8 +220,7 @@ public class SQLManager implements AbstractDB {
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
Logger.add(LogLevel.WARNING, "Failed to set helper for plots");
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -279,8 +259,7 @@ public class SQLManager implements AbstractDB {
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.DANGER, "Failed to save plots!");
|
||||
}
|
||||
@ -302,8 +281,7 @@ public class SQLManager implements AbstractDB {
|
||||
stmt.setString(4, plot.world);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.DANGER, "Failed to save plot " + plot.id);
|
||||
}
|
||||
@ -331,8 +309,7 @@ public class SQLManager implements AbstractDB {
|
||||
stmt.addBatch("ALTER TABLE `" + this.prefix + "plot_settings` ADD CONSTRAINT `" + this.prefix + "plot_settings_ibfk_1` FOREIGN KEY (`plot_plot_id`) REFERENCES `" + this.prefix + "plot` (`id`) ON DELETE CASCADE");
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot` (" + "`id` INTEGER PRIMARY KEY AUTOINCREMENT," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_z` INT(11) NOT NULL," + "`owner` VARCHAR(45) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP)");
|
||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
|
||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
|
||||
@ -379,8 +356,7 @@ public class SQLManager implements AbstractDB {
|
||||
stmt.setInt(1, id);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.DANGER, "Failed to delete plot " + plot.id);
|
||||
}
|
||||
@ -405,8 +381,7 @@ public class SQLManager implements AbstractDB {
|
||||
stmt.setInt(1, id);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@ -429,8 +404,7 @@ public class SQLManager implements AbstractDB {
|
||||
}
|
||||
stmt.close();
|
||||
return id;
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Integer.MAX_VALUE;
|
||||
@ -463,8 +437,7 @@ public class SQLManager implements AbstractDB {
|
||||
statement.executeBatch();
|
||||
statement.close();
|
||||
}
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
final HashMap<Integer, Plot> plots = new HashMap<>();
|
||||
@ -497,8 +470,7 @@ public class SQLManager implements AbstractDB {
|
||||
if (!worlds.contains(worldname)) {
|
||||
if (noExist.containsKey(worldname)) {
|
||||
noExist.put(worldname, noExist.get(worldname) + 1);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
noExist.put(worldname, 1);
|
||||
}
|
||||
}
|
||||
@ -528,8 +500,7 @@ public class SQLManager implements AbstractDB {
|
||||
final Plot plot = plots.get(id);
|
||||
if (plot != null) {
|
||||
plot.addHelper(user);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_helpers does not exist. Please create the plot or remove this entry.");
|
||||
}
|
||||
}
|
||||
@ -551,8 +522,7 @@ public class SQLManager implements AbstractDB {
|
||||
final Plot plot = plots.get(id);
|
||||
if (plot != null) {
|
||||
plot.addTrusted(user);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_trusted does not exist. Please create the plot or remove this entry.");
|
||||
}
|
||||
}
|
||||
@ -574,8 +544,7 @@ public class SQLManager implements AbstractDB {
|
||||
final Plot plot = plots.get(id);
|
||||
if (plot != null) {
|
||||
plot.addDenied(user);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_denied does not exist. Please create the plot or remove this entry.");
|
||||
}
|
||||
}
|
||||
@ -620,8 +589,7 @@ public class SQLManager implements AbstractDB {
|
||||
merged[3 - i] = ((m) & (1 << i)) != 0;
|
||||
}
|
||||
plot.settings.setMerged(merged);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
plot.settings.setMerged(new boolean[]{false, false, false, false});
|
||||
}
|
||||
|
||||
@ -629,8 +597,7 @@ public class SQLManager implements AbstractDB {
|
||||
final String myflags = r.getString("flags");
|
||||
if (myflags == null) {
|
||||
flags_string = new String[]{};
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
flags_string = myflags.split(",");
|
||||
}
|
||||
final ArrayList<Flag> flags = new ArrayList<Flag>();
|
||||
@ -640,12 +607,10 @@ public class SQLManager implements AbstractDB {
|
||||
final String[] split = element.split(":");
|
||||
try {
|
||||
flags.add(new Flag(FlagManager.getFlag(split[0], true), split[1].replaceAll("\u00AF", ":").replaceAll("<EFBFBD>", ",")));
|
||||
}
|
||||
catch (final Exception e) {
|
||||
} catch (final Exception e) {
|
||||
exception = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
flags.add(new Flag(FlagManager.getFlag(element, true), ""));
|
||||
}
|
||||
}
|
||||
@ -654,8 +619,7 @@ public class SQLManager implements AbstractDB {
|
||||
setFlags(id, flags.toArray(new Flag[0]));
|
||||
}
|
||||
plot.settings.setFlags(flags.toArray(new Flag[0]));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_settings does not exist. Please create the plot or remove this entry.");
|
||||
}
|
||||
}
|
||||
@ -675,8 +639,7 @@ public class SQLManager implements AbstractDB {
|
||||
if (invalidPlot) {
|
||||
PlotMain.sendConsoleSenderMessage("&c[WARNING] - Please create the world/s or remove the plots using the purge command");
|
||||
}
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
Logger.add(LogLevel.WARNING, "Failed to load plots.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -699,8 +662,7 @@ public class SQLManager implements AbstractDB {
|
||||
stmt.setInt(2, getId(world, plot.id));
|
||||
stmt.execute();
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.WARNING, "Could not set merged for plot " + plot.id);
|
||||
}
|
||||
@ -729,8 +691,7 @@ public class SQLManager implements AbstractDB {
|
||||
stmt.setInt(2, getId(world, plot.id));
|
||||
stmt.execute();
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.WARNING, "Could not set flag for plot " + plot.id);
|
||||
}
|
||||
@ -755,8 +716,7 @@ public class SQLManager implements AbstractDB {
|
||||
stmt.setInt(2, id);
|
||||
stmt.execute();
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.WARNING, "Could not set flag for plot " + id);
|
||||
}
|
||||
@ -781,8 +741,7 @@ public class SQLManager implements AbstractDB {
|
||||
stmt.setInt(2, getId(world, plot.id));
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
Logger.add(LogLevel.WARNING, "Failed to set alias for plot " + plot.id);
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -816,8 +775,7 @@ public class SQLManager implements AbstractDB {
|
||||
final int id = result.getInt("id");
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.WARNING, "FAILED TO PURGE WORLD '" + world + "'!");
|
||||
return;
|
||||
@ -853,8 +811,7 @@ public class SQLManager implements AbstractDB {
|
||||
stmt.setString(1, world);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.DANGER, "FAILED TO PURGE PLOT FROM DB '" + world + "' , '" + id + "' !");
|
||||
return;
|
||||
@ -881,8 +838,7 @@ public class SQLManager implements AbstractDB {
|
||||
final int id = result.getInt("id");
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.WARNING, "FAILED TO PURGE WORLD '" + world + "'!");
|
||||
return;
|
||||
@ -918,8 +874,7 @@ public class SQLManager implements AbstractDB {
|
||||
stmt.setString(1, world);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.DANGER, "FAILED TO PURGE WORLD '" + world + "'!");
|
||||
return;
|
||||
@ -947,8 +902,7 @@ public class SQLManager implements AbstractDB {
|
||||
stmt.setInt(2, getId(world, plot.id));
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
Logger.add(LogLevel.WARNING, "Failed to set position for plot " + plot.id);
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -958,6 +912,7 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
/**
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@ -1000,8 +955,7 @@ public class SQLManager implements AbstractDB {
|
||||
h.put(var, val);
|
||||
}
|
||||
stmt.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
Logger.add(LogLevel.WARNING, "Failed to load settings for plot: " + id);
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -1021,8 +975,7 @@ public class SQLManager implements AbstractDB {
|
||||
statement.setString(4, comment.senderName);
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.WARNING, "Failed to remove helper for plot " + plot.id);
|
||||
}
|
||||
@ -1046,8 +999,7 @@ public class SQLManager implements AbstractDB {
|
||||
comments.add(comment);
|
||||
}
|
||||
statement.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
Logger.add(LogLevel.WARNING, "Failed to fetch rating for plot " + plot.getId().toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -1067,8 +1019,7 @@ public class SQLManager implements AbstractDB {
|
||||
statement.setString(4, comment.senderName);
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.WARNING, "Failed to remove helper for plot " + plot.id);
|
||||
}
|
||||
@ -1092,8 +1043,7 @@ public class SQLManager implements AbstractDB {
|
||||
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.WARNING, "Failed to remove helper for plot " + plot.id);
|
||||
}
|
||||
@ -1116,8 +1066,7 @@ public class SQLManager implements AbstractDB {
|
||||
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.WARNING, "Failed to remove trusted user for plot " + plot.id);
|
||||
}
|
||||
@ -1140,8 +1089,7 @@ public class SQLManager implements AbstractDB {
|
||||
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
Logger.add(LogLevel.WARNING, "Failed to set helper for plot " + plot.id);
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -1164,8 +1112,7 @@ public class SQLManager implements AbstractDB {
|
||||
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
Logger.add(LogLevel.WARNING, "Failed to set plot trusted for plot " + plot.id);
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -1188,8 +1135,7 @@ public class SQLManager implements AbstractDB {
|
||||
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.WARNING, "Failed to remove denied for plot " + plot.id);
|
||||
}
|
||||
@ -1212,8 +1158,7 @@ public class SQLManager implements AbstractDB {
|
||||
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
Logger.add(LogLevel.WARNING, "Failed to set denied for plot " + plot.id);
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -1233,8 +1178,7 @@ public class SQLManager implements AbstractDB {
|
||||
}
|
||||
statement.close();
|
||||
return rating;
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
Logger.add(LogLevel.WARNING, "Failed to fetch rating for plot " + plot.getId().toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -21,17 +21,13 @@
|
||||
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Connects to and uses a SQLite database
|
||||
*
|
||||
@ -46,10 +42,8 @@ public class SQLite extends Database {
|
||||
/**
|
||||
* Creates a new SQLite instance
|
||||
*
|
||||
* @param plugin
|
||||
* Plugin instance
|
||||
* @param dbLocation
|
||||
* Location of the Database (Must end in .db)
|
||||
* @param plugin Plugin instance
|
||||
* @param dbLocation Location of the Database (Must end in .db)
|
||||
*/
|
||||
public SQLite(final Plugin plugin, final String dbLocation) {
|
||||
super(plugin);
|
||||
@ -68,8 +62,7 @@ public class SQLite extends Database {
|
||||
if (!(file.exists())) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
}
|
||||
catch (final IOException e) {
|
||||
} catch (final IOException e) {
|
||||
this.plugin.getLogger().log(Level.SEVERE, "Unable to create database!");
|
||||
}
|
||||
}
|
||||
|
@ -21,19 +21,17 @@
|
||||
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
||||
@SuppressWarnings("unused") public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Plot plot;
|
||||
private final boolean auto;
|
||||
@ -42,10 +40,8 @@ public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
||||
/**
|
||||
* PlayerClaimPlotEvent: Called when a plot is claimed
|
||||
*
|
||||
* @param player
|
||||
* Player that claimed the plot
|
||||
* @param plot
|
||||
* Plot that was claimed
|
||||
* @param player Player that claimed the plot
|
||||
* @param plot Plot that was claimed
|
||||
*/
|
||||
public PlayerClaimPlotEvent(final Player player, final Plot plot, final boolean auto) {
|
||||
super(player);
|
||||
|
@ -21,12 +21,11 @@
|
||||
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
@ -40,10 +39,8 @@ public class PlayerEnterPlotEvent extends PlayerEvent {
|
||||
/**
|
||||
* PlayerEnterPlotEvent: Called when a player leaves a plot
|
||||
*
|
||||
* @param player
|
||||
* Player that entered the plot
|
||||
* @param plot
|
||||
* Plot that was entered
|
||||
* @param player Player that entered the plot
|
||||
* @param plot Plot that was entered
|
||||
*/
|
||||
public PlayerEnterPlotEvent(final Player player, final Plot plot) {
|
||||
super(player);
|
||||
|
@ -21,12 +21,11 @@
|
||||
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
@ -39,10 +38,8 @@ public class PlayerLeavePlotEvent extends PlayerEvent {
|
||||
/**
|
||||
* PlayerLeavePlotEvent: Called when a player leaves a plot
|
||||
*
|
||||
* @param player
|
||||
* Player that left the plot
|
||||
* @param plot
|
||||
* Plot that was left
|
||||
* @param player Player that left the plot
|
||||
* @param plot Plot that was left
|
||||
*/
|
||||
public PlayerLeavePlotEvent(final Player player, final Plot plot) {
|
||||
super(player);
|
||||
|
@ -21,13 +21,12 @@
|
||||
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
@ -42,17 +41,12 @@ public class PlayerPlotDeniedEvent extends Event {
|
||||
private final UUID player;
|
||||
|
||||
/**
|
||||
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a
|
||||
* plot
|
||||
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a plot
|
||||
*
|
||||
* @param initiator
|
||||
* Player that initiated the event
|
||||
* @param plot
|
||||
* Plot in which the event occurred
|
||||
* @param player
|
||||
* Player that was denied/un-denied
|
||||
* @param added
|
||||
* true of add to deny list, false if removed
|
||||
* @param initiator Player that initiated the event
|
||||
* @param plot Plot in which the event occurred
|
||||
* @param player Player that was denied/un-denied
|
||||
* @param added true of add to deny list, false if removed
|
||||
*/
|
||||
public PlayerPlotDeniedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
this.initiator = initiator;
|
||||
|
@ -21,13 +21,12 @@
|
||||
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Empire92
|
||||
@ -44,14 +43,10 @@ public class PlayerPlotHelperEvent extends Event {
|
||||
/**
|
||||
* PlayerPlotHelperEvent: Called when a plot helper is added/removed
|
||||
*
|
||||
* @param initiator
|
||||
* Player that initiated the event
|
||||
* @param plot
|
||||
* Plot in which the event occurred
|
||||
* @param player
|
||||
* Player that was added/removed from the helper list
|
||||
* @param added
|
||||
* true of the player was added, false if the player was removed
|
||||
* @param initiator Player that initiated the event
|
||||
* @param plot Plot in which the event occurred
|
||||
* @param player Player that was added/removed from the helper list
|
||||
* @param added true of the player was added, false if the player was removed
|
||||
*/
|
||||
public PlayerPlotHelperEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
this.initiator = initiator;
|
||||
|
@ -21,13 +21,12 @@
|
||||
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
@ -44,14 +43,10 @@ public class PlayerPlotTrustedEvent extends Event {
|
||||
/**
|
||||
* PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed
|
||||
*
|
||||
* @param initiator
|
||||
* Player that initiated the event
|
||||
* @param plot
|
||||
* Plot in which the event occurred
|
||||
* @param player
|
||||
* Player that was added/removed from the trusted list
|
||||
* @param added
|
||||
* true of the player was added, false if the player was removed
|
||||
* @param initiator Player that initiated the event
|
||||
* @param plot Plot in which the event occurred
|
||||
* @param player Player that was added/removed from the trusted list
|
||||
* @param added true of the player was added, false if the player was removed
|
||||
*/
|
||||
public PlayerPlotTrustedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
this.initiator = initiator;
|
||||
|
@ -21,14 +21,13 @@
|
||||
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* Called when a player teleports to a plot
|
||||
*
|
||||
@ -46,12 +45,9 @@ public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellabl
|
||||
/**
|
||||
* PlayerTeleportToPlotEvent: Called when a player teleports to a plot
|
||||
*
|
||||
* @param player
|
||||
* That was teleported
|
||||
* @param from
|
||||
* Start location
|
||||
* @param plot
|
||||
* Plot to which the player was teleported
|
||||
* @param player That was teleported
|
||||
* @param from Start location
|
||||
* @param plot Plot to which the player was teleported
|
||||
*/
|
||||
public PlayerTeleportToPlotEvent(final Player player, final Location from, final Plot plot) {
|
||||
super(player);
|
||||
|
@ -21,12 +21,11 @@
|
||||
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
/**
|
||||
* Called when a plot is cleared
|
||||
*
|
||||
@ -42,10 +41,8 @@ public class PlotClearEvent extends Event implements Cancellable {
|
||||
/**
|
||||
* PlotDeleteEvent: Called when a plot is cleared
|
||||
*
|
||||
* @param world
|
||||
* The world in which the plot was cleared
|
||||
* @param id
|
||||
* The plot that was cleared
|
||||
* @param world The world in which the plot was cleared
|
||||
* @param id The plot that was cleared
|
||||
*/
|
||||
public PlotClearEvent(final String world, final PlotId id) {
|
||||
this.id = id;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user