Some optimization, fixed copyright.

This commit is contained in:
Sauilitired 2014-11-08 20:27:09 +01:00
parent bcc34e7cd8
commit f71fabbfbf
143 changed files with 5090 additions and 4580 deletions

View File

@ -11,8 +11,8 @@
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.bukkit:bukkit:1.7.9-R0.2" level="project" />
<orderEntry type="library" name="Maven: net.milkbowl.vault:Vault:1.3.2" level="project" /> <orderEntry type="library" name="Maven: net.milkbowl.vault:Vault:1.3.2" level="project" />
<orderEntry type="library" name="Maven: org.bukkit:bukkit:1.7.10-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.sk89q:worldedit:6.0.0-SNAPSHOT" level="project" /> <orderEntry type="library" name="Maven: com.sk89q:worldedit:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" /> <orderEntry type="library" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" name="Maven: rhino:js:1.7R2" level="project" /> <orderEntry type="library" name="Maven: rhino:js:1.7R2" level="project" />
@ -29,6 +29,8 @@
<SOURCES /> <SOURCES />
</library> </library>
</orderEntry> </orderEntry>
<orderEntry type="library" name="Maven: junit:junit:4.11" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component> </component>
</module> </module>

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
/** /**
@ -10,8 +31,7 @@ public final class ByteArrayTag extends Tag {
/** /**
* Creates the tag with an empty name. * Creates the tag with an empty name.
* *
* @param value * @param value the value of the tag
* the value of the tag
*/ */
public ByteArrayTag(final byte[] value) { public ByteArrayTag(final byte[] value) {
super(); super();
@ -21,10 +41,8 @@ public final class ByteArrayTag extends Tag {
/** /**
* Creates the tag. * Creates the tag.
* *
* @param name * @param name the name of the tag
* the name of the tag * @param value the value 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);

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
/** /**
@ -10,8 +31,7 @@ public final class ByteTag extends Tag {
/** /**
* Creates the tag with an empty name. * Creates the tag with an empty name.
* *
* @param value * @param value the value of the tag
* the value of the tag
*/ */
public ByteTag(final byte value) { public ByteTag(final byte value) {
super(); super();
@ -21,10 +41,8 @@ public final class ByteTag extends Tag {
/** /**
* Creates the tag. * Creates the tag.
* *
* @param name * @param name the name of the tag
* the name of the tag * @param value the value 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);

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
import java.util.Collections; import java.util.Collections;
@ -15,8 +36,7 @@ public final class CompoundTag extends Tag {
/** /**
* Creates the tag with an empty name. * Creates the tag with an empty name.
* *
* @param value * @param value the value of the tag
* the value of the tag
*/ */
public CompoundTag(final Map<String, Tag> value) { public CompoundTag(final Map<String, Tag> value) {
super(); super();
@ -26,10 +46,8 @@ public final class CompoundTag extends Tag {
/** /**
* Creates the tag. * Creates the tag.
* *
* @param name * @param name the name of the tag
* the name of the tag * @param value the value 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);
@ -39,8 +57,7 @@ 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 * @param key the given 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) {
@ -55,8 +72,7 @@ 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 * @param value the 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) {
@ -74,66 +90,60 @@ public final class CompoundTag extends Tag {
/** /**
* Get a byte array named with the given key. * Get a byte array named with the given key.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not a byte array tag, then an * If the key does not exist or its value is not a byte array tag, then an
* empty byte array will be returned. * empty byte array will be returned.
* </p> * </p>
* *
* @param key * @param key the 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];
} }
} }
/** /**
* Get a byte named with the given key. * Get a byte named with the given key.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not a byte tag, then {@code 0} * If the key does not exist or its value is not a byte tag, then {@code 0}
* will be returned. * will be returned.
* </p> * </p>
* *
* @param key * @param key the 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;
} }
} }
/** /**
* Get a double named with the given key. * Get a double named with the given key.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not a double tag, then * If the key does not exist or its value is not a double tag, then
* {@code 0} will be returned. * {@code 0} will be returned.
* </p> * </p>
* *
* @param key * @param key the 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;
} }
} }
@ -141,14 +151,13 @@ public final class CompoundTag extends Tag {
/** /**
* Get a double named with the given key, even if it's another * Get a double named with the given key, even if it's another
* type of number. * type of number.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not a number, then {@code 0} * If the key does not exist or its value is not a number, then {@code 0}
* will be returned. * will be returned.
* </p> * </p>
* *
* @param key * @param key the key
* the key
* @return a double * @return a double
*/ */
public double asDouble(final String key) { public double asDouble(final String key) {
@ -156,94 +165,82 @@ 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;
} }
} }
/** /**
* Get a float named with the given key. * Get a float named with the given key.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not a float tag, then {@code 0} * If the key does not exist or its value is not a float tag, then {@code 0}
* will be returned. * will be returned.
* </p> * </p>
* *
* @param key * @param key the 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;
} }
} }
/** /**
* Get a {@code int[]} named with the given key. * Get a {@code int[]} named with the given key.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not an int array tag, then an * If the key does not exist or its value is not an int array tag, then an
* empty array will be returned. * empty array will be returned.
* </p> * </p>
* *
* @param key * @param key the 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];
} }
} }
/** /**
* Get an int named with the given key. * Get an int named with the given key.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not an int tag, then {@code 0} * If the key does not exist or its value is not an int tag, then {@code 0}
* will be returned. * will be returned.
* </p> * </p>
* *
* @param key * @param key the 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;
} }
} }
@ -251,14 +248,13 @@ public final class CompoundTag extends Tag {
/** /**
* Get an int named with the given key, even if it's another * Get an int named with the given key, even if it's another
* type of number. * type of number.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not a number, then {@code 0} * If the key does not exist or its value is not a number, then {@code 0}
* will be returned. * will be returned.
* </p> * </p>
* *
* @param key * @param key the key
* the key
* @return an int * @return an int
*/ */
public int asInt(final String key) { public int asInt(final String key) {
@ -266,92 +262,79 @@ 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;
} }
} }
/** /**
* Get a list of tags named with the given key. * Get a list of tags named with the given key.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not a list tag, then an empty * If the key does not exist or its value is not a list tag, then an empty
* list will be returned. * list will be returned.
* </p> * </p>
* *
* @param key * @param key the 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();
} }
} }
/** /**
* Get a {@code TagList} named with the given key. * Get a {@code TagList} named with the given key.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not a list tag, then an empty * If the key does not exist or its value is not a list tag, then an empty
* tag list will be returned. * tag list will be returned.
* </p> * </p>
* *
* @param key * @param key the 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 {
else { return new ListTag(key, StringTag.class, Collections.<Tag>emptyList());
return new ListTag(key, StringTag.class, Collections.<Tag> emptyList());
} }
} }
/** /**
* Get a list of tags named with the given key. * Get a list of tags named with the given key.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not a list tag, then an empty * If the key does not exist or its value is not a list tag, then an empty
* list will be returned. If the given key references a list but the list of * list will be returned. If the given key references a list but the list of
* of a different type, then an empty list will also be returned. * of a different type, then an empty list will also be returned.
* </p> * </p>
* *
* @param key * @param key the key
* the key * @param listType the class of the contained type
* @param listType * @param <T> the type of list
* the class of the contained type
* @return a list of tags * @return a list of tags
* @param <T>
* the type of list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends Tag> List<T> getList(final String key, final Class<T> listType) { public <T extends Tag> List<T> getList(final String key, final Class<T> listType) {
@ -360,34 +343,30 @@ 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();
} }
} }
/** /**
* Get a long named with the given key. * Get a long named with the given key.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not a long tag, then {@code 0} * If the key does not exist or its value is not a long tag, then {@code 0}
* will be returned. * will be returned.
* </p> * </p>
* *
* @param key * @param key the 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;
} }
} }
@ -395,14 +374,13 @@ public final class CompoundTag extends Tag {
/** /**
* Get a long named with the given key, even if it's another * Get a long named with the given key, even if it's another
* type of number. * type of number.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not a number, then {@code 0} * If the key does not exist or its value is not a number, then {@code 0}
* will be returned. * will be returned.
* </p> * </p>
* *
* @param key * @param key the key
* the key
* @return a long * @return a long
*/ */
public long asLong(final String key) { public long asLong(final String key) {
@ -410,72 +388,62 @@ 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;
} }
} }
/** /**
* Get a short named with the given key. * Get a short named with the given key.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not a short tag, then {@code 0} * If the key does not exist or its value is not a short tag, then {@code 0}
* will be returned. * will be returned.
* </p> * </p>
* *
* @param key * @param key the 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;
} }
} }
/** /**
* Get a string named with the given key. * Get a string named with the given key.
* * <p/>
* <p> * <p>
* If the key does not exist or its value is not a string tag, then * If the key does not exist or its value is not a string tag, then
* {@code ""} will be returned. * {@code ""} will be returned.
* </p> * </p>
* *
* @param key * @param key the 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 "";
} }
} }

View File

@ -1,10 +1,31 @@
package com.intellectualcrafters.jnbt; ////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
import static com.google.common.base.Preconditions.checkNotNull; package com.intellectualcrafters.jnbt;
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,8 +43,7 @@ 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 * @param value the value
* the value
*/ */
CompoundTagBuilder(final Map<String, Tag> value) { CompoundTagBuilder(final Map<String, Tag> value) {
checkNotNull(value); checkNotNull(value);
@ -33,10 +53,8 @@ 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 * @param key they key
* they key * @param value the value
* @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) {
@ -50,10 +68,8 @@ 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 * @param key they key
* they key * @param value the value
* @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) {
@ -63,10 +79,8 @@ 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 * @param key they key
* they key * @param value the value
* @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) {
@ -76,10 +90,8 @@ 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 * @param key they key
* they key * @param value the value
* @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,10 +101,8 @@ 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 * @param key they key
* they key * @param value the value
* @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) {
@ -103,10 +113,8 @@ 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 * @param key they key
* they key * @param value the value
* @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) {
@ -116,10 +124,8 @@ 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 * @param key they key
* they key * @param value the value
* @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) {
@ -129,10 +135,8 @@ 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 * @param key they key
* they key * @param value the value
* @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) {
@ -142,10 +146,8 @@ 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 * @param key they key
* they key * @param value the value
* @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) {
@ -155,10 +157,8 @@ 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 * @param key they key
* they key * @param value the value
* @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) {
@ -168,8 +168,7 @@ 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 * @param value the map of tags
* 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) {
@ -192,8 +191,7 @@ 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 * @param name the name of the tag
* 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) {

View File

@ -1,8 +1,28 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
/** /**
* The {@code TAG_Double} tag. * The {@code TAG_Double} tag.
*
*/ */
public final class DoubleTag extends Tag { public final class DoubleTag extends Tag {
@ -11,8 +31,7 @@ public final class DoubleTag extends Tag {
/** /**
* Creates the tag with an empty name. * Creates the tag with an empty name.
* *
* @param value * @param value the value of the tag
* the value of the tag
*/ */
public DoubleTag(final double value) { public DoubleTag(final double value) {
super(); super();
@ -22,10 +41,8 @@ public final class DoubleTag extends Tag {
/** /**
* Creates the tag. * Creates the tag.
* *
* @param name * @param name the name of the tag
* the name of the tag * @param value the value 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);

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
/** /**
@ -10,8 +31,7 @@ public final class FloatTag extends Tag {
/** /**
* Creates the tag with an empty name. * Creates the tag with an empty name.
* *
* @param value * @param value the value of the tag
* the value of the tag
*/ */
public FloatTag(final float value) { public FloatTag(final float value) {
super(); super();
@ -21,10 +41,8 @@ public final class FloatTag extends Tag {
/** /**
* Creates the tag. * Creates the tag.
* *
* @param name * @param name the name of the tag
* the name of the tag * @param value the value 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);

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -12,8 +33,7 @@ public final class IntArrayTag extends Tag {
/** /**
* Creates the tag with an empty name. * Creates the tag with an empty name.
* *
* @param value * @param value the value of the tag
* the value of the tag
*/ */
public IntArrayTag(final int[] value) { public IntArrayTag(final int[] value) {
super(); super();
@ -24,10 +44,8 @@ public final class IntArrayTag extends Tag {
/** /**
* Creates the tag. * Creates the tag.
* *
* @param name * @param name the name of the tag
* the name of the tag * @param value the value 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);

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
/** /**
@ -10,8 +31,7 @@ public final class IntTag extends Tag {
/** /**
* Creates the tag with an empty name. * Creates the tag with an empty name.
* *
* @param value * @param value the value of the tag
* the value of the tag
*/ */
public IntTag(final int value) { public IntTag(final int value) {
super(); super();
@ -21,10 +41,8 @@ public final class IntTag extends Tag {
/** /**
* Creates the tag. * Creates the tag.
* *
* @param name * @param name the name of the tag
* the name of the tag * @param value the value 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);

View File

@ -1,12 +1,32 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
import static com.google.common.base.Preconditions.checkNotNull; import javax.annotation.Nullable;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import javax.annotation.Nullable; import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* The {@code TAG_List} tag. * The {@code TAG_List} tag.
@ -14,15 +34,13 @@ import javax.annotation.Nullable;
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 * @param type the type of tag
* the type of tag * @param value the value of the 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();
@ -34,12 +52,9 @@ public final class ListTag extends Tag {
/** /**
* Creates the tag. * Creates the tag.
* *
* @param name * @param name the name of the tag
* the name of the tag * @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 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);
@ -65,8 +80,7 @@ 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 * @param list the new 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) {
@ -76,82 +90,74 @@ 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 * @param index the 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;
} }
} }
/** /**
* Get a byte array named with the given index. * Get a byte array named with the given index.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not a byte array tag, then an * If the index does not exist or its value is not a byte array tag, then an
* empty byte array will be returned. * empty byte array will be returned.
* </p> * </p>
* *
* @param index * @param index the 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];
} }
} }
/** /**
* Get a byte named with the given index. * Get a byte named with the given index.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not a byte tag, then * If the index does not exist or its value is not a byte tag, then
* {@code 0} will be returned. * {@code 0} will be returned.
* </p> * </p>
* *
* @param index * @param index the 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;
} }
} }
/** /**
* Get a double named with the given index. * Get a double named with the given index.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not a double tag, then * If the index does not exist or its value is not a double tag, then
* {@code 0} will be returned. * {@code 0} will be returned.
* </p> * </p>
* *
* @param index * @param index the 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;
} }
} }
@ -159,14 +165,13 @@ public final class ListTag extends Tag {
/** /**
* Get a double named with the given index, even if it's another * Get a double named with the given index, even if it's another
* type of number. * type of number.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not a number, then {@code 0} * If the index does not exist or its value is not a number, then {@code 0}
* will be returned. * will be returned.
* </p> * </p>
* *
* @param index * @param index the index
* the index
* @return a double * @return a double
*/ */
public double asDouble(final int index) { public double asDouble(final int index) {
@ -174,94 +179,82 @@ 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;
} }
} }
/** /**
* Get a float named with the given index. * Get a float named with the given index.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not a float tag, then * If the index does not exist or its value is not a float tag, then
* {@code 0} will be returned. * {@code 0} will be returned.
* </p> * </p>
* *
* @param index * @param index the 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;
} }
} }
/** /**
* Get a {@code int[]} named with the given index. * Get a {@code int[]} named with the given index.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not an int array tag, then an * If the index does not exist or its value is not an int array tag, then an
* empty array will be returned. * empty array will be returned.
* </p> * </p>
* *
* @param index * @param index the 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];
} }
} }
/** /**
* Get an int named with the given index. * Get an int named with the given index.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not an int tag, then * If the index does not exist or its value is not an int tag, then
* {@code 0} will be returned. * {@code 0} will be returned.
* </p> * </p>
* *
* @param index * @param index the 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;
} }
} }
@ -269,14 +262,13 @@ public final class ListTag extends Tag {
/** /**
* Get an int named with the given index, even if it's another * Get an int named with the given index, even if it's another
* type of number. * type of number.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not a number, then {@code 0} * If the index does not exist or its value is not a number, then {@code 0}
* will be returned. * will be returned.
* </p> * </p>
* *
* @param index * @param index the index
* the index
* @return an int * @return an int
*/ */
public int asInt(final int index) { public int asInt(final int index) {
@ -284,92 +276,79 @@ 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;
} }
} }
/** /**
* Get a list of tags named with the given index. * Get a list of tags named with the given index.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not a list tag, then an empty * If the index does not exist or its value is not a list tag, then an empty
* list will be returned. * list will be returned.
* </p> * </p>
* *
* @param index * @param index the 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();
} }
} }
/** /**
* Get a {@code TagList} named with the given index. * Get a {@code TagList} named with the given index.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not a list tag, then an empty * If the index does not exist or its value is not a list tag, then an empty
* tag list will be returned. * tag list will be returned.
* </p> * </p>
* *
* @param index * @param index the 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 {
else { return new ListTag(StringTag.class, Collections.<Tag>emptyList());
return new ListTag(StringTag.class, Collections.<Tag> emptyList());
} }
} }
/** /**
* Get a list of tags named with the given index. * Get a list of tags named with the given index.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not a list tag, then an empty * If the index does not exist or its value is not a list tag, then an empty
* list will be returned. If the given index references a list but the list * list will be returned. If the given index references a list but the list
* of of a different type, then an empty list will also be returned. * of of a different type, then an empty list will also be returned.
* </p> * </p>
* *
* @param index * @param index the index
* the index * @param listType the class of the contained type
* @param listType * @param <T> the NBT type
* the class of the contained type
* @return a list of tags * @return a list of tags
* @param <T>
* the NBT type
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends Tag> List<T> getList(final int index, final Class<T> listType) { public <T extends Tag> List<T> getList(final int index, final Class<T> listType) {
@ -378,34 +357,30 @@ 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();
} }
} }
/** /**
* Get a long named with the given index. * Get a long named with the given index.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not a long tag, then * If the index does not exist or its value is not a long tag, then
* {@code 0} will be returned. * {@code 0} will be returned.
* </p> * </p>
* *
* @param index * @param index the 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;
} }
} }
@ -413,14 +388,13 @@ public final class ListTag extends Tag {
/** /**
* Get a long named with the given index, even if it's another * Get a long named with the given index, even if it's another
* type of number. * type of number.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not a number, then {@code 0} * If the index does not exist or its value is not a number, then {@code 0}
* will be returned. * will be returned.
* </p> * </p>
* *
* @param index * @param index the index
* the index
* @return a long * @return a long
*/ */
public long asLong(final int index) { public long asLong(final int index) {
@ -428,72 +402,62 @@ 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;
} }
} }
/** /**
* Get a short named with the given index. * Get a short named with the given index.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not a short tag, then * If the index does not exist or its value is not a short tag, then
* {@code 0} will be returned. * {@code 0} will be returned.
* </p> * </p>
* *
* @param index * @param index the 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;
} }
} }
/** /**
* Get a string named with the given index. * Get a string named with the given index.
* * <p/>
* <p> * <p>
* If the index does not exist or its value is not a string tag, then * If the index does not exist or its value is not a string tag, then
* {@code ""} will be returned. * {@code ""} will be returned.
* </p> * </p>
* *
* @param index * @param index the 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 "";
} }
} }

View File

@ -1,25 +1,45 @@
package com.intellectualcrafters.jnbt; ////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
import static com.google.common.base.Preconditions.checkNotNull; package com.intellectualcrafters.jnbt;
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 * @param type of tag contained in this list
* of tag contained in this list
*/ */
ListTagBuilder(final Class<? extends Tag> type) { ListTagBuilder(final Class<? extends Tag> type) {
checkNotNull(type); checkNotNull(type);
@ -30,8 +50,7 @@ public class ListTagBuilder {
/** /**
* Add the given tag. * Add the given tag.
* *
* @param value * @param value the tag
* the tag
* @return this object * @return this object
*/ */
public ListTagBuilder add(final Tag value) { public ListTagBuilder add(final Tag value) {
@ -46,8 +65,7 @@ public class ListTagBuilder {
/** /**
* Add all the tags in the given list. * Add all the tags in the given list.
* *
* @param value * @param value a list of tags
* 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) {
@ -70,8 +88,7 @@ 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 * @param name the name of the tag
* 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) {

View File

@ -1,8 +1,28 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
/** /**
* The {@code TAG_Long} tag. * The {@code TAG_Long} tag.
*
*/ */
public final class LongTag extends Tag { public final class LongTag extends Tag {
@ -11,8 +31,7 @@ public final class LongTag extends Tag {
/** /**
* Creates the tag with an empty name. * Creates the tag with an empty name.
* *
* @param value * @param value the value of the tag
* the value of the tag
*/ */
public LongTag(final long value) { public LongTag(final long value) {
super(); super();
@ -22,10 +41,8 @@ public final class LongTag extends Tag {
/** /**
* Creates the tag. * Creates the tag.
* *
* @param name * @param name the name of the tag
* the name of the tag * @param value the value 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);

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -9,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.
@ -21,11 +42,9 @@ 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 * @param id type ID
* type ID
* @return tag class * @return tag class
* @throws IllegalArgumentException * @throws IllegalArgumentException thrown if the tag ID is not valid
* 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) {

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
import java.io.Closeable; import java.io.Closeable;
@ -13,7 +34,7 @@ import java.util.Map;
* This class reads <strong>NBT</strong>, or <strong>Named Binary Tag</strong> * This class reads <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
* streams, and produces an object graph of subclasses of the {@code Tag} * streams, and produces an object graph of subclasses of the {@code Tag}
* object. * object.
* * <p/>
* <p> * <p>
* The NBT format was created by Markus Persson, and the specification may be * The NBT format was created by Markus Persson, and the specification may be
* found at <a href="http://www.minecraft.net/docs/NBT.txt"> * found at <a href="http://www.minecraft.net/docs/NBT.txt">
@ -28,10 +49,8 @@ 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 * @param is the input stream
* the input stream * @throws IOException if an I/O error occurs
* @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);
@ -41,8 +60,7 @@ 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 * @throws IOException if an I/O error occurs.
* if an I/O error occurs.
*/ */
public Tag readTag() throws IOException { public Tag readTag() throws IOException {
return readTag(0); return readTag(0);
@ -51,11 +69,9 @@ public final class NBTInputStream implements Closeable {
/** /**
* Reads an NBT from the stream. * Reads an NBT from the stream.
* *
* @param depth * @param depth the depth of this tag
* the depth of this tag
* @return The tag that was read. * @return The tag that was read.
* @throws IOException * @throws IOException if an I/O error occurs.
* 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;
@ -66,8 +82,7 @@ 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 = "";
} }
@ -77,23 +92,18 @@ 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 * @param type the type
* the type * @param name the name
* @param name * @param depth the depth
* the name
* @param depth
* the depth
* @return the tag * @return the tag
* @throws IOException * @throws IOException if an I/O error occurs.
* 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:
@ -138,8 +148,7 @@ 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);
} }
} }

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
import java.io.Closeable; import java.io.Closeable;
@ -11,7 +32,7 @@ import java.util.List;
* This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong> * This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
* <code>Tag</code> objects to an underlying <code>OutputStream</code>. * <code>Tag</code> objects to an underlying <code>OutputStream</code>.
* </p> * </p>
* * <p/>
* <p> * <p>
* The NBT format was created by Markus Persson, and the specification may be * The NBT format was created by Markus Persson, and the specification may be
* found at <a href="http://www.minecraft.net/docs/NBT.txt"> * found at <a href="http://www.minecraft.net/docs/NBT.txt">
@ -19,7 +40,6 @@ import java.util.List;
* </p> * </p>
* *
* @author Graham Edgecombe * @author Graham Edgecombe
*
*/ */
public final class NBTOutputStream implements Closeable { public final class NBTOutputStream implements Closeable {
@ -32,10 +52,8 @@ 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 * @param os The output stream.
* The output stream. * @throws IOException if an I/O error occurs.
* @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);
@ -44,10 +62,8 @@ public final class NBTOutputStream implements Closeable {
/** /**
* Writes a tag. * Writes a tag.
* *
* @param tag * @param tag The tag to write.
* The tag to write. * @throws IOException if an I/O error occurs.
* @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());
@ -68,10 +84,8 @@ public final class NBTOutputStream implements Closeable {
/** /**
* Writes tag payload. * Writes tag payload.
* *
* @param tag * @param tag The tag.
* The tag. * @throws IOException if an I/O error occurs.
* @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());
@ -120,10 +134,8 @@ public final class NBTOutputStream implements Closeable {
/** /**
* Writes a <code>TAG_Byte</code> tag. * Writes a <code>TAG_Byte</code> tag.
* *
* @param tag * @param tag The tag.
* The tag. * @throws IOException if an I/O error occurs.
* @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());
@ -132,10 +144,8 @@ public final class NBTOutputStream implements Closeable {
/** /**
* Writes a <code>TAG_Byte_Array</code> tag. * Writes a <code>TAG_Byte_Array</code> tag.
* *
* @param tag * @param tag The tag.
* The tag. * @throws IOException if an I/O error occurs.
* @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();
@ -146,10 +156,8 @@ public final class NBTOutputStream implements Closeable {
/** /**
* Writes a <code>TAG_Compound</code> tag. * Writes a <code>TAG_Compound</code> tag.
* *
* @param tag * @param tag The tag.
* The tag. * @throws IOException if an I/O error occurs.
* @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()) {
@ -161,10 +169,8 @@ public final class NBTOutputStream implements Closeable {
/** /**
* Writes a <code>TAG_List</code> tag. * Writes a <code>TAG_List</code> tag.
* *
* @param tag * @param tag The tag.
* The tag. * @throws IOException if an I/O error occurs.
* @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();
@ -181,10 +187,8 @@ public final class NBTOutputStream implements Closeable {
/** /**
* Writes a <code>TAG_String</code> tag. * Writes a <code>TAG_String</code> tag.
* *
* @param tag * @param tag The tag.
* The tag. * @throws IOException if an I/O error occurs.
* @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);
@ -195,10 +199,8 @@ public final class NBTOutputStream implements Closeable {
/** /**
* Writes a <code>TAG_Double</code> tag. * Writes a <code>TAG_Double</code> tag.
* *
* @param tag * @param tag The tag.
* The tag. * @throws IOException if an I/O error occurs.
* @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());
@ -207,10 +209,8 @@ public final class NBTOutputStream implements Closeable {
/** /**
* Writes a <code>TAG_Float</code> tag. * Writes a <code>TAG_Float</code> tag.
* *
* @param tag * @param tag The tag.
* The tag. * @throws IOException if an I/O error occurs.
* @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,10 +219,8 @@ public final class NBTOutputStream implements Closeable {
/** /**
* Writes a <code>TAG_Long</code> tag. * Writes a <code>TAG_Long</code> tag.
* *
* @param tag * @param tag The tag.
* The tag. * @throws IOException if an I/O error occurs.
* @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());
@ -231,10 +229,8 @@ public final class NBTOutputStream implements Closeable {
/** /**
* Writes a <code>TAG_Int</code> tag. * Writes a <code>TAG_Int</code> tag.
* *
* @param tag * @param tag The tag.
* The tag. * @throws IOException if an I/O error occurs.
* @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());
@ -243,10 +239,8 @@ public final class NBTOutputStream implements Closeable {
/** /**
* Writes a <code>TAG_Short</code> tag. * Writes a <code>TAG_Short</code> tag.
* *
* @param tag * @param tag The tag.
* The tag. * @throws IOException if an I/O error occurs.
* @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());
@ -255,10 +249,8 @@ public final class NBTOutputStream implements Closeable {
/** /**
* Writes a <code>TAG_Empty</code> tag. * Writes a <code>TAG_Empty</code> tag.
* *
* @param tag * @param tag The tag.
* The tag. * @throws IOException if an I/O error occurs.
* @throws IOException
* if an I/O error occurs.
*/ */
private void writeEndTagPayload(final EndTag tag) { private void writeEndTagPayload(final EndTag tag) {
/* empty */ /* empty */

View File

@ -1,10 +1,30 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
import java.util.Map; import java.util.Map;
/** /**
* A class which contains NBT-related utility methods. * A class which contains NBT-related utility methods.
*
*/ */
public final class NBTUtils { public final class NBTUtils {
@ -17,48 +37,35 @@ public final class NBTUtils {
/** /**
* Gets the type name of a tag. * Gets the type name of a tag.
* *
* @param clazz * @param clazz the tag class
* 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() + ").");
} }
} }
@ -66,50 +73,36 @@ public final class NBTUtils {
/** /**
* Gets the type code of a tag class. * Gets the type code of a tag class.
* *
* @param clazz * @param clazz the tag class
* the tag class
* @return The type code. * @return The type code.
* @throws IllegalArgumentException * @throws IllegalArgumentException if the tag class is invalid.
* 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() + ").");
} }
} }
@ -117,11 +110,9 @@ public final class NBTUtils {
/** /**
* Gets the class of a type of tag. * Gets the class of a type of tag.
* *
* @param type * @param type the type
* the type
* @return The class. * @return The class.
* @throws IllegalArgumentException * @throws IllegalArgumentException if the tag type is invalid.
* 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) {
@ -157,12 +148,9 @@ public final class NBTUtils {
/** /**
* Get child tag of a NBT structure. * Get child tag of a NBT structure.
* *
* @param items * @param items the map to read from
* the map to read from * @param key the key to look for
* @param key * @param expected the expected NBT class type
* the key to look for
* @param expected
* the expected NBT class type
* @return child tag * @return child tag
* @throws InvalidFormatException * @throws InvalidFormatException
*/ */

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
/** /**
@ -10,8 +31,7 @@ public final class ShortTag extends Tag {
/** /**
* Creates the tag with an empty name. * Creates the tag with an empty name.
* *
* @param value * @param value the value of the tag
* the value of the tag
*/ */
public ShortTag(final short value) { public ShortTag(final short value) {
super(); super();
@ -21,10 +41,8 @@ public final class ShortTag extends Tag {
/** /**
* Creates the tag. * Creates the tag.
* *
* @param name * @param name the name of the tag
* the name of the tag * @param value the value 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);

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -12,8 +33,7 @@ public final class StringTag extends Tag {
/** /**
* Creates the tag with an empty name. * Creates the tag with an empty name.
* *
* @param value * @param value the value of the tag
* the value of the tag
*/ */
public StringTag(final String value) { public StringTag(final String value) {
super(); super();
@ -24,10 +44,8 @@ public final class StringTag extends Tag {
/** /**
* Creates the tag. * Creates the tag.
* *
* @param name * @param name the name of the tag
* the name of the tag * @param value the value 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);

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
/** /**
@ -17,8 +38,7 @@ public abstract class Tag {
/** /**
* Creates the tag with the specified name. * Creates the tag with the specified name.
* *
* @param name * @param name the name
* the name
*/ */
Tag(String name) { Tag(String name) {
if (name == null) { if (name == null) {

View File

@ -1,14 +1,28 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.jnbt; package com.intellectualcrafters.jnbt;
import org.bukkit.World; import org.bukkit.World;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitUtil;
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) {

View File

@ -1,42 +1,39 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
/*
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/** /**
* This provides static methods to convert comma delimited text into a * This provides static methods to convert comma delimited text into a
* JSONArray, and to covert a JSONArray into comma delimited text. Comma * JSONArray, and to covert a JSONArray into comma delimited text. Comma
* delimited text is a very popular format for data interchange. It is * delimited text is a very popular format for data interchange. It is
* understood by most database, spreadsheet, and organizer programs. * understood by most database, spreadsheet, and organizer programs.
* <p> * <p/>
* Each row of text represents a row in a table or a data record. Each row ends * Each row of text represents a row in a table or a data record. Each row ends
* with a NEWLINE character. Each row contains one or more values. Values are * with a NEWLINE character. Each row contains one or more values. Values are
* separated by commas. A value can contain any character except for comma, * separated by commas. A value can contain any character except for comma,
* unless is is wrapped in single quotes or double quotes. * unless is is wrapped in single quotes or double quotes.
* <p> * <p/>
* The first row usually contains the names of the columns. * The first row usually contains the names of the columns.
* <p> * <p/>
* A comma delimited list can be converted into a JSONArray of JSONObjects. The * A comma delimited list can be converted into a JSONArray of JSONObjects. The
* names for the elements in the JSONObjects can be taken from the names in the * names for the elements in the JSONObjects can be taken from the names in the
* first row. * first row.
@ -50,11 +47,9 @@ 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 * @param x A JSONTokener of the source text.
* A JSONTokener of the source text.
* @return The value string, or null if empty. * @return The value string, or null if empty.
* @throws JSONException * @throws JSONException if the quoted string is badly formed.
* 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;
@ -71,7 +66,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;
@ -94,21 +89,20 @@ 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 * @param x A JSONTokener of the source text.
* 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;
} }
@ -127,13 +121,11 @@ 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 * @param names A JSONArray of names. This is commonly obtained from the
* A JSONArray of names. This is commonly obtained from the * first row of a comma delimited text file using the
* first row of a comma delimited text file using the * rowToJSONArray
* rowToJSONArray * method.
* method. * @param x A JSONTokener of the source text.
* @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
*/ */
@ -147,8 +139,7 @@ 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 * @param ja A JSONArray of strings.
* 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) {
@ -170,8 +161,7 @@ public class CDL {
} }
} }
sb.append('"'); sb.append('"');
} } else {
else {
sb.append(string); sb.append(string);
} }
} }
@ -184,8 +174,7 @@ 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 * @param string The comma delimited text.
* The comma delimited text.
* @return A JSONArray of JSONObjects. * @return A JSONArray of JSONObjects.
* @throws JSONException * @throws JSONException
*/ */
@ -197,8 +186,7 @@ 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 * @param x The JSONTokener containing the comma delimited text.
* The JSONTokener containing the comma delimited text.
* @return A JSONArray of JSONObjects. * @return A JSONArray of JSONObjects.
* @throws JSONException * @throws JSONException
*/ */
@ -210,10 +198,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 a supplied JSONArray as the source of element names. * using a supplied JSONArray as the source of element names.
* *
* @param names * @param names A JSONArray of strings.
* A JSONArray of strings. * @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
*/ */
@ -225,10 +211,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 a supplied JSONArray as the source of element names. * using a supplied JSONArray as the source of element names.
* *
* @param names * @param names A JSONArray of strings.
* A JSONArray of strings. * @param x A JSONTokener of the source text.
* @param x
* A JSONTokener of the source text.
* @return A JSONArray of JSONObjects. * @return A JSONArray of JSONObjects.
* @throws JSONException * @throws JSONException
*/ */
@ -237,7 +221,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;
@ -255,8 +239,7 @@ 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 * @param ja A JSONArray of JSONObjects.
* A JSONArray of JSONObjects.
* @return A comma delimited text. * @return A comma delimited text.
* @throws JSONException * @throws JSONException
*/ */
@ -276,10 +259,8 @@ 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 * @param names A JSONArray of strings.
* A JSONArray of strings. * @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
*/ */

View File

@ -1,29 +1,26 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
/*
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/** /**
* Convert a web browser cookie specification to a JSONObject and back. * Convert a web browser cookie specification to a JSONObject and back.
* JSON and Cookies are both notations for name/value pairs. * JSON and Cookies are both notations for name/value pairs.
@ -43,8 +40,7 @@ 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 * @param string The source 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) {
@ -58,8 +54,7 @@ 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);
} }
} }
@ -77,10 +72,9 @@ 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 * @param string The cookie specification 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 {
@ -97,12 +91,10 @@ 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();
} }
@ -118,8 +110,7 @@ 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 * @param jo A JSONObject
* A JSONObject
* @return A cookie specification string * @return A cookie specification string
* @throws JSONException * @throws JSONException
*/ */
@ -151,10 +142,9 @@ 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 * @param string A string that may contain <code>+</code>
* A string that may contain <code>+</code> * &nbsp;<small>(plus)</small> and <code>%</code><i>hh</i>
* &nbsp;<small>(plus)</small> and <code>%</code><i>hh</i> * sequences.
* sequences.
* @return The unescaped string. * @return The unescaped string.
*/ */
public static String unescape(final String string) { public static String unescape(final String string) {
@ -164,8 +154,7 @@ 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)) {

View File

@ -1,29 +1,26 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
/*
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import java.util.Iterator; import java.util.Iterator;
/** /**
@ -39,13 +36,12 @@ public class CookieList {
* of name/value pairs. The names are separated from the values by '='. * of name/value pairs. The names are separated from the values by '='.
* The pairs are separated by ';'. The names and the values * The pairs are separated by ';'. The names and the values
* will be unescaped, possibly converting '+' and '%' sequences. * will be unescaped, possibly converting '+' and '%' sequences.
* * <p/>
* To add a cookie to a cooklist, * To add a cookie to a cooklist,
* cookielistJSONObject.put(cookieJSONObject.getString("name"), * cookielistJSONObject.put(cookieJSONObject.getString("name"),
* cookieJSONObject.getString("value")); * cookieJSONObject.getString("value"));
* *
* @param string * @param string A cookie list string
* A cookie list string
* @return A JSONObject * @return A JSONObject
* @throws JSONException * @throws JSONException
*/ */
@ -67,8 +63,7 @@ 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 * @param jo A JSONObject
* A JSONObject
* @return A cookie list string * @return A cookie list string
* @throws JSONException * @throws JSONException
*/ */

View File

@ -1,29 +1,26 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
/*
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import java.util.Iterator; import java.util.Iterator;
/** /**
@ -34,13 +31,15 @@ import java.util.Iterator;
*/ */
public class HTTP { public class HTTP {
/** Carriage return/line feed. */ /**
* Carriage return/line feed.
*/
public static final String CRLF = "\r\n"; public static final String CRLF = "\r\n";
/** /**
* 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/>
* <pre> * <pre>
* { * {
* Method: "POST" (for example), * Method: "POST" (for example),
@ -48,9 +47,9 @@ public class HTTP {
* "HTTP-Version": "HTTP/1.1" (for example) * "HTTP-Version": "HTTP/1.1" (for example)
* } * }
* </pre> * </pre>
* * <p/>
* A response header will contain * A response header will contain
* * <p/>
* <pre> * <pre>
* { * {
* "HTTP-Version": "HTTP/1.1" (for example), * "HTTP-Version": "HTTP/1.1" (for example),
@ -58,18 +57,18 @@ public class HTTP {
* "Reason-Phrase": "OK" (for example) * "Reason-Phrase": "OK" (for example)
* } * }
* </pre> * </pre>
* * <p/>
* 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/>
* <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
* Cache-Control: no-cache * Cache-Control: no-cache
* </pre> * </pre>
* * <p/>
* become * become
* * <p/>
* <pre> * <pre>
* {... * {...
* Date: "Sun, 26 May 2002 18:06:04 GMT", * Date: "Sun, 26 May 2002 18:06:04 GMT",
@ -77,14 +76,13 @@ public class HTTP {
* "Cache-Control": "no-cache", * "Cache-Control": "no-cache",
* ...} * ...}
* </pre> * </pre>
* * <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 does not do '%' transforms on URLs. * It does not do '%' transforms on URLs.
* *
* @param string * @param string An HTTP header 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 {
@ -102,8 +100,7 @@ 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
@ -125,7 +122,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/>
* <pre> * <pre>
* { * {
* Method: "POST" (for example), * Method: "POST" (for example),
@ -133,9 +130,9 @@ public class HTTP {
* "HTTP-Version": "HTTP/1.1" (for example) * "HTTP-Version": "HTTP/1.1" (for example)
* } * }
* </pre> * </pre>
* * <p/>
* A response header must contain * A response header must contain
* * <p/>
* <pre> * <pre>
* { * {
* "HTTP-Version": "HTTP/1.1" (for example), * "HTTP-Version": "HTTP/1.1" (for example),
@ -143,16 +140,14 @@ public class HTTP {
* "Reason-Phrase": "OK" (for example) * "Reason-Phrase": "OK" (for example)
* } * }
* </pre> * </pre>
* * <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 result will end with two CRLF pairs. * The result will end with two CRLF pairs.
* *
* @param jo * @param jo A JSONObject
* A JSONObject
* @return An HTTP header string. * @return An HTTP header string.
* @throws JSONException * @throws JSONException if the object does not contain enough
* if the object does not contain enough * information.
* 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();
@ -164,8 +159,7 @@ 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('"');
@ -173,8 +167,7 @@ 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);

View File

@ -1,29 +1,26 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
/*
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/** /**
* The HTTPTokener extends the JSONTokener to provide additional methods * The HTTPTokener extends the JSONTokener to provide additional methods
* for the parsing of HTTP headers. * for the parsing of HTTP headers.
@ -36,8 +33,7 @@ public class HTTPTokener extends JSONTokener {
/** /**
* Construct an HTTPTokener from a string. * Construct an HTTPTokener from a string.
* *
* @param string * @param string A source string.
* A source string.
*/ */
public HTTPTokener(final String string) { public HTTPTokener(final String string) {
super(string); super(string);
@ -46,8 +42,8 @@ public class HTTPTokener extends JSONTokener {
/** /**
* Get the next token or string. This is used in parsing HTTP headers. * Get the next token or string. This is used in parsing HTTP headers.
* *
* @throws JSONException
* @return A String. * @return A String.
* @throws JSONException
*/ */
public String nextToken() throws JSONException { public String nextToken() throws JSONException {
char c; char c;
@ -59,7 +55,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.");
@ -70,7 +66,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();
} }

View File

@ -1,29 +1,26 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
/*
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
@ -42,20 +39,20 @@ import java.util.Map;
* <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>, * <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>,
* <code>Number</code>, <code>String</code>, or the * <code>Number</code>, <code>String</code>, or the
* <code>JSONObject.NULL object</code>. * <code>JSONObject.NULL object</code>.
* <p> * <p/>
* The constructor can convert a JSON text into a Java object. The * The constructor can convert a JSON text into a Java object. The
* <code>toString</code> method converts to JSON text. * <code>toString</code> method converts to JSON text.
* <p> * <p/>
* A <code>get</code> method returns a value if one can be found, and throws an * A <code>get</code> method returns a value if one can be found, and throws an
* exception if one cannot be found. An <code>opt</code> method returns a * exception if one cannot be found. An <code>opt</code> method returns a
* default value instead of throwing an exception, and so is useful for * default value instead of throwing an exception, and so is useful for
* obtaining optional values. * obtaining optional values.
* <p> * <p/>
* The generic <code>get()</code> and <code>opt()</code> methods return an * The generic <code>get()</code> and <code>opt()</code> methods return an
* object which you can cast or query for type. There are also typed * object which you can cast or query for type. There are also typed
* <code>get</code> and <code>opt</code> methods that do type checking and type * <code>get</code> and <code>opt</code> methods that do type checking and type
* coercion for you. * coercion for you.
* <p> * <p/>
* The texts produced by the <code>toString</code> methods strictly conform to * The texts produced by the <code>toString</code> methods strictly conform to
* JSON syntax rules. The constructors are more forgiving in the texts they will * JSON syntax rules. The constructors are more forgiving in the texts they will
* accept: * accept:
@ -94,10 +91,8 @@ public class JSONArray {
/** /**
* Construct a JSONArray from a JSONTokener. * Construct a JSONArray from a JSONTokener.
* *
* @param x * @param x A JSONTokener
* A JSONTokener * @throws JSONException If there is a syntax error.
* @throws JSONException
* If there is a syntax error.
*/ */
public JSONArray(final JSONTokener x) throws JSONException { public JSONArray(final JSONTokener x) throws JSONException {
this(); this();
@ -106,12 +101,11 @@ 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());
} }
@ -134,12 +128,10 @@ public class JSONArray {
/** /**
* Construct a JSONArray from a source JSON text. * Construct a JSONArray from a source JSON text.
* *
* @param source * @param source A string that begins with <code>[</code>&nbsp;<small>(left
* A string that begins with <code>[</code>&nbsp;<small>(left * bracket)</small> and ends with <code>]</code>
* bracket)</small> and ends with <code>]</code> * &nbsp;<small>(right bracket)</small>.
* &nbsp;<small>(right bracket)</small>. * @throws JSONException If there is a syntax error.
* @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));
@ -148,8 +140,7 @@ public class JSONArray {
/** /**
* Construct a JSONArray from a Collection. * Construct a JSONArray from a Collection.
* *
* @param collection * @param collection A 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>();
@ -164,8 +155,7 @@ public class JSONArray {
/** /**
* Construct a JSONArray from an array * Construct a JSONArray from an array
* *
* @throws JSONException * @throws JSONException If not an array.
* If not an array.
*/ */
public JSONArray(final Object array) throws JSONException { public JSONArray(final Object array) throws JSONException {
this(); this();
@ -174,8 +164,7 @@ 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.");
} }
} }
@ -183,11 +172,9 @@ public class JSONArray {
/** /**
* Get the object value associated with an index. * Get the object value associated with an index.
* *
* @param index * @param index The index must be between 0 and length() - 1.
* The index must be between 0 and length() - 1.
* @return An object value. * @return An object value.
* @throws JSONException * @throws JSONException If there is no value for the index.
* 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);
@ -201,19 +188,16 @@ 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 * @param index The index must be between 0 and length() - 1.
* The index must be between 0 and length() - 1.
* @return The truth. * @return The truth.
* @throws JSONException * @throws JSONException If there is no value for the index or if the value is not
* If there is no value for the index or if the value is not * convertible to boolean.
* 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.");
@ -222,19 +206,16 @@ public class JSONArray {
/** /**
* Get the double value associated with an index. * Get the double value associated with an index.
* *
* @param index * @param index The index must be between 0 and length() - 1.
* The index must be between 0 and length() - 1.
* @return The value. * @return The value.
* @throws JSONException * @throws JSONException If the key is not found or if the value cannot be converted
* If the key is not found or if the value cannot be converted * to a number.
* 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.");
} }
} }
@ -242,18 +223,15 @@ public class JSONArray {
/** /**
* Get the int value associated with an index. * Get the int value associated with an index.
* *
* @param index * @param index The index must be between 0 and length() - 1.
* The index must be between 0 and length() - 1.
* @return The value. * @return The value.
* @throws JSONException * @throws JSONException If the key is not found or if the value is not a number.
* 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.");
} }
} }
@ -261,12 +239,10 @@ public class JSONArray {
/** /**
* Get the JSONArray associated with an index. * Get the JSONArray associated with an index.
* *
* @param index * @param index The index must be between 0 and length() - 1.
* The index must be between 0 and length() - 1.
* @return A JSONArray value. * @return A JSONArray value.
* @throws JSONException * @throws JSONException If there is no value for the index. or if the value is not a
* If there is no value for the index. or if the value is not a * JSONArray
* 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);
@ -279,12 +255,10 @@ public class JSONArray {
/** /**
* Get the JSONObject associated with an index. * Get the JSONObject associated with an index.
* *
* @param index * @param index subscript
* subscript
* @return A JSONObject value. * @return A JSONObject value.
* @throws JSONException * @throws JSONException If there is no value for the index or if the value is not a
* If there is no value for the index or if the value is not a * JSONObject
* 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);
@ -297,19 +271,16 @@ public class JSONArray {
/** /**
* Get the long value associated with an index. * Get the long value associated with an index.
* *
* @param index * @param index The index must be between 0 and length() - 1.
* The index must be between 0 and length() - 1.
* @return The value. * @return The value.
* @throws JSONException * @throws JSONException If the key is not found or if the value cannot be converted
* If the key is not found or if the value cannot be converted * to a number.
* 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.");
} }
} }
@ -317,11 +288,9 @@ public class JSONArray {
/** /**
* Get the string associated with an index. * Get the string associated with an index.
* *
* @param index * @param index The index must be between 0 and length() - 1.
* The index must be between 0 and length() - 1.
* @return A string value. * @return A string value.
* @throws JSONException * @throws JSONException If there is no string value for the index.
* 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);
@ -334,8 +303,7 @@ public class JSONArray {
/** /**
* Determine if the value is null. * Determine if the value is null.
* *
* @param index * @param index The index must be between 0 and length() - 1.
* 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) {
@ -347,11 +315,9 @@ 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 * @param separator A string that will be inserted between the elements.
* A string that will be inserted between the elements.
* @return a string. * @return a string.
* @throws JSONException * @throws JSONException If the array contains an invalid number.
* 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();
@ -378,8 +344,7 @@ public class JSONArray {
/** /**
* Get the optional object value associated with an index. * Get the optional object value associated with an index.
* *
* @param index * @param index The index must be between 0 and length() - 1.
* 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) {
@ -391,8 +356,7 @@ 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 * @param index The index must be between 0 and length() - 1.
* 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) {
@ -404,17 +368,14 @@ 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 * @param index The index must be between 0 and length() - 1.
* The index must be between 0 and length() - 1. * @param defaultValue A boolean default.
* @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;
} }
} }
@ -424,8 +385,7 @@ 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 * @param index The index must be between 0 and length() - 1.
* 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) {
@ -437,17 +397,14 @@ 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 * @param index subscript
* subscript * @param defaultValue The default value.
* @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;
} }
} }
@ -457,8 +414,7 @@ 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 * @param index The index must be between 0 and length() - 1.
* 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) {
@ -470,17 +426,14 @@ 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 * @param index The index must be between 0 and length() - 1.
* The index must be between 0 and length() - 1. * @param defaultValue The default value.
* @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;
} }
} }
@ -488,10 +441,9 @@ public class JSONArray {
/** /**
* Get the optional JSONArray associated with an index. * Get the optional JSONArray associated with an index.
* *
* @param index * @param index subscript
* 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);
@ -503,8 +455,7 @@ 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 * @param index The index must be between 0 and length() - 1.
* 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) {
@ -517,8 +468,7 @@ 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 * @param index The index must be between 0 and length() - 1.
* 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) {
@ -530,17 +480,14 @@ 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 * @param index The index must be between 0 and length() - 1.
* The index must be between 0 and length() - 1. * @param defaultValue The default value.
* @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;
} }
} }
@ -550,8 +497,7 @@ 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 * @param index The index must be between 0 and length() - 1.
* 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) {
@ -562,10 +508,8 @@ 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 * @param index The index must be between 0 and length() - 1.
* The index must be between 0 and length() - 1. * @param defaultValue The default value.
* @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) {
@ -576,8 +520,7 @@ 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 * @param value A boolean value.
* A boolean value.
* @return this. * @return this.
*/ */
public JSONArray put(final boolean value) { public JSONArray put(final boolean value) {
@ -589,8 +532,7 @@ 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 * @param value A Collection value.
* A Collection value.
* @return this. * @return this.
*/ */
public JSONArray put(final Collection<Object> value) { public JSONArray put(final Collection<Object> value) {
@ -601,11 +543,9 @@ 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 * @param value A double value.
* A double value.
* @throws JSONException
* if the value is not finite.
* @return this. * @return this.
* @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 = new Double(value); final Double d = new Double(value);
@ -617,8 +557,7 @@ 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 * @param value An int value.
* An int value.
* @return this. * @return this.
*/ */
public JSONArray put(final int value) { public JSONArray put(final int value) {
@ -629,8 +568,7 @@ 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 * @param value A long value.
* A long value.
* @return this. * @return this.
*/ */
public JSONArray put(final long value) { public JSONArray put(final long value) {
@ -642,8 +580,7 @@ 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 * @param value A Map value.
* A Map value.
* @return this. * @return this.
*/ */
public JSONArray put(final Map<String, Object> value) { public JSONArray put(final Map<String, Object> value) {
@ -654,10 +591,9 @@ 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 * @param value An object value. The value should be a Boolean, Double,
* An object value. The value should be a Boolean, Double, * Integer, JSONArray, JSONObject, Long, or String, or the
* Integer, JSONArray, JSONObject, Long, or String, or the * JSONObject.NULL object.
* JSONObject.NULL object.
* @return this. * @return this.
*/ */
public JSONArray put(final Object value) { public JSONArray put(final Object value) {
@ -670,13 +606,10 @@ 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 * @param index The subscript.
* The subscript. * @param value A boolean value.
* @param value
* A boolean value.
* @return this. * @return this.
* @throws JSONException * @throws JSONException If the index is negative.
* 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);
@ -687,13 +620,10 @@ 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 * @param index The subscript.
* The subscript. * @param value A Collection value.
* @param value
* A Collection value.
* @return this. * @return this.
* @throws JSONException * @throws JSONException If the index is negative or if the value is not finite.
* 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));
@ -705,13 +635,10 @@ 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 * @param index The subscript.
* The subscript. * @param value A double value.
* @param value
* A double value.
* @return this. * @return this.
* @throws JSONException * @throws JSONException If the index is negative or if the value is not finite.
* 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));
@ -723,13 +650,10 @@ 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 * @param index The subscript.
* The subscript. * @param value An int value.
* @param value
* An int value.
* @return this. * @return this.
* @throws JSONException * @throws JSONException If the index is negative.
* 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));
@ -741,13 +665,10 @@ 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 * @param index The subscript.
* The subscript. * @param value A long value.
* @param value
* A long value.
* @return this. * @return this.
* @throws JSONException * @throws JSONException If the index is negative.
* 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));
@ -758,14 +679,11 @@ 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 * @param index The subscript.
* The subscript. * @param value The Map value.
* @param value
* The Map value.
* @return this. * @return this.
* @throws JSONException * @throws JSONException If the index is negative or if the the value is an invalid
* If the index is negative or if the the value is an invalid * number.
* 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));
@ -777,16 +695,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 * @param index The subscript.
* The subscript. * @param value The value to put into the array. The value should be a
* @param value * Boolean, Double, Integer, JSONArray, JSONObject, Long, or
* The value to put into the array. The value should be a * String, or the JSONObject.NULL object.
* Boolean, Double, Integer, JSONArray, JSONObject, Long, or
* String, or the JSONObject.NULL object.
* @return this. * @return this.
* @throws JSONException * @throws JSONException If the index is negative or if the the value is an invalid
* If the index is negative or if the the value is an invalid * number.
* 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);
@ -795,8 +710,7 @@ 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);
} }
@ -808,10 +722,9 @@ public class JSONArray {
/** /**
* Remove an index and close the hole. * Remove an index and close the hole.
* *
* @param index * @param index The index of the element to be removed.
* 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;
@ -821,8 +734,7 @@ 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 * @param other The other JSONArray
* 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) {
@ -840,13 +752,11 @@ 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;
} }
} }
@ -857,13 +767,11 @@ 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 * @param names A JSONArray containing a list of key strings. These will be
* A JSONArray containing a list of key strings. These will be * paired with the values.
* 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 * @throws JSONException If any of the names are null.
* 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)) {
@ -881,18 +789,17 @@ public class JSONArray {
* whitespace is added. If it is not possible to produce a syntactically * whitespace is added. If it is not possible to produce a syntactically
* correct JSON text then null will be returned instead. This could occur if * correct JSON text then null will be returned instead. This could occur if
* the array contains an invalid number. * the array contains an invalid number.
* <p> * <p/>
* 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;
} }
} }
@ -901,12 +808,11 @@ 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 * @param indentFactor The number of spaces to add to each level of indentation.
* 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>&nbsp;<small>(left * object, beginning with <code>[</code>&nbsp;<small>(left
* bracket)</small> and ending with <code>]</code> * bracket)</small> and ending with <code>]</code>
* &nbsp;<small>(right bracket)</small>. * &nbsp;<small>(right bracket)</small>.
* @throws JSONException * @throws JSONException
*/ */
public String toString(final int indentFactor) throws JSONException { public String toString(final int indentFactor) throws JSONException {
@ -919,7 +825,7 @@ public class JSONArray {
/** /**
* Write the contents of the JSONArray as JSON text to a writer. For * Write the contents of the JSONArray as JSON text to a writer. For
* compactness, no whitespace is added. * compactness, no whitespace is added.
* <p> * <p/>
* Warning: This method assumes that the data structure is acyclical. * Warning: This method assumes that the data structure is acyclical.
* *
* @return The writer. * @return The writer.
@ -932,13 +838,11 @@ public class JSONArray {
/** /**
* Write the contents of the JSONArray as JSON text to a writer. For * Write the contents of the JSONArray as JSON text to a writer. For
* compactness, no whitespace is added. * compactness, no whitespace is added.
* <p> * <p/>
* Warning: This method assumes that the data structure is acyclical. * Warning: This method assumes that the data structure is acyclical.
* *
* @param indentFactor * @param indentFactor The number of spaces to add to each level of indentation.
* The number of spaces to add to each level of indentation. * @param indent The indention of the top level.
* @param indent
* The indention of the top level.
* @return The writer. * @return The writer.
* @throws JSONException * @throws JSONException
*/ */
@ -950,8 +854,7 @@ 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) {
@ -972,8 +875,7 @@ 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);
} }
} }

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
/** /**
@ -8,13 +29,12 @@ 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 * @param message Detail about the reason for the exception.
* Detail about the reason for the exception.
*/ */
public JSONException(final String message) { public JSONException(final String message) {
super(message); super(message);
@ -23,8 +43,7 @@ public class JSONException extends RuntimeException {
/** /**
* Constructs a new JSONException with the specified cause. * Constructs a new JSONException with the specified cause.
* *
* @param cause * @param cause The cause.
* The cause.
*/ */
public JSONException(final Throwable cause) { public JSONException(final Throwable cause) {
super(cause.getMessage()); super(cause.getMessage());
@ -36,7 +55,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() {

View File

@ -1,29 +1,26 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
/*
Copyright (c) 2008 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import java.util.Iterator; import java.util.Iterator;
/** /**
@ -39,13 +36,10 @@ public class JSONML {
/** /**
* Parse XML values and store them in a JSONArray. * Parse XML values and store them in a JSONArray.
* *
* @param x * @param x The XMLTokener containing the source string.
* The XMLTokener containing the source string. * @param arrayForm true if array form, false if object form.
* @param arrayForm * @param ja The JSONArray that is containing the current tag or null
* true if array form, false if object form. * if we are at the outermost level.
* @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
*/ */
@ -85,8 +79,7 @@ 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) {
// <! // <!
@ -94,53 +87,44 @@ 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 + "'.");
} }
@ -152,15 +136,14 @@ 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();
} }
@ -185,8 +168,7 @@ 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, "");
} }
} }
@ -203,16 +185,14 @@ 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");
} }
@ -228,16 +208,14 @@ 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);
} }
@ -254,8 +232,7 @@ public class JSONML {
* JSONArrays will represent the child tags. * JSONArrays will represent the child tags.
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored. * Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
* *
* @param string * @param string The source 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
*/ */
@ -272,8 +249,7 @@ public class JSONML {
* JSONArrays will represent the child content and tags. * JSONArrays will represent the child content and tags.
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored. * Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
* *
* @param x * @param x An XMLTokener.
* 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
*/ */
@ -288,11 +264,10 @@ public class JSONML {
* the attributes will be in the JSONObject as properties. If the tag * the attributes will be in the JSONObject as properties. If the tag
* contains children, the object will have a "childNodes" property which * contains children, the object will have a "childNodes" property which
* will be an array of strings and JsonML JSONObjects. * will be an array of strings and JsonML JSONObjects.
* * <p/>
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored. * Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
* *
* @param x * @param x An XMLTokener of the XML source text.
* 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
*/ */
@ -307,11 +282,10 @@ public class JSONML {
* the attributes will be in the JSONObject as properties. If the tag * the attributes will be in the JSONObject as properties. If the tag
* contains children, the object will have a "childNodes" property which * contains children, the object will have a "childNodes" property which
* will be an array of strings and JsonML JSONObjects. * will be an array of strings and JsonML JSONObjects.
* * <p/>
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored. * Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
* *
* @param string * @param string The XML source text.
* 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
*/ */
@ -322,8 +296,7 @@ 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 * @param ja A JSONArray.
* A JSONArray.
* @return An XML string. * @return An XML string.
* @throws JSONException * @throws JSONException
*/ */
@ -367,8 +340,7 @@ public class JSONML {
sb.append('"'); sb.append('"');
} }
} }
} } else {
else {
i = 1; i = 1;
} }
@ -378,8 +350,7 @@ 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);
@ -387,11 +358,9 @@ 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));
} }
} }
@ -411,8 +380,7 @@ 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 * @param jo A JSONObject.
* A JSONObject.
* @return An XML string. * @return An XML string.
* @throws JSONException * @throws JSONException
*/ */
@ -463,8 +431,7 @@ 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) {
@ -472,14 +439,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));
} } else {
else {
sb.append(object.toString()); sb.append(object.toString());
} }
} }

View File

@ -1,29 +1,26 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
/*
Copyright (c) 2006 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import java.io.StringWriter; import java.io.StringWriter;
/** /**
@ -31,7 +28,7 @@ import java.io.StringWriter;
* The texts produced strictly conform to JSON syntax rules. No whitespace is * The texts produced strictly conform to JSON syntax rules. No whitespace is
* added, so the results are ready for transmission or storage. Each instance of * added, so the results are ready for transmission or storage. Each instance of
* JSONStringer can produce one JSON text. * JSONStringer can produce one JSON text.
* <p> * <p/>
* A JSONStringer instance provides a <code>value</code> method for appending * A JSONStringer instance provides a <code>value</code> method for appending
* values to the text, and a <code>key</code> method for adding keys before * values to the text, and a <code>key</code> method for adding keys before
* values in objects. There are <code>array</code> and <code>endArray</code> * values in objects. There are <code>array</code> and <code>endArray</code>
@ -39,21 +36,21 @@ import java.io.StringWriter;
* <code>endObject</code> methods which make and bound object values. All of * <code>endObject</code> methods which make and bound object values. All of
* these methods return the JSONWriter instance, permitting cascade style. For * these methods return the JSONWriter instance, permitting cascade style. For
* example, * example,
* * <p/>
* <pre> * <pre>
* myString = new JSONStringer().object().key(&quot;JSON&quot;).value(&quot;Hello, World!&quot;).endObject().toString(); * myString = new JSONStringer().object().key(&quot;JSON&quot;).value(&quot;Hello, World!&quot;).endObject().toString();
* </pre> * </pre>
* * <p/>
* which produces the string * which produces the string
* * <p/>
* <pre> * <pre>
* {"JSON":"Hello, World!"} * {"JSON":"Hello, World!"}
* </pre> * </pre>
* <p> * <p/>
* The first method called must be <code>array</code> or <code>object</code>. * The first method called must be <code>array</code> or <code>object</code>.
* There are no methods for adding commas or colons. JSONStringer adds them for * There are no methods for adding commas or colons. JSONStringer adds them for
* you. Objects and arrays can be nested up to 20 levels deep. * you. Objects and arrays can be nested up to 20 levels deep.
* <p> * <p/>
* This can sometimes be easier than using a JSONObject to build a string. * This can sometimes be easier than using a JSONObject to build a string.
* *
* @author JSON.org * @author JSON.org

View File

@ -1,35 +1,27 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
import java.io.BufferedReader; import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
/*
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/** /**
* A JSONTokener takes a source string and extracts characters and tokens from * A JSONTokener takes a source string and extracts characters and tokens from
@ -41,19 +33,18 @@ import java.io.StringReader;
*/ */
public class JSONTokener { public class JSONTokener {
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 final Reader reader; private final Reader reader;
private boolean usePrevious; private boolean usePrevious;
/** /**
* Construct a JSONTokener from a Reader. * Construct a JSONTokener from a Reader.
* *
* @param reader * @param reader A 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);
@ -68,8 +59,7 @@ public class JSONTokener {
/** /**
* Construct a JSONTokener from an InputStream. * Construct a JSONTokener from an InputStream.
* *
* @param inputStream * @param inputStream The source.
* The source.
*/ */
public JSONTokener(final InputStream inputStream) throws JSONException { public JSONTokener(final InputStream inputStream) throws JSONException {
this(new InputStreamReader(inputStream)); this(new InputStreamReader(inputStream));
@ -78,8 +68,7 @@ public class JSONTokener {
/** /**
* Construct a JSONTokener from a string. * Construct a JSONTokener from a string.
* *
* @param s * @param s A source string.
* A source string.
*/ */
public JSONTokener(final String s) { public JSONTokener(final String s) {
this(new StringReader(s)); this(new StringReader(s));
@ -103,9 +92,8 @@ public class JSONTokener {
/** /**
* Get the hex value of a character (base16). * Get the hex value of a character (base16).
* *
* @param c * @param c A character between '0' and '9' or between 'A' and 'F' or
* A character between '0' and '9' or between 'A' and 'F' or * between 'a' and 'f'.
* 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) {
@ -150,12 +138,10 @@ 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);
} }
@ -168,12 +154,10 @@ 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;
@ -184,11 +168,9 @@ 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 * @param c The character to match.
* The character to match.
* @return The character. * @return The character.
* @throws JSONException * @throws JSONException if the character does not match.
* 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();
@ -201,12 +183,10 @@ public class JSONTokener {
/** /**
* Get the next n characters. * Get the next n characters.
* *
* @param n * @param n The number of characters to take.
* The number of characters to take.
* @return A string of n characters. * @return A string of n characters.
* @throws JSONException * @throws JSONException Substring bounds error if there are not
* Substring bounds error if there are not * n characters remaining in the source string.
* 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) {
@ -229,11 +209,11 @@ public class JSONTokener {
/** /**
* Get the next char in the string, skipping whitespace. * Get the next char in the string, skipping whitespace.
* *
* @throws JSONException
* @return A character, or 0 if there are no more characters. * @return A character, or 0 if there are no more characters.
* @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;
@ -247,18 +227,16 @@ 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 * @param quote The quoting character, either <code>"</code>
* The quoting character, either <code>"</code> * &nbsp;<small>(double quote)</small> or <code>'</code>
* &nbsp;<small>(double quote)</small> or <code>'</code> * &nbsp;<small>(single quote)</small>.
* &nbsp;<small>(single quote)</small>.
* @return A String. * @return A String.
* @throws JSONException * @throws JSONException Unterminated string.
* 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:
@ -309,13 +287,12 @@ 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 * @param delimiter A delimiter character.
* 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) {
@ -331,14 +308,13 @@ 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 * @param delimiters A set of delimiter characters.
* 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) {
@ -354,10 +330,8 @@ public class JSONTokener {
* Get the next value. The value can be a Boolean, Double, Integer, * Get the next value. The value can be a Boolean, Double, Integer,
* JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object. * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
* *
* @throws JSONException
* If syntax error.
*
* @return An object. * @return An object.
* @throws JSONException If syntax error.
*/ */
public Object nextValue() throws JSONException { public Object nextValue() throws JSONException {
char c = this.nextClean(); char c = this.nextClean();
@ -401,10 +375,9 @@ 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 * @param to A character to skip 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;
@ -424,8 +397,7 @@ 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();
@ -435,8 +407,7 @@ public class JSONTokener {
/** /**
* Make a JSONException to signal a syntax error. * Make a JSONException to signal a syntax error.
* *
* @param message * @param message The error 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) {

View File

@ -1,38 +1,35 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
import java.io.IOException; import java.io.IOException;
import java.io.Writer; import java.io.Writer;
/*
Copyright (c) 2006 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/** /**
* JSONWriter provides a quick and convenient way of producing JSON text. * JSONWriter provides a quick and convenient way of producing JSON text.
* The texts produced strictly conform to JSON syntax rules. No whitespace is * The texts produced strictly conform to JSON syntax rules. No whitespace is
* added, so the results are ready for transmission or storage. Each instance of * added, so the results are ready for transmission or storage. Each instance of
* JSONWriter can produce one JSON text. * JSONWriter can produce one JSON text.
* <p> * <p/>
* A JSONWriter instance provides a <code>value</code> method for appending * A JSONWriter instance provides a <code>value</code> method for appending
* values to the text, and a <code>key</code> method for adding keys before * values to the text, and a <code>key</code> method for adding keys before
* values in objects. There are <code>array</code> and <code>endArray</code> * values in objects. There are <code>array</code> and <code>endArray</code>
@ -40,21 +37,21 @@ import java.io.Writer;
* <code>endObject</code> methods which make and bound object values. All of * <code>endObject</code> methods which make and bound object values. All of
* 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/>
* <pre> * <pre>
* new JSONWriter(myWriter).object().key(&quot;JSON&quot;).value(&quot;Hello, World!&quot;).endObject(); * new JSONWriter(myWriter).object().key(&quot;JSON&quot;).value(&quot;Hello, World!&quot;).endObject();
* </pre> * </pre>
* * <p/>
* which writes * which writes
* * <p/>
* <pre> * <pre>
* {"JSON":"Hello, World!"} * {"JSON":"Hello, World!"}
* </pre> * </pre>
* <p> * <p/>
* The first method called must be <code>array</code> or <code>object</code>. * The first method called must be <code>array</code> or <code>object</code>.
* There are no methods for adding commas or colons. JSONWriter adds them for * There are no methods for adding commas or colons. JSONWriter adds them for
* you. Objects and arrays can be nested up to 20 levels deep. * you. Objects and arrays can be nested up to 20 levels deep.
* <p> * <p/>
* This can sometimes be easier than using a JSONObject to build a string. * This can sometimes be easier than using a JSONObject to build a string.
* *
* @author JSON.org * @author JSON.org
@ -67,7 +64,7 @@ public class JSONWriter {
* 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 current mode. Values: * The current mode. Values:
@ -77,7 +74,7 @@ public class JSONWriter {
* 'k' (key), * 'k' (key),
* 'o' (object). * 'o' (object).
*/ */
protected char mode; protected char mode;
/** /**
* The object/array stack. * The object/array stack.
@ -87,12 +84,12 @@ public class JSONWriter {
/** /**
* 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;
/** /**
* The writer that will receive the output. * The writer that will receive the output.
*/ */
protected Writer writer; protected Writer writer;
/** /**
* 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.
@ -108,11 +105,9 @@ public class JSONWriter {
/** /**
* Append a value. * Append a value.
* *
* @param string * @param string A string value.
* A string value.
* @return this * @return this
* @throws JSONException * @throws JSONException If the value is out of sequence.
* 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) {
@ -124,8 +119,7 @@ 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') {
@ -143,11 +137,10 @@ 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 * @throws JSONException If the nesting is too deep, or if the object is
* If the nesting is too deep, or if the object is * started in the wrong place (for example as a key or after the
* started in the wrong place (for example as a key or after the * end of the
* end of the * outermost array or object).
* 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')) {
@ -162,13 +155,10 @@ public class JSONWriter {
/** /**
* End something. * End something.
* *
* @param mode * @param mode Mode
* Mode * @param c Closing character
* @param c
* Closing character
* @return this * @return this
* @throws JSONException * @throws JSONException If unbalanced.
* 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) {
@ -177,8 +167,7 @@ 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;
@ -190,8 +179,7 @@ public class JSONWriter {
* <code>array</code>. * <code>array</code>.
* *
* @return this * @return this
* @throws JSONException * @throws JSONException If incorrectly nested.
* If incorrectly nested.
*/ */
public JSONWriter endArray() throws JSONException { public JSONWriter endArray() throws JSONException {
return this.end('a', ']'); return this.end('a', ']');
@ -202,8 +190,7 @@ public class JSONWriter {
* <code>object</code>. * <code>object</code>.
* *
* @return this * @return this
* @throws JSONException * @throws JSONException If incorrectly nested.
* If incorrectly nested.
*/ */
public JSONWriter endObject() throws JSONException { public JSONWriter endObject() throws JSONException {
return this.end('k', '}'); return this.end('k', '}');
@ -213,12 +200,10 @@ 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 * @param string A key string.
* A key string.
* @return this * @return this
* @throws JSONException * @throws JSONException If the key is out of place. For example, keys
* If the key is out of place. For example, keys * do not belong in arrays or if the key is null.
* 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) {
@ -235,8 +220,7 @@ 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);
} }
} }
@ -249,11 +233,10 @@ 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 * @throws JSONException If the nesting is too deep, or if the object is
* If the nesting is too deep, or if the object is * started in the wrong place (for example as a key or after the
* started in the wrong place (for example as a key or after the * end of the
* end of the * outermost array or object).
* outermost array or object).
*/ */
public JSONWriter object() throws JSONException { public JSONWriter object() throws JSONException {
if (this.mode == 'i') { if (this.mode == 'i') {
@ -272,10 +255,8 @@ public class JSONWriter {
/** /**
* Pop an array or object scope. * Pop an array or object scope.
* *
* @param c * @param c The scope to close.
* The scope to close. * @throws JSONException If nesting is wrong.
* @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) {
@ -292,10 +273,8 @@ public class JSONWriter {
/** /**
* Push an array or object scope. * Push an array or object scope.
* *
* @param jo * @param jo The scope to open.
* The scope to open. * @throws JSONException If nesting is too deep.
* @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) {
@ -310,8 +289,7 @@ 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 * @param b A boolean.
* A boolean.
* @return this * @return this
* @throws JSONException * @throws JSONException
*/ */
@ -322,11 +300,9 @@ public class JSONWriter {
/** /**
* Append a double value. * Append a double value.
* *
* @param d * @param d A double.
* A double.
* @return this * @return this
* @throws JSONException * @throws JSONException If the number is not finite.
* 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));
@ -335,8 +311,7 @@ public class JSONWriter {
/** /**
* Append a long value. * Append a long value.
* *
* @param l * @param l A long.
* A long.
* @return this * @return this
* @throws JSONException * @throws JSONException
*/ */
@ -347,13 +322,11 @@ public class JSONWriter {
/** /**
* Append an object value. * Append an object value.
* *
* @param object * @param object The object to append. It can be null, or a Boolean, Number,
* The object to append. It can be null, or a Boolean, Number, * String, JSONObject, or JSONArray, or an object that implements
* String, JSONObject, or JSONArray, or an object that implements * JSONString.
* JSONString.
* @return this * @return this
* @throws JSONException * @throws JSONException If the value is out of sequence.
* 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));

View File

@ -1,29 +1,26 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
/*
Copyright (c) 2013 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/** /**
* Kim makes immutable eight bit Unicode strings. If the MSB of a byte is set, * Kim makes immutable eight bit Unicode strings. If the MSB of a byte is set,
* then the next byte is a continuation byte. The last byte of a character * then the next byte is a continuation byte. The last byte of a character
@ -31,16 +28,16 @@ package com.intellectualcrafters.json;
* set. Kim stands for "Keep it minimal". A Unicode character is never longer * set. Kim stands for "Keep it minimal". A Unicode character is never longer
* than 3 bytes. Every byte contributes 7 bits to the character. ASCII is * than 3 bytes. Every byte contributes 7 bits to the character. ASCII is
* unmodified. * unmodified.
* * <p/>
* Kim UTF-8 * Kim UTF-8
* one byte U+007F U+007F * one byte U+007F U+007F
* two bytes U+3FFF U+07FF * two bytes U+3FFF U+07FF
* three bytes U+10FFF U+FFFF * three bytes U+10FFF U+FFFF
* four bytes U+10FFFF * four bytes U+10FFFF
* * <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.
* * <p/>
* 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,
@ -50,10 +47,10 @@ package com.intellectualcrafters.json;
* Ol Chiki, Old Turkic, Oriya, Osmanya, Pahlavi, Parthian, Phags-Pa, * Ol Chiki, Old Turkic, Oriya, Osmanya, Pahlavi, Parthian, Phags-Pa,
* Phoenician, Samaritan, Sharada, Sinhala, Sora Sompeng, Tagalog, Tagbanwa, * Phoenician, Samaritan, Sharada, Sinhala, Sora Sompeng, Tagalog, Tagbanwa,
* Takri, Tai Le, Tai Tham, Tamil, Telugu, Thai, Tibetan, Tifinagh, UCAS. * Takri, Tai Le, Tai Tham, Tamil, Telugu, Thai, Tibetan, Tifinagh, UCAS.
* * <p/>
* A kim object can be constructed from an ordinary UTF-16 string, or from a * 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.
* * <p/>
* As with UTF-8, it is possible to detect character boundaries within a byte * As with UTF-8, it is possible to detect character boundaries within a byte
* sequence. UTF-8 is one of the world's great inventions. While Kim is more * sequence. UTF-8 is one of the world's great inventions. While Kim is more
* efficient, it is not clear that it is worth the expense of transition. * efficient, it is not clear that it is worth the expense of transition.
@ -65,33 +62,30 @@ public class Kim {
/** /**
* 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 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 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 * @param bytes A byte array.
* A byte array. * @param from The index of the first byte.
* @param from * @param thru The index of the last byte plus one.
* 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) {
@ -118,10 +112,8 @@ public class Kim {
/** /**
* Make a kim from a byte array. * Make a kim from a byte array.
* *
* @param bytes * @param bytes The byte array.
* The byte array. * @param length The number of bytes.
* @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);
@ -131,12 +123,9 @@ 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 * @param kim The source of bytes.
* The source of bytes. * @param from The point at which to take bytes.
* @param from * @param thru The point at which to stop taking bytes.
* 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);
@ -145,10 +134,8 @@ public class Kim {
/** /**
* Make a kim from a string. * Make a kim from a string.
* *
* @param string * @param string The string.
* The string. * @throws JSONException if surrogate pair mismatch.
* @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();
@ -163,11 +150,9 @@ 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);
@ -194,8 +179,7 @@ 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;
@ -206,8 +190,7 @@ 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;
@ -238,11 +221,9 @@ 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 * @param at the index of the char value. The first character is at 0.
* 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.
* @throws JSONException
* if at does not point to a valid character.
*/ */
public int characterAt(final int at) throws JSONException { public int characterAt(final int at) throws JSONException {
final int c = get(at); final int c = get(at);
@ -256,8 +237,7 @@ 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))) {
@ -271,11 +251,9 @@ 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 * @param character a Unicode character between 0 and 0x10FFFF.
* a Unicode character between 0 and 0x10FFFF.
* @return 1, 2, or 3 * @return 1, 2, or 3
* @throws JSONException * @throws JSONException if the character is not representable in a kim.
* 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)) {
@ -287,10 +265,8 @@ 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 * @param bytes A byte array of sufficient size.
* A byte array of sufficient size. * @param at The position within the byte array to take the byes.
* @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) {
@ -302,10 +278,9 @@ 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 * @param obj the other kim with which to compare.
* 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) {
@ -325,11 +300,9 @@ public class Kim {
/** /**
* Get a byte from a kim. * Get a byte from a kim.
* *
* @param at * @param at The position of the byte. The first byte is at 0.
* The position of the byte. The first byte is at 0.
* @return The byte. * @return The byte.
* @throws JSONException * @throws JSONException if there is no byte at that position.
* 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)) {
@ -352,8 +325,7 @@ 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 * @throws JSONException if the kim is not valid.
* if the kim is not valid.
*/ */
@Override @Override
public String toString() throws JSONException { public String toString() throws JSONException {
@ -366,8 +338,7 @@ 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));

View File

@ -1,29 +1,26 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
/*
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
@ -39,8 +36,7 @@ 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 * @param properties java.util.Properties
* java.util.Properties
* @return JSONObject * @return JSONObject
* @throws JSONException * @throws JSONException
*/ */
@ -59,8 +55,7 @@ public class Property {
/** /**
* Converts the JSONObject into a property file object. * Converts the JSONObject into a property file object.
* *
* @param jo * @param jo JSONObject
* JSONObject
* @return java.util.Properties * @return java.util.Properties
* @throws JSONException * @throws JSONException
*/ */

View File

@ -1,29 +1,26 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
/*
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import java.util.Iterator; import java.util.Iterator;
/** /**
@ -35,36 +32,54 @@ import java.util.Iterator;
*/ */
public class XML { public class XML {
/** The Character '&amp;'. */ /**
public static final Character AMP = '&'; * The Character '&amp;'.
*/
public static final Character AMP = '&';
/** The Character '''. */ /**
public static final Character APOS = '\''; * The Character '''.
*/
public static final Character APOS = '\'';
/** The Character '!'. */ /**
public static final Character BANG = '!'; * The Character '!'.
*/
public static final Character BANG = '!';
/** The Character '='. */ /**
public static final Character EQ = '='; * The Character '='.
*/
public static final Character EQ = '=';
/** The Character '>'. */ /**
public static final Character GT = '>'; * The Character '>'.
*/
public static final Character GT = '>';
/** The Character '&lt;'. */ /**
public static final Character LT = '<'; * The Character '&lt;'.
*/
public static final Character LT = '<';
/** The Character '?'. */ /**
* The Character '?'.
*/
public static final Character QUEST = '?'; public static final Character QUEST = '?';
/** The Character '"'. */ /**
public static final Character QUOT = '"'; * The Character '"'.
*/
public static final Character QUOT = '"';
/** The Character '/'. */ /**
* The Character '/'.
*/
public static final Character SLASH = '/'; public static final Character SLASH = '/';
/** /**
* Replace special characters with XML escapes: * Replace special characters with XML escapes:
* * <p/>
* <pre> * <pre>
* &amp; <small>(ampersand)</small> is replaced by &amp;amp; * &amp; <small>(ampersand)</small> is replaced by &amp;amp;
* &lt; <small>(less than)</small> is replaced by &amp;lt; * &lt; <small>(less than)</small> is replaced by &amp;lt;
@ -72,8 +87,7 @@ public class XML {
* &quot; <small>(double quote)</small> is replaced by &amp;quot; * &quot; <small>(double quote)</small> is replaced by &amp;quot;
* </pre> * </pre>
* *
* @param string * @param string The string to be escaped.
* 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) {
@ -107,8 +121,7 @@ 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 * @param string A 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 {
@ -127,12 +140,9 @@ 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 * @param x The XMLTokener containing the source string.
* The XMLTokener containing the source string. * @param context The JSONObject that will include the new material.
* @param context * @param name The tag name.
* 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
*/ */
@ -166,8 +176,7 @@ 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() == '[') {
@ -185,25 +194,21 @@ 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 </
@ -219,18 +224,16 @@ 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();
} }
@ -247,39 +250,34 @@ 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) {
else if (token == GT) { for (; ; ) {
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));
@ -287,24 +285,20 @@ 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");
} }
} }
@ -318,8 +312,7 @@ 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 * @param string A 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) {
@ -345,15 +338,13 @@ 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;
@ -370,8 +361,7 @@ 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>&lt;[ [ ]]></code> are ignored. * <code>&lt;[ [ ]]></code> are ignored.
* *
* @param string * @param string The source 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
*/ */
@ -387,8 +377,7 @@ 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 * @param object A JSONObject.
* A JSONObject.
* @return A string. * @return A string.
* @throws JSONException * @throws JSONException
*/ */
@ -399,10 +388,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 * @param object A JSONObject.
* A JSONObject. * @param tagName The optional name of the enclosing tag.
* @param tagName
* The optional name of the enclosing tag.
* @return A string. * @return A string.
* @throws JSONException * @throws JSONException
*/ */
@ -450,15 +437,13 @@ 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) {
@ -471,21 +456,18 @@ 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));
} }
} }
@ -503,8 +485,7 @@ 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);
} }
@ -515,8 +496,7 @@ 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 + ">";
} }

View File

@ -1,29 +1,26 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.json; package com.intellectualcrafters.json;
/*
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/** /**
* The XMLTokener extends the JSONTokener to provide additional methods * The XMLTokener extends the JSONTokener to provide additional methods
* for the parsing of XML texts. * for the parsing of XML texts.
@ -51,8 +48,7 @@ public class XMLTokener extends JSONTokener {
/** /**
* Construct an XMLTokener from a string. * Construct an XMLTokener from a string.
* *
* @param s * @param s A source string.
* A source string.
*/ */
public XMLTokener(final String s) { public XMLTokener(final String s) {
super(s); super(s);
@ -62,14 +58,13 @@ 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>]]&gt;</code>. * @return The string up to the <code>]]&gt;</code>.
* @throws JSONException * @throws JSONException If the <code>]]&gt;</code> is not found.
* If the <code>]]&gt;</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");
@ -88,7 +83,7 @@ public class XMLTokener extends JSONTokener {
* of tokens: the '<' character which begins a markup tag, and the content * of tokens: the '<' character which begins a markup tag, and the content
* text between markup tags. * text between markup tags.
* *
* @return A string, or a '<' Character, or null if there is no more * @return A string, or a '<' Character, or null if there is no more
* source text. * source text.
* @throws JSONException * @throws JSONException
*/ */
@ -106,15 +101,14 @@ 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();
@ -125,23 +119,19 @@ 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>&amp; &apos; &gt; &lt; &quot;</code>. * <code>&amp; &apos; &gt; &lt; &quot;</code>.
* *
* @param ampersand * @param ampersand An ampersand character.
* 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 * @throws JSONException If missing ';' in XML entity.
* 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);
} }
} }
@ -155,12 +145,11 @@ 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 * @throws JSONException If a string is not properly closed or if the XML
* If a string is not properly closed or if the XML * is badly structured.
* is badly structured.
*/ */
public Object nextMeta() throws JSONException { public Object nextMeta() throws JSONException {
char c; char c;
@ -187,7 +176,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");
@ -197,7 +186,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;
@ -226,8 +215,7 @@ public class XMLTokener extends JSONTokener {
* name. * name.
* *
* @return a String or a Character. * @return a String or a Character.
* @throws JSONException * @throws JSONException If the XML is not well formed.
* If the XML is not well formed.
*/ */
public Object nextToken() throws JSONException { public Object nextToken() throws JSONException {
char c; char c;
@ -253,13 +241,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");
@ -269,8 +257,7 @@ 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);
} }
} }
@ -279,7 +266,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)) {
@ -311,8 +298,7 @@ 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 * @param to A string to skip past.
* 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 {
@ -339,7 +325,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;

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -12,8 +33,7 @@ public class AbstractFlag {
/** /**
* AbstractFlag is a parameter used in creating a new Flag * AbstractFlag is a parameter used in creating a new Flag
* *
* @param key * @param key The key must be alphabetical characters and <= 16 characters
* The key must be alphabetical characters and <= 16 characters
* in length * in length
*/ */
public AbstractFlag(final String key) { public AbstractFlag(final String key) {

View File

@ -1,11 +1,32 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
public class BlockWrapper { public class BlockWrapper {
public int x; public int x;
public int y; public int y;
public int z; public int z;
public int id; public int id;
public byte data; public byte data;
public BlockWrapper(final int x, final int y, final int z, final short id, final byte data) { public BlockWrapper(final int x, final int y, final int z, final short id, final byte data) {

View File

@ -1,10 +1,23 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = C.java >> Generated by: Citymonstret at 2014-08-09 01:43 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
@ -360,15 +373,13 @@ public enum C {
/** /**
* Constructor * Constructor
* *
* @param d * @param d default
* default
*/ */
C(final String d) { C(final String d) {
this.d = d; this.d = d;
if (PlotMain.translations == null) { if (PlotMain.translations == null) {
this.s = d; this.s = d;
} } else {
else {
this.s = PlotMain.translations.getString(this.toString()); this.s = PlotMain.translations.getString(this.toString());
} }
if (this.s == null) { if (this.s == null) {

View File

@ -1,12 +1,33 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
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;
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;
@ -30,14 +51,13 @@ 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 {
Integer.parseInt(string); Integer.parseInt(string);
return true; return true;
} } catch (final Exception e) {
catch (final Exception e) {
return false; return false;
} }
} }
@ -48,14 +68,13 @@ 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.parseBoolean(string); Boolean.parseBoolean(string);
return true; return true;
} } catch (final Exception e) {
catch (final Exception e) {
return false; return false;
} }
} }
@ -66,14 +85,13 @@ 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.parseDouble(string); Double.parseDouble(string);
return true; return true;
} } catch (final Exception e) {
catch (final Exception e) {
return false; return false;
} }
} }
@ -84,14 +102,13 @@ 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;
} }
} }
@ -112,7 +129,7 @@ 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 {
@ -120,13 +137,11 @@ public class Configuration {
final String[] split = string.split(":"); final String[] split = string.split(":");
Short.parseShort(split[0]); Short.parseShort(split[0]);
Short.parseShort(split[1]); Short.parseShort(split[1]);
} } else {
else {
Short.parseShort(string); Short.parseShort(string);
} }
return true; return true;
} } catch (final Exception e) {
catch (final Exception e) {
return false; return false;
} }
} }
@ -136,8 +151,7 @@ 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);
} }
} }
@ -177,14 +191,12 @@ public class Configuration {
final String[] split = block.split(":"); final String[] split = block.split(":");
Short.parseShort(split[0]); Short.parseShort(split[0]);
Short.parseShort(split[1]); Short.parseShort(split[1]);
} } else {
else {
Short.parseShort(block); Short.parseShort(block);
} }
} }
return true; return true;
} } catch (final Exception e) {
catch (final Exception e) {
return false; return false;
} }
} }
@ -206,8 +218,7 @@ 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;
@ -216,8 +227,7 @@ 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);
} }
} }

