mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
Weekly code cleanup
This commit is contained in:
parent
ffc7a5c7b7
commit
59be72aefe
@ -10,7 +10,8 @@ public final class ByteArrayTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* 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) {
|
public ByteArrayTag(final byte[] value) {
|
||||||
super();
|
super();
|
||||||
@ -20,8 +21,10 @@ public final class ByteArrayTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
* @param name the name of the tag
|
* @param name
|
||||||
* @param value the value of the tag
|
* the name of the tag
|
||||||
|
* @param value
|
||||||
|
* the value of the tag
|
||||||
*/
|
*/
|
||||||
public ByteArrayTag(final String name, final byte[] value) {
|
public ByteArrayTag(final String name, final byte[] value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -10,7 +10,8 @@ public final class ByteTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* 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) {
|
public ByteTag(final byte value) {
|
||||||
super();
|
super();
|
||||||
@ -20,8 +21,10 @@ public final class ByteTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
* @param name the name of the tag
|
* @param name
|
||||||
* @param value the value of the tag
|
* the name of the tag
|
||||||
|
* @param value
|
||||||
|
* the value of the tag
|
||||||
*/
|
*/
|
||||||
public ByteTag(final String name, final byte value) {
|
public ByteTag(final String name, final byte value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -15,7 +15,8 @@ public final class CompoundTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* 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) {
|
public CompoundTag(final Map<String, Tag> value) {
|
||||||
super();
|
super();
|
||||||
@ -25,8 +26,10 @@ public final class CompoundTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
* @param name the name of the tag
|
* @param name
|
||||||
* @param value the value of the tag
|
* the name of the tag
|
||||||
|
* @param value
|
||||||
|
* the value of the tag
|
||||||
*/
|
*/
|
||||||
public CompoundTag(final String name, final Map<String, Tag> value) {
|
public CompoundTag(final String name, final Map<String, Tag> value) {
|
||||||
super(name);
|
super(name);
|
||||||
@ -36,7 +39,8 @@ public final class CompoundTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Returns whether this compound tag contains the given key.
|
* 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
|
* @return true if the tag contains the given key
|
||||||
*/
|
*/
|
||||||
public boolean containsKey(final String key) {
|
public boolean containsKey(final String key) {
|
||||||
@ -51,7 +55,8 @@ public final class CompoundTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Return a new compound tag with the given values.
|
* Return a new compound tag with the given values.
|
||||||
*
|
*
|
||||||
* @param value the value
|
* @param value
|
||||||
|
* the value
|
||||||
* @return the new compound tag
|
* @return the new compound tag
|
||||||
*/
|
*/
|
||||||
public CompoundTag setValue(final Map<String, Tag> value) {
|
public CompoundTag setValue(final Map<String, Tag> value) {
|
||||||
@ -75,14 +80,16 @@ public final class CompoundTag extends Tag {
|
|||||||
* empty byte array will be returned.
|
* empty byte array will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return a byte array
|
* @return a byte array
|
||||||
*/
|
*/
|
||||||
public byte[] getByteArray(final String key) {
|
public byte[] getByteArray(final String key) {
|
||||||
final Tag tag = this.value.get(key);
|
final Tag tag = this.value.get(key);
|
||||||
if (tag instanceof ByteArrayTag) {
|
if (tag instanceof ByteArrayTag) {
|
||||||
return ((ByteArrayTag) tag).getValue();
|
return ((ByteArrayTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,14 +102,16 @@ public final class CompoundTag extends Tag {
|
|||||||
* will be returned.
|
* will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return a byte
|
* @return a byte
|
||||||
*/
|
*/
|
||||||
public byte getByte(final String key) {
|
public byte getByte(final String key) {
|
||||||
final Tag tag = this.value.get(key);
|
final Tag tag = this.value.get(key);
|
||||||
if (tag instanceof ByteTag) {
|
if (tag instanceof ByteTag) {
|
||||||
return ((ByteTag) tag).getValue();
|
return ((ByteTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return (byte) 0;
|
return (byte) 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,14 +124,16 @@ public final class CompoundTag extends Tag {
|
|||||||
* {@code 0} will be returned.
|
* {@code 0} will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return a double
|
* @return a double
|
||||||
*/
|
*/
|
||||||
public double getDouble(final String key) {
|
public double getDouble(final String key) {
|
||||||
final Tag tag = this.value.get(key);
|
final Tag tag = this.value.get(key);
|
||||||
if (tag instanceof DoubleTag) {
|
if (tag instanceof DoubleTag) {
|
||||||
return ((DoubleTag) tag).getValue();
|
return ((DoubleTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +147,8 @@ public final class CompoundTag extends Tag {
|
|||||||
* will be returned.
|
* will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return a double
|
* @return a double
|
||||||
*/
|
*/
|
||||||
public double asDouble(final String key) {
|
public double asDouble(final String key) {
|
||||||
@ -144,22 +156,28 @@ public final class CompoundTag extends Tag {
|
|||||||
if (tag instanceof ByteTag) {
|
if (tag instanceof ByteTag) {
|
||||||
return ((ByteTag) tag).getValue();
|
return ((ByteTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof ShortTag) {
|
}
|
||||||
|
else if (tag instanceof ShortTag) {
|
||||||
return ((ShortTag) tag).getValue();
|
return ((ShortTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof IntTag) {
|
}
|
||||||
|
else if (tag instanceof IntTag) {
|
||||||
return ((IntTag) tag).getValue();
|
return ((IntTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof LongTag) {
|
}
|
||||||
|
else if (tag instanceof LongTag) {
|
||||||
return ((LongTag) tag).getValue();
|
return ((LongTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof FloatTag) {
|
}
|
||||||
|
else if (tag instanceof FloatTag) {
|
||||||
return ((FloatTag) tag).getValue();
|
return ((FloatTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof DoubleTag) {
|
}
|
||||||
|
else if (tag instanceof DoubleTag) {
|
||||||
return ((DoubleTag) tag).getValue();
|
return ((DoubleTag) tag).getValue();
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,14 +190,16 @@ public final class CompoundTag extends Tag {
|
|||||||
* will be returned.
|
* will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return a float
|
* @return a float
|
||||||
*/
|
*/
|
||||||
public float getFloat(final String key) {
|
public float getFloat(final String key) {
|
||||||
final Tag tag = this.value.get(key);
|
final Tag tag = this.value.get(key);
|
||||||
if (tag instanceof FloatTag) {
|
if (tag instanceof FloatTag) {
|
||||||
return ((FloatTag) tag).getValue();
|
return ((FloatTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,14 +212,16 @@ public final class CompoundTag extends Tag {
|
|||||||
* empty array will be returned.
|
* empty array will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return an int array
|
* @return an int array
|
||||||
*/
|
*/
|
||||||
public int[] getIntArray(final String key) {
|
public int[] getIntArray(final String key) {
|
||||||
final Tag tag = this.value.get(key);
|
final Tag tag = this.value.get(key);
|
||||||
if (tag instanceof IntArrayTag) {
|
if (tag instanceof IntArrayTag) {
|
||||||
return ((IntArrayTag) tag).getValue();
|
return ((IntArrayTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return new int[0];
|
return new int[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,14 +234,16 @@ public final class CompoundTag extends Tag {
|
|||||||
* will be returned.
|
* will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return an int
|
* @return an int
|
||||||
*/
|
*/
|
||||||
public int getInt(final String key) {
|
public int getInt(final String key) {
|
||||||
final Tag tag = this.value.get(key);
|
final Tag tag = this.value.get(key);
|
||||||
if (tag instanceof IntTag) {
|
if (tag instanceof IntTag) {
|
||||||
return ((IntTag) tag).getValue();
|
return ((IntTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -233,7 +257,8 @@ public final class CompoundTag extends Tag {
|
|||||||
* will be returned.
|
* will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return an int
|
* @return an int
|
||||||
*/
|
*/
|
||||||
public int asInt(final String key) {
|
public int asInt(final String key) {
|
||||||
@ -241,22 +266,28 @@ public final class CompoundTag extends Tag {
|
|||||||
if (tag instanceof ByteTag) {
|
if (tag instanceof ByteTag) {
|
||||||
return ((ByteTag) tag).getValue();
|
return ((ByteTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof ShortTag) {
|
}
|
||||||
|
else if (tag instanceof ShortTag) {
|
||||||
return ((ShortTag) tag).getValue();
|
return ((ShortTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof IntTag) {
|
}
|
||||||
|
else if (tag instanceof IntTag) {
|
||||||
return ((IntTag) tag).getValue();
|
return ((IntTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof LongTag) {
|
}
|
||||||
|
else if (tag instanceof LongTag) {
|
||||||
return ((LongTag) tag).getValue().intValue();
|
return ((LongTag) tag).getValue().intValue();
|
||||||
|
|
||||||
} else if (tag instanceof FloatTag) {
|
}
|
||||||
|
else if (tag instanceof FloatTag) {
|
||||||
return ((FloatTag) tag).getValue().intValue();
|
return ((FloatTag) tag).getValue().intValue();
|
||||||
|
|
||||||
} else if (tag instanceof DoubleTag) {
|
}
|
||||||
|
else if (tag instanceof DoubleTag) {
|
||||||
return ((DoubleTag) tag).getValue().intValue();
|
return ((DoubleTag) tag).getValue().intValue();
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -269,14 +300,16 @@ public final class CompoundTag extends Tag {
|
|||||||
* list will be returned.
|
* list will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return a list of tags
|
* @return a list of tags
|
||||||
*/
|
*/
|
||||||
public List<Tag> getList(final String key) {
|
public List<Tag> getList(final String key) {
|
||||||
final Tag tag = this.value.get(key);
|
final Tag tag = this.value.get(key);
|
||||||
if (tag instanceof ListTag) {
|
if (tag instanceof ListTag) {
|
||||||
return ((ListTag) tag).getValue();
|
return ((ListTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,15 +322,17 @@ public final class CompoundTag extends Tag {
|
|||||||
* tag list will be returned.
|
* tag list will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return a tag list instance
|
* @return a tag list instance
|
||||||
*/
|
*/
|
||||||
public ListTag getListTag(final String key) {
|
public ListTag getListTag(final String key) {
|
||||||
final Tag tag = this.value.get(key);
|
final Tag tag = this.value.get(key);
|
||||||
if (tag instanceof ListTag) {
|
if (tag instanceof ListTag) {
|
||||||
return (ListTag) tag;
|
return (ListTag) tag;
|
||||||
} else {
|
}
|
||||||
return new ListTag(key, StringTag.class, Collections.<Tag>emptyList());
|
else {
|
||||||
|
return new ListTag(key, StringTag.class, Collections.<Tag> emptyList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,9 +345,12 @@ public final class CompoundTag extends Tag {
|
|||||||
* of a different type, then an empty list will also be returned.
|
* of a different type, then an empty list will also be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
* @param listType the class of the contained type
|
* the key
|
||||||
* @param <T> the type of list
|
* @param listType
|
||||||
|
* the class of the contained type
|
||||||
|
* @param <T>
|
||||||
|
* the type of list
|
||||||
* @return a list of tags
|
* @return a list of tags
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -322,10 +360,12 @@ public final class CompoundTag extends Tag {
|
|||||||
final ListTag listTag = (ListTag) tag;
|
final ListTag listTag = (ListTag) tag;
|
||||||
if (listTag.getType().equals(listType)) {
|
if (listTag.getType().equals(listType)) {
|
||||||
return (List<T>) listTag.getValue();
|
return (List<T>) listTag.getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -338,14 +378,16 @@ public final class CompoundTag extends Tag {
|
|||||||
* will be returned.
|
* will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return a long
|
* @return a long
|
||||||
*/
|
*/
|
||||||
public long getLong(final String key) {
|
public long getLong(final String key) {
|
||||||
final Tag tag = this.value.get(key);
|
final Tag tag = this.value.get(key);
|
||||||
if (tag instanceof LongTag) {
|
if (tag instanceof LongTag) {
|
||||||
return ((LongTag) tag).getValue();
|
return ((LongTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -359,7 +401,8 @@ public final class CompoundTag extends Tag {
|
|||||||
* will be returned.
|
* will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return a long
|
* @return a long
|
||||||
*/
|
*/
|
||||||
public long asLong(final String key) {
|
public long asLong(final String key) {
|
||||||
@ -367,22 +410,28 @@ public final class CompoundTag extends Tag {
|
|||||||
if (tag instanceof ByteTag) {
|
if (tag instanceof ByteTag) {
|
||||||
return ((ByteTag) tag).getValue();
|
return ((ByteTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof ShortTag) {
|
}
|
||||||
|
else if (tag instanceof ShortTag) {
|
||||||
return ((ShortTag) tag).getValue();
|
return ((ShortTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof IntTag) {
|
}
|
||||||
|
else if (tag instanceof IntTag) {
|
||||||
return ((IntTag) tag).getValue();
|
return ((IntTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof LongTag) {
|
}
|
||||||
|
else if (tag instanceof LongTag) {
|
||||||
return ((LongTag) tag).getValue();
|
return ((LongTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof FloatTag) {
|
}
|
||||||
|
else if (tag instanceof FloatTag) {
|
||||||
return ((FloatTag) tag).getValue().longValue();
|
return ((FloatTag) tag).getValue().longValue();
|
||||||
|
|
||||||
} else if (tag instanceof DoubleTag) {
|
}
|
||||||
|
else if (tag instanceof DoubleTag) {
|
||||||
return ((DoubleTag) tag).getValue().longValue();
|
return ((DoubleTag) tag).getValue().longValue();
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -395,14 +444,16 @@ public final class CompoundTag extends Tag {
|
|||||||
* will be returned.
|
* will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return a short
|
* @return a short
|
||||||
*/
|
*/
|
||||||
public short getShort(final String key) {
|
public short getShort(final String key) {
|
||||||
final Tag tag = this.value.get(key);
|
final Tag tag = this.value.get(key);
|
||||||
if (tag instanceof ShortTag) {
|
if (tag instanceof ShortTag) {
|
||||||
return ((ShortTag) tag).getValue();
|
return ((ShortTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -415,14 +466,16 @@ public final class CompoundTag extends Tag {
|
|||||||
* {@code ""} will be returned.
|
* {@code ""} will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key
|
||||||
|
* the key
|
||||||
* @return a string
|
* @return a string
|
||||||
*/
|
*/
|
||||||
public String getString(final String key) {
|
public String getString(final String key) {
|
||||||
final Tag tag = this.value.get(key);
|
final Tag tag = this.value.get(key);
|
||||||
if (tag instanceof StringTag) {
|
if (tag instanceof StringTag) {
|
||||||
return ((StringTag) tag).getValue();
|
return ((StringTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helps create compound tags.
|
* Helps create compound tags.
|
||||||
*/
|
*/
|
||||||
@ -22,7 +22,8 @@ public class CompoundTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Create a new instance and use the given map (which will be modified).
|
* 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) {
|
CompoundTagBuilder(final Map<String, Tag> value) {
|
||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
@ -41,8 +42,10 @@ public class CompoundTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Put the given key and tag into the compound tag.
|
* Put the given key and tag into the compound tag.
|
||||||
*
|
*
|
||||||
* @param key they key
|
* @param key
|
||||||
* @param value the value
|
* they key
|
||||||
|
* @param value
|
||||||
|
* the value
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder put(final String key, final Tag value) {
|
public CompoundTagBuilder put(final String key, final Tag value) {
|
||||||
@ -56,8 +59,10 @@ public class CompoundTagBuilder {
|
|||||||
* Put the given key and value into the compound tag as a
|
* Put the given key and value into the compound tag as a
|
||||||
* {@code ByteArrayTag}.
|
* {@code ByteArrayTag}.
|
||||||
*
|
*
|
||||||
* @param key they key
|
* @param key
|
||||||
* @param value the value
|
* they key
|
||||||
|
* @param value
|
||||||
|
* the value
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder putByteArray(final String key, final byte[] value) {
|
public CompoundTagBuilder putByteArray(final String key, final byte[] value) {
|
||||||
@ -67,8 +72,10 @@ public class CompoundTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Put the given key and value into the compound tag as a {@code ByteTag}.
|
* Put the given key and value into the compound tag as a {@code ByteTag}.
|
||||||
*
|
*
|
||||||
* @param key they key
|
* @param key
|
||||||
* @param value the value
|
* they key
|
||||||
|
* @param value
|
||||||
|
* the value
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder putByte(final String key, final byte value) {
|
public CompoundTagBuilder putByte(final String key, final byte value) {
|
||||||
@ -78,8 +85,10 @@ public class CompoundTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Put the given key and value into the compound tag as a {@code DoubleTag}.
|
* Put the given key and value into the compound tag as a {@code DoubleTag}.
|
||||||
*
|
*
|
||||||
* @param key they key
|
* @param key
|
||||||
* @param value the value
|
* they key
|
||||||
|
* @param value
|
||||||
|
* the value
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder putDouble(final String key, final double value) {
|
public CompoundTagBuilder putDouble(final String key, final double value) {
|
||||||
@ -89,8 +98,10 @@ public class CompoundTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Put the given key and value into the compound tag as a {@code FloatTag}.
|
* Put the given key and value into the compound tag as a {@code FloatTag}.
|
||||||
*
|
*
|
||||||
* @param key they key
|
* @param key
|
||||||
* @param value the value
|
* they key
|
||||||
|
* @param value
|
||||||
|
* the value
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder putFloat(final String key, final float value) {
|
public CompoundTagBuilder putFloat(final String key, final float value) {
|
||||||
@ -101,8 +112,10 @@ public class CompoundTagBuilder {
|
|||||||
* Put the given key and value into the compound tag as a
|
* Put the given key and value into the compound tag as a
|
||||||
* {@code IntArrayTag}.
|
* {@code IntArrayTag}.
|
||||||
*
|
*
|
||||||
* @param key they key
|
* @param key
|
||||||
* @param value the value
|
* they key
|
||||||
|
* @param value
|
||||||
|
* the value
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder putIntArray(final String key, final int[] value) {
|
public CompoundTagBuilder putIntArray(final String key, final int[] value) {
|
||||||
@ -112,8 +125,10 @@ public class CompoundTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Put the given key and value into the compound tag as an {@code IntTag}.
|
* Put the given key and value into the compound tag as an {@code IntTag}.
|
||||||
*
|
*
|
||||||
* @param key they key
|
* @param key
|
||||||
* @param value the value
|
* they key
|
||||||
|
* @param value
|
||||||
|
* the value
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder putInt(final String key, final int value) {
|
public CompoundTagBuilder putInt(final String key, final int value) {
|
||||||
@ -123,8 +138,10 @@ public class CompoundTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Put the given key and value into the compound tag as a {@code LongTag}.
|
* Put the given key and value into the compound tag as a {@code LongTag}.
|
||||||
*
|
*
|
||||||
* @param key they key
|
* @param key
|
||||||
* @param value the value
|
* they key
|
||||||
|
* @param value
|
||||||
|
* the value
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder putLong(final String key, final long value) {
|
public CompoundTagBuilder putLong(final String key, final long value) {
|
||||||
@ -134,8 +151,10 @@ public class CompoundTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Put the given key and value into the compound tag as a {@code ShortTag}.
|
* Put the given key and value into the compound tag as a {@code ShortTag}.
|
||||||
*
|
*
|
||||||
* @param key they key
|
* @param key
|
||||||
* @param value the value
|
* they key
|
||||||
|
* @param value
|
||||||
|
* the value
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder putShort(final String key, final short value) {
|
public CompoundTagBuilder putShort(final String key, final short value) {
|
||||||
@ -145,8 +164,10 @@ public class CompoundTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Put the given key and value into the compound tag as a {@code StringTag}.
|
* Put the given key and value into the compound tag as a {@code StringTag}.
|
||||||
*
|
*
|
||||||
* @param key they key
|
* @param key
|
||||||
* @param value the value
|
* they key
|
||||||
|
* @param value
|
||||||
|
* the value
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder putString(final String key, final String value) {
|
public CompoundTagBuilder putString(final String key, final String value) {
|
||||||
@ -156,7 +177,8 @@ public class CompoundTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Put all the entries from the given map into this map.
|
* 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
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder putAll(final Map<String, ? extends Tag> value) {
|
public CompoundTagBuilder putAll(final Map<String, ? extends Tag> value) {
|
||||||
@ -179,7 +201,8 @@ public class CompoundTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Build a new compound tag with this builder's entries.
|
* 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
|
* @return the created compound tag
|
||||||
*/
|
*/
|
||||||
public CompoundTag build(final String name) {
|
public CompoundTag build(final String name) {
|
||||||
|
@ -10,7 +10,8 @@ public final class DoubleTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* 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) {
|
public DoubleTag(final double value) {
|
||||||
super();
|
super();
|
||||||
@ -20,8 +21,10 @@ public final class DoubleTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
* @param name the name of the tag
|
* @param name
|
||||||
* @param value the value of the tag
|
* the name of the tag
|
||||||
|
* @param value
|
||||||
|
* the value of the tag
|
||||||
*/
|
*/
|
||||||
public DoubleTag(final String name, final double value) {
|
public DoubleTag(final String name, final double value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -10,7 +10,8 @@ public final class FloatTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* 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) {
|
public FloatTag(final float value) {
|
||||||
super();
|
super();
|
||||||
@ -20,8 +21,10 @@ public final class FloatTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
* @param name the name of the tag
|
* @param name
|
||||||
* @param value the value of the tag
|
* the name of the tag
|
||||||
|
* @param value
|
||||||
|
* the value of the tag
|
||||||
*/
|
*/
|
||||||
public FloatTag(final String name, final float value) {
|
public FloatTag(final String name, final float value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -12,7 +12,8 @@ public final class IntArrayTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* 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) {
|
public IntArrayTag(final int[] value) {
|
||||||
super();
|
super();
|
||||||
@ -23,8 +24,10 @@ public final class IntArrayTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
* @param name the name of the tag
|
* @param name
|
||||||
* @param value the value of the tag
|
* the name of the tag
|
||||||
|
* @param value
|
||||||
|
* the value of the tag
|
||||||
*/
|
*/
|
||||||
public IntArrayTag(final String name, final int[] value) {
|
public IntArrayTag(final String name, final int[] value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -10,7 +10,8 @@ public final class IntTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* 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) {
|
public IntTag(final int value) {
|
||||||
super();
|
super();
|
||||||
@ -20,8 +21,10 @@ public final class IntTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
* @param name the name of the tag
|
* @param name
|
||||||
* @param value the value of the tag
|
* the name of the tag
|
||||||
|
* @param value
|
||||||
|
* the value of the tag
|
||||||
*/
|
*/
|
||||||
public IntTag(final String name, final int value) {
|
public IntTag(final String name, final int value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@code TAG_List} tag.
|
* The {@code TAG_List} tag.
|
||||||
@ -13,13 +14,15 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
public final class ListTag extends Tag {
|
public final class ListTag extends Tag {
|
||||||
|
|
||||||
private final Class<? extends Tag> type;
|
private final Class<? extends Tag> type;
|
||||||
private final List<Tag> value;
|
private final List<Tag> value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* Creates the tag with an empty name.
|
||||||
*
|
*
|
||||||
* @param type the type of tag
|
* @param type
|
||||||
* @param value the value of the tag
|
* the type of tag
|
||||||
|
* @param value
|
||||||
|
* the value of the tag
|
||||||
*/
|
*/
|
||||||
public ListTag(final Class<? extends Tag> type, final List<? extends Tag> value) {
|
public ListTag(final Class<? extends Tag> type, final List<? extends Tag> value) {
|
||||||
super();
|
super();
|
||||||
@ -31,9 +34,12 @@ public final class ListTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
* @param name the name of the tag
|
* @param name
|
||||||
* @param type the type of tag
|
* the name of the tag
|
||||||
* @param value the value 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) {
|
public ListTag(final String name, final Class<? extends Tag> type, final List<? extends Tag> value) {
|
||||||
super(name);
|
super(name);
|
||||||
@ -59,7 +65,8 @@ public final class ListTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Create a new list tag with this tag's name and type.
|
* 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
|
* @return a new list tag
|
||||||
*/
|
*/
|
||||||
public ListTag setValue(final List<Tag> list) {
|
public ListTag setValue(final List<Tag> list) {
|
||||||
@ -69,14 +76,16 @@ public final class ListTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Get the tag if it exists at the given index.
|
* Get the tag if it exists at the given index.
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return the tag or null
|
* @return the tag or null
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Tag getIfExists(final int index) {
|
public Tag getIfExists(final int index) {
|
||||||
try {
|
try {
|
||||||
return this.value.get(index);
|
return this.value.get(index);
|
||||||
} catch (final NoSuchElementException e) {
|
}
|
||||||
|
catch (final NoSuchElementException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,14 +98,16 @@ public final class ListTag extends Tag {
|
|||||||
* empty byte array will be returned.
|
* empty byte array will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return a byte array
|
* @return a byte array
|
||||||
*/
|
*/
|
||||||
public byte[] getByteArray(final int index) {
|
public byte[] getByteArray(final int index) {
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ByteArrayTag) {
|
if (tag instanceof ByteArrayTag) {
|
||||||
return ((ByteArrayTag) tag).getValue();
|
return ((ByteArrayTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,14 +120,16 @@ public final class ListTag extends Tag {
|
|||||||
* {@code 0} will be returned.
|
* {@code 0} will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return a byte
|
* @return a byte
|
||||||
*/
|
*/
|
||||||
public byte getByte(final int index) {
|
public byte getByte(final int index) {
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ByteTag) {
|
if (tag instanceof ByteTag) {
|
||||||
return ((ByteTag) tag).getValue();
|
return ((ByteTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return (byte) 0;
|
return (byte) 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,14 +142,16 @@ public final class ListTag extends Tag {
|
|||||||
* {@code 0} will be returned.
|
* {@code 0} will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return a double
|
* @return a double
|
||||||
*/
|
*/
|
||||||
public double getDouble(final int index) {
|
public double getDouble(final int index) {
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof DoubleTag) {
|
if (tag instanceof DoubleTag) {
|
||||||
return ((DoubleTag) tag).getValue();
|
return ((DoubleTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,7 +165,8 @@ public final class ListTag extends Tag {
|
|||||||
* will be returned.
|
* will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return a double
|
* @return a double
|
||||||
*/
|
*/
|
||||||
public double asDouble(final int index) {
|
public double asDouble(final int index) {
|
||||||
@ -158,22 +174,28 @@ public final class ListTag extends Tag {
|
|||||||
if (tag instanceof ByteTag) {
|
if (tag instanceof ByteTag) {
|
||||||
return ((ByteTag) tag).getValue();
|
return ((ByteTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof ShortTag) {
|
}
|
||||||
|
else if (tag instanceof ShortTag) {
|
||||||
return ((ShortTag) tag).getValue();
|
return ((ShortTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof IntTag) {
|
}
|
||||||
|
else if (tag instanceof IntTag) {
|
||||||
return ((IntTag) tag).getValue();
|
return ((IntTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof LongTag) {
|
}
|
||||||
|
else if (tag instanceof LongTag) {
|
||||||
return ((LongTag) tag).getValue();
|
return ((LongTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof FloatTag) {
|
}
|
||||||
|
else if (tag instanceof FloatTag) {
|
||||||
return ((FloatTag) tag).getValue();
|
return ((FloatTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof DoubleTag) {
|
}
|
||||||
|
else if (tag instanceof DoubleTag) {
|
||||||
return ((DoubleTag) tag).getValue();
|
return ((DoubleTag) tag).getValue();
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,14 +208,16 @@ public final class ListTag extends Tag {
|
|||||||
* {@code 0} will be returned.
|
* {@code 0} will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return a float
|
* @return a float
|
||||||
*/
|
*/
|
||||||
public float getFloat(final int index) {
|
public float getFloat(final int index) {
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof FloatTag) {
|
if (tag instanceof FloatTag) {
|
||||||
return ((FloatTag) tag).getValue();
|
return ((FloatTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,14 +230,16 @@ public final class ListTag extends Tag {
|
|||||||
* empty array will be returned.
|
* empty array will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return an int array
|
* @return an int array
|
||||||
*/
|
*/
|
||||||
public int[] getIntArray(final int index) {
|
public int[] getIntArray(final int index) {
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof IntArrayTag) {
|
if (tag instanceof IntArrayTag) {
|
||||||
return ((IntArrayTag) tag).getValue();
|
return ((IntArrayTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return new int[0];
|
return new int[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,14 +252,16 @@ public final class ListTag extends Tag {
|
|||||||
* {@code 0} will be returned.
|
* {@code 0} will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return an int
|
* @return an int
|
||||||
*/
|
*/
|
||||||
public int getInt(final int index) {
|
public int getInt(final int index) {
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof IntTag) {
|
if (tag instanceof IntTag) {
|
||||||
return ((IntTag) tag).getValue();
|
return ((IntTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,7 +275,8 @@ public final class ListTag extends Tag {
|
|||||||
* will be returned.
|
* will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return an int
|
* @return an int
|
||||||
*/
|
*/
|
||||||
public int asInt(final int index) {
|
public int asInt(final int index) {
|
||||||
@ -255,22 +284,28 @@ public final class ListTag extends Tag {
|
|||||||
if (tag instanceof ByteTag) {
|
if (tag instanceof ByteTag) {
|
||||||
return ((ByteTag) tag).getValue();
|
return ((ByteTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof ShortTag) {
|
}
|
||||||
|
else if (tag instanceof ShortTag) {
|
||||||
return ((ShortTag) tag).getValue();
|
return ((ShortTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof IntTag) {
|
}
|
||||||
|
else if (tag instanceof IntTag) {
|
||||||
return ((IntTag) tag).getValue();
|
return ((IntTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof LongTag) {
|
}
|
||||||
|
else if (tag instanceof LongTag) {
|
||||||
return ((LongTag) tag).getValue().intValue();
|
return ((LongTag) tag).getValue().intValue();
|
||||||
|
|
||||||
} else if (tag instanceof FloatTag) {
|
}
|
||||||
|
else if (tag instanceof FloatTag) {
|
||||||
return ((FloatTag) tag).getValue().intValue();
|
return ((FloatTag) tag).getValue().intValue();
|
||||||
|
|
||||||
} else if (tag instanceof DoubleTag) {
|
}
|
||||||
|
else if (tag instanceof DoubleTag) {
|
||||||
return ((DoubleTag) tag).getValue().intValue();
|
return ((DoubleTag) tag).getValue().intValue();
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -283,14 +318,16 @@ public final class ListTag extends Tag {
|
|||||||
* list will be returned.
|
* list will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return a list of tags
|
* @return a list of tags
|
||||||
*/
|
*/
|
||||||
public List<Tag> getList(final int index) {
|
public List<Tag> getList(final int index) {
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ListTag) {
|
if (tag instanceof ListTag) {
|
||||||
return ((ListTag) tag).getValue();
|
return ((ListTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,15 +340,17 @@ public final class ListTag extends Tag {
|
|||||||
* tag list will be returned.
|
* tag list will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return a tag list instance
|
* @return a tag list instance
|
||||||
*/
|
*/
|
||||||
public ListTag getListTag(final int index) {
|
public ListTag getListTag(final int index) {
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ListTag) {
|
if (tag instanceof ListTag) {
|
||||||
return (ListTag) tag;
|
return (ListTag) tag;
|
||||||
} else {
|
}
|
||||||
return new ListTag(StringTag.class, Collections.<Tag>emptyList());
|
else {
|
||||||
|
return new ListTag(StringTag.class, Collections.<Tag> emptyList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,9 +363,12 @@ public final class ListTag extends Tag {
|
|||||||
* of of a different type, then an empty list will also be returned.
|
* of of a different type, then an empty list will also be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
* @param listType the class of the contained type
|
* the index
|
||||||
* @param <T> the NBT type
|
* @param listType
|
||||||
|
* the class of the contained type
|
||||||
|
* @param <T>
|
||||||
|
* the NBT type
|
||||||
* @return a list of tags
|
* @return a list of tags
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -336,10 +378,12 @@ public final class ListTag extends Tag {
|
|||||||
final ListTag listTag = (ListTag) tag;
|
final ListTag listTag = (ListTag) tag;
|
||||||
if (listTag.getType().equals(listType)) {
|
if (listTag.getType().equals(listType)) {
|
||||||
return (List<T>) listTag.getValue();
|
return (List<T>) listTag.getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -352,14 +396,16 @@ public final class ListTag extends Tag {
|
|||||||
* {@code 0} will be returned.
|
* {@code 0} will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return a long
|
* @return a long
|
||||||
*/
|
*/
|
||||||
public long getLong(final int index) {
|
public long getLong(final int index) {
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof LongTag) {
|
if (tag instanceof LongTag) {
|
||||||
return ((LongTag) tag).getValue();
|
return ((LongTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -373,7 +419,8 @@ public final class ListTag extends Tag {
|
|||||||
* will be returned.
|
* will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return a long
|
* @return a long
|
||||||
*/
|
*/
|
||||||
public long asLong(final int index) {
|
public long asLong(final int index) {
|
||||||
@ -381,22 +428,28 @@ public final class ListTag extends Tag {
|
|||||||
if (tag instanceof ByteTag) {
|
if (tag instanceof ByteTag) {
|
||||||
return ((ByteTag) tag).getValue();
|
return ((ByteTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof ShortTag) {
|
}
|
||||||
|
else if (tag instanceof ShortTag) {
|
||||||
return ((ShortTag) tag).getValue();
|
return ((ShortTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof IntTag) {
|
}
|
||||||
|
else if (tag instanceof IntTag) {
|
||||||
return ((IntTag) tag).getValue();
|
return ((IntTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof LongTag) {
|
}
|
||||||
|
else if (tag instanceof LongTag) {
|
||||||
return ((LongTag) tag).getValue();
|
return ((LongTag) tag).getValue();
|
||||||
|
|
||||||
} else if (tag instanceof FloatTag) {
|
}
|
||||||
|
else if (tag instanceof FloatTag) {
|
||||||
return ((FloatTag) tag).getValue().longValue();
|
return ((FloatTag) tag).getValue().longValue();
|
||||||
|
|
||||||
} else if (tag instanceof DoubleTag) {
|
}
|
||||||
|
else if (tag instanceof DoubleTag) {
|
||||||
return ((DoubleTag) tag).getValue().longValue();
|
return ((DoubleTag) tag).getValue().longValue();
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -409,14 +462,16 @@ public final class ListTag extends Tag {
|
|||||||
* {@code 0} will be returned.
|
* {@code 0} will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return a short
|
* @return a short
|
||||||
*/
|
*/
|
||||||
public short getShort(final int index) {
|
public short getShort(final int index) {
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ShortTag) {
|
if (tag instanceof ShortTag) {
|
||||||
return ((ShortTag) tag).getValue();
|
return ((ShortTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -429,14 +484,16 @@ public final class ListTag extends Tag {
|
|||||||
* {@code ""} will be returned.
|
* {@code ""} will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param index the index
|
* @param index
|
||||||
|
* the index
|
||||||
* @return a string
|
* @return a string
|
||||||
*/
|
*/
|
||||||
public String getString(final int index) {
|
public String getString(final int index) {
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof StringTag) {
|
if (tag instanceof StringTag) {
|
||||||
return ((StringTag) tag).getValue();
|
return ((StringTag) tag).getValue();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,25 @@
|
|||||||
package com.intellectualcrafters.jnbt;
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helps create list tags.
|
* Helps create list tags.
|
||||||
*/
|
*/
|
||||||
public class ListTagBuilder {
|
public class ListTagBuilder {
|
||||||
|
|
||||||
private final Class<? extends Tag> type;
|
private final Class<? extends Tag> type;
|
||||||
private final List<Tag> entries;
|
private final List<Tag> entries;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* 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) {
|
ListTagBuilder(final Class<? extends Tag> type) {
|
||||||
checkNotNull(type);
|
checkNotNull(type);
|
||||||
@ -63,7 +64,8 @@ public class ListTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Add the given tag.
|
* Add the given tag.
|
||||||
*
|
*
|
||||||
* @param value the tag
|
* @param value
|
||||||
|
* the tag
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public ListTagBuilder add(final Tag value) {
|
public ListTagBuilder add(final Tag value) {
|
||||||
@ -78,7 +80,8 @@ public class ListTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Add all the tags in the given list.
|
* Add all the tags in the given list.
|
||||||
*
|
*
|
||||||
* @param value a list of tags
|
* @param value
|
||||||
|
* a list of tags
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public ListTagBuilder addAll(final Collection<? extends Tag> value) {
|
public ListTagBuilder addAll(final Collection<? extends Tag> value) {
|
||||||
@ -101,7 +104,8 @@ public class ListTagBuilder {
|
|||||||
/**
|
/**
|
||||||
* Build a new list tag with this builder's entries.
|
* 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
|
* @return the created list tag
|
||||||
*/
|
*/
|
||||||
public ListTag build(final String name) {
|
public ListTag build(final String name) {
|
||||||
|
@ -10,7 +10,8 @@ public final class LongTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* 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) {
|
public LongTag(final long value) {
|
||||||
super();
|
super();
|
||||||
@ -20,8 +21,10 @@ public final class LongTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
* @param name the name of the tag
|
* @param name
|
||||||
* @param value the value of the tag
|
* the name of the tag
|
||||||
|
* @param value
|
||||||
|
* the value of the tag
|
||||||
*/
|
*/
|
||||||
public LongTag(final String name, final long value) {
|
public LongTag(final String name, final long value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -30,7 +30,7 @@ public final class NBTConstants {
|
|||||||
|
|
||||||
public static final Charset CHARSET = Charset.forName("UTF-8");
|
public static final Charset CHARSET = Charset.forName("UTF-8");
|
||||||
|
|
||||||
public static final int TYPE_END = 0, TYPE_BYTE = 1, TYPE_SHORT = 2, TYPE_INT = 3, TYPE_LONG = 4, TYPE_FLOAT = 5, TYPE_DOUBLE = 6, TYPE_BYTE_ARRAY = 7, TYPE_STRING = 8, TYPE_LIST = 9, TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11;
|
public static final int TYPE_END = 0, TYPE_BYTE = 1, TYPE_SHORT = 2, TYPE_INT = 3, TYPE_LONG = 4, TYPE_FLOAT = 5, TYPE_DOUBLE = 6, TYPE_BYTE_ARRAY = 7, TYPE_STRING = 8, TYPE_LIST = 9, TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default private constructor.
|
* Default private constructor.
|
||||||
@ -42,9 +42,11 @@ public final class NBTConstants {
|
|||||||
/**
|
/**
|
||||||
* Convert a type ID to its corresponding {@link Tag} class.
|
* Convert a type ID to its corresponding {@link Tag} class.
|
||||||
*
|
*
|
||||||
* @param id type ID
|
* @param id
|
||||||
|
* type ID
|
||||||
* @return tag class
|
* @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) {
|
public static Class<? extends Tag> getClassFromType(final int id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
|
@ -28,8 +28,10 @@ public final class NBTInputStream implements Closeable {
|
|||||||
* Creates a new {@code NBTInputStream}, which will source its data
|
* Creates a new {@code NBTInputStream}, which will source its data
|
||||||
* from the specified input stream.
|
* from the specified input stream.
|
||||||
*
|
*
|
||||||
* @param is the input stream
|
* @param is
|
||||||
* @throws IOException if an I/O error occurs
|
* the input stream
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs
|
||||||
*/
|
*/
|
||||||
public NBTInputStream(final InputStream is) throws IOException {
|
public NBTInputStream(final InputStream is) throws IOException {
|
||||||
this.is = new DataInputStream(is);
|
this.is = new DataInputStream(is);
|
||||||
@ -39,7 +41,8 @@ public final class NBTInputStream implements Closeable {
|
|||||||
* Reads an NBT tag from the stream.
|
* Reads an NBT tag from the stream.
|
||||||
*
|
*
|
||||||
* @return The tag that was read.
|
* @return The tag that was read.
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public Tag readTag() throws IOException {
|
public Tag readTag() throws IOException {
|
||||||
return readTag(0);
|
return readTag(0);
|
||||||
@ -48,9 +51,11 @@ public final class NBTInputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Reads an NBT from the stream.
|
* Reads an NBT from the stream.
|
||||||
*
|
*
|
||||||
* @param depth the depth of this tag
|
* @param depth
|
||||||
|
* the depth of this tag
|
||||||
* @return The tag that was read.
|
* @return The tag that was read.
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private Tag readTag(final int depth) throws IOException {
|
private Tag readTag(final int depth) throws IOException {
|
||||||
final int type = this.is.readByte() & 0xFF;
|
final int type = this.is.readByte() & 0xFF;
|
||||||
@ -61,7 +66,8 @@ public final class NBTInputStream implements Closeable {
|
|||||||
final byte[] nameBytes = new byte[nameLength];
|
final byte[] nameBytes = new byte[nameLength];
|
||||||
this.is.readFully(nameBytes);
|
this.is.readFully(nameBytes);
|
||||||
name = new String(nameBytes, NBTConstants.CHARSET);
|
name = new String(nameBytes, NBTConstants.CHARSET);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
name = "";
|
name = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,18 +77,23 @@ public final class NBTInputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Reads the payload of a tag, given the name and type.
|
* Reads the payload of a tag, given the name and type.
|
||||||
*
|
*
|
||||||
* @param type the type
|
* @param type
|
||||||
* @param name the name
|
* the type
|
||||||
* @param depth the depth
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @param depth
|
||||||
|
* the depth
|
||||||
* @return the tag
|
* @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 {
|
private Tag readTagPayload(final int type, final String name, final int depth) throws IOException {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case NBTConstants.TYPE_END:
|
case NBTConstants.TYPE_END:
|
||||||
if (depth == 0) {
|
if (depth == 0) {
|
||||||
throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
|
throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return new EndTag();
|
return new EndTag();
|
||||||
}
|
}
|
||||||
case NBTConstants.TYPE_BYTE:
|
case NBTConstants.TYPE_BYTE:
|
||||||
@ -127,7 +138,8 @@ public final class NBTInputStream implements Closeable {
|
|||||||
final Tag tag = readTag(depth + 1);
|
final Tag tag = readTag(depth + 1);
|
||||||
if (tag instanceof EndTag) {
|
if (tag instanceof EndTag) {
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
tagMap.put(tag.getName(), tag);
|
tagMap.put(tag.getName(), tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
* Creates a new <code>NBTOutputStream</code>, which will write data to the
|
* Creates a new <code>NBTOutputStream</code>, which will write data to the
|
||||||
* specified underlying output stream.
|
* specified underlying output stream.
|
||||||
*
|
*
|
||||||
* @param os The output stream.
|
* @param os
|
||||||
* @throws IOException if an I/O error occurs.
|
* The output stream.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public NBTOutputStream(final OutputStream os) throws IOException {
|
public NBTOutputStream(final OutputStream os) throws IOException {
|
||||||
this.os = new DataOutputStream(os);
|
this.os = new DataOutputStream(os);
|
||||||
@ -62,8 +64,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Writes a tag.
|
* Writes a tag.
|
||||||
*
|
*
|
||||||
* @param tag The tag to write.
|
* @param tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* The tag to write.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public void writeTag(final Tag tag) throws IOException {
|
public void writeTag(final Tag tag) throws IOException {
|
||||||
final int type = NBTUtils.getTypeCode(tag.getClass());
|
final int type = NBTUtils.getTypeCode(tag.getClass());
|
||||||
@ -84,8 +88,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Writes tag payload.
|
* Writes tag payload.
|
||||||
*
|
*
|
||||||
* @param tag The tag.
|
* @param tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeTagPayload(final Tag tag) throws IOException {
|
private void writeTagPayload(final Tag tag) throws IOException {
|
||||||
final int type = NBTUtils.getTypeCode(tag.getClass());
|
final int type = NBTUtils.getTypeCode(tag.getClass());
|
||||||
@ -134,8 +140,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Byte</code> tag.
|
* Writes a <code>TAG_Byte</code> tag.
|
||||||
*
|
*
|
||||||
* @param tag The tag.
|
* @param tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeByteTagPayload(final ByteTag tag) throws IOException {
|
private void writeByteTagPayload(final ByteTag tag) throws IOException {
|
||||||
this.os.writeByte(tag.getValue());
|
this.os.writeByte(tag.getValue());
|
||||||
@ -144,8 +152,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Byte_Array</code> tag.
|
* Writes a <code>TAG_Byte_Array</code> tag.
|
||||||
*
|
*
|
||||||
* @param tag The tag.
|
* @param tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeByteArrayTagPayload(final ByteArrayTag tag) throws IOException {
|
private void writeByteArrayTagPayload(final ByteArrayTag tag) throws IOException {
|
||||||
final byte[] bytes = tag.getValue();
|
final byte[] bytes = tag.getValue();
|
||||||
@ -156,8 +166,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Compound</code> tag.
|
* Writes a <code>TAG_Compound</code> tag.
|
||||||
*
|
*
|
||||||
* @param tag The tag.
|
* @param tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeCompoundTagPayload(final CompoundTag tag) throws IOException {
|
private void writeCompoundTagPayload(final CompoundTag tag) throws IOException {
|
||||||
for (final Tag childTag : tag.getValue().values()) {
|
for (final Tag childTag : tag.getValue().values()) {
|
||||||
@ -169,8 +181,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_List</code> tag.
|
* Writes a <code>TAG_List</code> tag.
|
||||||
*
|
*
|
||||||
* @param tag The tag.
|
* @param tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeListTagPayload(final ListTag tag) throws IOException {
|
private void writeListTagPayload(final ListTag tag) throws IOException {
|
||||||
final Class<? extends Tag> clazz = tag.getType();
|
final Class<? extends Tag> clazz = tag.getType();
|
||||||
@ -179,7 +193,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
|
|
||||||
this.os.writeByte(NBTUtils.getTypeCode(clazz));
|
this.os.writeByte(NBTUtils.getTypeCode(clazz));
|
||||||
this.os.writeInt(size);
|
this.os.writeInt(size);
|
||||||
for (Tag tag1 : tags) {
|
for (final Tag tag1 : tags) {
|
||||||
writeTagPayload(tag1);
|
writeTagPayload(tag1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,8 +201,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_String</code> tag.
|
* Writes a <code>TAG_String</code> tag.
|
||||||
*
|
*
|
||||||
* @param tag The tag.
|
* @param tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeStringTagPayload(final StringTag tag) throws IOException {
|
private void writeStringTagPayload(final StringTag tag) throws IOException {
|
||||||
final byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
|
final byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
|
||||||
@ -199,8 +215,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Double</code> tag.
|
* Writes a <code>TAG_Double</code> tag.
|
||||||
*
|
*
|
||||||
* @param tag The tag.
|
* @param tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeDoubleTagPayload(final DoubleTag tag) throws IOException {
|
private void writeDoubleTagPayload(final DoubleTag tag) throws IOException {
|
||||||
this.os.writeDouble(tag.getValue());
|
this.os.writeDouble(tag.getValue());
|
||||||
@ -209,8 +227,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Float</code> tag.
|
* Writes a <code>TAG_Float</code> tag.
|
||||||
*
|
*
|
||||||
* @param tag The tag.
|
* @param tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeFloatTagPayload(final FloatTag tag) throws IOException {
|
private void writeFloatTagPayload(final FloatTag tag) throws IOException {
|
||||||
this.os.writeFloat(tag.getValue());
|
this.os.writeFloat(tag.getValue());
|
||||||
@ -219,8 +239,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Long</code> tag.
|
* Writes a <code>TAG_Long</code> tag.
|
||||||
*
|
*
|
||||||
* @param tag The tag.
|
* @param tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeLongTagPayload(final LongTag tag) throws IOException {
|
private void writeLongTagPayload(final LongTag tag) throws IOException {
|
||||||
this.os.writeLong(tag.getValue());
|
this.os.writeLong(tag.getValue());
|
||||||
@ -229,8 +251,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Int</code> tag.
|
* Writes a <code>TAG_Int</code> tag.
|
||||||
*
|
*
|
||||||
* @param tag The tag.
|
* @param tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeIntTagPayload(final IntTag tag) throws IOException {
|
private void writeIntTagPayload(final IntTag tag) throws IOException {
|
||||||
this.os.writeInt(tag.getValue());
|
this.os.writeInt(tag.getValue());
|
||||||
@ -239,8 +263,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Short</code> tag.
|
* Writes a <code>TAG_Short</code> tag.
|
||||||
*
|
*
|
||||||
* @param tag The tag.
|
* @param tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeShortTagPayload(final ShortTag tag) throws IOException {
|
private void writeShortTagPayload(final ShortTag tag) throws IOException {
|
||||||
this.os.writeShort(tag.getValue());
|
this.os.writeShort(tag.getValue());
|
||||||
@ -249,8 +275,10 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Empty</code> tag.
|
* Writes a <code>TAG_Empty</code> tag.
|
||||||
*
|
*
|
||||||
* @param tag The tag.
|
* @param tag
|
||||||
* @throws IOException if an I/O error occurs.
|
* The tag.
|
||||||
|
* @throws IOException
|
||||||
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeEndTagPayload(final EndTag tag) {
|
private void writeEndTagPayload(final EndTag tag) {
|
||||||
/* empty */
|
/* empty */
|
||||||
|
@ -16,35 +16,48 @@ public final class NBTUtils {
|
|||||||
/**
|
/**
|
||||||
* Gets the type name of a tag.
|
* Gets the type name of a tag.
|
||||||
*
|
*
|
||||||
* @param clazz the tag class
|
* @param clazz
|
||||||
|
* the tag class
|
||||||
* @return The type name.
|
* @return The type name.
|
||||||
*/
|
*/
|
||||||
public static String getTypeName(final Class<? extends Tag> clazz) {
|
public static String getTypeName(final Class<? extends Tag> clazz) {
|
||||||
if (clazz.equals(ByteArrayTag.class)) {
|
if (clazz.equals(ByteArrayTag.class)) {
|
||||||
return "TAG_Byte_Array";
|
return "TAG_Byte_Array";
|
||||||
} else if (clazz.equals(ByteTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(ByteTag.class)) {
|
||||||
return "TAG_Byte";
|
return "TAG_Byte";
|
||||||
} else if (clazz.equals(CompoundTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(CompoundTag.class)) {
|
||||||
return "TAG_Compound";
|
return "TAG_Compound";
|
||||||
} else if (clazz.equals(DoubleTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(DoubleTag.class)) {
|
||||||
return "TAG_Double";
|
return "TAG_Double";
|
||||||
} else if (clazz.equals(EndTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(EndTag.class)) {
|
||||||
return "TAG_End";
|
return "TAG_End";
|
||||||
} else if (clazz.equals(FloatTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(FloatTag.class)) {
|
||||||
return "TAG_Float";
|
return "TAG_Float";
|
||||||
} else if (clazz.equals(IntTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(IntTag.class)) {
|
||||||
return "TAG_Int";
|
return "TAG_Int";
|
||||||
} else if (clazz.equals(ListTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(ListTag.class)) {
|
||||||
return "TAG_List";
|
return "TAG_List";
|
||||||
} else if (clazz.equals(LongTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(LongTag.class)) {
|
||||||
return "TAG_Long";
|
return "TAG_Long";
|
||||||
} else if (clazz.equals(ShortTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(ShortTag.class)) {
|
||||||
return "TAG_Short";
|
return "TAG_Short";
|
||||||
} else if (clazz.equals(StringTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(StringTag.class)) {
|
||||||
return "TAG_String";
|
return "TAG_String";
|
||||||
} else if (clazz.equals(IntArrayTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(IntArrayTag.class)) {
|
||||||
return "TAG_Int_Array";
|
return "TAG_Int_Array";
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,36 +65,50 @@ public final class NBTUtils {
|
|||||||
/**
|
/**
|
||||||
* Gets the type code of a tag class.
|
* Gets the type code of a tag class.
|
||||||
*
|
*
|
||||||
* @param clazz the tag class
|
* @param clazz
|
||||||
|
* the tag class
|
||||||
* @return The type code.
|
* @return The type code.
|
||||||
* @throws IllegalArgumentException if the tag class is invalid.
|
* @throws IllegalArgumentException
|
||||||
|
* if the tag class is invalid.
|
||||||
*/
|
*/
|
||||||
public static int getTypeCode(final Class<? extends Tag> clazz) {
|
public static int getTypeCode(final Class<? extends Tag> clazz) {
|
||||||
if (clazz.equals(ByteArrayTag.class)) {
|
if (clazz.equals(ByteArrayTag.class)) {
|
||||||
return NBTConstants.TYPE_BYTE_ARRAY;
|
return NBTConstants.TYPE_BYTE_ARRAY;
|
||||||
} else if (clazz.equals(ByteTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(ByteTag.class)) {
|
||||||
return NBTConstants.TYPE_BYTE;
|
return NBTConstants.TYPE_BYTE;
|
||||||
} else if (clazz.equals(CompoundTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(CompoundTag.class)) {
|
||||||
return NBTConstants.TYPE_COMPOUND;
|
return NBTConstants.TYPE_COMPOUND;
|
||||||
} else if (clazz.equals(DoubleTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(DoubleTag.class)) {
|
||||||
return NBTConstants.TYPE_DOUBLE;
|
return NBTConstants.TYPE_DOUBLE;
|
||||||
} else if (clazz.equals(EndTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(EndTag.class)) {
|
||||||
return NBTConstants.TYPE_END;
|
return NBTConstants.TYPE_END;
|
||||||
} else if (clazz.equals(FloatTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(FloatTag.class)) {
|
||||||
return NBTConstants.TYPE_FLOAT;
|
return NBTConstants.TYPE_FLOAT;
|
||||||
} else if (clazz.equals(IntTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(IntTag.class)) {
|
||||||
return NBTConstants.TYPE_INT;
|
return NBTConstants.TYPE_INT;
|
||||||
} else if (clazz.equals(ListTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(ListTag.class)) {
|
||||||
return NBTConstants.TYPE_LIST;
|
return NBTConstants.TYPE_LIST;
|
||||||
} else if (clazz.equals(LongTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(LongTag.class)) {
|
||||||
return NBTConstants.TYPE_LONG;
|
return NBTConstants.TYPE_LONG;
|
||||||
} else if (clazz.equals(ShortTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(ShortTag.class)) {
|
||||||
return NBTConstants.TYPE_SHORT;
|
return NBTConstants.TYPE_SHORT;
|
||||||
} else if (clazz.equals(StringTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(StringTag.class)) {
|
||||||
return NBTConstants.TYPE_STRING;
|
return NBTConstants.TYPE_STRING;
|
||||||
} else if (clazz.equals(IntArrayTag.class)) {
|
}
|
||||||
|
else if (clazz.equals(IntArrayTag.class)) {
|
||||||
return NBTConstants.TYPE_INT_ARRAY;
|
return NBTConstants.TYPE_INT_ARRAY;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,9 +116,11 @@ public final class NBTUtils {
|
|||||||
/**
|
/**
|
||||||
* Gets the class of a type of tag.
|
* Gets the class of a type of tag.
|
||||||
*
|
*
|
||||||
* @param type the type
|
* @param type
|
||||||
|
* the type
|
||||||
* @return The class.
|
* @return The class.
|
||||||
* @throws IllegalArgumentException if the tag type is invalid.
|
* @throws IllegalArgumentException
|
||||||
|
* if the tag type is invalid.
|
||||||
*/
|
*/
|
||||||
public static Class<? extends Tag> getTypeClass(final int type) {
|
public static Class<? extends Tag> getTypeClass(final int type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -127,9 +156,12 @@ public final class NBTUtils {
|
|||||||
/**
|
/**
|
||||||
* Get child tag of a NBT structure.
|
* Get child tag of a NBT structure.
|
||||||
*
|
*
|
||||||
* @param items the map to read from
|
* @param items
|
||||||
* @param key the key to look for
|
* the map to read from
|
||||||
* @param expected the expected NBT class type
|
* @param key
|
||||||
|
* the key to look for
|
||||||
|
* @param expected
|
||||||
|
* the expected NBT class type
|
||||||
* @return child tag
|
* @return child tag
|
||||||
*/
|
*/
|
||||||
public static <T extends Tag> T getChildTag(final Map<String, Tag> items, final String key, final Class<T> expected) throws IllegalArgumentException {
|
public static <T extends Tag> T getChildTag(final Map<String, Tag> items, final String key, final Class<T> expected) throws IllegalArgumentException {
|
||||||
|
@ -31,7 +31,8 @@ public final class ShortTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* 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) {
|
public ShortTag(final short value) {
|
||||||
super();
|
super();
|
||||||
@ -41,8 +42,10 @@ public final class ShortTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
* @param name the name of the tag
|
* @param name
|
||||||
* @param value the value of the tag
|
* the name of the tag
|
||||||
|
* @param value
|
||||||
|
* the value of the tag
|
||||||
*/
|
*/
|
||||||
public ShortTag(final String name, final short value) {
|
public ShortTag(final String name, final short value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -12,7 +12,8 @@ public final class StringTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* 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) {
|
public StringTag(final String value) {
|
||||||
super();
|
super();
|
||||||
@ -23,8 +24,10 @@ public final class StringTag extends Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
* @param name the name of the tag
|
* @param name
|
||||||
* @param value the value of the tag
|
* the name of the tag
|
||||||
|
* @param value
|
||||||
|
* the value of the tag
|
||||||
*/
|
*/
|
||||||
public StringTag(final String name, final String value) {
|
public StringTag(final String name, final String value) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -38,7 +38,8 @@ public abstract class Tag {
|
|||||||
/**
|
/**
|
||||||
* Creates the tag with the specified name.
|
* Creates the tag with the specified name.
|
||||||
*
|
*
|
||||||
* @param name the name
|
* @param name
|
||||||
|
* the name
|
||||||
*/
|
*/
|
||||||
Tag(String name) {
|
Tag(String name) {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
|
@ -5,17 +5,17 @@ import org.bukkit.World;
|
|||||||
public class WorldEditUtils {
|
public class WorldEditUtils {
|
||||||
public static void setNBT(final World world, final short id, final byte data, final int x, final int y, final int z, final com.intellectualcrafters.jnbt.CompoundTag tag) {
|
public static void setNBT(final World world, final short id, final byte data, final int x, final int y, final int z, final com.intellectualcrafters.jnbt.CompoundTag tag) {
|
||||||
|
|
||||||
// final LocalWorld bukkitWorld = BukkitUtil.getLocalWorld(world);
|
// final LocalWorld bukkitWorld = BukkitUtil.getLocalWorld(world);
|
||||||
|
|
||||||
// I need to somehow convert our CompoundTag to WorldEdit's
|
// I need to somehow convert our CompoundTag to WorldEdit's
|
||||||
|
|
||||||
// final BaseBlock block = new BaseBlock(5, 5, (CompoundTag) tag);
|
// final BaseBlock block = new BaseBlock(5, 5, (CompoundTag) tag);
|
||||||
// final Vector vector = new Vector(x, y, z);
|
// final Vector vector = new Vector(x, y, z);
|
||||||
// try {
|
// try {
|
||||||
// bukkitWorld.setBlock(vector, block);
|
// bukkitWorld.setBlock(vector, block);
|
||||||
// }
|
// }
|
||||||
// catch (final WorldEditException e) {
|
// catch (final WorldEditException e) {
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,11 @@ public class CDL {
|
|||||||
* Get the next value. The value can be wrapped in quotes. The value can
|
* Get the next value. The value can be wrapped in quotes. The value can
|
||||||
* be empty.
|
* 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.
|
* @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 {
|
private static String getValue(final JSONTokener x) throws JSONException {
|
||||||
char c;
|
char c;
|
||||||
@ -45,7 +47,7 @@ public class CDL {
|
|||||||
case '\'':
|
case '\'':
|
||||||
q = c;
|
q = c;
|
||||||
sb = new StringBuffer();
|
sb = new StringBuffer();
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
c = x.next();
|
c = x.next();
|
||||||
if (c == q) {
|
if (c == q) {
|
||||||
break;
|
break;
|
||||||
@ -68,20 +70,21 @@ public class CDL {
|
|||||||
/**
|
/**
|
||||||
* Produce a JSONArray of strings from a row of comma delimited values.
|
* 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.
|
* @return A JSONArray of strings.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static JSONArray rowToJSONArray(final JSONTokener x) throws JSONException {
|
public static JSONArray rowToJSONArray(final JSONTokener x) throws JSONException {
|
||||||
final JSONArray ja = new JSONArray();
|
final JSONArray ja = new JSONArray();
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
final String value = getValue(x);
|
final String value = getValue(x);
|
||||||
char c = x.next();
|
char c = x.next();
|
||||||
if ((value == null) || ((ja.length() == 0) && (value.length() == 0) && (c != ','))) {
|
if ((value == null) || ((ja.length() == 0) && (value.length() == 0) && (c != ','))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ja.put(value);
|
ja.put(value);
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
if (c == ',') {
|
if (c == ',') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -100,11 +103,13 @@ public class CDL {
|
|||||||
* Produce a JSONObject from a row of comma delimited text, using a
|
* Produce a JSONObject from a row of comma delimited text, using a
|
||||||
* parallel JSONArray of strings to provides the names of the elements.
|
* parallel JSONArray of strings to provides the names of the elements.
|
||||||
*
|
*
|
||||||
* @param names A JSONArray of names. This is commonly obtained from the
|
* @param names
|
||||||
* first row of a comma delimited text file using the
|
* A JSONArray of names. This is commonly obtained from the
|
||||||
* rowToJSONArray
|
* first row of a comma delimited text file using the
|
||||||
* method.
|
* rowToJSONArray
|
||||||
* @param x A JSONTokener of the source text.
|
* method.
|
||||||
|
* @param x
|
||||||
|
* A JSONTokener of the source text.
|
||||||
* @return A JSONObject combining the names and values.
|
* @return A JSONObject combining the names and values.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -118,7 +123,8 @@ public class CDL {
|
|||||||
* the comma character will be quoted. Troublesome characters may be
|
* the comma character will be quoted. Troublesome characters may be
|
||||||
* removed.
|
* removed.
|
||||||
*
|
*
|
||||||
* @param ja A JSONArray of strings.
|
* @param ja
|
||||||
|
* A JSONArray of strings.
|
||||||
* @return A string ending in NEWLINE.
|
* @return A string ending in NEWLINE.
|
||||||
*/
|
*/
|
||||||
public static String rowToString(final JSONArray ja) {
|
public static String rowToString(final JSONArray ja) {
|
||||||
@ -140,7 +146,8 @@ public class CDL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.append('"');
|
sb.append('"');
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sb.append(string);
|
sb.append(string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,7 +160,8 @@ public class CDL {
|
|||||||
* Produce a JSONArray of JSONObjects from a comma delimited text string,
|
* Produce a JSONArray of JSONObjects from a comma delimited text string,
|
||||||
* using the first row as a source of names.
|
* 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.
|
* @return A JSONArray of JSONObjects.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -165,7 +173,8 @@ public class CDL {
|
|||||||
* Produce a JSONArray of JSONObjects from a comma delimited text string,
|
* Produce a JSONArray of JSONObjects from a comma delimited text string,
|
||||||
* using the first row as a source of names.
|
* 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.
|
* @return A JSONArray of JSONObjects.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -177,8 +186,10 @@ public class CDL {
|
|||||||
* Produce a JSONArray of JSONObjects from a comma delimited text string
|
* Produce a JSONArray of JSONObjects from a comma delimited text string
|
||||||
* using a supplied JSONArray as the source of element names.
|
* using a supplied JSONArray as the source of element names.
|
||||||
*
|
*
|
||||||
* @param names A JSONArray of strings.
|
* @param names
|
||||||
* @param string The comma delimited text.
|
* A JSONArray of strings.
|
||||||
|
* @param string
|
||||||
|
* The comma delimited text.
|
||||||
* @return A JSONArray of JSONObjects.
|
* @return A JSONArray of JSONObjects.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -190,8 +201,10 @@ public class CDL {
|
|||||||
* Produce a JSONArray of JSONObjects from a comma delimited text string
|
* Produce a JSONArray of JSONObjects from a comma delimited text string
|
||||||
* using a supplied JSONArray as the source of element names.
|
* using a supplied JSONArray as the source of element names.
|
||||||
*
|
*
|
||||||
* @param names A JSONArray of strings.
|
* @param names
|
||||||
* @param x A JSONTokener of the source text.
|
* A JSONArray of strings.
|
||||||
|
* @param x
|
||||||
|
* A JSONTokener of the source text.
|
||||||
* @return A JSONArray of JSONObjects.
|
* @return A JSONArray of JSONObjects.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -200,7 +213,7 @@ public class CDL {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final JSONArray ja = new JSONArray();
|
final JSONArray ja = new JSONArray();
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
final JSONObject jo = rowToJSONObject(names, x);
|
final JSONObject jo = rowToJSONObject(names, x);
|
||||||
if (jo == null) {
|
if (jo == null) {
|
||||||
break;
|
break;
|
||||||
@ -218,7 +231,8 @@ public class CDL {
|
|||||||
* first row will be a list of names obtained by inspecting the first
|
* first row will be a list of names obtained by inspecting the first
|
||||||
* JSONObject.
|
* JSONObject.
|
||||||
*
|
*
|
||||||
* @param ja A JSONArray of JSONObjects.
|
* @param ja
|
||||||
|
* A JSONArray of JSONObjects.
|
||||||
* @return A comma delimited text.
|
* @return A comma delimited text.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -238,8 +252,10 @@ public class CDL {
|
|||||||
* a provided list of names. The list of names is not included in the
|
* a provided list of names. The list of names is not included in the
|
||||||
* output.
|
* output.
|
||||||
*
|
*
|
||||||
* @param names A JSONArray of strings.
|
* @param names
|
||||||
* @param ja A JSONArray of JSONObjects.
|
* A JSONArray of strings.
|
||||||
|
* @param ja
|
||||||
|
* A JSONArray of JSONObjects.
|
||||||
* @return A comma delimited text.
|
* @return A comma delimited text.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
|
@ -40,7 +40,8 @@ public class Cookie {
|
|||||||
* encoded values. We encode '=' and ';' because we must. We encode '%' and
|
* encoded values. We encode '=' and ';' because we must. We encode '%' and
|
||||||
* '+' because they are meta characters in URL encoding.
|
* '+' because they are meta characters in URL encoding.
|
||||||
*
|
*
|
||||||
* @param string The source string.
|
* @param string
|
||||||
|
* The source string.
|
||||||
* @return The escaped result.
|
* @return The escaped result.
|
||||||
*/
|
*/
|
||||||
public static String escape(final String string) {
|
public static String escape(final String string) {
|
||||||
@ -54,7 +55,8 @@ public class Cookie {
|
|||||||
sb.append('%');
|
sb.append('%');
|
||||||
sb.append(Character.forDigit((char) ((c >>> 4) & 0x0f), 16));
|
sb.append(Character.forDigit((char) ((c >>> 4) & 0x0f), 16));
|
||||||
sb.append(Character.forDigit((char) (c & 0x0f), 16));
|
sb.append(Character.forDigit((char) (c & 0x0f), 16));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,9 +74,10 @@ public class Cookie {
|
|||||||
* validation of the parameters. It only converts the cookie string into
|
* validation of the parameters. It only converts the cookie string into
|
||||||
* a JSONObject.
|
* a JSONObject.
|
||||||
*
|
*
|
||||||
* @param string The cookie specification string.
|
* @param string
|
||||||
|
* The cookie specification string.
|
||||||
* @return A JSONObject containing "name", "value", and possibly other
|
* @return A JSONObject containing "name", "value", and possibly other
|
||||||
* members.
|
* members.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static JSONObject toJSONObject(final String string) throws JSONException {
|
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||||
@ -91,10 +94,12 @@ public class Cookie {
|
|||||||
if (x.next() != '=') {
|
if (x.next() != '=') {
|
||||||
if (name.equals("secure")) {
|
if (name.equals("secure")) {
|
||||||
value = Boolean.TRUE;
|
value = Boolean.TRUE;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw x.syntaxError("Missing '=' in cookie parameter.");
|
throw x.syntaxError("Missing '=' in cookie parameter.");
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
value = unescape(x.nextTo(';'));
|
value = unescape(x.nextTo(';'));
|
||||||
x.next();
|
x.next();
|
||||||
}
|
}
|
||||||
@ -110,7 +115,8 @@ public class Cookie {
|
|||||||
* members, they will be appended to the cookie specification string.
|
* members, they will be appended to the cookie specification string.
|
||||||
* All other members are ignored.
|
* All other members are ignored.
|
||||||
*
|
*
|
||||||
* @param jo A JSONObject
|
* @param jo
|
||||||
|
* A JSONObject
|
||||||
* @return A cookie specification string
|
* @return A cookie specification string
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -142,9 +148,10 @@ public class Cookie {
|
|||||||
* Convert <code>%</code><i>hh</i> sequences to single characters, and
|
* Convert <code>%</code><i>hh</i> sequences to single characters, and
|
||||||
* convert plus to space.
|
* convert plus to space.
|
||||||
*
|
*
|
||||||
* @param string A string that may contain <code>+</code>
|
* @param string
|
||||||
* <small>(plus)</small> and <code>%</code><i>hh</i>
|
* A string that may contain <code>+</code>
|
||||||
* sequences.
|
* <small>(plus)</small> and <code>%</code><i>hh</i>
|
||||||
|
* sequences.
|
||||||
* @return The unescaped string.
|
* @return The unescaped string.
|
||||||
*/
|
*/
|
||||||
public static String unescape(final String string) {
|
public static String unescape(final String string) {
|
||||||
@ -154,7 +161,8 @@ public class Cookie {
|
|||||||
char c = string.charAt(i);
|
char c = string.charAt(i);
|
||||||
if (c == '+') {
|
if (c == '+') {
|
||||||
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 d = JSONTokener.dehexchar(string.charAt(i + 1));
|
||||||
final int e = JSONTokener.dehexchar(string.charAt(i + 2));
|
final int e = JSONTokener.dehexchar(string.charAt(i + 2));
|
||||||
if ((d >= 0) && (e >= 0)) {
|
if ((d >= 0) && (e >= 0)) {
|
||||||
|
@ -20,7 +20,8 @@ public class CookieList {
|
|||||||
* cookielistJSONObject.put(cookieJSONObject.getString("name"),
|
* cookielistJSONObject.put(cookieJSONObject.getString("name"),
|
||||||
* cookieJSONObject.getString("value"));
|
* cookieJSONObject.getString("value"));
|
||||||
*
|
*
|
||||||
* @param string A cookie list string
|
* @param string
|
||||||
|
* A cookie list string
|
||||||
* @return A JSONObject
|
* @return A JSONObject
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -42,7 +43,8 @@ public class CookieList {
|
|||||||
* The pairs are separated by ';'. The characters '%', '+', '=', and ';'
|
* The pairs are separated by ';'. The characters '%', '+', '=', and ';'
|
||||||
* in the names and values are replaced by "%hh".
|
* in the names and values are replaced by "%hh".
|
||||||
*
|
*
|
||||||
* @param jo A JSONObject
|
* @param jo
|
||||||
|
* A JSONObject
|
||||||
* @return A cookie list string
|
* @return A cookie list string
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
|
@ -40,6 +40,7 @@ public class HTTP {
|
|||||||
* Convert an HTTP header string into a JSONObject. It can be a request
|
* Convert an HTTP header string into a JSONObject. It can be a request
|
||||||
* header or a response header. A request header will contain
|
* header or a response header. A request header will contain
|
||||||
* <p/>
|
* <p/>
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* {
|
* {
|
||||||
* Method: "POST" (for example),
|
* Method: "POST" (for example),
|
||||||
@ -50,6 +51,7 @@ public class HTTP {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* A response header will contain
|
* A response header will contain
|
||||||
* <p/>
|
* <p/>
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* {
|
* {
|
||||||
* "HTTP-Version": "HTTP/1.1" (for example),
|
* "HTTP-Version": "HTTP/1.1" (for example),
|
||||||
@ -61,6 +63,7 @@ public class HTTP {
|
|||||||
* In addition, the other parameters in the header will be captured, using
|
* In addition, the other parameters in the header will be captured, using
|
||||||
* the HTTP field names as JSON names, so that
|
* the HTTP field names as JSON names, so that
|
||||||
* <p/>
|
* <p/>
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* Date: Sun, 26 May 2002 18:06:04 GMT
|
* Date: Sun, 26 May 2002 18:06:04 GMT
|
||||||
* Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
|
* Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
|
||||||
@ -69,6 +72,7 @@ public class HTTP {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* become
|
* become
|
||||||
* <p/>
|
* <p/>
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* {...
|
* {...
|
||||||
* Date: "Sun, 26 May 2002 18:06:04 GMT",
|
* Date: "Sun, 26 May 2002 18:06:04 GMT",
|
||||||
@ -77,12 +81,13 @@ public class HTTP {
|
|||||||
* ...}
|
* ...}
|
||||||
* </pre>
|
* </pre>
|
||||||
* <p/>
|
* <p/>
|
||||||
* It does no further checking or conversion. It does not parse dates.
|
* It does no further checking or conversion. It does not parse dates. It
|
||||||
* It does not do '%' transforms on URLs.
|
* does not do '%' transforms on URLs.
|
||||||
*
|
*
|
||||||
* @param string An HTTP header string.
|
* @param string
|
||||||
|
* An HTTP header string.
|
||||||
* @return A JSONObject containing the elements and attributes
|
* @return A JSONObject containing the elements and attributes
|
||||||
* of the XML string.
|
* of the XML string.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static JSONObject toJSONObject(final String string) throws JSONException {
|
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||||
@ -100,7 +105,8 @@ public class HTTP {
|
|||||||
jo.put("Reason-Phrase", x.nextTo('\0'));
|
jo.put("Reason-Phrase", x.nextTo('\0'));
|
||||||
x.next();
|
x.next();
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
// Request
|
// Request
|
||||||
|
|
||||||
@ -123,6 +129,7 @@ public class HTTP {
|
|||||||
/**
|
/**
|
||||||
* Convert a JSONObject into an HTTP header. A request header must contain
|
* Convert a JSONObject into an HTTP header. A request header must contain
|
||||||
* <p/>
|
* <p/>
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* {
|
* {
|
||||||
* Method: "POST" (for example),
|
* Method: "POST" (for example),
|
||||||
@ -133,6 +140,7 @@ public class HTTP {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* A response header must contain
|
* A response header must contain
|
||||||
* <p/>
|
* <p/>
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* {
|
* {
|
||||||
* "HTTP-Version": "HTTP/1.1" (for example),
|
* "HTTP-Version": "HTTP/1.1" (for example),
|
||||||
@ -141,13 +149,15 @@ public class HTTP {
|
|||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
* <p/>
|
* <p/>
|
||||||
* Any other members of the JSONObject will be output as HTTP fields.
|
* Any other members of the JSONObject will be output as HTTP fields. The
|
||||||
* The result will end with two CRLF pairs.
|
* result will end with two CRLF pairs.
|
||||||
*
|
*
|
||||||
* @param jo A JSONObject
|
* @param jo
|
||||||
|
* A JSONObject
|
||||||
* @return An HTTP header string.
|
* @return An HTTP header string.
|
||||||
* @throws JSONException if the object does not contain enough
|
* @throws JSONException
|
||||||
* information.
|
* if the object does not contain enough
|
||||||
|
* information.
|
||||||
*/
|
*/
|
||||||
public static String toString(final JSONObject jo) throws JSONException {
|
public static String toString(final JSONObject jo) throws JSONException {
|
||||||
final Iterator<String> keys = jo.keys();
|
final Iterator<String> keys = jo.keys();
|
||||||
@ -159,7 +169,8 @@ public class HTTP {
|
|||||||
sb.append(jo.getString("Status-Code"));
|
sb.append(jo.getString("Status-Code"));
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
sb.append(jo.getString("Reason-Phrase"));
|
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(jo.getString("Method"));
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
sb.append('"');
|
sb.append('"');
|
||||||
@ -167,7 +178,8 @@ public class HTTP {
|
|||||||
sb.append('"');
|
sb.append('"');
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
sb.append(jo.getString("HTTP-Version"));
|
sb.append(jo.getString("HTTP-Version"));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new JSONException("Not enough material for an HTTP header.");
|
throw new JSONException("Not enough material for an HTTP header.");
|
||||||
}
|
}
|
||||||
sb.append(CRLF);
|
sb.append(CRLF);
|
||||||
|
@ -12,7 +12,8 @@ public class HTTPTokener extends JSONTokener {
|
|||||||
/**
|
/**
|
||||||
* Construct an HTTPTokener from a string.
|
* Construct an HTTPTokener from a string.
|
||||||
*
|
*
|
||||||
* @param string A source string.
|
* @param string
|
||||||
|
* A source string.
|
||||||
*/
|
*/
|
||||||
public HTTPTokener(final String string) {
|
public HTTPTokener(final String string) {
|
||||||
super(string);
|
super(string);
|
||||||
@ -34,7 +35,7 @@ public class HTTPTokener extends JSONTokener {
|
|||||||
while (Character.isWhitespace(c));
|
while (Character.isWhitespace(c));
|
||||||
if ((c == '"') || (c == '\'')) {
|
if ((c == '"') || (c == '\'')) {
|
||||||
q = c;
|
q = c;
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
c = next();
|
c = next();
|
||||||
if (c < ' ') {
|
if (c < ' ') {
|
||||||
throw syntaxError("Unterminated string.");
|
throw syntaxError("Unterminated string.");
|
||||||
@ -45,7 +46,7 @@ public class HTTPTokener extends JSONTokener {
|
|||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
if ((c == 0) || Character.isWhitespace(c)) {
|
if ((c == 0) || Character.isWhitespace(c)) {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
@ -90,8 +90,10 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Construct a JSONArray from a JSONTokener.
|
* Construct a JSONArray from a JSONTokener.
|
||||||
*
|
*
|
||||||
* @param x A JSONTokener
|
* @param x
|
||||||
* @throws JSONException If there is a syntax error.
|
* A JSONTokener
|
||||||
|
* @throws JSONException
|
||||||
|
* If there is a syntax error.
|
||||||
*/
|
*/
|
||||||
public JSONArray(final JSONTokener x) throws JSONException {
|
public JSONArray(final JSONTokener x) throws JSONException {
|
||||||
this();
|
this();
|
||||||
@ -100,11 +102,12 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
if (x.nextClean() != ']') {
|
if (x.nextClean() != ']') {
|
||||||
x.back();
|
x.back();
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
if (x.nextClean() == ',') {
|
if (x.nextClean() == ',') {
|
||||||
x.back();
|
x.back();
|
||||||
this.myArrayList.add(JSONObject.NULL);
|
this.myArrayList.add(JSONObject.NULL);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
x.back();
|
x.back();
|
||||||
this.myArrayList.add(x.nextValue());
|
this.myArrayList.add(x.nextValue());
|
||||||
}
|
}
|
||||||
@ -127,10 +130,12 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Construct a JSONArray from a source JSON text.
|
* Construct a JSONArray from a source JSON text.
|
||||||
*
|
*
|
||||||
* @param source A string that begins with <code>[</code> <small>(left
|
* @param source
|
||||||
* bracket)</small> and ends with <code>]</code>
|
* A string that begins with <code>[</code> <small>(left
|
||||||
* <small>(right bracket)</small>.
|
* bracket)</small> and ends with <code>]</code>
|
||||||
* @throws JSONException If there is a syntax error.
|
* <small>(right bracket)</small>.
|
||||||
|
* @throws JSONException
|
||||||
|
* If there is a syntax error.
|
||||||
*/
|
*/
|
||||||
public JSONArray(final String source) throws JSONException {
|
public JSONArray(final String source) throws JSONException {
|
||||||
this(new JSONTokener(source));
|
this(new JSONTokener(source));
|
||||||
@ -139,12 +144,13 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Construct a JSONArray from a Collection.
|
* Construct a JSONArray from a Collection.
|
||||||
*
|
*
|
||||||
* @param collection A Collection.
|
* @param collection
|
||||||
|
* A Collection.
|
||||||
*/
|
*/
|
||||||
public JSONArray(final Collection<Object> collection) {
|
public JSONArray(final Collection<Object> collection) {
|
||||||
this.myArrayList = new ArrayList<Object>();
|
this.myArrayList = new ArrayList<Object>();
|
||||||
if (collection != null) {
|
if (collection != null) {
|
||||||
for (Object aCollection : collection) {
|
for (final Object aCollection : collection) {
|
||||||
this.myArrayList.add(JSONObject.wrap(aCollection));
|
this.myArrayList.add(JSONObject.wrap(aCollection));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,7 +159,8 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Construct a JSONArray from an array
|
* 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 {
|
public JSONArray(final Object array) throws JSONException {
|
||||||
this();
|
this();
|
||||||
@ -162,7 +169,8 @@ public class JSONArray {
|
|||||||
for (int i = 0; i < length; i += 1) {
|
for (int i = 0; i < length; i += 1) {
|
||||||
this.put(JSONObject.wrap(Array.get(array, i)));
|
this.put(JSONObject.wrap(Array.get(array, i)));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new JSONException("JSONArray initial value should be a string or collection or array.");
|
throw new JSONException("JSONArray initial value should be a string or collection or array.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,9 +178,11 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the object value associated with an index.
|
* 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.
|
* @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 {
|
public Object get(final int index) throws JSONException {
|
||||||
final Object object = this.opt(index);
|
final Object object = this.opt(index);
|
||||||
@ -186,16 +196,19 @@ public class JSONArray {
|
|||||||
* Get the boolean value associated with an index. The string values "true"
|
* Get the boolean value associated with an index. The string values "true"
|
||||||
* and "false" are converted to boolean.
|
* 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.
|
* @return The truth.
|
||||||
* @throws JSONException If there is no value for the index or if the value is not
|
* @throws JSONException
|
||||||
* convertible to boolean.
|
* 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 {
|
public boolean getBoolean(final int index) throws JSONException {
|
||||||
final Object object = this.get(index);
|
final Object object = this.get(index);
|
||||||
if (object.equals(Boolean.FALSE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("false"))) {
|
if (object.equals(Boolean.FALSE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("false"))) {
|
||||||
return 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;
|
return true;
|
||||||
}
|
}
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
|
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
|
||||||
@ -204,16 +217,19 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the double value associated with an index.
|
* 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.
|
* @return The value.
|
||||||
* @throws JSONException If the key is not found or if the value cannot be converted
|
* @throws JSONException
|
||||||
* to a number.
|
* If the key is not found or if the value cannot be converted
|
||||||
|
* to a number.
|
||||||
*/
|
*/
|
||||||
public double getDouble(final int index) throws JSONException {
|
public double getDouble(final int index) throws JSONException {
|
||||||
final Object object = this.get(index);
|
final Object object = this.get(index);
|
||||||
try {
|
try {
|
||||||
return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object);
|
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.");
|
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,15 +237,18 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the int value associated with an index.
|
* 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.
|
* @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 {
|
public int getInt(final int index) throws JSONException {
|
||||||
final Object object = this.get(index);
|
final Object object = this.get(index);
|
||||||
try {
|
try {
|
||||||
return object instanceof Number ? ((Number) object).intValue() : Integer.parseInt((String) object);
|
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.");
|
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,10 +256,12 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the JSONArray associated with an index.
|
* 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.
|
* @return A JSONArray value.
|
||||||
* @throws JSONException If there is no value for the index. or if the value is not a
|
* @throws JSONException
|
||||||
* JSONArray
|
* If there is no value for the index. or if the value is not a
|
||||||
|
* JSONArray
|
||||||
*/
|
*/
|
||||||
public JSONArray getJSONArray(final int index) throws JSONException {
|
public JSONArray getJSONArray(final int index) throws JSONException {
|
||||||
final Object object = this.get(index);
|
final Object object = this.get(index);
|
||||||
@ -253,10 +274,12 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the JSONObject associated with an index.
|
* Get the JSONObject associated with an index.
|
||||||
*
|
*
|
||||||
* @param index subscript
|
* @param index
|
||||||
|
* subscript
|
||||||
* @return A JSONObject value.
|
* @return A JSONObject value.
|
||||||
* @throws JSONException If there is no value for the index or if the value is not a
|
* @throws JSONException
|
||||||
* JSONObject
|
* If there is no value for the index or if the value is not a
|
||||||
|
* JSONObject
|
||||||
*/
|
*/
|
||||||
public JSONObject getJSONObject(final int index) throws JSONException {
|
public JSONObject getJSONObject(final int index) throws JSONException {
|
||||||
final Object object = this.get(index);
|
final Object object = this.get(index);
|
||||||
@ -269,16 +292,19 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the long value associated with an index.
|
* 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.
|
* @return The value.
|
||||||
* @throws JSONException If the key is not found or if the value cannot be converted
|
* @throws JSONException
|
||||||
* to a number.
|
* If the key is not found or if the value cannot be converted
|
||||||
|
* to a number.
|
||||||
*/
|
*/
|
||||||
public long getLong(final int index) throws JSONException {
|
public long getLong(final int index) throws JSONException {
|
||||||
final Object object = this.get(index);
|
final Object object = this.get(index);
|
||||||
try {
|
try {
|
||||||
return object instanceof Number ? ((Number) object).longValue() : Long.parseLong((String) object);
|
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.");
|
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -286,9 +312,11 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the string associated with an index.
|
* 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.
|
* @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 {
|
public String getString(final int index) throws JSONException {
|
||||||
final Object object = this.get(index);
|
final Object object = this.get(index);
|
||||||
@ -301,7 +329,8 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Determine if the value is null.
|
* 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.
|
* @return true if the value at the index is null, or if there is no value.
|
||||||
*/
|
*/
|
||||||
public boolean isNull(final int index) {
|
public boolean isNull(final int index) {
|
||||||
@ -313,9 +342,11 @@ public class JSONArray {
|
|||||||
* <code>separator</code> string is inserted between each element. Warning:
|
* <code>separator</code> string is inserted between each element. Warning:
|
||||||
* This method assumes that the data structure is acyclical.
|
* 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.
|
* @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 {
|
public String join(final String separator) throws JSONException {
|
||||||
final int len = this.length();
|
final int len = this.length();
|
||||||
@ -342,7 +373,8 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the optional object value associated with an index.
|
* 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.
|
* @return An object value, or null if there is no object at that index.
|
||||||
*/
|
*/
|
||||||
public Object opt(final int index) {
|
public Object opt(final int index) {
|
||||||
@ -354,7 +386,8 @@ public class JSONArray {
|
|||||||
* if there is no value at that index, or if the value is not Boolean.TRUE
|
* if there is no value at that index, or if the value is not Boolean.TRUE
|
||||||
* or the String "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.
|
* @return The truth.
|
||||||
*/
|
*/
|
||||||
public boolean optBoolean(final int index) {
|
public boolean optBoolean(final int index) {
|
||||||
@ -366,14 +399,17 @@ public class JSONArray {
|
|||||||
* defaultValue if there is no value at that index or if it is not a Boolean
|
* defaultValue if there is no value at that index or if it is not a Boolean
|
||||||
* or the String "true" or "false" (case insensitive).
|
* or the String "true" or "false" (case insensitive).
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index
|
||||||
* @param defaultValue A boolean default.
|
* The index must be between 0 and length() - 1.
|
||||||
|
* @param defaultValue
|
||||||
|
* A boolean default.
|
||||||
* @return The truth.
|
* @return The truth.
|
||||||
*/
|
*/
|
||||||
public boolean optBoolean(final int index, final boolean defaultValue) {
|
public boolean optBoolean(final int index, final boolean defaultValue) {
|
||||||
try {
|
try {
|
||||||
return this.getBoolean(index);
|
return this.getBoolean(index);
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -383,7 +419,8 @@ public class JSONArray {
|
|||||||
* if there is no value for the index, or if the value is not a number and
|
* if there is no value for the index, or if the value is not a number and
|
||||||
* cannot be converted to a number.
|
* 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.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public double optDouble(final int index) {
|
public double optDouble(final int index) {
|
||||||
@ -395,14 +432,17 @@ public class JSONArray {
|
|||||||
* is returned if there is no value for the index, or if the value is not a
|
* 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.
|
* number and cannot be converted to a number.
|
||||||
*
|
*
|
||||||
* @param index subscript
|
* @param index
|
||||||
* @param defaultValue The default value.
|
* subscript
|
||||||
|
* @param defaultValue
|
||||||
|
* The default value.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public double optDouble(final int index, final double defaultValue) {
|
public double optDouble(final int index, final double defaultValue) {
|
||||||
try {
|
try {
|
||||||
return this.getDouble(index);
|
return this.getDouble(index);
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -412,7 +452,8 @@ public class JSONArray {
|
|||||||
* there is no value for the index, or if the value is not a number and
|
* there is no value for the index, or if the value is not a number and
|
||||||
* cannot be converted to a number.
|
* 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.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public int optInt(final int index) {
|
public int optInt(final int index) {
|
||||||
@ -424,14 +465,17 @@ public class JSONArray {
|
|||||||
* returned if there is no value for the index, or if the value is not a
|
* returned if there is no value for the index, or if the value is not a
|
||||||
* number and cannot be converted to a number.
|
* number and cannot be converted to a number.
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index
|
||||||
* @param defaultValue The default value.
|
* The index must be between 0 and length() - 1.
|
||||||
|
* @param defaultValue
|
||||||
|
* The default value.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public int optInt(final int index, final int defaultValue) {
|
public int optInt(final int index, final int defaultValue) {
|
||||||
try {
|
try {
|
||||||
return this.getInt(index);
|
return this.getInt(index);
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -439,9 +483,10 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the optional JSONArray associated with an index.
|
* Get the optional JSONArray associated with an index.
|
||||||
*
|
*
|
||||||
* @param index subscript
|
* @param index
|
||||||
|
* subscript
|
||||||
* @return A JSONArray value, or null if the index has no value, or if the
|
* @return A JSONArray value, or null if the index has no value, or if the
|
||||||
* value is not a JSONArray.
|
* value is not a JSONArray.
|
||||||
*/
|
*/
|
||||||
public JSONArray optJSONArray(final int index) {
|
public JSONArray optJSONArray(final int index) {
|
||||||
final Object o = this.opt(index);
|
final Object o = this.opt(index);
|
||||||
@ -453,7 +498,8 @@ public class JSONArray {
|
|||||||
* the key is not found, or null if the index has no value, or if the value
|
* the key is not found, or null if the index has no value, or if the value
|
||||||
* is not a JSONObject.
|
* 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.
|
* @return A JSONObject value.
|
||||||
*/
|
*/
|
||||||
public JSONObject optJSONObject(final int index) {
|
public JSONObject optJSONObject(final int index) {
|
||||||
@ -466,7 +512,8 @@ public class JSONArray {
|
|||||||
* there is no value for the index, or if the value is not a number and
|
* there is no value for the index, or if the value is not a number and
|
||||||
* cannot be converted to a number.
|
* 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.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public long optLong(final int index) {
|
public long optLong(final int index) {
|
||||||
@ -478,14 +525,17 @@ public class JSONArray {
|
|||||||
* returned if there is no value for the index, or if the value is not a
|
* returned if there is no value for the index, or if the value is not a
|
||||||
* number and cannot be converted to a number.
|
* number and cannot be converted to a number.
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index
|
||||||
* @param defaultValue The default value.
|
* The index must be between 0 and length() - 1.
|
||||||
|
* @param defaultValue
|
||||||
|
* The default value.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public long optLong(final int index, final long defaultValue) {
|
public long optLong(final int index, final long defaultValue) {
|
||||||
try {
|
try {
|
||||||
return this.getLong(index);
|
return this.getLong(index);
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -495,7 +545,8 @@ public class JSONArray {
|
|||||||
* empty string if there is no value at that index. If the value is not a
|
* 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.
|
* 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.
|
* @return A String value.
|
||||||
*/
|
*/
|
||||||
public String optString(final int index) {
|
public String optString(final int index) {
|
||||||
@ -506,8 +557,10 @@ public class JSONArray {
|
|||||||
* Get the optional string associated with an index. The defaultValue is
|
* Get the optional string associated with an index. The defaultValue is
|
||||||
* returned if the key is not found.
|
* returned if the key is not found.
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index
|
||||||
* @param defaultValue The default value.
|
* The index must be between 0 and length() - 1.
|
||||||
|
* @param defaultValue
|
||||||
|
* The default value.
|
||||||
* @return A String value.
|
* @return A String value.
|
||||||
*/
|
*/
|
||||||
public String optString(final int index, final String defaultValue) {
|
public String optString(final int index, final String defaultValue) {
|
||||||
@ -518,7 +571,8 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Append a boolean value. This increases the array's length by one.
|
* Append a boolean value. This increases the array's length by one.
|
||||||
*
|
*
|
||||||
* @param value A boolean value.
|
* @param value
|
||||||
|
* A boolean value.
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final boolean value) {
|
public JSONArray put(final boolean value) {
|
||||||
@ -530,7 +584,8 @@ public class JSONArray {
|
|||||||
* Put a value in the JSONArray, where the value will be a JSONArray which
|
* Put a value in the JSONArray, where the value will be a JSONArray which
|
||||||
* is produced from a Collection.
|
* is produced from a Collection.
|
||||||
*
|
*
|
||||||
* @param value A Collection value.
|
* @param value
|
||||||
|
* A Collection value.
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final Collection<Object> value) {
|
public JSONArray put(final Collection<Object> value) {
|
||||||
@ -541,9 +596,11 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Append a double value. This increases the array's length by one.
|
* Append a double value. This increases the array's length by one.
|
||||||
*
|
*
|
||||||
* @param value A double value.
|
* @param value
|
||||||
|
* A double value.
|
||||||
* @return this.
|
* @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 {
|
public JSONArray put(final double value) throws JSONException {
|
||||||
final Double d = value;
|
final Double d = value;
|
||||||
@ -555,7 +612,8 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Append an int value. This increases the array's length by one.
|
* Append an int value. This increases the array's length by one.
|
||||||
*
|
*
|
||||||
* @param value An int value.
|
* @param value
|
||||||
|
* An int value.
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final int value) {
|
public JSONArray put(final int value) {
|
||||||
@ -566,7 +624,8 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Append an long value. This increases the array's length by one.
|
* Append an long value. This increases the array's length by one.
|
||||||
*
|
*
|
||||||
* @param value A long value.
|
* @param value
|
||||||
|
* A long value.
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final long value) {
|
public JSONArray put(final long value) {
|
||||||
@ -578,7 +637,8 @@ public class JSONArray {
|
|||||||
* Put a value in the JSONArray, where the value will be a JSONObject which
|
* Put a value in the JSONArray, where the value will be a JSONObject which
|
||||||
* is produced from a Map.
|
* is produced from a Map.
|
||||||
*
|
*
|
||||||
* @param value A Map value.
|
* @param value
|
||||||
|
* A Map value.
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final Map<String, Object> value) {
|
public JSONArray put(final Map<String, Object> value) {
|
||||||
@ -589,9 +649,10 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Append an object value. This increases the array's length by one.
|
* Append an object value. This increases the array's length by one.
|
||||||
*
|
*
|
||||||
* @param value An object value. The value should be a Boolean, Double,
|
* @param value
|
||||||
* Integer, JSONArray, JSONObject, Long, or String, or the
|
* An object value. The value should be a Boolean, Double,
|
||||||
* JSONObject.NULL object.
|
* Integer, JSONArray, JSONObject, Long, or String, or the
|
||||||
|
* JSONObject.NULL object.
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final Object value) {
|
public JSONArray put(final Object value) {
|
||||||
@ -604,10 +665,13 @@ public class JSONArray {
|
|||||||
* than the length of the JSONArray, then null elements will be added as
|
* than the length of the JSONArray, then null elements will be added as
|
||||||
* necessary to pad it out.
|
* necessary to pad it out.
|
||||||
*
|
*
|
||||||
* @param index The subscript.
|
* @param index
|
||||||
* @param value A boolean value.
|
* The subscript.
|
||||||
|
* @param value
|
||||||
|
* A boolean value.
|
||||||
* @return this.
|
* @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 {
|
public JSONArray put(final int index, final boolean value) throws JSONException {
|
||||||
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
|
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
|
||||||
@ -618,10 +682,13 @@ public class JSONArray {
|
|||||||
* Put a value in the JSONArray, where the value will be a JSONArray which
|
* Put a value in the JSONArray, where the value will be a JSONArray which
|
||||||
* is produced from a Collection.
|
* is produced from a Collection.
|
||||||
*
|
*
|
||||||
* @param index The subscript.
|
* @param index
|
||||||
* @param value A Collection value.
|
* The subscript.
|
||||||
|
* @param value
|
||||||
|
* A Collection value.
|
||||||
* @return this.
|
* @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 {
|
public JSONArray put(final int index, final Collection<Object> value) throws JSONException {
|
||||||
this.put(index, new JSONArray(value));
|
this.put(index, new JSONArray(value));
|
||||||
@ -633,10 +700,13 @@ public class JSONArray {
|
|||||||
* the JSONArray, then null elements will be added as necessary to pad it
|
* the JSONArray, then null elements will be added as necessary to pad it
|
||||||
* out.
|
* out.
|
||||||
*
|
*
|
||||||
* @param index The subscript.
|
* @param index
|
||||||
* @param value A double value.
|
* The subscript.
|
||||||
|
* @param value
|
||||||
|
* A double value.
|
||||||
* @return this.
|
* @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 {
|
public JSONArray put(final int index, final double value) throws JSONException {
|
||||||
this.put(index, new Double(value));
|
this.put(index, new Double(value));
|
||||||
@ -648,10 +718,13 @@ public class JSONArray {
|
|||||||
* the JSONArray, then null elements will be added as necessary to pad it
|
* the JSONArray, then null elements will be added as necessary to pad it
|
||||||
* out.
|
* out.
|
||||||
*
|
*
|
||||||
* @param index The subscript.
|
* @param index
|
||||||
* @param value An int value.
|
* The subscript.
|
||||||
|
* @param value
|
||||||
|
* An int value.
|
||||||
* @return this.
|
* @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 {
|
public JSONArray put(final int index, final int value) throws JSONException {
|
||||||
this.put(index, new Integer(value));
|
this.put(index, new Integer(value));
|
||||||
@ -663,10 +736,13 @@ public class JSONArray {
|
|||||||
* the JSONArray, then null elements will be added as necessary to pad it
|
* the JSONArray, then null elements will be added as necessary to pad it
|
||||||
* out.
|
* out.
|
||||||
*
|
*
|
||||||
* @param index The subscript.
|
* @param index
|
||||||
* @param value A long value.
|
* The subscript.
|
||||||
|
* @param value
|
||||||
|
* A long value.
|
||||||
* @return this.
|
* @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 {
|
public JSONArray put(final int index, final long value) throws JSONException {
|
||||||
this.put(index, new Long(value));
|
this.put(index, new Long(value));
|
||||||
@ -677,11 +753,14 @@ public class JSONArray {
|
|||||||
* Put a value in the JSONArray, where the value will be a JSONObject that
|
* Put a value in the JSONArray, where the value will be a JSONObject that
|
||||||
* is produced from a Map.
|
* is produced from a Map.
|
||||||
*
|
*
|
||||||
* @param index The subscript.
|
* @param index
|
||||||
* @param value The Map value.
|
* The subscript.
|
||||||
|
* @param value
|
||||||
|
* The Map value.
|
||||||
* @return this.
|
* @return this.
|
||||||
* @throws JSONException If the index is negative or if the the value is an invalid
|
* @throws JSONException
|
||||||
* number.
|
* 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 {
|
public JSONArray put(final int index, final Map<String, Object> value) throws JSONException {
|
||||||
this.put(index, new JSONObject(value));
|
this.put(index, new JSONObject(value));
|
||||||
@ -693,13 +772,16 @@ public class JSONArray {
|
|||||||
* than the length of the JSONArray, then null elements will be added as
|
* than the length of the JSONArray, then null elements will be added as
|
||||||
* necessary to pad it out.
|
* necessary to pad it out.
|
||||||
*
|
*
|
||||||
* @param index The subscript.
|
* @param index
|
||||||
* @param value The value to put into the array. The value should be a
|
* The subscript.
|
||||||
* Boolean, Double, Integer, JSONArray, JSONObject, Long, or
|
* @param value
|
||||||
* String, or the JSONObject.NULL object.
|
* 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.
|
* @return this.
|
||||||
* @throws JSONException If the index is negative or if the the value is an invalid
|
* @throws JSONException
|
||||||
* number.
|
* 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 {
|
public JSONArray put(final int index, final Object value) throws JSONException {
|
||||||
JSONObject.testValidity(value);
|
JSONObject.testValidity(value);
|
||||||
@ -708,7 +790,8 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
if (index < this.length()) {
|
if (index < this.length()) {
|
||||||
this.myArrayList.set(index, value);
|
this.myArrayList.set(index, value);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
while (index != this.length()) {
|
while (index != this.length()) {
|
||||||
this.put(JSONObject.NULL);
|
this.put(JSONObject.NULL);
|
||||||
}
|
}
|
||||||
@ -720,9 +803,10 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Remove an index and close the hole.
|
* Remove an index and close the hole.
|
||||||
*
|
*
|
||||||
* @param index The index of the element to be removed.
|
* @param index
|
||||||
|
* The index of the element to be removed.
|
||||||
* @return The value that was associated with the index, or null if there
|
* @return The value that was associated with the index, or null if there
|
||||||
* was no value.
|
* was no value.
|
||||||
*/
|
*/
|
||||||
public Object remove(final int index) {
|
public Object remove(final int index) {
|
||||||
return (index >= 0) && (index < this.length()) ? this.myArrayList.remove(index) : null;
|
return (index >= 0) && (index < this.length()) ? this.myArrayList.remove(index) : null;
|
||||||
@ -732,7 +816,8 @@ public class JSONArray {
|
|||||||
* Determine if two JSONArrays are similar.
|
* Determine if two JSONArrays are similar.
|
||||||
* They must contain similar sequences.
|
* They must contain similar sequences.
|
||||||
*
|
*
|
||||||
* @param other The other JSONArray
|
* @param other
|
||||||
|
* The other JSONArray
|
||||||
* @return true if they are equal
|
* @return true if they are equal
|
||||||
*/
|
*/
|
||||||
public boolean similar(final Object other) {
|
public boolean similar(final Object other) {
|
||||||
@ -750,11 +835,13 @@ public class JSONArray {
|
|||||||
if (!((JSONObject) valueThis).similar(valueOther)) {
|
if (!((JSONObject) valueThis).similar(valueOther)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (valueThis instanceof JSONArray) {
|
}
|
||||||
|
else if (valueThis instanceof JSONArray) {
|
||||||
if (!((JSONArray) valueThis).similar(valueOther)) {
|
if (!((JSONArray) valueThis).similar(valueOther)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!valueThis.equals(valueOther)) {
|
}
|
||||||
|
else if (!valueThis.equals(valueOther)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -765,11 +852,13 @@ public class JSONArray {
|
|||||||
* Produce a JSONObject by combining a JSONArray of names with the values of
|
* Produce a JSONObject by combining a JSONArray of names with the values of
|
||||||
* this JSONArray.
|
* this JSONArray.
|
||||||
*
|
*
|
||||||
* @param names A JSONArray containing a list of key strings. These will be
|
* @param names
|
||||||
* paired with the values.
|
* 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
|
* @return A JSONObject, or null if there are no names or if this JSONArray
|
||||||
* has no values.
|
* has no values.
|
||||||
* @throws JSONException If any of the names are null.
|
* @throws JSONException
|
||||||
|
* If any of the names are null.
|
||||||
*/
|
*/
|
||||||
public JSONObject toJSONObject(final JSONArray names) throws JSONException {
|
public JSONObject toJSONObject(final JSONArray names) throws JSONException {
|
||||||
if ((names == null) || (names.length() == 0) || (this.length() == 0)) {
|
if ((names == null) || (names.length() == 0) || (this.length() == 0)) {
|
||||||
@ -791,13 +880,14 @@ public class JSONArray {
|
|||||||
* Warning: This method assumes that the data structure is acyclical.
|
* Warning: This method assumes that the data structure is acyclical.
|
||||||
*
|
*
|
||||||
* @return a printable, displayable, transmittable representation of the
|
* @return a printable, displayable, transmittable representation of the
|
||||||
* array.
|
* array.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
try {
|
||||||
return this.toString(0);
|
return this.toString(0);
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -806,11 +896,12 @@ public class JSONArray {
|
|||||||
* Make a prettyprinted JSON text of this JSONArray. Warning: This method
|
* Make a prettyprinted JSON text of this JSONArray. Warning: This method
|
||||||
* assumes that the data structure is acyclical.
|
* assumes that the data structure is acyclical.
|
||||||
*
|
*
|
||||||
* @param indentFactor The number of spaces to add to each level of indentation.
|
* @param indentFactor
|
||||||
|
* The number of spaces to add to each level of indentation.
|
||||||
* @return a printable, displayable, transmittable representation of the
|
* @return a printable, displayable, transmittable representation of the
|
||||||
* object, beginning with <code>[</code> <small>(left
|
* object, beginning with <code>[</code> <small>(left
|
||||||
* bracket)</small> and ending with <code>]</code>
|
* bracket)</small> and ending with <code>]</code>
|
||||||
* <small>(right bracket)</small>.
|
* <small>(right bracket)</small>.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public String toString(final int indentFactor) throws JSONException {
|
public String toString(final int indentFactor) throws JSONException {
|
||||||
@ -839,8 +930,10 @@ public class JSONArray {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* Warning: This method assumes that the data structure is acyclical.
|
* Warning: This method assumes that the data structure is acyclical.
|
||||||
*
|
*
|
||||||
* @param indentFactor The number of spaces to add to each level of indentation.
|
* @param indentFactor
|
||||||
* @param indent The indention of the top level.
|
* The number of spaces to add to each level of indentation.
|
||||||
|
* @param indent
|
||||||
|
* The indention of the top level.
|
||||||
* @return The writer.
|
* @return The writer.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -852,7 +945,8 @@ public class JSONArray {
|
|||||||
|
|
||||||
if (length == 1) {
|
if (length == 1) {
|
||||||
JSONObject.writeValue(writer, this.myArrayList.get(0), indentFactor, indent);
|
JSONObject.writeValue(writer, this.myArrayList.get(0), indentFactor, indent);
|
||||||
} else if (length != 0) {
|
}
|
||||||
|
else if (length != 0) {
|
||||||
final int newindent = indent + indentFactor;
|
final int newindent = indent + indentFactor;
|
||||||
|
|
||||||
for (int i = 0; i < length; i += 1) {
|
for (int i = 0; i < length; i += 1) {
|
||||||
@ -873,7 +967,8 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
writer.write(']');
|
writer.write(']');
|
||||||
return writer;
|
return writer;
|
||||||
} catch (final IOException e) {
|
}
|
||||||
|
catch (final IOException e) {
|
||||||
throw new JSONException(e);
|
throw new JSONException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,13 @@ package com.intellectualcrafters.json;
|
|||||||
*/
|
*/
|
||||||
public class JSONException extends RuntimeException {
|
public class JSONException extends RuntimeException {
|
||||||
private static final long serialVersionUID = 0;
|
private static final long serialVersionUID = 0;
|
||||||
private Throwable cause;
|
private Throwable cause;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a JSONException with an explanatory message.
|
* 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) {
|
public JSONException(final String message) {
|
||||||
super(message);
|
super(message);
|
||||||
@ -22,7 +23,8 @@ public class JSONException extends RuntimeException {
|
|||||||
/**
|
/**
|
||||||
* Constructs a new JSONException with the specified cause.
|
* Constructs a new JSONException with the specified cause.
|
||||||
*
|
*
|
||||||
* @param cause The cause.
|
* @param cause
|
||||||
|
* The cause.
|
||||||
*/
|
*/
|
||||||
public JSONException(final Throwable cause) {
|
public JSONException(final Throwable cause) {
|
||||||
super(cause.getMessage());
|
super(cause.getMessage());
|
||||||
@ -34,7 +36,7 @@ public class JSONException extends RuntimeException {
|
|||||||
* or unknown.
|
* or unknown.
|
||||||
*
|
*
|
||||||
* @return the cause of this exception or null if the cause is nonexistent
|
* @return the cause of this exception or null if the cause is nonexistent
|
||||||
* or unknown.
|
* or unknown.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Throwable getCause() {
|
public Throwable getCause() {
|
||||||
|
@ -15,10 +15,13 @@ public class JSONML {
|
|||||||
/**
|
/**
|
||||||
* Parse XML values and store them in a JSONArray.
|
* Parse XML values and store them in a JSONArray.
|
||||||
*
|
*
|
||||||
* @param x The XMLTokener containing the source string.
|
* @param x
|
||||||
* @param arrayForm true if array form, false if object form.
|
* The XMLTokener containing the source string.
|
||||||
* @param ja The JSONArray that is containing the current tag or null
|
* @param arrayForm
|
||||||
* if we are at the outermost level.
|
* 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.
|
* @return A JSONArray if the value is the outermost tag, otherwise null.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -58,7 +61,8 @@ public class JSONML {
|
|||||||
throw x.syntaxError("Misshaped close tag");
|
throw x.syntaxError("Misshaped close tag");
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
} else if (token == XML.BANG) {
|
}
|
||||||
|
else if (token == XML.BANG) {
|
||||||
|
|
||||||
// <!
|
// <!
|
||||||
|
|
||||||
@ -66,44 +70,53 @@ public class JSONML {
|
|||||||
if (c == '-') {
|
if (c == '-') {
|
||||||
if (x.next() == '-') {
|
if (x.next() == '-') {
|
||||||
x.skipPast("-->");
|
x.skipPast("-->");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
x.back();
|
x.back();
|
||||||
}
|
}
|
||||||
} else if (c == '[') {
|
}
|
||||||
|
else if (c == '[') {
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
if (token.equals("CDATA") && (x.next() == '[')) {
|
if (token.equals("CDATA") && (x.next() == '[')) {
|
||||||
if (ja != null) {
|
if (ja != null) {
|
||||||
ja.put(x.nextCDATA());
|
ja.put(x.nextCDATA());
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw x.syntaxError("Expected 'CDATA['");
|
throw x.syntaxError("Expected 'CDATA['");
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
i = 1;
|
i = 1;
|
||||||
do {
|
do {
|
||||||
token = x.nextMeta();
|
token = x.nextMeta();
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
throw x.syntaxError("Missing '>' after '<!'.");
|
throw x.syntaxError("Missing '>' after '<!'.");
|
||||||
} else if (token == XML.LT) {
|
}
|
||||||
|
else if (token == XML.LT) {
|
||||||
i += 1;
|
i += 1;
|
||||||
} else if (token == XML.GT) {
|
}
|
||||||
|
else if (token == XML.GT) {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (i > 0);
|
while (i > 0);
|
||||||
}
|
}
|
||||||
} else if (token == XML.QUEST) {
|
}
|
||||||
|
else if (token == XML.QUEST) {
|
||||||
|
|
||||||
// <?
|
// <?
|
||||||
|
|
||||||
x.skipPast("?>");
|
x.skipPast("?>");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw x.syntaxError("Misshaped tag");
|
throw x.syntaxError("Misshaped tag");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open tag <
|
// Open tag <
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (!(token instanceof String)) {
|
if (!(token instanceof String)) {
|
||||||
throw x.syntaxError("Bad tagName '" + token + "'.");
|
throw x.syntaxError("Bad tagName '" + token + "'.");
|
||||||
}
|
}
|
||||||
@ -115,14 +128,15 @@ public class JSONML {
|
|||||||
if (ja != null) {
|
if (ja != null) {
|
||||||
ja.put(newja);
|
ja.put(newja);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
newjo.put("tagName", tagName);
|
newjo.put("tagName", tagName);
|
||||||
if (ja != null) {
|
if (ja != null) {
|
||||||
ja.put(newjo);
|
ja.put(newjo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
token = null;
|
token = null;
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
}
|
}
|
||||||
@ -147,7 +161,8 @@ public class JSONML {
|
|||||||
}
|
}
|
||||||
newjo.accumulate(attribute, XML.stringToValue((String) token));
|
newjo.accumulate(attribute, XML.stringToValue((String) token));
|
||||||
token = null;
|
token = null;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
newjo.accumulate(attribute, "");
|
newjo.accumulate(attribute, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,14 +179,16 @@ public class JSONML {
|
|||||||
if (ja == null) {
|
if (ja == null) {
|
||||||
if (arrayForm) {
|
if (arrayForm) {
|
||||||
return newja;
|
return newja;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return newjo;
|
return newjo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Content, between <...> and </...>
|
// Content, between <...> and </...>
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (token != XML.GT) {
|
if (token != XML.GT) {
|
||||||
throw x.syntaxError("Misshaped tag");
|
throw x.syntaxError("Misshaped tag");
|
||||||
}
|
}
|
||||||
@ -187,14 +204,16 @@ public class JSONML {
|
|||||||
if (ja == null) {
|
if (ja == null) {
|
||||||
if (arrayForm) {
|
if (arrayForm) {
|
||||||
return newja;
|
return newja;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return newjo;
|
return newjo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (ja != null) {
|
if (ja != null) {
|
||||||
ja.put(token instanceof String ? XML.stringToValue((String) token) : token);
|
ja.put(token instanceof String ? XML.stringToValue((String) token) : token);
|
||||||
}
|
}
|
||||||
@ -211,7 +230,8 @@ public class JSONML {
|
|||||||
* JSONArrays will represent the child tags.
|
* JSONArrays will represent the child tags.
|
||||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
* 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.
|
* @return A JSONArray containing the structured data from the XML string.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -228,7 +248,8 @@ public class JSONML {
|
|||||||
* JSONArrays will represent the child content and tags.
|
* JSONArrays will represent the child content and tags.
|
||||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
* 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.
|
* @return A JSONArray containing the structured data from the XML string.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -246,7 +267,8 @@ public class JSONML {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
* 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.
|
* @return A JSONObject containing the structured data from the XML string.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -264,7 +286,8 @@ public class JSONML {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
* 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.
|
* @return A JSONObject containing the structured data from the XML string.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -275,7 +298,8 @@ public class JSONML {
|
|||||||
/**
|
/**
|
||||||
* Reverse the JSONML transformation, making an XML text from a JSONArray.
|
* Reverse the JSONML transformation, making an XML text from a JSONArray.
|
||||||
*
|
*
|
||||||
* @param ja A JSONArray.
|
* @param ja
|
||||||
|
* A JSONArray.
|
||||||
* @return An XML string.
|
* @return An XML string.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -319,7 +343,8 @@ public class JSONML {
|
|||||||
sb.append('"');
|
sb.append('"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
i = 1;
|
i = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,7 +354,8 @@ public class JSONML {
|
|||||||
if (i >= length) {
|
if (i >= length) {
|
||||||
sb.append('/');
|
sb.append('/');
|
||||||
sb.append('>');
|
sb.append('>');
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sb.append('>');
|
sb.append('>');
|
||||||
do {
|
do {
|
||||||
object = ja.get(i);
|
object = ja.get(i);
|
||||||
@ -337,9 +363,11 @@ public class JSONML {
|
|||||||
if (object != null) {
|
if (object != null) {
|
||||||
if (object instanceof String) {
|
if (object instanceof String) {
|
||||||
sb.append(XML.escape(object.toString()));
|
sb.append(XML.escape(object.toString()));
|
||||||
} else if (object instanceof JSONObject) {
|
}
|
||||||
|
else if (object instanceof JSONObject) {
|
||||||
sb.append(toString((JSONObject) object));
|
sb.append(toString((JSONObject) object));
|
||||||
} else if (object instanceof JSONArray) {
|
}
|
||||||
|
else if (object instanceof JSONArray) {
|
||||||
sb.append(toString((JSONArray) object));
|
sb.append(toString((JSONArray) object));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -359,7 +387,8 @@ public class JSONML {
|
|||||||
* then it must have a "childNodes" property containing an array of objects.
|
* then it must have a "childNodes" property containing an array of objects.
|
||||||
* The other properties are attributes with string values.
|
* The other properties are attributes with string values.
|
||||||
*
|
*
|
||||||
* @param jo A JSONObject.
|
* @param jo
|
||||||
|
* A JSONObject.
|
||||||
* @return An XML string.
|
* @return An XML string.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -410,7 +439,8 @@ public class JSONML {
|
|||||||
if (ja == null) {
|
if (ja == null) {
|
||||||
sb.append('/');
|
sb.append('/');
|
||||||
sb.append('>');
|
sb.append('>');
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sb.append('>');
|
sb.append('>');
|
||||||
length = ja.length();
|
length = ja.length();
|
||||||
for (i = 0; i < length; i += 1) {
|
for (i = 0; i < length; i += 1) {
|
||||||
@ -418,11 +448,14 @@ public class JSONML {
|
|||||||
if (object != null) {
|
if (object != null) {
|
||||||
if (object instanceof String) {
|
if (object instanceof String) {
|
||||||
sb.append(XML.escape(object.toString()));
|
sb.append(XML.escape(object.toString()));
|
||||||
} else if (object instanceof JSONObject) {
|
}
|
||||||
|
else if (object instanceof JSONObject) {
|
||||||
sb.append(toString((JSONObject) object));
|
sb.append(toString((JSONObject) object));
|
||||||
} else if (object instanceof JSONArray) {
|
}
|
||||||
|
else if (object instanceof JSONArray) {
|
||||||
sb.append(toString((JSONArray) object));
|
sb.append(toString((JSONArray) object));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sb.append(object.toString());
|
sb.append(object.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -16,12 +16,14 @@ import java.io.StringWriter;
|
|||||||
* these methods return the JSONWriter instance, permitting cascade style. For
|
* these methods return the JSONWriter instance, permitting cascade style. For
|
||||||
* example,
|
* example,
|
||||||
* <p/>
|
* <p/>
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* myString = new JSONStringer().object().key("JSON").value("Hello, World!").endObject().toString();
|
* myString = new JSONStringer().object().key("JSON").value("Hello, World!").endObject().toString();
|
||||||
* </pre>
|
* </pre>
|
||||||
* <p/>
|
* <p/>
|
||||||
* which produces the string
|
* which produces the string
|
||||||
* <p/>
|
* <p/>
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* {"JSON":"Hello, World!"}
|
* {"JSON":"Hello, World!"}
|
||||||
* </pre>
|
* </pre>
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package com.intellectualcrafters.json;
|
package com.intellectualcrafters.json;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.StringReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A JSONTokener takes a source string and extracts characters and tokens from
|
* A JSONTokener takes a source string and extracts characters and tokens from
|
||||||
@ -13,17 +18,18 @@ import java.io.*;
|
|||||||
public class JSONTokener {
|
public class JSONTokener {
|
||||||
|
|
||||||
private final Reader reader;
|
private final Reader reader;
|
||||||
private long character;
|
private long character;
|
||||||
private boolean eof;
|
private boolean eof;
|
||||||
private long index;
|
private long index;
|
||||||
private long line;
|
private long line;
|
||||||
private char previous;
|
private char previous;
|
||||||
private boolean usePrevious;
|
private boolean usePrevious;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONTokener from a Reader.
|
* Construct a JSONTokener from a Reader.
|
||||||
*
|
*
|
||||||
* @param reader A reader.
|
* @param reader
|
||||||
|
* A reader.
|
||||||
*/
|
*/
|
||||||
public JSONTokener(final Reader reader) {
|
public JSONTokener(final Reader reader) {
|
||||||
this.reader = reader.markSupported() ? reader : new BufferedReader(reader);
|
this.reader = reader.markSupported() ? reader : new BufferedReader(reader);
|
||||||
@ -38,7 +44,8 @@ public class JSONTokener {
|
|||||||
/**
|
/**
|
||||||
* Construct a JSONTokener from an InputStream.
|
* Construct a JSONTokener from an InputStream.
|
||||||
*
|
*
|
||||||
* @param inputStream The source.
|
* @param inputStream
|
||||||
|
* The source.
|
||||||
*/
|
*/
|
||||||
public JSONTokener(final InputStream inputStream) throws JSONException {
|
public JSONTokener(final InputStream inputStream) throws JSONException {
|
||||||
this(new InputStreamReader(inputStream));
|
this(new InputStreamReader(inputStream));
|
||||||
@ -47,7 +54,8 @@ public class JSONTokener {
|
|||||||
/**
|
/**
|
||||||
* Construct a JSONTokener from a string.
|
* Construct a JSONTokener from a string.
|
||||||
*
|
*
|
||||||
* @param s A source string.
|
* @param s
|
||||||
|
* A source string.
|
||||||
*/
|
*/
|
||||||
public JSONTokener(final String s) {
|
public JSONTokener(final String s) {
|
||||||
this(new StringReader(s));
|
this(new StringReader(s));
|
||||||
@ -56,8 +64,9 @@ public class JSONTokener {
|
|||||||
/**
|
/**
|
||||||
* Get the hex value of a character (base16).
|
* Get the hex value of a character (base16).
|
||||||
*
|
*
|
||||||
* @param c A character between '0' and '9' or between 'A' and 'F' or
|
* @param c
|
||||||
* between 'a' and 'f'.
|
* 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.
|
* @return An int between 0 and 15, or -1 if c was not a hex digit.
|
||||||
*/
|
*/
|
||||||
public static int dehexchar(final char c) {
|
public static int dehexchar(final char c) {
|
||||||
@ -117,10 +126,12 @@ public class JSONTokener {
|
|||||||
if (this.usePrevious) {
|
if (this.usePrevious) {
|
||||||
this.usePrevious = false;
|
this.usePrevious = false;
|
||||||
c = this.previous;
|
c = this.previous;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
try {
|
try {
|
||||||
c = this.reader.read();
|
c = this.reader.read();
|
||||||
} catch (final IOException exception) {
|
}
|
||||||
|
catch (final IOException exception) {
|
||||||
throw new JSONException(exception);
|
throw new JSONException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,10 +144,12 @@ public class JSONTokener {
|
|||||||
if (this.previous == '\r') {
|
if (this.previous == '\r') {
|
||||||
this.line += 1;
|
this.line += 1;
|
||||||
this.character = c == '\n' ? 0 : 1;
|
this.character = c == '\n' ? 0 : 1;
|
||||||
} else if (c == '\n') {
|
}
|
||||||
|
else if (c == '\n') {
|
||||||
this.line += 1;
|
this.line += 1;
|
||||||
this.character = 0;
|
this.character = 0;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.character += 1;
|
this.character += 1;
|
||||||
}
|
}
|
||||||
this.previous = (char) c;
|
this.previous = (char) c;
|
||||||
@ -147,9 +160,11 @@ public class JSONTokener {
|
|||||||
* Consume the next character, and check that it matches a specified
|
* Consume the next character, and check that it matches a specified
|
||||||
* character.
|
* character.
|
||||||
*
|
*
|
||||||
* @param c The character to match.
|
* @param c
|
||||||
|
* The character to match.
|
||||||
* @return The character.
|
* @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 {
|
public char next(final char c) throws JSONException {
|
||||||
final char n = this.next();
|
final char n = this.next();
|
||||||
@ -162,10 +177,12 @@ public class JSONTokener {
|
|||||||
/**
|
/**
|
||||||
* Get the next n characters.
|
* 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.
|
* @return A string of n characters.
|
||||||
* @throws JSONException Substring bounds error if there are not
|
* @throws JSONException
|
||||||
* n characters remaining in the source string.
|
* Substring bounds error if there are not
|
||||||
|
* n characters remaining in the source string.
|
||||||
*/
|
*/
|
||||||
public String next(final int n) throws JSONException {
|
public String next(final int n) throws JSONException {
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
@ -192,7 +209,7 @@ public class JSONTokener {
|
|||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public char nextClean() throws JSONException {
|
public char nextClean() throws JSONException {
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
final char c = this.next();
|
final char c = this.next();
|
||||||
if ((c == 0) || (c > ' ')) {
|
if ((c == 0) || (c > ' ')) {
|
||||||
return c;
|
return c;
|
||||||
@ -206,16 +223,18 @@ public class JSONTokener {
|
|||||||
* allow strings in single quotes, but an implementation is allowed to
|
* allow strings in single quotes, but an implementation is allowed to
|
||||||
* accept them.
|
* accept them.
|
||||||
*
|
*
|
||||||
* @param quote The quoting character, either <code>"</code>
|
* @param quote
|
||||||
* <small>(double quote)</small> or <code>'</code>
|
* The quoting character, either <code>"</code>
|
||||||
* <small>(single quote)</small>.
|
* <small>(double quote)</small> or <code>'</code>
|
||||||
|
* <small>(single quote)</small>.
|
||||||
* @return A String.
|
* @return A String.
|
||||||
* @throws JSONException Unterminated string.
|
* @throws JSONException
|
||||||
|
* Unterminated string.
|
||||||
*/
|
*/
|
||||||
public String nextString(final char quote) throws JSONException {
|
public String nextString(final char quote) throws JSONException {
|
||||||
char c;
|
char c;
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
c = this.next();
|
c = this.next();
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -266,12 +285,13 @@ public class JSONTokener {
|
|||||||
* Get the text up but not including the specified character or the
|
* Get the text up but not including the specified character or the
|
||||||
* end of line, whichever comes first.
|
* end of line, whichever comes first.
|
||||||
*
|
*
|
||||||
* @param delimiter A delimiter character.
|
* @param delimiter
|
||||||
|
* A delimiter character.
|
||||||
* @return A string.
|
* @return A string.
|
||||||
*/
|
*/
|
||||||
public String nextTo(final char delimiter) throws JSONException {
|
public String nextTo(final char delimiter) throws JSONException {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
final char c = this.next();
|
final char c = this.next();
|
||||||
if ((c == delimiter) || (c == 0) || (c == '\n') || (c == '\r')) {
|
if ((c == delimiter) || (c == 0) || (c == '\n') || (c == '\r')) {
|
||||||
if (c != 0) {
|
if (c != 0) {
|
||||||
@ -287,13 +307,14 @@ public class JSONTokener {
|
|||||||
* Get the text up but not including one of the specified delimiter
|
* Get the text up but not including one of the specified delimiter
|
||||||
* characters or the end of line, whichever comes first.
|
* 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.
|
* @return A string, trimmed.
|
||||||
*/
|
*/
|
||||||
public String nextTo(final String delimiters) throws JSONException {
|
public String nextTo(final String delimiters) throws JSONException {
|
||||||
char c;
|
char c;
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
c = this.next();
|
c = this.next();
|
||||||
if ((delimiters.indexOf(c) >= 0) || (c == 0) || (c == '\n') || (c == '\r')) {
|
if ((delimiters.indexOf(c) >= 0) || (c == 0) || (c == '\n') || (c == '\r')) {
|
||||||
if (c != 0) {
|
if (c != 0) {
|
||||||
@ -310,7 +331,8 @@ public class JSONTokener {
|
|||||||
* JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
|
* JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
|
||||||
*
|
*
|
||||||
* @return An object.
|
* @return An object.
|
||||||
* @throws JSONException If syntax error.
|
* @throws JSONException
|
||||||
|
* If syntax error.
|
||||||
*/
|
*/
|
||||||
public Object nextValue() throws JSONException {
|
public Object nextValue() throws JSONException {
|
||||||
char c = this.nextClean();
|
char c = this.nextClean();
|
||||||
@ -354,9 +376,10 @@ public class JSONTokener {
|
|||||||
* Skip characters until the next character is the requested character.
|
* Skip characters until the next character is the requested character.
|
||||||
* If the requested character is not found, no characters are skipped.
|
* If the requested character is not found, no characters are skipped.
|
||||||
*
|
*
|
||||||
* @param to A character to skip to.
|
* @param to
|
||||||
|
* A character to skip to.
|
||||||
* @return The requested character, or zero if the requested character
|
* @return The requested character, or zero if the requested character
|
||||||
* is not found.
|
* is not found.
|
||||||
*/
|
*/
|
||||||
public char skipTo(final char to) throws JSONException {
|
public char skipTo(final char to) throws JSONException {
|
||||||
char c;
|
char c;
|
||||||
@ -376,7 +399,8 @@ public class JSONTokener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (c != to);
|
while (c != to);
|
||||||
} catch (final IOException exception) {
|
}
|
||||||
|
catch (final IOException exception) {
|
||||||
throw new JSONException(exception);
|
throw new JSONException(exception);
|
||||||
}
|
}
|
||||||
this.back();
|
this.back();
|
||||||
@ -386,7 +410,8 @@ public class JSONTokener {
|
|||||||
/**
|
/**
|
||||||
* Make a JSONException to signal a syntax error.
|
* 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
|
* @return A JSONException object, suitable for throwing
|
||||||
*/
|
*/
|
||||||
public JSONException syntaxError(final String message) {
|
public JSONException syntaxError(final String message) {
|
||||||
|
@ -17,12 +17,14 @@ import java.io.Writer;
|
|||||||
* these methods return the JSONWriter instance, permitting a cascade style. For
|
* these methods return the JSONWriter instance, permitting a cascade style. For
|
||||||
* example,
|
* example,
|
||||||
* <p/>
|
* <p/>
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* new JSONWriter(myWriter).object().key("JSON").value("Hello, World!").endObject();
|
* new JSONWriter(myWriter).object().key("JSON").value("Hello, World!").endObject();
|
||||||
* </pre>
|
* </pre>
|
||||||
* <p/>
|
* <p/>
|
||||||
* which writes
|
* which writes
|
||||||
* <p/>
|
* <p/>
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* {"JSON":"Hello, World!"}
|
* {"JSON":"Hello, World!"}
|
||||||
* </pre>
|
* </pre>
|
||||||
@ -41,7 +43,7 @@ public class JSONWriter {
|
|||||||
/**
|
/**
|
||||||
* The writer that will receive the output.
|
* The writer that will receive the output.
|
||||||
*/
|
*/
|
||||||
protected final Writer writer;
|
protected final Writer writer;
|
||||||
/**
|
/**
|
||||||
* The object/array stack.
|
* The object/array stack.
|
||||||
*/
|
*/
|
||||||
@ -54,16 +56,16 @@ public class JSONWriter {
|
|||||||
* 'k' (key),
|
* 'k' (key),
|
||||||
* 'o' (object).
|
* 'o' (object).
|
||||||
*/
|
*/
|
||||||
protected char mode;
|
protected char mode;
|
||||||
/**
|
/**
|
||||||
* The comma flag determines if a comma should be output before the next
|
* The comma flag determines if a comma should be output before the next
|
||||||
* value.
|
* value.
|
||||||
*/
|
*/
|
||||||
private boolean comma;
|
private boolean comma;
|
||||||
/**
|
/**
|
||||||
* The stack top index. A value of 0 indicates that the stack is empty.
|
* The stack top index. A value of 0 indicates that the stack is empty.
|
||||||
*/
|
*/
|
||||||
private int top;
|
private int top;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a fresh JSONWriter. It can be used to build one JSON text.
|
* Make a fresh JSONWriter. It can be used to build one JSON text.
|
||||||
@ -79,9 +81,11 @@ public class JSONWriter {
|
|||||||
/**
|
/**
|
||||||
* Append a value.
|
* Append a value.
|
||||||
*
|
*
|
||||||
* @param string A string value.
|
* @param string
|
||||||
|
* A string value.
|
||||||
* @return this
|
* @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 {
|
private JSONWriter append(final String string) throws JSONException {
|
||||||
if (string == null) {
|
if (string == null) {
|
||||||
@ -93,7 +97,8 @@ public class JSONWriter {
|
|||||||
this.writer.write(',');
|
this.writer.write(',');
|
||||||
}
|
}
|
||||||
this.writer.write(string);
|
this.writer.write(string);
|
||||||
} catch (final IOException e) {
|
}
|
||||||
|
catch (final IOException e) {
|
||||||
throw new JSONException(e);
|
throw new JSONException(e);
|
||||||
}
|
}
|
||||||
if (this.mode == 'o') {
|
if (this.mode == 'o') {
|
||||||
@ -111,10 +116,11 @@ public class JSONWriter {
|
|||||||
* <code>endArray</code> method must be called to mark the array's end.
|
* <code>endArray</code> method must be called to mark the array's end.
|
||||||
*
|
*
|
||||||
* @return this
|
* @return this
|
||||||
* @throws JSONException If the nesting is too deep, or if the object is
|
* @throws JSONException
|
||||||
* started in the wrong place (for example as a key or after the
|
* If the nesting is too deep, or if the object is
|
||||||
* end of the
|
* started in the wrong place (for example as a key or after the
|
||||||
* outermost array or object).
|
* end of the
|
||||||
|
* outermost array or object).
|
||||||
*/
|
*/
|
||||||
public JSONWriter array() throws JSONException {
|
public JSONWriter array() throws JSONException {
|
||||||
if ((this.mode == 'i') || (this.mode == 'o') || (this.mode == 'a')) {
|
if ((this.mode == 'i') || (this.mode == 'o') || (this.mode == 'a')) {
|
||||||
@ -129,10 +135,13 @@ public class JSONWriter {
|
|||||||
/**
|
/**
|
||||||
* End something.
|
* End something.
|
||||||
*
|
*
|
||||||
* @param mode Mode
|
* @param mode
|
||||||
* @param c Closing character
|
* Mode
|
||||||
|
* @param c
|
||||||
|
* Closing character
|
||||||
* @return this
|
* @return this
|
||||||
* @throws JSONException If unbalanced.
|
* @throws JSONException
|
||||||
|
* If unbalanced.
|
||||||
*/
|
*/
|
||||||
private JSONWriter end(final char mode, final char c) throws JSONException {
|
private JSONWriter end(final char mode, final char c) throws JSONException {
|
||||||
if (this.mode != mode) {
|
if (this.mode != mode) {
|
||||||
@ -141,7 +150,8 @@ public class JSONWriter {
|
|||||||
this.pop(mode);
|
this.pop(mode);
|
||||||
try {
|
try {
|
||||||
this.writer.write(c);
|
this.writer.write(c);
|
||||||
} catch (final IOException e) {
|
}
|
||||||
|
catch (final IOException e) {
|
||||||
throw new JSONException(e);
|
throw new JSONException(e);
|
||||||
}
|
}
|
||||||
this.comma = true;
|
this.comma = true;
|
||||||
@ -153,7 +163,8 @@ public class JSONWriter {
|
|||||||
* <code>array</code>.
|
* <code>array</code>.
|
||||||
*
|
*
|
||||||
* @return this
|
* @return this
|
||||||
* @throws JSONException If incorrectly nested.
|
* @throws JSONException
|
||||||
|
* If incorrectly nested.
|
||||||
*/
|
*/
|
||||||
public JSONWriter endArray() throws JSONException {
|
public JSONWriter endArray() throws JSONException {
|
||||||
return this.end('a', ']');
|
return this.end('a', ']');
|
||||||
@ -164,7 +175,8 @@ public class JSONWriter {
|
|||||||
* <code>object</code>.
|
* <code>object</code>.
|
||||||
*
|
*
|
||||||
* @return this
|
* @return this
|
||||||
* @throws JSONException If incorrectly nested.
|
* @throws JSONException
|
||||||
|
* If incorrectly nested.
|
||||||
*/
|
*/
|
||||||
public JSONWriter endObject() throws JSONException {
|
public JSONWriter endObject() throws JSONException {
|
||||||
return this.end('k', '}');
|
return this.end('k', '}');
|
||||||
@ -174,10 +186,12 @@ public class JSONWriter {
|
|||||||
* Append a key. The key will be associated with the next value. In an
|
* Append a key. The key will be associated with the next value. In an
|
||||||
* object, every value must be preceded by a key.
|
* object, every value must be preceded by a key.
|
||||||
*
|
*
|
||||||
* @param string A key string.
|
* @param string
|
||||||
|
* A key string.
|
||||||
* @return this
|
* @return this
|
||||||
* @throws JSONException If the key is out of place. For example, keys
|
* @throws JSONException
|
||||||
* do not belong in arrays or if the key is null.
|
* 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 {
|
public JSONWriter key(final String string) throws JSONException {
|
||||||
if (string == null) {
|
if (string == null) {
|
||||||
@ -194,7 +208,8 @@ public class JSONWriter {
|
|||||||
this.comma = false;
|
this.comma = false;
|
||||||
this.mode = 'o';
|
this.mode = 'o';
|
||||||
return this;
|
return this;
|
||||||
} catch (final IOException e) {
|
}
|
||||||
|
catch (final IOException e) {
|
||||||
throw new JSONException(e);
|
throw new JSONException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,10 +222,11 @@ public class JSONWriter {
|
|||||||
* <code>endObject</code> method must be called to mark the object's end.
|
* <code>endObject</code> method must be called to mark the object's end.
|
||||||
*
|
*
|
||||||
* @return this
|
* @return this
|
||||||
* @throws JSONException If the nesting is too deep, or if the object is
|
* @throws JSONException
|
||||||
* started in the wrong place (for example as a key or after the
|
* If the nesting is too deep, or if the object is
|
||||||
* end of the
|
* started in the wrong place (for example as a key or after the
|
||||||
* outermost array or object).
|
* end of the
|
||||||
|
* outermost array or object).
|
||||||
*/
|
*/
|
||||||
public JSONWriter object() throws JSONException {
|
public JSONWriter object() throws JSONException {
|
||||||
if (this.mode == 'i') {
|
if (this.mode == 'i') {
|
||||||
@ -229,8 +245,10 @@ public class JSONWriter {
|
|||||||
/**
|
/**
|
||||||
* Pop an array or object scope.
|
* Pop an array or object scope.
|
||||||
*
|
*
|
||||||
* @param c The scope to close.
|
* @param c
|
||||||
* @throws JSONException If nesting is wrong.
|
* The scope to close.
|
||||||
|
* @throws JSONException
|
||||||
|
* If nesting is wrong.
|
||||||
*/
|
*/
|
||||||
private void pop(final char c) throws JSONException {
|
private void pop(final char c) throws JSONException {
|
||||||
if (this.top <= 0) {
|
if (this.top <= 0) {
|
||||||
@ -247,8 +265,10 @@ public class JSONWriter {
|
|||||||
/**
|
/**
|
||||||
* Push an array or object scope.
|
* Push an array or object scope.
|
||||||
*
|
*
|
||||||
* @param jo The scope to open.
|
* @param jo
|
||||||
* @throws JSONException If nesting is too deep.
|
* The scope to open.
|
||||||
|
* @throws JSONException
|
||||||
|
* If nesting is too deep.
|
||||||
*/
|
*/
|
||||||
private void push(final JSONObject jo) throws JSONException {
|
private void push(final JSONObject jo) throws JSONException {
|
||||||
if (this.top >= maxdepth) {
|
if (this.top >= maxdepth) {
|
||||||
@ -263,7 +283,8 @@ 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
|
* @return this
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -274,9 +295,11 @@ public class JSONWriter {
|
|||||||
/**
|
/**
|
||||||
* Append a double value.
|
* Append a double value.
|
||||||
*
|
*
|
||||||
* @param d A double.
|
* @param d
|
||||||
|
* A double.
|
||||||
* @return this
|
* @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 {
|
public JSONWriter value(final double d) throws JSONException {
|
||||||
return this.value(new Double(d));
|
return this.value(new Double(d));
|
||||||
@ -285,7 +308,8 @@ public class JSONWriter {
|
|||||||
/**
|
/**
|
||||||
* Append a long value.
|
* Append a long value.
|
||||||
*
|
*
|
||||||
* @param l A long.
|
* @param l
|
||||||
|
* A long.
|
||||||
* @return this
|
* @return this
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -296,11 +320,13 @@ public class JSONWriter {
|
|||||||
/**
|
/**
|
||||||
* Append an object value.
|
* Append an object value.
|
||||||
*
|
*
|
||||||
* @param object The object to append. It can be null, or a Boolean, Number,
|
* @param object
|
||||||
* String, JSONObject, or JSONArray, or an object that implements
|
* The object to append. It can be null, or a Boolean, Number,
|
||||||
* JSONString.
|
* String, JSONObject, or JSONArray, or an object that implements
|
||||||
|
* JSONString.
|
||||||
* @return this
|
* @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 {
|
public JSONWriter value(final Object object) throws JSONException {
|
||||||
return this.append(JSONObject.valueToString(object));
|
return this.append(JSONObject.valueToString(object));
|
||||||
|
@ -8,11 +8,8 @@ package com.intellectualcrafters.json;
|
|||||||
* than 3 bytes. Every byte contributes 7 bits to the character. ASCII is
|
* than 3 bytes. Every byte contributes 7 bits to the character. ASCII is
|
||||||
* unmodified.
|
* unmodified.
|
||||||
* <p/>
|
* <p/>
|
||||||
* Kim UTF-8
|
* Kim UTF-8 one byte U+007F U+007F two bytes U+3FFF U+07FF three bytes U+10FFF
|
||||||
* one byte U+007F U+007F
|
* U+FFFF four bytes U+10FFFF
|
||||||
* two bytes U+3FFF U+07FF
|
|
||||||
* three bytes U+10FFF U+FFFF
|
|
||||||
* four bytes U+10FFFF
|
|
||||||
* <p/>
|
* <p/>
|
||||||
* Characters in the ranges U+0800..U+3FFF and U+10000..U+10FFFF will be one
|
* 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.
|
* byte smaller when encoded in Kim compared to UTF-8.
|
||||||
@ -20,12 +17,12 @@ package com.intellectualcrafters.json;
|
|||||||
* Kim is beneficial when using scripts such as Old South Arabian, Aramaic,
|
* Kim is beneficial when using scripts such as Old South Arabian, Aramaic,
|
||||||
* Avestan, Balinese, Batak, Bopomofo, Buginese, Buhid, Carian, Cherokee,
|
* Avestan, Balinese, Batak, Bopomofo, Buginese, Buhid, Carian, Cherokee,
|
||||||
* Coptic, Cyrillic, Deseret, Egyptian Hieroglyphs, Ethiopic, Georgian,
|
* Coptic, Cyrillic, Deseret, Egyptian Hieroglyphs, Ethiopic, Georgian,
|
||||||
* Glagolitic, Gothic, Hangul Jamo, Hanunoo, Hiragana, Kanbun, Kaithi,
|
* Glagolitic, Gothic, Hangul Jamo, Hanunoo, Hiragana, Kanbun, Kaithi, Kannada,
|
||||||
* Kannada, Katakana, Kharoshthi, Khmer, Lao, Lepcha, Limbu, Lycian, Lydian,
|
* Katakana, Kharoshthi, Khmer, Lao, Lepcha, Limbu, Lycian, Lydian, Malayalam,
|
||||||
* Malayalam, Mandaic, Meroitic, Miao, Mongolian, Myanmar, New Tai Lue,
|
* Mandaic, Meroitic, Miao, Mongolian, Myanmar, New Tai Lue, Ol Chiki, Old
|
||||||
* Ol Chiki, Old Turkic, Oriya, Osmanya, Pahlavi, Parthian, Phags-Pa,
|
* Turkic, Oriya, Osmanya, Pahlavi, Parthian, Phags-Pa, Phoenician, Samaritan,
|
||||||
* Phoenician, Samaritan, Sharada, Sinhala, Sora Sompeng, Tagalog, Tagbanwa,
|
* Sharada, Sinhala, Sora Sompeng, Tagalog, Tagbanwa, Takri, Tai Le, Tai Tham,
|
||||||
* Takri, Tai Le, Tai Tham, Tamil, Telugu, Thai, Tibetan, Tifinagh, UCAS.
|
* Tamil, Telugu, Thai, Tibetan, Tifinagh, UCAS.
|
||||||
* <p/>
|
* <p/>
|
||||||
* A kim object can be constructed from an ordinary UTF-16 string, or from a
|
* 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.
|
* byte array. A kim object can produce a UTF-16 string.
|
||||||
@ -42,26 +39,29 @@ public class Kim {
|
|||||||
* The number of bytes in the kim. The number of bytes can be as much as
|
* The number of bytes in the kim. The number of bytes can be as much as
|
||||||
* three times the number of characters.
|
* three times the number of characters.
|
||||||
*/
|
*/
|
||||||
public int length = 0;
|
public int length = 0;
|
||||||
/**
|
/**
|
||||||
* The byte array containing the kim's content.
|
* The byte array containing the kim's content.
|
||||||
*/
|
*/
|
||||||
private byte[] bytes = null;
|
private byte[] bytes = null;
|
||||||
/**
|
/**
|
||||||
* The kim's hashcode, conforming to Java's hashcode conventions.
|
* The kim's hashcode, conforming to Java's hashcode conventions.
|
||||||
*/
|
*/
|
||||||
private int hashcode = 0;
|
private int hashcode = 0;
|
||||||
/**
|
/**
|
||||||
* The memoization of toString().
|
* The memoization of toString().
|
||||||
*/
|
*/
|
||||||
private String string = null;
|
private String string = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a kim from a portion of a byte array.
|
* Make a kim from a portion of a byte array.
|
||||||
*
|
*
|
||||||
* @param bytes A byte array.
|
* @param bytes
|
||||||
* @param from The index of the first byte.
|
* A byte array.
|
||||||
* @param thru The index of the last byte plus one.
|
* @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) {
|
public Kim(final byte[] bytes, final int from, final int thru) {
|
||||||
|
|
||||||
@ -88,8 +88,10 @@ public class Kim {
|
|||||||
/**
|
/**
|
||||||
* Make a kim from a byte array.
|
* Make a kim from a byte array.
|
||||||
*
|
*
|
||||||
* @param bytes The byte array.
|
* @param bytes
|
||||||
* @param length The number of bytes.
|
* The byte array.
|
||||||
|
* @param length
|
||||||
|
* The number of bytes.
|
||||||
*/
|
*/
|
||||||
public Kim(final byte[] bytes, final int length) {
|
public Kim(final byte[] bytes, final int length) {
|
||||||
this(bytes, 0, length);
|
this(bytes, 0, length);
|
||||||
@ -99,9 +101,12 @@ public class Kim {
|
|||||||
* Make a new kim from a substring of an existing kim. The coordinates are
|
* Make a new kim from a substring of an existing kim. The coordinates are
|
||||||
* in byte units, not character units.
|
* in byte units, not character units.
|
||||||
*
|
*
|
||||||
* @param kim The source of bytes.
|
* @param kim
|
||||||
* @param from The point at which to take bytes.
|
* The source of bytes.
|
||||||
* @param thru The point at which to stop taking 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) {
|
public Kim(final Kim kim, final int from, final int thru) {
|
||||||
this(kim.bytes, from, thru);
|
this(kim.bytes, from, thru);
|
||||||
@ -110,8 +115,10 @@ public class Kim {
|
|||||||
/**
|
/**
|
||||||
* Make a kim from a string.
|
* Make a kim from a string.
|
||||||
*
|
*
|
||||||
* @param string The string.
|
* @param string
|
||||||
* @throws JSONException if surrogate pair mismatch.
|
* The string.
|
||||||
|
* @throws JSONException
|
||||||
|
* if surrogate pair mismatch.
|
||||||
*/
|
*/
|
||||||
public Kim(final String string) throws JSONException {
|
public Kim(final String string) throws JSONException {
|
||||||
final int stringLength = string.length();
|
final int stringLength = string.length();
|
||||||
@ -126,9 +133,11 @@ public class Kim {
|
|||||||
final int c = string.charAt(i);
|
final int c = string.charAt(i);
|
||||||
if (c <= 0x7F) {
|
if (c <= 0x7F) {
|
||||||
this.length += 1;
|
this.length += 1;
|
||||||
} else if (c <= 0x3FFF) {
|
}
|
||||||
|
else if (c <= 0x3FFF) {
|
||||||
this.length += 2;
|
this.length += 2;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if ((c >= 0xD800) && (c <= 0xDFFF)) {
|
if ((c >= 0xD800) && (c <= 0xDFFF)) {
|
||||||
i += 1;
|
i += 1;
|
||||||
final int d = string.charAt(i);
|
final int d = string.charAt(i);
|
||||||
@ -155,7 +164,8 @@ public class Kim {
|
|||||||
sum += character;
|
sum += character;
|
||||||
this.hashcode += sum;
|
this.hashcode += sum;
|
||||||
at += 1;
|
at += 1;
|
||||||
} else if (character <= 0x3FFF) {
|
}
|
||||||
|
else if (character <= 0x3FFF) {
|
||||||
b = 0x80 | (character >>> 7);
|
b = 0x80 | (character >>> 7);
|
||||||
this.bytes[at] = (byte) b;
|
this.bytes[at] = (byte) b;
|
||||||
sum += b;
|
sum += b;
|
||||||
@ -166,7 +176,8 @@ public class Kim {
|
|||||||
sum += b;
|
sum += b;
|
||||||
this.hashcode += sum;
|
this.hashcode += sum;
|
||||||
at += 1;
|
at += 1;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if ((character >= 0xD800) && (character <= 0xDBFF)) {
|
if ((character >= 0xD800) && (character <= 0xDBFF)) {
|
||||||
i += 1;
|
i += 1;
|
||||||
character = (((character & 0x3FF) << 10) | (string.charAt(i) & 0x3FF)) + 65536;
|
character = (((character & 0x3FF) << 10) | (string.charAt(i) & 0x3FF)) + 65536;
|
||||||
@ -196,9 +207,11 @@ public class Kim {
|
|||||||
* Returns the number of bytes needed to contain the character in Kim
|
* Returns the number of bytes needed to contain the character in Kim
|
||||||
* format.
|
* format.
|
||||||
*
|
*
|
||||||
* @param character a Unicode character between 0 and 0x10FFFF.
|
* @param character
|
||||||
|
* a Unicode character between 0 and 0x10FFFF.
|
||||||
* @return 1, 2, or 3
|
* @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 {
|
public static int characterSize(final int character) throws JSONException {
|
||||||
if ((character < 0) || (character > 0x10FFFF)) {
|
if ((character < 0) || (character > 0x10FFFF)) {
|
||||||
@ -212,8 +225,10 @@ public class Kim {
|
|||||||
* values and ranges from 0 to length - 1. The index of the next character
|
* values and ranges from 0 to length - 1. The index of the next character
|
||||||
* is at index + Kim.characterSize(kim.characterAt(index)).
|
* is at index + Kim.characterSize(kim.characterAt(index)).
|
||||||
*
|
*
|
||||||
* @param at the index of the char value. The first character is at 0.
|
* @param at
|
||||||
* @throws JSONException if at does not point to a valid character.
|
* 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.
|
* @returns a Unicode character between 0 and 0x10FFFF.
|
||||||
*/
|
*/
|
||||||
public int characterAt(final int at) throws JSONException {
|
public int characterAt(final int at) throws JSONException {
|
||||||
@ -228,7 +243,8 @@ public class Kim {
|
|||||||
if (character > 0x7F) {
|
if (character > 0x7F) {
|
||||||
return character;
|
return character;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
final int c2 = get(at + 2);
|
final int c2 = get(at + 2);
|
||||||
character = ((c & 0x7F) << 14) | ((c1 & 0x7F) << 7) | c2;
|
character = ((c & 0x7F) << 14) | ((c1 & 0x7F) << 7) | c2;
|
||||||
if (((c2 & 0x80) == 0) && (character > 0x3FFF) && (character <= 0x10FFFF) && ((character < 0xD800) || (character > 0xDFFF))) {
|
if (((c2 & 0x80) == 0) && (character > 0x3FFF) && (character <= 0x10FFFF) && ((character < 0xD800) || (character > 0xDFFF))) {
|
||||||
@ -241,8 +257,10 @@ public class Kim {
|
|||||||
/**
|
/**
|
||||||
* Copy the contents of this kim to a byte array.
|
* Copy the contents of this kim to a byte array.
|
||||||
*
|
*
|
||||||
* @param bytes A byte array of sufficient size.
|
* @param bytes
|
||||||
* @param at The position within the byte array to take the byes.
|
* 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.
|
* @return The position immediately after the copy.
|
||||||
*/
|
*/
|
||||||
public int copy(final byte[] bytes, final int at) {
|
public int copy(final byte[] bytes, final int at) {
|
||||||
@ -254,9 +272,10 @@ public class Kim {
|
|||||||
* Two kim objects containing exactly the same bytes in the same order are
|
* Two kim objects containing exactly the same bytes in the same order are
|
||||||
* equal to each other.
|
* equal to each other.
|
||||||
*
|
*
|
||||||
* @param obj the other kim with which to compare.
|
* @param obj
|
||||||
|
* the other kim with which to compare.
|
||||||
* @returns true if this and obj are both kim objects containing identical
|
* @returns true if this and obj are both kim objects containing identical
|
||||||
* byte sequences.
|
* byte sequences.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(final Object obj) {
|
||||||
@ -276,9 +295,11 @@ public class Kim {
|
|||||||
/**
|
/**
|
||||||
* Get a byte from a 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.
|
* @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 {
|
public int get(final int at) throws JSONException {
|
||||||
if ((at < 0) || (at > this.length)) {
|
if ((at < 0) || (at > this.length)) {
|
||||||
@ -301,7 +322,8 @@ public class Kim {
|
|||||||
* it could be less.
|
* it could be less.
|
||||||
*
|
*
|
||||||
* @return The string. A kim memoizes its string representation.
|
* @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
|
@Override
|
||||||
public String toString() throws JSONException {
|
public String toString() throws JSONException {
|
||||||
@ -314,7 +336,8 @@ public class Kim {
|
|||||||
if (c < 0x10000) {
|
if (c < 0x10000) {
|
||||||
chars[length] = (char) c;
|
chars[length] = (char) c;
|
||||||
length += 1;
|
length += 1;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
chars[length] = (char) (0xD800 | ((c - 0x10000) >>> 10));
|
chars[length] = (char) (0xD800 | ((c - 0x10000) >>> 10));
|
||||||
length += 1;
|
length += 1;
|
||||||
chars[length] = (char) (0xDC00 | (c & 0x03FF));
|
chars[length] = (char) (0xDC00 | (c & 0x03FF));
|
||||||
|
@ -36,7 +36,8 @@ public class Property {
|
|||||||
* Converts a property file object into a JSONObject. The property file
|
* Converts a property file object into a JSONObject. The property file
|
||||||
* object is a table of name value pairs.
|
* object is a table of name value pairs.
|
||||||
*
|
*
|
||||||
* @param properties java.util.Properties
|
* @param properties
|
||||||
|
* java.util.Properties
|
||||||
* @return JSONObject
|
* @return JSONObject
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -55,7 +56,8 @@ public class Property {
|
|||||||
/**
|
/**
|
||||||
* Converts the JSONObject into a property file object.
|
* Converts the JSONObject into a property file object.
|
||||||
*
|
*
|
||||||
* @param jo JSONObject
|
* @param jo
|
||||||
|
* JSONObject
|
||||||
* @return java.util.Properties
|
* @return java.util.Properties
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
|
@ -14,32 +14,32 @@ public class XML {
|
|||||||
/**
|
/**
|
||||||
* The Character '&'.
|
* The Character '&'.
|
||||||
*/
|
*/
|
||||||
public static final Character AMP = '&';
|
public static final Character AMP = '&';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '''.
|
* The Character '''.
|
||||||
*/
|
*/
|
||||||
public static final Character APOS = '\'';
|
public static final Character APOS = '\'';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '!'.
|
* The Character '!'.
|
||||||
*/
|
*/
|
||||||
public static final Character BANG = '!';
|
public static final Character BANG = '!';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '='.
|
* The Character '='.
|
||||||
*/
|
*/
|
||||||
public static final Character EQ = '=';
|
public static final Character EQ = '=';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '>'.
|
* The Character '>'.
|
||||||
*/
|
*/
|
||||||
public static final Character GT = '>';
|
public static final Character GT = '>';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '<'.
|
* The Character '<'.
|
||||||
*/
|
*/
|
||||||
public static final Character LT = '<';
|
public static final Character LT = '<';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '?'.
|
* The Character '?'.
|
||||||
@ -49,7 +49,7 @@ public class XML {
|
|||||||
/**
|
/**
|
||||||
* The Character '"'.
|
* The Character '"'.
|
||||||
*/
|
*/
|
||||||
public static final Character QUOT = '"';
|
public static final Character QUOT = '"';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '/'.
|
* The Character '/'.
|
||||||
@ -59,6 +59,7 @@ public class XML {
|
|||||||
/**
|
/**
|
||||||
* Replace special characters with XML escapes:
|
* Replace special characters with XML escapes:
|
||||||
* <p/>
|
* <p/>
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* & <small>(ampersand)</small> is replaced by &amp;
|
* & <small>(ampersand)</small> is replaced by &amp;
|
||||||
* < <small>(less than)</small> is replaced by &lt;
|
* < <small>(less than)</small> is replaced by &lt;
|
||||||
@ -66,7 +67,8 @@ public class XML {
|
|||||||
* " <small>(double quote)</small> is replaced by &quot;
|
* " <small>(double quote)</small> is replaced by &quot;
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param string The string to be escaped.
|
* @param string
|
||||||
|
* The string to be escaped.
|
||||||
* @return The escaped string.
|
* @return The escaped string.
|
||||||
*/
|
*/
|
||||||
public static String escape(final String string) {
|
public static String escape(final String string) {
|
||||||
@ -100,7 +102,8 @@ public class XML {
|
|||||||
* Throw an exception if the string contains whitespace.
|
* Throw an exception if the string contains whitespace.
|
||||||
* Whitespace is not allowed in tagNames and attributes.
|
* Whitespace is not allowed in tagNames and attributes.
|
||||||
*
|
*
|
||||||
* @param string A string.
|
* @param string
|
||||||
|
* A string.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static void noSpace(final String string) throws JSONException {
|
public static void noSpace(final String string) throws JSONException {
|
||||||
@ -119,9 +122,12 @@ public class XML {
|
|||||||
/**
|
/**
|
||||||
* Scan the content following the named tag, attaching it to the context.
|
* Scan the content following the named tag, attaching it to the context.
|
||||||
*
|
*
|
||||||
* @param x The XMLTokener containing the source string.
|
* @param x
|
||||||
* @param context The JSONObject that will include the new material.
|
* The XMLTokener containing the source string.
|
||||||
* @param name The tag name.
|
* @param context
|
||||||
|
* The JSONObject that will include the new material.
|
||||||
|
* @param name
|
||||||
|
* The tag name.
|
||||||
* @return true if the close tag is processed.
|
* @return true if the close tag is processed.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -155,7 +161,8 @@ public class XML {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
x.back();
|
x.back();
|
||||||
} else if (c == '[') {
|
}
|
||||||
|
else if (c == '[') {
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
if ("CDATA".equals(token)) {
|
if ("CDATA".equals(token)) {
|
||||||
if (x.next() == '[') {
|
if (x.next() == '[') {
|
||||||
@ -173,21 +180,25 @@ public class XML {
|
|||||||
token = x.nextMeta();
|
token = x.nextMeta();
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
throw x.syntaxError("Missing '>' after '<!'.");
|
throw x.syntaxError("Missing '>' after '<!'.");
|
||||||
} else if (token == LT) {
|
}
|
||||||
|
else if (token == LT) {
|
||||||
i += 1;
|
i += 1;
|
||||||
} else if (token == GT) {
|
}
|
||||||
|
else if (token == GT) {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (i > 0);
|
while (i > 0);
|
||||||
return false;
|
return false;
|
||||||
} else if (token == QUEST) {
|
}
|
||||||
|
else if (token == QUEST) {
|
||||||
|
|
||||||
// <?
|
// <?
|
||||||
|
|
||||||
x.skipPast("?>");
|
x.skipPast("?>");
|
||||||
return false;
|
return false;
|
||||||
} else if (token == SLASH) {
|
}
|
||||||
|
else if (token == SLASH) {
|
||||||
|
|
||||||
// Close tag </
|
// Close tag </
|
||||||
|
|
||||||
@ -203,16 +214,18 @@ public class XML {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (token instanceof Character) {
|
}
|
||||||
|
else if (token instanceof Character) {
|
||||||
throw x.syntaxError("Misshaped tag");
|
throw x.syntaxError("Misshaped tag");
|
||||||
|
|
||||||
// Open tag <
|
// Open tag <
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
tagName = (String) token;
|
tagName = (String) token;
|
||||||
token = null;
|
token = null;
|
||||||
jsonobject = new JSONObject();
|
jsonobject = new JSONObject();
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
}
|
}
|
||||||
@ -229,34 +242,39 @@ public class XML {
|
|||||||
}
|
}
|
||||||
jsonobject.accumulate(string, XML.stringToValue((String) token));
|
jsonobject.accumulate(string, XML.stringToValue((String) token));
|
||||||
token = null;
|
token = null;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
jsonobject.accumulate(string, "");
|
jsonobject.accumulate(string, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty tag <.../>
|
// Empty tag <.../>
|
||||||
|
|
||||||
} else if (token == SLASH) {
|
}
|
||||||
|
else if (token == SLASH) {
|
||||||
if (x.nextToken() != GT) {
|
if (x.nextToken() != GT) {
|
||||||
throw x.syntaxError("Misshaped tag");
|
throw x.syntaxError("Misshaped tag");
|
||||||
}
|
}
|
||||||
if (jsonobject.length() > 0) {
|
if (jsonobject.length() > 0) {
|
||||||
context.accumulate(tagName, jsonobject);
|
context.accumulate(tagName, jsonobject);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
context.accumulate(tagName, "");
|
context.accumulate(tagName, "");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Content, between <...> and </...>
|
// Content, between <...> and </...>
|
||||||
|
|
||||||
} else if (token == GT) {
|
}
|
||||||
for (; ; ) {
|
else if (token == GT) {
|
||||||
|
for (;;) {
|
||||||
token = x.nextContent();
|
token = x.nextContent();
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
if (tagName != null) {
|
if (tagName != null) {
|
||||||
throw x.syntaxError("Unclosed tag " + tagName);
|
throw x.syntaxError("Unclosed tag " + tagName);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else if (token instanceof String) {
|
}
|
||||||
|
else if (token instanceof String) {
|
||||||
string = (String) token;
|
string = (String) token;
|
||||||
if (string.length() > 0) {
|
if (string.length() > 0) {
|
||||||
jsonobject.accumulate("content", XML.stringToValue(string));
|
jsonobject.accumulate("content", XML.stringToValue(string));
|
||||||
@ -264,20 +282,24 @@ public class XML {
|
|||||||
|
|
||||||
// Nested element
|
// Nested element
|
||||||
|
|
||||||
} else if (token == LT) {
|
}
|
||||||
|
else if (token == LT) {
|
||||||
if (parse(x, jsonobject, tagName)) {
|
if (parse(x, jsonobject, tagName)) {
|
||||||
if (jsonobject.length() == 0) {
|
if (jsonobject.length() == 0) {
|
||||||
context.accumulate(tagName, "");
|
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"));
|
context.accumulate(tagName, jsonobject.opt("content"));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
context.accumulate(tagName, jsonobject);
|
context.accumulate(tagName, jsonobject);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw x.syntaxError("Misshaped tag");
|
throw x.syntaxError("Misshaped tag");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -291,7 +313,8 @@ public class XML {
|
|||||||
* convert plus forms, octal forms, hex forms, or E forms lacking decimal
|
* convert plus forms, octal forms, hex forms, or E forms lacking decimal
|
||||||
* points.
|
* points.
|
||||||
*
|
*
|
||||||
* @param string A String.
|
* @param string
|
||||||
|
* A String.
|
||||||
* @return A simple JSON value.
|
* @return A simple JSON value.
|
||||||
*/
|
*/
|
||||||
public static Object stringToValue(final String string) {
|
public static Object stringToValue(final String string) {
|
||||||
@ -317,13 +340,15 @@ public class XML {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Exception ignore) {
|
}
|
||||||
|
catch (final Exception ignore) {
|
||||||
try {
|
try {
|
||||||
final Double value = new Double(string);
|
final Double value = new Double(string);
|
||||||
if (value.toString().equals(string)) {
|
if (value.toString().equals(string)) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
} catch (final Exception ignoreAlso) {
|
}
|
||||||
|
catch (final Exception ignoreAlso) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
@ -340,7 +365,8 @@ public class XML {
|
|||||||
* text may be placed in a "content" member. Comments, prologs, DTDs, and
|
* text may be placed in a "content" member. Comments, prologs, DTDs, and
|
||||||
* <code><[ [ ]]></code> are ignored.
|
* <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.
|
* @return A JSONObject containing the structured data from the XML string.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -356,7 +382,8 @@ public class XML {
|
|||||||
/**
|
/**
|
||||||
* Convert a JSONObject into a well-formed, element-normal XML string.
|
* Convert a JSONObject into a well-formed, element-normal XML string.
|
||||||
*
|
*
|
||||||
* @param object A JSONObject.
|
* @param object
|
||||||
|
* A JSONObject.
|
||||||
* @return A string.
|
* @return A string.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -367,8 +394,10 @@ public class XML {
|
|||||||
/**
|
/**
|
||||||
* Convert a JSONObject into a well-formed, element-normal XML string.
|
* Convert a JSONObject into a well-formed, element-normal XML string.
|
||||||
*
|
*
|
||||||
* @param object A JSONObject.
|
* @param object
|
||||||
* @param tagName The optional name of the enclosing tag.
|
* A JSONObject.
|
||||||
|
* @param tagName
|
||||||
|
* The optional name of the enclosing tag.
|
||||||
* @return A string.
|
* @return A string.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@ -416,13 +445,15 @@ public class XML {
|
|||||||
}
|
}
|
||||||
sb.append(escape(ja.get(i).toString()));
|
sb.append(escape(ja.get(i).toString()));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sb.append(escape(value.toString()));
|
sb.append(escape(value.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit an array of similar keys
|
// Emit an array of similar keys
|
||||||
|
|
||||||
} else if (value instanceof JSONArray) {
|
}
|
||||||
|
else if (value instanceof JSONArray) {
|
||||||
ja = (JSONArray) value;
|
ja = (JSONArray) value;
|
||||||
length = ja.length();
|
length = ja.length();
|
||||||
for (i = 0; i < length; i += 1) {
|
for (i = 0; i < length; i += 1) {
|
||||||
@ -435,18 +466,21 @@ public class XML {
|
|||||||
sb.append("</");
|
sb.append("</");
|
||||||
sb.append(key);
|
sb.append(key);
|
||||||
sb.append('>');
|
sb.append('>');
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sb.append(toString(value, key));
|
sb.append(toString(value, key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ("".equals(value)) {
|
}
|
||||||
|
else if ("".equals(value)) {
|
||||||
sb.append('<');
|
sb.append('<');
|
||||||
sb.append(key);
|
sb.append(key);
|
||||||
sb.append("/>");
|
sb.append("/>");
|
||||||
|
|
||||||
// Emit a new tag <k>
|
// Emit a new tag <k>
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sb.append(toString(value, key));
|
sb.append(toString(value, key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -464,7 +498,8 @@ public class XML {
|
|||||||
// a place
|
// a place
|
||||||
// where XML is lacking, synthesize an <array> element.
|
// where XML is lacking, synthesize an <array> element.
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (object.getClass().isArray()) {
|
if (object.getClass().isArray()) {
|
||||||
object = new JSONArray(object);
|
object = new JSONArray(object);
|
||||||
}
|
}
|
||||||
@ -475,7 +510,8 @@ public class XML {
|
|||||||
sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
|
sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
string = (object == null) ? "null" : escape(object.toString());
|
string = (object == null) ? "null" : escape(object.toString());
|
||||||
return (tagName == null) ? "\"" + string + "\"" : (string.length() == 0) ? "<" + tagName + "/>" : "<" + tagName + ">" + string + "</" + tagName + ">";
|
return (tagName == null) ? "\"" + string + "\"" : (string.length() == 0) ? "<" + tagName + "/>" : "<" + tagName + ">" + string + "</" + tagName + ">";
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,8 @@ public class XMLTokener extends JSONTokener {
|
|||||||
/**
|
/**
|
||||||
* Construct an XMLTokener from a string.
|
* Construct an XMLTokener from a string.
|
||||||
*
|
*
|
||||||
* @param s A source string.
|
* @param s
|
||||||
|
* A source string.
|
||||||
*/
|
*/
|
||||||
public XMLTokener(final String s) {
|
public XMLTokener(final String s) {
|
||||||
super(s);
|
super(s);
|
||||||
@ -37,13 +38,14 @@ public class XMLTokener extends JSONTokener {
|
|||||||
* Get the text in the CDATA block.
|
* Get the text in the CDATA block.
|
||||||
*
|
*
|
||||||
* @return The string up to the <code>]]></code>.
|
* @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 {
|
public String nextCDATA() throws JSONException {
|
||||||
char c;
|
char c;
|
||||||
int i;
|
int i;
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
c = next();
|
c = next();
|
||||||
if (end()) {
|
if (end()) {
|
||||||
throw syntaxError("Unclosed CDATA");
|
throw syntaxError("Unclosed CDATA");
|
||||||
@ -80,14 +82,15 @@ public class XMLTokener extends JSONTokener {
|
|||||||
return XML.LT;
|
return XML.LT;
|
||||||
}
|
}
|
||||||
sb = new StringBuilder();
|
sb = new StringBuilder();
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
if ((c == '<') || (c == 0)) {
|
if ((c == '<') || (c == 0)) {
|
||||||
back();
|
back();
|
||||||
return sb.toString().trim();
|
return sb.toString().trim();
|
||||||
}
|
}
|
||||||
if (c == '&') {
|
if (c == '&') {
|
||||||
sb.append(nextEntity(c));
|
sb.append(nextEntity(c));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
c = next();
|
c = next();
|
||||||
@ -98,19 +101,23 @@ public class XMLTokener extends JSONTokener {
|
|||||||
* Return the next entity. These entities are translated to Characters:
|
* Return the next entity. These entities are translated to Characters:
|
||||||
* <code>& ' > < "</code>.
|
* <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.
|
* @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 {
|
public Object nextEntity(final char ampersand) throws JSONException {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
final char c = next();
|
final char c = next();
|
||||||
if (Character.isLetterOrDigit(c) || (c == '#')) {
|
if (Character.isLetterOrDigit(c) || (c == '#')) {
|
||||||
sb.append(Character.toLowerCase(c));
|
sb.append(Character.toLowerCase(c));
|
||||||
} else if (c == ';') {
|
}
|
||||||
|
else if (c == ';') {
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw syntaxError("Missing ';' in XML entity: &" + sb);
|
throw syntaxError("Missing ';' in XML entity: &" + sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,11 +131,12 @@ public class XMLTokener extends JSONTokener {
|
|||||||
* and <?...?> structures.
|
* and <?...?> structures.
|
||||||
*
|
*
|
||||||
* @return Syntax characters (<code>< > / = ! ?</code>) are returned as
|
* @return Syntax characters (<code>< > / = ! ?</code>) are returned as
|
||||||
* Character, and strings and names are returned as Boolean. We
|
* Character, and strings and names are returned as Boolean. We
|
||||||
* don't care
|
* don't care
|
||||||
* what the values actually are.
|
* what the values actually are.
|
||||||
* @throws JSONException If a string is not properly closed or if the XML
|
* @throws JSONException
|
||||||
* is badly structured.
|
* If a string is not properly closed or if the XML
|
||||||
|
* is badly structured.
|
||||||
*/
|
*/
|
||||||
public Object nextMeta() throws JSONException {
|
public Object nextMeta() throws JSONException {
|
||||||
char c;
|
char c;
|
||||||
@ -155,7 +163,7 @@ public class XMLTokener extends JSONTokener {
|
|||||||
case '"':
|
case '"':
|
||||||
case '\'':
|
case '\'':
|
||||||
q = c;
|
q = c;
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
c = next();
|
c = next();
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
throw syntaxError("Unterminated string");
|
throw syntaxError("Unterminated string");
|
||||||
@ -165,7 +173,7 @@ public class XMLTokener extends JSONTokener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
c = next();
|
c = next();
|
||||||
if (Character.isWhitespace(c)) {
|
if (Character.isWhitespace(c)) {
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
@ -194,7 +202,8 @@ public class XMLTokener extends JSONTokener {
|
|||||||
* name.
|
* name.
|
||||||
*
|
*
|
||||||
* @return a String or a Character.
|
* @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 {
|
public Object nextToken() throws JSONException {
|
||||||
char c;
|
char c;
|
||||||
@ -220,13 +229,13 @@ public class XMLTokener extends JSONTokener {
|
|||||||
case '?':
|
case '?':
|
||||||
return XML.QUEST;
|
return XML.QUEST;
|
||||||
|
|
||||||
// Quoted string
|
// Quoted string
|
||||||
|
|
||||||
case '"':
|
case '"':
|
||||||
case '\'':
|
case '\'':
|
||||||
q = c;
|
q = c;
|
||||||
sb = new StringBuilder();
|
sb = new StringBuilder();
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
c = next();
|
c = next();
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
throw syntaxError("Unterminated string");
|
throw syntaxError("Unterminated string");
|
||||||
@ -236,7 +245,8 @@ public class XMLTokener extends JSONTokener {
|
|||||||
}
|
}
|
||||||
if (c == '&') {
|
if (c == '&') {
|
||||||
sb.append(nextEntity(c));
|
sb.append(nextEntity(c));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,7 +255,7 @@ public class XMLTokener extends JSONTokener {
|
|||||||
// Name
|
// Name
|
||||||
|
|
||||||
sb = new StringBuilder();
|
sb = new StringBuilder();
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
c = next();
|
c = next();
|
||||||
if (Character.isWhitespace(c)) {
|
if (Character.isWhitespace(c)) {
|
||||||
@ -277,7 +287,8 @@ public class XMLTokener extends JSONTokener {
|
|||||||
* If it is not found, we are left at the end of the source with a result of
|
* If it is not found, we are left at the end of the source with a result of
|
||||||
* false.
|
* false.
|
||||||
*
|
*
|
||||||
* @param to A string to skip past.
|
* @param to
|
||||||
|
* A string to skip past.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public boolean skipPast(final String to) throws JSONException {
|
public boolean skipPast(final String to) throws JSONException {
|
||||||
@ -304,7 +315,7 @@ public class XMLTokener extends JSONTokener {
|
|||||||
|
|
||||||
/* We will loop, possibly for all of the remaining characters. */
|
/* We will loop, possibly for all of the remaining characters. */
|
||||||
|
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
j = offset;
|
j = offset;
|
||||||
b = true;
|
b = true;
|
||||||
|
|
||||||
|
@ -21,42 +21,6 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot;
|
package com.intellectualcrafters.plot;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.commands.Auto;
|
|
||||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
|
||||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
|
||||||
import com.intellectualcrafters.plot.database.*;
|
|
||||||
import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent;
|
|
||||||
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
|
|
||||||
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
|
||||||
import com.intellectualcrafters.plot.generator.DefaultPlotManager;
|
|
||||||
import com.intellectualcrafters.plot.generator.DefaultPlotWorld;
|
|
||||||
import com.intellectualcrafters.plot.generator.WorldGenerator;
|
|
||||||
import com.intellectualcrafters.plot.listeners.*;
|
|
||||||
import com.intellectualcrafters.plot.object.*;
|
|
||||||
import com.intellectualcrafters.plot.util.*;
|
|
||||||
import com.intellectualcrafters.plot.util.Logger.LogLevel;
|
|
||||||
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
|
|
||||||
import com.intellectualcrafters.plot.uuid.PlotUUIDSaver;
|
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDSaver;
|
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
|
||||||
|
|
||||||
import me.confuser.barapi.BarAPI;
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
|
||||||
|
|
||||||
import org.bukkit.*;
|
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -64,10 +28,85 @@ import java.sql.Connection;
|
|||||||
import java.sql.DatabaseMetaData;
|
import java.sql.DatabaseMetaData;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import me.confuser.barapi.BarAPI;
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.commands.Auto;
|
||||||
|
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||||
|
import com.intellectualcrafters.plot.config.C;
|
||||||
|
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||||
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
|
import com.intellectualcrafters.plot.database.MySQL;
|
||||||
|
import com.intellectualcrafters.plot.database.PlotMeConverter;
|
||||||
|
import com.intellectualcrafters.plot.database.SQLManager;
|
||||||
|
import com.intellectualcrafters.plot.database.SQLite;
|
||||||
|
import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent;
|
||||||
|
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
|
||||||
|
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
||||||
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
|
import com.intellectualcrafters.plot.generator.DefaultPlotManager;
|
||||||
|
import com.intellectualcrafters.plot.generator.DefaultPlotWorld;
|
||||||
|
import com.intellectualcrafters.plot.generator.WorldGenerator;
|
||||||
|
import com.intellectualcrafters.plot.listeners.EntityListener;
|
||||||
|
import com.intellectualcrafters.plot.listeners.ForceFieldListener;
|
||||||
|
import com.intellectualcrafters.plot.listeners.InventoryListener;
|
||||||
|
import com.intellectualcrafters.plot.listeners.PlayerEvents;
|
||||||
|
import com.intellectualcrafters.plot.listeners.PlotListener;
|
||||||
|
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
|
||||||
|
import com.intellectualcrafters.plot.listeners.WorldEditListener;
|
||||||
|
import com.intellectualcrafters.plot.listeners.WorldGuardListener;
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotGenerator;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotManager;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
|
import com.intellectualcrafters.plot.util.ConsoleColors;
|
||||||
|
import com.intellectualcrafters.plot.util.Lag;
|
||||||
|
import com.intellectualcrafters.plot.util.Logger;
|
||||||
|
import com.intellectualcrafters.plot.util.Logger.LogLevel;
|
||||||
|
import com.intellectualcrafters.plot.util.Metrics;
|
||||||
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
|
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||||
|
import com.intellectualcrafters.plot.util.SendChunk;
|
||||||
|
import com.intellectualcrafters.plot.util.SetBlockFast;
|
||||||
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
|
||||||
|
import com.intellectualcrafters.plot.uuid.PlotUUIDSaver;
|
||||||
|
import com.intellectualcrafters.plot.uuid.UUIDSaver;
|
||||||
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlotMain class.
|
* PlotMain class.
|
||||||
*
|
*
|
||||||
@ -76,22 +115,19 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class PlotMain extends JavaPlugin {
|
public class PlotMain extends JavaPlugin {
|
||||||
private static PlotMain main = null;
|
private static PlotMain main = null;
|
||||||
/**
|
/**
|
||||||
* Permission that allows for "everything"
|
* Permission that allows for "everything"
|
||||||
*/
|
*/
|
||||||
public static final String ADMIN_PERMISSION =
|
public static final String ADMIN_PERMISSION = "plots.admin";
|
||||||
"plots.admin";
|
|
||||||
/**
|
/**
|
||||||
* Storage version
|
* Storage version
|
||||||
*/
|
*/
|
||||||
public final static int storage_ver =
|
public final static int storage_ver = 1;
|
||||||
1;
|
|
||||||
/**
|
/**
|
||||||
* Boolean Flags (material)
|
* Boolean Flags (material)
|
||||||
*/
|
*/
|
||||||
public final static HashMap<Material, String> booleanFlags =
|
public final static HashMap<Material, String> booleanFlags = new HashMap<>();
|
||||||
new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the material flags
|
* Initialize the material flags
|
||||||
@ -114,71 +150,63 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* All loaded plot worlds
|
* All loaded plot worlds
|
||||||
*/
|
*/
|
||||||
private final static HashMap<String, PlotWorld> worlds =
|
private final static HashMap<String, PlotWorld> worlds = new HashMap<>();
|
||||||
new HashMap<>();
|
|
||||||
/**
|
/**
|
||||||
* All world managers
|
* All world managers
|
||||||
*/
|
*/
|
||||||
private final static HashMap<String, PlotManager> managers =
|
private final static HashMap<String, PlotManager> managers = new HashMap<>();
|
||||||
new HashMap<>();
|
|
||||||
/**
|
/**
|
||||||
* settings.properties
|
* settings.properties
|
||||||
*/
|
*/
|
||||||
public static File configFile;
|
public static File configFile;
|
||||||
/**
|
/**
|
||||||
* The main configuration file
|
* The main configuration file
|
||||||
*/
|
*/
|
||||||
public static YamlConfiguration config;
|
public static YamlConfiguration config;
|
||||||
/**
|
/**
|
||||||
* storage.properties
|
* storage.properties
|
||||||
*/
|
*/
|
||||||
public static File storageFile;
|
public static File storageFile;
|
||||||
/**
|
/**
|
||||||
* Contains storage options
|
* Contains storage options
|
||||||
*/
|
*/
|
||||||
public static YamlConfiguration storage;
|
public static YamlConfiguration storage;
|
||||||
/**
|
/**
|
||||||
* MySQL Connection
|
* MySQL Connection
|
||||||
*/
|
*/
|
||||||
public static Connection connection;
|
public static Connection connection;
|
||||||
/**
|
/**
|
||||||
* WorldEdit object
|
* WorldEdit object
|
||||||
*/
|
*/
|
||||||
public static WorldEditPlugin worldEdit =
|
public static WorldEditPlugin worldEdit = null;
|
||||||
null;
|
|
||||||
/**
|
/**
|
||||||
* BarAPI object
|
* BarAPI object
|
||||||
*/
|
*/
|
||||||
public static BarAPI barAPI =
|
public static BarAPI barAPI = null;
|
||||||
null;
|
|
||||||
/**
|
/**
|
||||||
* World Guard Object
|
* World Guard Object
|
||||||
*/
|
*/
|
||||||
public static WorldGuardPlugin worldGuard =
|
public static WorldGuardPlugin worldGuard = null;
|
||||||
null;
|
|
||||||
/**
|
/**
|
||||||
* World Guard Listener
|
* World Guard Listener
|
||||||
*/
|
*/
|
||||||
public static WorldGuardListener worldGuardListener =
|
public static WorldGuardListener worldGuardListener = null;
|
||||||
null;
|
|
||||||
/**
|
/**
|
||||||
* Economy Object (vault)
|
* Economy Object (vault)
|
||||||
*/
|
*/
|
||||||
public static Economy
|
public static Economy economy;
|
||||||
economy;
|
|
||||||
/**
|
/**
|
||||||
* Use Economy?
|
* Use Economy?
|
||||||
*/
|
*/
|
||||||
public static boolean useEconomy =
|
public static boolean useEconomy = false;
|
||||||
false;
|
|
||||||
/**
|
/**
|
||||||
* The UUID Saver
|
* The UUID Saver
|
||||||
*/
|
*/
|
||||||
private static UUIDSaver uuidSaver;
|
private static UUIDSaver uuidSaver;
|
||||||
/**
|
/**
|
||||||
* MySQL Object
|
* MySQL Object
|
||||||
*/
|
*/
|
||||||
private static MySQL mySQL;
|
private static MySQL mySQL;
|
||||||
/**
|
/**
|
||||||
* List of all plots
|
* List of all plots
|
||||||
* DO NOT USE EXCEPT FOR DATABASE PURPOSES
|
* DO NOT USE EXCEPT FOR DATABASE PURPOSES
|
||||||
@ -202,7 +230,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
checkExpired(plugin, true);
|
checkExpired(plugin, true);
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,9 +242,12 @@ public class PlotMain extends JavaPlugin {
|
|||||||
* Check a range of permissions e.g. 'plots.plot.<0-100>'<br>
|
* Check a range of permissions e.g. 'plots.plot.<0-100>'<br>
|
||||||
* Returns highest integer in range.
|
* Returns highest integer in range.
|
||||||
*
|
*
|
||||||
* @param player to check
|
* @param player
|
||||||
* @param stub to check
|
* to check
|
||||||
* @param range tp check
|
* @param stub
|
||||||
|
* to check
|
||||||
|
* @param range
|
||||||
|
* tp check
|
||||||
* @return permitted range
|
* @return permitted range
|
||||||
*/
|
*/
|
||||||
public static int hasPermissionRange(final Player player, final String stub, final int range) {
|
public static int hasPermissionRange(final Player player, final String stub, final int range) {
|
||||||
@ -238,8 +270,10 @@ public class PlotMain extends JavaPlugin {
|
|||||||
* - Op has all permissions <br>
|
* - Op has all permissions <br>
|
||||||
* - checks for '*' nodes
|
* - checks for '*' nodes
|
||||||
*
|
*
|
||||||
* @param player to check
|
* @param player
|
||||||
* @param perms to check
|
* to check
|
||||||
|
* @param perms
|
||||||
|
* to check
|
||||||
* @return true of player has permissions
|
* @return true of player has permissions
|
||||||
*/
|
*/
|
||||||
public static boolean hasPermissions(final Player player, final String[] perms) {
|
public static boolean hasPermissions(final Player player, final String[] perms) {
|
||||||
@ -249,8 +283,9 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
for (final String perm : perms) {
|
for (final String perm : perms) {
|
||||||
boolean permitted = false;
|
boolean permitted = false;
|
||||||
if (player.hasPermission(perm))
|
if (player.hasPermission(perm)) {
|
||||||
permitted = true;
|
permitted = true;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
final String[] nodes = perm.split("\\.");
|
final String[] nodes = perm.split("\\.");
|
||||||
final StringBuilder n = new StringBuilder();
|
final StringBuilder n = new StringBuilder();
|
||||||
@ -283,7 +318,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Set the uuid saver
|
* Set the uuid saver
|
||||||
*
|
*
|
||||||
* @param saver new saver
|
* @param saver
|
||||||
|
* new saver
|
||||||
* @see com.intellectualcrafters.plot.uuid.UUIDSaver
|
* @see com.intellectualcrafters.plot.uuid.UUIDSaver
|
||||||
*/
|
*/
|
||||||
public static void setUUIDSaver(final UUIDSaver saver) {
|
public static void setUUIDSaver(final UUIDSaver saver) {
|
||||||
@ -295,8 +331,10 @@ public class PlotMain extends JavaPlugin {
|
|||||||
* - Op has all permissions <br>
|
* - Op has all permissions <br>
|
||||||
* - checks for '*' nodes
|
* - checks for '*' nodes
|
||||||
*
|
*
|
||||||
* @param player to check
|
* @param player
|
||||||
* @param perm to check
|
* to check
|
||||||
|
* @param perm
|
||||||
|
* to check
|
||||||
* @return true if player has the permission
|
* @return true if player has the permission
|
||||||
*/
|
*/
|
||||||
public static boolean hasPermission(final Player player, final String perm) {
|
public static boolean hasPermission(final Player player, final String perm) {
|
||||||
@ -345,7 +383,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param player player
|
* @param player
|
||||||
|
* player
|
||||||
* @return Set Containing the players plots
|
* @return Set Containing the players plots
|
||||||
*/
|
*/
|
||||||
public static Set<Plot> getPlots(final Player player) {
|
public static Set<Plot> getPlots(final Player player) {
|
||||||
@ -364,8 +403,10 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param world plot world
|
* @param world
|
||||||
* @param player plot owner
|
* plot world
|
||||||
|
* @param player
|
||||||
|
* plot owner
|
||||||
* @return players plots
|
* @return players plots
|
||||||
*/
|
*/
|
||||||
public static Set<Plot> getPlots(final World world, final Player player) {
|
public static Set<Plot> getPlots(final World world, final Player player) {
|
||||||
@ -384,7 +425,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Get plots for the specified world
|
* 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
|
* @return HashMap containing Plot IDs and Plot Objects
|
||||||
*/
|
*/
|
||||||
public static HashMap<PlotId, Plot> getPlots(final String world) {
|
public static HashMap<PlotId, Plot> getPlots(final String world) {
|
||||||
@ -395,7 +437,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param world plot world
|
* @param world
|
||||||
|
* plot world
|
||||||
* @return plots in world
|
* @return plots in world
|
||||||
*/
|
*/
|
||||||
public static HashMap<PlotId, Plot> getPlots(final World world) {
|
public static HashMap<PlotId, Plot> getPlots(final World world) {
|
||||||
@ -409,7 +452,7 @@ public class PlotMain extends JavaPlugin {
|
|||||||
* get all plot worlds
|
* get all plot worlds
|
||||||
*/
|
*/
|
||||||
public static String[] getPlotWorlds() {
|
public static String[] getPlotWorlds() {
|
||||||
Set<String> strings = worlds.keySet();
|
final Set<String> strings = worlds.keySet();
|
||||||
return (strings.toArray(new String[strings.size()]));
|
return (strings.toArray(new String[strings.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,12 +460,13 @@ public class PlotMain extends JavaPlugin {
|
|||||||
* @return plots worlds
|
* @return plots worlds
|
||||||
*/
|
*/
|
||||||
public static String[] getPlotWorldsString() {
|
public static String[] getPlotWorldsString() {
|
||||||
Set<String> strings = plots.keySet();
|
final Set<String> strings = plots.keySet();
|
||||||
return strings.toArray(new String[strings.size()]);
|
return strings.toArray(new String[strings.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param world plotworld(?)
|
* @param world
|
||||||
|
* plotworld(?)
|
||||||
* @return true if the world is a plotworld
|
* @return true if the world is a plotworld
|
||||||
*/
|
*/
|
||||||
public static boolean isPlotWorld(final World world) {
|
public static boolean isPlotWorld(final World world) {
|
||||||
@ -430,7 +474,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param world plotworld(?)
|
* @param world
|
||||||
|
* plotworld(?)
|
||||||
* @return true if the world is a plotworld
|
* @return true if the world is a plotworld
|
||||||
*/
|
*/
|
||||||
public static boolean isPlotWorld(final String world) {
|
public static boolean isPlotWorld(final String world) {
|
||||||
@ -438,7 +483,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param world World to get manager for
|
* @param world
|
||||||
|
* World to get manager for
|
||||||
* @return manager for world
|
* @return manager for world
|
||||||
*/
|
*/
|
||||||
public static PlotManager getPlotManager(final World world) {
|
public static PlotManager getPlotManager(final World world) {
|
||||||
@ -449,7 +495,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param world world
|
* @param world
|
||||||
|
* world
|
||||||
* @return PlotManager
|
* @return PlotManager
|
||||||
*/
|
*/
|
||||||
public static PlotManager getPlotManager(final String world) {
|
public static PlotManager getPlotManager(final String world) {
|
||||||
@ -460,7 +507,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param world to search
|
* @param world
|
||||||
|
* to search
|
||||||
* @return PlotWorld object
|
* @return PlotWorld object
|
||||||
*/
|
*/
|
||||||
public static PlotWorld getWorldSettings(final World world) {
|
public static PlotWorld getWorldSettings(final World world) {
|
||||||
@ -471,7 +519,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param world to search
|
* @param world
|
||||||
|
* to search
|
||||||
* @return PlotWorld object
|
* @return PlotWorld object
|
||||||
*/
|
*/
|
||||||
public static PlotWorld getWorldSettings(final String world) {
|
public static PlotWorld getWorldSettings(final String world) {
|
||||||
@ -482,20 +531,24 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param world world to search
|
* @param world
|
||||||
|
* world to search
|
||||||
* @return set containing the plots for a world
|
* @return set containing the plots for a world
|
||||||
*/
|
*/
|
||||||
public static Plot[] getWorldPlots(final World world) {
|
public static Plot[] getWorldPlots(final World world) {
|
||||||
Collection<Plot> values = plots.get(world.getName()).values();
|
final Collection<Plot> values = plots.get(world.getName()).values();
|
||||||
return (values.toArray(new Plot[values.size()]));
|
return (values.toArray(new Plot[values.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a plot
|
* Remove a plot
|
||||||
*
|
*
|
||||||
* @param world The Plot World
|
* @param world
|
||||||
* @param id The Plot ID
|
* The Plot World
|
||||||
* @param callEvent Whether or not to call the PlotDeleteEvent
|
* @param id
|
||||||
|
* The Plot ID
|
||||||
|
* @param callEvent
|
||||||
|
* Whether or not to call the PlotDeleteEvent
|
||||||
* @return true if successful, false if not
|
* @return true if successful, false if not
|
||||||
*/
|
*/
|
||||||
public static boolean removePlot(final String world, final PlotId id, final boolean callEvent) {
|
public static boolean removePlot(final String world, final PlotId id, final boolean callEvent) {
|
||||||
@ -514,7 +567,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Replace the plot object with an updated version
|
* Replace the plot object with an updated version
|
||||||
*
|
*
|
||||||
* @param plot plot object
|
* @param plot
|
||||||
|
* plot object
|
||||||
*/
|
*/
|
||||||
public static void updatePlot(final Plot plot) {
|
public static void updatePlot(final Plot plot) {
|
||||||
final String world = plot.world;
|
final String world = plot.world;
|
||||||
@ -546,8 +600,10 @@ public class PlotMain extends JavaPlugin {
|
|||||||
* - Add new plots to the end.<br>
|
* - Add new plots to the end.<br>
|
||||||
* - The task then only needs to go through the first few plots
|
* - The task then only needs to go through the first few plots
|
||||||
*
|
*
|
||||||
* @param plugin Plugin
|
* @param plugin
|
||||||
* @param async Call async?
|
* Plugin
|
||||||
|
* @param async
|
||||||
|
* Call async?
|
||||||
*/
|
*/
|
||||||
private static void checkExpired(final JavaPlugin plugin, final boolean async) {
|
private static void checkExpired(final JavaPlugin plugin, final boolean async) {
|
||||||
if (async) {
|
if (async) {
|
||||||
@ -573,7 +629,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
toDeletePlot.add(plot);
|
toDeletePlot.add(plot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -592,7 +649,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
for (final String world : getPlotWorldsString()) {
|
for (final String world : getPlotWorldsString()) {
|
||||||
if (PlotMain.plots.containsKey(world)) {
|
if (PlotMain.plots.containsKey(world)) {
|
||||||
for (final Plot plot : PlotMain.plots.get(world).values()) {
|
for (final Plot plot : PlotMain.plots.get(world).values()) {
|
||||||
@ -601,7 +659,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
DBFunc.delete(world, plot);
|
DBFunc.delete(world, plot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -632,12 +691,14 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Send a message to the console.
|
* Send a message to the console.
|
||||||
*
|
*
|
||||||
* @param string message
|
* @param string
|
||||||
|
* message
|
||||||
*/
|
*/
|
||||||
public static void sendConsoleSenderMessage(final String string) {
|
public static void sendConsoleSenderMessage(final String string) {
|
||||||
if (getMain().getServer().getConsoleSender() == null) {
|
if (getMain().getServer().getConsoleSender() == null) {
|
||||||
System.out.println(ChatColor.stripColor(ConsoleColors.fromString(string)));
|
System.out.println(ChatColor.stripColor(ConsoleColors.fromString(string)));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
getMain().getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', string));
|
getMain().getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', string));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -645,9 +706,12 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Teleport a player to a plot
|
* Teleport a player to a plot
|
||||||
*
|
*
|
||||||
* @param player Player to teleport
|
* @param player
|
||||||
* @param from Previous Location
|
* Player to teleport
|
||||||
* @param plot Plot to teleport to
|
* @param from
|
||||||
|
* Previous Location
|
||||||
|
* @param plot
|
||||||
|
* Plot to teleport to
|
||||||
* @return true if successful
|
* @return true if successful
|
||||||
*/
|
*/
|
||||||
public static boolean teleportPlayer(final Player player, final Location from, final Plot plot) {
|
public static boolean teleportPlayer(final Player player, final Location from, final Plot plot) {
|
||||||
@ -668,7 +732,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Send a message to the console
|
* Send a message to the console
|
||||||
*
|
*
|
||||||
* @param c message
|
* @param c
|
||||||
|
* message
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static void sendConsoleSenderMessage(final C c) {
|
public static void sendConsoleSenderMessage(final C c) {
|
||||||
@ -678,7 +743,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Broadcast publicly
|
* Broadcast publicly
|
||||||
*
|
*
|
||||||
* @param c message
|
* @param c
|
||||||
|
* message
|
||||||
*/
|
*/
|
||||||
public static void Broadcast(final C c) {
|
public static void Broadcast(final C c) {
|
||||||
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + c.s()));
|
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + c.s()));
|
||||||
@ -696,7 +762,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Broadcast a message to all admins
|
* Broadcast a message to all admins
|
||||||
*
|
*
|
||||||
* @param c message
|
* @param c
|
||||||
|
* message
|
||||||
*/
|
*/
|
||||||
public static void BroadcastWithPerms(final C c) {
|
public static void BroadcastWithPerms(final C c) {
|
||||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||||
@ -719,7 +786,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Ge the last played time
|
* Ge the last played time
|
||||||
*
|
*
|
||||||
* @param uuid UUID for the player
|
* @param uuid
|
||||||
|
* UUID for the player
|
||||||
* @return last play time as a long
|
* @return last play time as a long
|
||||||
*/
|
*/
|
||||||
public static long getLastPlayed(final UUID uuid) {
|
public static long getLastPlayed(final UUID uuid) {
|
||||||
@ -751,7 +819,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
config = YamlConfiguration.loadConfiguration(configFile);
|
config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
setupConfig();
|
setupConfig();
|
||||||
} catch (final Exception err_trans) {
|
}
|
||||||
|
catch (final Exception err_trans) {
|
||||||
Logger.add(LogLevel.DANGER, "Failed to save settings.yml");
|
Logger.add(LogLevel.DANGER, "Failed to save settings.yml");
|
||||||
System.out.println("Failed to save settings.yml");
|
System.out.println("Failed to save settings.yml");
|
||||||
}
|
}
|
||||||
@ -764,14 +833,16 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
storage = YamlConfiguration.loadConfiguration(storageFile);
|
storage = YamlConfiguration.loadConfiguration(storageFile);
|
||||||
setupStorage();
|
setupStorage();
|
||||||
} catch (final Exception err_trans) {
|
}
|
||||||
|
catch (final Exception err_trans) {
|
||||||
Logger.add(LogLevel.DANGER, "Failed to save storage.yml");
|
Logger.add(LogLevel.DANGER, "Failed to save storage.yml");
|
||||||
System.out.println("Failed to save storage.yml");
|
System.out.println("Failed to save storage.yml");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
config.save(configFile);
|
config.save(configFile);
|
||||||
storage.save(storageFile);
|
storage.save(storageFile);
|
||||||
} catch (final IOException e) {
|
}
|
||||||
|
catch (final IOException e) {
|
||||||
Logger.add(LogLevel.DANGER, "Configuration file saving failed");
|
Logger.add(LogLevel.DANGER, "Configuration file saving failed");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -817,7 +888,7 @@ public class PlotMain extends JavaPlugin {
|
|||||||
public static void killAllEntities() {
|
public static void killAllEntities() {
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(getMain(), new Runnable() {
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(getMain(), new Runnable() {
|
||||||
long ticked = 0l;
|
long ticked = 0l;
|
||||||
long error = 0l;
|
long error = 0l;
|
||||||
|
|
||||||
{
|
{
|
||||||
sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities started.");
|
sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities started.");
|
||||||
@ -906,9 +977,11 @@ public class PlotMain extends JavaPlugin {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Throwable e) {
|
}
|
||||||
|
catch (final Throwable e) {
|
||||||
++this.error;
|
++this.error;
|
||||||
} finally {
|
}
|
||||||
|
finally {
|
||||||
++this.ticked;
|
++this.ticked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -943,7 +1016,7 @@ public class PlotMain extends JavaPlugin {
|
|||||||
options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN);
|
options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN);
|
||||||
options.put("perm-based-mob-cap.enabled", Settings.MOB_CAP_ENABLED);
|
options.put("perm-based-mob-cap.enabled", Settings.MOB_CAP_ENABLED);
|
||||||
options.put("perm-based-mob-cap.max", Settings.MOB_CAP);
|
options.put("perm-based-mob-cap.max", Settings.MOB_CAP);
|
||||||
options.put("worldedit.require-selection-in-mask",Settings.REQUIRE_SELECTION);
|
options.put("worldedit.require-selection-in-mask", Settings.REQUIRE_SELECTION);
|
||||||
|
|
||||||
for (final Entry<String, Object> node : options.entrySet()) {
|
for (final Entry<String, Object> node : options.entrySet()) {
|
||||||
if (!config.contains(node.getKey())) {
|
if (!config.contains(node.getKey())) {
|
||||||
@ -976,7 +1049,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Create a plotworld config section
|
* Create a plotworld config section
|
||||||
*
|
*
|
||||||
* @param plotworld World to create the section for
|
* @param plotworld
|
||||||
|
* World to create the section for
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static void createConfiguration(final PlotWorld plotworld) {
|
public static void createConfiguration(final PlotWorld plotworld) {
|
||||||
@ -994,7 +1068,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
config.save(PlotMain.configFile);
|
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");
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1004,9 +1079,7 @@ public class PlotMain extends JavaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> worlds = (config.contains("worlds") ?
|
final Set<String> worlds = (config.contains("worlds") ? config.getConfigurationSection("worlds").getKeys(false) : new HashSet<String>());
|
||||||
config.getConfigurationSection("worlds").getKeys(false) :
|
|
||||||
new HashSet<String>());
|
|
||||||
|
|
||||||
// Let's create these here instead
|
// Let's create these here instead
|
||||||
final PlotWorld plotWorld;
|
final PlotWorld plotWorld;
|
||||||
@ -1015,12 +1088,9 @@ public class PlotMain extends JavaPlugin {
|
|||||||
final String path = "worlds." + world;
|
final String path = "worlds." + world;
|
||||||
|
|
||||||
if ((generator != null) && (generator instanceof PlotGenerator)) {
|
if ((generator != null) && (generator instanceof PlotGenerator)) {
|
||||||
plotGenerator =
|
plotGenerator = (PlotGenerator) generator;
|
||||||
(PlotGenerator) generator;
|
plotWorld = plotGenerator.getNewPlotWorld(world);
|
||||||
plotWorld =
|
plotManager = plotGenerator.getPlotManager();
|
||||||
plotGenerator.getNewPlotWorld(world);
|
|
||||||
plotManager =
|
|
||||||
plotGenerator.getPlotManager();
|
|
||||||
sendConsoleSenderMessage(C.PREFIX.s() + "&aDetected world load for '" + world + "'");
|
sendConsoleSenderMessage(C.PREFIX.s() + "&aDetected world load for '" + world + "'");
|
||||||
sendConsoleSenderMessage(C.PREFIX.s() + "&3 - generator: &7" + plotGenerator.getClass().getName());
|
sendConsoleSenderMessage(C.PREFIX.s() + "&3 - generator: &7" + plotGenerator.getClass().getName());
|
||||||
sendConsoleSenderMessage(C.PREFIX.s() + "&3 - plotworld: &7" + plotWorld.getClass().getName());
|
sendConsoleSenderMessage(C.PREFIX.s() + "&3 - plotworld: &7" + plotWorld.getClass().getName());
|
||||||
@ -1035,20 +1105,20 @@ public class PlotMain extends JavaPlugin {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
config.save(configFile);
|
config.save(configFile);
|
||||||
} catch (final IOException e) {
|
}
|
||||||
|
catch (final IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Now add it
|
// Now add it
|
||||||
addPlotWorld(world, plotWorld, plotManager);
|
addPlotWorld(world, plotWorld, plotManager);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (worlds.contains(world)) {
|
if (worlds.contains(world)) {
|
||||||
sendConsoleSenderMessage("&cWorld '" + world + "' in settings.yml is not using PlotSquared generator!");
|
sendConsoleSenderMessage("&cWorld '" + world + "' in settings.yml is not using PlotSquared generator!");
|
||||||
|
|
||||||
plotWorld =
|
plotWorld = new DefaultPlotWorld(world);
|
||||||
new DefaultPlotWorld(world);
|
plotManager = new DefaultPlotManager();
|
||||||
plotManager =
|
|
||||||
new DefaultPlotManager();
|
|
||||||
|
|
||||||
if (!config.contains(path)) {
|
if (!config.contains(path)) {
|
||||||
config.createSection(path);
|
config.createSection(path);
|
||||||
@ -1059,7 +1129,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
config.save(configFile);
|
config.save(configFile);
|
||||||
} catch (final IOException e) {
|
}
|
||||||
|
catch (final IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1075,7 +1146,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
* use this method unless the required world is preconfigured in the
|
* use this method unless the required world is preconfigured in the
|
||||||
* settings.yml
|
* settings.yml
|
||||||
*
|
*
|
||||||
* @param world to load
|
* @param world
|
||||||
|
* to load
|
||||||
*/
|
*/
|
||||||
public static void loadWorld(final World world) {
|
public static void loadWorld(final World world) {
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
@ -1135,14 +1207,17 @@ public class PlotMain extends JavaPlugin {
|
|||||||
seconds = 1;
|
seconds = 1;
|
||||||
try {
|
try {
|
||||||
amount = Integer.parseInt(values[0]);
|
amount = Integer.parseInt(values[0]);
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
try {
|
try {
|
||||||
amount = Integer.parseInt(values[0]);
|
amount = Integer.parseInt(values[0]);
|
||||||
seconds = Integer.parseInt(values[1]);
|
seconds = Integer.parseInt(values[1]);
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1269,7 +1344,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
public String parseValue(final String value) {
|
public String parseValue(final String value) {
|
||||||
try {
|
try {
|
||||||
return Long.parseLong(value) + "";
|
return Long.parseLong(value) + "";
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1307,9 +1383,12 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Add a Plot world
|
* Add a Plot world
|
||||||
*
|
*
|
||||||
* @param world World to add
|
* @param world
|
||||||
* @param plotworld PlotWorld Object
|
* World to add
|
||||||
* @param manager Plot Manager for the new world
|
* @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) {
|
public static void addPlotWorld(final String world, final PlotWorld plotworld, final PlotManager manager) {
|
||||||
worlds.put(world, plotworld);
|
worlds.put(world, plotworld);
|
||||||
@ -1322,7 +1401,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Remove a plot world
|
* Remove a plot world
|
||||||
*
|
*
|
||||||
* @param world World to remove
|
* @param world
|
||||||
|
* World to remove
|
||||||
*/
|
*/
|
||||||
public static void removePlotWorld(final String world) {
|
public static void removePlotWorld(final String world) {
|
||||||
plots.remove(world);
|
plots.remove(world);
|
||||||
@ -1342,7 +1422,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Set all plots
|
* Set all plots
|
||||||
*
|
*
|
||||||
* @param plots New Plot LinkedHashMap
|
* @param plots
|
||||||
|
* New Plot LinkedHashMap
|
||||||
*/
|
*/
|
||||||
public static void setAllPlotsRaw(final LinkedHashMap<String, HashMap<PlotId, Plot>> plots) {
|
public static void setAllPlotsRaw(final LinkedHashMap<String, HashMap<PlotId, Plot>> plots) {
|
||||||
PlotMain.plots = plots;
|
PlotMain.plots = plots;
|
||||||
@ -1351,7 +1432,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Set all plots
|
* Set all plots
|
||||||
*
|
*
|
||||||
* @param plots New Plot HashMap
|
* @param plots
|
||||||
|
* New Plot HashMap
|
||||||
*/
|
*/
|
||||||
public static void setAllPlotsRaw(final HashMap<String, HashMap<PlotId, Plot>> plots) {
|
public static void setAllPlotsRaw(final HashMap<String, HashMap<PlotId, Plot>> plots) {
|
||||||
PlotMain.plots = new LinkedHashMap<>(plots);
|
PlotMain.plots = new LinkedHashMap<>(plots);
|
||||||
@ -1383,7 +1465,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
writer.write("Created at: " + new Date().toString() + "\n\n\n");
|
writer.write("Created at: " + new Date().toString() + "\n\n\n");
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
} catch (final IOException e) {
|
}
|
||||||
|
catch (final IOException e) {
|
||||||
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -1410,7 +1493,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
sendConsoleSenderMessage(C.PREFIX.s() + "&cURL: &6https://java.com/en/download/index.jsp");
|
sendConsoleSenderMessage(C.PREFIX.s() + "&cURL: &6https://java.com/en/download/index.jsp");
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
return;
|
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");
|
sendConsoleSenderMessage(C.PREFIX.s() + "&cIt's really recommended to run Java 1.8, as it increases performance");
|
||||||
}
|
}
|
||||||
// Setup configuration
|
// Setup configuration
|
||||||
@ -1421,10 +1505,12 @@ public class PlotMain extends JavaPlugin {
|
|||||||
final Metrics metrics = new Metrics(this);
|
final Metrics metrics = new Metrics(this);
|
||||||
metrics.start();
|
metrics.start();
|
||||||
sendConsoleSenderMessage(C.PREFIX.s() + "&6Metrics enabled.");
|
sendConsoleSenderMessage(C.PREFIX.s() + "&6Metrics enabled.");
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to load up metrics.");
|
sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to load up metrics.");
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// We should at least make them feel bad.
|
// We should at least make them feel bad.
|
||||||
sendConsoleSenderMessage("Using metrics will allow us to improve the plugin\nPlease consider it :)");
|
sendConsoleSenderMessage("Using metrics will allow us to improve the plugin\nPlease consider it :)");
|
||||||
}
|
}
|
||||||
@ -1437,9 +1523,7 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add tables to this one, if we create more :D
|
// Add tables to this one, if we create more :D
|
||||||
final String[] tables = new String[]{
|
final String[] tables = new String[] { "plot_trusted", "plot_ratings", "plot_comments" };
|
||||||
"plot_trusted", "plot_ratings", "plot_comments"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Use mysql?
|
// Use mysql?
|
||||||
if (Settings.DB.USE_MYSQL) {
|
if (Settings.DB.USE_MYSQL) {
|
||||||
@ -1454,8 +1538,9 @@ public class PlotMain extends JavaPlugin {
|
|||||||
ResultSet res = meta.getTables(null, null, Settings.DB.PREFIX + "plot", null);
|
ResultSet res = meta.getTables(null, null, Settings.DB.PREFIX + "plot", null);
|
||||||
if (!res.next()) {
|
if (!res.next()) {
|
||||||
DBFunc.createTables("mysql", true);
|
DBFunc.createTables("mysql", true);
|
||||||
} else {
|
}
|
||||||
for (String table : tables) {
|
else {
|
||||||
|
for (final String table : tables) {
|
||||||
res = meta.getTables(null, null, Settings.DB.PREFIX + table, null);
|
res = meta.getTables(null, null, Settings.DB.PREFIX + table, null);
|
||||||
if (!res.next()) {
|
if (!res.next()) {
|
||||||
DBFunc.createTables("mysql", false);
|
DBFunc.createTables("mysql", false);
|
||||||
@ -1464,7 +1549,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
// We should not repeat our self :P
|
// We should not repeat our self :P
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
Logger.add(LogLevel.DANGER, "MySQL connection failed.");
|
Logger.add(LogLevel.DANGER, "MySQL connection failed.");
|
||||||
sendConsoleSenderMessage("&c[Plots] MySQL is not setup correctly. The plugin will disable itself.");
|
sendConsoleSenderMessage("&c[Plots] MySQL is not setup correctly. The plugin will disable itself.");
|
||||||
if ((config == null) || config.getBoolean("debug")) {
|
if ((config == null) || config.getBoolean("debug")) {
|
||||||
@ -1482,7 +1568,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
else if (Settings.DB.USE_MONGO) {
|
else if (Settings.DB.USE_MONGO) {
|
||||||
// DBFunc.dbManager = new MongoManager();
|
// DBFunc.dbManager = new MongoManager();
|
||||||
sendConsoleSenderMessage(C.PREFIX.s() + "MongoDB is not yet implemented");
|
sendConsoleSenderMessage(C.PREFIX.s() + "MongoDB is not yet implemented");
|
||||||
} else if (Settings.DB.USE_SQLITE) {
|
}
|
||||||
|
else if (Settings.DB.USE_SQLITE) {
|
||||||
try {
|
try {
|
||||||
connection = new SQLite(this, Settings.DB.SQLITE_DB + ".db").openConnection();
|
connection = new SQLite(this, Settings.DB.SQLITE_DB + ".db").openConnection();
|
||||||
{
|
{
|
||||||
@ -1491,8 +1578,9 @@ public class PlotMain extends JavaPlugin {
|
|||||||
ResultSet res = meta.getTables(null, null, Settings.DB.PREFIX + "plot", null);
|
ResultSet res = meta.getTables(null, null, Settings.DB.PREFIX + "plot", null);
|
||||||
if (!res.next()) {
|
if (!res.next()) {
|
||||||
DBFunc.createTables("sqlite", true);
|
DBFunc.createTables("sqlite", true);
|
||||||
} else {
|
}
|
||||||
for (String table : tables) {
|
else {
|
||||||
|
for (final String table : tables) {
|
||||||
res = meta.getTables(null, null, Settings.DB.PREFIX + table, null);
|
res = meta.getTables(null, null, Settings.DB.PREFIX + table, null);
|
||||||
if (!res.next()) {
|
if (!res.next()) {
|
||||||
DBFunc.createTables("sqlite", false);
|
DBFunc.createTables("sqlite", false);
|
||||||
@ -1500,7 +1588,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
Logger.add(LogLevel.DANGER, "SQLite connection failed");
|
Logger.add(LogLevel.DANGER, "SQLite connection failed");
|
||||||
sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to open SQLite connection. The plugin will disable itself.");
|
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 ===");
|
sendConsoleSenderMessage("&9==== Here is an ugly stacktrace, if you are interested in those things ===");
|
||||||
@ -1509,7 +1598,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plots = DBFunc.getPlots();
|
plots = DBFunc.getPlots();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Logger.add(LogLevel.DANGER, "No storage type is set.");
|
Logger.add(LogLevel.DANGER, "No storage type is set.");
|
||||||
sendConsoleSenderMessage(C.PREFIX + "&cNo storage type is set!");
|
sendConsoleSenderMessage(C.PREFIX + "&cNo storage type is set!");
|
||||||
getServer().getPluginManager().disablePlugin(this);
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
@ -1522,7 +1612,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
if (getServer().getPluginManager().getPlugin("PlotMe") != null) {
|
if (getServer().getPluginManager().getPlugin("PlotMe") != null) {
|
||||||
try {
|
try {
|
||||||
new PlotMeConverter(this).runAsync();
|
new PlotMeConverter(this).runAsync();
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1531,9 +1622,7 @@ public class PlotMain extends JavaPlugin {
|
|||||||
final MainCommand command = new MainCommand();
|
final MainCommand command = new MainCommand();
|
||||||
final PluginCommand plotCommand = getCommand("plots");
|
final PluginCommand plotCommand = getCommand("plots");
|
||||||
plotCommand.setExecutor(command);
|
plotCommand.setExecutor(command);
|
||||||
plotCommand.setAliases(
|
plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
|
||||||
Arrays.asList("p", "ps", "plotme", "plot")
|
|
||||||
);
|
|
||||||
plotCommand.setTabCompleter(command);
|
plotCommand.setTabCompleter(command);
|
||||||
}
|
}
|
||||||
if (Settings.MOB_CAP_ENABLED) {
|
if (Settings.MOB_CAP_ENABLED) {
|
||||||
@ -1564,7 +1653,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
PlotMain.sendConsoleSenderMessage("&cThis version of WorldEdit does not support PlotSquared.");
|
PlotMain.sendConsoleSenderMessage("&cThis version of WorldEdit does not support PlotSquared.");
|
||||||
PlotMain.sendConsoleSenderMessage("&cPlease use WorldEdit 6+");
|
PlotMain.sendConsoleSenderMessage("&cPlease use WorldEdit 6+");
|
||||||
PlotMain.sendConsoleSenderMessage("&c - http://builds.enginehub.org/job/worldedit");
|
PlotMain.sendConsoleSenderMessage("&c - http://builds.enginehub.org/job/worldedit");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
getServer().getPluginManager().registerEvents(new WorldEditListener(), this);
|
getServer().getPluginManager().registerEvents(new WorldEditListener(), this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1598,14 +1688,16 @@ public class PlotMain extends JavaPlugin {
|
|||||||
try {
|
try {
|
||||||
new SetBlockFast();
|
new SetBlockFast();
|
||||||
PlotHelper.canSetFast = true;
|
PlotHelper.canSetFast = true;
|
||||||
} catch (final Throwable e) {
|
}
|
||||||
|
catch (final Throwable e) {
|
||||||
PlotHelper.canSetFast = false;
|
PlotHelper.canSetFast = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new SendChunk();
|
new SendChunk();
|
||||||
PlotHelper.canSendChunk = true;
|
PlotHelper.canSendChunk = true;
|
||||||
} catch (final Throwable e) {
|
}
|
||||||
|
catch (final Throwable e) {
|
||||||
PlotHelper.canSendChunk = false;
|
PlotHelper.canSendChunk = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1635,7 +1727,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
final public void onDisable() {
|
final public void onDisable() {
|
||||||
try {
|
try {
|
||||||
C.saveTranslations();
|
C.saveTranslations();
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
sendConsoleSenderMessage("Failed to save translations");
|
sendConsoleSenderMessage("Failed to save translations");
|
||||||
Logger.add(LogLevel.DANGER, "Failed to save translations");
|
Logger.add(LogLevel.DANGER, "Failed to save translations");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -1643,13 +1736,15 @@ public class PlotMain extends JavaPlugin {
|
|||||||
Logger.add(LogLevel.GENERAL, "Logger disabled");
|
Logger.add(LogLevel.GENERAL, "Logger disabled");
|
||||||
try {
|
try {
|
||||||
Logger.write();
|
Logger.write();
|
||||||
} catch (final IOException e1) {
|
}
|
||||||
|
catch (final IOException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
connection.close();
|
connection.close();
|
||||||
mySQL.closeConnection();
|
mySQL.closeConnection();
|
||||||
} catch (NullPointerException | SQLException e) {
|
}
|
||||||
|
catch (NullPointerException | SQLException e) {
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
Logger.add(LogLevel.DANGER, "Could not close mysql connection");
|
Logger.add(LogLevel.DANGER, "Could not close mysql connection");
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,16 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.api;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||||
import com.intellectualcrafters.plot.commands.SubCommand;
|
import com.intellectualcrafters.plot.commands.SubCommand;
|
||||||
@ -38,16 +48,6 @@ import com.intellectualcrafters.plot.util.SchematicHandler;
|
|||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.sun.istack.internal.NotNull;
|
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
|
* PlotSquared API
|
||||||
*
|
*
|
||||||
@ -65,7 +65,7 @@ public class PlotAPI {
|
|||||||
* this permission node will allow the player
|
* this permission node will allow the player
|
||||||
* to use any part of the plugin, without limitations.
|
* to use any part of the plugin, without limitations.
|
||||||
*/
|
*/
|
||||||
public static final String ADMIN_PERMISSION = "plots.admin";
|
public static final String ADMIN_PERMISSION = "plots.admin";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plot Helper Class
|
* Plot Helper Class
|
||||||
@ -74,28 +74,31 @@ public class PlotAPI {
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.util.PlotHelper
|
* @see com.intellectualcrafters.plot.util.PlotHelper
|
||||||
*/
|
*/
|
||||||
private static PlotHelper plotHelper;
|
private static PlotHelper plotHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Player Functions
|
* Player Functions
|
||||||
*
|
*
|
||||||
* General functions involving players, and plot worlds
|
* General functions involving players, and plot worlds
|
||||||
|
*
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions
|
* @see com.intellectualcrafters.plot.util.PlayerFunctions
|
||||||
*/
|
*/
|
||||||
private static PlayerFunctions playerFunctions;
|
private static PlayerFunctions playerFunctions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag Manager
|
* Flag Manager
|
||||||
*
|
*
|
||||||
* The manager which handles all flags
|
* The manager which handles all flags
|
||||||
|
*
|
||||||
* @see com.intellectualcrafters.plot.flag.FlagManager
|
* @see com.intellectualcrafters.plot.flag.FlagManager
|
||||||
*/
|
*/
|
||||||
private static FlagManager flagManager;
|
private static FlagManager flagManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schematic Handler
|
* Schematic Handler
|
||||||
*
|
*
|
||||||
* The handler which is used to create, and paste, schematics
|
* The handler which is used to create, and paste, schematics
|
||||||
|
*
|
||||||
* @see com.intellectualcrafters.plot.util.SchematicHandler
|
* @see com.intellectualcrafters.plot.util.SchematicHandler
|
||||||
*/
|
*/
|
||||||
private static SchematicHandler schematicHandler;
|
private static SchematicHandler schematicHandler;
|
||||||
@ -105,27 +108,30 @@ public class PlotAPI {
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.config.C
|
* @see com.intellectualcrafters.plot.config.C
|
||||||
*/
|
*/
|
||||||
private static C c;
|
private static C c;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlotMain instance
|
* PlotMain instance
|
||||||
*
|
*
|
||||||
* This is the instance that allows for most methods to be used.
|
* This is the instance that allows for most methods to be used.
|
||||||
|
*
|
||||||
* @see com.intellectualcrafters.plot.PlotMain
|
* @see com.intellectualcrafters.plot.PlotMain
|
||||||
*/
|
*/
|
||||||
private final PlotMain plotMain;
|
private final PlotMain plotMain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor. Insert any Plugin.
|
* Constructor. Insert any Plugin.
|
||||||
* (Optimally the plugin that is accessing the method)
|
* (Optimally the plugin that is accessing the method)
|
||||||
*
|
*
|
||||||
* @param plugin Plugin used to access this method
|
* @param plugin
|
||||||
* @throws com.intellectualcrafters.plot.util.PlotSquaredException if the program fails to fetch the PlotMain instance
|
* 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
|
* @see com.intellectualcrafters.plot.PlotMain
|
||||||
*/
|
*/
|
||||||
public PlotAPI(@NotNull final JavaPlugin plugin) {
|
public PlotAPI(@NotNull final JavaPlugin plugin) {
|
||||||
this.plotMain = PlotMain.getMain();
|
this.plotMain = PlotMain.getMain();
|
||||||
if (plotMain == null) {
|
if (this.plotMain == null) {
|
||||||
throw new PlotSquaredException(PlotSquaredException.PlotError.PLOTMAIN_NULL, "Failed to fetch the plotmain instance, Plot API for " + plugin.getName() + " will be disabled");
|
throw new PlotSquaredException(PlotSquaredException.PlotError.PLOTMAIN_NULL, "Failed to fetch the plotmain instance, Plot API for " + plugin.getName() + " will be disabled");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,7 +149,8 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Return all plots for a player
|
* 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
|
* @return all plots that a player owns
|
||||||
*/
|
*/
|
||||||
public Set<Plot> getPlayerPlots(@NotNull final Player player) {
|
public Set<Plot> getPlayerPlots(@NotNull final Player player) {
|
||||||
@ -153,12 +160,15 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Add a plot world
|
* Add a plot world
|
||||||
*
|
*
|
||||||
* @param world World Name
|
* @param world
|
||||||
* @param plotWorld Plot World Object
|
* World Name
|
||||||
* @param manager World Manager
|
* @param plotWorld
|
||||||
|
* Plot World Object
|
||||||
|
* @param manager
|
||||||
|
* World Manager
|
||||||
* @see com.intellectualcrafters.plot.PlotMain#addPlotWorld(String,
|
* @see com.intellectualcrafters.plot.PlotMain#addPlotWorld(String,
|
||||||
* com.intellectualcrafters.plot.object.PlotWorld,
|
* com.intellectualcrafters.plot.object.PlotWorld,
|
||||||
* com.intellectualcrafters.plot.object.PlotManager)
|
* com.intellectualcrafters.plot.object.PlotManager)
|
||||||
*/
|
*/
|
||||||
public void addPlotWorld(@NotNull final String world, @NotNull final PlotWorld plotWorld, @NotNull final PlotManager manager) {
|
public void addPlotWorld(@NotNull final String world, @NotNull final PlotWorld plotWorld, @NotNull final PlotManager manager) {
|
||||||
PlotMain.addPlotWorld(world, plotWorld, manager);
|
PlotMain.addPlotWorld(world, plotWorld, manager);
|
||||||
@ -247,7 +257,8 @@ public class PlotAPI {
|
|||||||
* Get the plot manager for a world. - Most of these methods can be accessed
|
* Get the plot manager for a world. - Most of these methods can be accessed
|
||||||
* through the PlotHelper
|
* through the PlotHelper
|
||||||
*
|
*
|
||||||
* @param world Which manager to get
|
* @param world
|
||||||
|
* Which manager to get
|
||||||
* @return PlotManager
|
* @return PlotManager
|
||||||
* @see com.intellectualcrafters.plot.object.PlotManager
|
* @see com.intellectualcrafters.plot.object.PlotManager
|
||||||
* @see PlotMain#getPlotManager(org.bukkit.World)
|
* @see PlotMain#getPlotManager(org.bukkit.World)
|
||||||
@ -260,7 +271,8 @@ public class PlotAPI {
|
|||||||
* Get the plot manager for a world. - Contains useful low level methods for
|
* Get the plot manager for a world. - Contains useful low level methods for
|
||||||
* plot merging, clearing, and tessellation
|
* plot merging, clearing, and tessellation
|
||||||
*
|
*
|
||||||
* @param world Plot World
|
* @param world
|
||||||
|
* Plot World
|
||||||
* @return PlotManager
|
* @return PlotManager
|
||||||
* @see PlotMain#getPlotManager(String)
|
* @see PlotMain#getPlotManager(String)
|
||||||
* @see com.intellectualcrafters.plot.object.PlotManager
|
* @see com.intellectualcrafters.plot.object.PlotManager
|
||||||
@ -274,9 +286,10 @@ public class PlotAPI {
|
|||||||
* will need to downcast for the specific settings a Generator has. e.g.
|
* will need to downcast for the specific settings a Generator has. e.g.
|
||||||
* DefaultPlotWorld class implements PlotWorld
|
* DefaultPlotWorld class implements PlotWorld
|
||||||
*
|
*
|
||||||
* @param world (to get settings of)
|
* @param world
|
||||||
|
* (to get settings of)
|
||||||
* @return PlotWorld class for that world ! will return null if not a plot
|
* @return PlotWorld class for that world ! will return null if not a plot
|
||||||
* world world
|
* world world
|
||||||
* @see PlotMain#getWorldSettings(org.bukkit.World)
|
* @see PlotMain#getWorldSettings(org.bukkit.World)
|
||||||
* @see com.intellectualcrafters.plot.object.PlotWorld
|
* @see com.intellectualcrafters.plot.object.PlotWorld
|
||||||
*/
|
*/
|
||||||
@ -287,9 +300,10 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get the settings for a world (settings bundled in PlotWorld class)
|
* Get the settings for a world (settings bundled in PlotWorld class)
|
||||||
*
|
*
|
||||||
* @param world (to get settings of)
|
* @param world
|
||||||
|
* (to get settings of)
|
||||||
* @return PlotWorld class for that world ! will return null if not a plot
|
* @return PlotWorld class for that world ! will return null if not a plot
|
||||||
* world world
|
* world world
|
||||||
* @see PlotMain#getWorldSettings(String)
|
* @see PlotMain#getWorldSettings(String)
|
||||||
* @see com.intellectualcrafters.plot.object.PlotWorld
|
* @see com.intellectualcrafters.plot.object.PlotWorld
|
||||||
*/
|
*/
|
||||||
@ -300,9 +314,12 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Send a message to a player.
|
* Send a message to a player.
|
||||||
*
|
*
|
||||||
* @param player Player that will receive the message
|
* @param player
|
||||||
* @param c (Caption)
|
* Player that will receive the message
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player, com.intellectualcrafters.plot.config.C, String...)
|
* @param c
|
||||||
|
* (Caption)
|
||||||
|
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player,
|
||||||
|
* com.intellectualcrafters.plot.config.C, String...)
|
||||||
*/
|
*/
|
||||||
public void sendMessage(@NotNull final Player player, @NotNull final C c) {
|
public void sendMessage(@NotNull final Player player, @NotNull final C c) {
|
||||||
PlayerFunctions.sendMessage(player, c);
|
PlayerFunctions.sendMessage(player, c);
|
||||||
@ -311,9 +328,12 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Send a message to a player. - Supports color codes
|
* Send a message to a player. - Supports color codes
|
||||||
*
|
*
|
||||||
* @param player Player that will receive the message
|
* @param player
|
||||||
* @param string The message
|
* Player that will receive the message
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player, String)
|
* @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) {
|
public void sendMessage(@NotNull final Player player, @NotNull final String string) {
|
||||||
PlayerFunctions.sendMessage(player, string);
|
PlayerFunctions.sendMessage(player, string);
|
||||||
@ -322,7 +342,8 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Send a message to the console. - Supports color codes
|
* 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)
|
* @see PlotMain#sendConsoleSenderMessage(String)
|
||||||
*/
|
*/
|
||||||
public void sendConsoleMessage(@NotNull final String msg) {
|
public void sendConsoleMessage(@NotNull final String msg) {
|
||||||
@ -332,7 +353,8 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Send a message to the console
|
* Send a message to the console
|
||||||
*
|
*
|
||||||
* @param c (Caption)
|
* @param c
|
||||||
|
* (Caption)
|
||||||
* @see #sendConsoleMessage(String)
|
* @see #sendConsoleMessage(String)
|
||||||
* @see com.intellectualcrafters.plot.config.C
|
* @see com.intellectualcrafters.plot.config.C
|
||||||
*/
|
*/
|
||||||
@ -343,7 +365,8 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Register a flag for use in plots
|
* 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.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag)
|
||||||
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
||||||
*/
|
*/
|
||||||
@ -365,11 +388,15 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get a plot based on the ID
|
* Get a plot based on the ID
|
||||||
*
|
*
|
||||||
* @param world World in which the plot is located
|
* @param world
|
||||||
* @param x Plot Location X Co-ord
|
* World in which the plot is located
|
||||||
* @param z Plot Location Z Co-ord
|
* @param x
|
||||||
|
* Plot Location X Co-ord
|
||||||
|
* @param z
|
||||||
|
* Plot Location Z Co-ord
|
||||||
* @return plot, null if ID is wrong
|
* @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
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Plot getPlot(@NotNull final World world, final int x, final int z) {
|
public Plot getPlot(@NotNull final World world, final int x, final int z) {
|
||||||
@ -379,7 +406,8 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get a plot based on the location
|
* 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-
|
* @return plot if found, otherwise it creates a temporary plot-
|
||||||
* @see PlotHelper#getCurrentPlot(org.bukkit.Location)
|
* @see PlotHelper#getCurrentPlot(org.bukkit.Location)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
@ -391,7 +419,8 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get a plot based on the player location
|
* 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
|
* @return plot if found, otherwise it creates a temporary plot
|
||||||
* @see #getPlot(org.bukkit.Location)
|
* @see #getPlot(org.bukkit.Location)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
@ -403,7 +432,8 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Check whether or not a player has a plot
|
* 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.
|
* @return true if player has a plot, false if not.
|
||||||
* @see #getPlots(org.bukkit.World, org.bukkit.entity.Player, boolean)
|
* @see #getPlots(org.bukkit.World, org.bukkit.entity.Player, boolean)
|
||||||
*/
|
*/
|
||||||
@ -414,8 +444,10 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get all plots for the player
|
* Get all plots for the player
|
||||||
*
|
*
|
||||||
* @param plr to search for
|
* @param plr
|
||||||
* @param just_owner should we just search for owner? Or with rights?
|
* to search for
|
||||||
|
* @param just_owner
|
||||||
|
* should we just search for owner? Or with rights?
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Plot[] getPlots(@NotNull final World world, @NotNull final Player plr, final boolean just_owner) {
|
public Plot[] getPlots(@NotNull final World world, @NotNull final Player plr, final boolean just_owner) {
|
||||||
@ -425,7 +457,8 @@ public class PlotAPI {
|
|||||||
if ((plot.owner != null) && (plot.owner == UUIDHandler.getUUID(plr))) {
|
if ((plot.owner != null) && (plot.owner == UUIDHandler.getUUID(plr))) {
|
||||||
pPlots.add(plot);
|
pPlots.add(plot);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (plot.hasRights(plr)) {
|
if (plot.hasRights(plr)) {
|
||||||
pPlots.add(plot);
|
pPlots.add(plot);
|
||||||
}
|
}
|
||||||
@ -437,7 +470,8 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get all plots for the world
|
* 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
|
* @return Plot[] - array of plot objects in world
|
||||||
* @see PlotMain#getWorldPlots(org.bukkit.World)
|
* @see PlotMain#getWorldPlots(org.bukkit.World)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
@ -459,7 +493,8 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get if plot world
|
* 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)
|
* @return boolean (if plot world or not)
|
||||||
* @see com.intellectualcrafters.plot.PlotMain#isPlotWorld(org.bukkit.World)
|
* @see com.intellectualcrafters.plot.PlotMain#isPlotWorld(org.bukkit.World)
|
||||||
*/
|
*/
|
||||||
@ -470,25 +505,31 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get plot locations
|
* 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
|
* @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#getPlotBottomLoc(org.bukkit.World,
|
||||||
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotTopLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId)
|
* com.intellectualcrafters.plot.object.PlotId)
|
||||||
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World, com.intellectualcrafters.plot.object.Plot)
|
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotTopLoc(org.bukkit.World,
|
||||||
|
* com.intellectualcrafters.plot.object.PlotId)
|
||||||
|
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World,
|
||||||
|
* com.intellectualcrafters.plot.object.Plot)
|
||||||
* @see com.intellectualcrafters.plot.object.PlotHomePosition
|
* @see com.intellectualcrafters.plot.object.PlotHomePosition
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Location[] getLocations(@NotNull final Plot p) {
|
public Location[] getLocations(@NotNull final Plot p) {
|
||||||
final World world = Bukkit.getWorld(p.world);
|
final World world = Bukkit.getWorld(p.world);
|
||||||
return new Location[]{PlotHelper.getPlotBottomLoc(world, p.id), PlotHelper.getPlotTopLoc(world, p.id), PlotHelper.getPlotHome(world, p.id)};
|
return new Location[] { PlotHelper.getPlotBottomLoc(world, p.id), PlotHelper.getPlotTopLoc(world, p.id), PlotHelper.getPlotHome(world, p.id) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get home location
|
* 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
|
* @return plot bottom location
|
||||||
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World, com.intellectualcrafters.plot.object.Plot)
|
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World,
|
||||||
|
* com.intellectualcrafters.plot.object.Plot)
|
||||||
* @see com.intellectualcrafters.plot.object.PlotHomePosition
|
* @see com.intellectualcrafters.plot.object.PlotHomePosition
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
@ -499,9 +540,11 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get Bottom Location (min, min, min)
|
* 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
|
* @return plot bottom location
|
||||||
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotBottomLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId)
|
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotBottomLoc(org.bukkit.World,
|
||||||
|
* com.intellectualcrafters.plot.object.PlotId)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Location getBottomLocation(@NotNull final Plot p) {
|
public Location getBottomLocation(@NotNull final Plot p) {
|
||||||
@ -512,9 +555,11 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get Top Location (max, max, max)
|
* 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
|
* @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
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Location getTopLocation(@NotNull final Plot p) {
|
public Location getTopLocation(@NotNull final Plot p) {
|
||||||
@ -525,7 +570,8 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Check whether or not a player is in a plot
|
* 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-
|
* @return true if the player is in a plot, false if not-
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#isInPlot(org.bukkit.entity.Player)
|
* @see com.intellectualcrafters.plot.util.PlayerFunctions#isInPlot(org.bukkit.entity.Player)
|
||||||
*/
|
*/
|
||||||
@ -536,7 +582,8 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Register a subcommand
|
* 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.MainCommand#subCommands
|
||||||
* @see com.intellectualcrafters.plot.commands.SubCommand
|
* @see com.intellectualcrafters.plot.commands.SubCommand
|
||||||
*/
|
*/
|
||||||
@ -557,10 +604,13 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get the player plot count
|
* Get the player plot count
|
||||||
*
|
*
|
||||||
* @param world Specify the world we want to select the plots from
|
* @param world
|
||||||
* @param player Player, for whom we're getting the plot count
|
* 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
|
* @return the number of plots the player has
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#getPlayerPlotCount(org.bukkit.World, org.bukkit.entity.Player)
|
* @see com.intellectualcrafters.plot.util.PlayerFunctions#getPlayerPlotCount(org.bukkit.World,
|
||||||
|
* org.bukkit.entity.Player)
|
||||||
*/
|
*/
|
||||||
public int getPlayerPlotCount(@NotNull final World world, @NotNull final Player player) {
|
public int getPlayerPlotCount(@NotNull final World world, @NotNull final Player player) {
|
||||||
return PlayerFunctions.getPlayerPlotCount(world, player);
|
return PlayerFunctions.getPlayerPlotCount(world, player);
|
||||||
@ -569,10 +619,13 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get a collection containing the players plots
|
* Get a collection containing the players plots
|
||||||
*
|
*
|
||||||
* @param world Specify the world we want to select the plots from
|
* @param world
|
||||||
* @param player Player, for whom we're getting the plots
|
* 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
|
* @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.util.PlayerFunctions#getPlayerPlots(org.bukkit.World,
|
||||||
|
* org.bukkit.entity.Player)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Set<Plot> getPlayerPlots(@NotNull final World world, @NotNull final Player player) {
|
public Set<Plot> getPlayerPlots(@NotNull final World world, @NotNull final Player player) {
|
||||||
@ -582,7 +635,9 @@ public class PlotAPI {
|
|||||||
/**
|
/**
|
||||||
* Get the numbers of plots, which the player is able to build in
|
* 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
|
* @return the number of allowed plots
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#getAllowedPlots(org.bukkit.entity.Player)
|
* @see com.intellectualcrafters.plot.util.PlayerFunctions#getAllowedPlots(org.bukkit.entity.Player)
|
||||||
*/
|
*/
|
||||||
|
@ -21,6 +21,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
@ -33,12 +39,6 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
|||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
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")
|
@SuppressWarnings("deprecation")
|
||||||
public class Auto extends SubCommand {
|
public class Auto extends SubCommand {
|
||||||
public static PlotId lastPlot = new PlotId(0, 0);
|
public static PlotId lastPlot = new PlotId(0, 0);
|
||||||
@ -53,16 +53,20 @@ public class Auto extends SubCommand {
|
|||||||
if (absX > absY) {
|
if (absX > absY) {
|
||||||
if (id.x > 0) {
|
if (id.x > 0) {
|
||||||
return new PlotId(id.x, id.y + 1);
|
return new PlotId(id.x, id.y + 1);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return new PlotId(id.x, id.y - 1);
|
return new PlotId(id.x, id.y - 1);
|
||||||
}
|
}
|
||||||
} else if (absY > absX) {
|
}
|
||||||
|
else if (absY > absX) {
|
||||||
if (id.y > 0) {
|
if (id.y > 0) {
|
||||||
return new PlotId(id.x - 1, id.y);
|
return new PlotId(id.x - 1, id.y);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return new PlotId(id.x + 1, id.y);
|
return new PlotId(id.x + 1, id.y);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (id.x.equals(id.y) && (id.x > 0)) {
|
if (id.x.equals(id.y) && (id.x > 0)) {
|
||||||
return new PlotId(id.x, id.y + step);
|
return new PlotId(id.x, id.y + step);
|
||||||
}
|
}
|
||||||
@ -85,10 +89,12 @@ public class Auto extends SubCommand {
|
|||||||
String schematic = "";
|
String schematic = "";
|
||||||
if (PlotMain.getPlotWorlds().length == 1) {
|
if (PlotMain.getPlotWorlds().length == 1) {
|
||||||
world = Bukkit.getWorld(PlotMain.getPlotWorlds()[0]);
|
world = Bukkit.getWorld(PlotMain.getPlotWorlds()[0]);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (PlotMain.isPlotWorld(plr.getWorld())) {
|
if (PlotMain.isPlotWorld(plr.getWorld())) {
|
||||||
world = plr.getWorld();
|
world = plr.getWorld();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -108,7 +114,8 @@ public class Auto extends SubCommand {
|
|||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
schematic = args[1];
|
schematic = args[1];
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
size_x = 1;
|
size_x = 1;
|
||||||
size_z = 1;
|
size_z = 1;
|
||||||
schematic = args[0];
|
schematic = args[0];
|
||||||
@ -116,21 +123,22 @@ public class Auto extends SubCommand {
|
|||||||
// "&cError: Invalid size (X,Y)");
|
// "&cError: Invalid size (X,Y)");
|
||||||
// return false;
|
// return false;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
schematic = args[0];
|
schematic = args[0];
|
||||||
// PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
|
// PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
|
||||||
// return false;
|
// return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size_x * size_z > Settings.MAX_AUTO_SIZE) {
|
if ((size_x * size_z) > Settings.MAX_AUTO_SIZE) {
|
||||||
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + "");
|
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int diff = PlayerFunctions.getPlayerPlotCount(world, plr) - PlayerFunctions.getAllowedPlots(plr);
|
final int diff = PlayerFunctions.getPlayerPlotCount(world, plr) - PlayerFunctions.getAllowedPlots(plr);
|
||||||
if (diff + (size_x * size_z) >= 0) {
|
if ((diff + (size_x * size_z)) >= 0) {
|
||||||
if (diff < 0) {
|
if (diff < 0) {
|
||||||
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, - diff - 1 + "");
|
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff - 1) + "");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||||
@ -152,7 +160,7 @@ public class Auto extends SubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!schematic.equals("")) {
|
if (!schematic.equals("")) {
|
||||||
// if (pWorld.SCHEMATIC_CLAIM_SPECIFY) {
|
// if (pWorld.SCHEMATIC_CLAIM_SPECIFY) {
|
||||||
if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) {
|
if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) {
|
||||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
||||||
return true;
|
return true;
|
||||||
@ -161,36 +169,35 @@ public class Auto extends SubCommand {
|
|||||||
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
boolean br = false;
|
boolean br = false;
|
||||||
if ((size_x == 1) && (size_z == 1)) {
|
if ((size_x == 1) && (size_z == 1)) {
|
||||||
while (!br) {
|
while (!br) {
|
||||||
Plot plot = PlotHelper.getPlot(world, Auto.lastPlot);
|
final Plot plot = PlotHelper.getPlot(world, Auto.lastPlot);
|
||||||
if ((plot == null) || (plot.owner == null)) {
|
if ((plot == null) || (plot.owner == null)) {
|
||||||
Claim.claimPlot(plr, plot, true, true);
|
Claim.claimPlot(plr, plot, true, true);
|
||||||
br = true;
|
br = true;
|
||||||
final PlotWorld pw = PlotMain.getWorldSettings(world);
|
final PlotWorld pw = PlotMain.getWorldSettings(world);
|
||||||
final Plot plot2 = PlotMain.getPlots(world).get(plot.id);
|
final Plot plot2 = PlotMain.getPlots(world).get(plot.id);
|
||||||
if ((pw.DEFAULT_FLAGS != null) && (pw.DEFAULT_FLAGS.size() > 0)) {
|
if ((pw.DEFAULT_FLAGS != null) && (pw.DEFAULT_FLAGS.size() > 0)) {
|
||||||
Flag[] flags = FlagManager.parseFlags(pw.DEFAULT_FLAGS);
|
final Flag[] flags = FlagManager.parseFlags(pw.DEFAULT_FLAGS);
|
||||||
plot2.settings.setFlags(flags);
|
plot2.settings.setFlags(flags);
|
||||||
DBFunc.setFlags(plot2.world, plot2, flags);
|
DBFunc.setFlags(plot2.world, plot2, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Auto.lastPlot = getNextPlot(Auto.lastPlot, 1);
|
Auto.lastPlot = getNextPlot(Auto.lastPlot, 1);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
boolean lastPlot = true;
|
boolean lastPlot = true;
|
||||||
PlotId lastId = Auto.lastPlot;
|
|
||||||
while (!br) {
|
while (!br) {
|
||||||
final PlotId start = getNextPlot(Auto.lastPlot, 1);
|
final PlotId start = getNextPlot(Auto.lastPlot, 1);
|
||||||
// Checking if the current set of plots is a viable option.
|
// Checking if the current set of plots is a viable option.
|
||||||
Auto.lastPlot = start;
|
Auto.lastPlot = start;
|
||||||
if (lastPlot) {
|
if (lastPlot) {
|
||||||
lastId = start;
|
|
||||||
}
|
}
|
||||||
if (PlotMain.getPlots(world).get(start) != null && PlotMain.getPlots(world).get(start).owner != null) {
|
if ((PlotMain.getPlots(world).get(start) != null) && (PlotMain.getPlots(world).get(start).owner != null)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -214,7 +221,7 @@ public class Auto extends SubCommand {
|
|||||||
final PlotWorld pw = PlotMain.getWorldSettings(world);
|
final PlotWorld pw = PlotMain.getWorldSettings(world);
|
||||||
final Plot plot2 = PlotMain.getPlots(world).get(start);
|
final Plot plot2 = PlotMain.getPlots(world).get(start);
|
||||||
if ((pw.DEFAULT_FLAGS != null) && (pw.DEFAULT_FLAGS.size() > 0)) {
|
if ((pw.DEFAULT_FLAGS != null) && (pw.DEFAULT_FLAGS.size() > 0)) {
|
||||||
Flag[] flags = FlagManager.parseFlags(pw.DEFAULT_FLAGS);
|
final Flag[] flags = FlagManager.parseFlags(pw.DEFAULT_FLAGS);
|
||||||
plot2.settings.setFlags(flags);
|
plot2.settings.setFlags(flags);
|
||||||
DBFunc.setFlags(plot2.world, plot2, flags);
|
DBFunc.setFlags(plot2.world, plot2, flags);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2014-11-09 for PlotSquared
|
* Created 2014-11-09 for PlotSquared
|
||||||
@ -17,14 +18,14 @@ public class Ban extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(Player plr, String... args) {
|
public boolean execute(final Player plr, final String... args) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + usage);
|
return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + this.usage);
|
||||||
}
|
}
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
if (!PlayerFunctions.isInPlot(plr)) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
||||||
if (!plot.hasRights(plr)) {
|
if (!plot.hasRights(plr)) {
|
||||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,11 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
@ -34,9 +39,6 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||||
import com.intellectualcrafters.plot.util.SetBlockFast;
|
import com.intellectualcrafters.plot.util.SetBlockFast;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
@ -47,11 +49,11 @@ public class Claim extends SubCommand {
|
|||||||
super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING, true);
|
super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, boolean auto) {
|
public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, final boolean auto) {
|
||||||
return claimPlot(player, plot, teleport, "", auto);
|
return claimPlot(player, plot, teleport, "", auto);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, final String schematic, boolean auto) {
|
public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, final String schematic, final boolean auto) {
|
||||||
final PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot, auto);
|
final PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot, auto);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
@ -69,7 +71,8 @@ public class Claim extends SubCommand {
|
|||||||
SchematicHandler.Schematic sch;
|
SchematicHandler.Schematic sch;
|
||||||
if (schematic.equals("")) {
|
if (schematic.equals("")) {
|
||||||
sch = SchematicHandler.getSchematic(world.SCHEMATIC_FILE);
|
sch = SchematicHandler.getSchematic(world.SCHEMATIC_FILE);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sch = SchematicHandler.getSchematic(schematic);
|
sch = SchematicHandler.getSchematic(schematic);
|
||||||
if (sch == null) {
|
if (sch == null) {
|
||||||
sch = SchematicHandler.getSchematic(world.SCHEMATIC_FILE);
|
sch = SchematicHandler.getSchematic(world.SCHEMATIC_FILE);
|
||||||
@ -78,7 +81,7 @@ public class Claim extends SubCommand {
|
|||||||
SchematicHandler.paste(player.getLocation(), sch, plot2, 0, 0);
|
SchematicHandler.paste(player.getLocation(), sch, plot2, 0, 0);
|
||||||
}
|
}
|
||||||
if ((world.DEFAULT_FLAGS != null) && (world.DEFAULT_FLAGS.size() > 0)) {
|
if ((world.DEFAULT_FLAGS != null) && (world.DEFAULT_FLAGS.size() > 0)) {
|
||||||
Flag[] flags = FlagManager.parseFlags(world.DEFAULT_FLAGS);
|
final Flag[] flags = FlagManager.parseFlags(world.DEFAULT_FLAGS);
|
||||||
plot2.settings.setFlags(flags);
|
plot2.settings.setFlags(flags);
|
||||||
DBFunc.setFlags(plot.world, plot2, flags);
|
DBFunc.setFlags(plot.world, plot2, flags);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
@ -29,9 +32,6 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Clear extends SubCommand {
|
public class Clear extends SubCommand {
|
||||||
|
|
||||||
public Clear() {
|
public Clear() {
|
||||||
@ -44,19 +44,23 @@ public class Clear extends SubCommand {
|
|||||||
// Is console
|
// Is console
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
PlotMain.sendConsoleSenderMessage("You need to specify two arguments: ID (0;0) & World (world)");
|
PlotMain.sendConsoleSenderMessage("You need to specify two arguments: ID (0;0) & World (world)");
|
||||||
} else {
|
}
|
||||||
PlotId id = PlotId.fromString(args[0]);
|
else {
|
||||||
String world = args[1];
|
final PlotId id = PlotId.fromString(args[0]);
|
||||||
|
final String world = args[1];
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
PlotMain.sendConsoleSenderMessage("Invalid Plot ID: " + args[0]);
|
PlotMain.sendConsoleSenderMessage("Invalid Plot ID: " + args[0]);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (!PlotMain.isPlotWorld(world)) {
|
if (!PlotMain.isPlotWorld(world)) {
|
||||||
PlotMain.sendConsoleSenderMessage("Invalid plot world: " + world);
|
PlotMain.sendConsoleSenderMessage("Invalid plot world: " + world);
|
||||||
} else {
|
}
|
||||||
Plot plot = PlotHelper.getPlot(Bukkit.getWorld(world), id);
|
else {
|
||||||
|
final Plot plot = PlotHelper.getPlot(Bukkit.getWorld(world), id);
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
PlotMain.sendConsoleSenderMessage("Could not find plot " + args[0] + " in world " + world);
|
PlotMain.sendConsoleSenderMessage("Could not find plot " + args[0] + " in world " + world);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
plot.clear(null, false);
|
plot.clear(null, false);
|
||||||
PlotMain.sendConsoleSenderMessage("Plot " + plot.getId().toString() + " cleared.");
|
PlotMain.sendConsoleSenderMessage("Plot " + plot.getId().toString() + " cleared.");
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,14 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.config.C;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.object.PlotSelection;
|
import com.intellectualcrafters.plot.object.PlotSelection;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.object.PlotSelection.currentSelection;
|
|
||||||
|
|
||||||
public class Clipboard extends SubCommand {
|
public class Clipboard extends SubCommand {
|
||||||
|
|
||||||
|
@ -164,12 +164,12 @@ public enum Command {
|
|||||||
/**
|
/**
|
||||||
* Command
|
* Command
|
||||||
*/
|
*/
|
||||||
private final String command;
|
private final String command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alias
|
* Alias
|
||||||
*/
|
*/
|
||||||
private final String alias;
|
private final String alias;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permission Node
|
* Permission Node
|
||||||
@ -177,7 +177,8 @@ public enum Command {
|
|||||||
private final CommandPermission permission;
|
private final CommandPermission permission;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param command Command "name" (/plot [cmd])
|
* @param command
|
||||||
|
* Command "name" (/plot [cmd])
|
||||||
*/
|
*/
|
||||||
Command(final String command) {
|
Command(final String command) {
|
||||||
this.command = command;
|
this.command = command;
|
||||||
@ -186,8 +187,10 @@ public enum Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param command Command "name" (/plot [cmd])
|
* @param command
|
||||||
* @param permission Command Permission Node
|
* Command "name" (/plot [cmd])
|
||||||
|
* @param permission
|
||||||
|
* Command Permission Node
|
||||||
*/
|
*/
|
||||||
Command(final String command, final CommandPermission permission) {
|
Command(final String command, final CommandPermission permission) {
|
||||||
this.command = command;
|
this.command = command;
|
||||||
@ -196,8 +199,10 @@ public enum Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param command Command "name" (/plot [cmd])
|
* @param command
|
||||||
* @param alias Command Alias
|
* Command "name" (/plot [cmd])
|
||||||
|
* @param alias
|
||||||
|
* Command Alias
|
||||||
*/
|
*/
|
||||||
Command(final String command, final String alias) {
|
Command(final String command, final String alias) {
|
||||||
this.command = command;
|
this.command = command;
|
||||||
@ -206,9 +211,12 @@ public enum Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param command Command "name" (/plot [cmd])
|
* @param command
|
||||||
* @param alias Command Alias
|
* Command "name" (/plot [cmd])
|
||||||
* @param permission Required Permission Node
|
* @param alias
|
||||||
|
* Command Alias
|
||||||
|
* @param permission
|
||||||
|
* Required Permission Node
|
||||||
*/
|
*/
|
||||||
Command(final String command, final String alias, final CommandPermission permission) {
|
Command(final String command, final String alias, final CommandPermission permission) {
|
||||||
this.command = command;
|
this.command = command;
|
||||||
|
@ -21,9 +21,10 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Citymonstret on 2014-08-03.
|
* Created by Citymonstret on 2014-08-03.
|
||||||
*
|
*
|
||||||
@ -37,14 +38,16 @@ public class CommandPermission {
|
|||||||
public final String permission;
|
public final String permission;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param permission Command Permission
|
* @param permission
|
||||||
|
* Command Permission
|
||||||
*/
|
*/
|
||||||
public CommandPermission(final String permission) {
|
public CommandPermission(final String permission) {
|
||||||
this.permission = permission.toLowerCase();
|
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
|
* @return true of player has the required permission node
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(final Player player) {
|
public boolean hasPermission(final Player player) {
|
||||||
|
@ -21,17 +21,18 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotComment;
|
import com.intellectualcrafters.plot.object.PlotComment;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
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 {
|
public class Comment extends SubCommand {
|
||||||
|
|
||||||
@ -61,7 +62,8 @@ public class Comment extends SubCommand {
|
|||||||
DBFunc.setComment(plr.getWorld().getName(), plot, comment);
|
DBFunc.setComment(plr.getWorld().getName(), plot, comment);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return sendMessage(plr, C.NO_PERMISSION, "plots.comment." + args[0].toLowerCase());
|
return sendMessage(plr, C.NO_PERMISSION, "plots.comment." + args[0].toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,14 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotSelection;
|
import com.intellectualcrafters.plot.object.PlotSelection;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Copy extends SubCommand {
|
public class Copy extends SubCommand {
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2014-11-09 for PlotSquared
|
* Created 2014-11-09 for PlotSquared
|
||||||
@ -17,14 +18,14 @@ public class DEOP extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(Player plr, String... args) {
|
public boolean execute(final Player plr, final String... args) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + usage);
|
return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + this.usage);
|
||||||
}
|
}
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
if (!PlayerFunctions.isInPlot(plr)) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
||||||
if (!plot.hasRights(plr)) {
|
if (!plot.hasRights(plr)) {
|
||||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.database.MySQL;
|
import com.intellectualcrafters.plot.database.MySQL;
|
||||||
import com.intellectualcrafters.plot.database.SQLManager;
|
import com.intellectualcrafters.plot.database.SQLManager;
|
||||||
@ -8,17 +18,6 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
import com.intellectualcrafters.plot.util.StringComparison;
|
import com.intellectualcrafters.plot.util.StringComparison;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
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
|
* Created 2014-11-15 for PlotSquared
|
||||||
*
|
*
|
||||||
@ -26,47 +25,51 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class Database extends SubCommand {
|
public class Database extends SubCommand {
|
||||||
|
|
||||||
final String[] tables = new String[]{
|
final String[] tables = new String[] { "plot_trusted", "plot_ratings", "plot_comments" };
|
||||||
"plot_trusted", "plot_ratings", "plot_comments"
|
|
||||||
};
|
|
||||||
|
|
||||||
public Database() {
|
public Database() {
|
||||||
super(Command.DATABASE, "Convert/Backup Storage", "database [type] [...details]", CommandCategory.DEBUG, false);
|
super(Command.DATABASE, "Convert/Backup Storage", "database [type] [...details]", CommandCategory.DEBUG, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean sendMessageU(UUID uuid, String msg) {
|
private static boolean sendMessageU(final UUID uuid, final String msg) {
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
PlotMain.sendConsoleSenderMessage(msg);
|
PlotMain.sendConsoleSenderMessage(msg);
|
||||||
} else {
|
}
|
||||||
Player p = UUIDHandler.uuidWrapper.getPlayer(uuid);
|
else {
|
||||||
if (p != null && p.isOnline())
|
final Player p = UUIDHandler.uuidWrapper.getPlayer(uuid);
|
||||||
|
if ((p != null) && p.isOnline()) {
|
||||||
return PlayerFunctions.sendMessage(p, msg);
|
return PlayerFunctions.sendMessage(p, msg);
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
return sendMessageU(null, msg);
|
return sendMessageU(null, msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void insertPlots(final SQLManager manager, final UUID requester, final Connection c) {
|
public static void insertPlots(final SQLManager manager, final UUID requester, final Connection c) {
|
||||||
Plugin p = PlotMain.getMain();
|
final Plugin p = PlotMain.getMain();
|
||||||
final java.util.Set<Plot> plots = PlotMain.getPlots();
|
final java.util.Set<Plot> plots = PlotMain.getPlots();
|
||||||
p.getServer().getScheduler().runTaskAsynchronously(p, new Runnable() {
|
p.getServer().getScheduler().runTaskAsynchronously(p, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
ArrayList<Plot> ps = new ArrayList<>();
|
final ArrayList<Plot> ps = new ArrayList<>();
|
||||||
for (Plot p : plots)
|
for (final Plot p : plots) {
|
||||||
ps.add(p);
|
ps.add(p);
|
||||||
|
}
|
||||||
manager.createPlots(ps);
|
manager.createPlots(ps);
|
||||||
manager.createAllSettingsAndHelpers(ps);
|
manager.createAllSettingsAndHelpers(ps);
|
||||||
sendMessageU(requester, "&6Database conversion finished");
|
sendMessageU(requester, "&6Database conversion finished");
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
sendMessageU(requester, "Failed to insert plot objects, see stacktrace for info");
|
sendMessageU(requester, "Failed to insert plot objects, see stacktrace for info");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
c.close();
|
c.close();
|
||||||
} catch (SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,67 +77,56 @@ public class Database extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(Player plr, String... args) {
|
public boolean execute(final Player plr, final String... args) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
return sendMessage(plr, "/plot database [sqlite/mysql]");
|
return sendMessage(plr, "/plot database [sqlite/mysql]");
|
||||||
}
|
}
|
||||||
String type = new StringComparison(args[0], new String[]{"mysql", "sqlite"}).getBestMatch().toLowerCase();
|
final String type = new StringComparison(args[0], new String[] { "mysql", "sqlite" }).getBestMatch().toLowerCase();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "mysql":
|
case "mysql":
|
||||||
if (args.length < 6) {
|
if (args.length < 6) {
|
||||||
return sendMessage(plr, "/plot database mysql [host] [port] [username] [password] [database] {prefix}");
|
return sendMessage(plr, "/plot database mysql [host] [port] [username] [password] [database] {prefix}");
|
||||||
}
|
}
|
||||||
String host =
|
final String host = args[1];
|
||||||
args[1];
|
final String port = args[2];
|
||||||
String port =
|
final String username = args[3];
|
||||||
args[2];
|
final String password = args[4];
|
||||||
String username =
|
final String database = args[5];
|
||||||
args[3];
|
String prefix = "";
|
||||||
String password =
|
|
||||||
args[4];
|
|
||||||
String database =
|
|
||||||
args[5];
|
|
||||||
String prefix =
|
|
||||||
"";
|
|
||||||
if (args.length > 6) {
|
if (args.length > 6) {
|
||||||
prefix = args[6];
|
prefix = args[6];
|
||||||
}
|
}
|
||||||
Connection n;
|
Connection n;
|
||||||
try {
|
try {
|
||||||
n = new MySQL(
|
n = new MySQL(PlotMain.getMain(), host, port, database, username, password).openConnection();
|
||||||
PlotMain.getMain(),
|
|
||||||
host,
|
|
||||||
port,
|
|
||||||
database,
|
|
||||||
username,
|
|
||||||
password
|
|
||||||
).openConnection();
|
|
||||||
// Connection
|
// Connection
|
||||||
if (n.isClosed()) {
|
if (n.isClosed()) {
|
||||||
return sendMessage(plr, "Failed to open connection");
|
return sendMessage(plr, "Failed to open connection");
|
||||||
}
|
}
|
||||||
} catch (SQLException | ClassNotFoundException e) {
|
}
|
||||||
|
catch (SQLException | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return sendMessage(plr, "Failed to open connection, read stacktrace for info");
|
return sendMessage(plr, "Failed to open connection, read stacktrace for info");
|
||||||
}
|
}
|
||||||
SQLManager manager = new SQLManager(n, prefix);
|
final SQLManager manager = new SQLManager(n, prefix);
|
||||||
try {
|
try {
|
||||||
final DatabaseMetaData meta = n.getMetaData();
|
final DatabaseMetaData meta = n.getMetaData();
|
||||||
ResultSet set = meta.getTables(null, null, prefix + "plot", null);
|
ResultSet set = meta.getTables(null, null, prefix + "plot", null);
|
||||||
if (!set.next()) {
|
if (!set.next()) {
|
||||||
manager.createTables("mysql", true);
|
manager.createTables("mysql", true);
|
||||||
} else {
|
}
|
||||||
for (String s : tables) {
|
else {
|
||||||
|
for (final String s : this.tables) {
|
||||||
set = meta.getTables(null, null, prefix + s, null);
|
set = meta.getTables(null, null, prefix + s, null);
|
||||||
if (!set.next()) {
|
if (!set.next()) {
|
||||||
manager.createTables("mysql", false);
|
manager.createTables("mysql", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return sendMessage(plr, "Could not create the required tables and/or load the database") &&
|
return sendMessage(plr, "Could not create the required tables and/or load the database") && sendMessage(plr, "Please see the stacktrace for more information");
|
||||||
sendMessage(plr, "Please see the stacktrace for more information");
|
|
||||||
}
|
}
|
||||||
UUID requester = null;
|
UUID requester = null;
|
||||||
if (plr != null) {
|
if (plr != null) {
|
||||||
@ -154,10 +146,11 @@ public class Database extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean sendMessage(Player player, String msg) {
|
private boolean sendMessage(final Player player, final String msg) {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
PlotMain.sendConsoleSenderMessage(msg);
|
PlotMain.sendConsoleSenderMessage(msg);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(player, msg);
|
PlayerFunctions.sendMessage(player, msg);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -21,15 +21,16 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.util.Lag;
|
import com.intellectualcrafters.plot.util.Lag;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||||
import com.intellectualcrafters.plot.util.RUtils;
|
import com.intellectualcrafters.plot.util.RUtils;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Debug extends SubCommand {
|
public class Debug extends SubCommand {
|
||||||
|
|
||||||
@ -68,8 +69,8 @@ public class Debug extends SubCommand {
|
|||||||
information.append(getSection(section, "PlotWorld"));
|
information.append(getSection(section, "PlotWorld"));
|
||||||
information.append(getLine(line, "Plot Worlds", worlds));
|
information.append(getLine(line, "Plot Worlds", worlds));
|
||||||
information.append(getLine(line, "Owned Plots", PlotMain.getPlots().size()));
|
information.append(getLine(line, "Owned Plots", PlotMain.getPlots().size()));
|
||||||
//information.append(getLine(line, "PlotWorld Size",
|
// information.append(getLine(line, "PlotWorld Size",
|
||||||
//PlotHelper.getWorldFolderSize() + "MB"));
|
// PlotHelper.getWorldFolderSize() + "MB"));
|
||||||
for (final String worldname : PlotMain.getPlotWorlds()) {
|
for (final String worldname : PlotMain.getPlotWorlds()) {
|
||||||
final World world = Bukkit.getWorld(worldname);
|
final World world = Bukkit.getWorld(worldname);
|
||||||
information.append(getLine(line, "World: " + world.getName() + " size", PlotHelper.getWorldFolderSize(world)));
|
information.append(getLine(line, "World: " + world.getName() + " size", PlotHelper.getWorldFolderSize(world)));
|
||||||
|
@ -21,16 +21,9 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import java.util.ArrayList;
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import java.util.UUID;
|
||||||
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.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -39,8 +32,20 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.google.common.collect.BiMap;
|
||||||
import java.util.UUID;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
@ -90,7 +95,8 @@ public class DebugClaimTest extends SubCommand {
|
|||||||
|
|
||||||
min = new PlotId(Integer.parseInt(split1[0]), Integer.parseInt(split1[1]));
|
min = new PlotId(Integer.parseInt(split1[0]), Integer.parseInt(split1[1]));
|
||||||
max = new PlotId(Integer.parseInt(split2[0]), Integer.parseInt(split2[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.");
|
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...");
|
PlayerFunctions.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
|
||||||
@ -148,7 +154,8 @@ public class DebugClaimTest extends SubCommand {
|
|||||||
plot.owner = uuid;
|
plot.owner = uuid;
|
||||||
plot.hasChanged = true;
|
plot.hasChanged = true;
|
||||||
plots.add(plot);
|
plots.add(plot);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
|
PlayerFunctions.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,11 +174,13 @@ public class DebugClaimTest extends SubCommand {
|
|||||||
|
|
||||||
PlayerFunctions.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
|
PlayerFunctions.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(null, "No plots were found for the given search.");
|
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.");
|
PlayerFunctions.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -21,12 +21,13 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
@ -44,12 +45,14 @@ public class DebugLoadTest extends SubCommand {
|
|||||||
final Field fPlots = PlotMain.class.getDeclaredField("plots");
|
final Field fPlots = PlotMain.class.getDeclaredField("plots");
|
||||||
fPlots.setAccessible(true);
|
fPlots.setAccessible(true);
|
||||||
fPlots.set(null, DBFunc.getPlots());
|
fPlots.set(null, DBFunc.getPlots());
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
PlotMain.sendConsoleSenderMessage("&3===FAILED&3===");
|
PlotMain.sendConsoleSenderMessage("&3===FAILED&3===");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
PlotMain.sendConsoleSenderMessage("&3===END OF STACKTRACE===");
|
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.");
|
PlayerFunctions.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -21,13 +21,14 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
@ -45,7 +46,8 @@ public class DebugSaveTest extends SubCommand {
|
|||||||
plots.addAll(PlotMain.getPlots());
|
plots.addAll(PlotMain.getPlots());
|
||||||
DBFunc.createPlots(plots);
|
DBFunc.createPlots(plots);
|
||||||
DBFunc.createAllSettingsAndHelpers(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.");
|
PlayerFunctions.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -21,14 +21,16 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Delete extends SubCommand {
|
public class Delete extends SubCommand {
|
||||||
|
|
||||||
@ -50,7 +52,7 @@ public class Delete extends SubCommand {
|
|||||||
}
|
}
|
||||||
assert plot != null;
|
assert plot != null;
|
||||||
final PlotWorld pWorld = PlotMain.getWorldSettings(plot.getWorld());
|
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 && (plot != null) && plot.hasOwner() && plot.getOwner().equals(plr.getUniqueId())) {
|
||||||
final double c = pWorld.SELL_PRICE;
|
final double c = pWorld.SELL_PRICE;
|
||||||
if (c > 0d) {
|
if (c > 0d) {
|
||||||
final Economy economy = PlotMain.economy;
|
final Economy economy = PlotMain.economy;
|
||||||
@ -65,7 +67,8 @@ 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))) {
|
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;
|
Auto.lastPlot = plot.id;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, "Plot deletion has been denied.");
|
PlayerFunctions.sendMessage(plr, "Plot deletion has been denied.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -21,6 +21,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
@ -29,13 +35,6 @@ import com.intellectualcrafters.plot.object.Plot;
|
|||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class Denied extends SubCommand {
|
public class Denied extends SubCommand {
|
||||||
|
|
||||||
@ -63,7 +62,8 @@ public class Denied extends SubCommand {
|
|||||||
if (args[1].equalsIgnoreCase("*")) {
|
if (args[1].equalsIgnoreCase("*")) {
|
||||||
uuid = DBFunc.everyone;
|
uuid = DBFunc.everyone;
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
uuid = UUIDHandler.getUUID(args[1]);
|
uuid = UUIDHandler.getUUID(args[1]);
|
||||||
}
|
}
|
||||||
if (!plot.denied.contains(uuid)) {
|
if (!plot.denied.contains(uuid)) {
|
||||||
@ -88,11 +88,12 @@ public class Denied extends SubCommand {
|
|||||||
DBFunc.setDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
DBFunc.setDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
||||||
final PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, true);
|
final PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, true);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
|
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Player player = UUIDHandler.uuidWrapper.getPlayer(uuid);
|
final Player player = UUIDHandler.uuidWrapper.getPlayer(uuid);
|
||||||
if (!uuid.equals(DBFunc.everyone) && (player != null) && player.isOnline()) {
|
if (!uuid.equals(DBFunc.everyone) && (player != null) && player.isOnline()) {
|
||||||
final Plot pl = PlayerFunctions.getCurrentPlot(player);
|
final Plot pl = PlayerFunctions.getCurrentPlot(player);
|
||||||
if ((pl != null) && pl.id.equals(plot.id)) {
|
if ((pl != null) && pl.id.equals(plot.id)) {
|
||||||
@ -102,7 +103,8 @@ public class Denied extends SubCommand {
|
|||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.DENIED_ADDED);
|
PlayerFunctions.sendMessage(plr, C.DENIED_ADDED);
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
}
|
||||||
|
else if (args[0].equalsIgnoreCase("remove")) {
|
||||||
if (args[1].equalsIgnoreCase("*")) {
|
if (args[1].equalsIgnoreCase("*")) {
|
||||||
final UUID uuid = DBFunc.everyone;
|
final UUID uuid = DBFunc.everyone;
|
||||||
if (!plot.denied.contains(uuid)) {
|
if (!plot.denied.contains(uuid)) {
|
||||||
@ -132,7 +134,8 @@ public class Denied extends SubCommand {
|
|||||||
final PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, false);
|
final PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, false);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
PlayerFunctions.sendMessage(plr, C.DENIED_REMOVED);
|
PlayerFunctions.sendMessage(plr, C.DENIED_REMOVED);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.DENIED_NEED_ARGUMENT);
|
PlayerFunctions.sendMessage(plr, C.DENIED_NEED_ARGUMENT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ package com.intellectualcrafters.plot.commands;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
public class Help extends SubCommand {
|
public class Help extends SubCommand {
|
||||||
public Help() {
|
public Help() {
|
||||||
super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO, false);
|
super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO, false);
|
||||||
|
@ -21,6 +21,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
@ -29,12 +35,6 @@ import com.intellectualcrafters.plot.object.Plot;
|
|||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class Helpers extends SubCommand {
|
public class Helpers extends SubCommand {
|
||||||
|
|
||||||
@ -61,7 +61,8 @@ public class Helpers extends SubCommand {
|
|||||||
UUID uuid;
|
UUID uuid;
|
||||||
if (args[1].equalsIgnoreCase("*")) {
|
if (args[1].equalsIgnoreCase("*")) {
|
||||||
uuid = DBFunc.everyone;
|
uuid = DBFunc.everyone;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
uuid = UUIDHandler.getUUID(args[1]);
|
uuid = UUIDHandler.getUUID(args[1]);
|
||||||
}
|
}
|
||||||
if (!plot.helpers.contains(uuid)) {
|
if (!plot.helpers.contains(uuid)) {
|
||||||
@ -86,13 +87,15 @@ public class Helpers extends SubCommand {
|
|||||||
DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
||||||
final PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, true);
|
final PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, true);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
|
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.HELPER_ADDED);
|
PlayerFunctions.sendMessage(plr, C.HELPER_ADDED);
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
}
|
||||||
|
else if (args[0].equalsIgnoreCase("remove")) {
|
||||||
if (args[1].equalsIgnoreCase("*")) {
|
if (args[1].equalsIgnoreCase("*")) {
|
||||||
final UUID uuid = DBFunc.everyone;
|
final UUID uuid = DBFunc.everyone;
|
||||||
if (!plot.helpers.contains(uuid)) {
|
if (!plot.helpers.contains(uuid)) {
|
||||||
@ -123,7 +126,8 @@ public class Helpers extends SubCommand {
|
|||||||
final PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, false);
|
final PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, false);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
PlayerFunctions.sendMessage(plr, C.HELPER_REMOVED);
|
PlayerFunctions.sendMessage(plr, C.HELPER_REMOVED);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
|
PlayerFunctions.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
@ -51,14 +52,16 @@ public class Home extends SubCommand {
|
|||||||
if (plots.length == 1) {
|
if (plots.length == 1) {
|
||||||
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[0]);
|
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[0]);
|
||||||
return true;
|
return true;
|
||||||
} else if (plots.length > 1) {
|
}
|
||||||
|
else if (plots.length > 1) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
args = new String[]{"1"};
|
args = new String[] { "1" };
|
||||||
}
|
}
|
||||||
int id = 0;
|
int id = 0;
|
||||||
try {
|
try {
|
||||||
id = Integer.parseInt(args[0]);
|
id = Integer.parseInt(args[0]);
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
Plot temp;
|
Plot temp;
|
||||||
if ((temp = isAlias(args[0])) != null) {
|
if ((temp = isAlias(args[0])) != null) {
|
||||||
if (temp.hasOwner()) {
|
if (temp.hasOwner()) {
|
||||||
@ -79,7 +82,8 @@ public class Home extends SubCommand {
|
|||||||
}
|
}
|
||||||
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[id - 1]);
|
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[id - 1]);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PLOTS);
|
PlayerFunctions.sendMessage(plr, C.NO_PLOTS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -21,19 +21,20 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotComment;
|
import com.intellectualcrafters.plot.object.PlotComment;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
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 {
|
public class Inbox extends SubCommand {
|
||||||
|
|
||||||
@ -57,13 +58,17 @@ public class Inbox extends SubCommand {
|
|||||||
final UUID uuid = plr.getUniqueId();
|
final UUID uuid = plr.getUniqueId();
|
||||||
if (PlotMain.hasPermission(plr, "plots.admin")) {
|
if (PlotMain.hasPermission(plr, "plots.admin")) {
|
||||||
tier = 0;
|
tier = 0;
|
||||||
} else if (plot.owner == uuid) {
|
}
|
||||||
|
else if (plot.owner == uuid) {
|
||||||
tier = 1;
|
tier = 1;
|
||||||
} else if (plot.helpers.contains(uuid)) {
|
}
|
||||||
|
else if (plot.helpers.contains(uuid)) {
|
||||||
tier = 2;
|
tier = 2;
|
||||||
} else if (plot.trusted.contains(uuid)) {
|
}
|
||||||
|
else if (plot.trusted.contains(uuid)) {
|
||||||
tier = 3;
|
tier = 3;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
tier = 4;
|
tier = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +77,8 @@ public class Inbox extends SubCommand {
|
|||||||
case "admin":
|
case "admin":
|
||||||
if (tier <= 0) {
|
if (tier <= 0) {
|
||||||
tier = 0;
|
tier = 0;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -80,7 +86,8 @@ public class Inbox extends SubCommand {
|
|||||||
case "owner":
|
case "owner":
|
||||||
if (tier <= 1) {
|
if (tier <= 1) {
|
||||||
tier = 1;
|
tier = 1;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -88,7 +95,8 @@ public class Inbox extends SubCommand {
|
|||||||
case "helper":
|
case "helper":
|
||||||
if (tier <= 2) {
|
if (tier <= 2) {
|
||||||
tier = 2;
|
tier = 2;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -96,7 +104,8 @@ public class Inbox extends SubCommand {
|
|||||||
case "trusted":
|
case "trusted":
|
||||||
if (tier <= 3) {
|
if (tier <= 3) {
|
||||||
tier = 3;
|
tier = 3;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -104,13 +113,14 @@ public class Inbox extends SubCommand {
|
|||||||
case "everyone":
|
case "everyone":
|
||||||
if (tier <= 4) {
|
if (tier <= 4) {
|
||||||
tier = 4;
|
tier = 4;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "default":
|
case "default":
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_INBOX, Arrays.copyOfRange(new String[]{"admin", "owner", "helper", "trusted", "everyone"}, tier, 4));
|
PlayerFunctions.sendMessage(plr, C.INVALID_INBOX, Arrays.copyOfRange(new String[] { "admin", "owner", "helper", "trusted", "everyone" }, tier, 4));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,7 +151,8 @@ public class Inbox extends SubCommand {
|
|||||||
plot.settings.removeComment(comment);
|
plot.settings.removeComment(comment);
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMENT_REMOVED, "1 comment");
|
PlayerFunctions.sendMessage(plr, C.COMMENT_REMOVED, "1 comment");
|
||||||
return;
|
return;
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
PlayerFunctions.sendMessage(plr, "&cInvalid index:\n/plot inbox [tier] [clear][:#]");
|
PlayerFunctions.sendMessage(plr, "&cInvalid index:\n/plot inbox [tier] [clear][:#]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -151,7 +162,8 @@ public class Inbox extends SubCommand {
|
|||||||
}
|
}
|
||||||
plot.settings.removeComments(comments);
|
plot.settings.removeComments(comments);
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMENT_REMOVED, "all comments in that category");
|
PlayerFunctions.sendMessage(plr, C.COMMENT_REMOVED, "all comments in that category");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
final List<String> recipients = Arrays.asList("A", "O", "H", "T", "E");
|
final List<String> recipients = Arrays.asList("A", "O", "H", "T", "E");
|
||||||
int count = 1;
|
int count = 1;
|
||||||
final StringBuilder message = new StringBuilder();
|
final StringBuilder message = new StringBuilder();
|
||||||
|
@ -21,6 +21,16 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
@ -31,20 +41,11 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
|||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
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
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unused", "deprecated", "javadoc"})
|
@SuppressWarnings({ "unused", "deprecated", "javadoc" })
|
||||||
public class Info extends SubCommand {
|
public class Info extends SubCommand {
|
||||||
|
|
||||||
public Info() {
|
public Info() {
|
||||||
@ -62,7 +63,8 @@ public class Info extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
plot = PlayerFunctions.getCurrentPlot(player);
|
plot = PlayerFunctions.getCurrentPlot(player);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
PlayerFunctions.sendMessage(null, C.INFO_SYNTAX_CONSOLE);
|
PlayerFunctions.sendMessage(null, C.INFO_SYNTAX_CONSOLE);
|
||||||
return false;
|
return false;
|
||||||
@ -82,17 +84,19 @@ public class Info extends SubCommand {
|
|||||||
}
|
}
|
||||||
world = Bukkit.getWorld(args[0]);
|
world = Bukkit.getWorld(args[0]);
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
args = new String[]{args[2]};
|
args = new String[] { args[2] };
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
args = new String[0];
|
args = new String[0];
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
PlayerFunctions.sendMessage(player, C.INFO_SYNTAX_CONSOLE);
|
PlayerFunctions.sendMessage(player, C.INFO_SYNTAX_CONSOLE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 1 && args[0].equalsIgnoreCase("inv")) {
|
if ((args.length == 1) && args[0].equalsIgnoreCase("inv")) {
|
||||||
new InfoInventory(plot, player).build().display();
|
new InfoInventory(plot, player).build().display();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -103,8 +107,8 @@ public class Info extends SubCommand {
|
|||||||
|
|
||||||
// Wildcard player {added}
|
// Wildcard player {added}
|
||||||
{
|
{
|
||||||
containsEveryone = plot.helpers != null && plot.helpers.contains(DBFunc.everyone);
|
containsEveryone = (plot.helpers != null) && plot.helpers.contains(DBFunc.everyone);
|
||||||
trustedEveryone = plot.trusted != null && plot.trusted.contains(DBFunc.everyone);
|
trustedEveryone = (plot.trusted != null) && plot.trusted.contains(DBFunc.everyone);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unclaimed?
|
// Unclaimed?
|
||||||
@ -175,7 +179,7 @@ public class Info extends SubCommand {
|
|||||||
final String denied = getPlayerList(plot.denied);
|
final String denied = getPlayerList(plot.denied);
|
||||||
final String rating = String.format("%.1f", DBFunc.getRatings(plot));
|
final String rating = String.format("%.1f", DBFunc.getRatings(plot));
|
||||||
final String flags = "&6" + (StringUtils.join(plot.settings.getFlags(), "").length() > 0 ? StringUtils.join(plot.settings.getFlags(), "&7, &6") : "none");
|
final String flags = "&6" + (StringUtils.join(plot.settings.getFlags(), "").length() > 0 ? StringUtils.join(plot.settings.getFlags(), "&7, &6") : "none");
|
||||||
final boolean build = player == null || plot.hasRights(player);
|
final boolean build = (player == null) || plot.hasRights(player);
|
||||||
|
|
||||||
String owner = "none";
|
String owner = "none";
|
||||||
if (plot.owner != null) {
|
if (plot.owner != null) {
|
||||||
@ -211,7 +215,8 @@ public class Info extends SubCommand {
|
|||||||
for (int x = 0; x < l.size(); x++) {
|
for (int x = 0; x < l.size(); x++) {
|
||||||
if ((x + 1) == l.size()) {
|
if ((x + 1) == l.size()) {
|
||||||
list.append(c.replace("%user%", getPlayerName(l.get(x))).replace(",", ""));
|
list.append(c.replace("%user%", getPlayerName(l.get(x))).replace(",", ""));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
list.append(c.replace("%user%", getPlayerName(l.get(x))));
|
list.append(c.replace("%user%", getPlayerName(l.get(x))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -28,8 +30,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class Inventory extends SubCommand {
|
public class Inventory extends SubCommand {
|
||||||
|
|
||||||
public Inventory() {
|
public Inventory() {
|
||||||
|
@ -21,14 +21,15 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "deprecation", "javadoc"})
|
@SuppressWarnings({ "unused", "deprecation", "javadoc" })
|
||||||
public class Kick extends SubCommand {
|
public class Kick extends SubCommand {
|
||||||
|
|
||||||
public Kick() {
|
public Kick() {
|
||||||
|
@ -21,10 +21,10 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import java.util.ArrayList;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import java.util.Arrays;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import java.util.List;
|
||||||
import com.intellectualcrafters.plot.util.StringComparison;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
@ -32,9 +32,10 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import java.util.Arrays;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import java.util.List;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
|
import com.intellectualcrafters.plot.util.StringComparison;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlotMain command class
|
* PlotMain command class
|
||||||
@ -46,53 +47,11 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Main Permission Node
|
* Main Permission Node
|
||||||
*/
|
*/
|
||||||
public static final String
|
public static final String MAIN_PERMISSION = "plots.use";
|
||||||
MAIN_PERMISSION = "plots.use";
|
|
||||||
|
|
||||||
private final static SubCommand[] _subCommands =
|
private final static SubCommand[] _subCommands = new SubCommand[] { new Ban(), new Unban(), new OP(), new DEOP(), new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Setup(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand() };
|
||||||
new SubCommand[]{
|
|
||||||
new Ban(),
|
|
||||||
new Unban(),
|
|
||||||
new OP(),
|
|
||||||
new DEOP(),
|
|
||||||
new Claim(),
|
|
||||||
new Paste(),
|
|
||||||
new Copy(),
|
|
||||||
new Clipboard(),
|
|
||||||
new Auto(),
|
|
||||||
new Home(),
|
|
||||||
new Visit(),
|
|
||||||
new TP(),
|
|
||||||
new Set(),
|
|
||||||
new Clear(),
|
|
||||||
new Delete(),
|
|
||||||
new SetOwner(),
|
|
||||||
new Denied(),
|
|
||||||
new Helpers(),
|
|
||||||
new Trusted(),
|
|
||||||
new Info(),
|
|
||||||
new list(),
|
|
||||||
new Help(),
|
|
||||||
new Debug(),
|
|
||||||
new Schematic(),
|
|
||||||
new plugin(),
|
|
||||||
new Inventory(),
|
|
||||||
new Purge(),
|
|
||||||
new Reload(),
|
|
||||||
new Merge(),
|
|
||||||
new Unlink(),
|
|
||||||
new Kick(),
|
|
||||||
new Setup(),
|
|
||||||
new Rate(),
|
|
||||||
new DebugClaimTest(),
|
|
||||||
new Inbox(),
|
|
||||||
new Comment(),
|
|
||||||
new Database(),
|
|
||||||
new Unclaim(),
|
|
||||||
new Swap(),
|
|
||||||
new MusicSubcommand()};
|
|
||||||
|
|
||||||
public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
||||||
{
|
{
|
||||||
addAll(Arrays.asList(_subCommands));
|
addAll(Arrays.asList(_subCommands));
|
||||||
}
|
}
|
||||||
@ -116,7 +75,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
public static List<String> helpMenu(final Player player, final SubCommand.CommandCategory category, int page) {
|
public static List<String> helpMenu(final Player player, final SubCommand.CommandCategory category, int page) {
|
||||||
final List<SubCommand> commands = getCommands(category, player);
|
final List<SubCommand> commands = getCommands(category, player);
|
||||||
// final int totalPages = ((int) Math.ceil(12 * (commands.size()) /
|
// final int totalPages = ((int) Math.ceil(12 * (commands.size()) /
|
||||||
// 100));
|
// 100));
|
||||||
final int perPage = 5;
|
final int perPage = 5;
|
||||||
final int totalPages = (int) Math.ceil(commands.size() / perPage);
|
final int totalPages = (int) Math.ceil(commands.size() / perPage);
|
||||||
if (page > totalPages) {
|
if (page > totalPages) {
|
||||||
@ -131,13 +90,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
help.add(C.HELP_HEADER.s());
|
help.add(C.HELP_HEADER.s());
|
||||||
// HELP_CATEGORY("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"),
|
// HELP_CATEGORY("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"),
|
||||||
help.add(C.HELP_CATEGORY.s()
|
help.add(C.HELP_CATEGORY.s().replace("%category%", category.toString()).replace("%current%", "" + (page + 1)).replace("%max%", "" + (totalPages + 1)).replace("%dis%", "" + (commands.size() % perPage)).replace("%total%", "" + commands.size()));
|
||||||
.replace("%category%", category.toString())
|
|
||||||
.replace("%current%", "" + (page + 1))
|
|
||||||
.replace("%max%", "" + (totalPages + 1))
|
|
||||||
.replace("%dis%", "" + (commands.size() % perPage))
|
|
||||||
.replace("%total%", "" + commands.size())
|
|
||||||
);
|
|
||||||
|
|
||||||
SubCommand cmd;
|
SubCommand cmd;
|
||||||
|
|
||||||
@ -145,12 +98,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
for (int x = start; x < max; x++) {
|
for (int x = start; x < max; x++) {
|
||||||
cmd = commands.get(x);
|
cmd = commands.get(x);
|
||||||
String s = t(C.HELP_ITEM.s());
|
String s = t(C.HELP_ITEM.s());
|
||||||
s = s
|
s = s.replace("%alias%", cmd.alias.get(0)).replace("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage).replace("%cmd%", cmd.cmd).replace("%desc%", cmd.description);
|
||||||
.replace("%alias%", cmd.alias.get(0))
|
|
||||||
.replace("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage)
|
|
||||||
.replace("%cmd%", cmd.cmd)
|
|
||||||
.replace("%desc%", cmd.description)
|
|
||||||
;
|
|
||||||
help.add(s);
|
help.add(s);
|
||||||
}
|
}
|
||||||
if (help.size() < 2) {
|
if (help.size() < 2) {
|
||||||
@ -167,8 +115,9 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) {
|
||||||
final Player player = (sender instanceof Player) ? (Player) sender : null;
|
final Player player = (sender instanceof Player) ? (Player) sender : null;
|
||||||
|
|
||||||
if (!PlotMain.hasPermission(player, MAIN_PERMISSION))
|
if (!PlotMain.hasPermission(player, MAIN_PERMISSION)) {
|
||||||
return no_permission(player, MAIN_PERMISSION);
|
return no_permission(player, MAIN_PERMISSION);
|
||||||
|
}
|
||||||
|
|
||||||
if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
|
if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
@ -203,7 +152,8 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
String arg2;
|
String arg2;
|
||||||
if (args.length > 2) {
|
if (args.length > 2) {
|
||||||
arg2 = args[2];
|
arg2 = args[2];
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
arg2 = "1";
|
arg2 = "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,8 +174,9 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
help.append(string).append("\n");
|
help.append(string).append("\n");
|
||||||
}
|
}
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', help.toString()));
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', help.toString()));
|
||||||
//return PlayerFunctions.sendMessage(player, help.toString());
|
// return PlayerFunctions.sendMessage(player, help.toString());
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
for (final SubCommand command : subCommands) {
|
for (final SubCommand command : subCommands) {
|
||||||
if (command.cmd.equalsIgnoreCase(args[0]) || command.alias.contains(args[0].toLowerCase())) {
|
if (command.cmd.equalsIgnoreCase(args[0]) || command.alias.contains(args[0].toLowerCase())) {
|
||||||
final String[] arguments = new String[args.length - 1];
|
final String[] arguments = new String[args.length - 1];
|
||||||
@ -233,10 +184,12 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
if (command.permission.hasPermission(player)) {
|
if (command.permission.hasPermission(player)) {
|
||||||
if ((player != null) || !command.isPlayer) {
|
if ((player != null) || !command.isPlayer) {
|
||||||
return command.execute(player, arguments);
|
return command.execute(player, arguments);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return !PlayerFunctions.sendMessage(null, C.IS_CONSOLE);
|
return !PlayerFunctions.sendMessage(null, C.IS_CONSOLE);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return no_permission(player, command.permission.permission.toLowerCase());
|
return no_permission(player, command.permission.permission.toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -249,9 +202,10 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Let's try to get a proper usage string */
|
/* Let's try to get a proper usage string */
|
||||||
String command = new StringComparison(args[0], commands).getBestMatch();
|
final String command = new StringComparison(args[0], commands).getBestMatch();
|
||||||
return PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, "/plot " + command);
|
return PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, "/plot " + command);
|
||||||
//PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new StringComparsion(args[0], commands).getBestMatch());
|
// PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new
|
||||||
|
// StringComparsion(args[0], commands).getBestMatch());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -280,7 +234,8 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
if (cmd.permission.hasPermission(player)) {
|
if (cmd.permission.hasPermission(player)) {
|
||||||
if (cmd.cmd.startsWith(arg)) {
|
if (cmd.cmd.startsWith(arg)) {
|
||||||
tabOptions.add(cmd.cmd);
|
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));
|
tabOptions.add(cmd.alias.get(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,15 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.events.PlotMergeEvent;
|
import com.intellectualcrafters.plot.events.PlotMergeEvent;
|
||||||
@ -30,21 +39,14 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
|||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||||
import com.intellectualcrafters.plot.util.SetBlockFast;
|
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
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class Merge extends SubCommand {
|
public class Merge extends SubCommand {
|
||||||
|
|
||||||
public final static String[] values = new String[]{"north", "east", "south", "west"};
|
public final static String[] values = new String[] { "north", "east", "south", "west" };
|
||||||
public final static String[] aliases = new String[]{"n", "e", "s", "w"};
|
public final static String[] aliases = new String[] { "n", "e", "s", "w" };
|
||||||
|
|
||||||
public Merge() {
|
public Merge() {
|
||||||
super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS, true);
|
super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS, true);
|
||||||
|
@ -21,17 +21,18 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import java.util.Arrays;
|
||||||
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.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
public class MusicSubcommand extends SubCommand {
|
public class MusicSubcommand extends SubCommand {
|
||||||
public MusicSubcommand() {
|
public MusicSubcommand() {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2014-11-09 for PlotSquared
|
* Created 2014-11-09 for PlotSquared
|
||||||
@ -17,14 +18,14 @@ public class OP extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(Player plr, String... args) {
|
public boolean execute(final Player plr, final String... args) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + usage);
|
return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + this.usage);
|
||||||
}
|
}
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
if (!PlayerFunctions.isInPlot(plr)) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
||||||
if (!plot.hasRights(plr)) {
|
if (!plot.hasRights(plr)) {
|
||||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,14 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotSelection;
|
import com.intellectualcrafters.plot.object.PlotSelection;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Paste extends SubCommand {
|
public class Paste extends SubCommand {
|
||||||
|
|
||||||
@ -61,7 +62,8 @@ public class Paste extends SubCommand {
|
|||||||
}
|
}
|
||||||
selection.paste(plr.getWorld(), plot);
|
selection.paste(plr.getWorld(), plot);
|
||||||
sendMessage(plr, C.PASTED);
|
sendMessage(plr, C.PASTED);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sendMessage(plr, C.NO_CLIPBOARD);
|
sendMessage(plr, C.NO_CLIPBOARD);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,15 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "deprecated", "javadoc"})
|
@SuppressWarnings({ "unused", "deprecated", "javadoc" })
|
||||||
public class Purge extends SubCommand {
|
public class Purge extends SubCommand {
|
||||||
|
|
||||||
public Purge() {
|
public Purge() {
|
||||||
@ -59,7 +60,8 @@ public class Purge extends SubCommand {
|
|||||||
DBFunc.purge(world, id);
|
DBFunc.purge(world, id);
|
||||||
PlayerFunctions.sendMessage(null, "&aPurge of '" + args[0] + "' was successful!");
|
PlayerFunctions.sendMessage(null, "&aPurge of '" + args[0] + "' was successful!");
|
||||||
return true;
|
return true;
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,7 +77,8 @@ public class Purge extends SubCommand {
|
|||||||
DBFunc.purge(args[0]);
|
DBFunc.purge(args[0]);
|
||||||
PlayerFunctions.sendMessage(plr, (C.PURGE_SUCCESS));
|
PlayerFunctions.sendMessage(plr, (C.PURGE_SUCCESS));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, "This is a dangerous command, if you are sure, use /plot purge {world} -o");
|
PlayerFunctions.sendMessage(plr, "This is a dangerous command, if you are sure, use /plot purge {world} -o");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,14 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "deprecated", "javadoc"})
|
@SuppressWarnings({ "unused", "deprecated", "javadoc" })
|
||||||
public class Rate extends SubCommand {
|
public class Rate extends SubCommand {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -78,17 +79,19 @@ public class Rate extends SubCommand {
|
|||||||
boolean rated = true;
|
boolean rated = true;
|
||||||
try {
|
try {
|
||||||
DBFunc.getRatings(plot);
|
DBFunc.getRatings(plot);
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
rated = false;
|
rated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rated) {
|
if (rated) {
|
||||||
sendMessage(plr, C.RATING_ALREADY_EXISTS, plot.getId().toString());
|
sendMessage(plr, C.RATING_ALREADY_EXISTS, plot.getId().toString());
|
||||||
}
|
}
|
||||||
boolean success = true;
|
final boolean success = true;
|
||||||
if (success) {
|
if (success) {
|
||||||
sendMessage(plr, C.RATING_APPLIED, plot.getId().toString());
|
sendMessage(plr, C.RATING_APPLIED, plot.getId().toString());
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sendMessage(plr, C.COMMAND_WENT_WRONG);
|
sendMessage(plr, C.COMMAND_WENT_WRONG);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -21,11 +21,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Reload extends SubCommand {
|
public class Reload extends SubCommand {
|
||||||
|
|
||||||
@ -46,7 +47,8 @@ public class Reload extends SubCommand {
|
|||||||
plotworld.loadDefaultConfiguration(PlotMain.config.getConfigurationSection("worlds." + pw));
|
plotworld.loadDefaultConfiguration(PlotMain.config.getConfigurationSection("worlds." + pw));
|
||||||
}
|
}
|
||||||
PlotMain.BroadcastWithPerms(C.RELOADED_CONFIGS);
|
PlotMain.BroadcastWithPerms(C.RELOADED_CONFIGS);
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
PlayerFunctions.sendMessage(plr, C.RELOAD_FAILED);
|
PlayerFunctions.sendMessage(plr, C.RELOAD_FAILED);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -21,30 +21,35 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
import java.util.Collection;
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import java.util.HashMap;
|
||||||
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.*;
|
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection;
|
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.Collection;
|
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||||
import java.util.HashMap;
|
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.SchematicHandler.DataCollection;
|
||||||
|
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
|
||||||
|
import com.intellectualcrafters.plot.util.SetBlockFast;
|
||||||
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
|
||||||
public class Schematic extends SubCommand {
|
public class Schematic extends SubCommand {
|
||||||
|
|
||||||
private int counter = 0;
|
private int counter = 0;
|
||||||
private boolean running = false;
|
private boolean running = false;
|
||||||
private Plot[] plots;
|
private Plot[] plots;
|
||||||
private int task;
|
private int task;
|
||||||
|
|
||||||
public Schematic() {
|
public Schematic() {
|
||||||
super("schematic", "plots.schematic", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false);
|
super("schematic", "plots.schematic", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false);
|
||||||
@ -114,7 +119,8 @@ public class Schematic extends SubCommand {
|
|||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
x = Math.min(length2 - dem.getX(), loc.getBlockX() - bot.getBlockX());
|
x = Math.min(length2 - dem.getX(), loc.getBlockX() - bot.getBlockX());
|
||||||
z = Math.min(length2 - dem.getZ(), loc.getBlockZ() - bot.getBlockZ());
|
z = Math.min(length2 - dem.getZ(), loc.getBlockZ() - bot.getBlockZ());
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
x = 0;
|
x = 0;
|
||||||
z = 0;
|
z = 0;
|
||||||
}
|
}
|
||||||
@ -211,7 +217,7 @@ public class Schematic extends SubCommand {
|
|||||||
|
|
||||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared");
|
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared");
|
||||||
|
|
||||||
Collection<Plot> values = plotmap.values();
|
final Collection<Plot> values = plotmap.values();
|
||||||
this.plots = values.toArray(new Plot[values.size()]);
|
this.plots = values.toArray(new Plot[values.size()]);
|
||||||
this.running = true;
|
this.running = true;
|
||||||
this.counter = 0;
|
this.counter = 0;
|
||||||
@ -231,7 +237,8 @@ public class Schematic extends SubCommand {
|
|||||||
final String owner = o == null ? "unknown" : o;
|
final String owner = o == null ? "unknown" : o;
|
||||||
if (sch == null) {
|
if (sch == null) {
|
||||||
PlayerFunctions.sendMessage(null, "&7 - Skipped plot &c" + plot.id);
|
PlayerFunctions.sendMessage(null, "&7 - Skipped plot &c" + plot.id);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -239,7 +246,8 @@ public class Schematic extends SubCommand {
|
|||||||
final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + worldname + "," + owner + ".schematic");
|
final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + worldname + "," + owner + ".schematic");
|
||||||
if (!result) {
|
if (!result) {
|
||||||
PlayerFunctions.sendMessage(null, "&7 - Failed to save &c" + plot.id);
|
PlayerFunctions.sendMessage(null, "&7 - Failed to save &c" + plot.id);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(null, "&7 - &aExport success: " + plot.id);
|
PlayerFunctions.sendMessage(null, "&7 - &aExport success: " + plot.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,7 +281,8 @@ public class Schematic extends SubCommand {
|
|||||||
}
|
}
|
||||||
p2 = myplot;
|
p2 = myplot;
|
||||||
world = plr.getWorld().getName();
|
world = plr.getWorld().getName();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
try {
|
try {
|
||||||
world = args[0];
|
world = args[0];
|
||||||
@ -284,11 +293,13 @@ public class Schematic extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
p2 = PlotMain.getPlots(world).get(i);
|
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>");
|
PlayerFunctions.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
PlayerFunctions.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -296,7 +307,7 @@ public class Schematic extends SubCommand {
|
|||||||
|
|
||||||
final Plugin plugin2 = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared");
|
final Plugin plugin2 = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared");
|
||||||
|
|
||||||
this.plots = new Plot[]{p2};
|
this.plots = new Plot[] { p2 };
|
||||||
this.running = true;
|
this.running = true;
|
||||||
this.counter = 0;
|
this.counter = 0;
|
||||||
|
|
||||||
@ -315,7 +326,8 @@ public class Schematic extends SubCommand {
|
|||||||
final String owner = o == null ? "unknown" : o;
|
final String owner = o == null ? "unknown" : o;
|
||||||
if (sch == null) {
|
if (sch == null) {
|
||||||
PlayerFunctions.sendMessage(plr, "&7 - Skipped plot &c" + plot.id);
|
PlayerFunctions.sendMessage(plr, "&7 - Skipped plot &c" + plot.id);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -323,7 +335,8 @@ 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");
|
final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + world + "," + owner.trim() + ".schematic");
|
||||||
if (!result) {
|
if (!result) {
|
||||||
PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c" + plot.id);
|
PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c" + plot.id);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, "&7 - &aExport success: " + plot.id);
|
PlayerFunctions.sendMessage(plr, "&7 - &aExport success: " + plot.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,17 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
@ -37,24 +48,14 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
|||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||||
import com.intellectualcrafters.plot.util.StringComparison;
|
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
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class Set extends SubCommand {
|
public class Set extends SubCommand {
|
||||||
|
|
||||||
public final static String[] values = new String[]{"biome", "wall", "wall_filling", "floor", "alias", "home", "flag"};
|
public final static String[] values = new String[] { "biome", "wall", "wall_filling", "floor", "alias", "home", "flag" };
|
||||||
public final static String[] aliases = new String[]{"b", "w", "wf", "f", "a", "h", "fl"};
|
public final static String[] aliases = new String[] { "b", "w", "wf", "f", "a", "h", "fl" };
|
||||||
|
|
||||||
public Set() {
|
public Set() {
|
||||||
super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS, true);
|
super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS, true);
|
||||||
@ -99,7 +100,8 @@ public class Set extends SubCommand {
|
|||||||
if (PlotMain.worldGuardListener != null) {
|
if (PlotMain.worldGuardListener != null) {
|
||||||
if (message.equals("")) {
|
if (message.equals("")) {
|
||||||
message = StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6");
|
message = StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
message += "," + StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6");
|
message += "," + StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +113,8 @@ public class Set extends SubCommand {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
af = FlagManager.getFlag(args[1].toLowerCase());
|
af = FlagManager.getFlag(args[1].toLowerCase());
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
af = new AbstractFlag(args[1].toLowerCase());
|
af = new AbstractFlag(args[1].toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,12 +178,13 @@ public class Set extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
plot.settings.addFlag(flag);
|
plot.settings.addFlag(flag);
|
||||||
java.util.Set<Flag> flags = plot.settings.getFlags();
|
final java.util.Set<Flag> flags = plot.settings.getFlags();
|
||||||
DBFunc.setFlags(plr.getWorld().getName(), plot, flags.toArray(new Flag[flags.size()]));
|
DBFunc.setFlags(plr.getWorld().getName(), plot, flags.toArray(new Flag[flags.size()]));
|
||||||
PlayerFunctions.sendMessage(plr, C.FLAG_ADDED);
|
PlayerFunctions.sendMessage(plr, C.FLAG_ADDED);
|
||||||
PlotListener.plotEntry(plr, plot);
|
PlotListener.plotEntry(plr, plot);
|
||||||
return true;
|
return true;
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
PlayerFunctions.sendMessage(plr, "&c" + e.getMessage());
|
PlayerFunctions.sendMessage(plr, "&c" + e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -271,7 +275,8 @@ public class Set extends SubCommand {
|
|||||||
Material material;
|
Material material;
|
||||||
try {
|
try {
|
||||||
material = getMaterial(args[1], PlotWorld.BLOCKS);
|
material = getMaterial(args[1], PlotWorld.BLOCKS);
|
||||||
} catch (NullPointerException e) {
|
}
|
||||||
|
catch (final NullPointerException e) {
|
||||||
material = null;
|
material = null;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -291,7 +296,8 @@ public class Set extends SubCommand {
|
|||||||
if (args.length > 2) {
|
if (args.length > 2) {
|
||||||
try {
|
try {
|
||||||
data = (byte) Integer.parseInt(args[2]);
|
data = (byte) Integer.parseInt(args[2]);
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
|
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -346,11 +352,13 @@ public class Set extends SubCommand {
|
|||||||
if (ss.length == 1) {
|
if (ss.length == 1) {
|
||||||
|
|
||||||
blocks[index] = new PlotBlock((short) m.getId(), (byte) 0);
|
blocks[index] = new PlotBlock((short) m.getId(), (byte) 0);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
byte b;
|
byte b;
|
||||||
try {
|
try {
|
||||||
b = (byte) Integer.parseInt(ss[1]);
|
b = (byte) Integer.parseInt(ss[1]);
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
|
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -394,7 +402,8 @@ public class Set extends SubCommand {
|
|||||||
if (args.length > 2) {
|
if (args.length > 2) {
|
||||||
try {
|
try {
|
||||||
data = (byte) Integer.parseInt(args[2]);
|
data = (byte) Integer.parseInt(args[2]);
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
|
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -406,7 +415,8 @@ public class Set extends SubCommand {
|
|||||||
AbstractFlag af;
|
AbstractFlag af;
|
||||||
try {
|
try {
|
||||||
af = new AbstractFlag(args[0].toLowerCase());
|
af = new AbstractFlag(args[0].toLowerCase());
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
af = new AbstractFlag("");
|
af = new AbstractFlag("");
|
||||||
}
|
}
|
||||||
if (FlagManager.getFlags().contains(af)) {
|
if (FlagManager.getFlags().contains(af)) {
|
||||||
|
@ -21,6 +21,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
@ -30,12 +36,6 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class SetOwner extends SubCommand {
|
public class SetOwner extends SubCommand {
|
||||||
|
|
||||||
@ -65,14 +65,14 @@ public class SetOwner extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
World world = plr.getWorld();
|
final World world = plr.getWorld();
|
||||||
PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id;
|
final PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id;
|
||||||
PlotId top = PlayerFunctions.getTopPlot(world, plot).id;
|
final PlotId top = PlayerFunctions.getTopPlot(world, plot).id;
|
||||||
|
|
||||||
ArrayList<PlotId> plots = PlayerFunctions.getPlotSelectionIds(world, bot, top);
|
final ArrayList<PlotId> plots = PlayerFunctions.getPlotSelectionIds(world, bot, top);
|
||||||
|
|
||||||
for (PlotId id : plots) {
|
for (final PlotId id : plots) {
|
||||||
Plot current = PlotMain.getPlots(world).get(id);
|
final Plot current = PlotMain.getPlots(world).get(id);
|
||||||
current.owner = getUUID(args[0]);
|
current.owner = getUUID(args[0]);
|
||||||
PlotMain.updatePlot(current);
|
PlotMain.updatePlot(current);
|
||||||
DBFunc.setOwner(current, current.owner);
|
DBFunc.setOwner(current, current.owner);
|
||||||
|
@ -21,13 +21,11 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import java.io.IOException;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import java.util.ArrayList;
|
||||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
import java.util.HashMap;
|
||||||
import com.intellectualcrafters.plot.generator.DefaultPlotWorld;
|
import java.util.Map;
|
||||||
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.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -37,10 +35,13 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.io.IOException;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import java.util.ArrayList;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import java.util.HashMap;
|
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||||
import java.util.Map;
|
import com.intellectualcrafters.plot.generator.DefaultPlotWorld;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotGenerator;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2014-09-26 for PlotSquared
|
* Created 2014-09-26 for PlotSquared
|
||||||
@ -61,7 +62,8 @@ public class Setup extends SubCommand implements Listener {
|
|||||||
|
|
||||||
if (plr == null) {
|
if (plr == null) {
|
||||||
plrname = "";
|
plrname = "";
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
plrname = plr.getName();
|
plrname = plr.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,17 +77,20 @@ public class Setup extends SubCommand implements Listener {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
PlotMain.config.save(PlotMain.configFile);
|
PlotMain.config.save(PlotMain.configFile);
|
||||||
} catch (final IOException e) {
|
}
|
||||||
|
catch (final IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creating the worlds
|
// Creating the worlds
|
||||||
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
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);
|
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()) {
|
if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.plugin);
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.plugin);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||||
if (plugin.isEnabled()) {
|
if (plugin.isEnabled()) {
|
||||||
if (plugin.getDefaultWorldGenerator("world", "") != null) {
|
if (plugin.getDefaultWorldGenerator("world", "") != null) {
|
||||||
@ -115,7 +120,8 @@ public class Setup extends SubCommand implements Listener {
|
|||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (args[0].equalsIgnoreCase("cancel")) {
|
if (args[0].equalsIgnoreCase("cancel")) {
|
||||||
setupMap.remove(plrname);
|
setupMap.remove(plrname);
|
||||||
PlayerFunctions.sendMessage(plr, "&cCancelled setup.");
|
PlayerFunctions.sendMessage(plr, "&cCancelled setup.");
|
||||||
@ -127,7 +133,8 @@ public class Setup extends SubCommand implements Listener {
|
|||||||
step = object.step[object.current];
|
step = object.step[object.current];
|
||||||
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -144,13 +151,15 @@ public class Setup extends SubCommand implements Listener {
|
|||||||
step = object.step[object.current];
|
step = object.step[object.current];
|
||||||
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sendMessage(plr, C.SETUP_INVALID_ARG, args[0], step.getConstant());
|
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() + "");
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
sendMessage(plr, C.SETUP_MISSING_WORLD);
|
sendMessage(plr, C.SETUP_MISSING_WORLD);
|
||||||
return true;
|
return true;
|
||||||
@ -193,7 +202,8 @@ public class Setup extends SubCommand implements Listener {
|
|||||||
PlotWorld plotworld;
|
PlotWorld plotworld;
|
||||||
if (generator instanceof PlotGenerator) {
|
if (generator instanceof PlotGenerator) {
|
||||||
plotworld = ((PlotGenerator) generator).getNewPlotWorld(world);
|
plotworld = ((PlotGenerator) generator).getNewPlotWorld(world);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
plotworld = new DefaultPlotWorld(world);
|
plotworld = new DefaultPlotWorld(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,10 +217,10 @@ public class Setup extends SubCommand implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class SetupObject {
|
private class SetupObject {
|
||||||
final String world;
|
final String world;
|
||||||
final String plugin;
|
final String plugin;
|
||||||
final ConfigurationNode[] step;
|
final ConfigurationNode[] step;
|
||||||
int current = 0;
|
int current = 0;
|
||||||
|
|
||||||
public SetupObject(final String world, final PlotWorld plotworld, final String plugin) {
|
public SetupObject(final String world, final PlotWorld plotworld, final String plugin) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
@ -21,26 +21,26 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import java.util.ArrayList;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import java.util.Arrays;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SubCommand class
|
* SubCommand class
|
||||||
*
|
*
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"deprecation", "unused"})
|
@SuppressWarnings({ "deprecation", "unused" })
|
||||||
public abstract class SubCommand {
|
public abstract class SubCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command
|
* Command
|
||||||
*/
|
*/
|
||||||
public final String cmd;
|
public final String cmd;
|
||||||
/**
|
/**
|
||||||
* Permission node
|
* Permission node
|
||||||
*/
|
*/
|
||||||
@ -48,7 +48,7 @@ public abstract class SubCommand {
|
|||||||
/**
|
/**
|
||||||
* Simple description
|
* Simple description
|
||||||
*/
|
*/
|
||||||
public final String description;
|
public final String description;
|
||||||
/**
|
/**
|
||||||
* Aliases
|
* Aliases
|
||||||
*/
|
*/
|
||||||
@ -56,23 +56,29 @@ public abstract class SubCommand {
|
|||||||
/**
|
/**
|
||||||
* Command usage
|
* Command usage
|
||||||
*/
|
*/
|
||||||
public final String usage;
|
public final String usage;
|
||||||
/**
|
/**
|
||||||
* The category
|
* The category
|
||||||
*/
|
*/
|
||||||
public final CommandCategory category;
|
public final CommandCategory category;
|
||||||
/**
|
/**
|
||||||
* Is this a player-online command?
|
* Is this a player-online command?
|
||||||
*/
|
*/
|
||||||
public final boolean isPlayer;
|
public final boolean isPlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param cmd Command /plot {cmd} <-- That!
|
* @param cmd
|
||||||
* @param permission Permission Node
|
* Command /plot {cmd} <-- That!
|
||||||
* @param description Simple description
|
* @param permission
|
||||||
* @param usage Usage description: /plot command {args...}
|
* Permission Node
|
||||||
* @param alias Command alias
|
* @param description
|
||||||
* @param category CommandCategory. Pick whichever is closest to what you want.
|
* 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) {
|
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;
|
this.cmd = cmd;
|
||||||
@ -86,12 +92,18 @@ public abstract class SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param cmd Command /plot {cmd} <-- That!
|
* @param cmd
|
||||||
* @param permission Permission Node
|
* Command /plot {cmd} <-- That!
|
||||||
* @param description Simple description
|
* @param permission
|
||||||
* @param usage Usage description: /plot command {args...}
|
* Permission Node
|
||||||
* @param aliases Command aliases
|
* @param description
|
||||||
* @param category CommandCategory. Pick whichever is closest to what you want.
|
* 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) {
|
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;
|
this.cmd = cmd;
|
||||||
@ -105,10 +117,14 @@ public abstract class SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param command Command /plot {cmd} <-- That!
|
* @param command
|
||||||
* @param description Simple description
|
* Command /plot {cmd} <-- That!
|
||||||
* @param usage Usage description: /plot command {args...}
|
* @param description
|
||||||
* @param category CommandCategory. Pick whichever closests to what you want.
|
* 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) {
|
public SubCommand(final Command command, final String description, final String usage, final CommandCategory category, final boolean isPlayer) {
|
||||||
this.cmd = command.getCommand();
|
this.cmd = command.getCommand();
|
||||||
@ -124,8 +140,10 @@ public abstract class SubCommand {
|
|||||||
/**
|
/**
|
||||||
* Execute.
|
* Execute.
|
||||||
*
|
*
|
||||||
* @param plr executor
|
* @param plr
|
||||||
* @param args arguments
|
* executor
|
||||||
|
* @param args
|
||||||
|
* arguments
|
||||||
* @return true on success, false on failure
|
* @return true on success, false on failure
|
||||||
*/
|
*/
|
||||||
public abstract boolean execute(final Player plr, final String... args);
|
public abstract boolean execute(final Player plr, final String... args);
|
||||||
@ -133,7 +151,8 @@ public abstract class SubCommand {
|
|||||||
/**
|
/**
|
||||||
* Execute the command as console
|
* Execute the command as console
|
||||||
*
|
*
|
||||||
* @param args Arguments
|
* @param args
|
||||||
|
* Arguments
|
||||||
*/
|
*/
|
||||||
public void executeConsole(final String... args) {
|
public void executeConsole(final String... args) {
|
||||||
this.execute(null, args);
|
this.execute(null, args);
|
||||||
@ -142,10 +161,14 @@ public abstract class SubCommand {
|
|||||||
/**
|
/**
|
||||||
* Send a message
|
* Send a message
|
||||||
*
|
*
|
||||||
* @param plr Player who will receive the mssage
|
* @param plr
|
||||||
* @param c Caption
|
* Player who will receive the mssage
|
||||||
* @param args Arguments (%s's)
|
* @param c
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player, com.intellectualcrafters.plot.config.C, String...)
|
* Caption
|
||||||
|
* @param args
|
||||||
|
* Arguments (%s's)
|
||||||
|
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player,
|
||||||
|
* com.intellectualcrafters.plot.config.C, String...)
|
||||||
*/
|
*/
|
||||||
public boolean sendMessage(final Player plr, final C c, final String... args) {
|
public boolean sendMessage(final Player plr, final C c, final String... args) {
|
||||||
PlayerFunctions.sendMessage(plr, c, args);
|
PlayerFunctions.sendMessage(plr, c, args);
|
||||||
@ -198,7 +221,8 @@ public abstract class SubCommand {
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param name readable name
|
* @param name
|
||||||
|
* readable name
|
||||||
*/
|
*/
|
||||||
CommandCategory(final String name) {
|
CommandCategory(final String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
@ -29,8 +32,6 @@ import com.intellectualcrafters.plot.object.PlotSelection;
|
|||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||||
import com.intellectualcrafters.plot.util.SetBlockFast;
|
import com.intellectualcrafters.plot.util.SetBlockFast;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2014-08-01 for PlotSquared
|
* Created 2014-08-01 for PlotSquared
|
||||||
@ -73,7 +74,8 @@ public class Swap extends SubCommand {
|
|||||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE, plotid.toString());
|
PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE, plotid.toString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
PlayerFunctions.sendMessage(plr, C.SWAP_SYNTAX);
|
PlayerFunctions.sendMessage(plr, C.SWAP_SYNTAX);
|
||||||
return false;
|
return false;
|
||||||
|
@ -21,17 +21,17 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
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
|
* @author Citymonstret
|
||||||
@ -70,7 +70,8 @@ public class TP extends SubCommand {
|
|||||||
plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1]));
|
plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1]));
|
||||||
PlotMain.teleportPlayer(plr, plr.getLocation(), PlotHelper.getPlot(world, plotid));
|
PlotMain.teleportPlayer(plr, plr.getLocation(), PlotHelper.getPlot(world, plotid));
|
||||||
return true;
|
return true;
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -88,10 +89,8 @@ public class TP extends SubCommand {
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
final Player player = Bukkit.getPlayer(a);
|
final Player player = Bukkit.getPlayer(a);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
final java.util.Set<Plot> plotMainPlots =
|
final java.util.Set<Plot> plotMainPlots = PlotMain.getPlots(world, player);
|
||||||
PlotMain.getPlots(world, player);
|
final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]);
|
||||||
final Plot[] plots =
|
|
||||||
plotMainPlots.toArray(new Plot[plotMainPlots.size()]);
|
|
||||||
if (plots.length > index) {
|
if (plots.length > index) {
|
||||||
return plots[index];
|
return plots[index];
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
@ -29,12 +35,6 @@ import com.intellectualcrafters.plot.object.Plot;
|
|||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class Trusted extends SubCommand {
|
public class Trusted extends SubCommand {
|
||||||
|
|
||||||
@ -62,7 +62,8 @@ public class Trusted extends SubCommand {
|
|||||||
if (args[1].equalsIgnoreCase("*")) {
|
if (args[1].equalsIgnoreCase("*")) {
|
||||||
uuid = DBFunc.everyone;
|
uuid = DBFunc.everyone;
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
uuid = UUIDHandler.getUUID(args[1]);
|
uuid = UUIDHandler.getUUID(args[1]);
|
||||||
}
|
}
|
||||||
if (!plot.trusted.contains(uuid)) {
|
if (!plot.trusted.contains(uuid)) {
|
||||||
@ -87,13 +88,15 @@ public class Trusted extends SubCommand {
|
|||||||
DBFunc.setTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
DBFunc.setTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
||||||
final PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, true);
|
final PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, true);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
|
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED);
|
PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED);
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
}
|
||||||
|
else if (args[0].equalsIgnoreCase("remove")) {
|
||||||
if (args[1].equalsIgnoreCase("*")) {
|
if (args[1].equalsIgnoreCase("*")) {
|
||||||
final UUID uuid = DBFunc.everyone;
|
final UUID uuid = DBFunc.everyone;
|
||||||
if (!plot.trusted.contains(uuid)) {
|
if (!plot.trusted.contains(uuid)) {
|
||||||
@ -124,7 +127,8 @@ public class Trusted extends SubCommand {
|
|||||||
final PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, false);
|
final PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, false);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
PlayerFunctions.sendMessage(plr, C.TRUSTED_REMOVED);
|
PlayerFunctions.sendMessage(plr, C.TRUSTED_REMOVED);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
|
PlayerFunctions.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2014-11-09 for PlotSquared
|
* Created 2014-11-09 for PlotSquared
|
||||||
@ -17,14 +18,14 @@ public class Unban extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(Player plr, String... args) {
|
public boolean execute(final Player plr, final String... args) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + usage);
|
return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + this.usage);
|
||||||
}
|
}
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
if (!PlayerFunctions.isInPlot(plr)) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
||||||
if (!plot.hasRights(plr)) {
|
if (!plot.hasRights(plr)) {
|
||||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,16 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Unclaim extends SubCommand {
|
public class Unclaim extends SubCommand {
|
||||||
|
|
||||||
@ -64,7 +66,8 @@ 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))) {
|
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;
|
Auto.lastPlot = plot.id;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlayerFunctions.sendMessage(plr, "Plot removal has been denied.");
|
PlayerFunctions.sendMessage(plr, "Plot removal has been denied.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -21,6 +21,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
@ -34,12 +40,6 @@ import com.intellectualcrafters.plot.util.PlotHelper;
|
|||||||
import com.intellectualcrafters.plot.util.SetBlockFast;
|
import com.intellectualcrafters.plot.util.SetBlockFast;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
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
|
* Created 2014-08-01 for PlotSquared
|
||||||
*
|
*
|
||||||
@ -86,7 +86,9 @@ public class Unlink extends SubCommand {
|
|||||||
for (final PlotId id : ids) {
|
for (final PlotId id : ids) {
|
||||||
final Plot myplot = PlotMain.getPlots(world).get(id);
|
final Plot myplot = PlotMain.getPlots(world).get(id);
|
||||||
|
|
||||||
if (plot == null) continue;
|
if (plot == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (plot.helpers != null) {
|
if (plot.helpers != null) {
|
||||||
myplot.helpers = plot.helpers;
|
myplot.helpers = plot.helpers;
|
||||||
@ -95,7 +97,7 @@ public class Unlink extends SubCommand {
|
|||||||
myplot.denied = plot.denied;
|
myplot.denied = plot.denied;
|
||||||
}
|
}
|
||||||
myplot.deny_entry = plot.deny_entry;
|
myplot.deny_entry = plot.deny_entry;
|
||||||
myplot.settings.setMerged(new boolean[]{false, false, false, false});
|
myplot.settings.setMerged(new boolean[] { false, false, false, false });
|
||||||
DBFunc.setMerged(world.getName(), myplot, myplot.settings.getMerged());
|
DBFunc.setMerged(world.getName(), myplot, myplot.settings.getMerged());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,12 +126,13 @@ public class Unlink extends SubCommand {
|
|||||||
if (PlotHelper.canSetFast) {
|
if (PlotHelper.canSetFast) {
|
||||||
SetBlockFast.update(plr);
|
SetBlockFast.update(plr);
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
// execute(final Player plr, final String... args) {
|
// execute(final Player plr, final String... args) {
|
||||||
try {
|
try {
|
||||||
PlotMain.sendConsoleSenderMessage(
|
PlotMain.sendConsoleSenderMessage("Error on: " + getClass().getMethod("execute", Player.class, String[].class).toGenericString() + ":119, when trying to use \"SetBlockFast#update\"");
|
||||||
"Error on: " + getClass().getMethod("execute", Player.class, String[].class).toGenericString() + ":119, when trying to use \"SetBlockFast#update\"");
|
}
|
||||||
} catch (Exception ex) {
|
catch (final Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,16 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
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 class Visit extends SubCommand {
|
||||||
public Visit() {
|
public Visit() {
|
||||||
@ -67,7 +68,8 @@ public class Visit extends SubCommand {
|
|||||||
int i;
|
int i;
|
||||||
try {
|
try {
|
||||||
i = Integer.parseInt(args[1]);
|
i = Integer.parseInt(args[1]);
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return sendMessage(plr, C.NOT_VALID_NUMBER);
|
return sendMessage(plr, C.NOT_VALID_NUMBER);
|
||||||
}
|
}
|
||||||
if ((i < 0) || (i >= plots.size())) {
|
if ((i < 0) || (i >= plots.size())) {
|
||||||
|
@ -21,6 +21,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
@ -28,11 +34,6 @@ import com.intellectualcrafters.plot.object.PlotId;
|
|||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.StringComparison;
|
import com.intellectualcrafters.plot.util.StringComparison;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
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
|
* @author Citymonstret
|
||||||
@ -60,9 +61,10 @@ public class list extends SubCommand {
|
|||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s());
|
builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s());
|
||||||
if (plr != null) {
|
if (plr != null) {
|
||||||
builder.append(getArgumentList(new String[]{"mine", "shared", "world", "all"}));
|
builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all" }));
|
||||||
} else {
|
}
|
||||||
builder.append(getArgumentList(new String[]{"all"}));
|
else {
|
||||||
|
builder.append(getArgumentList(new String[] { "all" }));
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, builder.toString());
|
PlayerFunctions.sendMessage(plr, builder.toString());
|
||||||
return true;
|
return true;
|
||||||
@ -82,7 +84,8 @@ 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"));
|
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());
|
PlayerFunctions.sendMessage(plr, string.toString());
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("shared") && (plr != null)) {
|
}
|
||||||
|
else if (args[0].equalsIgnoreCase("shared") && (plr != null)) {
|
||||||
final StringBuilder string = new StringBuilder();
|
final StringBuilder string = new StringBuilder();
|
||||||
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")).append("\n");
|
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")).append("\n");
|
||||||
for (final Plot p : PlotMain.getPlotsSorted()) {
|
for (final Plot p : PlotMain.getPlotsSorted()) {
|
||||||
@ -93,7 +96,8 @@ 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"));
|
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());
|
PlayerFunctions.sendMessage(plr, string.toString());
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("all")) {
|
}
|
||||||
|
else if (args[0].equalsIgnoreCase("all")) {
|
||||||
// Current page
|
// Current page
|
||||||
int page = 0;
|
int page = 0;
|
||||||
|
|
||||||
@ -105,7 +109,8 @@ public class list extends SubCommand {
|
|||||||
if (page < 0) {
|
if (page < 0) {
|
||||||
page = 0;
|
page = 0;
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
page = 0;
|
page = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,7 +145,8 @@ 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"));
|
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());
|
PlayerFunctions.sendMessage(plr, string.toString());
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("world") && (plr != null)) {
|
}
|
||||||
|
else if (args[0].equalsIgnoreCase("world") && (plr != null)) {
|
||||||
final StringBuilder string = new StringBuilder();
|
final StringBuilder string = new StringBuilder();
|
||||||
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")).append("\n");
|
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")).append("\n");
|
||||||
final HashMap<PlotId, Plot> plots = PlotMain.getPlots(plr.getWorld());
|
final HashMap<PlotId, Plot> plots = PlotMain.getPlots(plr.getWorld());
|
||||||
@ -150,9 +156,10 @@ 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"));
|
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());
|
PlayerFunctions.sendMessage(plr, string.toString());
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// execute(plr);
|
// execute(plr);
|
||||||
sendMessage(plr, C.DID_YOU_MEAN, new StringComparison(args[0], new String[]{"mine", "shared", "world", "all"}).getBestMatch());
|
sendMessage(plr, C.DID_YOU_MEAN, new StringComparison(args[0], new String[] { "mine", "shared", "world", "all" }).getBestMatch());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,18 +21,19 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
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.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.ArrayList;
|
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 class plugin extends SubCommand {
|
||||||
|
|
||||||
public static String downloads, version;
|
public static String downloads, version;
|
||||||
@ -47,7 +48,8 @@ public class plugin extends SubCommand {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
downloads = convertToNumericString(getInfo("https://intellectualsites.com/spigot_api.php?method=downloads&url=http://www.spigotmc.org/resources/plotsquared.1177/"), false);
|
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";
|
downloads = "unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,7 +59,8 @@ public class plugin extends SubCommand {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
version = convertToNumericString(getInfo("https://intellectualsites.com/spigot_api.php?method=version&resource=1177"), true);
|
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...
|
// Let's just ignore this, most likely error 500...
|
||||||
version = "unknown";
|
version = "unknown";
|
||||||
}
|
}
|
||||||
@ -70,7 +73,8 @@ public class plugin extends SubCommand {
|
|||||||
for (final char c : str.toCharArray()) {
|
for (final char c : str.toCharArray()) {
|
||||||
if (Character.isDigit(c)) {
|
if (Character.isDigit(c)) {
|
||||||
builder.append(c);
|
builder.append(c);
|
||||||
} else if (dividers && ((c == ',') || (c == '.') || (c == '-') || (c == '_'))) {
|
}
|
||||||
|
else if (dividers && ((c == ',') || (c == '.') || (c == '-') || (c == '_'))) {
|
||||||
builder.append(c);
|
builder.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,16 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.config;
|
package com.intellectualcrafters.plot.config;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualsites.translation.*;
|
|
||||||
import com.intellectualsites.translation.bukkit.BukkitTranslation;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
|
import com.intellectualsites.translation.TranslationFile;
|
||||||
|
import com.intellectualsites.translation.TranslationLanguage;
|
||||||
|
import com.intellectualsites.translation.TranslationManager;
|
||||||
|
import com.intellectualsites.translation.TranslationObject;
|
||||||
|
import com.intellectualsites.translation.YamlTranslationFile;
|
||||||
|
import com.intellectualsites.translation.bukkit.BukkitTranslation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Captions class.
|
* Captions class.
|
||||||
*
|
*
|
||||||
@ -240,30 +245,21 @@ public enum C {
|
|||||||
* Info
|
* Info
|
||||||
*/
|
*/
|
||||||
PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"),
|
PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"),
|
||||||
/*PLOT_INFO("" +
|
/*
|
||||||
"&6ID&7: &a%id%&7\n" +
|
* PLOT_INFO("" +
|
||||||
"&6Alias&7: &a%alias%\n" +
|
* "&6ID&7: &a%id%&7\n" +
|
||||||
"&6Owner&7: &a%owner%\n" +
|
* "&6Alias&7: &a%alias%\n" +
|
||||||
"&6Helpers&7: &a%helpers%\n" +
|
* "&6Owner&7: &a%owner%\n" +
|
||||||
"&6Trusted&7: &a%trusted%\n" +
|
* "&6Helpers&7: &a%helpers%\n" +
|
||||||
"&6Denied&7: &a%denied%\n" +
|
* "&6Trusted&7: &a%trusted%\n" +
|
||||||
"&6Flags&7: &a%flags%\n" +
|
* "&6Denied&7: &a%denied%\n" +
|
||||||
"&6Biome&7: &a%biome%\n" +
|
* "&6Flags&7: &a%flags%\n" +
|
||||||
"&6Rating&7: &a%rating%&7/&a10\n" +
|
* "&6Biome&7: &a%biome%\n" +
|
||||||
"&6Can build&7: &a%build%"
|
* "&6Rating&7: &a%rating%&7/&a10\n" +
|
||||||
),*/
|
* "&6Can build&7: &a%build%"
|
||||||
PLOT_INFO(
|
* ),
|
||||||
"&cID: &6%id%&c\n" +
|
*/
|
||||||
"&cAlias: &6%alias%&c\n" +
|
PLOT_INFO("&cID: &6%id%&c\n" + "&cAlias: &6%alias%&c\n" + "&cOwner: &6%owner%&c\n" + "&cBiome: &6%biome%&c\n" + "&cCan Build: &6%build%&c\n" + "&cRating: &6%rating%&c/&610&c\n" + "&cHelpers: &6%helpers%&c\n" + "&cTrusted: &6%trusted%&c\n" + "&cDenied: &6%denied%&c\n" + "&cFlags: &6%flags%"),
|
||||||
"&cOwner: &6%owner%&c\n" +
|
|
||||||
"&cBiome: &6%biome%&c\n" +
|
|
||||||
"&cCan Build: &6%build%&c\n" +
|
|
||||||
"&cRating: &6%rating%&c/&610&c\n" +
|
|
||||||
"&cHelpers: &6%helpers%&c\n" +
|
|
||||||
"&cTrusted: &6%trusted%&c\n" +
|
|
||||||
"&cDenied: &6%denied%&c\n" +
|
|
||||||
"&cFlags: &6%flags%"
|
|
||||||
),
|
|
||||||
PLOT_INFO_HELPERS("&6Helpers&7: %helpers%"),
|
PLOT_INFO_HELPERS("&6Helpers&7: %helpers%"),
|
||||||
PLOT_INFO_TRUSTED("&6Trusted&7: %trusted%"),
|
PLOT_INFO_TRUSTED("&6Trusted&7: %trusted%"),
|
||||||
PLOT_INFO_DENIED("&6Denied&7: %denied%"),
|
PLOT_INFO_DENIED("&6Denied&7: %denied%"),
|
||||||
@ -394,24 +390,24 @@ public enum C {
|
|||||||
*
|
*
|
||||||
* @see com.intellectualsites.translation.TranslationManager
|
* @see com.intellectualsites.translation.TranslationManager
|
||||||
*/
|
*/
|
||||||
private static TranslationManager manager;
|
private static TranslationManager manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default file
|
* The default file
|
||||||
*
|
*
|
||||||
* @see com.intellectualsites.translation.TranslationFile
|
* @see com.intellectualsites.translation.TranslationFile
|
||||||
*/
|
*/
|
||||||
private static TranslationFile defaultFile;
|
private static TranslationFile defaultFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default
|
* Default
|
||||||
*/
|
*/
|
||||||
private String d;
|
private String d;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translated
|
* Translated
|
||||||
*/
|
*/
|
||||||
private String s;
|
private String s;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for custom strings.
|
* Constructor for custom strings.
|
||||||
@ -426,7 +422,8 @@ public enum C {
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param d default
|
* @param d
|
||||||
|
* default
|
||||||
*/
|
*/
|
||||||
C(final String d) {
|
C(final String d) {
|
||||||
this.d = d;
|
this.d = d;
|
||||||
@ -440,14 +437,11 @@ public enum C {
|
|||||||
manager = new TranslationManager();
|
manager = new TranslationManager();
|
||||||
}
|
}
|
||||||
if (defaultFile == null) {
|
if (defaultFile == null) {
|
||||||
defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getMain()), lang, "PlotSquared", manager)
|
defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getMain()), lang, "PlotSquared", manager).read();
|
||||||
.read();
|
|
||||||
}
|
}
|
||||||
// register everything in this class
|
// register everything in this class
|
||||||
for (C c : values()) {
|
for (final C c : values()) {
|
||||||
manager.addTranslationObject(
|
manager.addTranslationObject(new TranslationObject(c.toString(), c.d, "", ""));
|
||||||
new TranslationObject(c.toString(), c.d, "", "")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,16 +467,17 @@ public enum C {
|
|||||||
public String s() {
|
public String s() {
|
||||||
return manager.getTranslated(toString(), lang).getTranslated().replaceAll("&-", "\n").replaceAll("\\n", "\n");
|
return manager.getTranslated(toString(), lang).getTranslated().replaceAll("&-", "\n").replaceAll("\\n", "\n");
|
||||||
/*
|
/*
|
||||||
if (PlotMain.translations != null) {
|
* if (PlotMain.translations != null) {
|
||||||
final String t = PlotMain.translations.getString(this.toString());
|
* final String t = PlotMain.translations.getString(this.toString());
|
||||||
if (t != null) {
|
* if (t != null) {
|
||||||
this.s = t;
|
* this.s = t;
|
||||||
}
|
* }
|
||||||
}
|
* }
|
||||||
if (this.s.length() < 1) {
|
* if (this.s.length() < 1) {
|
||||||
return "";
|
* return "";
|
||||||
}
|
* }
|
||||||
return this.s.replace("\\n", "\n");*/
|
* return this.s.replace("\\n", "\n");
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,12 +21,13 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.config;
|
package com.intellectualcrafters.plot.config;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
|
||||||
import org.bukkit.block.Biome;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.block.Biome;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Configuration Utility
|
* Main Configuration Utility
|
||||||
*
|
*
|
||||||
@ -35,7 +36,7 @@ import java.util.List;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
|
|
||||||
public static final SettingValue STRING = new SettingValue("STRING") {
|
public static final SettingValue STRING = new SettingValue("STRING") {
|
||||||
@Override
|
@Override
|
||||||
public boolean validateValue(final String string) {
|
public boolean validateValue(final String string) {
|
||||||
return true;
|
return true;
|
||||||
@ -59,13 +60,14 @@ public class Configuration {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final SettingValue INTEGER = new SettingValue("INTEGER") {
|
public static final SettingValue INTEGER = new SettingValue("INTEGER") {
|
||||||
@Override
|
@Override
|
||||||
public boolean validateValue(final String string) {
|
public boolean validateValue(final String string) {
|
||||||
try {
|
try {
|
||||||
int x = Integer.parseInt(string);
|
Integer.parseInt(string);
|
||||||
return true;
|
return true;
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,13 +78,14 @@ public class Configuration {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final SettingValue BOOLEAN = new SettingValue("BOOLEAN") {
|
public static final SettingValue BOOLEAN = new SettingValue("BOOLEAN") {
|
||||||
@Override
|
@Override
|
||||||
public boolean validateValue(final String string) {
|
public boolean validateValue(final String string) {
|
||||||
try {
|
try {
|
||||||
boolean b = Boolean.parseBoolean(string);
|
Boolean.parseBoolean(string);
|
||||||
return true;
|
return true;
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,13 +96,14 @@ public class Configuration {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final SettingValue DOUBLE = new SettingValue("DOUBLE") {
|
public static final SettingValue DOUBLE = new SettingValue("DOUBLE") {
|
||||||
@Override
|
@Override
|
||||||
public boolean validateValue(final String string) {
|
public boolean validateValue(final String string) {
|
||||||
try {
|
try {
|
||||||
double d = Double.parseDouble(string);
|
Double.parseDouble(string);
|
||||||
return true;
|
return true;
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,13 +114,14 @@ public class Configuration {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final SettingValue BIOME = new SettingValue("BIOME") {
|
public static final SettingValue BIOME = new SettingValue("BIOME") {
|
||||||
@Override
|
@Override
|
||||||
public boolean validateValue(final String string) {
|
public boolean validateValue(final String string) {
|
||||||
try {
|
try {
|
||||||
Biome.valueOf(string.toUpperCase());
|
Biome.valueOf(string.toUpperCase());
|
||||||
return true;
|
return true;
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,21 +142,21 @@ public class Configuration {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final SettingValue BLOCK = new SettingValue("BLOCK") {
|
public static final SettingValue BLOCK = new SettingValue("BLOCK") {
|
||||||
@Override
|
@Override
|
||||||
public boolean validateValue(final String string) {
|
public boolean validateValue(final String string) {
|
||||||
try {
|
try {
|
||||||
if (string.contains(":")) {
|
if (string.contains(":")) {
|
||||||
final String[] split = string.split(":");
|
final String[] split = string.split(":");
|
||||||
short s =
|
Short.parseShort(split[0]);
|
||||||
Short.parseShort(split[0]);
|
Short.parseShort(split[1]);
|
||||||
short z =
|
}
|
||||||
Short.parseShort(split[1]);
|
else {
|
||||||
} else {
|
Short.parseShort(string);
|
||||||
short s = Short.parseShort(string);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,7 +166,8 @@ public class Configuration {
|
|||||||
if (string.contains(":")) {
|
if (string.contains(":")) {
|
||||||
final String[] split = string.split(":");
|
final String[] split = string.split(":");
|
||||||
return new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
|
return new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return new PlotBlock(Short.parseShort(string), (byte) 0);
|
return new PlotBlock(Short.parseShort(string), (byte) 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,26 +177,28 @@ public class Configuration {
|
|||||||
return ((PlotBlock) object).id + ":" + ((PlotBlock) object).data;
|
return ((PlotBlock) object).id + ":" + ((PlotBlock) object).data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") {
|
public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") {
|
||||||
@Override
|
@Override
|
||||||
public boolean validateValue(final String string) {
|
public boolean validateValue(final String string) {
|
||||||
try {
|
try {
|
||||||
for (String block : string.split(",")) {
|
for (String block : string.split(",")) {
|
||||||
if (block.contains("%")) {
|
if (block.contains("%")) {
|
||||||
final String[] split = block.split("%");
|
final String[] split = block.split("%");
|
||||||
int i = Integer.parseInt(split[0]);
|
Integer.parseInt(split[0]);
|
||||||
block = split[1];
|
block = split[1];
|
||||||
}
|
}
|
||||||
if (block.contains(":")) {
|
if (block.contains(":")) {
|
||||||
final String[] split = block.split(":");
|
final String[] split = block.split(":");
|
||||||
short s = Short.parseShort(split[0]);
|
Short.parseShort(split[0]);
|
||||||
short z = Short.parseShort(split[1]);
|
Short.parseShort(split[1]);
|
||||||
} else {
|
}
|
||||||
short s = Short.parseShort(block);
|
else {
|
||||||
|
Short.parseShort(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,7 +220,8 @@ public class Configuration {
|
|||||||
if (value < min) {
|
if (value < min) {
|
||||||
min = value;
|
min = value;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
counts[i] = 1;
|
counts[i] = 1;
|
||||||
if (1 < min) {
|
if (1 < min) {
|
||||||
min = 1;
|
min = 1;
|
||||||
@ -221,7 +230,8 @@ public class Configuration {
|
|||||||
if (blocks[i].contains(":")) {
|
if (blocks[i].contains(":")) {
|
||||||
final String[] split = blocks[i].split(":");
|
final String[] split = blocks[i].split(":");
|
||||||
values[i] = new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
|
values[i] = new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
values[i] = new PlotBlock(Short.parseShort(blocks[i]), (byte) 0);
|
values[i] = new PlotBlock(Short.parseShort(blocks[i]), (byte) 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,11 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.config;
|
package com.intellectualcrafters.plot.config;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.Configuration.SettingValue;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import com.intellectualcrafters.plot.config.Configuration.SettingValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration Node
|
* Configuration Node
|
||||||
@ -32,11 +33,11 @@ import java.util.Arrays;
|
|||||||
* @author Empire92
|
* @author Empire92
|
||||||
*/
|
*/
|
||||||
public class ConfigurationNode {
|
public class ConfigurationNode {
|
||||||
private final String constant;
|
private final String constant;
|
||||||
private final Object default_value;
|
private final Object default_value;
|
||||||
private final String description;
|
private final String description;
|
||||||
private final SettingValue type;
|
private final SettingValue type;
|
||||||
private Object value;
|
private Object value;
|
||||||
|
|
||||||
public ConfigurationNode(final String constant, final Object default_value, final String description, final SettingValue type, final boolean required) {
|
public ConfigurationNode(final String constant, final Object default_value, final String description, final SettingValue type, final boolean required) {
|
||||||
this.constant = constant;
|
this.constant = constant;
|
||||||
@ -54,7 +55,8 @@ public class ConfigurationNode {
|
|||||||
try {
|
try {
|
||||||
final Object result = this.type.parseString(string);
|
final Object result = this.type.parseString(string);
|
||||||
return result != null;
|
return result != null;
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,97 +31,98 @@ public class Settings {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static int MAX_AUTO_SIZE = 4;
|
public static int MAX_AUTO_SIZE = 4;
|
||||||
/**
|
/**
|
||||||
* Default worldedit-require-selection-in-mask: false
|
* Default worldedit-require-selection-in-mask: false
|
||||||
*/
|
*/
|
||||||
public static boolean REQUIRE_SELECTION = true;
|
public static boolean REQUIRE_SELECTION = true;
|
||||||
/**
|
/**
|
||||||
* Default kill road mobs: true
|
* Default kill road mobs: true
|
||||||
*/
|
*/
|
||||||
public final static boolean KILL_ROAD_MOBS_DEFAULT = true;
|
public final static boolean KILL_ROAD_MOBS_DEFAULT = true;
|
||||||
/**
|
/**
|
||||||
* Default mob pathfinding: true
|
* Default mob pathfinding: true
|
||||||
*/
|
*/
|
||||||
public final static boolean MOB_PATHFINDING_DEFAULT = true;
|
public final static boolean MOB_PATHFINDING_DEFAULT = true;
|
||||||
/**
|
/**
|
||||||
* Teleport to path on login
|
* Teleport to path on login
|
||||||
*/
|
*/
|
||||||
public static boolean TELEPORT_ON_LOGIN = false;
|
public static boolean TELEPORT_ON_LOGIN = false;
|
||||||
/**
|
/**
|
||||||
* Mob Cap Enabled
|
* Mob Cap Enabled
|
||||||
*/
|
*/
|
||||||
public static boolean MOB_CAP_ENABLED = false;
|
public static boolean MOB_CAP_ENABLED = false;
|
||||||
/**
|
/**
|
||||||
* The Mob Cap
|
* The Mob Cap
|
||||||
*/
|
*/
|
||||||
public static int MOB_CAP = 20;
|
public static int MOB_CAP = 20;
|
||||||
/**
|
/**
|
||||||
* Display titles
|
* Display titles
|
||||||
*/
|
*/
|
||||||
public static boolean TITLES = true;
|
public static boolean TITLES = true;
|
||||||
/**
|
/**
|
||||||
* Schematic Save Path
|
* Schematic Save Path
|
||||||
*/
|
*/
|
||||||
public static String SCHEMATIC_SAVE_PATH = "/var/www/schematics";
|
public static String SCHEMATIC_SAVE_PATH = "/var/www/schematics";
|
||||||
/**
|
/**
|
||||||
* Max allowed plots
|
* Max allowed plots
|
||||||
*/
|
*/
|
||||||
public static int MAX_PLOTS = 20;
|
public static int MAX_PLOTS = 20;
|
||||||
/**
|
/**
|
||||||
* WorldGuard region on claimed plots
|
* WorldGuard region on claimed plots
|
||||||
*/
|
*/
|
||||||
public static boolean WORLDGUARD = false;
|
public static boolean WORLDGUARD = false;
|
||||||
/**
|
/**
|
||||||
* metrics
|
* metrics
|
||||||
*/
|
*/
|
||||||
public static boolean METRICS = true;
|
public static boolean METRICS = true;
|
||||||
/**
|
/**
|
||||||
* plot specific resource pack
|
* plot specific resource pack
|
||||||
*/
|
*/
|
||||||
public static String PLOT_SPECIFIC_RESOURCE_PACK = "";
|
public static String PLOT_SPECIFIC_RESOURCE_PACK = "";
|
||||||
/**
|
/**
|
||||||
* Kill road mobs?
|
* Kill road mobs?
|
||||||
*/
|
*/
|
||||||
public static boolean KILL_ROAD_MOBS;
|
public static boolean KILL_ROAD_MOBS;
|
||||||
/**
|
/**
|
||||||
* mob pathfinding?
|
* mob pathfinding?
|
||||||
*/
|
*/
|
||||||
public static boolean MOB_PATHFINDING;
|
public static boolean MOB_PATHFINDING;
|
||||||
/**
|
/**
|
||||||
* Delete plots on ban?
|
* Delete plots on ban?
|
||||||
*/
|
*/
|
||||||
public static boolean DELETE_PLOTS_ON_BAN = false;
|
public static boolean DELETE_PLOTS_ON_BAN = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verbose?
|
* Verbose?
|
||||||
*/
|
*/
|
||||||
public static boolean DEBUG = true;
|
public static boolean DEBUG = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auto clear enabled
|
* Auto clear enabled
|
||||||
*/
|
*/
|
||||||
public static boolean AUTO_CLEAR = false;
|
public static boolean AUTO_CLEAR = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Days until a plot gets cleared
|
* Days until a plot gets cleared
|
||||||
*/
|
*/
|
||||||
public static int AUTO_CLEAR_DAYS = 365;
|
public static int AUTO_CLEAR_DAYS = 365;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API Location
|
* API Location
|
||||||
*/
|
*/
|
||||||
public static String API_URL = "http://www.intellectualsites.com/minecraft.php";
|
public static String API_URL = "http://www.intellectualsites.com/minecraft.php";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use the custom API
|
* Use the custom API
|
||||||
*/
|
*/
|
||||||
public static boolean CUSTOM_API = true;
|
public static boolean CUSTOM_API = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use offline mode storage
|
* Use offline mode storage
|
||||||
*/
|
*/
|
||||||
public static boolean OFFLINE_MODE = false;
|
public static boolean OFFLINE_MODE = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database settings
|
* Database settings
|
||||||
*
|
*
|
||||||
@ -131,7 +132,7 @@ public class Settings {
|
|||||||
/**
|
/**
|
||||||
* MongoDB enabled?
|
* MongoDB enabled?
|
||||||
*/
|
*/
|
||||||
public static boolean USE_MONGO = false; /*
|
public static boolean USE_MONGO = false; /*
|
||||||
* TODO: Implement Mongo
|
* TODO: Implement Mongo
|
||||||
* @Brandon
|
* @Brandon
|
||||||
*/
|
*/
|
||||||
@ -142,34 +143,34 @@ public class Settings {
|
|||||||
/**
|
/**
|
||||||
* MySQL Enabled?
|
* MySQL Enabled?
|
||||||
*/
|
*/
|
||||||
public static boolean USE_MYSQL = true; /* NOTE: Fixed connector */
|
public static boolean USE_MYSQL = true; /* NOTE: Fixed connector */
|
||||||
/**
|
/**
|
||||||
* SQLite Database name
|
* SQLite Database name
|
||||||
*/
|
*/
|
||||||
public static String SQLITE_DB = "storage";
|
public static String SQLITE_DB = "storage";
|
||||||
/**
|
/**
|
||||||
* MySQL Host name
|
* MySQL Host name
|
||||||
*/
|
*/
|
||||||
public static String HOST_NAME = "localhost";
|
public static String HOST_NAME = "localhost";
|
||||||
/**
|
/**
|
||||||
* MySQL Port
|
* MySQL Port
|
||||||
*/
|
*/
|
||||||
public static String PORT = "3306";
|
public static String PORT = "3306";
|
||||||
/**
|
/**
|
||||||
* MySQL DB
|
* MySQL DB
|
||||||
*/
|
*/
|
||||||
public static String DATABASE = "plot_db";
|
public static String DATABASE = "plot_db";
|
||||||
/**
|
/**
|
||||||
* MySQL User
|
* MySQL User
|
||||||
*/
|
*/
|
||||||
public static String USER = "root";
|
public static String USER = "root";
|
||||||
/**
|
/**
|
||||||
* MySQL Password
|
* MySQL Password
|
||||||
*/
|
*/
|
||||||
public static String PASSWORD = "password";
|
public static String PASSWORD = "password";
|
||||||
/**
|
/**
|
||||||
* MySQL Prefix
|
* MySQL Prefix
|
||||||
*/
|
*/
|
||||||
public static String PREFIX = "";
|
public static String PREFIX = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,18 +21,19 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.database;
|
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.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.UUID;
|
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 Citymonstret
|
||||||
* @author Empire92
|
* @author Empire92
|
||||||
@ -49,61 +50,73 @@ public interface AbstractDB {
|
|||||||
/**
|
/**
|
||||||
* Set Plot owner
|
* Set Plot owner
|
||||||
*
|
*
|
||||||
* @param plot Plot in which the owner should be set
|
* @param plot
|
||||||
* @param uuid The uuid of the new owner
|
* 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);
|
public void setOwner(final Plot plot, final UUID uuid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create all settings, and create default helpers, trusted + denied lists
|
* 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);
|
public void createAllSettingsAndHelpers(final ArrayList<Plot> plots);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a plot
|
* Create a plot
|
||||||
*
|
*
|
||||||
* @param plots Plots that should be created
|
* @param plots
|
||||||
|
* Plots that should be created
|
||||||
*/
|
*/
|
||||||
public void createPlots(final ArrayList<Plot> plots);
|
public void createPlots(final ArrayList<Plot> plots);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a plot
|
* Create a plot
|
||||||
*
|
*
|
||||||
* @param plot That should be created
|
* @param plot
|
||||||
|
* That should be created
|
||||||
*/
|
*/
|
||||||
public void createPlot(final Plot plot);
|
public void createPlot(final Plot plot);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create tables
|
* 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;
|
public void createTables(final String database, final boolean add_constraint) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a plot
|
* 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);
|
public void delete(final String world, final Plot plot);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create plot settings
|
* Create plot settings
|
||||||
*
|
*
|
||||||
* @param id Plot Entry ID
|
* @param id
|
||||||
* @param plot Plot Object
|
* Plot Entry ID
|
||||||
|
* @param plot
|
||||||
|
* Plot Object
|
||||||
*/
|
*/
|
||||||
public void createPlotSettings(final int id, final Plot plot);
|
public void createPlotSettings(final int id, final Plot plot);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the table entry ID
|
* Get the table entry ID
|
||||||
*
|
*
|
||||||
* @param world Which the plot is located in
|
* @param world
|
||||||
* @param id2 Plot ID
|
* Which the plot is located in
|
||||||
|
* @param id2
|
||||||
|
* Plot ID
|
||||||
* @return Integer = Plot Entry Id
|
* @return Integer = Plot Entry Id
|
||||||
*/
|
*/
|
||||||
public int getId(final String world, final PlotId id2);
|
public int getId(final String world, final PlotId id2);
|
||||||
@ -116,97 +129,125 @@ public interface AbstractDB {
|
|||||||
/**
|
/**
|
||||||
* Set the merged status for a plot
|
* Set the merged status for a plot
|
||||||
*
|
*
|
||||||
* @param world World in which the plot is located
|
* @param world
|
||||||
* @param plot Plot Object
|
* World in which the plot is located
|
||||||
* @param merged boolean[]
|
* @param plot
|
||||||
|
* Plot Object
|
||||||
|
* @param merged
|
||||||
|
* boolean[]
|
||||||
*/
|
*/
|
||||||
public void setMerged(final String world, final Plot plot, final boolean[] merged);
|
public void setMerged(final String world, final Plot plot, final boolean[] merged);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set plot flags
|
* Set plot flags
|
||||||
*
|
*
|
||||||
* @param world World in which the plot is located
|
* @param world
|
||||||
* @param plot Plot Object
|
* World in which the plot is located
|
||||||
* @param flags flags to set (flag[])
|
* @param plot
|
||||||
|
* Plot Object
|
||||||
|
* @param flags
|
||||||
|
* flags to set (flag[])
|
||||||
*/
|
*/
|
||||||
public void setFlags(final String world, final Plot plot, final Flag[] flags);
|
public void setFlags(final String world, final Plot plot, final Flag[] flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the plot alias
|
* Set the plot alias
|
||||||
*
|
*
|
||||||
* @param plot Plot for which the alias should be set
|
* @param plot
|
||||||
* @param alias Plot Alias
|
* Plot for which the alias should be set
|
||||||
|
* @param alias
|
||||||
|
* Plot Alias
|
||||||
*/
|
*/
|
||||||
public void setAlias(final String world, final Plot plot, final String alias);
|
public void setAlias(final String world, final Plot plot, final String alias);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purgle a plot
|
* Purgle a plot
|
||||||
*
|
*
|
||||||
* @param world World in which the plot is located
|
* @param world
|
||||||
* @param id Plot ID
|
* World in which the plot is located
|
||||||
|
* @param id
|
||||||
|
* Plot ID
|
||||||
*/
|
*/
|
||||||
public void purge(final String world, final PlotId id);
|
public void purge(final String world, final PlotId id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purge a whole world
|
* 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);
|
public void purge(final String world);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Plot Home Position
|
* 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);
|
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
|
* @return Plot Settings
|
||||||
*/
|
*/
|
||||||
public HashMap<String, Object> getSettings(final int id);
|
public HashMap<String, Object> getSettings(final int id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plot Plot Object
|
* @param plot
|
||||||
* @param player Player that should be removed
|
* Plot Object
|
||||||
|
* @param player
|
||||||
|
* Player that should be removed
|
||||||
*/
|
*/
|
||||||
public void removeHelper(final String world, final Plot plot, final OfflinePlayer player);
|
public void removeHelper(final String world, final Plot plot, final OfflinePlayer player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plot Plot Object
|
* @param plot
|
||||||
* @param player Player that should be removed
|
* Plot Object
|
||||||
|
* @param player
|
||||||
|
* Player that should be removed
|
||||||
*/
|
*/
|
||||||
public void removeTrusted(final String world, final Plot plot, final OfflinePlayer player);
|
public void removeTrusted(final String world, final Plot plot, final OfflinePlayer player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plot Plot Object
|
* @param plot
|
||||||
* @param player Player that should be removed
|
* Plot Object
|
||||||
|
* @param player
|
||||||
|
* Player that should be removed
|
||||||
*/
|
*/
|
||||||
public void setHelper(final String world, final Plot plot, final OfflinePlayer player);
|
public void setHelper(final String world, final Plot plot, final OfflinePlayer player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plot Plot Object
|
* @param plot
|
||||||
* @param player Player that should be added
|
* Plot Object
|
||||||
|
* @param player
|
||||||
|
* Player that should be added
|
||||||
*/
|
*/
|
||||||
public void setTrusted(final String world, final Plot plot, final OfflinePlayer player);
|
public void setTrusted(final String world, final Plot plot, final OfflinePlayer player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plot Plot Object
|
* @param plot
|
||||||
* @param player Player that should be added
|
* Plot Object
|
||||||
|
* @param player
|
||||||
|
* Player that should be added
|
||||||
*/
|
*/
|
||||||
public void removeDenied(final String world, final Plot plot, final OfflinePlayer player);
|
public void removeDenied(final String world, final Plot plot, final OfflinePlayer player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plot Plot Object
|
* @param plot
|
||||||
* @param player Player that should be added
|
* Plot Object
|
||||||
|
* @param player
|
||||||
|
* Player that should be added
|
||||||
*/
|
*/
|
||||||
public void setDenied(final String world, final Plot plot, final OfflinePlayer player);
|
public void setDenied(final String world, final Plot plot, final OfflinePlayer player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plots ratings
|
* Get Plots ratings
|
||||||
*
|
*
|
||||||
* @param plot Plot Object
|
* @param plot
|
||||||
|
* Plot Object
|
||||||
* @return Plot Ratings (pre-calculated)
|
* @return Plot Ratings (pre-calculated)
|
||||||
*/
|
*/
|
||||||
public double getRatings(final Plot plot);
|
public double getRatings(final Plot plot);
|
||||||
@ -214,27 +255,36 @@ public interface AbstractDB {
|
|||||||
/**
|
/**
|
||||||
* Remove a plot comment
|
* Remove a plot comment
|
||||||
*
|
*
|
||||||
* @param world World in which the plot is located
|
* @param world
|
||||||
* @param plot Plot Object
|
* World in which the plot is located
|
||||||
* @param comment Comment to remove
|
* @param plot
|
||||||
|
* Plot Object
|
||||||
|
* @param comment
|
||||||
|
* Comment to remove
|
||||||
*/
|
*/
|
||||||
public void removeComment(final String world, final Plot plot, final PlotComment comment);
|
public void removeComment(final String world, final Plot plot, final PlotComment comment);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a plot comment
|
* Set a plot comment
|
||||||
*
|
*
|
||||||
* @param world World in which the plot is located
|
* @param world
|
||||||
* @param plot Plot Object
|
* World in which the plot is located
|
||||||
* @param comment Comment to add
|
* @param plot
|
||||||
|
* Plot Object
|
||||||
|
* @param comment
|
||||||
|
* Comment to add
|
||||||
*/
|
*/
|
||||||
public void setComment(final String world, final Plot plot, final PlotComment comment);
|
public void setComment(final String world, final Plot plot, final PlotComment comment);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plot Comments
|
* Get Plot Comments
|
||||||
*
|
*
|
||||||
* @param world World in which the plot is located
|
* @param world
|
||||||
* @param plot Plot Object
|
* World in which the plot is located
|
||||||
* @param tier Comment Tier
|
* @param plot
|
||||||
|
* Plot Object
|
||||||
|
* @param tier
|
||||||
|
* Comment Tier
|
||||||
* @return Plot Comments within the specified tier
|
* @return Plot Comments within the specified tier
|
||||||
*/
|
*/
|
||||||
public ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier);
|
public ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier);
|
||||||
|
@ -21,17 +21,18 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.database;
|
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.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.UUID;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DB Functions
|
* DB Functions
|
||||||
*
|
*
|
||||||
@ -51,8 +52,11 @@ public class DBFunc {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the owner of a plot
|
* 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) {
|
public static void setOwner(final Plot plot, final UUID uuid) {
|
||||||
dbManager.setOwner(plot, uuid);
|
dbManager.setOwner(plot, uuid);
|
||||||
@ -60,7 +64,9 @@ public class DBFunc {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create all settings + (helpers, denied, trusted)
|
* 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) {
|
public static void createAllSettingsAndHelpers(final ArrayList<Plot> plots) {
|
||||||
dbManager.createAllSettingsAndHelpers(plots);
|
dbManager.createAllSettingsAndHelpers(plots);
|
||||||
@ -68,7 +74,9 @@ public class DBFunc {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create all plots
|
* 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) {
|
public static void createPlots(final ArrayList<Plot> plots) {
|
||||||
dbManager.createPlots(plots);
|
dbManager.createPlots(plots);
|
||||||
@ -77,7 +85,8 @@ public class DBFunc {
|
|||||||
/**
|
/**
|
||||||
* Create a plot
|
* Create a plot
|
||||||
*
|
*
|
||||||
* @param plot Plot to create
|
* @param plot
|
||||||
|
* Plot to create
|
||||||
*/
|
*/
|
||||||
public static void createPlot(final Plot plot) {
|
public static void createPlot(final Plot plot) {
|
||||||
dbManager.createPlot(plot);
|
dbManager.createPlot(plot);
|
||||||
@ -95,7 +104,8 @@ public class DBFunc {
|
|||||||
/**
|
/**
|
||||||
* Delete a plot
|
* Delete a plot
|
||||||
*
|
*
|
||||||
* @param plot Plot to delete
|
* @param plot
|
||||||
|
* Plot to delete
|
||||||
*/
|
*/
|
||||||
public static void delete(final String world, final Plot plot) {
|
public static void delete(final String world, final Plot plot) {
|
||||||
dbManager.delete(world, plot);
|
dbManager.delete(world, plot);
|
||||||
@ -104,8 +114,10 @@ public class DBFunc {
|
|||||||
/**
|
/**
|
||||||
* Create plot settings
|
* Create plot settings
|
||||||
*
|
*
|
||||||
* @param id Plot ID
|
* @param id
|
||||||
* @param plot Plot Object
|
* Plot ID
|
||||||
|
* @param plot
|
||||||
|
* Plot Object
|
||||||
*/
|
*/
|
||||||
public static void createPlotSettings(final int id, final Plot plot) {
|
public static void createPlotSettings(final int id, final Plot plot) {
|
||||||
dbManager.createPlotSettings(id, plot);
|
dbManager.createPlotSettings(id, plot);
|
||||||
@ -114,8 +126,10 @@ public class DBFunc {
|
|||||||
/**
|
/**
|
||||||
* Get a plot id
|
* Get a plot id
|
||||||
*
|
*
|
||||||
* @param world World
|
* @param world
|
||||||
* @param id2 Plot ID
|
* World
|
||||||
|
* @param id2
|
||||||
|
* Plot ID
|
||||||
* @return ID
|
* @return ID
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
|
@ -21,12 +21,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.database;
|
package com.intellectualcrafters.plot.database;
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract Database class, serves as a base for any connection method (MySQL,
|
* Abstract Database class, serves as a base for any connection method (MySQL,
|
||||||
* SQLite, etc.)
|
* SQLite, etc.)
|
||||||
@ -44,7 +44,8 @@ public abstract class Database {
|
|||||||
/**
|
/**
|
||||||
* Creates a new Database
|
* Creates a new Database
|
||||||
*
|
*
|
||||||
* @param plugin Plugin instance
|
* @param plugin
|
||||||
|
* Plugin instance
|
||||||
*/
|
*/
|
||||||
protected Database(final Plugin plugin) {
|
protected Database(final Plugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -54,8 +55,10 @@ public abstract class Database {
|
|||||||
* Opens a connection with the database
|
* Opens a connection with the database
|
||||||
*
|
*
|
||||||
* @return Opened connection
|
* @return Opened connection
|
||||||
* @throws SQLException if the connection can not be opened
|
* @throws SQLException
|
||||||
* @throws ClassNotFoundException if the driver cannot be found
|
* if the connection can not be opened
|
||||||
|
* @throws ClassNotFoundException
|
||||||
|
* if the driver cannot be found
|
||||||
*/
|
*/
|
||||||
public abstract Connection openConnection() throws SQLException, ClassNotFoundException;
|
public abstract Connection openConnection() throws SQLException, ClassNotFoundException;
|
||||||
|
|
||||||
@ -63,7 +66,8 @@ public abstract class Database {
|
|||||||
* Checks if a connection is open with the database
|
* Checks if a connection is open with the database
|
||||||
*
|
*
|
||||||
* @return true if the connection is open
|
* @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;
|
public abstract boolean checkConnection() throws SQLException;
|
||||||
|
|
||||||
@ -78,7 +82,8 @@ public abstract class Database {
|
|||||||
* Closes the connection with the database
|
* Closes the connection with the database
|
||||||
*
|
*
|
||||||
* @return true if successful
|
* @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;
|
public abstract boolean closeConnection() throws SQLException;
|
||||||
|
|
||||||
@ -86,10 +91,13 @@ public abstract class Database {
|
|||||||
* Executes a SQL Query<br>
|
* Executes a SQL Query<br>
|
||||||
* If the connection is closed, it will be opened
|
* 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
|
* @return the results of the query
|
||||||
* @throws SQLException If the query cannot be executed
|
* @throws SQLException
|
||||||
* @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()}
|
* 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;
|
public abstract ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException;
|
||||||
|
|
||||||
@ -98,10 +106,13 @@ public abstract class Database {
|
|||||||
* See {@link java.sql.Statement#executeUpdate(String)}<br>
|
* See {@link java.sql.Statement#executeUpdate(String)}<br>
|
||||||
* If the connection is closed, it will be opened
|
* 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)}
|
* @return Result Code, see {@link java.sql.Statement#executeUpdate(String)}
|
||||||
* @throws SQLException If the query cannot be executed
|
* @throws SQLException
|
||||||
* @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()}
|
* 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;
|
public abstract int updateSQL(final String query) throws SQLException, ClassNotFoundException;
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,13 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.database;
|
package com.intellectualcrafters.plot.database;
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
import java.sql.*;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects to and uses a MySQL database
|
* Connects to and uses a MySQL database
|
||||||
@ -38,17 +42,23 @@ public class MySQL extends Database {
|
|||||||
private final String port;
|
private final String port;
|
||||||
private final String hostname;
|
private final String hostname;
|
||||||
|
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new MySQL instance
|
* Creates a new MySQL instance
|
||||||
*
|
*
|
||||||
* @param plugin Plugin instance
|
* @param plugin
|
||||||
* @param hostname Name of the host
|
* Plugin instance
|
||||||
* @param port Port number
|
* @param hostname
|
||||||
* @param database Database name
|
* Name of the host
|
||||||
* @param username Username
|
* @param port
|
||||||
* @param password Password
|
* 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) {
|
public MySQL(final Plugin plugin, final String hostname, final String port, final String database, final String username, final String password) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
|
@ -21,6 +21,22 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.database;
|
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.google.common.base.Charsets;
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
@ -31,16 +47,6 @@ import com.worldcretornica.plotme.PlayerList;
|
|||||||
import com.worldcretornica.plotme.Plot;
|
import com.worldcretornica.plotme.Plot;
|
||||||
import com.worldcretornica.plotme.PlotManager;
|
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
|
* Created 2014-08-17 for PlotSquared
|
||||||
*
|
*
|
||||||
@ -57,13 +63,14 @@ public class PlotMeConverter {
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param plugin Plugin Used to run the converter
|
* @param plugin
|
||||||
|
* Plugin Used to run the converter
|
||||||
*/
|
*/
|
||||||
public PlotMeConverter(final PlotMain plugin) {
|
public PlotMeConverter(final PlotMain plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(String message) {
|
private void sendMessage(final String message) {
|
||||||
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: " + message);
|
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,17 +82,13 @@ public class PlotMeConverter {
|
|||||||
public void run() {
|
public void run() {
|
||||||
sendMessage("&7Conversion has started");
|
sendMessage("&7Conversion has started");
|
||||||
sendMessage("7Caching playerdata...");
|
sendMessage("7Caching playerdata...");
|
||||||
final ArrayList<com.intellectualcrafters.plot.object.Plot> createdPlots =
|
final ArrayList<com.intellectualcrafters.plot.object.Plot> createdPlots = new ArrayList<>();
|
||||||
new ArrayList<>();
|
|
||||||
// Online Mode
|
// Online Mode
|
||||||
final boolean online =
|
final boolean online = Bukkit.getServer().getOnlineMode() && !Settings.OFFLINE_MODE;
|
||||||
Bukkit.getServer().getOnlineMode() && !Settings.OFFLINE_MODE;
|
|
||||||
// PlotMe Plugin
|
// PlotMe Plugin
|
||||||
final Plugin plotMePlugin =
|
final Plugin plotMePlugin = Bukkit.getPluginManager().getPlugin("PlotMe");
|
||||||
Bukkit.getPluginManager().getPlugin("PlotMe");
|
|
||||||
// PlotMe Configuration
|
// PlotMe Configuration
|
||||||
final FileConfiguration plotConfig =
|
final FileConfiguration plotConfig = plotMePlugin.getConfig();
|
||||||
plotMePlugin.getConfig();
|
|
||||||
// Plot Worlds
|
// Plot Worlds
|
||||||
final Set<String> worlds = new HashSet<>();
|
final Set<String> worlds = new HashSet<>();
|
||||||
// Loop through the worlds
|
// Loop through the worlds
|
||||||
@ -124,7 +127,8 @@ public class PlotMeConverter {
|
|||||||
|
|
||||||
final Boolean auto_link = plotConfig.getBoolean("worlds." + world.getName() + ".AutoLinkPlots"); //
|
final Boolean auto_link = plotConfig.getBoolean("worlds." + world.getName() + ".AutoLinkPlots"); //
|
||||||
PlotMain.config.set("worlds." + world.getName() + ".plot.auto_merge", auto_link);
|
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");
|
sendMessage("&c-- &lFailed to save configuration for world '" + world.getName() + "'\nThis will need to be done using the setup command, or manually");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,11 +173,13 @@ public class PlotMeConverter {
|
|||||||
psDenied.add(set.getValue());
|
psDenied.add(set.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
for (final String user : plot.getAllowed().split(",")) {
|
for (final String user : plot.getAllowed().split(",")) {
|
||||||
if (user.equals("*")) {
|
if (user.equals("*")) {
|
||||||
psAdded.add(DBFunc.everyone);
|
psAdded.add(DBFunc.everyone);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
final UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8));
|
final UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8));
|
||||||
psAdded.add(uuid);
|
psAdded.add(uuid);
|
||||||
}
|
}
|
||||||
@ -182,16 +188,19 @@ public class PlotMeConverter {
|
|||||||
for (final String user : plot.getDenied().split(",")) {
|
for (final String user : plot.getDenied().split(",")) {
|
||||||
if (user.equals("*")) {
|
if (user.equals("*")) {
|
||||||
psDenied.add(DBFunc.everyone);
|
psDenied.add(DBFunc.everyone);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
final UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8));
|
final UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8));
|
||||||
psDenied.add(uuid);
|
psDenied.add(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Throwable e) {
|
}
|
||||||
|
catch (final Throwable e) {
|
||||||
// Okay, this is evil.
|
// Okay, this is evil.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Throwable e) {
|
}
|
||||||
|
catch (final Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
final PlotId id = new PlotId(Integer.parseInt(plot.id.split(";")[0]), Integer.parseInt(plot.id.split(";")[1]));
|
final PlotId id = new PlotId(Integer.parseInt(plot.id.split(";")[0]), Integer.parseInt(plot.id.split(";")[1]));
|
||||||
@ -199,18 +208,20 @@ public class PlotMeConverter {
|
|||||||
if (online) {
|
if (online) {
|
||||||
pl = new com.intellectualcrafters.plot.object.Plot(id, plot.getOwnerId(), psAdded, psTrusted, psDenied,
|
pl = new com.intellectualcrafters.plot.object.Plot(id, plot.getOwnerId(), psAdded, psTrusted, psDenied,
|
||||||
|
|
||||||
"", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[]{false, false, false, false});
|
"", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[] { false, false, false, false });
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
final String owner = plot.getOwner();
|
final String owner = plot.getOwner();
|
||||||
pl = new com.intellectualcrafters.plot.object.Plot(id, UUID.nameUUIDFromBytes(("OfflinePlayer:" + owner).getBytes(Charsets.UTF_8)), psAdded, psTrusted, psDenied,
|
pl = new com.intellectualcrafters.plot.object.Plot(id, UUID.nameUUIDFromBytes(("OfflinePlayer:" + owner).getBytes(Charsets.UTF_8)), psAdded, psTrusted, psDenied,
|
||||||
|
|
||||||
"", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[]{false, false, false, false});
|
"", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[] { false, false, false, false });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pl != null) {
|
if (pl != null) {
|
||||||
if (!PlotMain.getPlots(world).containsKey(id)) {
|
if (!PlotMain.getPlots(world).containsKey(id)) {
|
||||||
createdPlots.add(pl);
|
createdPlots.add(pl);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
duplicate++;
|
duplicate++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,7 +240,8 @@ public class PlotMeConverter {
|
|||||||
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Saving configuration...");
|
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Saving configuration...");
|
||||||
try {
|
try {
|
||||||
PlotMain.config.save(PlotMain.configFile);
|
PlotMain.config.save(PlotMain.configFile);
|
||||||
} catch (final IOException e) {
|
}
|
||||||
|
catch (final IOException e) {
|
||||||
PlotMain.sendConsoleSenderMessage(" - &cFailed to save configuration.");
|
PlotMain.sendConsoleSenderMessage(" - &cFailed to save configuration.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +250,8 @@ public class PlotMeConverter {
|
|||||||
|
|
||||||
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||||
MV = true;
|
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;
|
MW = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,22 +266,26 @@ public class PlotMeConverter {
|
|||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + worldname);
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + worldname);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (final InterruptedException ex) {
|
}
|
||||||
|
catch (final InterruptedException ex) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
// load
|
// load
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + worldname + " normal -g PlotSquared");
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + worldname + " normal -g PlotSquared");
|
||||||
} else if (MW) {
|
}
|
||||||
|
else if (MW) {
|
||||||
// unload
|
// unload
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + worldname);
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + worldname);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (final InterruptedException ex) {
|
}
|
||||||
|
catch (final InterruptedException ex) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
// load
|
// load
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + worldname + " plugin:PlotSquared");
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + worldname + " plugin:PlotSquared");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Bukkit.getServer().unloadWorld(world, true);
|
Bukkit.getServer().unloadWorld(world, true);
|
||||||
final World myworld = WorldCreator.name(worldname).generator(new WorldGenerator(worldname)).createWorld();
|
final World myworld = WorldCreator.name(worldname).generator(new WorldGenerator(worldname)).createWorld();
|
||||||
myworld.save();
|
myworld.save();
|
||||||
|
@ -21,6 +21,24 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.database;
|
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.PlotMain;
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
@ -32,65 +50,54 @@ import com.intellectualcrafters.plot.util.Logger;
|
|||||||
import com.intellectualcrafters.plot.util.Logger.LogLevel;
|
import com.intellectualcrafters.plot.util.Logger.LogLevel;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
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
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class SQLManager implements AbstractDB {
|
public class SQLManager implements AbstractDB {
|
||||||
|
|
||||||
// Public final
|
// Public final
|
||||||
public final String SET_OWNER;
|
public final String SET_OWNER;
|
||||||
public final String GET_ALL_PLOTS;
|
public final String GET_ALL_PLOTS;
|
||||||
public final String CREATE_PLOTS;
|
public final String CREATE_PLOTS;
|
||||||
public final String CREATE_SETTINGS;
|
public final String CREATE_SETTINGS;
|
||||||
public final String CREATE_HELPERS;
|
public final String CREATE_HELPERS;
|
||||||
public final String CREATE_PLOT;
|
public final String CREATE_PLOT;
|
||||||
// Private Final
|
// Private Final
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param c connection
|
* @param c
|
||||||
* @param p prefix
|
* connection
|
||||||
|
* @param p
|
||||||
|
* prefix
|
||||||
*/
|
*/
|
||||||
public SQLManager(Connection c, String p) {
|
public SQLManager(final Connection c, final String p) {
|
||||||
// Private final
|
// Private final
|
||||||
connection = c;
|
this.connection = c;
|
||||||
prefix = p;
|
this.prefix = p;
|
||||||
// Set timout
|
// Set timout
|
||||||
// setTimout();
|
// setTimout();
|
||||||
|
|
||||||
// Public final
|
// Public final
|
||||||
SET_OWNER =
|
this.SET_OWNER = "UPDATE `" + this.prefix + "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ?";
|
||||||
"UPDATE `" + prefix + "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ?";
|
this.GET_ALL_PLOTS = "SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `" + this.prefix + "plot`";
|
||||||
GET_ALL_PLOTS =
|
this.CREATE_PLOTS = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) values ";
|
||||||
"SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `" + prefix + "plot`";
|
this.CREATE_SETTINGS = "INSERT INTO `" + this.prefix + "plot_settings` (`plot_plot_id`) values ";
|
||||||
CREATE_PLOTS =
|
this.CREATE_HELPERS = "INSERT INTO `" + this.prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values ";
|
||||||
"INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) values ";
|
this.CREATE_PLOT = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)";
|
||||||
CREATE_SETTINGS =
|
|
||||||
"INSERT INTO `" + prefix + "plot_settings` (`plot_plot_id`) values ";
|
|
||||||
CREATE_HELPERS =
|
|
||||||
"INSERT INTO `" + prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values ";
|
|
||||||
CREATE_PLOT =
|
|
||||||
"INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)";
|
|
||||||
|
|
||||||
//schedule reconnect
|
// schedule reconnect
|
||||||
if (PlotMain.getMySQL() != null) {
|
if (PlotMain.getMySQL() != null) {
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable(){
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable() {
|
||||||
public void run(){
|
@Override
|
||||||
|
public void run() {
|
||||||
try {
|
try {
|
||||||
connection = PlotMain.getMySQL().forceConnection();
|
SQLManager.this.connection = PlotMain.getMySQL().forceConnection();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,28 +105,32 @@ public class SQLManager implements AbstractDB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// public void setTimout() {
|
//
|
||||||
// runTask(new Runnable() {
|
// public void setTimout() {
|
||||||
// @Override
|
// runTask(new Runnable() {
|
||||||
// public void run() {
|
// @Override
|
||||||
// try {
|
// public void run() {
|
||||||
// final PreparedStatement statement = connection.prepareStatement("SET GLOBAL wait_timeout =28800;");
|
// try {
|
||||||
// statement.executeQuery();
|
// final PreparedStatement statement =
|
||||||
// statement.close();
|
// connection.prepareStatement("SET GLOBAL wait_timeout =28800;");
|
||||||
// } catch (final SQLException e) {
|
// statement.executeQuery();
|
||||||
// e.printStackTrace();
|
// statement.close();
|
||||||
// Logger.add(LogLevel.DANGER, "Could not reset MySQL timout.");
|
// } catch (final SQLException e) {
|
||||||
// }
|
// e.printStackTrace();
|
||||||
// }
|
// Logger.add(LogLevel.DANGER, "Could not reset MySQL timout.");
|
||||||
// });
|
// }
|
||||||
// }
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Plot owner
|
* Set Plot owner
|
||||||
*
|
*
|
||||||
* @param plot Plot Object
|
* @param plot
|
||||||
* @param uuid Owner UUID
|
* Plot Object
|
||||||
|
* @param uuid
|
||||||
|
* Owner UUID
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setOwner(final Plot plot, final UUID uuid) {
|
public void setOwner(final Plot plot, final UUID uuid) {
|
||||||
@ -127,13 +138,14 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final PreparedStatement statement = connection.prepareStatement(SET_OWNER);
|
final PreparedStatement statement = SQLManager.this.connection.prepareStatement(SQLManager.this.SET_OWNER);
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
statement.setInt(2, plot.id.x);
|
statement.setInt(2, plot.id.x);
|
||||||
statement.setInt(3, plot.id.y);
|
statement.setInt(3, plot.id.y);
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
statement.close();
|
statement.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.DANGER, "Could not set owner for plot " + plot.id);
|
Logger.add(LogLevel.DANGER, "Could not set owner for plot " + plot.id);
|
||||||
}
|
}
|
||||||
@ -150,7 +162,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
final HashMap<String, HashMap<PlotId, Integer>> stored = new HashMap<>();
|
final HashMap<String, HashMap<PlotId, Integer>> stored = new HashMap<>();
|
||||||
final HashMap<Integer, ArrayList<UUID>> helpers = new HashMap<>();
|
final HashMap<Integer, ArrayList<UUID>> helpers = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
final PreparedStatement stmt = connection.prepareStatement(GET_ALL_PLOTS);
|
final PreparedStatement stmt = this.connection.prepareStatement(this.GET_ALL_PLOTS);
|
||||||
final ResultSet result = stmt.executeQuery();
|
final ResultSet result = stmt.executeQuery();
|
||||||
while (result.next()) {
|
while (result.next()) {
|
||||||
final int id = result.getInt("id");
|
final int id = result.getInt("id");
|
||||||
@ -163,7 +175,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
}
|
}
|
||||||
stored.get(world).put(new PlotId(idx, idz), id);
|
stored.get(world).put(new PlotId(idx, idz), id);
|
||||||
}
|
}
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,26 +196,27 @@ public class SQLManager implements AbstractDB {
|
|||||||
|
|
||||||
// add plot settings
|
// add plot settings
|
||||||
final Integer[] ids = helpers.keySet().toArray(new Integer[helpers.keySet().size()]);
|
final Integer[] ids = helpers.keySet().toArray(new Integer[helpers.keySet().size()]);
|
||||||
StringBuilder statement = new StringBuilder(CREATE_SETTINGS);
|
StringBuilder statement = new StringBuilder(this.CREATE_SETTINGS);
|
||||||
for (int i = 0; i < (ids.length - 1); i++) {
|
for (int i = 0; i < (ids.length - 1); i++) {
|
||||||
statement.append("(?),");
|
statement.append("(?),");
|
||||||
}
|
}
|
||||||
statement.append("(?)");
|
statement.append("(?)");
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
stmt = connection.prepareStatement(statement.toString());
|
stmt = this.connection.prepareStatement(statement.toString());
|
||||||
for (int i = 0; i < ids.length; i++) {
|
for (int i = 0; i < ids.length; i++) {
|
||||||
stmt.setInt(i + 1, ids[i]);
|
stmt.setInt(i + 1, ids[i]);
|
||||||
}
|
}
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
// add plot helpers
|
// add plot helpers
|
||||||
String prefix = "";
|
String prefix = "";
|
||||||
statement = new StringBuilder(CREATE_HELPERS);
|
statement = new StringBuilder(this.CREATE_HELPERS);
|
||||||
for (final Integer id : helpers.keySet()) {
|
for (final Integer id : helpers.keySet()) {
|
||||||
for (final UUID helper : helpers.get(id)) {
|
for (final UUID helper : helpers.get(id)) {
|
||||||
statement.append(prefix + "(?, ?)");
|
statement.append(prefix + "(?, ?)");
|
||||||
@ -213,7 +227,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
stmt = connection.prepareStatement(statement.toString());
|
stmt = this.connection.prepareStatement(statement.toString());
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (final Integer id : helpers.keySet()) {
|
for (final Integer id : helpers.keySet()) {
|
||||||
for (final UUID helper : helpers.get(id)) {
|
for (final UUID helper : helpers.get(id)) {
|
||||||
@ -225,7 +239,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
}
|
}
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
Logger.add(LogLevel.WARNING, "Failed to set helper for plots");
|
Logger.add(LogLevel.WARNING, "Failed to set helper for plots");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -245,7 +260,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
if (plots.size() == 0) {
|
if (plots.size() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final StringBuilder statement = new StringBuilder(CREATE_PLOTS);
|
final StringBuilder statement = new StringBuilder(this.CREATE_PLOTS);
|
||||||
|
|
||||||
for (int i = 0; i < (plots.size() - 1); i++) {
|
for (int i = 0; i < (plots.size() - 1); i++) {
|
||||||
statement.append("(?,?,?,?),");
|
statement.append("(?,?,?,?),");
|
||||||
@ -254,7 +269,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
|
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
stmt = connection.prepareStatement(statement.toString());
|
stmt = this.connection.prepareStatement(statement.toString());
|
||||||
for (int i = 0; i < plots.size(); i++) {
|
for (int i = 0; i < plots.size(); i++) {
|
||||||
final Plot plot = plots.get(i);
|
final Plot plot = plots.get(i);
|
||||||
stmt.setInt((i * 4) + 1, plot.id.x);
|
stmt.setInt((i * 4) + 1, plot.id.x);
|
||||||
@ -264,7 +279,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
}
|
}
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.DANGER, "Failed to save plots!");
|
Logger.add(LogLevel.DANGER, "Failed to save plots!");
|
||||||
}
|
}
|
||||||
@ -279,14 +295,15 @@ public class SQLManager implements AbstractDB {
|
|||||||
public void createPlot(final Plot plot) {
|
public void createPlot(final Plot plot) {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
stmt = connection.prepareStatement(CREATE_PLOT);
|
stmt = this.connection.prepareStatement(this.CREATE_PLOT);
|
||||||
stmt.setInt(1, plot.id.x);
|
stmt.setInt(1, plot.id.x);
|
||||||
stmt.setInt(2, plot.id.y);
|
stmt.setInt(2, plot.id.y);
|
||||||
stmt.setString(3, plot.owner.toString());
|
stmt.setString(3, plot.owner.toString());
|
||||||
stmt.setString(4, plot.world);
|
stmt.setString(4, plot.world);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.DANGER, "Failed to save plot " + plot.id);
|
Logger.add(LogLevel.DANGER, "Failed to save plot " + plot.id);
|
||||||
}
|
}
|
||||||
@ -300,31 +317,29 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public void createTables(final String database, final boolean add_constraint) throws SQLException {
|
public void createTables(final String database, final boolean add_constraint) throws SQLException {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final boolean mysql = database.equals("mysql");
|
final boolean mysql = database.equals("mysql");
|
||||||
final Statement stmt = connection.createStatement();
|
final Statement stmt = this.connection.createStatement();
|
||||||
if (mysql) {
|
if (mysql) {
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot` (" + "`id` INT(11) NOT NULL AUTO_INCREMENT," + "`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," + "PRIMARY KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot` (" + "`id` INT(11) NOT NULL AUTO_INCREMENT," + "`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," + "PRIMARY KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_comments` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`tier` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`tier` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)," + " UNIQUE KEY `unique_alias` (`alias`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)," + " UNIQUE KEY `unique_alias` (`alias`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_ratings` ( `plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL, PRIMARY KEY(`plot_plot_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_ratings` ( `plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL, PRIMARY KEY(`plot_plot_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
||||||
if (add_constraint) {
|
if (add_constraint) {
|
||||||
stmt.addBatch("ALTER TABLE `" + prefix + "plot_settings` ADD CONSTRAINT `" + prefix + "plot_settings_ibfk_1` FOREIGN KEY (`plot_plot_id`) REFERENCES `" + prefix + "plot` (`id`) ON DELETE CASCADE");
|
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 {
|
}
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + 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)");
|
else {
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + 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` (" + "`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 `" + prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
|
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 `" + prefix + "plot_trusted` (" + "`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" + ")");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_comments` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`tier` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)" + ")");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`tier` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_ratings` (`plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL, PRIMARY KEY(`plot_plot_id`))");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)" + ")");
|
||||||
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_ratings` (`plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL, PRIMARY KEY(`plot_plot_id`))");
|
||||||
}
|
}
|
||||||
stmt.executeBatch();
|
stmt.executeBatch();
|
||||||
stmt.clearBatch();
|
stmt.clearBatch();
|
||||||
@ -345,26 +360,27 @@ public class SQLManager implements AbstractDB {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
final int id = getId(world, plot.id);
|
final int id = getId(world, plot.id);
|
||||||
try {
|
try {
|
||||||
stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = ?");
|
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_settings` WHERE `plot_plot_id` = ?");
|
||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = ?");
|
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_helpers` WHERE `plot_plot_id` = ?");
|
||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = ?");
|
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_trusted` WHERE `plot_plot_id` = ?");
|
||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_comments` WHERE `plot_plot_id` = ?");
|
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `plot_plot_id` = ?");
|
||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot` WHERE `id` = ?");
|
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot` WHERE `id` = ?");
|
||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.DANGER, "Failed to delete plot " + plot.id);
|
Logger.add(LogLevel.DANGER, "Failed to delete plot " + plot.id);
|
||||||
}
|
}
|
||||||
@ -385,11 +401,12 @@ public class SQLManager implements AbstractDB {
|
|||||||
public void run() {
|
public void run() {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
stmt = connection.prepareStatement("INSERT INTO `" + prefix + "plot_settings`(`plot_plot_id`) VALUES(" + "?)");
|
stmt = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(" + "?)");
|
||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,7 +418,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
public int getId(final String world, final PlotId id2) {
|
public int getId(final String world, final PlotId id2) {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
stmt = connection.prepareStatement("SELECT `id` FROM `" + prefix + "plot` WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND world = ? ORDER BY `timestamp` ASC");
|
stmt = this.connection.prepareStatement("SELECT `id` FROM `" + this.prefix + "plot` WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND world = ? ORDER BY `timestamp` ASC");
|
||||||
stmt.setInt(1, id2.x);
|
stmt.setInt(1, id2.x);
|
||||||
stmt.setInt(2, id2.y);
|
stmt.setInt(2, id2.y);
|
||||||
stmt.setString(3, world);
|
stmt.setString(3, world);
|
||||||
@ -412,7 +429,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
}
|
}
|
||||||
stmt.close();
|
stmt.close();
|
||||||
return id;
|
return id;
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
@ -425,27 +443,28 @@ public class SQLManager implements AbstractDB {
|
|||||||
public LinkedHashMap<String, HashMap<PlotId, Plot>> getPlots() {
|
public LinkedHashMap<String, HashMap<PlotId, Plot>> getPlots() {
|
||||||
final LinkedHashMap<String, HashMap<PlotId, Plot>> newplots = new LinkedHashMap<>();
|
final LinkedHashMap<String, HashMap<PlotId, Plot>> newplots = new LinkedHashMap<>();
|
||||||
try {
|
try {
|
||||||
final DatabaseMetaData data = connection.getMetaData();
|
final DatabaseMetaData data = this.connection.getMetaData();
|
||||||
ResultSet rs = data.getColumns(null, null, prefix + "plot", "plot_id");
|
ResultSet rs = data.getColumns(null, null, this.prefix + "plot", "plot_id");
|
||||||
final boolean execute = rs.next();
|
final boolean execute = rs.next();
|
||||||
if (execute) {
|
if (execute) {
|
||||||
final Statement statement = connection.createStatement();
|
final Statement statement = this.connection.createStatement();
|
||||||
statement.addBatch("ALTER IGNORE TABLE `" + prefix + "plot` ADD `plot_id_x` int(11) DEFAULT 0");
|
statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot` ADD `plot_id_x` int(11) DEFAULT 0");
|
||||||
statement.addBatch("ALTER IGNORE TABLE `" + prefix + "plot` ADD `plot_id_z` int(11) DEFAULT 0");
|
statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot` ADD `plot_id_z` int(11) DEFAULT 0");
|
||||||
statement.addBatch("UPDATE `" + prefix + "plot` SET\n" + " `plot_id_x` = IF(" + " LOCATE(';', `plot_id`) > 0," + " SUBSTRING(`plot_id`, 1, LOCATE(';', `plot_id`) - 1)," + " `plot_id`" + " )," + " `plot_id_z` = IF(" + " LOCATE(';', `plot_id`) > 0," + " SUBSTRING(`plot_id`, LOCATE(';', `plot_id`) + 1)," + " NULL" + " )");
|
statement.addBatch("UPDATE `" + this.prefix + "plot` SET\n" + " `plot_id_x` = IF(" + " LOCATE(';', `plot_id`) > 0," + " SUBSTRING(`plot_id`, 1, LOCATE(';', `plot_id`) - 1)," + " `plot_id`" + " )," + " `plot_id_z` = IF(" + " LOCATE(';', `plot_id`) > 0," + " SUBSTRING(`plot_id`, LOCATE(';', `plot_id`) + 1)," + " NULL" + " )");
|
||||||
statement.addBatch("ALTER TABLE `" + prefix + "plot` DROP `plot_id`");
|
statement.addBatch("ALTER TABLE `" + this.prefix + "plot` DROP `plot_id`");
|
||||||
statement.addBatch("ALTER IGNORE TABLE `" + prefix + "plot_settings` ADD `flags` VARCHAR(512) DEFAULT NULL");
|
statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_settings` ADD `flags` VARCHAR(512) DEFAULT NULL");
|
||||||
statement.executeBatch();
|
statement.executeBatch();
|
||||||
statement.close();
|
statement.close();
|
||||||
}
|
}
|
||||||
rs = data.getColumns(null, null, prefix + "plot_settings", "merged");
|
rs = data.getColumns(null, null, this.prefix + "plot_settings", "merged");
|
||||||
if (!rs.next()) {
|
if (!rs.next()) {
|
||||||
final Statement statement = connection.createStatement();
|
final Statement statement = this.connection.createStatement();
|
||||||
statement.addBatch("ALTER TABLE `" + prefix + "plot_settings` ADD `merged` int(11) DEFAULT NULL");
|
statement.addBatch("ALTER TABLE `" + this.prefix + "plot_settings` ADD `merged` int(11) DEFAULT NULL");
|
||||||
statement.executeBatch();
|
statement.executeBatch();
|
||||||
statement.close();
|
statement.close();
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
}
|
||||||
|
catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
final HashMap<Integer, Plot> plots = new HashMap<>();
|
final HashMap<Integer, Plot> plots = new HashMap<>();
|
||||||
@ -464,8 +483,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
/*
|
/*
|
||||||
* Getting plots
|
* Getting plots
|
||||||
*/
|
*/
|
||||||
stmt = connection.createStatement();
|
stmt = this.connection.createStatement();
|
||||||
ResultSet r = stmt.executeQuery("SELECT `id`, `plot_id_x`, `plot_id_z`, `owner`, `world` FROM `" + prefix + "plot`");
|
ResultSet r = stmt.executeQuery("SELECT `id`, `plot_id_x`, `plot_id_z`, `owner`, `world` FROM `" + this.prefix + "plot`");
|
||||||
PlotId plot_id;
|
PlotId plot_id;
|
||||||
int id;
|
int id;
|
||||||
Plot p;
|
Plot p;
|
||||||
@ -478,7 +497,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
if (!worlds.contains(worldname)) {
|
if (!worlds.contains(worldname)) {
|
||||||
if (noExist.containsKey(worldname)) {
|
if (noExist.containsKey(worldname)) {
|
||||||
noExist.put(worldname, noExist.get(worldname) + 1);
|
noExist.put(worldname, noExist.get(worldname) + 1);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
noExist.put(worldname, 1);
|
noExist.put(worldname, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -488,15 +508,15 @@ public class SQLManager implements AbstractDB {
|
|||||||
user = UUID.fromString(o);
|
user = UUID.fromString(o);
|
||||||
uuids.put(o, user);
|
uuids.put(o, user);
|
||||||
}
|
}
|
||||||
p = new Plot(plot_id, user, new ArrayList<UUID>(), new ArrayList<UUID>(), new ArrayList<UUID>(), "", PlotHomePosition.DEFAULT, null, worldname, new boolean[]{false, false, false, false});
|
p = new Plot(plot_id, user, new ArrayList<UUID>(), new ArrayList<UUID>(), new ArrayList<UUID>(), "", PlotHomePosition.DEFAULT, null, worldname, new boolean[] { false, false, false, false });
|
||||||
plots.put(id, p);
|
plots.put(id, p);
|
||||||
}
|
}
|
||||||
// stmt.close();
|
// stmt.close();
|
||||||
/*
|
/*
|
||||||
* Getting helpers
|
* Getting helpers
|
||||||
*/
|
*/
|
||||||
// stmt = connection.createStatement();
|
// stmt = connection.createStatement();
|
||||||
r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + prefix + "plot_helpers`");
|
r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_helpers`");
|
||||||
while (r.next()) {
|
while (r.next()) {
|
||||||
id = r.getInt("plot_plot_id");
|
id = r.getInt("plot_plot_id");
|
||||||
o = r.getString("user_uuid");
|
o = r.getString("user_uuid");
|
||||||
@ -508,17 +528,18 @@ public class SQLManager implements AbstractDB {
|
|||||||
final Plot plot = plots.get(id);
|
final Plot plot = plots.get(id);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
plot.addHelper(user);
|
plot.addHelper(user);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_helpers does not exist. Please create the plot or remove this entry.");
|
PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_helpers does not exist. Please create the plot or remove this entry.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// stmt.close();
|
// stmt.close();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Getting trusted
|
* Getting trusted
|
||||||
*/
|
*/
|
||||||
// stmt = connection.createStatement();
|
// stmt = connection.createStatement();
|
||||||
r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + prefix + "plot_trusted`");
|
r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_trusted`");
|
||||||
while (r.next()) {
|
while (r.next()) {
|
||||||
id = r.getInt("plot_plot_id");
|
id = r.getInt("plot_plot_id");
|
||||||
o = r.getString("user_uuid");
|
o = r.getString("user_uuid");
|
||||||
@ -530,17 +551,18 @@ public class SQLManager implements AbstractDB {
|
|||||||
final Plot plot = plots.get(id);
|
final Plot plot = plots.get(id);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
plot.addTrusted(user);
|
plot.addTrusted(user);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_trusted does not exist. Please create the plot or remove this entry.");
|
PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_trusted does not exist. Please create the plot or remove this entry.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// stmt.close();
|
// stmt.close();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Getting denied
|
* Getting denied
|
||||||
*/
|
*/
|
||||||
// stmt = connection.createStatement();
|
// stmt = connection.createStatement();
|
||||||
r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + prefix + "plot_denied`");
|
r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_denied`");
|
||||||
while (r.next()) {
|
while (r.next()) {
|
||||||
id = r.getInt("plot_plot_id");
|
id = r.getInt("plot_plot_id");
|
||||||
o = r.getString("user_uuid");
|
o = r.getString("user_uuid");
|
||||||
@ -552,25 +574,24 @@ public class SQLManager implements AbstractDB {
|
|||||||
final Plot plot = plots.get(id);
|
final Plot plot = plots.get(id);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
plot.addDenied(user);
|
plot.addDenied(user);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_denied does not exist. Please create the plot or remove this entry.");
|
PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_denied does not exist. Please create the plot or remove this entry.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// stmt.close();
|
// stmt.close();
|
||||||
|
|
||||||
// stmt = connection.createStatement();
|
// stmt = connection.createStatement();
|
||||||
r = stmt.executeQuery("SELECT * FROM `" + prefix + "plot_settings`");
|
r = stmt.executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`");
|
||||||
while (r.next()) {
|
while (r.next()) {
|
||||||
id = r.getInt("plot_plot_id");
|
id = r.getInt("plot_plot_id");
|
||||||
final Plot plot = plots.get(id);
|
final Plot plot = plots.get(id);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
|
|
||||||
final String b = r.getString("biome");
|
final String b = r.getString("biome");
|
||||||
Biome biome = null;
|
|
||||||
if (b != null) {
|
if (b != null) {
|
||||||
for (final Biome mybiome : Biome.values()) {
|
for (final Biome mybiome : Biome.values()) {
|
||||||
if (mybiome.toString().equalsIgnoreCase(b)) {
|
if (mybiome.toString().equalsIgnoreCase(b)) {
|
||||||
biome = mybiome;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -599,15 +620,17 @@ public class SQLManager implements AbstractDB {
|
|||||||
merged[3 - i] = ((m) & (1 << i)) != 0;
|
merged[3 - i] = ((m) & (1 << i)) != 0;
|
||||||
}
|
}
|
||||||
plot.settings.setMerged(merged);
|
plot.settings.setMerged(merged);
|
||||||
} else {
|
}
|
||||||
plot.settings.setMerged(new boolean[]{false, false, false, false});
|
else {
|
||||||
|
plot.settings.setMerged(new boolean[] { false, false, false, false });
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] flags_string;
|
String[] flags_string;
|
||||||
final String myflags = r.getString("flags");
|
final String myflags = r.getString("flags");
|
||||||
if (myflags == null) {
|
if (myflags == null) {
|
||||||
flags_string = new String[]{};
|
flags_string = new String[] {};
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
flags_string = myflags.split(",");
|
flags_string = myflags.split(",");
|
||||||
}
|
}
|
||||||
final ArrayList<Flag> flags = new ArrayList<Flag>();
|
final ArrayList<Flag> flags = new ArrayList<Flag>();
|
||||||
@ -617,10 +640,12 @@ public class SQLManager implements AbstractDB {
|
|||||||
final String[] split = element.split(":");
|
final String[] split = element.split(":");
|
||||||
try {
|
try {
|
||||||
flags.add(new Flag(FlagManager.getFlag(split[0], true), split[1].replaceAll("\u00AF", ":").replaceAll("<EFBFBD>", ",")));
|
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;
|
exception = true;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
flags.add(new Flag(FlagManager.getFlag(element, true), ""));
|
flags.add(new Flag(FlagManager.getFlag(element, true), ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -629,7 +654,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
setFlags(id, flags.toArray(new Flag[0]));
|
setFlags(id, flags.toArray(new Flag[0]));
|
||||||
}
|
}
|
||||||
plot.settings.setFlags(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.");
|
PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_settings does not exist. Please create the plot or remove this entry.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -649,7 +675,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
if (invalidPlot) {
|
if (invalidPlot) {
|
||||||
PlotMain.sendConsoleSenderMessage("&c[WARNING] - Please create the world/s or remove the plots using the purge command");
|
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.");
|
Logger.add(LogLevel.WARNING, "Failed to load plots.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -667,12 +694,13 @@ public class SQLManager implements AbstractDB {
|
|||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
n = (n << 1) + (merged[i] ? 1 : 0);
|
n = (n << 1) + (merged[i] ? 1 : 0);
|
||||||
}
|
}
|
||||||
final PreparedStatement stmt = connection.prepareStatement("UPDATE `" + prefix + "plot_settings` SET `merged` = ? WHERE `plot_plot_id` = ?");
|
final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `merged` = ? WHERE `plot_plot_id` = ?");
|
||||||
stmt.setInt(1, n);
|
stmt.setInt(1, n);
|
||||||
stmt.setInt(2, getId(world, plot.id));
|
stmt.setInt(2, getId(world, plot.id));
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.WARNING, "Could not set merged for plot " + plot.id);
|
Logger.add(LogLevel.WARNING, "Could not set merged for plot " + plot.id);
|
||||||
}
|
}
|
||||||
@ -696,12 +724,13 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final PreparedStatement stmt = connection.prepareStatement("UPDATE `" + prefix + "plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?");
|
final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?");
|
||||||
stmt.setString(1, flag_string.toString());
|
stmt.setString(1, flag_string.toString());
|
||||||
stmt.setInt(2, getId(world, plot.id));
|
stmt.setInt(2, getId(world, plot.id));
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.WARNING, "Could not set flag for plot " + plot.id);
|
Logger.add(LogLevel.WARNING, "Could not set flag for plot " + plot.id);
|
||||||
}
|
}
|
||||||
@ -721,12 +750,13 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final PreparedStatement stmt = connection.prepareStatement("UPDATE `" + prefix + "plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?");
|
final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?");
|
||||||
stmt.setString(1, flag_string);
|
stmt.setString(1, flag_string);
|
||||||
stmt.setInt(2, id);
|
stmt.setInt(2, id);
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.WARNING, "Could not set flag for plot " + id);
|
Logger.add(LogLevel.WARNING, "Could not set flag for plot " + id);
|
||||||
}
|
}
|
||||||
@ -746,12 +776,13 @@ public class SQLManager implements AbstractDB {
|
|||||||
public void run() {
|
public void run() {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
stmt = connection.prepareStatement("UPDATE `" + prefix + "plot_settings` SET `alias` = ? WHERE `plot_plot_id` = ?");
|
stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `alias` = ? WHERE `plot_plot_id` = ?");
|
||||||
stmt.setString(1, alias);
|
stmt.setString(1, alias);
|
||||||
stmt.setInt(2, getId(world, plot.id));
|
stmt.setInt(2, getId(world, plot.id));
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
Logger.add(LogLevel.WARNING, "Failed to set alias for plot " + plot.id);
|
Logger.add(LogLevel.WARNING, "Failed to set alias for plot " + plot.id);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -776,7 +807,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
|
|
||||||
// Fetching a list of plot IDs for a world
|
// Fetching a list of plot IDs for a world
|
||||||
try {
|
try {
|
||||||
final PreparedStatement stmt = connection.prepareStatement("SELECT `id` FROM `" + prefix + "plot` WHERE `world` = ? AND `plot_id_x` = ? AND `plot_id_z` = ?");
|
final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("SELECT `id` FROM `" + SQLManager.this.prefix + "plot` WHERE `world` = ? AND `plot_id_x` = ? AND `plot_id_z` = ?");
|
||||||
stmt.setString(1, world);
|
stmt.setString(1, world);
|
||||||
stmt.setInt(2, id.x);
|
stmt.setInt(2, id.x);
|
||||||
stmt.setInt(3, id.y);
|
stmt.setInt(3, id.y);
|
||||||
@ -785,7 +816,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
final int id = result.getInt("id");
|
final int id = result.getInt("id");
|
||||||
ids.add(id);
|
ids.add(id);
|
||||||
}
|
}
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.WARNING, "FAILED TO PURGE WORLD '" + world + "'!");
|
Logger.add(LogLevel.WARNING, "FAILED TO PURGE WORLD '" + world + "'!");
|
||||||
return;
|
return;
|
||||||
@ -801,27 +833,28 @@ public class SQLManager implements AbstractDB {
|
|||||||
prefix = " OR `plot_plot_id` = ";
|
prefix = " OR `plot_plot_id` = ";
|
||||||
}
|
}
|
||||||
|
|
||||||
PreparedStatement stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = " + idstr + "");
|
PreparedStatement stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = " + idstr + "");
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
|
|
||||||
stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_denied` WHERE `plot_plot_id` = " + idstr + "");
|
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_denied` WHERE `plot_plot_id` = " + idstr + "");
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
|
|
||||||
stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = " + idstr + "");
|
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = " + idstr + "");
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
|
|
||||||
stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = " + idstr + "");
|
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = " + idstr + "");
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
|
|
||||||
stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot` WHERE `plot_plot_id` = " + idstr + "");
|
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot` WHERE `plot_plot_id` = " + idstr + "");
|
||||||
stmt.setString(1, world);
|
stmt.setString(1, world);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.DANGER, "FAILED TO PURGE PLOT FROM DB '" + world + "' , '" + id + "' !");
|
Logger.add(LogLevel.DANGER, "FAILED TO PURGE PLOT FROM DB '" + world + "' , '" + id + "' !");
|
||||||
return;
|
return;
|
||||||
@ -841,14 +874,15 @@ public class SQLManager implements AbstractDB {
|
|||||||
|
|
||||||
// Fetching a list of plot IDs for a world
|
// Fetching a list of plot IDs for a world
|
||||||
try {
|
try {
|
||||||
final PreparedStatement stmt = connection.prepareStatement("SELECT `id` FROM `" + prefix + "plot` WHERE `world` = ?");
|
final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("SELECT `id` FROM `" + SQLManager.this.prefix + "plot` WHERE `world` = ?");
|
||||||
stmt.setString(1, world);
|
stmt.setString(1, world);
|
||||||
final ResultSet result = stmt.executeQuery();
|
final ResultSet result = stmt.executeQuery();
|
||||||
while (result.next()) {
|
while (result.next()) {
|
||||||
final int id = result.getInt("id");
|
final int id = result.getInt("id");
|
||||||
ids.add(id);
|
ids.add(id);
|
||||||
}
|
}
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.WARNING, "FAILED TO PURGE WORLD '" + world + "'!");
|
Logger.add(LogLevel.WARNING, "FAILED TO PURGE WORLD '" + world + "'!");
|
||||||
return;
|
return;
|
||||||
@ -864,27 +898,28 @@ public class SQLManager implements AbstractDB {
|
|||||||
prefix = " OR `plot_plot_id` = ";
|
prefix = " OR `plot_plot_id` = ";
|
||||||
}
|
}
|
||||||
|
|
||||||
PreparedStatement stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = " + idstr + "");
|
PreparedStatement stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = " + idstr + "");
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
|
|
||||||
stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_denied` WHERE `plot_plot_id` = " + idstr + "");
|
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_denied` WHERE `plot_plot_id` = " + idstr + "");
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
|
|
||||||
stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = " + idstr + "");
|
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = " + idstr + "");
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
|
|
||||||
stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = " + idstr + "");
|
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = " + idstr + "");
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
|
|
||||||
stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot` WHERE `world` = ?");
|
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot` WHERE `world` = ?");
|
||||||
stmt.setString(1, world);
|
stmt.setString(1, world);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.DANGER, "FAILED TO PURGE WORLD '" + world + "'!");
|
Logger.add(LogLevel.DANGER, "FAILED TO PURGE WORLD '" + world + "'!");
|
||||||
return;
|
return;
|
||||||
@ -907,12 +942,13 @@ public class SQLManager implements AbstractDB {
|
|||||||
public void run() {
|
public void run() {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
stmt = connection.prepareStatement("UPDATE `" + prefix + "plot_settings` SET `position` = ? WHERE `plot_plot_id` = ?");
|
stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `position` = ? WHERE `plot_plot_id` = ?");
|
||||||
stmt.setString(1, position);
|
stmt.setString(1, position);
|
||||||
stmt.setInt(2, getId(world, plot.id));
|
stmt.setInt(2, getId(world, plot.id));
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
Logger.add(LogLevel.WARNING, "Failed to set position for plot " + plot.id);
|
Logger.add(LogLevel.WARNING, "Failed to set position for plot " + plot.id);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -929,7 +965,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
final HashMap<String, Object> h = new HashMap<String, Object>();
|
final HashMap<String, Object> h = new HashMap<String, Object>();
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
stmt = connection.prepareStatement("SELECT * FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = ?");
|
stmt = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_settings` WHERE `plot_plot_id` = ?");
|
||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id);
|
||||||
final ResultSet r = stmt.executeQuery();
|
final ResultSet r = stmt.executeQuery();
|
||||||
String var;
|
String var;
|
||||||
@ -964,7 +1000,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
h.put(var, val);
|
h.put(var, val);
|
||||||
}
|
}
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
Logger.add(LogLevel.WARNING, "Failed to load settings for plot: " + id);
|
Logger.add(LogLevel.WARNING, "Failed to load settings for plot: " + id);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -977,14 +1014,15 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final PreparedStatement statement = connection.prepareStatement("DELETE FROM `" + prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `comment` = ? AND `tier` = ? AND `sender` = ?");
|
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `comment` = ? AND `tier` = ? AND `sender` = ?");
|
||||||
statement.setInt(1, getId(world, plot.id));
|
statement.setInt(1, getId(world, plot.id));
|
||||||
statement.setString(2, comment.comment);
|
statement.setString(2, comment.comment);
|
||||||
statement.setInt(3, comment.tier);
|
statement.setInt(3, comment.tier);
|
||||||
statement.setString(4, comment.senderName);
|
statement.setString(4, comment.senderName);
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
statement.close();
|
statement.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.WARNING, "Failed to remove helper for plot " + plot.id);
|
Logger.add(LogLevel.WARNING, "Failed to remove helper for plot " + plot.id);
|
||||||
}
|
}
|
||||||
@ -996,7 +1034,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
public ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier) {
|
public ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier) {
|
||||||
final ArrayList<PlotComment> comments = new ArrayList<PlotComment>();
|
final ArrayList<PlotComment> comments = new ArrayList<PlotComment>();
|
||||||
try {
|
try {
|
||||||
final PreparedStatement statement = connection.prepareStatement("SELECT `*` FROM `" + prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `tier` = ?");
|
final PreparedStatement statement = this.connection.prepareStatement("SELECT `*` FROM `" + this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `tier` = ?");
|
||||||
statement.setInt(1, getId(plot.getWorld().getName(), plot.id));
|
statement.setInt(1, getId(plot.getWorld().getName(), plot.id));
|
||||||
statement.setInt(2, tier);
|
statement.setInt(2, tier);
|
||||||
final ResultSet set = statement.executeQuery();
|
final ResultSet set = statement.executeQuery();
|
||||||
@ -1008,7 +1046,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
comments.add(comment);
|
comments.add(comment);
|
||||||
}
|
}
|
||||||
statement.close();
|
statement.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
Logger.add(LogLevel.WARNING, "Failed to fetch rating for plot " + plot.getId().toString());
|
Logger.add(LogLevel.WARNING, "Failed to fetch rating for plot " + plot.getId().toString());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -1021,14 +1060,15 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final PreparedStatement statement = connection.prepareStatement("INSERT INTO `" + prefix + "plot_comments` (`plot_plot_id`, `comment`, `tier`, `sender`) VALUES(?,?,?,?)");
|
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_comments` (`plot_plot_id`, `comment`, `tier`, `sender`) VALUES(?,?,?,?)");
|
||||||
statement.setInt(1, getId(world, plot.id));
|
statement.setInt(1, getId(world, plot.id));
|
||||||
statement.setString(2, comment.comment);
|
statement.setString(2, comment.comment);
|
||||||
statement.setInt(3, comment.tier);
|
statement.setInt(3, comment.tier);
|
||||||
statement.setString(4, comment.senderName);
|
statement.setString(4, comment.senderName);
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
statement.close();
|
statement.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.WARNING, "Failed to remove helper for plot " + plot.id);
|
Logger.add(LogLevel.WARNING, "Failed to remove helper for plot " + plot.id);
|
||||||
}
|
}
|
||||||
@ -1047,12 +1087,13 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final PreparedStatement statement = connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = ? AND `user_uuid` = ?");
|
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_helpers` WHERE `plot_plot_id` = ? AND `user_uuid` = ?");
|
||||||
statement.setInt(1, getId(world, plot.id));
|
statement.setInt(1, getId(world, plot.id));
|
||||||
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
statement.close();
|
statement.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.WARNING, "Failed to remove helper for plot " + plot.id);
|
Logger.add(LogLevel.WARNING, "Failed to remove helper for plot " + plot.id);
|
||||||
}
|
}
|
||||||
@ -1070,12 +1111,13 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final PreparedStatement statement = connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = ? AND `user_uuid` = ?");
|
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_trusted` WHERE `plot_plot_id` = ? AND `user_uuid` = ?");
|
||||||
statement.setInt(1, getId(world, plot.id));
|
statement.setInt(1, getId(world, plot.id));
|
||||||
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
statement.close();
|
statement.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.WARNING, "Failed to remove trusted user for plot " + plot.id);
|
Logger.add(LogLevel.WARNING, "Failed to remove trusted user for plot " + plot.id);
|
||||||
}
|
}
|
||||||
@ -1093,12 +1135,13 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final PreparedStatement statement = connection.prepareStatement("INSERT INTO `" + prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) VALUES(?,?)");
|
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) VALUES(?,?)");
|
||||||
statement.setInt(1, getId(world, plot.id));
|
statement.setInt(1, getId(world, plot.id));
|
||||||
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
statement.close();
|
statement.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
Logger.add(LogLevel.WARNING, "Failed to set helper for plot " + plot.id);
|
Logger.add(LogLevel.WARNING, "Failed to set helper for plot " + plot.id);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -1116,12 +1159,13 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final PreparedStatement statement = connection.prepareStatement("INSERT INTO `" + prefix + "plot_trusted` (`plot_plot_id`, `user_uuid`) VALUES(?,?)");
|
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_trusted` (`plot_plot_id`, `user_uuid`) VALUES(?,?)");
|
||||||
statement.setInt(1, getId(world, plot.id));
|
statement.setInt(1, getId(world, plot.id));
|
||||||
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
statement.close();
|
statement.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
Logger.add(LogLevel.WARNING, "Failed to set plot trusted for plot " + plot.id);
|
Logger.add(LogLevel.WARNING, "Failed to set plot trusted for plot " + plot.id);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -1139,12 +1183,13 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final PreparedStatement statement = connection.prepareStatement("DELETE FROM `" + prefix + "plot_denied` WHERE `plot_plot_id` = ? AND `user_uuid` = ?");
|
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_denied` WHERE `plot_plot_id` = ? AND `user_uuid` = ?");
|
||||||
statement.setInt(1, getId(world, plot.id));
|
statement.setInt(1, getId(world, plot.id));
|
||||||
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
statement.close();
|
statement.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Logger.add(LogLevel.WARNING, "Failed to remove denied for plot " + plot.id);
|
Logger.add(LogLevel.WARNING, "Failed to remove denied for plot " + plot.id);
|
||||||
}
|
}
|
||||||
@ -1162,12 +1207,13 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final PreparedStatement statement = connection.prepareStatement("INSERT INTO `" + prefix + "plot_denied` (`plot_plot_id`, `user_uuid`) VALUES(?,?)");
|
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_denied` (`plot_plot_id`, `user_uuid`) VALUES(?,?)");
|
||||||
statement.setInt(1, getId(world, plot.id));
|
statement.setInt(1, getId(world, plot.id));
|
||||||
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
statement.setString(2, UUIDHandler.getUUID(player).toString());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
statement.close();
|
statement.close();
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
Logger.add(LogLevel.WARNING, "Failed to set denied for plot " + plot.id);
|
Logger.add(LogLevel.WARNING, "Failed to set denied for plot " + plot.id);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -1178,7 +1224,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public double getRatings(final Plot plot) {
|
public double getRatings(final Plot plot) {
|
||||||
try {
|
try {
|
||||||
final PreparedStatement statement = connection.prepareStatement("SELECT AVG(`rating`) AS `rating` FROM `" + prefix + "plot_ratings` WHERE `plot_plot_id` = ? ");
|
final PreparedStatement statement = this.connection.prepareStatement("SELECT AVG(`rating`) AS `rating` FROM `" + this.prefix + "plot_ratings` WHERE `plot_plot_id` = ? ");
|
||||||
statement.setInt(1, getId(plot.getWorld().getName(), plot.id));
|
statement.setInt(1, getId(plot.getWorld().getName(), plot.id));
|
||||||
final ResultSet set = statement.executeQuery();
|
final ResultSet set = statement.executeQuery();
|
||||||
double rating = 0;
|
double rating = 0;
|
||||||
@ -1187,7 +1233,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
}
|
}
|
||||||
statement.close();
|
statement.close();
|
||||||
return rating;
|
return rating;
|
||||||
} catch (final SQLException e) {
|
}
|
||||||
|
catch (final SQLException e) {
|
||||||
Logger.add(LogLevel.WARNING, "Failed to fetch rating for plot " + plot.getId().toString());
|
Logger.add(LogLevel.WARNING, "Failed to fetch rating for plot " + plot.getId().toString());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,17 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.database;
|
package com.intellectualcrafters.plot.database;
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.*;
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects to and uses a SQLite database
|
* Connects to and uses a SQLite database
|
||||||
*
|
*
|
||||||
@ -37,13 +41,15 @@ import java.util.logging.Level;
|
|||||||
public class SQLite extends Database {
|
public class SQLite extends Database {
|
||||||
|
|
||||||
private final String dbLocation;
|
private final String dbLocation;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new SQLite instance
|
* Creates a new SQLite instance
|
||||||
*
|
*
|
||||||
* @param plugin Plugin instance
|
* @param plugin
|
||||||
* @param dbLocation Location of the Database (Must end in .db)
|
* Plugin instance
|
||||||
|
* @param dbLocation
|
||||||
|
* Location of the Database (Must end in .db)
|
||||||
*/
|
*/
|
||||||
public SQLite(final Plugin plugin, final String dbLocation) {
|
public SQLite(final Plugin plugin, final String dbLocation) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
@ -62,7 +68,8 @@ public class SQLite extends Database {
|
|||||||
if (!(file.exists())) {
|
if (!(file.exists())) {
|
||||||
try {
|
try {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
} catch (final IOException e) {
|
}
|
||||||
|
catch (final IOException e) {
|
||||||
this.plugin.getLogger().log(Level.SEVERE, "Unable to create database!");
|
this.plugin.getLogger().log(Level.SEVERE, "Unable to create database!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,13 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.events;
|
package com.intellectualcrafters.plot.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
* @author Empire92
|
* @author Empire92
|
||||||
@ -34,17 +35,19 @@ import org.bukkit.event.player.PlayerEvent;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static HandlerList handlers = new HandlerList();
|
||||||
private final Plot plot;
|
private final Plot plot;
|
||||||
private final boolean auto;
|
private final boolean auto;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerClaimPlotEvent: Called when a plot is claimed
|
* PlayerClaimPlotEvent: Called when a plot is claimed
|
||||||
*
|
*
|
||||||
* @param player Player that claimed the plot
|
* @param player
|
||||||
* @param plot Plot that was claimed
|
* Player that claimed the plot
|
||||||
|
* @param plot
|
||||||
|
* Plot that was claimed
|
||||||
*/
|
*/
|
||||||
public PlayerClaimPlotEvent(final Player player, final Plot plot, boolean auto) {
|
public PlayerClaimPlotEvent(final Player player, final Plot plot, final boolean auto) {
|
||||||
super(player);
|
super(player);
|
||||||
this.plot = plot;
|
this.plot = plot;
|
||||||
this.auto = auto;
|
this.auto = auto;
|
||||||
|
@ -21,11 +21,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.events;
|
package com.intellectualcrafters.plot.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
* @author Empire92
|
* @author Empire92
|
||||||
@ -34,13 +35,15 @@ public class PlayerEnterPlotEvent extends PlayerEvent {
|
|||||||
|
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
private final Plot plot;
|
private final Plot plot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerEnterPlotEvent: Called when a player leaves a plot
|
* PlayerEnterPlotEvent: Called when a player leaves a plot
|
||||||
*
|
*
|
||||||
* @param player Player that entered the plot
|
* @param player
|
||||||
* @param plot Plot that was entered
|
* Player that entered the plot
|
||||||
|
* @param plot
|
||||||
|
* Plot that was entered
|
||||||
*/
|
*/
|
||||||
public PlayerEnterPlotEvent(final Player player, final Plot plot) {
|
public PlayerEnterPlotEvent(final Player player, final Plot plot) {
|
||||||
super(player);
|
super(player);
|
||||||
|
@ -21,11 +21,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.events;
|
package com.intellectualcrafters.plot.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
* @author Empire92
|
* @author Empire92
|
||||||
@ -33,13 +34,15 @@ import org.bukkit.event.player.PlayerEvent;
|
|||||||
public class PlayerLeavePlotEvent extends PlayerEvent {
|
public class PlayerLeavePlotEvent extends PlayerEvent {
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
private final Plot plot;
|
private final Plot plot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerLeavePlotEvent: Called when a player leaves a plot
|
* PlayerLeavePlotEvent: Called when a player leaves a plot
|
||||||
*
|
*
|
||||||
* @param player Player that left the plot
|
* @param player
|
||||||
* @param plot Plot that was left
|
* Player that left the plot
|
||||||
|
* @param plot
|
||||||
|
* Plot that was left
|
||||||
*/
|
*/
|
||||||
public PlayerLeavePlotEvent(final Player player, final Plot plot) {
|
public PlayerLeavePlotEvent(final Player player, final Plot plot) {
|
||||||
super(player);
|
super(player);
|
||||||
|
@ -21,12 +21,13 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.events;
|
package com.intellectualcrafters.plot.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import java.util.UUID;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
@ -35,19 +36,23 @@ import java.util.UUID;
|
|||||||
public class PlayerPlotDeniedEvent extends Event {
|
public class PlayerPlotDeniedEvent extends Event {
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
private final Plot plot;
|
private final Plot plot;
|
||||||
private final Player initiator;
|
private final Player initiator;
|
||||||
private final boolean added;
|
private final boolean added;
|
||||||
private final UUID player;
|
private final UUID player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a
|
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a
|
||||||
* plot
|
* plot
|
||||||
*
|
*
|
||||||
* @param initiator Player that initiated the event
|
* @param initiator
|
||||||
* @param plot Plot in which the event occurred
|
* Player that initiated the event
|
||||||
* @param player Player that was denied/un-denied
|
* @param plot
|
||||||
* @param added true of add to deny list, false if removed
|
* 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) {
|
public PlayerPlotDeniedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||||
this.initiator = initiator;
|
this.initiator = initiator;
|
||||||
|
@ -21,12 +21,13 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.events;
|
package com.intellectualcrafters.plot.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import java.util.UUID;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Empire92
|
* @author Empire92
|
||||||
@ -35,18 +36,22 @@ import java.util.UUID;
|
|||||||
public class PlayerPlotHelperEvent extends Event {
|
public class PlayerPlotHelperEvent extends Event {
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
private final Plot plot;
|
private final Plot plot;
|
||||||
private final Player initiator;
|
private final Player initiator;
|
||||||
private final boolean added;
|
private final boolean added;
|
||||||
private final UUID player;
|
private final UUID player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerPlotHelperEvent: Called when a plot helper is added/removed
|
* PlayerPlotHelperEvent: Called when a plot helper is added/removed
|
||||||
*
|
*
|
||||||
* @param initiator Player that initiated the event
|
* @param initiator
|
||||||
* @param plot Plot in which the event occurred
|
* Player that initiated the event
|
||||||
* @param player Player that was added/removed from the helper list
|
* @param plot
|
||||||
* @param added true of the player was added, false if the player was removed
|
* 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) {
|
public PlayerPlotHelperEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||||
this.initiator = initiator;
|
this.initiator = initiator;
|
||||||
|
@ -21,12 +21,13 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.events;
|
package com.intellectualcrafters.plot.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import java.util.UUID;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
@ -35,18 +36,22 @@ import java.util.UUID;
|
|||||||
public class PlayerPlotTrustedEvent extends Event {
|
public class PlayerPlotTrustedEvent extends Event {
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
private final Plot plot;
|
private final Plot plot;
|
||||||
private final Player initiator;
|
private final Player initiator;
|
||||||
private final boolean added;
|
private final boolean added;
|
||||||
private final UUID player;
|
private final UUID player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed
|
* PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed
|
||||||
*
|
*
|
||||||
* @param initiator Player that initiated the event
|
* @param initiator
|
||||||
* @param plot Plot in which the event occurred
|
* Player that initiated the event
|
||||||
* @param player Player that was added/removed from the trusted list
|
* @param plot
|
||||||
* @param added true of the player was added, false if the player was removed
|
* 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) {
|
public PlayerPlotTrustedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||||
this.initiator = initiator;
|
this.initiator = initiator;
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user