mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
commit
746c580c84
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
|
PlotSquared/.project
|
||||||
# Created by https://www.gitignore.io
|
# Created by https://www.gitignore.io
|
||||||
|
|
||||||
### Intellij ###
|
### Intellij ###
|
||||||
@ -48,6 +49,8 @@ com_crashlytics_export_strings.xml
|
|||||||
|
|
||||||
|
|
||||||
### Eclipse ###
|
### Eclipse ###
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
*.pydevproject
|
*.pydevproject
|
||||||
.metadata
|
.metadata
|
||||||
.gradle
|
.gradle
|
||||||
@ -93,8 +96,6 @@ local.properties
|
|||||||
|
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
.classpath
|
|
||||||
.project
|
|
||||||
/target
|
/target
|
||||||
/plotsquared/target
|
/plotsquared/target
|
||||||
*.MF
|
*.MF
|
@ -4,9 +4,8 @@ package com.intellectualcrafters.jnbt;
|
|||||||
* The {@code TAG_Byte_Array} tag.
|
* The {@code TAG_Byte_Array} tag.
|
||||||
*/
|
*/
|
||||||
public final class ByteArrayTag extends Tag {
|
public final class ByteArrayTag extends Tag {
|
||||||
|
|
||||||
private final byte[] value;
|
private final byte[] value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* Creates the tag with an empty name.
|
||||||
*
|
*
|
||||||
@ -16,7 +15,7 @@ public final class ByteArrayTag extends Tag {
|
|||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
@ -27,12 +26,12 @@ public final class ByteArrayTag extends Tag {
|
|||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getValue() {
|
public byte[] getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder hex = new StringBuilder();
|
final StringBuilder hex = new StringBuilder();
|
||||||
@ -50,5 +49,4 @@ public final class ByteArrayTag extends Tag {
|
|||||||
}
|
}
|
||||||
return "TAG_Byte_Array" + append + ": " + hex;
|
return "TAG_Byte_Array" + append + ": " + hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,8 @@ package com.intellectualcrafters.jnbt;
|
|||||||
* The {@code TAG_Byte} tag.
|
* The {@code TAG_Byte} tag.
|
||||||
*/
|
*/
|
||||||
public final class ByteTag extends Tag {
|
public final class ByteTag extends Tag {
|
||||||
|
|
||||||
private final byte value;
|
private final byte value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* Creates the tag with an empty name.
|
||||||
*
|
*
|
||||||
@ -16,7 +15,7 @@ public final class ByteTag extends Tag {
|
|||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
@ -27,12 +26,12 @@ public final class ByteTag extends Tag {
|
|||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Byte getValue() {
|
public Byte getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
@ -42,5 +41,4 @@ public final class ByteTag extends Tag {
|
|||||||
}
|
}
|
||||||
return "TAG_Byte" + append + ": " + this.value;
|
return "TAG_Byte" + append + ": " + this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,8 @@ import java.util.Map;
|
|||||||
* The {@code TAG_Compound} tag.
|
* The {@code TAG_Compound} tag.
|
||||||
*/
|
*/
|
||||||
public final class CompoundTag extends Tag {
|
public final class CompoundTag extends Tag {
|
||||||
|
|
||||||
private final Map<String, Tag> value;
|
private final Map<String, Tag> value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* Creates the tag with an empty name.
|
||||||
*
|
*
|
||||||
@ -21,7 +20,7 @@ public final class CompoundTag extends Tag {
|
|||||||
super();
|
super();
|
||||||
this.value = Collections.unmodifiableMap(value);
|
this.value = Collections.unmodifiableMap(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
@ -32,7 +31,7 @@ public final class CompoundTag extends Tag {
|
|||||||
super(name);
|
super(name);
|
||||||
this.value = Collections.unmodifiableMap(value);
|
this.value = Collections.unmodifiableMap(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this compound tag contains the given key.
|
* Returns whether this compound tag contains the given key.
|
||||||
*
|
*
|
||||||
@ -43,12 +42,12 @@ public final class CompoundTag extends Tag {
|
|||||||
public boolean containsKey(final String key) {
|
public boolean containsKey(final String key) {
|
||||||
return this.value.containsKey(key);
|
return this.value.containsKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Tag> getValue() {
|
public Map<String, Tag> getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a new compound tag with the given values.
|
* Return a new compound tag with the given values.
|
||||||
*
|
*
|
||||||
@ -59,7 +58,7 @@ public final class CompoundTag extends Tag {
|
|||||||
public CompoundTag setValue(final Map<String, Tag> value) {
|
public CompoundTag setValue(final Map<String, Tag> value) {
|
||||||
return new CompoundTag(getName(), value);
|
return new CompoundTag(getName(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a compound tag builder.
|
* Create a compound tag builder.
|
||||||
*
|
*
|
||||||
@ -68,7 +67,7 @@ public final class CompoundTag extends Tag {
|
|||||||
public CompoundTagBuilder createBuilder() {
|
public CompoundTagBuilder createBuilder() {
|
||||||
return new CompoundTagBuilder(new HashMap<String, Tag>(this.value));
|
return new CompoundTagBuilder(new HashMap<String, Tag>(this.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a byte array named with the given key. <p/> <p> If the key does not exist or its value is not a byte array
|
* Get a byte array named with the given key. <p/> <p> If the key does not exist or its value is not a byte array
|
||||||
* tag, then an empty byte array will be returned. </p>
|
* tag, then an empty byte array will be returned. </p>
|
||||||
@ -85,7 +84,7 @@ public final class CompoundTag extends Tag {
|
|||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a byte named with the given key. <p/> <p> If the key does not exist or its value is not a byte tag, then
|
* Get a byte named with the given key. <p/> <p> If the key does not exist or its value is not a byte tag, then
|
||||||
* {@code 0} will be returned. </p>
|
* {@code 0} will be returned. </p>
|
||||||
@ -102,7 +101,7 @@ public final class CompoundTag extends Tag {
|
|||||||
return (byte) 0;
|
return (byte) 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a double named with the given key. <p/> <p> If the key does not exist or its value is not a double tag, then
|
* Get a double named with the given key. <p/> <p> If the key does not exist or its value is not a double tag, then
|
||||||
* {@code 0} will be returned. </p>
|
* {@code 0} will be returned. </p>
|
||||||
@ -119,7 +118,7 @@ public final class CompoundTag extends Tag {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a double named with the given key, even if it's another type of number. <p/> <p> If the key does not exist or
|
* Get a double named with the given key, even if it's another type of number. <p/> <p> If the key does not exist or
|
||||||
* its value is not a number, then {@code 0} will be returned. </p>
|
* its value is not a number, then {@code 0} will be returned. </p>
|
||||||
@ -132,27 +131,21 @@ public final class CompoundTag extends Tag {
|
|||||||
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 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. <p/> <p> If the key does not exist or its value is not a float tag, then
|
* Get a float named with the given key. <p/> <p> If the key does not exist or its value is not a float tag, then
|
||||||
* {@code 0} will be returned. </p>
|
* {@code 0} will be returned. </p>
|
||||||
@ -169,7 +162,7 @@ public final class CompoundTag extends Tag {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a {@code int[]} named with the given key. <p/> <p> If the key does not exist or its value is not an int array
|
* Get a {@code int[]} named with the given key. <p/> <p> If the key does not exist or its value is not an int array
|
||||||
* tag, then an empty array will be returned. </p>
|
* tag, then an empty array will be returned. </p>
|
||||||
@ -186,7 +179,7 @@ public final class CompoundTag extends Tag {
|
|||||||
return new int[0];
|
return new int[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an int named with the given key. <p/> <p> If the key does not exist or its value is not an int tag, then
|
* Get an int named with the given key. <p/> <p> If the key does not exist or its value is not an int tag, then
|
||||||
* {@code 0} will be returned. </p>
|
* {@code 0} will be returned. </p>
|
||||||
@ -203,7 +196,7 @@ public final class CompoundTag extends Tag {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an int named with the given key, even if it's another type of number. <p/> <p> If the key does not exist or
|
* Get an int named with the given key, even if it's another type of number. <p/> <p> If the key does not exist or
|
||||||
* its value is not a number, then {@code 0} will be returned. </p>
|
* its value is not a number, then {@code 0} will be returned. </p>
|
||||||
@ -216,27 +209,21 @@ public final class CompoundTag extends Tag {
|
|||||||
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 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. <p/> <p> If the key does not exist or its value is not a list tag,
|
* Get a list of tags named with the given key. <p/> <p> If the key does not exist or its value is not a list tag,
|
||||||
* then an empty list will be returned. </p>
|
* then an empty list will be returned. </p>
|
||||||
@ -253,7 +240,7 @@ public final class CompoundTag extends Tag {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a {@code TagList} named with the given key. <p/> <p> If the key does not exist or its value is not a list
|
* Get a {@code TagList} named with the given key. <p/> <p> If the key does not exist or its value is not a list
|
||||||
* tag, then an empty tag list will be returned. </p>
|
* tag, then an empty tag list will be returned. </p>
|
||||||
@ -267,10 +254,10 @@ public final class CompoundTag extends Tag {
|
|||||||
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. <p/> <p> If the key does not exist or its value is not a list tag,
|
* Get a list of tags named with the given key. <p/> <p> If the key does not exist or its value is not a list tag,
|
||||||
* then an empty list will be returned. If the given key references a list but the list of of a different type, then
|
* then an empty list will be returned. If the given key references a list but the list of of a different type, then
|
||||||
@ -296,7 +283,7 @@ public final class CompoundTag extends Tag {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a long named with the given key. <p/> <p> If the key does not exist or its value is not a long tag, then
|
* Get a long named with the given key. <p/> <p> If the key does not exist or its value is not a long tag, then
|
||||||
* {@code 0} will be returned. </p>
|
* {@code 0} will be returned. </p>
|
||||||
@ -313,7 +300,7 @@ public final class CompoundTag extends Tag {
|
|||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a long named with the given key, even if it's another type of number. <p/> <p> If the key does not exist or
|
* Get a long named with the given key, even if it's another type of number. <p/> <p> If the key does not exist or
|
||||||
* its value is not a number, then {@code 0} will be returned. </p>
|
* its value is not a number, then {@code 0} will be returned. </p>
|
||||||
@ -326,27 +313,21 @@ public final class CompoundTag extends Tag {
|
|||||||
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 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. <p/> <p> If the key does not exist or its value is not a short tag, then
|
* Get a short named with the given key. <p/> <p> If the key does not exist or its value is not a short tag, then
|
||||||
* {@code 0} will be returned. </p>
|
* {@code 0} will be returned. </p>
|
||||||
@ -363,7 +344,7 @@ public final class CompoundTag extends Tag {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a string named with the given key. <p/> <p> If the key does not exist or its value is not a string tag, then
|
* Get a string named with the given key. <p/> <p> If the key does not exist or its value is not a string tag, then
|
||||||
* {@code ""} will be returned. </p>
|
* {@code ""} will be returned. </p>
|
||||||
@ -380,7 +361,7 @@ public final class CompoundTag extends Tag {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
@ -396,5 +377,4 @@ public final class CompoundTag extends Tag {
|
|||||||
bldr.append("}");
|
bldr.append("}");
|
||||||
return bldr.toString();
|
return bldr.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,16 +9,15 @@ import java.util.Map;
|
|||||||
* Helps create compound tags.
|
* Helps create compound tags.
|
||||||
*/
|
*/
|
||||||
public class CompoundTagBuilder {
|
public class CompoundTagBuilder {
|
||||||
|
|
||||||
private final Map<String, Tag> entries;
|
private final Map<String, Tag> entries;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
*/
|
*/
|
||||||
CompoundTagBuilder() {
|
CompoundTagBuilder() {
|
||||||
this.entries = new HashMap<String, Tag>();
|
this.entries = new HashMap<String, Tag>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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).
|
||||||
*
|
*
|
||||||
@ -28,7 +27,7 @@ public class CompoundTagBuilder {
|
|||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
this.entries = value;
|
this.entries = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new builder instance.
|
* Create a new builder instance.
|
||||||
*
|
*
|
||||||
@ -37,7 +36,7 @@ public class CompoundTagBuilder {
|
|||||||
public static CompoundTagBuilder create() {
|
public static CompoundTagBuilder create() {
|
||||||
return new CompoundTagBuilder();
|
return new CompoundTagBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put the given key and tag into the compound tag.
|
* Put the given key and tag into the compound tag.
|
||||||
*
|
*
|
||||||
@ -52,7 +51,7 @@ public class CompoundTagBuilder {
|
|||||||
this.entries.put(key, value);
|
this.entries.put(key, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put the given key and value into the compound tag as a {@code ByteArrayTag}.
|
* Put the given key and value into the compound tag as a {@code ByteArrayTag}.
|
||||||
*
|
*
|
||||||
@ -64,7 +63,7 @@ public class CompoundTagBuilder {
|
|||||||
public CompoundTagBuilder putByteArray(final String key, final byte[] value) {
|
public CompoundTagBuilder putByteArray(final String key, final byte[] value) {
|
||||||
return put(key, new ByteArrayTag(key, value));
|
return put(key, new ByteArrayTag(key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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}.
|
||||||
*
|
*
|
||||||
@ -76,7 +75,7 @@ public class CompoundTagBuilder {
|
|||||||
public CompoundTagBuilder putByte(final String key, final byte value) {
|
public CompoundTagBuilder putByte(final String key, final byte value) {
|
||||||
return put(key, new ByteTag(key, value));
|
return put(key, new ByteTag(key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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}.
|
||||||
*
|
*
|
||||||
@ -88,7 +87,7 @@ public class CompoundTagBuilder {
|
|||||||
public CompoundTagBuilder putDouble(final String key, final double value) {
|
public CompoundTagBuilder putDouble(final String key, final double value) {
|
||||||
return put(key, new DoubleTag(key, value));
|
return put(key, new DoubleTag(key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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}.
|
||||||
*
|
*
|
||||||
@ -100,7 +99,7 @@ public class CompoundTagBuilder {
|
|||||||
public CompoundTagBuilder putFloat(final String key, final float value) {
|
public CompoundTagBuilder putFloat(final String key, final float value) {
|
||||||
return put(key, new FloatTag(key, value));
|
return put(key, new FloatTag(key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put the given key and value into the compound tag as a {@code IntArrayTag}.
|
* Put the given key and value into the compound tag as a {@code IntArrayTag}.
|
||||||
*
|
*
|
||||||
@ -112,7 +111,7 @@ public class CompoundTagBuilder {
|
|||||||
public CompoundTagBuilder putIntArray(final String key, final int[] value) {
|
public CompoundTagBuilder putIntArray(final String key, final int[] value) {
|
||||||
return put(key, new IntArrayTag(key, value));
|
return put(key, new IntArrayTag(key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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}.
|
||||||
*
|
*
|
||||||
@ -124,7 +123,7 @@ public class CompoundTagBuilder {
|
|||||||
public CompoundTagBuilder putInt(final String key, final int value) {
|
public CompoundTagBuilder putInt(final String key, final int value) {
|
||||||
return put(key, new IntTag(key, value));
|
return put(key, new IntTag(key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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}.
|
||||||
*
|
*
|
||||||
@ -136,7 +135,7 @@ public class CompoundTagBuilder {
|
|||||||
public CompoundTagBuilder putLong(final String key, final long value) {
|
public CompoundTagBuilder putLong(final String key, final long value) {
|
||||||
return put(key, new LongTag(key, value));
|
return put(key, new LongTag(key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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}.
|
||||||
*
|
*
|
||||||
@ -148,7 +147,7 @@ public class CompoundTagBuilder {
|
|||||||
public CompoundTagBuilder putShort(final String key, final short value) {
|
public CompoundTagBuilder putShort(final String key, final short value) {
|
||||||
return put(key, new ShortTag(key, value));
|
return put(key, new ShortTag(key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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}.
|
||||||
*
|
*
|
||||||
@ -160,7 +159,7 @@ public class CompoundTagBuilder {
|
|||||||
public CompoundTagBuilder putString(final String key, final String value) {
|
public CompoundTagBuilder putString(final String key, final String value) {
|
||||||
return put(key, new StringTag(key, value));
|
return put(key, new StringTag(key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put all the entries from the given map into this map.
|
* Put all the entries from the given map into this map.
|
||||||
*
|
*
|
||||||
@ -175,7 +174,7 @@ public class CompoundTagBuilder {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build an unnamed compound tag with this builder's entries.
|
* Build an unnamed compound tag with this builder's entries.
|
||||||
*
|
*
|
||||||
@ -184,7 +183,7 @@ public class CompoundTagBuilder {
|
|||||||
public CompoundTag build() {
|
public CompoundTag build() {
|
||||||
return new CompoundTag(new HashMap<String, Tag>(this.entries));
|
return new CompoundTag(new HashMap<String, Tag>(this.entries));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a new compound tag with this builder's entries.
|
* Build a new compound tag with this builder's entries.
|
||||||
*
|
*
|
||||||
@ -195,5 +194,4 @@ public class CompoundTagBuilder {
|
|||||||
public CompoundTag build(final String name) {
|
public CompoundTag build(final String name) {
|
||||||
return new CompoundTag(name, new HashMap<String, Tag>(this.entries));
|
return new CompoundTag(name, new HashMap<String, Tag>(this.entries));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,8 @@ 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 {
|
||||||
|
|
||||||
private final double value;
|
private final double value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* Creates the tag with an empty name.
|
||||||
*
|
*
|
||||||
@ -16,7 +15,7 @@ public final class DoubleTag extends Tag {
|
|||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
@ -27,12 +26,12 @@ public final class DoubleTag extends Tag {
|
|||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Double getValue() {
|
public Double getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
@ -42,5 +41,4 @@ public final class DoubleTag extends Tag {
|
|||||||
}
|
}
|
||||||
return "TAG_Double" + append + ": " + this.value;
|
return "TAG_Double" + append + ": " + this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,22 +4,20 @@ package com.intellectualcrafters.jnbt;
|
|||||||
* The {@code TAG_End} tag.
|
* The {@code TAG_End} tag.
|
||||||
*/
|
*/
|
||||||
public final class EndTag extends Tag {
|
public final class EndTag extends Tag {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*/
|
*/
|
||||||
public EndTag() {
|
public EndTag() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValue() {
|
public Object getValue() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "TAG_End";
|
return "TAG_End";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,8 @@ package com.intellectualcrafters.jnbt;
|
|||||||
* The {@code TAG_Float} tag.
|
* The {@code TAG_Float} tag.
|
||||||
*/
|
*/
|
||||||
public final class FloatTag extends Tag {
|
public final class FloatTag extends Tag {
|
||||||
|
|
||||||
private final float value;
|
private final float value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* Creates the tag with an empty name.
|
||||||
*
|
*
|
||||||
@ -16,7 +15,7 @@ public final class FloatTag extends Tag {
|
|||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
@ -27,12 +26,12 @@ public final class FloatTag extends Tag {
|
|||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Float getValue() {
|
public Float getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
@ -42,5 +41,4 @@ public final class FloatTag extends Tag {
|
|||||||
}
|
}
|
||||||
return "TAG_Float" + append + ": " + this.value;
|
return "TAG_Float" + append + ": " + this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
* The {@code TAG_Int_Array} tag.
|
* The {@code TAG_Int_Array} tag.
|
||||||
*/
|
*/
|
||||||
public final class IntArrayTag extends Tag {
|
public final class IntArrayTag extends Tag {
|
||||||
|
|
||||||
private final int[] value;
|
private final int[] value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* Creates the tag with an empty name.
|
||||||
*
|
*
|
||||||
@ -19,7 +18,7 @@ public final class IntArrayTag extends Tag {
|
|||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
@ -31,12 +30,12 @@ public final class IntArrayTag extends Tag {
|
|||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getValue() {
|
public int[] getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder hex = new StringBuilder();
|
final StringBuilder hex = new StringBuilder();
|
||||||
@ -54,5 +53,4 @@ public final class IntArrayTag extends Tag {
|
|||||||
}
|
}
|
||||||
return "TAG_Int_Array" + append + ": " + hex;
|
return "TAG_Int_Array" + append + ": " + hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,8 @@ package com.intellectualcrafters.jnbt;
|
|||||||
* The {@code TAG_Int} tag.
|
* The {@code TAG_Int} tag.
|
||||||
*/
|
*/
|
||||||
public final class IntTag extends Tag {
|
public final class IntTag extends Tag {
|
||||||
|
|
||||||
private final int value;
|
private final int value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* Creates the tag with an empty name.
|
||||||
*
|
*
|
||||||
@ -16,7 +15,7 @@ public final class IntTag extends Tag {
|
|||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
@ -27,12 +26,12 @@ public final class IntTag extends Tag {
|
|||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getValue() {
|
public Integer getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
@ -42,5 +41,4 @@ public final class IntTag extends Tag {
|
|||||||
}
|
}
|
||||||
return "TAG_Int" + append + ": " + this.value;
|
return "TAG_Int" + append + ": " + this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,9 @@ import javax.annotation.Nullable;
|
|||||||
* The {@code TAG_List} tag.
|
* The {@code TAG_List} tag.
|
||||||
*/
|
*/
|
||||||
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.
|
||||||
*
|
*
|
||||||
@ -28,7 +27,7 @@ public final class ListTag extends Tag {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
this.value = Collections.unmodifiableList(value);
|
this.value = Collections.unmodifiableList(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
@ -42,7 +41,7 @@ public final class ListTag extends Tag {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
this.value = Collections.unmodifiableList(value);
|
this.value = Collections.unmodifiableList(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the type of item in this list.
|
* Gets the type of item in this list.
|
||||||
*
|
*
|
||||||
@ -51,12 +50,12 @@ public final class ListTag extends Tag {
|
|||||||
public Class<? extends Tag> getType() {
|
public Class<? extends Tag> getType() {
|
||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Tag> getValue() {
|
public List<Tag> getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new list tag with this tag's name and type.
|
* Create a new list tag with this tag's name and type.
|
||||||
*
|
*
|
||||||
@ -67,7 +66,7 @@ public final class ListTag extends Tag {
|
|||||||
public ListTag setValue(final List<Tag> list) {
|
public ListTag setValue(final List<Tag> list) {
|
||||||
return new ListTag(getName(), getType(), list);
|
return new ListTag(getName(), getType(), list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the tag if it exists at the given index.
|
* Get the tag if it exists at the given index.
|
||||||
*
|
*
|
||||||
@ -83,7 +82,7 @@ public final class ListTag extends Tag {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a byte array named with the given index. <p/> <p> If the index does not exist or its value is not a byte
|
* Get a byte array named with the given index. <p/> <p> If the index does not exist or its value is not a byte
|
||||||
* array tag, then an empty byte array will be returned. </p>
|
* array tag, then an empty byte array will be returned. </p>
|
||||||
@ -100,7 +99,7 @@ public final class ListTag extends Tag {
|
|||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a byte named with the given index. <p/> <p> If the index does not exist or its value is not a byte tag, then
|
* Get a byte named with the given index. <p/> <p> If the index does not exist or its value is not a byte tag, then
|
||||||
* {@code 0} will be returned. </p>
|
* {@code 0} will be returned. </p>
|
||||||
@ -117,7 +116,7 @@ public final class ListTag extends Tag {
|
|||||||
return (byte) 0;
|
return (byte) 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a double named with the given index. <p/> <p> If the index does not exist or its value is not a double tag,
|
* Get a double named with the given index. <p/> <p> If the index does not exist or its value is not a double tag,
|
||||||
* then {@code 0} will be returned. </p>
|
* then {@code 0} will be returned. </p>
|
||||||
@ -134,7 +133,7 @@ public final class ListTag extends Tag {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a double named with the given index, even if it's another type of number. <p/> <p> If the index does not
|
* Get a double named with the given index, even if it's another type of number. <p/> <p> If the index does not
|
||||||
* exist or its value is not a number, then {@code 0} will be returned. </p>
|
* exist or its value is not a number, then {@code 0} will be returned. </p>
|
||||||
@ -147,27 +146,21 @@ public final class ListTag extends Tag {
|
|||||||
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 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. <p/> <p> If the index does not exist or its value is not a float tag,
|
* Get a float named with the given index. <p/> <p> If the index does not exist or its value is not a float tag,
|
||||||
* then {@code 0} will be returned. </p>
|
* then {@code 0} will be returned. </p>
|
||||||
@ -184,7 +177,7 @@ public final class ListTag extends Tag {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a {@code int[]} named with the given index. <p/> <p> If the index does not exist or its value is not an int
|
* Get a {@code int[]} named with the given index. <p/> <p> If the index does not exist or its value is not an int
|
||||||
* array tag, then an empty array will be returned. </p>
|
* array tag, then an empty array will be returned. </p>
|
||||||
@ -201,7 +194,7 @@ public final class ListTag extends Tag {
|
|||||||
return new int[0];
|
return new int[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an int named with the given index. <p/> <p> If the index does not exist or its value is not an int tag, then
|
* Get an int named with the given index. <p/> <p> If the index does not exist or its value is not an int tag, then
|
||||||
* {@code 0} will be returned. </p>
|
* {@code 0} will be returned. </p>
|
||||||
@ -218,7 +211,7 @@ public final class ListTag extends Tag {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an int named with the given index, even if it's another type of number. <p/> <p> If the index does not exist
|
* Get an int named with the given index, even if it's another type of number. <p/> <p> If the index does not exist
|
||||||
* or its value is not a number, then {@code 0} will be returned. </p>
|
* or its value is not a number, then {@code 0} will be returned. </p>
|
||||||
@ -231,27 +224,21 @@ public final class ListTag extends Tag {
|
|||||||
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 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. <p/> <p> If the index does not exist or its value is not a list
|
* Get a list of tags named with the given index. <p/> <p> If the index does not exist or its value is not a list
|
||||||
* tag, then an empty list will be returned. </p>
|
* tag, then an empty list will be returned. </p>
|
||||||
@ -268,7 +255,7 @@ public final class ListTag extends Tag {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a {@code TagList} named with the given index. <p/> <p> If the index does not exist or its value is not a list
|
* Get a {@code TagList} named with the given index. <p/> <p> If the index does not exist or its value is not a list
|
||||||
* tag, then an empty tag list will be returned. </p>
|
* tag, then an empty tag list will be returned. </p>
|
||||||
@ -282,10 +269,10 @@ public final class ListTag extends Tag {
|
|||||||
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. <p/> <p> If the index does not exist or its value is not a list
|
* Get a list of tags named with the given index. <p/> <p> If the index does not exist or its value is not a list
|
||||||
* tag, then an empty list will be returned. If the given index references a list but the list of of a different
|
* tag, then an empty list will be returned. If the given index references a list but the list of of a different
|
||||||
@ -311,7 +298,7 @@ public final class ListTag extends Tag {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a long named with the given index. <p/> <p> If the index does not exist or its value is not a long tag, then
|
* Get a long named with the given index. <p/> <p> If the index does not exist or its value is not a long tag, then
|
||||||
* {@code 0} will be returned. </p>
|
* {@code 0} will be returned. </p>
|
||||||
@ -328,7 +315,7 @@ public final class ListTag extends Tag {
|
|||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a long named with the given index, even if it's another type of number. <p/> <p> If the index does not exist
|
* Get a long named with the given index, even if it's another type of number. <p/> <p> If the index does not exist
|
||||||
* or its value is not a number, then {@code 0} will be returned. </p>
|
* or its value is not a number, then {@code 0} will be returned. </p>
|
||||||
@ -341,27 +328,21 @@ public final class ListTag extends Tag {
|
|||||||
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 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. <p/> <p> If the index does not exist or its value is not a short tag,
|
* Get a short named with the given index. <p/> <p> If the index does not exist or its value is not a short tag,
|
||||||
* then {@code 0} will be returned. </p>
|
* then {@code 0} will be returned. </p>
|
||||||
@ -378,7 +359,7 @@ public final class ListTag extends Tag {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a string named with the given index. <p/> <p> If the index does not exist or its value is not a string tag,
|
* Get a string named with the given index. <p/> <p> If the index does not exist or its value is not a string tag,
|
||||||
* then {@code ""} will be returned. </p>
|
* then {@code ""} will be returned. </p>
|
||||||
@ -395,7 +376,7 @@ public final class ListTag extends Tag {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
@ -411,5 +392,4 @@ public final class ListTag extends Tag {
|
|||||||
bldr.append("}");
|
bldr.append("}");
|
||||||
return bldr.toString();
|
return bldr.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,9 @@ import java.util.List;
|
|||||||
* 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.
|
||||||
*
|
*
|
||||||
@ -25,7 +24,7 @@ public class ListTagBuilder {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
this.entries = new ArrayList<Tag>();
|
this.entries = new ArrayList<Tag>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new builder instance.
|
* Create a new builder instance.
|
||||||
*
|
*
|
||||||
@ -34,7 +33,7 @@ public class ListTagBuilder {
|
|||||||
public static ListTagBuilder create(final Class<? extends Tag> type) {
|
public static ListTagBuilder create(final Class<? extends Tag> type) {
|
||||||
return new ListTagBuilder(type);
|
return new ListTagBuilder(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new builder instance.
|
* Create a new builder instance.
|
||||||
*
|
*
|
||||||
@ -43,23 +42,20 @@ public class ListTagBuilder {
|
|||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <T extends Tag> ListTagBuilder createWith(final T... entries) {
|
public static <T extends Tag> ListTagBuilder createWith(final T... entries) {
|
||||||
checkNotNull(entries);
|
checkNotNull(entries);
|
||||||
|
|
||||||
if (entries.length == 0) {
|
if (entries.length == 0) {
|
||||||
throw new IllegalArgumentException("This method needs an array of at least one entry");
|
throw new IllegalArgumentException("This method needs an array of at least one entry");
|
||||||
}
|
}
|
||||||
|
|
||||||
final Class<? extends Tag> type = entries[0].getClass();
|
final Class<? extends Tag> type = entries[0].getClass();
|
||||||
for (int i = 1; i < entries.length; i++) {
|
for (int i = 1; i < entries.length; i++) {
|
||||||
if (!type.isInstance(entries[i])) {
|
if (!type.isInstance(entries[i])) {
|
||||||
throw new IllegalArgumentException("An array of different tag types was provided");
|
throw new IllegalArgumentException("An array of different tag types was provided");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final ListTagBuilder builder = new ListTagBuilder(type);
|
final ListTagBuilder builder = new ListTagBuilder(type);
|
||||||
builder.addAll(Arrays.asList(entries));
|
builder.addAll(Arrays.asList(entries));
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the given tag.
|
* Add the given tag.
|
||||||
*
|
*
|
||||||
@ -75,7 +71,7 @@ public class ListTagBuilder {
|
|||||||
this.entries.add(value);
|
this.entries.add(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add all the tags in the given list.
|
* Add all the tags in the given list.
|
||||||
*
|
*
|
||||||
@ -90,7 +86,7 @@ public class ListTagBuilder {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build an unnamed list tag with this builder's entries.
|
* Build an unnamed list tag with this builder's entries.
|
||||||
*
|
*
|
||||||
@ -99,7 +95,7 @@ public class ListTagBuilder {
|
|||||||
public ListTag build() {
|
public ListTag build() {
|
||||||
return new ListTag(this.type, new ArrayList<Tag>(this.entries));
|
return new ListTag(this.type, new ArrayList<Tag>(this.entries));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a new list tag with this builder's entries.
|
* Build a new list tag with this builder's entries.
|
||||||
*
|
*
|
||||||
@ -110,5 +106,4 @@ public class ListTagBuilder {
|
|||||||
public ListTag build(final String name) {
|
public ListTag build(final String name) {
|
||||||
return new ListTag(name, this.type, new ArrayList<Tag>(this.entries));
|
return new ListTag(name, this.type, new ArrayList<Tag>(this.entries));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,8 @@ 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 {
|
||||||
|
|
||||||
private final long value;
|
private final long value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* Creates the tag with an empty name.
|
||||||
*
|
*
|
||||||
@ -16,7 +15,7 @@ public final class LongTag extends Tag {
|
|||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
@ -27,12 +26,12 @@ public final class LongTag extends Tag {
|
|||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getValue() {
|
public Long getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
@ -42,5 +41,4 @@ public final class LongTag extends Tag {
|
|||||||
}
|
}
|
||||||
return "TAG_Long" + append + ": " + this.value;
|
return "TAG_Long" + append + ": " + this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// 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;
|
||||||
@ -27,18 +26,15 @@ import java.nio.charset.Charset;
|
|||||||
* A class which holds constant values.
|
* A class which holds constant values.
|
||||||
*/
|
*/
|
||||||
public final class NBTConstants {
|
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.
|
||||||
*/
|
*/
|
||||||
private NBTConstants() {
|
private NBTConstants() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a type ID to its corresponding {@link Tag} class.
|
* Convert a type ID to its corresponding {@link Tag} class.
|
||||||
*
|
*
|
||||||
@ -78,5 +74,4 @@ public final class NBTConstants {
|
|||||||
throw new IllegalArgumentException("Unknown tag type ID of " + id);
|
throw new IllegalArgumentException("Unknown tag type ID of " + id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,8 @@ import java.util.Map;
|
|||||||
* may be found at <a href="http://www.minecraft.net/docs/NBT.txt"> http://www.minecraft.net/docs/NBT.txt</a>. </p>
|
* may be found at <a href="http://www.minecraft.net/docs/NBT.txt"> http://www.minecraft.net/docs/NBT.txt</a>. </p>
|
||||||
*/
|
*/
|
||||||
public final class NBTInputStream implements Closeable {
|
public final class NBTInputStream implements Closeable {
|
||||||
|
|
||||||
private final DataInputStream is;
|
private final DataInputStream is;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@code NBTInputStream}, which will source its data from the specified input stream.
|
* Creates a new {@code NBTInputStream}, which will source its data from the specified input stream.
|
||||||
*
|
*
|
||||||
@ -28,7 +27,7 @@ public final class NBTInputStream implements Closeable {
|
|||||||
public NBTInputStream(final InputStream is) throws IOException {
|
public NBTInputStream(final InputStream is) throws IOException {
|
||||||
this.is = new DataInputStream(is);
|
this.is = new DataInputStream(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads an NBT tag from the stream.
|
* Reads an NBT tag from the stream.
|
||||||
*
|
*
|
||||||
@ -39,7 +38,7 @@ public final class NBTInputStream implements Closeable {
|
|||||||
public Tag readTag() throws IOException {
|
public Tag readTag() throws IOException {
|
||||||
return readTag(0);
|
return readTag(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads an NBT from the stream.
|
* Reads an NBT from the stream.
|
||||||
*
|
*
|
||||||
@ -51,7 +50,6 @@ public final class NBTInputStream implements Closeable {
|
|||||||
*/
|
*/
|
||||||
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;
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
if (type != NBTConstants.TYPE_END) {
|
if (type != NBTConstants.TYPE_END) {
|
||||||
final int nameLength = this.is.readShort() & 0xFFFF;
|
final int nameLength = this.is.readShort() & 0xFFFF;
|
||||||
@ -61,10 +59,9 @@ public final class NBTInputStream implements Closeable {
|
|||||||
} else {
|
} else {
|
||||||
name = "";
|
name = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return readTagPayload(type, name, depth);
|
return readTagPayload(type, name, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the payload of a tag, given the name and type.
|
* Reads the payload of a tag, given the name and type.
|
||||||
*
|
*
|
||||||
@ -109,7 +106,6 @@ public final class NBTInputStream implements Closeable {
|
|||||||
case NBTConstants.TYPE_LIST:
|
case NBTConstants.TYPE_LIST:
|
||||||
final int childType = this.is.readByte();
|
final int childType = this.is.readByte();
|
||||||
length = this.is.readInt();
|
length = this.is.readInt();
|
||||||
|
|
||||||
final List<Tag> tagList = new ArrayList<Tag>();
|
final List<Tag> tagList = new ArrayList<Tag>();
|
||||||
for (int i = 0; i < length; ++i) {
|
for (int i = 0; i < length; ++i) {
|
||||||
final Tag tag = readTagPayload(childType, "", depth + 1);
|
final Tag tag = readTagPayload(childType, "", depth + 1);
|
||||||
@ -118,7 +114,6 @@ public final class NBTInputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
tagList.add(tag);
|
tagList.add(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ListTag(name, NBTUtils.getTypeClass(childType), tagList);
|
return new ListTag(name, NBTUtils.getTypeClass(childType), tagList);
|
||||||
case NBTConstants.TYPE_COMPOUND:
|
case NBTConstants.TYPE_COMPOUND:
|
||||||
final Map<String, Tag> tagMap = new HashMap<String, Tag>();
|
final Map<String, Tag> tagMap = new HashMap<String, Tag>();
|
||||||
@ -130,7 +125,6 @@ public final class NBTInputStream implements Closeable {
|
|||||||
tagMap.put(tag.getName(), tag);
|
tagMap.put(tag.getName(), tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CompoundTag(name, tagMap);
|
return new CompoundTag(name, tagMap);
|
||||||
case NBTConstants.TYPE_INT_ARRAY:
|
case NBTConstants.TYPE_INT_ARRAY:
|
||||||
length = this.is.readInt();
|
length = this.is.readInt();
|
||||||
@ -143,10 +137,9 @@ public final class NBTInputStream implements Closeable {
|
|||||||
throw new IOException("Invalid tag type: " + type + ".");
|
throw new IOException("Invalid tag type: " + type + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
this.is.close();
|
this.is.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.jnbt;
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
@ -36,12 +35,11 @@ import java.util.List;
|
|||||||
* @author Graham Edgecombe
|
* @author Graham Edgecombe
|
||||||
*/
|
*/
|
||||||
public final class NBTOutputStream implements Closeable {
|
public final class NBTOutputStream implements Closeable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The output stream.
|
* The output stream.
|
||||||
*/
|
*/
|
||||||
private final DataOutputStream os;
|
private final DataOutputStream os;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <code>NBTOutputStream</code>, which will write data to the specified underlying output stream.
|
* Creates a new <code>NBTOutputStream</code>, which will write data to the specified underlying output stream.
|
||||||
*
|
*
|
||||||
@ -52,7 +50,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
public NBTOutputStream(final OutputStream os) throws IOException {
|
public NBTOutputStream(final OutputStream os) throws IOException {
|
||||||
this.os = new DataOutputStream(os);
|
this.os = new DataOutputStream(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a tag.
|
* Writes a tag.
|
||||||
*
|
*
|
||||||
@ -64,18 +62,15 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
final int type = NBTUtils.getTypeCode(tag.getClass());
|
final int type = NBTUtils.getTypeCode(tag.getClass());
|
||||||
final String name = tag.getName();
|
final String name = tag.getName();
|
||||||
final byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
|
final byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
|
||||||
|
|
||||||
this.os.writeByte(type);
|
this.os.writeByte(type);
|
||||||
this.os.writeShort(nameBytes.length);
|
this.os.writeShort(nameBytes.length);
|
||||||
this.os.write(nameBytes);
|
this.os.write(nameBytes);
|
||||||
|
|
||||||
if (type == NBTConstants.TYPE_END) {
|
if (type == NBTConstants.TYPE_END) {
|
||||||
throw new IOException("Named TAG_End not permitted.");
|
throw new IOException("Named TAG_End not permitted.");
|
||||||
}
|
}
|
||||||
|
|
||||||
writeTagPayload(tag);
|
writeTagPayload(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes tag payload.
|
* Writes tag payload.
|
||||||
*
|
*
|
||||||
@ -126,7 +121,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
throw new IOException("Invalid tag type: " + type + ".");
|
throw new IOException("Invalid tag type: " + type + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Byte</code> tag.
|
* Writes a <code>TAG_Byte</code> tag.
|
||||||
*
|
*
|
||||||
@ -137,7 +132,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Byte_Array</code> tag.
|
* Writes a <code>TAG_Byte_Array</code> tag.
|
||||||
*
|
*
|
||||||
@ -150,7 +145,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
this.os.writeInt(bytes.length);
|
this.os.writeInt(bytes.length);
|
||||||
this.os.write(bytes);
|
this.os.write(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Compound</code> tag.
|
* Writes a <code>TAG_Compound</code> tag.
|
||||||
*
|
*
|
||||||
@ -164,7 +159,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
this.os.writeByte((byte) 0); // end tag - better way?
|
this.os.writeByte((byte) 0); // end tag - better way?
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_List</code> tag.
|
* Writes a <code>TAG_List</code> tag.
|
||||||
*
|
*
|
||||||
@ -176,14 +171,13 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
final Class<? extends Tag> clazz = tag.getType();
|
final Class<? extends Tag> clazz = tag.getType();
|
||||||
final List<Tag> tags = tag.getValue();
|
final List<Tag> tags = tag.getValue();
|
||||||
final int size = tags.size();
|
final int size = tags.size();
|
||||||
|
|
||||||
this.os.writeByte(NBTUtils.getTypeCode(clazz));
|
this.os.writeByte(NBTUtils.getTypeCode(clazz));
|
||||||
this.os.writeInt(size);
|
this.os.writeInt(size);
|
||||||
for (final Tag tag1 : tags) {
|
for (final Tag tag1 : tags) {
|
||||||
writeTagPayload(tag1);
|
writeTagPayload(tag1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_String</code> tag.
|
* Writes a <code>TAG_String</code> tag.
|
||||||
*
|
*
|
||||||
@ -196,7 +190,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
this.os.writeShort(bytes.length);
|
this.os.writeShort(bytes.length);
|
||||||
this.os.write(bytes);
|
this.os.write(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Double</code> tag.
|
* Writes a <code>TAG_Double</code> tag.
|
||||||
*
|
*
|
||||||
@ -207,7 +201,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Float</code> tag.
|
* Writes a <code>TAG_Float</code> tag.
|
||||||
*
|
*
|
||||||
@ -218,7 +212,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Long</code> tag.
|
* Writes a <code>TAG_Long</code> tag.
|
||||||
*
|
*
|
||||||
@ -229,7 +223,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Int</code> tag.
|
* Writes a <code>TAG_Int</code> tag.
|
||||||
*
|
*
|
||||||
@ -240,7 +234,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Short</code> tag.
|
* Writes a <code>TAG_Short</code> tag.
|
||||||
*
|
*
|
||||||
@ -251,7 +245,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Empty</code> tag.
|
* Writes a <code>TAG_Empty</code> tag.
|
||||||
*
|
*
|
||||||
@ -262,7 +256,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
private void writeEndTagPayload(final EndTag tag) {
|
private void writeEndTagPayload(final EndTag tag) {
|
||||||
/* empty */
|
/* empty */
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeIntArrayTagPayload(final IntArrayTag tag) throws IOException {
|
private void writeIntArrayTagPayload(final IntArrayTag tag) throws IOException {
|
||||||
final int[] data = tag.getValue();
|
final int[] data = tag.getValue();
|
||||||
this.os.writeInt(data.length);
|
this.os.writeInt(data.length);
|
||||||
@ -270,10 +264,9 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
this.os.writeInt(element);
|
this.os.writeInt(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
this.os.close();
|
this.os.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,12 @@ 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 {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default private constructor.
|
* Default private constructor.
|
||||||
*/
|
*/
|
||||||
private NBTUtils() {
|
private NBTUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the type name of a tag.
|
* Gets the type name of a tag.
|
||||||
*
|
*
|
||||||
@ -49,7 +48,7 @@ public final class NBTUtils {
|
|||||||
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the type code of a tag class.
|
* Gets the type code of a tag class.
|
||||||
*
|
*
|
||||||
@ -88,7 +87,7 @@ public final class NBTUtils {
|
|||||||
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the class of a type of tag.
|
* Gets the class of a type of tag.
|
||||||
*
|
*
|
||||||
@ -128,7 +127,7 @@ public final class NBTUtils {
|
|||||||
throw new IllegalArgumentException("Invalid tag type : " + type + ".");
|
throw new IllegalArgumentException("Invalid tag type : " + type + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get child tag of a NBT structure.
|
* Get child tag of a NBT structure.
|
||||||
*
|
*
|
||||||
@ -148,5 +147,4 @@ public final class NBTUtils {
|
|||||||
}
|
}
|
||||||
return expected.cast(tag);
|
return expected.cast(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,14 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.jnbt;
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@code TAG_Short} tag.
|
* The {@code TAG_Short} tag.
|
||||||
*/
|
*/
|
||||||
public final class ShortTag extends Tag {
|
public final class ShortTag extends Tag {
|
||||||
|
|
||||||
private final short value;
|
private final short value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* Creates the tag with an empty name.
|
||||||
*
|
*
|
||||||
@ -37,7 +35,7 @@ public final class ShortTag extends Tag {
|
|||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
@ -48,12 +46,12 @@ public final class ShortTag extends Tag {
|
|||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Short getValue() {
|
public Short getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
@ -63,5 +61,4 @@ public final class ShortTag extends Tag {
|
|||||||
}
|
}
|
||||||
return "TAG_Short" + append + ": " + this.value;
|
return "TAG_Short" + append + ": " + this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
* The {@code TAG_String} tag.
|
* The {@code TAG_String} tag.
|
||||||
*/
|
*/
|
||||||
public final class StringTag extends Tag {
|
public final class StringTag extends Tag {
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag with an empty name.
|
* Creates the tag with an empty name.
|
||||||
*
|
*
|
||||||
@ -19,7 +18,7 @@ public final class StringTag extends Tag {
|
|||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
@ -31,12 +30,12 @@ public final class StringTag extends Tag {
|
|||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
@ -46,5 +45,4 @@ public final class StringTag extends Tag {
|
|||||||
}
|
}
|
||||||
return "TAG_String" + append + ": " + this.value;
|
return "TAG_String" + append + ": " + this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,23 +18,21 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.jnbt;
|
package com.intellectualcrafters.jnbt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a NBT tag.
|
* Represents a NBT tag.
|
||||||
*/
|
*/
|
||||||
public abstract class Tag {
|
public abstract class Tag {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new tag with an empty name.
|
* Create a new tag with an empty name.
|
||||||
*/
|
*/
|
||||||
Tag() {
|
Tag() {
|
||||||
this("");
|
this("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag with the specified name.
|
* Creates the tag with the specified name.
|
||||||
*
|
*
|
||||||
@ -46,7 +44,7 @@ public abstract class Tag {
|
|||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of this tag.
|
* Gets the name of this tag.
|
||||||
*
|
*
|
||||||
@ -55,12 +53,11 @@ public abstract class Tag {
|
|||||||
public final String getName() {
|
public final String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of this tag.
|
* Gets the value of this tag.
|
||||||
*
|
*
|
||||||
* @return the value
|
* @return the value
|
||||||
*/
|
*/
|
||||||
public abstract Object getValue();
|
public abstract Object getValue();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,8 @@ import org.bukkit.World;
|
|||||||
|
|
||||||
public class WorldEditUtils {
|
public class WorldEditUtils {
|
||||||
public static void setNBT(final World world, final short id, final byte data, final int x, final int y, final int z, final com.intellectualcrafters.jnbt.CompoundTag tag) {
|
public static void setNBT(final World world, final short id, final byte data, final int x, final int y, final int z, final com.intellectualcrafters.jnbt.CompoundTag tag) {
|
||||||
|
|
||||||
// final LocalWorld bukkitWorld = BukkitUtil.getLocalWorld(world);
|
// final LocalWorld bukkitWorld = BukkitUtil.getLocalWorld(world);
|
||||||
|
|
||||||
// I need to somehow convert our CompoundTag to WorldEdit's
|
// I need to somehow convert our CompoundTag to WorldEdit's
|
||||||
|
|
||||||
// final BaseBlock block = new BaseBlock(5, 5, (CompoundTag) tag);
|
// final BaseBlock block = new BaseBlock(5, 5, (CompoundTag) tag);
|
||||||
// final Vector vector = new Vector(x, y, z);
|
// final Vector vector = new Vector(x, y, z);
|
||||||
// try {
|
// try {
|
||||||
|
@ -18,7 +18,6 @@ package com.intellectualcrafters.json;
|
|||||||
* @version 2014-05-03
|
* @version 2014-05-03
|
||||||
*/
|
*/
|
||||||
public class CDL {
|
public class CDL {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next value. The value can be wrapped in quotes. The value can be empty.
|
* Get the next value. The value can be wrapped in quotes. The value can be empty.
|
||||||
*
|
*
|
||||||
@ -42,7 +41,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;
|
||||||
@ -61,7 +60,7 @@ public class CDL {
|
|||||||
return x.nextTo(',');
|
return x.nextTo(',');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a JSONArray of strings from a row of comma delimited values.
|
* Produce a JSONArray of strings from a row of comma delimited values.
|
||||||
*
|
*
|
||||||
@ -73,14 +72,14 @@ public class CDL {
|
|||||||
*/
|
*/
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -94,7 +93,7 @@ public class CDL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a JSONObject from a row of comma delimited text, using a parallel JSONArray of strings to provides the
|
* Produce a JSONObject from a row of comma delimited text, using a parallel JSONArray of strings to provides the
|
||||||
* names of the elements.
|
* names of the elements.
|
||||||
@ -111,7 +110,7 @@ public class CDL {
|
|||||||
final JSONArray ja = rowToJSONArray(x);
|
final JSONArray ja = rowToJSONArray(x);
|
||||||
return ja != null ? ja.toJSONObject(names) : null;
|
return ja != null ? ja.toJSONObject(names) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a comma delimited text row from a JSONArray. Values containing the comma character will be quoted.
|
* Produce a comma delimited text row from a JSONArray. Values containing the comma character will be quoted.
|
||||||
* Troublesome characters may be removed.
|
* Troublesome characters may be removed.
|
||||||
@ -147,7 +146,7 @@ public class CDL {
|
|||||||
sb.append('\n');
|
sb.append('\n');
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a JSONArray of JSONObjects from a comma delimited text string, using the first row as a source of names.
|
* Produce a JSONArray of JSONObjects from a comma delimited text string, using the first row as a source of names.
|
||||||
*
|
*
|
||||||
@ -160,7 +159,7 @@ public class CDL {
|
|||||||
public static JSONArray toJSONArray(final String string) throws JSONException {
|
public static JSONArray toJSONArray(final String string) throws JSONException {
|
||||||
return toJSONArray(new JSONTokener(string));
|
return toJSONArray(new JSONTokener(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a JSONArray of JSONObjects from a comma delimited text string, using the first row as a source of names.
|
* Produce a JSONArray of JSONObjects from a comma delimited text string, using the first row as a source of names.
|
||||||
*
|
*
|
||||||
@ -173,7 +172,7 @@ public class CDL {
|
|||||||
public static JSONArray toJSONArray(final JSONTokener x) throws JSONException {
|
public static JSONArray toJSONArray(final JSONTokener x) throws JSONException {
|
||||||
return toJSONArray(rowToJSONArray(x), x);
|
return toJSONArray(rowToJSONArray(x), x);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a JSONArray of JSONObjects from a comma delimited text string using a supplied JSONArray as the source of
|
* Produce a JSONArray of JSONObjects from a comma delimited text string using a supplied JSONArray as the source of
|
||||||
* element names.
|
* element names.
|
||||||
@ -188,7 +187,7 @@ public class CDL {
|
|||||||
public static JSONArray toJSONArray(final JSONArray names, final String string) throws JSONException {
|
public static JSONArray toJSONArray(final JSONArray names, final String string) throws JSONException {
|
||||||
return toJSONArray(names, new JSONTokener(string));
|
return toJSONArray(names, new JSONTokener(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a JSONArray of JSONObjects from a comma delimited text string using a supplied JSONArray as the source of
|
* Produce a JSONArray of JSONObjects from a comma delimited text string using a supplied JSONArray as the source of
|
||||||
* element names.
|
* element names.
|
||||||
@ -205,7 +204,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;
|
||||||
@ -217,7 +216,7 @@ public class CDL {
|
|||||||
}
|
}
|
||||||
return ja;
|
return ja;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a comma delimited text from a JSONArray of JSONObjects. The first row will be a list of names obtained by
|
* Produce a comma delimited text from a JSONArray of JSONObjects. The first row will be a list of names obtained by
|
||||||
* inspecting the first JSONObject.
|
* inspecting the first JSONObject.
|
||||||
@ -238,7 +237,7 @@ public class CDL {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a comma delimited text from a JSONArray of JSONObjects using a provided list of names. The list of names
|
* Produce a comma delimited text from a JSONArray of JSONObjects using a provided list of names. The list of names
|
||||||
* is not included in the output.
|
* is not included in the output.
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.json;
|
package com.intellectualcrafters.json;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +28,6 @@ package com.intellectualcrafters.json;
|
|||||||
* @version 2014-05-03
|
* @version 2014-05-03
|
||||||
*/
|
*/
|
||||||
public class Cookie {
|
public class Cookie {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a copy of a string in which the characters '+', '%', '=', ';' and control characters are replaced with
|
* Produce a copy of a string in which the characters '+', '%', '=', ';' and control characters are replaced with
|
||||||
* "%hh". This is a gentle form of URL encoding, attempting to cause as little distortion to the string as possible.
|
* "%hh". This is a gentle form of URL encoding, attempting to cause as little distortion to the string as possible.
|
||||||
@ -58,7 +56,7 @@ public class Cookie {
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a cookie specification string into a JSONObject. The string will contain a name value pair separated by
|
* Convert a cookie specification string into a JSONObject. The string will contain a name value pair separated by
|
||||||
* '='. The name and the value will be unescaped, possibly converting '+' and '%' sequences. The cookie properties
|
* '='. The name and the value will be unescaped, possibly converting '+' and '%' sequences. The cookie properties
|
||||||
@ -98,7 +96,7 @@ public class Cookie {
|
|||||||
}
|
}
|
||||||
return jo;
|
return jo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a JSONObject into a cookie specification string. The JSONObject must contain "name" and "value" members.
|
* Convert a JSONObject into a cookie specification string. The JSONObject must contain "name" and "value" members.
|
||||||
* If the JSONObject contains "expires", "domain", "path", or "secure" members, they will be appended to the cookie
|
* If the JSONObject contains "expires", "domain", "path", or "secure" members, they will be appended to the cookie
|
||||||
@ -112,7 +110,6 @@ public class Cookie {
|
|||||||
*/
|
*/
|
||||||
public static String toString(final JSONObject jo) throws JSONException {
|
public static String toString(final JSONObject jo) throws JSONException {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
sb.append(escape(jo.getString("name")));
|
sb.append(escape(jo.getString("name")));
|
||||||
sb.append("=");
|
sb.append("=");
|
||||||
sb.append(escape(jo.getString("value")));
|
sb.append(escape(jo.getString("value")));
|
||||||
@ -133,7 +130,7 @@ public class Cookie {
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert <code>%</code><i>hh</i> sequences to single characters, and convert plus to space.
|
* Convert <code>%</code><i>hh</i> sequences to single characters, and convert plus to space.
|
||||||
*
|
*
|
||||||
|
@ -9,7 +9,6 @@ import java.util.Iterator;
|
|||||||
* @version 2014-05-03
|
* @version 2014-05-03
|
||||||
*/
|
*/
|
||||||
public class CookieList {
|
public class CookieList {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a cookie list into a JSONObject. A cookie list is a sequence of name/value pairs. The names are separated
|
* Convert a cookie list into a JSONObject. A cookie list is a sequence of name/value pairs. The names are separated
|
||||||
* from the values by '='. The pairs are separated by ';'. The names and the values will be unescaped, possibly
|
* from the values by '='. The pairs are separated by ';'. The names and the values will be unescaped, possibly
|
||||||
@ -35,7 +34,7 @@ public class CookieList {
|
|||||||
}
|
}
|
||||||
return jo;
|
return jo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a JSONObject into a cookie list. A cookie list is a sequence of name/value pairs. The names are separated
|
* Convert a JSONObject into a cookie list. A cookie list is a sequence of name/value pairs. The names are separated
|
||||||
* from the values by '='. The pairs are separated by ';'. The characters '%', '+', '=', and ';' in the names and
|
* from the values by '='. The pairs are separated by ';'. The characters '%', '+', '=', and ';' in the names and
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.json;
|
package com.intellectualcrafters.json;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -30,12 +29,11 @@ import java.util.Iterator;
|
|||||||
* @version 2014-05-03
|
* @version 2014-05-03
|
||||||
*/
|
*/
|
||||||
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 header or a response header. 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 will contain
|
||||||
@ -93,28 +91,20 @@ public class HTTP {
|
|||||||
final JSONObject jo = new JSONObject();
|
final JSONObject jo = new JSONObject();
|
||||||
final HTTPTokener x = new HTTPTokener(string);
|
final HTTPTokener x = new HTTPTokener(string);
|
||||||
String token;
|
String token;
|
||||||
|
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
if (token.toUpperCase().startsWith("HTTP")) {
|
if (token.toUpperCase().startsWith("HTTP")) {
|
||||||
|
|
||||||
// Response
|
// Response
|
||||||
|
|
||||||
jo.put("HTTP-Version", token);
|
jo.put("HTTP-Version", token);
|
||||||
jo.put("Status-Code", x.nextToken());
|
jo.put("Status-Code", x.nextToken());
|
||||||
jo.put("Reason-Phrase", x.nextTo('\0'));
|
jo.put("Reason-Phrase", x.nextTo('\0'));
|
||||||
x.next();
|
x.next();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Request
|
// Request
|
||||||
|
|
||||||
jo.put("Method", token);
|
jo.put("Method", token);
|
||||||
jo.put("Request-URI", x.nextToken());
|
jo.put("Request-URI", x.nextToken());
|
||||||
jo.put("HTTP-Version", x.nextToken());
|
jo.put("HTTP-Version", x.nextToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fields
|
// Fields
|
||||||
|
|
||||||
while (x.more()) {
|
while (x.more()) {
|
||||||
final String name = x.nextTo(':');
|
final String name = x.nextTo(':');
|
||||||
x.next(':');
|
x.next(':');
|
||||||
@ -123,7 +113,7 @@ public class HTTP {
|
|||||||
}
|
}
|
||||||
return jo;
|
return jo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a JSONObject into an HTTP header. A request header must contain
|
* Convert a JSONObject into an HTTP header. A request header must contain
|
||||||
* <p/>
|
* <p/>
|
||||||
|
@ -7,7 +7,6 @@ package com.intellectualcrafters.json;
|
|||||||
* @version 2014-05-03
|
* @version 2014-05-03
|
||||||
*/
|
*/
|
||||||
public class HTTPTokener extends JSONTokener {
|
public class HTTPTokener extends JSONTokener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an HTTPTokener from a string.
|
* Construct an HTTPTokener from a string.
|
||||||
*
|
*
|
||||||
@ -16,7 +15,7 @@ public class HTTPTokener extends JSONTokener {
|
|||||||
public HTTPTokener(final String string) {
|
public HTTPTokener(final String string) {
|
||||||
super(string);
|
super(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
@ -33,7 +32,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.");
|
||||||
@ -44,7 +43,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();
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.json;
|
package com.intellectualcrafters.json;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -58,19 +57,18 @@ import java.util.Map;
|
|||||||
* @version 2014-05-03
|
* @version 2014-05-03
|
||||||
*/
|
*/
|
||||||
public class JSONArray {
|
public class JSONArray {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The arrayList where the JSONArray's properties are kept.
|
* The arrayList where the JSONArray's properties are kept.
|
||||||
*/
|
*/
|
||||||
private final ArrayList<Object> myArrayList;
|
private final ArrayList<Object> myArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an empty JSONArray.
|
* Construct an empty JSONArray.
|
||||||
*/
|
*/
|
||||||
public JSONArray() {
|
public JSONArray() {
|
||||||
this.myArrayList = new ArrayList<Object>();
|
this.myArrayList = new ArrayList<Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONArray from a JSONTokener.
|
* Construct a JSONArray from a JSONTokener.
|
||||||
*
|
*
|
||||||
@ -85,7 +83,7 @@ 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);
|
||||||
@ -108,7 +106,7 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONArray from a source JSON text.
|
* Construct a JSONArray from a source JSON text.
|
||||||
*
|
*
|
||||||
@ -120,7 +118,7 @@ public class JSONArray {
|
|||||||
public JSONArray(final String source) throws JSONException {
|
public JSONArray(final String source) throws JSONException {
|
||||||
this(new JSONTokener(source));
|
this(new JSONTokener(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONArray from a Collection.
|
* Construct a JSONArray from a Collection.
|
||||||
*
|
*
|
||||||
@ -134,7 +132,7 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONArray from an array
|
* Construct a JSONArray from an array
|
||||||
*
|
*
|
||||||
@ -151,7 +149,7 @@ public class JSONArray {
|
|||||||
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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the object value associated with an index.
|
* Get the object value associated with an index.
|
||||||
*
|
*
|
||||||
@ -168,7 +166,7 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the boolean value associated with an index. The string values "true" and "false" are converted to boolean.
|
* Get the boolean value associated with an index. The string values "true" and "false" are converted to boolean.
|
||||||
*
|
*
|
||||||
@ -187,7 +185,7 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
|
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the double value associated with an index.
|
* Get the double value associated with an index.
|
||||||
*
|
*
|
||||||
@ -205,7 +203,7 @@ public class JSONArray {
|
|||||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the int value associated with an index.
|
* Get the int value associated with an index.
|
||||||
*
|
*
|
||||||
@ -223,7 +221,7 @@ public class JSONArray {
|
|||||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the JSONArray associated with an index.
|
* Get the JSONArray associated with an index.
|
||||||
*
|
*
|
||||||
@ -240,7 +238,7 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
|
throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the JSONObject associated with an index.
|
* Get the JSONObject associated with an index.
|
||||||
*
|
*
|
||||||
@ -257,7 +255,7 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
|
throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the long value associated with an index.
|
* Get the long value associated with an index.
|
||||||
*
|
*
|
||||||
@ -275,7 +273,7 @@ public class JSONArray {
|
|||||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the string associated with an index.
|
* Get the string associated with an index.
|
||||||
*
|
*
|
||||||
@ -292,7 +290,7 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
throw new JSONException("JSONArray[" + index + "] not a string.");
|
throw new JSONException("JSONArray[" + index + "] not a string.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the value is null.
|
* Determine if the value is null.
|
||||||
*
|
*
|
||||||
@ -303,7 +301,7 @@ public class JSONArray {
|
|||||||
public boolean isNull(final int index) {
|
public boolean isNull(final int index) {
|
||||||
return JSONObject.NULL.equals(this.opt(index));
|
return JSONObject.NULL.equals(this.opt(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a string from the contents of this JSONArray. The <code>separator</code> string is inserted between each
|
* Make a string from the contents of this JSONArray. The <code>separator</code> string is inserted between each
|
||||||
* element. Warning: This method assumes that the data structure is acyclical.
|
* element. Warning: This method assumes that the data structure is acyclical.
|
||||||
@ -317,7 +315,6 @@ public class JSONArray {
|
|||||||
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();
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
for (int i = 0; i < len; i += 1) {
|
for (int i = 0; i < len; i += 1) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
sb.append(separator);
|
sb.append(separator);
|
||||||
@ -326,7 +323,7 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of elements in the JSONArray, included nulls.
|
* Get the number of elements in the JSONArray, included nulls.
|
||||||
*
|
*
|
||||||
@ -335,7 +332,7 @@ public class JSONArray {
|
|||||||
public int length() {
|
public int length() {
|
||||||
return this.myArrayList.size();
|
return this.myArrayList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the optional object value associated with an index.
|
* Get the optional object value associated with an index.
|
||||||
*
|
*
|
||||||
@ -346,7 +343,7 @@ public class JSONArray {
|
|||||||
public Object opt(final int index) {
|
public Object opt(final int index) {
|
||||||
return ((index < 0) || (index >= this.length())) ? null : this.myArrayList.get(index);
|
return ((index < 0) || (index >= this.length())) ? null : this.myArrayList.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the optional boolean value associated with an index. It returns false if there is no value at that index, or
|
* Get the optional boolean value associated with an index. It returns false if there is no value at that index, or
|
||||||
* if the value is not Boolean.TRUE or the String "true".
|
* if the value is not Boolean.TRUE or the String "true".
|
||||||
@ -358,7 +355,7 @@ public class JSONArray {
|
|||||||
public boolean optBoolean(final int index) {
|
public boolean optBoolean(final int index) {
|
||||||
return this.optBoolean(index, false);
|
return this.optBoolean(index, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the optional boolean value associated with an index. It returns the defaultValue if there is no value at that
|
* Get the optional boolean value associated with an index. It returns the defaultValue if there is no value at that
|
||||||
* index or if it is not a Boolean or the String "true" or "false" (case insensitive).
|
* index or if it is not a Boolean or the String "true" or "false" (case insensitive).
|
||||||
@ -375,7 +372,7 @@ public class JSONArray {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the optional double value associated with an index. NaN is returned if there is no value for the index, or if
|
* Get the optional double value associated with an index. NaN is returned if there is no value for the index, or if
|
||||||
* the value is not a number and cannot be converted to a number.
|
* the value is not a number and cannot be converted to a number.
|
||||||
@ -387,7 +384,7 @@ public class JSONArray {
|
|||||||
public double optDouble(final int index) {
|
public double optDouble(final int index) {
|
||||||
return this.optDouble(index, Double.NaN);
|
return this.optDouble(index, Double.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the optional double value associated with an index. The defaultValue is returned if there is no value for the
|
* Get the optional double value associated with an index. The defaultValue is returned if there is no value for the
|
||||||
* index, or if the value is not a number and cannot be converted to a number.
|
* index, or if the value is not a number and cannot be converted to a number.
|
||||||
@ -404,7 +401,7 @@ public class JSONArray {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the optional int value associated with an index. Zero is returned if there is no value for the index, or if
|
* Get the optional int value associated with an index. Zero is returned if there is no value for the index, or if
|
||||||
* the value is not a number and cannot be converted to a number.
|
* the value is not a number and cannot be converted to a number.
|
||||||
@ -416,7 +413,7 @@ public class JSONArray {
|
|||||||
public int optInt(final int index) {
|
public int optInt(final int index) {
|
||||||
return this.optInt(index, 0);
|
return this.optInt(index, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the optional int value associated with an index. The defaultValue is returned if there is no value for the
|
* Get the optional int value associated with an index. The defaultValue is returned if there is no value for the
|
||||||
* index, or if the value is not a number and cannot be converted to a number.
|
* index, or if the value is not a number and cannot be converted to a number.
|
||||||
@ -433,7 +430,7 @@ public class JSONArray {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the optional JSONArray associated with an index.
|
* Get the optional JSONArray associated with an index.
|
||||||
*
|
*
|
||||||
@ -445,7 +442,7 @@ public class JSONArray {
|
|||||||
final Object o = this.opt(index);
|
final Object o = this.opt(index);
|
||||||
return o instanceof JSONArray ? (JSONArray) o : null;
|
return o instanceof JSONArray ? (JSONArray) o : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the optional JSONObject associated with an index. Null is returned if the key is not found, or null if the
|
* Get the optional JSONObject associated with an index. Null is returned if the key is not found, or null if the
|
||||||
* index has no value, or if the value is not a JSONObject.
|
* index has no value, or if the value is not a JSONObject.
|
||||||
@ -458,7 +455,7 @@ public class JSONArray {
|
|||||||
final Object o = this.opt(index);
|
final Object o = this.opt(index);
|
||||||
return o instanceof JSONObject ? (JSONObject) o : null;
|
return o instanceof JSONObject ? (JSONObject) o : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the optional long value associated with an index. Zero is returned if there is no value for the index, or if
|
* Get the optional long value associated with an index. Zero is returned if there is no value for the index, or if
|
||||||
* the value is not a number and cannot be converted to a number.
|
* the value is not a number and cannot be converted to a number.
|
||||||
@ -470,7 +467,7 @@ public class JSONArray {
|
|||||||
public long optLong(final int index) {
|
public long optLong(final int index) {
|
||||||
return this.optLong(index, 0);
|
return this.optLong(index, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the optional long value associated with an index. The defaultValue is returned if there is no value for the
|
* Get the optional long value associated with an index. The defaultValue is returned if there is no value for the
|
||||||
* index, or if the value is not a number and cannot be converted to a number.
|
* index, or if the value is not a number and cannot be converted to a number.
|
||||||
@ -487,7 +484,7 @@ public class JSONArray {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the optional string value associated with an index. It returns an empty string if there is no value at that
|
* Get the optional string value associated with an index. It returns an empty string if there is no value at that
|
||||||
* index. If the value is not a string and is not null, then it is coverted to a string.
|
* index. If the value is not a string and is not null, then it is coverted to a string.
|
||||||
@ -499,7 +496,7 @@ public class JSONArray {
|
|||||||
public String optString(final int index) {
|
public String optString(final int index) {
|
||||||
return this.optString(index, "");
|
return this.optString(index, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the optional string associated with an index. The defaultValue is returned if the key is not found.
|
* Get the optional string associated with an index. The defaultValue is returned if the key is not found.
|
||||||
*
|
*
|
||||||
@ -512,7 +509,7 @@ public class JSONArray {
|
|||||||
final Object object = this.opt(index);
|
final Object object = this.opt(index);
|
||||||
return JSONObject.NULL.equals(object) ? defaultValue : object.toString();
|
return JSONObject.NULL.equals(object) ? defaultValue : object.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a boolean value. This increases the array's length by one.
|
* Append a boolean value. This increases the array's length by one.
|
||||||
*
|
*
|
||||||
@ -524,7 +521,7 @@ public class JSONArray {
|
|||||||
this.put(value ? Boolean.TRUE : Boolean.FALSE);
|
this.put(value ? Boolean.TRUE : Boolean.FALSE);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a value in the JSONArray, where the value will be a JSONArray which is produced from a Collection.
|
* Put a value in the JSONArray, where the value will be a JSONArray which is produced from a Collection.
|
||||||
*
|
*
|
||||||
@ -536,7 +533,7 @@ public class JSONArray {
|
|||||||
this.put(new JSONArray(value));
|
this.put(new JSONArray(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a double value. This increases the array's length by one.
|
* Append a double value. This increases the array's length by one.
|
||||||
*
|
*
|
||||||
@ -552,7 +549,7 @@ public class JSONArray {
|
|||||||
this.put(d);
|
this.put(d);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append an int value. This increases the array's length by one.
|
* Append an int value. This increases the array's length by one.
|
||||||
*
|
*
|
||||||
@ -564,7 +561,7 @@ public class JSONArray {
|
|||||||
this.put(new Integer(value));
|
this.put(new Integer(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append an long value. This increases the array's length by one.
|
* Append an long value. This increases the array's length by one.
|
||||||
*
|
*
|
||||||
@ -576,7 +573,7 @@ public class JSONArray {
|
|||||||
this.put(new Long(value));
|
this.put(new Long(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a value in the JSONArray, where the value will be a JSONObject which is produced from a Map.
|
* Put a value in the JSONArray, where the value will be a JSONObject which is produced from a Map.
|
||||||
*
|
*
|
||||||
@ -588,7 +585,7 @@ public class JSONArray {
|
|||||||
this.put(new JSONObject(value));
|
this.put(new JSONObject(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append an object value. This increases the array's length by one.
|
* Append an object value. This increases the array's length by one.
|
||||||
*
|
*
|
||||||
@ -601,7 +598,7 @@ public class JSONArray {
|
|||||||
this.myArrayList.add(value);
|
this.myArrayList.add(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put or replace a boolean value in the JSONArray. If the index is greater than the length of the JSONArray, then
|
* Put or replace a boolean value in the JSONArray. If the index is greater than the length of the JSONArray, then
|
||||||
* null elements will be added as necessary to pad it out.
|
* null elements will be added as necessary to pad it out.
|
||||||
@ -617,7 +614,7 @@ public class JSONArray {
|
|||||||
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
|
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a value in the JSONArray, where the value will be a JSONArray which is produced from a Collection.
|
* Put a value in the JSONArray, where the value will be a JSONArray which is produced from a Collection.
|
||||||
*
|
*
|
||||||
@ -632,7 +629,7 @@ public class JSONArray {
|
|||||||
this.put(index, new JSONArray(value));
|
this.put(index, new JSONArray(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put or replace a double value. If the index is greater than the length of the JSONArray, then null elements will
|
* Put or replace a double value. If the index is greater than the length of the JSONArray, then null elements will
|
||||||
* be added as necessary to pad it out.
|
* be added as necessary to pad it out.
|
||||||
@ -648,7 +645,7 @@ public class JSONArray {
|
|||||||
this.put(index, new Double(value));
|
this.put(index, new Double(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put or replace an int value. If the index is greater than the length of the JSONArray, then null elements will be
|
* Put or replace an int value. If the index is greater than the length of the JSONArray, then null elements will be
|
||||||
* added as necessary to pad it out.
|
* added as necessary to pad it out.
|
||||||
@ -664,7 +661,7 @@ public class JSONArray {
|
|||||||
this.put(index, new Integer(value));
|
this.put(index, new Integer(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put or replace a long value. If the index is greater than the length of the JSONArray, then null elements will be
|
* Put or replace a long value. If the index is greater than the length of the JSONArray, then null elements will be
|
||||||
* added as necessary to pad it out.
|
* added as necessary to pad it out.
|
||||||
@ -680,7 +677,7 @@ public class JSONArray {
|
|||||||
this.put(index, new Long(value));
|
this.put(index, new Long(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a value in the JSONArray, where the value will be a JSONObject that is produced from a Map.
|
* Put a value in the JSONArray, where the value will be a JSONObject that is produced from a Map.
|
||||||
*
|
*
|
||||||
@ -695,7 +692,7 @@ public class JSONArray {
|
|||||||
this.put(index, new JSONObject(value));
|
this.put(index, new JSONObject(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put or replace an object value in the JSONArray. If the index is greater than the length of the JSONArray, then
|
* Put or replace an object value in the JSONArray. If the index is greater than the length of the JSONArray, then
|
||||||
* null elements will be added as necessary to pad it out.
|
* null elements will be added as necessary to pad it out.
|
||||||
@ -723,7 +720,7 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an index and close the hole.
|
* Remove an index and close the hole.
|
||||||
*
|
*
|
||||||
@ -734,7 +731,7 @@ public class JSONArray {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if two JSONArrays are similar. They must contain similar sequences.
|
* Determine if two JSONArrays are similar. They must contain similar sequences.
|
||||||
*
|
*
|
||||||
@ -767,7 +764,7 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a JSONObject by combining a JSONArray of names with the values of this JSONArray.
|
* Produce a JSONObject by combining a JSONArray of names with the values of this JSONArray.
|
||||||
*
|
*
|
||||||
@ -787,7 +784,7 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
return jo;
|
return jo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a JSON text of this JSONArray. For compactness, no unnecessary whitespace is added. If it is not possible to
|
* Make a JSON text of this JSONArray. For compactness, no unnecessary whitespace is added. If it is not possible to
|
||||||
* produce a syntactically correct JSON text then null will be returned instead. This could occur if the array
|
* produce a syntactically correct JSON text then null will be returned instead. This could occur if the array
|
||||||
@ -805,7 +802,7 @@ public class JSONArray {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a prettyprinted JSON text of this JSONArray. Warning: This method assumes that the data structure is
|
* Make a prettyprinted JSON text of this JSONArray. Warning: This method assumes that the data structure is
|
||||||
* acyclical.
|
* acyclical.
|
||||||
@ -824,7 +821,7 @@ public class JSONArray {
|
|||||||
return this.write(sw, indentFactor, 0).toString();
|
return this.write(sw, indentFactor, 0).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added.
|
* Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added.
|
||||||
* <p/>
|
* <p/>
|
||||||
@ -837,7 +834,7 @@ public class JSONArray {
|
|||||||
public Writer write(final Writer writer) throws JSONException {
|
public Writer write(final Writer writer) throws JSONException {
|
||||||
return this.write(writer, 0, 0);
|
return this.write(writer, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added.
|
* Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added.
|
||||||
* <p/>
|
* <p/>
|
||||||
@ -855,12 +852,10 @@ public class JSONArray {
|
|||||||
boolean commanate = false;
|
boolean commanate = false;
|
||||||
final int length = this.length();
|
final int length = this.length();
|
||||||
writer.write('[');
|
writer.write('[');
|
||||||
|
|
||||||
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) {
|
||||||
if (commanate) {
|
if (commanate) {
|
||||||
writer.write(',');
|
writer.write(',');
|
||||||
|
@ -9,7 +9,7 @@ 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.
|
||||||
*
|
*
|
||||||
@ -18,7 +18,7 @@ public class JSONException extends RuntimeException {
|
|||||||
public JSONException(final String message) {
|
public JSONException(final String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new JSONException with the specified cause.
|
* Constructs a new JSONException with the specified cause.
|
||||||
*
|
*
|
||||||
@ -28,7 +28,7 @@ public class JSONException extends RuntimeException {
|
|||||||
super(cause.getMessage());
|
super(cause.getMessage());
|
||||||
this.cause = cause;
|
this.cause = cause;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the cause of this exception or null if the cause is nonexistent or unknown.
|
* Returns the cause of this exception or null if the cause is nonexistent or unknown.
|
||||||
*
|
*
|
||||||
|
@ -10,7 +10,6 @@ import java.util.Iterator;
|
|||||||
* @version 2014-05-03
|
* @version 2014-05-03
|
||||||
*/
|
*/
|
||||||
public class JSONML {
|
public class JSONML {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse XML values and store them in a JSONArray.
|
* Parse XML values and store them in a JSONArray.
|
||||||
*
|
*
|
||||||
@ -31,13 +30,11 @@ public class JSONML {
|
|||||||
JSONObject newjo = null;
|
JSONObject newjo = null;
|
||||||
Object token;
|
Object token;
|
||||||
String tagName = null;
|
String tagName = null;
|
||||||
|
|
||||||
// Test for and skip past these forms:
|
// Test for and skip past these forms:
|
||||||
// <!-- ... -->
|
// <!-- ... -->
|
||||||
// <![ ... ]]>
|
// <![ ... ]]>
|
||||||
// <! ... >
|
// <! ... >
|
||||||
// <? ... ?>
|
// <? ... ?>
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!x.more()) {
|
if (!x.more()) {
|
||||||
throw x.syntaxError("Bad XML");
|
throw x.syntaxError("Bad XML");
|
||||||
@ -47,9 +44,7 @@ public class JSONML {
|
|||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
if (token instanceof Character) {
|
if (token instanceof Character) {
|
||||||
if (token == XML.SLASH) {
|
if (token == XML.SLASH) {
|
||||||
|
|
||||||
// Close tag </
|
// Close tag </
|
||||||
|
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
if (!(token instanceof String)) {
|
if (!(token instanceof String)) {
|
||||||
throw new JSONException("Expected a closing name instead of '" + token + "'.");
|
throw new JSONException("Expected a closing name instead of '" + token + "'.");
|
||||||
@ -59,9 +54,7 @@ public class JSONML {
|
|||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
} else if (token == XML.BANG) {
|
} else if (token == XML.BANG) {
|
||||||
|
|
||||||
// <!
|
// <!
|
||||||
|
|
||||||
c = x.next();
|
c = x.next();
|
||||||
if (c == '-') {
|
if (c == '-') {
|
||||||
if (x.next() == '-') {
|
if (x.next() == '-') {
|
||||||
@ -92,16 +85,12 @@ public class JSONML {
|
|||||||
} 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 + "'.");
|
||||||
@ -121,7 +110,7 @@ public class JSONML {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
token = null;
|
token = null;
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
}
|
}
|
||||||
@ -131,9 +120,7 @@ public class JSONML {
|
|||||||
if (!(token instanceof String)) {
|
if (!(token instanceof String)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// attribute = value
|
// attribute = value
|
||||||
|
|
||||||
attribute = (String) token;
|
attribute = (String) token;
|
||||||
if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) {
|
if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) {
|
||||||
throw x.syntaxError("Reserved attribute.");
|
throw x.syntaxError("Reserved attribute.");
|
||||||
@ -153,9 +140,7 @@ public class JSONML {
|
|||||||
if (arrayForm && (newjo.length() > 0)) {
|
if (arrayForm && (newjo.length() > 0)) {
|
||||||
newja.put(newjo);
|
newja.put(newjo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty tag <.../>
|
// Empty tag <.../>
|
||||||
|
|
||||||
if (token == XML.SLASH) {
|
if (token == XML.SLASH) {
|
||||||
if (x.nextToken() != XML.GT) {
|
if (x.nextToken() != XML.GT) {
|
||||||
throw x.syntaxError("Misshaped tag");
|
throw x.syntaxError("Misshaped tag");
|
||||||
@ -167,9 +152,7 @@ public class JSONML {
|
|||||||
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");
|
||||||
@ -200,7 +183,7 @@ public class JSONML {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONArray using the JsonML transform. Each
|
* Convert a well-formed (but not necessarily valid) XML string into a JSONArray using the JsonML transform. Each
|
||||||
* XML tag is represented as a JSONArray in which the first element is the tag name. If the tag has attributes, then
|
* XML tag is represented as a JSONArray in which the first element is the tag name. If the tag has attributes, then
|
||||||
@ -216,7 +199,7 @@ public class JSONML {
|
|||||||
public static JSONArray toJSONArray(final String string) throws JSONException {
|
public static JSONArray toJSONArray(final String string) throws JSONException {
|
||||||
return toJSONArray(new XMLTokener(string));
|
return toJSONArray(new XMLTokener(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONArray using the JsonML transform. Each
|
* Convert a well-formed (but not necessarily valid) XML string into a JSONArray using the JsonML transform. Each
|
||||||
* XML tag is represented as a JSONArray in which the first element is the tag name. If the tag has attributes, then
|
* XML tag is represented as a JSONArray in which the first element is the tag name. If the tag has attributes, then
|
||||||
@ -233,7 +216,7 @@ public class JSONML {
|
|||||||
public static JSONArray toJSONArray(final XMLTokener x) throws JSONException {
|
public static JSONArray toJSONArray(final XMLTokener x) throws JSONException {
|
||||||
return (JSONArray) parse(x, true, null);
|
return (JSONArray) parse(x, true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML transform. Each
|
* Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML transform. Each
|
||||||
* XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes
|
* XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes
|
||||||
@ -251,7 +234,7 @@ public class JSONML {
|
|||||||
public static JSONObject toJSONObject(final XMLTokener x) throws JSONException {
|
public static JSONObject toJSONObject(final XMLTokener x) throws JSONException {
|
||||||
return (JSONObject) parse(x, false, null);
|
return (JSONObject) parse(x, false, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML transform. Each
|
* Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML transform. Each
|
||||||
* XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes
|
* XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes
|
||||||
@ -269,7 +252,7 @@ public class JSONML {
|
|||||||
public static JSONObject toJSONObject(final String string) throws JSONException {
|
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||||
return toJSONObject(new XMLTokener(string));
|
return toJSONObject(new XMLTokener(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverse the JSONML transformation, making an XML text from a JSONArray.
|
* Reverse the JSONML transformation, making an XML text from a JSONArray.
|
||||||
*
|
*
|
||||||
@ -289,22 +272,17 @@ public class JSONML {
|
|||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
String tagName;
|
String tagName;
|
||||||
String value;
|
String value;
|
||||||
|
|
||||||
// Emit <tagName
|
// Emit <tagName
|
||||||
|
|
||||||
tagName = ja.getString(0);
|
tagName = ja.getString(0);
|
||||||
XML.noSpace(tagName);
|
XML.noSpace(tagName);
|
||||||
tagName = XML.escape(tagName);
|
tagName = XML.escape(tagName);
|
||||||
sb.append('<');
|
sb.append('<');
|
||||||
sb.append(tagName);
|
sb.append(tagName);
|
||||||
|
|
||||||
object = ja.opt(1);
|
object = ja.opt(1);
|
||||||
if (object instanceof JSONObject) {
|
if (object instanceof JSONObject) {
|
||||||
i = 2;
|
i = 2;
|
||||||
jo = (JSONObject) object;
|
jo = (JSONObject) object;
|
||||||
|
|
||||||
// Emit the attributes
|
// Emit the attributes
|
||||||
|
|
||||||
keys = jo.keys();
|
keys = jo.keys();
|
||||||
while (keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
key = keys.next();
|
key = keys.next();
|
||||||
@ -322,9 +300,7 @@ public class JSONML {
|
|||||||
} else {
|
} else {
|
||||||
i = 1;
|
i = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit content in body
|
// Emit content in body
|
||||||
|
|
||||||
length = ja.length();
|
length = ja.length();
|
||||||
if (i >= length) {
|
if (i >= length) {
|
||||||
sb.append('/');
|
sb.append('/');
|
||||||
@ -351,7 +327,7 @@ public class JSONML {
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverse the JSONML transformation, making an XML text from a JSONObject. The JSONObject must contain a "tagName"
|
* Reverse the JSONML transformation, making an XML text from a JSONObject. The JSONObject must contain a "tagName"
|
||||||
* property. If it has children, then it must have a "childNodes" property containing an array of objects. The other
|
* property. If it has children, then it must have a "childNodes" property containing an array of objects. The other
|
||||||
@ -373,9 +349,7 @@ public class JSONML {
|
|||||||
Object object;
|
Object object;
|
||||||
String tagName;
|
String tagName;
|
||||||
String value;
|
String value;
|
||||||
|
|
||||||
// Emit <tagName
|
// Emit <tagName
|
||||||
|
|
||||||
tagName = jo.optString("tagName");
|
tagName = jo.optString("tagName");
|
||||||
if (tagName == null) {
|
if (tagName == null) {
|
||||||
return XML.escape(jo.toString());
|
return XML.escape(jo.toString());
|
||||||
@ -384,9 +358,7 @@ public class JSONML {
|
|||||||
tagName = XML.escape(tagName);
|
tagName = XML.escape(tagName);
|
||||||
sb.append('<');
|
sb.append('<');
|
||||||
sb.append(tagName);
|
sb.append(tagName);
|
||||||
|
|
||||||
// Emit the attributes
|
// Emit the attributes
|
||||||
|
|
||||||
keys = jo.keys();
|
keys = jo.keys();
|
||||||
while (keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
key = keys.next();
|
key = keys.next();
|
||||||
@ -403,9 +375,7 @@ public class JSONML {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit content in body
|
// Emit content in body
|
||||||
|
|
||||||
ja = jo.optJSONArray("childNodes");
|
ja = jo.optJSONArray("childNodes");
|
||||||
if (ja == null) {
|
if (ja == null) {
|
||||||
sb.append('/');
|
sb.append('/');
|
||||||
|
@ -64,14 +64,14 @@ public class JSONObject {
|
|||||||
* The map where the JSONObject's properties are kept.
|
* The map where the JSONObject's properties are kept.
|
||||||
*/
|
*/
|
||||||
private final Map<String, Object> map;
|
private final Map<String, Object> map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an empty JSONObject.
|
* Construct an empty JSONObject.
|
||||||
*/
|
*/
|
||||||
public JSONObject() {
|
public JSONObject() {
|
||||||
this.map = new HashMap<String, Object>();
|
this.map = new HashMap<String, Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONObject from a subset of another JSONObject. An array of strings is used to identify the keys that
|
* Construct a JSONObject from a subset of another JSONObject. An array of strings is used to identify the keys that
|
||||||
* should be copied. Missing keys are ignored.
|
* should be copied. Missing keys are ignored.
|
||||||
@ -91,7 +91,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONObject from a JSONTokener.
|
* Construct a JSONObject from a JSONTokener.
|
||||||
*
|
*
|
||||||
@ -103,11 +103,10 @@ public class JSONObject {
|
|||||||
this();
|
this();
|
||||||
char c;
|
char c;
|
||||||
String key;
|
String key;
|
||||||
|
|
||||||
if (x.nextClean() != '{') {
|
if (x.nextClean() != '{') {
|
||||||
throw x.syntaxError("A JSONObject text must begin with '{'");
|
throw x.syntaxError("A JSONObject text must begin with '{'");
|
||||||
}
|
}
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
c = x.nextClean();
|
c = x.nextClean();
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -118,17 +117,13 @@ public class JSONObject {
|
|||||||
x.back();
|
x.back();
|
||||||
key = x.nextValue().toString();
|
key = x.nextValue().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// The key is followed by ':'.
|
// The key is followed by ':'.
|
||||||
|
|
||||||
c = x.nextClean();
|
c = x.nextClean();
|
||||||
if (c != ':') {
|
if (c != ':') {
|
||||||
throw x.syntaxError("Expected a ':' after a key");
|
throw x.syntaxError("Expected a ':' after a key");
|
||||||
}
|
}
|
||||||
this.putOnce(key, x.nextValue());
|
this.putOnce(key, x.nextValue());
|
||||||
|
|
||||||
// Pairs are separated by ','.
|
// Pairs are separated by ','.
|
||||||
|
|
||||||
switch (x.nextClean()) {
|
switch (x.nextClean()) {
|
||||||
case ';':
|
case ';':
|
||||||
case ',':
|
case ',':
|
||||||
@ -144,7 +139,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONObject from a Map.
|
* Construct a JSONObject from a Map.
|
||||||
*
|
*
|
||||||
@ -163,7 +158,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONObject from an Object using bean getters. It reflects on all of the public methods of the object.
|
* Construct a JSONObject from an Object using bean getters. It reflects on all of the public methods of the object.
|
||||||
* For each of the methods with no parameters and a name starting with <code>"get"</code> or <code>"is"</code>
|
* For each of the methods with no parameters and a name starting with <code>"get"</code> or <code>"is"</code>
|
||||||
@ -183,7 +178,7 @@ public class JSONObject {
|
|||||||
this();
|
this();
|
||||||
this.populateMap(bean);
|
this.populateMap(bean);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONObject from an Object, using reflection to find the public members. The resulting JSONObject's
|
* Construct a JSONObject from an Object, using reflection to find the public members. The resulting JSONObject's
|
||||||
* keys will be the strings from the names array, and the values will be the field values associated with those keys
|
* keys will be the strings from the names array, and the values will be the field values associated with those keys
|
||||||
@ -202,7 +197,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONObject from a source JSON text string. This is the most commonly used JSONObject constructor.
|
* Construct a JSONObject from a source JSON text string. This is the most commonly used JSONObject constructor.
|
||||||
*
|
*
|
||||||
@ -214,7 +209,7 @@ public class JSONObject {
|
|||||||
public JSONObject(final String source) throws JSONException {
|
public JSONObject(final String source) throws JSONException {
|
||||||
this(new JSONTokener(source));
|
this(new JSONTokener(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONObject from a ResourceBundle.
|
* Construct a JSONObject from a ResourceBundle.
|
||||||
*
|
*
|
||||||
@ -226,20 +221,16 @@ public class JSONObject {
|
|||||||
public JSONObject(final String baseName, final Locale locale) throws JSONException {
|
public JSONObject(final String baseName, final Locale locale) throws JSONException {
|
||||||
this();
|
this();
|
||||||
final ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, Thread.currentThread().getContextClassLoader());
|
final ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, Thread.currentThread().getContextClassLoader());
|
||||||
|
|
||||||
// Iterate through the keys in the bundle.
|
// Iterate through the keys in the bundle.
|
||||||
|
|
||||||
final Enumeration<String> keys = bundle.getKeys();
|
final Enumeration<String> keys = bundle.getKeys();
|
||||||
while (keys.hasMoreElements()) {
|
while (keys.hasMoreElements()) {
|
||||||
final Object key = keys.nextElement();
|
final Object key = keys.nextElement();
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
|
|
||||||
// Go through the path, ensuring that there is a nested
|
// Go through the path, ensuring that there is a nested
|
||||||
// JSONObject for each
|
// JSONObject for each
|
||||||
// segment except the last. Add the value using the last
|
// segment except the last. Add the value using the last
|
||||||
// segment's name into
|
// segment's name into
|
||||||
// the deepest nested JSONObject.
|
// the deepest nested JSONObject.
|
||||||
|
|
||||||
final String[] path = ((String) key).split("\\.");
|
final String[] path = ((String) key).split("\\.");
|
||||||
final int last = path.length - 1;
|
final int last = path.length - 1;
|
||||||
JSONObject target = this;
|
JSONObject target = this;
|
||||||
@ -256,7 +247,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a string from a double. The string "null" will be returned if the number is not finite.
|
* Produce a string from a double. The string "null" will be returned if the number is not finite.
|
||||||
*
|
*
|
||||||
@ -268,9 +259,7 @@ public class JSONObject {
|
|||||||
if (Double.isInfinite(d) || Double.isNaN(d)) {
|
if (Double.isInfinite(d) || Double.isNaN(d)) {
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shave off trailing zeros and decimal point, if possible.
|
// Shave off trailing zeros and decimal point, if possible.
|
||||||
|
|
||||||
String string = Double.toString(d);
|
String string = Double.toString(d);
|
||||||
if ((string.indexOf('.') > 0) && (string.indexOf('e') < 0) && (string.indexOf('E') < 0)) {
|
if ((string.indexOf('.') > 0) && (string.indexOf('e') < 0) && (string.indexOf('E') < 0)) {
|
||||||
while (string.endsWith("0")) {
|
while (string.endsWith("0")) {
|
||||||
@ -282,7 +271,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an array of field names from a JSONObject.
|
* Get an array of field names from a JSONObject.
|
||||||
*
|
*
|
||||||
@ -302,7 +291,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an array of field names from an Object.
|
* Get an array of field names from an Object.
|
||||||
*
|
*
|
||||||
@ -324,7 +313,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a string from a Number.
|
* Produce a string from a Number.
|
||||||
*
|
*
|
||||||
@ -339,9 +328,7 @@ public class JSONObject {
|
|||||||
throw new JSONException("Null pointer");
|
throw new JSONException("Null pointer");
|
||||||
}
|
}
|
||||||
testValidity(number);
|
testValidity(number);
|
||||||
|
|
||||||
// Shave off trailing zeros and decimal point, if possible.
|
// Shave off trailing zeros and decimal point, if possible.
|
||||||
|
|
||||||
String string = number.toString();
|
String string = number.toString();
|
||||||
if ((string.indexOf('.') > 0) && (string.indexOf('e') < 0) && (string.indexOf('E') < 0)) {
|
if ((string.indexOf('.') > 0) && (string.indexOf('e') < 0) && (string.indexOf('E') < 0)) {
|
||||||
while (string.endsWith("0")) {
|
while (string.endsWith("0")) {
|
||||||
@ -353,7 +340,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a string in double quotes with backslash sequences in all the right places. A backslash will be inserted
|
* Produce a string in double quotes with backslash sequences in all the right places. A backslash will be inserted
|
||||||
* within </, producing <\/, allowing JSON text to be delivered in HTML. In JSON text, a string cannot contain a
|
* within </, producing <\/, allowing JSON text to be delivered in HTML. In JSON text, a string cannot contain a
|
||||||
@ -374,19 +361,17 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Writer quote(final String string, final Writer w) throws IOException {
|
public static Writer quote(final String string, final Writer w) throws IOException {
|
||||||
if ((string == null) || (string.length() == 0)) {
|
if ((string == null) || (string.length() == 0)) {
|
||||||
w.write("\"\"");
|
w.write("\"\"");
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
char b;
|
char b;
|
||||||
char c = 0;
|
char c = 0;
|
||||||
String hhhh;
|
String hhhh;
|
||||||
int i;
|
int i;
|
||||||
final int len = string.length();
|
final int len = string.length();
|
||||||
|
|
||||||
w.write('"');
|
w.write('"');
|
||||||
for (i = 0; i < len; i += 1) {
|
for (i = 0; i < len; i += 1) {
|
||||||
b = c;
|
b = c;
|
||||||
@ -432,7 +417,7 @@ public class JSONObject {
|
|||||||
w.write('"');
|
w.write('"');
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to convert a string into a number, boolean, or null. If the string can't be converted, return the string.
|
* Try to convert a string into a number, boolean, or null. If the string can't be converted, return the string.
|
||||||
*
|
*
|
||||||
@ -454,12 +439,10 @@ public class JSONObject {
|
|||||||
if (string.equalsIgnoreCase("null")) {
|
if (string.equalsIgnoreCase("null")) {
|
||||||
return JSONObject.NULL;
|
return JSONObject.NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If it might be a number, try converting it. If a number cannot be
|
* If it might be a number, try converting it. If a number cannot be
|
||||||
* produced, then the value will just be a string.
|
* produced, then the value will just be a string.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
final char b = string.charAt(0);
|
final char b = string.charAt(0);
|
||||||
if (((b >= '0') && (b <= '9')) || (b == '-')) {
|
if (((b >= '0') && (b <= '9')) || (b == '-')) {
|
||||||
try {
|
try {
|
||||||
@ -483,7 +466,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throw an exception if the object is a NaN or infinite number.
|
* Throw an exception if the object is a NaN or infinite number.
|
||||||
*
|
*
|
||||||
@ -504,7 +487,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a JSON text of an Object value. If the object has an value.toJSONString() method, then that method will be
|
* Make a JSON text of an Object value. If the object has an value.toJSONString() method, then that method will be
|
||||||
* used to produce the JSON text. The method is required to produce a strictly conforming text. If the object does
|
* used to produce the JSON text. The method is required to produce a strictly conforming text. If the object does
|
||||||
@ -557,7 +540,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return quote(value.toString());
|
return quote(value.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap an object, if necessary. If the object is null, return the NULL object. If it is an array or collection,
|
* Wrap an object, if necessary. If the object is null, return the NULL object. If it is an array or collection,
|
||||||
* wrap it in a JSONArray. If it is a map, wrap it in a JSONObject. If it is a standard property (Double, String, et
|
* wrap it in a JSONArray. If it is a map, wrap it in a JSONObject. If it is a standard property (Double, String, et
|
||||||
@ -576,7 +559,6 @@ public class JSONObject {
|
|||||||
if ((object instanceof JSONObject) || (object instanceof JSONArray) || NULL.equals(object) || (object instanceof JSONString) || (object instanceof Byte) || (object instanceof Character) || (object instanceof Short) || (object instanceof Integer) || (object instanceof Long) || (object instanceof Boolean) || (object instanceof Float) || (object instanceof Double) || (object instanceof String)) {
|
if ((object instanceof JSONObject) || (object instanceof JSONArray) || NULL.equals(object) || (object instanceof JSONString) || (object instanceof Byte) || (object instanceof Character) || (object instanceof Short) || (object instanceof Integer) || (object instanceof Long) || (object instanceof Boolean) || (object instanceof Float) || (object instanceof Double) || (object instanceof String)) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object instanceof Collection) {
|
if (object instanceof Collection) {
|
||||||
return new JSONArray((Collection<Object>) object);
|
return new JSONArray((Collection<Object>) object);
|
||||||
}
|
}
|
||||||
@ -596,7 +578,7 @@ public class JSONObject {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static final Writer writeValue(final Writer writer, final Object value, final int indentFactor, final int indent) throws JSONException, IOException {
|
static final Writer writeValue(final Writer writer, final Object value, final int indentFactor, final int indent) throws JSONException, IOException {
|
||||||
if ((value == null) || value.equals(null)) {
|
if ((value == null) || value.equals(null)) {
|
||||||
writer.write("null");
|
writer.write("null");
|
||||||
@ -627,13 +609,13 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return writer;
|
return writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static final void indent(final Writer writer, final int indent) throws IOException {
|
static final void indent(final Writer writer, final int indent) throws IOException {
|
||||||
for (int i = 0; i < indent; i += 1) {
|
for (int i = 0; i < indent; i += 1) {
|
||||||
writer.write(' ');
|
writer.write(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accumulate values under a key. It is similar to the put method except that if there is already an object stored
|
* Accumulate values under a key. It is similar to the put method except that if there is already an object stored
|
||||||
* under the key then a JSONArray is stored under the key to hold all of the accumulated values. If there is already
|
* under the key then a JSONArray is stored under the key to hold all of the accumulated values. If there is already
|
||||||
@ -661,7 +643,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append values to the array under a key. If the key does not exist in the JSONObject, then the key is put in the
|
* Append values to the array under a key. If the key does not exist in the JSONObject, then the key is put in the
|
||||||
* JSONObject with its value being a JSONArray containing the value parameter. If the key was already associated
|
* JSONObject with its value being a JSONArray containing the value parameter. If the key was already associated
|
||||||
@ -686,7 +668,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value object associated with a key.
|
* Get the value object associated with a key.
|
||||||
*
|
*
|
||||||
@ -706,7 +688,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the boolean value associated with a key.
|
* Get the boolean value associated with a key.
|
||||||
*
|
*
|
||||||
@ -725,7 +707,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
throw new JSONException("JSONObject[" + quote(key) + "] is not a Boolean.");
|
throw new JSONException("JSONObject[" + quote(key) + "] is not a Boolean.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the double value associated with a key.
|
* Get the double value associated with a key.
|
||||||
*
|
*
|
||||||
@ -744,7 +726,7 @@ public class JSONObject {
|
|||||||
throw new JSONException("JSONObject[" + quote(key) + "] is not a number.");
|
throw new JSONException("JSONObject[" + quote(key) + "] is not a number.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the int value associated with a key.
|
* Get the int value associated with a key.
|
||||||
*
|
*
|
||||||
@ -762,7 +744,7 @@ public class JSONObject {
|
|||||||
throw new JSONException("JSONObject[" + quote(key) + "] is not an int.");
|
throw new JSONException("JSONObject[" + quote(key) + "] is not an int.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the JSONArray value associated with a key.
|
* Get the JSONArray value associated with a key.
|
||||||
*
|
*
|
||||||
@ -779,7 +761,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONArray.");
|
throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONArray.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the JSONObject value associated with a key.
|
* Get the JSONObject value associated with a key.
|
||||||
*
|
*
|
||||||
@ -796,7 +778,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONObject.");
|
throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONObject.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the long value associated with a key.
|
* Get the long value associated with a key.
|
||||||
*
|
*
|
||||||
@ -814,7 +796,7 @@ public class JSONObject {
|
|||||||
throw new JSONException("JSONObject[" + quote(key) + "] is not a long.");
|
throw new JSONException("JSONObject[" + quote(key) + "] is not a long.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the string associated with a key.
|
* Get the string associated with a key.
|
||||||
*
|
*
|
||||||
@ -831,7 +813,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
throw new JSONException("JSONObject[" + quote(key) + "] not a string.");
|
throw new JSONException("JSONObject[" + quote(key) + "] not a string.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the JSONObject contains a specific key.
|
* Determine if the JSONObject contains a specific key.
|
||||||
*
|
*
|
||||||
@ -842,7 +824,7 @@ public class JSONObject {
|
|||||||
public boolean has(final String key) {
|
public boolean has(final String key) {
|
||||||
return this.map.containsKey(key);
|
return this.map.containsKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increment a property of a JSONObject. If there is no such property, create one with a value of 1. If there is
|
* Increment a property of a JSONObject. If there is no such property, create one with a value of 1. If there is
|
||||||
* such a property, and if it is an Integer, Long, Double, or Float, then add one to it.
|
* such a property, and if it is an Integer, Long, Double, or Float, then add one to it.
|
||||||
@ -871,7 +853,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the value associated with the key is null or if there is no value.
|
* Determine if the value associated with the key is null or if there is no value.
|
||||||
*
|
*
|
||||||
@ -882,7 +864,7 @@ public class JSONObject {
|
|||||||
public boolean isNull(final String key) {
|
public boolean isNull(final String key) {
|
||||||
return JSONObject.NULL.equals(this.opt(key));
|
return JSONObject.NULL.equals(this.opt(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an enumeration of the keys of the JSONObject.
|
* Get an enumeration of the keys of the JSONObject.
|
||||||
*
|
*
|
||||||
@ -891,7 +873,7 @@ public class JSONObject {
|
|||||||
public Iterator<String> keys() {
|
public Iterator<String> keys() {
|
||||||
return this.keySet().iterator();
|
return this.keySet().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a set of keys of the JSONObject.
|
* Get a set of keys of the JSONObject.
|
||||||
*
|
*
|
||||||
@ -900,7 +882,7 @@ public class JSONObject {
|
|||||||
public Set<String> keySet() {
|
public Set<String> keySet() {
|
||||||
return this.map.keySet();
|
return this.map.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of keys stored in the JSONObject.
|
* Get the number of keys stored in the JSONObject.
|
||||||
*
|
*
|
||||||
@ -909,7 +891,7 @@ public class JSONObject {
|
|||||||
public int length() {
|
public int length() {
|
||||||
return this.map.size();
|
return this.map.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a JSONArray containing the names of the elements of this JSONObject.
|
* Produce a JSONArray containing the names of the elements of this JSONObject.
|
||||||
*
|
*
|
||||||
@ -923,7 +905,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return ja.length() == 0 ? null : ja;
|
return ja.length() == 0 ? null : ja;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an optional value associated with a key.
|
* Get an optional value associated with a key.
|
||||||
*
|
*
|
||||||
@ -934,7 +916,7 @@ public class JSONObject {
|
|||||||
public Object opt(final String key) {
|
public Object opt(final String key) {
|
||||||
return key == null ? null : this.map.get(key);
|
return key == null ? null : this.map.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an optional boolean associated with a key. It returns false if there is no such key, or if the value is not
|
* Get an optional boolean associated with a key. It returns false if there is no such key, or if the value is not
|
||||||
* Boolean.TRUE or the String "true".
|
* Boolean.TRUE or the String "true".
|
||||||
@ -946,7 +928,7 @@ public class JSONObject {
|
|||||||
public boolean optBoolean(final String key) {
|
public boolean optBoolean(final String key) {
|
||||||
return this.optBoolean(key, false);
|
return this.optBoolean(key, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an optional boolean associated with a key. It returns the defaultValue if there is no such key, or if it is
|
* Get an optional boolean associated with a key. It returns the defaultValue if there is no such key, or if it is
|
||||||
* not a Boolean or the String "true" or "false" (case insensitive).
|
* not a Boolean or the String "true" or "false" (case insensitive).
|
||||||
@ -963,7 +945,7 @@ public class JSONObject {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an optional double associated with a key, or NaN if there is no such key or if its value is not a number. If
|
* Get an optional double associated with a key, or NaN if there is no such key or if its value is not a number. If
|
||||||
* the value is a string, an attempt will be made to evaluate it as a number.
|
* the value is a string, an attempt will be made to evaluate it as a number.
|
||||||
@ -975,7 +957,7 @@ public class JSONObject {
|
|||||||
public double optDouble(final String key) {
|
public double optDouble(final String key) {
|
||||||
return this.optDouble(key, Double.NaN);
|
return this.optDouble(key, Double.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an optional double associated with a key, or the defaultValue if there is no such key or if its value is not
|
* Get an optional double associated with a key, or the defaultValue if there is no such key or if its value is not
|
||||||
* a number. If the value is a string, an attempt will be made to evaluate it as a number.
|
* a number. If the value is a string, an attempt will be made to evaluate it as a number.
|
||||||
@ -992,7 +974,7 @@ public class JSONObject {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an optional int value associated with a key, or zero if there is no such key or if the value is not a number.
|
* Get an optional int value associated with a key, or zero if there is no such key or if the value is not a number.
|
||||||
* If the value is a string, an attempt will be made to evaluate it as a number.
|
* If the value is a string, an attempt will be made to evaluate it as a number.
|
||||||
@ -1004,7 +986,7 @@ public class JSONObject {
|
|||||||
public int optInt(final String key) {
|
public int optInt(final String key) {
|
||||||
return this.optInt(key, 0);
|
return this.optInt(key, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an optional int value associated with a key, or the default if there is no such key or if the value is not a
|
* Get an optional int value associated with a key, or the default if there is no such key or if the value is not a
|
||||||
* number. If the value is a string, an attempt will be made to evaluate it as a number.
|
* number. If the value is a string, an attempt will be made to evaluate it as a number.
|
||||||
@ -1021,7 +1003,7 @@ public class JSONObject {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an optional JSONArray associated with a key. It returns null if there is no such key, or if its value is not
|
* Get an optional JSONArray associated with a key. It returns null if there is no such key, or if its value is not
|
||||||
* a JSONArray.
|
* a JSONArray.
|
||||||
@ -1034,7 +1016,7 @@ public class JSONObject {
|
|||||||
final Object o = this.opt(key);
|
final Object o = this.opt(key);
|
||||||
return o instanceof JSONArray ? (JSONArray) o : null;
|
return o instanceof JSONArray ? (JSONArray) o : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an optional JSONObject associated with a key. It returns null if there is no such key, or if its value is not
|
* Get an optional JSONObject associated with a key. It returns null if there is no such key, or if its value is not
|
||||||
* a JSONObject.
|
* a JSONObject.
|
||||||
@ -1047,7 +1029,7 @@ public class JSONObject {
|
|||||||
final Object object = this.opt(key);
|
final Object object = this.opt(key);
|
||||||
return object instanceof JSONObject ? (JSONObject) object : null;
|
return object instanceof JSONObject ? (JSONObject) object : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an optional long value associated with a key, or zero if there is no such key or if the value is not a
|
* Get an optional long value associated with a key, or zero if there is no such key or if the value is not a
|
||||||
* number. If the value is a string, an attempt will be made to evaluate it as a number.
|
* number. If the value is a string, an attempt will be made to evaluate it as a number.
|
||||||
@ -1059,7 +1041,7 @@ public class JSONObject {
|
|||||||
public long optLong(final String key) {
|
public long optLong(final String key) {
|
||||||
return this.optLong(key, 0);
|
return this.optLong(key, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an optional long value associated with a key, or the default if there is no such key or if the value is not a
|
* Get an optional long value associated with a key, or the default if there is no such key or if the value is not a
|
||||||
* number. If the value is a string, an attempt will be made to evaluate it as a number.
|
* number. If the value is a string, an attempt will be made to evaluate it as a number.
|
||||||
@ -1076,7 +1058,7 @@ public class JSONObject {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an optional string associated with a key. It returns an empty string if there is no such key. If the value is
|
* Get an optional string associated with a key. It returns an empty string if there is no such key. If the value is
|
||||||
* not a string and is not null, then it is converted to a string.
|
* not a string and is not null, then it is converted to a string.
|
||||||
@ -1088,7 +1070,7 @@ public class JSONObject {
|
|||||||
public String optString(final String key) {
|
public String optString(final String key) {
|
||||||
return this.optString(key, "");
|
return this.optString(key, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an optional string associated with a key. It returns the defaultValue if there is no such key.
|
* Get an optional string associated with a key. It returns the defaultValue if there is no such key.
|
||||||
*
|
*
|
||||||
@ -1101,14 +1083,11 @@ public class JSONObject {
|
|||||||
final Object object = this.opt(key);
|
final Object object = this.opt(key);
|
||||||
return NULL.equals(object) ? defaultValue : object.toString();
|
return NULL.equals(object) ? defaultValue : object.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateMap(final Object bean) {
|
private void populateMap(final Object bean) {
|
||||||
final Class klass = bean.getClass();
|
final Class klass = bean.getClass();
|
||||||
|
|
||||||
// If klass is a System class then set includeSuperClass to false.
|
// If klass is a System class then set includeSuperClass to false.
|
||||||
|
|
||||||
final boolean includeSuperClass = klass.getClassLoader() != null;
|
final boolean includeSuperClass = klass.getClassLoader() != null;
|
||||||
|
|
||||||
final Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
|
final Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
|
||||||
for (final Method method : methods) {
|
for (final Method method : methods) {
|
||||||
try {
|
try {
|
||||||
@ -1130,7 +1109,6 @@ public class JSONObject {
|
|||||||
} else if (!Character.isUpperCase(key.charAt(1))) {
|
} else if (!Character.isUpperCase(key.charAt(1))) {
|
||||||
key = key.substring(0, 1).toLowerCase() + key.substring(1);
|
key = key.substring(0, 1).toLowerCase() + key.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object result = method.invoke(bean, (Object[]) null);
|
final Object result = method.invoke(bean, (Object[]) null);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
this.map.put(key, wrap(result));
|
this.map.put(key, wrap(result));
|
||||||
@ -1141,7 +1119,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a key/boolean pair in the JSONObject.
|
* Put a key/boolean pair in the JSONObject.
|
||||||
*
|
*
|
||||||
@ -1156,7 +1134,7 @@ public class JSONObject {
|
|||||||
this.put(key, value ? Boolean.TRUE : Boolean.FALSE);
|
this.put(key, value ? Boolean.TRUE : Boolean.FALSE);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a key/value pair in the JSONObject, where the value will be a JSONArray which is produced from a Collection.
|
* Put a key/value pair in the JSONObject, where the value will be a JSONArray which is produced from a Collection.
|
||||||
*
|
*
|
||||||
@ -1171,7 +1149,7 @@ public class JSONObject {
|
|||||||
this.put(key, new JSONArray(value));
|
this.put(key, new JSONArray(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a key/double pair in the JSONObject.
|
* Put a key/double pair in the JSONObject.
|
||||||
*
|
*
|
||||||
@ -1186,7 +1164,7 @@ public class JSONObject {
|
|||||||
this.put(key, new Double(value));
|
this.put(key, new Double(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a key/int pair in the JSONObject.
|
* Put a key/int pair in the JSONObject.
|
||||||
*
|
*
|
||||||
@ -1201,7 +1179,7 @@ public class JSONObject {
|
|||||||
this.put(key, new Integer(value));
|
this.put(key, new Integer(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a key/long pair in the JSONObject.
|
* Put a key/long pair in the JSONObject.
|
||||||
*
|
*
|
||||||
@ -1216,7 +1194,7 @@ public class JSONObject {
|
|||||||
this.put(key, new Long(value));
|
this.put(key, new Long(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a key/value pair in the JSONObject, where the value will be a JSONObject which is produced from a Map.
|
* Put a key/value pair in the JSONObject, where the value will be a JSONObject which is produced from a Map.
|
||||||
*
|
*
|
||||||
@ -1231,7 +1209,7 @@ public class JSONObject {
|
|||||||
this.put(key, new JSONObject(value));
|
this.put(key, new JSONObject(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a key/value pair in the JSONObject. If the value is null, then the key will be removed from the JSONObject if
|
* Put a key/value pair in the JSONObject. If the value is null, then the key will be removed from the JSONObject if
|
||||||
* it is present.
|
* it is present.
|
||||||
@ -1256,7 +1234,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a key/value pair in the JSONObject, but only if the key and the value are both non-null, and only if there is
|
* Put a key/value pair in the JSONObject, but only if the key and the value are both non-null, and only if there is
|
||||||
* not already a member with that name.
|
* not already a member with that name.
|
||||||
@ -1277,7 +1255,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a key/value pair in the JSONObject, but only if the key and the value are both non-null.
|
* Put a key/value pair in the JSONObject, but only if the key and the value are both non-null.
|
||||||
*
|
*
|
||||||
@ -1295,7 +1273,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a name and its value, if present.
|
* Remove a name and its value, if present.
|
||||||
*
|
*
|
||||||
@ -1306,7 +1284,7 @@ public class JSONObject {
|
|||||||
public Object remove(final String key) {
|
public Object remove(final String key) {
|
||||||
return this.map.remove(key);
|
return this.map.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if two JSONObjects are similar. They must contain the same set of names which must be associated with
|
* Determine if two JSONObjects are similar. They must contain the same set of names which must be associated with
|
||||||
* similar values.
|
* similar values.
|
||||||
@ -1344,7 +1322,7 @@ public class JSONObject {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a JSONArray containing the values of the members of this JSONObject.
|
* Produce a JSONArray containing the values of the members of this JSONObject.
|
||||||
*
|
*
|
||||||
@ -1365,7 +1343,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
return ja;
|
return ja;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a JSON text of this JSONObject. For compactness, no whitespace is added. If this would not result in a
|
* Make a JSON text of this JSONObject. For compactness, no whitespace is added. If this would not result in a
|
||||||
* syntactically correct JSON text, then null will be returned instead.
|
* syntactically correct JSON text, then null will be returned instead.
|
||||||
@ -1384,7 +1362,7 @@ public class JSONObject {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a prettyprinted JSON text of this JSONObject.
|
* Make a prettyprinted JSON text of this JSONObject.
|
||||||
* <p/>
|
* <p/>
|
||||||
@ -1404,7 +1382,7 @@ public class JSONObject {
|
|||||||
return this.write(w, indentFactor, 0).toString();
|
return this.write(w, indentFactor, 0).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the contents of the JSONObject as JSON text to a writer. For compactness, no whitespace is added.
|
* Write the contents of the JSONObject as JSON text to a writer. For compactness, no whitespace is added.
|
||||||
* <p/>
|
* <p/>
|
||||||
@ -1417,7 +1395,7 @@ public class JSONObject {
|
|||||||
public Writer write(final Writer writer) throws JSONException {
|
public Writer write(final Writer writer) throws JSONException {
|
||||||
return this.write(writer, 0, 0);
|
return this.write(writer, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the contents of the JSONObject as JSON text to a writer. For compactness, no whitespace is added.
|
* Write the contents of the JSONObject as JSON text to a writer. For compactness, no whitespace is added.
|
||||||
* <p/>
|
* <p/>
|
||||||
@ -1433,7 +1411,6 @@ public class JSONObject {
|
|||||||
final int length = this.length();
|
final int length = this.length();
|
||||||
final Iterator<String> keys = this.keys();
|
final Iterator<String> keys = this.keys();
|
||||||
writer.write('{');
|
writer.write('{');
|
||||||
|
|
||||||
if (length == 1) {
|
if (length == 1) {
|
||||||
final Object key = keys.next();
|
final Object key = keys.next();
|
||||||
writer.write(quote(key.toString()));
|
writer.write(quote(key.toString()));
|
||||||
@ -1472,13 +1449,12 @@ public class JSONObject {
|
|||||||
throw new JSONException(exception);
|
throw new JSONException(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSONObject.NULL is equivalent to the value that JavaScript calls null, whilst Java's null is equivalent to the
|
* JSONObject.NULL is equivalent to the value that JavaScript calls null, whilst Java's null is equivalent to the
|
||||||
* value that JavaScript calls undefined.
|
* value that JavaScript calls undefined.
|
||||||
*/
|
*/
|
||||||
private static final class Null {
|
private static final class Null {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* There is only intended to be a single instance of the NULL object, so the clone method returns itself.
|
* There is only intended to be a single instance of the NULL object, so the clone method returns itself.
|
||||||
*
|
*
|
||||||
@ -1492,7 +1468,7 @@ public class JSONObject {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Null object is equal to the null value and to itself.
|
* A Null object is equal to the null value and to itself.
|
||||||
*
|
*
|
||||||
@ -1504,7 +1480,7 @@ public class JSONObject {
|
|||||||
public boolean equals(final Object object) {
|
public boolean equals(final Object object) {
|
||||||
return (object == null) || (object == this);
|
return (object == null) || (object == this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the "null" string value.
|
* Get the "null" string value.
|
||||||
*
|
*
|
||||||
|
@ -40,7 +40,7 @@ public class JSONStringer extends JSONWriter {
|
|||||||
public JSONStringer() {
|
public JSONStringer() {
|
||||||
super(new StringWriter());
|
super(new StringWriter());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the JSON text. This method is used to obtain the product of the JSONStringer instance. It will return
|
* Return the JSON text. This method is used to obtain the product of the JSONStringer instance. It will return
|
||||||
* <code>null</code> if there was a problem in the construction of the JSON text (such as the calls to
|
* <code>null</code> if there was a problem in the construction of the JSON text (such as the calls to
|
||||||
|
@ -15,7 +15,6 @@ import java.io.StringReader;
|
|||||||
* @version 2014-05-03
|
* @version 2014-05-03
|
||||||
*/
|
*/
|
||||||
public class JSONTokener {
|
public class JSONTokener {
|
||||||
|
|
||||||
private final Reader reader;
|
private final Reader reader;
|
||||||
private long character;
|
private long character;
|
||||||
private boolean eof;
|
private boolean eof;
|
||||||
@ -23,7 +22,7 @@ public class JSONTokener {
|
|||||||
private long line;
|
private long line;
|
||||||
private char previous;
|
private char previous;
|
||||||
private boolean usePrevious;
|
private boolean usePrevious;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONTokener from a Reader.
|
* Construct a JSONTokener from a Reader.
|
||||||
*
|
*
|
||||||
@ -38,7 +37,7 @@ public class JSONTokener {
|
|||||||
this.character = 1;
|
this.character = 1;
|
||||||
this.line = 1;
|
this.line = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONTokener from an InputStream.
|
* Construct a JSONTokener from an InputStream.
|
||||||
*
|
*
|
||||||
@ -47,7 +46,7 @@ public class JSONTokener {
|
|||||||
public JSONTokener(final InputStream inputStream) throws JSONException {
|
public JSONTokener(final InputStream inputStream) throws JSONException {
|
||||||
this(new InputStreamReader(inputStream));
|
this(new InputStreamReader(inputStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONTokener from a string.
|
* Construct a JSONTokener from a string.
|
||||||
*
|
*
|
||||||
@ -56,7 +55,7 @@ public class JSONTokener {
|
|||||||
public JSONTokener(final String s) {
|
public JSONTokener(final String s) {
|
||||||
this(new StringReader(s));
|
this(new StringReader(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the hex value of a character (base16).
|
* Get the hex value of a character (base16).
|
||||||
*
|
*
|
||||||
@ -76,7 +75,7 @@ public class JSONTokener {
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Back up one character. This provides a sort of lookahead capability, so that you can test for a digit or letter
|
* Back up one character. This provides a sort of lookahead capability, so that you can test for a digit or letter
|
||||||
* before attempting to parse the next number or identifier.
|
* before attempting to parse the next number or identifier.
|
||||||
@ -90,11 +89,11 @@ public class JSONTokener {
|
|||||||
this.usePrevious = true;
|
this.usePrevious = true;
|
||||||
this.eof = false;
|
this.eof = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean end() {
|
public boolean end() {
|
||||||
return this.eof && !this.usePrevious;
|
return this.eof && !this.usePrevious;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the source string still contains characters that next() can consume.
|
* Determine if the source string still contains characters that next() can consume.
|
||||||
*
|
*
|
||||||
@ -108,7 +107,7 @@ public class JSONTokener {
|
|||||||
this.back();
|
this.back();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next character in the source string.
|
* Get the next character in the source string.
|
||||||
*
|
*
|
||||||
@ -125,7 +124,6 @@ public class JSONTokener {
|
|||||||
} catch (final IOException exception) {
|
} catch (final IOException exception) {
|
||||||
throw new JSONException(exception);
|
throw new JSONException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c <= 0) { // End of stream
|
if (c <= 0) { // End of stream
|
||||||
this.eof = true;
|
this.eof = true;
|
||||||
c = 0;
|
c = 0;
|
||||||
@ -144,7 +142,7 @@ public class JSONTokener {
|
|||||||
this.previous = (char) c;
|
this.previous = (char) c;
|
||||||
return this.previous;
|
return this.previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Consume the next character, and check that it matches a specified character.
|
* Consume the next character, and check that it matches a specified character.
|
||||||
*
|
*
|
||||||
@ -161,7 +159,7 @@ public class JSONTokener {
|
|||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next n characters.
|
* Get the next n characters.
|
||||||
*
|
*
|
||||||
@ -175,10 +173,8 @@ public class JSONTokener {
|
|||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
final char[] chars = new char[n];
|
final char[] chars = new char[n];
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
while (pos < n) {
|
while (pos < n) {
|
||||||
chars[pos] = this.next();
|
chars[pos] = this.next();
|
||||||
if (this.end()) {
|
if (this.end()) {
|
||||||
@ -188,7 +184,7 @@ public class JSONTokener {
|
|||||||
}
|
}
|
||||||
return new String(chars);
|
return new String(chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next char in the string, skipping whitespace.
|
* Get the next char in the string, skipping whitespace.
|
||||||
*
|
*
|
||||||
@ -197,14 +193,14 @@ public class JSONTokener {
|
|||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public char nextClean() throws JSONException {
|
public char nextClean() throws JSONException {
|
||||||
for (; ; ) {
|
for (;;) {
|
||||||
final char c = this.next();
|
final char c = this.next();
|
||||||
if ((c == 0) || (c > ' ')) {
|
if ((c == 0) || (c > ' ')) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the characters up to the next close quote character. Backslash processing is done. The formal JSON format
|
* Return the characters up to the next close quote character. Backslash processing is done. The formal JSON format
|
||||||
* does not allow strings in single quotes, but an implementation is allowed to accept them.
|
* does not allow strings in single quotes, but an implementation is allowed to accept them.
|
||||||
@ -219,7 +215,7 @@ public class JSONTokener {
|
|||||||
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:
|
||||||
@ -265,7 +261,7 @@ public class JSONTokener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the text up but not including the specified character or the end of line, whichever comes first.
|
* Get the text up but not including the specified character or the end of line, whichever comes first.
|
||||||
*
|
*
|
||||||
@ -275,7 +271,7 @@ public class JSONTokener {
|
|||||||
*/
|
*/
|
||||||
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) {
|
||||||
@ -286,7 +282,7 @@ public class JSONTokener {
|
|||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the text up but not including one of the specified delimiter characters or the end of line, whichever comes
|
* Get the text up but not including one of the specified delimiter characters or the end of line, whichever comes
|
||||||
* first.
|
* first.
|
||||||
@ -298,7 +294,7 @@ public class JSONTokener {
|
|||||||
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) {
|
||||||
@ -309,7 +305,7 @@ public class JSONTokener {
|
|||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next value. The value can be a Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
|
* Get the next value. The value can be a Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
|
||||||
* JSONObject.NULL object.
|
* JSONObject.NULL object.
|
||||||
@ -321,7 +317,6 @@ public class JSONTokener {
|
|||||||
public Object nextValue() throws JSONException {
|
public Object nextValue() throws JSONException {
|
||||||
char c = this.nextClean();
|
char c = this.nextClean();
|
||||||
String string;
|
String string;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '"':
|
case '"':
|
||||||
case '\'':
|
case '\'':
|
||||||
@ -333,7 +328,6 @@ public class JSONTokener {
|
|||||||
this.back();
|
this.back();
|
||||||
return new JSONArray(this);
|
return new JSONArray(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle unquoted text. This could be the values true, false, or
|
* Handle unquoted text. This could be the values true, false, or
|
||||||
* null, or it can be a number. An implementation (such as this one)
|
* null, or it can be a number. An implementation (such as this one)
|
||||||
@ -341,21 +335,19 @@ public class JSONTokener {
|
|||||||
* Accumulate characters until we reach the end of the text or a
|
* Accumulate characters until we reach the end of the text or a
|
||||||
* formatting character.
|
* formatting character.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
while ((c >= ' ') && (",:]}/\\\"[{;=#".indexOf(c) < 0)) {
|
while ((c >= ' ') && (",:]}/\\\"[{;=#".indexOf(c) < 0)) {
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
c = this.next();
|
c = this.next();
|
||||||
}
|
}
|
||||||
this.back();
|
this.back();
|
||||||
|
|
||||||
string = sb.toString().trim();
|
string = sb.toString().trim();
|
||||||
if ("".equals(string)) {
|
if ("".equals(string)) {
|
||||||
throw this.syntaxError("Missing value");
|
throw this.syntaxError("Missing value");
|
||||||
}
|
}
|
||||||
return JSONObject.stringToValue(string);
|
return JSONObject.stringToValue(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skip characters until the next character is the requested character. If the requested character is not found, no
|
* Skip characters until the next character is the requested character. If the requested character is not found, no
|
||||||
* characters are skipped.
|
* characters are skipped.
|
||||||
@ -387,7 +379,7 @@ public class JSONTokener {
|
|||||||
this.back();
|
this.back();
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a JSONException to signal a syntax error.
|
* Make a JSONException to signal a syntax error.
|
||||||
*
|
*
|
||||||
@ -398,7 +390,7 @@ public class JSONTokener {
|
|||||||
public JSONException syntaxError(final String message) {
|
public JSONException syntaxError(final String message) {
|
||||||
return new JSONException(message + this.toString());
|
return new JSONException(message + this.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a printable string of this JSONTokener.
|
* Make a printable string of this JSONTokener.
|
||||||
*
|
*
|
||||||
|
@ -55,7 +55,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
@ -66,7 +66,7 @@ public class JSONWriter {
|
|||||||
this.top = 0;
|
this.top = 0;
|
||||||
this.writer = w;
|
this.writer = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a value.
|
* Append a value.
|
||||||
*
|
*
|
||||||
@ -97,7 +97,7 @@ public class JSONWriter {
|
|||||||
}
|
}
|
||||||
throw new JSONException("Value out of sequence.");
|
throw new JSONException("Value out of sequence.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begin appending a new array. All values until the balancing <code>endArray</code> will be appended to this array.
|
* Begin appending a new array. All values until the balancing <code>endArray</code> will be appended to this array.
|
||||||
* The <code>endArray</code> method must be called to mark the array's end.
|
* The <code>endArray</code> method must be called to mark the array's end.
|
||||||
@ -116,7 +116,7 @@ public class JSONWriter {
|
|||||||
}
|
}
|
||||||
throw new JSONException("Misplaced array.");
|
throw new JSONException("Misplaced array.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End something.
|
* End something.
|
||||||
*
|
*
|
||||||
@ -140,7 +140,7 @@ public class JSONWriter {
|
|||||||
this.comma = true;
|
this.comma = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End an array. This method most be called to balance calls to <code>array</code>.
|
* End an array. This method most be called to balance calls to <code>array</code>.
|
||||||
*
|
*
|
||||||
@ -151,7 +151,7 @@ public class JSONWriter {
|
|||||||
public JSONWriter endArray() throws JSONException {
|
public JSONWriter endArray() throws JSONException {
|
||||||
return this.end('a', ']');
|
return this.end('a', ']');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End an object. This method most be called to balance calls to <code>object</code>.
|
* End an object. This method most be called to balance calls to <code>object</code>.
|
||||||
*
|
*
|
||||||
@ -162,7 +162,7 @@ public class JSONWriter {
|
|||||||
public JSONWriter endObject() throws JSONException {
|
public JSONWriter endObject() throws JSONException {
|
||||||
return this.end('k', '}');
|
return this.end('k', '}');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a key. The key will be associated with the next value. In an object, every value must be preceded by a
|
* Append a key. The key will be associated with the next value. In an object, every value must be preceded by a
|
||||||
* key.
|
* key.
|
||||||
@ -195,7 +195,7 @@ public class JSONWriter {
|
|||||||
}
|
}
|
||||||
throw new JSONException("Misplaced key.");
|
throw new JSONException("Misplaced key.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begin appending a new object. All keys and values until the balancing <code>endObject</code> will be appended to
|
* Begin appending a new object. All keys and values until the balancing <code>endObject</code> will be appended to
|
||||||
* this object. The <code>endObject</code> method must be called to mark the object's end.
|
* this object. The <code>endObject</code> method must be called to mark the object's end.
|
||||||
@ -216,9 +216,8 @@ public class JSONWriter {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
throw new JSONException("Misplaced object.");
|
throw new JSONException("Misplaced object.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pop an array or object scope.
|
* Pop an array or object scope.
|
||||||
*
|
*
|
||||||
@ -237,7 +236,7 @@ public class JSONWriter {
|
|||||||
this.top -= 1;
|
this.top -= 1;
|
||||||
this.mode = this.top == 0 ? 'd' : this.stack[this.top - 1] == null ? 'a' : 'k';
|
this.mode = this.top == 0 ? 'd' : this.stack[this.top - 1] == null ? 'a' : 'k';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push an array or object scope.
|
* Push an array or object scope.
|
||||||
*
|
*
|
||||||
@ -253,7 +252,7 @@ public class JSONWriter {
|
|||||||
this.mode = jo == null ? 'a' : 'k';
|
this.mode = jo == null ? 'a' : 'k';
|
||||||
this.top += 1;
|
this.top += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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> .
|
||||||
*
|
*
|
||||||
@ -266,7 +265,7 @@ public class JSONWriter {
|
|||||||
public JSONWriter value(final boolean b) throws JSONException {
|
public JSONWriter value(final boolean b) throws JSONException {
|
||||||
return this.append(b ? "true" : "false");
|
return this.append(b ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a double value.
|
* Append a double value.
|
||||||
*
|
*
|
||||||
@ -279,7 +278,7 @@ public class JSONWriter {
|
|||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a long value.
|
* Append a long value.
|
||||||
*
|
*
|
||||||
@ -292,7 +291,7 @@ public class JSONWriter {
|
|||||||
public JSONWriter value(final long l) throws JSONException {
|
public JSONWriter value(final long l) throws JSONException {
|
||||||
return this.append(Long.toString(l));
|
return this.append(Long.toString(l));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append an object value.
|
* Append an object value.
|
||||||
*
|
*
|
||||||
|
@ -27,7 +27,6 @@ package com.intellectualcrafters.json;
|
|||||||
* @version 2013-04-18
|
* @version 2013-04-18
|
||||||
*/
|
*/
|
||||||
public class Kim {
|
public class Kim {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of bytes in the kim. The number of bytes can be as much as three times the number of characters.
|
* The number of bytes in the kim. The number of bytes can be as much as three times the number of characters.
|
||||||
*/
|
*/
|
||||||
@ -44,7 +43,7 @@ public class Kim {
|
|||||||
* 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.
|
||||||
*
|
*
|
||||||
@ -53,11 +52,9 @@ public class Kim {
|
|||||||
* @param thru The index of the last byte plus one.
|
* @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) {
|
||||||
|
|
||||||
// As the bytes are copied into the new kim, a hashcode is computed
|
// As the bytes are copied into the new kim, a hashcode is computed
|
||||||
// using a
|
// using a
|
||||||
// modified Fletcher code.
|
// modified Fletcher code.
|
||||||
|
|
||||||
int sum = 1;
|
int sum = 1;
|
||||||
int value;
|
int value;
|
||||||
this.hashcode = 0;
|
this.hashcode = 0;
|
||||||
@ -73,7 +70,7 @@ public class Kim {
|
|||||||
this.hashcode += sum << 16;
|
this.hashcode += sum << 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a kim from a byte array.
|
* Make a kim from a byte array.
|
||||||
*
|
*
|
||||||
@ -83,7 +80,7 @@ public class Kim {
|
|||||||
public Kim(final byte[] bytes, final int length) {
|
public Kim(final byte[] bytes, final int length) {
|
||||||
this(bytes, 0, length);
|
this(bytes, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a new kim from a substring of an existing kim. The coordinates are in byte units, not character units.
|
* Make a new kim from a substring of an existing kim. The coordinates are in byte units, not character units.
|
||||||
*
|
*
|
||||||
@ -94,7 +91,7 @@ public class Kim {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a kim from a string.
|
* Make a kim from a string.
|
||||||
*
|
*
|
||||||
@ -106,10 +103,8 @@ public class Kim {
|
|||||||
final int stringLength = string.length();
|
final int stringLength = string.length();
|
||||||
this.hashcode = 0;
|
this.hashcode = 0;
|
||||||
this.length = 0;
|
this.length = 0;
|
||||||
|
|
||||||
// First pass: Determine the length of the kim, allowing for the UTF-16
|
// First pass: Determine the length of the kim, allowing for the UTF-16
|
||||||
// to UTF-32 conversion, and then the UTF-32 to Kim conversion.
|
// to UTF-32 conversion, and then the UTF-32 to Kim conversion.
|
||||||
|
|
||||||
if (stringLength > 0) {
|
if (stringLength > 0) {
|
||||||
for (int i = 0; i < stringLength; i += 1) {
|
for (int i = 0; i < stringLength; i += 1) {
|
||||||
final int c = string.charAt(i);
|
final int c = string.charAt(i);
|
||||||
@ -128,11 +123,9 @@ public class Kim {
|
|||||||
this.length += 3;
|
this.length += 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second pass: Allocate a byte array and fill that array with the
|
// Second pass: Allocate a byte array and fill that array with the
|
||||||
// conversion
|
// conversion
|
||||||
// while computing the hashcode.
|
// while computing the hashcode.
|
||||||
|
|
||||||
this.bytes = new byte[this.length];
|
this.bytes = new byte[this.length];
|
||||||
int at = 0;
|
int at = 0;
|
||||||
int b;
|
int b;
|
||||||
@ -180,7 +173,7 @@ public class Kim {
|
|||||||
this.hashcode += sum << 16;
|
this.hashcode += sum << 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of bytes needed to contain the character in Kim format.
|
* Returns the number of bytes needed to contain the character in Kim format.
|
||||||
*
|
*
|
||||||
@ -196,7 +189,7 @@ public class Kim {
|
|||||||
}
|
}
|
||||||
return character <= 0x7F ? 1 : character <= 0x3FFF ? 2 : 3;
|
return character <= 0x7F ? 1 : character <= 0x3FFF ? 2 : 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the character at the specified index. The index refers to byte values and ranges from 0 to length - 1.
|
* Returns the character at the specified index. The index refers to byte values and ranges from 0 to length - 1.
|
||||||
* The index of the next character is at index + Kim.characterSize(kim.characterAt(index)).
|
* The index of the next character is at index + Kim.characterSize(kim.characterAt(index)).
|
||||||
@ -227,7 +220,7 @@ public class Kim {
|
|||||||
}
|
}
|
||||||
throw new JSONException("Bad character at " + at);
|
throw new JSONException("Bad character at " + at);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the contents of this kim to a byte array.
|
* Copy the contents of this kim to a byte array.
|
||||||
*
|
*
|
||||||
@ -240,7 +233,7 @@ public class Kim {
|
|||||||
System.arraycopy(this.bytes, 0, bytes, at, this.length);
|
System.arraycopy(this.bytes, 0, bytes, at, this.length);
|
||||||
return at + this.length;
|
return at + this.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Two kim objects containing exactly the same bytes in the same order are equal to each other.
|
* Two kim objects containing exactly the same bytes in the same order are equal to each other.
|
||||||
*
|
*
|
||||||
@ -262,7 +255,7 @@ public class Kim {
|
|||||||
}
|
}
|
||||||
return java.util.Arrays.equals(this.bytes, that.bytes);
|
return java.util.Arrays.equals(this.bytes, that.bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a byte from a kim.
|
* Get a byte from a kim.
|
||||||
*
|
*
|
||||||
@ -278,7 +271,7 @@ public class Kim {
|
|||||||
}
|
}
|
||||||
return (this.bytes[at]) & 0xFF;
|
return (this.bytes[at]) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a hash code value for the kim.
|
* Returns a hash code value for the kim.
|
||||||
*/
|
*/
|
||||||
@ -286,7 +279,7 @@ public class Kim {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return this.hashcode;
|
return this.hashcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a UTF-16 String from this kim. The number of codepoints in the string will not be greater than the number
|
* Produce a UTF-16 String from this kim. The number of codepoints in the string will not be greater than the number
|
||||||
* of bytes in the kim, although it could be less.
|
* of bytes in the kim, although it could be less.
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.json;
|
package com.intellectualcrafters.json;
|
||||||
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
@ -52,7 +51,7 @@ public class Property {
|
|||||||
}
|
}
|
||||||
return jo;
|
return jo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the JSONObject into a property file object.
|
* Converts the JSONObject into a property file object.
|
||||||
*
|
*
|
||||||
|
@ -9,52 +9,43 @@ import java.util.Iterator;
|
|||||||
* @version 2014-05-03
|
* @version 2014-05-03
|
||||||
*/
|
*/
|
||||||
public class XML {
|
public class XML {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '&'.
|
* The Character '&'.
|
||||||
*/
|
*/
|
||||||
public static final Character AMP = '&';
|
public static final Character AMP = '&';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '''.
|
* The Character '''.
|
||||||
*/
|
*/
|
||||||
public static final Character APOS = '\'';
|
public static final Character APOS = '\'';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '!'.
|
* The Character '!'.
|
||||||
*/
|
*/
|
||||||
public static final Character BANG = '!';
|
public static final Character BANG = '!';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '='.
|
* The Character '='.
|
||||||
*/
|
*/
|
||||||
public static final Character EQ = '=';
|
public static final Character EQ = '=';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '>'.
|
* The Character '>'.
|
||||||
*/
|
*/
|
||||||
public static final Character GT = '>';
|
public static final Character GT = '>';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '<'.
|
* The Character '<'.
|
||||||
*/
|
*/
|
||||||
public static final Character LT = '<';
|
public static final Character LT = '<';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '?'.
|
* The Character '?'.
|
||||||
*/
|
*/
|
||||||
public static final Character QUEST = '?';
|
public static final Character QUEST = '?';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Character '"'.
|
* The Character '"'.
|
||||||
*/
|
*/
|
||||||
public static final Character QUOT = '"';
|
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/>
|
* <p/>
|
||||||
@ -96,7 +87,7 @@ public class XML {
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throw an exception if the string contains whitespace. Whitespace is not allowed in tagNames and attributes.
|
* Throw an exception if the string contains whitespace. Whitespace is not allowed in tagNames and attributes.
|
||||||
*
|
*
|
||||||
@ -116,7 +107,7 @@ 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.
|
||||||
*
|
*
|
||||||
@ -135,7 +126,6 @@ public class XML {
|
|||||||
String string;
|
String string;
|
||||||
String tagName;
|
String tagName;
|
||||||
Object token;
|
Object token;
|
||||||
|
|
||||||
// Test for and skip past these forms:
|
// Test for and skip past these forms:
|
||||||
// <!-- ... -->
|
// <!-- ... -->
|
||||||
// <! ... >
|
// <! ... >
|
||||||
@ -145,11 +135,8 @@ public class XML {
|
|||||||
// <>
|
// <>
|
||||||
// <=
|
// <=
|
||||||
// <<
|
// <<
|
||||||
|
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
|
|
||||||
// <!
|
// <!
|
||||||
|
|
||||||
if (token == BANG) {
|
if (token == BANG) {
|
||||||
c = x.next();
|
c = x.next();
|
||||||
if (c == '-') {
|
if (c == '-') {
|
||||||
@ -184,15 +171,11 @@ public class XML {
|
|||||||
} 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 </
|
||||||
|
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
throw x.syntaxError("Mismatched close tag " + token);
|
throw x.syntaxError("Mismatched close tag " + token);
|
||||||
@ -204,23 +187,18 @@ public class XML {
|
|||||||
throw x.syntaxError("Misshaped close tag");
|
throw x.syntaxError("Misshaped close tag");
|
||||||
}
|
}
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
// attribute = value
|
// attribute = value
|
||||||
|
|
||||||
if (token instanceof String) {
|
if (token instanceof String) {
|
||||||
string = (String) token;
|
string = (String) token;
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
@ -234,9 +212,7 @@ public class XML {
|
|||||||
} 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");
|
||||||
@ -247,11 +223,9 @@ public class XML {
|
|||||||
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) {
|
||||||
@ -263,9 +237,7 @@ public class XML {
|
|||||||
if (string.length() > 0) {
|
if (string.length() > 0) {
|
||||||
jsonobject.accumulate("content", XML.stringToValue(string));
|
jsonobject.accumulate("content", XML.stringToValue(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
@ -285,7 +257,7 @@ public class XML {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to convert a string into a number, boolean, or null. If the string can't be converted, return the string.
|
* Try to convert a string into a number, boolean, or null. If the string can't be converted, return the string.
|
||||||
* This is much less ambitious than JSONObject.stringToValue, especially because it does not attempt to convert plus
|
* This is much less ambitious than JSONObject.stringToValue, especially because it does not attempt to convert plus
|
||||||
@ -305,11 +277,9 @@ public class XML {
|
|||||||
if ("null".equalsIgnoreCase(string)) {
|
if ("null".equalsIgnoreCase(string)) {
|
||||||
return JSONObject.NULL;
|
return JSONObject.NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it might be a number, try converting it, first as a Long, and then
|
// If it might be a number, try converting it, first as a Long, and then
|
||||||
// as a
|
// as a
|
||||||
// Double. If that doesn't work, return the string.
|
// Double. If that doesn't work, return the string.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final char initial = string.charAt(0);
|
final char initial = string.charAt(0);
|
||||||
if ((initial == '-') || ((initial >= '0') && (initial <= '9'))) {
|
if ((initial == '-') || ((initial >= '0') && (initial <= '9'))) {
|
||||||
@ -329,7 +299,7 @@ public class XML {
|
|||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONObject. Some information may be lost in
|
* Convert a well-formed (but not necessarily valid) XML string into a JSONObject. Some information may be lost in
|
||||||
* this transformation because JSON is a data format and XML is a document format. XML uses elements, attributes,
|
* this transformation because JSON is a data format and XML is a document format. XML uses elements, attributes,
|
||||||
@ -352,7 +322,7 @@ public class XML {
|
|||||||
}
|
}
|
||||||
return jo;
|
return jo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a JSONObject into a well-formed, element-normal XML string.
|
* Convert a JSONObject into a well-formed, element-normal XML string.
|
||||||
*
|
*
|
||||||
@ -365,7 +335,7 @@ public class XML {
|
|||||||
public static String toString(final Object object) throws JSONException {
|
public static String toString(final Object object) throws JSONException {
|
||||||
return toString(object, null);
|
return toString(object, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a JSONObject into a well-formed, element-normal XML string.
|
* Convert a JSONObject into a well-formed, element-normal XML string.
|
||||||
*
|
*
|
||||||
@ -387,17 +357,13 @@ public class XML {
|
|||||||
String string;
|
String string;
|
||||||
Object value;
|
Object value;
|
||||||
if (object instanceof JSONObject) {
|
if (object instanceof JSONObject) {
|
||||||
|
|
||||||
// Emit <tagName>
|
// Emit <tagName>
|
||||||
|
|
||||||
if (tagName != null) {
|
if (tagName != null) {
|
||||||
sb.append('<');
|
sb.append('<');
|
||||||
sb.append(tagName);
|
sb.append(tagName);
|
||||||
sb.append('>');
|
sb.append('>');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop thru the keys.
|
// Loop thru the keys.
|
||||||
|
|
||||||
jo = (JSONObject) object;
|
jo = (JSONObject) object;
|
||||||
keys = jo.keys();
|
keys = jo.keys();
|
||||||
while (keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
@ -407,9 +373,7 @@ public class XML {
|
|||||||
value = "";
|
value = "";
|
||||||
}
|
}
|
||||||
string = value instanceof String ? (String) value : null;
|
string = value instanceof String ? (String) value : null;
|
||||||
|
|
||||||
// Emit content in body
|
// Emit content in body
|
||||||
|
|
||||||
if ("content".equals(key)) {
|
if ("content".equals(key)) {
|
||||||
if (value instanceof JSONArray) {
|
if (value instanceof JSONArray) {
|
||||||
ja = (JSONArray) value;
|
ja = (JSONArray) value;
|
||||||
@ -423,9 +387,7 @@ public class XML {
|
|||||||
} 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();
|
||||||
@ -447,27 +409,21 @@ public class XML {
|
|||||||
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tagName != null) {
|
if (tagName != null) {
|
||||||
|
|
||||||
// Emit the </tagname> close tag
|
// Emit the </tagname> close tag
|
||||||
|
|
||||||
sb.append("</");
|
sb.append("</");
|
||||||
sb.append(tagName);
|
sb.append(tagName);
|
||||||
sb.append('>');
|
sb.append('>');
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
|
||||||
// XML does not have good support for arrays. If an array appears in
|
// XML does not have good support for arrays. If an array appears in
|
||||||
// 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);
|
||||||
|
@ -7,12 +7,10 @@ package com.intellectualcrafters.json;
|
|||||||
* @version 2014-05-03
|
* @version 2014-05-03
|
||||||
*/
|
*/
|
||||||
public class XMLTokener extends JSONTokener {
|
public class XMLTokener extends JSONTokener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The table of entity values. It initially contains Character values for amp, apos, gt, lt, quot.
|
* The table of entity values. It initially contains Character values for amp, apos, gt, lt, quot.
|
||||||
*/
|
*/
|
||||||
public static final java.util.HashMap<String, Character> entity;
|
public static final java.util.HashMap<String, Character> entity;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
entity = new java.util.HashMap<String, Character>(8);
|
entity = new java.util.HashMap<String, Character>(8);
|
||||||
entity.put("amp", XML.AMP);
|
entity.put("amp", XML.AMP);
|
||||||
@ -21,7 +19,7 @@ public class XMLTokener extends JSONTokener {
|
|||||||
entity.put("lt", XML.LT);
|
entity.put("lt", XML.LT);
|
||||||
entity.put("quot", XML.QUOT);
|
entity.put("quot", XML.QUOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an XMLTokener from a string.
|
* Construct an XMLTokener from a string.
|
||||||
*
|
*
|
||||||
@ -30,7 +28,7 @@ public class XMLTokener extends JSONTokener {
|
|||||||
public XMLTokener(final String s) {
|
public XMLTokener(final String s) {
|
||||||
super(s);
|
super(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the text in the CDATA block.
|
* Get the text in the CDATA block.
|
||||||
*
|
*
|
||||||
@ -42,7 +40,7 @@ public class XMLTokener extends JSONTokener {
|
|||||||
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");
|
||||||
@ -55,7 +53,7 @@ public class XMLTokener extends JSONTokener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next XML outer token, trimming whitespace. There are two kinds of tokens: the '<' character which begins
|
* Get the next XML outer token, trimming whitespace. There are two kinds of tokens: the '<' character which begins
|
||||||
* a markup tag, and the content text between markup tags.
|
* a markup tag, and the content text between markup tags.
|
||||||
@ -77,7 +75,7 @@ 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();
|
||||||
@ -90,7 +88,7 @@ public class XMLTokener extends JSONTokener {
|
|||||||
c = next();
|
c = next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the next entity. These entities are translated to Characters: <code>& ' > <
|
* Return the next entity. These entities are translated to Characters: <code>& ' > <
|
||||||
* "</code>.
|
* "</code>.
|
||||||
@ -103,7 +101,7 @@ public class XMLTokener extends JSONTokener {
|
|||||||
*/
|
*/
|
||||||
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));
|
||||||
@ -117,7 +115,7 @@ public class XMLTokener extends JSONTokener {
|
|||||||
final Object object = entity.get(string);
|
final Object object = entity.get(string);
|
||||||
return object != null ? object : ampersand + string + ";";
|
return object != null ? object : ampersand + string + ";";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next XML meta token. This is used for skipping over <!...> and <?...?> structures.
|
* Returns the next XML meta token. This is used for skipping over <!...> and <?...?> structures.
|
||||||
*
|
*
|
||||||
@ -150,7 +148,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");
|
||||||
@ -160,7 +158,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;
|
||||||
@ -181,7 +179,7 @@ public class XMLTokener extends JSONTokener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next XML Token. These tokens are found inside of angle brackets. It may be one of these characters:
|
* Get the next XML Token. These tokens are found inside of angle brackets. It may be one of these characters:
|
||||||
* <code>/ > = ! ?</code> or it may be a string wrapped in single quotes or double quotes, or it may be a name.
|
* <code>/ > = ! ?</code> or it may be a string wrapped in single quotes or double quotes, or it may be a name.
|
||||||
@ -212,14 +210,12 @@ public class XMLTokener extends JSONTokener {
|
|||||||
return XML.BANG;
|
return XML.BANG;
|
||||||
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");
|
||||||
@ -234,11 +230,9 @@ public class XMLTokener extends JSONTokener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
||||||
// 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)) {
|
||||||
@ -264,7 +258,7 @@ public class XMLTokener extends JSONTokener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skip characters until past the requested string. If it is not found, we are left at the end of the source with a
|
* Skip characters until past the requested string. If it is not found, we are left at the end of the source with a
|
||||||
* result of false.
|
* result of false.
|
||||||
@ -281,12 +275,10 @@ public class XMLTokener extends JSONTokener {
|
|||||||
int offset = 0;
|
int offset = 0;
|
||||||
final int length = to.length();
|
final int length = to.length();
|
||||||
final char[] circle = new char[length];
|
final char[] circle = new char[length];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* First fill the circle buffer with as many characters as are in the
|
* First fill the circle buffer with as many characters as are in the
|
||||||
* to string. If we reach an early end, bail.
|
* to string. If we reach an early end, bail.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (i = 0; i < length; i += 1) {
|
for (i = 0; i < length; i += 1) {
|
||||||
c = next();
|
c = next();
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
@ -294,15 +286,11 @@ public class XMLTokener extends JSONTokener {
|
|||||||
}
|
}
|
||||||
circle[i] = c;
|
circle[i] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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;
|
||||||
|
|
||||||
/* Compare the circle buffer with the to string. */
|
/* Compare the circle buffer with the to string. */
|
||||||
|
|
||||||
for (i = 0; i < length; i += 1) {
|
for (i = 0; i < length; i += 1) {
|
||||||
if (circle[j] != to.charAt(i)) {
|
if (circle[j] != to.charAt(i)) {
|
||||||
b = false;
|
b = false;
|
||||||
@ -313,15 +301,11 @@ public class XMLTokener extends JSONTokener {
|
|||||||
j -= length;
|
j -= length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we exit the loop with b intact, then victory is ours. */
|
/* If we exit the loop with b intact, then victory is ours. */
|
||||||
|
|
||||||
if (b) {
|
if (b) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the next character. If there isn't one, then defeat is ours. */
|
/* Get the next character. If there isn't one, then defeat is ours. */
|
||||||
|
|
||||||
c = next();
|
c = next();
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -0,0 +1,340 @@
|
|||||||
|
package com.intellectualcrafters.plot;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.world.WorldLoadEvent;
|
||||||
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.commands.BukkitCommand;
|
||||||
|
import com.intellectualcrafters.plot.commands.Buy;
|
||||||
|
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||||
|
import com.intellectualcrafters.plot.commands.WE_Anywhere;
|
||||||
|
import com.intellectualcrafters.plot.config.C;
|
||||||
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
|
import com.intellectualcrafters.plot.database.PlotMeConverter;
|
||||||
|
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
|
||||||
|
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
|
||||||
|
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||||
|
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||||
|
import com.intellectualcrafters.plot.listeners.ForceFieldListener;
|
||||||
|
import com.intellectualcrafters.plot.listeners.InventoryListener;
|
||||||
|
import com.intellectualcrafters.plot.listeners.PlayerEvents;
|
||||||
|
import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8;
|
||||||
|
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
|
||||||
|
import com.intellectualcrafters.plot.listeners.WorldEditListener;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
|
import com.intellectualcrafters.plot.util.ConsoleColors;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||||
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.BukkitSetupUtils;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.Metrics;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.SendChunk;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.SetBlockFast;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.SetBlockFast_1_8;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.SetBlockManager;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.SetBlockSlow;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
|
|
||||||
|
public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||||
|
public static BukkitMain THIS = null;
|
||||||
|
public static PlotSquared MAIN = null;
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public static void worldLoad(final WorldLoadEvent event) {
|
||||||
|
UUIDHandler.cacheAll(event.getWorld().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkVersion(final int major, final int minor, final int minor2) {
|
||||||
|
try {
|
||||||
|
final String[] version = Bukkit.getBukkitVersion().split("-")[0].split("\\.");
|
||||||
|
final int a = Integer.parseInt(version[0]);
|
||||||
|
final int b = Integer.parseInt(version[1]);
|
||||||
|
int c = 0;
|
||||||
|
if (version.length == 3) {
|
||||||
|
c = Integer.parseInt(version[2]);
|
||||||
|
}
|
||||||
|
if ((a > major) || ((a == major) && (b > minor)) || ((a == major) && (b == minor) && (c >= minor2))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void PlayerCommand(final PlayerCommandPreprocessEvent event) {
|
||||||
|
final String message = event.getMessage();
|
||||||
|
if (message.toLowerCase().startsWith("/plotme")) {
|
||||||
|
final Plugin plotme = Bukkit.getPluginManager().getPlugin("PlotMe");
|
||||||
|
if (plotme == null) {
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
if (Settings.USE_PLOTME_ALIAS) {
|
||||||
|
player.performCommand(message.replace("/plotme", "plots"));
|
||||||
|
} else {
|
||||||
|
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_USING_PLOTME);
|
||||||
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
MAIN = new PlotSquared(this);
|
||||||
|
THIS = this;
|
||||||
|
if (Settings.METRICS) {
|
||||||
|
try {
|
||||||
|
final Metrics metrics = new Metrics(this);
|
||||||
|
metrics.start();
|
||||||
|
log(C.PREFIX.s() + "&6Metrics enabled.");
|
||||||
|
} catch (final Exception e) {
|
||||||
|
log(C.PREFIX.s() + "&cFailed to load up metrics.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log("&dUsing metrics will allow us to improve the plugin, please consider it :)");
|
||||||
|
}
|
||||||
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
MAIN.disable();
|
||||||
|
MAIN = null;
|
||||||
|
THIS = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(String message) {
|
||||||
|
if ((THIS == null) || (Bukkit.getServer().getConsoleSender() == null)) {
|
||||||
|
System.out.println(ChatColor.stripColor(ConsoleColors.fromString(message)));
|
||||||
|
} else {
|
||||||
|
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||||
|
if (!Settings.CONSOLE_COLOR) {
|
||||||
|
message = ChatColor.stripColor(message);
|
||||||
|
}
|
||||||
|
Bukkit.getServer().getConsoleSender().sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disable() {
|
||||||
|
onDisable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getVersion() {
|
||||||
|
return this.getDescription().getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerCommands() {
|
||||||
|
final MainCommand command = new MainCommand();
|
||||||
|
final BukkitCommand bcmd = new BukkitCommand();
|
||||||
|
final PluginCommand plotCommand = getCommand("plots");
|
||||||
|
plotCommand.setExecutor(bcmd);
|
||||||
|
plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
|
||||||
|
plotCommand.setTabCompleter(bcmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getDirectory() {
|
||||||
|
return getDataFolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TaskManager getTaskManager() {
|
||||||
|
return new BukkitTaskManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runEntityTask() {
|
||||||
|
log(C.PREFIX.s() + "KillAllEntities started.");
|
||||||
|
TaskManager.runTaskRepeat(new Runnable() {
|
||||||
|
long ticked = 0l;
|
||||||
|
long error = 0l;
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (this.ticked > 36_000L) {
|
||||||
|
this.ticked = 0l;
|
||||||
|
if (this.error > 0) {
|
||||||
|
log(C.PREFIX.s() + "KillAllEntities has been running for 6 hours. Errors: " + this.error);
|
||||||
|
}
|
||||||
|
this.error = 0l;
|
||||||
|
}
|
||||||
|
World world;
|
||||||
|
for (final String w : PlotSquared.getPlotWorlds()) {
|
||||||
|
world = Bukkit.getWorld(w);
|
||||||
|
try {
|
||||||
|
if (world.getLoadedChunks().length < 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (final Chunk chunk : world.getLoadedChunks()) {
|
||||||
|
final Entity[] entities = chunk.getEntities();
|
||||||
|
Entity entity;
|
||||||
|
for (int i = entities.length - 1; i >= 0; i--) {
|
||||||
|
if (!((entity = entities[i]) instanceof Player) && (MainUtil.getPlot(BukkitUtil.getLocation(entity)) == null)) {
|
||||||
|
entity.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
++this.error;
|
||||||
|
} finally {
|
||||||
|
++this.ticked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) {
|
||||||
|
if (!PlotSquared.setupPlotWorld(world, id)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new HybridGen(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerPlayerEvents() {
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerEvents(), this);
|
||||||
|
if (checkVersion(1, 8, 0)) {
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerInventoryEvents() {
|
||||||
|
getServer().getPluginManager().registerEvents(new InventoryListener(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerPlotPlusEvents() {
|
||||||
|
PlotPlusListener.startRunnable(this);
|
||||||
|
getServer().getPluginManager().registerEvents(new PlotPlusListener(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerForceFieldEvents() {
|
||||||
|
getServer().getPluginManager().registerEvents(new ForceFieldListener(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerWorldEditEvents() {
|
||||||
|
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
|
||||||
|
PlotSquared.worldEdit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
|
||||||
|
final String version = PlotSquared.worldEdit.getDescription().getVersion();
|
||||||
|
if ((version != null) && version.startsWith("5.")) {
|
||||||
|
log("&cThis version of WorldEdit does not support PlotSquared.");
|
||||||
|
log("&cPlease use WorldEdit 6+ for masking support");
|
||||||
|
log("&c - http://builds.enginehub.org/job/worldedit");
|
||||||
|
} else {
|
||||||
|
getServer().getPluginManager().registerEvents(new WorldEditListener(), this);
|
||||||
|
MainCommand.subCommands.add(new WE_Anywhere());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Economy getEconomy() {
|
||||||
|
if ((getServer().getPluginManager().getPlugin("Vault") != null) && getServer().getPluginManager().getPlugin("Vault").isEnabled()) {
|
||||||
|
final RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||||
|
if (economyProvider != null) {
|
||||||
|
MainCommand.subCommands.add(new Buy());
|
||||||
|
return economyProvider.getProvider();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockManager initBlockManager() {
|
||||||
|
if (checkVersion(1, 8, 0)) {
|
||||||
|
try {
|
||||||
|
SetBlockManager.setBlockManager = new SetBlockFast_1_8();
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
SetBlockManager.setBlockManager = new SetBlockSlow();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
SetBlockManager.setBlockManager = new SetBlockFast();
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
SetBlockManager.setBlockManager = new SetBlockSlow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
new SendChunk();
|
||||||
|
MainUtil.canSendChunk = true;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
MainUtil.canSendChunk = false;
|
||||||
|
}
|
||||||
|
return BlockManager.manager = new BukkitUtil();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean initPlotMeConverter() {
|
||||||
|
try {
|
||||||
|
new PlotMeConverter().runAsync();
|
||||||
|
} catch (final Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (Bukkit.getPluginManager().getPlugin("PlotMe") != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getGenerator(final String world, final String name) {
|
||||||
|
final Plugin gen_plugin = Bukkit.getPluginManager().getPlugin(name);
|
||||||
|
if ((gen_plugin != null) && gen_plugin.isEnabled()) {
|
||||||
|
gen_plugin.getDefaultWorldGenerator(world, "");
|
||||||
|
} else {
|
||||||
|
new HybridGen(world);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean callRemovePlot(final String world, final PlotId id) {
|
||||||
|
final PlotDeleteEvent event = new PlotDeleteEvent(world, id);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HybridUtils initHybridUtils() {
|
||||||
|
return new BukkitHybridUtils();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SetupUtils initSetupUtils() {
|
||||||
|
return new BukkitSetupUtils();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package com.intellectualcrafters.plot;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
|
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||||
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
|
|
||||||
|
public interface IPlotMain {
|
||||||
|
public void log(String message);
|
||||||
|
|
||||||
|
public File getDirectory();
|
||||||
|
|
||||||
|
public void disable();
|
||||||
|
|
||||||
|
public String getVersion();
|
||||||
|
|
||||||
|
public TaskManager getTaskManager();
|
||||||
|
|
||||||
|
public void runEntityTask();
|
||||||
|
|
||||||
|
public void registerCommands();
|
||||||
|
|
||||||
|
public void registerPlayerEvents();
|
||||||
|
|
||||||
|
public void registerInventoryEvents();
|
||||||
|
|
||||||
|
public void registerPlotPlusEvents();
|
||||||
|
|
||||||
|
public void registerForceFieldEvents();
|
||||||
|
|
||||||
|
public void registerWorldEditEvents();
|
||||||
|
|
||||||
|
public Economy getEconomy();
|
||||||
|
|
||||||
|
public BlockManager initBlockManager();
|
||||||
|
|
||||||
|
public SetupUtils initSetupUtils();
|
||||||
|
|
||||||
|
public HybridUtils initHybridUtils();
|
||||||
|
|
||||||
|
public boolean initPlotMeConverter();
|
||||||
|
|
||||||
|
public void getGenerator(String world, String name);
|
||||||
|
|
||||||
|
public boolean callRemovePlot(String world, PlotId id);
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,836 @@
|
|||||||
|
package com.intellectualcrafters.plot;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.commands.Cluster;
|
||||||
|
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||||
|
import com.intellectualcrafters.plot.config.C;
|
||||||
|
import com.intellectualcrafters.plot.config.Configuration;
|
||||||
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
|
import com.intellectualcrafters.plot.database.MySQL;
|
||||||
|
import com.intellectualcrafters.plot.database.SQLManager;
|
||||||
|
import com.intellectualcrafters.plot.database.SQLite;
|
||||||
|
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
||||||
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
|
import com.intellectualcrafters.plot.flag.FlagValue;
|
||||||
|
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
|
||||||
|
import com.intellectualcrafters.plot.generator.ClassicPlotWorld;
|
||||||
|
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||||
|
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
||||||
|
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||||
|
import com.intellectualcrafters.plot.generator.SquarePlotManager;
|
||||||
|
import com.intellectualcrafters.plot.generator.SquarePlotWorld;
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotGenerator;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotManager;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
|
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||||
|
import com.intellectualcrafters.plot.util.ExpireManager;
|
||||||
|
import com.intellectualcrafters.plot.util.Logger;
|
||||||
|
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||||
|
import com.intellectualcrafters.plot.util.Logger.LogLevel;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
|
|
||||||
|
public class PlotSquared {
|
||||||
|
public static final String MAIN_PERMISSION = "plots.use";
|
||||||
|
public static final String ADMIN_PERMISSION = "plots.admin";
|
||||||
|
public static File styleFile;
|
||||||
|
public static YamlConfiguration style;
|
||||||
|
public static File configFile;
|
||||||
|
public static YamlConfiguration config;
|
||||||
|
public static File storageFile;
|
||||||
|
public static YamlConfiguration storage;
|
||||||
|
public static PlotSquared THIS = null; // This class
|
||||||
|
public static IPlotMain IMP = null; // Specific implementation of PlotSquared
|
||||||
|
public static String VERSION = null;
|
||||||
|
public static TaskManager TASK = null;
|
||||||
|
private static boolean LOADING_WORLD = false;
|
||||||
|
public static Economy economy = null;
|
||||||
|
public static WorldEditPlugin worldEdit = null;
|
||||||
|
private final static HashMap<String, PlotWorld> plotworlds = new HashMap<>();
|
||||||
|
private final static HashMap<String, PlotManager> plotmanagers = new HashMap<>();
|
||||||
|
private static LinkedHashMap<String, HashMap<PlotId, Plot>> plots;
|
||||||
|
private static MySQL mySQL;
|
||||||
|
public static Connection connection;
|
||||||
|
|
||||||
|
public static MySQL getMySQL() {
|
||||||
|
return mySQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updatePlot(final Plot plot) {
|
||||||
|
final String world = plot.world;
|
||||||
|
if (!plots.containsKey(world)) {
|
||||||
|
plots.put(world, new HashMap<PlotId, Plot>());
|
||||||
|
}
|
||||||
|
plot.hasChanged = true;
|
||||||
|
plots.get(world).put(plot.id, plot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlotWorld getPlotWorld(final String world) {
|
||||||
|
if (plotworlds.containsKey(world)) {
|
||||||
|
return plotworlds.get(world);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addPlotWorld(final String world, final PlotWorld plotworld, final PlotManager manager) {
|
||||||
|
plotworlds.put(world, plotworld);
|
||||||
|
plotmanagers.put(world, manager);
|
||||||
|
if (!plots.containsKey(world)) {
|
||||||
|
plots.put(world, new HashMap<PlotId, Plot>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removePlotWorld(final String world) {
|
||||||
|
plots.remove(world);
|
||||||
|
plotmanagers.remove(world);
|
||||||
|
plotworlds.remove(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashMap<String, HashMap<PlotId, Plot>> getAllPlotsRaw() {
|
||||||
|
return plots;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setAllPlotsRaw(final LinkedHashMap<String, HashMap<PlotId, Plot>> plots) {
|
||||||
|
PlotSquared.plots = plots;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<Plot> getPlots() {
|
||||||
|
final ArrayList<Plot> newplots = new ArrayList<>();
|
||||||
|
for (final HashMap<PlotId, Plot> world : plots.values()) {
|
||||||
|
newplots.addAll(world.values());
|
||||||
|
}
|
||||||
|
return new LinkedHashSet<>(newplots);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LinkedHashSet<Plot> getPlotsSorted() {
|
||||||
|
final ArrayList<Plot> newplots = new ArrayList<>();
|
||||||
|
for (final HashMap<PlotId, Plot> world : plots.values()) {
|
||||||
|
newplots.addAll(world.values());
|
||||||
|
}
|
||||||
|
return new LinkedHashSet<>(newplots);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<Plot> getPlots(final String world, final String player) {
|
||||||
|
final UUID uuid = UUIDHandler.getUUID(player);
|
||||||
|
return getPlots(world, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<Plot> getPlots(final String world, final PlotPlayer player) {
|
||||||
|
final UUID uuid = player.getUUID();
|
||||||
|
return getPlots(world, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<Plot> getPlots(final String world, final UUID uuid) {
|
||||||
|
final ArrayList<Plot> myplots = new ArrayList<>();
|
||||||
|
for (final Plot plot : getPlots(world).values()) {
|
||||||
|
if (plot.hasOwner()) {
|
||||||
|
if (plot.getOwner().equals(uuid)) {
|
||||||
|
myplots.add(plot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new HashSet<>(myplots);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isPlotWorld(final String world) {
|
||||||
|
return (plotworlds.containsKey(world));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlotManager getPlotManager(final String world) {
|
||||||
|
if (plotmanagers.containsKey(world)) {
|
||||||
|
return plotmanagers.get(world);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getPlotWorldsString() {
|
||||||
|
final Set<String> strings = plots.keySet();
|
||||||
|
return strings.toArray(new String[strings.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashMap<PlotId, Plot> getPlots(final String world) {
|
||||||
|
if (plots.containsKey(world)) {
|
||||||
|
return plots.get(world);
|
||||||
|
}
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<Plot> getPlots(final PlotPlayer player) {
|
||||||
|
final UUID uuid = player.getUUID();
|
||||||
|
final ArrayList<Plot> myplots = new ArrayList<>();
|
||||||
|
for (final String world : plots.keySet()) {
|
||||||
|
if (isPlotWorld(world)) {
|
||||||
|
for (final Plot plot : plots.get(world).values()) {
|
||||||
|
if (plot.hasOwner()) {
|
||||||
|
if (plot.getOwner().equals(uuid)) {
|
||||||
|
myplots.add(plot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new HashSet<>(myplots);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean removePlot(final String world, final PlotId id, final boolean callEvent) {
|
||||||
|
if (callEvent) {
|
||||||
|
if (!IMP.callRemovePlot(world, id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
plots.get(world).remove(id);
|
||||||
|
if (MainUtil.lastPlot.containsKey(world)) {
|
||||||
|
final PlotId last = MainUtil.lastPlot.get(world);
|
||||||
|
final int last_max = Math.max(last.x, last.y);
|
||||||
|
final int this_max = Math.max(id.x, id.y);
|
||||||
|
if (this_max < last_max) {
|
||||||
|
MainUtil.lastPlot.put(world, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadWorld(final String world, final PlotGenerator generator) {
|
||||||
|
if (getPlotWorld(world) != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Set<String> worlds = (config.contains("worlds") ? config.getConfigurationSection("worlds").getKeys(false) : new HashSet<String>());
|
||||||
|
final PlotWorld plotWorld;
|
||||||
|
final PlotGenerator plotGenerator;
|
||||||
|
final PlotManager plotManager;
|
||||||
|
final String path = "worlds." + world;
|
||||||
|
if (!LOADING_WORLD && (generator != null) && (generator instanceof PlotGenerator)) {
|
||||||
|
plotGenerator = generator;
|
||||||
|
plotWorld = plotGenerator.getNewPlotWorld(world);
|
||||||
|
plotManager = plotGenerator.getPlotManager();
|
||||||
|
if (!world.equals("CheckingPlotSquaredGenerator")) {
|
||||||
|
log(C.PREFIX.s() + "&aDetected world load for '" + world + "'");
|
||||||
|
log(C.PREFIX.s() + "&3 - generator: &7" + plotGenerator.getClass().getName());
|
||||||
|
log(C.PREFIX.s() + "&3 - plotworld: &7" + plotWorld.getClass().getName());
|
||||||
|
log(C.PREFIX.s() + "&3 - manager: &7" + plotManager.getClass().getName());
|
||||||
|
}
|
||||||
|
if (!config.contains(path)) {
|
||||||
|
config.createSection(path);
|
||||||
|
}
|
||||||
|
plotWorld.saveConfiguration(config.getConfigurationSection(path));
|
||||||
|
plotWorld.loadDefaultConfiguration(config.getConfigurationSection(path));
|
||||||
|
try {
|
||||||
|
config.save(configFile);
|
||||||
|
} catch (final IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// Now add it
|
||||||
|
addPlotWorld(world, plotWorld, plotManager);
|
||||||
|
MainUtil.setupBorder(world);
|
||||||
|
} else {
|
||||||
|
if (!worlds.contains(world)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!LOADING_WORLD) {
|
||||||
|
LOADING_WORLD = true;
|
||||||
|
try {
|
||||||
|
final String gen_string = config.getString("worlds." + world + "." + "generator.plugin");
|
||||||
|
if (gen_string == null) {
|
||||||
|
new HybridGen(world);
|
||||||
|
} else {
|
||||||
|
IMP.getGenerator(world, gen_string);
|
||||||
|
}
|
||||||
|
} catch (final Exception e) {
|
||||||
|
log("&d=== Oh no! Please set the generator for the " + world + " ===");
|
||||||
|
e.printStackTrace();
|
||||||
|
LOADING_WORLD = false;
|
||||||
|
removePlotWorld(world);
|
||||||
|
} finally {
|
||||||
|
LOADING_WORLD = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
final PlotGenerator gen_class = generator;
|
||||||
|
plotWorld = gen_class.getNewPlotWorld(world);
|
||||||
|
plotManager = gen_class.getPlotManager();
|
||||||
|
if (!config.contains(path)) {
|
||||||
|
config.createSection(path);
|
||||||
|
}
|
||||||
|
plotWorld.TYPE = 2;
|
||||||
|
plotWorld.TERRAIN = 0;
|
||||||
|
plotWorld.saveConfiguration(config.getConfigurationSection(path));
|
||||||
|
plotWorld.loadDefaultConfiguration(config.getConfigurationSection(path));
|
||||||
|
try {
|
||||||
|
config.save(configFile);
|
||||||
|
} catch (final IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (((plotWorld.TYPE == 2) && !Settings.ENABLE_CLUSTERS) || !(plotManager instanceof SquarePlotManager)) {
|
||||||
|
log("&c[ERROR] World '" + world + "' in settings.yml is not using PlotSquared generator! Please set the generator correctly or delete the world from the 'settings.yml'!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
addPlotWorld(world, plotWorld, plotManager);
|
||||||
|
if (plotWorld.TYPE == 2) {
|
||||||
|
if (ClusterManager.getClusters(world).size() > 0) {
|
||||||
|
for (final PlotCluster cluster : ClusterManager.getClusters(world)) {
|
||||||
|
new AugmentedPopulator(world, gen_class, cluster, plotWorld.TERRAIN == 2, plotWorld.TERRAIN != 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (plotWorld.TYPE == 1) {
|
||||||
|
new AugmentedPopulator(world, gen_class, null, plotWorld.TERRAIN == 2, plotWorld.TERRAIN != 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean setupPlotWorld(final String world, final String id) {
|
||||||
|
if ((id != null) && (id.length() > 0)) {
|
||||||
|
// save configuration
|
||||||
|
final String[] split = id.split(",");
|
||||||
|
final HybridPlotWorld plotworld = new HybridPlotWorld(world);
|
||||||
|
final int width = SquarePlotWorld.PLOT_WIDTH_DEFAULT;
|
||||||
|
final int gap = SquarePlotWorld.ROAD_WIDTH_DEFAULT;
|
||||||
|
final int height = ClassicPlotWorld.PLOT_HEIGHT_DEFAULT;
|
||||||
|
final PlotBlock[] floor = ClassicPlotWorld.TOP_BLOCK_DEFAULT;
|
||||||
|
final PlotBlock[] main = ClassicPlotWorld.MAIN_BLOCK_DEFAULT;
|
||||||
|
final PlotBlock wall = ClassicPlotWorld.WALL_FILLING_DEFAULT;
|
||||||
|
final PlotBlock border = ClassicPlotWorld.WALL_BLOCK_DEFAULT;
|
||||||
|
for (final String element : split) {
|
||||||
|
final String[] pair = element.split("=");
|
||||||
|
if (pair.length != 2) {
|
||||||
|
log("&cNo value provided for: &7" + element);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final String key = pair[0].toLowerCase();
|
||||||
|
final String value = pair[1];
|
||||||
|
try {
|
||||||
|
switch (key) {
|
||||||
|
case "s":
|
||||||
|
case "size": {
|
||||||
|
SquarePlotWorld.PLOT_WIDTH_DEFAULT = ((Integer) Configuration.INTEGER.parseString(value)).shortValue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "g":
|
||||||
|
case "gap": {
|
||||||
|
SquarePlotWorld.ROAD_WIDTH_DEFAULT = ((Integer) Configuration.INTEGER.parseString(value)).shortValue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "h":
|
||||||
|
case "height": {
|
||||||
|
ClassicPlotWorld.PLOT_HEIGHT_DEFAULT = (Integer) Configuration.INTEGER.parseString(value);
|
||||||
|
ClassicPlotWorld.ROAD_HEIGHT_DEFAULT = (Integer) Configuration.INTEGER.parseString(value);
|
||||||
|
ClassicPlotWorld.WALL_HEIGHT_DEFAULT = (Integer) Configuration.INTEGER.parseString(value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "f":
|
||||||
|
case "floor": {
|
||||||
|
ClassicPlotWorld.TOP_BLOCK_DEFAULT = (PlotBlock[]) Configuration.BLOCKLIST.parseString(value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "m":
|
||||||
|
case "main": {
|
||||||
|
ClassicPlotWorld.MAIN_BLOCK_DEFAULT = (PlotBlock[]) Configuration.BLOCKLIST.parseString(value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "w":
|
||||||
|
case "wall": {
|
||||||
|
ClassicPlotWorld.WALL_FILLING_DEFAULT = (PlotBlock) Configuration.BLOCK.parseString(value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "b":
|
||||||
|
case "border": {
|
||||||
|
ClassicPlotWorld.WALL_BLOCK_DEFAULT = (PlotBlock) Configuration.BLOCK.parseString(value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
log("&cKey not found: &7" + element);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (final Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
log("&cInvalid value: &7" + value + " in arg " + element);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
final String root = "worlds." + world;
|
||||||
|
if (!config.contains(root)) {
|
||||||
|
config.createSection(root);
|
||||||
|
}
|
||||||
|
plotworld.saveConfiguration(config.getConfigurationSection(root));
|
||||||
|
ClassicPlotWorld.PLOT_HEIGHT_DEFAULT = height;
|
||||||
|
ClassicPlotWorld.ROAD_HEIGHT_DEFAULT = height;
|
||||||
|
ClassicPlotWorld.WALL_HEIGHT_DEFAULT = height;
|
||||||
|
ClassicPlotWorld.TOP_BLOCK_DEFAULT = floor;
|
||||||
|
ClassicPlotWorld.MAIN_BLOCK_DEFAULT = main;
|
||||||
|
ClassicPlotWorld.WALL_BLOCK_DEFAULT = border;
|
||||||
|
ClassicPlotWorld.WALL_FILLING_DEFAULT = wall;
|
||||||
|
SquarePlotWorld.PLOT_WIDTH_DEFAULT = width;
|
||||||
|
SquarePlotWorld.ROAD_WIDTH_DEFAULT = gap;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Connection getConnection() {
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlotSquared(final IPlotMain imp_class) {
|
||||||
|
THIS = this;
|
||||||
|
IMP = imp_class;
|
||||||
|
VERSION = IMP.getVersion();
|
||||||
|
economy = IMP.getEconomy();
|
||||||
|
C.setupTranslations();
|
||||||
|
C.saveTranslations();
|
||||||
|
if (getJavaVersion() < 1.7) {
|
||||||
|
log(C.PREFIX.s() + "&cYour java version is outdated. Please update to at least 1.7.");
|
||||||
|
// Didn't know of any other link :D
|
||||||
|
log(C.PREFIX.s() + "&cURL: &6https://java.com/en/download/index.jsp");
|
||||||
|
IMP.disable();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (getJavaVersion() < 1.8) {
|
||||||
|
log(C.PREFIX.s() + "&cIt's really recommended to run Java 1.8, as it increases performance");
|
||||||
|
}
|
||||||
|
TASK = IMP.getTaskManager();
|
||||||
|
if (Settings.KILL_ROAD_MOBS) {
|
||||||
|
IMP.runEntityTask();
|
||||||
|
}
|
||||||
|
if (C.ENABLED.s().length() > 0) {
|
||||||
|
log(C.ENABLED.s());
|
||||||
|
}
|
||||||
|
setupConfigs();
|
||||||
|
setupDefaultFlags();
|
||||||
|
setupDatabase();
|
||||||
|
// Events
|
||||||
|
IMP.registerCommands();
|
||||||
|
IMP.registerPlayerEvents();
|
||||||
|
IMP.registerInventoryEvents();
|
||||||
|
IMP.registerPlotPlusEvents();
|
||||||
|
IMP.registerForceFieldEvents();
|
||||||
|
IMP.registerWorldEditEvents();
|
||||||
|
// create Hybrid utility class
|
||||||
|
HybridUtils.manager = IMP.initHybridUtils();
|
||||||
|
// create setup util class
|
||||||
|
SetupUtils.manager = IMP.initSetupUtils();
|
||||||
|
// Set block
|
||||||
|
BlockManager.manager = IMP.initBlockManager();
|
||||||
|
// PlotMe
|
||||||
|
TaskManager.runTaskLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (IMP.initPlotMeConverter()) {
|
||||||
|
log("&c=== IMPORTANT ===");
|
||||||
|
log("&cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME!");
|
||||||
|
log("&c - Make sure 'UUID.read-from-disk' is disabled (false)!");
|
||||||
|
log("&c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue!");
|
||||||
|
log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml@'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
|
if (Settings.AUTO_CLEAR) {
|
||||||
|
ExpireManager.runTask();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disable() {
|
||||||
|
try {
|
||||||
|
connection.close();
|
||||||
|
mySQL.closeConnection();
|
||||||
|
} catch (NullPointerException | SQLException e) {
|
||||||
|
if (connection != null) {
|
||||||
|
log("&cCould not close mysql connection!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void log(final String message) {
|
||||||
|
IMP.log(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setupDatabase() {
|
||||||
|
final String[] tables;
|
||||||
|
if (Settings.ENABLE_CLUSTERS) {
|
||||||
|
MainCommand.subCommands.add(new Cluster());
|
||||||
|
tables = new String[] { "plot_trusted", "plot_ratings", "plot_comments", "cluster" };
|
||||||
|
} else {
|
||||||
|
tables = new String[] { "plot_trusted", "plot_ratings", "plot_comments" };
|
||||||
|
}
|
||||||
|
if (Settings.DB.USE_MYSQL) {
|
||||||
|
try {
|
||||||
|
mySQL = new MySQL(THIS, Settings.DB.HOST_NAME, Settings.DB.PORT, Settings.DB.DATABASE, Settings.DB.USER, Settings.DB.PASSWORD);
|
||||||
|
connection = mySQL.openConnection();
|
||||||
|
{
|
||||||
|
if (DBFunc.dbManager == null) {
|
||||||
|
DBFunc.dbManager = new SQLManager(connection, Settings.DB.PREFIX);
|
||||||
|
}
|
||||||
|
final DatabaseMetaData meta = connection.getMetaData();
|
||||||
|
ResultSet res = meta.getTables(null, null, Settings.DB.PREFIX + "plot", null);
|
||||||
|
if (!res.next()) {
|
||||||
|
DBFunc.createTables("mysql", true);
|
||||||
|
} else {
|
||||||
|
for (final String table : tables) {
|
||||||
|
res = meta.getTables(null, null, Settings.DB.PREFIX + table, null);
|
||||||
|
if (!res.next()) {
|
||||||
|
DBFunc.createTables("mysql", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (final Exception e) {
|
||||||
|
log("&c[Plots] MySQL is not setup correctly. The plugin will disable itself.");
|
||||||
|
if ((config == null) || config.getBoolean("debug")) {
|
||||||
|
log("&d==== Here is an ugly stacktrace if you are interested in those things ====");
|
||||||
|
e.printStackTrace();
|
||||||
|
log("&d==== End of stacktrace ====");
|
||||||
|
log("&6Please go to the PlotSquared 'storage.yml' and configure MySQL correctly.");
|
||||||
|
}
|
||||||
|
IMP.disable();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
plots = DBFunc.getPlots();
|
||||||
|
if (Settings.ENABLE_CLUSTERS) {
|
||||||
|
ClusterManager.clusters = DBFunc.getClusters();
|
||||||
|
}
|
||||||
|
} else if (Settings.DB.USE_MONGO) {
|
||||||
|
// DBFunc.dbManager = new MongoManager();
|
||||||
|
log(C.PREFIX.s() + "MongoDB is not yet implemented");
|
||||||
|
} else if (Settings.DB.USE_SQLITE) {
|
||||||
|
try {
|
||||||
|
connection = new SQLite(THIS, IMP.getDirectory() + File.separator + Settings.DB.SQLITE_DB + ".db").openConnection();
|
||||||
|
{
|
||||||
|
DBFunc.dbManager = new SQLManager(connection, Settings.DB.PREFIX);
|
||||||
|
final DatabaseMetaData meta = connection.getMetaData();
|
||||||
|
ResultSet res = meta.getTables(null, null, Settings.DB.PREFIX + "plot", null);
|
||||||
|
if (!res.next()) {
|
||||||
|
DBFunc.createTables("sqlite", true);
|
||||||
|
} else {
|
||||||
|
for (final String table : tables) {
|
||||||
|
res = meta.getTables(null, null, Settings.DB.PREFIX + table, null);
|
||||||
|
if (!res.next()) {
|
||||||
|
DBFunc.createTables("sqlite", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (final Exception e) {
|
||||||
|
log(C.PREFIX.s() + "&cFailed to open SQLite connection. The plugin will disable itself.");
|
||||||
|
log("&9==== Here is an ugly stacktrace, if you are interested in those things ===");
|
||||||
|
e.printStackTrace();
|
||||||
|
IMP.disable();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
plots = DBFunc.getPlots();
|
||||||
|
if (Settings.ENABLE_CLUSTERS) {
|
||||||
|
ClusterManager.clusters = DBFunc.getClusters();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log(C.PREFIX + "&cNo storage type is set!");
|
||||||
|
IMP.disable();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setupDefaultFlags() {
|
||||||
|
final List<String> booleanFlags = Arrays.asList("notify-enter", "notify-leave", "item-drop", "invincible", "instabreak", "drop-protection", "forcefield", "titles", "pve", "pvp", "no-worldedit");
|
||||||
|
final List<String> intervalFlags = Arrays.asList("feed", "heal");
|
||||||
|
final List<String> stringFlags = Arrays.asList("greeting", "farewell");
|
||||||
|
for (final String flag : stringFlags) {
|
||||||
|
FlagManager.addFlag(new AbstractFlag(flag));
|
||||||
|
}
|
||||||
|
for (final String flag : intervalFlags) {
|
||||||
|
FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.IntervalValue()));
|
||||||
|
}
|
||||||
|
for (final String flag : booleanFlags) {
|
||||||
|
FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.BooleanValue()));
|
||||||
|
}
|
||||||
|
FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("hostile-interact", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("hostile-attack", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("animal-interact", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("animal-attack", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("tamed-interact", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("tamed-attack", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("misc-interact", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("hanging-place", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("hanging-break", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("vehicle-use", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("vehicle-place", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("vehicle-break", new FlagValue.BooleanValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("place", new FlagValue.PlotBlockListValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("break", new FlagValue.PlotBlockListValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("use", new FlagValue.PlotBlockListValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("gamemode") {
|
||||||
|
@Override
|
||||||
|
public String parseValueRaw(final String value) {
|
||||||
|
switch (value) {
|
||||||
|
case "creative":
|
||||||
|
case "c":
|
||||||
|
case "1":
|
||||||
|
return "creative";
|
||||||
|
case "survival":
|
||||||
|
case "s":
|
||||||
|
case "0":
|
||||||
|
return "survival";
|
||||||
|
case "adventure":
|
||||||
|
case "a":
|
||||||
|
case "2":
|
||||||
|
return "adventure";
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getValueDesc() {
|
||||||
|
return "Flag value must be a gamemode: 'creative' , 'survival' or 'adventure'";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
FlagManager.addFlag(new AbstractFlag("price", new FlagValue.UnsignedDoubleValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("time", new FlagValue.LongValue()));
|
||||||
|
FlagManager.addFlag(new AbstractFlag("weather") {
|
||||||
|
@Override
|
||||||
|
public String parseValueRaw(final String value) {
|
||||||
|
switch (value) {
|
||||||
|
case "rain":
|
||||||
|
case "storm":
|
||||||
|
case "on":
|
||||||
|
return "rain";
|
||||||
|
case "clear":
|
||||||
|
case "off":
|
||||||
|
case "sun":
|
||||||
|
return "clear";
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getValueDesc() {
|
||||||
|
return "Flag value must be weather type: 'clear' or 'rain'";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setupConfig() {
|
||||||
|
config.set("version", VERSION);
|
||||||
|
final Map<String, Object> options = new HashMap<>();
|
||||||
|
options.put("teleport.delay", 0);
|
||||||
|
options.put("auto_update", false);
|
||||||
|
options.put("clusters.enabled", Settings.ENABLE_CLUSTERS);
|
||||||
|
options.put("plotme-alias", Settings.USE_PLOTME_ALIAS);
|
||||||
|
options.put("plotme-convert.enabled", Settings.CONVERT_PLOTME);
|
||||||
|
options.put("claim.max-auto-area", Settings.MAX_AUTO_SIZE);
|
||||||
|
options.put("UUID.offline", Settings.OFFLINE_MODE);
|
||||||
|
options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT);
|
||||||
|
options.put("mob_pathfinding", Settings.MOB_PATHFINDING_DEFAULT);
|
||||||
|
options.put("console.color", Settings.CONSOLE_COLOR);
|
||||||
|
options.put("metrics", true);
|
||||||
|
options.put("debug", true);
|
||||||
|
options.put("clear.auto.enabled", false);
|
||||||
|
options.put("clear.auto.days", 365);
|
||||||
|
options.put("clear.check-disk", Settings.AUTO_CLEAR_CHECK_DISK);
|
||||||
|
options.put("clear.on.ban", false);
|
||||||
|
options.put("max_plots", Settings.MAX_PLOTS);
|
||||||
|
options.put("schematics.save_path", Settings.SCHEMATIC_SAVE_PATH);
|
||||||
|
options.put("uuid.read-from-disk", Settings.UUID_FROM_DISK);
|
||||||
|
options.put("titles", Settings.TITLES);
|
||||||
|
options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN);
|
||||||
|
options.put("worldedit.require-selection-in-mask", Settings.REQUIRE_SELECTION);
|
||||||
|
for (final Entry<String, Object> node : options.entrySet()) {
|
||||||
|
if (!config.contains(node.getKey())) {
|
||||||
|
config.set(node.getKey(), node.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Settings.ENABLE_CLUSTERS = config.getBoolean("clusters.enabled");
|
||||||
|
Settings.DEBUG = config.getBoolean("debug");
|
||||||
|
if (Settings.DEBUG) {
|
||||||
|
log(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off.");
|
||||||
|
}
|
||||||
|
Settings.TELEPORT_DELAY = config.getInt("teleport.delay");
|
||||||
|
Settings.CONSOLE_COLOR = config.getBoolean("console.color");
|
||||||
|
Settings.TELEPORT_ON_LOGIN = config.getBoolean("teleport.on_login");
|
||||||
|
Settings.USE_PLOTME_ALIAS = config.getBoolean("plotme-alias");
|
||||||
|
Settings.CONVERT_PLOTME = config.getBoolean("plotme-convert.enabled");
|
||||||
|
Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs");
|
||||||
|
Settings.MOB_PATHFINDING = config.getBoolean("mob_pathf" + "inding");
|
||||||
|
Settings.METRICS = config.getBoolean("metrics");
|
||||||
|
Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days");
|
||||||
|
Settings.AUTO_CLEAR_CHECK_DISK = config.getBoolean("clear.check-disk");
|
||||||
|
Settings.MAX_AUTO_SIZE = config.getInt("claim.max-auto-area");
|
||||||
|
Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled");
|
||||||
|
Settings.TITLES = config.getBoolean("titles");
|
||||||
|
Settings.MAX_PLOTS = config.getInt("max_plots");
|
||||||
|
if (Settings.MAX_PLOTS > 32767) {
|
||||||
|
log("&c`max_plots` Is set too high! This is a per player setting and does not need to be very large.");
|
||||||
|
Settings.MAX_PLOTS = 32767;
|
||||||
|
}
|
||||||
|
Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path");
|
||||||
|
Settings.OFFLINE_MODE = config.getBoolean("UUID.offline");
|
||||||
|
Settings.UUID_FROM_DISK = config.getBoolean("uuid.read-from-disk");
|
||||||
|
Settings.REQUIRE_SELECTION = config.getBoolean("worldedit.require-selection-in-mask");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setupConfigs() {
|
||||||
|
final File folder = new File(IMP.getDirectory() + File.separator + "config");
|
||||||
|
if (!folder.exists() && !folder.mkdirs()) {
|
||||||
|
log(C.PREFIX.s() + "&cFailed to create the /plugins/config folder. Please create it manually.");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
styleFile = new File(IMP.getDirectory() + File.separator + "translations" + File.separator + "style.yml");
|
||||||
|
if (!styleFile.exists()) {
|
||||||
|
if (!styleFile.createNewFile()) {
|
||||||
|
log("Could not create the style file, please create \"translations/style.yml\" manually");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
style = YamlConfiguration.loadConfiguration(styleFile);
|
||||||
|
setupStyle();
|
||||||
|
} catch (final Exception err) {
|
||||||
|
Logger.add(LogLevel.DANGER, "Failed to save style.yml");
|
||||||
|
System.out.println("failed to save style.yml");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
configFile = new File(IMP.getDirectory() + File.separator + "config" + File.separator + "settings.yml");
|
||||||
|
if (!configFile.exists()) {
|
||||||
|
if (!configFile.createNewFile()) {
|
||||||
|
log("Could not create the settings file, please create \"settings.yml\" manually.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
setupConfig();
|
||||||
|
} catch (final Exception err_trans) {
|
||||||
|
Logger.add(LogLevel.DANGER, "Failed to save settings.yml");
|
||||||
|
System.out.println("Failed to save settings.yml");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
storageFile = new File(IMP.getDirectory() + File.separator + "config" + File.separator + "storage.yml");
|
||||||
|
if (!storageFile.exists()) {
|
||||||
|
if (!storageFile.createNewFile()) {
|
||||||
|
log("Could not the storage settings file, please create \"storage.yml\" manually.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
storage = YamlConfiguration.loadConfiguration(storageFile);
|
||||||
|
setupStorage();
|
||||||
|
} catch (final Exception err_trans) {
|
||||||
|
Logger.add(LogLevel.DANGER, "Failed to save storage.yml");
|
||||||
|
System.out.println("Failed to save storage.yml");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
style.save(styleFile);
|
||||||
|
config.save(configFile);
|
||||||
|
storage.save(storageFile);
|
||||||
|
} catch (final IOException e) {
|
||||||
|
Logger.add(LogLevel.DANGER, "Configuration file saving failed");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setupStorage() {
|
||||||
|
storage.set("version", VERSION);
|
||||||
|
final Map<String, Object> options = new HashMap<>();
|
||||||
|
options.put("mysql.use", false);
|
||||||
|
options.put("sqlite.use", true);
|
||||||
|
options.put("sqlite.db", "storage");
|
||||||
|
options.put("mysql.host", "localhost");
|
||||||
|
options.put("mysql.port", "3306");
|
||||||
|
options.put("mysql.user", "root");
|
||||||
|
options.put("mysql.password", "password");
|
||||||
|
options.put("mysql.database", "plot_db");
|
||||||
|
options.put("prefix", "");
|
||||||
|
for (final Entry<String, Object> node : options.entrySet()) {
|
||||||
|
if (!storage.contains(node.getKey())) {
|
||||||
|
storage.set(node.getKey(), node.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showDebug() {
|
||||||
|
Settings.DB.USE_MYSQL = storage.getBoolean("mysql.use");
|
||||||
|
Settings.DB.USER = storage.getString("mysql.user");
|
||||||
|
Settings.DB.PASSWORD = storage.getString("mysql.password");
|
||||||
|
Settings.DB.HOST_NAME = storage.getString("mysql.host");
|
||||||
|
Settings.DB.PORT = storage.getString("mysql.port");
|
||||||
|
Settings.DB.DATABASE = storage.getString("mysql.database");
|
||||||
|
Settings.DB.USE_SQLITE = storage.getBoolean("sqlite.use");
|
||||||
|
Settings.DB.SQLITE_DB = storage.getString("sqlite.db");
|
||||||
|
Settings.DB.PREFIX = storage.getString("prefix");
|
||||||
|
Settings.METRICS = config.getBoolean("metrics");
|
||||||
|
Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled");
|
||||||
|
Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days");
|
||||||
|
Settings.DELETE_PLOTS_ON_BAN = config.getBoolean("clear.on.ban");
|
||||||
|
Settings.API_URL = config.getString("uuid.api.location");
|
||||||
|
Settings.CUSTOM_API = config.getBoolean("uuid.api.custom");
|
||||||
|
Settings.UUID_FECTHING = config.getBoolean("uuid.fetching");
|
||||||
|
C.COLOR_1 = "\u00A7" + (style.getString("color.1"));
|
||||||
|
C.COLOR_2 = "\u00A7" + (style.getString("color.2"));
|
||||||
|
C.COLOR_3 = "\u00A7" + (style.getString("color.3"));
|
||||||
|
C.COLOR_4 = "\u00A7" + (style.getString("color.4"));
|
||||||
|
if (Settings.DEBUG) {
|
||||||
|
final Map<String, String> settings = new HashMap<>();
|
||||||
|
settings.put("Kill Road Mobs", "" + Settings.KILL_ROAD_MOBS);
|
||||||
|
settings.put("Use Metrics", "" + Settings.METRICS);
|
||||||
|
settings.put("Delete Plots On Ban", "" + Settings.DELETE_PLOTS_ON_BAN);
|
||||||
|
settings.put("Mob Pathfinding", "" + Settings.MOB_PATHFINDING);
|
||||||
|
settings.put("DB Mysql Enabled", "" + Settings.DB.USE_MYSQL);
|
||||||
|
settings.put("DB SQLite Enabled", "" + Settings.DB.USE_SQLITE);
|
||||||
|
settings.put("Auto Clear Enabled", "" + Settings.AUTO_CLEAR);
|
||||||
|
settings.put("Auto Clear Days", "" + Settings.AUTO_CLEAR_DAYS);
|
||||||
|
settings.put("Schematics Save Path", "" + Settings.SCHEMATIC_SAVE_PATH);
|
||||||
|
settings.put("API Location", "" + Settings.API_URL);
|
||||||
|
for (final Entry<String, String> setting : settings.entrySet()) {
|
||||||
|
log(C.PREFIX.s() + String.format("&cKey: &6%s&c, Value: &6%s", setting.getKey(), setting.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setupStyle() {
|
||||||
|
style.set("version", VERSION);
|
||||||
|
final Map<String, Object> o = new HashMap<>();
|
||||||
|
o.put("color.1", C.COLOR_1.substring(1));
|
||||||
|
o.put("color.2", C.COLOR_2.substring(1));
|
||||||
|
o.put("color.3", C.COLOR_3.substring(1));
|
||||||
|
o.put("color.4", C.COLOR_4.substring(1));
|
||||||
|
for (final Entry<String, Object> node : o.entrySet()) {
|
||||||
|
if (!style.contains(node.getKey())) {
|
||||||
|
style.set(node.getKey(), node.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getJavaVersion() {
|
||||||
|
return Double.parseDouble(System.getProperty("java.specification.version"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<String> getPlotWorlds() {
|
||||||
|
return plotworlds.keySet();
|
||||||
|
}
|
||||||
|
}
|
@ -1,651 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 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.api;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
|
||||||
import com.intellectualcrafters.plot.commands.SubCommand;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
|
||||||
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotManager;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
|
||||||
import com.intellectualcrafters.plot.util.PlotSquaredException;
|
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PlotSquared API
|
|
||||||
*
|
|
||||||
* @author Citymonstret
|
|
||||||
* @author Empire92
|
|
||||||
* @version API 2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
@SuppressWarnings("unused") public class PlotAPI {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Permission that allows for admin access, this permission node will allow the player to use any part of the
|
|
||||||
* plugin, without limitations.
|
|
||||||
*/
|
|
||||||
public static final String ADMIN_PERMISSION = "plots.admin";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plot Helper Class
|
|
||||||
* <p/>
|
|
||||||
* General functions involving plots, and the management of them
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlotHelper
|
|
||||||
*/
|
|
||||||
private static PlotHelper plotHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Player Functions
|
|
||||||
* <p/>
|
|
||||||
* General functions involving players, and plot worlds
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions
|
|
||||||
*/
|
|
||||||
private static PlayerFunctions playerFunctions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag Manager
|
|
||||||
* <p/>
|
|
||||||
* The manager which handles all flags
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.flag.FlagManager
|
|
||||||
*/
|
|
||||||
private static FlagManager flagManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Schematic Handler
|
|
||||||
* <p/>
|
|
||||||
* The handler which is used to create, and paste, schematics
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.SchematicHandler
|
|
||||||
*/
|
|
||||||
private static SchematicHandler schematicHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The translation class.
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.config.C
|
|
||||||
*/
|
|
||||||
private static C c;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PlotMain instance
|
|
||||||
* <p/>
|
|
||||||
* This is the instance that allows for most methods to be used.
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.PlotMain
|
|
||||||
*/
|
|
||||||
private final PlotMain plotMain;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor. Insert any Plugin. (Optimally the plugin that is accessing the method)
|
|
||||||
*
|
|
||||||
* @param plugin Plugin used to access this method
|
|
||||||
*
|
|
||||||
* @throws com.intellectualcrafters.plot.util.PlotSquaredException if the program fails to fetch the PlotMain
|
|
||||||
* instance
|
|
||||||
* @see com.intellectualcrafters.plot.PlotMain
|
|
||||||
*/
|
|
||||||
public PlotAPI(final JavaPlugin plugin) {
|
|
||||||
this.plotMain = PlotMain.getMain();
|
|
||||||
if (this.plotMain == null) {
|
|
||||||
throw new PlotSquaredException(PlotSquaredException.PlotError.PLOTMAIN_NULL, "Failed to fetch the plotmain instance, Plot API for " + plugin.getName() + " will be disabled");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all plots
|
|
||||||
*
|
|
||||||
* @return all plots
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.PlotMain#getPlots()
|
|
||||||
*/
|
|
||||||
public Set<Plot> getAllPlots() {
|
|
||||||
return PlotMain.getPlots();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return all plots for a player
|
|
||||||
*
|
|
||||||
* @param player Player, whose plots to search for
|
|
||||||
*
|
|
||||||
* @return all plots that a player owns
|
|
||||||
*/
|
|
||||||
public Set<Plot> getPlayerPlots(final Player player) {
|
|
||||||
return PlotMain.getPlots(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a plot world
|
|
||||||
*
|
|
||||||
* @param world World Name
|
|
||||||
* @param plotWorld Plot World Object
|
|
||||||
* @param manager World Manager
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.PlotMain#addPlotWorld(String, com.intellectualcrafters.plot.object.PlotWorld,
|
|
||||||
* com.intellectualcrafters.plot.object.PlotManager)
|
|
||||||
*/
|
|
||||||
public void addPlotWorld(final String world, final PlotWorld plotWorld, final PlotManager manager) {
|
|
||||||
PlotMain.addPlotWorld(world, plotWorld, manager);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return main configuration
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.PlotMain#config
|
|
||||||
*/
|
|
||||||
public YamlConfiguration getConfig() {
|
|
||||||
return PlotMain.config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return storage configuration
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.PlotMain#storage
|
|
||||||
*/
|
|
||||||
public YamlConfiguration getStorage() {
|
|
||||||
return PlotMain.storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the main class for this plugin <br> - Contains a lot of fields and methods - not very well organized <br>
|
|
||||||
* Only use this if you really need it
|
|
||||||
*
|
|
||||||
* @return PlotMain PlotSquared Main Class
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.PlotMain
|
|
||||||
*/
|
|
||||||
public PlotMain getMain() {
|
|
||||||
return this.plotMain;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PlotHelper class contains useful methods relating to plots.
|
|
||||||
*
|
|
||||||
* @return PlotHelper
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlotHelper
|
|
||||||
*/
|
|
||||||
public PlotHelper getPlotHelper() {
|
|
||||||
return plotHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PlayerFunctions class contains useful methods relating to players - Some player/plot methods are here as well
|
|
||||||
*
|
|
||||||
* @return PlayerFunctions
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions
|
|
||||||
*/
|
|
||||||
public PlayerFunctions getPlayerFunctions() {
|
|
||||||
return playerFunctions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FlagManager class contains methods relating to plot flags
|
|
||||||
*
|
|
||||||
* @return FlagManager
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.flag.FlagManager
|
|
||||||
*/
|
|
||||||
public FlagManager getFlagManager() {
|
|
||||||
return flagManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SchematicHandler class contains methods related to pasting schematics
|
|
||||||
*
|
|
||||||
* @return SchematicHandler
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.SchematicHandler
|
|
||||||
*/
|
|
||||||
public SchematicHandler getSchematicHandler() {
|
|
||||||
return schematicHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* C class contains all the captions from the translations.yml file.
|
|
||||||
*
|
|
||||||
* @return C
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.config.C
|
|
||||||
*/
|
|
||||||
public C getCaptions() {
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the plot manager for a world. - Most of these methods can be accessed through the PlotHelper
|
|
||||||
*
|
|
||||||
* @param world Which manager to get
|
|
||||||
*
|
|
||||||
* @return PlotManager
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.object.PlotManager
|
|
||||||
* @see PlotMain#getPlotManager(org.bukkit.World)
|
|
||||||
*/
|
|
||||||
public PlotManager getPlotManager(final World world) {
|
|
||||||
return PlotMain.getPlotManager(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the plot manager for a world. - Contains useful low level methods for plot merging, clearing, and
|
|
||||||
* tessellation
|
|
||||||
*
|
|
||||||
* @param world Plot World
|
|
||||||
*
|
|
||||||
* @return PlotManager
|
|
||||||
*
|
|
||||||
* @see PlotMain#getPlotManager(String)
|
|
||||||
* @see com.intellectualcrafters.plot.object.PlotManager
|
|
||||||
*/
|
|
||||||
public PlotManager getPlotManager(final String world) {
|
|
||||||
return PlotMain.getPlotManager(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the settings for a world (settings bundled in PlotWorld class) - You will need to downcast for the specific
|
|
||||||
* settings a Generator has. e.g. DefaultPlotWorld class implements PlotWorld
|
|
||||||
*
|
|
||||||
* @param world (to get settings of)
|
|
||||||
*
|
|
||||||
* @return PlotWorld class for that world ! will return null if not a plot world world
|
|
||||||
*
|
|
||||||
* @see PlotMain#getWorldSettings(org.bukkit.World)
|
|
||||||
* @see com.intellectualcrafters.plot.object.PlotWorld
|
|
||||||
*/
|
|
||||||
public PlotWorld getWorldSettings(final World world) {
|
|
||||||
return PlotMain.getWorldSettings(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the settings for a world (settings bundled in PlotWorld class)
|
|
||||||
*
|
|
||||||
* @param world (to get settings of)
|
|
||||||
*
|
|
||||||
* @return PlotWorld class for that world ! will return null if not a plot world world
|
|
||||||
*
|
|
||||||
* @see PlotMain#getWorldSettings(String)
|
|
||||||
* @see com.intellectualcrafters.plot.object.PlotWorld
|
|
||||||
*/
|
|
||||||
public PlotWorld getWorldSettings(final String world) {
|
|
||||||
return PlotMain.getWorldSettings(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a message to a player.
|
|
||||||
*
|
|
||||||
* @param player Player that will receive the message
|
|
||||||
* @param c (Caption)
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player,
|
|
||||||
* com.intellectualcrafters.plot.config.C, String...)
|
|
||||||
*/
|
|
||||||
public void sendMessage(final Player player, final C c) {
|
|
||||||
PlayerFunctions.sendMessage(player, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a message to a player. - Supports color codes
|
|
||||||
*
|
|
||||||
* @param player Player that will receive the message
|
|
||||||
* @param string The message
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player, String)
|
|
||||||
*/
|
|
||||||
public void sendMessage(final Player player, final String string) {
|
|
||||||
PlayerFunctions.sendMessage(player, string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a message to the console. - Supports color codes
|
|
||||||
*
|
|
||||||
* @param msg Message that should be sent to the console
|
|
||||||
*
|
|
||||||
* @see PlotMain#sendConsoleSenderMessage(String)
|
|
||||||
*/
|
|
||||||
public void sendConsoleMessage(final String msg) {
|
|
||||||
PlotMain.sendConsoleSenderMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a message to the console
|
|
||||||
*
|
|
||||||
* @param c (Caption)
|
|
||||||
*
|
|
||||||
* @see #sendConsoleMessage(String)
|
|
||||||
* @see com.intellectualcrafters.plot.config.C
|
|
||||||
*/
|
|
||||||
public void sendConsoleMessage(final C c) {
|
|
||||||
sendConsoleMessage(c.s());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a flag for use in plots
|
|
||||||
*
|
|
||||||
* @param flag Flag that should be registered
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag)
|
|
||||||
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
|
||||||
*/
|
|
||||||
public void addFlag(final AbstractFlag flag) {
|
|
||||||
FlagManager.addFlag(flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get all the currently registered flags
|
|
||||||
*
|
|
||||||
* @return array of Flag[]
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.flag.FlagManager#getFlags()
|
|
||||||
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
|
||||||
*/
|
|
||||||
public AbstractFlag[] getFlags() {
|
|
||||||
return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a plot based on the ID
|
|
||||||
*
|
|
||||||
* @param world World in which the plot is located
|
|
||||||
* @param x Plot Location X Co-ord
|
|
||||||
* @param z Plot Location Z Co-ord
|
|
||||||
*
|
|
||||||
* @return plot, null if ID is wrong
|
|
||||||
*
|
|
||||||
* @see PlotHelper#getPlot(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId)
|
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
|
||||||
*/
|
|
||||||
public Plot getPlot(final World world, final int x, final int z) {
|
|
||||||
return PlotHelper.getPlot(world, new PlotId(x, z));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a plot based on the location
|
|
||||||
*
|
|
||||||
* @param l The location that you want to to retrieve the plot from
|
|
||||||
*
|
|
||||||
* @return plot if found, otherwise it creates a temporary plot-
|
|
||||||
*
|
|
||||||
* @see PlotHelper#getCurrentPlot(org.bukkit.Location)
|
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
|
||||||
*/
|
|
||||||
public Plot getPlot(final Location l) {
|
|
||||||
return PlotHelper.getCurrentPlot(l);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a plot based on the player location
|
|
||||||
*
|
|
||||||
* @param player Get the current plot for the player location
|
|
||||||
*
|
|
||||||
* @return plot if found, otherwise it creates a temporary plot
|
|
||||||
*
|
|
||||||
* @see #getPlot(org.bukkit.Location)
|
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
|
||||||
*/
|
|
||||||
public Plot getPlot(final Player player) {
|
|
||||||
return this.getPlot(player.getLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether or not a player has a plot
|
|
||||||
*
|
|
||||||
* @param player Player that you want to check for
|
|
||||||
*
|
|
||||||
* @return true if player has a plot, false if not.
|
|
||||||
*
|
|
||||||
* @see #getPlots(org.bukkit.World, org.bukkit.entity.Player, boolean)
|
|
||||||
*/
|
|
||||||
public boolean hasPlot(final World world, final Player player) {
|
|
||||||
return (getPlots(world, player, true) != null) && (getPlots(world, player, true).length > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all plots for the player
|
|
||||||
*
|
|
||||||
* @param plr to search for
|
|
||||||
* @param just_owner should we just search for owner? Or with rights?
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
|
||||||
*/
|
|
||||||
public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) {
|
|
||||||
final ArrayList<Plot> pPlots = new ArrayList<>();
|
|
||||||
for (final Plot plot : PlotMain.getPlots(world).values()) {
|
|
||||||
if (just_owner) {
|
|
||||||
if ((plot.owner != null) && (plot.owner == UUIDHandler.getUUID(plr))) {
|
|
||||||
pPlots.add(plot);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (plot.hasRights(plr)) {
|
|
||||||
pPlots.add(plot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pPlots.toArray(new Plot[pPlots.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all plots for the world
|
|
||||||
*
|
|
||||||
* @param world to get plots of
|
|
||||||
*
|
|
||||||
* @return Plot[] - array of plot objects in world
|
|
||||||
*
|
|
||||||
* @see PlotMain#getWorldPlots(org.bukkit.World)
|
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
|
||||||
*/
|
|
||||||
public Plot[] getPlots(final World world) {
|
|
||||||
return PlotMain.getWorldPlots(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all plot worlds
|
|
||||||
*
|
|
||||||
* @return World[] - array of plot worlds
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.PlotMain#getPlotWorlds()
|
|
||||||
*/
|
|
||||||
public String[] getPlotWorlds() {
|
|
||||||
return PlotMain.getPlotWorlds();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get if plot world
|
|
||||||
*
|
|
||||||
* @param world (to check if plot world)
|
|
||||||
*
|
|
||||||
* @return boolean (if plot world or not)
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.PlotMain#isPlotWorld(org.bukkit.World)
|
|
||||||
*/
|
|
||||||
public boolean isPlotWorld(final World world) {
|
|
||||||
return PlotMain.isPlotWorld(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get plot locations
|
|
||||||
*
|
|
||||||
* @param p Plot that you want to get the locations for
|
|
||||||
*
|
|
||||||
* @return [0] = bottomLc, [1] = topLoc, [2] = home
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotBottomLoc(org.bukkit.World,
|
|
||||||
* com.intellectualcrafters.plot.object.PlotId)
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotTopLoc(org.bukkit.World,
|
|
||||||
* com.intellectualcrafters.plot.object.PlotId)
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World,
|
|
||||||
* com.intellectualcrafters.plot.object.Plot)
|
|
||||||
* @see com.intellectualcrafters.plot.object.PlotHomePosition
|
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
|
||||||
*/
|
|
||||||
public Location[] getLocations(final Plot p) {
|
|
||||||
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)};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get home location
|
|
||||||
*
|
|
||||||
* @param p Plot that you want to get the location for
|
|
||||||
*
|
|
||||||
* @return plot bottom location
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World,
|
|
||||||
* com.intellectualcrafters.plot.object.Plot)
|
|
||||||
* @see com.intellectualcrafters.plot.object.PlotHomePosition
|
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
|
||||||
*/
|
|
||||||
public Location getHomeLocation(final Plot p) {
|
|
||||||
return PlotHelper.getPlotHome(p.getWorld(), p.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Bottom Location (min, min, min)
|
|
||||||
*
|
|
||||||
* @param p Plot that you want to get the location for
|
|
||||||
*
|
|
||||||
* @return plot bottom location
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotBottomLoc(org.bukkit.World,
|
|
||||||
* com.intellectualcrafters.plot.object.PlotId)
|
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
|
||||||
*/
|
|
||||||
public Location getBottomLocation(final Plot p) {
|
|
||||||
final World world = Bukkit.getWorld(p.world);
|
|
||||||
return PlotHelper.getPlotBottomLoc(world, p.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Top Location (max, max, max)
|
|
||||||
*
|
|
||||||
* @param p Plot that you want to get the location for
|
|
||||||
*
|
|
||||||
* @return plot top location
|
|
||||||
*
|
|
||||||
* @see PlotHelper#getPlotTopLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId)
|
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
|
||||||
*/
|
|
||||||
public Location getTopLocation(final Plot p) {
|
|
||||||
final World world = Bukkit.getWorld(p.world);
|
|
||||||
return PlotHelper.getPlotTopLoc(world, p.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether or not a player is in a plot
|
|
||||||
*
|
|
||||||
* @param player who we're checking for
|
|
||||||
*
|
|
||||||
* @return true if the player is in a plot, false if not-
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#isInPlot(org.bukkit.entity.Player)
|
|
||||||
*/
|
|
||||||
public boolean isInPlot(final Player player) {
|
|
||||||
return PlayerFunctions.isInPlot(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a subcommand
|
|
||||||
*
|
|
||||||
* @param c SubCommand, that we want to register
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.commands.MainCommand#subCommands
|
|
||||||
* @see com.intellectualcrafters.plot.commands.SubCommand
|
|
||||||
*/
|
|
||||||
public void registerCommand(final SubCommand c) {
|
|
||||||
MainCommand.subCommands.add(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the plotMain class
|
|
||||||
*
|
|
||||||
* @return PlotMain Class
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.PlotMain
|
|
||||||
*/
|
|
||||||
public PlotMain getPlotMain() {
|
|
||||||
return this.plotMain;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the player plot count
|
|
||||||
*
|
|
||||||
* @param world Specify the world we want to select the plots from
|
|
||||||
* @param player Player, for whom we're getting the plot count
|
|
||||||
*
|
|
||||||
* @return the number of plots the player has
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#getPlayerPlotCount(org.bukkit.World,
|
|
||||||
* org.bukkit.entity.Player)
|
|
||||||
*/
|
|
||||||
public int getPlayerPlotCount(final World world, final Player player) {
|
|
||||||
return PlayerFunctions.getPlayerPlotCount(world, player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a collection containing the players plots
|
|
||||||
*
|
|
||||||
* @param world Specify the world we want to select the plots from
|
|
||||||
* @param player Player, for whom we're getting the plots
|
|
||||||
*
|
|
||||||
* @return a set containing the players plots
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#getPlayerPlots(org.bukkit.World,
|
|
||||||
* org.bukkit.entity.Player)
|
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
|
||||||
*/
|
|
||||||
public Set<Plot> getPlayerPlots(final World world, final Player player) {
|
|
||||||
return PlayerFunctions.getPlayerPlots(world, player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the numbers of plots, which the player is able to build in
|
|
||||||
*
|
|
||||||
* @param player Player, for whom we're getting the plots (trusted, helper and owner)
|
|
||||||
*
|
|
||||||
* @return the number of allowed plots
|
|
||||||
*
|
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#getAllowedPlots(org.bukkit.entity.Player)
|
|
||||||
*/
|
|
||||||
public int getAllowedPlots(final Player player) {
|
|
||||||
return PlayerFunctions.getAllowedPlots(player);
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,32 +18,29 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// 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 net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.EconHandler;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
|
||||||
public class Auto extends SubCommand {
|
public class Auto extends SubCommand {
|
||||||
public Auto() {
|
public Auto() {
|
||||||
super("auto", "plots.auto", "Claim the nearest plot", "auto", "a", CommandCategory.CLAIMING, true);
|
super("auto", "plots.auto", "Claim the nearest plot", "auto", "a", CommandCategory.CLAIMING, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlotId getNextPlot(final PlotId id, final int step) {
|
public static PlotId getNextPlot(final PlotId id, final int step) {
|
||||||
final int absX = Math.abs(id.x);
|
final int absX = Math.abs(id.x);
|
||||||
final int absY = Math.abs(id.y);
|
final int absY = Math.abs(id.y);
|
||||||
@ -72,35 +69,34 @@ public class Auto extends SubCommand {
|
|||||||
return new PlotId(id.x + 1, id.y);
|
return new PlotId(id.x + 1, id.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO auto claim a mega plot with schematic
|
// TODO auto claim a mega plot with schematic
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
World world;
|
String world;
|
||||||
int size_x = 1;
|
int size_x = 1;
|
||||||
int size_z = 1;
|
int size_z = 1;
|
||||||
String schematic = "";
|
String schematic = "";
|
||||||
if (PlotMain.getPlotWorlds().length == 1) {
|
if (PlotSquared.getPlotWorlds().size() == 1) {
|
||||||
world = Bukkit.getWorld(PlotMain.getPlotWorlds()[0]);
|
world = PlotSquared.getPlotWorlds().iterator().next();
|
||||||
} else {
|
} else {
|
||||||
if (PlotMain.isPlotWorld(plr.getWorld())) {
|
world = plr.getLocation().getWorld();
|
||||||
world = plr.getWorld();
|
if (!PlotSquared.isPlotWorld(world)) {
|
||||||
} else {
|
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
if (PlotMain.hasPermission(plr, "plots.auto.mega")) {
|
if (Permissions.hasPermission(plr, "plots.auto.mega")) {
|
||||||
try {
|
try {
|
||||||
final String[] split = args[0].split(",");
|
final String[] split = args[0].split(",");
|
||||||
size_x = Integer.parseInt(split[0]);
|
size_x = Integer.parseInt(split[0]);
|
||||||
size_z = Integer.parseInt(split[1]);
|
size_z = Integer.parseInt(split[1]);
|
||||||
if ((size_x < 1) || (size_z < 1)) {
|
if ((size_x < 1) || (size_z < 1)) {
|
||||||
PlayerFunctions.sendMessage(plr, "&cError: size<=0");
|
MainUtil.sendMessage(plr, "&cError: size<=0");
|
||||||
}
|
}
|
||||||
if ((size_x > 4) || (size_z > 4)) {
|
if ((size_x > 4) || (size_z > 4)) {
|
||||||
PlayerFunctions.sendMessage(plr, "&cError: size>4");
|
MainUtil.sendMessage(plr, "&cError: size>4");
|
||||||
}
|
}
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
schematic = args[1];
|
schematic = args[1];
|
||||||
@ -119,31 +115,31 @@ public class Auto extends SubCommand {
|
|||||||
// return false;
|
// return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((size_x * size_z) > Settings.MAX_AUTO_SIZE) {
|
if ((size_x * size_z) > Settings.MAX_AUTO_SIZE) {
|
||||||
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + "");
|
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final int diff = PlayerFunctions.getPlayerPlotCount(world, plr) - PlayerFunctions.getAllowedPlots(plr);
|
int currentPlots = MainUtil.getPlayerPlotCount(world, plr);
|
||||||
|
final int diff = currentPlots - MainUtil.getAllowedPlots(plr, currentPlots);
|
||||||
if ((diff + (size_x * size_z)) > 0) {
|
if ((diff + (size_x * size_z)) > 0) {
|
||||||
if (diff < 0) {
|
if (diff < 0) {
|
||||||
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + "");
|
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + "");
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlotWorld pWorld = PlotMain.getWorldSettings(world);
|
final PlotWorld pWorld = PlotSquared.getPlotWorld(world);
|
||||||
if (PlotMain.useEconomy && pWorld.USE_ECONOMY) {
|
if ((PlotSquared.economy != null) && pWorld.USE_ECONOMY) {
|
||||||
double cost = pWorld.PLOT_PRICE;
|
double cost = pWorld.PLOT_PRICE;
|
||||||
cost = (size_x * size_z) * cost;
|
cost = (size_x * size_z) * cost;
|
||||||
if (cost > 0d) {
|
if (cost > 0d) {
|
||||||
final Economy economy = PlotMain.economy;
|
final Economy economy = PlotSquared.economy;
|
||||||
if (economy.getBalance(plr) < cost) {
|
if (economy.getBalance(plr.getName()) < cost) {
|
||||||
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
economy.withdrawPlayer(plr, cost);
|
EconHandler.withdrawPlayer(plr, cost);
|
||||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,97 +149,93 @@ public class Auto extends SubCommand {
|
|||||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!PlotMain.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin.command.schematic")) {
|
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin.command.schematic")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
MainUtil.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
final String worldname = world;
|
||||||
PlotWorld plotworld = PlotMain.getWorldSettings(world);
|
final PlotWorld plotworld = PlotSquared.getPlotWorld(worldname);
|
||||||
if (plotworld.TYPE == 2) {
|
if (plotworld.TYPE == 2) {
|
||||||
Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
Plot plot = PlotHelper.getCurrentPlot(loc);
|
final Plot plot = MainUtil.getPlot(new Location(worldname, loc.getX(), loc.getY(), loc.getZ()));
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
PlotCluster cluster = ClusterManager.getCluster(loc);
|
final PlotCluster cluster = ClusterManager.getCluster(loc);
|
||||||
// Must be standing in a cluster
|
// Must be standing in a cluster
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotId bot = cluster.getP1();
|
final PlotId bot = cluster.getP1();
|
||||||
PlotId top = cluster.getP2();
|
final PlotId top = cluster.getP2();
|
||||||
PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
|
final PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
|
||||||
PlotId id = new PlotId(0, 0);
|
PlotId id = new PlotId(0, 0);
|
||||||
int width = Math.max(top.x - bot.x + 1, top.y - bot.y + 1);
|
final int width = Math.max((top.x - bot.x) + 1, (top.y - bot.y) + 1);
|
||||||
int max = width * width;
|
final int max = width * width;
|
||||||
//
|
//
|
||||||
for (int i = 0; i <= max; i++) {
|
for (int i = 0; i <= max; i++) {
|
||||||
PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y);
|
final PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y);
|
||||||
Plot current = PlotHelper.getPlot(world, currentId);
|
final Plot current = MainUtil.getPlot(worldname, currentId);
|
||||||
if (current != null && (current.hasOwner() == false) && (current.settings.isMerged() == false) && cluster.equals(ClusterManager.getCluster(current))) {
|
if ((current != null) && (current.hasOwner() == false) && (current.settings.isMerged() == false) && cluster.equals(ClusterManager.getCluster(current))) {
|
||||||
Claim.claimPlot(plr, current, true, true);
|
Claim.claimPlot(plr, current, true, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
id = getNextPlot(id, 1);
|
id = getNextPlot(id, 1);
|
||||||
}
|
}
|
||||||
|
// no free plots
|
||||||
// no free plots
|
MainUtil.sendMessage(plr, C.NO_FREE_PLOTS);
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_FREE_PLOTS);
|
return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean br = false;
|
boolean br = false;
|
||||||
String worldname = world.getName();
|
|
||||||
if ((size_x == 1) && (size_z == 1)) {
|
if ((size_x == 1) && (size_z == 1)) {
|
||||||
while (!br) {
|
while (!br) {
|
||||||
final Plot plot = PlotHelper.getPlot(world, getLastPlot(worldname));
|
final Plot plot = MainUtil.getPlot(worldname, getLastPlot(worldname));
|
||||||
if ((plot.owner == null)) {
|
if ((plot.owner == null)) {
|
||||||
Claim.claimPlot(plr, plot, true, true);
|
Claim.claimPlot(plr, plot, true, true);
|
||||||
br = true;
|
br = true;
|
||||||
}
|
}
|
||||||
PlotHelper.lastPlot.put(worldname, getNextPlot(getLastPlot(worldname), 1));
|
MainUtil.lastPlot.put(worldname, getNextPlot(getLastPlot(worldname), 1));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
boolean lastPlot = true;
|
boolean lastPlot = true;
|
||||||
while (!br) {
|
while (!br) {
|
||||||
final PlotId start = getNextPlot(getLastPlot(worldname), 1);
|
final PlotId start = getNextPlot(getLastPlot(worldname), 1);
|
||||||
// Checking if the current set of plots is a viable option.
|
// Checking if the current set of plots is a viable option.
|
||||||
PlotHelper.lastPlot.put(worldname, start);
|
MainUtil.lastPlot.put(worldname, start);
|
||||||
if (lastPlot) {
|
if (lastPlot) {
|
||||||
}
|
}
|
||||||
if ((PlotMain.getPlots(world).get(start) != null) && (PlotMain.getPlots(world).get(start).owner != null)) {
|
if ((PlotSquared.getPlots(worldname).get(start) != null) && (PlotSquared.getPlots(worldname).get(start).owner != null)) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
lastPlot = false;
|
lastPlot = false;
|
||||||
}
|
}
|
||||||
final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1);
|
final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1);
|
||||||
if (PlotHelper.isUnowned(world, start, end)) {
|
if (MainUtil.isUnowned(worldname, start, end)) {
|
||||||
for (int i = start.x; i <= end.x; i++) {
|
for (int i = start.x; i <= end.x; i++) {
|
||||||
for (int j = start.y; j <= end.y; j++) {
|
for (int j = start.y; j <= end.y; j++) {
|
||||||
final Plot plot = PlotHelper.getPlot(world, new PlotId(i, j));
|
final Plot plot = MainUtil.getPlot(worldname, new PlotId(i, j));
|
||||||
final boolean teleport = ((i == end.x) && (j == end.y));
|
final boolean teleport = ((i == end.x) && (j == end.y));
|
||||||
Claim.claimPlot(plr, plot, teleport, true);
|
Claim.claimPlot(plr, plot, teleport, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!PlotHelper.mergePlots(plr, world, PlayerFunctions.getPlotSelectionIds(start, end))) {
|
if (!MainUtil.mergePlots(worldname, MainUtil.getPlotSelectionIds(start, end), true)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
br = true;
|
br = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlotHelper.lastPlot.put(worldname, new PlotId(0, 0));
|
MainUtil.lastPlot.put(worldname, new PlotId(0, 0));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlotId getLastPlot(String world) {
|
|
||||||
if (PlotHelper.lastPlot == null || !PlotHelper.lastPlot.containsKey(world)) {
|
|
||||||
PlotHelper.lastPlot.put(world, new PlotId(0,0));
|
|
||||||
}
|
|
||||||
return PlotHelper.lastPlot.get(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public PlotId getLastPlot(final String world) {
|
||||||
|
if ((MainUtil.lastPlot == null) || !MainUtil.lastPlot.containsKey(world)) {
|
||||||
|
MainUtil.lastPlot.put(world, new PlotId(0, 0));
|
||||||
|
}
|
||||||
|
return MainUtil.lastPlot.get(world);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package com.intellectualcrafters.plot.commands;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created 2014-11-09 for PlotSquared
|
|
||||||
*
|
|
||||||
* @author Citymonstret
|
|
||||||
*/
|
|
||||||
public class Ban extends SubCommand {
|
|
||||||
|
|
||||||
public Ban() {
|
|
||||||
super(Command.BAN, "Alias for /plot denied add", "/plot ban [player]", CommandCategory.ACTIONS, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(final Player plr, final String... args) {
|
|
||||||
if (args.length < 1) {
|
|
||||||
return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + this.usage);
|
|
||||||
}
|
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
|
||||||
}
|
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if (!plot.hasRights(plr)) {
|
|
||||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
|
||||||
}
|
|
||||||
return plr.performCommand("plot denied add " + args[0]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created 2015-02-20 for PlotSquared
|
||||||
|
*
|
||||||
|
* @author Citymonstret
|
||||||
|
*/
|
||||||
|
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender commandSender, Command command, String commandLabel, String[] args) {
|
||||||
|
Player player = null;
|
||||||
|
if (commandSender instanceof Player) {
|
||||||
|
player = (Player) commandSender;
|
||||||
|
}
|
||||||
|
return MainCommand.onCommand(BukkitUtil.getPlayer(player), commandLabel, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(final CommandSender commandSender, final Command command, final String s, final String[] strings) {
|
||||||
|
if (!(commandSender instanceof Player)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
|
||||||
|
if (strings.length < 1) {
|
||||||
|
if ((strings.length == 0) || "plots".startsWith(s)) {
|
||||||
|
return Arrays.asList("plots");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (strings.length > 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!command.getLabel().equalsIgnoreCase("plots")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final List<String> tabOptions = new ArrayList<>();
|
||||||
|
final String arg = strings[0].toLowerCase();
|
||||||
|
for (final SubCommand cmd : MainCommand.subCommands) {
|
||||||
|
if (cmd.permission.hasPermission(player)) {
|
||||||
|
if (cmd.cmd.startsWith(arg)) {
|
||||||
|
tabOptions.add(cmd.cmd);
|
||||||
|
} else if (cmd.alias.get(0).startsWith(arg)) {
|
||||||
|
tabOptions.add(cmd.alias.get(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tabOptions.size() > 0) {
|
||||||
|
return tabOptions;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -18,101 +18,95 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// 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.PlotSquared;
|
||||||
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.EconHandler;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class Buy extends SubCommand {
|
public class Buy extends SubCommand {
|
||||||
|
|
||||||
public Buy() {
|
public Buy() {
|
||||||
super(Command.BUY, "Buy the plot you are standing on", "b", CommandCategory.CLAIMING, true);
|
super(Command.BUY, "Buy the plot you are standing on", "b", CommandCategory.CLAIMING, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (!PlotMain.useEconomy) {
|
if (PlotSquared.economy == null) {
|
||||||
return sendMessage(plr, C.ECON_DISABLED);
|
return sendMessage(plr, C.ECON_DISABLED);
|
||||||
}
|
}
|
||||||
World world = plr.getWorld();
|
Location loc = plr.getLocation();
|
||||||
if (!PlotMain.isPlotWorld(world)) {
|
final String world = loc.getWorld();
|
||||||
|
if (!PlotSquared.isPlotWorld(world)) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
return sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||||
}
|
}
|
||||||
Plot plot;
|
Plot plot;
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
try {
|
try {
|
||||||
String[] split = args[0].split(";");
|
final String[] split = args[0].split(";");
|
||||||
PlotId id = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
final PlotId id = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||||
plot = PlotHelper.getPlot(world, id);
|
plot = MainUtil.getPlot(world, id);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
return sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
return sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
plot = MainUtil.getPlot(loc);
|
||||||
plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
}
|
}
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
if (PlayerFunctions.getPlayerPlotCount(world, plr) >= PlayerFunctions.getAllowedPlots(plr)) {
|
int currentPlots = MainUtil.getPlayerPlotCount(world, plr);
|
||||||
|
if (currentPlots >= MainUtil.getAllowedPlots(plr, currentPlots)) {
|
||||||
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||||
}
|
}
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
return sendMessage(plr, C.PLOT_UNOWNED);
|
return sendMessage(plr, C.PLOT_UNOWNED);
|
||||||
}
|
}
|
||||||
if (plot.owner.equals(UUIDHandler.getUUID(plr))) {
|
if (plot.owner.equals(plr.getUUID())) {
|
||||||
return sendMessage(plr, C.CANNOT_BUY_OWN);
|
return sendMessage(plr, C.CANNOT_BUY_OWN);
|
||||||
}
|
}
|
||||||
Flag flag = FlagManager.getPlotFlag(plot, "price");
|
final Flag flag = FlagManager.getPlotFlag(plot, "price");
|
||||||
if (flag == null) {
|
if (flag == null) {
|
||||||
return sendMessage(plr, C.NOT_FOR_SALE);
|
return sendMessage(plr, C.NOT_FOR_SALE);
|
||||||
}
|
}
|
||||||
double initPrice = (double) flag.getValue();
|
double initPrice = (double) flag.getValue();
|
||||||
double price = initPrice;
|
double price = initPrice;
|
||||||
PlotId id = plot.id;
|
final PlotId id = plot.id;
|
||||||
PlotId id2 = PlayerFunctions.getTopPlot(world, plot).id;
|
final PlotId id2 = MainUtil.getTopPlot(plot).id;
|
||||||
int size = PlayerFunctions.getPlotSelectionIds(id, id2).size();
|
final int size = MainUtil.getPlotSelectionIds(id, id2).size();
|
||||||
PlotWorld plotworld = PlotMain.getWorldSettings(world);
|
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
|
||||||
if (plotworld.USE_ECONOMY) {
|
if (plotworld.USE_ECONOMY) {
|
||||||
price += plotworld.PLOT_PRICE * size;
|
price += plotworld.PLOT_PRICE * size;
|
||||||
initPrice += plotworld.SELL_PRICE * size;
|
initPrice += plotworld.SELL_PRICE * size;
|
||||||
}
|
}
|
||||||
if (price > 0d) {
|
if (PlotSquared.economy != null && price > 0d) {
|
||||||
final Economy economy = PlotMain.economy;
|
if (EconHandler.getBalance(plr) < price) {
|
||||||
if (economy.getBalance(plr) < price) {
|
|
||||||
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price);
|
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price);
|
||||||
}
|
}
|
||||||
economy.withdrawPlayer(plr, price);
|
EconHandler.withdrawPlayer(plr, price);
|
||||||
sendMessage(plr, C.REMOVED_BALANCE, price + "");
|
sendMessage(plr, C.REMOVED_BALANCE, price + "");
|
||||||
economy.depositPlayer(UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner), initPrice);
|
EconHandler.depositPlayer(UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner), initPrice);
|
||||||
Player owner = UUIDHandler.uuidWrapper.getPlayer(plot.owner);
|
PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
|
||||||
if (owner != null) {
|
if (owner != null) {
|
||||||
sendMessage(plr, C.PLOT_SOLD, plot.id + "", plr.getName(), initPrice + "");
|
sendMessage(plr, C.PLOT_SOLD, plot.id + "", plr.getName(), initPrice + "");
|
||||||
}
|
}
|
||||||
FlagManager.removePlotFlag(plot, "price");
|
FlagManager.removePlotFlag(plot, "price");
|
||||||
}
|
}
|
||||||
plot.owner = UUIDHandler.getUUID(plr);
|
plot.owner = plr.getUUID();
|
||||||
DBFunc.setOwner(plot, plot.owner);
|
DBFunc.setOwner(plot, plot.owner);
|
||||||
PlayerFunctions.sendMessage(plr, C.CLAIMED);
|
MainUtil.sendMessage(plr, C.CLAIMED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,57 +18,54 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// 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 net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.generator.ClassicPlotWorld;
|
|
||||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.EconHandler;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class Claim extends SubCommand {
|
public class Claim extends SubCommand {
|
||||||
|
|
||||||
public Claim() {
|
public Claim() {
|
||||||
super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING, true);
|
super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, final boolean auto) {
|
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final boolean auto) {
|
||||||
return claimPlot(player, plot, teleport, "", auto);
|
return claimPlot(player, plot, teleport, "", auto);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, final String schematic, final boolean auto) {
|
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic, final boolean auto) {
|
||||||
if (plot.hasOwner() || plot.settings.isMerged()) {
|
if (plot.hasOwner() || plot.settings.isMerged()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot, auto);
|
// FIXME claim plot event
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
// final PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot, auto);
|
||||||
if (!event.isCancelled()) {
|
// Bukkit.getPluginManager().callEvent(event);
|
||||||
PlotHelper.createPlot(player, plot);
|
// boolean result = event.isCancelled();
|
||||||
PlotHelper.setSign(player, plot);
|
boolean result = true;
|
||||||
PlayerFunctions.sendMessage(player, C.CLAIMED);
|
|
||||||
|
if (!result) {
|
||||||
|
MainUtil.createPlot(player.getUUID(), plot);
|
||||||
|
MainUtil.setSign(player.getName(), plot);
|
||||||
|
MainUtil.sendMessage(player, C.CLAIMED);
|
||||||
|
Location loc = player.getLocation();
|
||||||
if (teleport) {
|
if (teleport) {
|
||||||
PlotMain.teleportPlayer(player, player.getLocation(), plot);
|
MainUtil.teleportPlayer(player, loc, plot);
|
||||||
}
|
}
|
||||||
World world = plot.getWorld();
|
final String world = plot.world;
|
||||||
final PlotWorld plotworld = PlotMain.getWorldSettings(world);
|
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
|
||||||
|
final Plot plot2 = PlotSquared.getPlots(world).get(plot.id);
|
||||||
final Plot plot2 = PlotMain.getPlots(player.getWorld()).get(plot.id);
|
|
||||||
|
|
||||||
if (plotworld.SCHEMATIC_ON_CLAIM) {
|
if (plotworld.SCHEMATIC_ON_CLAIM) {
|
||||||
SchematicHandler.Schematic sch;
|
SchematicHandler.Schematic sch;
|
||||||
if (schematic.equals("")) {
|
if (schematic.equals("")) {
|
||||||
@ -81,37 +78,39 @@ public class Claim extends SubCommand {
|
|||||||
}
|
}
|
||||||
SchematicHandler.paste(player.getLocation(), sch, plot2, 0, 0);
|
SchematicHandler.paste(player.getLocation(), sch, plot2, 0, 0);
|
||||||
}
|
}
|
||||||
PlotMain.getPlotManager(plot.world).claimPlot(world, plotworld, plot);
|
PlotSquared.getPlotManager(world).claimPlot(plotworld, plot);
|
||||||
PlotHelper.update(player.getLocation());
|
MainUtil.update(loc);
|
||||||
}
|
}
|
||||||
return event.isCancelled();
|
return !result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
String schematic = "";
|
String schematic = "";
|
||||||
if (args.length >= 1) {
|
if (args.length >= 1) {
|
||||||
schematic = args[0];
|
schematic = args[0];
|
||||||
}
|
}
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
|
Plot plot = MainUtil.getPlot(loc);
|
||||||
|
if (plot == null) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
if (PlayerFunctions.getPlayerPlotCount(plr.getWorld(), plr) >= PlayerFunctions.getAllowedPlots(plr)) {
|
int currentPlots = MainUtil.getPlayerPlotCount(loc.getWorld(), plr);
|
||||||
|
if (currentPlots >= MainUtil.getAllowedPlots(plr, currentPlots)) {
|
||||||
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if (plot.hasOwner()) {
|
if (plot.hasOwner()) {
|
||||||
return sendMessage(plr, C.PLOT_IS_CLAIMED);
|
return sendMessage(plr, C.PLOT_IS_CLAIMED);
|
||||||
}
|
}
|
||||||
final PlotWorld world = PlotMain.getWorldSettings(plot.getWorld());
|
final PlotWorld world = PlotSquared.getPlotWorld(plot.world);
|
||||||
if (PlotMain.useEconomy && world.USE_ECONOMY) {
|
if (PlotSquared.economy != null && world.USE_ECONOMY) {
|
||||||
final double cost = world.PLOT_PRICE;
|
final double cost = world.PLOT_PRICE;
|
||||||
if (cost > 0d) {
|
if (cost > 0d) {
|
||||||
final Economy economy = PlotMain.economy;
|
final Economy economy = PlotSquared.economy;
|
||||||
if (economy.getBalance(plr) < cost) {
|
if (EconHandler.getBalance(plr) < cost) {
|
||||||
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
||||||
}
|
}
|
||||||
economy.withdrawPlayer(plr, cost);
|
EconHandler.withdrawPlayer(plr, cost);
|
||||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,12 +119,11 @@ public class Claim extends SubCommand {
|
|||||||
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
|
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
|
||||||
return sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
return sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
||||||
}
|
}
|
||||||
if (!PlotMain.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin.command.schematic")) {
|
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin.command.schematic")) {
|
||||||
return sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
return sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return !claimPlot(plr, plot, false, schematic, false) || sendMessage(plr, C.PLOT_NOT_CLAIMED);
|
return !claimPlot(plr, plot, false, schematic, false) || sendMessage(plr, C.PLOT_NOT_CLAIMED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,71 +18,74 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
public class Clear extends SubCommand {
|
public class Clear extends SubCommand {
|
||||||
|
|
||||||
public Clear() {
|
public Clear() {
|
||||||
super(Command.CLEAR, "Clear a plot", "clear", CommandCategory.ACTIONS, false);
|
super(Command.CLEAR, "Clear a plot", "clear", CommandCategory.ACTIONS, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (plr == null) {
|
if (plr == null) {
|
||||||
// Is console
|
// Is console
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
PlotMain.sendConsoleSenderMessage("You need to specify two arguments: ID (0;0) & World (world)");
|
PlotSquared.log("You need to specify two arguments: ID (0;0) & World (world)");
|
||||||
} else {
|
} else {
|
||||||
final PlotId id = PlotId.fromString(args[0]);
|
final PlotId id = PlotId.fromString(args[0]);
|
||||||
final String world = args[1];
|
final String world = args[1];
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
PlotMain.sendConsoleSenderMessage("Invalid Plot ID: " + args[0]);
|
PlotSquared.log("Invalid Plot ID: " + args[0]);
|
||||||
} else {
|
} else {
|
||||||
if (!PlotMain.isPlotWorld(world)) {
|
if (!PlotSquared.isPlotWorld(world)) {
|
||||||
PlotMain.sendConsoleSenderMessage("Invalid plot world: " + world);
|
PlotSquared.log("Invalid plot world: " + world);
|
||||||
} else {
|
} else {
|
||||||
final Plot plot = PlotHelper.getPlot(Bukkit.getWorld(world), id);
|
final Plot plot = MainUtil.getPlot(world, id);
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
PlotMain.sendConsoleSenderMessage("Could not find plot " + args[0] + " in world " + world);
|
PlotSquared.log("Could not find plot " + args[0] + " in world " + world);
|
||||||
} else {
|
} else {
|
||||||
plot.clear(null, false);
|
MainUtil.clear(world, plot, true, null);
|
||||||
PlotMain.sendConsoleSenderMessage("Plot " + plot.getId().toString() + " cleared.");
|
PlotSquared.log("Plot " + plot.getId().toString() + " cleared.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Location loc = plr.getLocation();
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Plot plot = MainUtil.getPlot(loc);
|
||||||
|
if (plot == null) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot( plot))) {
|
||||||
if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
|
|
||||||
return sendMessage(plr, C.UNLINK_REQUIRED);
|
return sendMessage(plr, C.UNLINK_REQUIRED);
|
||||||
}
|
}
|
||||||
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !PlotMain.hasPermission(plr, "plots.admin.command.clear")) {
|
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) {
|
||||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
}
|
}
|
||||||
assert plot != null;
|
assert plot != null;
|
||||||
plot.clear(plr, false);
|
final long start = System.currentTimeMillis();
|
||||||
|
boolean result = MainUtil.clearAsPlayer(plot, false, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!result) {
|
||||||
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
|
}
|
||||||
// sign
|
// sign
|
||||||
|
|
||||||
// wall
|
// wall
|
||||||
|
return result;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,58 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.object.PlotSelection.currentSelection;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotSelection;
|
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|
||||||
|
|
||||||
public class Clipboard extends SubCommand {
|
|
||||||
|
|
||||||
public Clipboard() {
|
|
||||||
super(Command.CLIPBOARD, "View information about your current copy", "clipboard", CommandCategory.INFO, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(final Player plr, final String... args) {
|
|
||||||
if (!currentSelection.containsKey(plr.getName())) {
|
|
||||||
return sendMessage(plr, C.NO_CLIPBOARD);
|
|
||||||
}
|
|
||||||
final PlotSelection selection = currentSelection.get(plr.getName());
|
|
||||||
|
|
||||||
final PlotId plotId = selection.getPlot().getId();
|
|
||||||
final int width = selection.getWidth();
|
|
||||||
final int total = selection.getBlocks().length;
|
|
||||||
|
|
||||||
String message = C.CLIPBOARD_INFO.s();
|
|
||||||
|
|
||||||
message = message.replace("%id", plotId.toString()).replace("%width", width + "").replace("%total", total + "");
|
|
||||||
|
|
||||||
PlayerFunctions.sendMessage(plr, message);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,117 +18,108 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.generator.BlockPopulator;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
|
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
|
||||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
import com.intellectualcrafters.plot.object.BlockLoc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||||
import com.intellectualcrafters.plot.object.PlotClusterId;
|
import com.intellectualcrafters.plot.object.PlotClusterId;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
public class Cluster extends SubCommand {
|
public class Cluster extends SubCommand {
|
||||||
|
|
||||||
public Cluster() {
|
public Cluster() {
|
||||||
super(Command.CLUSTER, "Manage a plot cluster", "cluster", CommandCategory.ACTIONS, true);
|
super(Command.CLUSTER, "Manage a plot cluster", "cluster", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
|
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
// return arguments
|
// return arguments
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
|
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String sub = args[0].toLowerCase();
|
final String sub = args[0].toLowerCase();
|
||||||
switch (sub) {
|
switch (sub) {
|
||||||
case "l":
|
case "l":
|
||||||
case "list": {
|
case "list": {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.list")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.list")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.list");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.list");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
HashSet<PlotCluster> clusters = ClusterManager.getClusters(plr.getWorld());
|
final HashSet<PlotCluster> clusters = ClusterManager.getClusters(plr.getLocation().getWorld());
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + "");
|
MainUtil.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + "");
|
||||||
for (PlotCluster cluster : clusters) {
|
for (final PlotCluster cluster : clusters) {
|
||||||
// Ignore unmanaged clusters
|
// Ignore unmanaged clusters
|
||||||
String name = "'" + cluster.getName() + "' : " + cluster.toString();
|
final String name = "'" + cluster.getName() + "' : " + cluster.toString();
|
||||||
if (UUIDHandler.getUUID(plr).equals(cluster.owner)) {
|
if (UUIDHandler.getUUID(plr).equals(cluster.owner)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&a" + name);
|
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&a" + name);
|
||||||
}
|
} else if (cluster.helpers.contains(UUIDHandler.getUUID(plr))) {
|
||||||
else if (cluster.helpers.contains(UUIDHandler.getUUID(plr))) {
|
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&3" + name);
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&3" + name);
|
} else if (cluster.invited.contains(UUIDHandler.getUUID(plr))) {
|
||||||
}
|
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&9" + name);
|
||||||
else if (cluster.invited.contains(UUIDHandler.getUUID(plr))) {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&9" + name);
|
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, cluster.toString());
|
||||||
}
|
|
||||||
else {
|
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, cluster.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "c":
|
case "c":
|
||||||
case "create": {
|
case "create": {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.create")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.create")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 4) {
|
if (args.length != 4) {
|
||||||
PlotId id = ClusterManager.estimatePlotId(plr.getLocation());
|
final PlotId id = ClusterManager.estimatePlotId(plr.getLocation());
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster create <name> <id-bot> <id-top>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster create <name> <id-bot> <id-top>");
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_CURRENT_PLOTID, "" + id);
|
MainUtil.sendMessage(plr, C.CLUSTER_CURRENT_PLOTID, "" + id);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check pos1 / pos2
|
// check pos1 / pos2
|
||||||
PlotId pos1 = PlotHelper.parseId(args[2]);
|
final PlotId pos1 = MainUtil.parseId(args[2]);
|
||||||
PlotId pos2 = PlotHelper.parseId(args[3]);
|
final PlotId pos2 = MainUtil.parseId(args[3]);
|
||||||
if (pos1 == null || pos2 == null) {
|
if ((pos1 == null) || (pos2 == null)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check if name is taken
|
// check if name is taken
|
||||||
String name = args[1];
|
final String name = args[1];
|
||||||
for (PlotCluster cluster : ClusterManager.getClusters(plr.getWorld())) {
|
for (final PlotCluster cluster : ClusterManager.getClusters(plr.getLocation().getWorld())) {
|
||||||
if (name.equals(cluster.getName())) {
|
if (name.equals(cluster.getName())) {
|
||||||
PlayerFunctions.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//check if overlap
|
//check if overlap
|
||||||
PlotClusterId id = new PlotClusterId(pos1, pos2);
|
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
||||||
HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getWorld().getName(), id);
|
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getLocation().getWorld(), id);
|
||||||
if (intersects.size() > 0 || pos2.x < pos1.x || pos2.y < pos1.y) {
|
if ((intersects.size() > 0) || (pos2.x < pos1.x) || (pos2.y < pos1.y)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
|
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// create cluster
|
// create cluster
|
||||||
String world = plr.getWorld().getName();
|
final String world = plr.getLocation().getWorld();
|
||||||
PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
|
final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
|
||||||
cluster.settings.setAlias(name);
|
cluster.settings.setAlias(name);
|
||||||
DBFunc.createCluster(world, cluster);
|
DBFunc.createCluster(world, cluster);
|
||||||
if (!ClusterManager.clusters.containsKey(world)) {
|
if (!ClusterManager.clusters.containsKey(world)) {
|
||||||
@ -136,234 +127,225 @@ public class Cluster extends SubCommand {
|
|||||||
}
|
}
|
||||||
ClusterManager.clusters.get(world).add(cluster);
|
ClusterManager.clusters.get(world).add(cluster);
|
||||||
// Add any existing plots to the current cluster
|
// Add any existing plots to the current cluster
|
||||||
for (Plot plot : PlotMain.getPlots(plr.getWorld()).values()) {
|
for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld()).values()) {
|
||||||
PlotCluster current = ClusterManager.getCluster(plot);
|
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||||
if (cluster.equals(current) && !cluster.hasRights(plot.owner)) {
|
if (cluster.equals(current) && !cluster.hasRights(plot.owner)) {
|
||||||
cluster.invited.add(plot.owner);
|
cluster.invited.add(plot.owner);
|
||||||
DBFunc.setInvited(world, cluster, plot.owner);
|
DBFunc.setInvited(world, cluster, plot.owner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!PlotMain.isPlotWorld(world)) {
|
if (!PlotSquared.isPlotWorld(world)) {
|
||||||
PlotMain.config.createSection("worlds." + world);
|
PlotSquared.config.createSection("worlds." + world);
|
||||||
PlotMain.loadWorld(plr.getWorld());
|
PlotSquared.loadWorld(world, null);
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_ADDED);
|
MainUtil.sendMessage(plr, C.CLUSTER_ADDED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "disband":
|
case "disband":
|
||||||
case "del":
|
case "del":
|
||||||
case "delete": {
|
case "delete": {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.delete")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.delete")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 1 && args.length != 2) {
|
if ((args.length != 1) && (args.length != 2)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster delete [name]");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster delete [name]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotCluster cluster;
|
PlotCluster cluster;
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]);
|
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
cluster = ClusterManager.getCluster(plr.getLocation());
|
cluster = ClusterManager.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) {
|
if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.delete.other")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.delete.other")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld());
|
final PlotWorld plotworld = PlotSquared.getPlotWorld(plr.getLocation().getWorld());
|
||||||
if (plotworld.TYPE == 2) {
|
if (plotworld.TYPE == 2) {
|
||||||
ArrayList<Plot> toRemove = new ArrayList<>();
|
final ArrayList<Plot> toRemove = new ArrayList<>();
|
||||||
for (Plot plot : PlotMain.getPlots(plr.getWorld()).values()) {
|
for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld()).values()) {
|
||||||
PlotCluster other = ClusterManager.getCluster(plot);
|
final PlotCluster other = ClusterManager.getCluster(plot);
|
||||||
if (cluster.equals(other)) {
|
if (cluster.equals(other)) {
|
||||||
toRemove.add(plot);
|
toRemove.add(plot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Plot plot : toRemove) {
|
for (final Plot plot : toRemove) {
|
||||||
DBFunc.delete(plot.world, plot);
|
DBFunc.delete(plot.world, plot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DBFunc.delete(cluster);
|
DBFunc.delete(cluster);
|
||||||
if (plotworld.TYPE == 2) {
|
if (plotworld.TYPE == 2) {
|
||||||
for (Iterator<BlockPopulator> iterator = plr.getWorld().getPopulators().iterator(); iterator.hasNext();) {
|
AugmentedPopulator.removePopulator(plr.getLocation().getWorld(), cluster);
|
||||||
BlockPopulator populator = iterator.next();
|
|
||||||
if (populator instanceof AugmentedPopulator) {
|
|
||||||
if (((AugmentedPopulator) populator).cluster.equals(cluster)) {
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (String set : ClusterManager.clusters.keySet()) {
|
for (final String set : ClusterManager.clusters.keySet()) {
|
||||||
}
|
}
|
||||||
ClusterManager.last = null;
|
ClusterManager.last = null;
|
||||||
ClusterManager.clusters.get(cluster.world).remove(cluster);
|
ClusterManager.clusters.get(cluster.world).remove(cluster);
|
||||||
ClusterManager.regenCluster(cluster);
|
ClusterManager.regenCluster(cluster);
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_DELETED);
|
MainUtil.sendMessage(plr, C.CLUSTER_DELETED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "res":
|
case "res":
|
||||||
case "resize": {
|
case "resize": {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.resize")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.resize")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster resize <pos1> <pos2>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster resize <pos1> <pos2>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check pos1 / pos2
|
// check pos1 / pos2
|
||||||
PlotId pos1 = PlotHelper.parseId(args[1]);
|
final PlotId pos1 = MainUtil.parseId(args[1]);
|
||||||
PlotId pos2 = PlotHelper.parseId(args[2]);
|
final PlotId pos2 = MainUtil.parseId(args[2]);
|
||||||
if (pos1 == null || pos2 == null) {
|
if ((pos1 == null) || (pos2 == null)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check if in cluster
|
// check if in cluster
|
||||||
PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
|
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.resize.other")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.resize.other")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//check if overlap
|
//check if overlap
|
||||||
PlotClusterId id = new PlotClusterId(pos1, pos2);
|
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
||||||
HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getWorld().getName(), id);
|
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getLocation().getWorld(), id);
|
||||||
if (intersects.size() > 1) {
|
if (intersects.size() > 1) {
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
|
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// resize cluster
|
// resize cluster
|
||||||
DBFunc.resizeCluster(cluster, id);
|
DBFunc.resizeCluster(cluster, id);
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_RESIZED);
|
MainUtil.sendMessage(plr, C.CLUSTER_RESIZED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "reg":
|
case "reg":
|
||||||
case "regenerate":
|
case "regenerate":
|
||||||
case "regen": {
|
case "regen": {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.delete")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.delete")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 1 && args.length != 2) {
|
if ((args.length != 1) && (args.length != 2)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster regen [name]");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster regen [name]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotCluster cluster;
|
PlotCluster cluster;
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]);
|
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
cluster = ClusterManager.getCluster(plr.getLocation());
|
cluster = ClusterManager.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) {
|
if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.regen.other")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.regen.other")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ClusterManager.regenCluster(cluster);
|
ClusterManager.regenCluster(cluster);
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_REGENERATED);
|
MainUtil.sendMessage(plr, C.CLUSTER_REGENERATED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "add":
|
case "add":
|
||||||
case "inv":
|
case "inv":
|
||||||
case "invite": {
|
case "invite": {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.invite")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.invite")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster invite <player>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster invite <player>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check if in cluster
|
// check if in cluster
|
||||||
PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
|
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.invite.other")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.invite.other")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check uuid
|
// check uuid
|
||||||
UUID uuid = UUIDHandler.getUUID(args[1]);
|
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!cluster.hasRights(uuid)) {
|
if (!cluster.hasRights(uuid)) {
|
||||||
// add the user if not added
|
// add the user if not added
|
||||||
cluster.invited.add(uuid);
|
cluster.invited.add(uuid);
|
||||||
String world = plr.getWorld().getName();
|
final String world = plr.getLocation().getWorld();
|
||||||
DBFunc.setInvited(world, cluster, uuid);
|
DBFunc.setInvited(world, cluster, uuid);
|
||||||
Player player = UUIDHandler.uuidWrapper.getPlayer(uuid);
|
PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PlayerFunctions.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
|
MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_ADDED_USER);
|
MainUtil.sendMessage(plr, C.CLUSTER_ADDED_USER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "k":
|
case "k":
|
||||||
case "remove":
|
case "remove":
|
||||||
case "kick": {
|
case "kick": {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.kick")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.kick")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster kick <player>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster kick <player>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
|
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.kick.other")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.kick.other")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check uuid
|
// check uuid
|
||||||
UUID uuid = UUIDHandler.getUUID(args[1]);
|
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Can't kick if the player is yourself, the owner, or not added to the cluster
|
// Can't kick if the player is yourself, the owner, or not added to the cluster
|
||||||
if (uuid.equals(UUIDHandler.getUUID(plr)) || uuid.equals(cluster.owner) || !cluster.hasRights(uuid)) {
|
if (uuid.equals(UUIDHandler.getUUID(plr)) || uuid.equals(cluster.owner) || !cluster.hasRights(uuid)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.CANNOT_KICK_PLAYER, cluster.getName());
|
MainUtil.sendMessage(plr, C.CANNOT_KICK_PLAYER, cluster.getName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (cluster.helpers.contains(uuid)) {
|
if (cluster.helpers.contains(uuid)) {
|
||||||
@ -372,52 +354,51 @@ public class Cluster extends SubCommand {
|
|||||||
}
|
}
|
||||||
cluster.invited.remove(uuid);
|
cluster.invited.remove(uuid);
|
||||||
DBFunc.removeInvited(cluster, uuid);
|
DBFunc.removeInvited(cluster, uuid);
|
||||||
Player player = UUIDHandler.uuidWrapper.getPlayer(uuid);
|
PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PlayerFunctions.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
|
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
|
||||||
}
|
}
|
||||||
for (Plot plot : PlotMain.getPlots(plr.getWorld(), uuid)) {
|
for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld(), uuid)) {
|
||||||
PlotCluster current = ClusterManager.getCluster(plot);
|
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||||
if (current != null && current.equals(cluster)) {
|
if ((current != null) && current.equals(cluster)) {
|
||||||
String world = plr.getWorld().getName();
|
final String world = plr.getLocation().getWorld();
|
||||||
DBFunc.delete(world, plot);
|
DBFunc.delete(world, plot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_KICKED_USER);
|
MainUtil.sendMessage(plr, C.CLUSTER_KICKED_USER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "quit":
|
case "quit":
|
||||||
case "leave": {
|
case "leave": {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.leave")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.leave")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.leave");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.leave");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 1 && args.length != 2) {
|
if ((args.length != 1) && (args.length != 2)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster leave [name]");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster leave [name]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotCluster cluster;
|
PlotCluster cluster;
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]);
|
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
cluster = ClusterManager.getCluster(plr.getLocation());
|
cluster = ClusterManager.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UUID uuid = UUIDHandler.getUUID(plr);
|
final UUID uuid = UUIDHandler.getUUID(plr);
|
||||||
if (!cluster.hasRights(uuid)) {
|
if (!cluster.hasRights(uuid)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_NOT_ADDED);
|
MainUtil.sendMessage(plr, C.CLUSTER_NOT_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (uuid.equals(cluster.owner)) {
|
if (uuid.equals(cluster.owner)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_CANNOT_LEAVE);
|
MainUtil.sendMessage(plr, C.CLUSTER_CANNOT_LEAVE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (cluster.helpers.contains(uuid)) {
|
if (cluster.helpers.contains(uuid)) {
|
||||||
@ -426,11 +407,11 @@ public class Cluster extends SubCommand {
|
|||||||
}
|
}
|
||||||
cluster.invited.remove(uuid);
|
cluster.invited.remove(uuid);
|
||||||
DBFunc.removeInvited(cluster, uuid);
|
DBFunc.removeInvited(cluster, uuid);
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
|
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
|
||||||
for (Plot plot : PlotMain.getPlots(plr.getWorld(), uuid)) {
|
for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld(), uuid)) {
|
||||||
PlotCluster current = ClusterManager.getCluster(plot);
|
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||||
if (current != null && current.equals(cluster)) {
|
if ((current != null) && current.equals(cluster)) {
|
||||||
String world = plr.getWorld().getName();
|
final String world = plr.getLocation().getWorld();
|
||||||
DBFunc.delete(world, plot);
|
DBFunc.delete(world, plot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -439,139 +420,135 @@ public class Cluster extends SubCommand {
|
|||||||
case "admin":
|
case "admin":
|
||||||
case "helper":
|
case "helper":
|
||||||
case "helpers": {
|
case "helpers": {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.helpers")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.helpers")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.helpers");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.helpers");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UUID uuid = UUIDHandler.getUUID(args[2]);
|
final UUID uuid = UUIDHandler.getUUID(args[2]);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args[1].toLowerCase().equals("add")) {
|
if (args[1].toLowerCase().equals("add")) {
|
||||||
cluster.helpers.add(uuid);
|
cluster.helpers.add(uuid);
|
||||||
return PlayerFunctions.sendMessage(plr, C.CLUSTER_ADDED_HELPER);
|
return MainUtil.sendMessage(plr, C.CLUSTER_ADDED_HELPER);
|
||||||
}
|
}
|
||||||
if (args[1].toLowerCase().equals("remove")) {
|
if (args[1].toLowerCase().equals("remove")) {
|
||||||
cluster.helpers.remove(uuid);
|
cluster.helpers.remove(uuid);
|
||||||
return PlayerFunctions.sendMessage(plr, C.CLUSTER_REMOVED_HELPER);
|
return MainUtil.sendMessage(plr, C.CLUSTER_REMOVED_HELPER);
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case "spawn":
|
case "spawn":
|
||||||
case "home":
|
case "home":
|
||||||
case "tp": {
|
case "tp": {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.tp")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.tp")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotCluster cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]);
|
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UUID uuid = UUIDHandler.getUUID(plr);
|
final UUID uuid = UUIDHandler.getUUID(plr);
|
||||||
if (!cluster.hasRights(uuid)) {
|
if (!cluster.hasRights(uuid)) {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.tp.other")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.tp.other")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
plr.teleport(ClusterManager.getHome(cluster));
|
plr.teleport(ClusterManager.getHome(cluster));
|
||||||
return PlayerFunctions.sendMessage(plr, C.CLUSTER_TELEPORTING);
|
return MainUtil.sendMessage(plr, C.CLUSTER_TELEPORTING);
|
||||||
}
|
}
|
||||||
case "i":
|
case "i":
|
||||||
case "info":
|
case "info":
|
||||||
case "show":
|
case "show":
|
||||||
case "information": {
|
case "information": {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.info")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.info")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.info");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.info");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 1 && args.length != 2) {
|
if ((args.length != 1) && (args.length != 2)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster info [name]");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster info [name]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotCluster cluster;
|
PlotCluster cluster;
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]);
|
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
cluster = ClusterManager.getCluster(plr.getLocation());
|
cluster = ClusterManager.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String id = cluster.toString();
|
final String id = cluster.toString();
|
||||||
String owner = UUIDHandler.getName(cluster.owner);
|
String owner = UUIDHandler.getName(cluster.owner);
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
owner = "unknown";
|
owner = "unknown";
|
||||||
}
|
}
|
||||||
String name = cluster.getName();
|
final String name = cluster.getName();
|
||||||
String size = (cluster.getP2().x - cluster.getP1().x + 1) + "x" + (cluster.getP2().y - cluster.getP1().y + 1);
|
final String size = ((cluster.getP2().x - cluster.getP1().x) + 1) + "x" + ((cluster.getP2().y - cluster.getP1().y) + 1);
|
||||||
String rights = cluster.hasRights(UUIDHandler.getUUID(plr)) + "";
|
final String rights = cluster.hasRights(UUIDHandler.getUUID(plr)) + "";
|
||||||
|
|
||||||
String message = C.CLUSTER_INFO.s();
|
String message = C.CLUSTER_INFO.s();
|
||||||
message = message.replaceAll("%id%", id);
|
message = message.replaceAll("%id%", id);
|
||||||
message = message.replaceAll("%owner%", owner);
|
message = message.replaceAll("%owner%", owner);
|
||||||
message = message.replaceAll("%name%", name);
|
message = message.replaceAll("%name%", name);
|
||||||
message = message.replaceAll("%size%", size);
|
message = message.replaceAll("%size%", size);
|
||||||
message = message.replaceAll("%rights%", rights);
|
message = message.replaceAll("%rights%", rights);
|
||||||
|
MainUtil.sendMessage(plr, message);
|
||||||
PlayerFunctions.sendMessage(plr, message);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "sh":
|
case "sh":
|
||||||
case "setspawn":
|
case "setspawn":
|
||||||
case "sethome": {
|
case "sethome": {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.sethome")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.sethome")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 1 && args.length != 2) {
|
if ((args.length != 1) && (args.length != 2)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster sethome");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster sethome");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
|
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
|
||||||
if (!PlotMain.hasPermission(plr, "plots.cluster.sethome.other")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.sethome.other")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Location base = ClusterManager.getClusterBottom(cluster);
|
final Location base = ClusterManager.getClusterBottom(cluster);
|
||||||
base.setY(0);
|
final Location relative = plr.getLocation().subtract(base.getX(), 0, base.getZ());
|
||||||
Location relative = plr.getLocation().subtract(base);
|
final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ());
|
||||||
BlockLoc blockloc = new BlockLoc(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ());
|
|
||||||
cluster.settings.setPosition(blockloc);
|
cluster.settings.setPosition(blockloc);
|
||||||
DBFunc.setPosition(cluster, relative.getBlockX() + "," + relative.getBlockY() + "," + relative.getBlockZ());
|
DBFunc.setPosition(cluster, relative.getX() + "," + relative.getY() + "," + relative.getZ());
|
||||||
return PlayerFunctions.sendMessage(plr, C.POSITION_SET);
|
return MainUtil.sendMessage(plr, C.POSITION_SET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
|
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +27,6 @@ package com.intellectualcrafters.plot.commands;
|
|||||||
* @author Empire92
|
* @author Empire92
|
||||||
*/
|
*/
|
||||||
public enum Command {
|
public enum Command {
|
||||||
|
|
||||||
// TODO new commands
|
// TODO new commands
|
||||||
// (economy)
|
// (economy)
|
||||||
// - /plot buy
|
// - /plot buy
|
||||||
@ -39,7 +37,7 @@ public enum Command {
|
|||||||
FLAG("flag", "f"),
|
FLAG("flag", "f"),
|
||||||
TARGET("target"),
|
TARGET("target"),
|
||||||
CLUSTER("cluster", "clusters"),
|
CLUSTER("cluster", "clusters"),
|
||||||
BUY("buy","b"),
|
BUY("buy", "b"),
|
||||||
CREATEROADSCHEMATIC("createroadschematic"),
|
CREATEROADSCHEMATIC("createroadschematic"),
|
||||||
DEBUGROADREGEN("debugroadregen"),
|
DEBUGROADREGEN("debugroadregen"),
|
||||||
DEBUGFIXFLAGS("debugfixflags"),
|
DEBUGFIXFLAGS("debugfixflags"),
|
||||||
@ -77,22 +75,19 @@ public enum Command {
|
|||||||
UNBAN("unban", "unblock"),
|
UNBAN("unban", "unblock"),
|
||||||
DATABASE("database", "convert"),
|
DATABASE("database", "convert"),
|
||||||
TP("tp", "tp");
|
TP("tp", "tp");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command
|
* Command
|
||||||
*/
|
*/
|
||||||
private final String command;
|
private final String command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alias
|
* Alias
|
||||||
*/
|
*/
|
||||||
private final String alias;
|
private final String alias;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permission Node
|
* Permission Node
|
||||||
*/
|
*/
|
||||||
private final CommandPermission permission;
|
private final CommandPermission permission;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param command Command "name" (/plot [cmd])
|
* @param command Command "name" (/plot [cmd])
|
||||||
*/
|
*/
|
||||||
@ -101,7 +96,7 @@ public enum Command {
|
|||||||
this.alias = command;
|
this.alias = command;
|
||||||
this.permission = new CommandPermission("plots." + command);
|
this.permission = new CommandPermission("plots." + command);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param command Command "name" (/plot [cmd])
|
* @param command Command "name" (/plot [cmd])
|
||||||
* @param permission Command Permission Node
|
* @param permission Command Permission Node
|
||||||
@ -111,7 +106,7 @@ public enum Command {
|
|||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
this.alias = command;
|
this.alias = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param command Command "name" (/plot [cmd])
|
* @param command Command "name" (/plot [cmd])
|
||||||
* @param alias Command Alias
|
* @param alias Command Alias
|
||||||
@ -121,7 +116,7 @@ public enum Command {
|
|||||||
this.alias = alias;
|
this.alias = alias;
|
||||||
this.permission = new CommandPermission("plots." + command);
|
this.permission = new CommandPermission("plots." + command);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param command Command "name" (/plot [cmd])
|
* @param command Command "name" (/plot [cmd])
|
||||||
* @param alias Command Alias
|
* @param alias Command Alias
|
||||||
@ -132,21 +127,21 @@ public enum Command {
|
|||||||
this.alias = alias;
|
this.alias = alias;
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return command
|
* @return command
|
||||||
*/
|
*/
|
||||||
public String getCommand() {
|
public String getCommand() {
|
||||||
return this.command;
|
return this.command;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return alias
|
* @return alias
|
||||||
*/
|
*/
|
||||||
public String getAlias() {
|
public String getAlias() {
|
||||||
return this.alias;
|
return this.alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return permission object
|
* @return permission object
|
||||||
*
|
*
|
||||||
|
@ -18,12 +18,10 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// 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.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Citymonstret on 2014-08-03.
|
* Created by Citymonstret on 2014-08-03.
|
||||||
@ -31,25 +29,24 @@ import com.intellectualcrafters.plot.PlotMain;
|
|||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class CommandPermission {
|
public class CommandPermission {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permission Node
|
* Permission Node
|
||||||
*/
|
*/
|
||||||
public final String permission;
|
public final String permission;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param permission Command Permission
|
* @param permission Command Permission
|
||||||
*/
|
*/
|
||||||
public CommandPermission(final String permission) {
|
public CommandPermission(final String permission) {
|
||||||
this.permission = permission.toLowerCase();
|
this.permission = permission.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param player Does the player have the permission?
|
* @param player Does the player have the permission?
|
||||||
*
|
*
|
||||||
* @return true of player has the required permission node
|
* @return true of player has the required permission node
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(final Player player) {
|
public boolean hasPermission(final PlotPlayer player) {
|
||||||
return PlotMain.hasPermission(player, this.permission);
|
return Permissions.hasPermission(player, this.permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,47 +18,44 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotComment;
|
import com.intellectualcrafters.plot.object.PlotComment;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
|
||||||
public class Comment extends SubCommand {
|
public class Comment extends SubCommand {
|
||||||
|
|
||||||
public Comment() {
|
public Comment() {
|
||||||
super(Command.COMMENT, "Comment on a plot", "comment", CommandCategory.ACTIONS, true);
|
super(Command.COMMENT, "Comment on a plot", "comment", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
|
Plot plot = MainUtil.getPlot(loc);
|
||||||
|
if (plot == null) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<String> recipients = Arrays.asList("admin", "owner", "helper", "trusted", "everyone");
|
final List<String> recipients = Arrays.asList("admin", "owner", "helper", "trusted", "everyone");
|
||||||
|
|
||||||
if ((args.length > 1) && recipients.contains(args[0].toLowerCase())) {
|
if ((args.length > 1) && recipients.contains(args[0].toLowerCase())) {
|
||||||
|
if (Permissions.hasPermission(plr, "plots.comment." + args[0].toLowerCase())) {
|
||||||
if (PlotMain.hasPermission(plr, "plots.comment." + args[0].toLowerCase())) {
|
|
||||||
final String text = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " ");
|
final String text = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " ");
|
||||||
final PlotComment comment = new PlotComment(text, plr.getName(), recipients.indexOf(args[0].toLowerCase()));
|
final PlotComment comment = new PlotComment(text, plr.getName(), recipients.indexOf(args[0].toLowerCase()));
|
||||||
plot.settings.addComment(comment);
|
plot.settings.addComment(comment);
|
||||||
DBFunc.setComment(plr.getWorld().getName(), plot, comment);
|
DBFunc.setComment(loc.getWorld(), plot, comment);
|
||||||
return sendMessage(plr, C.COMMENT_ADDED);
|
return sendMessage(plr, C.COMMENT_ADDED);
|
||||||
} else {
|
} else {
|
||||||
return sendMessage(plr, C.NO_PERMISSION, "plots.comment." + args[0].toLowerCase());
|
return sendMessage(plr, C.NO_PERMISSION, "plots.comment." + args[0].toLowerCase());
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -28,79 +27,74 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
|
||||||
public class Condense extends SubCommand {
|
public class Condense extends SubCommand {
|
||||||
|
|
||||||
public static boolean TASK = false;
|
public static boolean TASK = false;
|
||||||
private static int TASK_ID = 0;
|
|
||||||
|
|
||||||
public Condense() {
|
public Condense() {
|
||||||
super("condense", "plots.admin", "Condense a plotworld", "condense", "", CommandCategory.DEBUG, false);
|
super("condense", "plots.admin", "Condense a plotworld", "condense", "", CommandCategory.DEBUG, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (plr != null) {
|
if (plr != null) {
|
||||||
PlayerFunctions.sendMessage(plr, (C.NOT_CONSOLE));
|
MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 2 && args.length != 3) {
|
if ((args.length != 2) && (args.length != 3)) {
|
||||||
PlayerFunctions.sendMessage(plr, "/plot condense <world> <start|stop|info> [radius]");
|
MainUtil.sendMessage(plr, "/plot condense <world> <start|stop|info> [radius]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String worldname = args[0];
|
final String worldname = args[0];
|
||||||
final World world = Bukkit.getWorld(worldname);
|
if (!BlockManager.manager.isWorld(worldname) || !PlotSquared.isPlotWorld(worldname)) {
|
||||||
if (world == null || !PlotMain.isPlotWorld(worldname)) {
|
MainUtil.sendMessage(plr, "INVALID WORLD");
|
||||||
PlayerFunctions.sendMessage(plr, "INVALID WORLD");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (args[1].toLowerCase()) {
|
switch (args[1].toLowerCase()) {
|
||||||
case "start": {
|
case "start": {
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
PlayerFunctions.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (TASK) {
|
if (TASK) {
|
||||||
PlayerFunctions.sendMessage(plr, "TASK ALREADY STARTED");
|
MainUtil.sendMessage(plr, "TASK ALREADY STARTED");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
PlayerFunctions.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!StringUtils.isNumeric(args[2])) {
|
if (!StringUtils.isNumeric(args[2])) {
|
||||||
PlayerFunctions.sendMessage(plr, "INVALID RADIUS");
|
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int radius = Integer.parseInt(args[2]);
|
final int radius = Integer.parseInt(args[2]);
|
||||||
Collection<Plot> plots = PlotMain.getPlots(worldname).values();
|
final Collection<Plot> plots = PlotSquared.getPlots(worldname).values();
|
||||||
int size = plots.size();
|
final int size = plots.size();
|
||||||
int minimum_radius = (int) Math.ceil((Math.sqrt(size)/2) + 1);
|
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
|
||||||
if (radius < minimum_radius) {
|
if (radius < minimum_radius) {
|
||||||
PlayerFunctions.sendMessage(plr, "RADIUS TOO SMALL");
|
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final List<PlotId> to_move = new ArrayList<>(getPlots(plots, radius));
|
final List<PlotId> to_move = new ArrayList<>(getPlots(plots, radius));
|
||||||
final List<PlotId> free = new ArrayList<>();
|
final List<PlotId> free = new ArrayList<>();
|
||||||
PlotId start = new PlotId(0,0);
|
PlotId start = new PlotId(0, 0);
|
||||||
while (start.x <= minimum_radius && start.y <= minimum_radius) {
|
while ((start.x <= minimum_radius) && (start.y <= minimum_radius)) {
|
||||||
Plot plot = PlotHelper.getPlot(world, start);
|
final Plot plot = MainUtil.getPlot(worldname, start);
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
free.add(plot.id);
|
free.add(plot.id);
|
||||||
}
|
}
|
||||||
start = Auto.getNextPlot(start, 1);
|
start = Auto.getNextPlot(start, 1);
|
||||||
}
|
}
|
||||||
PlotHelper.move(world, to_move.get(0), free.get(0), new Runnable() {
|
MainUtil.move(worldname, to_move.get(0), free.get(0), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!TASK) {
|
if (!TASK) {
|
||||||
@ -110,25 +104,25 @@ public class Condense extends SubCommand {
|
|||||||
to_move.remove(0);
|
to_move.remove(0);
|
||||||
free.remove(0);
|
free.remove(0);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (PlotId id : to_move) {
|
for (final PlotId id : to_move) {
|
||||||
Plot plot = PlotHelper.getPlot(world, id);
|
final Plot plot = MainUtil.getPlot(worldname, id);
|
||||||
if (plot.hasOwner()) {
|
if (plot.hasOwner()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i<index; i++) {
|
for (int i = 0; i < index; i++) {
|
||||||
to_move.remove(0);
|
to_move.remove(0);
|
||||||
}
|
}
|
||||||
index = 0;
|
index = 0;
|
||||||
for (PlotId id : free) {
|
for (final PlotId id : free) {
|
||||||
Plot plot = PlotHelper.getPlot(world, id);
|
final Plot plot = MainUtil.getPlot(worldname, id);
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i<index; i++) {
|
for (int i = 0; i < index; i++) {
|
||||||
free.remove(0);
|
free.remove(0);
|
||||||
}
|
}
|
||||||
if (to_move.size() == 0) {
|
if (to_move.size() == 0) {
|
||||||
@ -141,61 +135,61 @@ public class Condense extends SubCommand {
|
|||||||
TASK = false;
|
TASK = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendMessage("MOVING " + to_move.get(0) +" to " + free.get(0));
|
sendMessage("MOVING " + to_move.get(0) + " to " + free.get(0));
|
||||||
PlotHelper.move(world, to_move.get(0), free.get(0), this);
|
MainUtil.move(worldname, to_move.get(0), free.get(0), this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
TASK = true;
|
TASK = true;
|
||||||
PlayerFunctions.sendMessage(plr, "TASK STARTED...");
|
MainUtil.sendMessage(plr, "TASK STARTED...");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "stop": {
|
case "stop": {
|
||||||
if (!TASK) {
|
if (!TASK) {
|
||||||
PlayerFunctions.sendMessage(plr, "TASK ALREADY STOPPED");
|
MainUtil.sendMessage(plr, "TASK ALREADY STOPPED");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TASK = false;
|
TASK = false;
|
||||||
PlayerFunctions.sendMessage(plr, "TASK STOPPED");
|
MainUtil.sendMessage(plr, "TASK STOPPED");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "info": {
|
case "info": {
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
PlayerFunctions.sendMessage(plr, "/plot condense " + worldname + " info <radius>");
|
MainUtil.sendMessage(plr, "/plot condense " + worldname + " info <radius>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!StringUtils.isNumeric(args[2])) {
|
if (!StringUtils.isNumeric(args[2])) {
|
||||||
PlayerFunctions.sendMessage(plr, "INVALID RADIUS");
|
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int radius = Integer.parseInt(args[2]);
|
final int radius = Integer.parseInt(args[2]);
|
||||||
Collection<Plot> plots = PlotMain.getPlots(worldname).values();
|
final Collection<Plot> plots = PlotSquared.getPlots(worldname).values();
|
||||||
int size = plots.size();
|
final int size = plots.size();
|
||||||
int minimum_radius = (int) Math.ceil((Math.sqrt(size)/2) + 1);
|
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
|
||||||
if (radius < minimum_radius) {
|
if (radius < minimum_radius) {
|
||||||
PlayerFunctions.sendMessage(plr, "RADIUS TOO SMALL");
|
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int max_move = getPlots(plots, minimum_radius).size();
|
final int max_move = getPlots(plots, minimum_radius).size();
|
||||||
int user_move = getPlots(plots, radius).size();
|
final int user_move = getPlots(plots, radius).size();
|
||||||
PlayerFunctions.sendMessage(plr, "=== DEFAULT EVAL ===");
|
MainUtil.sendMessage(plr, "=== DEFAULT EVAL ===");
|
||||||
PlayerFunctions.sendMessage(plr, "MINIMUM RADIUS: " + minimum_radius);
|
MainUtil.sendMessage(plr, "MINIMUM RADIUS: " + minimum_radius);
|
||||||
PlayerFunctions.sendMessage(plr, "MAXIMUM MOVES: " + max_move);
|
MainUtil.sendMessage(plr, "MAXIMUM MOVES: " + max_move);
|
||||||
PlayerFunctions.sendMessage(plr, "=== INPUT EVAL ===");
|
MainUtil.sendMessage(plr, "=== INPUT EVAL ===");
|
||||||
PlayerFunctions.sendMessage(plr, "INPUT RADIUS: " + radius);
|
MainUtil.sendMessage(plr, "INPUT RADIUS: " + radius);
|
||||||
PlayerFunctions.sendMessage(plr, "ESTIMATED MOVES: " + user_move);
|
MainUtil.sendMessage(plr, "ESTIMATED MOVES: " + user_move);
|
||||||
PlayerFunctions.sendMessage(plr, "ESTIMATED TIME: " + "No idea, times will drastically change based on the system performance and load");
|
MainUtil.sendMessage(plr, "ESTIMATED TIME: " + "No idea, times will drastically change based on the system performance and load");
|
||||||
PlayerFunctions.sendMessage(plr, "&e - Radius is measured in plot width");
|
MainUtil.sendMessage(plr, "&e - Radius is measured in plot width");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, "/plot condense " + worldname + " <start|stop|info> [radius]");
|
MainUtil.sendMessage(plr, "/plot condense " + worldname + " <start|stop|info> [radius]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<PlotId> getPlots(Collection<Plot> plots, int radius) {
|
public Set<PlotId> getPlots(final Collection<Plot> plots, final int radius) {
|
||||||
HashSet<PlotId> outside = new HashSet<>();
|
final HashSet<PlotId> outside = new HashSet<>();
|
||||||
for (Plot plot : plots) {
|
for (final Plot plot : plots) {
|
||||||
if (plot.id.x > radius || plot.id.x < -radius || plot.id.y > radius || plot.id.y < -radius) {
|
if ((plot.id.x > radius) || (plot.id.x < -radius) || (plot.id.y > radius) || (plot.id.y < -radius)) {
|
||||||
outside.add(plot.id);
|
outside.add(plot.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,7 +197,6 @@ public class Condense extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(final String message) {
|
public static void sendMessage(final String message) {
|
||||||
PlotMain.sendConsoleSenderMessage("&3PlotSquared -> Plot condense&8: &7" + message);
|
PlotSquared.log("&3PlotSquared -> Plot condense&8: &7" + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotSelection;
|
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
|
|
||||||
public class Copy extends SubCommand {
|
|
||||||
|
|
||||||
public Copy() {
|
|
||||||
super(Command.COPY, "Copy a plot", "copy", CommandCategory.ACTIONS, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(final Player plr, final String... args) {
|
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !PlotMain.hasPermission(plr, "plots.admin.command.copy")) {
|
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
assert plot != null;
|
|
||||||
if (plot.settings.isMerged()) {
|
|
||||||
PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
if (PlotSelection.currentSelection.containsKey(plr.getName())) {
|
|
||||||
PlotSelection.currentSelection.remove(plr.getName());
|
|
||||||
}
|
|
||||||
PlotSelection.currentSelection.put(plr.getName(), selection);
|
|
||||||
sendMessage(plr, C.CLIPBOARD_SET);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,45 +18,35 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// 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.PlotSquared;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.generator.HybridPlotManager;
|
|
||||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
||||||
|
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
|
||||||
public class CreateRoadSchematic extends SubCommand {
|
public class CreateRoadSchematic extends SubCommand {
|
||||||
|
|
||||||
public CreateRoadSchematic() {
|
public CreateRoadSchematic() {
|
||||||
super(Command.CREATEROADSCHEMATIC, "Add a road schematic to your world using the road around your current plot", "crs", CommandCategory.DEBUG, true);
|
super(Command.CREATEROADSCHEMATIC, "Add a road schematic to your world using the road around your current plot", "crs", CommandCategory.DEBUG, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player player, final String... args) {
|
public boolean execute(final PlotPlayer player, final String... args) {
|
||||||
|
Location loc = player.getLocation();
|
||||||
if (!PlayerFunctions.isInPlot(player)) {
|
Plot plot = MainUtil.getPlot(loc);
|
||||||
PlayerFunctions.sendMessage(player, C.NOT_IN_PLOT);
|
if (plot == null) {
|
||||||
return false;
|
return sendMessage(player, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
|
if (!(PlotSquared.getPlotWorld(loc.getWorld()) instanceof HybridPlotWorld)) {
|
||||||
if (!(PlotMain.getWorldSettings(player.getWorld()) instanceof HybridPlotWorld)) {
|
|
||||||
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
|
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
|
||||||
}
|
}
|
||||||
|
HybridUtils.manager.setupRoadSchematic(plot);
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(player);
|
MainUtil.update(loc);
|
||||||
|
MainUtil.sendMessage(player, "&6Saved new road schematic");
|
||||||
HybridPlotManager manager = (HybridPlotManager) PlotMain.getPlotManager(player.getWorld());
|
|
||||||
|
|
||||||
manager.setupRoadSchematic(plot);
|
|
||||||
PlotHelper.update(player.getLocation());
|
|
||||||
PlayerFunctions.sendMessage(player, "&6Saved new road schematic");
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package com.intellectualcrafters.plot.commands;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created 2014-11-09 for PlotSquared
|
|
||||||
*
|
|
||||||
* @author Citymonstret
|
|
||||||
*/
|
|
||||||
public class DEOP extends SubCommand {
|
|
||||||
|
|
||||||
public DEOP() {
|
|
||||||
super(Command.DEOP, "Alias for /plot trusted remove", "/plot deop [player]", CommandCategory.ACTIONS, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(final Player plr, final String... args) {
|
|
||||||
if (args.length < 1) {
|
|
||||||
return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + this.usage);
|
|
||||||
}
|
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
|
||||||
}
|
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if (!plot.hasRights(plr)) {
|
|
||||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
|
||||||
}
|
|
||||||
return plr.performCommand("plot trusted remove " + args[0]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,16 +7,15 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.database.MySQL;
|
import com.intellectualcrafters.plot.database.MySQL;
|
||||||
import com.intellectualcrafters.plot.database.SQLManager;
|
import com.intellectualcrafters.plot.database.SQLManager;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.StringComparison;
|
import com.intellectualcrafters.plot.util.StringComparison;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2014-11-15 for PlotSquared
|
* Created 2014-11-15 for PlotSquared
|
||||||
@ -24,31 +23,29 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class Database extends SubCommand {
|
public class Database extends SubCommand {
|
||||||
|
final String[] tables = new String[] { "plot_trusted", "plot_ratings", "plot_comments" };
|
||||||
final String[] tables = new String[]{"plot_trusted", "plot_ratings", "plot_comments"};
|
|
||||||
|
|
||||||
public Database() {
|
public Database() {
|
||||||
super(Command.DATABASE, "Convert/Backup Storage", "database [type] [...details]", CommandCategory.DEBUG, false);
|
super(Command.DATABASE, "Convert/Backup Storage", "database [type] [...details]", CommandCategory.DEBUG, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean sendMessageU(final UUID uuid, final String msg) {
|
private static boolean sendMessageU(final UUID uuid, final String msg) {
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
PlotMain.sendConsoleSenderMessage(msg);
|
PlotSquared.log(msg);
|
||||||
} else {
|
} else {
|
||||||
final Player p = UUIDHandler.uuidWrapper.getPlayer(uuid);
|
final PlotPlayer p = UUIDHandler.getPlayer(uuid);
|
||||||
if ((p != null) && p.isOnline()) {
|
if ((p != null) && p.isOnline()) {
|
||||||
return PlayerFunctions.sendMessage(p, msg);
|
return MainUtil.sendMessage(p, msg);
|
||||||
} else {
|
} else {
|
||||||
return sendMessageU(null, msg);
|
return sendMessageU(null, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void insertPlots(final SQLManager manager, final UUID requester, final Connection c) {
|
public static void insertPlots(final SQLManager manager, final UUID requester, final Connection c) {
|
||||||
final Plugin p = PlotMain.getMain();
|
final java.util.Set<Plot> plots = PlotSquared.getPlots();
|
||||||
final java.util.Set<Plot> plots = PlotMain.getPlots();
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
p.getServer().getScheduler().runTaskAsynchronously(p, new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@ -71,13 +68,13 @@ public class Database extends SubCommand {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
return sendMessage(plr, "/plot database [sqlite/mysql]");
|
return sendMessage(plr, "/plot database [sqlite/mysql]");
|
||||||
}
|
}
|
||||||
final String type = new StringComparison(args[0], new String[]{"mysql", "sqlite"}).getBestMatch().toLowerCase();
|
final String type = new StringComparison(args[0], new String[] { "mysql", "sqlite" }).getBestMatch().toLowerCase();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "mysql":
|
case "mysql":
|
||||||
if (args.length < 6) {
|
if (args.length < 6) {
|
||||||
@ -94,7 +91,7 @@ public class Database extends SubCommand {
|
|||||||
}
|
}
|
||||||
Connection n;
|
Connection n;
|
||||||
try {
|
try {
|
||||||
n = new MySQL(PlotMain.getMain(), host, port, database, username, password).openConnection();
|
n = new MySQL(PlotSquared.THIS, host, port, database, username, password).openConnection();
|
||||||
// Connection
|
// Connection
|
||||||
if (n.isClosed()) {
|
if (n.isClosed()) {
|
||||||
return sendMessage(plr, "Failed to open connection");
|
return sendMessage(plr, "Failed to open connection");
|
||||||
@ -138,12 +135,12 @@ public class Database extends SubCommand {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean sendMessage(final Player player, final String msg) {
|
private boolean sendMessage(final PlotPlayer player, final String msg) {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
PlotMain.sendConsoleSenderMessage(msg);
|
PlotSquared.log(msg);
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(player, msg);
|
MainUtil.sendMessage(player, msg);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -18,34 +18,28 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.Lag;
|
import com.intellectualcrafters.plot.util.Lag;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
|
||||||
import com.intellectualcrafters.plot.util.RUtils;
|
import com.intellectualcrafters.plot.util.RUtils;
|
||||||
|
|
||||||
public class Debug extends SubCommand {
|
public class Debug extends SubCommand {
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
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()).append("\n");
|
msg.append(c.s()).append("\n");
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, msg.toString());
|
MainUtil.sendMessage(plr, msg.toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
StringBuilder information;
|
StringBuilder information;
|
||||||
@ -58,9 +52,12 @@ public class Debug extends SubCommand {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
final StringBuilder worlds = new StringBuilder("");
|
final StringBuilder worlds = new StringBuilder("");
|
||||||
for (final String world : PlotMain.getPlotWorlds()) {
|
for (final String world : PlotSquared.getPlotWorlds()) {
|
||||||
worlds.append(world).append(" ");
|
worlds.append(world).append(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME not sure if we actually need any of this debug info as we should just do a timings report which is more detailed anyway
|
||||||
|
|
||||||
information.append(header);
|
information.append(header);
|
||||||
information.append(getSection(section, "Lag / TPS"));
|
information.append(getSection(section, "Lag / TPS"));
|
||||||
information.append(getLine(line, "Ticks Per Second", Lag.getTPS()));
|
information.append(getLine(line, "Ticks Per Second", Lag.getTPS()));
|
||||||
@ -68,16 +65,7 @@ public class Debug extends SubCommand {
|
|||||||
information.append(getLine(line, "TPS Percentage", (int) Lag.getFullPercentage() + "%"));
|
information.append(getLine(line, "TPS Percentage", (int) Lag.getFullPercentage() + "%"));
|
||||||
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", PlotSquared.getPlots().size()));
|
||||||
// information.append(getLine(line, "PlotWorld Size",
|
|
||||||
// PlotHelper.getWorldFolderSize() + "MB"));
|
|
||||||
for (final String worldname : PlotMain.getPlotWorlds()) {
|
|
||||||
final World world = Bukkit.getWorld(worldname);
|
|
||||||
information.append(getLine(line, "World: " + world.getName() + " size", PlotHelper.getWorldFolderSize(world)));
|
|
||||||
information.append(getLine(line, " - Entities", PlotHelper.getEntities(world)));
|
|
||||||
information.append(getLine(line, " - Loaded Tile Entities", PlotHelper.getTileEntities(world)));
|
|
||||||
information.append(getLine(line, " - Loaded Chunks", PlotHelper.getLoadedChunks(world)));
|
|
||||||
}
|
|
||||||
information.append(getSection(section, "RAM"));
|
information.append(getSection(section, "RAM"));
|
||||||
information.append(getLine(line, "Free Ram", RUtils.getFreeRam() + "MB"));
|
information.append(getLine(line, "Free Ram", RUtils.getFreeRam() + "MB"));
|
||||||
information.append(getLine(line, "Total Ram", RUtils.getTotalRam() + "MB"));
|
information.append(getLine(line, "Total Ram", RUtils.getTotalRam() + "MB"));
|
||||||
@ -86,15 +74,15 @@ public class Debug extends SubCommand {
|
|||||||
information.append(getLine(line, "View all captions", "/plot debug msg"));
|
information.append(getLine(line, "View all captions", "/plot debug msg"));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
PlayerFunctions.sendMessage(plr, information.toString());
|
MainUtil.sendMessage(plr, information.toString());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSection(final String line, final String val) {
|
private String getSection(final String line, final String val) {
|
||||||
return line.replaceAll("%val%", val) + "\n";
|
return line.replaceAll("%val%", val) + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLine(final String line, final String var, final Object val) {
|
private String getLine(final String line, final String var, final Object val) {
|
||||||
return line.replaceAll("%var%", var).replaceAll("%val%", "" + val) + "\n";
|
return line.replaceAll("%var%", var).replaceAll("%val%", "" + val) + "\n";
|
||||||
}
|
}
|
||||||
|
@ -18,164 +18,135 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.Sign;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.object.PlotManager;
|
import com.intellectualcrafters.plot.object.PlotManager;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.AChunkManager;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class DebugClaimTest extends SubCommand {
|
public class DebugClaimTest extends SubCommand {
|
||||||
|
|
||||||
public DebugClaimTest() {
|
public DebugClaimTest() {
|
||||||
super(Command.DEBUGCLAIMTEST, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. Execution time may vary", "debugclaimtest", CommandCategory.DEBUG, false);
|
super(Command.DEBUGCLAIMTEST, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. Execution time may vary", "debugclaimtest", CommandCategory.DEBUG, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
public static boolean claimPlot(final PlotPlayer 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, @SuppressWarnings("unused") final String schematic) {
|
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic) {
|
||||||
final PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot, true);
|
// FIXME call claim event
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
// boolean result = event result
|
||||||
if (!event.isCancelled()) {
|
boolean result = true;
|
||||||
PlotHelper.createPlot(player, plot);
|
|
||||||
PlotHelper.setSign(player, plot);
|
if (!result) {
|
||||||
PlayerFunctions.sendMessage(player, C.CLAIMED);
|
MainUtil.createPlot(player.getUUID(), plot);
|
||||||
|
MainUtil.setSign(player.getName(), plot);
|
||||||
|
MainUtil.sendMessage(player, C.CLAIMED);
|
||||||
if (teleport) {
|
if (teleport) {
|
||||||
PlotMain.teleportPlayer(player, player.getLocation(), plot);
|
MainUtil.teleportPlayer(player, player.getLocation(), plot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return event.isCancelled();
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (plr == null) {
|
if (plr == null) {
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
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 !MainUtil.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}");
|
||||||
}
|
}
|
||||||
final World world = Bukkit.getWorld(args[0]);
|
String world = args[0];
|
||||||
if ((world == null) || !PlotMain.isPlotWorld(world)) {
|
if (!BlockManager.manager.isWorld(world) || !PlotSquared.isPlotWorld(world)) {
|
||||||
return !PlayerFunctions.sendMessage(null, "&cInvalid plot world!");
|
return !MainUtil.sendMessage(null, "&cInvalid plot world!");
|
||||||
}
|
}
|
||||||
|
|
||||||
PlotId min, max;
|
PlotId min, max;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String[] split1 = args[1].split(";");
|
final String[] split1 = args[1].split(";");
|
||||||
final String[] split2 = args[2].split(";");
|
final String[] split2 = args[2].split(";");
|
||||||
|
|
||||||
min = new PlotId(Integer.parseInt(split1[0]), Integer.parseInt(split1[1]));
|
min = new PlotId(Integer.parseInt(split1[0]), Integer.parseInt(split1[1]));
|
||||||
max = new PlotId(Integer.parseInt(split2[0]), Integer.parseInt(split2[1]));
|
max = new PlotId(Integer.parseInt(split2[0]), Integer.parseInt(split2[1]));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return !PlayerFunctions.sendMessage(null, "&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X,Y are the plot coords\nThe conversion will only check the plots in the selected area.");
|
return !MainUtil.sendMessage(null, "&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X,Y are the plot coords\nThe conversion will only check the plots in the selected area.");
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
|
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
|
||||||
PlayerFunctions.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
|
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
|
||||||
|
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||||
final PlotManager manager = PlotMain.getPlotManager(world);
|
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
|
||||||
final PlotWorld plotworld = PlotMain.getWorldSettings(world);
|
|
||||||
|
|
||||||
final ArrayList<Plot> plots = new ArrayList<>();
|
final ArrayList<Plot> plots = new ArrayList<>();
|
||||||
|
for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
|
||||||
for (final PlotId id : PlayerFunctions.getPlotSelectionIds(min, max)) {
|
final Plot plot = MainUtil.getPlot(world, id);
|
||||||
final Plot plot = PlotHelper.getPlot(world, id);
|
final boolean contains = PlotSquared.getPlots(world).containsKey(plot.id);
|
||||||
final boolean contains = PlotMain.getPlots(world).containsKey(plot.id);
|
|
||||||
if (contains) {
|
if (contains) {
|
||||||
PlayerFunctions.sendMessage(null, " - &cDB Already contains: " + plot.id);
|
MainUtil.sendMessage(null, " - &cDB Already contains: " + plot.id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
final Location loc = manager.getSignLoc(plotworld, plot);
|
||||||
final Location loc = manager.getSignLoc(world, plotworld, plot);
|
ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
||||||
|
boolean result = AChunkManager.manager.loadChunk(world, chunk);
|
||||||
final Chunk chunk = world.getChunkAt(loc);
|
if (!result) {
|
||||||
|
continue;
|
||||||
if (!chunk.isLoaded()) {
|
|
||||||
final boolean result = chunk.load(false);
|
|
||||||
if (!result) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
String[] lines = BlockManager.manager.getSign(loc);
|
||||||
final Block block = world.getBlockAt(loc);
|
if (lines != null) {
|
||||||
if (block != null) {
|
String line = lines[2];
|
||||||
if (block.getState() instanceof Sign) {
|
if ((line != null) && (line.length() > 2)) {
|
||||||
final Sign sign = (Sign) block.getState();
|
line = line.substring(2);
|
||||||
String line = sign.getLine(2);
|
final BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
|
||||||
if ((line != null) && (line.length() > 2)) {
|
UUID uuid = (map.get(new StringWrapper(line)));
|
||||||
line = line.substring(2);
|
if (uuid == null) {
|
||||||
|
for (final StringWrapper string : map.keySet()) {
|
||||||
final BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
|
if (string.value.toLowerCase().startsWith(line.toLowerCase())) {
|
||||||
|
uuid = map.get(string);
|
||||||
UUID uuid = (map.get(new StringWrapper(line)));
|
break;
|
||||||
|
|
||||||
if (uuid == null) {
|
|
||||||
for (final StringWrapper string : map.keySet()) {
|
|
||||||
if (string.value.toLowerCase().startsWith(line.toLowerCase())) {
|
|
||||||
uuid = map.get(string);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uuid == null) {
|
}
|
||||||
uuid = UUIDHandler.getUUID(line);
|
if (uuid == null) {
|
||||||
}
|
uuid = UUIDHandler.getUUID(line);
|
||||||
if (uuid != null) {
|
}
|
||||||
PlayerFunctions.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line);
|
if (uuid != null) {
|
||||||
plot.owner = uuid;
|
MainUtil.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line);
|
||||||
plot.hasChanged = true;
|
plot.owner = uuid;
|
||||||
plots.add(plot);
|
plot.hasChanged = true;
|
||||||
} else {
|
plots.add(plot);
|
||||||
PlayerFunctions.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
|
} else {
|
||||||
}
|
MainUtil.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plots.size() > 0) {
|
if (plots.size() > 0) {
|
||||||
PlayerFunctions.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
|
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
|
||||||
DBFunc.createPlots(plots);
|
DBFunc.createPlots(plots);
|
||||||
DBFunc.createAllSettingsAndHelpers(plots);
|
DBFunc.createAllSettingsAndHelpers(plots);
|
||||||
|
|
||||||
for (final Plot plot : plots) {
|
for (final Plot plot : plots) {
|
||||||
PlotMain.updatePlot(plot);
|
PlotSquared.updatePlot(plot);
|
||||||
}
|
}
|
||||||
|
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
|
||||||
PlayerFunctions.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(null, "No plots were found for the given search.");
|
MainUtil.sendMessage(null, "No plots were found for the given search.");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, "&6This command can only be executed by console as it has been deemed unsafe if abused.");
|
MainUtil.sendMessage(plr, "&6This command can only be executed by console as it has been deemed unsafe if abused.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -18,63 +18,57 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.generator.SquarePlotWorld;
|
import com.intellectualcrafters.plot.generator.SquarePlotWorld;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.bukkit.ChunkManager;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
public class DebugClear extends SubCommand {
|
public class DebugClear extends SubCommand {
|
||||||
|
|
||||||
public DebugClear() {
|
public DebugClear() {
|
||||||
super(Command.DEBUGCLEAR, "Clear a plot using a fast experimental algorithm", "debugclear", CommandCategory.DEBUG, false);
|
super(Command.DEBUGCLEAR, "Clear a plot using a fast experimental algorithm", "debugclear", CommandCategory.DEBUG, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (plr == null) {
|
if (plr == null) {
|
||||||
// Is console
|
// Is console
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
PlotMain.sendConsoleSenderMessage("You need to specify two arguments: ID (0;0) & World (world)");
|
PlotSquared.log("You need to specify two arguments: ID (0;0) & World (world)");
|
||||||
} else {
|
} else {
|
||||||
final PlotId id = PlotId.fromString(args[0]);
|
final PlotId id = PlotId.fromString(args[0]);
|
||||||
final String world = args[1];
|
final String world = args[1];
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
PlotMain.sendConsoleSenderMessage("Invalid Plot ID: " + args[0]);
|
PlotSquared.log("Invalid Plot ID: " + args[0]);
|
||||||
} else {
|
} else {
|
||||||
if (!PlotMain.isPlotWorld(world) || !(PlotMain.getWorldSettings(world) instanceof SquarePlotWorld)) {
|
if (!PlotSquared.isPlotWorld(world) || !(PlotSquared.getPlotWorld(world) instanceof SquarePlotWorld)) {
|
||||||
PlotMain.sendConsoleSenderMessage("Invalid plot world: " + world);
|
PlotSquared.log("Invalid plot world: " + world);
|
||||||
} else {
|
} else {
|
||||||
final Plot plot = PlotHelper.getPlot(Bukkit.getWorld(world), id);
|
final Plot plot = MainUtil.getPlot(world, id);
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
PlotMain.sendConsoleSenderMessage("Could not find plot " + args[0] + " in world " + world);
|
PlotSquared.log("Could not find plot " + args[0] + " in world " + world);
|
||||||
} else {
|
} else {
|
||||||
World bukkitWorld = Bukkit.getWorld(world);
|
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
|
||||||
Location pos1 = PlotHelper.getPlotBottomLoc(bukkitWorld, plot.id).add(1, 0, 1);
|
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
|
||||||
Location pos2 = PlotHelper.getPlotTopLoc(bukkitWorld, plot.id);
|
if (MainUtil.runners.containsKey(plot)) {
|
||||||
if (PlotHelper.runners.containsKey(plot)) {
|
MainUtil.sendMessage(null, C.WAIT_FOR_TIMER);
|
||||||
PlayerFunctions.sendMessage(null, C.WAIT_FOR_TIMER);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotHelper.runners.put(plot, 1);
|
MainUtil.runners.put(plot, 1);
|
||||||
ChunkManager.regenerateRegion(pos1, pos2, new Runnable() {
|
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PlotHelper.runners.remove(plot);
|
MainUtil.runners.remove(plot);
|
||||||
PlotMain.sendConsoleSenderMessage("Plot " + plot.getId().toString() + " cleared.");
|
PlotSquared.log("Plot " + plot.getId().toString() + " cleared.");
|
||||||
PlotMain.sendConsoleSenderMessage("&aDone!");
|
PlotSquared.log("&aDone!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -83,38 +77,34 @@ public class DebugClear extends SubCommand {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Location loc = plr.getLocation();
|
||||||
if (!PlayerFunctions.isInPlot(plr) || !(PlotMain.getWorldSettings(plr.getWorld()) instanceof SquarePlotWorld)) {
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
|
if (plot == null || !(PlotSquared.getPlotWorld(loc.getWorld()) instanceof SquarePlotWorld)) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||||
if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
|
|
||||||
return sendMessage(plr, C.UNLINK_REQUIRED);
|
return sendMessage(plr, C.UNLINK_REQUIRED);
|
||||||
}
|
}
|
||||||
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !PlotMain.hasPermission(plr, "plots.admin.command.debugclear")) {
|
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.debugclear")) {
|
||||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
}
|
}
|
||||||
assert plot != null;
|
assert plot != null;
|
||||||
World bukkitWorld = plr.getWorld();
|
final Location pos1 = MainUtil.getPlotBottomLoc(loc.getWorld(), plot.id).add(1, 0, 1);
|
||||||
Location pos1 = PlotHelper.getPlotBottomLoc(bukkitWorld, plot.id).add(1, 0, 1);
|
final Location pos2 = MainUtil.getPlotTopLoc(loc.getWorld(), plot.id);
|
||||||
Location pos2 = PlotHelper.getPlotTopLoc(bukkitWorld, plot.id);
|
if (MainUtil.runners.containsKey(plot)) {
|
||||||
if (PlotHelper.runners.containsKey(plot)) {
|
MainUtil.sendMessage(null, C.WAIT_FOR_TIMER);
|
||||||
PlayerFunctions.sendMessage(null, C.WAIT_FOR_TIMER);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotHelper.runners.put(plot, 1);
|
MainUtil.runners.put(plot, 1);
|
||||||
ChunkManager.regenerateRegion(pos1, pos2, new Runnable() {
|
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PlotHelper.runners.remove(plot);
|
MainUtil.runners.remove(plot);
|
||||||
PlayerFunctions.sendMessage(plr, "&aDone!");
|
MainUtil.sendMessage(plr, "&aDone!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// sign
|
// sign
|
||||||
|
|
||||||
// wall
|
// wall
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -34,129 +33,125 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
|
import com.intellectualcrafters.plot.object.BukkitOfflinePlayer;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
import com.intellectualcrafters.plot.util.ExpireManager;
|
import com.intellectualcrafters.plot.util.ExpireManager;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
public class DebugExec extends SubCommand {
|
public class DebugExec extends SubCommand {
|
||||||
|
|
||||||
private ArrayList<ChunkLoc> chunks = null;
|
|
||||||
private World world;
|
|
||||||
|
|
||||||
public DebugExec() {
|
public DebugExec() {
|
||||||
super("debugexec", "plots.admin", "Multi-purpose debug command", "debugexec", "exec", CommandCategory.DEBUG, false);
|
super("debugexec", "plots.admin", "Multi-purpose debug command", "debugexec", "exec", CommandCategory.DEBUG, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player player, final String... args) {
|
public boolean execute(final PlotPlayer player, final String... args) {
|
||||||
List<String> allowed_params = Arrays.asList(new String[]{"stop-expire","start-expire", "show-expired", "update-expired", "seen", "trim-check"});
|
final List<String> allowed_params = Arrays.asList(new String[] { "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "trim-check" });
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
String arg = args[0].toLowerCase();
|
final String arg = args[0].toLowerCase();
|
||||||
switch (arg) {
|
switch (arg) {
|
||||||
case "stop-expire": {
|
case "stop-expire": {
|
||||||
if (ExpireManager.task != -1) {
|
if (ExpireManager.task != -1) {
|
||||||
Bukkit.getScheduler().cancelTask(ExpireManager.task);
|
Bukkit.getScheduler().cancelTask(ExpireManager.task);
|
||||||
}
|
} else {
|
||||||
else {
|
return MainUtil.sendMessage(null, "Task already halted");
|
||||||
return PlayerFunctions.sendMessage(null, "Task already halted");
|
|
||||||
}
|
|
||||||
ExpireManager.task = -1;
|
|
||||||
return PlayerFunctions.sendMessage(null, "Cancelled task.");
|
|
||||||
}
|
|
||||||
case "start-expire": {
|
|
||||||
if (ExpireManager.task == -1) {
|
|
||||||
ExpireManager.runTask();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return PlayerFunctions.sendMessage(null, "Plot expiry task already started");
|
|
||||||
}
|
|
||||||
return PlayerFunctions.sendMessage(null, "Started plot expiry task");
|
|
||||||
}
|
|
||||||
case "update-expired": {
|
|
||||||
if (args.length > 1) {
|
|
||||||
World world = Bukkit.getWorld(args[1]);
|
|
||||||
if (world == null) {
|
|
||||||
return PlayerFunctions.sendMessage(null, "Invalid world: "+args[1]);
|
|
||||||
}
|
|
||||||
PlayerFunctions.sendMessage(null, "Updating expired plot list");
|
|
||||||
ExpireManager.updateExpired(args[1]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return PlayerFunctions.sendMessage(null, "Use /plot debugexec update-expired <world>");
|
|
||||||
}
|
|
||||||
case "show-expired": {
|
|
||||||
if (args.length > 1) {
|
|
||||||
World world = Bukkit.getWorld(args[1]);
|
|
||||||
if (world == null || !ExpireManager.expiredPlots.containsKey(args[1])) {
|
|
||||||
return PlayerFunctions.sendMessage(null, "Invalid world: "+args[1]);
|
|
||||||
}
|
|
||||||
PlayerFunctions.sendMessage(null, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
|
|
||||||
for (Entry<Plot, Long> entry : ExpireManager.expiredPlots.get(args[1]).entrySet()) {
|
|
||||||
Plot plot = entry.getKey();
|
|
||||||
Long stamp = entry.getValue();
|
|
||||||
PlayerFunctions.sendMessage(null, " - " + plot.world + ";" + plot.id.x + ";" + plot.id.y + ";" + UUIDHandler.getName(plot.owner) +" : " + stamp);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return PlayerFunctions.sendMessage(null, "Use /plot debugexec show-expired <world>");
|
|
||||||
}
|
|
||||||
case "seen": {
|
|
||||||
if (args.length != 2) {
|
|
||||||
return PlayerFunctions.sendMessage(null, "Use /plot debugexec seen <player>");
|
|
||||||
}
|
|
||||||
UUID uuid = UUIDHandler.getUUID(args[1]);
|
|
||||||
if (uuid == null) {
|
|
||||||
return PlayerFunctions.sendMessage(null, "player not found: " + args[1]);
|
|
||||||
}
|
|
||||||
OfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
|
|
||||||
if (op == null || !op.hasPlayedBefore()) {
|
|
||||||
return PlayerFunctions.sendMessage(null, "player hasn't connected before: " + args[1]);
|
|
||||||
}
|
|
||||||
Timestamp stamp = new Timestamp(op.getLastPlayed());
|
|
||||||
Date date = new Date(stamp.getTime());
|
|
||||||
PlayerFunctions.sendMessage(null, "PLAYER: " + args[1]);
|
|
||||||
PlayerFunctions.sendMessage(null, "UUID: " + uuid);
|
|
||||||
PlayerFunctions.sendMessage(null, "Object: " + date.toGMTString());
|
|
||||||
PlayerFunctions.sendMessage(null, "GMT: " + date.toGMTString());
|
|
||||||
PlayerFunctions.sendMessage(null, "Local: " + date.toLocaleString());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case "trim-check": {
|
|
||||||
if (args.length != 2) {
|
|
||||||
PlayerFunctions.sendMessage(null, "Use /plot debugexec trim-check <world>");
|
|
||||||
PlayerFunctions.sendMessage(null, "&7 - Generates a list of regions to trim");
|
|
||||||
return PlayerFunctions.sendMessage(null, "&7 - Run after plot expiry has run");
|
|
||||||
}
|
|
||||||
final World world = Bukkit.getWorld(args[1]);
|
|
||||||
if (world == null || !PlotMain.isPlotWorld(args[1])) {
|
|
||||||
return PlayerFunctions.sendMessage(null, "Invalid world: "+args[1]);
|
|
||||||
}
|
}
|
||||||
final ArrayList<ChunkLoc> empty = new ArrayList<>();
|
ExpireManager.task = -1;
|
||||||
boolean result = Trim.getTrimRegions(empty, world, new Runnable() {
|
return MainUtil.sendMessage(null, "Cancelled task.");
|
||||||
|
}
|
||||||
|
case "start-expire": {
|
||||||
|
if (ExpireManager.task == -1) {
|
||||||
|
ExpireManager.runTask();
|
||||||
|
} else {
|
||||||
|
return MainUtil.sendMessage(null, "Plot expiry task already started");
|
||||||
|
}
|
||||||
|
return MainUtil.sendMessage(null, "Started plot expiry task");
|
||||||
|
}
|
||||||
|
case "update-expired": {
|
||||||
|
if (args.length > 1) {
|
||||||
|
final String world = args[1];
|
||||||
|
if (!BlockManager.manager.isWorld(world)) {
|
||||||
|
return MainUtil.sendMessage(null, "Invalid world: " + args[1]);
|
||||||
|
}
|
||||||
|
MainUtil.sendMessage(null, "Updating expired plot list");
|
||||||
|
ExpireManager.updateExpired(args[1]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return MainUtil.sendMessage(null, "Use /plot debugexec update-expired <world>");
|
||||||
|
}
|
||||||
|
case "show-expired": {
|
||||||
|
if (args.length > 1) {
|
||||||
|
final String world = args[1];
|
||||||
|
if (!BlockManager.manager.isWorld(world)) {
|
||||||
|
return MainUtil.sendMessage(null, "Invalid world: " + args[1]);
|
||||||
|
}
|
||||||
|
if (!ExpireManager.expiredPlots.containsKey(args[1])) {
|
||||||
|
return MainUtil.sendMessage(null, "No task for world: " + args[1]);
|
||||||
|
}
|
||||||
|
MainUtil.sendMessage(null, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
|
||||||
|
for (final Entry<Plot, Long> entry : ExpireManager.expiredPlots.get(args[1]).entrySet()) {
|
||||||
|
final Plot plot = entry.getKey();
|
||||||
|
final Long stamp = entry.getValue();
|
||||||
|
MainUtil.sendMessage(null, " - " + plot.world + ";" + plot.id.x + ";" + plot.id.y + ";" + UUIDHandler.getName(plot.owner) + " : " + stamp);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return MainUtil.sendMessage(null, "Use /plot debugexec show-expired <world>");
|
||||||
|
}
|
||||||
|
case "seen": {
|
||||||
|
if (args.length != 2) {
|
||||||
|
return MainUtil.sendMessage(null, "Use /plot debugexec seen <player>");
|
||||||
|
}
|
||||||
|
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
||||||
|
if (uuid == null) {
|
||||||
|
return MainUtil.sendMessage(null, "player not found: " + args[1]);
|
||||||
|
}
|
||||||
|
BukkitOfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
|
||||||
|
if ((op == null) || op.getLastPlayed() == 0) {
|
||||||
|
return MainUtil.sendMessage(null, "player hasn't connected before: " + args[1]);
|
||||||
|
}
|
||||||
|
final Timestamp stamp = new Timestamp(op.getLastPlayed());
|
||||||
|
final Date date = new Date(stamp.getTime());
|
||||||
|
MainUtil.sendMessage(null, "PLAYER: " + args[1]);
|
||||||
|
MainUtil.sendMessage(null, "UUID: " + uuid);
|
||||||
|
MainUtil.sendMessage(null, "Object: " + date.toGMTString());
|
||||||
|
MainUtil.sendMessage(null, "GMT: " + date.toGMTString());
|
||||||
|
MainUtil.sendMessage(null, "Local: " + date.toLocaleString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case "trim-check": {
|
||||||
|
if (args.length != 2) {
|
||||||
|
MainUtil.sendMessage(null, "Use /plot debugexec trim-check <world>");
|
||||||
|
MainUtil.sendMessage(null, "&7 - Generates a list of regions to trim");
|
||||||
|
return MainUtil.sendMessage(null, "&7 - Run after plot expiry has run");
|
||||||
|
}
|
||||||
|
final String world = args[1];
|
||||||
|
if (!BlockManager.manager.isWorld(world) || !PlotSquared.isPlotWorld(args[1])) {
|
||||||
|
return MainUtil.sendMessage(null, "Invalid world: " + args[1]);
|
||||||
|
}
|
||||||
|
final ArrayList<ChunkLoc> empty = new ArrayList<>();
|
||||||
|
final boolean result = Trim.getTrimRegions(empty, world, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Trim.sendMessage("Processing is complete! Here's how many chunks would be deleted:");
|
Trim.sendMessage("Processing is complete! Here's how many chunks would be deleted:");
|
||||||
Trim.sendMessage(" - MCA #: " + empty.size());
|
Trim.sendMessage(" - MCA #: " + empty.size());
|
||||||
Trim.sendMessage(" - CHUNKS: " + (empty.size() * 1024) + " (max)");
|
Trim.sendMessage(" - CHUNKS: " + (empty.size() * 1024) + " (max)");
|
||||||
Trim.sendMessage("Exporting log for manual approval...");
|
Trim.sendMessage("Exporting log for manual approval...");
|
||||||
final File file = new File(PlotMain.getMain().getDataFolder() + File.separator + "trim.txt");
|
final File file = new File(PlotSquared.IMP.getDirectory() + File.separator + "trim.txt");
|
||||||
PrintWriter writer;
|
PrintWriter writer;
|
||||||
try {
|
try {
|
||||||
writer = new PrintWriter(file);
|
writer = new PrintWriter(file);
|
||||||
String worldname = world.getName();
|
for (final ChunkLoc loc : empty) {
|
||||||
for (ChunkLoc loc : empty) {
|
writer.println(world + "/region/r." + loc.x + "." + loc.z + ".mca");
|
||||||
writer.println(worldname +"/region/r." + loc.x + "." + loc.z +".mca" );
|
|
||||||
}
|
}
|
||||||
writer.close();
|
writer.close();
|
||||||
Trim.sendMessage("File saved to 'plugins/PlotSquared/trim.txt'");
|
Trim.sendMessage("File saved to 'plugins/PlotSquared/trim.txt'");
|
||||||
} catch (FileNotFoundException e) {
|
} catch (final FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Trim.sendMessage("File failed to save! :(");
|
Trim.sendMessage("File failed to save! :(");
|
||||||
}
|
}
|
||||||
@ -166,14 +161,14 @@ public class DebugExec extends SubCommand {
|
|||||||
Trim.sendMessage(" - Add 31 to each number to get the end position");
|
Trim.sendMessage(" - Add 31 to each number to get the end position");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!result) {
|
if (!result) {
|
||||||
PlayerFunctions.sendMessage(null, "Trim task already started!");
|
MainUtil.sendMessage(null, "Trim task already started!");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringUtils.join(allowed_params, "|") + ">");
|
MainUtil.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringUtils.join(allowed_params, "|") + ">");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,65 +18,60 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
|
||||||
public class DebugFixFlags extends SubCommand {
|
public class DebugFixFlags extends SubCommand {
|
||||||
|
|
||||||
public DebugFixFlags() {
|
public DebugFixFlags() {
|
||||||
super(Command.DEBUGFIXFLAGS, "Attempt to fix all flags for a world", "debugclear", CommandCategory.DEBUG, false);
|
super(Command.DEBUGFIXFLAGS, "Attempt to fix all flags for a world", "debugclear", CommandCategory.DEBUG, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (plr != null) {
|
if (plr != null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_CONSOLE);
|
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot debugfixflags <world>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot debugfixflags <world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
World world = Bukkit.getWorld(args[0]);
|
final String world = args[0];
|
||||||
if (world == null || !PlotMain.isPlotWorld(world)) {
|
if (!BlockManager.manager.isWorld(world) || !PlotSquared.isPlotWorld(world)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_WORLD, args[0]);
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD, args[0]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, "&8--- &6Starting task &8 ---");
|
MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---");
|
||||||
for (Plot plot : PlotMain.getPlots(world).values()) {
|
for (final Plot plot : PlotSquared.getPlots(world).values()) {
|
||||||
Set<Flag> flags = plot.settings.flags;
|
final Set<Flag> flags = plot.settings.flags;
|
||||||
ArrayList<Flag> toRemove = new ArrayList<Flag>();
|
final ArrayList<Flag> toRemove = new ArrayList<Flag>();
|
||||||
for (Flag flag : flags) {
|
for (final Flag flag : flags) {
|
||||||
AbstractFlag af = FlagManager.getFlag(flag.getKey());
|
final AbstractFlag af = FlagManager.getFlag(flag.getKey());
|
||||||
if (af == null) {
|
if (af == null) {
|
||||||
toRemove.add(flag);
|
toRemove.add(flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Flag flag : toRemove) {
|
for (final Flag flag : toRemove) {
|
||||||
plot.settings.flags.remove(flag);
|
plot.settings.flags.remove(flag);
|
||||||
}
|
}
|
||||||
if (toRemove.size() > 0) {
|
if (toRemove.size() > 0) {
|
||||||
DBFunc.setFlags(plot.world, plot, plot.settings.flags);
|
DBFunc.setFlags(plot.world, plot, plot.settings.flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, "&aDone!");
|
MainUtil.sendMessage(plr, "&aDone!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,40 +18,37 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class DebugLoadTest extends SubCommand {
|
public class DebugLoadTest extends SubCommand {
|
||||||
|
|
||||||
public DebugLoadTest() {
|
public DebugLoadTest() {
|
||||||
super(Command.DEBUGLOADTEST, "This debug command will force the reload of all plots in the DB", "debugloadtest", CommandCategory.DEBUG, false);
|
super(Command.DEBUGLOADTEST, "This debug command will force the reload of all plots in the DB", "debugloadtest", CommandCategory.DEBUG, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (plr == null) {
|
if (plr == null) {
|
||||||
try {
|
try {
|
||||||
final Field fPlots = PlotMain.class.getDeclaredField("plots");
|
final Field fPlots = PlotSquared.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===");
|
PlotSquared.log("&3===FAILED&3===");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
PlotMain.sendConsoleSenderMessage("&3===END OF STACKTRACE===");
|
PlotSquared.log("&3===END OF STACKTRACE===");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, "&6This command can only be executed by console as it has been deemed unsafe if abused..");
|
MainUtil.sendMessage(plr, "&6This command can only be executed by console as it has been deemed unsafe if abused..");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -18,40 +18,35 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// 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.PlotSquared;
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.generator.HybridPlotManager;
|
|
||||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.AbstractSetBlock;
|
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
|
||||||
public class DebugRoadRegen extends SubCommand {
|
public class DebugRoadRegen extends SubCommand {
|
||||||
|
|
||||||
public DebugRoadRegen() {
|
public DebugRoadRegen() {
|
||||||
super(Command.DEBUGROADREGEN, "Regenerate all road schematic in your current chunk", "debugroadregen", CommandCategory.DEBUG, true);
|
super(Command.DEBUGROADREGEN, "Regenerate all road schematic in your current chunk", "debugroadregen", CommandCategory.DEBUG, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player player, final String... args) {
|
public boolean execute(final PlotPlayer player, final String... args) {
|
||||||
if (!(PlotMain.getWorldSettings(player.getWorld()) instanceof HybridPlotWorld)) {
|
Location loc = player.getLocation();
|
||||||
|
String world = loc.getWorld();
|
||||||
|
if (!(PlotSquared.getPlotWorld(world) instanceof HybridPlotWorld)) {
|
||||||
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
|
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
|
||||||
}
|
}
|
||||||
HybridPlotManager manager = (HybridPlotManager) PlotMain.getPlotManager(player.getWorld());
|
ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
||||||
|
boolean result = HybridUtils.manager.regenerateRoad(world, chunk);
|
||||||
Chunk chunk = player.getLocation().getChunk();
|
|
||||||
boolean result = manager.regenerateRoad(chunk);
|
|
||||||
if (result) {
|
if (result) {
|
||||||
AbstractSetBlock.setBlockManager.update(Arrays.asList(new Chunk[] {chunk}));
|
MainUtil.update(loc);
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(player, "&6Regenerating chunk: "+chunk.getX() + "," + chunk.getZ() + "\n&6 - Result: " + (result == true ? "&aSuccess" : "&cFailed"));
|
MainUtil.sendMessage(player, "&6Regenerating chunk: " + chunk.x + "," + chunk.z + "\n&6 - Result: " + (result == true ? "&aSuccess" : "&cFailed"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,36 +18,33 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class DebugSaveTest extends SubCommand {
|
public class DebugSaveTest extends SubCommand {
|
||||||
|
|
||||||
public DebugSaveTest() {
|
public DebugSaveTest() {
|
||||||
super(Command.DEBUGSAVETEST, "This debug command will force the recreation of all plots in the DB", "debugsavetest", CommandCategory.DEBUG, false);
|
super(Command.DEBUGSAVETEST, "This debug command will force the recreation of all plots in the DB", "debugsavetest", CommandCategory.DEBUG, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (plr == null) {
|
if (plr == null) {
|
||||||
final ArrayList<Plot> plots = new ArrayList<Plot>();
|
final ArrayList<Plot> plots = new ArrayList<Plot>();
|
||||||
plots.addAll(PlotMain.getPlots());
|
plots.addAll(PlotSquared.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");
|
MainUtil.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -18,55 +18,66 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// 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.PlotSquared;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.EconHandler;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
public class Delete extends SubCommand {
|
public class Delete extends SubCommand {
|
||||||
|
|
||||||
public Delete() {
|
public Delete() {
|
||||||
super(Command.DELETE, "Delete a plot", "delete", CommandCategory.ACTIONS, true);
|
super(Command.DELETE, "Delete a plot", "delete", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
|
if (plot == null) {
|
||||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||||
if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
|
|
||||||
return !sendMessage(plr, C.UNLINK_REQUIRED);
|
return !sendMessage(plr, C.UNLINK_REQUIRED);
|
||||||
}
|
}
|
||||||
if ((((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.uuidWrapper.getUUID(plr)))) && !PlotMain.hasPermission(plr, "plots.admin.command.delete")) {
|
if ((((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.uuidWrapper.getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) {
|
||||||
return !sendMessage(plr, C.NO_PLOT_PERMS);
|
return !sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
}
|
}
|
||||||
assert plot != null;
|
assert plot != null;
|
||||||
final PlotWorld pWorld = PlotMain.getWorldSettings(plot.getWorld());
|
final PlotWorld pWorld = PlotSquared.getPlotWorld(plot.world);
|
||||||
if (PlotMain.useEconomy && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.getOwner().equals(UUIDHandler.getUUID(plr))) {
|
if (PlotSquared.economy != null && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.getOwner().equals(UUIDHandler.getUUID(plr))) {
|
||||||
final double c = pWorld.SELL_PRICE;
|
final double c = pWorld.SELL_PRICE;
|
||||||
if (c > 0d) {
|
if (c > 0d) {
|
||||||
final Economy economy = PlotMain.economy;
|
EconHandler.depositPlayer(plr, c);
|
||||||
economy.depositPlayer(plr, c);
|
|
||||||
sendMessage(plr, C.ADDED_BALANCE, c + "");
|
sendMessage(plr, C.ADDED_BALANCE, c + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final boolean result = PlotMain.removePlot(plr.getWorld().getName(), plot.id, true);
|
if (MainUtil.runners.containsKey(plot)) {
|
||||||
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final boolean result = PlotSquared.removePlot(loc.getWorld(), plot.id, true);
|
||||||
|
final long start = System.currentTimeMillis();
|
||||||
if (result) {
|
if (result) {
|
||||||
plot.clear(plr, true);
|
boolean result2 = MainUtil.clearAsPlayer(plot, false, new Runnable() {
|
||||||
DBFunc.delete(plr.getWorld().getName(), plot);
|
@Override
|
||||||
|
public void run() {
|
||||||
|
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!result2) {
|
||||||
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
|
}
|
||||||
|
DBFunc.delete(loc.getWorld(), plot);
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, "Plot deletion has been denied.");
|
MainUtil.sendMessage(plr, "Plot deletion has been denied.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -18,110 +18,104 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.events.PlayerPlotDeniedEvent;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
@SuppressWarnings("deprecation") public class Denied extends SubCommand {
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
|
public class Denied extends SubCommand {
|
||||||
public Denied() {
|
public Denied() {
|
||||||
super(Command.DENIED, "Manage plot helpers", "denied {add|remove} {player}", CommandCategory.ACTIONS, true);
|
super(Command.DENIED, "Manage plot helpers", "denied {add|remove} {player}", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
PlayerFunctions.sendMessage(plr, C.DENIED_NEED_ARGUMENT);
|
MainUtil.sendMessage(plr, C.DENIED_NEED_ARGUMENT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
return true;
|
if (plot == null) {
|
||||||
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if ((plot == null) || !plot.hasOwner()) {
|
if ((plot == null) || !plot.hasOwner()) {
|
||||||
PlayerFunctions.sendMessage(plr, C.PLOT_UNOWNED);
|
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.getOwner().equals(UUIDHandler.getUUID(plr)) && !PlotMain.hasPermission(plr, "plots.admin.command.denied")) {
|
if (!plot.getOwner().equals(UUIDHandler.getUUID(plr)) && !Permissions.hasPermission(plr, "plots.admin.command.denied")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("add")) {
|
if (args[0].equalsIgnoreCase("add")) {
|
||||||
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 (uuid == null) {
|
if (uuid == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.denied.contains(uuid)) {
|
if (!plot.denied.contains(uuid)) {
|
||||||
if (plot.owner.equals(uuid)) {
|
if (plot.owner.equals(uuid)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER);
|
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot.trusted.contains(uuid)) {
|
if (plot.trusted.contains(uuid)) {
|
||||||
plot.trusted.remove(uuid);
|
plot.trusted.remove(uuid);
|
||||||
DBFunc.removeTrusted(plr.getWorld().getName(), plot, uuid);
|
DBFunc.removeTrusted(loc.getWorld(), plot, uuid);
|
||||||
}
|
}
|
||||||
if (plot.helpers.contains(uuid)) {
|
if (plot.helpers.contains(uuid)) {
|
||||||
plot.helpers.remove(uuid);
|
plot.helpers.remove(uuid);
|
||||||
DBFunc.removeHelper(plr.getWorld().getName(), plot, uuid);
|
DBFunc.removeHelper(loc.getWorld(), plot, uuid);
|
||||||
}
|
}
|
||||||
plot.addDenied(uuid);
|
plot.addDenied(uuid);
|
||||||
DBFunc.setDenied(plr.getWorld().getName(), plot, uuid);
|
DBFunc.setDenied(loc.getWorld(), plot, uuid);
|
||||||
final PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, true);
|
//FIXME PlayerPlotDeniedEvent
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
|
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Player player = UUIDHandler.uuidWrapper.getPlayer(uuid);
|
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
||||||
if (!uuid.equals(DBFunc.everyone) && (player != null) && player.isOnline()) {
|
if (!uuid.equals(DBFunc.everyone) && (player != null) && player.isOnline()) {
|
||||||
final Plot pl = PlayerFunctions.getCurrentPlot(player);
|
final Plot pl = MainUtil.getPlot(loc);
|
||||||
if ((pl != null) && pl.id.equals(plot.id)) {
|
if ((pl != null) && pl.id.equals(plot.id)) {
|
||||||
PlayerFunctions.sendMessage(player, C.YOU_BE_DENIED);
|
MainUtil.sendMessage(player, C.YOU_BE_DENIED);
|
||||||
player.teleport(player.getWorld().getSpawnLocation());
|
player.teleport(BlockManager.manager.getSpawn(loc.getWorld()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.DENIED_ADDED);
|
MainUtil.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)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.WAS_NOT_ADDED);
|
MainUtil.sendMessage(plr, C.WAS_NOT_ADDED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
plot.removeDenied(uuid);
|
plot.removeDenied(uuid);
|
||||||
DBFunc.removeDenied(plr.getWorld().getName(), plot, uuid);
|
DBFunc.removeDenied(loc.getWorld(), plot, uuid);
|
||||||
PlayerFunctions.sendMessage(plr, C.DENIED_REMOVED);
|
MainUtil.sendMessage(plr, C.DENIED_REMOVED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
||||||
plot.removeDenied(uuid);
|
plot.removeDenied(uuid);
|
||||||
DBFunc.removeDenied(plr.getWorld().getName(), plot, uuid);
|
DBFunc.removeDenied(loc.getWorld(), plot, uuid);
|
||||||
final PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, false);
|
// FIXME PlayerPlotDeniedEvent
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
MainUtil.sendMessage(plr, C.DENIED_REMOVED);
|
||||||
PlayerFunctions.sendMessage(plr, C.DENIED_REMOVED);
|
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.DENIED_NEED_ARGUMENT);
|
MainUtil.sendMessage(plr, C.DENIED_NEED_ARGUMENT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -26,9 +25,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
||||||
@ -36,17 +33,19 @@ import com.intellectualcrafters.plot.flag.Flag;
|
|||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
import com.intellectualcrafters.plot.flag.FlagValue;
|
import com.intellectualcrafters.plot.flag.FlagValue;
|
||||||
import com.intellectualcrafters.plot.listeners.PlotListener;
|
import com.intellectualcrafters.plot.listeners.PlotListener;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
|
||||||
public class FlagCmd extends SubCommand {
|
public class FlagCmd extends SubCommand {
|
||||||
|
|
||||||
public FlagCmd() {
|
public FlagCmd() {
|
||||||
super(Command.FLAG, "Manage plot flags", "f", CommandCategory.ACTIONS, true);
|
super(Command.FLAG, "Manage plot flags", "f", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player player, final String... args) {
|
public boolean execute(final PlotPlayer player, final String... args) {
|
||||||
/*
|
/*
|
||||||
* plot flag set fly true
|
* plot flag set fly true
|
||||||
* plot flag remove fly
|
* plot flag remove fly
|
||||||
@ -55,172 +54,171 @@ public class FlagCmd extends SubCommand {
|
|||||||
* plot flag list
|
* plot flag list
|
||||||
*/
|
*/
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
PlayerFunctions.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Plot plot = PlayerFunctions.getCurrentPlot(player);
|
Location loc = player.getLocation();
|
||||||
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
PlayerFunctions.sendMessage(player, C.NOT_IN_PLOT);
|
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
sendMessage(player, C.PLOT_NOT_CLAIMED);
|
sendMessage(player, C.PLOT_NOT_CLAIMED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.hasRights(player) && !PlotMain.hasPermission(player, "plots.set.flag.other")) {
|
if (!plot.isAdded(player.getUUID()) && !Permissions.hasPermission(player, "plots.set.flag.other")) {
|
||||||
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other");
|
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "info": {
|
case "info": {
|
||||||
if (!PlotMain.hasPermission(player, "plots.set.flag")) {
|
if (!Permissions.hasPermission(player, "plots.set.flag")) {
|
||||||
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.flag.info");
|
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.info");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
PlayerFunctions.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
AbstractFlag af = FlagManager.getFlag(args[1]);
|
final AbstractFlag af = FlagManager.getFlag(args[1]);
|
||||||
if (af == null) {
|
if (af == null) {
|
||||||
PlayerFunctions.sendMessage(player, C.NOT_VALID_FLAG);
|
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||||
PlayerFunctions.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// flag key
|
// flag key
|
||||||
PlayerFunctions.sendMessage(player, C.FLAG_KEY, af.getKey());
|
MainUtil.sendMessage(player, C.FLAG_KEY, af.getKey());
|
||||||
// flag type
|
// flag type
|
||||||
PlayerFunctions.sendMessage(player, C.FLAG_TYPE, af.value.getClass().getSimpleName());
|
MainUtil.sendMessage(player, C.FLAG_TYPE, af.value.getClass().getSimpleName());
|
||||||
// Flag type description
|
// Flag type description
|
||||||
PlayerFunctions.sendMessage(player, C.FLAG_DESC, af.getValueDesc());
|
MainUtil.sendMessage(player, C.FLAG_DESC, af.getValueDesc());
|
||||||
PlayerFunctions.sendMessage(player, "&cNot implemented.");
|
MainUtil.sendMessage(player, "&cNot implemented.");
|
||||||
}
|
}
|
||||||
case "set": {
|
case "set": {
|
||||||
if (!PlotMain.hasPermission(player, "plots.set.flag")) {
|
if (!Permissions.hasPermission(player, "plots.set.flag")) {
|
||||||
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.set.flag");
|
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
PlayerFunctions.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag set <flag> <value>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag set <flag> <value>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||||
if (af == null) {
|
if (af == null) {
|
||||||
PlayerFunctions.sendMessage(player, C.NOT_VALID_FLAG);
|
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!PlotMain.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||||
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||||
Object parsed = af.parseValueRaw(value);
|
final Object parsed = af.parseValueRaw(value);
|
||||||
if (parsed == null) {
|
if (parsed == null) {
|
||||||
PlayerFunctions.sendMessage(player, "&c" + af.getValueDesc());
|
MainUtil.sendMessage(player, "&c" + af.getValueDesc());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
|
final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
|
||||||
boolean result = FlagManager.addPlotFlag(plot, flag);
|
final boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
PlayerFunctions.sendMessage(player, C.FLAG_NOT_ADDED);
|
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(player, C.FLAG_ADDED);
|
MainUtil.sendMessage(player, C.FLAG_ADDED);
|
||||||
PlotListener.plotEntry(player, plot);
|
PlotListener.plotEntry(player, plot);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "remove": {
|
case "remove": {
|
||||||
if (!PlotMain.hasPermission(player, "plots.flag.remove")) {
|
if (!Permissions.hasPermission(player, "plots.flag.remove")) {
|
||||||
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove");
|
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 2 && args.length != 3) {
|
if ((args.length != 2) && (args.length != 3)) {
|
||||||
PlayerFunctions.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove <flag> [values]");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove <flag> [values]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||||
if (af == null) {
|
if (af == null) {
|
||||||
PlayerFunctions.sendMessage(player, C.NOT_VALID_FLAG);
|
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!PlotMain.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||||
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase());
|
final Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase());
|
||||||
if (flag == null) {
|
if (flag == null) {
|
||||||
PlayerFunctions.sendMessage(player, C.FLAG_NOT_IN_PLOT);
|
MainUtil.sendMessage(player, C.FLAG_NOT_IN_PLOT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length == 3 && flag.getAbstractFlag().isList()) {
|
if ((args.length == 3) && flag.getAbstractFlag().isList()) {
|
||||||
String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||||
((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value);
|
((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value);
|
||||||
DBFunc.setFlags(plot.world, plot, plot.settings.flags);
|
DBFunc.setFlags(plot.world, plot, plot.settings.flags);
|
||||||
}
|
} else {
|
||||||
else {
|
final boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
|
||||||
boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
PlayerFunctions.sendMessage(player, C.FLAG_NOT_REMOVED);
|
MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(player, C.FLAG_REMOVED);
|
MainUtil.sendMessage(player, C.FLAG_REMOVED);
|
||||||
PlotListener.plotEntry(player, plot);
|
PlotListener.plotEntry(player, plot);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "add": {
|
case "add": {
|
||||||
if (!PlotMain.hasPermission(player, "plots.flag.add")) {
|
if (!Permissions.hasPermission(player, "plots.flag.add")) {
|
||||||
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.flag.add");
|
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.add");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
PlayerFunctions.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag add <flag> <values>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag add <flag> <values>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||||
if (af == null) {
|
if (af == null) {
|
||||||
PlayerFunctions.sendMessage(player, C.NOT_VALID_FLAG);
|
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!PlotMain.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||||
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||||
Object parsed = af.parseValueRaw(value);
|
final Object parsed = af.parseValueRaw(value);
|
||||||
if (parsed == null) {
|
if (parsed == null) {
|
||||||
PlayerFunctions.sendMessage(player, "&c" + af.getValueDesc());
|
MainUtil.sendMessage(player, "&c" + af.getValueDesc());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Flag flag = FlagManager.getPlotFlag(plot, args[1].toLowerCase());
|
Flag flag = FlagManager.getPlotFlag(plot, args[1].toLowerCase());
|
||||||
if (flag == null || !flag.getAbstractFlag().isList()) {
|
if ((flag == null) || !flag.getAbstractFlag().isList()) {
|
||||||
flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
|
flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
((FlagValue.ListValue) flag.getAbstractFlag().value).add(flag.getValue(), value);
|
((FlagValue.ListValue) flag.getAbstractFlag().value).add(flag.getValue(), value);
|
||||||
}
|
}
|
||||||
boolean result = FlagManager.addPlotFlag(plot, flag);
|
final boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
PlayerFunctions.sendMessage(player, C.FLAG_NOT_ADDED);
|
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
DBFunc.setFlags(plot.world, plot, plot.settings.flags);
|
DBFunc.setFlags(plot.world, plot, plot.settings.flags);
|
||||||
PlayerFunctions.sendMessage(player, C.FLAG_ADDED);
|
MainUtil.sendMessage(player, C.FLAG_ADDED);
|
||||||
PlotListener.plotEntry(player, plot);
|
PlotListener.plotEntry(player, plot);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "list": {
|
case "list": {
|
||||||
if (!PlotMain.hasPermission(player, "plots.flag.list")) {
|
if (!Permissions.hasPermission(player, "plots.flag.list")) {
|
||||||
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.flag.list");
|
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.list");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
PlayerFunctions.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag list");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag list");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
HashMap<String, ArrayList<String>> flags = new HashMap<>();
|
final HashMap<String, ArrayList<String>> flags = new HashMap<>();
|
||||||
for (AbstractFlag af : FlagManager.getFlags()) {
|
for (final AbstractFlag af : FlagManager.getFlags()) {
|
||||||
String type = af.value.getClass().getSimpleName().replaceAll("Value", "");
|
final String type = af.value.getClass().getSimpleName().replaceAll("Value", "");
|
||||||
if (!flags.containsKey(type)) {
|
if (!flags.containsKey(type)) {
|
||||||
flags.put(type, new ArrayList<String>());
|
flags.put(type, new ArrayList<String>());
|
||||||
}
|
}
|
||||||
@ -228,15 +226,15 @@ public class FlagCmd extends SubCommand {
|
|||||||
}
|
}
|
||||||
String message = "";
|
String message = "";
|
||||||
String prefix = "";
|
String prefix = "";
|
||||||
for (String flag : flags.keySet()) {
|
for (final String flag : flags.keySet()) {
|
||||||
message += prefix + "&6" + flag +": &7" + StringUtils.join(flags.get(flag), ", ");
|
message += prefix + "&6" + flag + ": &7" + StringUtils.join(flags.get(flag), ", ");
|
||||||
prefix = "\n";
|
prefix = "\n";
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(player, message);
|
MainUtil.sendMessage(player, message);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,18 +5,17 @@
|
|||||||
*
|
*
|
||||||
* >> File = Help.java >> Generated by: Citymonstret at 2014-08-11 17:32
|
* >> File = Help.java >> Generated by: Citymonstret at 2014-08-11 17:32
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
|
||||||
public class Help extends SubCommand {
|
public class Help extends SubCommand {
|
||||||
public Help() {
|
public Help() {
|
||||||
super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO, false);
|
super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,45 +18,41 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.events.PlayerPlotHelperEvent;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
public class Helpers extends SubCommand {
|
public class Helpers extends SubCommand {
|
||||||
|
|
||||||
public Helpers() {
|
public Helpers() {
|
||||||
super(Command.HELPERS, "Manage plot helpers", "helpers {add|remove} {player}", CommandCategory.ACTIONS, true);
|
super(Command.HELPERS, "Manage plot helpers", "helpers {add|remove} {player}", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
PlayerFunctions.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
|
MainUtil.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
return true;
|
if (plot == null) {
|
||||||
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if ((plot == null) || !plot.hasOwner()) {
|
if ((plot == null) || !plot.hasOwner()) {
|
||||||
PlayerFunctions.sendMessage(plr, C.PLOT_UNOWNED);
|
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.getOwner().equals(UUIDHandler.getUUID(plr)) && !PlotMain.hasPermission(plr, "plots.admin.command.helpers")) {
|
if (!plot.getOwner().equals(UUIDHandler.getUUID(plr)) && !Permissions.hasPermission(plr, "plots.admin.command.helpers")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("add")) {
|
if (args[0].equalsIgnoreCase("add")) {
|
||||||
@ -67,52 +63,50 @@ public class Helpers extends SubCommand {
|
|||||||
uuid = UUIDHandler.getUUID(args[1]);
|
uuid = UUIDHandler.getUUID(args[1]);
|
||||||
}
|
}
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.helpers.contains(uuid)) {
|
if (!plot.helpers.contains(uuid)) {
|
||||||
if (plot.owner.equals(uuid)) {
|
if (plot.owner.equals(uuid)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER);
|
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot.trusted.contains(uuid)) {
|
if (plot.trusted.contains(uuid)) {
|
||||||
plot.trusted.remove(uuid);
|
plot.trusted.remove(uuid);
|
||||||
DBFunc.removeTrusted(plr.getWorld().getName(), plot, uuid);
|
DBFunc.removeTrusted(loc.getWorld(), plot, uuid);
|
||||||
}
|
}
|
||||||
if (plot.denied.contains(uuid)) {
|
if (plot.denied.contains(uuid)) {
|
||||||
plot.denied.remove(uuid);
|
plot.denied.remove(uuid);
|
||||||
DBFunc.removeDenied(plr.getWorld().getName(), plot, uuid);
|
DBFunc.removeDenied(loc.getWorld(), plot, uuid);
|
||||||
}
|
}
|
||||||
plot.addHelper(uuid);
|
plot.addHelper(uuid);
|
||||||
DBFunc.setHelper(plr.getWorld().getName(), plot, uuid);
|
DBFunc.setHelper(loc.getWorld(), plot, uuid);
|
||||||
final PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, true);
|
// FIXME PlayerPlotHelperEvent
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
|
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.HELPER_ADDED);
|
MainUtil.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)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.WAS_NOT_ADDED);
|
MainUtil.sendMessage(plr, C.WAS_NOT_ADDED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
plot.removeHelper(uuid);
|
plot.removeHelper(uuid);
|
||||||
DBFunc.removeHelper(plr.getWorld().getName(), plot, uuid);
|
DBFunc.removeHelper(loc.getWorld(), plot, uuid);
|
||||||
PlayerFunctions.sendMessage(plr, C.HELPER_REMOVED);
|
MainUtil.sendMessage(plr, C.HELPER_REMOVED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
||||||
plot.removeHelper(uuid);
|
plot.removeHelper(uuid);
|
||||||
DBFunc.removeHelper(plr.getWorld().getName(), plot, uuid);
|
DBFunc.removeHelper(loc.getWorld(), plot, uuid);
|
||||||
final PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, false);
|
// FIXME PlayerPlotHelperEvent
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
MainUtil.sendMessage(plr, C.HELPER_REMOVED);
|
||||||
PlayerFunctions.sendMessage(plr, C.HELPER_REMOVED);
|
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
|
MainUtil.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -18,44 +18,41 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// 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.PlotSquared;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class Home extends SubCommand {
|
public class Home extends SubCommand {
|
||||||
|
|
||||||
public Home() {
|
public Home() {
|
||||||
super(Command.HOME, "Go to your plot", "home {id|alias}", CommandCategory.TELEPORT, true);
|
super(Command.HOME, "Go to your plot", "home {id|alias}", CommandCategory.TELEPORT, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Plot isAlias(final String a) {
|
private Plot isAlias(final String a) {
|
||||||
for (final Plot p : PlotMain.getPlots()) {
|
for (final Plot p : PlotSquared.getPlots()) {
|
||||||
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
|
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, String... args) {
|
public boolean execute(final PlotPlayer plr, String... args) {
|
||||||
final Plot[] plots = PlotMain.getPlots(plr).toArray(new Plot[0]);
|
final Plot[] plots = PlotSquared.getPlots(plr).toArray(new Plot[0]);
|
||||||
if (plots.length == 1) {
|
if (plots.length == 1) {
|
||||||
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[0]);
|
MainUtil.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 {
|
||||||
@ -65,30 +62,29 @@ public class Home extends SubCommand {
|
|||||||
if ((temp = isAlias(args[0])) != null) {
|
if ((temp = isAlias(args[0])) != null) {
|
||||||
if (temp.hasOwner()) {
|
if (temp.hasOwner()) {
|
||||||
if (temp.getOwner().equals(UUIDHandler.getUUID(plr))) {
|
if (temp.getOwner().equals(UUIDHandler.getUUID(plr))) {
|
||||||
teleportPlayer(plr, temp);
|
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_YOUR_PLOT);
|
MainUtil.sendMessage(plr, C.NOT_YOUR_PLOT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
|
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((id > (plots.length)) || (id < 1)) {
|
if ((id > (plots.length)) || (id < 1)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
|
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
teleportPlayer(plr, plots[id - 1]);
|
MainUtil.teleportPlayer(plr, plr.getLocation(), plots[id - 1]);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PLOTS);
|
MainUtil.sendMessage(plr, C.NO_PLOTS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void teleportPlayer(Player player, Plot plot) {
|
public void teleportPlayer(final PlotPlayer player, final Plot plot) {
|
||||||
PlotMain.teleportPlayer(player, player.getLocation(), plot);
|
MainUtil.teleportPlayer(player, player.getLocation(), plot);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -26,63 +25,61 @@ 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.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotComment;
|
import com.intellectualcrafters.plot.object.PlotComment;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
public class Inbox extends SubCommand {
|
public class Inbox extends SubCommand {
|
||||||
|
|
||||||
public Inbox() {
|
public Inbox() {
|
||||||
super(Command.INBOX, "Review the comments for a plot", "inbox", CommandCategory.ACTIONS, true);
|
super(Command.INBOX, "Review the comments for a plot", "inbox", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
boolean report = false;
|
boolean report = false;
|
||||||
if (args.length == 1){
|
if (args.length == 1) {
|
||||||
if (args[0].equalsIgnoreCase("reports")) {
|
if (args[0].equalsIgnoreCase("reports")) {
|
||||||
report = true;
|
report = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!PlayerFunctions.isInPlot(plr) && !report) {
|
Location loc = plr.getLocation();
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
|
if (plot == null && !report) {
|
||||||
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
|
}
|
||||||
|
if ((plot != null) && !plot.hasOwner()) {
|
||||||
|
MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if (plot != null && !plot.hasOwner()) {
|
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer tier;
|
Integer tier;
|
||||||
final UUID uuid = UUIDHandler.getUUID(plr);
|
final UUID uuid = UUIDHandler.getUUID(plr);
|
||||||
if (PlotMain.hasPermission(plr, "plots.comment.admin")) {
|
if (Permissions.hasPermission(plr, "plots.comment.admin")) {
|
||||||
tier = 0;
|
tier = 0;
|
||||||
} else if (plot != null && plot.owner.equals(uuid)) {
|
} else if ((plot != null) && plot.owner.equals(uuid)) {
|
||||||
tier = 1;
|
tier = 1;
|
||||||
} else if (plot != null && plot.helpers.contains(uuid)) {
|
} else if ((plot != null) && plot.helpers.contains(uuid)) {
|
||||||
tier = 2;
|
tier = 2;
|
||||||
} else if (plot != null && plot.trusted.contains(uuid)) {
|
} else if ((plot != null) && plot.trusted.contains(uuid)) {
|
||||||
tier = 3;
|
tier = 3;
|
||||||
} else {
|
} else {
|
||||||
tier = 4;
|
tier = 4;
|
||||||
}
|
}
|
||||||
final boolean below;
|
final boolean below;
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
below = false;
|
below = false;
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "admin":
|
case "admin":
|
||||||
if (tier <= 0) {
|
if (tier <= 0) {
|
||||||
tier = 0;
|
tier = 0;
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.admin");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.admin");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -90,7 +87,7 @@ public class Inbox extends SubCommand {
|
|||||||
if (tier <= 1) {
|
if (tier <= 1) {
|
||||||
tier = 1;
|
tier = 1;
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.owner");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.owner");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -98,7 +95,7 @@ public class Inbox extends SubCommand {
|
|||||||
if (tier <= 2) {
|
if (tier <= 2) {
|
||||||
tier = 2;
|
tier = 2;
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.helper");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.helper");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -106,7 +103,7 @@ public class Inbox extends SubCommand {
|
|||||||
if (tier <= 3) {
|
if (tier <= 3) {
|
||||||
tier = 3;
|
tier = 3;
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.trusted");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.trusted");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -114,49 +111,44 @@ public class Inbox extends SubCommand {
|
|||||||
if (tier <= 4) {
|
if (tier <= 4) {
|
||||||
tier = 4;
|
tier = 4;
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.everyone");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.everyone");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "reports":
|
case "reports":
|
||||||
if (tier <= 0) {
|
if (tier <= 0) {
|
||||||
tier = -1;
|
tier = -1;
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.admin");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.admin");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_INBOX, Arrays.copyOfRange(new String[]{"admin", "owner", "helper", "trusted", "everyone"}, Math.max(0, tier), 4));
|
MainUtil.sendMessage(plr, C.INVALID_INBOX, Arrays.copyOfRange(new String[] { "admin", "owner", "helper", "trusted", "everyone" }, Math.max(0, tier), 4));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
below = true;
|
||||||
}
|
}
|
||||||
else {
|
final String world = loc.getWorld();
|
||||||
below = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String world = plr.getWorld().getName();
|
|
||||||
final int tier2 = tier;
|
final int tier2 = tier;
|
||||||
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(PlotMain.getMain(), new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ArrayList<PlotComment> comments = null;
|
ArrayList<PlotComment> comments = null;
|
||||||
if (tier2 == -1) {
|
if (tier2 == -1) {
|
||||||
comments = DBFunc.getComments(world, null, 0, false);
|
comments = DBFunc.getComments(world, null, 0, false);
|
||||||
}
|
} else {
|
||||||
else {
|
comments = plot.settings.getComments(tier2);
|
||||||
comments = plot.settings.getComments(tier2);
|
}
|
||||||
}
|
|
||||||
if (comments == null) {
|
if (comments == null) {
|
||||||
comments = DBFunc.getComments(world, plot, tier2, below);
|
comments = DBFunc.getComments(world, plot, tier2, below);
|
||||||
plot.settings.setComments(comments);
|
plot.settings.setComments(comments);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
final String[] split = args[1].toLowerCase().split(":");
|
final String[] split = args[1].toLowerCase().split(":");
|
||||||
if (!split[0].equals("clear")) {
|
if (!split[0].equals("clear")) {
|
||||||
PlayerFunctions.sendMessage(plr, "&c/plot inbox [tier] [clear][:#]");
|
MainUtil.sendMessage(plr, "&c/plot inbox [tier] [clear][:#]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
@ -165,10 +157,10 @@ public class Inbox extends SubCommand {
|
|||||||
final PlotComment comment = comments.get(index - 1);
|
final PlotComment comment = comments.get(index - 1);
|
||||||
DBFunc.removeComment(world, plot, comment);
|
DBFunc.removeComment(world, plot, comment);
|
||||||
plot.settings.removeComment(comment);
|
plot.settings.removeComment(comment);
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMENT_REMOVED, "1 comment");
|
MainUtil.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][:#]");
|
MainUtil.sendMessage(plr, "&cInvalid index:\n/plot inbox [tier] [clear][:#]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,7 +168,7 @@ public class Inbox extends SubCommand {
|
|||||||
DBFunc.removeComment(world, plot, comment);
|
DBFunc.removeComment(world, plot, comment);
|
||||||
}
|
}
|
||||||
plot.settings.removeComments(comments);
|
plot.settings.removeComments(comments);
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMENT_REMOVED, "all comments in that category");
|
MainUtil.sendMessage(plr, C.COMMENT_REMOVED, "all comments in that category");
|
||||||
} else {
|
} else {
|
||||||
final List<String> recipients = Arrays.asList("A", "O", "H", "T", "E");
|
final List<String> recipients = Arrays.asList("A", "O", "H", "T", "E");
|
||||||
int count = 1;
|
int count = 1;
|
||||||
@ -190,7 +182,7 @@ public class Inbox extends SubCommand {
|
|||||||
if (comments.size() == 0) {
|
if (comments.size() == 0) {
|
||||||
message.append("&cNo messages.");
|
message.append("&cNo messages.");
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, message.toString());
|
MainUtil.sendMessage(plr, message.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -18,106 +18,97 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Biome;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
import com.intellectualcrafters.plot.object.InfoInventory;
|
import com.intellectualcrafters.plot.object.InfoInventory;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"javadoc"}) public class Info extends SubCommand {
|
@SuppressWarnings({ "javadoc" })
|
||||||
|
public class Info extends SubCommand {
|
||||||
public Info() {
|
public Info() {
|
||||||
super(Command.INFO, "Display plot info", "info", CommandCategory.INFO, false);
|
super(Command.INFO, "Display plot info", "info", CommandCategory.INFO, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player player, String... args) {
|
public boolean execute(final PlotPlayer player, String... args) {
|
||||||
World world;
|
|
||||||
Plot plot;
|
Plot plot;
|
||||||
|
String world;
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
world = player.getWorld();
|
Location loc = player.getLocation();
|
||||||
if (!PlotMain.isPlotWorld(world)) {
|
world = loc.getWorld();
|
||||||
PlayerFunctions.sendMessage(player, C.NOT_IN_PLOT_WORLD);
|
if (!PlotSquared.isPlotWorld(world)) {
|
||||||
|
MainUtil.sendMessage(player, C.NOT_IN_PLOT_WORLD);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!PlayerFunctions.isInPlot(player)) {
|
plot = MainUtil.getPlot(loc);
|
||||||
PlayerFunctions.sendMessage(player, C.NOT_IN_PLOT);
|
if (plot == null) {
|
||||||
return false;
|
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
plot = PlayerFunctions.getCurrentPlot(player);
|
|
||||||
} else {
|
} else {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
PlayerFunctions.sendMessage(null, C.INFO_SYNTAX_CONSOLE);
|
MainUtil.sendMessage(null, C.INFO_SYNTAX_CONSOLE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlotWorld plotworld = PlotMain.getWorldSettings(args[0]);
|
final PlotWorld plotworld = PlotSquared.getPlotWorld(args[0]);
|
||||||
if (plotworld == null) {
|
if (plotworld == null) {
|
||||||
PlayerFunctions.sendMessage(player, C.NOT_VALID_WORLD);
|
MainUtil.sendMessage(player, C.NOT_VALID_WORLD);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final String[] split = args[1].split(";");
|
final String[] split = args[1].split(";");
|
||||||
final PlotId id = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
final PlotId id = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||||
plot = PlotHelper.getPlot(Bukkit.getWorld(plotworld.worldname), id);
|
plot = MainUtil.getPlot(plotworld.worldname, id);
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
PlayerFunctions.sendMessage(player, C.NOT_VALID_PLOT_ID);
|
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_ID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
world = Bukkit.getWorld(args[0]);
|
world = 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);
|
MainUtil.sendMessage(player, C.INFO_SYNTAX_CONSOLE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((args.length == 1) && args[0].equalsIgnoreCase("inv")) {
|
if ((args.length == 1) && args[0].equalsIgnoreCase("inv")) {
|
||||||
new InfoInventory(plot, player).build().display();
|
new InfoInventory(plot, player).build().display();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean hasOwner = plot.hasOwner();
|
final boolean hasOwner = plot.hasOwner();
|
||||||
boolean containsEveryone;
|
boolean containsEveryone;
|
||||||
boolean trustedEveryone;
|
boolean trustedEveryone;
|
||||||
|
|
||||||
// Wildcard player {added}
|
// Wildcard player {added}
|
||||||
{
|
{
|
||||||
containsEveryone = (plot.helpers != null) && plot.helpers.contains(DBFunc.everyone);
|
containsEveryone = (plot.helpers != null) && plot.helpers.contains(DBFunc.everyone);
|
||||||
trustedEveryone = (plot.trusted != null) && plot.trusted.contains(DBFunc.everyone);
|
trustedEveryone = (plot.trusted != null) && plot.trusted.contains(DBFunc.everyone);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unclaimed?
|
// Unclaimed?
|
||||||
if (!hasOwner && !containsEveryone && !trustedEveryone) {
|
if (!hasOwner && !containsEveryone && !trustedEveryone) {
|
||||||
PlayerFunctions.sendMessage(player, C.PLOT_INFO_UNCLAIMED, (plot.id.x + ";" + plot.id.y));
|
MainUtil.sendMessage(player, C.PLOT_INFO_UNCLAIMED, (plot.id.x + ";" + plot.id.y));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String owner = "none";
|
String owner = "none";
|
||||||
if (plot.owner != null) {
|
if (plot.owner != null) {
|
||||||
owner = UUIDHandler.getName(plot.owner);
|
owner = UUIDHandler.getName(plot.owner);
|
||||||
@ -126,21 +117,19 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
owner = plot.owner.toString();
|
owner = plot.owner.toString();
|
||||||
}
|
}
|
||||||
String info = C.PLOT_INFO.s();
|
String info = C.PLOT_INFO.s();
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
info = getCaption(args[0].toLowerCase());
|
info = getCaption(args[0].toLowerCase());
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
PlayerFunctions.sendMessage(player, "&6Categories&7: &ahelpers&7, &aalias&7, &abiome&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, &aowner&7, &arating");
|
MainUtil.sendMessage(player, "&6Categories&7: &ahelpers&7, &aalias&7, &abiome&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, &aowner&7, &arating");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info = format(info, world, plot, player);
|
info = format(info, world, plot, player);
|
||||||
PlayerFunctions.sendMessage(player, C.PLOT_INFO_HEADER);
|
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER);
|
||||||
PlayerFunctions.sendMessage(player, info, false);
|
MainUtil.sendMessage(player, info, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCaption(final String string) {
|
private String getCaption(final String string) {
|
||||||
switch (string) {
|
switch (string) {
|
||||||
case "helpers":
|
case "helpers":
|
||||||
@ -167,21 +156,19 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String format(String info, final World world, final Plot plot, final Player player) {
|
private String format(String info, final String world, final Plot plot, final PlotPlayer player) {
|
||||||
|
|
||||||
final PlotId id = plot.id;
|
final PlotId id = plot.id;
|
||||||
final PlotId id2 = PlayerFunctions.getTopPlot(world, plot).id;
|
final PlotId id2 = MainUtil.getTopPlot(plot).id;
|
||||||
final int num = PlayerFunctions.getPlotSelectionIds(id, id2).size();
|
final int num = MainUtil.getPlotSelectionIds(id, id2).size();
|
||||||
final String alias = plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : "none";
|
final String alias = plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : "none";
|
||||||
final String biome = getBiomeAt(plot).toString();
|
final String biome = BlockManager.manager.getBiome(MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1));
|
||||||
final String helpers = getPlayerList(plot.helpers);
|
final String helpers = getPlayerList(plot.helpers);
|
||||||
final String trusted = getPlayerList(plot.trusted);
|
final String trusted = getPlayerList(plot.trusted);
|
||||||
final String denied = getPlayerList(plot.denied);
|
final String denied = getPlayerList(plot.denied);
|
||||||
final String rating = String.format("%.1f", DBFunc.getRatings(plot));
|
final String rating = String.format("%.1f", DBFunc.getRatings(plot));
|
||||||
final String flags = "&6" + (StringUtils.join(FlagManager.getPlotFlags(plot), "").length() > 0 ? StringUtils.join(FlagManager.getPlotFlags(plot), "&7, &6") : "none");
|
final String flags = "&6" + (StringUtils.join(FlagManager.getPlotFlags(plot), "").length() > 0 ? StringUtils.join(FlagManager.getPlotFlags(plot), "&7, &6") : "none");
|
||||||
final boolean build = (player == null) || plot.hasRights(player);
|
final boolean build = (player == null) || plot.isAdded(player.getUUID());
|
||||||
|
|
||||||
String owner = "none";
|
String owner = "none";
|
||||||
if (plot.owner != null) {
|
if (plot.owner != null) {
|
||||||
owner = UUIDHandler.getName(plot.owner);
|
owner = UUIDHandler.getName(plot.owner);
|
||||||
@ -189,7 +176,6 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
owner = plot.owner.toString();
|
owner = plot.owner.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
info = info.replaceAll("%alias%", alias);
|
info = info.replaceAll("%alias%", alias);
|
||||||
info = info.replaceAll("%id%", id.toString());
|
info = info.replaceAll("%id%", id.toString());
|
||||||
info = info.replaceAll("%id2%", id2.toString());
|
info = info.replaceAll("%id2%", id2.toString());
|
||||||
@ -203,10 +189,9 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
info = info.replaceAll("%flags%", flags);
|
info = info.replaceAll("%flags%", flags);
|
||||||
info = info.replaceAll("%build%", build + "");
|
info = info.replaceAll("%build%", build + "");
|
||||||
info = info.replaceAll("%desc%", "No description set.");
|
info = info.replaceAll("%desc%", "No description set.");
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPlayerList(final ArrayList<UUID> l) {
|
private String getPlayerList(final ArrayList<UUID> l) {
|
||||||
if ((l == null) || (l.size() < 1)) {
|
if ((l == null) || (l.size() < 1)) {
|
||||||
return " none";
|
return " none";
|
||||||
@ -222,7 +207,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
}
|
}
|
||||||
return list.toString();
|
return list.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPlayerName(final UUID uuid) {
|
private String getPlayerName(final UUID uuid) {
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
return "unknown";
|
return "unknown";
|
||||||
@ -230,16 +215,10 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
if (uuid.equals(DBFunc.everyone) || uuid.toString().equalsIgnoreCase(DBFunc.everyone.toString())) {
|
if (uuid.equals(DBFunc.everyone) || uuid.toString().equalsIgnoreCase(DBFunc.everyone.toString())) {
|
||||||
return "everyone";
|
return "everyone";
|
||||||
}
|
}
|
||||||
String name = UUIDHandler.getName(uuid);
|
final String name = UUIDHandler.getName(uuid);
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Biome getBiomeAt(final Plot plot) {
|
|
||||||
final World w = Bukkit.getWorld(plot.world);
|
|
||||||
final Location bl = PlotHelper.getPlotTopLoc(w, plot.id);
|
|
||||||
return bl.getBlock().getBiome();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -26,18 +25,19 @@ 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;
|
||||||
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;
|
||||||
|
|
||||||
public class Inventory extends SubCommand {
|
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
|
||||||
|
public class Inventory extends SubCommand {
|
||||||
public Inventory() {
|
public Inventory() {
|
||||||
super("inventory", "plots.inventory", "Open a command inventory", "inventory", "inv", CommandCategory.INFO, true);
|
super("inventory", "plots.inventory", "Open a command inventory", "inventory", "inv", CommandCategory.INFO, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
final ArrayList<SubCommand> cmds = new ArrayList<>();
|
final ArrayList<SubCommand> cmds = new ArrayList<>();
|
||||||
for (final SubCommand cmd : MainCommand.subCommands) {
|
for (final SubCommand cmd : MainCommand.subCommands) {
|
||||||
if (cmd.permission.hasPermission(plr)) {
|
if (cmd.permission.hasPermission(plr)) {
|
||||||
@ -49,10 +49,11 @@ public class Inventory extends SubCommand {
|
|||||||
for (final SubCommand cmd : cmds) {
|
for (final SubCommand cmd : cmds) {
|
||||||
inventory.addItem(getItem(cmd));
|
inventory.addItem(getItem(cmd));
|
||||||
}
|
}
|
||||||
plr.openInventory(inventory);
|
// FIXME unchecked cast
|
||||||
|
((BukkitPlayer) plr).player.openInventory(inventory);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack getItem(final SubCommand cmd) {
|
private ItemStack getItem(final SubCommand cmd) {
|
||||||
final ItemStack stack = new ItemStack(Material.COMMAND);
|
final ItemStack stack = new ItemStack(Material.COMMAND);
|
||||||
final ItemMeta meta = stack.getItemMeta();
|
final ItemMeta meta = stack.getItemMeta();
|
||||||
|
@ -18,49 +18,48 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// 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.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
@SuppressWarnings({"unused", "deprecation", "javadoc"}) public class Kick extends SubCommand {
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
|
@SuppressWarnings({ "unused", "deprecation", "javadoc" })
|
||||||
|
public class Kick extends SubCommand {
|
||||||
public Kick() {
|
public Kick() {
|
||||||
super(Command.KICK, "Kick a player from your plot", "kick", CommandCategory.ACTIONS, true);
|
super(Command.KICK, "Kick a player from your plot", "kick", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
return false;
|
if (plot == null) {
|
||||||
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.kick")) {
|
||||||
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !PlotMain.hasPermission(plr, "plots.admin.command.kick")) {
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
PlayerFunctions.sendMessage(plr, "&c/plot kick <player>");
|
MainUtil.sendMessage(plr, "&c/plot kick <player>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Bukkit.getPlayer(args[0]) == null) {
|
PlotPlayer player = UUIDHandler.getPlayer(args[0]);
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
if (player == null) {
|
||||||
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Player player = Bukkit.getPlayer(args[0]);
|
if (!player.getLocation().getWorld().equals(loc.getWorld()) || !plot.equals(MainUtil.getPlot(loc))) {
|
||||||
if (!player.getWorld().equals(plr.getWorld()) || !PlayerFunctions.isInPlot(player) || (PlayerFunctions.getCurrentPlot(player) == null) || !PlayerFunctions.getCurrentPlot(player).equals(plot)) {
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER.s().replaceAll("%player%", args[0]));
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER.s().replaceAll("%player%", args[0]));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
player.teleport(player.getWorld().getSpawnLocation());
|
player.teleport(BlockManager.manager.getSpawn(loc.getWorld()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,63 +18,53 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
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 org.bukkit.ChatColor;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.TabCompleter;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.intellectualcrafters.plot.util.StringComparison;
|
import com.intellectualcrafters.plot.util.StringComparison;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlotMain command class
|
* PlotSquared command class
|
||||||
*
|
*
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class MainCommand implements CommandExecutor, TabCompleter {
|
public class MainCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Permission Node
|
* Main Permission Node
|
||||||
*/
|
*/
|
||||||
public static final String MAIN_PERMISSION = "plots.use";
|
private final static SubCommand[] _subCommands = new SubCommand[] { new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Claim(), 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 Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense() };
|
||||||
|
|
||||||
private final static SubCommand[] _subCommands = new SubCommand[]{new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Ban(), new Unban(), new OP(), new DEOP(), new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense() };
|
|
||||||
|
|
||||||
public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
||||||
{
|
{
|
||||||
addAll(Arrays.asList(_subCommands));
|
addAll(Arrays.asList(_subCommands));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static boolean no_permission(final Player player, final String permission) {
|
public static boolean no_permission(final PlotPlayer player, final String permission) {
|
||||||
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, permission);
|
MainUtil.sendMessage(player, C.NO_PERMISSION, permission);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final Player player) {
|
public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final PlotPlayer 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.isPlayer || player != null) {
|
if (!c.isPlayer || (player != null)) {
|
||||||
if ((c.category.equals(category)) && c.permission.hasPermission(player)) {
|
if ((c.category.equals(category)) && c.permission.hasPermission(player)) {
|
||||||
cmds.add(c);
|
cmds.add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cmds;
|
return cmds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> helpMenu(final Player player, final SubCommand.CommandCategory category, int page) {
|
public static List<String> helpMenu(final PlotPlayer player, final SubCommand.CommandCategory category, int page) {
|
||||||
List<SubCommand> commands;
|
List<SubCommand> commands;
|
||||||
if (category != null) {
|
if (category != null) {
|
||||||
commands = getCommands(category, player);
|
commands = getCommands(category, player);
|
||||||
@ -92,15 +82,11 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
if (max > commands.size()) {
|
if (max > commands.size()) {
|
||||||
max = commands.size();
|
max = commands.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<String> help = new ArrayList<>();
|
final List<String> help = new ArrayList<>();
|
||||||
|
|
||||||
help.add(C.HELP_HEADER.s());
|
help.add(C.HELP_HEADER.s());
|
||||||
// HELP_CATEGORY("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"),
|
// HELP_CATEGORY("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"),
|
||||||
help.add(C.HELP_CATEGORY.s().replace("%category%", category == null ? "All" : category.toString()).replace("%current%", "" + (page + 1)).replace("%max%", "" + (totalPages + 1)).replace("%dis%", "" + (commands.size() % perPage)).replace("%total%", "" + commands.size()));
|
help.add(C.HELP_CATEGORY.s().replace("%category%", category == null ? "All" : category.toString()).replace("%current%", "" + (page + 1)).replace("%max%", "" + (totalPages + 1)).replace("%dis%", "" + (commands.size() % perPage)).replace("%total%", "" + commands.size()));
|
||||||
|
|
||||||
SubCommand cmd;
|
SubCommand cmd;
|
||||||
|
|
||||||
final int start = page * perPage;
|
final int start = page * perPage;
|
||||||
for (int x = start; x < max; x++) {
|
for (int x = start; x < max; x++) {
|
||||||
cmd = commands.get(x);
|
cmd = commands.get(x);
|
||||||
@ -113,19 +99,15 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
return help;
|
return help;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String t(final String s) {
|
private static String t(final String s) {
|
||||||
return ChatColor.translateAlternateColorCodes('&', s);
|
return MainUtil.colorise('&', s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static boolean onCommand(final PlotPlayer player, final String cmd, final String... args) {
|
||||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) {
|
if (!Permissions.hasPermission(player, PlotSquared.MAIN_PERMISSION)) {
|
||||||
final Player player = (sender instanceof Player) ? (Player) sender : null;
|
return no_permission(player, PlotSquared.MAIN_PERMISSION);
|
||||||
|
|
||||||
if (!PlotMain.hasPermission(player, MAIN_PERMISSION)) {
|
|
||||||
return no_permission(player, MAIN_PERMISSION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
|
if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
@ -134,7 +116,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
||||||
}
|
}
|
||||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", "all").replaceAll("%category_desc%", "Display all commands"));
|
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", "all").replaceAll("%category_desc%", "Display all commands"));
|
||||||
return PlayerFunctions.sendMessage(player, builder.toString());
|
return MainUtil.sendMessage(player, builder.toString());
|
||||||
}
|
}
|
||||||
final String cat = args[1];
|
final String cat = args[1];
|
||||||
SubCommand.CommandCategory cato = null;
|
SubCommand.CommandCategory cato = null;
|
||||||
@ -144,26 +126,23 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cato == null && !cat.equalsIgnoreCase("all")) {
|
if ((cato == null) && !cat.equalsIgnoreCase("all")) {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
builder.append(C.HELP_INFO.s());
|
builder.append(C.HELP_INFO.s());
|
||||||
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
||||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
||||||
}
|
}
|
||||||
return PlayerFunctions.sendMessage(player, builder.toString(), false);
|
return MainUtil.sendMessage(player, builder.toString(), false);
|
||||||
}
|
}
|
||||||
final StringBuilder help = new StringBuilder();
|
final StringBuilder help = new StringBuilder();
|
||||||
int page = 0;
|
int page = 0;
|
||||||
|
|
||||||
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";
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final char c : arg2.toCharArray()) {
|
for (final char c : arg2.toCharArray()) {
|
||||||
if (!Character.isDigit(c)) {
|
if (!Character.isDigit(c)) {
|
||||||
digit = false;
|
digit = false;
|
||||||
@ -176,11 +155,10 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
page = 0;
|
page = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final String string : helpMenu(player, cato, page)) {
|
for (final String string : helpMenu(player, cato, page)) {
|
||||||
help.append(string).append("\n");
|
help.append(string).append("\n");
|
||||||
}
|
}
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', help.toString()));
|
player.sendMessage(MainUtil.colorise('&', help.toString()));
|
||||||
// return PlayerFunctions.sendMessage(player, help.toString());
|
// return PlayerFunctions.sendMessage(player, help.toString());
|
||||||
} else {
|
} else {
|
||||||
for (final SubCommand command : subCommands) {
|
for (final SubCommand command : subCommands) {
|
||||||
@ -191,61 +169,24 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
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 !MainUtil.sendMessage(null, C.IS_CONSOLE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return no_permission(player, command.permission.permission.toLowerCase());
|
return no_permission(player, command.permission.permission.toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(player, C.NOT_VALID_SUBCOMMAND);
|
MainUtil.sendMessage(player, C.NOT_VALID_SUBCOMMAND);
|
||||||
|
|
||||||
final String[] commands = new String[subCommands.size()];
|
final String[] commands = new String[subCommands.size()];
|
||||||
for (int x = 0; x < subCommands.size(); x++) {
|
for (int x = 0; x < subCommands.size(); x++) {
|
||||||
commands[x] = subCommands.get(x).cmd;
|
commands[x] = subCommands.get(x).cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Let's try to get a proper usage string */
|
/* Let's try to get a proper usage string */
|
||||||
final String command = new StringComparison(args[0], commands).getBestMatch();
|
final String command = new StringComparison(args[0], commands).getBestMatch();
|
||||||
return PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, "/plot " + command);
|
return MainUtil.sendMessage(player, C.DID_YOU_MEAN, "/plot " + command);
|
||||||
// PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new
|
// PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new
|
||||||
// StringComparsion(args[0], commands).getBestMatch());
|
// StringComparsion(args[0], commands).getBestMatch());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> onTabComplete(final CommandSender commandSender, final Command command, final String s, final String[] strings) {
|
|
||||||
if (!(commandSender instanceof Player)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final Player player = (Player) commandSender;
|
|
||||||
|
|
||||||
if (strings.length < 1) {
|
|
||||||
if ((strings.length == 0) || "plots".startsWith(s)) {
|
|
||||||
return Arrays.asList("plots");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (strings.length > 1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!command.getLabel().equalsIgnoreCase("plots")) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final List<String> tabOptions = new ArrayList<>();
|
|
||||||
final String arg = strings[0].toLowerCase();
|
|
||||||
for (final SubCommand cmd : subCommands) {
|
|
||||||
if (cmd.permission.hasPermission(player)) {
|
|
||||||
if (cmd.cmd.startsWith(arg)) {
|
|
||||||
tabOptions.add(cmd.cmd);
|
|
||||||
} else if (cmd.alias.get(0).startsWith(arg)) {
|
|
||||||
tabOptions.add(cmd.alias.get(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tabOptions.size() > 0) {
|
|
||||||
return tabOptions;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -26,32 +25,30 @@ import java.util.ArrayList;
|
|||||||
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.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.events.PlotMergeEvent;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.EconHandler;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class Merge extends SubCommand {
|
public class Merge extends SubCommand {
|
||||||
|
public final static String[] values = new String[] { "north", "east", "south", "west" };
|
||||||
public final static String[] values = new String[]{"north", "east", "south", "west"};
|
public final static String[] aliases = new String[] { "n", "e", "s", "w" };
|
||||||
public final static String[] aliases = new String[]{"n", "e", "s", "w"};
|
|
||||||
|
|
||||||
public Merge() {
|
public Merge() {
|
||||||
super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS, true);
|
super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String direction(float yaw) {
|
public static String direction(float yaw) {
|
||||||
yaw = yaw / 90;
|
yaw = yaw / 90;
|
||||||
final int i = Math.round(yaw);
|
final int i = Math.round(yaw);
|
||||||
@ -73,26 +70,26 @@ public class Merge extends SubCommand {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
return true;
|
if (plot == null) {
|
||||||
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if ((plot == null) || !plot.hasOwner()) {
|
if ((plot == null) || !plot.hasOwner()) {
|
||||||
PlayerFunctions.sendMessage(plr, C.PLOT_UNOWNED);
|
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean admin = PlotMain.hasPermission(plr, "plots.admin.command.merge");
|
final boolean admin = Permissions.hasPermission(plr, "plots.admin.command.merge");
|
||||||
if (!plot.getOwner().equals(UUIDHandler.getUUID(plr)) && !admin) {
|
if (!plot.getOwner().equals(UUIDHandler.getUUID(plr)) && !admin) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values, C.BLOCK_LIST_SEPARATER.s()));
|
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values, C.BLOCK_LIST_SEPARATER.s()));
|
||||||
PlayerFunctions.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(plr.getLocation().getYaw())));
|
MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(plr.getLocation().getYaw())));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int direction = -1;
|
int direction = -1;
|
||||||
@ -103,81 +100,71 @@ public class Merge extends SubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (direction == -1) {
|
if (direction == -1) {
|
||||||
PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values, C.BLOCK_LIST_SEPARATER.s()));
|
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values, C.BLOCK_LIST_SEPARATER.s()));
|
||||||
PlayerFunctions.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(plr.getLocation().getYaw())));
|
MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(plr.getLocation().getYaw())));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final World world = plr.getWorld();
|
PlotId bot = MainUtil.getBottomPlot(plot).id;
|
||||||
PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id;
|
PlotId top = MainUtil.getTopPlot(plot).id;
|
||||||
PlotId top = PlayerFunctions.getTopPlot(world, plot).id;
|
|
||||||
ArrayList<PlotId> plots;
|
ArrayList<PlotId> plots;
|
||||||
|
String world = plr.getLocation().getWorld();
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case 0: // north = -y
|
case 0: // north = -y
|
||||||
plots = PlayerFunctions.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
|
plots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
|
||||||
break;
|
break;
|
||||||
case 1: // east = +x
|
case 1: // east = +x
|
||||||
plots = PlayerFunctions.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
|
plots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
|
||||||
break;
|
break;
|
||||||
case 2: // south = +y
|
case 2: // south = +y
|
||||||
plots = PlayerFunctions.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
|
plots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
|
||||||
break;
|
break;
|
||||||
case 3: // west = -x
|
case 3: // west = -x
|
||||||
plots = PlayerFunctions.getMaxPlotSelectionIds(world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
|
plots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
final PlotId botId = plots.get(0);
|
||||||
PlotId botId = plots.get(0);
|
final PlotId topId = plots.get(plots.size() - 1);
|
||||||
PlotId topId = plots.get(plots.size() - 1);
|
final PlotId bot1 = MainUtil.getBottomPlot(MainUtil.getPlot(world, botId)).id;
|
||||||
|
final PlotId bot2 = MainUtil.getBottomPlot(MainUtil.getPlot(world, topId)).id;
|
||||||
PlotId bot1 = PlayerFunctions.getBottomPlot(world, PlotHelper.getPlot(world, botId)).id;
|
final PlotId top1 = MainUtil.getTopPlot(MainUtil.getPlot(world, topId)).id;
|
||||||
PlotId bot2 = PlayerFunctions.getBottomPlot(world, PlotHelper.getPlot(world, topId)).id;
|
final PlotId top2 = MainUtil.getTopPlot(MainUtil.getPlot(world, botId)).id;
|
||||||
|
|
||||||
PlotId top1 = PlayerFunctions.getTopPlot(world, PlotHelper.getPlot(world, topId)).id;
|
|
||||||
PlotId top2 = PlayerFunctions.getTopPlot(world, PlotHelper.getPlot(world, botId)).id;
|
|
||||||
|
|
||||||
bot = new PlotId(Math.min(bot1.x, bot2.x), Math.min(bot1.y, bot2.y));
|
bot = new PlotId(Math.min(bot1.x, bot2.x), Math.min(bot1.y, bot2.y));
|
||||||
top = new PlotId(Math.max(top1.x, top2.x), Math.max(top1.y, top2.y));
|
top = new PlotId(Math.max(top1.x, top2.x), Math.max(top1.y, top2.y));
|
||||||
|
plots = MainUtil.getMaxPlotSelectionIds(world, bot, top);
|
||||||
plots = PlayerFunctions.getMaxPlotSelectionIds(world, bot, top);
|
|
||||||
|
|
||||||
for (final PlotId myid : plots) {
|
for (final PlotId myid : plots) {
|
||||||
final Plot myplot = PlotMain.getPlots(world).get(myid);
|
final Plot myplot = PlotSquared.getPlots(world).get(myid);
|
||||||
if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(UUIDHandler.getUUID(plr)) || admin)) {
|
if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(UUIDHandler.getUUID(plr)) || admin)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
|
MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
final PlotWorld plotWorld = PlotSquared.getPlotWorld(world);
|
||||||
final PlotWorld plotWorld = PlotMain.getWorldSettings(world);
|
if (PlotSquared.economy != null && plotWorld.USE_ECONOMY) {
|
||||||
if (PlotMain.useEconomy && plotWorld.USE_ECONOMY) {
|
|
||||||
double cost = plotWorld.MERGE_PRICE;
|
double cost = plotWorld.MERGE_PRICE;
|
||||||
cost = plots.size() * cost;
|
cost = plots.size() * cost;
|
||||||
if (cost > 0d) {
|
if (cost > 0d) {
|
||||||
final Economy economy = PlotMain.economy;
|
final Economy economy = PlotSquared.economy;
|
||||||
if (economy.getBalance(plr) < cost) {
|
if (EconHandler.getBalance(plr) < cost) {
|
||||||
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
|
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
economy.withdrawPlayer(plr, cost);
|
EconHandler.withdrawPlayer(plr, cost);
|
||||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//FIXME PlotMergeEvent
|
||||||
final PlotMergeEvent event = new PlotMergeEvent(world, plot, plots);
|
// boolean result = event.isCancelled();
|
||||||
|
boolean result = false;
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
if (result) {
|
||||||
if (event.isCancelled()) {
|
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
|
||||||
event.setCancelled(true);
|
|
||||||
PlayerFunctions.sendMessage(plr, "&cMerge has been cancelled");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, "&cPlots have been merged");
|
MainUtil.sendMessage(plr, "&cPlots have been merged");
|
||||||
PlotHelper.mergePlots(world, plots, true);
|
MainUtil.mergePlots(world, plots, true);
|
||||||
|
MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
|
||||||
PlotHelper.setSign(world, UUIDHandler.getName(plot.owner), plot);
|
MainUtil.update(plr.getLocation());
|
||||||
PlotHelper.update(plr.getLocation());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,24 +18,11 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2014-08-01 for PlotSquared
|
* Created 2014-08-01 for PlotSquared
|
||||||
@ -43,41 +30,39 @@ import com.intellectualcrafters.plot.util.TaskManager;
|
|||||||
* @author Empire92
|
* @author Empire92
|
||||||
*/
|
*/
|
||||||
public class Move extends SubCommand {
|
public class Move extends SubCommand {
|
||||||
|
|
||||||
public Move() {
|
public Move() {
|
||||||
super("debugmove", "plots.admin", "plot moving debug test", "debugmove", "move", CommandCategory.DEBUG, true);
|
super("debugmove", "plots.admin", "plot moving debug test", "debugmove", "move", CommandCategory.DEBUG, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (plr == null) {
|
if (plr == null) {
|
||||||
PlayerFunctions.sendMessage(plr, "MUST BE EXECUTED BY PLAYER");
|
MainUtil.sendMessage(plr, "MUST BE EXECUTED BY PLAYER");
|
||||||
}
|
}
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
PlayerFunctions.sendMessage(plr, "/plot move <pos1> <pos2>");
|
MainUtil.sendMessage(plr, "/plot move <pos1> <pos2>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
World world = plr.getWorld();
|
final String world = plr.getLocation().getWorld();
|
||||||
PlotId plot1 = PlotHelper.parseId(args[0]);
|
final PlotId plot1 = MainUtil.parseId(args[0]);
|
||||||
PlotId plot2 = PlotHelper.parseId(args[1]);
|
final PlotId plot2 = MainUtil.parseId(args[1]);
|
||||||
if (plot1 == null || plot2 == null) {
|
if ((plot1 == null) || (plot2 == null)) {
|
||||||
PlayerFunctions.sendMessage(plr, "INVALID PLOT ID\n/plot move <pos1> <pos2>");
|
MainUtil.sendMessage(plr, "INVALID PLOT ID\n/plot move <pos1> <pos2>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot1 == plot2) {
|
if (plot1 == plot2) {
|
||||||
PlayerFunctions.sendMessage(plr, "DUPLICATE ID");
|
MainUtil.sendMessage(plr, "DUPLICATE ID");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (PlotHelper.move(world, plot1, plot2, new Runnable() {
|
if (MainUtil.move(world, plot1, plot2, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PlayerFunctions.sendMessage(plr, "MOVE SUCCESS");
|
MainUtil.sendMessage(plr, "MOVE SUCCESS");
|
||||||
}
|
}
|
||||||
})) {
|
})) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
MainUtil.sendMessage(plr, "MOVE FAILED");
|
||||||
PlayerFunctions.sendMessage(plr, "MOVE FAILED");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,35 +18,36 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
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.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
|
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
|
||||||
|
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
|
||||||
public class MusicSubcommand extends SubCommand {
|
public class MusicSubcommand extends SubCommand {
|
||||||
public MusicSubcommand() {
|
public MusicSubcommand() {
|
||||||
super("music", "plots.music", "Play music in plot", "music", "mus", CommandCategory.ACTIONS, true);
|
super("music", "plots.music", "Play music in plot", "music", "mus", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player player, final String... args) {
|
public boolean execute(final PlotPlayer player, final String... args) {
|
||||||
if (!PlayerFunctions.isInPlot(player)) {
|
Location loc = player.getLocation();
|
||||||
sendMessage(player, C.NOT_IN_PLOT);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
return true;
|
if (plot == null) {
|
||||||
|
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(player);
|
if (!plot.isAdded(player.getUUID())) {
|
||||||
if (!plot.hasRights(player)) {
|
|
||||||
sendMessage(player, C.NO_PLOT_PERMS);
|
sendMessage(player, C.NO_PLOT_PERMS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -59,7 +60,8 @@ public class MusicSubcommand extends SubCommand {
|
|||||||
stack.setItemMeta(itemMeta);
|
stack.setItemMeta(itemMeta);
|
||||||
inventory.addItem(stack);
|
inventory.addItem(stack);
|
||||||
}
|
}
|
||||||
player.openInventory(inventory);
|
// FIXME unchecked casting
|
||||||
|
((BukkitPlayer) player).player.openInventory(inventory);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package com.intellectualcrafters.plot.commands;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created 2014-11-09 for PlotSquared
|
|
||||||
*
|
|
||||||
* @author Citymonstret
|
|
||||||
*/
|
|
||||||
public class OP extends SubCommand {
|
|
||||||
|
|
||||||
public OP() {
|
|
||||||
super(Command.OP, "Alias for /plot trusted add", "/plot op [player]", CommandCategory.ACTIONS, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(final Player plr, final String... args) {
|
|
||||||
if (args.length < 1) {
|
|
||||||
return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + this.usage);
|
|
||||||
}
|
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
|
||||||
}
|
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if (!plot.hasRights(plr)) {
|
|
||||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
|
||||||
}
|
|
||||||
return plr.performCommand("plot trusted add " + args[0]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotSelection;
|
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
|
|
||||||
public class Paste extends SubCommand {
|
|
||||||
|
|
||||||
public Paste() {
|
|
||||||
super(Command.PASTE, "Paste a plot", "paste", CommandCategory.ACTIONS, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(final Player plr, final String... args) {
|
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !PlotMain.hasPermission(plr, "plots.admin.command.paste")) {
|
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
|
|
||||||
PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
assert plot != null;
|
|
||||||
final int size = (PlotHelper.getPlotTopLocAbs(plr.getWorld(), plot.getId()).getBlockX() - PlotHelper.getPlotBottomLocAbs(plr.getWorld(), plot.getId()).getBlockX());
|
|
||||||
|
|
||||||
if (PlotSelection.currentSelection.containsKey(plr.getName())) {
|
|
||||||
final PlotSelection selection = PlotSelection.currentSelection.get(plr.getName());
|
|
||||||
if (size != selection.getWidth()) {
|
|
||||||
sendMessage(plr, C.PASTE_FAILED, "The size of the current plot is not the same as the paste");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
selection.paste(plr.getWorld(), plot);
|
|
||||||
sendMessage(plr, C.PASTED);
|
|
||||||
} else {
|
|
||||||
sendMessage(plr, C.NO_CLIPBOARD);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
PlotSelection.currentSelection.remove(plr.getName());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -26,148 +25,143 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
@SuppressWarnings({"javadoc"}) public class Purge extends SubCommand {
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
|
@SuppressWarnings({ "javadoc" })
|
||||||
|
public class Purge extends SubCommand {
|
||||||
public Purge() {
|
public Purge() {
|
||||||
super("purge", "plots.admin", "Purge all plots for a world", "purge", "", CommandCategory.DEBUG, false);
|
super("purge", "plots.admin", "Purge all plots for a world", "purge", "", CommandCategory.DEBUG, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlotId getId(String id) {
|
public PlotId getId(final String id) {
|
||||||
try {
|
try {
|
||||||
String[] split = id.split(";");
|
final String[] split = id.split(";");
|
||||||
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (plr != null) {
|
if (plr != null) {
|
||||||
PlayerFunctions.sendMessage(plr, (C.NOT_CONSOLE));
|
MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
String arg = args[0].toLowerCase();
|
final String arg = args[0].toLowerCase();
|
||||||
PlotId id = getId(arg);
|
final PlotId id = getId(arg);
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
PlayerFunctions.sendMessage(plr, "/plot purge x;z &l<world>");
|
MainUtil.sendMessage(plr, "/plot purge x;z &l<world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
final UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||||
if (uuid != null) {
|
if (uuid != null) {
|
||||||
PlayerFunctions.sendMessage(plr, "/plot purge "+args[0]+" &l<world>");
|
MainUtil.sendMessage(plr, "/plot purge " + args[0] + " &l<world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (arg.equals("player")) {
|
if (arg.equals("player")) {
|
||||||
PlayerFunctions.sendMessage(plr, "/plot purge &l<player> <world>");
|
MainUtil.sendMessage(plr, "/plot purge &l<player> <world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (arg.equals("unowned")) {
|
if (arg.equals("unowned")) {
|
||||||
PlayerFunctions.sendMessage(plr, "/plot purge unowned &l<world>");
|
MainUtil.sendMessage(plr, "/plot purge unowned &l<world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (arg.equals("unknown")) {
|
if (arg.equals("unknown")) {
|
||||||
PlayerFunctions.sendMessage(plr, "/plot purge unknown &l<world>");
|
MainUtil.sendMessage(plr, "/plot purge unknown &l<world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (arg.equals("all")) {
|
if (arg.equals("all")) {
|
||||||
PlayerFunctions.sendMessage(plr, "/plot purge all &l<world>");
|
MainUtil.sendMessage(plr, "/plot purge all &l<world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.PURGE_SYNTAX);
|
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
PlayerFunctions.sendMessage(plr, C.PURGE_SYNTAX);
|
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
World world = Bukkit.getWorld(args[1]);
|
final String worldname = args[0];
|
||||||
if (world == null || !PlotMain.isPlotWorld(world)) {
|
if (!BlockManager.manager.isWorld(worldname) || !PlotSquared.isPlotWorld(worldname)) {
|
||||||
PlayerFunctions.sendMessage(null, C.NOT_VALID_PLOT_WORLD);
|
MainUtil.sendMessage(plr, "INVALID WORLD");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String worldname = world.getName();
|
final String arg = args[0].toLowerCase();
|
||||||
String arg = args[0].toLowerCase();
|
final PlotId id = getId(arg);
|
||||||
PlotId id = getId(arg);
|
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
HashSet<Integer> ids = new HashSet<Integer>();
|
final HashSet<Integer> ids = new HashSet<Integer>();
|
||||||
int DBid = DBFunc.getId(worldname, id);
|
final int DBid = DBFunc.getId(worldname, id);
|
||||||
if (DBid != Integer.MAX_VALUE) {
|
if (DBid != Integer.MAX_VALUE) {
|
||||||
ids.add(DBid);
|
ids.add(DBid);
|
||||||
}
|
}
|
||||||
DBFunc.purgeIds(worldname, ids);
|
DBFunc.purgeIds(worldname, ids);
|
||||||
return finishPurge(DBid == Integer.MAX_VALUE ? 1 : 0);
|
return finishPurge(DBid == Integer.MAX_VALUE ? 1 : 0);
|
||||||
}
|
}
|
||||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
final UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||||
if (uuid != null) {
|
if (uuid != null) {
|
||||||
Set<Plot> plots = PlotMain.getPlots(world,uuid);
|
final Set<Plot> plots = PlotSquared.getPlots(worldname, uuid);
|
||||||
Set<PlotId> ids = new HashSet<>();
|
final Set<PlotId> ids = new HashSet<>();
|
||||||
for (Plot plot : plots) {
|
for (final Plot plot : plots) {
|
||||||
ids.add(plot.id);
|
ids.add(plot.id);
|
||||||
}
|
}
|
||||||
DBFunc.purge(worldname, ids);
|
DBFunc.purge(worldname, ids);
|
||||||
return finishPurge(ids.size());
|
return finishPurge(ids.size());
|
||||||
}
|
}
|
||||||
if (arg.equals("all")) {
|
if (arg.equals("all")) {
|
||||||
Set<PlotId> ids = PlotMain.getPlots(world).keySet();
|
final Set<PlotId> ids = PlotSquared.getPlots(worldname).keySet();
|
||||||
if (ids.size() == 0) {
|
if (ids.size() == 0) {
|
||||||
return PlayerFunctions.sendMessage(null, "&cNo plots found");
|
return MainUtil.sendMessage(null, "&cNo plots found");
|
||||||
}
|
}
|
||||||
DBFunc.purge(worldname, ids);
|
DBFunc.purge(worldname, ids);
|
||||||
return finishPurge(ids.size());
|
return finishPurge(ids.size());
|
||||||
}
|
}
|
||||||
if (arg.equals("unknown")) {
|
if (arg.equals("unknown")) {
|
||||||
Collection<Plot> plots = PlotMain.getPlots(world).values();
|
final Collection<Plot> plots = PlotSquared.getPlots(worldname).values();
|
||||||
Set<PlotId> ids = new HashSet<>();
|
final Set<PlotId> ids = new HashSet<>();
|
||||||
for (Plot plot : plots) {
|
for (final Plot plot : plots) {
|
||||||
if (plot.owner != null) {
|
if (plot.owner != null) {
|
||||||
String name = UUIDHandler.getName(plot.owner);
|
final String name = UUIDHandler.getName(plot.owner);
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
ids.add(plot.id);
|
ids.add(plot.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ids.size() == 0) {
|
if (ids.size() == 0) {
|
||||||
return PlayerFunctions.sendMessage(null, "&cNo plots found");
|
return MainUtil.sendMessage(null, "&cNo plots found");
|
||||||
}
|
}
|
||||||
DBFunc.purge(worldname, ids);
|
DBFunc.purge(worldname, ids);
|
||||||
return finishPurge(ids.size());
|
return finishPurge(ids.size());
|
||||||
}
|
}
|
||||||
if (arg.equals("unowned")) {
|
if (arg.equals("unowned")) {
|
||||||
Collection<Plot> plots = PlotMain.getPlots(world).values();
|
final Collection<Plot> plots = PlotSquared.getPlots(worldname).values();
|
||||||
Set<PlotId> ids = new HashSet<>();
|
final Set<PlotId> ids = new HashSet<>();
|
||||||
for (Plot plot : plots) {
|
for (final Plot plot : plots) {
|
||||||
if (plot.owner == null) {
|
if (plot.owner == null) {
|
||||||
ids.add(plot.id);
|
ids.add(plot.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ids.size() == 0) {
|
if (ids.size() == 0) {
|
||||||
return PlayerFunctions.sendMessage(null, "&cNo plots found");
|
return MainUtil.sendMessage(null, "&cNo plots found");
|
||||||
}
|
}
|
||||||
DBFunc.purge(worldname, ids);
|
DBFunc.purge(worldname, ids);
|
||||||
return finishPurge(ids.size());
|
return finishPurge(ids.size());
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.PURGE_SYNTAX);
|
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean finishPurge(int amount) {
|
private boolean finishPurge(final int amount) {
|
||||||
PlayerFunctions.sendMessage(null, C.PURGE_SUCCESS, amount + "");
|
MainUtil.sendMessage(null, C.PURGE_SUCCESS, amount + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,39 +18,36 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// 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.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
@SuppressWarnings({"unused", "deprecated", "javadoc"}) public class Rate extends SubCommand {
|
|
||||||
|
|
||||||
|
public class Rate extends SubCommand {
|
||||||
/*
|
/*
|
||||||
* String cmd, String permission, String description, String usage, String
|
* String cmd, String permission, String description, String usage, String
|
||||||
* alias, CommandCategory category
|
* alias, CommandCategory category
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Rate() {
|
public Rate() {
|
||||||
super("rate", "plots.rate", "Rate the plot", "rate {0-10}", "rt", CommandCategory.ACTIONS, true);
|
super("rate", "plots.rate", "Rate the plot", "rate {0-10}", "rt", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
sendMessage(plr, C.RATING_NOT_VALID);
|
sendMessage(plr, C.RATING_NOT_VALID);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
sendMessage(plr, C.NOT_IN_PLOT);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
return true;
|
if (plot == null) {
|
||||||
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
sendMessage(plr, C.RATING_NOT_OWNED);
|
sendMessage(plr, C.RATING_NOT_OWNED);
|
||||||
return true;
|
return true;
|
||||||
@ -82,7 +79,6 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
rated = false;
|
rated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rated) {
|
if (rated) {
|
||||||
sendMessage(plr, C.RATING_ALREADY_EXISTS, plot.getId().toString());
|
sendMessage(plr, C.RATING_ALREADY_EXISTS, plot.getId().toString());
|
||||||
}
|
}
|
||||||
|
@ -18,66 +18,50 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.generator.HybridPlotManager;
|
import com.intellectualcrafters.plot.generator.HybridPlotManager;
|
||||||
|
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.PlotManager;
|
import com.intellectualcrafters.plot.object.PlotManager;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.AChunkManager;
|
||||||
|
|
||||||
public class RegenAllRoads extends SubCommand {
|
public class RegenAllRoads extends SubCommand {
|
||||||
|
|
||||||
public RegenAllRoads() {
|
public RegenAllRoads() {
|
||||||
super(Command.REGENALLROADS, "Regenerate all roads in the map using the set road schematic", "rgar", CommandCategory.DEBUG, false);
|
super(Command.REGENALLROADS, "Regenerate all roads in the map using the set road schematic", "rgar", CommandCategory.DEBUG, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player player, final String... args) {
|
public boolean execute(final PlotPlayer player, final String... args) {
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
sendMessage(player, C.NOT_CONSOLE);
|
sendMessage(player, C.NOT_CONSOLE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
sendMessage(player, C.NEED_PLOT_WORLD);
|
sendMessage(player, C.NEED_PLOT_WORLD);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
final String name = args[0];
|
||||||
String name = args[0];
|
final PlotManager manager = PlotSquared.getPlotManager(name);
|
||||||
PlotManager manager = PlotMain.getPlotManager(name);
|
if ((manager == null) || !(manager instanceof HybridPlotManager)) {
|
||||||
|
|
||||||
if (manager == null || !(manager instanceof HybridPlotManager)) {
|
|
||||||
sendMessage(player, C.NOT_VALID_PLOT_WORLD);
|
sendMessage(player, C.NOT_VALID_PLOT_WORLD);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
final List<ChunkLoc> chunks = AChunkManager.manager.getChunkChunks(name);
|
||||||
HybridPlotManager hpm = (HybridPlotManager) manager;
|
PlotSquared.log("&cIf no schematic is set, the following will not do anything");
|
||||||
|
PlotSquared.log("&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic");
|
||||||
World world = Bukkit.getWorld(name);
|
PlotSquared.log("&6Potential chunks to update: &7" + (chunks.size() * 1024));
|
||||||
ArrayList<ChunkLoc> chunks = ChunkManager.getChunkChunks(world);
|
PlotSquared.log("&6Estimated time: &7" + (chunks.size()) + " seconds");
|
||||||
|
final boolean result = HybridUtils.manager.scheduleRoadUpdate(name);
|
||||||
PlotMain.sendConsoleSenderMessage("&cIf no schematic is set, the following will not do anything");
|
|
||||||
PlotMain.sendConsoleSenderMessage("&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic");
|
|
||||||
PlotMain.sendConsoleSenderMessage("&6Potential chunks to update: &7"+ (chunks.size() * 1024));
|
|
||||||
PlotMain.sendConsoleSenderMessage("&6Estimated time: &7"+ (chunks.size()) + " seconds");
|
|
||||||
|
|
||||||
boolean result = hpm.scheduleRoadUpdate(world);
|
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
PlotMain.sendConsoleSenderMessage("&cCannot schedule mass schematic update! (Is one already in progress?)");
|
PlotSquared.log("&cCannot schedule mass schematic update! (Is one already in progress?)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,39 +18,35 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// 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.PlotSquared;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
|
||||||
public class Reload extends SubCommand {
|
public class Reload extends SubCommand {
|
||||||
|
|
||||||
public Reload() {
|
public Reload() {
|
||||||
super("reload", "plots.admin.command.reload", "Reload configurations", "", "reload", CommandCategory.INFO, false);
|
super("reload", "plots.admin.command.reload", "Reload configurations", "", "reload", CommandCategory.INFO, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
try {
|
try {
|
||||||
// The following won't affect world generation, as that has to be
|
// The following won't affect world generation, as that has to be
|
||||||
// loaded during startup unfortunately.
|
// loaded during startup unfortunately.
|
||||||
PlotMain.config.load(PlotMain.configFile);
|
PlotSquared.config.load(PlotSquared.configFile);
|
||||||
PlotMain.setupConfig();
|
PlotSquared.setupConfig();
|
||||||
C.setupTranslations();
|
C.setupTranslations();
|
||||||
for (final String pw : PlotMain.getPlotWorlds()) {
|
for (final String pw : PlotSquared.getPlotWorlds()) {
|
||||||
final PlotWorld plotworld = PlotMain.getWorldSettings(pw);
|
final PlotWorld plotworld = PlotSquared.getPlotWorld(pw);
|
||||||
plotworld.loadDefaultConfiguration(PlotMain.config.getConfigurationSection("worlds." + pw));
|
plotworld.loadDefaultConfiguration(PlotSquared.config.getConfigurationSection("worlds." + pw));
|
||||||
}
|
}
|
||||||
PlotMain.BroadcastWithPerms(C.RELOADED_CONFIGS);
|
MainUtil.sendMessage(plr, C.RELOADED_CONFIGS);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
PlayerFunctions.sendMessage(plr, C.RELOAD_FAILED);
|
MainUtil.sendMessage(plr, C.RELOAD_FAILED);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,45 +18,41 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection;
|
import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection;
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
|
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
public class Schematic extends SubCommand {
|
public class Schematic extends SubCommand {
|
||||||
|
|
||||||
private int counter = 0;
|
private int counter = 0;
|
||||||
private boolean running = false;
|
private boolean running = false;
|
||||||
private Plot[] plots;
|
private Plot[] plots;
|
||||||
private int task;
|
private int task;
|
||||||
|
|
||||||
public Schematic() {
|
public Schematic() {
|
||||||
super("schematic", "plots.schematic", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false);
|
super("schematic", "plots.schematic", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false);
|
||||||
// TODO command to fetch schematic from worldedit directory
|
// TODO command to fetch schematic from worldedit directory
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||||
return true;
|
return true;
|
||||||
@ -65,31 +61,33 @@ public class Schematic extends SubCommand {
|
|||||||
final String file;
|
final String file;
|
||||||
final SchematicHandler.Schematic schematic;
|
final SchematicHandler.Schematic schematic;
|
||||||
switch (arg) {
|
switch (arg) {
|
||||||
case "paste":
|
case "paste": {
|
||||||
if (plr == null) {
|
if (plr == null) {
|
||||||
PlotMain.sendConsoleSenderMessage(C.IS_CONSOLE);
|
PlotSquared.log(C.IS_CONSOLE.s());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!PlotMain.hasPermission(plr, "plots.schematic.paste")) {
|
if (!Permissions.hasPermission(plr, "plots.schematic.paste")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.paste");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.paste");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
final Location loc = plr.getLocation();
|
||||||
|
Plot plot = MainUtil.getPlot(loc);
|
||||||
|
if (plot == null) {
|
||||||
sendMessage(plr, C.NOT_IN_PLOT);
|
sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this.running) {
|
if (this.running) {
|
||||||
PlayerFunctions.sendMessage(plr, "&cTask is already running.");
|
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String file2 = args[1];
|
final String file2 = args[1];
|
||||||
this.running = true;
|
this.running = true;
|
||||||
this.counter = 0;
|
this.counter = 0;
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final SchematicHandler.Schematic schematic = SchematicHandler.getSchematic(file2);
|
final SchematicHandler.Schematic schematic = SchematicHandler.getSchematic(file2);
|
||||||
@ -98,40 +96,32 @@ public class Schematic extends SubCommand {
|
|||||||
Schematic.this.running = false;
|
Schematic.this.running = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int x;
|
final int x;
|
||||||
final int z;
|
final int z;
|
||||||
|
final Plot plot2 = MainUtil.getPlot(loc);
|
||||||
final Plot plot2 = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
|
|
||||||
final Dimension dem = schematic.getSchematicDimension();
|
final Dimension dem = schematic.getSchematicDimension();
|
||||||
final Location bot = PlotHelper.getPlotBottomLoc(plr.getWorld(), plot2.id).add(1, 0, 1);
|
final Location bot = MainUtil.getPlotBottomLoc(loc.getWorld(), plot2.id).add(1, 0, 1);
|
||||||
final int length2 = PlotHelper.getPlotWidth(plr.getWorld(), plot2.id);
|
final int length2 = MainUtil.getPlotWidth(loc.getWorld(), plot2.id);
|
||||||
|
|
||||||
if ((dem.getX() > length2) || (dem.getZ() > length2)) {
|
if ((dem.getX() > length2) || (dem.getZ() > length2)) {
|
||||||
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", dem.getX(), dem.getZ(), length2));
|
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", dem.getX(), dem.getZ(), length2));
|
||||||
Schematic.this.running = false;
|
Schematic.this.running = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dem.getX() != length2) || (dem.getZ() != length2)) {
|
if ((dem.getX() != length2) || (dem.getZ() != length2)) {
|
||||||
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.getX() - bot.getX());
|
||||||
z = Math.min(length2 - dem.getZ(), loc.getBlockZ() - bot.getBlockZ());
|
z = Math.min(length2 - dem.getZ(), loc.getZ() - bot.getZ());
|
||||||
} else {
|
} else {
|
||||||
x = 0;
|
x = 0;
|
||||||
z = 0;
|
z = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
final World w = plot2.getWorld();
|
|
||||||
final DataCollection[] b = schematic.getBlockCollection();
|
final DataCollection[] b = schematic.getBlockCollection();
|
||||||
final int sy = w.getHighestBlockYAt(bot.getBlockX(), bot.getBlockZ());
|
final int sy = BlockManager.manager.getHeighestBlock(bot);
|
||||||
final Location l1 = bot.add(0, sy - 1, 0);
|
final Location l1 = bot.add(0, sy - 1, 0);
|
||||||
final int WIDTH = schematic.getSchematicDimension().getX();
|
final int WIDTH = schematic.getSchematicDimension().getX();
|
||||||
final int LENGTH = schematic.getSchematicDimension().getZ();
|
final int LENGTH = schematic.getSchematicDimension().getZ();
|
||||||
final int blen = b.length - 1;
|
final int blen = b.length - 1;
|
||||||
|
Schematic.this.task = TaskManager.runTaskRepeat(new Runnable() {
|
||||||
Schematic.this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
@ -139,27 +129,28 @@ public class Schematic extends SubCommand {
|
|||||||
final int start = Schematic.this.counter * 5000;
|
final int start = Schematic.this.counter * 5000;
|
||||||
if (start > blen) {
|
if (start > blen) {
|
||||||
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
|
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
|
||||||
PlotHelper.update(plr.getLocation());
|
MainUtil.update(plr.getLocation());
|
||||||
Schematic.this.running = false;
|
Schematic.this.running = false;
|
||||||
Bukkit.getScheduler().cancelTask(Schematic.this.task);
|
PlotSquared.TASK.cancelTask(Schematic.this.task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int end = Math.min(start + 5000, blen);
|
final int end = Math.min(start + 5000, blen);
|
||||||
result = SchematicHandler.pastePart(w, b, l1, x, z, start, end, WIDTH, LENGTH);
|
result = SchematicHandler.pastePart(loc.getWorld(), b, l1, x, z, start, end, WIDTH, LENGTH);
|
||||||
Schematic.this.counter++;
|
Schematic.this.counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1, 1);
|
}, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "test":
|
}
|
||||||
|
case "test": {
|
||||||
if (plr == null) {
|
if (plr == null) {
|
||||||
PlotMain.sendConsoleSenderMessage(C.IS_CONSOLE);
|
PlotSquared.log(C.IS_CONSOLE.s());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!PlotMain.hasPermission(plr, "plots.schematic.test")) {
|
if (!Permissions.hasPermission(plr, "plots.schematic.test")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
@ -172,171 +163,164 @@ public class Schematic extends SubCommand {
|
|||||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
|
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Location loc = plr.getLocation();
|
||||||
final int l1 = schematic.getSchematicDimension().getX();
|
final int l1 = schematic.getSchematicDimension().getX();
|
||||||
final int l2 = schematic.getSchematicDimension().getZ();
|
final int l2 = schematic.getSchematicDimension().getZ();
|
||||||
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
final int length = MainUtil.getPlotWidth(loc.getWorld(), plot.id);
|
||||||
final int length = PlotHelper.getPlotWidth(plr.getWorld(), plot.id);
|
|
||||||
|
|
||||||
if ((l1 < length) || (l2 < length)) {
|
if ((l1 < length) || (l2 < length)) {
|
||||||
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", l1, l2, length));
|
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", l1, l2, length));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sendMessage(plr, C.SCHEMATIC_VALID);
|
sendMessage(plr, C.SCHEMATIC_VALID);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "saveall":
|
case "saveall":
|
||||||
case "exportall":
|
case "exportall": {
|
||||||
if (plr != null) {
|
if (plr != null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_CONSOLE);
|
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
PlayerFunctions.sendMessage(null, "&cNeed world arg. Use &7/plots sch exportall <world>");
|
MainUtil.sendMessage(null, "&cNeed world arg. Use &7/plots sch exportall <world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final HashMap<PlotId, Plot> plotmap = PlotMain.getPlots(args[1]);
|
final HashMap<PlotId, Plot> plotmap = PlotSquared.getPlots(args[1]);
|
||||||
if ((plotmap == null) || (plotmap.size() == 0)) {
|
if ((plotmap == null) || (plotmap.size() == 0)) {
|
||||||
PlayerFunctions.sendMessage(null, "&cInvalid world. Use &7/plots sch exportall <world>");
|
MainUtil.sendMessage(null, "&cInvalid world. Use &7/plots sch exportall <world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.running) {
|
if (this.running) {
|
||||||
PlayerFunctions.sendMessage(null, "&cTask is already running.");
|
MainUtil.sendMessage(null, "&cTask is already running.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
|
||||||
PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
|
PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plotmap.size() + "&7 plots...");
|
||||||
PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plotmap.size() + "&7 plots...");
|
final String worldname = args[1];
|
||||||
final World worldObj = Bukkit.getWorld(args[1]);
|
|
||||||
final String worldname = Bukkit.getWorld(args[1]).getName();
|
|
||||||
|
|
||||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared");
|
|
||||||
|
|
||||||
final Collection<Plot> values = plotmap.values();
|
final Collection<Plot> values = plotmap.values();
|
||||||
this.plots = values.toArray(new Plot[values.size()]);
|
this.plots = values.toArray(new Plot[values.size()]);
|
||||||
this.running = true;
|
this.running = true;
|
||||||
this.counter = 0;
|
this.counter = 0;
|
||||||
|
this.task = TaskManager.runTaskRepeat(new Runnable() {
|
||||||
this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (Schematic.this.counter >= Schematic.this.plots.length) {
|
if (Schematic.this.counter >= Schematic.this.plots.length) {
|
||||||
PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &aFinished!");
|
PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &aFinished!");
|
||||||
Schematic.this.running = false;
|
Schematic.this.running = false;
|
||||||
Bukkit.getScheduler().cancelTask(Schematic.this.task);
|
PlotSquared.TASK.cancelTask(Schematic.this.task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Plot plot = Schematic.this.plots[Schematic.this.counter];
|
final Plot plot = Schematic.this.plots[Schematic.this.counter];
|
||||||
final CompoundTag sch = SchematicHandler.getCompoundTag(worldObj, plot.id);
|
final CompoundTag sch = SchematicHandler.getCompoundTag(worldname, plot.id);
|
||||||
final String o = UUIDHandler.getName(plot.owner);
|
final String o = UUIDHandler.getName(plot.owner);
|
||||||
final String owner = o == null ? "unknown" : o;
|
final String owner = o == null ? "unknown" : o;
|
||||||
if (sch == null) {
|
if (sch == null) {
|
||||||
PlayerFunctions.sendMessage(null, "&7 - Skipped plot &c" + plot.id);
|
MainUtil.sendMessage(null, "&7 - Skipped plot &c" + plot.id);
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PlayerFunctions.sendMessage(null, "&6ID: " + plot.id);
|
MainUtil.sendMessage(null, "&6ID: " + plot.id);
|
||||||
final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + worldname + "," + owner + ".schematic");
|
final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + worldname + "," + owner + ".schematic");
|
||||||
if (!result) {
|
if (!result) {
|
||||||
PlayerFunctions.sendMessage(null, "&7 - Failed to save &c" + plot.id);
|
MainUtil.sendMessage(null, "&7 - Failed to save &c" + plot.id);
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(null, "&7 - &aExport success: " + plot.id);
|
MainUtil.sendMessage(null, "&7 - &aExport success: " + plot.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Schematic.this.counter++;
|
Schematic.this.counter++;
|
||||||
}
|
}
|
||||||
}, 20, 20);
|
}, 20);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "export":
|
case "export":
|
||||||
case "save":
|
case "save":
|
||||||
if (!PlotMain.hasPermission(plr, "plots.schematic.save")) {
|
{
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.save");
|
if (!Permissions.hasPermission(plr, "plots.schematic.save")) {
|
||||||
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.save");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.running) {
|
if (this.running) {
|
||||||
PlayerFunctions.sendMessage(plr, "&cTask is already running.");
|
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String world;
|
final String world;
|
||||||
final Plot p2;
|
final Plot p2;
|
||||||
if (plr != null) {
|
if (plr != null) {
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
sendMessage(plr, C.NOT_IN_PLOT);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
return false;
|
if (plot == null) {
|
||||||
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot myplot = PlayerFunctions.getCurrentPlot(plr);
|
if (!plot.isAdded(plr.getUUID())) {
|
||||||
if (!myplot.hasRights(plr)) {
|
|
||||||
sendMessage(plr, C.NO_PLOT_PERMS);
|
sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
p2 = myplot;
|
p2 = plot;
|
||||||
world = plr.getWorld().getName();
|
world = loc.getWorld();
|
||||||
} else {
|
} else {
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
try {
|
try {
|
||||||
world = args[0];
|
world = args[0];
|
||||||
final String[] split = args[2].split(";");
|
final String[] split = args[2].split(";");
|
||||||
final PlotId i = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
final PlotId i = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||||
if ((PlotMain.getPlots(world) == null) || (PlotMain.getPlots(world).get(i) == null)) {
|
if ((PlotSquared.getPlots(world) == null) || (PlotSquared.getPlots(world).get(i) == null)) {
|
||||||
PlayerFunctions.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
p2 = PlotMain.getPlots(world).get(i);
|
p2 = PlotSquared.getPlots(world).get(i);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
PlayerFunctions.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.plots = new Plot[] { p2 };
|
||||||
final Plugin plugin2 = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared");
|
|
||||||
|
|
||||||
this.plots = new Plot[]{p2};
|
|
||||||
this.running = true;
|
this.running = true;
|
||||||
this.counter = 0;
|
this.counter = 0;
|
||||||
|
this.task = TaskManager.runTaskRepeat(new Runnable() {
|
||||||
this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin2, new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (Schematic.this.counter >= Schematic.this.plots.length) {
|
if (Schematic.this.counter >= Schematic.this.plots.length) {
|
||||||
PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &aFinished!");
|
PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &aFinished!");
|
||||||
Schematic.this.running = false;
|
Schematic.this.running = false;
|
||||||
Bukkit.getScheduler().cancelTask(Schematic.this.task);
|
PlotSquared.TASK.cancelTask(Schematic.this.task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Plot plot = Schematic.this.plots[Schematic.this.counter];
|
final Plot plot = Schematic.this.plots[Schematic.this.counter];
|
||||||
final CompoundTag sch = SchematicHandler.getCompoundTag(Bukkit.getWorld(world), plot.id);
|
final CompoundTag sch = SchematicHandler.getCompoundTag(world, plot.id);
|
||||||
final String o = UUIDHandler.getName(plot.owner);
|
final String o = UUIDHandler.getName(plot.owner);
|
||||||
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);
|
MainUtil.sendMessage(plr, "&7 - Skipped plot &c" + plot.id);
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PlayerFunctions.sendMessage(plr, "&6ID: " + plot.id);
|
MainUtil.sendMessage(plr, "&6ID: " + plot.id);
|
||||||
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);
|
MainUtil.sendMessage(plr, "&7 - Failed to save &c" + plot.id);
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, "&7 - &aExport success: " + plot.id);
|
MainUtil.sendMessage(plr, "&7 - &aExport success: " + plot.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Schematic.this.counter++;
|
Schematic.this.counter++;
|
||||||
}
|
}
|
||||||
}, 20, 60);
|
}, 60);
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
|
default: {
|
||||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -18,72 +18,62 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Biome;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.config.Configuration;
|
import com.intellectualcrafters.plot.config.Configuration;
|
||||||
import com.intellectualcrafters.plot.config.Configuration.SettingValue;
|
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
import com.intellectualcrafters.plot.flag.FlagValue;
|
|
||||||
import com.intellectualcrafters.plot.listeners.PlotListener;
|
import com.intellectualcrafters.plot.listeners.PlotListener;
|
||||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
import com.intellectualcrafters.plot.object.BlockLoc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||||
import com.intellectualcrafters.plot.object.PlotManager;
|
import com.intellectualcrafters.plot.object.PlotManager;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.StringComparison;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class Set extends SubCommand {
|
public class Set extends SubCommand {
|
||||||
|
public final static String[] values = new String[] { "biome", "wall", "wall_filling", "floor", "alias", "home", "flag" };
|
||||||
public final static String[] values = new String[]{"biome", "wall", "wall_filling", "floor", "alias", "home", "flag"};
|
public final static String[] aliases = new String[] { "b", "w", "wf", "f", "a", "h", "fl" };
|
||||||
public final static String[] aliases = new String[]{"b", "w", "wf", "f", "a", "h", "fl"};
|
|
||||||
|
|
||||||
public Set() {
|
public Set() {
|
||||||
super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS, true);
|
super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
return false;
|
if (plot == null) {
|
||||||
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
sendMessage(plr, C.PLOT_NOT_CLAIMED);
|
sendMessage(plr, C.PLOT_NOT_CLAIMED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.hasRights(plr) && !PlotMain.hasPermission(plr, "plots.admin.command.set")) {
|
if (!plot.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.set")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(values));
|
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(values));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < aliases.length; i++) {
|
for (int i = 0; i < aliases.length; i++) {
|
||||||
@ -94,146 +84,118 @@ public class Set extends SubCommand {
|
|||||||
}
|
}
|
||||||
/* TODO: Implement option */
|
/* TODO: Implement option */
|
||||||
// final boolean advanced_permissions = true;
|
// final boolean advanced_permissions = true;
|
||||||
if (!PlotMain.hasPermission(plr, "plots.set." + args[0].toLowerCase())) {
|
if (!Permissions.hasPermission(plr, "plots.set." + args[0].toLowerCase())) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.set." + args[0].toLowerCase());
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set." + args[0].toLowerCase());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("flag")) {
|
if (args[0].equalsIgnoreCase("flag")) {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
String message = StringUtils.join(FlagManager.getFlags(plr), "&c, &6");
|
String message = StringUtils.join(FlagManager.getFlags(plr), "&c, &6");
|
||||||
if (PlotMain.worldGuardListener != null) {
|
MainUtil.sendMessage(plr, C.NEED_KEY.s().replaceAll("%values%", message));
|
||||||
if (message.equals("")) {
|
|
||||||
message = StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6");
|
|
||||||
} else {
|
|
||||||
message += "," + StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PlayerFunctions.sendMessage(plr, C.NEED_KEY.s().replaceAll("%values%", message));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractFlag af;
|
AbstractFlag af;
|
||||||
|
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
if (!FlagManager.getFlags().contains(af)) {
|
||||||
if (!FlagManager.getFlags().contains(af) && ((PlotMain.worldGuardListener == null) || !PlotMain.worldGuardListener.str_flags.contains(args[1].toLowerCase()))) {
|
MainUtil.sendMessage(plr, C.NOT_VALID_FLAG);
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_FLAG);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!PlotMain.hasPermission(plr, "plots.set.flag." + args[1].toLowerCase())) {
|
if (!Permissions.hasPermission(plr, "plots.set.flag." + args[1].toLowerCase())) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
|
MainUtil.sendMessage(plr, C.NO_PERMISSION);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
if (FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase()) == null) {
|
if (FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase()) == null) {
|
||||||
if (PlotMain.worldGuardListener != null) {
|
MainUtil.sendMessage(plr, C.FLAG_NOT_IN_PLOT);
|
||||||
if (PlotMain.worldGuardListener.str_flags.contains(args[1].toLowerCase())) {
|
|
||||||
PlotMain.worldGuardListener.removeFlag(plr, plr.getWorld(), plot, args[1]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PlayerFunctions.sendMessage(plr, C.FLAG_NOT_IN_PLOT);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
final boolean result = FlagManager.removePlotFlag(plot, args[1].toLowerCase());
|
||||||
boolean result = FlagManager.removePlotFlag(plot, args[1].toLowerCase());
|
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
PlayerFunctions.sendMessage(plr, C.FLAG_NOT_REMOVED);
|
MainUtil.sendMessage(plr, C.FLAG_NOT_REMOVED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.FLAG_REMOVED);
|
MainUtil.sendMessage(plr, C.FLAG_REMOVED);
|
||||||
PlotListener.plotEntry(plr, plot);
|
PlotListener.plotEntry(plr, plot);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||||
Object parsed_value = af.parseValueRaw(value);
|
final Object parsed_value = af.parseValueRaw(value);
|
||||||
if (parsed_value == null) {
|
if (parsed_value == null) {
|
||||||
PlayerFunctions.sendMessage(plr, af.getValueDesc());
|
MainUtil.sendMessage(plr, af.getValueDesc());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((FlagManager.getFlag(args[1].toLowerCase()) == null) && (PlotMain.worldGuardListener != null)) {
|
|
||||||
PlotMain.worldGuardListener.addFlag(plr, plr.getWorld(), plot, args[1], af.toString(parsed_value));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed_value);
|
final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed_value);
|
||||||
boolean result = FlagManager.addPlotFlag(plot, flag);
|
final boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
PlayerFunctions.sendMessage(plr, C.FLAG_NOT_ADDED);
|
MainUtil.sendMessage(plr, C.FLAG_NOT_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.FLAG_ADDED);
|
MainUtil.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());
|
MainUtil.sendMessage(plr, "&c" + e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("home")) {
|
if (args[0].equalsIgnoreCase("home")) {
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
if (args[1].equalsIgnoreCase("none")) {
|
if (args[1].equalsIgnoreCase("none")) {
|
||||||
plot.settings.setPosition(null);
|
plot.settings.setPosition(null);
|
||||||
DBFunc.setPosition(plr.getWorld().getName(), plot, "");
|
DBFunc.setPosition(loc.getWorld(), plot, "");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return PlayerFunctions.sendMessage(plr, C.HOME_ARGUMENT);
|
return MainUtil.sendMessage(plr, C.HOME_ARGUMENT);
|
||||||
}
|
}
|
||||||
//set to current location
|
//set to current location
|
||||||
World world = plr.getWorld();
|
final String world = plr.getLocation().getWorld();
|
||||||
Location base = PlotHelper.getPlotBottomLoc(world, plot.id);
|
final Location base = MainUtil.getPlotBottomLoc(world, plot.id);
|
||||||
base.setY(0);
|
base.setY(0);
|
||||||
Location relative = plr.getLocation().subtract(base);
|
final Location relative = plr.getLocation().subtract(base.getX(), base.getZ(), base.getY());
|
||||||
BlockLoc blockloc = new BlockLoc(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ());
|
final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ());
|
||||||
plot.settings.setPosition(blockloc);
|
plot.settings.setPosition(blockloc);
|
||||||
DBFunc.setPosition(plr.getWorld().getName(), plot, relative.getBlockX() + "," + relative.getBlockY() + "," + relative.getBlockZ());
|
DBFunc.setPosition(loc.getWorld(), plot, relative.getX() + "," + relative.getY() + "," + relative.getZ());
|
||||||
return PlayerFunctions.sendMessage(plr, C.POSITION_SET);
|
return MainUtil.sendMessage(plr, C.POSITION_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("alias")) {
|
if (args[0].equalsIgnoreCase("alias")) {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
PlayerFunctions.sendMessage(plr, C.MISSING_ALIAS);
|
MainUtil.sendMessage(plr, C.MISSING_ALIAS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String alias = args[1];
|
final String alias = args[1];
|
||||||
if (alias.length() >= 50) {
|
if (alias.length() >= 50) {
|
||||||
PlayerFunctions.sendMessage(plr, C.ALIAS_TOO_LONG);
|
MainUtil.sendMessage(plr, C.ALIAS_TOO_LONG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (final Plot p : PlotMain.getPlots(plr.getWorld()).values()) {
|
for (final Plot p : PlotSquared.getPlots(plr.getLocation().getWorld()).values()) {
|
||||||
if (p.settings.getAlias().equalsIgnoreCase(alias)) {
|
if (p.settings.getAlias().equalsIgnoreCase(alias)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (UUIDHandler.nameExists(new StringWrapper(alias))) {
|
if (UUIDHandler.nameExists(new StringWrapper(alias))) {
|
||||||
PlayerFunctions.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DBFunc.setAlias(plr.getWorld().getName(), plot, alias);
|
DBFunc.setAlias(loc.getWorld(), plot, alias);
|
||||||
PlayerFunctions.sendMessage(plr, C.ALIAS_SET_TO.s().replaceAll("%alias%", alias));
|
MainUtil.sendMessage(plr, C.ALIAS_SET_TO.s().replaceAll("%alias%", alias));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("biome")) {
|
if (args[0].equalsIgnoreCase("biome")) {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NEED_BIOME);
|
MainUtil.sendMessage(plr, C.NEED_BIOME);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args[1].length() < 2) {
|
if (args[1].length() < 2) {
|
||||||
sendMessage(plr, C.NAME_LITTLE, "Biome", args[1].length() + "", "2");
|
sendMessage(plr, C.NAME_LITTLE, "Biome", args[1].length() + "", "2");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
final int biome = BlockManager.manager.getBiomeFromString(args[1]);
|
||||||
final Biome biome = Biome.valueOf(new StringComparison(args[1], Biome.values()).getBestMatch());
|
|
||||||
/*
|
/*
|
||||||
* for (Biome b : Biome.values()) {
|
* for (Biome b : Biome.values()) {
|
||||||
* if (b.toString().equalsIgnoreCase(args[1])) {
|
* if (b.toString().equalsIgnoreCase(args[1])) {
|
||||||
@ -242,41 +204,38 @@ public class Set extends SubCommand {
|
|||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
if (biome == -1) {
|
||||||
if (biome == null) {
|
MainUtil.sendMessage(plr, getBiomeList(BlockManager.manager.getBiomeList()));
|
||||||
PlayerFunctions.sendMessage(plr, getBiomeList(Arrays.asList(Biome.values())));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PlotHelper.setBiome(plr.getWorld(), plot, biome);
|
MainUtil.setBiome(plr.getLocation().getWorld(), plot, args[1].toUpperCase());
|
||||||
PlayerFunctions.sendMessage(plr, C.BIOME_SET_TO.s() + biome.toString().toLowerCase());
|
MainUtil.sendMessage(plr, C.BIOME_SET_TO.s() + args[1].toLowerCase());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get components
|
// Get components
|
||||||
World world = plr.getWorld();
|
final String world = plr.getLocation().getWorld();
|
||||||
final PlotWorld plotworld = PlotMain.getWorldSettings(world);
|
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
|
||||||
PlotManager manager = PlotMain.getPlotManager(world);
|
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||||
String[] components = manager.getPlotComponents(world, plotworld, plot.id);
|
final String[] components = manager.getPlotComponents(plotworld, plot.id);
|
||||||
for (String component : components) {
|
for (final String component : components) {
|
||||||
if (component.equalsIgnoreCase(args[0])) {
|
if (component.equalsIgnoreCase(args[0])) {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NEED_BLOCK);
|
MainUtil.sendMessage(plr, C.NEED_BLOCK);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PlotBlock[] blocks;
|
PlotBlock[] blocks;
|
||||||
try {
|
try {
|
||||||
blocks = (PlotBlock[]) Configuration.BLOCKLIST.parseObject(args[2]);
|
blocks = (PlotBlock[]) Configuration.BLOCKLIST.parseObject(args[2]);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
try {
|
try {
|
||||||
blocks = new PlotBlock[] {new PlotBlock((short) getMaterial(args[1], PlotWorld.BLOCKS).getId(), (byte) 0)};
|
blocks = new PlotBlock[] { new PlotBlock((short) BlockManager.manager.getBlockIdFromString(args[2]), (byte) 0) };
|
||||||
} catch (Exception e2) {
|
} catch (final Exception e2) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_BLOCK);
|
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
manager.setComponent(world, plotworld, plot.id, component, blocks);
|
manager.setComponent(plotworld, plot.id, component, blocks);
|
||||||
PlayerFunctions.sendMessage(plr, C.GENERATING_COMPONENT);
|
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -294,26 +253,18 @@ public class Set extends SubCommand {
|
|||||||
a.append(" ").append(args[x]);
|
a.append(" ").append(args[x]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
plr.performCommand("plot set flag " + args[0] + a.toString());
|
MainCommand.onCommand(plr, world, ("plot set flag " + args[0] + a.toString()).split(" "));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(values));
|
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(values));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMaterial(final Material m) {
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", m.toString().toLowerCase()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getBiome(final Biome b) {
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", b.toString().toLowerCase()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getString(final String s) {
|
private String getString(final String s) {
|
||||||
return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", s));
|
return MainUtil.colorise('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", s));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getArgumentList(final String[] strings) {
|
private String getArgumentList(final String[] strings) {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
for (final String s : strings) {
|
for (final String s : strings) {
|
||||||
@ -321,27 +272,13 @@ public class Set extends SubCommand {
|
|||||||
}
|
}
|
||||||
return builder.toString().substring(1, builder.toString().length() - 1);
|
return builder.toString().substring(1, builder.toString().length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getBiomeList(final List<Biome> biomes) {
|
private String getBiomeList(final String[] biomes) {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
builder.append(ChatColor.translateAlternateColorCodes('&', C.NOT_VALID_BLOCK_LIST_HEADER.s()));
|
builder.append(MainUtil.colorise('&', C.NOT_VALID_BLOCK_LIST_HEADER.s()));
|
||||||
for (final Biome b : biomes) {
|
for (final String b : biomes) {
|
||||||
builder.append(getBiome(b));
|
builder.append(getString(b));
|
||||||
}
|
}
|
||||||
return builder.toString().substring(1, builder.toString().length() - 1);
|
return builder.toString().substring(1, builder.toString().length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Material getMaterial(final String input, final List<Material> blocks) {
|
|
||||||
return Material.valueOf(new StringComparison(input, blocks.toArray()).getBestMatch());
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getBlockList(final List<Material> blocks) {
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append(ChatColor.translateAlternateColorCodes('&', C.NOT_VALID_BLOCK_LIST_HEADER.s()));
|
|
||||||
for (final Material b : blocks) {
|
|
||||||
builder.append(getMaterial(b));
|
|
||||||
}
|
|
||||||
return builder.toString().substring(1, builder.toString().length() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,80 +18,69 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
public class SetOwner extends SubCommand {
|
public class SetOwner extends SubCommand {
|
||||||
|
|
||||||
public SetOwner() {
|
public SetOwner() {
|
||||||
super("setowner", "plots.set.owner", "Set the plot owner", "setowner {player}", "so", CommandCategory.ACTIONS, true);
|
super("setowner", "plots.set.owner", "Set the plot owner", "setowner {player}", "so", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* private UUID getUUID(String string) { OfflinePlayer player =
|
* private UUID getUUID(String string) { OfflinePlayer player =
|
||||||
* Bukkit.getOfflinePlayer(string); return ((player != null) &&
|
* Bukkit.getOfflinePlayer(string); return ((player != null) &&
|
||||||
* player.hasPlayedBefore()) ? UUIDHandler.getUUID(player) : null; }
|
* player.hasPlayedBefore()) ? UUIDHandler.getUUID(player) : null; }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private UUID getUUID(final String string) {
|
private UUID getUUID(final String string) {
|
||||||
return UUIDHandler.getUUID(string);
|
return UUIDHandler.getUUID(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
Location loc = plr.getLocation();
|
||||||
if (plot == null || plot.owner == null) {
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
if ((plot == null) || (plot.owner == null)) {
|
||||||
|
MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NEED_USER);
|
MainUtil.sendMessage(plr, C.NEED_USER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!plot.owner.equals(UUIDHandler.getUUID(plr)) && !Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
|
||||||
if (!plot.owner.equals(UUIDHandler.getUUID(plr)) && !PlotMain.hasPermission(plr, "plots.admin.command.setowner")) {
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.setowner");
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.setowner");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final World world = plr.getWorld();
|
final String world = loc.getWorld();
|
||||||
final PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id;
|
final PlotId bot = MainUtil.getBottomPlot(plot).id;
|
||||||
final PlotId top = PlayerFunctions.getTopPlot(world, plot).id;
|
final PlotId top = MainUtil.getTopPlot( plot).id;
|
||||||
final ArrayList<PlotId> plots = PlayerFunctions.getPlotSelectionIds(bot, top);
|
final ArrayList<PlotId> plots = MainUtil.getPlotSelectionIds(bot, top);
|
||||||
for (final PlotId id : plots) {
|
for (final PlotId id : plots) {
|
||||||
final Plot current = PlotMain.getPlots(world).get(id);
|
final Plot current = PlotSquared.getPlots(world).get(id);
|
||||||
|
final UUID uuid = getUUID(args[0]);
|
||||||
UUID uuid = getUUID(args[0]);
|
|
||||||
|
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
current.owner = uuid;
|
current.owner = uuid;
|
||||||
PlotMain.updatePlot(current);
|
PlotSquared.updatePlot(current);
|
||||||
DBFunc.setOwner(current, current.owner);
|
DBFunc.setOwner(current, current.owner);
|
||||||
|
|
||||||
if (PlotMain.worldGuardListener != null) {
|
|
||||||
PlotMain.worldGuardListener.changeOwner(plr, current.owner, plr.getWorld(), current);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
PlotHelper.setSign(world, args[0], plot);
|
MainUtil.setSign(args[0], plot);
|
||||||
PlayerFunctions.sendMessage(plr, C.SET_OWNER);
|
MainUtil.sendMessage(plr, C.SET_OWNER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,180 +18,116 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.World.Environment;
|
|
||||||
import org.bukkit.WorldCreator;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
import com.intellectualcrafters.plot.generator.SquarePlotManager;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotGenerator;
|
import com.intellectualcrafters.plot.object.SetupObject;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||||
|
|
||||||
public class Setup extends SubCommand {
|
public class Setup extends SubCommand {
|
||||||
|
|
||||||
public final static Map<String, SetupObject> setupMap = new HashMap<>();
|
|
||||||
public HashMap<String, PlotGenerator> generators = new HashMap<>();
|
|
||||||
|
|
||||||
public Setup() {
|
public Setup() {
|
||||||
super("setup", "plots.admin.command.setup", "Plotworld setup command", "setup", "create", CommandCategory.ACTIONS, true);
|
super("setup", "plots.admin.command.setup", "Plotworld setup command", "setup", "create", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SetupObject {
|
|
||||||
int current = 0;
|
|
||||||
int setup_index = 0;
|
|
||||||
String world = null;
|
|
||||||
String generator = null;
|
|
||||||
int type = 0;
|
|
||||||
int terrain = 0;
|
|
||||||
ConfigurationNode[] step = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateGenerators() {
|
|
||||||
if (generators.size() > 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String testWorld = "CheckingPlotSquaredGenerator";
|
|
||||||
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
|
||||||
if (plugin.isEnabled()) {
|
|
||||||
ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
|
|
||||||
if (generator != null) {
|
|
||||||
PlotMain.removePlotWorld(testWorld);
|
|
||||||
final String name = plugin.getDescription().getName();
|
|
||||||
if (generator instanceof PlotGenerator) {
|
|
||||||
PlotGenerator pgen = (PlotGenerator) generator;
|
|
||||||
if (pgen.getPlotManager() instanceof SquarePlotManager) {
|
|
||||||
generators.put(name, pgen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
// going through setup
|
// going through setup
|
||||||
|
final String name = plr.getName();
|
||||||
String name = plr.getName();
|
if (!SetupUtils.setupMap.containsKey(name)) {
|
||||||
if (!setupMap.containsKey(name)) {
|
final SetupObject object = new SetupObject();
|
||||||
SetupObject object = new SetupObject();
|
SetupUtils.setupMap.put(name, object);
|
||||||
setupMap.put(name, object);
|
SetupUtils.manager.updateGenerators();
|
||||||
updateGenerators();
|
final String prefix = "\n&8 - &7";
|
||||||
String prefix = "\n&8 - &7";
|
|
||||||
sendMessage(plr, C.SETUP_INIT);
|
sendMessage(plr, C.SETUP_INIT);
|
||||||
PlayerFunctions.sendMessage(plr, "&6What generator do you want?" + prefix + StringUtils.join(generators.keySet(), prefix).replaceAll("PlotSquared", "&2PlotSquared"));
|
MainUtil.sendMessage(plr, "&6What generator do you want?" + prefix + StringUtils.join(SetupUtils.generators.keySet(), prefix).replaceAll("PlotSquared", "&2PlotSquared"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
if (args[0].equalsIgnoreCase("cancel")) {
|
if (args[0].equalsIgnoreCase("cancel")) {
|
||||||
setupMap.remove(plr.getName());
|
SetupUtils.setupMap.remove(plr.getName());
|
||||||
PlayerFunctions.sendMessage(plr, "&aCancelled setup");
|
MainUtil.sendMessage(plr, "&aCancelled setup");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("back")) {
|
if (args[0].equalsIgnoreCase("back")) {
|
||||||
SetupObject object = setupMap.get(plr.getName());
|
final SetupObject object = SetupUtils.setupMap.get(plr.getName());
|
||||||
if (object.setup_index > 0) {
|
if (object.setup_index > 0) {
|
||||||
object.setup_index--;
|
object.setup_index--;
|
||||||
ConfigurationNode node = object.step[object.current];
|
final ConfigurationNode node = object.step[object.current];
|
||||||
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", node.getDescription(), node.getType().getType(), node.getDefaultValue() + "");
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", node.getDescription(), node.getType().getType(), node.getDefaultValue() + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if (object.current > 0) {
|
||||||
else if (object.current > 0 ){
|
|
||||||
object.current--;
|
object.current--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetupObject object = setupMap.get(name);
|
final SetupObject object = SetupUtils.setupMap.get(name);
|
||||||
int index = object.current;
|
final int index = object.current;
|
||||||
switch(index) {
|
switch (index) {
|
||||||
case 0: { // choose generator
|
case 0: { // choose generator
|
||||||
if (args.length != 1 || !generators.containsKey(args[0])) {
|
if ((args.length != 1) || !SetupUtils.generators.containsKey(args[0])) {
|
||||||
String prefix = "\n&8 - &7";
|
final String prefix = "\n&8 - &7";
|
||||||
PlayerFunctions.sendMessage(plr, "&cYou must choose a generator!" + prefix + StringUtils.join(generators.keySet(), prefix).replaceAll("PlotSquared", "&2PlotSquared"));
|
MainUtil.sendMessage(plr, "&cYou must choose a generator!" + prefix + StringUtils.join(SetupUtils.generators.keySet(), prefix).replaceAll("PlotSquared", "&2PlotSquared"));
|
||||||
sendMessage(plr, C.SETUP_INIT);
|
sendMessage(plr, C.SETUP_INIT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
object.generator = args[0];
|
object.generator = args[0];
|
||||||
object.current++;
|
object.current++;
|
||||||
|
final String partial = Settings.ENABLE_CLUSTERS ? "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots" : "";
|
||||||
String partial = Settings.ENABLE_CLUSTERS ? "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots" : "";
|
MainUtil.sendMessage(plr, "&6What world type do you want?" + "\n&8 - &2DEFAULT&8 - &7Standard plot generation" + "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain" + partial);
|
||||||
PlayerFunctions.sendMessage(plr, "&6What world type do you want?"
|
|
||||||
+ "\n&8 - &2DEFAULT&8 - &7Standard plot generation"
|
|
||||||
+ "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain"
|
|
||||||
+ partial);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1: { // choose world type
|
case 1: { // choose world type
|
||||||
List<String> types;
|
List<String> types;
|
||||||
if (Settings.ENABLE_CLUSTERS) {
|
if (Settings.ENABLE_CLUSTERS) {
|
||||||
types = Arrays.asList(new String[] {"default", "augmented", "partial"});
|
types = Arrays.asList(new String[] { "default", "augmented", "partial" });
|
||||||
|
} else {
|
||||||
|
types = Arrays.asList(new String[] { "default", "augmented" });
|
||||||
}
|
}
|
||||||
else {
|
if ((args.length != 1) || !types.contains(args[0].toLowerCase())) {
|
||||||
types = Arrays.asList(new String[] {"default", "augmented"});
|
MainUtil.sendMessage(plr, "&cYou must choose a world type!" + "\n&8 - &2DEFAULT&8 - &7Standard plot generation" + "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain" + "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots");
|
||||||
}
|
|
||||||
if (args.length != 1 || !types.contains(args[0].toLowerCase())) {
|
|
||||||
PlayerFunctions.sendMessage(plr, "&cYou must choose a world type!"
|
|
||||||
+ "\n&8 - &2DEFAULT&8 - &7Standard plot generation"
|
|
||||||
+ "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain"
|
|
||||||
+ "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
object.type = types.indexOf(args[0].toLowerCase());
|
object.type = types.indexOf(args[0].toLowerCase());
|
||||||
if (object.type == 0) {
|
if (object.type == 0) {
|
||||||
object.current++;
|
object.current++;
|
||||||
if (object.step == null) {
|
if (object.step == null) {
|
||||||
object.step = generators.get(object.generator).getNewPlotWorld(null).getSettingNodes();
|
object.step = SetupUtils.generators.get(object.generator).getNewPlotWorld(null).getSettingNodes();
|
||||||
}
|
}
|
||||||
ConfigurationNode step = object.step[object.setup_index];
|
final ConfigurationNode step = object.step[object.setup_index];
|
||||||
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||||
}
|
} else {
|
||||||
else {
|
MainUtil.sendMessage(plr, "&6What terrain would you like in plots?" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
|
||||||
PlayerFunctions.sendMessage(plr, "&6What terrain would you like in plots?"
|
|
||||||
+ "\n&8 - &2NONE&8 - &7No terrain at all"
|
|
||||||
+ "\n&8 - &7ORE&8 - &7Just some ore veins and trees"
|
|
||||||
+ "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
|
|
||||||
}
|
}
|
||||||
object.current++;
|
object.current++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2: { // Choose terrain
|
case 2: { // Choose terrain
|
||||||
List<String> terrain = Arrays.asList(new String[] {"none", "ore", "all"});
|
final List<String> terrain = Arrays.asList(new String[] { "none", "ore", "all" });
|
||||||
if (args.length != 1 || !terrain.contains(args[0].toLowerCase())) {
|
if ((args.length != 1) || !terrain.contains(args[0].toLowerCase())) {
|
||||||
PlayerFunctions.sendMessage(plr, "&cYou must choose the terrain!"
|
MainUtil.sendMessage(plr, "&cYou must choose the terrain!" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
|
||||||
+ "\n&8 - &2NONE&8 - &7No terrain at all"
|
|
||||||
+ "\n&8 - &7ORE&8 - &7Just some ore veins and trees"
|
|
||||||
+ "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
object.terrain = terrain.indexOf(args[0].toLowerCase());
|
object.terrain = terrain.indexOf(args[0].toLowerCase());
|
||||||
object.current++;
|
object.current++;
|
||||||
if (object.step == null) {
|
if (object.step == null) {
|
||||||
object.step = generators.get(object.generator).getNewPlotWorld(null).getSettingNodes();
|
object.step = SetupUtils.generators.get(object.generator).getNewPlotWorld(null).getSettingNodes();
|
||||||
}
|
}
|
||||||
ConfigurationNode step = object.step[object.setup_index];
|
final ConfigurationNode step = object.step[object.setup_index];
|
||||||
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 3: { // world setup
|
case 3: { // world setup
|
||||||
if (object.setup_index == object.step.length) {
|
if (object.setup_index == object.step.length) {
|
||||||
PlayerFunctions.sendMessage(plr, "&6What do you want your world to be called?");
|
MainUtil.sendMessage(plr, "&6What do you want your world to be called?");
|
||||||
object.setup_index = 0;
|
object.setup_index = 0;
|
||||||
object.current++;
|
object.current++;
|
||||||
return true;
|
return true;
|
||||||
@ -221,121 +157,27 @@ public class Setup extends SubCommand {
|
|||||||
}
|
}
|
||||||
case 4: {
|
case 4: {
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
PlayerFunctions.sendMessage(plr, "&cYou need to choose a world name!");
|
MainUtil.sendMessage(plr, "&cYou need to choose a world name!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Bukkit.getWorld(args[0]) != null) {
|
if (BlockManager.manager.isWorld(args[0])) {
|
||||||
PlayerFunctions.sendMessage(plr, "&cThat world name is already taken!");
|
MainUtil.sendMessage(plr, "&cThat world name is already taken!");
|
||||||
}
|
}
|
||||||
object.world = args[0];
|
object.world = args[0];
|
||||||
setupMap.remove(plr.getName());
|
SetupUtils.setupMap.remove(plr.getName());
|
||||||
World world = setupWorld(object);
|
final String world = SetupUtils.manager.setupWorld(object);
|
||||||
try {
|
try {
|
||||||
plr.teleport(world.getSpawnLocation());
|
plr.teleport(BlockManager.manager.getSpawn(world));
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
plr.sendMessage("&cAn error occured. See console for more information");
|
plr.sendMessage("&cAn error occured. See console for more information");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
sendMessage(plr, C.SETUP_FINISHED, object.world);
|
sendMessage(plr, C.SETUP_FINISHED, object.world);
|
||||||
setupMap.remove(plr.getName());
|
SetupUtils.setupMap.remove(plr.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* 0.0 normal hybrid no clusters
|
|
||||||
* 0.1 normal hybrid with clusters
|
|
||||||
* 0.2 normal hybrid require clusters
|
|
||||||
* 1.0 augmented whole world
|
|
||||||
* 1.1 augmented whole world with ore
|
|
||||||
* 1.2 augmented whole world with terrain
|
|
||||||
* 2.1 augmented partial world
|
|
||||||
* 2.2 augmented partial world with ore
|
|
||||||
* 2.3 augmented partial world with terrain
|
|
||||||
* 3.0 no generation + normal manager
|
|
||||||
*
|
|
||||||
* generator.TYPE: PlotSquared, augmented, partial
|
|
||||||
* generator.TERRAIN
|
|
||||||
*
|
|
||||||
* WORLD.TYPE: hybrid, augmented, partial
|
|
||||||
* if (augmented/partial)
|
|
||||||
* WORLD.TERRAIN:
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* types (0, 1, 2, 3)
|
|
||||||
* 0: no options
|
|
||||||
* 1:
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* - return null
|
|
||||||
* - schedule task to create world later
|
|
||||||
* - externalize multiverse/world hooks to separate class
|
|
||||||
* - create vanilla world
|
|
||||||
* - add augmented populator
|
|
||||||
* - add config option type
|
|
||||||
* - Work on heirarchy for setting nodes so you don't need to provide irrelevent info (world setup)
|
|
||||||
* - use code from setup command for world arguments (above) so that it persists
|
|
||||||
* - work on plot clearing for augmented plot worlds (terrain) (heads, banners, paintings, animals, inventoryhandler)
|
|
||||||
* - make a generic clear function for any generator
|
|
||||||
* - clean up plotmanager class (remove unnecessary methods)
|
|
||||||
* - make simple plot manager which can be used by external generators (don't make abstract)
|
|
||||||
* - plugins will override any of it's methods
|
|
||||||
* - make heirarchy of generators of increasing abstraction:
|
|
||||||
* = totally abstract (circle plots, moving plots, no tesselation)
|
|
||||||
* = tessellating generator
|
|
||||||
* = grid generator
|
|
||||||
* = square generator
|
|
||||||
* = square plot generator (must have plot section and road section) (plot height, road height)
|
|
||||||
* = hybrid generator
|
|
||||||
*
|
|
||||||
* - All will support whole world augmentation
|
|
||||||
* - Only grid will support partial plot worlds
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public World setupWorld(SetupObject object) {
|
|
||||||
// Configuration
|
|
||||||
final ConfigurationNode[] steps = object.step;
|
|
||||||
final String world = object.world;
|
|
||||||
for (final ConfigurationNode step : steps) {
|
|
||||||
PlotMain.config.set("worlds." + world + "." + step.getConstant(), step.getValue());
|
|
||||||
}
|
|
||||||
if (object.type != 0) {
|
|
||||||
PlotMain.config.set("worlds." + world + "." + "generator.type", object.type);
|
|
||||||
PlotMain.config.set("worlds." + world + "." + "generator.terrain", object.terrain);
|
|
||||||
PlotMain.config.set("worlds." + world + "." + "generator.plugin", object.generator);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
PlotMain.config.save(PlotMain.configFile);
|
|
||||||
} catch (final IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (object.type == 0) {
|
|
||||||
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.generator);
|
|
||||||
} else {
|
|
||||||
if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.generator);
|
|
||||||
} else {
|
|
||||||
WorldCreator wc = new WorldCreator(object.world);
|
|
||||||
wc.generator(object.generator);
|
|
||||||
wc.environment(Environment.NORMAL);
|
|
||||||
World newWorld = Bukkit.createWorld(wc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal");
|
|
||||||
} else {
|
|
||||||
if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world);
|
|
||||||
} else {
|
|
||||||
Bukkit.createWorld(new WorldCreator(object.world).environment(World.Environment.NORMAL));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Bukkit.getWorld(object.world);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,24 +18,22 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SubCommand class
|
* SubCommand class
|
||||||
*
|
*
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"deprecation", "unused"}) public abstract class SubCommand {
|
@SuppressWarnings({ "deprecation", "unused" })
|
||||||
|
public abstract class SubCommand {
|
||||||
/**
|
/**
|
||||||
* Command
|
* Command
|
||||||
*/
|
*/
|
||||||
@ -64,7 +62,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
* Is this a player-online command?
|
* Is this a player-online command?
|
||||||
*/
|
*/
|
||||||
public final boolean isPlayer;
|
public final boolean isPlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param cmd Command /plot {cmd} <-- That!
|
* @param cmd Command /plot {cmd} <-- That!
|
||||||
* @param permission Permission Node
|
* @param permission Permission Node
|
||||||
@ -83,7 +81,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
this.category = category;
|
this.category = category;
|
||||||
this.isPlayer = isPlayer;
|
this.isPlayer = isPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param cmd Command /plot {cmd} <-- That!
|
* @param cmd Command /plot {cmd} <-- That!
|
||||||
* @param permission Permission Node
|
* @param permission Permission Node
|
||||||
@ -102,7 +100,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
this.category = category;
|
this.category = category;
|
||||||
this.isPlayer = isPlayer;
|
this.isPlayer = isPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param command Command /plot {cmd} <-- That!
|
* @param command Command /plot {cmd} <-- That!
|
||||||
* @param description Simple description
|
* @param description Simple description
|
||||||
@ -119,7 +117,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
this.category = category;
|
this.category = category;
|
||||||
this.isPlayer = isPlayer;
|
this.isPlayer = isPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute.
|
* Execute.
|
||||||
*
|
*
|
||||||
@ -128,8 +126,8 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
*
|
*
|
||||||
* @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 PlotPlayer plr, final String... args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the command as console
|
* Execute the command as console
|
||||||
*
|
*
|
||||||
@ -138,7 +136,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
public void executeConsole(final String... args) {
|
public void executeConsole(final String... args) {
|
||||||
this.execute(null, args);
|
this.execute(null, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message
|
* Send a message
|
||||||
*
|
*
|
||||||
@ -146,14 +144,14 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
* @param c Caption
|
* @param c Caption
|
||||||
* @param args Arguments (%s's)
|
* @param args Arguments (%s's)
|
||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player,
|
* @see com.intellectualcrafters.plot.util.bukkit.BukkitPlayerFunctions#sendMessage(org.bukkit.entity.Player,
|
||||||
* com.intellectualcrafters.plot.config.C, String...)
|
* com.intellectualcrafters.plot.config.C, String...)
|
||||||
*/
|
*/
|
||||||
public boolean sendMessage(final Player plr, final C c, final String... args) {
|
public boolean sendMessage(final PlotPlayer plr, final C c, final String... args) {
|
||||||
PlayerFunctions.sendMessage(plr, c, args);
|
MainUtil.sendMessage(plr, c, args);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CommandCategory
|
* CommandCategory
|
||||||
*
|
*
|
||||||
@ -191,12 +189,11 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
* Such as: /plot debug
|
* Such as: /plot debug
|
||||||
*/
|
*/
|
||||||
DEBUG("Debug");
|
DEBUG("Debug");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The category name (Readable)
|
* The category name (Readable)
|
||||||
*/
|
*/
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -205,7 +202,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
CommandCategory(final String name) {
|
CommandCategory(final String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.name;
|
return this.name;
|
||||||
|
@ -18,21 +18,19 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.object.PlotSelection;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.AChunkManager;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2014-08-01 for PlotSquared
|
* Created 2014-08-01 for PlotSquared
|
||||||
@ -40,60 +38,56 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
* @author Empire92
|
* @author Empire92
|
||||||
*/
|
*/
|
||||||
public class Swap extends SubCommand {
|
public class Swap extends SubCommand {
|
||||||
|
|
||||||
public Swap() {
|
public Swap() {
|
||||||
super(Command.SWAP, "Swap two plots", "switch", CommandCategory.ACTIONS, true);
|
super(Command.SWAP, "Swap two plots", "switch", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NEED_PLOT_ID);
|
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
||||||
PlayerFunctions.sendMessage(plr, C.SWAP_SYNTAX);
|
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
return false;
|
if (plot == null) {
|
||||||
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.swap")) {
|
||||||
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !PlotMain.hasPermission(plr, "plots.admin.command.swap")) {
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((plot != null) && plot.settings.isMerged()) {
|
if ((plot != null) && plot.settings.isMerged()) {
|
||||||
PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED);
|
MainUtil.sendMessage(plr, C.UNLINK_REQUIRED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String id = args[0];
|
final String id = args[0];
|
||||||
PlotId plotid;
|
PlotId plotid;
|
||||||
final World world = plr.getWorld();
|
final String world = loc.getWorld();
|
||||||
try {
|
try {
|
||||||
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]));
|
||||||
final Plot plot2 = PlotMain.getPlots(world).get(plotid);
|
final Plot plot2 = PlotSquared.getPlots(world).get(plotid);
|
||||||
if (((plot2 == null) || !plot2.hasOwner() || (plot2.owner != UUIDHandler.getUUID(plr))) && !PlotMain.hasPermission(plr, "plots.admin.command.swap")) {
|
if (((plot2 == null) || !plot2.hasOwner() || (plot2.owner != UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.swap")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE, plotid.toString());
|
MainUtil.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);
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
PlayerFunctions.sendMessage(plr, C.SWAP_SYNTAX);
|
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
assert plot != null;
|
assert plot != null;
|
||||||
if (plot.id.equals(plotid)) {
|
if (plot.id.equals(plotid)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
PlayerFunctions.sendMessage(plr, C.SWAP_SYNTAX);
|
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotSelection.swap(world, plot.id, plotid);
|
AChunkManager.manager.swap(world, plot.id, plotid);
|
||||||
|
// FIXME Requires testing!!
|
||||||
// TODO Requires testing!!
|
DBFunc.dbManager.swapPlots(plot, MainUtil.getPlot(world, plotid));
|
||||||
DBFunc.dbManager.swapPlots(plot, PlotHelper.getPlot(world, plotid));
|
MainUtil.sendMessage(plr, C.SWAP_SUCCESS);
|
||||||
// TODO Requires testing!!
|
MainUtil.update(plr.getLocation());
|
||||||
|
|
||||||
PlayerFunctions.sendMessage(plr, C.SWAP_SUCCESS);
|
|
||||||
PlotHelper.update(plr.getLocation());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,65 +18,64 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class TP extends SubCommand {
|
public class TP extends SubCommand {
|
||||||
|
|
||||||
public TP() {
|
public TP() {
|
||||||
super(Command.TP, "Teleport to a plot", "tp {alias|id}", CommandCategory.TELEPORT, true);
|
super(Command.TP, "Teleport to a plot", "tp {alias|id}", CommandCategory.TELEPORT, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NEED_PLOT_ID);
|
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String id = args[0];
|
final String id = args[0];
|
||||||
PlotId plotid;
|
PlotId plotid;
|
||||||
World world = plr.getWorld();
|
Location loc = plr.getLocation();
|
||||||
|
String pworld = loc.getWorld();
|
||||||
|
String world = pworld;
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
if (Bukkit.getWorld(args[1]) != null) {
|
if (BlockManager.manager.isWorld(args[1])) {
|
||||||
world = Bukkit.getWorld(args[1]);
|
world = args[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!PlotMain.isPlotWorld(world)) {
|
if (!PlotSquared.isPlotWorld(world)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Plot temp;
|
Plot temp;
|
||||||
if ((temp = isAlias(world, id)) != null) {
|
if ((temp = isAlias(world, id)) != null) {
|
||||||
PlotMain.teleportPlayer(plr, plr.getLocation(), temp);
|
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
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));
|
MainUtil.teleportPlayer(plr, plr.getLocation(), MainUtil.getPlot(world, plotid));
|
||||||
return true;
|
return true;
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Plot isAlias(final World world, String a) {
|
private Plot isAlias(final String world, String a) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
if (a.contains(";")) {
|
if (a.contains(";")) {
|
||||||
final String[] split = a.split(";");
|
final String[] split = a.split(";");
|
||||||
@ -85,16 +84,16 @@ public class TP extends SubCommand {
|
|||||||
}
|
}
|
||||||
a = split[0];
|
a = split[0];
|
||||||
}
|
}
|
||||||
@SuppressWarnings("deprecation") final Player player = Bukkit.getPlayer(a);
|
final PlotPlayer player = UUIDHandler.getPlayer(a);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
final java.util.Set<Plot> plotMainPlots = PlotMain.getPlots(world, player);
|
final java.util.Set<Plot> plotMainPlots = PlotSquared.getPlots(world, player);
|
||||||
final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]);
|
final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]);
|
||||||
if (plots.length > index) {
|
if (plots.length > index) {
|
||||||
return plots[index];
|
return plots[index];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (final Plot p : PlotMain.getPlots(world).values()) {
|
for (final Plot p : PlotSquared.getPlots(world).values()) {
|
||||||
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
|
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -18,42 +18,39 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
|
||||||
public class Target extends SubCommand {
|
public class Target extends SubCommand {
|
||||||
|
|
||||||
public Target() {
|
public Target() {
|
||||||
super(Command.TARGET, "Target a plot with your compass", "target <X;Z>", CommandCategory.ACTIONS, true);
|
super(Command.TARGET, "Target a plot with your compass", "target <X;Z>", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (!PlotMain.isPlotWorld(plr.getWorld())) {
|
Location ploc = plr.getLocation();
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
if (!PlotSquared.isPlotWorld(ploc.getWorld())) {
|
||||||
|
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
PlotId id = PlotHelper.parseId(args[1]);
|
final PlotId id = MainUtil.parseId(args[1]);
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Location loc = PlotHelper.getPlotHome(plr.getWorld(), id);
|
final Location loc = MainUtil.getPlotHome(ploc.getWorld(), id);
|
||||||
plr.setCompassTarget(loc);
|
plr.setCompassTarget(loc);
|
||||||
PlayerFunctions.sendMessage(plr, C.COMPASS_TARGET);
|
MainUtil.sendMessage(plr, C.COMPASS_TARGET);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot target <X;Z>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot target <X;Z>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,31 +18,66 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
|
||||||
public class Template extends SubCommand {
|
public class Template extends SubCommand {
|
||||||
|
|
||||||
public Template() {
|
public Template() {
|
||||||
super("template", "plots.admin", "Create or use a world template", "template", "", CommandCategory.DEBUG, true);
|
super("template", "plots.admin", "Create or use a world template", "template", "", CommandCategory.DEBUG, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template <import|export> <world>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template <import|export> <world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
String world = args[1];
|
||||||
|
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
|
||||||
|
if (!BlockManager.manager.isWorld(world) || (plotworld == null)) {
|
||||||
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "import": {
|
||||||
|
// TODO import template
|
||||||
|
MainUtil.sendMessage(plr, "TODO");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case "export": {
|
||||||
|
MainUtil.sendMessage(plr, "TODO");
|
||||||
|
}
|
||||||
|
}
|
||||||
// TODO allow world settings (including schematics to be packed into a single file)
|
// TODO allow world settings (including schematics to be packed into a single file)
|
||||||
|
|
||||||
// TODO allow world created based on these packaged files
|
// TODO allow world created based on these packaged files
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void gzipIt(final String output, final String input) {
|
||||||
|
final byte[] buffer = new byte[1024];
|
||||||
|
try {
|
||||||
|
final GZIPOutputStream gzos = new GZIPOutputStream(new FileOutputStream(output));
|
||||||
|
final FileInputStream in = new FileInputStream(input);
|
||||||
|
int len;
|
||||||
|
while ((len = in.read(buffer)) > 0) {
|
||||||
|
gzos.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
gzos.finish();
|
||||||
|
gzos.close();
|
||||||
|
} catch (final IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -28,85 +27,75 @@ import java.nio.file.Paths;
|
|||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.generator.SquarePlotManager;
|
|
||||||
import com.intellectualcrafters.plot.generator.SquarePlotWorld;
|
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.ExpireManager;
|
import com.intellectualcrafters.plot.util.AChunkManager;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.ChunkManager;
|
||||||
|
|
||||||
public class Trim extends SubCommand {
|
public class Trim extends SubCommand {
|
||||||
|
|
||||||
public static boolean TASK = false;
|
public static boolean TASK = false;
|
||||||
private static int TASK_ID = 0;
|
private static int TASK_ID = 0;
|
||||||
|
|
||||||
public Trim() {
|
public Trim() {
|
||||||
super("trim", "plots.admin", "Delete unmodified portions of your plotworld", "trim", "", CommandCategory.DEBUG, false);
|
super("trim", "plots.admin", "Delete unmodified portions of your plotworld", "trim", "", CommandCategory.DEBUG, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlotId getId(String id) {
|
public PlotId getId(final String id) {
|
||||||
try {
|
try {
|
||||||
String[] split = id.split(";");
|
final String[] split = id.split(";");
|
||||||
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (plr != null) {
|
if (plr != null) {
|
||||||
PlayerFunctions.sendMessage(plr, (C.NOT_CONSOLE));
|
MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
String arg = args[0].toLowerCase();
|
final String arg = args[0].toLowerCase();
|
||||||
PlotId id = getId(arg);
|
final PlotId id = getId(arg);
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
PlayerFunctions.sendMessage(plr, "/plot trim x;z &l<world>");
|
MainUtil.sendMessage(plr, "/plot trim x;z &l<world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (arg.equals("all")) {
|
if (arg.equals("all")) {
|
||||||
PlayerFunctions.sendMessage(plr, "/plot trim all &l<world>");
|
MainUtil.sendMessage(plr, "/plot trim all &l<world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.TRIM_SYNTAX);
|
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
PlayerFunctions.sendMessage(plr, C.TRIM_SYNTAX);
|
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String arg = args[0].toLowerCase();
|
final String arg = args[0].toLowerCase();
|
||||||
if (!arg.equals("all")) {
|
if (!arg.equals("all")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.TRIM_SYNTAX);
|
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final World world = Bukkit.getWorld(args[1]);
|
final String world = args[1];
|
||||||
if (world == null || PlotMain.getWorldSettings(world) == null) {
|
if (!BlockManager.manager.isWorld(world) || (PlotSquared.getPlotWorld(world) == null)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_WORLD);
|
MainUtil.sendMessage(plr, C.NOT_VALID_WORLD);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Trim.TASK) {
|
if (Trim.TASK) {
|
||||||
sendMessage(C.TRIM_IN_PROGRESS.s());
|
sendMessage(C.TRIM_IN_PROGRESS.s());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(C.TRIM_START.s());
|
sendMessage(C.TRIM_START.s());
|
||||||
final ArrayList<ChunkLoc> empty = new ArrayList<>();
|
final ArrayList<ChunkLoc> empty = new ArrayList<>();
|
||||||
getTrimRegions(empty, world, new Runnable() {
|
getTrimRegions(empty, world, new Runnable() {
|
||||||
@ -118,52 +107,48 @@ public class Trim extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getBulkRegions(final ArrayList<ChunkLoc> empty, final World world, final Runnable whenDone) {
|
public static boolean getBulkRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
|
||||||
if (Trim.TASK) {
|
if (Trim.TASK) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String directory = world.getName() + File.separator + "region";
|
final String directory = world + File.separator + "region";
|
||||||
File folder = new File(directory);
|
final File folder = new File(directory);
|
||||||
File[] regionFiles = folder.listFiles();
|
final File[] regionFiles = folder.listFiles();
|
||||||
for (File file : regionFiles) {
|
for (final File file : regionFiles) {
|
||||||
String name = file.getName();
|
final String name = file.getName();
|
||||||
if (name.endsWith("mca")) {
|
if (name.endsWith("mca")) {
|
||||||
if (file.getTotalSpace() <= 8192) {
|
if (file.getTotalSpace() <= 8192) {
|
||||||
try {
|
try {
|
||||||
String[] split = name.split("\\.");
|
final String[] split = name.split("\\.");
|
||||||
int x = Integer.parseInt(split[1]);
|
final int x = Integer.parseInt(split[1]);
|
||||||
int z = Integer.parseInt(split[2]);
|
final int z = Integer.parseInt(split[2]);
|
||||||
ChunkLoc loc = new ChunkLoc(x, z);
|
final ChunkLoc loc = new ChunkLoc(x, z);
|
||||||
empty.add(loc);
|
empty.add(loc);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
System.out.print("INVALID MCA: " + name);
|
System.out.print("INVALID MCA: " + name);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
final Path path = Paths.get(file.getPath());
|
||||||
Path path = Paths.get(file.getPath());
|
|
||||||
try {
|
try {
|
||||||
BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
|
final BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
|
||||||
long creation = attr.creationTime().toMillis();
|
final long creation = attr.creationTime().toMillis();
|
||||||
long modification = file.lastModified();
|
final long modification = file.lastModified();
|
||||||
long diff = Math.abs(creation - modification);
|
final long diff = Math.abs(creation - modification);
|
||||||
if (diff < 10000) {
|
if (diff < 10000) {
|
||||||
try {
|
try {
|
||||||
String[] split = name.split("\\.");
|
final String[] split = name.split("\\.");
|
||||||
int x = Integer.parseInt(split[1]);
|
final int x = Integer.parseInt(split[1]);
|
||||||
int z = Integer.parseInt(split[2]);
|
final int z = Integer.parseInt(split[2]);
|
||||||
ChunkLoc loc = new ChunkLoc(x, z);
|
final ChunkLoc loc = new ChunkLoc(x, z);
|
||||||
empty.add(loc);
|
empty.add(loc);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
System.out.print("INVALID MCA: " + name);
|
System.out.print("INVALID MCA: " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,91 +161,57 @@ public class Trim extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getTrimRegions(final ArrayList<ChunkLoc> empty, final World world, final Runnable whenDone) {
|
public static boolean getTrimRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
|
||||||
if (Trim.TASK) {
|
if (Trim.TASK) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final long startOld = System.currentTimeMillis();
|
final long startOld = System.currentTimeMillis();
|
||||||
sendMessage("Collecting region data...");
|
sendMessage("Collecting region data...");
|
||||||
final ArrayList<Plot> plots = new ArrayList<>();
|
final ArrayList<Plot> plots = new ArrayList<>();
|
||||||
plots.addAll(PlotMain.getPlots(world).values());
|
plots.addAll(PlotSquared.getPlots(world).values());
|
||||||
final HashSet<ChunkLoc> chunks = new HashSet<>(ChunkManager.getChunkChunks(world));
|
final HashSet<ChunkLoc> chunks = new HashSet<>(AChunkManager.manager.getChunkChunks(world));
|
||||||
sendMessage(" - MCA #: " + chunks.size());
|
sendMessage(" - MCA #: " + chunks.size());
|
||||||
sendMessage(" - CHUNKS: " + (chunks.size() * 1024) +" (max)");
|
sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)");
|
||||||
sendMessage(" - TIME ESTIMATE: " + (chunks.size()/1200) +" minutes");
|
sendMessage(" - TIME ESTIMATE: " + (chunks.size() / 1200) + " minutes");
|
||||||
Trim.TASK_ID = Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable() {
|
Trim.TASK_ID = TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
while (System.currentTimeMillis() - start < 50) {
|
while ((System.currentTimeMillis() - start) < 50) {
|
||||||
if (plots.size() == 0) {
|
if (plots.size() == 0) {
|
||||||
empty.addAll(chunks);
|
empty.addAll(chunks);
|
||||||
System.out.print("DONE!");
|
System.out.print("DONE!");
|
||||||
Trim.TASK = false;
|
Trim.TASK = false;
|
||||||
TaskManager.runTaskAsync(whenDone);
|
TaskManager.runTaskAsync(whenDone);
|
||||||
Bukkit.getScheduler().cancelTask(Trim.TASK_ID);
|
PlotSquared.TASK.cancelTask(Trim.TASK_ID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Plot plot = plots.get(0);
|
final Plot plot = plots.get(0);
|
||||||
plots.remove(0);
|
plots.remove(0);
|
||||||
Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id);
|
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id);
|
||||||
Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id);
|
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
|
||||||
|
final Location pos3 = new Location(world, pos1.getX(), 64, pos2.getZ());
|
||||||
Location pos3 = new Location(world, pos1.getBlockX(), 64, pos2.getBlockZ());
|
final Location pos4 = new Location(world, pos2.getX(), 64, pos1.getZ());
|
||||||
Location pos4 = new Location(world, pos2.getBlockX(), 64, pos1.getBlockZ());
|
|
||||||
|
|
||||||
chunks.remove(ChunkManager.getChunkChunk(pos1));
|
chunks.remove(ChunkManager.getChunkChunk(pos1));
|
||||||
chunks.remove(ChunkManager.getChunkChunk(pos2));
|
chunks.remove(ChunkManager.getChunkChunk(pos2));
|
||||||
chunks.remove(ChunkManager.getChunkChunk(pos3));
|
chunks.remove(ChunkManager.getChunkChunk(pos3));
|
||||||
chunks.remove(ChunkManager.getChunkChunk(pos4));
|
chunks.remove(ChunkManager.getChunkChunk(pos4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 20L, 20L);
|
}, 20);
|
||||||
Trim.TASK = true;
|
Trim.TASK = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Plot> expired = null;
|
public static ArrayList<Plot> expired = null;
|
||||||
|
|
||||||
// public static void updateUnmodifiedPlots(final World world) {
|
public static void deleteChunks(final String world, final ArrayList<ChunkLoc> chunks) {
|
||||||
// final SquarePlotManager manager = (SquarePlotManager) PlotMain.getPlotManager(world);
|
for (final ChunkLoc loc : chunks) {
|
||||||
// final SquarePlotWorld plotworld = (SquarePlotWorld) PlotMain.getWorldSettings(world);
|
AChunkManager.manager.deleteRegionFile(world, loc);
|
||||||
// final ArrayList<Plot> expired = new ArrayList<>();
|
|
||||||
// final Set<Plot> plots = ExpireManager.getOldPlots(world.getName()).keySet();
|
|
||||||
// sendMessage("Checking " + plots.size() +" plots! This may take a long time...");
|
|
||||||
// Trim.TASK_ID = Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable() {
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// if (manager != null && plots.size() > 0) {
|
|
||||||
// Plot plot = plots.iterator().next();
|
|
||||||
// if (plot.hasOwner()) {
|
|
||||||
// SquarePlotManager.checkModified(plot, 0);
|
|
||||||
// }
|
|
||||||
// if (plot.owner == null || !SquarePlotManager.checkModified(plot, plotworld.REQUIRED_CHANGES)) {
|
|
||||||
// expired.add(plot);
|
|
||||||
// sendMessage("found expired: " + plot);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// Trim.expired = expired;
|
|
||||||
// Trim.TASK = false;
|
|
||||||
// sendMessage("Done!");
|
|
||||||
// Bukkit.getScheduler().cancelTask(Trim.TASK_ID);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }, 1, 1);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
public static void deleteChunks(World world, ArrayList<ChunkLoc> chunks) {
|
|
||||||
String worldname = world.getName();
|
|
||||||
for (ChunkLoc loc : chunks) {
|
|
||||||
ChunkManager.deleteRegionFile(worldname, loc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(final String message) {
|
public static void sendMessage(final String message) {
|
||||||
PlotMain.sendConsoleSenderMessage("&3PlotSquared -> World trim&8: &7" + message);
|
PlotSquared.log("&3PlotSquared -> World trim&8: &7" + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,102 +18,96 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.events.PlayerPlotTrustedEvent;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
@SuppressWarnings("deprecation") public class Trusted extends SubCommand {
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public class Trusted extends SubCommand {
|
||||||
public Trusted() {
|
public Trusted() {
|
||||||
super(Command.TRUSTED, "Manage trusted users for a plot", "trusted {add|remove} {player}", CommandCategory.ACTIONS, true);
|
super(Command.TRUSTED, "Manage trusted users for a plot", "trusted {add|remove} {player}", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
PlayerFunctions.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
|
MainUtil.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
return true;
|
if (plot == null) {
|
||||||
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if ((plot == null) || !plot.hasOwner()) {
|
if ((plot == null) || !plot.hasOwner()) {
|
||||||
PlayerFunctions.sendMessage(plr, C.PLOT_UNOWNED);
|
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.getOwner().equals(UUIDHandler.getUUID(plr)) && !PlotMain.hasPermission(plr, "plots.admin.command.trusted")) {
|
if (!plot.getOwner().equals(UUIDHandler.getUUID(plr)) && !Permissions.hasPermission(plr, "plots.admin.command.trusted")) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("add")) {
|
if (args[0].equalsIgnoreCase("add")) {
|
||||||
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 (uuid == null) {
|
if (uuid == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.trusted.contains(uuid)) {
|
if (!plot.trusted.contains(uuid)) {
|
||||||
if (plot.owner.equals(uuid)) {
|
if (plot.owner.equals(uuid)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER);
|
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot.helpers.contains(uuid)) {
|
if (plot.helpers.contains(uuid)) {
|
||||||
plot.helpers.remove(uuid);
|
plot.helpers.remove(uuid);
|
||||||
DBFunc.removeHelper(plr.getWorld().getName(), plot, uuid);
|
DBFunc.removeHelper(loc.getWorld(), plot, uuid);
|
||||||
}
|
}
|
||||||
if (plot.denied.contains(uuid)) {
|
if (plot.denied.contains(uuid)) {
|
||||||
plot.denied.remove(uuid);
|
plot.denied.remove(uuid);
|
||||||
DBFunc.removeDenied(plr.getWorld().getName(), plot, uuid);
|
DBFunc.removeDenied(loc.getWorld(), plot, uuid);
|
||||||
}
|
}
|
||||||
plot.addTrusted(uuid);
|
plot.addTrusted(uuid);
|
||||||
DBFunc.setTrusted(plr.getWorld().getName(), plot, uuid);
|
DBFunc.setTrusted(loc.getWorld(), plot, uuid);
|
||||||
final PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, true);
|
// FIXME PlayerPlotTrustedEvent
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
|
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED);
|
MainUtil.sendMessage(plr, C.TRUSTED_ADDED);
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
} else if (args[0].equalsIgnoreCase("remove")) {
|
||||||
if (args[1].equalsIgnoreCase("*")) {
|
if (args[1].equalsIgnoreCase("*")) {
|
||||||
final UUID uuid = DBFunc.everyone;
|
final UUID uuid = DBFunc.everyone;
|
||||||
if (!plot.trusted.contains(uuid)) {
|
if (!plot.trusted.contains(uuid)) {
|
||||||
PlayerFunctions.sendMessage(plr, C.T_WAS_NOT_ADDED);
|
MainUtil.sendMessage(plr, C.T_WAS_NOT_ADDED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
plot.removeTrusted(uuid);
|
plot.removeTrusted(uuid);
|
||||||
DBFunc.removeTrusted(plr.getWorld().getName(), plot, uuid);
|
DBFunc.removeTrusted(loc.getWorld(), plot, uuid);
|
||||||
PlayerFunctions.sendMessage(plr, C.TRUSTED_REMOVED);
|
MainUtil.sendMessage(plr, C.TRUSTED_REMOVED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
||||||
plot.removeTrusted(uuid);
|
plot.removeTrusted(uuid);
|
||||||
DBFunc.removeTrusted(plr.getWorld().getName(), plot, uuid);
|
DBFunc.removeTrusted(loc.getWorld(), plot, uuid);
|
||||||
final PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, false);
|
// FIXME PlayerPlotTrustedEvent
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
MainUtil.sendMessage(plr, C.TRUSTED_REMOVED);
|
||||||
PlayerFunctions.sendMessage(plr, C.TRUSTED_REMOVED);
|
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
|
MainUtil.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package com.intellectualcrafters.plot.commands;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created 2014-11-09 for PlotSquared
|
|
||||||
*
|
|
||||||
* @author Citymonstret
|
|
||||||
*/
|
|
||||||
public class Unban extends SubCommand {
|
|
||||||
|
|
||||||
public Unban() {
|
|
||||||
super(Command.UNBAN, "Alias for /plot denied remove", "/plot unban [player]", CommandCategory.ACTIONS, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(final Player plr, final String... args) {
|
|
||||||
if (args.length < 1) {
|
|
||||||
return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + this.usage);
|
|
||||||
}
|
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
|
||||||
}
|
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
||||||
if (!plot.hasRights(plr)) {
|
|
||||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
|
||||||
}
|
|
||||||
return plr.performCommand("plot denied remove " + args[0]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,61 +18,60 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// 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 net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.EconHandler;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
public class Unclaim extends SubCommand {
|
public class Unclaim extends SubCommand {
|
||||||
|
|
||||||
public Unclaim() {
|
public Unclaim() {
|
||||||
super(Command.UNCLAIM, "Unclaim a plot", "unclaim", CommandCategory.ACTIONS, true);
|
super(Command.UNCLAIM, "Unclaim a plot", "unclaim", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
|
if (plot == null) {
|
||||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||||
if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
|
|
||||||
return !sendMessage(plr, C.UNLINK_REQUIRED);
|
return !sendMessage(plr, C.UNLINK_REQUIRED);
|
||||||
}
|
}
|
||||||
if ((((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr)))) && !PlotMain.hasPermission(plr, "plots.admin.command.unclaim")) {
|
if ((((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) {
|
||||||
return !sendMessage(plr, C.NO_PLOT_PERMS);
|
return !sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
}
|
}
|
||||||
assert plot != null;
|
assert plot != null;
|
||||||
final PlotWorld pWorld = PlotMain.getWorldSettings(plot.getWorld());
|
final PlotWorld pWorld = PlotSquared.getPlotWorld(plot.world);
|
||||||
if (PlotMain.useEconomy && pWorld.USE_ECONOMY) {
|
if (PlotSquared.economy != null && pWorld.USE_ECONOMY) {
|
||||||
final double c = pWorld.SELL_PRICE;
|
final double c = pWorld.SELL_PRICE;
|
||||||
if (c > 0d) {
|
if (c > 0d) {
|
||||||
final Economy economy = PlotMain.economy;
|
final Economy economy = PlotSquared.economy;
|
||||||
economy.depositPlayer(plr, c);
|
EconHandler.depositPlayer(plr, c);
|
||||||
sendMessage(plr, C.ADDED_BALANCE, c + "");
|
sendMessage(plr, C.ADDED_BALANCE, c + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final boolean result = PlotMain.removePlot(plr.getWorld().getName(), plot.id, true);
|
final boolean result = PlotSquared.removePlot(loc.getWorld(), plot.id, true);
|
||||||
if (result) {
|
if (result) {
|
||||||
World world = plr.getWorld();
|
final String worldname = plr.getLocation().getWorld();
|
||||||
String worldname = world.getName();
|
PlotSquared.getPlotManager(worldname).unclaimPlot(pWorld, plot);
|
||||||
PlotMain.getPlotManager(world).unclaimPlot(world, pWorld, plot);
|
|
||||||
DBFunc.delete(worldname, plot);
|
DBFunc.delete(worldname, plot);
|
||||||
// TODO set wall block
|
// TODO set wall block
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, "Plot removal has been denied.");
|
MainUtil.sendMessage(plr, "Plot removal has been denied.");
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, C.UNCLAIM_SUCCESS);
|
MainUtil.sendMessage(plr, C.UNCLAIM_SUCCESS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,26 +18,22 @@
|
|||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.events.PlotUnlinkEvent;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.object.PlotManager;
|
import com.intellectualcrafters.plot.object.PlotManager;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2014-08-01 for PlotSquared
|
* Created 2014-08-01 for PlotSquared
|
||||||
@ -45,68 +41,46 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public class Unlink extends SubCommand {
|
public class Unlink extends SubCommand {
|
||||||
|
|
||||||
public Unlink() {
|
public Unlink() {
|
||||||
super(Command.UNLINK, "Unlink a mega-plot", "unlink", CommandCategory.ACTIONS, true);
|
super(Command.UNLINK, "Unlink a mega-plot", "unlink", CommandCategory.ACTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
if (!PlayerFunctions.isInPlot(plr)) {
|
Location loc = plr.getLocation();
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
|
if (plot == null) {
|
||||||
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) {
|
||||||
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !PlotMain.hasPermission(plr, "plots.admin.command.unlink")) {
|
|
||||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
}
|
}
|
||||||
if (PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
|
if (MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||||
return sendMessage(plr, C.UNLINK_IMPOSSIBLE);
|
return sendMessage(plr, C.UNLINK_IMPOSSIBLE);
|
||||||
}
|
}
|
||||||
|
if (!unlinkPlot(plot)) {
|
||||||
final World world = plr.getWorld();
|
MainUtil.sendMessage(plr, "&cUnlink has been cancelled");
|
||||||
if (!unlinkPlot(world, plot)) {
|
|
||||||
PlayerFunctions.sendMessage(plr, "&cUnlink has been cancelled");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
MainUtil.update(plr.getLocation());
|
||||||
PlotHelper.update(plr.getLocation());
|
MainUtil.sendMessage(plr, "&6Plots unlinked successfully!");
|
||||||
} catch (final Exception e) {
|
|
||||||
// execute(final Player plr, final String... args) {
|
|
||||||
try {
|
|
||||||
PlotMain.sendConsoleSenderMessage("Error on: " + getClass().getMethod("execute", Player.class, String[].class).toGenericString() + ":119, when trying to use \"SetBlockFast#update\"");
|
|
||||||
} catch (final Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PlayerFunctions.sendMessage(plr, "&6Plots unlinked successfully!");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean unlinkPlot(World world, Plot plot) {
|
public static boolean unlinkPlot(final Plot plot) {
|
||||||
final PlotId pos1 = PlayerFunctions.getBottomPlot(world, plot).id;
|
String world = plot.world;
|
||||||
final PlotId pos2 = PlayerFunctions.getTopPlot(world, plot).id;
|
final PlotId pos1 = MainUtil.getBottomPlot(plot).id;
|
||||||
final ArrayList<PlotId> ids = PlayerFunctions.getPlotSelectionIds(pos1, pos2);
|
final PlotId pos2 = MainUtil.getTopPlot(plot).id;
|
||||||
|
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(pos1, pos2);
|
||||||
final PlotUnlinkEvent event = new PlotUnlinkEvent(world, ids);
|
// FIXME PlotUnlinkEvent (cancellable)
|
||||||
|
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
|
||||||
if (event.isCancelled()) {
|
manager.startPlotUnlink(plotworld, ids);
|
||||||
event.setCancelled(true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final PlotManager manager = PlotMain.getPlotManager(world);
|
|
||||||
final PlotWorld plotworld = PlotMain.getWorldSettings(world);
|
|
||||||
|
|
||||||
manager.startPlotUnlink(world, plotworld, ids);
|
|
||||||
|
|
||||||
for (final PlotId id : ids) {
|
for (final PlotId id : ids) {
|
||||||
final Plot myplot = PlotMain.getPlots(world).get(id);
|
final Plot myplot = PlotSquared.getPlots(world).get(id);
|
||||||
|
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plot.helpers != null) {
|
if (plot.helpers != null) {
|
||||||
myplot.helpers = plot.helpers;
|
myplot.helpers = plot.helpers;
|
||||||
}
|
}
|
||||||
@ -114,38 +88,33 @@ public class Unlink extends SubCommand {
|
|||||||
myplot.denied = plot.denied;
|
myplot.denied = plot.denied;
|
||||||
}
|
}
|
||||||
myplot.deny_entry = plot.deny_entry;
|
myplot.deny_entry = plot.deny_entry;
|
||||||
myplot.settings.setMerged(new boolean[]{false, false, false, false});
|
myplot.settings.setMerged(new boolean[] { false, false, false, false });
|
||||||
DBFunc.setMerged(world.getName(), myplot, myplot.settings.getMerged());
|
DBFunc.setMerged(world, myplot, myplot.settings.getMerged());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x = pos1.x; x <= pos2.x; x++) {
|
for (int x = pos1.x; x <= pos2.x; x++) {
|
||||||
for (int y = pos1.y; y <= pos2.y; y++) {
|
for (int y = pos1.y; y <= pos2.y; y++) {
|
||||||
final boolean lx = x < pos2.x;
|
final boolean lx = x < pos2.x;
|
||||||
final boolean ly = y < pos2.y;
|
final boolean ly = y < pos2.y;
|
||||||
|
final Plot p = MainUtil.getPlot(world, new PlotId(x, y));
|
||||||
final Plot p = PlotHelper.getPlot(world, new PlotId(x, y));
|
|
||||||
|
|
||||||
if (lx) {
|
if (lx) {
|
||||||
manager.createRoadEast(plotworld, p);
|
manager.createRoadEast(plotworld, p);
|
||||||
if (ly) {
|
if (ly) {
|
||||||
manager.createRoadSouthEast(plotworld, p);
|
manager.createRoadSouthEast(plotworld, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ly) {
|
if (ly) {
|
||||||
manager.createRoadSouth(plotworld, p);
|
manager.createRoadSouth(plotworld, p);
|
||||||
}
|
}
|
||||||
PlotHelper.setSign(world, UUIDHandler.getName(plot.owner), plot);
|
MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
manager.finishPlotUnlink(world, plotworld, ids);
|
manager.finishPlotUnlink(plotworld, ids);
|
||||||
for (PlotId id : ids) {
|
for (final PlotId id : ids) {
|
||||||
Plot myPlot = PlotHelper.getPlot(world, id);
|
final Plot myPlot = MainUtil.getPlot(world, id);
|
||||||
if (plot.hasOwner()) {
|
if (plot.hasOwner()) {
|
||||||
String name = UUIDHandler.getName(myPlot.owner);
|
final String name = UUIDHandler.getName(myPlot.owner);
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
PlotHelper.setSign(world, name, myPlot);
|
MainUtil.setSign(name, myPlot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user