View File

@ -1,16 +1,36 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import com.intellectualcrafters.plot.Configuration.SettingValue;
import org.apache.commons.lang.StringUtils;
import java.util.Arrays; import java.util.Arrays;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.Configuration.SettingValue;
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 Object value; private Object value;
private final SettingValue type; private final SettingValue type;
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) {
@ -32,8 +52,7 @@ public class ConfigurationNode {
return false; return false;
} }
return true; return true;
} } catch (final Exception e) {
catch (final Exception e) {
return false; return false;
} }
} }

View File

@ -1,26 +1,44 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
public class Flag { public class Flag {
private final AbstractFlag key; private final AbstractFlag key;
private final String value; private final String value;
/** /**
* Flag object used to store basic information for a Plot. Flags are a * Flag object used to store basic information for a Plot. Flags are a
* key/value pair. For a flag to be usable by a player, you need to register * key/value pair. For a flag to be usable by a player, you need to register
* it with PlotSquared. * it with PlotSquared.
* *
* @param key * @param key AbstractFlag
* AbstractFlag * @param value Value must be alphanumerical (can have spaces) and be <= 48
* @param value * characters
* Value must be alphanumerical (can have spaces) and be <= 48 * @throws IllegalArgumentException if you provide inadequate inputs
* characters
* @throws IllegalArgumentException
* if you provide inadequate inputs
*/ */
public Flag(final AbstractFlag key, final String value) { public Flag(final AbstractFlag key, final String value) {
final char[] allowedCharacters = new char[] { '[', ']', '(', ')', ',', '_', '-', '.', ',', '?', '!', '&', '§' }; final char[] allowedCharacters = new char[]{'[', ']', '(', ')', ',', '_', '-', '.', ',', '?', '!', '&', '<27>'};
String tempValue = value; String tempValue = value;
for (final char c : allowedCharacters) { for (final char c : allowedCharacters) {
tempValue = tempValue.replace(c, 'c'); tempValue = tempValue.replace(c, 'c');

View File

@ -1,11 +1,32 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.entity.Player;
public class FlagManager { public class FlagManager {
// TODO add some flags // TODO add some flags
@ -64,8 +85,7 @@ public class FlagManager {
/** /**
* Get a list of registerd AbstragFlag objects based on player permissions * Get a list of registerd AbstragFlag objects based on player permissions
* *
* @param player * @param player with permissions
* with permissions
* @return List (AbstractFlag) * @return List (AbstractFlag)
*/ */
public static List<AbstractFlag> getFlags(final Player player) { public static List<AbstractFlag> getFlags(final Player player) {
@ -97,8 +117,7 @@ public class FlagManager {
* Get an AbstractFlag by a string * Get an AbstractFlag by a string
* *
* @param string * @param string
* @param create * @param create If to create the flag if it does not exist
* If to create the flag if it does not exist
* @return AbstractFlag * @return AbstractFlag
*/ */
public static AbstractFlag getFlag(final String string, final boolean create) { public static AbstractFlag getFlag(final String string, final boolean create) {
@ -126,8 +145,7 @@ public class FlagManager {
final String[] split = flagstrings.get(i).split(";"); final String[] split = flagstrings.get(i).split(";");
if (split.length == 1) { if (split.length == 1) {
flags[i] = new Flag(getFlag(split[0], true), ""); flags[i] = new Flag(getFlag(split[0], true), "");
} } else {
else {
flags[i] = new Flag(getFlag(split[0], true), split[1]); flags[i] = new Flag(getFlag(split[0], true), split[1]);
} }
} }

View File

@ -1,10 +1,23 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = LSetCube.java >> Generated by: Citymonstret at 2014-08-09 01:43 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
@ -92,7 +105,7 @@ public class LSetCube {
/** /**
* *
*/ */
private Location current; private Location current;
/** /**
* @param cube * @param cube

View File

@ -1,10 +1,23 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Lag.java >> Generated by: Citymonstret at 2014-08-09 01:43 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
@ -18,16 +31,16 @@ public class Lag implements Runnable {
/** /**
* Tick count * Tick count
*/ */
public static int TC = 0; public static int TC = 0;
/** /**
* Ticks * Ticks
*/ */
public static long[] T = new long[600]; public static long[] T = new long[600];
/** /**
* something :_: * something :_:
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static long LT = 0L; public static long LT = 0L;
/** /**
* Get the server TPS * Get the server TPS
@ -41,8 +54,7 @@ public class Lag implements Runnable {
/** /**
* Return the tick per second (measured in $ticks) * Return the tick per second (measured in $ticks)
* *
* @param ticks * @param ticks Ticks
* Ticks
* @return ticks per second * @return ticks per second
*/ */
public static double getTPS(final int ticks) { public static double getTPS(final int ticks) {
@ -57,8 +69,7 @@ public class Lag implements Runnable {
/** /**
* Get number of ticks since * Get number of ticks since
* *
* @param tI * @param tI Ticks <
* Ticks <
* @return number of ticks since $tI * @return number of ticks since $tI
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")

View File

@ -1,18 +1,27 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Logger.java >> Generated by: Citymonstret at 2014-08-09 01:43 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import java.io.BufferedReader; import java.io.*;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -24,7 +33,7 @@ import java.util.Date;
public class Logger { public class Logger {
private static ArrayList<String> entries; private static ArrayList<String> entries;
private static File log; private static File log;
public static void setup(final File file) { public static void setup(final File file) {
log = file; log = file;
@ -36,8 +45,7 @@ public class Logger {
entries.add(line); entries.add(line);
} }
reader.close(); reader.close();
} } catch (final IOException e) {
catch (final IOException e) {
PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + "File setup error Logger#setup"); PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + "File setup error Logger#setup");
} }
} }

View File

@ -1,56 +1,26 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
/*
* Copyright 2011-2013 Tyler Blair. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and contributors and should not be interpreted as
* representing official policies, either expressed or implied, of anybody else.
*/
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -59,31 +29,41 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.*;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
public class Metrics { public class Metrics {
/** /**
* The current revision number * The current revision number
*/ */
private final static int REVISION = 7; private final static int REVISION = 7;
/** /**
* The base url of the metrics domain * The base url of the metrics domain
*/ */
private static final String BASE_URL = "http://report.mcstats.org"; private static final String BASE_URL = "http://report.mcstats.org";
/** /**
* The url used to report a server's status * The url used to report a server's status
*/ */
private static final String REPORT_URL = "/plugin/%s"; private static final String REPORT_URL = "/plugin/%s";
/** /**
* Interval of time to ping (in minutes) * Interval of time to ping (in minutes)
*/ */
private static final int PING_INTERVAL = 15; private static final int PING_INTERVAL = 15;
/** /**
* The plugin this metrics submits for * The plugin this metrics submits for
*/ */
private final Plugin plugin; private final Plugin plugin;
/** /**
* All of the custom graphs to submit to metrics * All of the custom graphs to submit to metrics
*/ */
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>()); private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
/** /**
* The plugin configuration file * The plugin configuration file
*/ */
@ -91,23 +71,23 @@ public class Metrics {
/** /**
* The plugin configuration file * The plugin configuration file
*/ */
private final File configurationFile; private final File configurationFile;
/** /**
* Unique server id * Unique server id
*/ */
private final String guid; private final String guid;
/** /**
* Debug mode * Debug mode
*/ */
private final boolean debug; private final boolean debug;
/** /**
* Lock for synchronization * Lock for synchronization
*/ */
private final Object optOutLock = new Object(); private final Object optOutLock = new Object();
/** /**
* The scheduled task * The scheduled task
*/ */
private volatile BukkitTask task = null; private volatile BukkitTask task = null;
public Metrics(final Plugin plugin) throws IOException { public Metrics(final Plugin plugin) throws IOException {
if (plugin == null) { if (plugin == null) {
@ -136,10 +116,9 @@ public class Metrics {
* plotters to their own graphs on the metrics website. Plotters can be * plotters to their own graphs on the metrics website. Plotters can be
* added to the graph object returned. * added to the graph object returned.
* *
* @param name * @param name The name of the graph
* The name of the graph
* @return Graph object created. Will never return NULL under normal * @return Graph object created. Will never return NULL under normal
* circumstances unless bad parameters are given * circumstances unless bad parameters are given
*/ */
public Graph createGraph(final String name) { public Graph createGraph(final String name) {
if (name == null) { if (name == null) {
@ -157,8 +136,7 @@ public class Metrics {
* Add a Graph object to BukkitMetrics that represents data for the plugin * Add a Graph object to BukkitMetrics that represents data for the plugin
* that should be sent to the backend * that should be sent to the backend
* *
* @param graph * @param graph The name of the graph
* The name of the graph
*/ */
public void addGraph(final Graph graph) { public void addGraph(final Graph graph) {
if (graph == null) { if (graph == null) {
@ -222,8 +200,7 @@ public class Metrics {
// false // false
// Each post thereafter will be a ping // Each post thereafter will be a ping
this.firstPost = false; this.firstPost = false;
} } catch (final IOException e) {
catch (final IOException e) {
if (Metrics.this.debug) { if (Metrics.this.debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
} }
@ -244,14 +221,12 @@ public class Metrics {
try { try {
// Reload the metrics file // Reload the metrics file
this.configuration.load(getConfigFile()); this.configuration.load(getConfigFile());
} } catch (final IOException ex) {
catch (final IOException ex) {
if (this.debug) { if (this.debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
} }
return true; return true;
} } catch (final InvalidConfigurationException ex) {
catch (final InvalidConfigurationException ex) {
if (this.debug) { if (this.debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
} }
@ -334,7 +309,7 @@ public class Metrics {
final PluginDescriptionFile description = this.plugin.getDescription(); final PluginDescriptionFile description = this.plugin.getDescription();
final String pluginName = description.getName(); final String pluginName = description.getName();
final boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE final boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE
// if // if
// online // online
// mode // mode
// is // is
@ -345,12 +320,10 @@ public class Metrics {
try { try {
if (Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).getReturnType() == Collection.class) { if (Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).getReturnType() == Collection.class) {
playersOnline = ((Collection<?>) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null, new Object[0])).size(); playersOnline = ((Collection<?>) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null, new Object[0])).size();
} } else {
else {
playersOnline = ((Player[]) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null, new Object[0])).length; playersOnline = ((Player[]) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null, new Object[0])).length;
} }
} } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
} }
// END server software specific section -- all code below does not use // END server software specific section -- all code below does not use
@ -423,8 +396,7 @@ public class Metrics {
// It does not reroute POST requests so we need to go around it // It does not reroute POST requests so we need to go around it
if (isMineshafterPresent()) { if (isMineshafterPresent()) {
connection = url.openConnection(Proxy.NO_PROXY); connection = url.openConnection(Proxy.NO_PROXY);
} } else {
else {
connection = url.openConnection(); connection = url.openConnection();
} }
final byte[] uncompressed = json.toString().getBytes(); final byte[] uncompressed = json.toString().getBytes();
@ -453,13 +425,11 @@ public class Metrics {
if ((response == null) || response.startsWith("ERR") || response.startsWith("7")) { if ((response == null) || response.startsWith("ERR") || response.startsWith("7")) {
if (response == null) { if (response == null) {
response = "null"; response = "null";
} } else if (response.startsWith("7")) {
else if (response.startsWith("7")) {
response = response.substring(response.startsWith("7,") ? 2 : 1); response = response.substring(response.startsWith("7,") ? 2 : 1);
} }
throw new IOException(response); throw new IOException(response);
} } else {
else {
// Is this the first update this hour? // Is this the first update this hour?
if (response.equals("1") || response.contains("This is your first update this hour")) { if (response.equals("1") || response.contains("This is your first update this hour")) {
synchronized (this.graphs) { synchronized (this.graphs) {
@ -487,16 +457,13 @@ public class Metrics {
try { try {
gzos = new GZIPOutputStream(baos); gzos = new GZIPOutputStream(baos);
gzos.write(input.getBytes("UTF-8")); gzos.write(input.getBytes("UTF-8"));
} } catch (final IOException e) {
catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
} } finally {
finally {
if (gzos != null) { if (gzos != null) {
try { try {
gzos.close(); gzos.close();
} } catch (final IOException ignore) {
catch (final IOException ignore) {
} }
} }
} }
@ -513,8 +480,7 @@ public class Metrics {
try { try {
Class.forName("mineshafter.MineServer"); Class.forName("mineshafter.MineServer");
return true; return true;
} } catch (final Exception e) {
catch (final Exception e) {
return false; return false;
} }
} }
@ -534,8 +500,7 @@ public class Metrics {
Double.parseDouble(value); Double.parseDouble(value);
isValueNumeric = true; isValueNumeric = true;
} }
} } catch (final NumberFormatException e) {
catch (final NumberFormatException e) {
isValueNumeric = false; isValueNumeric = false;
} }
if (json.charAt(json.length() - 1) != '{') { if (json.charAt(json.length() - 1) != '{') {
@ -545,8 +510,7 @@ public class Metrics {
json.append(':'); json.append(':');
if (isValueNumeric) { if (isValueNumeric) {
json.append(value); json.append(value);
} } else {
else {
json.append(escapeJSON(value)); json.append(escapeJSON(value));
} }
} }
@ -584,8 +548,7 @@ public class Metrics {
if (chr < ' ') { if (chr < ' ') {
final String t = "000" + Integer.toHexString(chr); final String t = "000" + Integer.toHexString(chr);
builder.append("\\u" + t.substring(t.length() - 4)); builder.append("\\u" + t.substring(t.length() - 4));
} } else {
else {
builder.append(chr); builder.append(chr);
} }
break; break;
@ -598,8 +561,7 @@ public class Metrics {
/** /**
* Encode text as UTF-8 * Encode text as UTF-8
* *
* @param text * @param text the text to encode
* the text to encode
* @return the encoded text, as UTF-8 * @return the encoded text, as UTF-8
*/ */
private static String urlEncode(final String text) throws UnsupportedEncodingException { private static String urlEncode(final String text) throws UnsupportedEncodingException {
@ -614,7 +576,7 @@ public class Metrics {
* The graph's name, alphanumeric and spaces only :) If it does not * The graph's name, alphanumeric and spaces only :) If it does not
* comply to the above when submitted, it is rejected * comply to the above when submitted, it is rejected
*/ */
private final String name; private final String name;
/** /**
* The set of plotters that are contained within this graph * The set of plotters that are contained within this graph
*/ */
@ -636,8 +598,7 @@ public class Metrics {
/** /**
* Add a plotter to the graph, which will be used to plot entries * Add a plotter to the graph, which will be used to plot entries
* *
* @param plotter * @param plotter the plotter to add to the graph
* the plotter to add to the graph
*/ */
public void addPlotter(final Plotter plotter) { public void addPlotter(final Plotter plotter) {
this.plotters.add(plotter); this.plotters.add(plotter);
@ -646,8 +607,7 @@ public class Metrics {
/** /**
* Remove a plotter from the graph * Remove a plotter from the graph
* *
* @param plotter * @param plotter the plotter to remove from the graph
* the plotter to remove from the graph
*/ */
public void removePlotter(final Plotter plotter) { public void removePlotter(final Plotter plotter) {
this.plotters.remove(plotter); this.plotters.remove(plotter);
@ -703,9 +663,8 @@ public class Metrics {
/** /**
* Construct a plotter with a specific plot name * Construct a plotter with a specific plot name
* *
* @param name * @param name the name of the plotter to use, which will show up on the
* the name of the plotter to use, which will show up on the * website
* website
*/ */
public Plotter(final String name) { public Plotter(final String name) {
this.name = name; this.name = name;

View File

@ -1,8 +1,25 @@
package com.intellectualcrafters.plot; ////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
import org.bukkit.Location; package com.intellectualcrafters.plot;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
@ -13,6 +30,9 @@ import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.RegionMask; import com.sk89q.worldedit.function.mask.RegionMask;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
/** /**
* @author Citymonstret * @author Citymonstret
@ -25,8 +45,7 @@ public class PWE {
LocalSession s; LocalSession s;
if (PlotMain.worldEdit == null) { if (PlotMain.worldEdit == null) {
s = WorldEdit.getInstance().getSession(p.getName()); s = WorldEdit.getInstance().getSession(p.getName());
} } else {
else {
s = PlotMain.worldEdit.getSession(p); s = PlotMain.worldEdit.getSession(p);
} }
@ -41,8 +60,7 @@ public class PWE {
removeMask(p, s); removeMask(p, s);
return; return;
} }
} } else {
else {
final World w = p.getWorld(); final World w = p.getWorld();
@ -66,8 +84,7 @@ public class PWE {
final Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69); final Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69);
s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2)));
} }
} } catch (final Exception e) {
catch (final Exception e) {
// throw new // throw new
// PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, // PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY,
// "WorldEdit == Null?"); // "WorldEdit == Null?");
@ -83,15 +100,13 @@ public class PWE {
LocalSession s; LocalSession s;
if (PlotMain.worldEdit == null) { if (PlotMain.worldEdit == null) {
s = WorldEdit.getInstance().getSession(p.getName()); s = WorldEdit.getInstance().getSession(p.getName());
} } else {
else {
s = PlotMain.worldEdit.getSession(p); s = PlotMain.worldEdit.getSession(p);
} }
final BukkitPlayer plr = PlotMain.worldEdit.wrapPlayer(p); final BukkitPlayer plr = PlotMain.worldEdit.wrapPlayer(p);
final Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69); final Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69);
s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2)));
} } catch (final Exception e) {
catch (final Exception e) {
} }
} }
@ -106,13 +121,11 @@ public class PWE {
LocalSession s; LocalSession s;
if (PlotMain.worldEdit == null) { if (PlotMain.worldEdit == null) {
s = WorldEdit.getInstance().getSession(p.getName()); s = WorldEdit.getInstance().getSession(p.getName());
} } else {
else {
s = PlotMain.worldEdit.getSession(p); s = PlotMain.worldEdit.getSession(p);
} }
removeMask(p, s); removeMask(p, s);
} } catch (final Exception e) {
catch (final Exception e) {
// throw new // throw new
// PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, // PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY,
// "WorldEdit == Null?"); // "WorldEdit == Null?");

View File

@ -1,22 +1,34 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Plot.java >> Generated by: Citymonstret at 2014-08-09 01:43 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import java.util.ArrayList; import com.intellectualcrafters.plot.database.DBFunc;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.database.DBFunc; import java.util.ArrayList;
import java.util.UUID;
/** /**
* The plot class * The plot class
@ -29,19 +41,19 @@ public class Plot implements Cloneable {
/** /**
* plot ID * plot ID
*/ */
public PlotId id; public PlotId id;
/** /**
* plot world * plot world
*/ */
public String world; public String world;
/** /**
* plot owner * plot owner
*/ */
public UUID owner; public UUID owner;
/** /**
* Deny Entry * Deny Entry
*/ */
public boolean deny_entry; public boolean deny_entry;
/** /**
* List of helpers (with plot permissions) * List of helpers (with plot permissions)
*/ */
@ -57,16 +69,16 @@ public class Plot implements Cloneable {
/** /**
* External settings class * External settings class
*/ */
public PlotSettings settings; public PlotSettings settings;
/** /**
* Delete on next save cycle? * Delete on next save cycle?
*/ */
public boolean delete; public boolean delete;
/** /**
* Has the plot changed since the last save cycle? * Has the plot changed since the last save cycle?
*/ */
public boolean hasChanged = false; public boolean hasChanged = false;
public boolean countsTowardsMax = true; public boolean countsTowardsMax = true;
/** /**
* Primary constructor * Primary constructor
@ -120,8 +132,7 @@ public class Plot implements Cloneable {
this.delete = false; this.delete = false;
if (flags != null) { if (flags != null) {
this.settings.setFlags(flags); this.settings.setFlags(flags);
} } else {
else {
this.settings.setFlags(new Flag[0]); this.settings.setFlags(new Flag[0]);
} }
this.world = world; this.world = world;
@ -195,8 +206,7 @@ public class Plot implements Cloneable {
public Object clone() throws CloneNotSupportedException { public Object clone() throws CloneNotSupportedException {
try { try {
return super.clone(); return super.clone();
} } catch (final CloneNotSupportedException e) {
catch (final CloneNotSupportedException e) {
return null; return null;
} }
} }
@ -270,8 +280,7 @@ public class Plot implements Cloneable {
/** /**
* Clear a plot * Clear a plot
* *
* @param plr * @param plr initiator
* initiator
*/ */
public void clear(final Player plr) { public void clear(final Player plr) {
PlotHelper.clear(plr, this); PlotHelper.clear(plr, this);
@ -292,21 +301,18 @@ public class Plot implements Cloneable {
int y = id.y; int y = id.y;
if (x >= 0) { if (x >= 0) {
if (y >= 0) { if (y >= 0) {
return x*x + 3*x + 2*x*y + y + y*y; return x * x + 3 * x + 2 * x * y + y + y * y;
} } else {
else {
int y1 = -y; int y1 = -y;
return x*x + 3*x + 2*x*y1 + y1 + y1*y1 + 1; return x * x + 3 * x + 2 * x * y1 + y1 + y1 * y1 + 1;
} }
} } else {
else {
int x1 = -x; int x1 = -x;
if (y >= 0) { if (y >= 0) {
return -(x1*x1 + 3*x1 + 2*x1*y + y + y*y); return -(x1 * x1 + 3 * x1 + 2 * x1 * y + y + y * y);
} } else {
else {
int y1 = -y; int y1 = -y;
return -(x1*x1 + 3*x1 + 2*x1*y1 + y1 + y1*y1 + 1); return -(x1 * x1 + 3 * x1 + 2 * x1 * y1 + y1 + y1 * y1 + 1);
} }
} }
} }

View File

@ -1,8 +1,29 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
public class PlotBlock { public class PlotBlock {
public short id; public short id;
public byte data; public byte data;
public PlotBlock(final short id, final byte data) { public PlotBlock(final short id, final byte data) {
this.id = id; this.id = id;

View File

@ -1,8 +1,29 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
public class PlotComment { public class PlotComment {
public final String comment; public final String comment;
public final int tier; public final int tier;
public final String senderName; public final String senderName;
public PlotComment(final String comment, final String senderName, final int tier) { public PlotComment(final String comment, final String senderName, final int tier) {

View File

@ -1,26 +1,30 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = PlotHelper.java >> Generated by: Citymonstret at 2014-08-09 01:43 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import java.io.File; import com.intellectualcrafters.plot.database.DBFunc;
import java.util.ArrayList; import com.intellectualcrafters.plot.listeners.PlotListener;
import java.util.HashMap;
import java.util.UUID;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
@ -28,8 +32,10 @@ import org.bukkit.block.Sign;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.database.DBFunc; import java.io.File;
import com.intellectualcrafters.plot.listeners.PlotListener; import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;
/** /**
* plot functions * plot functions
@ -38,7 +44,7 @@ import com.intellectualcrafters.plot.listeners.PlotListener;
*/ */
public class PlotHelper { public class PlotHelper {
public static boolean canSetFast = false; public static boolean canSetFast = false;
static long state = 1; static long state = 1;
/** /**
* direction 0 = north, 1 = south, etc: * direction 0 = north, 1 = south, etc:
@ -185,8 +191,7 @@ public class PlotHelper {
greaterPlot.settings.setMerged(0, true); greaterPlot.settings.setMerged(0, true);
manager.removeRoadSouth(plotworld, lesserPlot); manager.removeRoadSouth(plotworld, lesserPlot);
} }
} } else {
else {
if (!lesserPlot.settings.getMerged(1)) { if (!lesserPlot.settings.getMerged(1)) {
lesserPlot.settings.setMerged(1, true); lesserPlot.settings.setMerged(1, true);
greaterPlot.settings.setMerged(3, true); greaterPlot.settings.setMerged(3, true);
@ -216,7 +221,7 @@ public class PlotHelper {
return 0; return 0;
} }
final long r = ((nextLong() >>> 32) * n) >> 32; final long r = ((nextLong() >>> 32) * n) >> 32;
return (int) r; return (int) r;
} }
/* /*
@ -283,8 +288,7 @@ public class PlotHelper {
try { try {
SetBlockFast.set(block.getWorld(), block.getX(), block.getY(), block.getZ(), plotblock.id, plotblock.data); SetBlockFast.set(block.getWorld(), block.getX(), block.getY(), block.getZ(), plotblock.id, plotblock.data);
return true; return true;
} } catch (final Throwable e) {
catch (final Throwable e) {
canSetFast = false; canSetFast = false;
} }
} }
@ -294,12 +298,10 @@ public class PlotHelper {
if (block.getTypeId() != plotblock.id) { if (block.getTypeId() != plotblock.id) {
block.setTypeId(plotblock.id); block.setTypeId(plotblock.id);
} }
} } else {
else {
if (block.getTypeId() == plotblock.id) { if (block.getTypeId() == plotblock.id) {
block.setData(plotblock.data); block.setData(plotblock.data);
} } else {
else {
block.setTypeIdAndData(plotblock.id, plotblock.data, false); block.setTypeIdAndData(plotblock.id, plotblock.data, false);
} }
} }
@ -603,8 +605,8 @@ public class PlotHelper {
return x + ";" + z; return x + ";" + z;
} }
public static ArrayList<String> runners_p = new ArrayList<String>(); public static ArrayList<String> runners_p = new ArrayList<String>();
public static HashMap<Plot, Integer> runners = new HashMap<Plot, Integer>(); public static HashMap<Plot, Integer> runners = new HashMap<Plot, Integer>();
public static void adjustWallFilling(final Player requester, final Plot plot, final PlotBlock block) { public static void adjustWallFilling(final Player requester, final Plot plot, final PlotBlock block) {
if (runners.containsKey(plot)) { if (runners.containsKey(plot)) {
@ -644,9 +646,9 @@ public class PlotHelper {
public static short[] getBlock(final String block) { public static short[] getBlock(final String block) {
if (block.contains(":")) { if (block.contains(":")) {
final String[] split = block.split(":"); final String[] split = block.split(":");
return new short[] { Short.parseShort(split[0]), Short.parseShort(split[1]) }; return new short[]{Short.parseShort(split[0]), Short.parseShort(split[1])};
} }
return new short[] { Short.parseShort(block), 0 }; return new short[]{Short.parseShort(block), 0};
} }
public static void clearAllEntities(final World world, final Plot plot, final boolean tile) { public static void clearAllEntities(final World world, final Plot plot, final boolean tile) {
@ -662,8 +664,7 @@ public class PlotHelper {
Player player = (Player) entity; Player player = (Player) entity;
PlotMain.teleportPlayer(player, entity.getLocation(), plot); PlotMain.teleportPlayer(player, entity.getLocation(), plot);
PlotListener.plotExit(player, plot); PlotListener.plotExit(player, plot);
} } else {
else {
entity.remove(); entity.remove();
} }
} }
@ -717,8 +718,7 @@ public class PlotHelper {
final World world; final World world;
if (requester != null) { if (requester != null) {
world = requester.getWorld(); world = requester.getWorld();
} } else {
else {
world = Bukkit.getWorld(plot.world); world = Bukkit.getWorld(plot.world);
} }
@ -747,8 +747,7 @@ public class PlotHelper {
} }
} }
} }
} } else {
else {
try { try {
for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) {
for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) {
@ -762,8 +761,7 @@ public class PlotHelper {
} }
} }
} }
} } catch (final Exception e) {
catch (final Exception e) {
} }
} }
} }
@ -780,8 +778,7 @@ public class PlotHelper {
} }
} }
} }
} } else {
else {
try { try {
for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) {
for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) {
@ -793,8 +790,7 @@ public class PlotHelper {
} }
} }
} }
} } catch (final Exception e) {
catch (final Exception e) {
} }
} }
@ -841,8 +837,7 @@ public class PlotHelper {
final int z = bot.getBlockZ() - 2; final int z = bot.getBlockZ() - 2;
final int y = getHeighestBlock(w, x, z); final int y = getHeighestBlock(w, x, z);
return new Location(w, x, y, z); return new Location(w, x, y, z);
} } else {
else {
final Location bot = getPlotBottomLoc(w, plotid), top = getPlotTopLoc(w, plotid); final Location bot = getPlotBottomLoc(w, plotid), top = getPlotTopLoc(w, plotid);
final int x = top.getBlockX() - bot.getBlockX(); final int x = top.getBlockX() - bot.getBlockX();
final int z = top.getBlockZ() - bot.getBlockZ(); final int z = top.getBlockZ() - bot.getBlockZ();

View File

@ -1,11 +1,23 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = PlotHomePosition.java >> Generated by: Citymonstret at 2014-08-09 // it under the terms of the GNU General Public License as published by /
* 01:44 // the Free Software Foundation; either version 3 of the License, or /
*/ // (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
@ -17,7 +29,7 @@ public enum PlotHomePosition {
DEFAULT("Default", 'd'); DEFAULT("Default", 'd');
private String string; private String string;
private char ch; private char ch;
PlotHomePosition(final String string, final char ch) { PlotHomePosition(final String string, final char ch) {
this.string = string; this.string = string;

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
public class PlotId { public class PlotId {
@ -13,10 +34,8 @@ public class PlotId {
/** /**
* PlotId class (PlotId x,y values do not correspond to Block locations) * PlotId class (PlotId x,y values do not correspond to Block locations)
* *
* @param x * @param x The plot x coordinate
* The plot x coordinate * @param y The plot y coordinate
* @param y
* The plot y coordinate
*/ */
public PlotId(final int x, final int y) { public PlotId(final int x, final int y) {
this.x = x; this.x = x;
@ -47,21 +66,18 @@ public class PlotId {
public int hashCode() { public int hashCode() {
if (x >= 0) { if (x >= 0) {
if (y >= 0) { if (y >= 0) {
return x*x + 3*x + 2*x*y + y + y*y; return x * x + 3 * x + 2 * x * y + y + y * y;
} } else {
else {
int y1 = -y; int y1 = -y;
return x*x + 3*x + 2*x*y1 + y1 + y1*y1 + 1; return x * x + 3 * x + 2 * x * y1 + y1 + y1 * y1 + 1;
} }
} } else {
else {
int x1 = -x; int x1 = -x;
if (y >= 0) { if (y >= 0) {
return -(x1*x1 + 3*x1 + 2*x1*y + y + y*y); return -(x1 * x1 + 3 * x1 + 2 * x1 * y + y + y * y);
} } else {
else {
int y1 = -y; int y1 = -y;
return -(x1*x1 + 3*x1 + 2*x1*y1 + y1 + y1*y1 + 1); return -(x1 * x1 + 3 * x1 + 2 * x1 * y1 + y1 + y1 * y1 + 1);
} }
} }
} }

View File

@ -1,11 +1,32 @@
package com.intellectualcrafters.plot; ////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
import java.util.ArrayList; package com.intellectualcrafters.plot;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import java.util.ArrayList;
public abstract class PlotManager { public abstract class PlotManager {
/* /*

View File

@ -1,12 +1,33 @@
package com.intellectualcrafters.plot; ////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
import java.util.HashMap; package com.intellectualcrafters.plot;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import java.util.HashMap;
/** /**
* Created by Citymonstret on 2014-10-12. * Created by Citymonstret on 2014-10-12.
*/ */
@ -14,13 +35,13 @@ public class PlotSelection {
public static HashMap<String, PlotSelection> currentSelection = new HashMap<>(); public static HashMap<String, PlotSelection> currentSelection = new HashMap<>();
private final PlotBlock[] plotBlocks; private final PlotBlock[] plotBlocks;
private final int width; private final int width;
private final Plot plot; private final Plot plot;
private final Biome biome; private final Biome biome;
public PlotSelection(final int width, final World world, final Plot plot) { public PlotSelection(final int width, final World world, final Plot plot) {
this.width = width; this.width = width;
@ -86,21 +107,17 @@ public class PlotSelection {
try { try {
SetBlockFast.set(world, b1.x, b1.y, b1.z, b2.id, b2.data); SetBlockFast.set(world, b1.x, b1.y, b1.z, b2.id, b2.data);
SetBlockFast.set(world, b2.x, b2.y, b2.z, b1.id, b1.data); SetBlockFast.set(world, b2.x, b2.y, b2.z, b1.id, b1.data);
} } catch (final NoSuchMethodException e) {
catch (final NoSuchMethodException e) {
PlotHelper.canSetFast = false; PlotHelper.canSetFast = false;
} }
} } else {
else {
if ((b1.id != b2.id) && (b1.data != b2.data)) { if ((b1.id != b2.id) && (b1.data != b2.data)) {
block1.setTypeIdAndData(b2.id, b2.data, false); block1.setTypeIdAndData(b2.id, b2.data, false);
block2.setTypeIdAndData(b1.id, b1.data, false); block2.setTypeIdAndData(b1.id, b1.data, false);
} } else if (b1.id != b2.id) {
else if (b1.id != b2.id) {
block1.setTypeId(b2.id); block1.setTypeId(b2.id);
block2.setTypeId(b1.id); block2.setTypeId(b1.id);
} } else {
else {
block1.setData(b2.data); block1.setData(b2.data);
block2.setData(b1.data); block2.setData(b1.data);
} }

View File

@ -1,20 +1,33 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = PlotSettings.java >> Generated by: Citymonstret at 2014-08-09 01:44 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import org.bukkit.block.Biome;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.bukkit.block.Biome;
/** /**
* plot settings * plot settings
* *
@ -24,23 +37,23 @@ public class PlotSettings {
/** /**
* merged plots * merged plots
*/ */
private boolean[] merged = new boolean[] { false, false, false, false }; private boolean[] merged = new boolean[]{false, false, false, false};
/** /**
* plot alias * plot alias
*/ */
private String alias; private String alias;
/** /**
* plot biome * plot biome
*/ */
private Biome biome; private Biome biome;
private ArrayList<PlotComment> comments = null; private ArrayList<PlotComment> comments = null;
/** /**
* *
*/ */
private Set<Flag> flags; private Set<Flag> flags;
private PlotHomePosition position; private PlotHomePosition position;
/** /**
* Constructor * Constructor

View File

@ -1,164 +1,101 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import static org.bukkit.Material.ACACIA_STAIRS; import org.bukkit.Material;
import static org.bukkit.Material.BEACON; import org.bukkit.block.Biome;
import static org.bukkit.Material.BEDROCK; import org.bukkit.configuration.ConfigurationSection;
import static org.bukkit.Material.BIRCH_WOOD_STAIRS;
import static org.bukkit.Material.BOOKSHELF;
import static org.bukkit.Material.BREWING_STAND;
import static org.bukkit.Material.BRICK;
import static org.bukkit.Material.BRICK_STAIRS;
import static org.bukkit.Material.BURNING_FURNACE;
import static org.bukkit.Material.CAKE_BLOCK;
import static org.bukkit.Material.CAULDRON;
import static org.bukkit.Material.CLAY;
import static org.bukkit.Material.CLAY_BRICK;
import static org.bukkit.Material.COAL_BLOCK;
import static org.bukkit.Material.COAL_ORE;
import static org.bukkit.Material.COBBLESTONE;
import static org.bukkit.Material.COBBLESTONE_STAIRS;
import static org.bukkit.Material.COBBLE_WALL;
import static org.bukkit.Material.COMMAND;
import static org.bukkit.Material.DARK_OAK_STAIRS;
import static org.bukkit.Material.DAYLIGHT_DETECTOR;
import static org.bukkit.Material.DIAMOND_BLOCK;
import static org.bukkit.Material.DIAMOND_ORE;
import static org.bukkit.Material.DIRT;
import static org.bukkit.Material.DISPENSER;
import static org.bukkit.Material.DROPPER;
import static org.bukkit.Material.EMERALD_BLOCK;
import static org.bukkit.Material.EMERALD_ORE;
import static org.bukkit.Material.ENCHANTMENT_TABLE;
import static org.bukkit.Material.ENDER_PORTAL_FRAME;
import static org.bukkit.Material.ENDER_STONE;
import static org.bukkit.Material.FURNACE;
import static org.bukkit.Material.GLASS;
import static org.bukkit.Material.GLOWSTONE;
import static org.bukkit.Material.GOLD_BLOCK;
import static org.bukkit.Material.GOLD_ORE;
import static org.bukkit.Material.GRASS;
import static org.bukkit.Material.GRAVEL;
import static org.bukkit.Material.HARD_CLAY;
import static org.bukkit.Material.HAY_BLOCK;
import static org.bukkit.Material.HUGE_MUSHROOM_1;
import static org.bukkit.Material.HUGE_MUSHROOM_2;
import static org.bukkit.Material.IRON_BLOCK;
import static org.bukkit.Material.IRON_ORE;
import static org.bukkit.Material.JACK_O_LANTERN;
import static org.bukkit.Material.JUKEBOX;
import static org.bukkit.Material.JUNGLE_WOOD_STAIRS;
import static org.bukkit.Material.LAPIS_BLOCK;
import static org.bukkit.Material.LAPIS_ORE;
import static org.bukkit.Material.LEAVES;
import static org.bukkit.Material.LEAVES_2;
import static org.bukkit.Material.LOG;
import static org.bukkit.Material.LOG_2;
import static org.bukkit.Material.MELON_BLOCK;
import static org.bukkit.Material.MOB_SPAWNER;
import static org.bukkit.Material.MOSSY_COBBLESTONE;
import static org.bukkit.Material.MYCEL;
import static org.bukkit.Material.NETHERRACK;
import static org.bukkit.Material.NETHER_BRICK;
import static org.bukkit.Material.NETHER_BRICK_STAIRS;
import static org.bukkit.Material.NOTE_BLOCK;
import static org.bukkit.Material.OBSIDIAN;
import static org.bukkit.Material.PACKED_ICE;
import static org.bukkit.Material.PUMPKIN;
import static org.bukkit.Material.QUARTZ_BLOCK;
import static org.bukkit.Material.QUARTZ_ORE;
import static org.bukkit.Material.QUARTZ_STAIRS;
import static org.bukkit.Material.REDSTONE_BLOCK;
import static org.bukkit.Material.SAND;
import static org.bukkit.Material.SANDSTONE;
import static org.bukkit.Material.SANDSTONE_STAIRS;
import static org.bukkit.Material.SMOOTH_BRICK;
import static org.bukkit.Material.SMOOTH_STAIRS;
import static org.bukkit.Material.SNOW_BLOCK;
import static org.bukkit.Material.SOUL_SAND;
import static org.bukkit.Material.SPONGE;
import static org.bukkit.Material.SPRUCE_WOOD_STAIRS;
import static org.bukkit.Material.STONE;
import static org.bukkit.Material.WOOD;
import static org.bukkit.Material.WOOD_STAIRS;
import static org.bukkit.Material.WOOL;
import static org.bukkit.Material.WORKBENCH;
import static org.bukkit.Material.getMaterial;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import org.bukkit.Material; import static org.bukkit.Material.*;
import org.bukkit.block.Biome;
import org.bukkit.configuration.ConfigurationSection;
/** /**
*
* @author Jesse Boyd * @author Jesse Boyd
*
*/ */
public abstract class PlotWorld { public abstract class PlotWorld {
// TODO make this configurable // TODO make this configurable
// make non static and static_default_valu + add config option // make non static and static_default_valu + add config option
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static ArrayList<Material> BLOCKS = new ArrayList<Material>(Arrays.asList(new Material[] { ACACIA_STAIRS, BEACON, BEDROCK, BIRCH_WOOD_STAIRS, BOOKSHELF, BREWING_STAND, BRICK, BRICK_STAIRS, BURNING_FURNACE, CAKE_BLOCK, CAULDRON, CLAY_BRICK, CLAY, COAL_BLOCK, COAL_ORE, COBBLE_WALL, COBBLESTONE, COBBLESTONE_STAIRS, COMMAND, DARK_OAK_STAIRS, DAYLIGHT_DETECTOR, DIAMOND_ORE, DIAMOND_BLOCK, DIRT, DISPENSER, DROPPER, EMERALD_BLOCK, EMERALD_ORE, ENCHANTMENT_TABLE, ENDER_PORTAL_FRAME, ENDER_STONE, FURNACE, GLOWSTONE, GOLD_ORE, GOLD_BLOCK, GRASS, GRAVEL, GLASS, HARD_CLAY, HAY_BLOCK, HUGE_MUSHROOM_1, HUGE_MUSHROOM_2, IRON_BLOCK, IRON_ORE, JACK_O_LANTERN, JUKEBOX, JUNGLE_WOOD_STAIRS, LAPIS_BLOCK, LAPIS_ORE, LEAVES, LEAVES_2, LOG, LOG_2, MELON_BLOCK, MOB_SPAWNER, MOSSY_COBBLESTONE, MYCEL, NETHER_BRICK, NETHER_BRICK_STAIRS, NETHERRACK, NOTE_BLOCK, OBSIDIAN, PACKED_ICE, PUMPKIN, QUARTZ_BLOCK, QUARTZ_ORE, QUARTZ_STAIRS, REDSTONE_BLOCK, SANDSTONE, SAND, public static ArrayList<Material> BLOCKS = new ArrayList<Material>(Arrays.asList(new Material[]{ACACIA_STAIRS, BEACON, BEDROCK, BIRCH_WOOD_STAIRS, BOOKSHELF, BREWING_STAND, BRICK, BRICK_STAIRS, BURNING_FURNACE, CAKE_BLOCK, CAULDRON, CLAY_BRICK, CLAY, COAL_BLOCK, COAL_ORE, COBBLE_WALL, COBBLESTONE, COBBLESTONE_STAIRS, COMMAND, DARK_OAK_STAIRS, DAYLIGHT_DETECTOR, DIAMOND_ORE, DIAMOND_BLOCK, DIRT, DISPENSER, DROPPER, EMERALD_BLOCK, EMERALD_ORE, ENCHANTMENT_TABLE, ENDER_PORTAL_FRAME, ENDER_STONE, FURNACE, GLOWSTONE, GOLD_ORE, GOLD_BLOCK, GRASS, GRAVEL, GLASS, HARD_CLAY, HAY_BLOCK, HUGE_MUSHROOM_1, HUGE_MUSHROOM_2, IRON_BLOCK, IRON_ORE, JACK_O_LANTERN, JUKEBOX, JUNGLE_WOOD_STAIRS, LAPIS_BLOCK, LAPIS_ORE, LEAVES, LEAVES_2, LOG, LOG_2, MELON_BLOCK, MOB_SPAWNER, MOSSY_COBBLESTONE, MYCEL, NETHER_BRICK, NETHER_BRICK_STAIRS, NETHERRACK, NOTE_BLOCK, OBSIDIAN, PACKED_ICE, PUMPKIN, QUARTZ_BLOCK, QUARTZ_ORE, QUARTZ_STAIRS, REDSTONE_BLOCK, SANDSTONE, SAND,
SANDSTONE_STAIRS, SMOOTH_BRICK, SMOOTH_STAIRS, SNOW_BLOCK, SOUL_SAND, SPONGE, SPRUCE_WOOD_STAIRS, STONE, WOOD, WOOD_STAIRS, WORKBENCH, WOOL, getMaterial(44), getMaterial(126) })); SANDSTONE_STAIRS, SMOOTH_BRICK, SMOOTH_STAIRS, SNOW_BLOCK, SOUL_SAND, SPONGE, SPRUCE_WOOD_STAIRS, STONE, WOOD, WOOD_STAIRS, WORKBENCH, WOOL, getMaterial(44), getMaterial(126)}));
public boolean AUTO_MERGE; public boolean AUTO_MERGE;
public static boolean AUTO_MERGE_DEFAULT = false; public static boolean AUTO_MERGE_DEFAULT = false;
public boolean MOB_SPAWNING; public boolean MOB_SPAWNING;
public static boolean MOB_SPAWNING_DEFAULT = false; public static boolean MOB_SPAWNING_DEFAULT = false;
public Biome PLOT_BIOME; public Biome PLOT_BIOME;
public static Biome PLOT_BIOME_DEFAULT = Biome.FOREST; public static Biome PLOT_BIOME_DEFAULT = Biome.FOREST;
public boolean PLOT_CHAT; public boolean PLOT_CHAT;
public static boolean PLOT_CHAT_DEFAULT = false; public static boolean PLOT_CHAT_DEFAULT = false;
public boolean SCHEMATIC_CLAIM_SPECIFY = false; public boolean SCHEMATIC_CLAIM_SPECIFY = false;
public static boolean SCHEMATIC_CLAIM_SPECIFY_DEFAULT = false; public static boolean SCHEMATIC_CLAIM_SPECIFY_DEFAULT = false;
public boolean SCHEMATIC_ON_CLAIM; public boolean SCHEMATIC_ON_CLAIM;
public static boolean SCHEMATIC_ON_CLAIM_DEFAULT = false; public static boolean SCHEMATIC_ON_CLAIM_DEFAULT = false;
public String SCHEMATIC_FILE; public String SCHEMATIC_FILE;
public static String SCHEMATIC_FILE_DEFAULT = "null"; public static String SCHEMATIC_FILE_DEFAULT = "null";
public List<String> SCHEMATICS; public List<String> SCHEMATICS;
public static List<String> SCHEMATICS_DEFAULT = null; public static List<String> SCHEMATICS_DEFAULT = null;
public List<String> DEFAULT_FLAGS; public List<String> DEFAULT_FLAGS;
public static List<String> DEFAULT_FLAGS_DEFAULT = new ArrayList<String>(); public static List<String> DEFAULT_FLAGS_DEFAULT = new ArrayList<String>();
public boolean USE_ECONOMY; public boolean USE_ECONOMY;
public static boolean USE_ECONOMY_DEFAULT = false; public static boolean USE_ECONOMY_DEFAULT = false;
public double PLOT_PRICE; public double PLOT_PRICE;
public static double PLOT_PRICE_DEFAULT = 100; public static double PLOT_PRICE_DEFAULT = 100;
public double MERGE_PRICE; public double MERGE_PRICE;
public static double MERGE_PRICE_DEFAULT = 100; public static double MERGE_PRICE_DEFAULT = 100;
public double SELL_PRICE; public double SELL_PRICE;
public static double SELL_PRICE_DEFAULT = 75; public static double SELL_PRICE_DEFAULT = 75;
public boolean PVP; public boolean PVP;
public static boolean PVP_DEFAULT = false; public static boolean PVP_DEFAULT = false;
public boolean PVE; public boolean PVE;
public static boolean PVE_DEFAULT = false; public static boolean PVE_DEFAULT = false;
public boolean SPAWN_EGGS; public boolean SPAWN_EGGS;
public static boolean SPAWN_EGGS_DEFAULT = false; public static boolean SPAWN_EGGS_DEFAULT = false;
public boolean SPAWN_CUSTOM; public boolean SPAWN_CUSTOM;
public static boolean SPAWN_CUSTOM_DEFAULT = true; public static boolean SPAWN_CUSTOM_DEFAULT = true;
public boolean SPAWN_BREEDING; public boolean SPAWN_BREEDING;
public static boolean SPAWN_BREEDING_DEFAULT = false; public static boolean SPAWN_BREEDING_DEFAULT = false;
public PlotWorld(final String worldname) { public PlotWorld(final String worldname) {
this.worldname = worldname; this.worldname = worldname;

View File

@ -1,5 +1,29 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -7,22 +31,25 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Server;
/** /**
* @author DPOH-VAR * @author DPOH-VAR
* @version 1.0 * @version 1.0
*/ */
@SuppressWarnings({ "UnusedDeclaration", "rawtypes" }) @SuppressWarnings({"UnusedDeclaration", "rawtypes"})
public class ReflectionUtils { public class ReflectionUtils {
/** prefix of bukkit classes */ /**
private static String preClassB = "org.bukkit.craftbukkit"; * prefix of bukkit classes
/** prefix of minecraft classes */ */
private static String preClassM = "net.minecraft.server"; private static String preClassB = "org.bukkit.craftbukkit";
/** boolean value, TRUE if server uses forge or MCPC+ */ /**
private static boolean forge = false; * prefix of minecraft classes
*/
private static String preClassM = "net.minecraft.server";
/**
* boolean value, TRUE if server uses forge or MCPC+
*/
private static boolean forge = false;
/** check server version and class names */ /** check server version and class names */
static { static {
@ -46,8 +73,7 @@ public class ReflectionUtils {
final String verM = pas[3]; final String verM = pas[3];
preClassM += "." + verM; preClassM += "." + verM;
} }
} } catch (final Exception ignored) {
catch (final Exception ignored) {
} }
} }
} }
@ -63,19 +89,16 @@ public class ReflectionUtils {
* Get class for name. Replace {nms} to net.minecraft.server.V*. Replace * Get class for name. Replace {nms} to net.minecraft.server.V*. Replace
* {cb} to org.bukkit.craftbukkit.V*. Replace {nm} to net.minecraft * {cb} to org.bukkit.craftbukkit.V*. Replace {nm} to net.minecraft
* *
* @param classes * @param classes possible class paths
* possible class paths
* @return RefClass object * @return RefClass object
* @throws RuntimeException * @throws RuntimeException if no class found
* if no class found
*/ */
public static RefClass getRefClass(final String... classes) { public static RefClass getRefClass(final String... classes) {
for (String className : classes) { for (String className : classes) {
try { try {
className = className.replace("{cb}", preClassB).replace("{nms}", preClassM).replace("{nm}", "net.minecraft"); className = className.replace("{cb}", preClassB).replace("{nms}", preClassM).replace("{nm}", "net.minecraft");
return getRefClass(Class.forName(className)); return getRefClass(Class.forName(className));
} } catch (final ClassNotFoundException ignored) {
catch (final ClassNotFoundException ignored) {
} }
} }
throw new RuntimeException("no class found"); throw new RuntimeException("no class found");
@ -84,8 +107,7 @@ public class ReflectionUtils {
/** /**
* get RefClass object by real class * get RefClass object by real class
* *
* @param clazz * @param clazz class
* class
* @return RefClass based on passed class * @return RefClass based on passed class
*/ */
public static RefClass getRefClass(final Class clazz) { public static RefClass getRefClass(final Class clazz) {
@ -114,8 +136,7 @@ public class ReflectionUtils {
/** /**
* see {@link Class#isInstance(Object)} * see {@link Class#isInstance(Object)}
* *
* @param object * @param object the object to check
* the object to check
* @return true if object is an instance of this class * @return true if object is an instance of this class
*/ */
public boolean isInstance(final Object object) { public boolean isInstance(final Object object) {
@ -125,13 +146,10 @@ public class ReflectionUtils {
/** /**
* get existing method by name and types * get existing method by name and types
* *
* @param name * @param name name
* name * @param types method parameters. can be Class or RefClass
* @param types
* method parameters. can be Class or RefClass
* @return RefMethod object * @return RefMethod object
* @throws RuntimeException * @throws RuntimeException if method not found
* if method not found
*/ */
public RefMethod getMethod(final String name, final Object... types) throws NoSuchMethodException { public RefMethod getMethod(final String name, final Object... types) throws NoSuchMethodException {
try { try {
@ -140,22 +158,18 @@ public class ReflectionUtils {
for (final Object e : types) { for (final Object e : types) {
if (e instanceof Class) { if (e instanceof Class) {
classes[i++] = (Class) e; classes[i++] = (Class) e;
} } else if (e instanceof RefClass) {
else if (e instanceof RefClass) {
classes[i++] = ((RefClass) e).getRealClass(); classes[i++] = ((RefClass) e).getRealClass();
} } else {
else {
classes[i++] = e.getClass(); classes[i++] = e.getClass();
} }
} }
try { try {
return new RefMethod(this.clazz.getMethod(name, classes)); return new RefMethod(this.clazz.getMethod(name, classes));
} } catch (final NoSuchMethodException ignored) {
catch (final NoSuchMethodException ignored) {
return new RefMethod(this.clazz.getDeclaredMethod(name, classes)); return new RefMethod(this.clazz.getDeclaredMethod(name, classes));
} }
} } catch (final Exception e) {
catch (final Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@ -163,11 +177,9 @@ public class ReflectionUtils {
/** /**
* get existing constructor by types * get existing constructor by types
* *
* @param types * @param types parameters. can be Class or RefClass
* parameters. can be Class or RefClass
* @return RefMethod object * @return RefMethod object
* @throws RuntimeException * @throws RuntimeException if constructor not found
* if constructor not found
*/ */
public RefConstructor getConstructor(final Object... types) { public RefConstructor getConstructor(final Object... types) {
try { try {
@ -176,22 +188,18 @@ public class ReflectionUtils {
for (final Object e : types) { for (final Object e : types) {
if (e instanceof Class) { if (e instanceof Class) {
classes[i++] = (Class) e; classes[i++] = (Class) e;
} } else if (e instanceof RefClass) {
else if (e instanceof RefClass) {
classes[i++] = ((RefClass) e).getRealClass(); classes[i++] = ((RefClass) e).getRealClass();
} } else {
else {
classes[i++] = e.getClass(); classes[i++] = e.getClass();
} }
} }
try { try {
return new RefConstructor(this.clazz.getConstructor(classes)); return new RefConstructor(this.clazz.getConstructor(classes));
} } catch (final NoSuchMethodException ignored) {
catch (final NoSuchMethodException ignored) {
return new RefConstructor(this.clazz.getDeclaredConstructor(classes)); return new RefConstructor(this.clazz.getDeclaredConstructor(classes));
} }
} } catch (final Exception e) {
catch (final Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@ -199,11 +207,9 @@ public class ReflectionUtils {
/** /**
* find method by type parameters * find method by type parameters
* *
* @param types * @param types parameters. can be Class or RefClass
* parameters. can be Class or RefClass
* @return RefMethod object * @return RefMethod object
* @throws RuntimeException * @throws RuntimeException if method not found
* if method not found
*/ */
public RefMethod findMethod(final Object... types) { public RefMethod findMethod(final Object... types) {
final Class[] classes = new Class[types.length]; final Class[] classes = new Class[types.length];
@ -211,18 +217,17 @@ public class ReflectionUtils {
for (final Object e : types) { for (final Object e : types) {
if (e instanceof Class) { if (e instanceof Class) {
classes[t++] = (Class) e; classes[t++] = (Class) e;
} } else if (e instanceof RefClass) {
else if (e instanceof RefClass) {
classes[t++] = ((RefClass) e).getRealClass(); classes[t++] = ((RefClass) e).getRealClass();
} } else {
else {
classes[t++] = e.getClass(); classes[t++] = e.getClass();
} }
} }
final List<Method> methods = new ArrayList<>(); final List<Method> methods = new ArrayList<>();
Collections.addAll(methods, this.clazz.getMethods()); Collections.addAll(methods, this.clazz.getMethods());
Collections.addAll(methods, this.clazz.getDeclaredMethods()); Collections.addAll(methods, this.clazz.getDeclaredMethods());
findMethod: for (final Method m : methods) { findMethod:
for (final Method m : methods) {
final Class<?>[] methodTypes = m.getParameterTypes(); final Class<?>[] methodTypes = m.getParameterTypes();
if (methodTypes.length != classes.length) { if (methodTypes.length != classes.length) {
continue; continue;
@ -240,11 +245,9 @@ public class ReflectionUtils {
/** /**
* find method by name * find method by name
* *
* @param names * @param names possible names of method
* possible names of method
* @return RefMethod object * @return RefMethod object
* @throws RuntimeException * @throws RuntimeException if method not found
* if method not found
*/ */
public RefMethod findMethodByName(final String... names) { public RefMethod findMethodByName(final String... names) {
final List<Method> methods = new ArrayList<>(); final List<Method> methods = new ArrayList<>();
@ -263,11 +266,9 @@ public class ReflectionUtils {
/** /**
* find method by return value * find method by return value
* *
* @param type * @param type type of returned value
* type of returned value
* @throws RuntimeException
* if method not found
* @return RefMethod * @return RefMethod
* @throws RuntimeException if method not found
*/ */
public RefMethod findMethodByReturnType(final RefClass type) { public RefMethod findMethodByReturnType(final RefClass type) {
return findMethodByReturnType(type.clazz); return findMethodByReturnType(type.clazz);
@ -276,11 +277,9 @@ public class ReflectionUtils {
/** /**
* find method by return value * find method by return value
* *
* @param type * @param type type of returned value
* type of returned value
* @return RefMethod * @return RefMethod
* @throws RuntimeException * @throws RuntimeException if method not found
* if method not found
*/ */
public RefMethod findMethodByReturnType(Class type) { public RefMethod findMethodByReturnType(Class type) {
if (type == null) { if (type == null) {
@ -300,11 +299,9 @@ public class ReflectionUtils {
/** /**
* find constructor by number of arguments * find constructor by number of arguments
* *
* @param number * @param number number of arguments
* number of arguments
* @return RefConstructor * @return RefConstructor
* @throws RuntimeException * @throws RuntimeException if constructor not found
* if constructor not found
*/ */
public RefConstructor findConstructor(final int number) { public RefConstructor findConstructor(final int number) {
final List<Constructor> constructors = new ArrayList<>(); final List<Constructor> constructors = new ArrayList<>();
@ -321,22 +318,18 @@ public class ReflectionUtils {
/** /**
* get field by name * get field by name
* *
* @param name * @param name field name
* field name
* @return RefField * @return RefField
* @throws RuntimeException * @throws RuntimeException if field not found
* if field not found
*/ */
public RefField getField(final String name) { public RefField getField(final String name) {
try { try {
try { try {
return new RefField(this.clazz.getField(name)); return new RefField(this.clazz.getField(name));
} } catch (final NoSuchFieldException ignored) {
catch (final NoSuchFieldException ignored) {
return new RefField(this.clazz.getDeclaredField(name)); return new RefField(this.clazz.getDeclaredField(name));
} }
} } catch (final Exception e) {
catch (final Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@ -344,11 +337,9 @@ public class ReflectionUtils {
/** /**
* find field by type * find field by type
* *
* @param type * @param type field type
* field type
* @return RefField * @return RefField
* @throws RuntimeException * @throws RuntimeException if field not found
* if field not found
*/ */
public RefField findField(final RefClass type) { public RefField findField(final RefClass type) {
return findField(type.clazz); return findField(type.clazz);
@ -357,11 +348,9 @@ public class ReflectionUtils {
/** /**
* find field by type * find field by type
* *
* @param type * @param type field type
* field type
* @return RefField * @return RefField
* @throws RuntimeException * @throws RuntimeException if field not found
* if field not found
*/ */
public RefField findField(Class type) { public RefField findField(Class type) {
if (type == null) { if (type == null) {
@ -414,8 +403,7 @@ public class ReflectionUtils {
/** /**
* apply method to object * apply method to object
* *
* @param e * @param e object to which the method is applied
* object to which the method is applied
* @return RefExecutor with method call(...) * @return RefExecutor with method call(...)
*/ */
public RefExecutor of(final Object e) { public RefExecutor of(final Object e) {
@ -425,15 +413,13 @@ public class ReflectionUtils {
/** /**
* call static method * call static method
* *
* @param params * @param params sent parameters
* sent parameters
* @return return value * @return return value
*/ */
public Object call(final Object... params) { public Object call(final Object... params) {
try { try {
return this.method.invoke(null, params); return this.method.invoke(null, params);
} } catch (final Exception e) {
catch (final Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@ -448,17 +434,14 @@ public class ReflectionUtils {
/** /**
* apply method for selected object * apply method for selected object
* *
* @param params * @param params sent parameters
* sent parameters
* @return return value * @return return value
* @throws RuntimeException * @throws RuntimeException if something went wrong
* if something went wrong
*/ */
public Object call(final Object... params) { public Object call(final Object... params) {
try { try {
return RefMethod.this.method.invoke(this.e, params); return RefMethod.this.method.invoke(this.e, params);
} } catch (final Exception e) {
catch (final Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@ -493,17 +476,14 @@ public class ReflectionUtils {
/** /**
* create new instance with constructor * create new instance with constructor
* *
* @param params * @param params parameters for constructor
* parameters for constructor
* @return new object * @return new object
* @throws RuntimeException * @throws RuntimeException if something went wrong
* if something went wrong
*/ */
public Object create(final Object... params) { public Object create(final Object... params) {
try { try {
return this.constructor.newInstance(params); return this.constructor.newInstance(params);
} } catch (final Exception e) {
catch (final Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@ -541,8 +521,7 @@ public class ReflectionUtils {
/** /**
* apply fiend for object * apply fiend for object
* *
* @param e * @param e applied object
* applied object
* @return RefExecutor with getter and setter * @return RefExecutor with getter and setter
*/ */
public RefExecutor of(final Object e) { public RefExecutor of(final Object e) {
@ -559,14 +538,12 @@ public class ReflectionUtils {
/** /**
* set field value for applied object * set field value for applied object
* *
* @param param * @param param value
* value
*/ */
public void set(final Object param) { public void set(final Object param) {
try { try {
RefField.this.field.set(this.e, param); RefField.this.field.set(this.e, param);
} } catch (final Exception e) {
catch (final Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@ -579,8 +556,7 @@ public class ReflectionUtils {
public Object get() { public Object get() {
try { try {
return RefField.this.field.get(this.e); return RefField.this.field.get(this.e);
} } catch (final Exception e) {
catch (final Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }

View File

@ -1,32 +1,39 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import java.io.File; import com.intellectualcrafters.jnbt.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.intellectualcrafters.jnbt.ByteArrayTag; import java.io.*;
import com.intellectualcrafters.jnbt.CompoundTag; import java.util.ArrayList;
import com.intellectualcrafters.jnbt.IntTag; import java.util.HashMap;
import com.intellectualcrafters.jnbt.ListTag; import java.util.Map;
import com.intellectualcrafters.jnbt.NBTInputStream; import java.util.zip.GZIPInputStream;
import com.intellectualcrafters.jnbt.NBTOutputStream; import java.util.zip.GZIPOutputStream;
import com.intellectualcrafters.jnbt.ShortTag;
import com.intellectualcrafters.jnbt.StringTag;
import com.intellectualcrafters.jnbt.Tag;
/** /**
* Schematic Handler * Schematic Handler
@ -34,17 +41,14 @@ import com.intellectualcrafters.jnbt.Tag;
* @author Citymonstret * @author Citymonstret
* @author Empire92 * @author Empire92
*/ */
@SuppressWarnings({ "all" }) @SuppressWarnings({"all"})
public class SchematicHandler { public class SchematicHandler {
/** /**
* Paste a schematic * Paste a schematic
* *
* @param location * @param location origin
* origin * @param schematic schematic to paste
* @param schematic * @param plot plot to paste in
* schematic to paste
* @param plot
* plot to paste in
* @return true if succeeded * @return true if succeeded
*/ */
public static boolean paste(final Location location, final Schematic schematic, final Plot plot, final int x_offset, final int z_offset) { public static boolean paste(final Location location, final Schematic schematic, final Plot plot, final int x_offset, final int z_offset) {
@ -72,8 +76,7 @@ public class SchematicHandler {
int y_offset; int y_offset;
if (HEIGHT == location.getWorld().getMaxHeight()) { if (HEIGHT == location.getWorld().getMaxHeight()) {
y_offset = 0; y_offset = 0;
} } else {
else {
y_offset = l1.getBlockY(); y_offset = l1.getBlockY();
} }
@ -102,8 +105,7 @@ public class SchematicHandler {
} }
} }
} }
} } catch (final Exception e) {
catch (final Exception e) {
return false; return false;
} }
return true; return true;
@ -112,8 +114,7 @@ public class SchematicHandler {
/** /**
* Get a schematic * Get a schematic
* *
* @param name * @param name to check
* to check
* @return schematic if found, else null * @return schematic if found, else null
*/ */
public static Schematic getSchematic(final String name) { public static Schematic getSchematic(final String name) {
@ -155,12 +156,10 @@ public class SchematicHandler {
if ((index >> 1) >= addId.length) { // No corresponding if ((index >> 1) >= addId.length) { // No corresponding
// AddBlocks index // AddBlocks index
blocks[index] = (short) (b[index] & 0xFF); blocks[index] = (short) (b[index] & 0xFF);
} } else {
else {
if ((index & 1) == 0) { if ((index & 1) == 0) {
blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (b[index] & 0xFF)); blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (b[index] & 0xFF));
} } else {
else {
blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (b[index] & 0xFF)); blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (b[index] & 0xFF));
} }
} }
@ -208,8 +207,7 @@ public class SchematicHandler {
// } // }
// } // }
schematic = new Schematic(collection, dimension, file); schematic = new Schematic(collection, dimension, file);
} } catch (final Exception e) {
catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
@ -223,8 +221,8 @@ public class SchematicHandler {
*/ */
public static class Schematic { public static class Schematic {
private final DataCollection[] blockCollection; private final DataCollection[] blockCollection;
private final Dimension schematicDimension; private final Dimension schematicDimension;
private final File file; private final File file;
public Schematic(final DataCollection[] blockCollection, final Dimension schematicDimension, final File file) { public Schematic(final DataCollection[] blockCollection, final Dimension schematicDimension, final File file) {
this.blockCollection = blockCollection; this.blockCollection = blockCollection;
@ -277,10 +275,8 @@ public class SchematicHandler {
/** /**
* Saves a schematic to a file path * Saves a schematic to a file path
* *
* @param tag * @param tag to save
* to save * @param path to save in
* @param path
* to save in
* @return true if succeeded * @return true if succeeded
*/ */
public static boolean save(final CompoundTag tag, final String path) { public static boolean save(final CompoundTag tag, final String path) {
@ -296,8 +292,7 @@ public class SchematicHandler {
output.writeTag(tag); output.writeTag(tag);
output.close(); output.close();
stream.close(); stream.close();
} } catch (final IOException e) {
catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
@ -307,10 +302,8 @@ public class SchematicHandler {
/** /**
* Gets the schematic of a plot * Gets the schematic of a plot
* *
* @param world * @param world to check
* to check * @param id plot
* @param id
* plot
* @return tag * @return tag
*/ */
public static CompoundTag getCompoundTag(final World world, final PlotId id) { public static CompoundTag getCompoundTag(final World world, final PlotId id) {
@ -338,8 +331,7 @@ public class SchematicHandler {
} }
} }
} }
} } catch (final Exception e) {
catch (final Exception e) {
PlotMain.sendConsoleSenderMessage("&7 - Cannot save: corrupt chunk at " + (i / 16) + ", " + (j / 16)); PlotMain.sendConsoleSenderMessage("&7 - Cannot save: corrupt chunk at " + (i / 16) + ", " + (j / 16));
return null; return null;
} }
@ -407,7 +399,7 @@ public class SchematicHandler {
*/ */
public static class DataCollection { public static class DataCollection {
private final short block; private final short block;
private final byte data; private final byte data;
// public CompoundTag tag; // public CompoundTag tag;

View File

@ -1,11 +1,31 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import static com.intellectualcrafters.plot.ReflectionUtils.getRefClass;
import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.ReflectionUtils.RefClass; import com.intellectualcrafters.plot.ReflectionUtils.RefClass;
import com.intellectualcrafters.plot.ReflectionUtils.RefMethod; import com.intellectualcrafters.plot.ReflectionUtils.RefMethod;
import org.bukkit.Bukkit;
import static com.intellectualcrafters.plot.ReflectionUtils.getRefClass;
/** /**
* SetBlockFast class<br> * SetBlockFast class<br>
@ -13,15 +33,15 @@ import com.intellectualcrafters.plot.ReflectionUtils.RefMethod;
*/ */
public class SetBlockFast { public class SetBlockFast {
private static final RefClass classBlock = getRefClass("{nms}.Block"); private static final RefClass classBlock = getRefClass("{nms}.Block");
private static final RefClass classChunk = getRefClass("{nms}.Chunk"); private static final RefClass classChunk = getRefClass("{nms}.Chunk");
private static final RefClass classWorld = getRefClass("{nms}.World"); private static final RefClass classWorld = getRefClass("{nms}.World");
private static final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); private static final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
private static RefMethod methodGetHandle; private static RefMethod methodGetHandle;
private static RefMethod methodGetChunkAt; private static RefMethod methodGetChunkAt;
private static RefMethod methodA; private static RefMethod methodA;
private static RefMethod methodGetById; private static RefMethod methodGetById;
public SetBlockFast() throws NoSuchMethodException { public SetBlockFast() throws NoSuchMethodException {
methodGetHandle = classCraftWorld.getMethod("getHandle"); methodGetHandle = classCraftWorld.getMethod("getHandle");

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import java.util.ArrayList; import java.util.ArrayList;
@ -28,12 +49,13 @@ public class StringComparsion {
public Object getMatchObject() { public Object getMatchObject() {
return this.bestMatchObject; return this.bestMatchObject;
} }
public String getBestMatch() { public String getBestMatch() {
return this.bestMatch; return this.bestMatch;
} }
public Object[] getBestMatchAdvanced() { public Object[] getBestMatchAdvanced() {
return new Object[] { this.match, this.bestMatch }; return new Object[]{this.match, this.bestMatch};
} }
public static double compare(final String s1, final String s2) { public static double compare(final String s1, final String s2) {

View File

@ -1,3 +1,24 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
/** /**
@ -9,8 +30,7 @@ public class StringWrapper {
/** /**
* Constructor * Constructor
* *
* @param value * @param value to wrap
* to wrap
*/ */
public StringWrapper(final String value) { public StringWrapper(final String value) {
this.value = value; this.value = value;
@ -19,8 +39,7 @@ public class StringWrapper {
/** /**
* Check if a wrapped string equals another one * Check if a wrapped string equals another one
* *
* @param obj * @param obj to compare
* to compare
* @return true if obj equals the stored value * @return true if obj equals the stored value
*/ */
@Override @Override

View File

@ -1,39 +1,60 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
/** /**
* Minecraft 1.8 Title * Minecraft 1.8 Title
* *
* @version 1.0.3
* @author Maxim Van de Wynckel * @author Maxim Van de Wynckel
* @version 1.0.3
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class Title { public class Title {
/* Title packet */ /* Title packet */
private Class<?> packetTitle; private Class<?> packetTitle;
/* Title packet actions ENUM */ /* Title packet actions ENUM */
private Class<?> packetActions; private Class<?> packetActions;
/* Chat serializer */ /* Chat serializer */
private Class<?> nmsChatSerializer; private Class<?> nmsChatSerializer;
/* Title text and color */ /* Title text and color */
private String title = ""; private String title = "";
private ChatColor titleColor = ChatColor.WHITE; private ChatColor titleColor = ChatColor.WHITE;
/* Subtitle text and color */ /* Subtitle text and color */
private String subtitle = ""; private String subtitle = "";
private ChatColor subtitleColor = ChatColor.WHITE; private ChatColor subtitleColor = ChatColor.WHITE;
/* Title timings */ /* Title timings */
private int fadeInTime = -1; private int fadeInTime = -1;
private int stayTime = -1; private int stayTime = -1;
private int fadeOutTime = -1; private int fadeOutTime = -1;
private boolean ticks = false; private boolean ticks = false;
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES; private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES;
@ -44,8 +65,7 @@ public class Title {
/** /**
* Create a new 1.8 title * Create a new 1.8 title
* *
* @param title * @param title Title
* Title
*/ */
public Title(final String title) { public Title(final String title) {
this.title = title; this.title = title;
@ -55,10 +75,8 @@ public class Title {
/** /**
* Create a new 1.8 title * Create a new 1.8 title
* *
* @param title * @param title Title text
* Title text * @param subtitle Subtitle text
* @param subtitle
* Subtitle text
*/ */
public Title(final String title, final String subtitle) { public Title(final String title, final String subtitle) {
this.title = title; this.title = title;
@ -69,16 +87,11 @@ public class Title {
/** /**
* Create a new 1.8 title * Create a new 1.8 title
* *
* @param title * @param title Title text
* Title text * @param subtitle Subtitle text
* @param subtitle * @param fadeInTime Fade in time
* Subtitle text * @param stayTime Stay on screen time
* @param fadeInTime * @param fadeOutTime Fade out time
* Fade in time
* @param stayTime
* Stay on screen time
* @param fadeOutTime
* Fade out time
*/ */
public Title(final String title, final String subtitle, final int fadeInTime, final int stayTime, final int fadeOutTime) { public Title(final String title, final String subtitle, final int fadeInTime, final int stayTime, final int fadeOutTime) {
this.title = title; this.title = title;
@ -101,8 +114,7 @@ public class Title {
/** /**
* Set the title color * Set the title color
* *
* @param color * @param color Chat color
* Chat color
*/ */
public void setTitleColor(final ChatColor color) { public void setTitleColor(final ChatColor color) {
this.titleColor = color; this.titleColor = color;
@ -111,8 +123,7 @@ public class Title {
/** /**
* Set the subtitle color * Set the subtitle color
* *
* @param color * @param color Chat color
* Chat color
*/ */
public void setSubtitleColor(final ChatColor color) { public void setSubtitleColor(final ChatColor color) {
this.subtitleColor = color; this.subtitleColor = color;
@ -121,8 +132,7 @@ public class Title {
/** /**
* Set title fade in time * Set title fade in time
* *
* @param time * @param time Time
* Time
*/ */
public void setFadeInTime(final int time) { public void setFadeInTime(final int time) {
this.fadeInTime = time; this.fadeInTime = time;
@ -131,8 +141,7 @@ public class Title {
/** /**
* Set title fade out time * Set title fade out time
* *
* @param time * @param time Time
* Time
*/ */
public void setFadeOutTime(final int time) { public void setFadeOutTime(final int time) {
this.fadeOutTime = time; this.fadeOutTime = time;
@ -141,8 +150,7 @@ public class Title {
/** /**
* Set title stay time * Set title stay time
* *
* @param time * @param time Time
* Time
*/ */
public void setStayTime(final int time) { public void setStayTime(final int time) {
this.stayTime = time; this.stayTime = time;
@ -165,8 +173,7 @@ public class Title {
/** /**
* Send the title to a player * Send the title to a player
* *
* @param player * @param player Player
* Player
*/ */
public void send(final Player player) { public void send(final Player player) {
if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) { if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) {
@ -194,8 +201,7 @@ public class Title {
packet = this.packetTitle.getConstructor(this.packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[1], serialized); packet = this.packetTitle.getConstructor(this.packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[1], serialized);
sendPacket.invoke(connection, packet); sendPacket.invoke(connection, packet);
} }
} } catch (final Exception e) {
catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -213,8 +219,7 @@ public class Title {
/** /**
* Clear the title * Clear the title
* *
* @param player * @param player Player
* Player
*/ */
public void clearTitle(final Player player) { public void clearTitle(final Player player) {
if ((getProtocolVersion(player) >= 47) && isSpigot()) { if ((getProtocolVersion(player) >= 47) && isSpigot()) {
@ -226,8 +231,7 @@ public class Title {
final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); final Method sendPacket = getMethod(connection.getClass(), "sendPacket");
final Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[3]); final Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[3]);
sendPacket.invoke(connection, packet); sendPacket.invoke(connection, packet);
} } catch (final Exception e) {
catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -236,8 +240,7 @@ public class Title {
/** /**
* Reset the title settings * Reset the title settings
* *
* @param player * @param player Player
* Player
*/ */
public void resetTitle(final Player player) { public void resetTitle(final Player player) {
if ((getProtocolVersion(player) >= 47) && isSpigot()) { if ((getProtocolVersion(player) >= 47) && isSpigot()) {
@ -249,8 +252,7 @@ public class Title {
final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); final Method sendPacket = getMethod(connection.getClass(), "sendPacket");
final Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[4]); final Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[4]);
sendPacket.invoke(connection, packet); sendPacket.invoke(connection, packet);
} } catch (final Exception e) {
catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -259,8 +261,7 @@ public class Title {
/** /**
* Get the protocol version of the player * Get the protocol version of the player
* *
* @param player * @param player Player
* Player
* @return Protocol version * @return Protocol version
*/ */
private int getProtocolVersion(final Player player) { private int getProtocolVersion(final Player player) {
@ -272,8 +273,7 @@ public class Title {
version = (Integer) getMethod("getVersion", networkManager.getClass()).invoke(networkManager); version = (Integer) getMethod("getVersion", networkManager.getClass()).invoke(networkManager);
return version; return version;
} } catch (final Exception ex) {
catch (final Exception ex) {
// ex.printStackTrace(); <-- spammy console // ex.printStackTrace(); <-- spammy console
} }
return version; return version;
@ -291,15 +291,13 @@ public class Title {
/** /**
* Get class by url * Get class by url
* *
* @param namespace * @param namespace Namespace url
* Namespace url
* @return Class * @return Class
*/ */
private Class<?> getClass(final String namespace) { private Class<?> getClass(final String namespace) {
try { try {
return Class.forName(namespace); return Class.forName(namespace);
} } catch (final Exception e) {
catch (final Exception e) {
return null; return null;
} }
} }
@ -342,8 +340,7 @@ public class Title {
private Object getHandle(final Object obj) { private Object getHandle(final Object obj) {
try { try {
return getMethod("getHandle", obj.getClass()).invoke(obj); return getMethod("getHandle", obj.getClass()).invoke(obj);
} } catch (final Exception e) {
catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
@ -370,8 +367,7 @@ public class Title {
Class<?> clazz = null; Class<?> clazz = null;
try { try {
clazz = Class.forName(fullName); clazz = Class.forName(fullName);
} } catch (final Exception e) {
catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return clazz; return clazz;
@ -382,8 +378,7 @@ public class Title {
final Field field = clazz.getDeclaredField(name); final Field field = clazz.getDeclaredField(name);
field.setAccessible(true); field.setAccessible(true);
return field; return field;
} } catch (final Exception e) {
catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }

View File

@ -1,19 +1,39 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.intellectualcrafters.plot.uuid.NameFetcher; import com.intellectualcrafters.plot.uuid.NameFetcher;
import com.intellectualcrafters.plot.uuid.UUIDFetcher; import com.intellectualcrafters.plot.uuid.UUIDFetcher;
import com.intellectualcrafters.plot.uuid.UUIDSaver; import com.intellectualcrafters.plot.uuid.UUIDSaver;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;
/** /**
* This class can be used to efficiently translate UUIDs and names back and * This class can be used to efficiently translate UUIDs and names back and
@ -24,13 +44,13 @@ import com.intellectualcrafters.plot.uuid.UUIDSaver;
* - Read from (if onlinemode: mojang api) (else: playername hashing) * - Read from (if onlinemode: mojang api) (else: playername hashing)
* All UUIDs/Usernames will be stored in a map (cache) until the server is * All UUIDs/Usernames will be stored in a map (cache) until the server is
* restarted. * restarted.
* * <p/>
* You can use getUuidMap() to save the uuids/names to a file (SQLite db for * You can use getUuidMap() to save the uuids/names to a file (SQLite db for
* example). * example).
* Primary methods: getUUID(String name) & getName(UUID uuid) <-- You should * Primary methods: getUUID(String name) & getName(UUID uuid) <-- You should
* ONLY use these. * ONLY use these.
* Call startFetch(JavaPlugin plugin) in your onEnable(). * Call startFetch(JavaPlugin plugin) in your onEnable().
* * <p/>
* Originally created by: * Originally created by:
* *
* @author Citymonstret * @author Citymonstret
@ -44,7 +64,7 @@ public class UUIDHandler {
* *
* @see org.bukkit.Server#getOnlineMode() * @see org.bukkit.Server#getOnlineMode()
*/ */
private static boolean online = Bukkit.getServer().getOnlineMode(); private static boolean online = Bukkit.getServer().getOnlineMode();
/** /**
* Map containing names and UUID's * Map containing names and UUID's
@ -63,8 +83,7 @@ public class UUIDHandler {
/** /**
* Check if a uuid is cached * Check if a uuid is cached
* *
* @param uuid * @param uuid to check
* to check
* @return true of the uuid is cached * @return true of the uuid is cached
*/ */
public static boolean uuidExists(final UUID uuid) { public static boolean uuidExists(final UUID uuid) {
@ -74,8 +93,7 @@ public class UUIDHandler {
/** /**
* Check if a name is cached * Check if a name is cached
* *
* @param name * @param name to check
* to check
* @return true of the name is cached * @return true of the name is cached
*/ */
public static boolean nameExists(final StringWrapper name) { public static boolean nameExists(final StringWrapper name) {
@ -85,10 +103,8 @@ public class UUIDHandler {
/** /**
* Add a set to the cache * Add a set to the cache
* *
* @param name * @param name to cache
* to cache * @param uuid to cache
* @param uuid
* to cache
*/ */
public static void add(final StringWrapper name, final UUID uuid) { public static void add(final StringWrapper name, final UUID uuid) {
if (!uuidMap.containsKey(name) && !uuidMap.inverse().containsKey(uuid)) { if (!uuidMap.containsKey(name) && !uuidMap.inverse().containsKey(uuid)) {
@ -97,8 +113,7 @@ public class UUIDHandler {
} }
/** /**
* @param name * @param name to use as key
* to use as key
* @return uuid * @return uuid
*/ */
public static UUID getUUID(final String name) { public static UUID getUUID(final String name) {
@ -121,38 +136,32 @@ public class UUIDHandler {
} }
try { try {
return PlotMain.getUUIDSaver().mojangUUID(name); return PlotMain.getUUIDSaver().mojangUUID(name);
} } catch (final Exception e) {
catch (final Exception e) {
try { try {
final UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name)); final UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
uuid = fetcher.call().get(name); uuid = fetcher.call().get(name);
add(nameWrap, uuid); add(nameWrap, uuid);
} } catch (final Exception ex) {
catch (final Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
} } else {
else {
try { try {
final UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name)); final UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
uuid = fetcher.call().get(name); uuid = fetcher.call().get(name);
add(nameWrap, uuid); add(nameWrap, uuid);
} } catch (final Exception ex) {
catch (final Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
} } else {
else {
return getUuidOfflineMode(nameWrap); return getUuidOfflineMode(nameWrap);
} }
return null; return null;
} }
/** /**
* @param uuid * @param uuid to use as key
* to use as key
* @return name (cache) * @return name (cache)
*/ */
private static StringWrapper loopSearch(final UUID uuid) { private static StringWrapper loopSearch(final UUID uuid) {
@ -160,8 +169,7 @@ public class UUIDHandler {
} }
/** /**
* @param uuid * @param uuid to use as key
* to use as key
* @return Name * @return Name
*/ */
public static String getName(final UUID uuid) { public static String getName(final UUID uuid) {
@ -182,51 +190,43 @@ public class UUIDHandler {
name = fetcher.call().get(uuid); name = fetcher.call().get(uuid);
add(new StringWrapper(name), uuid); add(new StringWrapper(name), uuid);
return name; return name;
} } catch (final Exception ex) {
catch (final Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} } else {
else {
try { try {
return PlotMain.getUUIDSaver().mojangName(uuid); return PlotMain.getUUIDSaver().mojangName(uuid);
} } catch (final Exception e) {
catch (final Exception e) {
try { try {
final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid)); final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid));
name = fetcher.call().get(uuid); name = fetcher.call().get(uuid);
add(new StringWrapper(name), uuid); add(new StringWrapper(name), uuid);
return name; return name;
} } catch (final Exception ex) {
catch (final Exception ex) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
try { try {
return PlotMain.getUUIDSaver().mojangName(uuid); return PlotMain.getUUIDSaver().mojangName(uuid);
} } catch (final Exception e) {
catch (final Exception e) {
try { try {
final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid)); final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid));
name = fetcher.call().get(uuid); name = fetcher.call().get(uuid);
add(new StringWrapper(name), uuid); add(new StringWrapper(name), uuid);
return name; return name;
} } catch (final Exception ex) {
catch (final Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
} } else {
else {
return "unknown"; return "unknown";
} }
return ""; return "";
} }
/** /**
* @param name * @param name to use as key
* to use as key
* @return UUID (name hash) * @return UUID (name hash)
*/ */
private static UUID getUuidOfflineMode(final StringWrapper name) { private static UUID getUuidOfflineMode(final StringWrapper name) {
@ -236,8 +236,7 @@ public class UUIDHandler {
} }
/** /**
* @param uuid * @param uuid to use as key
* to use as key
* @return String - name * @return String - name
*/ */
private static String getNameOnlinePlayer(final UUID uuid) { private static String getNameOnlinePlayer(final UUID uuid) {
@ -251,8 +250,7 @@ public class UUIDHandler {
} }
/** /**
* @param uuid * @param uuid to use as key
* to use as key
* @return String - name * @return String - name
*/ */
private static String getNameOfflinePlayer(final UUID uuid) { private static String getNameOfflinePlayer(final UUID uuid) {
@ -266,8 +264,7 @@ public class UUIDHandler {
} }
/** /**
* @param name * @param name to use as key
* to use as key
* @return UUID * @return UUID
*/ */
private static UUID getUuidOnlinePlayer(final StringWrapper name) { private static UUID getUuidOnlinePlayer(final StringWrapper name) {

View File

@ -1,16 +1,29 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = PlotAPI.java >> Generated by: Citymonstret at 2014-08-09 01:44 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.api; package com.intellectualcrafters.plot.api;
import java.util.ArrayList; import com.intellectualcrafters.plot.*;
import java.util.Set; import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.commands.SubCommand;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -18,33 +31,22 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.intellectualcrafters.plot.AbstractFlag; import java.util.ArrayList;
import com.intellectualcrafters.plot.C; import java.util.Set;
import com.intellectualcrafters.plot.FlagManager;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotManager;
import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.SchematicHandler;
import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.commands.SubCommand;
/** /**
* The plotMain api class. * The plotMain api class.
* *
* @author Citymonstret, Empire92 * @author Citymonstret, Empire92
*/ */
@SuppressWarnings({ "unused", "javadoc" }) @SuppressWarnings({"unused", "javadoc"})
public class PlotAPI { public class PlotAPI {
private static PlotHelper plotHelper; private static PlotHelper plotHelper;
private static PlayerFunctions playerFunctions; private static PlayerFunctions playerFunctions;
private static FlagManager flagManager; private static FlagManager flagManager;
private static SchematicHandler schematicHandler; private static SchematicHandler schematicHandler;
private static C c; private static C c;
// Methods/fields in PlotMain class // Methods/fields in PlotMain class
@ -63,13 +65,13 @@ public class PlotAPI {
// PlotMain.updatePlot(plot); // PlotMain.updatePlot(plot);
// To access plotMain stuff. // To access plotMain stuff.
private final PlotMain plotMain; private final PlotMain plotMain;
// Reference // Reference
/** /**
* Admin Permission * Admin Permission
*/ */
public static final String ADMIN_PERMISSION = "plots.admin"; public static final String ADMIN_PERMISSION = "plots.admin";
/** /**
* Get all plots * Get all plots
@ -93,39 +95,36 @@ public class PlotAPI {
/** /**
* Add a plotoworld * Add a plotoworld
* *
* @param world World Name
* @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.PlotWorld, * com.intellectualcrafters.plot.PlotWorld,
* com.intellectualcrafters.plot.PlotManager) * com.intellectualcrafters.plot.PlotManager)
* @param world
* World Name
* @param plotWorld
* Plot World Object
* @param manager
* World Manager
*/ */
public void addPlotWorld(final String world, final PlotWorld plotWorld, final PlotManager manager) { public void addPlotWorld(final String world, final PlotWorld plotWorld, final PlotManager manager) {
PlotMain.addPlotWorld(world, plotWorld, manager); PlotMain.addPlotWorld(world, plotWorld, manager);
} }
/** /**
* @see com.intellectualcrafters.plot.PlotMain#config
* @return main configuration * @return main configuration
* @see com.intellectualcrafters.plot.PlotMain#config
*/ */
public YamlConfiguration getConfig() { public YamlConfiguration getConfig() {
return PlotMain.config; return PlotMain.config;
} }
/** /**
* @see com.intellectualcrafters.plot.PlotMain#translations
* @return translation configuration * @return translation configuration
* @see com.intellectualcrafters.plot.PlotMain#translations
*/ */
public YamlConfiguration getTranslations() { public YamlConfiguration getTranslations() {
return PlotMain.translations; return PlotMain.translations;
} }
/** /**
* @see com.intellectualcrafters.plot.PlotMain#storage
* @return storage configuration * @return storage configuration
* @see com.intellectualcrafters.plot.PlotMain#storage
*/ */
public YamlConfiguration getStorage() { public YamlConfiguration getStorage() {
return PlotMain.storage; return PlotMain.storage;
@ -135,8 +134,7 @@ public class PlotAPI {
* 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 * @param plugin Plugin used to access this method
* Plugin used to access this method
*/ */
public PlotAPI(final JavaPlugin plugin) { public PlotAPI(final JavaPlugin plugin) {
this.plotMain = JavaPlugin.getPlugin(PlotMain.class); this.plotMain = JavaPlugin.getPlugin(PlotMain.class);
@ -226,10 +224,9 @@ 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 * @param world (to get settings of)
* (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
*/ */
public PlotWorld getWorldSettings(final World world) { public PlotWorld getWorldSettings(final World world) {
return PlotMain.getWorldSettings(world); return PlotMain.getWorldSettings(world);
@ -238,10 +235,9 @@ 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 * @param world (to get settings of)
* (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
*/ */
public PlotWorld getWorldSettings(final String world) { public PlotWorld getWorldSettings(final String world) {
return PlotMain.getWorldSettings(world); return PlotMain.getWorldSettings(world);
@ -251,8 +247,7 @@ public class PlotAPI {
* Send a message to a player. * Send a message to a player.
* *
* @param player * @param player
* @param c * @param c (Caption)
* (Caption)
*/ */
public void sendMessage(final Player player, final C c) { public void sendMessage(final Player player, final C c) {
PlayerFunctions.sendMessage(player, c); PlayerFunctions.sendMessage(player, c);
@ -280,8 +275,7 @@ public class PlotAPI {
/** /**
* Send a message to the console * Send a message to the console
* *
* @param c * @param c (Caption)
* (Caption)
*/ */
public void sendConsoleMessage(final C c) { public void sendConsoleMessage(final C c) {
sendConsoleMessage(c.s()); sendConsoleMessage(c.s());
@ -350,10 +344,8 @@ public class PlotAPI {
/** /**
* Get all plots for the player * Get all plots for the player
* *
* @param plr * @param plr to search for
* to search for * @param just_owner should we just search for owner? Or with rights?
* @param just_owner
* should we just search for owner? Or with rights?
*/ */
public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) { public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) {
final ArrayList<Plot> pPlots = new ArrayList<>(); final ArrayList<Plot> pPlots = new ArrayList<>();
@ -362,8 +354,7 @@ public class PlotAPI {
if ((plot.owner != null) && (plot.owner == plr.getUniqueId())) { if ((plot.owner != null) && (plot.owner == plr.getUniqueId())) {
pPlots.add(plot); pPlots.add(plot);
} }
} } else {
else {
if (plot.hasRights(plr)) { if (plot.hasRights(plr)) {
pPlots.add(plot); pPlots.add(plot);
} }
@ -375,8 +366,7 @@ public class PlotAPI {
/** /**
* Get all plots for the world * Get all plots for the world
* *
* @param world * @param world to get plots of
* to get plots of
* @return Plot[] - array of plot objects in world * @return Plot[] - array of plot objects in world
*/ */
public Plot[] getPlots(final World world) { public Plot[] getPlots(final World world) {
@ -395,8 +385,7 @@ public class PlotAPI {
/** /**
* Get if plot world * Get if plot world
* *
* @param world * @param world (to check if plot world)
* (to check if plot world)
* @return boolean (if plot world or not) * @return boolean (if plot world or not)
*/ */
public boolean isPlotWorld(final World world) { public boolean isPlotWorld(final World world) {
@ -411,7 +400,7 @@ public class PlotAPI {
*/ */
public Location[] getLocations(final Plot p) { public Location[] getLocations(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)};
} }
/** /**

View File

@ -1,27 +1,32 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Auto.java >> Generated by: Citymonstret at 2014-08-09 01:40 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.FlagManager;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class Auto extends SubCommand { public class Auto extends SubCommand {
public Auto() { public Auto() {
@ -39,12 +44,10 @@ 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;
} }
@ -64,15 +67,13 @@ 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) {
schematic = args[0]; schematic = args[0];
// PlayerFunctions.sendMessage(plr, // PlayerFunctions.sendMessage(plr,
// "&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;
@ -124,14 +125,16 @@ public class Auto extends SubCommand {
} }
Auto.lastPlot = getNextPlot(Auto.lastPlot, 1); Auto.lastPlot = getNextPlot(Auto.lastPlot, 1);
} }
} } else {
else { // FIXME: Not used
final boolean claimed = true; // TODO: Fix this!
// final boolean claimed = true;
while (!br) { while (!br) {
final PlotId start = getNextPlot(Auto.lastPlot, 1); final PlotId start = getNextPlot(Auto.lastPlot, 1);
// FIXME: Wtf is going on here? // FIXME: Wtf is going on here?
if (claimed) { /*if (claimed) */
{
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)) {
Auto.lastPlot = start; Auto.lastPlot = start;
continue; continue;
@ -168,20 +171,16 @@ 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);
} }

View File

@ -1,28 +1,32 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Claim.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import net.milkbowl.vault.economy.Economy; import com.intellectualcrafters.plot.*;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.FlagManager;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.SchematicHandler;
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent; import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
import com.intellectualcrafters.plot.generator.DefaultPlotWorld; import com.intellectualcrafters.plot.generator.DefaultPlotWorld;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
/** /**
* @author Citymonstret * @author Citymonstret
@ -40,17 +44,14 @@ public class Claim extends SubCommand {
schematic = args[0]; schematic = args[0];
} }
if (!PlayerFunctions.isInPlot(plr)) { if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT); return sendMessage(plr, C.NOT_IN_PLOT);
return true;
} }
if (PlayerFunctions.getPlayerPlotCount(plr.getWorld(), plr) >= PlayerFunctions.getAllowedPlots(plr)) { if (PlayerFunctions.getPlayerPlotCount(plr.getWorld(), plr) >= PlayerFunctions.getAllowedPlots(plr)) {
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
return true;
} }
final Plot plot = PlayerFunctions.getCurrentPlot(plr); final Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (plot.hasOwner()) { if (plot.hasOwner()) {
PlayerFunctions.sendMessage(plr, C.PLOT_IS_CLAIMED); return sendMessage(plr, C.PLOT_IS_CLAIMED);
return false;
} }
final PlotWorld world = PlotMain.getWorldSettings(plot.getWorld()); final PlotWorld world = PlotMain.getWorldSettings(plot.getWorld());
if (PlotMain.useEconomy && world.USE_ECONOMY) { if (PlotMain.useEconomy && world.USE_ECONOMY) {
@ -58,8 +59,7 @@ public class Claim extends SubCommand {
if (cost > 0d) { if (cost > 0d) {
final Economy economy = PlotMain.economy; final Economy economy = PlotMain.economy;
if (economy.getBalance(plr) < cost) { if (economy.getBalance(plr) < cost) {
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost); return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
return true;
} }
economy.withdrawPlayer(plr, cost); economy.withdrawPlayer(plr, cost);
sendMessage(plr, C.REMOVED_BALANCE, cost + ""); sendMessage(plr, C.REMOVED_BALANCE, cost + "");
@ -68,21 +68,15 @@ public class Claim extends SubCommand {
if (!schematic.equals("")) { if (!schematic.equals("")) {
if (world.SCHEMATIC_CLAIM_SPECIFY) { if (world.SCHEMATIC_CLAIM_SPECIFY) {
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) { if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); return sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
return true;
} }
if (!PlotMain.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin")) { if (!PlotMain.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic); return sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
return true;
} }
} }
} }
final boolean result = claimPlot(plr, plot, false, schematic);
if (result) { return !claimPlot(plr, plot, false, schematic) || sendMessage(plr, C.PLOT_NOT_CLAIMED);
PlayerFunctions.sendMessage(plr, C.PLOT_NOT_CLAIMED);
return false;
}
return true;
} }
public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport) { public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport) {
@ -107,8 +101,7 @@ 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);

View File

@ -1,23 +1,32 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Clear.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import org.bukkit.entity.Player;
/**
* Created by Citymonstret on 2014-08-01.
*/
public class Clear extends SubCommand { public class Clear extends SubCommand {
public Clear() { public Clear() {
@ -30,18 +39,16 @@ public class Clear extends SubCommand {
@Override @Override
public boolean execute(final Player plr, final String... args) { public boolean execute(final Player plr, final String... args) {
if (!PlayerFunctions.isInPlot(plr)) { if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot."); return sendMessage(plr, C.NOT_IN_PLOT);
return false;
} }
final Plot plot = PlayerFunctions.getCurrentPlot(plr); final Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED); return sendMessage(plr, C.UNLINK_REQUIRED);
return false;
} }
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !PlotMain.hasPermission(plr, "plots.admin")) { if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !PlotMain.hasPermission(plr, "plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return sendMessage(plr, C.NO_PLOT_PERMS);
return false;
} }
assert plot != null;
plot.clear(plr); plot.clear(plr);
return true; return true;
} }

View File

@ -1,17 +1,34 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import static com.intellectualcrafters.plot.PlotSelection.currentSelection;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotSelection; import com.intellectualcrafters.plot.PlotSelection;
import org.bukkit.entity.Player;
import static com.intellectualcrafters.plot.PlotSelection.currentSelection;
/**
* Created by Citymonstret on 2014-10-13.
*/
public class Clipboard extends SubCommand { public class Clipboard extends SubCommand {
public Clipboard() { public Clipboard() {
@ -21,8 +38,7 @@ public class Clipboard extends SubCommand {
@Override @Override
public boolean execute(final Player plr, final String... args) { public boolean execute(final Player plr, final String... args) {
if (!currentSelection.containsKey(plr.getName())) { if (!currentSelection.containsKey(plr.getName())) {
sendMessage(plr, C.NO_CLIPBOARD); return sendMessage(plr, C.NO_CLIPBOARD);
return true;
} }
final PlotSelection selection = currentSelection.get(plr.getName()); final PlotSelection selection = currentSelection.get(plr.getName());

View File

@ -1,10 +1,23 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Command.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
@ -118,11 +131,11 @@ public enum Command {
/** /**
* *
*/ */
private String command; private String command;
/** /**
* *
*/ */
private String alias; private String alias;
/** /**
* *
*/ */

View File

@ -1,17 +1,28 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = CommandPermission.java >> Generated by: Citymonstret at 2014-08-09 // it under the terms of the GNU General Public License as published by /
* 01:41 // the Free Software Foundation; either version 3 of the License, or /
*/ // (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
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 org.bukkit.entity.Player;
/** /**
* Created by Citymonstret on 2014-08-03. * Created by Citymonstret on 2014-08-03.
@ -26,15 +37,15 @@ public class CommandPermission {
public String permission; public String permission;
/** /**
* @param 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 * @param player Does the player have the permission?
* @return * @return true of player has the required permission node
*/ */
public boolean hasPermission(final Player player) { public boolean hasPermission(final Player player) {
return PlotMain.hasPermission(player, this.permission) || PlotMain.hasPermission(player, "plots.admin"); return PlotMain.hasPermission(player, this.permission) || PlotMain.hasPermission(player, "plots.admin");

View File

@ -1,29 +1,34 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Clear.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.database.DBFunc;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Player;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotComment;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.database.DBFunc;
/**
* Created by Citymonstret on 2014-08-01.
*/
public class Comment extends SubCommand { public class Comment extends SubCommand {
public Comment() { public Comment() {
@ -33,16 +38,14 @@ public class Comment extends SubCommand {
@Override @Override
public boolean execute(final Player plr, final String... args) { public boolean execute(final Player plr, final String... args) {
if (!PlayerFunctions.isInPlot(plr)) { if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT); return sendMessage(plr, C.NOT_IN_PLOT);
return false;
} }
final Plot plot = PlayerFunctions.getCurrentPlot(plr); final Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT); return sendMessage(plr, C.NOT_IN_PLOT);
return false;
} }
final List<String> recipients = Arrays.asList(new String[] { "admin", "owner", "helper", "trusted", "everyone" }); final List<String> recipients = Arrays.asList("admin", "owner", "helper", "trusted", "everyone");
if ((args.length == 2) && recipients.contains(args[0].toLowerCase())) { if ((args.length == 2) && recipients.contains(args[0].toLowerCase())) {
@ -54,13 +57,10 @@ 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());
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.comment." + args[0].toLowerCase());
return false;
} }
} }
PlayerFunctions.sendMessage(plr, C.COMMENT_SYNTAX); return sendMessage(plr, C.COMMENT_SYNTAX);
return false;
} }
} }

View File

@ -1,25 +1,29 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Clear.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotSelection;
/**
* Created by Citymonstret on 2014-08-01.
*/
public class Copy extends SubCommand { public class Copy extends SubCommand {
public Copy() { public Copy() {
@ -37,11 +41,11 @@ public class Copy extends SubCommand {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false; return false;
} }
assert plot != null;
if (plot.settings.isMerged()) { if (plot.settings.isMerged()) {
PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED); PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED);
return false; return false;
} }
assert plot != null;
final int size = (PlotHelper.getPlotTopLocAbs(plr.getWorld(), plot.getId()).getBlockX() - PlotHelper.getPlotBottomLocAbs(plr.getWorld(), plot.getId()).getBlockX()); final int size = (PlotHelper.getPlotTopLocAbs(plr.getWorld(), plot.getId()).getBlockX() - PlotHelper.getPlotBottomLocAbs(plr.getWorld(), plot.getId()).getBlockX());
final PlotSelection selection = new PlotSelection(size, plr.getWorld(), plot); final PlotSelection selection = new PlotSelection(size, plr.getWorld(), plot);
if (PlotSelection.currentSelection.containsKey(plr.getName())) { if (PlotSelection.currentSelection.containsKey(plr.getName())) {
@ -49,8 +53,6 @@ public class Copy extends SubCommand {
} }
PlotSelection.currentSelection.put(plr.getName(), selection); PlotSelection.currentSelection.put(plr.getName(), selection);
sendMessage(plr, C.CLIPBOARD_SET); sendMessage(plr, C.CLIPBOARD_SET);
// section.paste(plr.getWorld(), PlotHelper.getPlot(plr.getWorld()zs,
// new PlotId(plot.getId().x + 1, plot.getId().y)));
return true; return true;
} }
} }

View File

@ -1,45 +1,35 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Debug.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.Lag;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.RUtils;
/**
* @author Citymonstret \\SuperCharged Compiler made by Citymonstret\\
* ||#Compiler:ALPHA-1.0#########################
* ||#ST:Java(1.7.*)\impl(bukkit)->api(s[])######
* ||#Section:\Debug\############################
* ||##Debug->Debug.properties|Debug.txt#########
* ||############################################ ||#Signed
* By:Citymonstret@IC##################
* \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
*/
public class Debug extends SubCommand { public class Debug extends SubCommand {
// private extends SubCommand^Implements {Command, Information} from
// >>\\S.txt6\\
public Debug() { public Debug() {
super(Command.DEBUG, "Show debug information", "debug [msg]", CommandCategory.DEBUG, false); super(Command.DEBUG, "Show debug information", "debug [msg]", CommandCategory.DEBUG, false);
{
/**
* This.
*/
}
} }
@Override @Override
@ -47,35 +37,23 @@ public class Debug extends SubCommand {
if ((args.length > 0) && args[0].equalsIgnoreCase("msg")) { if ((args.length > 0) && args[0].equalsIgnoreCase("msg")) {
final StringBuilder msg = new StringBuilder(); final StringBuilder msg = new StringBuilder();
for (final C c : C.values()) { for (final C c : C.values()) {
msg.append(c.s() + "\n"); msg.append(c.s()).append("\n");
} }
PlayerFunctions.sendMessage(plr, msg.toString()); PlayerFunctions.sendMessage(plr, msg.toString());
return true; return true;
} }
StringBuilder information; StringBuilder information;
String header, line, section; String header, line, section;
/**
* {$notnull || compile:: \\Debug:Captions\\}
*/
{ {
information = new StringBuilder(); information = new StringBuilder();
header = C.DEUBG_HEADER.s(); header = C.DEUBG_HEADER.s();
line = C.DEBUG_LINE.s(); line = C.DEBUG_LINE.s();
section = C.DEBUG_SECTION.s(); section = C.DEBUG_SECTION.s();
} }
/**
* {||direct:: load: debug::I>Captions::trsl} \\ if(missing)
* set(default) -> this->(){} \\ echo line->line(Compiler.cpp ->
* lineCompiler); when finished: now = this();
* now(getter)->setter(this())->{ "string" = getter(this);
* setter(string) = getter(this->setter); } when ^ finished compile;
* if(^compile failed -> |this->failed.|tests->failed.| ||run test
* {this->test}|on fail(action(){return FAILED})|
*/
{ {
final StringBuilder worlds = new StringBuilder(""); final StringBuilder worlds = new StringBuilder("");
for (final String world : PlotMain.getPlotWorlds()) { for (final String world : PlotMain.getPlotWorlds()) {
worlds.append(world + " "); worlds.append(world).append(" ");
} }
information.append(header); information.append(header);
information.append(getSection(section, "Lag / TPS")); information.append(getSection(section, "Lag / TPS"));
@ -85,8 +63,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 + " size", PlotHelper.getWorldFolderSize(world))); information.append(getLine(line, "World: " + world + " size", PlotHelper.getWorldFolderSize(world)));
@ -101,10 +79,6 @@ public class Debug extends SubCommand {
information.append(getLine(line, "Total Messages", C.values().length)); information.append(getLine(line, "Total Messages", C.values().length));
information.append(getLine(line, "View all captions", "/plot debug msg")); information.append(getLine(line, "View all captions", "/plot debug msg"));
} }
/**
* {function:: SEND_MESSAGE |local player -> plr|local string ->
* information.toString())}
*/
{ {
PlayerFunctions.sendMessage(plr, information.toString()); PlayerFunctions.sendMessage(plr, information.toString());
} }

View File

@ -1,16 +1,30 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Claim.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList; import com.google.common.collect.BiMap;
import java.util.UUID; import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
@ -19,20 +33,8 @@ 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 com.google.common.collect.BiMap; import java.util.ArrayList;
import com.intellectualcrafters.plot.C; import java.util.UUID;
import com.intellectualcrafters.plot.FlagManager;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotManager;
import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.StringWrapper;
import com.intellectualcrafters.plot.UUIDHandler;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
/** /**
* @author Citymonstret * @author Citymonstret
@ -47,13 +49,11 @@ public class DebugClaimTest extends SubCommand {
public boolean execute(final Player plr, final String... args) { public boolean execute(final Player plr, final String... args) {
if (plr == null) { if (plr == null) {
if (args.length < 3) { if (args.length < 3) {
PlayerFunctions.sendMessage(plr, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}"); return !PlayerFunctions.sendMessage(null, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
return false;
} }
final World world = Bukkit.getWorld(args[0]); final World world = Bukkit.getWorld(args[0]);
if ((world == null) || !PlotMain.isPlotWorld(world)) { if ((world == null) || !PlotMain.isPlotWorld(world)) {
PlayerFunctions.sendMessage(plr, "&cInvalid plot world!"); return !PlayerFunctions.sendMessage(null, "&cInvalid plot world!");
return false;
} }
PlotId min, max; PlotId min, max;
@ -64,24 +64,22 @@ 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) {
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.");
} }
catch (final Exception e) { PlayerFunctions.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
PlayerFunctions.sendMessage(plr, "&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: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
return false;
}
PlayerFunctions.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
PlayerFunctions.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
final PlotManager manager = PlotMain.getPlotManager(world); final PlotManager manager = PlotMain.getPlotManager(world);
final PlotWorld plotworld = PlotMain.getWorldSettings(world); final PlotWorld plotworld = PlotMain.getWorldSettings(world);
final ArrayList<Plot> plots = new ArrayList<Plot>(); final ArrayList<Plot> plots = new ArrayList<>();
for (final PlotId id : PlayerFunctions.getPlotSelectionIds(world, min, max)) { for (final PlotId id : PlayerFunctions.getPlotSelectionIds(world, min, max)) {
final Plot plot = PlotHelper.getPlot(world, id); final Plot plot = PlotHelper.getPlot(world, id);
final boolean contains = PlotMain.getPlots(world).containsKey(plot.id); final boolean contains = PlotMain.getPlots(world).containsKey(plot.id);
if (contains) { if (contains) {
PlayerFunctions.sendMessage(plr, " - &cDB Already contains: " + plot.id); PlayerFunctions.sendMessage(null, " - &cDB Already contains: " + plot.id);
continue; continue;
} }
@ -100,35 +98,32 @@ public class DebugClaimTest extends SubCommand {
if (block != null) { if (block != null) {
if (block.getState() instanceof Sign) { if (block.getState() instanceof Sign) {
final Sign sign = (Sign) block.getState(); final Sign sign = (Sign) block.getState();
if (sign != null) { String line = sign.getLine(2);
String line = sign.getLine(2); if ((line != null) && (line.length() > 2)) {
if ((line != null) && (line.length() > 2)) { line = line.substring(2);
line = line.substring(2);
final BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap(); final BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
UUID uuid = (map.get(new StringWrapper(line))); UUID uuid = (map.get(new StringWrapper(line)));
if (uuid == null) { if (uuid == null) {
for (final StringWrapper string : map.keySet()) { for (final StringWrapper string : map.keySet()) {
if (string.value.toLowerCase().startsWith(line.toLowerCase())) { if (string.value.toLowerCase().startsWith(line.toLowerCase())) {
uuid = map.get(string); uuid = map.get(string);
break; break;
}
} }
} }
if (uuid == null) { }
uuid = UUIDHandler.getUUID(line); if (uuid == null) {
} uuid = UUIDHandler.getUUID(line);
if (uuid != null) { }
PlayerFunctions.sendMessage(plr, " - &aFound plot: " + plot.id + " : " + line); if (uuid != null) {
plot.owner = uuid; PlayerFunctions.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line);
plot.hasChanged = true; plot.owner = uuid;
plots.add(plot); plot.hasChanged = true;
} plots.add(plot);
else { } else {
PlayerFunctions.sendMessage(plr, " - &cInvalid playername: " + plot.id + " : " + line); PlayerFunctions.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
}
} }
} }
} }
@ -136,7 +131,7 @@ public class DebugClaimTest extends SubCommand {
} }
if (plots.size() > 0) { if (plots.size() > 0) {
PlayerFunctions.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!"); PlayerFunctions.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
DBFunc.createPlots(plots); DBFunc.createPlots(plots);
DBFunc.createAllSettingsAndHelpers(plots); DBFunc.createAllSettingsAndHelpers(plots);
@ -144,25 +139,24 @@ public class DebugClaimTest extends SubCommand {
PlotMain.updatePlot(plot); PlotMain.updatePlot(plot);
} }
PlayerFunctions.sendMessage(plr, "&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(plr, "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;
} }
@SuppressWarnings("unused")
public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport) { public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport) {
return claimPlot(player, plot, teleport, ""); return claimPlot(player, plot, teleport, "");
} }
public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, final String schematic) { public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, @SuppressWarnings("unused") final String schematic) {
final PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot); final PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {

View File

@ -1,20 +1,32 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Claim.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.lang.reflect.Field;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
/** /**
* @author Citymonstret * @author Citymonstret
@ -32,14 +44,12 @@ 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;

View File

@ -1,21 +1,33 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Claim.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import org.bukkit.entity.Player;
import java.util.ArrayList;
/** /**
* @author Citymonstret * @author Citymonstret
@ -33,8 +45,7 @@ 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;

View File

@ -1,27 +1,31 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Delete.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.database.DBFunc;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.database.DBFunc;
/**
* Created by Citymonstret on 2014-08-01.
*/
public class Delete extends SubCommand { public class Delete extends SubCommand {
public Delete() { public Delete() {
@ -31,18 +35,16 @@ public class Delete extends SubCommand {
@Override @Override
public boolean execute(final Player plr, final String... args) { public boolean execute(final Player plr, final String... args) {
if (!PlayerFunctions.isInPlot(plr)) { if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot."); return !sendMessage(plr, C.NOT_IN_PLOT);
return false;
} }
final Plot plot = PlayerFunctions.getCurrentPlot(plr); final Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED); return !sendMessage(plr, C.UNLINK_REQUIRED);
return false;
} }
if ((((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId()))) && !PlotMain.hasPermission(plr, "plots.admin")) { if ((((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId()))) && !PlotMain.hasPermission(plr, "plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return !sendMessage(plr, C.NO_PLOT_PERMS);
return false;
} }
assert plot != null;
final PlotWorld pWorld = PlotMain.getWorldSettings(plot.getWorld()); final PlotWorld pWorld = PlotMain.getWorldSettings(plot.getWorld());
if (PlotMain.useEconomy && pWorld.USE_ECONOMY) { if (PlotMain.useEconomy && pWorld.USE_ECONOMY) {
final double c = pWorld.SELL_PRICE; final double c = pWorld.SELL_PRICE;
@ -59,8 +61,7 @@ public class Delete extends SubCommand {
if ((Math.abs(plot.id.x) <= Math.abs(Auto.lastPlot.x)) && (Math.abs(plot.id.y) <= Math.abs(Auto.lastPlot.y))) { 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 clearing has been denied."); PlayerFunctions.sendMessage(plr, "Plot clearing has been denied.");
} }
return true; return true;

View File

@ -1,28 +1,38 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Denied.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.UUIDHandler; import com.intellectualcrafters.plot.UUIDHandler;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlayerPlotDeniedEvent; import com.intellectualcrafters.plot.events.PlayerPlotDeniedEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.UUID;
/**
* Created by Citymonstret on 2014-08-03.
*/
@SuppressWarnings("deprecated") @SuppressWarnings("deprecated")
public class Denied extends SubCommand { public class Denied extends SubCommand {
@ -50,8 +60,7 @@ 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)) {
@ -71,8 +80,7 @@ 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;
} }
@ -85,8 +93,7 @@ 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)) {
@ -116,8 +123,7 @@ 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;
} }

View File

@ -1,24 +1,36 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Helpers.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.UUIDHandler; import com.intellectualcrafters.plot.UUIDHandler;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlayerPlotHelperEvent; import com.intellectualcrafters.plot.events.PlayerPlotHelperEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.UUID;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class Helpers extends SubCommand { public class Helpers extends SubCommand {
@ -46,8 +58,7 @@ 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)) {
@ -67,15 +78,13 @@ 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)) {
@ -106,8 +115,7 @@ 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;
} }

View File

@ -1,19 +1,31 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Home.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import org.bukkit.entity.Player;
/** /**
* @author Citymonstret * @author Citymonstret
@ -39,16 +51,14 @@ 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()) {
@ -69,8 +79,7 @@ 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;
} }

View File

@ -1,28 +1,36 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Clear.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.database.DBFunc;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotComment;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.database.DBFunc;
/** /**
* Created by Citymonstret on 2014-08-01. * Created by Citymonstret on 2014-08-01.
*/ */
@ -48,17 +56,13 @@ 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;
} }
@ -67,8 +71,7 @@ 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;
} }
@ -76,8 +79,7 @@ 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;
} }
@ -85,8 +87,7 @@ 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;
} }
@ -94,8 +95,7 @@ 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;
} }
@ -103,14 +103,13 @@ 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,8 +140,7 @@ 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;
} }
@ -153,9 +151,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");
return; return;
} } else {
else { final List<String> recipients = Arrays.asList(new String[]{"A", "O", "H", "T", "E"});
final List<String> recipients = Arrays.asList(new String[] { "A", "O", "H", "T", "E" });
int count = 1; int count = 1;
final StringBuilder message = new StringBuilder(); final StringBuilder message = new StringBuilder();
String prefix = ""; String prefix = "";

View File

@ -1,16 +1,28 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Info.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList; import com.intellectualcrafters.plot.*;
import java.util.UUID; import com.intellectualcrafters.plot.database.DBFunc;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -18,15 +30,8 @@ import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import java.util.ArrayList;
import com.intellectualcrafters.plot.PlayerFunctions; import java.util.UUID;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.UUIDHandler;
import com.intellectualcrafters.plot.database.DBFunc;
/** /**
* @author Citymonstret * @author Citymonstret
@ -48,8 +53,7 @@ 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(player, C.INFO_SYNTAX_CONSOLE); PlayerFunctions.sendMessage(player, C.INFO_SYNTAX_CONSOLE);
return false; return false;
@ -69,13 +73,11 @@ 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;
} }
@ -89,14 +91,12 @@ public class Info extends SubCommand {
{ {
if (plot.helpers == null) { if (plot.helpers == null) {
containsEveryone = false; containsEveryone = false;
} } else {
else {
containsEveryone = plot.helpers.contains(DBFunc.everyone); containsEveryone = plot.helpers.contains(DBFunc.everyone);
} }
if (plot.trusted == null) { if (plot.trusted == null) {
trustedEveryone = false; trustedEveryone = false;
} } else {
else {
trustedEveryone = plot.trusted.contains(DBFunc.everyone); trustedEveryone = plot.trusted.contains(DBFunc.everyone);
} }
} }
@ -205,8 +205,7 @@ 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))));
} }
} }

View File

@ -1,15 +1,26 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Inventory.java >> Generated by: Citymonstret at 2014-08-10 13:57 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
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;
@ -17,6 +28,8 @@ 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() {

View File

@ -1,20 +1,32 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Kick.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
/** /**
* Created by Citymonstret on 2014-08-01. * Created by Citymonstret on 2014-08-01.

View File

@ -1,10 +1,23 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = MainCommand.java >> Generated by: Citymonstret at 2014-08-09 01:42 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
@ -34,9 +47,9 @@ public class MainCommand implements CommandExecutor, TabCompleter {
public static final String public static final String
MAIN_PERMISSION = "plots.use"; MAIN_PERMISSION = "plots.use";
private static SubCommand[] _subCommands = new SubCommand[] { 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 DebugClaimTest(), new Inbox(), new Comment(), new Swap(), new MusicSubcommand() }; private static SubCommand[] _subCommands = new SubCommand[]{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 DebugClaimTest(), new Inbox(), new Comment(), new Swap(), new MusicSubcommand()};
public static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() { public static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
{ {
addAll(Arrays.asList(_subCommands)); addAll(Arrays.asList(_subCommands));
} }
@ -85,10 +98,9 @@ public class MainCommand implements CommandExecutor, TabCompleter {
boolean digit = true; boolean digit = true;
String arg2; String arg2;
if (args.length>2) { if (args.length > 2) {
arg2 = args[2]; arg2 = args[2];
} } else {
else {
arg2 = "1"; arg2 = "1";
} }
@ -110,8 +122,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
} }
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.equalsIgnoreCase(args[0])) { if (command.cmd.equalsIgnoreCase(args[0]) || command.alias.equalsIgnoreCase(args[0])) {
final String[] arguments = new String[args.length - 1]; final String[] arguments = new String[args.length - 1];
@ -119,12 +130,10 @@ 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());
} }
} }
@ -146,7 +155,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final Player player) { public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final Player player) {
final List<SubCommand> cmds = new ArrayList<>(); final List<SubCommand> cmds = new ArrayList<>();
for (final SubCommand c : subCommands) { for (final SubCommand c : subCommands) {
if ((c.category == category) && c.permission.hasPermission(player)) { if ((c.category.equals(category)) && c.permission.hasPermission(player)) {
cmds.add(c); cmds.add(c);
} }
} }
@ -224,8 +233,7 @@ 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.startsWith(arg)) {
else if (cmd.alias.startsWith(arg)) {
tabOptions.add(cmd.alias); tabOptions.add(cmd.alias);
} }
} }

View File

@ -1,39 +1,43 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Merge.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList; import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.events.PlotMergeEvent;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
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;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import java.util.ArrayList;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.SetBlockFast;
import com.intellectualcrafters.plot.events.PlotMergeEvent;
/** /**
* @author Citymonstret * @author Citymonstret
*/ */
public class Merge extends SubCommand { public class Merge extends SubCommand {
public static String[] values = new String[] { "north", "east", "south", "west" }; public static String[] values = new String[]{"north", "east", "south", "west"};
public static String[] aliases = new String[] { "n", "e", "s", "w" }; public 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);

View File

@ -1,17 +1,37 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.Arrays; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
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 com.intellectualcrafters.plot.C; import java.util.Arrays;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
public class MusicSubcommand extends SubCommand { public class MusicSubcommand extends SubCommand {
public MusicSubcommand() { public MusicSubcommand() {

View File

@ -1,14 +1,29 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotSelection;
/** /**
* Created by Citymonstret on 2014-10-12. * Created by Citymonstret on 2014-10-12.
*/ */
@ -44,8 +59,7 @@ 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;
} }

View File

@ -1,21 +1,32 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Purge.java >> Generated by: Citymonstret at 2014-08-09 01:42 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import org.bukkit.entity.Player;
/** /**
* @Deprecated * @Deprecated
@ -50,8 +61,7 @@ public class Purge extends SubCommand {
DBFunc.purge(world, id); DBFunc.purge(world, id);
PlayerFunctions.sendMessage(plr, "&aPurge of '" + args[0] + "' was successful!"); PlayerFunctions.sendMessage(plr, "&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);
} }
} }
@ -59,7 +69,7 @@ public class Purge extends SubCommand {
return false; return false;
} }
if (args[1].equals("-o")) { if (args[1].equals("-o")) {
if (PlotMain.getPlots(args[0])==null) { if (PlotMain.getPlots(args[0]) == null) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_WORLD); PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false; return false;
} }
@ -67,8 +77,7 @@ 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;
} }

View File

@ -1,10 +1,30 @@
package com.intellectualcrafters.plot.commands; ////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
import org.bukkit.entity.Player; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.Plot;
import org.bukkit.entity.Player;
/** /**
* Created by Citymonstret on 2014-10-02. * Created by Citymonstret on 2014-10-02.
@ -64,8 +84,7 @@ public class Rate extends SubCommand {
final boolean success = false; final boolean success = false;
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;

View File

@ -1,19 +1,31 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Reload.java >> Generated by: Citymonstret at 2014-08-09 01:42 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld; import com.intellectualcrafters.plot.PlotWorld;
import org.bukkit.entity.Player;
/** /**
* @Deprecated * @Deprecated
@ -40,8 +52,7 @@ 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;

View File

@ -1,26 +1,37 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.HashMap; import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.SchematicHandler.DataCollection;
import com.intellectualcrafters.plot.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 com.intellectualcrafters.jnbt.CompoundTag; import java.util.HashMap;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.SchematicHandler;
import com.intellectualcrafters.plot.SchematicHandler.DataCollection;
import com.intellectualcrafters.plot.SchematicHandler.Dimension;
import com.intellectualcrafters.plot.SetBlockFast;
import com.intellectualcrafters.plot.Settings;
import com.intellectualcrafters.plot.UUIDHandler;
public class Schematic extends SubCommand { public class Schematic extends SubCommand {
@ -30,10 +41,10 @@ public class Schematic extends SubCommand {
// TODO command to fetch schematic from worldedit directory // TODO command to fetch schematic from worldedit directory
} }
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;
@Override @Override
public boolean execute(final Player plr, final String... args) { public boolean execute(final Player plr, final String... args) {
@ -98,8 +109,7 @@ 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;
} }
@ -215,8 +225,7 @@ 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() {
@ -224,8 +233,7 @@ public class Schematic extends SubCommand {
final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + worldname + "," + owner + ".schematic"); 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(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);
} }
} }
@ -259,8 +267,7 @@ 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];
@ -271,13 +278,11 @@ 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(plr, "&cInvalid world or id. Use &7/plots sch save <world> <id>"); PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
return false; return false;
} }
} } else {
else {
PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save <world> <id>"); PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
return false; return false;
} }
@ -285,7 +290,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;
@ -304,8 +309,7 @@ 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() {
@ -313,8 +317,7 @@ public class Schematic extends SubCommand {
final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + world + "," + owner.trim() + ".schematic"); 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);
} }
} }

View File

@ -1,17 +1,31 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Set.java >> Generated by: Citymonstret at 2014-08-09 01:42 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList; import com.intellectualcrafters.plot.*;
import java.util.Arrays; import com.intellectualcrafters.plot.database.DBFunc;
import java.util.List; import com.intellectualcrafters.plot.events.PlotFlagAddEvent;
import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent;
import com.intellectualcrafters.plot.listeners.PlotListener;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -19,22 +33,9 @@ import org.bukkit.Material;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.AbstractFlag; import java.util.ArrayList;
import com.intellectualcrafters.plot.C; import java.util.Arrays;
import com.intellectualcrafters.plot.Flag; import java.util.List;
import com.intellectualcrafters.plot.FlagManager;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotBlock;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotHomePosition;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.StringComparsion;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlotFlagAddEvent;
import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent;
import com.intellectualcrafters.plot.listeners.PlotListener;
/** /**
* @author Citymonstret * @author Citymonstret
@ -45,8 +46,8 @@ public class Set extends SubCommand {
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);
} }
public static String[] values = new String[] { "biome", "wall", "wall_filling", "floor", "alias", "home", "flag" }; public static String[] values = new String[]{"biome", "wall", "wall_filling", "floor", "alias", "home", "flag"};
public static String[] aliases = new String[] { "b", "w", "wf", "f", "a", "h", "fl" }; public static String[] aliases = new String[]{"b", "w", "wf", "f", "a", "h", "fl"};
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
@ -92,8 +93,7 @@ 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");
} }
} }
@ -105,8 +105,7 @@ 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());
} }
@ -174,8 +173,7 @@ public class Set extends SubCommand {
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;
} }
@ -265,8 +263,7 @@ 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 (NullPointerException e) {
material = null; material = null;
} }
/* /*
@ -286,8 +283,7 @@ 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;
} }
@ -343,12 +339,10 @@ 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 {
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;
} }
@ -392,8 +386,7 @@ 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;
} }
@ -405,8 +398,7 @@ public class Set extends SubCommand {
AbstractFlag af = new AbstractFlag(""); AbstractFlag af = new AbstractFlag("");
try { try {
af = new AbstractFlag(args[0].toLowerCase()); af = new AbstractFlag(args[0].toLowerCase());
} } catch (final Exception e) {
catch (final Exception e) {
} }
if (FlagManager.getFlags().contains(af)) { if (FlagManager.getFlags().contains(af)) {
final StringBuilder a = new StringBuilder(); final StringBuilder a = new StringBuilder();

View File

@ -1,23 +1,31 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = SetOwner.java >> Generated by: Citymonstret at 2014-08-09 01:42 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.UUID; import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.database.DBFunc;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import java.util.UUID;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.UUIDHandler;
import com.intellectualcrafters.plot.database.DBFunc;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class SetOwner extends SubCommand { public class SetOwner extends SubCommand {

View File

@ -1,10 +1,28 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.io.IOException; import com.intellectualcrafters.plot.*;
import java.util.ArrayList; import com.intellectualcrafters.plot.generator.DefaultPlotWorld;
import java.util.HashMap;
import java.util.Map;
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;
@ -14,13 +32,10 @@ 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 com.intellectualcrafters.plot.C; import java.io.IOException;
import com.intellectualcrafters.plot.ConfigurationNode; import java.util.ArrayList;
import com.intellectualcrafters.plot.PlayerFunctions; import java.util.HashMap;
import com.intellectualcrafters.plot.PlotGenerator; import java.util.Map;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.generator.DefaultPlotWorld;
/** /**
* Created by Citymonstret on 2014-09-26. * Created by Citymonstret on 2014-09-26.
@ -30,9 +45,9 @@ public class Setup extends SubCommand implements Listener {
public static Map<String, SetupObject> setupMap = new HashMap<>(); public static Map<String, SetupObject> setupMap = new HashMap<>();
private class SetupObject { private class SetupObject {
String world; String world;
String plugin; String plugin;
int current = 0; int current = 0;
ConfigurationNode[] step; ConfigurationNode[] step;
@ -61,8 +76,7 @@ public class Setup extends SubCommand implements Listener {
if (plr == null) { if (plr == null) {
plrname = ""; plrname = "";
} } else {
else {
plrname = plr.getName(); plrname = plr.getName();
} }
@ -76,20 +90,17 @@ 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) {
@ -117,8 +128,7 @@ 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.");
@ -130,8 +140,7 @@ 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;
} }
@ -148,15 +157,13 @@ 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;
@ -200,8 +207,7 @@ 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);
} }

View File

@ -1,17 +1,29 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = SubCommand.java >> Generated by: Citymonstret at 2014-08-09 01:42 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import org.bukkit.entity.Player;
/** /**
* SubCommand class * SubCommand class
@ -19,11 +31,11 @@ import com.intellectualcrafters.plot.PlayerFunctions;
* @author Citymonstret * @author Citymonstret
*/ */
public abstract class SubCommand { public abstract class SubCommand {
public boolean isPlayer; public boolean isPlayer;
/** /**
* Command * Command
*/ */
public String cmd; public String cmd;
/** /**
* Permission node * Permission node
*/ */
@ -31,32 +43,26 @@ public abstract class SubCommand {
/** /**
* Simple description * Simple description
*/ */
public String description; public String description;
/** /**
* Alias * Alias
*/ */
public String alias; public String alias;
/** /**
* Command usage * Command usage
*/ */
public String usage; public String usage;
public CommandCategory category; public CommandCategory category;
/** /**
* @param cmd * @param cmd Command /plot {cmd} <-- That!
* Command /plot {cmd} <-- That! * @param permission Permission Node
* @param permission * @param description Simple description
* Permission Node * @param usage Usage description: /plot command {args...}
* @param description * @param alias Command alias
* Simple description * @param category CommandCategory. Pick whichever closests to what you want.
* @param usage
* Usage description: /plot command {args...}
* @param alias
* Command alias
* @param category
* CommandCategory. Pick whichever closests 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;
@ -69,14 +75,10 @@ public abstract class SubCommand {
} }
/** /**
* @param command * @param command Command /plot {cmd} <-- That!
* Command /plot {cmd} <-- That! * @param description Simple description
* @param description * @param usage Usage description: /plot command {args...}
* Simple description * @param category CommandCategory. Pick whichever closests to what you want.
* @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();
@ -91,10 +93,8 @@ public abstract class SubCommand {
/** /**
* Execute. * Execute.
* *
* @param plr * @param plr executor
* executor * @param args arguments
* @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);
@ -110,8 +110,9 @@ public abstract class SubCommand {
* @param c * @param c
* @param args * @param args
*/ */
public void 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);
return true;
} }
public enum CommandCategory { public enum CommandCategory {

View File

@ -1,25 +1,30 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = Clear.java >> Generated by: Citymonstret at 2014-08-09 01:41 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotSelection;
import com.intellectualcrafters.plot.SetBlockFast;
/** /**
* Created by Citymonstret on 2014-08-01. * Created by Citymonstret on 2014-08-01.
*/ */
@ -59,8 +64,7 @@ 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;

View File

@ -1,25 +1,32 @@
/* ////////////////////////////////////////////////////////////////////////////////////////////////////
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute // PlotSquared - A plot manager and world generator for the Bukkit API /
* and/or monetize any of our intellectual property. IntellectualCrafters is not // Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. // /
* // This program is free software; you can redistribute it and/or modify /
* >> File = TP.java >> Generated by: Citymonstret at 2014-08-09 01:42 // it under the terms of the GNU General Public License as published by /
*/ // the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
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;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
/** /**
* @author Citymonstret * @author Citymonstret
*/ */
@ -57,8 +64,7 @@ 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;

Some files were not shown because too many files have changed in this diff Show More