mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-29 16:46:45 +01:00
Hows this?
This commit is contained in:
parent
1cccdd9d4d
commit
5137b23357
@ -5,8 +5,7 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* Represents a source of configurable options and settings
|
* Represents a source of configurable options and settings
|
||||||
*/
|
*/
|
||||||
public interface Configuration extends ConfigurationSection
|
public interface Configuration extends ConfigurationSection {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Sets the default value of the given path as provided.
|
* Sets the default value of the given path as provided.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -4,14 +4,12 @@ package com.intellectualcrafters.configuration;
|
|||||||
* Various settings for controlling the input and output of a {@link
|
* Various settings for controlling the input and output of a {@link
|
||||||
* Configuration}
|
* Configuration}
|
||||||
*/
|
*/
|
||||||
public class ConfigurationOptions
|
public class ConfigurationOptions {
|
||||||
{
|
|
||||||
private char pathSeparator = '.';
|
private char pathSeparator = '.';
|
||||||
private boolean copyDefaults = false;
|
private boolean copyDefaults = false;
|
||||||
private final Configuration configuration;
|
private final Configuration configuration;
|
||||||
|
|
||||||
protected ConfigurationOptions(final Configuration configuration)
|
protected ConfigurationOptions(final Configuration configuration) {
|
||||||
{
|
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,8 +18,7 @@ public class ConfigurationOptions
|
|||||||
*
|
*
|
||||||
* @return Parent configuration
|
* @return Parent configuration
|
||||||
*/
|
*/
|
||||||
public Configuration configuration()
|
public Configuration configuration() {
|
||||||
{
|
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,8 +31,7 @@ public class ConfigurationOptions
|
|||||||
*
|
*
|
||||||
* @return Path separator
|
* @return Path separator
|
||||||
*/
|
*/
|
||||||
public char pathSeparator()
|
public char pathSeparator() {
|
||||||
{
|
|
||||||
return pathSeparator;
|
return pathSeparator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,8 +45,7 @@ public class ConfigurationOptions
|
|||||||
* @param value Path separator
|
* @param value Path separator
|
||||||
* @return This object, for chaining
|
* @return This object, for chaining
|
||||||
*/
|
*/
|
||||||
public ConfigurationOptions pathSeparator(final char value)
|
public ConfigurationOptions pathSeparator(final char value) {
|
||||||
{
|
|
||||||
pathSeparator = value;
|
pathSeparator = value;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -69,8 +64,7 @@ public class ConfigurationOptions
|
|||||||
*
|
*
|
||||||
* @return Whether or not defaults are directly copied
|
* @return Whether or not defaults are directly copied
|
||||||
*/
|
*/
|
||||||
public boolean copyDefaults()
|
public boolean copyDefaults() {
|
||||||
{
|
|
||||||
return copyDefaults;
|
return copyDefaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,8 +83,7 @@ public class ConfigurationOptions
|
|||||||
* @param value Whether or not defaults are directly copied
|
* @param value Whether or not defaults are directly copied
|
||||||
* @return This object, for chaining
|
* @return This object, for chaining
|
||||||
*/
|
*/
|
||||||
public ConfigurationOptions copyDefaults(final boolean value)
|
public ConfigurationOptions copyDefaults(final boolean value) {
|
||||||
{
|
|
||||||
copyDefaults = value;
|
copyDefaults = value;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,7 @@ import java.util.Set;
|
|||||||
/**
|
/**
|
||||||
* Represents a section of a {@link Configuration}
|
* Represents a section of a {@link Configuration}
|
||||||
*/
|
*/
|
||||||
public interface ConfigurationSection
|
public interface ConfigurationSection {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Gets a set containing all keys in this section.
|
* Gets a set containing all keys in this section.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -4,15 +4,13 @@ package com.intellectualcrafters.configuration;
|
|||||||
* Exception thrown when attempting to load an invalid {@link Configuration}
|
* Exception thrown when attempting to load an invalid {@link Configuration}
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class InvalidConfigurationException extends Exception
|
public class InvalidConfigurationException extends Exception {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of InvalidConfigurationException without a
|
* Creates a new instance of InvalidConfigurationException without a
|
||||||
* message or cause.
|
* message or cause.
|
||||||
*/
|
*/
|
||||||
public InvalidConfigurationException()
|
public InvalidConfigurationException() {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of InvalidConfigurationException with the
|
* Constructs an instance of InvalidConfigurationException with the
|
||||||
@ -20,8 +18,7 @@ public class InvalidConfigurationException extends Exception
|
|||||||
*
|
*
|
||||||
* @param msg The details of the exception.
|
* @param msg The details of the exception.
|
||||||
*/
|
*/
|
||||||
public InvalidConfigurationException(final String msg)
|
public InvalidConfigurationException(final String msg) {
|
||||||
{
|
|
||||||
super(msg);
|
super(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,8 +28,7 @@ public class InvalidConfigurationException extends Exception
|
|||||||
*
|
*
|
||||||
* @param cause The cause of the exception.
|
* @param cause The cause of the exception.
|
||||||
*/
|
*/
|
||||||
public InvalidConfigurationException(final Throwable cause)
|
public InvalidConfigurationException(final Throwable cause) {
|
||||||
{
|
|
||||||
super(cause);
|
super(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,8 +39,7 @@ public class InvalidConfigurationException extends Exception
|
|||||||
* @param cause The cause of the exception.
|
* @param cause The cause of the exception.
|
||||||
* @param msg The details of the exception.
|
* @param msg The details of the exception.
|
||||||
*/
|
*/
|
||||||
public InvalidConfigurationException(final String msg, final Throwable cause)
|
public InvalidConfigurationException(final String msg, final Throwable cause) {
|
||||||
{
|
|
||||||
super(msg, cause);
|
super(msg, cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,16 +7,14 @@ import java.util.Map;
|
|||||||
* from any source, and stores all values in memory only.
|
* from any source, and stores all values in memory only.
|
||||||
* This is useful for temporary Configurations for providing defaults.
|
* This is useful for temporary Configurations for providing defaults.
|
||||||
*/
|
*/
|
||||||
public class MemoryConfiguration extends MemorySection implements Configuration
|
public class MemoryConfiguration extends MemorySection implements Configuration {
|
||||||
{
|
|
||||||
protected Configuration defaults;
|
protected Configuration defaults;
|
||||||
protected MemoryConfigurationOptions options;
|
protected MemoryConfigurationOptions options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty {@link MemoryConfiguration} with no default values.
|
* Creates an empty {@link MemoryConfiguration} with no default values.
|
||||||
*/
|
*/
|
||||||
public MemoryConfiguration()
|
public MemoryConfiguration() {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty {@link MemoryConfiguration} using the specified {@link
|
* Creates an empty {@link MemoryConfiguration} using the specified {@link
|
||||||
@ -25,17 +23,16 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
|||||||
* @param defaults Default value provider
|
* @param defaults Default value provider
|
||||||
* @throws IllegalArgumentException Thrown if defaults is null
|
* @throws IllegalArgumentException Thrown if defaults is null
|
||||||
*/
|
*/
|
||||||
public MemoryConfiguration(final Configuration defaults)
|
public MemoryConfiguration(final Configuration defaults) {
|
||||||
{
|
|
||||||
this.defaults = defaults;
|
this.defaults = defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addDefault(final String path, final Object value)
|
public void addDefault(final String path, final Object value) {
|
||||||
{
|
if (path == null) {
|
||||||
if (path == null) { throw new NullPointerException("Path may not be null"); }
|
throw new NullPointerException("Path may not be null");
|
||||||
if (defaults == null)
|
}
|
||||||
{
|
if (defaults == null) {
|
||||||
defaults = new MemoryConfiguration();
|
defaults = new MemoryConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,49 +40,47 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addDefaults(final Map<String, Object> defaults)
|
public void addDefaults(final Map<String, Object> defaults) {
|
||||||
{
|
if (defaults == null) {
|
||||||
if (defaults == null) { throw new NullPointerException("Defaults may not be null"); }
|
throw new NullPointerException("Defaults may not be null");
|
||||||
|
}
|
||||||
|
|
||||||
for (final Map.Entry<String, Object> entry : defaults.entrySet())
|
for (final Map.Entry<String, Object> entry : defaults.entrySet()) {
|
||||||
{
|
|
||||||
addDefault(entry.getKey(), entry.getValue());
|
addDefault(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addDefaults(final Configuration defaults)
|
public void addDefaults(final Configuration defaults) {
|
||||||
{
|
if (defaults == null) {
|
||||||
if (defaults == null) { throw new NullPointerException("Defaults may not be null"); }
|
throw new NullPointerException("Defaults may not be null");
|
||||||
|
}
|
||||||
|
|
||||||
addDefaults(defaults.getValues(true));
|
addDefaults(defaults.getValues(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDefaults(final Configuration defaults)
|
public void setDefaults(final Configuration defaults) {
|
||||||
{
|
if (defaults == null) {
|
||||||
if (defaults == null) { throw new NullPointerException("Defaults may not be null"); }
|
throw new NullPointerException("Defaults may not be null");
|
||||||
|
}
|
||||||
|
|
||||||
this.defaults = defaults;
|
this.defaults = defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Configuration getDefaults()
|
public Configuration getDefaults() {
|
||||||
{
|
|
||||||
return defaults;
|
return defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigurationSection getParent()
|
public ConfigurationSection getParent() {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MemoryConfigurationOptions options()
|
public MemoryConfigurationOptions options() {
|
||||||
{
|
if (options == null) {
|
||||||
if (options == null)
|
|
||||||
{
|
|
||||||
options = new MemoryConfigurationOptions(this);
|
options = new MemoryConfigurationOptions(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,29 +4,24 @@ package com.intellectualcrafters.configuration;
|
|||||||
* Various settings for controlling the input and output of a {@link
|
* Various settings for controlling the input and output of a {@link
|
||||||
* MemoryConfiguration}
|
* MemoryConfiguration}
|
||||||
*/
|
*/
|
||||||
public class MemoryConfigurationOptions extends ConfigurationOptions
|
public class MemoryConfigurationOptions extends ConfigurationOptions {
|
||||||
{
|
protected MemoryConfigurationOptions(final MemoryConfiguration configuration) {
|
||||||
protected MemoryConfigurationOptions(final MemoryConfiguration configuration)
|
|
||||||
{
|
|
||||||
super(configuration);
|
super(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MemoryConfiguration configuration()
|
public MemoryConfiguration configuration() {
|
||||||
{
|
|
||||||
return (MemoryConfiguration) super.configuration();
|
return (MemoryConfiguration) super.configuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MemoryConfigurationOptions copyDefaults(final boolean value)
|
public MemoryConfigurationOptions copyDefaults(final boolean value) {
|
||||||
{
|
|
||||||
super.copyDefaults(value);
|
super.copyDefaults(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MemoryConfigurationOptions pathSeparator(final char value)
|
public MemoryConfigurationOptions pathSeparator(final char value) {
|
||||||
{
|
|
||||||
super.pathSeparator(value);
|
super.pathSeparator(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -24,8 +24,7 @@ import com.intellectualcrafters.configuration.MemoryConfiguration;
|
|||||||
* This is a base class for all File based implementations of {@link
|
* This is a base class for all File based implementations of {@link
|
||||||
* Configuration}
|
* Configuration}
|
||||||
*/
|
*/
|
||||||
public abstract class FileConfiguration extends MemoryConfiguration
|
public abstract class FileConfiguration extends MemoryConfiguration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* This value specified that the system default encoding should be
|
* This value specified that the system default encoding should be
|
||||||
* completely ignored, as it cannot handle the ASCII character set, or it
|
* completely ignored, as it cannot handle the ASCII character set, or it
|
||||||
@ -50,8 +49,7 @@ public abstract class FileConfiguration extends MemoryConfiguration
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static final boolean SYSTEM_UTF;
|
public static final boolean SYSTEM_UTF;
|
||||||
static
|
static {
|
||||||
{
|
|
||||||
final byte[] testBytes = Base64Coder.decode("ICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX4NCg==");
|
final byte[] testBytes = Base64Coder.decode("ICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX4NCg==");
|
||||||
final String testString = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\r\n";
|
final String testString = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\r\n";
|
||||||
final Charset defaultCharset = Charset.defaultCharset();
|
final Charset defaultCharset = Charset.defaultCharset();
|
||||||
@ -65,8 +63,7 @@ public abstract class FileConfiguration extends MemoryConfiguration
|
|||||||
/**
|
/**
|
||||||
* Creates an empty {@link FileConfiguration} with no default values.
|
* Creates an empty {@link FileConfiguration} with no default values.
|
||||||
*/
|
*/
|
||||||
public FileConfiguration()
|
public FileConfiguration() {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,8 +73,7 @@ public abstract class FileConfiguration extends MemoryConfiguration
|
|||||||
*
|
*
|
||||||
* @param defaults Default value provider
|
* @param defaults Default value provider
|
||||||
*/
|
*/
|
||||||
public FileConfiguration(final Configuration defaults)
|
public FileConfiguration(final Configuration defaults) {
|
||||||
{
|
|
||||||
super(defaults);
|
super(defaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,21 +92,19 @@ public abstract class FileConfiguration extends MemoryConfiguration
|
|||||||
* any reason.
|
* any reason.
|
||||||
* @throws IllegalArgumentException Thrown when file is null.
|
* @throws IllegalArgumentException Thrown when file is null.
|
||||||
*/
|
*/
|
||||||
public void save(final File file) throws IOException
|
public void save(final File file) throws IOException {
|
||||||
{
|
if (file == null) {
|
||||||
if (file == null) { throw new NullPointerException("File cannot be null"); }
|
throw new NullPointerException("File cannot be null");
|
||||||
|
}
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
|
|
||||||
final String data = saveToString();
|
final String data = saveToString();
|
||||||
|
|
||||||
final Writer writer = new OutputStreamWriter(new FileOutputStream(file), UTF8_OVERRIDE && !UTF_BIG ? StandardCharsets.UTF_8 : Charset.defaultCharset());
|
final Writer writer = new OutputStreamWriter(new FileOutputStream(file), UTF8_OVERRIDE && !UTF_BIG ? StandardCharsets.UTF_8 : Charset.defaultCharset());
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
writer.write(data);
|
writer.write(data);
|
||||||
}
|
} finally {
|
||||||
finally
|
|
||||||
{
|
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,9 +124,10 @@ public abstract class FileConfiguration extends MemoryConfiguration
|
|||||||
* any reason.
|
* any reason.
|
||||||
* @throws IllegalArgumentException Thrown when file is null.
|
* @throws IllegalArgumentException Thrown when file is null.
|
||||||
*/
|
*/
|
||||||
public void save(final String file) throws IOException
|
public void save(final String file) throws IOException {
|
||||||
{
|
if (file == null) {
|
||||||
if (file == null) { throw new NullPointerException("File cannot be null"); }
|
throw new NullPointerException("File cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
save(new File(file));
|
save(new File(file));
|
||||||
}
|
}
|
||||||
@ -166,9 +161,10 @@ public abstract class FileConfiguration extends MemoryConfiguration
|
|||||||
* a valid Configuration.
|
* a valid Configuration.
|
||||||
* @throws IllegalArgumentException Thrown when file is null.
|
* @throws IllegalArgumentException Thrown when file is null.
|
||||||
*/
|
*/
|
||||||
public void load(final File file) throws IOException, InvalidConfigurationException
|
public void load(final File file) throws IOException, InvalidConfigurationException {
|
||||||
{
|
if (file == null) {
|
||||||
if (file == null) { throw new NullPointerException("File cannot be null"); }
|
throw new NullPointerException("File cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
final FileInputStream stream = new FileInputStream(file);
|
final FileInputStream stream = new FileInputStream(file);
|
||||||
|
|
||||||
@ -194,9 +190,10 @@ public abstract class FileConfiguration extends MemoryConfiguration
|
|||||||
* @see #load(Reader)
|
* @see #load(Reader)
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void load(final InputStream stream) throws IOException, InvalidConfigurationException
|
public void load(final InputStream stream) throws IOException, InvalidConfigurationException {
|
||||||
{
|
if (stream == null) {
|
||||||
if (stream == null) { throw new NullPointerException("Stream cannot be null"); }
|
throw new NullPointerException("Stream cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
load(new InputStreamReader(stream, UTF8_OVERRIDE ? StandardCharsets.UTF_8 : Charset.defaultCharset()));
|
load(new InputStreamReader(stream, UTF8_OVERRIDE ? StandardCharsets.UTF_8 : Charset.defaultCharset()));
|
||||||
}
|
}
|
||||||
@ -214,24 +211,19 @@ public abstract class FileConfiguration extends MemoryConfiguration
|
|||||||
* represent a valid Configuration
|
* represent a valid Configuration
|
||||||
* @throws IllegalArgumentException thrown when reader is null
|
* @throws IllegalArgumentException thrown when reader is null
|
||||||
*/
|
*/
|
||||||
public void load(final Reader reader) throws IOException, InvalidConfigurationException
|
public void load(final Reader reader) throws IOException, InvalidConfigurationException {
|
||||||
{
|
|
||||||
final BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
|
final BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
|
||||||
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
String line;
|
String line;
|
||||||
|
|
||||||
while ((line = input.readLine()) != null)
|
while ((line = input.readLine()) != null) {
|
||||||
{
|
|
||||||
builder.append(line);
|
builder.append(line);
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally
|
|
||||||
{
|
|
||||||
input.close();
|
input.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,9 +248,10 @@ public abstract class FileConfiguration extends MemoryConfiguration
|
|||||||
* a valid Configuration.
|
* a valid Configuration.
|
||||||
* @throws IllegalArgumentException Thrown when file is null.
|
* @throws IllegalArgumentException Thrown when file is null.
|
||||||
*/
|
*/
|
||||||
public void load(final String file) throws IOException, InvalidConfigurationException
|
public void load(final String file) throws IOException, InvalidConfigurationException {
|
||||||
{
|
if (file == null) {
|
||||||
if (file == null) { throw new NullPointerException("File cannot be null"); }
|
throw new NullPointerException("File cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
load(new File(file));
|
load(new File(file));
|
||||||
}
|
}
|
||||||
@ -293,10 +286,8 @@ public abstract class FileConfiguration extends MemoryConfiguration
|
|||||||
protected abstract String buildHeader();
|
protected abstract String buildHeader();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileConfigurationOptions options()
|
public FileConfigurationOptions options() {
|
||||||
{
|
if (options == null) {
|
||||||
if (options == null)
|
|
||||||
{
|
|
||||||
options = new FileConfigurationOptions(this);
|
options = new FileConfigurationOptions(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,32 +7,27 @@ import com.intellectualcrafters.configuration.MemoryConfigurationOptions;
|
|||||||
* Various settings for controlling the input and output of a {@link
|
* Various settings for controlling the input and output of a {@link
|
||||||
* FileConfiguration}
|
* FileConfiguration}
|
||||||
*/
|
*/
|
||||||
public class FileConfigurationOptions extends MemoryConfigurationOptions
|
public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||||
{
|
|
||||||
private String header = null;
|
private String header = null;
|
||||||
private boolean copyHeader = true;
|
private boolean copyHeader = true;
|
||||||
|
|
||||||
protected FileConfigurationOptions(final MemoryConfiguration configuration)
|
protected FileConfigurationOptions(final MemoryConfiguration configuration) {
|
||||||
{
|
|
||||||
super(configuration);
|
super(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileConfiguration configuration()
|
public FileConfiguration configuration() {
|
||||||
{
|
|
||||||
return (FileConfiguration) super.configuration();
|
return (FileConfiguration) super.configuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileConfigurationOptions copyDefaults(final boolean value)
|
public FileConfigurationOptions copyDefaults(final boolean value) {
|
||||||
{
|
|
||||||
super.copyDefaults(value);
|
super.copyDefaults(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileConfigurationOptions pathSeparator(final char value)
|
public FileConfigurationOptions pathSeparator(final char value) {
|
||||||
{
|
|
||||||
super.pathSeparator(value);
|
super.pathSeparator(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -51,8 +46,7 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions
|
|||||||
*
|
*
|
||||||
* @return Header
|
* @return Header
|
||||||
*/
|
*/
|
||||||
public String header()
|
public String header() {
|
||||||
{
|
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,8 +65,7 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions
|
|||||||
* @param value New header
|
* @param value New header
|
||||||
* @return This object, for chaining
|
* @return This object, for chaining
|
||||||
*/
|
*/
|
||||||
public FileConfigurationOptions header(final String value)
|
public FileConfigurationOptions header(final String value) {
|
||||||
{
|
|
||||||
header = value;
|
header = value;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -95,8 +88,7 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions
|
|||||||
*
|
*
|
||||||
* @return Whether or not to copy the header
|
* @return Whether or not to copy the header
|
||||||
*/
|
*/
|
||||||
public boolean copyHeader()
|
public boolean copyHeader() {
|
||||||
{
|
|
||||||
return copyHeader;
|
return copyHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,8 +111,7 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions
|
|||||||
* @param value Whether or not to copy the header
|
* @param value Whether or not to copy the header
|
||||||
* @return This object, for chaining
|
* @return This object, for chaining
|
||||||
*/
|
*/
|
||||||
public FileConfigurationOptions copyHeader(final boolean value)
|
public FileConfigurationOptions copyHeader(final boolean value) {
|
||||||
{
|
|
||||||
copyHeader = value;
|
copyHeader = value;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -22,8 +22,7 @@ import com.intellectualcrafters.plot.PS;
|
|||||||
* An implementation of {@link Configuration} which saves all files in Yaml.
|
* An implementation of {@link Configuration} which saves all files in Yaml.
|
||||||
* Note that this implementation is not synchronized.
|
* Note that this implementation is not synchronized.
|
||||||
*/
|
*/
|
||||||
public class YamlConfiguration extends FileConfiguration
|
public class YamlConfiguration extends FileConfiguration {
|
||||||
{
|
|
||||||
protected static final String COMMENT_PREFIX = "# ";
|
protected static final String COMMENT_PREFIX = "# ";
|
||||||
protected static final String BLANK_CONFIG = "{}\n";
|
protected static final String BLANK_CONFIG = "{}\n";
|
||||||
private final DumperOptions yamlOptions = new DumperOptions();
|
private final DumperOptions yamlOptions = new DumperOptions();
|
||||||
@ -31,8 +30,7 @@ public class YamlConfiguration extends FileConfiguration
|
|||||||
private final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
|
private final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String saveToString()
|
public String saveToString() {
|
||||||
{
|
|
||||||
yamlOptions.setIndent(options().indent());
|
yamlOptions.setIndent(options().indent());
|
||||||
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
yamlOptions.setAllowUnicode(SYSTEM_UTF);
|
yamlOptions.setAllowUnicode(SYSTEM_UTF);
|
||||||
@ -41,8 +39,7 @@ public class YamlConfiguration extends FileConfiguration
|
|||||||
final String header = buildHeader();
|
final String header = buildHeader();
|
||||||
String dump = yaml.dump(getValues(false));
|
String dump = yaml.dump(getValues(false));
|
||||||
|
|
||||||
if (dump.equals(BLANK_CONFIG))
|
if (dump.equals(BLANK_CONFIG)) {
|
||||||
{
|
|
||||||
dump = "";
|
dump = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,85 +47,65 @@ public class YamlConfiguration extends FileConfiguration
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadFromString(final String contents) throws InvalidConfigurationException
|
public void loadFromString(final String contents) throws InvalidConfigurationException {
|
||||||
{
|
if (contents == null) {
|
||||||
if (contents == null) { throw new NullPointerException("Contents cannot be null"); }
|
throw new NullPointerException("Contents cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
Map<?, ?> input;
|
Map<?, ?> input;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
input = (Map<?, ?>) yaml.load(contents);
|
input = (Map<?, ?>) yaml.load(contents);
|
||||||
}
|
} catch (final YAMLException e) {
|
||||||
catch (final YAMLException e)
|
|
||||||
{
|
|
||||||
throw new InvalidConfigurationException(e);
|
throw new InvalidConfigurationException(e);
|
||||||
}
|
} catch (final ClassCastException e) {
|
||||||
catch (final ClassCastException e)
|
|
||||||
{
|
|
||||||
throw new InvalidConfigurationException("Top level is not a Map.");
|
throw new InvalidConfigurationException("Top level is not a Map.");
|
||||||
}
|
}
|
||||||
|
|
||||||
final String header = parseHeader(contents);
|
final String header = parseHeader(contents);
|
||||||
if (header.length() > 0)
|
if (header.length() > 0) {
|
||||||
{
|
|
||||||
options().header(header);
|
options().header(header);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input != null)
|
if (input != null) {
|
||||||
{
|
|
||||||
convertMapsToSections(input, this);
|
convertMapsToSections(input, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void convertMapsToSections(final Map<?, ?> input, final ConfigurationSection section)
|
protected void convertMapsToSections(final Map<?, ?> input, final ConfigurationSection section) {
|
||||||
{
|
for (final Map.Entry<?, ?> entry : input.entrySet()) {
|
||||||
for (final Map.Entry<?, ?> entry : input.entrySet())
|
|
||||||
{
|
|
||||||
final String key = entry.getKey().toString();
|
final String key = entry.getKey().toString();
|
||||||
final Object value = entry.getValue();
|
final Object value = entry.getValue();
|
||||||
|
|
||||||
if (value instanceof Map)
|
if (value instanceof Map) {
|
||||||
{
|
|
||||||
convertMapsToSections((Map<?, ?>) value, section.createSection(key));
|
convertMapsToSections((Map<?, ?>) value, section.createSection(key));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
section.set(key, value);
|
section.set(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String parseHeader(final String input)
|
protected String parseHeader(final String input) {
|
||||||
{
|
|
||||||
final String[] lines = input.split("\r?\n", -1);
|
final String[] lines = input.split("\r?\n", -1);
|
||||||
final StringBuilder result = new StringBuilder();
|
final StringBuilder result = new StringBuilder();
|
||||||
boolean readingHeader = true;
|
boolean readingHeader = true;
|
||||||
boolean foundHeader = false;
|
boolean foundHeader = false;
|
||||||
|
|
||||||
for (int i = 0; (i < lines.length) && (readingHeader); i++)
|
for (int i = 0; (i < lines.length) && (readingHeader); i++) {
|
||||||
{
|
|
||||||
final String line = lines[i];
|
final String line = lines[i];
|
||||||
|
|
||||||
if (line.startsWith(COMMENT_PREFIX))
|
if (line.startsWith(COMMENT_PREFIX)) {
|
||||||
{
|
if (i > 0) {
|
||||||
if (i > 0)
|
|
||||||
{
|
|
||||||
result.append("\n");
|
result.append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.length() > COMMENT_PREFIX.length())
|
if (line.length() > COMMENT_PREFIX.length()) {
|
||||||
{
|
|
||||||
result.append(line.substring(COMMENT_PREFIX.length()));
|
result.append(line.substring(COMMENT_PREFIX.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
foundHeader = true;
|
foundHeader = true;
|
||||||
}
|
} else if ((foundHeader) && (line.length() == 0)) {
|
||||||
else if ((foundHeader) && (line.length() == 0))
|
|
||||||
{
|
|
||||||
result.append("\n");
|
result.append("\n");
|
||||||
}
|
} else if (foundHeader) {
|
||||||
else if (foundHeader)
|
|
||||||
{
|
|
||||||
readingHeader = false;
|
readingHeader = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,35 +114,34 @@ public class YamlConfiguration extends FileConfiguration
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String buildHeader()
|
protected String buildHeader() {
|
||||||
{
|
|
||||||
final String header = options().header();
|
final String header = options().header();
|
||||||
|
|
||||||
if (options().copyHeader())
|
if (options().copyHeader()) {
|
||||||
{
|
|
||||||
final Configuration def = getDefaults();
|
final Configuration def = getDefaults();
|
||||||
|
|
||||||
if ((def != null) && (def instanceof FileConfiguration))
|
if ((def != null) && (def instanceof FileConfiguration)) {
|
||||||
{
|
|
||||||
final FileConfiguration filedefaults = (FileConfiguration) def;
|
final FileConfiguration filedefaults = (FileConfiguration) def;
|
||||||
final String defaultsHeader = filedefaults.buildHeader();
|
final String defaultsHeader = filedefaults.buildHeader();
|
||||||
|
|
||||||
if ((defaultsHeader != null) && (defaultsHeader.length() > 0)) { return defaultsHeader; }
|
if ((defaultsHeader != null) && (defaultsHeader.length() > 0)) {
|
||||||
|
return defaultsHeader;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header == null) { return ""; }
|
if (header == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
final String[] lines = header.split("\r?\n", -1);
|
final String[] lines = header.split("\r?\n", -1);
|
||||||
boolean startedHeader = false;
|
boolean startedHeader = false;
|
||||||
|
|
||||||
for (int i = lines.length - 1; i >= 0; i--)
|
for (int i = lines.length - 1; i >= 0; i--) {
|
||||||
{
|
|
||||||
builder.insert(0, "\n");
|
builder.insert(0, "\n");
|
||||||
|
|
||||||
if ((startedHeader) || (lines[i].length() != 0))
|
if ((startedHeader) || (lines[i].length() != 0)) {
|
||||||
{
|
|
||||||
builder.insert(0, lines[i]);
|
builder.insert(0, lines[i]);
|
||||||
builder.insert(0, COMMENT_PREFIX);
|
builder.insert(0, COMMENT_PREFIX);
|
||||||
startedHeader = true;
|
startedHeader = true;
|
||||||
@ -176,10 +152,8 @@ public class YamlConfiguration extends FileConfiguration
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YamlConfigurationOptions options()
|
public YamlConfigurationOptions options() {
|
||||||
{
|
if (options == null) {
|
||||||
if (options == null)
|
|
||||||
{
|
|
||||||
options = new YamlConfigurationOptions(this);
|
options = new YamlConfigurationOptions(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,25 +173,21 @@ public class YamlConfiguration extends FileConfiguration
|
|||||||
* @return Resulting configuration
|
* @return Resulting configuration
|
||||||
* @throws IllegalArgumentException Thrown if file is null
|
* @throws IllegalArgumentException Thrown if file is null
|
||||||
*/
|
*/
|
||||||
public static YamlConfiguration loadConfiguration(final File file)
|
public static YamlConfiguration loadConfiguration(final File file) {
|
||||||
{
|
if (file == null) {
|
||||||
if (file == null) { throw new NullPointerException("File cannot be null"); }
|
throw new NullPointerException("File cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
final YamlConfiguration config = new YamlConfiguration();
|
final YamlConfiguration config = new YamlConfiguration();
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
config.load(file);
|
config.load(file);
|
||||||
}
|
} catch (final Exception ex) {
|
||||||
catch (final Exception ex)
|
try {
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
file.getAbsolutePath();
|
file.getAbsolutePath();
|
||||||
File dest = new File(file.getAbsolutePath() + "_broken");
|
File dest = new File(file.getAbsolutePath() + "_broken");
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (dest.exists())
|
while (dest.exists()) {
|
||||||
{
|
|
||||||
dest = new File(file.getAbsolutePath() + "_broken_" + i++);
|
dest = new File(file.getAbsolutePath() + "_broken_" + i++);
|
||||||
}
|
}
|
||||||
Files.copy(file.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(file.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
@ -226,9 +196,7 @@ public class YamlConfiguration extends FileConfiguration
|
|||||||
PS.debug("&c============ Full stacktrace ============");
|
PS.debug("&c============ Full stacktrace ============");
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
PS.debug("&c=========================================");
|
PS.debug("&c=========================================");
|
||||||
}
|
} catch (final IOException e) {
|
||||||
catch (final IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,23 +219,19 @@ public class YamlConfiguration extends FileConfiguration
|
|||||||
* @see #loadConfiguration(Reader)
|
* @see #loadConfiguration(Reader)
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static YamlConfiguration loadConfiguration(final InputStream stream)
|
public static YamlConfiguration loadConfiguration(final InputStream stream) {
|
||||||
{
|
if (stream == null) {
|
||||||
if (stream == null) { throw new NullPointerException("Stream cannot be null"); }
|
throw new NullPointerException("Stream cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
final YamlConfiguration config = new YamlConfiguration();
|
final YamlConfiguration config = new YamlConfiguration();
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
config.load(stream);
|
config.load(stream);
|
||||||
}
|
} catch (final IOException ex) {
|
||||||
catch (final IOException ex)
|
|
||||||
{
|
|
||||||
PS.debug("Cannot load configuration from stream");
|
PS.debug("Cannot load configuration from stream");
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
} catch (final InvalidConfigurationException ex) {
|
||||||
catch (final InvalidConfigurationException ex)
|
|
||||||
{
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
PS.debug("Cannot load configuration from stream");
|
PS.debug("Cannot load configuration from stream");
|
||||||
}
|
}
|
||||||
@ -286,23 +250,19 @@ public class YamlConfiguration extends FileConfiguration
|
|||||||
* @return resulting configuration
|
* @return resulting configuration
|
||||||
* @throws IllegalArgumentException Thrown if stream is null
|
* @throws IllegalArgumentException Thrown if stream is null
|
||||||
*/
|
*/
|
||||||
public static YamlConfiguration loadConfiguration(final Reader reader)
|
public static YamlConfiguration loadConfiguration(final Reader reader) {
|
||||||
{
|
if (reader == null) {
|
||||||
if (reader == null) { throw new NullPointerException("Reader cannot be null"); }
|
throw new NullPointerException("Reader cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
final YamlConfiguration config = new YamlConfiguration();
|
final YamlConfiguration config = new YamlConfiguration();
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
config.load(reader);
|
config.load(reader);
|
||||||
}
|
} catch (final IOException ex) {
|
||||||
catch (final IOException ex)
|
|
||||||
{
|
|
||||||
PS.debug("Cannot load configuration from stream");
|
PS.debug("Cannot load configuration from stream");
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
} catch (final InvalidConfigurationException ex) {
|
||||||
catch (final InvalidConfigurationException ex)
|
|
||||||
{
|
|
||||||
PS.debug("Cannot load configuration from stream");
|
PS.debug("Cannot load configuration from stream");
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -4,45 +4,38 @@ package com.intellectualcrafters.configuration.file;
|
|||||||
* Various settings for controlling the input and output of a {@link
|
* Various settings for controlling the input and output of a {@link
|
||||||
* YamlConfiguration}
|
* YamlConfiguration}
|
||||||
*/
|
*/
|
||||||
public class YamlConfigurationOptions extends FileConfigurationOptions
|
public class YamlConfigurationOptions extends FileConfigurationOptions {
|
||||||
{
|
|
||||||
private int indent = 2;
|
private int indent = 2;
|
||||||
|
|
||||||
protected YamlConfigurationOptions(final YamlConfiguration configuration)
|
protected YamlConfigurationOptions(final YamlConfiguration configuration) {
|
||||||
{
|
|
||||||
super(configuration);
|
super(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YamlConfiguration configuration()
|
public YamlConfiguration configuration() {
|
||||||
{
|
|
||||||
return (YamlConfiguration) super.configuration();
|
return (YamlConfiguration) super.configuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YamlConfigurationOptions copyDefaults(final boolean value)
|
public YamlConfigurationOptions copyDefaults(final boolean value) {
|
||||||
{
|
|
||||||
super.copyDefaults(value);
|
super.copyDefaults(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YamlConfigurationOptions pathSeparator(final char value)
|
public YamlConfigurationOptions pathSeparator(final char value) {
|
||||||
{
|
|
||||||
super.pathSeparator(value);
|
super.pathSeparator(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YamlConfigurationOptions header(final String value)
|
public YamlConfigurationOptions header(final String value) {
|
||||||
{
|
|
||||||
super.header(value);
|
super.header(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YamlConfigurationOptions copyHeader(final boolean value)
|
public YamlConfigurationOptions copyHeader(final boolean value) {
|
||||||
{
|
|
||||||
super.copyHeader(value);
|
super.copyHeader(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -54,8 +47,7 @@ public class YamlConfigurationOptions extends FileConfigurationOptions
|
|||||||
*
|
*
|
||||||
* @return How much to indent by
|
* @return How much to indent by
|
||||||
*/
|
*/
|
||||||
public int indent()
|
public int indent() {
|
||||||
{
|
|
||||||
return indent;
|
return indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,10 +59,13 @@ public class YamlConfigurationOptions extends FileConfigurationOptions
|
|||||||
* @param value New indent
|
* @param value New indent
|
||||||
* @return This object, for chaining
|
* @return This object, for chaining
|
||||||
*/
|
*/
|
||||||
public YamlConfigurationOptions indent(final int value)
|
public YamlConfigurationOptions indent(final int value) {
|
||||||
{
|
if (value < 2) {
|
||||||
if (value < 2) { throw new IllegalArgumentException("Indent must be at least 2 characters"); }
|
throw new IllegalArgumentException("Indent must be at least 2 characters");
|
||||||
if (value > 9) { throw new IllegalArgumentException("Indent cannot be greater than 9 characters"); }
|
}
|
||||||
|
if (value > 9) {
|
||||||
|
throw new IllegalArgumentException("Indent cannot be greater than 9 characters");
|
||||||
|
}
|
||||||
|
|
||||||
indent = value;
|
indent = value;
|
||||||
return this;
|
return this;
|
||||||
|
@ -10,37 +10,30 @@ import org.yaml.snakeyaml.nodes.Tag;
|
|||||||
|
|
||||||
import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization;
|
import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization;
|
||||||
|
|
||||||
public class YamlConstructor extends SafeConstructor
|
public class YamlConstructor extends SafeConstructor {
|
||||||
{
|
|
||||||
|
|
||||||
public YamlConstructor()
|
public YamlConstructor() {
|
||||||
{
|
|
||||||
yamlConstructors.put(Tag.MAP, new ConstructCustomObject());
|
yamlConstructors.put(Tag.MAP, new ConstructCustomObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ConstructCustomObject extends ConstructYamlMap
|
private class ConstructCustomObject extends ConstructYamlMap {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public Object construct(final Node node)
|
public Object construct(final Node node) {
|
||||||
{
|
if (node.isTwoStepsConstruction()) {
|
||||||
if (node.isTwoStepsConstruction()) { throw new YAMLException("Unexpected referential mapping structure. Node: " + node); }
|
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
|
||||||
|
}
|
||||||
|
|
||||||
final Map<?, ?> raw = (Map<?, ?>) super.construct(node);
|
final Map<?, ?> raw = (Map<?, ?>) super.construct(node);
|
||||||
|
|
||||||
if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY))
|
if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
|
||||||
{
|
|
||||||
final Map<String, Object> typed = new LinkedHashMap<String, Object>(raw.size());
|
final Map<String, Object> typed = new LinkedHashMap<String, Object>(raw.size());
|
||||||
for (final Map.Entry<?, ?> entry : raw.entrySet())
|
for (final Map.Entry<?, ?> entry : raw.entrySet()) {
|
||||||
{
|
|
||||||
typed.put(entry.getKey().toString(), entry.getValue());
|
typed.put(entry.getKey().toString(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
return ConfigurationSerialization.deserializeObject(typed);
|
return ConfigurationSerialization.deserializeObject(typed);
|
||||||
}
|
} catch (final IllegalArgumentException ex) {
|
||||||
catch (final IllegalArgumentException ex)
|
|
||||||
{
|
|
||||||
throw new YAMLException("Could not deserialize object", ex);
|
throw new YAMLException("Could not deserialize object", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,8 +42,7 @@ public class YamlConstructor extends SafeConstructor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void construct2ndStep(final Node node, final Object object)
|
public void construct2ndStep(final Node node, final Object object) {
|
||||||
{
|
|
||||||
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
|
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,29 +10,23 @@ import com.intellectualcrafters.configuration.ConfigurationSection;
|
|||||||
import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable;
|
import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable;
|
||||||
import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization;
|
import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization;
|
||||||
|
|
||||||
public class YamlRepresenter extends Representer
|
public class YamlRepresenter extends Representer {
|
||||||
{
|
|
||||||
|
|
||||||
public YamlRepresenter()
|
public YamlRepresenter() {
|
||||||
{
|
|
||||||
multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection());
|
multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection());
|
||||||
multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());
|
multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RepresentConfigurationSection extends RepresentMap
|
private class RepresentConfigurationSection extends RepresentMap {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public Node representData(final Object data)
|
public Node representData(final Object data) {
|
||||||
{
|
|
||||||
return super.representData(((ConfigurationSection) data).getValues(false));
|
return super.representData(((ConfigurationSection) data).getValues(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RepresentConfigurationSerializable extends RepresentMap
|
private class RepresentConfigurationSerializable extends RepresentMap {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public Node representData(final Object data)
|
public Node representData(final Object data) {
|
||||||
{
|
|
||||||
final ConfigurationSerializable serializable = (ConfigurationSerializable) data;
|
final ConfigurationSerializable serializable = (ConfigurationSerializable) data;
|
||||||
final Map<String, Object> values = new LinkedHashMap<String, Object>();
|
final Map<String, Object> values = new LinkedHashMap<String, Object>();
|
||||||
values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass()));
|
values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass()));
|
||||||
|
@ -21,8 +21,7 @@ import java.util.Map;
|
|||||||
* @see DelegateDeserialization
|
* @see DelegateDeserialization
|
||||||
* @see SerializableAs
|
* @see SerializableAs
|
||||||
*/
|
*/
|
||||||
public interface ConfigurationSerializable
|
public interface ConfigurationSerializable {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Map representation of this class.
|
* Creates a Map representation of this class.
|
||||||
|
@ -14,130 +14,100 @@ import com.intellectualcrafters.configuration.Configuration;
|
|||||||
/**
|
/**
|
||||||
* Utility class for storing and retrieving classes for {@link Configuration}.
|
* Utility class for storing and retrieving classes for {@link Configuration}.
|
||||||
*/
|
*/
|
||||||
public class ConfigurationSerialization
|
public class ConfigurationSerialization {
|
||||||
{
|
|
||||||
public static final String SERIALIZED_TYPE_KEY = "==";
|
public static final String SERIALIZED_TYPE_KEY = "==";
|
||||||
private final Class<? extends ConfigurationSerializable> clazz;
|
private final Class<? extends ConfigurationSerializable> clazz;
|
||||||
private static Map<String, Class<? extends ConfigurationSerializable>> aliases = new HashMap<String, Class<? extends ConfigurationSerializable>>();
|
private static Map<String, Class<? extends ConfigurationSerializable>> aliases = new HashMap<String, Class<? extends ConfigurationSerializable>>();
|
||||||
|
|
||||||
protected ConfigurationSerialization(final Class<? extends ConfigurationSerializable> clazz)
|
protected ConfigurationSerialization(final Class<? extends ConfigurationSerializable> clazz) {
|
||||||
{
|
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Method getMethod(final String name, final boolean isStatic)
|
protected Method getMethod(final String name, final boolean isStatic) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final Method method = clazz.getDeclaredMethod(name, Map.class);
|
final Method method = clazz.getDeclaredMethod(name, Map.class);
|
||||||
|
|
||||||
if (!ConfigurationSerializable.class.isAssignableFrom(method.getReturnType())) { return null; }
|
if (!ConfigurationSerializable.class.isAssignableFrom(method.getReturnType())) {
|
||||||
if (Modifier.isStatic(method.getModifiers()) != isStatic) { return null; }
|
return null;
|
||||||
|
}
|
||||||
|
if (Modifier.isStatic(method.getModifiers()) != isStatic) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return method;
|
return method;
|
||||||
}
|
} catch (final NoSuchMethodException ex) {
|
||||||
catch (final NoSuchMethodException ex)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
} catch (final SecurityException ex) {
|
||||||
catch (final SecurityException ex)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Constructor<? extends ConfigurationSerializable> getConstructor()
|
protected Constructor<? extends ConfigurationSerializable> getConstructor() {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
return clazz.getConstructor(Map.class);
|
return clazz.getConstructor(Map.class);
|
||||||
}
|
} catch (final NoSuchMethodException ex) {
|
||||||
catch (final NoSuchMethodException ex)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
} catch (final SecurityException ex) {
|
||||||
catch (final SecurityException ex)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ConfigurationSerializable deserializeViaMethod(final Method method, final Map<String, ?> args)
|
protected ConfigurationSerializable deserializeViaMethod(final Method method, final Map<String, ?> args) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final ConfigurationSerializable result = (ConfigurationSerializable) method.invoke(null, args);
|
final ConfigurationSerializable result = (ConfigurationSerializable) method.invoke(null, args);
|
||||||
|
|
||||||
if (result == null)
|
if (result == null) {
|
||||||
{
|
|
||||||
Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE,
|
Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE,
|
||||||
"Could not call method '" + method.toString() + "' of " + clazz + " for deserialization: method returned null");
|
"Could not call method '" + method.toString() + "' of " + clazz + " for deserialization: method returned null");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
} catch (final Throwable ex) {
|
||||||
catch (final Throwable ex)
|
Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE, "Could not call method '" + method.toString() + "' of " + clazz + " for deserialization",
|
||||||
{
|
|
||||||
Logger.getLogger(ConfigurationSerialization.class.getName()).log(
|
|
||||||
Level.SEVERE,
|
|
||||||
"Could not call method '" + method.toString() + "' of " + clazz + " for deserialization",
|
|
||||||
ex instanceof InvocationTargetException ? ex.getCause() : ex);
|
ex instanceof InvocationTargetException ? ex.getCause() : ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ConfigurationSerializable deserializeViaCtor(final Constructor<? extends ConfigurationSerializable> ctor, final Map<String, ?> args)
|
protected ConfigurationSerializable deserializeViaCtor(final Constructor<? extends ConfigurationSerializable> ctor, final Map<String, ?> args) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
return ctor.newInstance(args);
|
return ctor.newInstance(args);
|
||||||
}
|
} catch (final Throwable ex) {
|
||||||
catch (final Throwable ex)
|
Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE, "Could not call constructor '" + ctor.toString() + "' of " + clazz + " for deserialization",
|
||||||
{
|
|
||||||
Logger.getLogger(ConfigurationSerialization.class.getName()).log(
|
|
||||||
Level.SEVERE,
|
|
||||||
"Could not call constructor '" + ctor.toString() + "' of " + clazz + " for deserialization",
|
|
||||||
ex instanceof InvocationTargetException ? ex.getCause() : ex);
|
ex instanceof InvocationTargetException ? ex.getCause() : ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigurationSerializable deserialize(final Map<String, ?> args)
|
public ConfigurationSerializable deserialize(final Map<String, ?> args) {
|
||||||
{
|
if (args == null) {
|
||||||
if (args == null) { throw new NullPointerException("Args must not be null"); }
|
throw new NullPointerException("Args must not be null");
|
||||||
|
}
|
||||||
ConfigurationSerializable result = null;
|
ConfigurationSerializable result = null;
|
||||||
Method method = null;
|
Method method = null;
|
||||||
|
|
||||||
if (result == null)
|
if (result == null) {
|
||||||
{
|
|
||||||
method = getMethod("deserialize", true);
|
method = getMethod("deserialize", true);
|
||||||
|
|
||||||
if (method != null)
|
if (method != null) {
|
||||||
{
|
|
||||||
result = deserializeViaMethod(method, args);
|
result = deserializeViaMethod(method, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == null)
|
if (result == null) {
|
||||||
{
|
|
||||||
method = getMethod("valueOf", true);
|
method = getMethod("valueOf", true);
|
||||||
|
|
||||||
if (method != null)
|
if (method != null) {
|
||||||
{
|
|
||||||
result = deserializeViaMethod(method, args);
|
result = deserializeViaMethod(method, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == null)
|
if (result == null) {
|
||||||
{
|
|
||||||
final Constructor<? extends ConfigurationSerializable> constructor = getConstructor();
|
final Constructor<? extends ConfigurationSerializable> constructor = getConstructor();
|
||||||
|
|
||||||
if (constructor != null)
|
if (constructor != null) {
|
||||||
{
|
|
||||||
result = deserializeViaCtor(constructor, args);
|
result = deserializeViaCtor(constructor, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,8 +130,7 @@ public class ConfigurationSerialization
|
|||||||
* @param clazz Class to deserialize into
|
* @param clazz Class to deserialize into
|
||||||
* @return New instance of the specified class
|
* @return New instance of the specified class
|
||||||
*/
|
*/
|
||||||
public static ConfigurationSerializable deserializeObject(final Map<String, ?> args, final Class<? extends ConfigurationSerializable> clazz)
|
public static ConfigurationSerializable deserializeObject(final Map<String, ?> args, final Class<? extends ConfigurationSerializable> clazz) {
|
||||||
{
|
|
||||||
return new ConfigurationSerialization(clazz).deserialize(args);
|
return new ConfigurationSerialization(clazz).deserialize(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,28 +148,25 @@ public class ConfigurationSerialization
|
|||||||
* @param args Arguments for deserialization
|
* @param args Arguments for deserialization
|
||||||
* @return New instance of the specified class
|
* @return New instance of the specified class
|
||||||
*/
|
*/
|
||||||
public static ConfigurationSerializable deserializeObject(final Map<String, ?> args)
|
public static ConfigurationSerializable deserializeObject(final Map<String, ?> args) {
|
||||||
{
|
|
||||||
Class<? extends ConfigurationSerializable> clazz = null;
|
Class<? extends ConfigurationSerializable> clazz = null;
|
||||||
|
|
||||||
if (args.containsKey(SERIALIZED_TYPE_KEY))
|
if (args.containsKey(SERIALIZED_TYPE_KEY)) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final String alias = (String) args.get(SERIALIZED_TYPE_KEY);
|
final String alias = (String) args.get(SERIALIZED_TYPE_KEY);
|
||||||
|
|
||||||
if (alias == null) { throw new IllegalArgumentException("Cannot have null alias"); }
|
if (alias == null) {
|
||||||
clazz = getClassByAlias(alias);
|
throw new IllegalArgumentException("Cannot have null alias");
|
||||||
if (clazz == null) { throw new IllegalArgumentException("Specified class does not exist ('" + alias + "')"); }
|
|
||||||
}
|
}
|
||||||
catch (final ClassCastException ex)
|
clazz = getClassByAlias(alias);
|
||||||
{
|
if (clazz == null) {
|
||||||
|
throw new IllegalArgumentException("Specified class does not exist ('" + alias + "')");
|
||||||
|
}
|
||||||
|
} catch (final ClassCastException ex) {
|
||||||
ex.fillInStackTrace();
|
ex.fillInStackTrace();
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Args doesn't contain type key ('" + SERIALIZED_TYPE_KEY + "')");
|
throw new IllegalArgumentException("Args doesn't contain type key ('" + SERIALIZED_TYPE_KEY + "')");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,12 +179,10 @@ public class ConfigurationSerialization
|
|||||||
*
|
*
|
||||||
* @param clazz Class to register
|
* @param clazz Class to register
|
||||||
*/
|
*/
|
||||||
public static void registerClass(final Class<? extends ConfigurationSerializable> clazz)
|
public static void registerClass(final Class<? extends ConfigurationSerializable> clazz) {
|
||||||
{
|
|
||||||
final DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);
|
final DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);
|
||||||
|
|
||||||
if (delegate == null)
|
if (delegate == null) {
|
||||||
{
|
|
||||||
registerClass(clazz, getAlias(clazz));
|
registerClass(clazz, getAlias(clazz));
|
||||||
registerClass(clazz, clazz.getName());
|
registerClass(clazz, clazz.getName());
|
||||||
}
|
}
|
||||||
@ -232,8 +196,7 @@ public class ConfigurationSerialization
|
|||||||
* @param alias Alias to register as
|
* @param alias Alias to register as
|
||||||
* @see SerializableAs
|
* @see SerializableAs
|
||||||
*/
|
*/
|
||||||
public static void registerClass(final Class<? extends ConfigurationSerializable> clazz, final String alias)
|
public static void registerClass(final Class<? extends ConfigurationSerializable> clazz, final String alias) {
|
||||||
{
|
|
||||||
aliases.put(alias, clazz);
|
aliases.put(alias, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,8 +205,7 @@ public class ConfigurationSerialization
|
|||||||
*
|
*
|
||||||
* @param alias Alias to unregister
|
* @param alias Alias to unregister
|
||||||
*/
|
*/
|
||||||
public static void unregisterClass(final String alias)
|
public static void unregisterClass(final String alias) {
|
||||||
{
|
|
||||||
aliases.remove(alias);
|
aliases.remove(alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,10 +215,8 @@ public class ConfigurationSerialization
|
|||||||
*
|
*
|
||||||
* @param clazz Class to unregister
|
* @param clazz Class to unregister
|
||||||
*/
|
*/
|
||||||
public static void unregisterClass(final Class<? extends ConfigurationSerializable> clazz)
|
public static void unregisterClass(final Class<? extends ConfigurationSerializable> clazz) {
|
||||||
{
|
while (aliases.values().remove(clazz)) {}
|
||||||
while (aliases.values().remove(clazz))
|
|
||||||
{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -266,8 +226,7 @@ public class ConfigurationSerialization
|
|||||||
* @param alias Alias of the serializable
|
* @param alias Alias of the serializable
|
||||||
* @return Registered class, or null if not found
|
* @return Registered class, or null if not found
|
||||||
*/
|
*/
|
||||||
public static Class<? extends ConfigurationSerializable> getClassByAlias(final String alias)
|
public static Class<? extends ConfigurationSerializable> getClassByAlias(final String alias) {
|
||||||
{
|
|
||||||
return aliases.get(alias);
|
return aliases.get(alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,27 +237,23 @@ public class ConfigurationSerialization
|
|||||||
* @param clazz Class to get alias for
|
* @param clazz Class to get alias for
|
||||||
* @return Alias to use for the class
|
* @return Alias to use for the class
|
||||||
*/
|
*/
|
||||||
public static String getAlias(final Class<? extends ConfigurationSerializable> clazz)
|
public static String getAlias(final Class<? extends ConfigurationSerializable> clazz) {
|
||||||
{
|
|
||||||
DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);
|
DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);
|
||||||
|
|
||||||
if (delegate != null)
|
if (delegate != null) {
|
||||||
{
|
if ((delegate.value() == null) || (delegate.value() == clazz)) {
|
||||||
if ((delegate.value() == null) || (delegate.value() == clazz))
|
|
||||||
{
|
|
||||||
delegate = null;
|
delegate = null;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return getAlias(delegate.value());
|
return getAlias(delegate.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delegate == null)
|
if (delegate == null) {
|
||||||
{
|
|
||||||
final SerializableAs alias = clazz.getAnnotation(SerializableAs.class);
|
final SerializableAs alias = clazz.getAnnotation(SerializableAs.class);
|
||||||
|
|
||||||
if ((alias != null) && (alias.value() != null)) { return alias.value(); }
|
if ((alias != null) && (alias.value() != null)) {
|
||||||
|
return alias.value();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return clazz.getName();
|
return clazz.getName();
|
||||||
|
@ -11,8 +11,7 @@ import java.lang.annotation.Target;
|
|||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
public @interface DelegateDeserialization
|
public @interface DelegateDeserialization {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Which class should be used as a delegate for this classes
|
* Which class should be used as a delegate for this classes
|
||||||
* deserialization
|
* deserialization
|
||||||
|
@ -21,8 +21,7 @@ import java.lang.annotation.Target;
|
|||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
public @interface SerializableAs
|
public @interface SerializableAs {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* This is the name your class will be stored and retrieved as.
|
* This is the name your class will be stored and retrieved as.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -3,8 +3,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,8 +11,7 @@ public final class ByteArrayTag extends Tag
|
|||||||
*
|
*
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public ByteArrayTag(final byte[] value)
|
public ByteArrayTag(final byte[] value) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@ -24,35 +22,29 @@ public final class ByteArrayTag extends Tag
|
|||||||
* @param name the name of the tag
|
* @param name the name of the tag
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public ByteArrayTag(final String name, final byte[] value)
|
public ByteArrayTag(final String name, final byte[] value) {
|
||||||
{
|
|
||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getValue()
|
public byte[] getValue() {
|
||||||
{
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
final StringBuilder hex = new StringBuilder();
|
final StringBuilder hex = new StringBuilder();
|
||||||
for (final byte b : value)
|
for (final byte b : value) {
|
||||||
{
|
|
||||||
final String hexDigits = Integer.toHexString(b).toUpperCase();
|
final String hexDigits = Integer.toHexString(b).toUpperCase();
|
||||||
if (hexDigits.length() == 1)
|
if (hexDigits.length() == 1) {
|
||||||
{
|
|
||||||
hex.append("0");
|
hex.append("0");
|
||||||
}
|
}
|
||||||
hex.append(hexDigits).append(" ");
|
hex.append(hexDigits).append(" ");
|
||||||
}
|
}
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
String append = "";
|
String append = "";
|
||||||
if ((name != null) && !name.equals(""))
|
if ((name != null) && !name.equals("")) {
|
||||||
{
|
|
||||||
append = "(\"" + getName() + "\")";
|
append = "(\"" + getName() + "\")";
|
||||||
}
|
}
|
||||||
return "TAG_Byte_Array" + append + ": " + hex;
|
return "TAG_Byte_Array" + append + ": " + hex;
|
||||||
|
@ -3,8 +3,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,8 +11,7 @@ public final class ByteTag extends Tag
|
|||||||
*
|
*
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public ByteTag(final byte value)
|
public ByteTag(final byte value) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@ -24,25 +22,21 @@ public final class ByteTag extends Tag
|
|||||||
* @param name the name of the tag
|
* @param name the name of the tag
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public ByteTag(final String name, final byte value)
|
public ByteTag(final String name, final byte value) {
|
||||||
{
|
|
||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Byte getValue()
|
public Byte getValue() {
|
||||||
{
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
String append = "";
|
String append = "";
|
||||||
if ((name != null) && !name.equals(""))
|
if ((name != null) && !name.equals("")) {
|
||||||
{
|
|
||||||
append = "(\"" + getName() + "\")";
|
append = "(\"" + getName() + "\")";
|
||||||
}
|
}
|
||||||
return "TAG_Byte" + append + ": " + value;
|
return "TAG_Byte" + append + ": " + value;
|
||||||
|
@ -8,8 +8,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,8 +16,7 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public CompoundTag(final Map<String, Tag> value)
|
public CompoundTag(final Map<String, Tag> value) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
this.value = Collections.unmodifiableMap(value);
|
this.value = Collections.unmodifiableMap(value);
|
||||||
}
|
}
|
||||||
@ -29,8 +27,7 @@ public final class CompoundTag extends Tag
|
|||||||
* @param name the name of the tag
|
* @param name the name of the tag
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public CompoundTag(final String name, final Map<String, Tag> value)
|
public CompoundTag(final String name, final Map<String, Tag> value) {
|
||||||
{
|
|
||||||
super(name);
|
super(name);
|
||||||
this.value = Collections.unmodifiableMap(value);
|
this.value = Collections.unmodifiableMap(value);
|
||||||
}
|
}
|
||||||
@ -42,14 +39,12 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return true if the tag contains the given key
|
* @return true if the tag contains the given key
|
||||||
*/
|
*/
|
||||||
public boolean containsKey(final String key)
|
public boolean containsKey(final String key) {
|
||||||
{
|
|
||||||
return value.containsKey(key);
|
return value.containsKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Tag> getValue()
|
public Map<String, Tag> getValue() {
|
||||||
{
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,8 +55,7 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return the new compound tag
|
* @return the new compound tag
|
||||||
*/
|
*/
|
||||||
public CompoundTag setValue(final Map<String, Tag> value)
|
public CompoundTag setValue(final Map<String, Tag> value) {
|
||||||
{
|
|
||||||
return new CompoundTag(getName(), value);
|
return new CompoundTag(getName(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,8 +64,7 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return the builder
|
* @return the builder
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder createBuilder()
|
public CompoundTagBuilder createBuilder() {
|
||||||
{
|
|
||||||
return new CompoundTagBuilder(new HashMap<String, Tag>(value));
|
return new CompoundTagBuilder(new HashMap<String, Tag>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,15 +76,11 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a byte array
|
* @return a byte array
|
||||||
*/
|
*/
|
||||||
public byte[] getByteArray(final String key)
|
public byte[] getByteArray(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = value.get(key);
|
||||||
if (tag instanceof ByteArrayTag)
|
if (tag instanceof ByteArrayTag) {
|
||||||
{
|
|
||||||
return ((ByteArrayTag) tag).getValue();
|
return ((ByteArrayTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,15 +93,11 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a byte
|
* @return a byte
|
||||||
*/
|
*/
|
||||||
public byte getByte(final String key)
|
public byte getByte(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = value.get(key);
|
||||||
if (tag instanceof ByteTag)
|
if (tag instanceof ByteTag) {
|
||||||
{
|
|
||||||
return ((ByteTag) tag).getValue();
|
return ((ByteTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return (byte) 0;
|
return (byte) 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,15 +110,11 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a double
|
* @return a double
|
||||||
*/
|
*/
|
||||||
public double getDouble(final String key)
|
public double getDouble(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = value.get(key);
|
||||||
if (tag instanceof DoubleTag)
|
if (tag instanceof DoubleTag) {
|
||||||
{
|
|
||||||
return ((DoubleTag) tag).getValue();
|
return ((DoubleTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,35 +127,21 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a double
|
* @return a double
|
||||||
*/
|
*/
|
||||||
public double asDouble(final String key)
|
public double asDouble(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,15 +154,11 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a float
|
* @return a float
|
||||||
*/
|
*/
|
||||||
public float getFloat(final String key)
|
public float getFloat(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = value.get(key);
|
||||||
if (tag instanceof FloatTag)
|
if (tag instanceof FloatTag) {
|
||||||
{
|
|
||||||
return ((FloatTag) tag).getValue();
|
return ((FloatTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -208,15 +171,11 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return an int array
|
* @return an int array
|
||||||
*/
|
*/
|
||||||
public int[] getIntArray(final String key)
|
public int[] getIntArray(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = value.get(key);
|
||||||
if (tag instanceof IntArrayTag)
|
if (tag instanceof IntArrayTag) {
|
||||||
{
|
|
||||||
return ((IntArrayTag) tag).getValue();
|
return ((IntArrayTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return new int[0];
|
return new int[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,15 +188,11 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return an int
|
* @return an int
|
||||||
*/
|
*/
|
||||||
public int getInt(final String key)
|
public int getInt(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = value.get(key);
|
||||||
if (tag instanceof IntTag)
|
if (tag instanceof IntTag) {
|
||||||
{
|
|
||||||
return ((IntTag) tag).getValue();
|
return ((IntTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,35 +205,21 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return an int
|
* @return an int
|
||||||
*/
|
*/
|
||||||
public int asInt(final String key)
|
public int asInt(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -291,15 +232,11 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a list of tags
|
* @return a list of tags
|
||||||
*/
|
*/
|
||||||
public List<Tag> getList(final String key)
|
public List<Tag> getList(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = value.get(key);
|
||||||
if (tag instanceof ListTag)
|
if (tag instanceof ListTag) {
|
||||||
{
|
|
||||||
return ((ListTag) tag).getValue();
|
return ((ListTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -312,15 +249,11 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a tag list instance
|
* @return a tag list instance
|
||||||
*/
|
*/
|
||||||
public ListTag getListTag(final String key)
|
public ListTag getListTag(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = value.get(key);
|
||||||
if (tag instanceof ListTag)
|
if (tag instanceof ListTag) {
|
||||||
{
|
|
||||||
return (ListTag) tag;
|
return (ListTag) tag;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return new ListTag(key, StringTag.class, Collections.<Tag> emptyList());
|
return new ListTag(key, StringTag.class, Collections.<Tag> emptyList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,23 +270,16 @@ public final class CompoundTag extends Tag
|
|||||||
* @return a list of tags
|
* @return a list of tags
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends Tag> List<T> getList(final String key, final Class<T> listType)
|
public <T extends Tag> List<T> getList(final String key, final Class<T> listType) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = value.get(key);
|
||||||
if (tag instanceof ListTag)
|
if (tag instanceof ListTag) {
|
||||||
{
|
|
||||||
final ListTag listTag = (ListTag) tag;
|
final ListTag listTag = (ListTag) tag;
|
||||||
if (listTag.getType().equals(listType))
|
if (listTag.getType().equals(listType)) {
|
||||||
{
|
|
||||||
return (List<T>) listTag.getValue();
|
return (List<T>) listTag.getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -366,15 +292,11 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a long
|
* @return a long
|
||||||
*/
|
*/
|
||||||
public long getLong(final String key)
|
public long getLong(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = value.get(key);
|
||||||
if (tag instanceof LongTag)
|
if (tag instanceof LongTag) {
|
||||||
{
|
|
||||||
return ((LongTag) tag).getValue();
|
return ((LongTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -387,35 +309,21 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a long
|
* @return a long
|
||||||
*/
|
*/
|
||||||
public long asLong(final String key)
|
public long asLong(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -428,15 +336,11 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a short
|
* @return a short
|
||||||
*/
|
*/
|
||||||
public short getShort(final String key)
|
public short getShort(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = value.get(key);
|
||||||
if (tag instanceof ShortTag)
|
if (tag instanceof ShortTag) {
|
||||||
{
|
|
||||||
return ((ShortTag) tag).getValue();
|
return ((ShortTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -449,32 +353,25 @@ public final class CompoundTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a string
|
* @return a string
|
||||||
*/
|
*/
|
||||||
public String getString(final String key)
|
public String getString(final String key) {
|
||||||
{
|
|
||||||
final Tag tag = value.get(key);
|
final Tag tag = value.get(key);
|
||||||
if (tag instanceof StringTag)
|
if (tag instanceof StringTag) {
|
||||||
{
|
|
||||||
return ((StringTag) tag).getValue();
|
return ((StringTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
String append = "";
|
String append = "";
|
||||||
if ((name != null) && !name.equals(""))
|
if ((name != null) && !name.equals("")) {
|
||||||
{
|
|
||||||
append = "(\"" + getName() + "\")";
|
append = "(\"" + getName() + "\")";
|
||||||
}
|
}
|
||||||
final StringBuilder bldr = new StringBuilder();
|
final StringBuilder bldr = new StringBuilder();
|
||||||
bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n");
|
bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n");
|
||||||
for (final Map.Entry<String, Tag> entry : value.entrySet())
|
for (final Map.Entry<String, Tag> entry : value.entrySet()) {
|
||||||
{
|
|
||||||
bldr.append(" ").append(entry.getValue().toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
|
bldr.append(" ").append(entry.getValue().toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
|
||||||
}
|
}
|
||||||
bldr.append("}");
|
bldr.append("}");
|
||||||
|
@ -8,15 +8,13 @@ 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() {
|
||||||
{
|
|
||||||
entries = new HashMap<String, Tag>();
|
entries = new HashMap<String, Tag>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,8 +23,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @param value the value
|
* @param value the value
|
||||||
*/
|
*/
|
||||||
CompoundTagBuilder(final Map<String, Tag> value)
|
CompoundTagBuilder(final Map<String, Tag> value) {
|
||||||
{
|
|
||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
entries = value;
|
entries = value;
|
||||||
}
|
}
|
||||||
@ -36,8 +33,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return a new builder
|
* @return a new builder
|
||||||
*/
|
*/
|
||||||
public static CompoundTagBuilder create()
|
public static CompoundTagBuilder create() {
|
||||||
{
|
|
||||||
return new CompoundTagBuilder();
|
return new CompoundTagBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,8 +45,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder put(final String key, final Tag value)
|
public CompoundTagBuilder put(final String key, final Tag value) {
|
||||||
{
|
|
||||||
checkNotNull(key);
|
checkNotNull(key);
|
||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
entries.put(key, value);
|
entries.put(key, value);
|
||||||
@ -65,8 +60,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,8 +72,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,8 +84,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,8 +96,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,8 +108,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,8 +120,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,8 +132,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,8 +144,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,8 +156,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,11 +167,9 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public CompoundTagBuilder putAll(final Map<String, ? extends Tag> value)
|
public CompoundTagBuilder putAll(final Map<String, ? extends Tag> value) {
|
||||||
{
|
|
||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
for (final Map.Entry<String, ? extends Tag> entry : value.entrySet())
|
for (final Map.Entry<String, ? extends Tag> entry : value.entrySet()) {
|
||||||
{
|
|
||||||
put(entry.getKey(), entry.getValue());
|
put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@ -196,8 +180,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return the new compound tag
|
* @return the new compound tag
|
||||||
*/
|
*/
|
||||||
public CompoundTag build()
|
public CompoundTag build() {
|
||||||
{
|
|
||||||
return new CompoundTag(new HashMap<String, Tag>(entries));
|
return new CompoundTag(new HashMap<String, Tag>(entries));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,8 +191,7 @@ public class CompoundTagBuilder
|
|||||||
*
|
*
|
||||||
* @return the created compound tag
|
* @return the created compound tag
|
||||||
*/
|
*/
|
||||||
public CompoundTag build(final String name)
|
public CompoundTag build(final String name) {
|
||||||
{
|
|
||||||
return new CompoundTag(name, new HashMap<String, Tag>(entries));
|
return new CompoundTag(name, new HashMap<String, Tag>(entries));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,8 +11,7 @@ public final class DoubleTag extends Tag
|
|||||||
*
|
*
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public DoubleTag(final double value)
|
public DoubleTag(final double value) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@ -24,25 +22,21 @@ public final class DoubleTag extends Tag
|
|||||||
* @param name the name of the tag
|
* @param name the name of the tag
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public DoubleTag(final String name, final double value)
|
public DoubleTag(final String name, final double value) {
|
||||||
{
|
|
||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Double getValue()
|
public Double getValue() {
|
||||||
{
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
String append = "";
|
String append = "";
|
||||||
if ((name != null) && !name.equals(""))
|
if ((name != null) && !name.equals("")) {
|
||||||
{
|
|
||||||
append = "(\"" + getName() + "\")";
|
append = "(\"" + getName() + "\")";
|
||||||
}
|
}
|
||||||
return "TAG_Double" + append + ": " + value;
|
return "TAG_Double" + append + ": " + value;
|
||||||
|
@ -3,25 +3,21 @@ 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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,8 +11,7 @@ public final class FloatTag extends Tag
|
|||||||
*
|
*
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public FloatTag(final float value)
|
public FloatTag(final float value) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@ -24,25 +22,21 @@ public final class FloatTag extends Tag
|
|||||||
* @param name the name of the tag
|
* @param name the name of the tag
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public FloatTag(final String name, final float value)
|
public FloatTag(final String name, final float value) {
|
||||||
{
|
|
||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Float getValue()
|
public Float getValue() {
|
||||||
{
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
String append = "";
|
String append = "";
|
||||||
if ((name != null) && !name.equals(""))
|
if ((name != null) && !name.equals("")) {
|
||||||
{
|
|
||||||
append = "(\"" + getName() + "\")";
|
append = "(\"" + getName() + "\")";
|
||||||
}
|
}
|
||||||
return "TAG_Float" + append + ": " + value;
|
return "TAG_Float" + append + ": " + value;
|
||||||
|
@ -5,8 +5,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -14,8 +13,7 @@ public final class IntArrayTag extends Tag
|
|||||||
*
|
*
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public IntArrayTag(final int[] value)
|
public IntArrayTag(final int[] value) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
@ -27,36 +25,30 @@ public final class IntArrayTag extends Tag
|
|||||||
* @param name the name of the tag
|
* @param name the name of the tag
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public IntArrayTag(final String name, final int[] value)
|
public IntArrayTag(final String name, final int[] value) {
|
||||||
{
|
|
||||||
super(name);
|
super(name);
|
||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getValue()
|
public int[] getValue() {
|
||||||
{
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
final StringBuilder hex = new StringBuilder();
|
final StringBuilder hex = new StringBuilder();
|
||||||
for (final int b : value)
|
for (final int b : value) {
|
||||||
{
|
|
||||||
final String hexDigits = Integer.toHexString(b).toUpperCase();
|
final String hexDigits = Integer.toHexString(b).toUpperCase();
|
||||||
if (hexDigits.length() == 1)
|
if (hexDigits.length() == 1) {
|
||||||
{
|
|
||||||
hex.append("0");
|
hex.append("0");
|
||||||
}
|
}
|
||||||
hex.append(hexDigits).append(" ");
|
hex.append(hexDigits).append(" ");
|
||||||
}
|
}
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
String append = "";
|
String append = "";
|
||||||
if ((name != null) && !name.equals(""))
|
if ((name != null) && !name.equals("")) {
|
||||||
{
|
|
||||||
append = "(\"" + getName() + "\")";
|
append = "(\"" + getName() + "\")";
|
||||||
}
|
}
|
||||||
return "TAG_Int_Array" + append + ": " + hex;
|
return "TAG_Int_Array" + append + ": " + hex;
|
||||||
|
@ -3,8 +3,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,8 +11,7 @@ public final class IntTag extends Tag
|
|||||||
*
|
*
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public IntTag(final int value)
|
public IntTag(final int value) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@ -24,25 +22,21 @@ public final class IntTag extends Tag
|
|||||||
* @param name the name of the tag
|
* @param name the name of the tag
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public IntTag(final String name, final int value)
|
public IntTag(final String name, final int value) {
|
||||||
{
|
|
||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getValue()
|
public Integer getValue() {
|
||||||
{
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
String append = "";
|
String append = "";
|
||||||
if ((name != null) && !name.equals(""))
|
if ((name != null) && !name.equals("")) {
|
||||||
{
|
|
||||||
append = "(\"" + getName() + "\")";
|
append = "(\"" + getName() + "\")";
|
||||||
}
|
}
|
||||||
return "TAG_Int" + append + ": " + value;
|
return "TAG_Int" + append + ": " + value;
|
||||||
|
@ -9,8 +9,7 @@ import java.util.NoSuchElementException;
|
|||||||
/**
|
/**
|
||||||
* 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;
|
||||||
|
|
||||||
@ -20,8 +19,7 @@ public final class ListTag extends Tag
|
|||||||
* @param type the type of tag
|
* @param type the type of tag
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public ListTag(final Class<? extends Tag> type, final List<? extends Tag> value)
|
public ListTag(final Class<? extends Tag> type, final List<? extends Tag> value) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -35,8 +33,7 @@ public final class ListTag extends Tag
|
|||||||
* @param type the type of tag
|
* @param type the type of tag
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public ListTag(final String name, final Class<? extends Tag> type, final List<? extends Tag> value)
|
public ListTag(final String name, final Class<? extends Tag> type, final List<? extends Tag> value) {
|
||||||
{
|
|
||||||
super(name);
|
super(name);
|
||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -48,14 +45,12 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return The type of item in this list.
|
* @return The type of item in this list.
|
||||||
*/
|
*/
|
||||||
public Class<? extends Tag> getType()
|
public Class<? extends Tag> getType() {
|
||||||
{
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Tag> getValue()
|
public List<Tag> getValue() {
|
||||||
{
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,8 +61,7 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a new list tag
|
* @return a new list 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,14 +72,10 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return the tag or null
|
* @return the tag or null
|
||||||
*/
|
*/
|
||||||
public Tag getIfExists(final int index)
|
public Tag getIfExists(final int index) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
return value.get(index);
|
return value.get(index);
|
||||||
}
|
} catch (final NoSuchElementException e) {
|
||||||
catch (final NoSuchElementException e)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,15 +88,11 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a byte array
|
* @return a byte array
|
||||||
*/
|
*/
|
||||||
public byte[] getByteArray(final int index)
|
public byte[] getByteArray(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ByteArrayTag)
|
if (tag instanceof ByteArrayTag) {
|
||||||
{
|
|
||||||
return ((ByteArrayTag) tag).getValue();
|
return ((ByteArrayTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,15 +105,11 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a byte
|
* @return a byte
|
||||||
*/
|
*/
|
||||||
public byte getByte(final int index)
|
public byte getByte(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ByteTag)
|
if (tag instanceof ByteTag) {
|
||||||
{
|
|
||||||
return ((ByteTag) tag).getValue();
|
return ((ByteTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return (byte) 0;
|
return (byte) 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,15 +122,11 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a double
|
* @return a double
|
||||||
*/
|
*/
|
||||||
public double getDouble(final int index)
|
public double getDouble(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof DoubleTag)
|
if (tag instanceof DoubleTag) {
|
||||||
{
|
|
||||||
return ((DoubleTag) tag).getValue();
|
return ((DoubleTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,35 +139,21 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a double
|
* @return a double
|
||||||
*/
|
*/
|
||||||
public double asDouble(final int index)
|
public double asDouble(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ByteTag)
|
if (tag instanceof ByteTag) {
|
||||||
{
|
|
||||||
return ((ByteTag) tag).getValue();
|
return ((ByteTag) tag).getValue();
|
||||||
}
|
} else 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,15 +166,11 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a float
|
* @return a float
|
||||||
*/
|
*/
|
||||||
public float getFloat(final int index)
|
public float getFloat(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof FloatTag)
|
if (tag instanceof FloatTag) {
|
||||||
{
|
|
||||||
return ((FloatTag) tag).getValue();
|
return ((FloatTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,15 +183,11 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return an int array
|
* @return an int array
|
||||||
*/
|
*/
|
||||||
public int[] getIntArray(final int index)
|
public int[] getIntArray(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof IntArrayTag)
|
if (tag instanceof IntArrayTag) {
|
||||||
{
|
|
||||||
return ((IntArrayTag) tag).getValue();
|
return ((IntArrayTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return new int[0];
|
return new int[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,15 +200,11 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return an int
|
* @return an int
|
||||||
*/
|
*/
|
||||||
public int getInt(final int index)
|
public int getInt(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof IntTag)
|
if (tag instanceof IntTag) {
|
||||||
{
|
|
||||||
return ((IntTag) tag).getValue();
|
return ((IntTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,35 +217,21 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return an int
|
* @return an int
|
||||||
*/
|
*/
|
||||||
public int asInt(final int index)
|
public int asInt(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ByteTag)
|
if (tag instanceof ByteTag) {
|
||||||
{
|
|
||||||
return ((ByteTag) tag).getValue();
|
return ((ByteTag) tag).getValue();
|
||||||
}
|
} else 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -306,15 +244,11 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a list of tags
|
* @return a list of tags
|
||||||
*/
|
*/
|
||||||
public List<Tag> getList(final int index)
|
public List<Tag> getList(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ListTag)
|
if (tag instanceof ListTag) {
|
||||||
{
|
|
||||||
return ((ListTag) tag).getValue();
|
return ((ListTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -327,15 +261,11 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a tag list instance
|
* @return a tag list instance
|
||||||
*/
|
*/
|
||||||
public ListTag getListTag(final int index)
|
public ListTag getListTag(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ListTag)
|
if (tag instanceof ListTag) {
|
||||||
{
|
|
||||||
return (ListTag) tag;
|
return (ListTag) tag;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return new ListTag(StringTag.class, Collections.<Tag> emptyList());
|
return new ListTag(StringTag.class, Collections.<Tag> emptyList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -352,23 +282,16 @@ public final class ListTag extends Tag
|
|||||||
* @return a list of tags
|
* @return a list of tags
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends Tag> List<T> getList(final int index, final Class<T> listType)
|
public <T extends Tag> List<T> getList(final int index, final Class<T> listType) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ListTag)
|
if (tag instanceof ListTag) {
|
||||||
{
|
|
||||||
final ListTag listTag = (ListTag) tag;
|
final ListTag listTag = (ListTag) tag;
|
||||||
if (listTag.getType().equals(listType))
|
if (listTag.getType().equals(listType)) {
|
||||||
{
|
|
||||||
return (List<T>) listTag.getValue();
|
return (List<T>) listTag.getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -381,15 +304,11 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a long
|
* @return a long
|
||||||
*/
|
*/
|
||||||
public long getLong(final int index)
|
public long getLong(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof LongTag)
|
if (tag instanceof LongTag) {
|
||||||
{
|
|
||||||
return ((LongTag) tag).getValue();
|
return ((LongTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -402,35 +321,21 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a long
|
* @return a long
|
||||||
*/
|
*/
|
||||||
public long asLong(final int index)
|
public long asLong(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ByteTag)
|
if (tag instanceof ByteTag) {
|
||||||
{
|
|
||||||
return ((ByteTag) tag).getValue();
|
return ((ByteTag) tag).getValue();
|
||||||
}
|
} else 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -443,15 +348,11 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a short
|
* @return a short
|
||||||
*/
|
*/
|
||||||
public short getShort(final int index)
|
public short getShort(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof ShortTag)
|
if (tag instanceof ShortTag) {
|
||||||
{
|
|
||||||
return ((ShortTag) tag).getValue();
|
return ((ShortTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -464,32 +365,25 @@ public final class ListTag extends Tag
|
|||||||
*
|
*
|
||||||
* @return a string
|
* @return a string
|
||||||
*/
|
*/
|
||||||
public String getString(final int index)
|
public String getString(final int index) {
|
||||||
{
|
|
||||||
final Tag tag = getIfExists(index);
|
final Tag tag = getIfExists(index);
|
||||||
if (tag instanceof StringTag)
|
if (tag instanceof StringTag) {
|
||||||
{
|
|
||||||
return ((StringTag) tag).getValue();
|
return ((StringTag) tag).getValue();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
String append = "";
|
String append = "";
|
||||||
if ((name != null) && !name.equals(""))
|
if ((name != null) && !name.equals("")) {
|
||||||
{
|
|
||||||
append = "(\"" + getName() + "\")";
|
append = "(\"" + getName() + "\")";
|
||||||
}
|
}
|
||||||
final StringBuilder bldr = new StringBuilder();
|
final StringBuilder bldr = new StringBuilder();
|
||||||
bldr.append("TAG_List").append(append).append(": ").append(value.size()).append(" entries of type ").append(NBTUtils.getTypeName(type)).append("\r\n{\r\n");
|
bldr.append("TAG_List").append(append).append(": ").append(value.size()).append(" entries of type ").append(NBTUtils.getTypeName(type)).append("\r\n{\r\n");
|
||||||
for (final Tag t : value)
|
for (final Tag t : value) {
|
||||||
{
|
|
||||||
bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
|
bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
|
||||||
}
|
}
|
||||||
bldr.append("}");
|
bldr.append("}");
|
||||||
|
@ -10,8 +10,7 @@ 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;
|
||||||
|
|
||||||
@ -20,8 +19,7 @@ public class ListTagBuilder
|
|||||||
*
|
*
|
||||||
* @param type of tag contained in this list
|
* @param type of tag contained in this list
|
||||||
*/
|
*/
|
||||||
ListTagBuilder(final Class<? extends Tag> type)
|
ListTagBuilder(final Class<? extends Tag> type) {
|
||||||
{
|
|
||||||
checkNotNull(type);
|
checkNotNull(type);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
entries = new ArrayList<Tag>();
|
entries = new ArrayList<Tag>();
|
||||||
@ -34,8 +32,7 @@ public class ListTagBuilder
|
|||||||
*
|
*
|
||||||
* @return a new builder
|
* @return a new builder
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,14 +45,16 @@ public class ListTagBuilder
|
|||||||
* @return a new builder
|
* @return a new builder
|
||||||
*/
|
*/
|
||||||
@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) { throw new IllegalArgumentException("This method needs an array of at least one entry"); }
|
if (entries.length == 0) {
|
||||||
|
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));
|
||||||
@ -69,10 +68,11 @@ public class ListTagBuilder
|
|||||||
*
|
*
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public ListTagBuilder add(final Tag value)
|
public ListTagBuilder add(final Tag value) {
|
||||||
{
|
|
||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
if (!type.isInstance(value)) { throw new IllegalArgumentException(value.getClass().getCanonicalName() + " is not of expected type " + type.getCanonicalName()); }
|
if (!type.isInstance(value)) {
|
||||||
|
throw new IllegalArgumentException(value.getClass().getCanonicalName() + " is not of expected type " + type.getCanonicalName());
|
||||||
|
}
|
||||||
entries.add(value);
|
entries.add(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -84,11 +84,9 @@ public class ListTagBuilder
|
|||||||
*
|
*
|
||||||
* @return this object
|
* @return this object
|
||||||
*/
|
*/
|
||||||
public ListTagBuilder addAll(final Collection<? extends Tag> value)
|
public ListTagBuilder addAll(final Collection<? extends Tag> value) {
|
||||||
{
|
|
||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
for (final Tag v : value)
|
for (final Tag v : value) {
|
||||||
{
|
|
||||||
add(v);
|
add(v);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@ -99,8 +97,7 @@ public class ListTagBuilder
|
|||||||
*
|
*
|
||||||
* @return the new list tag
|
* @return the new list tag
|
||||||
*/
|
*/
|
||||||
public ListTag build()
|
public ListTag build() {
|
||||||
{
|
|
||||||
return new ListTag(type, new ArrayList<Tag>(entries));
|
return new ListTag(type, new ArrayList<Tag>(entries));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,8 +108,7 @@ public class ListTagBuilder
|
|||||||
*
|
*
|
||||||
* @return the created list tag
|
* @return the created list tag
|
||||||
*/
|
*/
|
||||||
public ListTag build(final String name)
|
public ListTag build(final String name) {
|
||||||
{
|
|
||||||
return new ListTag(name, type, new ArrayList<Tag>(entries));
|
return new ListTag(name, type, new ArrayList<Tag>(entries));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,8 +11,7 @@ public final class LongTag extends Tag
|
|||||||
*
|
*
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public LongTag(final long value)
|
public LongTag(final long value) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@ -24,25 +22,21 @@ public final class LongTag extends Tag
|
|||||||
* @param name the name of the tag
|
* @param name the name of the tag
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public LongTag(final String name, final long value)
|
public LongTag(final String name, final long value) {
|
||||||
{
|
|
||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getValue()
|
public Long getValue() {
|
||||||
{
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
String append = "";
|
String append = "";
|
||||||
if ((name != null) && !name.equals(""))
|
if ((name != null) && !name.equals("")) {
|
||||||
{
|
|
||||||
append = "(\"" + getName() + "\")";
|
append = "(\"" + getName() + "\")";
|
||||||
}
|
}
|
||||||
return "TAG_Long" + append + ": " + value;
|
return "TAG_Long" + append + ": " + value;
|
||||||
|
@ -25,8 +25,7 @@ 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,
|
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;
|
TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11;
|
||||||
@ -34,8 +33,7 @@ public final class NBTConstants
|
|||||||
/**
|
/**
|
||||||
* 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.
|
||||||
@ -46,10 +44,8 @@ public final class NBTConstants
|
|||||||
*
|
*
|
||||||
* @throws IllegalArgumentException thrown if the tag ID is not valid
|
* @throws IllegalArgumentException thrown if the tag ID is not valid
|
||||||
*/
|
*/
|
||||||
public static Class<? extends Tag> getClassFromType(final int id)
|
public static Class<? extends Tag> getClassFromType(final int id) {
|
||||||
{
|
switch (id) {
|
||||||
switch (id)
|
|
||||||
{
|
|
||||||
case TYPE_END:
|
case TYPE_END:
|
||||||
return EndTag.class;
|
return EndTag.class;
|
||||||
case TYPE_BYTE:
|
case TYPE_BYTE:
|
||||||
|
@ -14,8 +14,7 @@ import java.util.Map;
|
|||||||
* subclasses of the {@code Tag} object. The NBT format was created by Markus Persson, and the specification
|
* subclasses of the {@code Tag} object. The NBT format was created by Markus Persson, and the specification
|
||||||
* may be found at @linktourl http://www.minecraft.net/docs/NBT.txt"> http://www.minecraft.net/docs/NBT.txt.
|
* may be found at @linktourl http://www.minecraft.net/docs/NBT.txt"> http://www.minecraft.net/docs/NBT.txt.
|
||||||
*/
|
*/
|
||||||
public final class NBTInputStream implements Closeable
|
public final class NBTInputStream implements Closeable {
|
||||||
{
|
|
||||||
private final DataInputStream is;
|
private final DataInputStream is;
|
||||||
|
|
||||||
private int count;
|
private int count;
|
||||||
@ -27,8 +26,7 @@ public final class NBTInputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs
|
* @throws IOException if an I/O error occurs
|
||||||
*/
|
*/
|
||||||
public NBTInputStream(final InputStream is) throws IOException
|
public NBTInputStream(final InputStream is) throws IOException {
|
||||||
{
|
|
||||||
this.is = new DataInputStream(is);
|
this.is = new DataInputStream(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,8 +37,7 @@ public final class NBTInputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public Tag readTag() throws IOException
|
public Tag readTag() throws IOException {
|
||||||
{
|
|
||||||
return readTag(0, Integer.MAX_VALUE);
|
return readTag(0, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,8 +48,7 @@ public final class NBTInputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public Tag readTag(final int maxDepth) throws IOException
|
public Tag readTag(final int maxDepth) throws IOException {
|
||||||
{
|
|
||||||
return readTag(0, maxDepth);
|
return readTag(0, maxDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,20 +61,18 @@ public final class NBTInputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private Tag readTag(final int depth, final int maxDepth) throws IOException
|
private Tag readTag(final int depth, final int maxDepth) throws IOException {
|
||||||
{
|
if ((count++) > maxDepth) {
|
||||||
if ((count++) > maxDepth) { throw new IOException("Exceeds max depth: " + count); }
|
throw new IOException("Exceeds max depth: " + count);
|
||||||
|
}
|
||||||
final int type = is.readByte() & 0xFF;
|
final int type = is.readByte() & 0xFF;
|
||||||
String name;
|
String name;
|
||||||
if (type != NBTConstants.TYPE_END)
|
if (type != NBTConstants.TYPE_END) {
|
||||||
{
|
|
||||||
final int nameLength = is.readShort() & 0xFFFF;
|
final int nameLength = is.readShort() & 0xFFFF;
|
||||||
final byte[] nameBytes = new byte[nameLength];
|
final byte[] nameBytes = new byte[nameLength];
|
||||||
is.readFully(nameBytes);
|
is.readFully(nameBytes);
|
||||||
name = new String(nameBytes, NBTConstants.CHARSET);
|
name = new String(nameBytes, NBTConstants.CHARSET);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
name = "";
|
name = "";
|
||||||
}
|
}
|
||||||
return readTagPayload(type, name, depth, maxDepth);
|
return readTagPayload(type, name, depth, maxDepth);
|
||||||
@ -95,19 +89,16 @@ public final class NBTInputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private Tag readTagPayload(final int type, final String name, final int depth, final int maxDepth) throws IOException
|
private Tag readTagPayload(final int type, final String name, final int depth, final int maxDepth) throws IOException {
|
||||||
{
|
if ((count++) > maxDepth) {
|
||||||
if ((count++) > maxDepth) { throw new IOException("Exceeds max depth: " + count); }
|
throw new IOException("Exceeds max depth: " + count);
|
||||||
count++;
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case NBTConstants.TYPE_END:
|
|
||||||
if (depth == 0)
|
|
||||||
{
|
|
||||||
throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
|
|
||||||
}
|
}
|
||||||
else
|
count++;
|
||||||
{
|
switch (type) {
|
||||||
|
case NBTConstants.TYPE_END:
|
||||||
|
if (depth == 0) {
|
||||||
|
throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
|
||||||
|
} else {
|
||||||
return new EndTag();
|
return new EndTag();
|
||||||
}
|
}
|
||||||
case NBTConstants.TYPE_BYTE:
|
case NBTConstants.TYPE_BYTE:
|
||||||
@ -126,7 +117,8 @@ public final class NBTInputStream implements Closeable
|
|||||||
int length = is.readInt();
|
int length = is.readInt();
|
||||||
|
|
||||||
// Max depth
|
// Max depth
|
||||||
if ((count += length) > maxDepth) { throw new IOException("Exceeds max depth: " + count);
|
if ((count += length) > maxDepth) {
|
||||||
|
throw new IOException("Exceeds max depth: " + count);
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +129,8 @@ public final class NBTInputStream implements Closeable
|
|||||||
length = is.readShort();
|
length = is.readShort();
|
||||||
|
|
||||||
// Max depth
|
// Max depth
|
||||||
if ((count += length) > maxDepth) { throw new IOException("Exceeds max depth: " + count);
|
if ((count += length) > maxDepth) {
|
||||||
|
throw new IOException("Exceeds max depth: " + count);
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,29 +142,27 @@ public final class NBTInputStream implements Closeable
|
|||||||
length = is.readInt();
|
length = is.readInt();
|
||||||
|
|
||||||
// Max depth
|
// Max depth
|
||||||
if ((count += length) > maxDepth) { throw new IOException("Exceeds max depth: " + count);
|
if ((count += length) > maxDepth) {
|
||||||
|
throw new IOException("Exceeds max depth: " + count);
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
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, maxDepth);
|
final Tag tag = readTagPayload(childType, "", depth + 1, maxDepth);
|
||||||
if (tag instanceof EndTag) { throw new IOException("TAG_End not permitted in a list."); }
|
if (tag instanceof EndTag) {
|
||||||
|
throw new IOException("TAG_End not permitted in a list.");
|
||||||
|
}
|
||||||
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>();
|
||||||
while (true)
|
while (true) {
|
||||||
{
|
|
||||||
final Tag tag = readTag(depth + 1, maxDepth);
|
final Tag tag = readTag(depth + 1, maxDepth);
|
||||||
if (tag instanceof EndTag)
|
if (tag instanceof EndTag) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
tagMap.put(tag.getName(), tag);
|
tagMap.put(tag.getName(), tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,11 +170,12 @@ public final class NBTInputStream implements Closeable
|
|||||||
case NBTConstants.TYPE_INT_ARRAY:
|
case NBTConstants.TYPE_INT_ARRAY:
|
||||||
length = is.readInt();
|
length = is.readInt();
|
||||||
// Max depth
|
// Max depth
|
||||||
if ((count += length) > maxDepth) { throw new IOException("Exceeds max depth: " + count); }
|
if ((count += length) > maxDepth) {
|
||||||
|
throw new IOException("Exceeds max depth: " + count);
|
||||||
|
}
|
||||||
//
|
//
|
||||||
final int[] data = new int[length];
|
final int[] data = new int[length];
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++) {
|
||||||
{
|
|
||||||
data[i] = is.readInt();
|
data[i] = is.readInt();
|
||||||
}
|
}
|
||||||
return new IntArrayTag(name, data);
|
return new IntArrayTag(name, data);
|
||||||
@ -193,8 +185,7 @@ public final class NBTInputStream implements Closeable
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException
|
public void close() throws IOException {
|
||||||
{
|
|
||||||
is.close();
|
is.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,7 @@ 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.
|
||||||
*/
|
*/
|
||||||
@ -49,8 +48,7 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public NBTOutputStream(final OutputStream os) throws IOException
|
public NBTOutputStream(final OutputStream os) throws IOException {
|
||||||
{
|
|
||||||
this.os = new DataOutputStream(os);
|
this.os = new DataOutputStream(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,15 +59,16 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public void writeTag(final Tag tag) throws IOException
|
public void writeTag(final Tag tag) throws IOException {
|
||||||
{
|
|
||||||
final int type = NBTUtils.getTypeCode(tag.getClass());
|
final int type = NBTUtils.getTypeCode(tag.getClass());
|
||||||
final String name = tag.getName();
|
final String name = tag.getName();
|
||||||
final byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
|
final byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
|
||||||
os.writeByte(type);
|
os.writeByte(type);
|
||||||
os.writeShort(nameBytes.length);
|
os.writeShort(nameBytes.length);
|
||||||
os.write(nameBytes);
|
os.write(nameBytes);
|
||||||
if (type == NBTConstants.TYPE_END) { throw new IOException("Named TAG_End not permitted."); }
|
if (type == NBTConstants.TYPE_END) {
|
||||||
|
throw new IOException("Named TAG_End not permitted.");
|
||||||
|
}
|
||||||
writeTagPayload(tag);
|
writeTagPayload(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,11 +79,9 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeTagPayload(final Tag tag) throws IOException
|
private void writeTagPayload(final Tag tag) throws IOException {
|
||||||
{
|
|
||||||
final int type = NBTUtils.getTypeCode(tag.getClass());
|
final int type = NBTUtils.getTypeCode(tag.getClass());
|
||||||
switch (type)
|
switch (type) {
|
||||||
{
|
|
||||||
case NBTConstants.TYPE_END:
|
case NBTConstants.TYPE_END:
|
||||||
writeEndTagPayload((EndTag) tag);
|
writeEndTagPayload((EndTag) tag);
|
||||||
break;
|
break;
|
||||||
@ -133,8 +130,7 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeByteTagPayload(final ByteTag tag) throws IOException
|
private void writeByteTagPayload(final ByteTag tag) throws IOException {
|
||||||
{
|
|
||||||
os.writeByte(tag.getValue());
|
os.writeByte(tag.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,8 +141,7 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeByteArrayTagPayload(final ByteArrayTag tag) throws IOException
|
private void writeByteArrayTagPayload(final ByteArrayTag tag) throws IOException {
|
||||||
{
|
|
||||||
final byte[] bytes = tag.getValue();
|
final byte[] bytes = tag.getValue();
|
||||||
os.writeInt(bytes.length);
|
os.writeInt(bytes.length);
|
||||||
os.write(bytes);
|
os.write(bytes);
|
||||||
@ -159,10 +154,8 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeCompoundTagPayload(final CompoundTag tag) throws IOException
|
private void writeCompoundTagPayload(final CompoundTag tag) throws IOException {
|
||||||
{
|
for (final Tag childTag : tag.getValue().values()) {
|
||||||
for (final Tag childTag : tag.getValue().values())
|
|
||||||
{
|
|
||||||
writeTag(childTag);
|
writeTag(childTag);
|
||||||
}
|
}
|
||||||
os.writeByte((byte) 0); // end tag - better way?
|
os.writeByte((byte) 0); // end tag - better way?
|
||||||
@ -175,15 +168,13 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeListTagPayload(final ListTag tag) throws IOException
|
private void writeListTagPayload(final ListTag tag) throws IOException {
|
||||||
{
|
|
||||||
final Class<? extends Tag> clazz = tag.getType();
|
final Class<? extends Tag> clazz = tag.getType();
|
||||||
final List<Tag> tags = tag.getValue();
|
final List<Tag> tags = tag.getValue();
|
||||||
final int size = tags.size();
|
final int size = tags.size();
|
||||||
os.writeByte(NBTUtils.getTypeCode(clazz));
|
os.writeByte(NBTUtils.getTypeCode(clazz));
|
||||||
os.writeInt(size);
|
os.writeInt(size);
|
||||||
for (final Tag tag1 : tags)
|
for (final Tag tag1 : tags) {
|
||||||
{
|
|
||||||
writeTagPayload(tag1);
|
writeTagPayload(tag1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,8 +186,7 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeStringTagPayload(final StringTag tag) throws IOException
|
private void writeStringTagPayload(final StringTag tag) throws IOException {
|
||||||
{
|
|
||||||
final byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
|
final byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
|
||||||
os.writeShort(bytes.length);
|
os.writeShort(bytes.length);
|
||||||
os.write(bytes);
|
os.write(bytes);
|
||||||
@ -209,8 +199,7 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeDoubleTagPayload(final DoubleTag tag) throws IOException
|
private void writeDoubleTagPayload(final DoubleTag tag) throws IOException {
|
||||||
{
|
|
||||||
os.writeDouble(tag.getValue());
|
os.writeDouble(tag.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,8 +210,7 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeFloatTagPayload(final FloatTag tag) throws IOException
|
private void writeFloatTagPayload(final FloatTag tag) throws IOException {
|
||||||
{
|
|
||||||
os.writeFloat(tag.getValue());
|
os.writeFloat(tag.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,8 +221,7 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeLongTagPayload(final LongTag tag) throws IOException
|
private void writeLongTagPayload(final LongTag tag) throws IOException {
|
||||||
{
|
|
||||||
os.writeLong(tag.getValue());
|
os.writeLong(tag.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,8 +232,7 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeIntTagPayload(final IntTag tag) throws IOException
|
private void writeIntTagPayload(final IntTag tag) throws IOException {
|
||||||
{
|
|
||||||
os.writeInt(tag.getValue());
|
os.writeInt(tag.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,8 +243,7 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeShortTagPayload(final ShortTag tag) throws IOException
|
private void writeShortTagPayload(final ShortTag tag) throws IOException {
|
||||||
{
|
|
||||||
os.writeShort(tag.getValue());
|
os.writeShort(tag.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,24 +254,20 @@ public final class NBTOutputStream implements Closeable
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void writeEndTagPayload(final EndTag tag)
|
private void writeEndTagPayload(final EndTag tag) {
|
||||||
{
|
|
||||||
/* empty */
|
/* empty */
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
os.writeInt(data.length);
|
os.writeInt(data.length);
|
||||||
for (final int element : data)
|
for (final int element : data) {
|
||||||
{
|
|
||||||
os.writeInt(element);
|
os.writeInt(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException
|
public void close() throws IOException {
|
||||||
{
|
|
||||||
os.close();
|
os.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,8 +275,7 @@ public final class NBTOutputStream implements Closeable
|
|||||||
* Flush output
|
* Flush output
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void flush() throws IOException
|
public void flush() throws IOException {
|
||||||
{
|
|
||||||
os.flush();
|
os.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,11 @@ 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.
|
||||||
@ -20,58 +18,32 @@ public final class NBTUtils
|
|||||||
*
|
*
|
||||||
* @return The type name.
|
* @return The type name.
|
||||||
*/
|
*/
|
||||||
public static String getTypeName(final Class<? extends Tag> clazz)
|
public static String getTypeName(final Class<? extends Tag> clazz) {
|
||||||
{
|
if (clazz.equals(ByteArrayTag.class)) {
|
||||||
if (clazz.equals(ByteArrayTag.class))
|
|
||||||
{
|
|
||||||
return "TAG_Byte_Array";
|
return "TAG_Byte_Array";
|
||||||
}
|
} else if (clazz.equals(ByteTag.class)) {
|
||||||
else if (clazz.equals(ByteTag.class))
|
|
||||||
{
|
|
||||||
return "TAG_Byte";
|
return "TAG_Byte";
|
||||||
}
|
} else if (clazz.equals(CompoundTag.class)) {
|
||||||
else if (clazz.equals(CompoundTag.class))
|
|
||||||
{
|
|
||||||
return "TAG_Compound";
|
return "TAG_Compound";
|
||||||
}
|
} else if (clazz.equals(DoubleTag.class)) {
|
||||||
else if (clazz.equals(DoubleTag.class))
|
|
||||||
{
|
|
||||||
return "TAG_Double";
|
return "TAG_Double";
|
||||||
}
|
} else if (clazz.equals(EndTag.class)) {
|
||||||
else if (clazz.equals(EndTag.class))
|
|
||||||
{
|
|
||||||
return "TAG_End";
|
return "TAG_End";
|
||||||
}
|
} else if (clazz.equals(FloatTag.class)) {
|
||||||
else if (clazz.equals(FloatTag.class))
|
|
||||||
{
|
|
||||||
return "TAG_Float";
|
return "TAG_Float";
|
||||||
}
|
} else if (clazz.equals(IntTag.class)) {
|
||||||
else if (clazz.equals(IntTag.class))
|
|
||||||
{
|
|
||||||
return "TAG_Int";
|
return "TAG_Int";
|
||||||
}
|
} else if (clazz.equals(ListTag.class)) {
|
||||||
else if (clazz.equals(ListTag.class))
|
|
||||||
{
|
|
||||||
return "TAG_List";
|
return "TAG_List";
|
||||||
}
|
} else if (clazz.equals(LongTag.class)) {
|
||||||
else if (clazz.equals(LongTag.class))
|
|
||||||
{
|
|
||||||
return "TAG_Long";
|
return "TAG_Long";
|
||||||
}
|
} else if (clazz.equals(ShortTag.class)) {
|
||||||
else if (clazz.equals(ShortTag.class))
|
|
||||||
{
|
|
||||||
return "TAG_Short";
|
return "TAG_Short";
|
||||||
}
|
} else if (clazz.equals(StringTag.class)) {
|
||||||
else if (clazz.equals(StringTag.class))
|
|
||||||
{
|
|
||||||
return "TAG_String";
|
return "TAG_String";
|
||||||
}
|
} else if (clazz.equals(IntArrayTag.class)) {
|
||||||
else if (clazz.equals(IntArrayTag.class))
|
|
||||||
{
|
|
||||||
return "TAG_Int_Array";
|
return "TAG_Int_Array";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,58 +57,32 @@ public final class NBTUtils
|
|||||||
*
|
*
|
||||||
* @throws IllegalArgumentException if the tag class is invalid.
|
* @throws IllegalArgumentException if the tag class is invalid.
|
||||||
*/
|
*/
|
||||||
public static int getTypeCode(final Class<? extends Tag> clazz)
|
public static int getTypeCode(final Class<? extends Tag> clazz) {
|
||||||
{
|
if (clazz.equals(ByteArrayTag.class)) {
|
||||||
if (clazz.equals(ByteArrayTag.class))
|
|
||||||
{
|
|
||||||
return NBTConstants.TYPE_BYTE_ARRAY;
|
return NBTConstants.TYPE_BYTE_ARRAY;
|
||||||
}
|
} else if (clazz.equals(ByteTag.class)) {
|
||||||
else if (clazz.equals(ByteTag.class))
|
|
||||||
{
|
|
||||||
return NBTConstants.TYPE_BYTE;
|
return NBTConstants.TYPE_BYTE;
|
||||||
}
|
} else if (clazz.equals(CompoundTag.class)) {
|
||||||
else if (clazz.equals(CompoundTag.class))
|
|
||||||
{
|
|
||||||
return NBTConstants.TYPE_COMPOUND;
|
return NBTConstants.TYPE_COMPOUND;
|
||||||
}
|
} else if (clazz.equals(DoubleTag.class)) {
|
||||||
else if (clazz.equals(DoubleTag.class))
|
|
||||||
{
|
|
||||||
return NBTConstants.TYPE_DOUBLE;
|
return NBTConstants.TYPE_DOUBLE;
|
||||||
}
|
} else if (clazz.equals(EndTag.class)) {
|
||||||
else if (clazz.equals(EndTag.class))
|
|
||||||
{
|
|
||||||
return NBTConstants.TYPE_END;
|
return NBTConstants.TYPE_END;
|
||||||
}
|
} else if (clazz.equals(FloatTag.class)) {
|
||||||
else if (clazz.equals(FloatTag.class))
|
|
||||||
{
|
|
||||||
return NBTConstants.TYPE_FLOAT;
|
return NBTConstants.TYPE_FLOAT;
|
||||||
}
|
} else if (clazz.equals(IntTag.class)) {
|
||||||
else if (clazz.equals(IntTag.class))
|
|
||||||
{
|
|
||||||
return NBTConstants.TYPE_INT;
|
return NBTConstants.TYPE_INT;
|
||||||
}
|
} else if (clazz.equals(ListTag.class)) {
|
||||||
else if (clazz.equals(ListTag.class))
|
|
||||||
{
|
|
||||||
return NBTConstants.TYPE_LIST;
|
return NBTConstants.TYPE_LIST;
|
||||||
}
|
} else if (clazz.equals(LongTag.class)) {
|
||||||
else if (clazz.equals(LongTag.class))
|
|
||||||
{
|
|
||||||
return NBTConstants.TYPE_LONG;
|
return NBTConstants.TYPE_LONG;
|
||||||
}
|
} else if (clazz.equals(ShortTag.class)) {
|
||||||
else if (clazz.equals(ShortTag.class))
|
|
||||||
{
|
|
||||||
return NBTConstants.TYPE_SHORT;
|
return NBTConstants.TYPE_SHORT;
|
||||||
}
|
} else if (clazz.equals(StringTag.class)) {
|
||||||
else if (clazz.equals(StringTag.class))
|
|
||||||
{
|
|
||||||
return NBTConstants.TYPE_STRING;
|
return NBTConstants.TYPE_STRING;
|
||||||
}
|
} else if (clazz.equals(IntArrayTag.class)) {
|
||||||
else if (clazz.equals(IntArrayTag.class))
|
|
||||||
{
|
|
||||||
return NBTConstants.TYPE_INT_ARRAY;
|
return NBTConstants.TYPE_INT_ARRAY;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,10 +96,8 @@ public final class NBTUtils
|
|||||||
*
|
*
|
||||||
* @throws IllegalArgumentException if the tag type is invalid.
|
* @throws IllegalArgumentException if the tag type is invalid.
|
||||||
*/
|
*/
|
||||||
public static Class<? extends Tag> getTypeClass(final int type)
|
public static Class<? extends Tag> getTypeClass(final int type) {
|
||||||
{
|
switch (type) {
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case NBTConstants.TYPE_END:
|
case NBTConstants.TYPE_END:
|
||||||
return EndTag.class;
|
return EndTag.class;
|
||||||
case NBTConstants.TYPE_BYTE:
|
case NBTConstants.TYPE_BYTE:
|
||||||
@ -193,11 +137,14 @@ public final class NBTUtils
|
|||||||
*
|
*
|
||||||
* @return child tag
|
* @return child tag
|
||||||
*/
|
*/
|
||||||
public static <T extends Tag> T getChildTag(final Map<String, Tag> items, final String key, final Class<T> expected) throws IllegalArgumentException
|
public static <T extends Tag> T getChildTag(final Map<String, Tag> items, final String key, final Class<T> expected) throws IllegalArgumentException {
|
||||||
{
|
if (!items.containsKey(key)) {
|
||||||
if (!items.containsKey(key)) { throw new IllegalArgumentException("Missing a \"" + key + "\" tag"); }
|
throw new IllegalArgumentException("Missing a \"" + key + "\" tag");
|
||||||
|
}
|
||||||
final Tag tag = items.get(key);
|
final Tag tag = items.get(key);
|
||||||
if (!expected.isInstance(tag)) { throw new IllegalArgumentException(key + " tag is not of tag type " + expected.getName()); }
|
if (!expected.isInstance(tag)) {
|
||||||
|
throw new IllegalArgumentException(key + " tag is not of tag type " + expected.getName());
|
||||||
|
}
|
||||||
return expected.cast(tag);
|
return expected.cast(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,8 +31,7 @@ public final class ShortTag extends Tag
|
|||||||
*
|
*
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public ShortTag(final short value)
|
public ShortTag(final short value) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@ -44,25 +42,21 @@ public final class ShortTag extends Tag
|
|||||||
* @param name the name of the tag
|
* @param name the name of the tag
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public ShortTag(final String name, final short value)
|
public ShortTag(final String name, final short value) {
|
||||||
{
|
|
||||||
super(name);
|
super(name);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Short getValue()
|
public Short getValue() {
|
||||||
{
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
String append = "";
|
String append = "";
|
||||||
if ((name != null) && !name.equals(""))
|
if ((name != null) && !name.equals("")) {
|
||||||
{
|
|
||||||
append = "(\"" + getName() + "\")";
|
append = "(\"" + getName() + "\")";
|
||||||
}
|
}
|
||||||
return "TAG_Short" + append + ": " + value;
|
return "TAG_Short" + append + ": " + value;
|
||||||
|
@ -5,8 +5,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -14,8 +13,7 @@ public final class StringTag extends Tag
|
|||||||
*
|
*
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public StringTag(final String value)
|
public StringTag(final String value) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
@ -27,26 +25,22 @@ public final class StringTag extends Tag
|
|||||||
* @param name the name of the tag
|
* @param name the name of the tag
|
||||||
* @param value the value of the tag
|
* @param value the value of the tag
|
||||||
*/
|
*/
|
||||||
public StringTag(final String name, final String value)
|
public StringTag(final String name, final String value) {
|
||||||
{
|
|
||||||
super(name);
|
super(name);
|
||||||
checkNotNull(value);
|
checkNotNull(value);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue()
|
public String getValue() {
|
||||||
{
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
final String name = getName();
|
final String name = getName();
|
||||||
String append = "";
|
String append = "";
|
||||||
if ((name != null) && !name.equals(""))
|
if ((name != null) && !name.equals("")) {
|
||||||
{
|
|
||||||
append = "(\"" + getName() + "\")";
|
append = "(\"" + getName() + "\")";
|
||||||
}
|
}
|
||||||
return "TAG_String" + append + ": " + value;
|
return "TAG_String" + append + ": " + value;
|
||||||
|
@ -23,15 +23,13 @@ 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("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,10 +38,8 @@ public abstract class Tag
|
|||||||
*
|
*
|
||||||
* @param name the name
|
* @param name the name
|
||||||
*/
|
*/
|
||||||
Tag(String name)
|
Tag(String name) {
|
||||||
{
|
if (name == null) {
|
||||||
if (name == null)
|
|
||||||
{
|
|
||||||
name = "";
|
name = "";
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -54,8 +50,7 @@ public abstract class Tag
|
|||||||
*
|
*
|
||||||
* @return the name of this tag
|
* @return the name of this tag
|
||||||
*/
|
*/
|
||||||
public final String getName()
|
public final String getName() {
|
||||||
{
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,7 @@ package com.intellectualcrafters.json;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @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.
|
||||||
*
|
*
|
||||||
@ -28,32 +27,28 @@ public class CDL
|
|||||||
*
|
*
|
||||||
* @throws JSONException if the quoted string is badly formed.
|
* @throws JSONException if the quoted string is badly formed.
|
||||||
*/
|
*/
|
||||||
private static String getValue(final JSONTokener x) throws JSONException
|
private static String getValue(final JSONTokener x) throws JSONException {
|
||||||
{
|
|
||||||
char c;
|
char c;
|
||||||
char q;
|
char q;
|
||||||
StringBuffer sb;
|
StringBuffer sb;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
c = x.next();
|
c = x.next();
|
||||||
}
|
} while ((c == ' ') || (c == '\t'));
|
||||||
while ((c == ' ') || (c == '\t'));
|
switch (c) {
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
return null;
|
return null;
|
||||||
case '"':
|
case '"':
|
||||||
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;
|
||||||
}
|
}
|
||||||
if ((c == 0) || (c == '\n') || (c == '\r')) { throw x.syntaxError("Missing close quote '" + q + "'."); }
|
if ((c == 0) || (c == '\n') || (c == '\r')) {
|
||||||
|
throw x.syntaxError("Missing close quote '" + q + "'.");
|
||||||
|
}
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
@ -75,24 +70,23 @@ public class CDL
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static JSONArray rowToJSONArray(final JSONTokener x) throws JSONException
|
public static JSONArray rowToJSONArray(final JSONTokener x) throws JSONException {
|
||||||
{
|
|
||||||
final JSONArray ja = new JSONArray();
|
final JSONArray ja = new JSONArray();
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
final String value = getValue(x);
|
final String value = getValue(x);
|
||||||
char c = x.next();
|
char c = x.next();
|
||||||
if ((value == null) || ((ja.length() == 0) && (value.length() == 0) && (c != ','))) { return null; }
|
if ((value == null) || ((ja.length() == 0) && (value.length() == 0) && (c != ','))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
ja.put(value);
|
ja.put(value);
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
if (c == ',') {
|
||||||
if (c == ',')
|
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (c != ' ')
|
if (c != ' ') {
|
||||||
{
|
if ((c == '\n') || (c == '\r') || (c == 0)) {
|
||||||
if ((c == '\n') || (c == '\r') || (c == 0)) { return ja; }
|
return ja;
|
||||||
|
}
|
||||||
throw x.syntaxError("Bad character '" + c + "' (" + (int) c + ").");
|
throw x.syntaxError("Bad character '" + c + "' (" + (int) c + ").");
|
||||||
}
|
}
|
||||||
c = x.next();
|
c = x.next();
|
||||||
@ -112,8 +106,7 @@ public class CDL
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static JSONObject rowToJSONObject(final JSONArray names, final JSONTokener x) throws JSONException
|
public static JSONObject rowToJSONObject(final JSONArray names, final JSONTokener x) throws JSONException {
|
||||||
{
|
|
||||||
final JSONArray ja = rowToJSONArray(x);
|
final JSONArray ja = rowToJSONArray(x);
|
||||||
return ja != null ? ja.toJSONObject(names) : null;
|
return ja != null ? ja.toJSONObject(names) : null;
|
||||||
}
|
}
|
||||||
@ -126,35 +119,26 @@ public class CDL
|
|||||||
*
|
*
|
||||||
* @return A string ending in NEWLINE.
|
* @return A string ending in NEWLINE.
|
||||||
*/
|
*/
|
||||||
public static String rowToString(final JSONArray ja)
|
public static String rowToString(final JSONArray ja) {
|
||||||
{
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < ja.length(); i += 1)
|
for (int i = 0; i < ja.length(); i += 1) {
|
||||||
{
|
if (i > 0) {
|
||||||
if (i > 0)
|
|
||||||
{
|
|
||||||
sb.append(',');
|
sb.append(',');
|
||||||
}
|
}
|
||||||
final Object object = ja.opt(i);
|
final Object object = ja.opt(i);
|
||||||
if (object != null)
|
if (object != null) {
|
||||||
{
|
|
||||||
final String string = object.toString();
|
final String string = object.toString();
|
||||||
if ((string.length() > 0) && ((string.indexOf(',') >= 0) || (string.indexOf('\n') >= 0) || (string.indexOf('\r') >= 0) || (string.indexOf(0) >= 0) || (string.charAt(0) == '"')))
|
if ((string.length() > 0) && ((string.indexOf(',') >= 0) || (string.indexOf('\n') >= 0) || (string.indexOf('\r') >= 0) || (string.indexOf(0) >= 0) || (string.charAt(0) == '"'))) {
|
||||||
{
|
|
||||||
sb.append('"');
|
sb.append('"');
|
||||||
final int length = string.length();
|
final int length = string.length();
|
||||||
for (int j = 0; j < length; j += 1)
|
for (int j = 0; j < length; j += 1) {
|
||||||
{
|
|
||||||
final char c = string.charAt(j);
|
final char c = string.charAt(j);
|
||||||
if ((c >= ' ') && (c != '"'))
|
if ((c >= ' ') && (c != '"')) {
|
||||||
{
|
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.append('"');
|
sb.append('"');
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.append(string);
|
sb.append(string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,8 +156,7 @@ public class CDL
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,8 +169,7 @@ public class CDL
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,8 +184,7 @@ public class CDL
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,20 +199,21 @@ public class CDL
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static JSONArray toJSONArray(final JSONArray names, final JSONTokener x) throws JSONException
|
public static JSONArray toJSONArray(final JSONArray names, final JSONTokener x) throws JSONException {
|
||||||
{
|
if ((names == null) || (names.length() == 0)) {
|
||||||
if ((names == null) || (names.length() == 0)) { 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;
|
||||||
}
|
}
|
||||||
ja.put(jo);
|
ja.put(jo);
|
||||||
}
|
}
|
||||||
if (ja.length() == 0) { return null; }
|
if (ja.length() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return ja;
|
return ja;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,13 +227,13 @@ public class CDL
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static String toString(final JSONArray ja) throws JSONException
|
public static String toString(final JSONArray ja) throws JSONException {
|
||||||
{
|
|
||||||
final JSONObject jo = ja.optJSONObject(0);
|
final JSONObject jo = ja.optJSONObject(0);
|
||||||
if (jo != null)
|
if (jo != null) {
|
||||||
{
|
|
||||||
final JSONArray names = jo.names();
|
final JSONArray names = jo.names();
|
||||||
if (names != null) { return rowToString(names) + toString(names, ja); }
|
if (names != null) {
|
||||||
|
return rowToString(names) + toString(names, ja);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -267,15 +249,14 @@ public class CDL
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static String toString(final JSONArray names, final JSONArray ja) throws JSONException
|
public static String toString(final JSONArray names, final JSONArray ja) throws JSONException {
|
||||||
{
|
if ((names == null) || (names.length() == 0)) {
|
||||||
if ((names == null) || (names.length() == 0)) { return null; }
|
return null;
|
||||||
|
}
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < ja.length(); i += 1)
|
for (int i = 0; i < ja.length(); i += 1) {
|
||||||
{
|
|
||||||
final JSONObject jo = ja.optJSONObject(i);
|
final JSONObject jo = ja.optJSONObject(i);
|
||||||
if (jo != null)
|
if (jo != null) {
|
||||||
{
|
|
||||||
sb.append(rowToString(jo.toJSONArray(names)));
|
sb.append(rowToString(jo.toJSONArray(names)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,7 @@ package com.intellectualcrafters.json;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @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.
|
||||||
@ -40,23 +39,18 @@ public class Cookie
|
|||||||
*
|
*
|
||||||
* @return The escaped result.
|
* @return The escaped result.
|
||||||
*/
|
*/
|
||||||
public static String escape(final String string)
|
public static String escape(final String string) {
|
||||||
{
|
|
||||||
char c;
|
char c;
|
||||||
final String s = string.trim();
|
final String s = string.trim();
|
||||||
final int length = s.length();
|
final int length = s.length();
|
||||||
final StringBuilder sb = new StringBuilder(length);
|
final StringBuilder sb = new StringBuilder(length);
|
||||||
for (int i = 0; i < length; i += 1)
|
for (int i = 0; i < length; i += 1) {
|
||||||
{
|
|
||||||
c = s.charAt(i);
|
c = s.charAt(i);
|
||||||
if ((c < ' ') || (c == '+') || (c == '%') || (c == '=') || (c == ';'))
|
if ((c < ' ') || (c == '+') || (c == '%') || (c == '=') || (c == ';')) {
|
||||||
{
|
|
||||||
sb.append('%');
|
sb.append('%');
|
||||||
sb.append(Character.forDigit((char) ((c >>> 4) & 0x0f), 16));
|
sb.append(Character.forDigit((char) ((c >>> 4) & 0x0f), 16));
|
||||||
sb.append(Character.forDigit((char) (c & 0x0f), 16));
|
sb.append(Character.forDigit((char) (c & 0x0f), 16));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,8 +71,7 @@ public class Cookie
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static JSONObject toJSONObject(final String string) throws JSONException
|
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||||
{
|
|
||||||
String name;
|
String name;
|
||||||
final JSONObject jo = new JSONObject();
|
final JSONObject jo = new JSONObject();
|
||||||
Object value;
|
Object value;
|
||||||
@ -87,22 +80,15 @@ public class Cookie
|
|||||||
x.next('=');
|
x.next('=');
|
||||||
jo.put("value", x.nextTo(';'));
|
jo.put("value", x.nextTo(';'));
|
||||||
x.next();
|
x.next();
|
||||||
while (x.more())
|
while (x.more()) {
|
||||||
{
|
|
||||||
name = unescape(x.nextTo("=;"));
|
name = unescape(x.nextTo("=;"));
|
||||||
if (x.next() != '=')
|
if (x.next() != '=') {
|
||||||
{
|
if (name.equals("secure")) {
|
||||||
if (name.equals("secure"))
|
|
||||||
{
|
|
||||||
value = Boolean.TRUE;
|
value = Boolean.TRUE;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw x.syntaxError("Missing '=' in cookie parameter.");
|
throw x.syntaxError("Missing '=' in cookie parameter.");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
value = unescape(x.nextTo(';'));
|
value = unescape(x.nextTo(';'));
|
||||||
x.next();
|
x.next();
|
||||||
}
|
}
|
||||||
@ -122,29 +108,24 @@ public class Cookie
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
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")));
|
||||||
if (jo.has("expires"))
|
if (jo.has("expires")) {
|
||||||
{
|
|
||||||
sb.append(";expires=");
|
sb.append(";expires=");
|
||||||
sb.append(jo.getString("expires"));
|
sb.append(jo.getString("expires"));
|
||||||
}
|
}
|
||||||
if (jo.has("domain"))
|
if (jo.has("domain")) {
|
||||||
{
|
|
||||||
sb.append(";domain=");
|
sb.append(";domain=");
|
||||||
sb.append(escape(jo.getString("domain")));
|
sb.append(escape(jo.getString("domain")));
|
||||||
}
|
}
|
||||||
if (jo.has("path"))
|
if (jo.has("path")) {
|
||||||
{
|
|
||||||
sb.append(";path=");
|
sb.append(";path=");
|
||||||
sb.append(escape(jo.getString("path")));
|
sb.append(escape(jo.getString("path")));
|
||||||
}
|
}
|
||||||
if (jo.optBoolean("secure"))
|
if (jo.optBoolean("secure")) {
|
||||||
{
|
|
||||||
sb.append(";secure");
|
sb.append(";secure");
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
@ -158,23 +139,17 @@ public class Cookie
|
|||||||
*
|
*
|
||||||
* @return The unescaped string.
|
* @return The unescaped string.
|
||||||
*/
|
*/
|
||||||
public static String unescape(final String string)
|
public static String unescape(final String string) {
|
||||||
{
|
|
||||||
final int length = string.length();
|
final int length = string.length();
|
||||||
final StringBuilder sb = new StringBuilder(length);
|
final StringBuilder sb = new StringBuilder(length);
|
||||||
for (int i = 0; i < length; ++i)
|
for (int i = 0; i < length; ++i) {
|
||||||
{
|
|
||||||
char c = string.charAt(i);
|
char c = string.charAt(i);
|
||||||
if (c == '+')
|
if (c == '+') {
|
||||||
{
|
|
||||||
c = ' ';
|
c = ' ';
|
||||||
}
|
} else if ((c == '%') && ((i + 2) < length)) {
|
||||||
else if ((c == '%') && ((i + 2) < length))
|
|
||||||
{
|
|
||||||
final int d = JSONTokener.dehexchar(string.charAt(i + 1));
|
final int d = JSONTokener.dehexchar(string.charAt(i + 1));
|
||||||
final int e = JSONTokener.dehexchar(string.charAt(i + 2));
|
final int e = JSONTokener.dehexchar(string.charAt(i + 2));
|
||||||
if ((d >= 0) && (e >= 0))
|
if ((d >= 0) && (e >= 0)) {
|
||||||
{
|
|
||||||
c = (char) ((d * 16) + e);
|
c = (char) ((d * 16) + e);
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,7 @@ import java.util.Iterator;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @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
|
||||||
@ -24,12 +23,10 @@ public class CookieList
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static JSONObject toJSONObject(final String string) throws JSONException
|
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||||
{
|
|
||||||
final JSONObject jo = new JSONObject();
|
final JSONObject jo = new JSONObject();
|
||||||
final JSONTokener x = new JSONTokener(string);
|
final JSONTokener x = new JSONTokener(string);
|
||||||
while (x.more())
|
while (x.more()) {
|
||||||
{
|
|
||||||
final String name = Cookie.unescape(x.nextTo('='));
|
final String name = Cookie.unescape(x.nextTo('='));
|
||||||
x.next('=');
|
x.next('=');
|
||||||
jo.put(name, Cookie.unescape(x.nextTo(';')));
|
jo.put(name, Cookie.unescape(x.nextTo(';')));
|
||||||
@ -49,19 +46,15 @@ public class CookieList
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static String toString(final JSONObject jo) throws JSONException
|
public static String toString(final JSONObject jo) throws JSONException {
|
||||||
{
|
|
||||||
boolean b = false;
|
boolean b = false;
|
||||||
final Iterator<String> keys = jo.keys();
|
final Iterator<String> keys = jo.keys();
|
||||||
String string;
|
String string;
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
while (keys.hasNext())
|
while (keys.hasNext()) {
|
||||||
{
|
|
||||||
string = keys.next();
|
string = keys.next();
|
||||||
if (!jo.isNull(string))
|
if (!jo.isNull(string)) {
|
||||||
{
|
if (b) {
|
||||||
if (b)
|
|
||||||
{
|
|
||||||
sb.append(';');
|
sb.append(';');
|
||||||
}
|
}
|
||||||
sb.append(Cookie.escape(string));
|
sb.append(Cookie.escape(string));
|
||||||
|
@ -28,37 +28,31 @@ import java.util.Iterator;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @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";
|
||||||
|
|
||||||
public static JSONObject toJSONObject(final String string) throws JSONException
|
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||||
{
|
|
||||||
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(':');
|
||||||
jo.put(name, x.nextTo('\0'));
|
jo.put(name, x.nextTo('\0'));
|
||||||
@ -98,21 +92,17 @@ public class HTTP
|
|||||||
*
|
*
|
||||||
* @throws JSONException if the object does not contain enough information.
|
* @throws JSONException if the object does not contain enough information.
|
||||||
*/
|
*/
|
||||||
public static String toString(final JSONObject jo) throws JSONException
|
public static String toString(final JSONObject jo) throws JSONException {
|
||||||
{
|
|
||||||
final Iterator<String> keys = jo.keys();
|
final Iterator<String> keys = jo.keys();
|
||||||
String string;
|
String string;
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
if (jo.has("Status-Code") && jo.has("Reason-Phrase"))
|
if (jo.has("Status-Code") && jo.has("Reason-Phrase")) {
|
||||||
{
|
|
||||||
sb.append(jo.getString("HTTP-Version"));
|
sb.append(jo.getString("HTTP-Version"));
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
sb.append(jo.getString("Status-Code"));
|
sb.append(jo.getString("Status-Code"));
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
sb.append(jo.getString("Reason-Phrase"));
|
sb.append(jo.getString("Reason-Phrase"));
|
||||||
}
|
} else if (jo.has("Method") && jo.has("Request-URI")) {
|
||||||
else if (jo.has("Method") && jo.has("Request-URI"))
|
|
||||||
{
|
|
||||||
sb.append(jo.getString("Method"));
|
sb.append(jo.getString("Method"));
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
sb.append('"');
|
sb.append('"');
|
||||||
@ -120,17 +110,13 @@ public class HTTP
|
|||||||
sb.append('"');
|
sb.append('"');
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
sb.append(jo.getString("HTTP-Version"));
|
sb.append(jo.getString("HTTP-Version"));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new JSONException("Not enough material for an HTTP header.");
|
throw new JSONException("Not enough material for an HTTP header.");
|
||||||
}
|
}
|
||||||
sb.append(CRLF);
|
sb.append(CRLF);
|
||||||
while (keys.hasNext())
|
while (keys.hasNext()) {
|
||||||
{
|
|
||||||
string = keys.next();
|
string = keys.next();
|
||||||
if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) && !"Reason-Phrase".equals(string) && !"Method".equals(string) && !"Request-URI".equals(string) && !jo.isNull(string))
|
if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) && !"Reason-Phrase".equals(string) && !"Method".equals(string) && !"Request-URI".equals(string) && !jo.isNull(string)) {
|
||||||
{
|
|
||||||
sb.append(string);
|
sb.append(string);
|
||||||
sb.append(": ");
|
sb.append(": ");
|
||||||
sb.append(jo.getString(string));
|
sb.append(jo.getString(string));
|
||||||
|
@ -6,15 +6,13 @@ package com.intellectualcrafters.json;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @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.
|
||||||
*
|
*
|
||||||
* @param string A source string.
|
* @param string A source string.
|
||||||
*/
|
*/
|
||||||
public HTTPTokener(final String string)
|
public HTTPTokener(final String string) {
|
||||||
{
|
|
||||||
super(string);
|
super(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,30 +23,30 @@ public class HTTPTokener extends JSONTokener
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public String nextToken() throws JSONException
|
public String nextToken() throws JSONException {
|
||||||
{
|
|
||||||
char c;
|
char c;
|
||||||
char q;
|
char q;
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
c = next();
|
c = next();
|
||||||
}
|
} 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 < ' ') { throw syntaxError("Unterminated string."); }
|
if (c < ' ') {
|
||||||
if (c == q) { return sb.toString(); }
|
throw syntaxError("Unterminated string.");
|
||||||
|
}
|
||||||
|
if (c == q) {
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
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();
|
||||||
|
}
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
c = next();
|
c = next();
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,7 @@ import java.util.Map;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @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.
|
||||||
*/
|
*/
|
||||||
@ -66,8 +65,7 @@ public class JSONArray
|
|||||||
/**
|
/**
|
||||||
* Construct an empty JSONArray.
|
* Construct an empty JSONArray.
|
||||||
*/
|
*/
|
||||||
public JSONArray()
|
public JSONArray() {
|
||||||
{
|
|
||||||
myArrayList = new ArrayList<Object>();
|
myArrayList = new ArrayList<Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,29 +76,26 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If there is a syntax error.
|
* @throws JSONException If there is a syntax error.
|
||||||
*/
|
*/
|
||||||
public JSONArray(final JSONTokener x) throws JSONException
|
public JSONArray(final JSONTokener x) throws JSONException {
|
||||||
{
|
|
||||||
this();
|
this();
|
||||||
if (x.nextClean() != '[') { throw x.syntaxError("A JSONArray text must start with '['"); }
|
if (x.nextClean() != '[') {
|
||||||
if (x.nextClean() != ']')
|
throw x.syntaxError("A JSONArray text must start with '['");
|
||||||
{
|
}
|
||||||
|
if (x.nextClean() != ']') {
|
||||||
x.back();
|
x.back();
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
if (x.nextClean() == ',') {
|
||||||
if (x.nextClean() == ',')
|
|
||||||
{
|
|
||||||
x.back();
|
x.back();
|
||||||
myArrayList.add(JSONObject.NULL);
|
myArrayList.add(JSONObject.NULL);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
x.back();
|
x.back();
|
||||||
myArrayList.add(x.nextValue());
|
myArrayList.add(x.nextValue());
|
||||||
}
|
}
|
||||||
switch (x.nextClean())
|
switch (x.nextClean()) {
|
||||||
{
|
|
||||||
case ',':
|
case ',':
|
||||||
if (x.nextClean() == ']') { return; }
|
if (x.nextClean() == ']') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
x.back();
|
x.back();
|
||||||
break;
|
break;
|
||||||
case ']':
|
case ']':
|
||||||
@ -120,8 +115,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If there is a syntax error.
|
* @throws JSONException If there is a syntax error.
|
||||||
*/
|
*/
|
||||||
public JSONArray(final String source) throws JSONException
|
public JSONArray(final String source) throws JSONException {
|
||||||
{
|
|
||||||
this(new JSONTokener(source));
|
this(new JSONTokener(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,13 +124,10 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @param collection A Collection.
|
* @param collection A Collection.
|
||||||
*/
|
*/
|
||||||
public JSONArray(final Collection<Object> collection)
|
public JSONArray(final Collection<Object> collection) {
|
||||||
{
|
|
||||||
myArrayList = new ArrayList<Object>();
|
myArrayList = new ArrayList<Object>();
|
||||||
if (collection != null)
|
if (collection != null) {
|
||||||
{
|
for (final Object aCollection : collection) {
|
||||||
for (final Object aCollection : collection)
|
|
||||||
{
|
|
||||||
myArrayList.add(JSONObject.wrap(aCollection));
|
myArrayList.add(JSONObject.wrap(aCollection));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,19 +138,14 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If not an array.
|
* @throws JSONException If not an array.
|
||||||
*/
|
*/
|
||||||
public JSONArray(final Object array) throws JSONException
|
public JSONArray(final Object array) throws JSONException {
|
||||||
{
|
|
||||||
this();
|
this();
|
||||||
if (array.getClass().isArray())
|
if (array.getClass().isArray()) {
|
||||||
{
|
|
||||||
final int length = Array.getLength(array);
|
final int length = Array.getLength(array);
|
||||||
for (int i = 0; i < length; i += 1)
|
for (int i = 0; i < length; i += 1) {
|
||||||
{
|
|
||||||
this.put(JSONObject.wrap(Array.get(array, i)));
|
this.put(JSONObject.wrap(Array.get(array, i)));
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new JSONException("JSONArray initial value should be a string or collection or array.");
|
throw new JSONException("JSONArray initial value should be a string or collection or array.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,10 +159,11 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If there is no value for the index.
|
* @throws JSONException If there is no value for the index.
|
||||||
*/
|
*/
|
||||||
public Object get(final int index) throws JSONException
|
public Object get(final int index) throws JSONException {
|
||||||
{
|
|
||||||
final Object object = opt(index);
|
final Object object = opt(index);
|
||||||
if (object == null) { throw new JSONException("JSONArray[" + index + "] not found."); }
|
if (object == null) {
|
||||||
|
throw new JSONException("JSONArray[" + index + "] not found.");
|
||||||
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,14 +176,13 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If there is no value for the index or if the value is not convertible to boolean.
|
* @throws JSONException If there is no value for the index or if the value is not convertible to boolean.
|
||||||
*/
|
*/
|
||||||
public boolean getBoolean(final int index) throws JSONException
|
public boolean getBoolean(final int index) throws JSONException {
|
||||||
{
|
|
||||||
final Object object = get(index);
|
final Object object = get(index);
|
||||||
if (object.equals(Boolean.FALSE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("false")))
|
if (object.equals(Boolean.FALSE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("false"))) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
|
} else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) { return true; }
|
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
|
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,15 +195,11 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the key is not found or if the value cannot be converted to a number.
|
* @throws JSONException If the key is not found or if the value cannot be converted to a number.
|
||||||
*/
|
*/
|
||||||
public double getDouble(final int index) throws JSONException
|
public double getDouble(final int index) throws JSONException {
|
||||||
{
|
|
||||||
final Object object = get(index);
|
final Object object = get(index);
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object);
|
return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,15 +213,11 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the key is not found or if the value is not a number.
|
* @throws JSONException If the key is not found or if the value is not a number.
|
||||||
*/
|
*/
|
||||||
public int getInt(final int index) throws JSONException
|
public int getInt(final int index) throws JSONException {
|
||||||
{
|
|
||||||
final Object object = get(index);
|
final Object object = get(index);
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
return object instanceof Number ? ((Number) object).intValue() : Integer.parseInt((String) object);
|
return object instanceof Number ? ((Number) object).intValue() : Integer.parseInt((String) object);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,10 +231,11 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If there is no value for the index. or if the value is not a JSONArray
|
* @throws JSONException If there is no value for the index. or if the value is not a JSONArray
|
||||||
*/
|
*/
|
||||||
public JSONArray getJSONArray(final int index) throws JSONException
|
public JSONArray getJSONArray(final int index) throws JSONException {
|
||||||
{
|
|
||||||
final Object object = get(index);
|
final Object object = get(index);
|
||||||
if (object instanceof JSONArray) { return (JSONArray) object; }
|
if (object instanceof JSONArray) {
|
||||||
|
return (JSONArray) object;
|
||||||
|
}
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
|
throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,10 +248,11 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If there is no value for the index or if the value is not a JSONObject
|
* @throws JSONException If there is no value for the index or if the value is not a JSONObject
|
||||||
*/
|
*/
|
||||||
public JSONObject getJSONObject(final int index) throws JSONException
|
public JSONObject getJSONObject(final int index) throws JSONException {
|
||||||
{
|
|
||||||
final Object object = get(index);
|
final Object object = get(index);
|
||||||
if (object instanceof JSONObject) { return (JSONObject) object; }
|
if (object instanceof JSONObject) {
|
||||||
|
return (JSONObject) object;
|
||||||
|
}
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
|
throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,15 +265,11 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the key is not found or if the value cannot be converted to a number.
|
* @throws JSONException If the key is not found or if the value cannot be converted to a number.
|
||||||
*/
|
*/
|
||||||
public long getLong(final int index) throws JSONException
|
public long getLong(final int index) throws JSONException {
|
||||||
{
|
|
||||||
final Object object = get(index);
|
final Object object = get(index);
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
return object instanceof Number ? ((Number) object).longValue() : Long.parseLong((String) object);
|
return object instanceof Number ? ((Number) object).longValue() : Long.parseLong((String) object);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,10 +283,11 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If there is no string value for the index.
|
* @throws JSONException If there is no string value for the index.
|
||||||
*/
|
*/
|
||||||
public String getString(final int index) throws JSONException
|
public String getString(final int index) throws JSONException {
|
||||||
{
|
|
||||||
final Object object = get(index);
|
final Object object = get(index);
|
||||||
if (object instanceof String) { return (String) object; }
|
if (object instanceof String) {
|
||||||
|
return (String) object;
|
||||||
|
}
|
||||||
throw new JSONException("JSONArray[" + index + "] not a string.");
|
throw new JSONException("JSONArray[" + index + "] not a string.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,8 +298,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return true if the value at the index is null, or if there is no value.
|
* @return true if the value at the index is null, or if there is no value.
|
||||||
*/
|
*/
|
||||||
public boolean isNull(final int index)
|
public boolean isNull(final int index) {
|
||||||
{
|
|
||||||
return JSONObject.NULL.equals(opt(index));
|
return JSONObject.NULL.equals(opt(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,14 +312,11 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the array contains an invalid number.
|
* @throws JSONException If the array contains an invalid number.
|
||||||
*/
|
*/
|
||||||
public String join(final String separator) throws JSONException
|
public String join(final String separator) throws JSONException {
|
||||||
{
|
|
||||||
final int len = length();
|
final int len = 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);
|
||||||
}
|
}
|
||||||
sb.append(JSONObject.valueToString(myArrayList.get(i)));
|
sb.append(JSONObject.valueToString(myArrayList.get(i)));
|
||||||
@ -356,8 +329,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return The length (or size).
|
* @return The length (or size).
|
||||||
*/
|
*/
|
||||||
public int length()
|
public int length() {
|
||||||
{
|
|
||||||
return myArrayList.size();
|
return myArrayList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,8 +340,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return An object value, or null if there is no object at that index.
|
* @return An object value, or null if there is no object at that index.
|
||||||
*/
|
*/
|
||||||
public Object opt(final int index)
|
public Object opt(final int index) {
|
||||||
{
|
|
||||||
return ((index < 0) || (index >= length())) ? null : myArrayList.get(index);
|
return ((index < 0) || (index >= length())) ? null : myArrayList.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,8 +352,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return The truth.
|
* @return The truth.
|
||||||
*/
|
*/
|
||||||
public boolean optBoolean(final int index)
|
public boolean optBoolean(final int index) {
|
||||||
{
|
|
||||||
return this.optBoolean(index, false);
|
return this.optBoolean(index, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,14 +365,10 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return The truth.
|
* @return The truth.
|
||||||
*/
|
*/
|
||||||
public boolean optBoolean(final int index, final boolean defaultValue)
|
public boolean optBoolean(final int index, final boolean defaultValue) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
return getBoolean(index);
|
return getBoolean(index);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -415,8 +381,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public double optDouble(final int index)
|
public double optDouble(final int index) {
|
||||||
{
|
|
||||||
return this.optDouble(index, Double.NaN);
|
return this.optDouble(index, Double.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,14 +394,10 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public double optDouble(final int index, final double defaultValue)
|
public double optDouble(final int index, final double defaultValue) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
return getDouble(index);
|
return getDouble(index);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -449,8 +410,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public int optInt(final int index)
|
public int optInt(final int index) {
|
||||||
{
|
|
||||||
return this.optInt(index, 0);
|
return this.optInt(index, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,14 +423,10 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public int optInt(final int index, final int defaultValue)
|
public int optInt(final int index, final int defaultValue) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
return getInt(index);
|
return getInt(index);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -482,8 +438,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return A JSONArray value, or null if the index has no value, or if the value is not a JSONArray.
|
* @return A JSONArray value, or null if the index has no value, or if the value is not a JSONArray.
|
||||||
*/
|
*/
|
||||||
public JSONArray optJSONArray(final int index)
|
public JSONArray optJSONArray(final int index) {
|
||||||
{
|
|
||||||
final Object o = opt(index);
|
final Object o = opt(index);
|
||||||
return o instanceof JSONArray ? (JSONArray) o : null;
|
return o instanceof JSONArray ? (JSONArray) o : null;
|
||||||
}
|
}
|
||||||
@ -496,8 +451,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return A JSONObject value.
|
* @return A JSONObject value.
|
||||||
*/
|
*/
|
||||||
public JSONObject optJSONObject(final int index)
|
public JSONObject optJSONObject(final int index) {
|
||||||
{
|
|
||||||
final Object o = opt(index);
|
final Object o = opt(index);
|
||||||
return o instanceof JSONObject ? (JSONObject) o : null;
|
return o instanceof JSONObject ? (JSONObject) o : null;
|
||||||
}
|
}
|
||||||
@ -510,8 +464,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public long optLong(final int index)
|
public long optLong(final int index) {
|
||||||
{
|
|
||||||
return this.optLong(index, 0);
|
return this.optLong(index, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,14 +477,10 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public long optLong(final int index, final long defaultValue)
|
public long optLong(final int index, final long defaultValue) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
return getLong(index);
|
return getLong(index);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -544,8 +493,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return A String value.
|
* @return A String value.
|
||||||
*/
|
*/
|
||||||
public String optString(final int index)
|
public String optString(final int index) {
|
||||||
{
|
|
||||||
return this.optString(index, "");
|
return this.optString(index, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,8 +505,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return A String value.
|
* @return A String value.
|
||||||
*/
|
*/
|
||||||
public String optString(final int index, final String defaultValue)
|
public String optString(final int index, final String defaultValue) {
|
||||||
{
|
|
||||||
final Object object = opt(index);
|
final Object object = opt(index);
|
||||||
return JSONObject.NULL.equals(object) ? defaultValue : object.toString();
|
return JSONObject.NULL.equals(object) ? defaultValue : object.toString();
|
||||||
}
|
}
|
||||||
@ -570,8 +517,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final boolean value)
|
public JSONArray put(final boolean value) {
|
||||||
{
|
|
||||||
this.put(value ? Boolean.TRUE : Boolean.FALSE);
|
this.put(value ? Boolean.TRUE : Boolean.FALSE);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -583,8 +529,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final Collection<Object> value)
|
public JSONArray put(final Collection<Object> value) {
|
||||||
{
|
|
||||||
this.put(new JSONArray(value));
|
this.put(new JSONArray(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -598,8 +543,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException if the value is not finite.
|
* @throws JSONException if the value is not finite.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final double value) throws JSONException
|
public JSONArray put(final double value) throws JSONException {
|
||||||
{
|
|
||||||
final Double d = value;
|
final Double d = value;
|
||||||
JSONObject.testValidity(d);
|
JSONObject.testValidity(d);
|
||||||
this.put(d);
|
this.put(d);
|
||||||
@ -613,8 +557,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final int value)
|
public JSONArray put(final int value) {
|
||||||
{
|
|
||||||
this.put(new Integer(value));
|
this.put(new Integer(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -626,8 +569,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final long value)
|
public JSONArray put(final long value) {
|
||||||
{
|
|
||||||
this.put(new Long(value));
|
this.put(new Long(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -639,8 +581,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final Map<String, Object> value)
|
public JSONArray put(final Map<String, Object> value) {
|
||||||
{
|
|
||||||
this.put(new JSONObject(value));
|
this.put(new JSONObject(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -653,8 +594,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final Object value)
|
public JSONArray put(final Object value) {
|
||||||
{
|
|
||||||
myArrayList.add(value);
|
myArrayList.add(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -670,8 +610,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the index is negative.
|
* @throws JSONException If the index is negative.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final int index, final boolean value) throws JSONException
|
public JSONArray put(final int index, final boolean value) throws JSONException {
|
||||||
{
|
|
||||||
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
|
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -686,8 +625,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the index is negative or if the value is not finite.
|
* @throws JSONException If the index is negative or if the value is not finite.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final int index, final Collection<Object> value) throws JSONException
|
public JSONArray put(final int index, final Collection<Object> value) throws JSONException {
|
||||||
{
|
|
||||||
this.put(index, new JSONArray(value));
|
this.put(index, new JSONArray(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -703,8 +641,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the index is negative or if the value is not finite.
|
* @throws JSONException If the index is negative or if the value is not finite.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final int index, final double value) throws JSONException
|
public JSONArray put(final int index, final double value) throws JSONException {
|
||||||
{
|
|
||||||
this.put(index, new Double(value));
|
this.put(index, new Double(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -720,8 +657,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the index is negative.
|
* @throws JSONException If the index is negative.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final int index, final int value) throws JSONException
|
public JSONArray put(final int index, final int value) throws JSONException {
|
||||||
{
|
|
||||||
this.put(index, new Integer(value));
|
this.put(index, new Integer(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -737,8 +673,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the index is negative.
|
* @throws JSONException If the index is negative.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final int index, final long value) throws JSONException
|
public JSONArray put(final int index, final long value) throws JSONException {
|
||||||
{
|
|
||||||
this.put(index, new Long(value));
|
this.put(index, new Long(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -753,8 +688,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the index is negative or if the the value is an invalid number.
|
* @throws JSONException If the index is negative or if the the value is an invalid number.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final int index, final Map<String, Object> value) throws JSONException
|
public JSONArray put(final int index, final Map<String, Object> value) throws JSONException {
|
||||||
{
|
|
||||||
this.put(index, new JSONObject(value));
|
this.put(index, new JSONObject(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -771,18 +705,15 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the index is negative or if the the value is an invalid number.
|
* @throws JSONException If the index is negative or if the the value is an invalid number.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final int index, final Object value) throws JSONException
|
public JSONArray put(final int index, final Object value) throws JSONException {
|
||||||
{
|
|
||||||
JSONObject.testValidity(value);
|
JSONObject.testValidity(value);
|
||||||
if (index < 0) { throw new JSONException("JSONArray[" + index + "] not found."); }
|
if (index < 0) {
|
||||||
if (index < length())
|
throw new JSONException("JSONArray[" + index + "] not found.");
|
||||||
{
|
|
||||||
myArrayList.set(index, value);
|
|
||||||
}
|
}
|
||||||
else
|
if (index < length()) {
|
||||||
{
|
myArrayList.set(index, value);
|
||||||
while (index != length())
|
} else {
|
||||||
{
|
while (index != length()) {
|
||||||
this.put(JSONObject.NULL);
|
this.put(JSONObject.NULL);
|
||||||
}
|
}
|
||||||
this.put(value);
|
this.put(value);
|
||||||
@ -797,8 +728,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return The value that was associated with the index, or null if there was no value.
|
* @return The value that was associated with the index, or null if there was no value.
|
||||||
*/
|
*/
|
||||||
public Object remove(final int index)
|
public Object remove(final int index) {
|
||||||
{
|
|
||||||
return (index >= 0) && (index < length()) ? myArrayList.remove(index) : null;
|
return (index >= 0) && (index < length()) ? myArrayList.remove(index) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -809,24 +739,28 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @return true if they are equal
|
* @return true if they are equal
|
||||||
*/
|
*/
|
||||||
public boolean similar(final Object other)
|
public boolean similar(final Object other) {
|
||||||
{
|
if (!(other instanceof JSONArray)) {
|
||||||
if (!(other instanceof JSONArray)) { return false; }
|
return false;
|
||||||
|
}
|
||||||
final int len = length();
|
final int len = length();
|
||||||
if (len != ((JSONArray) other).length()) { return false; }
|
if (len != ((JSONArray) other).length()) {
|
||||||
for (int i = 0; i < len; i += 1)
|
return false;
|
||||||
{
|
}
|
||||||
|
for (int i = 0; i < len; i += 1) {
|
||||||
final Object valueThis = get(i);
|
final Object valueThis = get(i);
|
||||||
final Object valueOther = ((JSONArray) other).get(i);
|
final Object valueOther = ((JSONArray) other).get(i);
|
||||||
if (valueThis instanceof JSONObject)
|
if (valueThis instanceof JSONObject) {
|
||||||
{
|
if (!((JSONObject) valueThis).similar(valueOther)) {
|
||||||
if (!((JSONObject) valueThis).similar(valueOther)) { return false; }
|
return false;
|
||||||
}
|
}
|
||||||
else if (valueThis instanceof JSONArray)
|
} else if (valueThis instanceof JSONArray) {
|
||||||
{
|
if (!((JSONArray) valueThis).similar(valueOther)) {
|
||||||
if (!((JSONArray) valueThis).similar(valueOther)) { return false; }
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!valueThis.equals(valueOther)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else if (!valueThis.equals(valueOther)) { return false; }
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -840,12 +774,12 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException If any of the names are null.
|
* @throws JSONException If any of the names are null.
|
||||||
*/
|
*/
|
||||||
public JSONObject toJSONObject(final JSONArray names) throws JSONException
|
public JSONObject toJSONObject(final JSONArray names) throws JSONException {
|
||||||
{
|
if ((names == null) || (names.length() == 0) || (length() == 0)) {
|
||||||
if ((names == null) || (names.length() == 0) || (length() == 0)) { return null; }
|
return null;
|
||||||
|
}
|
||||||
final JSONObject jo = new JSONObject();
|
final JSONObject jo = new JSONObject();
|
||||||
for (int i = 0; i < names.length(); i += 1)
|
for (int i = 0; i < names.length(); i += 1) {
|
||||||
{
|
|
||||||
jo.put(names.getString(i), opt(i));
|
jo.put(names.getString(i), opt(i));
|
||||||
}
|
}
|
||||||
return jo;
|
return jo;
|
||||||
@ -861,14 +795,10 @@ public class JSONArray
|
|||||||
* @return a printable, displayable, transmittable representation of the array.
|
* @return a printable, displayable, transmittable representation of the array.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
return this.toString(0);
|
return this.toString(0);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -885,11 +815,9 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public String toString(final int indentFactor) throws JSONException
|
public String toString(final int indentFactor) throws JSONException {
|
||||||
{
|
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
synchronized (sw.getBuffer())
|
synchronized (sw.getBuffer()) {
|
||||||
{
|
|
||||||
return this.write(sw, indentFactor, 0).toString();
|
return this.write(sw, indentFactor, 0).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -903,8 +831,7 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -920,45 +847,34 @@ public class JSONArray
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
Writer write(final Writer writer, final int indentFactor, final int indent) throws JSONException
|
Writer write(final Writer writer, final int indentFactor, final int indent) throws JSONException {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
boolean commanate = false;
|
boolean commanate = false;
|
||||||
final int length = length();
|
final int length = length();
|
||||||
writer.write('[');
|
writer.write('[');
|
||||||
if (length == 1)
|
if (length == 1) {
|
||||||
{
|
|
||||||
JSONObject.writeValue(writer, myArrayList.get(0), indentFactor, indent);
|
JSONObject.writeValue(writer, 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(',');
|
||||||
}
|
}
|
||||||
if (indentFactor > 0)
|
if (indentFactor > 0) {
|
||||||
{
|
|
||||||
writer.write('\n');
|
writer.write('\n');
|
||||||
}
|
}
|
||||||
JSONObject.indent(writer, newindent);
|
JSONObject.indent(writer, newindent);
|
||||||
JSONObject.writeValue(writer, myArrayList.get(i), indentFactor, newindent);
|
JSONObject.writeValue(writer, myArrayList.get(i), indentFactor, newindent);
|
||||||
commanate = true;
|
commanate = true;
|
||||||
}
|
}
|
||||||
if (indentFactor > 0)
|
if (indentFactor > 0) {
|
||||||
{
|
|
||||||
writer.write('\n');
|
writer.write('\n');
|
||||||
}
|
}
|
||||||
JSONObject.indent(writer, indent);
|
JSONObject.indent(writer, indent);
|
||||||
}
|
}
|
||||||
writer.write(']');
|
writer.write(']');
|
||||||
return writer;
|
return writer;
|
||||||
}
|
} catch (final IOException e) {
|
||||||
catch (final IOException e)
|
|
||||||
{
|
|
||||||
throw new JSONException(e);
|
throw new JSONException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,7 @@ package com.intellectualcrafters.json;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @version 2014-05-03
|
* @version 2014-05-03
|
||||||
*/
|
*/
|
||||||
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;
|
||||||
|
|
||||||
@ -16,8 +15,7 @@ public class JSONException extends RuntimeException
|
|||||||
*
|
*
|
||||||
* @param message Detail about the reason for the exception.
|
* @param message Detail about the reason for the exception.
|
||||||
*/
|
*/
|
||||||
public JSONException(final String message)
|
public JSONException(final String message) {
|
||||||
{
|
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,8 +24,7 @@ public class JSONException extends RuntimeException
|
|||||||
*
|
*
|
||||||
* @param cause The cause.
|
* @param cause The cause.
|
||||||
*/
|
*/
|
||||||
public JSONException(final Throwable cause)
|
public JSONException(final Throwable cause) {
|
||||||
{
|
|
||||||
super(cause.getMessage());
|
super(cause.getMessage());
|
||||||
this.cause = cause;
|
this.cause = cause;
|
||||||
}
|
}
|
||||||
@ -38,8 +35,7 @@ public class JSONException extends RuntimeException
|
|||||||
* @return the cause of this exception or null if the cause is nonexistent or unknown.
|
* @return the cause of this exception or null if the cause is nonexistent or unknown.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Throwable getCause()
|
public Throwable getCause() {
|
||||||
{
|
|
||||||
return cause;
|
return cause;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,7 @@ import java.util.Iterator;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @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.
|
||||||
*
|
*
|
||||||
@ -22,8 +21,7 @@ public class JSONML
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
private static Object parse(final XMLTokener x, final boolean arrayForm, final JSONArray ja) throws JSONException
|
private static Object parse(final XMLTokener x, final boolean arrayForm, final JSONArray ja) throws JSONException {
|
||||||
{
|
|
||||||
String attribute;
|
String attribute;
|
||||||
char c;
|
char c;
|
||||||
String closeTag = null;
|
String closeTag = null;
|
||||||
@ -37,188 +35,149 @@ public class JSONML
|
|||||||
// <![ ... ]]>
|
// <![ ... ]]>
|
||||||
// <! ... >
|
// <! ... >
|
||||||
// <? ... ?>
|
// <? ... ?>
|
||||||
while (true)
|
while (true) {
|
||||||
{
|
if (!x.more()) {
|
||||||
if (!x.more()) { throw x.syntaxError("Bad XML"); }
|
throw x.syntaxError("Bad XML");
|
||||||
|
}
|
||||||
token = x.nextContent();
|
token = x.nextContent();
|
||||||
if (token == XML.LT)
|
if (token == XML.LT) {
|
||||||
{
|
|
||||||
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)) { throw new JSONException("Expected a closing name instead of '" + token + "'."); }
|
if (!(token instanceof String)) {
|
||||||
if (x.nextToken() != XML.GT) { throw x.syntaxError("Misshaped close tag"); }
|
throw new JSONException("Expected a closing name instead of '" + token + "'.");
|
||||||
return token;
|
|
||||||
}
|
}
|
||||||
else if (token == XML.BANG)
|
if (x.nextToken() != XML.GT) {
|
||||||
{
|
throw x.syntaxError("Misshaped close tag");
|
||||||
|
}
|
||||||
|
return token;
|
||||||
|
} else if (token == XML.BANG) {
|
||||||
// <!
|
// <!
|
||||||
c = x.next();
|
c = x.next();
|
||||||
if (c == '-')
|
if (c == '-') {
|
||||||
{
|
if (x.next() == '-') {
|
||||||
if (x.next() == '-')
|
|
||||||
{
|
|
||||||
x.skipPast("-->");
|
x.skipPast("-->");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
x.back();
|
x.back();
|
||||||
}
|
}
|
||||||
}
|
} else if (c == '[') {
|
||||||
else if (c == '[')
|
|
||||||
{
|
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
if (token.equals("CDATA") && (x.next() == '['))
|
if (token.equals("CDATA") && (x.next() == '[')) {
|
||||||
{
|
if (ja != null) {
|
||||||
if (ja != null)
|
|
||||||
{
|
|
||||||
ja.put(x.nextCDATA());
|
ja.put(x.nextCDATA());
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw x.syntaxError("Expected 'CDATA['");
|
throw x.syntaxError("Expected 'CDATA['");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
i = 1;
|
i = 1;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
token = x.nextMeta();
|
token = x.nextMeta();
|
||||||
if (token == null)
|
if (token == null) {
|
||||||
{
|
|
||||||
throw x.syntaxError("Missing '>' after '<!'.");
|
throw x.syntaxError("Missing '>' after '<!'.");
|
||||||
}
|
} else if (token == XML.LT) {
|
||||||
else if (token == XML.LT)
|
|
||||||
{
|
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
} else if (token == XML.GT) {
|
||||||
else if (token == XML.GT)
|
|
||||||
{
|
|
||||||
i -= 1;
|
i -= 1;
|
||||||
}
|
}
|
||||||
|
} while (i > 0);
|
||||||
}
|
}
|
||||||
while (i > 0);
|
} else if (token == XML.QUEST) {
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (token == XML.QUEST)
|
|
||||||
{
|
|
||||||
// <?
|
// <?
|
||||||
x.skipPast("?>");
|
x.skipPast("?>");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw x.syntaxError("Misshaped tag");
|
throw x.syntaxError("Misshaped tag");
|
||||||
}
|
}
|
||||||
// Open tag <
|
// Open tag <
|
||||||
|
} else {
|
||||||
|
if (!(token instanceof String)) {
|
||||||
|
throw x.syntaxError("Bad tagName '" + token + "'.");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!(token instanceof String)) { throw x.syntaxError("Bad tagName '" + token + "'."); }
|
|
||||||
tagName = (String) token;
|
tagName = (String) token;
|
||||||
newja = new JSONArray();
|
newja = new JSONArray();
|
||||||
newjo = new JSONObject();
|
newjo = new JSONObject();
|
||||||
if (arrayForm)
|
if (arrayForm) {
|
||||||
{
|
|
||||||
newja.put(tagName);
|
newja.put(tagName);
|
||||||
if (ja != null)
|
if (ja != null) {
|
||||||
{
|
|
||||||
ja.put(newja);
|
ja.put(newja);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
newjo.put("tagName", tagName);
|
newjo.put("tagName", tagName);
|
||||||
if (ja != null)
|
if (ja != null) {
|
||||||
{
|
|
||||||
ja.put(newjo);
|
ja.put(newjo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
token = null;
|
token = null;
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
if (token == null) {
|
||||||
if (token == null)
|
|
||||||
{
|
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
}
|
}
|
||||||
if (token == null) { throw x.syntaxError("Misshaped tag"); }
|
if (token == null) {
|
||||||
if (!(token instanceof String))
|
throw x.syntaxError("Misshaped tag");
|
||||||
{
|
}
|
||||||
|
if (!(token instanceof String)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// attribute = value
|
// attribute = value
|
||||||
attribute = (String) token;
|
attribute = (String) token;
|
||||||
if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) { throw x.syntaxError("Reserved attribute."); }
|
if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) {
|
||||||
|
throw x.syntaxError("Reserved attribute.");
|
||||||
|
}
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
if (token == XML.EQ)
|
if (token == XML.EQ) {
|
||||||
{
|
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
if (!(token instanceof String)) { throw x.syntaxError("Missing value"); }
|
if (!(token instanceof String)) {
|
||||||
|
throw x.syntaxError("Missing value");
|
||||||
|
}
|
||||||
newjo.accumulate(attribute, XML.stringToValue((String) token));
|
newjo.accumulate(attribute, XML.stringToValue((String) token));
|
||||||
token = null;
|
token = null;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
newjo.accumulate(attribute, "");
|
newjo.accumulate(attribute, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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");
|
||||||
if (ja == null)
|
|
||||||
{
|
|
||||||
if (arrayForm)
|
|
||||||
{
|
|
||||||
return newja;
|
|
||||||
}
|
}
|
||||||
else
|
if (ja == null) {
|
||||||
{
|
if (arrayForm) {
|
||||||
|
return newja;
|
||||||
|
} else {
|
||||||
return newjo;
|
return newjo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Content, between <...> and </...>
|
// Content, between <...> and </...>
|
||||||
|
} else {
|
||||||
|
if (token != XML.GT) {
|
||||||
|
throw x.syntaxError("Misshaped tag");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (token != XML.GT) { throw x.syntaxError("Misshaped tag"); }
|
|
||||||
closeTag = (String) parse(x, arrayForm, newja);
|
closeTag = (String) parse(x, arrayForm, newja);
|
||||||
if (closeTag != null)
|
if (closeTag != null) {
|
||||||
{
|
if (!closeTag.equals(tagName)) {
|
||||||
if (!closeTag.equals(tagName)) { throw x.syntaxError("Mismatched '" + tagName + "' and '" + closeTag + "'"); }
|
throw x.syntaxError("Mismatched '" + tagName + "' and '" + closeTag + "'");
|
||||||
|
}
|
||||||
tagName = null;
|
tagName = null;
|
||||||
if (!arrayForm && (newja.length() > 0))
|
if (!arrayForm && (newja.length() > 0)) {
|
||||||
{
|
|
||||||
newjo.put("childNodes", newja);
|
newjo.put("childNodes", newja);
|
||||||
}
|
}
|
||||||
if (ja == null)
|
if (ja == null) {
|
||||||
{
|
if (arrayForm) {
|
||||||
if (arrayForm)
|
|
||||||
{
|
|
||||||
return newja;
|
return newja;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return newjo;
|
return newjo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if (ja != null) {
|
||||||
{
|
|
||||||
if (ja != null)
|
|
||||||
{
|
|
||||||
ja.put(token instanceof String ? XML.stringToValue((String) token) : token);
|
ja.put(token instanceof String ? XML.stringToValue((String) token) : token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,8 +195,7 @@ public class JSONML
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,8 +212,7 @@ public class JSONML
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,8 +230,7 @@ public class JSONML
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,8 +248,7 @@ public class JSONML
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,8 +261,7 @@ public class JSONML
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static String toString(final JSONArray ja) throws JSONException
|
public static String toString(final JSONArray ja) throws JSONException {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
JSONObject jo;
|
JSONObject jo;
|
||||||
String key;
|
String key;
|
||||||
@ -324,19 +278,16 @@ public class JSONML
|
|||||||
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();
|
||||||
XML.noSpace(key);
|
XML.noSpace(key);
|
||||||
value = jo.optString(key);
|
value = jo.optString(key);
|
||||||
if (value != null)
|
if (value != null) {
|
||||||
{
|
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
sb.append(XML.escape(key));
|
sb.append(XML.escape(key));
|
||||||
sb.append('=');
|
sb.append('=');
|
||||||
@ -345,42 +296,29 @@ public class JSONML
|
|||||||
sb.append('"');
|
sb.append('"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} 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('/');
|
||||||
sb.append('>');
|
sb.append('>');
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.append('>');
|
sb.append('>');
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
object = ja.get(i);
|
object = ja.get(i);
|
||||||
i += 1;
|
i += 1;
|
||||||
if (object != null)
|
if (object != null) {
|
||||||
{
|
if (object instanceof String) {
|
||||||
if (object instanceof String)
|
|
||||||
{
|
|
||||||
sb.append(XML.escape(object.toString()));
|
sb.append(XML.escape(object.toString()));
|
||||||
}
|
} else if (object instanceof JSONObject) {
|
||||||
else if (object instanceof JSONObject)
|
|
||||||
{
|
|
||||||
sb.append(toString((JSONObject) object));
|
sb.append(toString((JSONObject) object));
|
||||||
}
|
} else if (object instanceof JSONArray) {
|
||||||
else if (object instanceof JSONArray)
|
|
||||||
{
|
|
||||||
sb.append(toString((JSONArray) object));
|
sb.append(toString((JSONArray) object));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} while (i < length);
|
||||||
while (i < length);
|
|
||||||
sb.append('<');
|
sb.append('<');
|
||||||
sb.append('/');
|
sb.append('/');
|
||||||
sb.append(tagName);
|
sb.append(tagName);
|
||||||
@ -400,8 +338,7 @@ public class JSONML
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
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();
|
||||||
int i;
|
int i;
|
||||||
JSONArray ja;
|
JSONArray ja;
|
||||||
@ -413,22 +350,21 @@ public class JSONML
|
|||||||
String value;
|
String value;
|
||||||
// Emit <tagName
|
// Emit <tagName
|
||||||
tagName = jo.optString("tagName");
|
tagName = jo.optString("tagName");
|
||||||
if (tagName == null) { return XML.escape(jo.toString()); }
|
if (tagName == null) {
|
||||||
|
return XML.escape(jo.toString());
|
||||||
|
}
|
||||||
XML.noSpace(tagName);
|
XML.noSpace(tagName);
|
||||||
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();
|
||||||
if (!"tagName".equals(key) && !"childNodes".equals(key))
|
if (!"tagName".equals(key) && !"childNodes".equals(key)) {
|
||||||
{
|
|
||||||
XML.noSpace(key);
|
XML.noSpace(key);
|
||||||
value = jo.optString(key);
|
value = jo.optString(key);
|
||||||
if (value != null)
|
if (value != null) {
|
||||||
{
|
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
sb.append(XML.escape(key));
|
sb.append(XML.escape(key));
|
||||||
sb.append('=');
|
sb.append('=');
|
||||||
@ -440,34 +376,22 @@ 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('/');
|
||||||
sb.append('>');
|
sb.append('>');
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.append('>');
|
sb.append('>');
|
||||||
length = ja.length();
|
length = ja.length();
|
||||||
for (i = 0; i < length; i += 1)
|
for (i = 0; i < length; i += 1) {
|
||||||
{
|
|
||||||
object = ja.get(i);
|
object = ja.get(i);
|
||||||
if (object != null)
|
if (object != null) {
|
||||||
{
|
if (object instanceof String) {
|
||||||
if (object instanceof String)
|
|
||||||
{
|
|
||||||
sb.append(XML.escape(object.toString()));
|
sb.append(XML.escape(object.toString()));
|
||||||
}
|
} else if (object instanceof JSONObject) {
|
||||||
else if (object instanceof JSONObject)
|
|
||||||
{
|
|
||||||
sb.append(toString((JSONObject) object));
|
sb.append(toString((JSONObject) object));
|
||||||
}
|
} else if (object instanceof JSONArray) {
|
||||||
else if (object instanceof JSONArray)
|
|
||||||
{
|
|
||||||
sb.append(toString((JSONArray) object));
|
sb.append(toString((JSONArray) object));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.append(object.toString());
|
sb.append(object.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -6,8 +6,7 @@ package com.intellectualcrafters.json;
|
|||||||
* <code>JSONWriter.value(</code>Object<code>)</code>. The <code>toJSONString</code> method will be used instead of the
|
* <code>JSONWriter.value(</code>Object<code>)</code>. The <code>toJSONString</code> method will be used instead of the
|
||||||
* default behavior of using the Object's <code>toString()</code> method and quoting the result.
|
* default behavior of using the Object's <code>toString()</code> method and quoting the result.
|
||||||
*/
|
*/
|
||||||
public interface JSONString
|
public interface JSONString {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* The <code>toJSONString</code> method allows a class to produce its own JSON serialization.
|
* The <code>toJSONString</code> method allows a class to produce its own JSON serialization.
|
||||||
*
|
*
|
||||||
|
@ -33,13 +33,11 @@ import java.io.StringWriter;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @version 2008-09-18
|
* @version 2008-09-18
|
||||||
*/
|
*/
|
||||||
public class JSONStringer extends JSONWriter
|
public class JSONStringer extends JSONWriter {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Make a fresh JSONStringer. It can be used to build one JSON text.
|
* Make a fresh JSONStringer. It can be used to build one JSON text.
|
||||||
*/
|
*/
|
||||||
public JSONStringer()
|
public JSONStringer() {
|
||||||
{
|
|
||||||
super(new StringWriter());
|
super(new StringWriter());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,8 +49,7 @@ public class JSONStringer extends JSONWriter
|
|||||||
* @return The JSON text.
|
* @return The JSON text.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
return mode == 'd' ? writer.toString() : null;
|
return mode == 'd' ? writer.toString() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,7 @@ import java.io.StringReader;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @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;
|
||||||
@ -29,8 +28,7 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @param reader A reader.
|
* @param reader A reader.
|
||||||
*/
|
*/
|
||||||
public JSONTokener(final Reader reader)
|
public JSONTokener(final Reader reader) {
|
||||||
{
|
|
||||||
this.reader = reader.markSupported() ? reader : new BufferedReader(reader);
|
this.reader = reader.markSupported() ? reader : new BufferedReader(reader);
|
||||||
eof = false;
|
eof = false;
|
||||||
usePrevious = false;
|
usePrevious = false;
|
||||||
@ -45,8 +43,7 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @param inputStream The source.
|
* @param inputStream The source.
|
||||||
*/
|
*/
|
||||||
public JSONTokener(final InputStream inputStream) throws JSONException
|
public JSONTokener(final InputStream inputStream) throws JSONException {
|
||||||
{
|
|
||||||
this(new InputStreamReader(inputStream));
|
this(new InputStreamReader(inputStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +52,7 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @param s A source string.
|
* @param s A source string.
|
||||||
*/
|
*/
|
||||||
public JSONTokener(final String s)
|
public JSONTokener(final String s) {
|
||||||
{
|
|
||||||
this(new StringReader(s));
|
this(new StringReader(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,11 +63,16 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @return An int between 0 and 15, or -1 if c was not a hex digit.
|
* @return An int between 0 and 15, or -1 if c was not a hex digit.
|
||||||
*/
|
*/
|
||||||
public static int dehexchar(final char c)
|
public static int dehexchar(final char c) {
|
||||||
{
|
if ((c >= '0') && (c <= '9')) {
|
||||||
if ((c >= '0') && (c <= '9')) { return c - '0'; }
|
return c - '0';
|
||||||
if ((c >= 'A') && (c <= 'F')) { return c - ('A' - 10); }
|
}
|
||||||
if ((c >= 'a') && (c <= 'f')) { return c - ('a' - 10); }
|
if ((c >= 'A') && (c <= 'F')) {
|
||||||
|
return c - ('A' - 10);
|
||||||
|
}
|
||||||
|
if ((c >= 'a') && (c <= 'f')) {
|
||||||
|
return c - ('a' - 10);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,17 +80,17 @@ public class JSONTokener
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
public void back() throws JSONException
|
public void back() throws JSONException {
|
||||||
{
|
if (usePrevious || (index <= 0)) {
|
||||||
if (usePrevious || (index <= 0)) { throw new JSONException("Stepping back two steps is not supported"); }
|
throw new JSONException("Stepping back two steps is not supported");
|
||||||
|
}
|
||||||
index -= 1;
|
index -= 1;
|
||||||
character -= 1;
|
character -= 1;
|
||||||
usePrevious = true;
|
usePrevious = true;
|
||||||
eof = false;
|
eof = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean end()
|
public boolean end() {
|
||||||
{
|
|
||||||
return eof && !usePrevious;
|
return eof && !usePrevious;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,10 +99,11 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @return true if not yet at the end of the source.
|
* @return true if not yet at the end of the source.
|
||||||
*/
|
*/
|
||||||
public boolean more() throws JSONException
|
public boolean more() throws JSONException {
|
||||||
{
|
|
||||||
this.next();
|
this.next();
|
||||||
if (end()) { return false; }
|
if (end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
back();
|
back();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -111,43 +113,30 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @return The next character, or 0 if past the end of the source string.
|
* @return The next character, or 0 if past the end of the source string.
|
||||||
*/
|
*/
|
||||||
public char next() throws JSONException
|
public char next() throws JSONException {
|
||||||
{
|
|
||||||
int c;
|
int c;
|
||||||
if (usePrevious)
|
if (usePrevious) {
|
||||||
{
|
|
||||||
usePrevious = false;
|
usePrevious = false;
|
||||||
c = previous;
|
c = previous;
|
||||||
}
|
} else {
|
||||||
else
|
try {
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
c = reader.read();
|
c = reader.read();
|
||||||
}
|
} catch (final IOException exception) {
|
||||||
catch (final IOException exception)
|
|
||||||
{
|
|
||||||
throw new JSONException(exception);
|
throw new JSONException(exception);
|
||||||
}
|
}
|
||||||
if (c <= 0)
|
if (c <= 0) { // End of stream
|
||||||
{ // End of stream
|
|
||||||
eof = true;
|
eof = true;
|
||||||
c = 0;
|
c = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
index += 1;
|
index += 1;
|
||||||
if (previous == '\r')
|
if (previous == '\r') {
|
||||||
{
|
|
||||||
line += 1;
|
line += 1;
|
||||||
character = c == '\n' ? 0 : 1;
|
character = c == '\n' ? 0 : 1;
|
||||||
}
|
} else if (c == '\n') {
|
||||||
else if (c == '\n')
|
|
||||||
{
|
|
||||||
line += 1;
|
line += 1;
|
||||||
character = 0;
|
character = 0;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
character += 1;
|
character += 1;
|
||||||
}
|
}
|
||||||
previous = (char) c;
|
previous = (char) c;
|
||||||
@ -163,10 +152,11 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @throws JSONException if the character does not match.
|
* @throws JSONException if the character does not match.
|
||||||
*/
|
*/
|
||||||
public char next(final char c) throws JSONException
|
public char next(final char c) throws JSONException {
|
||||||
{
|
|
||||||
final char n = this.next();
|
final char n = this.next();
|
||||||
if (n != c) { throw syntaxError("Expected '" + c + "' and instead saw '" + n + "'"); }
|
if (n != c) {
|
||||||
|
throw syntaxError("Expected '" + c + "' and instead saw '" + n + "'");
|
||||||
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,15 +169,17 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @throws JSONException Substring bounds error if there are not n characters remaining in the source string.
|
* @throws JSONException Substring bounds error if there are not n characters remaining in the source string.
|
||||||
*/
|
*/
|
||||||
public String next(final int n) throws JSONException
|
public String next(final int n) throws JSONException {
|
||||||
{
|
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 (end()) { throw syntaxError("Substring bounds error"); }
|
if (end()) {
|
||||||
|
throw syntaxError("Substring bounds error");
|
||||||
|
}
|
||||||
pos += 1;
|
pos += 1;
|
||||||
}
|
}
|
||||||
return new String(chars);
|
return new String(chars);
|
||||||
@ -200,12 +192,12 @@ 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 > ' ')) { return c; }
|
if ((c == 0) || (c > ' ')) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,23 +212,19 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @throws JSONException Unterminated string.
|
* @throws JSONException Unterminated string.
|
||||||
*/
|
*/
|
||||||
public String nextString(final char quote) throws JSONException
|
public String nextString(final char quote) throws JSONException {
|
||||||
{
|
|
||||||
char c;
|
char c;
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
c = this.next();
|
c = this.next();
|
||||||
switch (c)
|
switch (c) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
case '\n':
|
case '\n':
|
||||||
case '\r':
|
case '\r':
|
||||||
throw syntaxError("Unterminated string");
|
throw syntaxError("Unterminated string");
|
||||||
case '\\':
|
case '\\':
|
||||||
c = this.next();
|
c = this.next();
|
||||||
switch (c)
|
switch (c) {
|
||||||
{
|
|
||||||
case 'b':
|
case 'b':
|
||||||
sb.append('\b');
|
sb.append('\b');
|
||||||
break;
|
break;
|
||||||
@ -266,7 +254,9 @@ public class JSONTokener
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (c == quote) { return sb.toString(); }
|
if (c == quote) {
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -279,16 +269,12 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @return A string.
|
* @return A string.
|
||||||
*/
|
*/
|
||||||
public String nextTo(final char delimiter) throws JSONException
|
public String nextTo(final char delimiter) throws JSONException {
|
||||||
{
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
final char c = this.next();
|
final char c = this.next();
|
||||||
if ((c == delimiter) || (c == 0) || (c == '\n') || (c == '\r'))
|
if ((c == delimiter) || (c == 0) || (c == '\n') || (c == '\r')) {
|
||||||
{
|
if (c != 0) {
|
||||||
if (c != 0)
|
|
||||||
{
|
|
||||||
back();
|
back();
|
||||||
}
|
}
|
||||||
return sb.toString().trim();
|
return sb.toString().trim();
|
||||||
@ -305,17 +291,13 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @return A string, trimmed.
|
* @return A string, trimmed.
|
||||||
*/
|
*/
|
||||||
public String nextTo(final String delimiters) throws JSONException
|
public String nextTo(final String delimiters) throws JSONException {
|
||||||
{
|
|
||||||
char c;
|
char c;
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
c = this.next();
|
c = this.next();
|
||||||
if ((delimiters.indexOf(c) >= 0) || (c == 0) || (c == '\n') || (c == '\r'))
|
if ((delimiters.indexOf(c) >= 0) || (c == 0) || (c == '\n') || (c == '\r')) {
|
||||||
{
|
if (c != 0) {
|
||||||
if (c != 0)
|
|
||||||
{
|
|
||||||
back();
|
back();
|
||||||
}
|
}
|
||||||
return sb.toString().trim();
|
return sb.toString().trim();
|
||||||
@ -332,12 +314,10 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @throws JSONException If syntax error.
|
* @throws JSONException If syntax error.
|
||||||
*/
|
*/
|
||||||
public Object nextValue() throws JSONException
|
public Object nextValue() throws JSONException {
|
||||||
{
|
|
||||||
char c = nextClean();
|
char c = nextClean();
|
||||||
String string;
|
String string;
|
||||||
switch (c)
|
switch (c) {
|
||||||
{
|
|
||||||
case '"':
|
case '"':
|
||||||
case '\'':
|
case '\'':
|
||||||
return nextString(c);
|
return nextString(c);
|
||||||
@ -356,14 +336,15 @@ public class JSONTokener
|
|||||||
* 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();
|
||||||
}
|
}
|
||||||
back();
|
back();
|
||||||
string = sb.toString().trim();
|
string = sb.toString().trim();
|
||||||
if ("".equals(string)) { throw syntaxError("Missing value"); }
|
if ("".equals(string)) {
|
||||||
|
throw syntaxError("Missing value");
|
||||||
|
}
|
||||||
return JSONObject.stringToValue(string);
|
return JSONObject.stringToValue(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,31 +356,24 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @return The requested character, or zero if the requested character is not found.
|
* @return The requested character, or zero if the requested character is not found.
|
||||||
*/
|
*/
|
||||||
public char skipTo(final char to) throws JSONException
|
public char skipTo(final char to) throws JSONException {
|
||||||
{
|
|
||||||
char c;
|
char c;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
final long startIndex = index;
|
final long startIndex = index;
|
||||||
final long startCharacter = character;
|
final long startCharacter = character;
|
||||||
final long startLine = line;
|
final long startLine = line;
|
||||||
reader.mark(1000000);
|
reader.mark(1000000);
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
c = this.next();
|
c = this.next();
|
||||||
if (c == 0)
|
if (c == 0) {
|
||||||
{
|
|
||||||
reader.reset();
|
reader.reset();
|
||||||
index = startIndex;
|
index = startIndex;
|
||||||
character = startCharacter;
|
character = startCharacter;
|
||||||
line = startLine;
|
line = startLine;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
} while (c != to);
|
||||||
while (c != to);
|
} catch (final IOException exception) {
|
||||||
}
|
|
||||||
catch (final IOException exception)
|
|
||||||
{
|
|
||||||
throw new JSONException(exception);
|
throw new JSONException(exception);
|
||||||
}
|
}
|
||||||
back();
|
back();
|
||||||
@ -413,8 +387,7 @@ public class JSONTokener
|
|||||||
*
|
*
|
||||||
* @return A JSONException object, suitable for throwing
|
* @return A JSONException object, suitable for throwing
|
||||||
*/
|
*/
|
||||||
public JSONException syntaxError(final String message)
|
public JSONException syntaxError(final String message) {
|
||||||
{
|
|
||||||
return new JSONException(message + toString());
|
return new JSONException(message + toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,8 +397,7 @@ public class JSONTokener
|
|||||||
* @return " at {index} [character {character} line {line}]"
|
* @return " at {index} [character {character} line {line}]"
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
return " at " + index + " [character " + character + " line " + line + "]";
|
return " at " + index + " [character " + character + " line " + line + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,7 @@ import java.io.Writer;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @version 2011-11-24
|
* @version 2011-11-24
|
||||||
*/
|
*/
|
||||||
public class JSONWriter
|
public class JSONWriter {
|
||||||
{
|
|
||||||
private static final int maxdepth = 200;
|
private static final int maxdepth = 200;
|
||||||
/**
|
/**
|
||||||
* The writer that will receive the output.
|
* The writer that will receive the output.
|
||||||
@ -60,8 +59,7 @@ public class JSONWriter
|
|||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
public JSONWriter(final Writer w)
|
public JSONWriter(final Writer w) {
|
||||||
{
|
|
||||||
comma = false;
|
comma = false;
|
||||||
mode = 'i';
|
mode = 'i';
|
||||||
stack = new JSONObject[maxdepth];
|
stack = new JSONObject[maxdepth];
|
||||||
@ -78,25 +76,20 @@ public class JSONWriter
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the value is out of sequence.
|
* @throws JSONException If the value is out of sequence.
|
||||||
*/
|
*/
|
||||||
private JSONWriter append(final String string) throws JSONException
|
private JSONWriter append(final String string) throws JSONException {
|
||||||
{
|
if (string == null) {
|
||||||
if (string == null) { throw new JSONException("Null pointer"); }
|
throw new JSONException("Null pointer");
|
||||||
if ((mode == 'o') || (mode == 'a'))
|
}
|
||||||
{
|
if ((mode == 'o') || (mode == 'a')) {
|
||||||
try
|
try {
|
||||||
{
|
if (comma && (mode == 'a')) {
|
||||||
if (comma && (mode == 'a'))
|
|
||||||
{
|
|
||||||
writer.write(',');
|
writer.write(',');
|
||||||
}
|
}
|
||||||
writer.write(string);
|
writer.write(string);
|
||||||
}
|
} catch (final IOException e) {
|
||||||
catch (final IOException e)
|
|
||||||
{
|
|
||||||
throw new JSONException(e);
|
throw new JSONException(e);
|
||||||
}
|
}
|
||||||
if (mode == 'o')
|
if (mode == 'o') {
|
||||||
{
|
|
||||||
mode = 'k';
|
mode = 'k';
|
||||||
}
|
}
|
||||||
comma = true;
|
comma = true;
|
||||||
@ -114,10 +107,8 @@ public class JSONWriter
|
|||||||
* @throws JSONException If the nesting is too deep, or if the object is started in the wrong place (for example as
|
* @throws JSONException If the nesting is too deep, or if the object is started in the wrong place (for example as
|
||||||
* a key or after the end of the outermost array or object).
|
* a key or after the end of the outermost array or object).
|
||||||
*/
|
*/
|
||||||
public JSONWriter array() throws JSONException
|
public JSONWriter array() throws JSONException {
|
||||||
{
|
if ((mode == 'i') || (mode == 'o') || (mode == 'a')) {
|
||||||
if ((mode == 'i') || (mode == 'o') || (mode == 'a'))
|
|
||||||
{
|
|
||||||
push(null);
|
push(null);
|
||||||
append("[");
|
append("[");
|
||||||
comma = false;
|
comma = false;
|
||||||
@ -136,16 +127,14 @@ public class JSONWriter
|
|||||||
*
|
*
|
||||||
* @throws JSONException If unbalanced.
|
* @throws JSONException If unbalanced.
|
||||||
*/
|
*/
|
||||||
private JSONWriter end(final char mode, final char c) throws JSONException
|
private JSONWriter end(final char mode, final char c) throws JSONException {
|
||||||
{
|
if (this.mode != mode) {
|
||||||
if (this.mode != mode) { throw new JSONException(mode == 'a' ? "Misplaced endArray." : "Misplaced endObject."); }
|
throw new JSONException(mode == 'a' ? "Misplaced endArray." : "Misplaced endObject.");
|
||||||
pop(mode);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
writer.write(c);
|
|
||||||
}
|
}
|
||||||
catch (final IOException e)
|
pop(mode);
|
||||||
{
|
try {
|
||||||
|
writer.write(c);
|
||||||
|
} catch (final IOException e) {
|
||||||
throw new JSONException(e);
|
throw new JSONException(e);
|
||||||
}
|
}
|
||||||
comma = true;
|
comma = true;
|
||||||
@ -159,8 +148,7 @@ public class JSONWriter
|
|||||||
*
|
*
|
||||||
* @throws JSONException If incorrectly nested.
|
* @throws JSONException If incorrectly nested.
|
||||||
*/
|
*/
|
||||||
public JSONWriter endArray() throws JSONException
|
public JSONWriter endArray() throws JSONException {
|
||||||
{
|
|
||||||
return end('a', ']');
|
return end('a', ']');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,8 +159,7 @@ public class JSONWriter
|
|||||||
*
|
*
|
||||||
* @throws JSONException If incorrectly nested.
|
* @throws JSONException If incorrectly nested.
|
||||||
*/
|
*/
|
||||||
public JSONWriter endObject() throws JSONException
|
public JSONWriter endObject() throws JSONException {
|
||||||
{
|
|
||||||
return end('k', '}');
|
return end('k', '}');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,16 +174,14 @@ public class JSONWriter
|
|||||||
* @throws JSONException If the key is out of place. For example, keys do not belong in arrays or if the key is
|
* @throws JSONException If the key is out of place. For example, keys do not belong in arrays or if the key is
|
||||||
* null.
|
* null.
|
||||||
*/
|
*/
|
||||||
public JSONWriter key(final String string) throws JSONException
|
public JSONWriter key(final String string) throws JSONException {
|
||||||
{
|
if (string == null) {
|
||||||
if (string == null) { throw new JSONException("Null key."); }
|
throw new JSONException("Null key.");
|
||||||
if (mode == 'k')
|
}
|
||||||
{
|
if (mode == 'k') {
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
stack[top - 1].putOnce(string, Boolean.TRUE);
|
stack[top - 1].putOnce(string, Boolean.TRUE);
|
||||||
if (comma)
|
if (comma) {
|
||||||
{
|
|
||||||
writer.write(',');
|
writer.write(',');
|
||||||
}
|
}
|
||||||
writer.write(JSONObject.quote(string));
|
writer.write(JSONObject.quote(string));
|
||||||
@ -204,9 +189,7 @@ public class JSONWriter
|
|||||||
comma = false;
|
comma = false;
|
||||||
mode = 'o';
|
mode = 'o';
|
||||||
return this;
|
return this;
|
||||||
}
|
} catch (final IOException e) {
|
||||||
catch (final IOException e)
|
|
||||||
{
|
|
||||||
throw new JSONException(e);
|
throw new JSONException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,14 +205,11 @@ public class JSONWriter
|
|||||||
* @throws JSONException If the nesting is too deep, or if the object is started in the wrong place (for example as
|
* @throws JSONException If the nesting is too deep, or if the object is started in the wrong place (for example as
|
||||||
* a key or after the end of the outermost array or object).
|
* a key or after the end of the outermost array or object).
|
||||||
*/
|
*/
|
||||||
public JSONWriter object() throws JSONException
|
public JSONWriter object() throws JSONException {
|
||||||
{
|
if (mode == 'i') {
|
||||||
if (mode == 'i')
|
|
||||||
{
|
|
||||||
mode = 'o';
|
mode = 'o';
|
||||||
}
|
}
|
||||||
if ((mode == 'o') || (mode == 'a'))
|
if ((mode == 'o') || (mode == 'a')) {
|
||||||
{
|
|
||||||
append("{");
|
append("{");
|
||||||
push(new JSONObject());
|
push(new JSONObject());
|
||||||
comma = false;
|
comma = false;
|
||||||
@ -245,11 +225,14 @@ public class JSONWriter
|
|||||||
*
|
*
|
||||||
* @throws JSONException If nesting is wrong.
|
* @throws JSONException If nesting is wrong.
|
||||||
*/
|
*/
|
||||||
private void pop(final char c) throws JSONException
|
private void pop(final char c) throws JSONException {
|
||||||
{
|
if (top <= 0) {
|
||||||
if (top <= 0) { throw new JSONException("Nesting error."); }
|
throw new JSONException("Nesting error.");
|
||||||
|
}
|
||||||
final char m = stack[top - 1] == null ? 'a' : 'k';
|
final char m = stack[top - 1] == null ? 'a' : 'k';
|
||||||
if (m != c) { throw new JSONException("Nesting error."); }
|
if (m != c) {
|
||||||
|
throw new JSONException("Nesting error.");
|
||||||
|
}
|
||||||
top -= 1;
|
top -= 1;
|
||||||
mode = top == 0 ? 'd' : stack[top - 1] == null ? 'a' : 'k';
|
mode = top == 0 ? 'd' : stack[top - 1] == null ? 'a' : 'k';
|
||||||
}
|
}
|
||||||
@ -261,9 +244,10 @@ public class JSONWriter
|
|||||||
*
|
*
|
||||||
* @throws JSONException If nesting is too deep.
|
* @throws JSONException If nesting is too deep.
|
||||||
*/
|
*/
|
||||||
private void push(final JSONObject jo) throws JSONException
|
private void push(final JSONObject jo) throws JSONException {
|
||||||
{
|
if (top >= maxdepth) {
|
||||||
if (top >= maxdepth) { throw new JSONException("Nesting too deep."); }
|
throw new JSONException("Nesting too deep.");
|
||||||
|
}
|
||||||
stack[top] = jo;
|
stack[top] = jo;
|
||||||
mode = jo == null ? 'a' : 'k';
|
mode = jo == null ? 'a' : 'k';
|
||||||
top += 1;
|
top += 1;
|
||||||
@ -278,8 +262,7 @@ public class JSONWriter
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public JSONWriter value(final boolean b) throws JSONException
|
public JSONWriter value(final boolean b) throws JSONException {
|
||||||
{
|
|
||||||
return append(b ? "true" : "false");
|
return append(b ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,8 +275,7 @@ public class JSONWriter
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the number is not finite.
|
* @throws JSONException If the number is not finite.
|
||||||
*/
|
*/
|
||||||
public JSONWriter value(final double d) throws JSONException
|
public JSONWriter value(final double d) throws JSONException {
|
||||||
{
|
|
||||||
return this.value(new Double(d));
|
return this.value(new Double(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,8 +288,7 @@ public class JSONWriter
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public JSONWriter value(final long l) throws JSONException
|
public JSONWriter value(final long l) throws JSONException {
|
||||||
{
|
|
||||||
return append(Long.toString(l));
|
return append(Long.toString(l));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,8 +302,7 @@ public class JSONWriter
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the value is out of sequence.
|
* @throws JSONException If the value is out of sequence.
|
||||||
*/
|
*/
|
||||||
public JSONWriter value(final Object object) throws JSONException
|
public JSONWriter value(final Object object) throws JSONException {
|
||||||
{
|
|
||||||
return append(JSONObject.valueToString(object));
|
return append(JSONObject.valueToString(object));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,7 @@ 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.
|
||||||
*/
|
*/
|
||||||
@ -52,8 +51,7 @@ public class Kim
|
|||||||
* @param from The index of the first byte.
|
* @param from The index of the first byte.
|
||||||
* @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.
|
||||||
@ -61,11 +59,9 @@ public class Kim
|
|||||||
int value;
|
int value;
|
||||||
hashcode = 0;
|
hashcode = 0;
|
||||||
length = thru - from;
|
length = thru - from;
|
||||||
if (length > 0)
|
if (length > 0) {
|
||||||
{
|
|
||||||
this.bytes = new byte[length];
|
this.bytes = new byte[length];
|
||||||
for (int at = 0; at < length; at += 1)
|
for (int at = 0; at < length; at += 1) {
|
||||||
{
|
|
||||||
value = bytes[at + from] & 0xFF;
|
value = bytes[at + from] & 0xFF;
|
||||||
sum += value;
|
sum += value;
|
||||||
hashcode += sum;
|
hashcode += sum;
|
||||||
@ -81,8 +77,7 @@ public class Kim
|
|||||||
* @param bytes The byte array.
|
* @param bytes The byte array.
|
||||||
* @param length The number of bytes.
|
* @param length The number of bytes.
|
||||||
*/
|
*/
|
||||||
public Kim(final byte[] bytes, final int length)
|
public Kim(final byte[] bytes, final int length) {
|
||||||
{
|
|
||||||
this(bytes, 0, length);
|
this(bytes, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,8 +88,7 @@ public class Kim
|
|||||||
* @param from The point at which to take bytes.
|
* @param from The point at which to take bytes.
|
||||||
* @param thru The point at which to stop taking bytes.
|
* @param thru The point at which to stop taking bytes.
|
||||||
*/
|
*/
|
||||||
public Kim(final Kim kim, final int from, final int thru)
|
public Kim(final Kim kim, final int from, final int thru) {
|
||||||
{
|
|
||||||
this(kim.bytes, from, thru);
|
this(kim.bytes, from, thru);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,33 +99,26 @@ public class Kim
|
|||||||
*
|
*
|
||||||
* @throws JSONException if surrogate pair mismatch.
|
* @throws JSONException if surrogate pair mismatch.
|
||||||
*/
|
*/
|
||||||
public Kim(final String string) throws JSONException
|
public Kim(final String string) throws JSONException {
|
||||||
{
|
|
||||||
final int stringLength = string.length();
|
final int stringLength = string.length();
|
||||||
hashcode = 0;
|
hashcode = 0;
|
||||||
length = 0;
|
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);
|
||||||
if (c <= 0x7F)
|
if (c <= 0x7F) {
|
||||||
{
|
|
||||||
length += 1;
|
length += 1;
|
||||||
}
|
} else if (c <= 0x3FFF) {
|
||||||
else if (c <= 0x3FFF)
|
|
||||||
{
|
|
||||||
length += 2;
|
length += 2;
|
||||||
}
|
} else {
|
||||||
else
|
if ((c >= 0xD800) && (c <= 0xDFFF)) {
|
||||||
{
|
|
||||||
if ((c >= 0xD800) && (c <= 0xDFFF))
|
|
||||||
{
|
|
||||||
i += 1;
|
i += 1;
|
||||||
final int d = string.charAt(i);
|
final int d = string.charAt(i);
|
||||||
if ((c > 0xDBFF) || (d < 0xDC00) || (d > 0xDFFF)) { throw new JSONException("Bad UTF16"); }
|
if ((c > 0xDBFF) || (d < 0xDC00) || (d > 0xDFFF)) {
|
||||||
|
throw new JSONException("Bad UTF16");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
length += 3;
|
length += 3;
|
||||||
}
|
}
|
||||||
@ -143,18 +130,14 @@ public class Kim
|
|||||||
int at = 0;
|
int at = 0;
|
||||||
int b;
|
int b;
|
||||||
int sum = 1;
|
int sum = 1;
|
||||||
for (int i = 0; i < stringLength; i += 1)
|
for (int i = 0; i < stringLength; i += 1) {
|
||||||
{
|
|
||||||
int character = string.charAt(i);
|
int character = string.charAt(i);
|
||||||
if (character <= 0x7F)
|
if (character <= 0x7F) {
|
||||||
{
|
|
||||||
bytes[at] = (byte) character;
|
bytes[at] = (byte) character;
|
||||||
sum += character;
|
sum += character;
|
||||||
hashcode += sum;
|
hashcode += sum;
|
||||||
at += 1;
|
at += 1;
|
||||||
}
|
} else if (character <= 0x3FFF) {
|
||||||
else if (character <= 0x3FFF)
|
|
||||||
{
|
|
||||||
b = 0x80 | (character >>> 7);
|
b = 0x80 | (character >>> 7);
|
||||||
bytes[at] = (byte) b;
|
bytes[at] = (byte) b;
|
||||||
sum += b;
|
sum += b;
|
||||||
@ -165,11 +148,8 @@ public class Kim
|
|||||||
sum += b;
|
sum += b;
|
||||||
hashcode += sum;
|
hashcode += sum;
|
||||||
at += 1;
|
at += 1;
|
||||||
}
|
} else {
|
||||||
else
|
if ((character >= 0xD800) && (character <= 0xDBFF)) {
|
||||||
{
|
|
||||||
if ((character >= 0xD800) && (character <= 0xDBFF))
|
|
||||||
{
|
|
||||||
i += 1;
|
i += 1;
|
||||||
character = (((character & 0x3FF) << 10) | (string.charAt(i) & 0x3FF)) + 65536;
|
character = (((character & 0x3FF) << 10) | (string.charAt(i) & 0x3FF)) + 65536;
|
||||||
}
|
}
|
||||||
@ -203,9 +183,10 @@ public class Kim
|
|||||||
*
|
*
|
||||||
* @throws JSONException if the character is not representable in a kim.
|
* @throws JSONException if the character is not representable in a kim.
|
||||||
*/
|
*/
|
||||||
public static int characterSize(final int character) throws JSONException
|
public static int characterSize(final int character) throws JSONException {
|
||||||
{
|
if ((character < 0) || (character > 0x10FFFF)) {
|
||||||
if ((character < 0) || (character > 0x10FFFF)) { throw new JSONException("Bad character " + character); }
|
throw new JSONException("Bad character " + character);
|
||||||
|
}
|
||||||
return character <= 0x7F ? 1 : character <= 0x3FFF ? 2 : 3;
|
return character <= 0x7F ? 1 : character <= 0x3FFF ? 2 : 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,22 +199,24 @@ public class Kim
|
|||||||
* @throws JSONException if at does not point to a valid character.
|
* @throws JSONException if at does not point to a valid character.
|
||||||
* @return a Unicode character between 0 and 0x10FFFF.
|
* @return a Unicode character between 0 and 0x10FFFF.
|
||||||
*/
|
*/
|
||||||
public int characterAt(final int at) throws JSONException
|
public int characterAt(final int at) throws JSONException {
|
||||||
{
|
|
||||||
final int c = get(at);
|
final int c = get(at);
|
||||||
if ((c & 0x80) == 0) { return c; }
|
if ((c & 0x80) == 0) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
int character;
|
int character;
|
||||||
final int c1 = get(at + 1);
|
final int c1 = get(at + 1);
|
||||||
if ((c1 & 0x80) == 0)
|
if ((c1 & 0x80) == 0) {
|
||||||
{
|
|
||||||
character = ((c & 0x7F) << 7) | c1;
|
character = ((c & 0x7F) << 7) | c1;
|
||||||
if (character > 0x7F) { return character; }
|
if (character > 0x7F) {
|
||||||
|
return character;
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
final int c2 = get(at + 2);
|
final int c2 = get(at + 2);
|
||||||
character = ((c & 0x7F) << 14) | ((c1 & 0x7F) << 7) | c2;
|
character = ((c & 0x7F) << 14) | ((c1 & 0x7F) << 7) | c2;
|
||||||
if (((c2 & 0x80) == 0) && (character > 0x3FFF) && (character <= 0x10FFFF) && ((character < 0xD800) || (character > 0xDFFF))) { return character; }
|
if (((c2 & 0x80) == 0) && (character > 0x3FFF) && (character <= 0x10FFFF) && ((character < 0xD800) || (character > 0xDFFF))) {
|
||||||
|
return character;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw new JSONException("Bad character at " + at);
|
throw new JSONException("Bad character at " + at);
|
||||||
}
|
}
|
||||||
@ -246,8 +229,7 @@ public class Kim
|
|||||||
*
|
*
|
||||||
* @return The position immediately after the copy.
|
* @return The position immediately after the copy.
|
||||||
*/
|
*/
|
||||||
public int copy(final byte[] bytes, final int at)
|
public int copy(final byte[] bytes, final int at) {
|
||||||
{
|
|
||||||
System.arraycopy(this.bytes, 0, bytes, at, length);
|
System.arraycopy(this.bytes, 0, bytes, at, length);
|
||||||
return at + length;
|
return at + length;
|
||||||
}
|
}
|
||||||
@ -260,12 +242,17 @@ public class Kim
|
|||||||
* @return true if this and obj are both kim objects containing identical byte sequences.
|
* @return true if this and obj are both kim objects containing identical byte sequences.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj)
|
public boolean equals(final Object obj) {
|
||||||
{
|
if (!(obj instanceof Kim)) {
|
||||||
if (!(obj instanceof Kim)) { return false; }
|
return false;
|
||||||
|
}
|
||||||
final Kim that = (Kim) obj;
|
final Kim that = (Kim) obj;
|
||||||
if (this == that) { return true; }
|
if (this == that) {
|
||||||
if (hashcode != that.hashcode) { return false; }
|
return true;
|
||||||
|
}
|
||||||
|
if (hashcode != that.hashcode) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return java.util.Arrays.equals(bytes, that.bytes);
|
return java.util.Arrays.equals(bytes, that.bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,9 +265,10 @@ public class Kim
|
|||||||
*
|
*
|
||||||
* @throws JSONException if there is no byte at that position.
|
* @throws JSONException if there is no byte at that position.
|
||||||
*/
|
*/
|
||||||
public int get(final int at) throws JSONException
|
public int get(final int at) throws JSONException {
|
||||||
{
|
if ((at < 0) || (at > length)) {
|
||||||
if ((at < 0) || (at > length)) { throw new JSONException("Bad character at " + at); }
|
throw new JSONException("Bad character at " + at);
|
||||||
|
}
|
||||||
return (bytes[at]) & 0xFF;
|
return (bytes[at]) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,8 +276,7 @@ public class Kim
|
|||||||
* Returns a hash code value for the kim.
|
* Returns a hash code value for the kim.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode() {
|
||||||
{
|
|
||||||
return hashcode;
|
return hashcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,23 +289,17 @@ public class Kim
|
|||||||
* @throws JSONException if the kim is not valid.
|
* @throws JSONException if the kim is not valid.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() throws JSONException
|
public String toString() throws JSONException {
|
||||||
{
|
if (string == null) {
|
||||||
if (string == null)
|
|
||||||
{
|
|
||||||
int c;
|
int c;
|
||||||
int length = 0;
|
int length = 0;
|
||||||
final char chars[] = new char[this.length];
|
final char chars[] = new char[this.length];
|
||||||
for (int at = 0; at < this.length; at += characterSize(c))
|
for (int at = 0; at < this.length; at += characterSize(c)) {
|
||||||
{
|
|
||||||
c = characterAt(at);
|
c = characterAt(at);
|
||||||
if (c < 0x10000)
|
if (c < 0x10000) {
|
||||||
{
|
|
||||||
chars[length] = (char) c;
|
chars[length] = (char) c;
|
||||||
length += 1;
|
length += 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
chars[length] = (char) (0xD800 | ((c - 0x10000) >>> 10));
|
chars[length] = (char) (0xD800 | ((c - 0x10000) >>> 10));
|
||||||
length += 1;
|
length += 1;
|
||||||
chars[length] = (char) (0xDC00 | (c & 0x03FF));
|
chars[length] = (char) (0xDC00 | (c & 0x03FF));
|
||||||
|
@ -30,8 +30,7 @@ import java.util.Properties;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @version 2014-05-03
|
* @version 2014-05-03
|
||||||
*/
|
*/
|
||||||
public class Property
|
public class Property {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Converts a property file object into a JSONObject. The property file object is a table of name value pairs.
|
* Converts a property file object into a JSONObject. The property file object is a table of name value pairs.
|
||||||
*
|
*
|
||||||
@ -41,14 +40,11 @@ public class Property
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static JSONObject toJSONObject(final java.util.Properties properties) throws JSONException
|
public static JSONObject toJSONObject(final java.util.Properties properties) throws JSONException {
|
||||||
{
|
|
||||||
final JSONObject jo = new JSONObject();
|
final JSONObject jo = new JSONObject();
|
||||||
if ((properties != null) && !properties.isEmpty())
|
if ((properties != null) && !properties.isEmpty()) {
|
||||||
{
|
|
||||||
final Enumeration enumProperties = properties.propertyNames();
|
final Enumeration enumProperties = properties.propertyNames();
|
||||||
while (enumProperties.hasMoreElements())
|
while (enumProperties.hasMoreElements()) {
|
||||||
{
|
|
||||||
final String name = (String) enumProperties.nextElement();
|
final String name = (String) enumProperties.nextElement();
|
||||||
jo.put(name, properties.getProperty(name));
|
jo.put(name, properties.getProperty(name));
|
||||||
}
|
}
|
||||||
@ -65,14 +61,11 @@ public class Property
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static Properties toProperties(final JSONObject jo) throws JSONException
|
public static Properties toProperties(final JSONObject jo) throws JSONException {
|
||||||
{
|
|
||||||
final Properties properties = new Properties();
|
final Properties properties = new Properties();
|
||||||
if (jo != null)
|
if (jo != null) {
|
||||||
{
|
|
||||||
final Iterator<String> keys = jo.keys();
|
final Iterator<String> keys = jo.keys();
|
||||||
while (keys.hasNext())
|
while (keys.hasNext()) {
|
||||||
{
|
|
||||||
final String name = keys.next();
|
final String name = keys.next();
|
||||||
properties.put(name, jo.getString(name));
|
properties.put(name, jo.getString(name));
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,7 @@ import java.util.Iterator;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @version 2014-05-03
|
* @version 2014-05-03
|
||||||
*/
|
*/
|
||||||
public class XML
|
public class XML {
|
||||||
{
|
|
||||||
public static final Character AMP = '&';
|
public static final Character AMP = '&';
|
||||||
public static final Character APOS = '\'';
|
public static final Character APOS = '\'';
|
||||||
public static final Character BANG = '!';
|
public static final Character BANG = '!';
|
||||||
@ -20,14 +19,11 @@ public class XML
|
|||||||
public static final Character QUOT = '"';
|
public static final Character QUOT = '"';
|
||||||
public static final Character SLASH = '/';
|
public static final Character SLASH = '/';
|
||||||
|
|
||||||
public static String escape(final String string)
|
public static String escape(final String string) {
|
||||||
{
|
|
||||||
final StringBuilder sb = new StringBuilder(string.length());
|
final StringBuilder sb = new StringBuilder(string.length());
|
||||||
for (int i = 0, length = string.length(); i < length; i++)
|
for (int i = 0, length = string.length(); i < length; i++) {
|
||||||
{
|
|
||||||
final char c = string.charAt(i);
|
final char c = string.charAt(i);
|
||||||
switch (c)
|
switch (c) {
|
||||||
{
|
|
||||||
case '&':
|
case '&':
|
||||||
sb.append("&");
|
sb.append("&");
|
||||||
break;
|
break;
|
||||||
@ -57,14 +53,16 @@ public class XML
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static void noSpace(final String string) throws JSONException
|
public static void noSpace(final String string) throws JSONException {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
final int length = string.length();
|
final int length = string.length();
|
||||||
if (length == 0) { throw new JSONException("Empty string."); }
|
if (length == 0) {
|
||||||
for (i = 0; i < length; i += 1)
|
throw new JSONException("Empty string.");
|
||||||
{
|
}
|
||||||
if (Character.isWhitespace(string.charAt(i))) { throw new JSONException("'" + string + "' contains a space character."); }
|
for (i = 0; i < length; i += 1) {
|
||||||
|
if (Character.isWhitespace(string.charAt(i))) {
|
||||||
|
throw new JSONException("'" + string + "' contains a space character.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,8 +77,7 @@ public class XML
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
private static boolean parse(final XMLTokener x, final JSONObject context, final String name) throws JSONException
|
private static boolean parse(final XMLTokener x, final JSONObject context, final String name) throws JSONException {
|
||||||
{
|
|
||||||
char c;
|
char c;
|
||||||
int i;
|
int i;
|
||||||
JSONObject jsonobject = null;
|
JSONObject jsonobject = null;
|
||||||
@ -98,28 +95,20 @@ 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 == '-') {
|
||||||
{
|
if (x.next() == '-') {
|
||||||
if (x.next() == '-')
|
|
||||||
{
|
|
||||||
x.skipPast("-->");
|
x.skipPast("-->");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
x.back();
|
x.back();
|
||||||
}
|
} else if (c == '[') {
|
||||||
else if (c == '[')
|
|
||||||
{
|
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
if ("CDATA".equals(token))
|
if ("CDATA".equals(token)) {
|
||||||
{
|
if (x.next() == '[') {
|
||||||
if (x.next() == '[')
|
|
||||||
{
|
|
||||||
string = x.nextCDATA();
|
string = x.nextCDATA();
|
||||||
if (string.length() > 0)
|
if (string.length() > 0) {
|
||||||
{
|
|
||||||
context.accumulate("content", string);
|
context.accumulate("content", string);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -128,130 +117,99 @@ public class XML
|
|||||||
throw x.syntaxError("Expected 'CDATA['");
|
throw x.syntaxError("Expected 'CDATA['");
|
||||||
}
|
}
|
||||||
i = 1;
|
i = 1;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
token = x.nextMeta();
|
token = x.nextMeta();
|
||||||
if (token == null)
|
if (token == null) {
|
||||||
{
|
|
||||||
throw x.syntaxError("Missing '>' after '<!'.");
|
throw x.syntaxError("Missing '>' after '<!'.");
|
||||||
}
|
} else if (token == LT) {
|
||||||
else if (token == LT)
|
|
||||||
{
|
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
} else if (token == GT) {
|
||||||
else if (token == GT)
|
|
||||||
{
|
|
||||||
i -= 1;
|
i -= 1;
|
||||||
}
|
}
|
||||||
}
|
} while (i > 0);
|
||||||
while (i > 0);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if (token == QUEST) {
|
||||||
else if (token == QUEST)
|
|
||||||
{
|
|
||||||
// <?
|
// <?
|
||||||
x.skipPast("?>");
|
x.skipPast("?>");
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if (token == SLASH) {
|
||||||
else if (token == SLASH)
|
|
||||||
{
|
|
||||||
// Close tag </
|
// Close tag </
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
if (name == null) { throw x.syntaxError("Mismatched close tag " + token); }
|
if (name == null) {
|
||||||
if (!token.equals(name)) { throw x.syntaxError("Mismatched " + name + " and " + token); }
|
throw x.syntaxError("Mismatched close tag " + token);
|
||||||
if (x.nextToken() != GT) { throw x.syntaxError("Misshaped close tag"); }
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else if (token instanceof Character)
|
if (!token.equals(name)) {
|
||||||
{
|
throw x.syntaxError("Mismatched " + name + " and " + token);
|
||||||
|
}
|
||||||
|
if (x.nextToken() != GT) {
|
||||||
|
throw x.syntaxError("Misshaped close tag");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} 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();
|
||||||
if (token == EQ)
|
if (token == EQ) {
|
||||||
{
|
|
||||||
token = x.nextToken();
|
token = x.nextToken();
|
||||||
if (!(token instanceof String)) { throw x.syntaxError("Missing value"); }
|
if (!(token instanceof String)) {
|
||||||
|
throw x.syntaxError("Missing value");
|
||||||
|
}
|
||||||
jsonobject.accumulate(string, XML.stringToValue((String) token));
|
jsonobject.accumulate(string, XML.stringToValue((String) token));
|
||||||
token = null;
|
token = null;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
jsonobject.accumulate(string, "");
|
jsonobject.accumulate(string, "");
|
||||||
}
|
}
|
||||||
// Empty tag <.../>
|
// Empty tag <.../>
|
||||||
|
} else if (token == SLASH) {
|
||||||
|
if (x.nextToken() != GT) {
|
||||||
|
throw x.syntaxError("Misshaped tag");
|
||||||
}
|
}
|
||||||
else if (token == SLASH)
|
if (jsonobject.length() > 0) {
|
||||||
{
|
|
||||||
if (x.nextToken() != GT) { throw x.syntaxError("Misshaped tag"); }
|
|
||||||
if (jsonobject.length() > 0)
|
|
||||||
{
|
|
||||||
context.accumulate(tagName, jsonobject);
|
context.accumulate(tagName, jsonobject);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
context.accumulate(tagName, "");
|
context.accumulate(tagName, "");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
// Content, between <...> and </...>
|
// Content, between <...> and </...>
|
||||||
}
|
} else if (token == GT) {
|
||||||
else if (token == GT)
|
for (;;) {
|
||||||
{
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
token = x.nextContent();
|
token = x.nextContent();
|
||||||
if (token == null)
|
if (token == null) {
|
||||||
{
|
if (tagName != null) {
|
||||||
if (tagName != null) { throw x.syntaxError("Unclosed tag " + tagName); }
|
throw x.syntaxError("Unclosed tag " + tagName);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if (token instanceof String)
|
return false;
|
||||||
{
|
} else if (token instanceof String) {
|
||||||
string = (String) token;
|
string = (String) token;
|
||||||
if (string.length() > 0)
|
if (string.length() > 0) {
|
||||||
{
|
|
||||||
jsonobject.accumulate("content", XML.stringToValue(string));
|
jsonobject.accumulate("content", XML.stringToValue(string));
|
||||||
}
|
}
|
||||||
// Nested element
|
// Nested element
|
||||||
}
|
} else if (token == LT) {
|
||||||
else if (token == LT)
|
if (parse(x, jsonobject, tagName)) {
|
||||||
{
|
if (jsonobject.length() == 0) {
|
||||||
if (parse(x, jsonobject, tagName))
|
|
||||||
{
|
|
||||||
if (jsonobject.length() == 0)
|
|
||||||
{
|
|
||||||
context.accumulate(tagName, "");
|
context.accumulate(tagName, "");
|
||||||
}
|
} else if ((jsonobject.length() == 1) && (jsonobject.opt("content") != null)) {
|
||||||
else if ((jsonobject.length() == 1) && (jsonobject.opt("content") != null))
|
|
||||||
{
|
|
||||||
context.accumulate(tagName, jsonobject.opt("content"));
|
context.accumulate(tagName, jsonobject.opt("content"));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
context.accumulate(tagName, jsonobject);
|
context.accumulate(tagName, jsonobject);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw x.syntaxError("Misshaped tag");
|
throw x.syntaxError("Misshaped tag");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,42 +225,42 @@ public class XML
|
|||||||
*
|
*
|
||||||
* @return A simple JSON value.
|
* @return A simple JSON value.
|
||||||
*/
|
*/
|
||||||
public static Object stringToValue(final String string)
|
public static Object stringToValue(final String string) {
|
||||||
{
|
if ("true".equalsIgnoreCase(string)) {
|
||||||
if ("true".equalsIgnoreCase(string)) { return Boolean.TRUE; }
|
return Boolean.TRUE;
|
||||||
if ("false".equalsIgnoreCase(string)) { return Boolean.FALSE; }
|
}
|
||||||
if ("null".equalsIgnoreCase(string)) { return JSONObject.NULL; }
|
if ("false".equalsIgnoreCase(string)) {
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
if ("null".equalsIgnoreCase(string)) {
|
||||||
|
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'))) {
|
||||||
{
|
|
||||||
final Long value = new Long(string);
|
final Long value = new Long(string);
|
||||||
if (value.toString().equals(string)) { return value; }
|
if (value.toString().equals(string)) {
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (final Exception ignore)
|
} catch (final Exception ignore) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final Double value = new Double(string);
|
final Double value = new Double(string);
|
||||||
if (value.toString().equals(string)) { return value; }
|
if (value.toString().equals(string)) {
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
catch (final Exception ignoreAlso)
|
} catch (final Exception ignoreAlso) {}
|
||||||
{}
|
|
||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JSONObject toJSONObject(final String string) throws JSONException
|
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||||
{
|
|
||||||
final JSONObject jo = new JSONObject();
|
final JSONObject jo = new JSONObject();
|
||||||
final XMLTokener x = new XMLTokener(string);
|
final XMLTokener x = new XMLTokener(string);
|
||||||
while (x.more() && x.skipPast("<"))
|
while (x.more() && x.skipPast("<")) {
|
||||||
{
|
|
||||||
parse(x, jo, null);
|
parse(x, jo, null);
|
||||||
}
|
}
|
||||||
return jo;
|
return jo;
|
||||||
@ -317,8 +275,7 @@ public class XML
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,8 +289,7 @@ public class XML
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public static String toString(Object object, final String tagName) throws JSONException
|
public static String toString(Object object, final String tagName) throws JSONException {
|
||||||
{
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
int i;
|
int i;
|
||||||
JSONArray ja;
|
JSONArray ja;
|
||||||
@ -343,11 +299,9 @@ public class XML
|
|||||||
int length;
|
int length;
|
||||||
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('>');
|
||||||
@ -355,46 +309,34 @@ public class XML
|
|||||||
// 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()) {
|
||||||
{
|
|
||||||
key = keys.next();
|
key = keys.next();
|
||||||
value = jo.opt(key);
|
value = jo.opt(key);
|
||||||
if (value == null)
|
if (value == null) {
|
||||||
{
|
|
||||||
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;
|
||||||
length = ja.length();
|
length = ja.length();
|
||||||
for (i = 0; i < length; i += 1)
|
for (i = 0; i < length; i += 1) {
|
||||||
{
|
if (i > 0) {
|
||||||
if (i > 0)
|
|
||||||
{
|
|
||||||
sb.append('\n');
|
sb.append('\n');
|
||||||
}
|
}
|
||||||
sb.append(escape(ja.get(i).toString()));
|
sb.append(escape(ja.get(i).toString()));
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.append(escape(value.toString()));
|
sb.append(escape(value.toString()));
|
||||||
}
|
}
|
||||||
// Emit an array of similar keys
|
// Emit an array of similar keys
|
||||||
}
|
} else if (value instanceof JSONArray) {
|
||||||
else if (value instanceof JSONArray)
|
|
||||||
{
|
|
||||||
ja = (JSONArray) value;
|
ja = (JSONArray) value;
|
||||||
length = ja.length();
|
length = ja.length();
|
||||||
for (i = 0; i < length; i += 1)
|
for (i = 0; i < length; i += 1) {
|
||||||
{
|
|
||||||
value = ja.get(i);
|
value = ja.get(i);
|
||||||
if (value instanceof JSONArray)
|
if (value instanceof JSONArray) {
|
||||||
{
|
|
||||||
sb.append('<');
|
sb.append('<');
|
||||||
sb.append(key);
|
sb.append(key);
|
||||||
sb.append('>');
|
sb.append('>');
|
||||||
@ -402,27 +344,20 @@ public class XML
|
|||||||
sb.append("</");
|
sb.append("</");
|
||||||
sb.append(key);
|
sb.append(key);
|
||||||
sb.append('>');
|
sb.append('>');
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.append(toString(value, key));
|
sb.append(toString(value, key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if ("".equals(value)) {
|
||||||
else if ("".equals(value))
|
|
||||||
{
|
|
||||||
sb.append('<');
|
sb.append('<');
|
||||||
sb.append(key);
|
sb.append(key);
|
||||||
sb.append("/>");
|
sb.append("/>");
|
||||||
// Emit a new tag <k>
|
// Emit a new tag <k>
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.append(toString(value, key));
|
sb.append(toString(value, key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
||||||
@ -432,25 +367,18 @@ public class XML
|
|||||||
// 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);
|
||||||
}
|
}
|
||||||
if (object instanceof JSONArray)
|
if (object instanceof JSONArray) {
|
||||||
{
|
|
||||||
ja = (JSONArray) object;
|
ja = (JSONArray) object;
|
||||||
length = ja.length();
|
length = ja.length();
|
||||||
for (i = 0; i < length; i += 1)
|
for (i = 0; i < length; i += 1) {
|
||||||
{
|
|
||||||
sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
|
sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
string = (object == null) ? "null" : escape(object.toString());
|
string = (object == null) ? "null" : escape(object.toString());
|
||||||
return (tagName == null) ? "\"" + string + "\"" : (string.length() == 0) ? "<" + tagName + "/>" : "<" + tagName + ">" + string + "</" + tagName + ">";
|
return (tagName == null) ? "\"" + string + "\"" : (string.length() == 0) ? "<" + tagName + "/>" : "<" + tagName + ">" + string + "</" + tagName + ">";
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,12 @@ package com.intellectualcrafters.json;
|
|||||||
* @author JSON.org
|
* @author JSON.org
|
||||||
* @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);
|
||||||
entity.put("apos", XML.APOS);
|
entity.put("apos", XML.APOS);
|
||||||
@ -27,8 +25,7 @@ public class XMLTokener extends JSONTokener
|
|||||||
*
|
*
|
||||||
* @param s A source string.
|
* @param s A source string.
|
||||||
*/
|
*/
|
||||||
public XMLTokener(final String s)
|
public XMLTokener(final String s) {
|
||||||
{
|
|
||||||
super(s);
|
super(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,19 +36,18 @@ public class XMLTokener extends JSONTokener
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the <code>]]></code> is not found.
|
* @throws JSONException If the <code>]]></code> is not found.
|
||||||
*/
|
*/
|
||||||
public String nextCDATA() throws JSONException
|
public String nextCDATA() throws JSONException {
|
||||||
{
|
|
||||||
char c;
|
char c;
|
||||||
int i;
|
int i;
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
c = next();
|
c = next();
|
||||||
if (end()) { throw syntaxError("Unclosed CDATA"); }
|
if (end()) {
|
||||||
|
throw syntaxError("Unclosed CDATA");
|
||||||
|
}
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
i = sb.length() - 3;
|
i = sb.length() - 3;
|
||||||
if ((i >= 0) && (sb.charAt(i) == ']') && (sb.charAt(i + 1) == ']') && (sb.charAt(i + 2) == '>'))
|
if ((i >= 0) && (sb.charAt(i) == ']') && (sb.charAt(i + 1) == ']') && (sb.charAt(i + 2) == '>')) {
|
||||||
{
|
|
||||||
sb.setLength(i);
|
sb.setLength(i);
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
@ -66,31 +62,27 @@ public class XMLTokener extends JSONTokener
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public Object nextContent() throws JSONException
|
public Object nextContent() throws JSONException {
|
||||||
{
|
|
||||||
char c;
|
char c;
|
||||||
StringBuilder sb;
|
StringBuilder sb;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
c = next();
|
c = next();
|
||||||
|
} while (Character.isWhitespace(c));
|
||||||
|
if (c == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (c == '<') {
|
||||||
|
return XML.LT;
|
||||||
}
|
}
|
||||||
while (Character.isWhitespace(c));
|
|
||||||
if (c == 0) { return null; }
|
|
||||||
if (c == '<') { return XML.LT; }
|
|
||||||
sb = new StringBuilder();
|
sb = new StringBuilder();
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
if ((c == '<') || (c == 0)) {
|
||||||
if ((c == '<') || (c == 0))
|
|
||||||
{
|
|
||||||
back();
|
back();
|
||||||
return sb.toString().trim();
|
return sb.toString().trim();
|
||||||
}
|
}
|
||||||
if (c == '&')
|
if (c == '&') {
|
||||||
{
|
|
||||||
sb.append(nextEntity(c));
|
sb.append(nextEntity(c));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
c = next();
|
c = next();
|
||||||
@ -107,22 +99,15 @@ public class XMLTokener extends JSONTokener
|
|||||||
*
|
*
|
||||||
* @throws JSONException If missing ';' in XML entity.
|
* @throws JSONException If missing ';' in XML entity.
|
||||||
*/
|
*/
|
||||||
public Object nextEntity(final char ampersand) throws JSONException
|
public Object nextEntity(final char ampersand) throws JSONException {
|
||||||
{
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
final char c = next();
|
final char c = next();
|
||||||
if (Character.isLetterOrDigit(c) || (c == '#'))
|
if (Character.isLetterOrDigit(c) || (c == '#')) {
|
||||||
{
|
|
||||||
sb.append(Character.toLowerCase(c));
|
sb.append(Character.toLowerCase(c));
|
||||||
}
|
} else if (c == ';') {
|
||||||
else if (c == ';')
|
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw syntaxError("Missing ';' in XML entity: &" + sb);
|
throw syntaxError("Missing ';' in XML entity: &" + sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,17 +124,13 @@ public class XMLTokener extends JSONTokener
|
|||||||
*
|
*
|
||||||
* @throws JSONException If a string is not properly closed or if the XML is badly structured.
|
* @throws JSONException If a string is not properly closed or if the XML is badly structured.
|
||||||
*/
|
*/
|
||||||
public Object nextMeta() throws JSONException
|
public Object nextMeta() throws JSONException {
|
||||||
{
|
|
||||||
char c;
|
char c;
|
||||||
char q;
|
char q;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
c = next();
|
c = next();
|
||||||
}
|
} while (Character.isWhitespace(c));
|
||||||
while (Character.isWhitespace(c));
|
switch (c) {
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
throw syntaxError("Misshaped meta tag");
|
throw syntaxError("Misshaped meta tag");
|
||||||
case '<':
|
case '<':
|
||||||
@ -167,19 +148,22 @@ public class XMLTokener extends JSONTokener
|
|||||||
case '"':
|
case '"':
|
||||||
case '\'':
|
case '\'':
|
||||||
q = c;
|
q = c;
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
c = next();
|
c = next();
|
||||||
if (c == 0) { throw syntaxError("Unterminated string"); }
|
if (c == 0) {
|
||||||
if (c == q) { return Boolean.TRUE; }
|
throw syntaxError("Unterminated string");
|
||||||
|
}
|
||||||
|
if (c == q) {
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
c = next();
|
c = next();
|
||||||
if (Character.isWhitespace(c)) { return Boolean.TRUE; }
|
if (Character.isWhitespace(c)) {
|
||||||
switch (c)
|
return Boolean.TRUE;
|
||||||
{
|
}
|
||||||
|
switch (c) {
|
||||||
case 0:
|
case 0:
|
||||||
case '<':
|
case '<':
|
||||||
case '>':
|
case '>':
|
||||||
@ -204,18 +188,14 @@ public class XMLTokener extends JSONTokener
|
|||||||
*
|
*
|
||||||
* @throws JSONException If the XML is not well formed.
|
* @throws JSONException If the XML is not well formed.
|
||||||
*/
|
*/
|
||||||
public Object nextToken() throws JSONException
|
public Object nextToken() throws JSONException {
|
||||||
{
|
|
||||||
char c;
|
char c;
|
||||||
char q;
|
char q;
|
||||||
StringBuilder sb;
|
StringBuilder sb;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
c = next();
|
c = next();
|
||||||
}
|
} while (Character.isWhitespace(c));
|
||||||
while (Character.isWhitespace(c));
|
switch (c) {
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
throw syntaxError("Misshaped element");
|
throw syntaxError("Misshaped element");
|
||||||
case '<':
|
case '<':
|
||||||
@ -235,30 +215,30 @@ public class XMLTokener extends JSONTokener
|
|||||||
case '\'':
|
case '\'':
|
||||||
q = c;
|
q = c;
|
||||||
sb = new StringBuilder();
|
sb = new StringBuilder();
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
c = next();
|
c = next();
|
||||||
if (c == 0) { throw syntaxError("Unterminated string"); }
|
if (c == 0) {
|
||||||
if (c == q) { return sb.toString(); }
|
throw syntaxError("Unterminated string");
|
||||||
if (c == '&')
|
|
||||||
{
|
|
||||||
sb.append(nextEntity(c));
|
|
||||||
}
|
}
|
||||||
else
|
if (c == q) {
|
||||||
{
|
return sb.toString();
|
||||||
|
}
|
||||||
|
if (c == '&') {
|
||||||
|
sb.append(nextEntity(c));
|
||||||
|
} else {
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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)) { return sb.toString(); }
|
if (Character.isWhitespace(c)) {
|
||||||
switch (c)
|
return sb.toString();
|
||||||
{
|
}
|
||||||
|
switch (c) {
|
||||||
case 0:
|
case 0:
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
case '>':
|
case '>':
|
||||||
@ -287,8 +267,7 @@ public class XMLTokener extends JSONTokener
|
|||||||
*
|
*
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public boolean skipPast(final String to) throws JSONException
|
public boolean skipPast(final String to) throws JSONException {
|
||||||
{
|
|
||||||
boolean b;
|
boolean b;
|
||||||
char c;
|
char c;
|
||||||
int i;
|
int i;
|
||||||
@ -300,44 +279,44 @@ public class XMLTokener extends JSONTokener
|
|||||||
* 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) { return false; }
|
if (c == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
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;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
j += 1;
|
j += 1;
|
||||||
if (j >= length)
|
if (j >= length) {
|
||||||
{
|
|
||||||
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) { return true; }
|
if (b) {
|
||||||
|
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) { return false; }
|
if (c == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Shove the character in the circle buffer and advance the
|
* Shove the character in the circle buffer and advance the
|
||||||
* circle offset. The offset is mod n.
|
* circle offset. The offset is mod n.
|
||||||
*/
|
*/
|
||||||
circle[offset] = c;
|
circle[offset] = c;
|
||||||
offset += 1;
|
offset += 1;
|
||||||
if (offset >= length)
|
if (offset >= length) {
|
||||||
{
|
|
||||||
offset -= length;
|
offset -= length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,7 @@ import com.intellectualcrafters.plot.util.SetupUtils;
|
|||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
||||||
|
|
||||||
public interface IPlotMain
|
public interface IPlotMain {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a message to console
|
* Log a message to console
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -61,8 +61,7 @@ import com.plotsquared.bukkit.util.BukkitUtil;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class PlotAPI
|
public class PlotAPI {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permission that allows for admin access, this permission node will allow the player to use any part of the
|
* Permission that allows for admin access, this permission node will allow the player to use any part of the
|
||||||
@ -76,8 +75,7 @@ public class PlotAPI
|
|||||||
* @deprecated Use new PlotAPI() instead
|
* @deprecated Use new PlotAPI() instead
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public PlotAPI(final JavaPlugin plugin)
|
public PlotAPI(final JavaPlugin plugin) {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plugin Plugin used to access this method
|
* @param plugin Plugin used to access this method
|
||||||
@ -94,8 +92,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public PlotAPI()
|
public PlotAPI() {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all plots
|
* Get all plots
|
||||||
@ -104,8 +101,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.PS#getPlots()
|
* @see com.intellectualcrafters.plot.PS#getPlots()
|
||||||
*/
|
*/
|
||||||
public Set<Plot> getAllPlots()
|
public Set<Plot> getAllPlots() {
|
||||||
{
|
|
||||||
return PS.get().getPlots();
|
return PS.get().getPlots();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,8 +112,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @return all plots that a player owns
|
* @return all plots that a player owns
|
||||||
*/
|
*/
|
||||||
public Set<Plot> getPlayerPlots(final Player player)
|
public Set<Plot> getPlayerPlots(final Player player) {
|
||||||
{
|
|
||||||
return PS.get().getPlots(BukkitUtil.getPlayer(player));
|
return PS.get().getPlots(BukkitUtil.getPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,8 +126,7 @@ public class PlotAPI
|
|||||||
* @see com.intellectualcrafters.plot.PS#addPlotWorld(String, com.intellectualcrafters.plot.object.PlotWorld,
|
* @see com.intellectualcrafters.plot.PS#addPlotWorld(String, com.intellectualcrafters.plot.object.PlotWorld,
|
||||||
* com.intellectualcrafters.plot.object.PlotManager)
|
* com.intellectualcrafters.plot.object.PlotManager)
|
||||||
*/
|
*/
|
||||||
public void addPlotWorld(final String world, final PlotWorld plotWorld, final PlotManager manager)
|
public void addPlotWorld(final String world, final PlotWorld plotWorld, final PlotManager manager) {
|
||||||
{
|
|
||||||
PS.get().addPlotWorld(world, plotWorld, manager);
|
PS.get().addPlotWorld(world, plotWorld, manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,8 +135,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.PS#config
|
* @see com.intellectualcrafters.plot.PS#config
|
||||||
*/
|
*/
|
||||||
public YamlConfiguration getConfig()
|
public YamlConfiguration getConfig() {
|
||||||
{
|
|
||||||
return PS.get().config;
|
return PS.get().config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,8 +144,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.PS#storage
|
* @see com.intellectualcrafters.plot.PS#storage
|
||||||
*/
|
*/
|
||||||
public YamlConfiguration getStorage()
|
public YamlConfiguration getStorage() {
|
||||||
{
|
|
||||||
return PS.get().storage;
|
return PS.get().storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,8 +156,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.PS
|
* @see com.intellectualcrafters.plot.PS
|
||||||
*/
|
*/
|
||||||
public PS getMain()
|
public PS getMain() {
|
||||||
{
|
|
||||||
return PS.get();
|
return PS.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,8 +172,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.util.ChunkManager
|
* @see com.intellectualcrafters.plot.util.ChunkManager
|
||||||
*/
|
*/
|
||||||
public ChunkManager getChunkManager()
|
public ChunkManager getChunkManager() {
|
||||||
{
|
|
||||||
return ChunkManager.manager;
|
return ChunkManager.manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,8 +183,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.util.BlockManager
|
* @see com.intellectualcrafters.plot.util.BlockManager
|
||||||
*/
|
*/
|
||||||
public BlockManager getBlockManager()
|
public BlockManager getBlockManager() {
|
||||||
{
|
|
||||||
return BlockManager.manager;
|
return BlockManager.manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,8 +194,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.plotsquared.bukkit.util.BukkitSetBlockManager
|
* @see com.plotsquared.bukkit.util.BukkitSetBlockManager
|
||||||
*/
|
*/
|
||||||
public BukkitSetBlockManager getBukkitBlockManager()
|
public BukkitSetBlockManager getBukkitBlockManager() {
|
||||||
{
|
|
||||||
return BukkitSetBlockManager.setBlockManager;
|
return BukkitSetBlockManager.setBlockManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,8 +205,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.uuid.UUIDWrapper
|
* @see com.intellectualcrafters.plot.uuid.UUIDWrapper
|
||||||
*/
|
*/
|
||||||
public UUIDWrapper getUUIDWrapper()
|
public UUIDWrapper getUUIDWrapper() {
|
||||||
{
|
|
||||||
return UUIDHandler.getUUIDWrapper();
|
return UUIDHandler.getUUIDWrapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,8 +218,7 @@ public class PlotAPI
|
|||||||
* @see com.intellectualcrafters.plot.flag.FlagManager
|
* @see com.intellectualcrafters.plot.flag.FlagManager
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public FlagManager getFlagManager()
|
public FlagManager getFlagManager() {
|
||||||
{
|
|
||||||
return new FlagManager();
|
return new FlagManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,8 +231,7 @@ public class PlotAPI
|
|||||||
* @see com.intellectualcrafters.plot.util.ClusterManager
|
* @see com.intellectualcrafters.plot.util.ClusterManager
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public ClusterManager getClusterManager()
|
public ClusterManager getClusterManager() {
|
||||||
{
|
|
||||||
return new ClusterManager();
|
return new ClusterManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,8 +244,7 @@ public class PlotAPI
|
|||||||
* @see com.intellectualcrafters.plot.util.MainUtil
|
* @see com.intellectualcrafters.plot.util.MainUtil
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public MainUtil getMainUtil()
|
public MainUtil getMainUtil() {
|
||||||
{
|
|
||||||
return new MainUtil();
|
return new MainUtil();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,13 +257,10 @@ public class PlotAPI
|
|||||||
* @see com.intellectualcrafters.plot.util.Permissions
|
* @see com.intellectualcrafters.plot.util.Permissions
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public String[] getPermissions()
|
public String[] getPermissions() {
|
||||||
{
|
|
||||||
final ArrayList<String> perms = new ArrayList<>();
|
final ArrayList<String> perms = new ArrayList<>();
|
||||||
for (final C c : C.values())
|
for (final C c : C.values()) {
|
||||||
{
|
if (c.getCat().equals("static.permissions")) {
|
||||||
if (c.getCat().equals("static.permissions"))
|
|
||||||
{
|
|
||||||
perms.add(c.s());
|
perms.add(c.s());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,8 +274,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.util.SchematicHandler
|
* @see com.intellectualcrafters.plot.util.SchematicHandler
|
||||||
*/
|
*/
|
||||||
public SchematicHandler getSchematicHandler()
|
public SchematicHandler getSchematicHandler() {
|
||||||
{
|
|
||||||
return SchematicHandler.manager;
|
return SchematicHandler.manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,8 +286,7 @@ public class PlotAPI
|
|||||||
* @see com.intellectualcrafters.plot.config.C
|
* @see com.intellectualcrafters.plot.config.C
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public C[] getCaptions()
|
public C[] getCaptions() {
|
||||||
{
|
|
||||||
return C.values();
|
return C.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,8 +300,7 @@ public class PlotAPI
|
|||||||
* @see com.intellectualcrafters.plot.object.PlotManager
|
* @see com.intellectualcrafters.plot.object.PlotManager
|
||||||
* @see PS#getPlotManager(String)
|
* @see PS#getPlotManager(String)
|
||||||
*/
|
*/
|
||||||
public PlotManager getPlotManager(final World world)
|
public PlotManager getPlotManager(final World world) {
|
||||||
{
|
|
||||||
return PS.get().getPlotManager(world.getName());
|
return PS.get().getPlotManager(world.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,8 +315,7 @@ public class PlotAPI
|
|||||||
* @see PS#getPlotManager(String)
|
* @see PS#getPlotManager(String)
|
||||||
* @see com.intellectualcrafters.plot.object.PlotManager
|
* @see com.intellectualcrafters.plot.object.PlotManager
|
||||||
*/
|
*/
|
||||||
public PlotManager getPlotManager(final String world)
|
public PlotManager getPlotManager(final String world) {
|
||||||
{
|
|
||||||
return PS.get().getPlotManager(world);
|
return PS.get().getPlotManager(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,8 +330,7 @@ public class PlotAPI
|
|||||||
* @see PS#getPlotWorld(String)
|
* @see PS#getPlotWorld(String)
|
||||||
* @see com.intellectualcrafters.plot.object.PlotWorld
|
* @see com.intellectualcrafters.plot.object.PlotWorld
|
||||||
*/
|
*/
|
||||||
public PlotWorld getWorldSettings(final World world)
|
public PlotWorld getWorldSettings(final World world) {
|
||||||
{
|
|
||||||
return PS.get().getPlotWorld(world.getName());
|
return PS.get().getPlotWorld(world.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,8 +344,7 @@ public class PlotAPI
|
|||||||
* @see PS#getPlotWorld(String)
|
* @see PS#getPlotWorld(String)
|
||||||
* @see com.intellectualcrafters.plot.object.PlotWorld
|
* @see com.intellectualcrafters.plot.object.PlotWorld
|
||||||
*/
|
*/
|
||||||
public PlotWorld getWorldSettings(final String world)
|
public PlotWorld getWorldSettings(final String world) {
|
||||||
{
|
|
||||||
return PS.get().getPlotWorld(world);
|
return PS.get().getPlotWorld(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,8 +357,7 @@ public class PlotAPI
|
|||||||
* @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, C, String...)
|
* @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, C, String...)
|
||||||
* com.intellectualcrafters.plot.config.C, String...)
|
* com.intellectualcrafters.plot.config.C, String...)
|
||||||
*/
|
*/
|
||||||
public void sendMessage(final Player player, final C c)
|
public void sendMessage(final Player player, final C c) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), c);
|
MainUtil.sendMessage(BukkitUtil.getPlayer(player), c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,8 +369,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, String)
|
* @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, String)
|
||||||
*/
|
*/
|
||||||
public void sendMessage(final Player player, final String string)
|
public void sendMessage(final Player player, final String string) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
|
MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,8 +380,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see MainUtil#sendConsoleMessage(String)
|
* @see MainUtil#sendConsoleMessage(String)
|
||||||
*/
|
*/
|
||||||
public void sendConsoleMessage(final String msg)
|
public void sendConsoleMessage(final String msg) {
|
||||||
{
|
|
||||||
MainUtil.sendConsoleMessage(msg);
|
MainUtil.sendConsoleMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,8 +392,7 @@ public class PlotAPI
|
|||||||
* @see #sendConsoleMessage(String)
|
* @see #sendConsoleMessage(String)
|
||||||
* @see com.intellectualcrafters.plot.config.C
|
* @see com.intellectualcrafters.plot.config.C
|
||||||
*/
|
*/
|
||||||
public void sendConsoleMessage(final C c)
|
public void sendConsoleMessage(final C c) {
|
||||||
{
|
|
||||||
sendConsoleMessage(c.s());
|
sendConsoleMessage(c.s());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,8 +404,7 @@ public class PlotAPI
|
|||||||
* @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag)
|
* @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag)
|
||||||
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
||||||
*/
|
*/
|
||||||
public void addFlag(final AbstractFlag flag)
|
public void addFlag(final AbstractFlag flag) {
|
||||||
{
|
|
||||||
FlagManager.addFlag(flag);
|
FlagManager.addFlag(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,8 +416,7 @@ public class PlotAPI
|
|||||||
* @see com.intellectualcrafters.plot.flag.FlagManager#getFlags()
|
* @see com.intellectualcrafters.plot.flag.FlagManager#getFlags()
|
||||||
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
||||||
*/
|
*/
|
||||||
public AbstractFlag[] getFlags()
|
public AbstractFlag[] getFlags() {
|
||||||
{
|
|
||||||
return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]);
|
return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,8 +432,7 @@ public class PlotAPI
|
|||||||
* @see MainUtil#getPlot(String, com.intellectualcrafters.plot.object.PlotId)
|
* @see MainUtil#getPlot(String, com.intellectualcrafters.plot.object.PlotId)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Plot getPlot(final World world, final int x, final int z)
|
public Plot getPlot(final World world, final int x, final int z) {
|
||||||
{
|
|
||||||
return MainUtil.getPlot(world.getName(), new PlotId(x, z));
|
return MainUtil.getPlot(world.getName(), new PlotId(x, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,8 +446,7 @@ public class PlotAPI
|
|||||||
* @see MainUtil#getPlot(com.intellectualcrafters.plot.object.Location)
|
* @see MainUtil#getPlot(com.intellectualcrafters.plot.object.Location)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Plot getPlot(final Location l)
|
public Plot getPlot(final Location l) {
|
||||||
{
|
|
||||||
return MainUtil.getPlot(BukkitUtil.getLocation(l));
|
return MainUtil.getPlot(BukkitUtil.getLocation(l));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,8 +460,7 @@ public class PlotAPI
|
|||||||
* @see #getPlot(org.bukkit.Location)
|
* @see #getPlot(org.bukkit.Location)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Plot getPlot(final Player player)
|
public Plot getPlot(final Player player) {
|
||||||
{
|
|
||||||
return this.getPlot(player.getLocation());
|
return this.getPlot(player.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,8 +473,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see #getPlots(World, Player, boolean)
|
* @see #getPlots(World, Player, boolean)
|
||||||
*/
|
*/
|
||||||
public boolean hasPlot(final World world, final Player player)
|
public boolean hasPlot(final World world, final Player player) {
|
||||||
{
|
|
||||||
return (getPlots(world, player, true) != null) && (getPlots(world, player, true).length > 0);
|
return (getPlots(world, player, true) != null) && (getPlots(world, player, true).length > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -520,22 +485,15 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Plot[] getPlots(final World world, final Player plr, final boolean just_owner)
|
public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) {
|
||||||
{
|
|
||||||
final ArrayList<Plot> pPlots = new ArrayList<>();
|
final ArrayList<Plot> pPlots = new ArrayList<>();
|
||||||
for (final Plot plot : PS.get().getPlotsInWorld(world.getName()))
|
for (final Plot plot : PS.get().getPlotsInWorld(world.getName())) {
|
||||||
{
|
if (just_owner) {
|
||||||
if (just_owner)
|
if ((plot.owner != null) && (plot.owner.equals(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr))))) {
|
||||||
{
|
|
||||||
if ((plot.owner != null) && (plot.owner.equals(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr)))))
|
|
||||||
{
|
|
||||||
pPlots.add(plot);
|
pPlots.add(plot);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if (plot.isAdded(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr)))) {
|
||||||
{
|
|
||||||
if (plot.isAdded(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr))))
|
|
||||||
{
|
|
||||||
pPlots.add(plot);
|
pPlots.add(plot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -553,8 +511,7 @@ public class PlotAPI
|
|||||||
* @see PS#getPlots(String)
|
* @see PS#getPlots(String)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Plot[] getPlots(final World world)
|
public Plot[] getPlots(final World world) {
|
||||||
{
|
|
||||||
final Collection<Plot> plots = PS.get().getPlotsInWorld(world.getName());
|
final Collection<Plot> plots = PS.get().getPlotsInWorld(world.getName());
|
||||||
return plots.toArray(new Plot[plots.size()]);
|
return plots.toArray(new Plot[plots.size()]);
|
||||||
}
|
}
|
||||||
@ -566,8 +523,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.PS#getPlotWorlds()
|
* @see com.intellectualcrafters.plot.PS#getPlotWorlds()
|
||||||
*/
|
*/
|
||||||
public String[] getPlotWorlds()
|
public String[] getPlotWorlds() {
|
||||||
{
|
|
||||||
final Set<String> worlds = PS.get().getPlotWorlds();
|
final Set<String> worlds = PS.get().getPlotWorlds();
|
||||||
return worlds.toArray(new String[worlds.size()]);
|
return worlds.toArray(new String[worlds.size()]);
|
||||||
}
|
}
|
||||||
@ -581,8 +537,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.PS#isPlotWorld(String)
|
* @see com.intellectualcrafters.plot.PS#isPlotWorld(String)
|
||||||
*/
|
*/
|
||||||
public boolean isPlotWorld(final World world)
|
public boolean isPlotWorld(final World world) {
|
||||||
{
|
|
||||||
return PS.get().isPlotWorld(world.getName());
|
return PS.get().isPlotWorld(world.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,8 +556,7 @@ public class PlotAPI
|
|||||||
* com.intellectualcrafters.plot.object.Plot)
|
* com.intellectualcrafters.plot.object.Plot)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Location[] getLocations(final Plot p)
|
public Location[] getLocations(final Plot p) {
|
||||||
{
|
|
||||||
return new Location[] {
|
return new Location[] {
|
||||||
BukkitUtil.getLocation(MainUtil.getPlotBottomLoc(p.world, p.id)),
|
BukkitUtil.getLocation(MainUtil.getPlotBottomLoc(p.world, p.id)),
|
||||||
BukkitUtil.getLocation(MainUtil.getPlotTopLoc(p.world, p.id)),
|
BukkitUtil.getLocation(MainUtil.getPlotTopLoc(p.world, p.id)),
|
||||||
@ -620,8 +574,7 @@ public class PlotAPI
|
|||||||
* com.intellectualcrafters.plot.object.Plot)
|
* com.intellectualcrafters.plot.object.Plot)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Location getHomeLocation(final Plot p)
|
public Location getHomeLocation(final Plot p) {
|
||||||
{
|
|
||||||
return BukkitUtil.getLocation(MainUtil.getPlotHome(p.world, p.id));
|
return BukkitUtil.getLocation(MainUtil.getPlotHome(p.world, p.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -636,8 +589,7 @@ public class PlotAPI
|
|||||||
* com.intellectualcrafters.plot.object.PlotId)
|
* com.intellectualcrafters.plot.object.PlotId)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Location getBottomLocation(final Plot p)
|
public Location getBottomLocation(final Plot p) {
|
||||||
{
|
|
||||||
return BukkitUtil.getLocation(MainUtil.getPlotBottomLoc(p.world, p.id));
|
return BukkitUtil.getLocation(MainUtil.getPlotBottomLoc(p.world, p.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -651,8 +603,7 @@ public class PlotAPI
|
|||||||
* @see MainUtil#getPlotTopLoc(String, com.intellectualcrafters.plot.object.PlotId)
|
* @see MainUtil#getPlotTopLoc(String, com.intellectualcrafters.plot.object.PlotId)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Location getTopLocation(final Plot p)
|
public Location getTopLocation(final Plot p) {
|
||||||
{
|
|
||||||
return BukkitUtil.getLocation(MainUtil.getPlotTopLoc(p.world, p.id));
|
return BukkitUtil.getLocation(MainUtil.getPlotTopLoc(p.world, p.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,8 +616,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.util.MainUtil#getPlot(com.intellectualcrafters.plot.object.Location)
|
* @see com.intellectualcrafters.plot.util.MainUtil#getPlot(com.intellectualcrafters.plot.object.Location)
|
||||||
*/
|
*/
|
||||||
public boolean isInPlot(final Player player)
|
public boolean isInPlot(final Player player) {
|
||||||
{
|
|
||||||
return MainUtil.getPlot(BukkitUtil.getLocation(player)) != null;
|
return MainUtil.getPlot(BukkitUtil.getLocation(player)) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -677,14 +627,10 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.commands.SubCommand
|
* @see com.intellectualcrafters.plot.commands.SubCommand
|
||||||
*/
|
*/
|
||||||
public void registerCommand(final SubCommand c)
|
public void registerCommand(final SubCommand c) {
|
||||||
{
|
if (c.getCommand() != null) {
|
||||||
if (c.getCommand() != null)
|
|
||||||
{
|
|
||||||
MainCommand.getInstance().addCommand(c);
|
MainCommand.getInstance().addCommand(c);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainCommand.getInstance().createCommand(c);
|
MainCommand.getInstance().createCommand(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -696,8 +642,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.PS
|
* @see com.intellectualcrafters.plot.PS
|
||||||
*/
|
*/
|
||||||
public PS getPlotSquared()
|
public PS getPlotSquared() {
|
||||||
{
|
|
||||||
return PS.get();
|
return PS.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -711,8 +656,7 @@ public class PlotAPI
|
|||||||
*
|
*
|
||||||
* @see com.intellectualcrafters.plot.util.MainUtil#getPlayerPlotCount(String, PlotPlayer)
|
* @see com.intellectualcrafters.plot.util.MainUtil#getPlayerPlotCount(String, PlotPlayer)
|
||||||
*/
|
*/
|
||||||
public int getPlayerPlotCount(final World world, final Player player)
|
public int getPlayerPlotCount(final World world, final Player player) {
|
||||||
{
|
|
||||||
return MainUtil.getPlayerPlotCount(world.getName(), BukkitUtil.getPlayer(player));
|
return MainUtil.getPlayerPlotCount(world.getName(), BukkitUtil.getPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -728,8 +672,7 @@ public class PlotAPI
|
|||||||
* org.bukkit.entity.Player)
|
* org.bukkit.entity.Player)
|
||||||
* @see com.intellectualcrafters.plot.object.Plot
|
* @see com.intellectualcrafters.plot.object.Plot
|
||||||
*/
|
*/
|
||||||
public Set<Plot> getPlayerPlots(final World world, final Player player)
|
public Set<Plot> getPlayerPlots(final World world, final Player player) {
|
||||||
{
|
|
||||||
return PS.get().getPlots(world.getName(), BukkitUtil.getPlayer(player));
|
return PS.get().getPlots(world.getName(), BukkitUtil.getPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -741,8 +684,7 @@ public class PlotAPI
|
|||||||
* @return the number of allowed plots
|
* @return the number of allowed plots
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public int getAllowedPlots(final Player player)
|
public int getAllowedPlots(final Player player) {
|
||||||
{
|
|
||||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
return MainUtil.getAllowedPlots(pp);
|
return MainUtil.getAllowedPlots(pp);
|
||||||
}
|
}
|
||||||
@ -756,8 +698,7 @@ public class PlotAPI
|
|||||||
* @param player
|
* @param player
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public PlotPlayer wrapPlayer(final Player player)
|
public PlotPlayer wrapPlayer(final Player player) {
|
||||||
{
|
|
||||||
return PlotPlayer.wrap(player);
|
return PlotPlayer.wrap(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -769,8 +710,7 @@ public class PlotAPI
|
|||||||
* @param player
|
* @param player
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public PlotPlayer wrapPlayer(final UUID uuid)
|
public PlotPlayer wrapPlayer(final UUID uuid) {
|
||||||
{
|
|
||||||
return PlotPlayer.wrap(uuid);
|
return PlotPlayer.wrap(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -782,8 +722,7 @@ public class PlotAPI
|
|||||||
* @param player
|
* @param player
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public PlotPlayer wrapPlayer(final String player)
|
public PlotPlayer wrapPlayer(final String player) {
|
||||||
{
|
|
||||||
return PlotPlayer.wrap(player);
|
return PlotPlayer.wrap(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -796,8 +735,7 @@ public class PlotAPI
|
|||||||
* @param player
|
* @param player
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public PlotPlayer wrapPlayer(final OfflinePlayer player)
|
public PlotPlayer wrapPlayer(final OfflinePlayer player) {
|
||||||
{
|
|
||||||
return PlotPlayer.wrap(player);
|
return PlotPlayer.wrap(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,71 +43,55 @@ usage = "/plot add <player>",
|
|||||||
category = CommandCategory.ACTIONS,
|
category = CommandCategory.ACTIONS,
|
||||||
permission = "plots.add",
|
permission = "plots.add",
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Add extends SubCommand
|
public class Add extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
public Add()
|
public Add() {
|
||||||
{
|
requiredArguments = new Argument[] { Argument.PlayerName };
|
||||||
requiredArguments = new Argument[] {
|
|
||||||
Argument.PlayerName
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final Plot plot = MainUtil.getPlot(loc);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
|
if (plot == null) {
|
||||||
if (!plot.hasOwner())
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
{
|
}
|
||||||
|
if (!plot.hasOwner()) {
|
||||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.add"))
|
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.add")) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
if (args[0].equalsIgnoreCase("*"))
|
if (args[0].equalsIgnoreCase("*")) {
|
||||||
{
|
|
||||||
uuid = DBFunc.everyone;
|
uuid = DBFunc.everyone;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// TODO have a runnable for fetch
|
// TODO have a runnable for fetch
|
||||||
uuid = UUIDHandler.getUUID(args[0], null);
|
uuid = UUIDHandler.getUUID(args[0], null);
|
||||||
}
|
}
|
||||||
if (uuid == null)
|
if (uuid == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot.isOwner(uuid))
|
if (plot.isOwner(uuid)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plot.getMembers().contains(uuid))
|
if (plot.getMembers().contains(uuid)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot.removeTrusted(uuid))
|
if (plot.removeTrusted(uuid)) {
|
||||||
{
|
|
||||||
plot.addMember(uuid);
|
plot.addMember(uuid);
|
||||||
}
|
} else {
|
||||||
else
|
if ((plot.getMembers().size() + plot.getTrusted().size()) >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
|
||||||
{
|
|
||||||
if ((plot.getMembers().size() + plot.getTrusted().size()) >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
|
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot.getDenied().contains(uuid))
|
if (plot.getDenied().contains(uuid)) {
|
||||||
{
|
|
||||||
plot.removeDenied(uuid);
|
plot.removeDenied(uuid);
|
||||||
}
|
}
|
||||||
plot.addMember(uuid);
|
plot.addMember(uuid);
|
||||||
|
@ -42,89 +42,69 @@ requiredType = RequiredType.NONE,
|
|||||||
description = "Claim the nearest plot",
|
description = "Claim the nearest plot",
|
||||||
aliases = { "a" },
|
aliases = { "a" },
|
||||||
usage = "/plot auto")
|
usage = "/plot auto")
|
||||||
public class Auto extends SubCommand
|
public class Auto extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
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);
|
||||||
if (absX > absY)
|
if (absX > absY) {
|
||||||
{
|
if (id.x > 0) {
|
||||||
if (id.x > 0)
|
|
||||||
{
|
|
||||||
return new PlotId(id.x, id.y + 1);
|
return new PlotId(id.x, id.y + 1);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return new PlotId(id.x, id.y - 1);
|
return new PlotId(id.x, id.y - 1);
|
||||||
}
|
}
|
||||||
}
|
} else if (absY > absX) {
|
||||||
else if (absY > absX)
|
if (id.y > 0) {
|
||||||
{
|
|
||||||
if (id.y > 0)
|
|
||||||
{
|
|
||||||
return new PlotId(id.x - 1, id.y);
|
return new PlotId(id.x - 1, id.y);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return new PlotId(id.x + 1, id.y);
|
return new PlotId(id.x + 1, id.y);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (id.x.equals(id.y) && (id.x > 0)) {
|
||||||
|
return new PlotId(id.x, id.y + step);
|
||||||
|
}
|
||||||
|
if (id.x == absX) {
|
||||||
|
return new PlotId(id.x, id.y + 1);
|
||||||
|
}
|
||||||
|
if (id.y == absY) {
|
||||||
|
return new PlotId(id.x, id.y - 1);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (id.x.equals(id.y) && (id.x > 0)) { return new PlotId(id.x, id.y + step); }
|
|
||||||
if (id.x == absX) { return new PlotId(id.x, id.y + 1); }
|
|
||||||
if (id.y == absY) { return new PlotId(id.x, id.y - 1); }
|
|
||||||
return new PlotId(id.x + 1, id.y);
|
return new PlotId(id.x + 1, id.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
String world;
|
String world;
|
||||||
int size_x = 1;
|
int size_x = 1;
|
||||||
int size_z = 1;
|
int size_z = 1;
|
||||||
String schematic = "";
|
String schematic = "";
|
||||||
if (PS.get().getPlotWorlds().size() == 1)
|
if (PS.get().getPlotWorlds().size() == 1) {
|
||||||
{
|
|
||||||
world = PS.get().getPlotWorlds().iterator().next();
|
world = PS.get().getPlotWorlds().iterator().next();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
world = plr.getLocation().getWorld();
|
world = plr.getLocation().getWorld();
|
||||||
if (!PS.get().isPlotWorld(world))
|
if (!PS.get().isPlotWorld(world)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (args.length > 0)
|
if (args.length > 0) {
|
||||||
{
|
if (Permissions.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)) {
|
||||||
{
|
|
||||||
MainUtil.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)) {
|
||||||
{
|
|
||||||
MainUtil.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];
|
||||||
}
|
}
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
size_x = 1;
|
size_x = 1;
|
||||||
size_z = 1;
|
size_z = 1;
|
||||||
schematic = args[0];
|
schematic = args[0];
|
||||||
@ -132,42 +112,32 @@ public class Auto extends SubCommand
|
|||||||
// "&cError: Invalid size (X,Y)");
|
// "&cError: Invalid size (X,Y)");
|
||||||
// return false;
|
// return false;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
schematic = args[0];
|
schematic = args[0];
|
||||||
// PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
|
// PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
|
||||||
// return false;
|
// return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((size_x * size_z) > Settings.MAX_AUTO_SIZE)
|
if ((size_x * size_z) > Settings.MAX_AUTO_SIZE) {
|
||||||
{
|
|
||||||
MainUtil.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 currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr);
|
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr);
|
||||||
final int diff = currentPlots - MainUtil.getAllowedPlots(plr);
|
final int diff = currentPlots - MainUtil.getAllowedPlots(plr);
|
||||||
if ((diff + (size_x * size_z)) > 0)
|
if ((diff + (size_x * size_z)) > 0) {
|
||||||
{
|
if (diff < 0) {
|
||||||
if (diff < 0)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + "");
|
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + "");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlotWorld pWorld = PS.get().getPlotWorld(world);
|
final PlotWorld pWorld = PS.get().getPlotWorld(world);
|
||||||
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY)
|
if ((EconHandler.manager != 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) {
|
||||||
{
|
if (EconHandler.manager.getMoney(plr) < cost) {
|
||||||
if (EconHandler.manager.getMoney(plr) < cost)
|
|
||||||
{
|
|
||||||
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -175,16 +145,13 @@ public class Auto extends SubCommand
|
|||||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!schematic.equals(""))
|
if (!schematic.equals("")) {
|
||||||
{
|
|
||||||
// if (pWorld.SCHEMATIC_CLAIM_SPECIFY) {
|
// if (pWorld.SCHEMATIC_CLAIM_SPECIFY) {
|
||||||
if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase()))
|
if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) {
|
||||||
{
|
|
||||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !Permissions.hasPermission(plr, "plots.admin.command.schematic"))
|
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !Permissions.hasPermission(plr, "plots.admin.command.schematic")) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
MainUtil.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -192,15 +159,15 @@ public class Auto extends SubCommand
|
|||||||
}
|
}
|
||||||
final String worldname = world;
|
final String worldname = world;
|
||||||
final PlotWorld plotworld = PS.get().getPlotWorld(worldname);
|
final PlotWorld plotworld = PS.get().getPlotWorld(worldname);
|
||||||
if (plotworld.TYPE == 2)
|
if (plotworld.TYPE == 2) {
|
||||||
{
|
|
||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final Plot plot = MainUtil.getPlot(new Location(worldname, loc.getX(), loc.getY(), loc.getZ()));
|
final Plot plot = MainUtil.getPlot(new Location(worldname, loc.getX(), loc.getY(), loc.getZ()));
|
||||||
if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); }
|
if (plot == null) {
|
||||||
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
|
}
|
||||||
final PlotCluster cluster = plot.getCluster();
|
final PlotCluster cluster = plot.getCluster();
|
||||||
// Must be standing in a cluster
|
// Must be standing in a cluster
|
||||||
if (cluster == null)
|
if (cluster == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -211,12 +178,10 @@ public class Auto extends SubCommand
|
|||||||
final 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);
|
||||||
final int max = width * width;
|
final int max = width * width;
|
||||||
//
|
//
|
||||||
for (int i = 0; i <= max; i++)
|
for (int i = 0; i <= max; i++) {
|
||||||
{
|
|
||||||
final 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);
|
||||||
final Plot current = MainUtil.getPlot(worldname, currentId);
|
final Plot current = MainUtil.getPlot(worldname, currentId);
|
||||||
if (MainUtil.canClaim(plr, current) && (current.getSettings().isMerged() == false) && cluster.equals(current.getCluster()))
|
if (MainUtil.canClaim(plr, current) && (current.getSettings().isMerged() == false) && cluster.equals(current.getCluster())) {
|
||||||
{
|
|
||||||
Claim.claimPlot(plr, current, true, true);
|
Claim.claimPlot(plr, current, true, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -227,50 +192,39 @@ public class Auto extends SubCommand
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean br = false;
|
boolean br = false;
|
||||||
if ((size_x == 1) && (size_z == 1))
|
if ((size_x == 1) && (size_z == 1)) {
|
||||||
{
|
while (!br) {
|
||||||
while (!br)
|
|
||||||
{
|
|
||||||
final Plot plot = MainUtil.getPlot(worldname, getLastPlot(worldname));
|
final Plot plot = MainUtil.getPlot(worldname, getLastPlot(worldname));
|
||||||
if (MainUtil.canClaim(plr, plot))
|
if (MainUtil.canClaim(plr, plot)) {
|
||||||
{
|
|
||||||
Claim.claimPlot(plr, plot, true, true);
|
Claim.claimPlot(plr, plot, true, true);
|
||||||
br = true;
|
br = true;
|
||||||
}
|
}
|
||||||
MainUtil.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.
|
||||||
MainUtil.lastPlot.put(worldname, start);
|
MainUtil.lastPlot.put(worldname, start);
|
||||||
if (lastPlot)
|
if (lastPlot) {}
|
||||||
{}
|
if ((PS.get().getPlot(worldname, start) != null) && (PS.get().getPlot(worldname, start).owner != null)) {
|
||||||
if ((PS.get().getPlot(worldname, start) != null) && (PS.get().getPlot(worldname, 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 (MainUtil.canClaim(plr, worldname, start, end))
|
if (MainUtil.canClaim(plr, 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 = MainUtil.getPlot(worldname, 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 (!MainUtil.mergePlots(worldname, MainUtil.getPlotSelectionIds(start, end), true, true)) { return false; }
|
if (!MainUtil.mergePlots(worldname, MainUtil.getPlotSelectionIds(start, end), true, true)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
br = true;
|
br = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -279,10 +233,8 @@ public class Auto extends SubCommand
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlotId getLastPlot(final String world)
|
public PlotId getLastPlot(final String world) {
|
||||||
{
|
if ((MainUtil.lastPlot == null) || !MainUtil.lastPlot.containsKey(world)) {
|
||||||
if ((MainUtil.lastPlot == null) || !MainUtil.lastPlot.containsKey(world))
|
|
||||||
{
|
|
||||||
MainUtil.lastPlot.put(world, new PlotId(0, 0));
|
MainUtil.lastPlot.put(world, new PlotId(0, 0));
|
||||||
}
|
}
|
||||||
return MainUtil.lastPlot.get(world);
|
return MainUtil.lastPlot.get(world);
|
||||||
|
@ -29,57 +29,44 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
|||||||
import com.intellectualcrafters.plot.util.Permissions;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "bo3", aliases = { "bo2" }, description = "Mark a plot as done", permission = "plots.bo3", category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE)
|
||||||
command = "bo3",
|
public class BO3 extends SubCommand {
|
||||||
aliases = { "bo2" },
|
|
||||||
description = "Mark a plot as done",
|
|
||||||
permission = "plots.bo3",
|
|
||||||
category = CommandCategory.ACTIONS,
|
|
||||||
requiredType = RequiredType.NONE)
|
|
||||||
public class BO3 extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
public void noArgs(final PlotPlayer plr)
|
public void noArgs(final PlotPlayer plr) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot bo3 export [category] [alias] [-r]");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot bo3 export [category] [alias] [-r]");
|
||||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot bo3 import <file>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot bo3 import <file>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final Plot plot = MainUtil.getPlot(loc);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if ((plot == null) || !plot.hasOwner()) { return !sendMessage(plr, C.NOT_IN_PLOT); }
|
if ((plot == null) || !plot.hasOwner()) {
|
||||||
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.bo3"))
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
{
|
}
|
||||||
|
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.bo3")) {
|
||||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length == 0)
|
if (args.length == 0) {
|
||||||
{
|
|
||||||
noArgs(plr);
|
noArgs(plr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (args[0].toLowerCase())
|
switch (args[0].toLowerCase()) {
|
||||||
{
|
|
||||||
case "output":
|
case "output":
|
||||||
case "save":
|
case "save":
|
||||||
case "export":
|
case "export": {
|
||||||
{
|
|
||||||
return BO3Handler.saveBO3(plr, plot);
|
return BO3Handler.saveBO3(plr, plot);
|
||||||
}
|
}
|
||||||
case "paste":
|
case "paste":
|
||||||
case "load":
|
case "load":
|
||||||
case "import":
|
case "import":
|
||||||
case "input":
|
case "input": {
|
||||||
{
|
|
||||||
// TODO NOT IMPLEMENTED YET
|
// TODO NOT IMPLEMENTED YET
|
||||||
MainUtil.sendMessage(plr, "NOT IMPLEMENTED YET!!!");
|
MainUtil.sendMessage(plr, "NOT IMPLEMENTED YET!!!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
noArgs(plr);
|
noArgs(plr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -45,70 +45,74 @@ usage = "/plot buy",
|
|||||||
permission = "plots.buy",
|
permission = "plots.buy",
|
||||||
category = CommandCategory.CLAIMING,
|
category = CommandCategory.CLAIMING,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Buy extends SubCommand
|
public class Buy extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args)
|
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
||||||
{
|
|
||||||
|
|
||||||
if (EconHandler.manager == null) { return sendMessage(plr, C.ECON_DISABLED); }
|
if (EconHandler.manager == null) {
|
||||||
|
return sendMessage(plr, C.ECON_DISABLED);
|
||||||
|
}
|
||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final String world = loc.getWorld();
|
final String world = loc.getWorld();
|
||||||
if (!PS.get().isPlotWorld(world)) { return sendMessage(plr, C.NOT_IN_PLOT_WORLD); }
|
if (!PS.get().isPlotWorld(world)) {
|
||||||
|
return sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||||
|
}
|
||||||
Plot plot;
|
Plot plot;
|
||||||
if (args.length > 0)
|
if (args.length > 0) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final String[] split = args[0].split(";");
|
final String[] split = args[0].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 = MainUtil.getPlot(world, id);
|
plot = MainUtil.getPlot(world, id);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final 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 = MainUtil.getPlot(loc);
|
||||||
}
|
}
|
||||||
if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); }
|
if (plot == null) {
|
||||||
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
|
}
|
||||||
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr);
|
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr);
|
||||||
if (currentPlots >= MainUtil.getAllowedPlots(plr)) { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); }
|
if (currentPlots >= MainUtil.getAllowedPlots(plr)) {
|
||||||
if (!plot.hasOwner()) { return sendMessage(plr, C.PLOT_UNOWNED); }
|
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||||
if (PlotHandler.isOwner(plot, plr.getUUID())) { return sendMessage(plr, C.CANNOT_BUY_OWN); }
|
}
|
||||||
|
if (!plot.hasOwner()) {
|
||||||
|
return sendMessage(plr, C.PLOT_UNOWNED);
|
||||||
|
}
|
||||||
|
if (PlotHandler.isOwner(plot, plr.getUUID())) {
|
||||||
|
return sendMessage(plr, C.CANNOT_BUY_OWN);
|
||||||
|
}
|
||||||
final Flag flag = FlagManager.getPlotFlag(plot, "price");
|
final Flag flag = FlagManager.getPlotFlag(plot, "price");
|
||||||
if (flag == null) { return sendMessage(plr, C.NOT_FOR_SALE); }
|
if (flag == null) {
|
||||||
|
return sendMessage(plr, C.NOT_FOR_SALE);
|
||||||
|
}
|
||||||
double initPrice = (double) flag.getValue();
|
double initPrice = (double) flag.getValue();
|
||||||
double price = initPrice;
|
double price = initPrice;
|
||||||
final PlotId id = plot.id;
|
final PlotId id = plot.id;
|
||||||
final PlotId id2 = MainUtil.getTopPlot(plot).id;
|
final PlotId id2 = MainUtil.getTopPlot(plot).id;
|
||||||
final int size = MainUtil.getPlotSelectionIds(id, id2).size();
|
final int size = MainUtil.getPlotSelectionIds(id, id2).size();
|
||||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
final PlotWorld plotworld = PS.get().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 ((EconHandler.manager != null) && (price > 0d))
|
if ((EconHandler.manager != null) && (price > 0d)) {
|
||||||
{
|
if (EconHandler.manager.getMoney(plr) < price) {
|
||||||
if (EconHandler.manager.getMoney(plr) < price) { return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price); }
|
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price);
|
||||||
|
}
|
||||||
EconHandler.manager.withdrawMoney(plr, price);
|
EconHandler.manager.withdrawMoney(plr, price);
|
||||||
sendMessage(plr, C.REMOVED_BALANCE, price + "");
|
sendMessage(plr, C.REMOVED_BALANCE, price + "");
|
||||||
EconHandler.manager.depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), initPrice);
|
EconHandler.manager.depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), initPrice);
|
||||||
final PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
|
final 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");
|
||||||
}
|
}
|
||||||
final Plot top = MainUtil.getTopPlot(plot);
|
final Plot top = MainUtil.getTopPlot(plot);
|
||||||
|
|
||||||
for (final PlotId myId : MainUtil.getPlotSelectionIds(plot.id, top.id))
|
for (final PlotId myId : MainUtil.getPlotSelectionIds(plot.id, top.id)) {
|
||||||
{
|
|
||||||
final Plot myPlot = MainUtil.getPlot(plot.world, myId);
|
final Plot myPlot = MainUtil.getPlot(plot.world, myId);
|
||||||
myPlot.owner = plr.getUUID();
|
myPlot.owner = plr.getUUID();
|
||||||
DBFunc.setOwner(plot, myPlot.owner);
|
DBFunc.setOwner(plot, myPlot.owner);
|
||||||
|
@ -10,12 +10,10 @@ usage = "/plot chat [on|off]",
|
|||||||
permission = "plots.chat",
|
permission = "plots.chat",
|
||||||
category = CommandCategory.ACTIONS,
|
category = CommandCategory.ACTIONS,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Chat extends SubCommand
|
public class Chat extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, final String... args)
|
public boolean onCommand(final PlotPlayer player, final String... args) {
|
||||||
{
|
|
||||||
return MainCommand.onCommand(player, "plot", new String[] { "toggle", "chat" });
|
return MainCommand.onCommand(player, "plot", new String[] { "toggle", "chat" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,57 +44,44 @@ category = CommandCategory.CLAIMING,
|
|||||||
requiredType = RequiredType.NONE,
|
requiredType = RequiredType.NONE,
|
||||||
permission = "plots.claim",
|
permission = "plots.claim",
|
||||||
usage = "/plot claim")
|
usage = "/plot claim")
|
||||||
public class Claim extends SubCommand
|
public class Claim extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
public static boolean claimPlot(final PlotPlayer 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 PlotPlayer 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.getSettings().isMerged()) {
|
||||||
if (plot.hasOwner() || plot.getSettings().isMerged()) { return false; }
|
return false;
|
||||||
|
}
|
||||||
final boolean result = EventUtil.manager.callClaim(player, plot, false);
|
final boolean result = EventUtil.manager.callClaim(player, plot, false);
|
||||||
if (result)
|
if (result) {
|
||||||
{
|
|
||||||
MainUtil.createPlot(player.getUUID(), plot);
|
MainUtil.createPlot(player.getUUID(), plot);
|
||||||
MainUtil.setSign(player.getName(), plot);
|
MainUtil.setSign(player.getName(), plot);
|
||||||
MainUtil.sendMessage(player, C.CLAIMED);
|
MainUtil.sendMessage(player, C.CLAIMED);
|
||||||
final Location loc = player.getLocation();
|
final Location loc = player.getLocation();
|
||||||
if (teleport)
|
if (teleport) {
|
||||||
{
|
|
||||||
MainUtil.teleportPlayer(player, loc, plot);
|
MainUtil.teleportPlayer(player, loc, plot);
|
||||||
}
|
}
|
||||||
final String world = plot.world;
|
final String world = plot.world;
|
||||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||||
final Plot plot2 = PS.get().getPlot(world, plot.id);
|
final Plot plot2 = PS.get().getPlot(world, plot.id);
|
||||||
if (plotworld.SCHEMATIC_ON_CLAIM)
|
if (plotworld.SCHEMATIC_ON_CLAIM) {
|
||||||
{
|
|
||||||
Schematic sch;
|
Schematic sch;
|
||||||
if (schematic.equals(""))
|
if (schematic.equals("")) {
|
||||||
{
|
|
||||||
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
|
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sch = SchematicHandler.manager.getSchematic(schematic);
|
sch = SchematicHandler.manager.getSchematic(schematic);
|
||||||
if (sch == null)
|
if (sch == null) {
|
||||||
{
|
|
||||||
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
|
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SchematicHandler.manager.paste(sch, plot2, 0, 0, new RunnableVal<Boolean>()
|
SchematicHandler.manager.paste(sch, plot2, 0, 0, new RunnableVal<Boolean>() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
if (value) {
|
||||||
if (value)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS);
|
MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_FAILED);
|
MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_FAILED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,38 +93,43 @@ public class Claim extends SubCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args)
|
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
||||||
{
|
|
||||||
|
|
||||||
String schematic = "";
|
String schematic = "";
|
||||||
if (args.length >= 1)
|
if (args.length >= 1) {
|
||||||
{
|
|
||||||
schematic = args[0];
|
schematic = args[0];
|
||||||
}
|
}
|
||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final Plot plot = MainUtil.getPlot(loc);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); }
|
if (plot == null) {
|
||||||
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
|
}
|
||||||
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(loc.getWorld(), plr);
|
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(loc.getWorld(), plr);
|
||||||
if (currentPlots >= MainUtil.getAllowedPlots(plr)) { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); }
|
if (currentPlots >= MainUtil.getAllowedPlots(plr)) {
|
||||||
if (!MainUtil.canClaim(plr, plot)) { return sendMessage(plr, C.PLOT_IS_CLAIMED); }
|
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||||
|
}
|
||||||
|
if (!MainUtil.canClaim(plr, plot)) {
|
||||||
|
return sendMessage(plr, C.PLOT_IS_CLAIMED);
|
||||||
|
}
|
||||||
final PlotWorld world = PS.get().getPlotWorld(plot.world);
|
final PlotWorld world = PS.get().getPlotWorld(plot.world);
|
||||||
if ((EconHandler.manager != null) && world.USE_ECONOMY)
|
if ((EconHandler.manager != null) && world.USE_ECONOMY) {
|
||||||
{
|
|
||||||
final double cost = world.PLOT_PRICE;
|
final double cost = world.PLOT_PRICE;
|
||||||
if (cost > 0d)
|
if (cost > 0d) {
|
||||||
{
|
if (EconHandler.manager.getMoney(plr) < cost) {
|
||||||
if (EconHandler.manager.getMoney(plr) < cost) { return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost); }
|
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
||||||
|
}
|
||||||
EconHandler.manager.withdrawMoney(plr, cost);
|
EconHandler.manager.withdrawMoney(plr, cost);
|
||||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!schematic.equals(""))
|
if (!schematic.equals("")) {
|
||||||
{
|
if (world.SCHEMATIC_CLAIM_SPECIFY) {
|
||||||
if (world.SCHEMATIC_CLAIM_SPECIFY)
|
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
|
||||||
{
|
return sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
||||||
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) { return sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); }
|
}
|
||||||
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !Permissions.hasPermission(plr, "plots.admin.command.schematic")) { return sendMessage(plr,
|
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !Permissions.hasPermission(plr, "plots.admin.command.schematic")) {
|
||||||
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);
|
||||||
|
@ -37,106 +37,78 @@ import com.intellectualcrafters.plot.util.TaskManager;
|
|||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "clear", description = "Clear a plot", permission = "plots.clear", category = CommandCategory.ACTIONS, usage = "/plot clear [id]")
|
||||||
command = "clear",
|
public class Clear extends SubCommand {
|
||||||
description = "Clear a plot",
|
|
||||||
permission = "plots.clear",
|
|
||||||
category = CommandCategory.ACTIONS,
|
|
||||||
usage = "/plot clear [id]")
|
|
||||||
public class Clear extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args)
|
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
||||||
{
|
|
||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final Plot plot;
|
final Plot plot;
|
||||||
if (args.length == 2)
|
if (args.length == 2) {
|
||||||
{
|
|
||||||
final PlotId id = PlotId.fromString(args[0]);
|
final PlotId id = PlotId.fromString(args[0]);
|
||||||
if (id == null)
|
if (id == null) {
|
||||||
{
|
if (args[1].equalsIgnoreCase("mine")) {
|
||||||
if (args[1].equalsIgnoreCase("mine"))
|
|
||||||
{
|
|
||||||
final Set<Plot> plots = PS.get().getPlots(plr);
|
final Set<Plot> plots = PS.get().getPlots(plr);
|
||||||
if (plots.size() == 0)
|
if (plots.size() == 0) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PLOTS);
|
MainUtil.sendMessage(plr, C.NO_PLOTS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
plot = plots.iterator().next();
|
plot = plots.iterator().next();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
plot = MainUtil.getPlot(loc.getWorld(), id);
|
plot = MainUtil.getPlot(loc.getWorld(), id);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
plot = MainUtil.getPlot(loc);
|
plot = MainUtil.getPlot(loc);
|
||||||
}
|
}
|
||||||
if (plot == null)
|
if (plot == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
// if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
// if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||||
// return sendMessage(plr, C.UNLINK_REQUIRED);
|
// return sendMessage(plr, C.UNLINK_REQUIRED);
|
||||||
// }
|
// }
|
||||||
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) { return sendMessage(plr, C.NO_PLOT_PERMS); }
|
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) {
|
||||||
|
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
|
}
|
||||||
assert plot != null;
|
assert plot != null;
|
||||||
if (MainUtil.runners.containsKey(plot))
|
if (MainUtil.runners.containsKey(plot)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((FlagManager.getPlotFlag(plot, "done") != null)
|
if ((FlagManager.getPlotFlag(plot, "done") != null)
|
||||||
&& (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && (MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)))))
|
&& (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && (MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr))))) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
|
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Runnable runnable = new Runnable()
|
final Runnable runnable = new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable()
|
final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
// If the state changes, then mark it as no longer done
|
// If the state changes, then mark it as no longer done
|
||||||
if (FlagManager.getPlotFlag(plot, "done") != null)
|
if (FlagManager.getPlotFlag(plot, "done") != null) {
|
||||||
{
|
|
||||||
FlagManager.removePlotFlag(plot, "done");
|
FlagManager.removePlotFlag(plot, "done");
|
||||||
}
|
}
|
||||||
if (FlagManager.getPlotFlag(plot, "analysis") != null)
|
if (FlagManager.getPlotFlag(plot, "analysis") != null) {
|
||||||
{
|
|
||||||
FlagManager.removePlotFlag(plot, "analysis");
|
FlagManager.removePlotFlag(plot, "analysis");
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!result)
|
if (!result) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass")))
|
if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
|
||||||
{
|
|
||||||
CmdConfirm.addPending(plr, "/plot clear " + plot.id, runnable);
|
CmdConfirm.addPending(plr, "/plot clear " + plot.id, runnable);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
TaskManager.runTask(runnable);
|
TaskManager.runTask(runnable);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -59,71 +59,53 @@ category = CommandCategory.ACTIONS,
|
|||||||
requiredType = RequiredType.NONE,
|
requiredType = RequiredType.NONE,
|
||||||
permission = "plots.cluster",
|
permission = "plots.cluster",
|
||||||
description = "Manage a plot cluster")
|
description = "Manage a plot cluster")
|
||||||
public class Cluster extends SubCommand
|
public class Cluster extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args)
|
public boolean onCommand(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
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
|
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String sub = args[0].toLowerCase();
|
final String sub = args[0].toLowerCase();
|
||||||
switch (sub)
|
switch (sub) {
|
||||||
{
|
|
||||||
case "l":
|
case "l":
|
||||||
case "list":
|
case "list": {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.list")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.list"))
|
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final HashSet<PlotCluster> clusters = ClusterManager.getClusters(plr.getLocation().getWorld());
|
final HashSet<PlotCluster> clusters = ClusterManager.getClusters(plr.getLocation().getWorld());
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + "");
|
MainUtil.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + "");
|
||||||
for (final PlotCluster cluster : clusters)
|
for (final PlotCluster cluster : clusters) {
|
||||||
{
|
|
||||||
// Ignore unmanaged clusters
|
// Ignore unmanaged clusters
|
||||||
final 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)) {
|
||||||
{
|
|
||||||
MainUtil.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);
|
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&3" + name);
|
||||||
}
|
} else if (cluster.invited.contains(UUIDHandler.getUUID(plr))) {
|
||||||
else if (cluster.invited.contains(UUIDHandler.getUUID(plr)))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&9" + name);
|
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&9" + name);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, cluster.toString());
|
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, cluster.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "c":
|
case "c":
|
||||||
case "create":
|
case "create": {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.create")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.create"))
|
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
final PlotId id = ClusterManager.estimatePlotId(plr.getLocation());
|
final PlotId id = ClusterManager.estimatePlotId(plr.getLocation());
|
||||||
MainUtil.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>");
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_CURRENT_PLOTID, "" + id);
|
MainUtil.sendMessage(plr, C.CLUSTER_CURRENT_PLOTID, "" + id);
|
||||||
@ -132,23 +114,19 @@ public class Cluster extends SubCommand
|
|||||||
// check pos1 / pos2
|
// check pos1 / pos2
|
||||||
PlotId pos1 = MainUtil.parseId(args[2]);
|
PlotId pos1 = MainUtil.parseId(args[2]);
|
||||||
PlotId pos2 = MainUtil.parseId(args[3]);
|
PlotId pos2 = MainUtil.parseId(args[3]);
|
||||||
if ((pos1 == null) || (pos2 == null))
|
if ((pos1 == null) || (pos2 == null)) {
|
||||||
{
|
|
||||||
MainUtil.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
|
||||||
final String name = args[1];
|
final String name = args[1];
|
||||||
for (final PlotCluster cluster : ClusterManager.getClusters(plr.getLocation().getWorld()))
|
for (final PlotCluster cluster : ClusterManager.getClusters(plr.getLocation().getWorld())) {
|
||||||
{
|
if (name.equals(cluster.getName())) {
|
||||||
if (name.equals(cluster.getName()))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((pos2.x < pos1.x) || (pos2.y < pos1.y))
|
if ((pos2.x < pos1.x) || (pos2.y < pos1.y)) {
|
||||||
{
|
|
||||||
pos1 = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y));
|
pos1 = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y));
|
||||||
pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y));
|
pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y));
|
||||||
}
|
}
|
||||||
@ -156,22 +134,17 @@ public class Cluster extends SubCommand
|
|||||||
final String world = plr.getLocation().getWorld();
|
final String world = plr.getLocation().getWorld();
|
||||||
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
||||||
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(world, id);
|
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(world, id);
|
||||||
if ((intersects.size() > 0))
|
if ((intersects.size() > 0)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
|
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check if it occupies existing plots
|
// Check if it occupies existing plots
|
||||||
final Set<Plot> plots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
|
final Set<Plot> plots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
|
||||||
if (plots.size() > 0)
|
if (plots.size() > 0) {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.create.other")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.create.other"))
|
|
||||||
{
|
|
||||||
final UUID uuid = plr.getUUID();
|
final UUID uuid = plr.getUUID();
|
||||||
for (final Plot plot : plots)
|
for (final Plot plot : plots) {
|
||||||
{
|
if (!plot.isOwner(uuid)) {
|
||||||
if (!plot.isOwner(uuid))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -181,41 +154,30 @@ public class Cluster extends SubCommand
|
|||||||
// Check allowed cluster size
|
// Check allowed cluster size
|
||||||
final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
|
final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
|
||||||
int current;
|
int current;
|
||||||
if (Settings.GLOBAL_LIMIT)
|
if (Settings.GLOBAL_LIMIT) {
|
||||||
{
|
|
||||||
current = ClusterManager.getPlayerClusterCount(plr);
|
current = ClusterManager.getPlayerClusterCount(plr);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
current = ClusterManager.getPlayerClusterCount(world, plr);
|
current = ClusterManager.getPlayerClusterCount(world, plr);
|
||||||
}
|
}
|
||||||
final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
|
final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
|
||||||
if ((current + cluster.getArea()) > allowed)
|
if ((current + cluster.getArea()) > allowed) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Set the generator (if applicable)
|
// Set the generator (if applicable)
|
||||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||||
if (plotworld == null)
|
if (plotworld == null) {
|
||||||
{
|
|
||||||
PS.get().config.createSection("worlds." + world);
|
PS.get().config.createSection("worlds." + world);
|
||||||
PS.get().loadWorld(world, PS.get().IMP.getGenerator(world, null));
|
PS.get().loadWorld(world, PS.get().IMP.getGenerator(world, null));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
String gen_string = PS.get().config.getString("worlds." + world + "." + "generator.plugin");
|
String gen_string = PS.get().config.getString("worlds." + world + "." + "generator.plugin");
|
||||||
if (gen_string == null)
|
if (gen_string == null) {
|
||||||
{
|
|
||||||
gen_string = "PlotSquared";
|
gen_string = "PlotSquared";
|
||||||
}
|
}
|
||||||
final PlotGenerator<?> wrapper = PS.get().IMP.getGenerator(world, gen_string);
|
final PlotGenerator<?> wrapper = PS.get().IMP.getGenerator(world, gen_string);
|
||||||
if (wrapper.isFull())
|
if (wrapper.isFull()) {
|
||||||
{
|
|
||||||
wrapper.augment(cluster, plotworld);
|
wrapper.augment(cluster, plotworld);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringMan.join(SetupUtils.generators.keySet(), ","));
|
MainUtil.sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringMan.join(SetupUtils.generators.keySet(), ","));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -237,20 +199,16 @@ public class Cluster extends SubCommand
|
|||||||
// create cluster
|
// create cluster
|
||||||
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)) {
|
||||||
{
|
|
||||||
ClusterManager.clusters.put(world, new HashSet<PlotCluster>());
|
ClusterManager.clusters.put(world, new HashSet<PlotCluster>());
|
||||||
}
|
}
|
||||||
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 (final Plot plot : plots)
|
for (final Plot plot : plots) {
|
||||||
{
|
if (plot.hasOwner()) {
|
||||||
if (plot.hasOwner())
|
|
||||||
{
|
|
||||||
final Flag flag = new Flag(FlagManager.getFlag("cluster"), cluster);
|
final Flag flag = new Flag(FlagManager.getFlag("cluster"), cluster);
|
||||||
FlagManager.addPlotFlag(plot, flag);
|
FlagManager.addPlotFlag(plot, flag);
|
||||||
if (!cluster.isAdded(plot.owner))
|
if (!cluster.isAdded(plot.owner)) {
|
||||||
{
|
|
||||||
cluster.invited.add(plot.owner);
|
cluster.invited.add(plot.owner);
|
||||||
DBFunc.setInvited(world, cluster, plot.owner);
|
DBFunc.setInvited(world, cluster, plot.owner);
|
||||||
}
|
}
|
||||||
@ -261,65 +219,50 @@ public class Cluster extends SubCommand
|
|||||||
}
|
}
|
||||||
case "disband":
|
case "disband":
|
||||||
case "del":
|
case "del":
|
||||||
case "delete":
|
case "delete": {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.delete")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.delete"))
|
|
||||||
{
|
|
||||||
MainUtil.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)) {
|
||||||
{
|
|
||||||
MainUtil.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.getLocation().getWorld(), args[1]);
|
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||||
if (cluster == null)
|
if (cluster == null) {
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.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 (!Permissions.hasPermission(plr, "plots.cluster.delete.other")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.delete.other"))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final PlotWorld plotworld = PS.get().getPlotWorld(plr.getLocation().getWorld());
|
final PlotWorld plotworld = PS.get().getPlotWorld(plr.getLocation().getWorld());
|
||||||
if (plotworld.TYPE == 2)
|
if (plotworld.TYPE == 2) {
|
||||||
{
|
|
||||||
final ArrayList<Plot> toRemove = new ArrayList<>();
|
final ArrayList<Plot> toRemove = new ArrayList<>();
|
||||||
for (final Plot plot : PS.get().getPlotsInWorld(plr.getLocation().getWorld()))
|
for (final Plot plot : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) {
|
||||||
{
|
|
||||||
final 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 (final Plot plot : toRemove)
|
for (final Plot plot : toRemove) {
|
||||||
{
|
|
||||||
plot.unclaim();
|
plot.unclaim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DBFunc.delete(cluster);
|
DBFunc.delete(cluster);
|
||||||
if (plotworld.TYPE == 2)
|
if (plotworld.TYPE == 2) {
|
||||||
{
|
|
||||||
SetupUtils.manager.removePopulator(plr.getLocation().getWorld(), cluster);
|
SetupUtils.manager.removePopulator(plr.getLocation().getWorld(), cluster);
|
||||||
}
|
}
|
||||||
ClusterManager.last = null;
|
ClusterManager.last = null;
|
||||||
@ -329,28 +272,23 @@ public class Cluster extends SubCommand
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "res":
|
case "res":
|
||||||
case "resize":
|
case "resize": {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.resize")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.resize"))
|
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.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 = MainUtil.parseId(args[1]);
|
PlotId pos1 = MainUtil.parseId(args[1]);
|
||||||
PlotId pos2 = MainUtil.parseId(args[2]);
|
PlotId pos2 = MainUtil.parseId(args[2]);
|
||||||
if ((pos1 == null) || (pos2 == null))
|
if ((pos1 == null) || (pos2 == null)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((pos2.x < pos1.x) || (pos2.y < pos1.y))
|
if ((pos2.x < pos1.x) || (pos2.y < pos1.y)) {
|
||||||
{
|
|
||||||
pos1 = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y));
|
pos1 = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y));
|
||||||
pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y));
|
pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y));
|
||||||
}
|
}
|
||||||
@ -358,15 +296,12 @@ public class Cluster extends SubCommand
|
|||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final String world = loc.getWorld();
|
final String world = loc.getWorld();
|
||||||
final PlotCluster cluster = ClusterManager.getCluster(loc);
|
final PlotCluster cluster = ClusterManager.getCluster(loc);
|
||||||
if (cluster == null)
|
if (cluster == null) {
|
||||||
{
|
|
||||||
MainUtil.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 (!Permissions.hasPermission(plr, "plots.cluster.resize.other")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.resize.other"))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -374,8 +309,7 @@ public class Cluster extends SubCommand
|
|||||||
//check if overlap
|
//check if overlap
|
||||||
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
||||||
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(world, id);
|
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(world, id);
|
||||||
if (intersects.size() > 1)
|
if (intersects.size() > 1) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
|
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -384,46 +318,36 @@ public class Cluster extends SubCommand
|
|||||||
final HashSet<Plot> removed = ((HashSet<Plot>) existing.clone());
|
final HashSet<Plot> removed = ((HashSet<Plot>) existing.clone());
|
||||||
removed.removeAll(newplots);
|
removed.removeAll(newplots);
|
||||||
// Check expand / shrink
|
// Check expand / shrink
|
||||||
if (removed.size() > 0)
|
if (removed.size() > 0) {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.resize.shrink")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.resize.shrink"))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.shrink");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.shrink");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newplots.removeAll(existing);
|
newplots.removeAll(existing);
|
||||||
if (newplots.size() > 0)
|
if (newplots.size() > 0) {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.resize.expand")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.resize.expand"))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.expand");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.expand");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check allowed cluster size
|
// Check allowed cluster size
|
||||||
int current;
|
int current;
|
||||||
if (Settings.GLOBAL_LIMIT)
|
if (Settings.GLOBAL_LIMIT) {
|
||||||
{
|
|
||||||
current = ClusterManager.getPlayerClusterCount(plr);
|
current = ClusterManager.getPlayerClusterCount(plr);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
current = ClusterManager.getPlayerClusterCount(world, plr);
|
current = ClusterManager.getPlayerClusterCount(world, plr);
|
||||||
}
|
}
|
||||||
current -= cluster.getArea() + (((1 + pos2.x) - pos1.x) * ((1 + pos2.y) - pos1.y));
|
current -= cluster.getArea() + (((1 + pos2.x) - pos1.x) * ((1 + pos2.y) - pos1.y));
|
||||||
final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
|
final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
|
||||||
if ((current + cluster.getArea()) > allowed)
|
if ((current + cluster.getArea()) > allowed) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (final Plot plot : removed)
|
for (final Plot plot : removed) {
|
||||||
{
|
|
||||||
FlagManager.removePlotFlag(plot, "cluster");
|
FlagManager.removePlotFlag(plot, "cluster");
|
||||||
}
|
}
|
||||||
for (final Plot plot : newplots)
|
for (final Plot plot : newplots) {
|
||||||
{
|
|
||||||
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("cluster"), cluster));
|
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("cluster"), cluster));
|
||||||
}
|
}
|
||||||
// resize cluster
|
// resize cluster
|
||||||
@ -433,41 +357,31 @@ public class Cluster extends SubCommand
|
|||||||
}
|
}
|
||||||
case "reg":
|
case "reg":
|
||||||
case "regenerate":
|
case "regenerate":
|
||||||
case "regen":
|
case "regen": {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.delete")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.delete"))
|
|
||||||
{
|
|
||||||
MainUtil.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)) {
|
||||||
{
|
|
||||||
MainUtil.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.getLocation().getWorld(), args[1]);
|
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||||
if (cluster == null)
|
if (cluster == null) {
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.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 (!Permissions.hasPermission(plr, "plots.cluster.regen.other")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.regen.other"))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -479,49 +393,40 @@ public class Cluster extends SubCommand
|
|||||||
}
|
}
|
||||||
case "add":
|
case "add":
|
||||||
case "inv":
|
case "inv":
|
||||||
case "invite":
|
case "invite": {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.invite")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.invite"))
|
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.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
|
||||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||||
if (cluster == null)
|
if (cluster == null) {
|
||||||
{
|
|
||||||
MainUtil.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 (!Permissions.hasPermission(plr, "plots.cluster.invite.other")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.invite.other"))
|
|
||||||
{
|
|
||||||
MainUtil.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
|
||||||
final UUID uuid = UUIDHandler.getUUID(args[1], null);
|
final UUID uuid = UUIDHandler.getUUID(args[1], null);
|
||||||
if (uuid == null)
|
if (uuid == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!cluster.isAdded(uuid))
|
if (!cluster.isAdded(uuid)) {
|
||||||
{
|
|
||||||
// add the user if not added
|
// add the user if not added
|
||||||
cluster.invited.add(uuid);
|
cluster.invited.add(uuid);
|
||||||
final String world = plr.getLocation().getWorld();
|
final String world = plr.getLocation().getWorld();
|
||||||
DBFunc.setInvited(world, cluster, uuid);
|
DBFunc.setInvited(world, cluster, uuid);
|
||||||
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
||||||
if (player != null)
|
if (player != null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
|
MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -530,62 +435,50 @@ public class Cluster extends SubCommand
|
|||||||
}
|
}
|
||||||
case "k":
|
case "k":
|
||||||
case "remove":
|
case "remove":
|
||||||
case "kick":
|
case "kick": {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.kick")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.kick"))
|
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster kick <player>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster kick <player>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||||
if (cluster == null)
|
if (cluster == null) {
|
||||||
{
|
|
||||||
MainUtil.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 (!Permissions.hasPermission(plr, "plots.cluster.kick.other")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.kick.other"))
|
|
||||||
{
|
|
||||||
MainUtil.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
|
||||||
final UUID uuid = UUIDHandler.getUUID(args[1], null);
|
final UUID uuid = UUIDHandler.getUUID(args[1], null);
|
||||||
if (uuid == null)
|
if (uuid == null) {
|
||||||
{
|
|
||||||
MainUtil.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.isAdded(uuid))
|
if (uuid.equals(UUIDHandler.getUUID(plr)) || uuid.equals(cluster.owner) || !cluster.isAdded(uuid)) {
|
||||||
{
|
|
||||||
MainUtil.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)) {
|
||||||
{
|
|
||||||
cluster.helpers.remove(uuid);
|
cluster.helpers.remove(uuid);
|
||||||
DBFunc.removeHelper(cluster, uuid);
|
DBFunc.removeHelper(cluster, uuid);
|
||||||
}
|
}
|
||||||
cluster.invited.remove(uuid);
|
cluster.invited.remove(uuid);
|
||||||
DBFunc.removeInvited(cluster, uuid);
|
DBFunc.removeInvited(cluster, uuid);
|
||||||
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
||||||
if (player != null)
|
if (player != null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
|
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
|
||||||
}
|
}
|
||||||
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid)))
|
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
|
||||||
{
|
|
||||||
final PlotCluster current = ClusterManager.getCluster(plot);
|
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||||
if ((current != null) && current.equals(cluster))
|
if ((current != null) && current.equals(cluster)) {
|
||||||
{
|
|
||||||
plr.getLocation().getWorld();
|
plr.getLocation().getWorld();
|
||||||
plot.unclaim();
|
plot.unclaim();
|
||||||
}
|
}
|
||||||
@ -594,61 +487,48 @@ public class Cluster extends SubCommand
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "quit":
|
case "quit":
|
||||||
case "leave":
|
case "leave": {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.leave")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.leave"))
|
|
||||||
{
|
|
||||||
MainUtil.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)) {
|
||||||
{
|
|
||||||
MainUtil.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.getLocation().getWorld(), args[1]);
|
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||||
if (cluster == null)
|
if (cluster == null) {
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final UUID uuid = UUIDHandler.getUUID(plr);
|
final UUID uuid = UUIDHandler.getUUID(plr);
|
||||||
if (!cluster.isAdded(uuid))
|
if (!cluster.isAdded(uuid)) {
|
||||||
{
|
|
||||||
MainUtil.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)) {
|
||||||
{
|
|
||||||
MainUtil.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)) {
|
||||||
{
|
|
||||||
cluster.helpers.remove(uuid);
|
cluster.helpers.remove(uuid);
|
||||||
DBFunc.removeHelper(cluster, uuid);
|
DBFunc.removeHelper(cluster, uuid);
|
||||||
}
|
}
|
||||||
cluster.invited.remove(uuid);
|
cluster.invited.remove(uuid);
|
||||||
DBFunc.removeInvited(cluster, uuid);
|
DBFunc.removeInvited(cluster, uuid);
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
|
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
|
||||||
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid)))
|
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
|
||||||
{
|
|
||||||
final PlotCluster current = ClusterManager.getCluster(plot);
|
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||||
if ((current != null) && current.equals(cluster))
|
if ((current != null) && current.equals(cluster)) {
|
||||||
{
|
|
||||||
plr.getLocation().getWorld();
|
plr.getLocation().getWorld();
|
||||||
plot.unclaim();
|
plot.unclaim();
|
||||||
}
|
}
|
||||||
@ -657,38 +537,31 @@ public class Cluster extends SubCommand
|
|||||||
}
|
}
|
||||||
case "admin":
|
case "admin":
|
||||||
case "helper":
|
case "helper":
|
||||||
case "helpers":
|
case "helpers": {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.helpers")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.helpers"))
|
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.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;
|
||||||
}
|
}
|
||||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||||
if (cluster == null)
|
if (cluster == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final UUID uuid = UUIDHandler.getUUID(args[2], null);
|
final UUID uuid = UUIDHandler.getUUID(args[2], null);
|
||||||
if (uuid == null)
|
if (uuid == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args[1].toLowerCase().equals("add"))
|
if (args[1].toLowerCase().equals("add")) {
|
||||||
{
|
|
||||||
cluster.helpers.add(uuid);
|
cluster.helpers.add(uuid);
|
||||||
DBFunc.setHelper(cluster, uuid);
|
DBFunc.setHelper(cluster, uuid);
|
||||||
return MainUtil.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);
|
||||||
DBFunc.removeHelper(cluster, uuid);
|
DBFunc.removeHelper(cluster, uuid);
|
||||||
return MainUtil.sendMessage(plr, C.CLUSTER_REMOVED_HELPER);
|
return MainUtil.sendMessage(plr, C.CLUSTER_REMOVED_HELPER);
|
||||||
@ -698,29 +571,23 @@ public class Cluster extends SubCommand
|
|||||||
}
|
}
|
||||||
case "spawn":
|
case "spawn":
|
||||||
case "home":
|
case "home":
|
||||||
case "tp":
|
case "tp": {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.tp")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.tp"))
|
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||||
if (cluster == null)
|
if (cluster == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final UUID uuid = UUIDHandler.getUUID(plr);
|
final UUID uuid = UUIDHandler.getUUID(plr);
|
||||||
if (!cluster.isAdded(uuid))
|
if (!cluster.isAdded(uuid)) {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.tp.other")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.tp.other"))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -731,41 +598,32 @@ public class Cluster extends SubCommand
|
|||||||
case "i":
|
case "i":
|
||||||
case "info":
|
case "info":
|
||||||
case "show":
|
case "show":
|
||||||
case "information":
|
case "information": {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.info")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.info"))
|
|
||||||
{
|
|
||||||
MainUtil.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)) {
|
||||||
{
|
|
||||||
MainUtil.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.getLocation().getWorld(), args[1]);
|
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||||
if (cluster == null)
|
if (cluster == null) {
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final 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";
|
||||||
}
|
}
|
||||||
final String name = cluster.getName();
|
final String name = cluster.getName();
|
||||||
@ -782,28 +640,22 @@ public class Cluster extends SubCommand
|
|||||||
}
|
}
|
||||||
case "sh":
|
case "sh":
|
||||||
case "setspawn":
|
case "setspawn":
|
||||||
case "sethome":
|
case "sethome": {
|
||||||
{
|
if (!Permissions.hasPermission(plr, "plots.cluster.sethome")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.sethome"))
|
|
||||||
{
|
|
||||||
MainUtil.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)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster sethome");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster sethome");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||||
if (cluster == null)
|
if (cluster == null) {
|
||||||
{
|
|
||||||
MainUtil.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 (!Permissions.hasPermission(plr, "plots.cluster.sethome.other")) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.sethome.other"))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,7 @@ package com.intellectualcrafters.plot.commands;
|
|||||||
* CommandCategory
|
* CommandCategory
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public enum CommandCategory
|
public enum CommandCategory {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Claiming Commands
|
* Claiming Commands
|
||||||
*
|
*
|
||||||
@ -46,14 +45,12 @@ public enum CommandCategory
|
|||||||
*
|
*
|
||||||
* @param name readable name
|
* @param name readable name
|
||||||
*/
|
*/
|
||||||
CommandCategory(final String name)
|
CommandCategory(final String name) {
|
||||||
{
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,7 @@ import com.intellectualcrafters.plot.util.Permissions;
|
|||||||
* Created by Citymonstret on 2014-08-03.
|
* Created by Citymonstret on 2014-08-03.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class CommandPermission
|
public class CommandPermission {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Permission Node
|
* Permission Node
|
||||||
*/
|
*/
|
||||||
@ -37,8 +36,7 @@ public class CommandPermission
|
|||||||
/**
|
/**
|
||||||
* @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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,8 +45,7 @@ public class CommandPermission
|
|||||||
*
|
*
|
||||||
* @return true of player has the required permission node
|
* @return true of player has the required permission node
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(final PlotPlayer player)
|
public boolean hasPermission(final PlotPlayer player) {
|
||||||
{
|
|
||||||
return Permissions.hasPermission(player, permission);
|
return Permissions.hasPermission(player, permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,27 +35,17 @@ import com.intellectualcrafters.plot.util.StringMan;
|
|||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "comment", aliases = { "msg" }, description = "Comment on a plot", category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE, permission = "plots.comment")
|
||||||
command = "comment",
|
public class Comment extends SubCommand {
|
||||||
aliases = { "msg" },
|
|
||||||
description = "Comment on a plot",
|
|
||||||
category = CommandCategory.ACTIONS,
|
|
||||||
requiredType = RequiredType.NONE,
|
|
||||||
permission = "plots.comment")
|
|
||||||
public class Comment extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, final String[] args)
|
public boolean onCommand(final PlotPlayer player, final String[] args) {
|
||||||
{
|
if (args.length < 2) {
|
||||||
if (args.length < 2)
|
|
||||||
{
|
|
||||||
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
||||||
if (inbox == null)
|
if (inbox == null) {
|
||||||
{
|
|
||||||
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -63,39 +53,31 @@ public class Comment extends SubCommand
|
|||||||
final Location loc = player.getLocation();
|
final Location loc = player.getLocation();
|
||||||
final PlotId id = PlotId.fromString(args[1]);
|
final PlotId id = PlotId.fromString(args[1]);
|
||||||
int index;
|
int index;
|
||||||
if (id != null)
|
if (id != null) {
|
||||||
{
|
if (args.length < 4) {
|
||||||
if (args.length < 4)
|
|
||||||
{
|
|
||||||
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
index = 2;
|
index = 2;
|
||||||
plot = MainUtil.getPlot(loc.getWorld(), id);
|
plot = MainUtil.getPlot(loc.getWorld(), id);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
index = 1;
|
index = 1;
|
||||||
plot = MainUtil.getPlot(loc);
|
plot = MainUtil.getPlot(loc);
|
||||||
}
|
}
|
||||||
if (!inbox.canWrite(plot, player))
|
if (!inbox.canWrite(plot, player)) {
|
||||||
{
|
|
||||||
sendMessage(player, C.NO_PERM_INBOX, "");
|
sendMessage(player, C.NO_PERM_INBOX, "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String message = StringMan.join(Arrays.copyOfRange(args, index, args.length), " ");
|
final String message = StringMan.join(Arrays.copyOfRange(args, index, args.length), " ");
|
||||||
final PlotComment comment = new PlotComment(loc.getWorld(), id, message, player.getName(), inbox.toString(), System.currentTimeMillis());
|
final PlotComment comment = new PlotComment(loc.getWorld(), id, message, player.getName(), inbox.toString(), System.currentTimeMillis());
|
||||||
final boolean result = inbox.addComment(plot, comment);
|
final boolean result = inbox.addComment(plot, comment);
|
||||||
if (!result)
|
if (!result) {
|
||||||
{
|
|
||||||
sendMessage(player, C.NO_PLOT_INBOX, "");
|
sendMessage(player, C.NO_PLOT_INBOX, "");
|
||||||
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (final PlotPlayer pp : UUIDHandler.getPlayers().values())
|
for (final PlotPlayer pp : UUIDHandler.getPlayers().values()) {
|
||||||
{
|
if (pp.getAttribute("chatspy")) {
|
||||||
if (pp.getAttribute("chatspy"))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(pp, "/plot comment " + StringMan.join(args, " "));
|
MainUtil.sendMessage(pp, "/plot comment " + StringMan.join(args, " "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,52 +35,37 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
|||||||
import com.intellectualcrafters.plot.util.MathMan;
|
import com.intellectualcrafters.plot.util.MathMan;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "condense", permission = "plots.admin", description = "Condense a plotworld", category = CommandCategory.DEBUG, requiredType = RequiredType.CONSOLE)
|
||||||
command = "condense",
|
public class Condense extends SubCommand {
|
||||||
permission = "plots.admin",
|
|
||||||
description = "Condense a plotworld",
|
|
||||||
category = CommandCategory.DEBUG,
|
|
||||||
requiredType = RequiredType.CONSOLE)
|
|
||||||
public class Condense extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
public static boolean TASK = false;
|
public static boolean TASK = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args)
|
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
||||||
{
|
if ((args.length != 2) && (args.length != 3)) {
|
||||||
if ((args.length != 2) && (args.length != 3))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "/plot condense <world> <start|stop|info> [radius]");
|
MainUtil.sendMessage(plr, "/plot condense <world> <start|stop|info> [radius]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String worldname = args[0];
|
final String worldname = args[0];
|
||||||
if (!BlockManager.manager.isWorld(worldname) || !PS.get().isPlotWorld(worldname))
|
if (!BlockManager.manager.isWorld(worldname) || !PS.get().isPlotWorld(worldname)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "INVALID WORLD");
|
MainUtil.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)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (TASK)
|
if (TASK) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "TASK ALREADY STARTED");
|
MainUtil.sendMessage(plr, "TASK ALREADY STARTED");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length == 2)
|
if (args.length == 2) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!MathMan.isInteger(args[2]))
|
if (!MathMan.isInteger(args[2])) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -88,76 +73,61 @@ public class Condense extends SubCommand
|
|||||||
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
|
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
|
||||||
final int size = plots.size();
|
final int size = plots.size();
|
||||||
final 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) {
|
||||||
{
|
|
||||||
MainUtil.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)) {
|
||||||
{
|
|
||||||
final Plot plot = MainUtil.getPlot(worldname, 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);
|
||||||
}
|
}
|
||||||
if ((free.size() == 0) || (to_move.size() == 0))
|
if ((free.size() == 0) || (to_move.size() == 0)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "NO FREE PLOTS FOUND");
|
MainUtil.sendMessage(plr, "NO FREE PLOTS FOUND");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), new Runnable()
|
MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
if (!TASK) {
|
||||||
if (!TASK)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "CONDENSE TASK CANCELLED");
|
MainUtil.sendMessage(plr, "CONDENSE TASK CANCELLED");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
to_move.remove(0);
|
to_move.remove(0);
|
||||||
free.remove(0);
|
free.remove(0);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (final PlotId id : to_move)
|
for (final PlotId id : to_move) {
|
||||||
{
|
|
||||||
final Plot plot = MainUtil.getPlot(worldname, 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 (final PlotId id : free)
|
for (final PlotId id : free) {
|
||||||
{
|
|
||||||
final Plot plot = MainUtil.getPlot(worldname, 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) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "TASK COMPLETE. PLEASE VERIFY THAT NO NEW PLOTS HAVE BEEN CLAIMED DURING TASK.");
|
MainUtil.sendMessage(plr, "TASK COMPLETE. PLEASE VERIFY THAT NO NEW PLOTS HAVE BEEN CLAIMED DURING TASK.");
|
||||||
TASK = false;
|
TASK = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (free.size() == 0)
|
if (free.size() == 0) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "TASK FAILED. NO FREE PLOTS FOUND!");
|
MainUtil.sendMessage(plr, "TASK FAILED. NO FREE PLOTS FOUND!");
|
||||||
TASK = false;
|
TASK = false;
|
||||||
return;
|
return;
|
||||||
@ -170,10 +140,8 @@ public class Condense extends SubCommand
|
|||||||
MainUtil.sendMessage(plr, "TASK STARTED...");
|
MainUtil.sendMessage(plr, "TASK STARTED...");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "stop":
|
case "stop": {
|
||||||
{
|
if (!TASK) {
|
||||||
if (!TASK)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "TASK ALREADY STOPPED");
|
MainUtil.sendMessage(plr, "TASK ALREADY STOPPED");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -181,15 +149,12 @@ public class Condense extends SubCommand
|
|||||||
MainUtil.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)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "/plot condense " + worldname + " info <radius>");
|
MainUtil.sendMessage(plr, "/plot condense " + worldname + " info <radius>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!MathMan.isInteger(args[2]))
|
if (!MathMan.isInteger(args[2])) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -197,8 +162,7 @@ public class Condense extends SubCommand
|
|||||||
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
|
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
|
||||||
final int size = plots.size();
|
final int size = plots.size();
|
||||||
final 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) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
|
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -219,13 +183,10 @@ public class Condense extends SubCommand
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<PlotId> getPlots(final Collection<Plot> plots, final int radius)
|
public Set<PlotId> getPlots(final Collection<Plot> plots, final int radius) {
|
||||||
{
|
|
||||||
final HashSet<PlotId> outside = new HashSet<>();
|
final HashSet<PlotId> outside = new HashSet<>();
|
||||||
for (final 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,26 +28,18 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
|||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "confirm", permission = "plots.use", description = "Confirm an action", category = CommandCategory.ACTIONS)
|
||||||
command = "confirm",
|
public class Confirm extends SubCommand {
|
||||||
permission = "plots.use",
|
|
||||||
description = "Confirm an action",
|
|
||||||
category = CommandCategory.ACTIONS)
|
|
||||||
public class Confirm extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args)
|
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
||||||
{
|
|
||||||
final CmdInstance command = CmdConfirm.getPending(plr);
|
final CmdInstance command = CmdConfirm.getPending(plr);
|
||||||
if (command == null)
|
if (command == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
|
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
CmdConfirm.removePending(plr);
|
CmdConfirm.removePending(plr);
|
||||||
if ((System.currentTimeMillis() - command.timestamp) > 20000)
|
if ((System.currentTimeMillis() - command.timestamp) > 20000) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
|
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -36,32 +36,28 @@ description = "Continue a plot that was previously marked as done",
|
|||||||
permission = "plots.continue",
|
permission = "plots.continue",
|
||||||
category = CommandCategory.ACTIONS,
|
category = CommandCategory.ACTIONS,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Continue extends SubCommand
|
public class Continue extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final Plot plot = MainUtil.getPlot(loc);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if ((plot == null) || !plot.hasOwner()) { return !sendMessage(plr, C.NOT_IN_PLOT); }
|
if ((plot == null) || !plot.hasOwner()) {
|
||||||
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.continue"))
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
{
|
}
|
||||||
|
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.continue")) {
|
||||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.getSettings().flags.containsKey("done"))
|
if (!plot.getSettings().flags.containsKey("done")) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.DONE_NOT_DONE);
|
MainUtil.sendMessage(plr, C.DONE_NOT_DONE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Settings.DONE_COUNTS_TOWARDS_LIMIT && (MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)))
|
if (Settings.DONE_COUNTS_TOWARDS_LIMIT && (MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr))) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.continue");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.continue");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (MainUtil.runners.containsKey(plot))
|
if (MainUtil.runners.containsKey(plot)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -38,54 +38,43 @@ category = CommandCategory.ACTIONS,
|
|||||||
description = "Copy a plot",
|
description = "Copy a plot",
|
||||||
usage = "/plot copy <X;Z>",
|
usage = "/plot copy <X;Z>",
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Copy extends SubCommand
|
public class Copy extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
public Copy()
|
public Copy() {
|
||||||
{
|
requiredArguments = new Argument[] { Argument.PlotID };
|
||||||
requiredArguments = new Argument[] {
|
|
||||||
Argument.PlotID
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args)
|
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
||||||
{
|
|
||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final Plot plot1 = MainUtil.getPlot(loc);
|
final Plot plot1 = MainUtil.getPlot(loc);
|
||||||
if (plot1 == null) { return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT); }
|
if (plot1 == null) {
|
||||||
if (!plot1.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s()))
|
return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
{
|
}
|
||||||
|
if (!plot1.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s())) {
|
||||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String world = loc.getWorld();
|
final String world = loc.getWorld();
|
||||||
final PlotId plot2 = MainUtil.parseId(args[0]);
|
final PlotId plot2 = MainUtil.parseId(args[0]);
|
||||||
if ((plot2 == null))
|
if ((plot2 == null)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot1.id.equals(plot2))
|
if (plot1.id.equals(plot2)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (MainUtil.copy(world, plot1.id, plot2, new Runnable()
|
if (MainUtil.copy(world, plot1.id, plot2, new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.COPY_SUCCESS);
|
MainUtil.sendMessage(plr, C.COPY_SUCCESS);
|
||||||
}
|
}
|
||||||
}))
|
})) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.REQUIRES_UNOWNED);
|
MainUtil.sendMessage(plr, C.REQUIRES_UNOWNED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -38,16 +38,18 @@ requiredType = RequiredType.NONE,
|
|||||||
permission = "plots.createroadschematic",
|
permission = "plots.createroadschematic",
|
||||||
description = "Add a road schematic to your world using the roads around your current plot",
|
description = "Add a road schematic to your world using the roads around your current plot",
|
||||||
usage = "/plot createroadschematic")
|
usage = "/plot createroadschematic")
|
||||||
public class CreateRoadSchematic extends SubCommand
|
public class CreateRoadSchematic extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, final String... args)
|
public boolean onCommand(final PlotPlayer player, final String... args) {
|
||||||
{
|
|
||||||
final Location loc = player.getLocation();
|
final Location loc = player.getLocation();
|
||||||
final Plot plot = MainUtil.getPlot(loc);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if (plot == null) { return sendMessage(player, C.NOT_IN_PLOT); }
|
if (plot == null) {
|
||||||
if (!(PS.get().getPlotWorld(loc.getWorld()) instanceof HybridPlotWorld)) { return sendMessage(player, C.NOT_IN_PLOT_WORLD); }
|
return sendMessage(player, C.NOT_IN_PLOT);
|
||||||
|
}
|
||||||
|
if (!(PS.get().getPlotWorld(loc.getWorld()) instanceof HybridPlotWorld)) {
|
||||||
|
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
|
||||||
|
}
|
||||||
HybridUtils.manager.setupRoadSchematic(plot);
|
HybridUtils.manager.setupRoadSchematic(plot);
|
||||||
MainUtil.sendMessage(player, "&6Saved new road schematic. To test the road, fly to a few other plots and use /plot debugroadregen");
|
MainUtil.sendMessage(player, "&6Saved new road schematic. To test the road, fly to a few other plots and use /plot debugroadregen");
|
||||||
return true;
|
return true;
|
||||||
|
@ -28,36 +28,26 @@ requiredType = RequiredType.CONSOLE,
|
|||||||
usage = "/plots database [world] <sqlite|mysql|import>"
|
usage = "/plots database [world] <sqlite|mysql|import>"
|
||||||
|
|
||||||
)
|
)
|
||||||
public class Database extends SubCommand
|
public class Database extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
public static void insertPlots(final SQLManager manager, final ArrayList<Plot> plots, final PlotPlayer player)
|
public static void insertPlots(final SQLManager manager, final ArrayList<Plot> plots, final PlotPlayer player) {
|
||||||
{
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
TaskManager.runTaskAsync(new Runnable()
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final ArrayList<Plot> ps = new ArrayList<>();
|
final ArrayList<Plot> ps = new ArrayList<>();
|
||||||
for (final Plot p : plots)
|
for (final Plot p : plots) {
|
||||||
{
|
|
||||||
ps.add(p);
|
ps.add(p);
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, "&6Starting...");
|
MainUtil.sendMessage(player, "&6Starting...");
|
||||||
manager.createPlotsAndData(ps, new Runnable()
|
manager.createPlotsAndData(ps, new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "&6Database conversion finished!");
|
MainUtil.sendMessage(player, "&6Database conversion finished!");
|
||||||
manager.close();
|
manager.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "Failed to insert plot objects, see stacktrace for info");
|
MainUtil.sendMessage(player, "Failed to insert plot objects, see stacktrace for info");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -66,39 +56,29 @@ public class Database extends SubCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, String[] args)
|
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||||
{
|
if (args.length < 1) {
|
||||||
if (args.length < 1)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql>");
|
MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ArrayList<Plot> plots;
|
ArrayList<Plot> plots;
|
||||||
if (PS.get().isPlotWorld(args[0]))
|
if (PS.get().isPlotWorld(args[0])) {
|
||||||
{
|
|
||||||
plots = PS.get().sortPlotsByTemp(PS.get().getPlotsInWorld(args[0]));
|
plots = PS.get().sortPlotsByTemp(PS.get().getPlotsInWorld(args[0]));
|
||||||
args = Arrays.copyOfRange(args, 1, args.length);
|
args = Arrays.copyOfRange(args, 1, args.length);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
plots = PS.get().sortPlotsByTemp(PS.get().getPlotsRaw());
|
plots = PS.get().sortPlotsByTemp(PS.get().getPlotsRaw());
|
||||||
}
|
}
|
||||||
if (args.length < 1)
|
if (args.length < 1) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql|import>");
|
MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql|import>");
|
||||||
MainUtil.sendMessage(player, "[arg] indicates an optional argument");
|
MainUtil.sendMessage(player, "[arg] indicates an optional argument");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
com.intellectualcrafters.plot.database.Database implementation;
|
com.intellectualcrafters.plot.database.Database implementation;
|
||||||
String prefix = "";
|
String prefix = "";
|
||||||
switch (args[0].toLowerCase())
|
switch (args[0].toLowerCase()) {
|
||||||
{
|
case "import": {
|
||||||
case "import":
|
if (args.length < 2) {
|
||||||
{
|
|
||||||
if (args.length < 2)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "/plot database import [sqlite file] [prefix]");
|
MainUtil.sendMessage(player, "/plot database import [sqlite file] [prefix]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -107,13 +87,10 @@ public class Database extends SubCommand
|
|||||||
final SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true);
|
final SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true);
|
||||||
final ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> map = manager.getPlots();
|
final ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> map = manager.getPlots();
|
||||||
plots = new ArrayList<Plot>();
|
plots = new ArrayList<Plot>();
|
||||||
for (final Entry<String, ConcurrentHashMap<PlotId, Plot>> entry : map.entrySet())
|
for (final Entry<String, ConcurrentHashMap<PlotId, Plot>> entry : map.entrySet()) {
|
||||||
{
|
for (final Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
|
||||||
for (final Entry<PlotId, Plot> entry2 : entry.getValue().entrySet())
|
|
||||||
{
|
|
||||||
final Plot plot = entry2.getValue();
|
final Plot plot = entry2.getValue();
|
||||||
if (PS.get().getPlot(plot.world, plot.id) != null)
|
if (PS.get().getPlot(plot.world, plot.id) != null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "Skipping duplicate plot: " + plot + " | id=" + plot.temp);
|
MainUtil.sendMessage(player, "Skipping duplicate plot: " + plot + " | id=" + plot.temp);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -121,44 +98,42 @@ public class Database extends SubCommand
|
|||||||
plots.add(entry2.getValue());
|
plots.add(entry2.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DBFunc.createPlotsAndData(plots, new Runnable()
|
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "&6Database conversion finished!");
|
MainUtil.sendMessage(player, "&6Database conversion finished!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "mysql":
|
case "mysql":
|
||||||
if (args.length < 6) { return MainUtil.sendMessage(player, "/plot database mysql [host] [port] [username] [password] [database] {prefix}"); }
|
if (args.length < 6) {
|
||||||
|
return MainUtil.sendMessage(player, "/plot database mysql [host] [port] [username] [password] [database] {prefix}");
|
||||||
|
}
|
||||||
final String host = args[1];
|
final String host = args[1];
|
||||||
final String port = args[2];
|
final String port = args[2];
|
||||||
final String username = args[3];
|
final String username = args[3];
|
||||||
final String password = args[4];
|
final String password = args[4];
|
||||||
final String database = args[5];
|
final String database = args[5];
|
||||||
if (args.length > 6)
|
if (args.length > 6) {
|
||||||
{
|
|
||||||
prefix = args[6];
|
prefix = args[6];
|
||||||
}
|
}
|
||||||
implementation = new MySQL(host, port, database, username, password);
|
implementation = new MySQL(host, port, database, username, password);
|
||||||
break;
|
break;
|
||||||
case "sqlite":
|
case "sqlite":
|
||||||
if (args.length < 2) { return MainUtil.sendMessage(player, "/plot database sqlite [file]"); }
|
if (args.length < 2) {
|
||||||
|
return MainUtil.sendMessage(player, "/plot database sqlite [file]");
|
||||||
|
}
|
||||||
implementation = new SQLite(PS.get().IMP.getDirectory() + File.separator + args[1] + ".db");
|
implementation = new SQLite(PS.get().IMP.getDirectory() + File.separator + args[1] + ".db");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return MainUtil.sendMessage(player, "/plot database [sqlite/mysql]");
|
return MainUtil.sendMessage(player, "/plot database [sqlite/mysql]");
|
||||||
}
|
}
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
final SQLManager manager = new SQLManager(implementation, prefix, true);
|
final SQLManager manager = new SQLManager(implementation, prefix, true);
|
||||||
insertPlots(manager, plots, player);
|
insertPlots(manager, plots, player);
|
||||||
return true;
|
return true;
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "$1Failed to save plots, read stacktrace for info");
|
MainUtil.sendMessage(player, "$1Failed to save plots, read stacktrace for info");
|
||||||
MainUtil.sendMessage(player, "&d==== Here is an ugly stacktrace, if you are interested in those things ===");
|
MainUtil.sendMessage(player, "&d==== Here is an ugly stacktrace, if you are interested in those things ===");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -166,9 +141,7 @@ public class Database extends SubCommand
|
|||||||
MainUtil.sendMessage(player, "$1Please make sure you are using the correct arguments!");
|
MainUtil.sendMessage(player, "$1Please make sure you are using the correct arguments!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "$1Failed to open connection, read stacktrace for info");
|
MainUtil.sendMessage(player, "$1Failed to open connection, read stacktrace for info");
|
||||||
MainUtil.sendMessage(player, "&d==== Here is an ugly stacktrace, if you are interested in those things ===");
|
MainUtil.sendMessage(player, "&d==== Here is an ugly stacktrace, if you are interested in those things ===");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -27,23 +27,14 @@ import com.intellectualcrafters.plot.util.Lag;
|
|||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "debug", category = CommandCategory.DEBUG, description = "Show debug information", usage = "/plot debug [msg]", permission = "plots.admin")
|
||||||
command = "debug",
|
public class Debug extends SubCommand {
|
||||||
category = CommandCategory.DEBUG,
|
|
||||||
description = "Show debug information",
|
|
||||||
usage = "/plot debug [msg]",
|
|
||||||
permission = "plots.admin")
|
|
||||||
public class Debug extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(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");
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(plr, msg.toString());
|
MainUtil.sendMessage(plr, msg.toString());
|
||||||
@ -59,8 +50,7 @@ public class Debug extends SubCommand
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
final StringBuilder worlds = new StringBuilder("");
|
final StringBuilder worlds = new StringBuilder("");
|
||||||
for (final String world : PS.get().getPlotWorlds())
|
for (final String world : PS.get().getPlotWorlds()) {
|
||||||
{
|
|
||||||
worlds.append(world).append(" ");
|
worlds.append(world).append(" ");
|
||||||
}
|
}
|
||||||
information.append(header);
|
information.append(header);
|
||||||
@ -81,13 +71,11 @@ public class Debug extends SubCommand
|
|||||||
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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,22 +15,17 @@ usage = "/plot debugallowunsafe",
|
|||||||
category = CommandCategory.DEBUG,
|
category = CommandCategory.DEBUG,
|
||||||
requiredType = RequiredType.NONE,
|
requiredType = RequiredType.NONE,
|
||||||
permission = "plots.debugallowunsafe")
|
permission = "plots.debugallowunsafe")
|
||||||
public class DebugAllowUnsafe extends SubCommand
|
public class DebugAllowUnsafe extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
public static final List<UUID> unsafeAllowed = new ArrayList<>();
|
public static final List<UUID> unsafeAllowed = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args)
|
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
||||||
{
|
|
||||||
|
|
||||||
if (unsafeAllowed.contains(plr.getUUID()))
|
if (unsafeAllowed.contains(plr.getUUID())) {
|
||||||
{
|
|
||||||
unsafeAllowed.remove(plr.getUUID());
|
unsafeAllowed.remove(plr.getUUID());
|
||||||
sendMessage(plr, C.DEBUGALLOWUNSAFE_OFF);
|
sendMessage(plr, C.DEBUGALLOWUNSAFE_OFF);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
unsafeAllowed.add(plr.getUUID());
|
unsafeAllowed.add(plr.getUUID());
|
||||||
sendMessage(plr, C.DEBUGALLOWUNSAFE_ON);
|
sendMessage(plr, C.DEBUGALLOWUNSAFE_ON);
|
||||||
}
|
}
|
||||||
|
@ -48,24 +48,19 @@ description = "If you accidentally delete your database, this command will attem
|
|||||||
category = CommandCategory.DEBUG,
|
category = CommandCategory.DEBUG,
|
||||||
requiredType = RequiredType.CONSOLE,
|
requiredType = RequiredType.CONSOLE,
|
||||||
permission = "plots.debugclaimtest")
|
permission = "plots.debugclaimtest")
|
||||||
public class DebugClaimTest extends SubCommand
|
public class DebugClaimTest extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport)
|
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport) {
|
||||||
{
|
|
||||||
return claimPlot(player, plot, teleport, "");
|
return claimPlot(player, plot, teleport, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic)
|
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic) {
|
||||||
{
|
|
||||||
final boolean result = EventUtil.manager.callClaim(player, plot, false);
|
final boolean result = EventUtil.manager.callClaim(player, plot, false);
|
||||||
if (result)
|
if (result) {
|
||||||
{
|
|
||||||
MainUtil.createPlot(player.getUUID(), plot);
|
MainUtil.createPlot(player.getUUID(), plot);
|
||||||
MainUtil.setSign(player.getName(), plot);
|
MainUtil.setSign(player.getName(), plot);
|
||||||
MainUtil.sendMessage(player, C.CLAIMED);
|
MainUtil.sendMessage(player, C.CLAIMED);
|
||||||
if (teleport)
|
if (teleport) {
|
||||||
{
|
|
||||||
MainUtil.teleportPlayer(player, player.getLocation(), plot);
|
MainUtil.teleportPlayer(player, player.getLocation(), plot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,24 +68,24 @@ public class DebugClaimTest extends SubCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
if (args.length < 3) {
|
||||||
if (args.length < 3) { return !MainUtil
|
return !MainUtil
|
||||||
.sendMessage(
|
.sendMessage(
|
||||||
null,
|
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}"); }
|
"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 String world = args[0];
|
final String world = args[0];
|
||||||
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) { return !MainUtil.sendMessage(null, "&cInvalid plot world!"); }
|
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) {
|
||||||
|
return !MainUtil.sendMessage(null, "&cInvalid plot world!");
|
||||||
|
}
|
||||||
PlotId min, max;
|
PlotId min, max;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
args[1].split(";");
|
args[1].split(";");
|
||||||
args[2].split(";");
|
args[2].split(";");
|
||||||
min = PlotId.fromString(args[1]);
|
min = PlotId.fromString(args[1]);
|
||||||
max = PlotId.fromString(args[2]);
|
max = PlotId.fromString(args[2]);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
return !MainUtil.sendMessage(null,
|
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.");
|
"&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.");
|
||||||
}
|
}
|
||||||
@ -99,77 +94,59 @@ public class DebugClaimTest extends SubCommand
|
|||||||
final PlotManager manager = PS.get().getPlotManager(world);
|
final PlotManager manager = PS.get().getPlotManager(world);
|
||||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
final PlotWorld plotworld = PS.get().getPlotWorld(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 : MainUtil.getPlotSelectionIds(min, max)) {
|
||||||
{
|
|
||||||
final Plot plot = MainUtil.getPlot(world, id);
|
final Plot plot = MainUtil.getPlot(world, id);
|
||||||
if (PS.get().getPlot(world, plot.id) != null)
|
if (PS.get().getPlot(world, plot.id) != null) {
|
||||||
{
|
|
||||||
MainUtil.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(plotworld, plot);
|
||||||
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
||||||
final boolean result = ChunkManager.manager.loadChunk(world, chunk, false);
|
final boolean result = ChunkManager.manager.loadChunk(world, chunk, false);
|
||||||
if (!result)
|
if (!result) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final String[] lines = BlockManager.manager.getSign(loc);
|
final String[] lines = BlockManager.manager.getSign(loc);
|
||||||
if (lines != null)
|
if (lines != null) {
|
||||||
{
|
|
||||||
String line = lines[2];
|
String line = lines[2];
|
||||||
if ((line != null) && (line.length() > 2))
|
if ((line != null) && (line.length() > 2)) {
|
||||||
{
|
|
||||||
line = line.substring(2);
|
line = line.substring(2);
|
||||||
final BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
|
final BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
|
||||||
UUID uuid = (map.get(new StringWrapper(line)));
|
UUID uuid = (map.get(new StringWrapper(line)));
|
||||||
if (uuid == null)
|
if (uuid == null) {
|
||||||
{
|
for (final StringWrapper string : map.keySet()) {
|
||||||
for (final StringWrapper string : map.keySet())
|
if (string.value.toLowerCase().startsWith(line.toLowerCase())) {
|
||||||
{
|
|
||||||
if (string.value.toLowerCase().startsWith(line.toLowerCase()))
|
|
||||||
{
|
|
||||||
uuid = map.get(string);
|
uuid = map.get(string);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uuid == null)
|
if (uuid == null) {
|
||||||
{
|
|
||||||
uuid = UUIDHandler.getUUID(line, null);
|
uuid = UUIDHandler.getUUID(line, null);
|
||||||
}
|
}
|
||||||
if (uuid != null)
|
if (uuid != null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line);
|
MainUtil.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line);
|
||||||
plot.owner = uuid;
|
plot.owner = uuid;
|
||||||
plots.add(plot);
|
plots.add(plot);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
|
MainUtil.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (plots.size() > 0)
|
if (plots.size() > 0) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
|
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
|
||||||
DBFunc.createPlotsAndData(plots, new Runnable()
|
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(null, "&6Database update finished!");
|
MainUtil.sendMessage(null, "&6Database update finished!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (final Plot plot : plots)
|
for (final Plot plot : plots) {
|
||||||
{
|
|
||||||
PS.get().updatePlot(plot);
|
PS.get().updatePlot(plot);
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
|
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(null, "No plots were found for the given search.");
|
MainUtil.sendMessage(null, "No plots were found for the given search.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -32,35 +32,32 @@ import com.intellectualcrafters.plot.util.Permissions;
|
|||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "debugclear", aliases = { "fastclear" }, description = "Clear a plot using a fast experiment algorithm", category = CommandCategory.DEBUG)
|
||||||
command = "debugclear",
|
public class DebugClear extends SubCommand {
|
||||||
aliases = { "fastclear" },
|
|
||||||
description = "Clear a plot using a fast experiment algorithm",
|
|
||||||
category = CommandCategory.DEBUG)
|
|
||||||
public class DebugClear extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final Plot plot = MainUtil.getPlot(loc);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if ((plot == null) || !(PS.get().getPlotWorld(loc.getWorld()) instanceof SquarePlotWorld)) { return sendMessage(plr, C.NOT_IN_PLOT); }
|
if ((plot == null) || !(PS.get().getPlotWorld(loc.getWorld()) instanceof SquarePlotWorld)) {
|
||||||
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return sendMessage(plr, C.UNLINK_REQUIRED); }
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
if ((!plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.debugclear")) { return sendMessage(plr, C.NO_PLOT_PERMS); }
|
}
|
||||||
|
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||||
|
return sendMessage(plr, C.UNLINK_REQUIRED);
|
||||||
|
}
|
||||||
|
if ((!plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.debugclear")) {
|
||||||
|
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
|
}
|
||||||
final Location pos1 = MainUtil.getPlotBottomLoc(loc.getWorld(), plot.id).add(1, 0, 1);
|
final Location pos1 = MainUtil.getPlotBottomLoc(loc.getWorld(), plot.id).add(1, 0, 1);
|
||||||
final Location pos2 = MainUtil.getPlotTopLoc(loc.getWorld(), plot.id);
|
final Location pos2 = MainUtil.getPlotTopLoc(loc.getWorld(), plot.id);
|
||||||
if (MainUtil.runners.containsKey(plot))
|
if (MainUtil.runners.containsKey(plot)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MainUtil.runners.put(plot, 1);
|
MainUtil.runners.put(plot, 1);
|
||||||
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable()
|
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.runners.remove(plot);
|
MainUtil.runners.remove(plot);
|
||||||
MainUtil.sendMessage(plr, "&aDone!");
|
MainUtil.sendMessage(plr, "&aDone!");
|
||||||
}
|
}
|
||||||
|
@ -74,25 +74,16 @@ import com.plotsquared.bukkit.util.BukkitHybridUtils;
|
|||||||
import com.plotsquared.general.commands.Command;
|
import com.plotsquared.general.commands.Command;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "debugexec", permission = "plots.admin", description = "Mutli-purpose debug command", aliases = { "exec" }, category = CommandCategory.DEBUG)
|
||||||
command = "debugexec",
|
public class DebugExec extends SubCommand {
|
||||||
permission = "plots.admin",
|
|
||||||
description = "Mutli-purpose debug command",
|
|
||||||
aliases = { "exec" },
|
|
||||||
category = CommandCategory.DEBUG)
|
|
||||||
public class DebugExec extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
private ScriptEngine engine;
|
private ScriptEngine engine;
|
||||||
private Bindings scope;
|
private Bindings scope;
|
||||||
|
|
||||||
public DebugExec()
|
public DebugExec() {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final File file = new File(PS.get().IMP.getDirectory(), "scripts" + File.separator + "start.js");
|
final File file = new File(PS.get().IMP.getDirectory(), "scripts" + File.separator + "start.js");
|
||||||
if (file.exists())
|
if (file.exists()) {
|
||||||
{
|
|
||||||
init();
|
init();
|
||||||
final String script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), "start.js"), StandardCharsets.UTF_8),
|
final String script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), "start.js"), StandardCharsets.UTF_8),
|
||||||
System.getProperty("line.separator"));
|
System.getProperty("line.separator"));
|
||||||
@ -100,27 +91,23 @@ public class DebugExec extends SubCommand
|
|||||||
scope.put("PlotPlayer", ConsolePlayer.getConsole());
|
scope.put("PlotPlayer", ConsolePlayer.getConsole());
|
||||||
engine.eval(script, scope);
|
engine.eval(script, scope);
|
||||||
}
|
}
|
||||||
}
|
} catch (final Exception e) {}
|
||||||
catch (final Exception e)
|
|
||||||
{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptEngine getEngine()
|
public ScriptEngine getEngine() {
|
||||||
{
|
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bindings getScope()
|
public Bindings getScope() {
|
||||||
{
|
|
||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init()
|
public void init() {
|
||||||
{
|
if (engine != null) {
|
||||||
if (engine != null) { return; }
|
return;
|
||||||
|
}
|
||||||
engine = (new ScriptEngineManager(null)).getEngineByName("nashorn");
|
engine = (new ScriptEngineManager(null)).getEngineByName("nashorn");
|
||||||
if (engine == null)
|
if (engine == null) {
|
||||||
{
|
|
||||||
engine = (new ScriptEngineManager(null)).getEngineByName("JavaScript");
|
engine = (new ScriptEngineManager(null)).getEngineByName("JavaScript");
|
||||||
}
|
}
|
||||||
final ScriptContext context = new SimpleScriptContext();
|
final ScriptContext context = new SimpleScriptContext();
|
||||||
@ -159,141 +146,108 @@ public class DebugExec extends SubCommand
|
|||||||
scope.put("MainCommand", MainCommand.getInstance());
|
scope.put("MainCommand", MainCommand.getInstance());
|
||||||
|
|
||||||
// enums
|
// enums
|
||||||
for (final Enum<?> value : C.values())
|
for (final Enum<?> value : C.values()) {
|
||||||
{
|
|
||||||
scope.put("C_" + value.name(), value);
|
scope.put("C_" + value.name(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, final String... args)
|
public boolean onCommand(final PlotPlayer player, final String... args) {
|
||||||
{
|
|
||||||
final List<String> allowed_params = Arrays.asList("calibrate-analysis", "remove-flag", "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "trim-check");
|
final List<String> allowed_params = Arrays.asList("calibrate-analysis", "remove-flag", "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "trim-check");
|
||||||
if (args.length > 0)
|
if (args.length > 0) {
|
||||||
{
|
|
||||||
final String arg = args[0].toLowerCase();
|
final String arg = args[0].toLowerCase();
|
||||||
String script;
|
String script;
|
||||||
boolean async = false;
|
boolean async = false;
|
||||||
switch (arg)
|
switch (arg) {
|
||||||
{
|
case "analyze": {
|
||||||
case "analyze":
|
|
||||||
{
|
|
||||||
final Plot plot = MainUtil.getPlot(player.getLocation());
|
final Plot plot = MainUtil.getPlot(player.getLocation());
|
||||||
if (plot == null)
|
if (plot == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlotAnalysis analysis = plot.getComplexity();
|
final PlotAnalysis analysis = plot.getComplexity();
|
||||||
if (analysis != null)
|
if (analysis != null) {
|
||||||
{
|
|
||||||
final int complexity = analysis.getComplexity();
|
final int complexity = analysis.getComplexity();
|
||||||
MainUtil.sendMessage(player, "Changes: " + analysis.changes);
|
MainUtil.sendMessage(player, "Changes: " + analysis.changes);
|
||||||
MainUtil.sendMessage(player, "Complexity: " + complexity);
|
MainUtil.sendMessage(player, "Complexity: " + complexity);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, "$1Starting task...");
|
MainUtil.sendMessage(player, "$1Starting task...");
|
||||||
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>()
|
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "$1Done: $2use $3/plot debugexec analyze$2 for more information");
|
MainUtil.sendMessage(player, "$1Done: $2use $3/plot debugexec analyze$2 for more information");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "calibrate-analysis":
|
case "calibrate-analysis": {
|
||||||
{
|
if (args.length != 2) {
|
||||||
if (args.length != 2)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec analyze <threshold>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec analyze <threshold>");
|
||||||
MainUtil.sendMessage(player, "$1<threshold> $2= $1The percentage of plots you want to clear (100 clears 100% of plots so no point calibrating it)");
|
MainUtil.sendMessage(player, "$1<threshold> $2= $1The percentage of plots you want to clear (100 clears 100% of plots so no point calibrating it)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
double threshold;
|
double threshold;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
threshold = Integer.parseInt(args[1]) / 100d;
|
threshold = Integer.parseInt(args[1]) / 100d;
|
||||||
}
|
} catch (final NumberFormatException e) {
|
||||||
catch (final NumberFormatException e)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "$2Invalid threshold: " + args[1]);
|
MainUtil.sendMessage(player, "$2Invalid threshold: " + args[1]);
|
||||||
MainUtil.sendMessage(player, "$1<threshold> $2= $1The percentage of plots you want to clear as a number between 0 - 100");
|
MainUtil.sendMessage(player, "$1<threshold> $2= $1The percentage of plots you want to clear as a number between 0 - 100");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotAnalysis.calcOptimalModifiers(new Runnable()
|
PlotAnalysis.calcOptimalModifiers(new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "$1Thank you for calibrating PlotSquared plot expiry");
|
MainUtil.sendMessage(player, "$1Thank you for calibrating PlotSquared plot expiry");
|
||||||
}
|
}
|
||||||
}, threshold);
|
}, threshold);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "stop-expire":
|
case "stop-expire": {
|
||||||
{
|
if (ExpireManager.task != -1) {
|
||||||
if (ExpireManager.task != -1)
|
|
||||||
{
|
|
||||||
PS.get().TASK.cancelTask(ExpireManager.task);
|
PS.get().TASK.cancelTask(ExpireManager.task);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return MainUtil.sendMessage(player, "Task already halted");
|
return MainUtil.sendMessage(player, "Task already halted");
|
||||||
}
|
}
|
||||||
ExpireManager.task = -1;
|
ExpireManager.task = -1;
|
||||||
return MainUtil.sendMessage(player, "Cancelled task.");
|
return MainUtil.sendMessage(player, "Cancelled task.");
|
||||||
}
|
}
|
||||||
case "remove-flag":
|
case "remove-flag": {
|
||||||
{
|
if (args.length != 2) {
|
||||||
if (args.length != 2)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec remove-flag <flag>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec remove-flag <flag>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String flag = args[1];
|
final String flag = args[1];
|
||||||
for (final Plot plot : PS.get().getPlots())
|
for (final Plot plot : PS.get().getPlots()) {
|
||||||
{
|
if (FlagManager.getPlotFlag(plot, flag) != null) {
|
||||||
if (FlagManager.getPlotFlag(plot, flag) != null)
|
|
||||||
{
|
|
||||||
FlagManager.removePlotFlag(plot, flag);
|
FlagManager.removePlotFlag(plot, flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
|
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
|
||||||
}
|
}
|
||||||
case "start-rgar":
|
case "start-rgar": {
|
||||||
{
|
if (args.length != 2) {
|
||||||
if (args.length != 2)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "&cInvalid syntax: /plot debugexec start-rgar <world>");
|
MainUtil.sendMessage(player, "&cInvalid syntax: /plot debugexec start-rgar <world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean result;
|
boolean result;
|
||||||
if (!PS.get().isPlotWorld(args[1]))
|
if (!PS.get().isPlotWorld(args[1])) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[1]);
|
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (HybridUtils.regions != null)
|
if (HybridUtils.regions != null) {
|
||||||
{
|
|
||||||
result = ((BukkitHybridUtils) (HybridUtils.manager)).scheduleRoadUpdate(args[1], HybridUtils.regions, 0);
|
result = ((BukkitHybridUtils) (HybridUtils.manager)).scheduleRoadUpdate(args[1], HybridUtils.regions, 0);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
result = HybridUtils.manager.scheduleRoadUpdate(args[1], 0);
|
result = HybridUtils.manager.scheduleRoadUpdate(args[1], 0);
|
||||||
}
|
}
|
||||||
if (!result)
|
if (!result) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "&cCannot schedule mass schematic update! (Is one already in progress?)");
|
MainUtil.sendMessage(player, "&cCannot schedule mass schematic update! (Is one already in progress?)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "stop-rgar":
|
case "stop-rgar": {
|
||||||
{
|
if (!HybridUtils.UPDATE) {
|
||||||
if (!HybridUtils.UPDATE)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "&cTASK NOT RUNNING!");
|
MainUtil.sendMessage(player, "&cTASK NOT RUNNING!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -301,53 +255,55 @@ public class DebugExec extends SubCommand
|
|||||||
MainUtil.sendMessage(player, "&cCancelling task... (please wait)");
|
MainUtil.sendMessage(player, "&cCancelling task... (please wait)");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "start-expire":
|
case "start-expire": {
|
||||||
{
|
if (ExpireManager.task == -1) {
|
||||||
if (ExpireManager.task == -1)
|
|
||||||
{
|
|
||||||
ExpireManager.runTask();
|
ExpireManager.runTask();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return MainUtil.sendMessage(player, "Plot expiry task already started");
|
return MainUtil.sendMessage(player, "Plot expiry task already started");
|
||||||
}
|
}
|
||||||
return MainUtil.sendMessage(player, "Started plot expiry task");
|
return MainUtil.sendMessage(player, "Started plot expiry task");
|
||||||
}
|
}
|
||||||
case "update-expired":
|
case "update-expired": {
|
||||||
{
|
if (args.length > 1) {
|
||||||
if (args.length > 1)
|
|
||||||
{
|
|
||||||
final String world = args[1];
|
final String world = args[1];
|
||||||
if (!BlockManager.manager.isWorld(world)) { return MainUtil.sendMessage(player, "Invalid world: " + args[1]); }
|
if (!BlockManager.manager.isWorld(world)) {
|
||||||
|
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
|
||||||
|
}
|
||||||
MainUtil.sendMessage(player, "Updating expired plot list");
|
MainUtil.sendMessage(player, "Updating expired plot list");
|
||||||
ExpireManager.updateExpired(args[1]);
|
ExpireManager.updateExpired(args[1]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return MainUtil.sendMessage(player, "Use /plot debugexec update-expired <world>");
|
return MainUtil.sendMessage(player, "Use /plot debugexec update-expired <world>");
|
||||||
}
|
}
|
||||||
case "show-expired":
|
case "show-expired": {
|
||||||
{
|
if (args.length > 1) {
|
||||||
if (args.length > 1)
|
|
||||||
{
|
|
||||||
final String world = args[1];
|
final String world = args[1];
|
||||||
if (!BlockManager.manager.isWorld(world)) { return MainUtil.sendMessage(player, "Invalid world: " + args[1]); }
|
if (!BlockManager.manager.isWorld(world)) {
|
||||||
if (!ExpireManager.expiredPlots.containsKey(args[1])) { return MainUtil.sendMessage(player, "No task for world: " + args[1]); }
|
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
|
||||||
|
}
|
||||||
|
if (!ExpireManager.expiredPlots.containsKey(args[1])) {
|
||||||
|
return MainUtil.sendMessage(player, "No task for world: " + args[1]);
|
||||||
|
}
|
||||||
MainUtil.sendMessage(player, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
|
MainUtil.sendMessage(player, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
|
||||||
for (final Plot plot : ExpireManager.expiredPlots.get(args[1]))
|
for (final Plot plot : ExpireManager.expiredPlots.get(args[1])) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, " - " + plot.world + ";" + plot.id.x + ";" + plot.id.y + ";" + UUIDHandler.getName(plot.owner) + " : " + ExpireManager.dates.get(plot.owner));
|
MainUtil.sendMessage(player, " - " + plot.world + ";" + plot.id.x + ";" + plot.id.y + ";" + UUIDHandler.getName(plot.owner) + " : " + ExpireManager.dates.get(plot.owner));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return MainUtil.sendMessage(player, "Use /plot debugexec show-expired <world>");
|
return MainUtil.sendMessage(player, "Use /plot debugexec show-expired <world>");
|
||||||
}
|
}
|
||||||
case "seen":
|
case "seen": {
|
||||||
{
|
if (args.length != 2) {
|
||||||
if (args.length != 2) { return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>"); }
|
return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>");
|
||||||
|
}
|
||||||
final UUID uuid = UUIDHandler.getUUID(args[1], null);
|
final UUID uuid = UUIDHandler.getUUID(args[1], null);
|
||||||
if (uuid == null) { return MainUtil.sendMessage(player, "player not found: " + args[1]); }
|
if (uuid == null) {
|
||||||
|
return MainUtil.sendMessage(player, "player not found: " + args[1]);
|
||||||
|
}
|
||||||
final OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
|
final OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
|
||||||
if ((op == null) || (op.getLastPlayed() == 0)) { return MainUtil.sendMessage(player, "player hasn't connected before: " + args[1]); }
|
if ((op == null) || (op.getLastPlayed() == 0)) {
|
||||||
|
return MainUtil.sendMessage(player, "player hasn't connected before: " + args[1]);
|
||||||
|
}
|
||||||
final Timestamp stamp = new Timestamp(op.getLastPlayed());
|
final Timestamp stamp = new Timestamp(op.getLastPlayed());
|
||||||
final Date date = new Date(stamp.getTime());
|
final Date date = new Date(stamp.getTime());
|
||||||
MainUtil.sendMessage(player, "PLAYER: " + args[1]);
|
MainUtil.sendMessage(player, "PLAYER: " + args[1]);
|
||||||
@ -357,40 +313,34 @@ public class DebugExec extends SubCommand
|
|||||||
MainUtil.sendMessage(player, "Local: " + date.toLocaleString());
|
MainUtil.sendMessage(player, "Local: " + date.toLocaleString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "trim-check":
|
case "trim-check": {
|
||||||
{
|
if (args.length != 2) {
|
||||||
if (args.length != 2)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "Use /plot debugexec trim-check <world>");
|
MainUtil.sendMessage(player, "Use /plot debugexec trim-check <world>");
|
||||||
MainUtil.sendMessage(player, "&7 - Generates a list of regions to trim");
|
MainUtil.sendMessage(player, "&7 - Generates a list of regions to trim");
|
||||||
return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run");
|
return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run");
|
||||||
}
|
}
|
||||||
final String world = args[1];
|
final String world = args[1];
|
||||||
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(args[1])) { return MainUtil.sendMessage(player, "Invalid world: " + args[1]); }
|
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(args[1])) {
|
||||||
|
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
|
||||||
|
}
|
||||||
final ArrayList<ChunkLoc> empty = new ArrayList<>();
|
final ArrayList<ChunkLoc> empty = new ArrayList<>();
|
||||||
final boolean result = Trim.getTrimRegions(empty, world, new Runnable()
|
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(PS.get().IMP.getDirectory() + File.separator + "trim.txt");
|
final File file = new File(PS.get().IMP.getDirectory() + File.separator + "trim.txt");
|
||||||
PrintWriter writer;
|
PrintWriter writer;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
writer = new PrintWriter(file);
|
writer = new PrintWriter(file);
|
||||||
for (final ChunkLoc loc : empty)
|
for (final ChunkLoc loc : empty) {
|
||||||
{
|
|
||||||
writer.println(world + "/region/r." + loc.x + "." + loc.z + ".mca");
|
writer.println(world + "/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 (final FileNotFoundException e) {
|
||||||
catch (final FileNotFoundException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Trim.sendMessage("File failed to save! :(");
|
Trim.sendMessage("File failed to save! :(");
|
||||||
}
|
}
|
||||||
@ -400,8 +350,7 @@ 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) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "Trim task already started!");
|
MainUtil.sendMessage(player, "Trim task already started!");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -409,31 +358,23 @@ public class DebugExec extends SubCommand
|
|||||||
case "h":
|
case "h":
|
||||||
case "he":
|
case "he":
|
||||||
case "?":
|
case "?":
|
||||||
case "help":
|
case "help": {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringMan.join(allowed_params, "|") + ">");
|
MainUtil.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringMan.join(allowed_params, "|") + ">");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case "addcmd":
|
case "addcmd": {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final String cmd = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8),
|
final String cmd = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8),
|
||||||
System.getProperty("line.separator"));
|
System.getProperty("line.separator"));
|
||||||
final Command<PlotPlayer> subcommand = new Command<PlotPlayer>(args[1].split("\\.")[0])
|
final Command<PlotPlayer> subcommand = new Command<PlotPlayer>(args[1].split("\\.")[0]) {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
scope.put("PlotPlayer", plr);
|
scope.put("PlotPlayer", plr);
|
||||||
scope.put("args", args);
|
scope.put("args", args);
|
||||||
engine.eval(cmd, scope);
|
engine.eval(cmd, scope);
|
||||||
return true;
|
return true;
|
||||||
}
|
} catch (final ScriptException e) {
|
||||||
catch (final ScriptException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
MainUtil.sendMessage(player, C.COMMAND_WENT_WRONG);
|
MainUtil.sendMessage(player, C.COMMAND_WENT_WRONG);
|
||||||
return false;
|
return false;
|
||||||
@ -442,87 +383,65 @@ public class DebugExec extends SubCommand
|
|||||||
};
|
};
|
||||||
MainCommand.getInstance().addCommand(subcommand);
|
MainCommand.getInstance().addCommand(subcommand);
|
||||||
return true;
|
return true;
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec addcmd <file>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec addcmd <file>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "runasync":
|
case "runasync": {
|
||||||
{
|
|
||||||
async = true;
|
async = true;
|
||||||
}
|
}
|
||||||
case "run":
|
case "run": {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8),
|
script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8),
|
||||||
System.getProperty("line.separator"));
|
System.getProperty("line.separator"));
|
||||||
if (args.length > 2)
|
if (args.length > 2) {
|
||||||
{
|
|
||||||
final HashMap<String, String> replacements = new HashMap<>();
|
final HashMap<String, String> replacements = new HashMap<>();
|
||||||
for (int i = 2; i < args.length; i++)
|
for (int i = 2; i < args.length; i++) {
|
||||||
{
|
|
||||||
replacements.put("%s" + (i - 2), args[i]);
|
replacements.put("%s" + (i - 2), args[i]);
|
||||||
}
|
}
|
||||||
script = StringMan.replaceFromMap(script, replacements);
|
script = StringMan.replaceFromMap(script, replacements);
|
||||||
}
|
}
|
||||||
}
|
} catch (final IOException e) {
|
||||||
catch (final IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
script = StringMan.join(args, " ");
|
script = StringMan.join(args, " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ConsolePlayer.isConsole(player))
|
if (!ConsolePlayer.isConsole(player)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NOT_CONSOLE);
|
MainUtil.sendMessage(player, C.NOT_CONSOLE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
scope.put("PlotPlayer", player);
|
scope.put("PlotPlayer", player);
|
||||||
PS.debug("> " + script);
|
PS.debug("> " + script);
|
||||||
try
|
try {
|
||||||
{
|
if (async) {
|
||||||
if (async)
|
|
||||||
{
|
|
||||||
final String toExec = script;
|
final String toExec = script;
|
||||||
TaskManager.runTaskAsync(new Runnable()
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
engine.eval(toExec, scope);
|
engine.eval(toExec, scope);
|
||||||
}
|
} catch (final ScriptException e) {
|
||||||
catch (final ScriptException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
PS.log("> " + (System.currentTimeMillis() - start) + "ms");
|
PS.log("> " + (System.currentTimeMillis() - start) + "ms");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
engine.eval(script, scope);
|
engine.eval(script, scope);
|
||||||
PS.log("> " + (System.currentTimeMillis() - start) + "ms");
|
PS.log("> " + (System.currentTimeMillis() - start) + "ms");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
} catch (final ScriptException e) {
|
||||||
catch (final ScriptException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -39,32 +39,28 @@ usage = "/plot fill",
|
|||||||
aliases = { "debugfill" },
|
aliases = { "debugfill" },
|
||||||
category = CommandCategory.DEBUG,
|
category = CommandCategory.DEBUG,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class DebugFill extends SubCommand
|
public class DebugFill extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, final String... args)
|
public boolean onCommand(final PlotPlayer player, final String... args) {
|
||||||
{
|
if ((args.length != 1) || (!args[0].equalsIgnoreCase("outline") && !args[0].equalsIgnoreCase("all"))) {
|
||||||
if ((args.length != 1) || (!args[0].equalsIgnoreCase("outline") && !args[0].equalsIgnoreCase("all")))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot fill <outline|all>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot fill <outline|all>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final Location loc = player.getLocation();
|
final Location loc = player.getLocation();
|
||||||
final Plot plot = MainUtil.getPlot(loc);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if (plot == null) { return !sendMessage(player, C.NOT_IN_PLOT); }
|
if (plot == null) {
|
||||||
if (!plot.hasOwner())
|
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||||
{
|
}
|
||||||
|
if (!plot.hasOwner()) {
|
||||||
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
|
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.fill"))
|
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.fill")) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (MainUtil.runners.containsKey(plot))
|
if (MainUtil.runners.containsKey(plot)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(player, C.WAIT_FOR_TIMER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -72,119 +68,87 @@ public class DebugFill extends SubCommand
|
|||||||
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
||||||
MainUtil.sendMessage(player, "&cPreparing task");
|
MainUtil.sendMessage(player, "&cPreparing task");
|
||||||
MainUtil.runners.put(plot, 1);
|
MainUtil.runners.put(plot, 1);
|
||||||
SetBlockQueue.addNotify(new Runnable()
|
SetBlockQueue.addNotify(new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
TaskManager.runTaskAsync(new Runnable()
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "&7 - Starting");
|
MainUtil.sendMessage(player, "&7 - Starting");
|
||||||
if (args[0].equalsIgnoreCase("all"))
|
if (args[0].equalsIgnoreCase("all")) {
|
||||||
{
|
|
||||||
int height = 255;
|
int height = 255;
|
||||||
PlotBlock block = new PlotBlock((short) 7, (byte) 0);
|
PlotBlock block = new PlotBlock((short) 7, (byte) 0);
|
||||||
final PlotBlock air = new PlotBlock((short) 0, (byte) 0);
|
final PlotBlock air = new PlotBlock((short) 0, (byte) 0);
|
||||||
if (args.length > 2)
|
if (args.length > 2) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
block = new PlotBlock(Short.parseShort(args[1]), (byte) 0);
|
block = new PlotBlock(Short.parseShort(args[1]), (byte) 0);
|
||||||
if (args.length == 3)
|
if (args.length == 3) {
|
||||||
{
|
|
||||||
height = Integer.parseInt(args[2]);
|
height = Integer.parseInt(args[2]);
|
||||||
}
|
}
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot fill all <id> <height>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot fill all <id> <height>");
|
||||||
MainUtil.runners.remove(plot);
|
MainUtil.runners.remove(plot);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int y = 0; y <= height; y++)
|
for (int y = 0; y <= height; y++) {
|
||||||
{
|
for (int x = bottom.getX(); x <= top.getX(); x++) {
|
||||||
for (int x = bottom.getX(); x <= top.getX(); x++)
|
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
|
||||||
{
|
|
||||||
for (int z = bottom.getZ(); z <= top.getZ(); z++)
|
|
||||||
{
|
|
||||||
SetBlockQueue.setBlock(plot.world, x, y, z, block);
|
SetBlockQueue.setBlock(plot.world, x, y, z, block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int y = height + 1; y <= 255; y++)
|
for (int y = height + 1; y <= 255; y++) {
|
||||||
{
|
for (int x = bottom.getX(); x <= top.getX(); x++) {
|
||||||
for (int x = bottom.getX(); x <= top.getX(); x++)
|
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
|
||||||
{
|
|
||||||
for (int z = bottom.getZ(); z <= top.getZ(); z++)
|
|
||||||
{
|
|
||||||
SetBlockQueue.setBlock(plot.world, x, y, z, air);
|
SetBlockQueue.setBlock(plot.world, x, y, z, air);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetBlockQueue.addNotify(new Runnable()
|
SetBlockQueue.addNotify(new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.runners.remove(plot);
|
MainUtil.runners.remove(plot);
|
||||||
MainUtil.sendMessage(player, "&aFill task complete!");
|
MainUtil.sendMessage(player, "&aFill task complete!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
} else if (args[0].equals("outline")) {
|
||||||
else if (args[0].equals("outline"))
|
|
||||||
{
|
|
||||||
int x, z;
|
int x, z;
|
||||||
z = bottom.getZ();
|
z = bottom.getZ();
|
||||||
for (x = bottom.getX(); x <= (top.getX() - 1); x++)
|
for (x = bottom.getX(); x <= (top.getX() - 1); x++) {
|
||||||
{
|
for (int y = 1; y <= 255; y++) {
|
||||||
for (int y = 1; y <= 255; y++)
|
|
||||||
{
|
|
||||||
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
|
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x = top.getX();
|
x = top.getX();
|
||||||
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++)
|
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) {
|
||||||
{
|
for (int y = 1; y <= 255; y++) {
|
||||||
for (int y = 1; y <= 255; y++)
|
|
||||||
{
|
|
||||||
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
|
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
z = top.getZ();
|
z = top.getZ();
|
||||||
for (x = top.getX(); x >= (bottom.getX() + 1); x--)
|
for (x = top.getX(); x >= (bottom.getX() + 1); x--) {
|
||||||
{
|
for (int y = 1; y <= 255; y++) {
|
||||||
for (int y = 1; y <= 255; y++)
|
|
||||||
{
|
|
||||||
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
|
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x = bottom.getX();
|
x = bottom.getX();
|
||||||
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--)
|
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) {
|
||||||
{
|
for (int y = 1; y <= 255; y++) {
|
||||||
for (int y = 1; y <= 255; y++)
|
|
||||||
{
|
|
||||||
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
|
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetBlockQueue.addNotify(new Runnable()
|
SetBlockQueue.addNotify(new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "&aWalls complete! The ceiling will take a while :(");
|
MainUtil.sendMessage(player, "&aWalls complete! The ceiling will take a while :(");
|
||||||
bottom.setY(255);
|
bottom.setY(255);
|
||||||
top.add(1, 0, 1);
|
top.add(1, 0, 1);
|
||||||
SetBlockQueue.setSlow(true);
|
SetBlockQueue.setSlow(true);
|
||||||
MainUtil.setSimpleCuboidAsync(plot.world, bottom, top, new PlotBlock((short) 7, (byte) 0));
|
MainUtil.setSimpleCuboidAsync(plot.world, bottom, top, new PlotBlock((short) 7, (byte) 0));
|
||||||
SetBlockQueue.addNotify(new Runnable()
|
SetBlockQueue.addNotify(new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.runners.remove(plot);
|
MainUtil.runners.remove(plot);
|
||||||
MainUtil.sendMessage(player, "&aFill task complete!");
|
MainUtil.sendMessage(player, "&aFill task complete!");
|
||||||
SetBlockQueue.setSlow(false);
|
SetBlockQueue.setSlow(false);
|
||||||
|
@ -43,41 +43,31 @@ permission = "plots.debugfixflags",
|
|||||||
description = "Attempt to fix all flags for a world",
|
description = "Attempt to fix all flags for a world",
|
||||||
requiredType = RequiredType.CONSOLE,
|
requiredType = RequiredType.CONSOLE,
|
||||||
category = CommandCategory.DEBUG)
|
category = CommandCategory.DEBUG)
|
||||||
public class DebugFixFlags extends SubCommand
|
public class DebugFixFlags extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
public DebugFixFlags()
|
public DebugFixFlags() {
|
||||||
{
|
requiredArguments = new Argument[] { Argument.String };
|
||||||
requiredArguments = new Argument[] {
|
|
||||||
Argument.String
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
final String world = args[0];
|
final String world = args[0];
|
||||||
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world))
|
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD, args[0]);
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD, args[0]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---");
|
MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---");
|
||||||
for (final Plot plot : PS.get().getPlotsInWorld(world))
|
for (final Plot plot : PS.get().getPlotsInWorld(world)) {
|
||||||
{
|
|
||||||
final HashMap<String, Flag> flags = plot.getSettings().flags;
|
final HashMap<String, Flag> flags = plot.getSettings().flags;
|
||||||
final Iterator<Entry<String, Flag>> i = flags.entrySet().iterator();
|
final Iterator<Entry<String, Flag>> i = flags.entrySet().iterator();
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
while (i.hasNext())
|
while (i.hasNext()) {
|
||||||
{
|
if (FlagManager.getFlag(i.next().getKey()) == null) {
|
||||||
if (FlagManager.getFlag(i.next().getKey()) == null)
|
|
||||||
{
|
|
||||||
changed = true;
|
changed = true;
|
||||||
i.remove();
|
i.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (changed)
|
if (changed) {
|
||||||
{
|
|
||||||
DBFunc.setFlags(plot, plot.getSettings().flags.values());
|
DBFunc.setFlags(plot, plot.getSettings().flags.values());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,20 +34,15 @@ description = "This debug command will force the reload of all plots in the DB",
|
|||||||
usage = "/plot debugloadtest",
|
usage = "/plot debugloadtest",
|
||||||
category = CommandCategory.DEBUG,
|
category = CommandCategory.DEBUG,
|
||||||
requiredType = RequiredType.CONSOLE)
|
requiredType = RequiredType.CONSOLE)
|
||||||
public class DebugLoadTest extends SubCommand
|
public class DebugLoadTest extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final Field fPlots = PS.class.getDeclaredField("plots");
|
final Field fPlots = PS.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)
|
|
||||||
{
|
|
||||||
PS.debug("&3===FAILED&3===");
|
PS.debug("&3===FAILED&3===");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
PS.debug("&3===END OF STACKTRACE===");
|
PS.debug("&3===END OF STACKTRACE===");
|
||||||
|
@ -21,27 +21,19 @@ usage = "/plot debugpaste",
|
|||||||
description = "Upload settings.yml & latest.log to hastebin",
|
description = "Upload settings.yml & latest.log to hastebin",
|
||||||
permission = "plots.debugpaste",
|
permission = "plots.debugpaste",
|
||||||
category = CommandCategory.DEBUG)
|
category = CommandCategory.DEBUG)
|
||||||
public class DebugPaste extends SubCommand
|
public class DebugPaste extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
TaskManager.runTaskAsync(new Runnable()
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final String settingsYML = HastebinUtility.upload(PS.get().configFile);
|
final String settingsYML = HastebinUtility.upload(PS.get().configFile);
|
||||||
String latestLOG;
|
String latestLOG;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
latestLOG = HastebinUtility.upload(new File(BukkitMain.THIS.getDirectory(), "../../logs/latest.log"));
|
latestLOG = HastebinUtility.upload(new File(BukkitMain.THIS.getDirectory(), "../../logs/latest.log"));
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
plr.sendMessage("&clatest.log is too big to be pasted, will ignore");
|
plr.sendMessage("&clatest.log is too big to be pasted, will ignore");
|
||||||
latestLOG = "too big :(";
|
latestLOG = "too big :(";
|
||||||
}
|
}
|
||||||
@ -54,8 +46,7 @@ public class DebugPaste extends SubCommand
|
|||||||
b.append("version.bukkit: '").append(Bukkit.getBukkitVersion()).append("'\n");
|
b.append("version.bukkit: '").append(Bukkit.getBukkitVersion()).append("'\n");
|
||||||
b.append("online_mode: ").append(Bukkit.getServer().getOnlineMode()).append("\n");
|
b.append("online_mode: ").append(Bukkit.getServer().getOnlineMode()).append("\n");
|
||||||
b.append("plugins:");
|
b.append("plugins:");
|
||||||
for (final Plugin p : Bukkit.getPluginManager().getPlugins())
|
for (final Plugin p : Bukkit.getPluginManager().getPlugins()) {
|
||||||
{
|
|
||||||
b.append("\n ").append(p.getName()).append(":\n ").append("version: '").append(p.getDescription().getVersion()).append("'").append("\n enabled: ").append(p.isEnabled());
|
b.append("\n ").append(p.getName()).append(":\n ").append("version: '").append(p.getDescription().getVersion()).append("'").append("\n enabled: ").append(p.isEnabled());
|
||||||
}
|
}
|
||||||
b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n");
|
b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n");
|
||||||
@ -73,9 +64,7 @@ public class DebugPaste extends SubCommand
|
|||||||
|
|
||||||
final String link = HastebinUtility.upload(b.toString());
|
final String link = HastebinUtility.upload(b.toString());
|
||||||
plr.sendMessage(C.DEBUG_REPORT_CREATED.s().replace("%url%", link));
|
plr.sendMessage(C.DEBUG_REPORT_CREATED.s().replace("%url%", link));
|
||||||
}
|
} catch (final IOException e) {
|
||||||
catch (final IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,31 +41,25 @@ requiredType = RequiredType.NONE,
|
|||||||
description = "Regenerate all roads based on the road schematic",
|
description = "Regenerate all roads based on the road schematic",
|
||||||
category = CommandCategory.DEBUG,
|
category = CommandCategory.DEBUG,
|
||||||
permission = "plots.debugroadregen")
|
permission = "plots.debugroadregen")
|
||||||
public class DebugRoadRegen extends SubCommand
|
public class DebugRoadRegen extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, final String... args)
|
public boolean onCommand(final PlotPlayer player, final String... args) {
|
||||||
{
|
|
||||||
final Location loc = player.getLocation();
|
final Location loc = player.getLocation();
|
||||||
final String world = loc.getWorld();
|
final String world = loc.getWorld();
|
||||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||||
if (!(plotworld instanceof HybridPlotWorld)) { return sendMessage(player, C.NOT_IN_PLOT_WORLD); }
|
if (!(plotworld instanceof HybridPlotWorld)) {
|
||||||
|
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
|
||||||
|
}
|
||||||
final Plot plot = player.getCurrentPlot();
|
final Plot plot = player.getCurrentPlot();
|
||||||
if (plot == null)
|
if (plot == null) {
|
||||||
{
|
|
||||||
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
||||||
int extend = 0;
|
int extend = 0;
|
||||||
if (args.length == 1)
|
if (args.length == 1) {
|
||||||
{
|
if (MathMan.isInteger(args[0])) {
|
||||||
if (MathMan.isInteger(args[0]))
|
try {
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
extend = Integer.parseInt(args[0]);
|
extend = Integer.parseInt(args[0]);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
C.NOT_VALID_NUMBER.send(player, "(0, <EXTEND HEIGHT>)");
|
C.NOT_VALID_NUMBER.send(player, "(0, <EXTEND HEIGHT>)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -74,9 +68,7 @@ public class DebugRoadRegen extends SubCommand
|
|||||||
final boolean result = HybridUtils.manager.regenerateRoad(world, chunk, extend);
|
final boolean result = HybridUtils.manager.regenerateRoad(world, chunk, extend);
|
||||||
MainUtil.sendMessage(player, "&6Regenerating chunk: " + chunk.x + "," + chunk.z + "\n&6 - Result: " + (result == true ? "&aSuccess" : "&cFailed"));
|
MainUtil.sendMessage(player, "&6Regenerating chunk: " + chunk.x + "," + chunk.z + "\n&6 - Result: " + (result == true ? "&aSuccess" : "&cFailed"));
|
||||||
MainUtil.sendMessage(player, "&cTo regenerate all roads: /plot regenallroads");
|
MainUtil.sendMessage(player, "&cTo regenerate all roads: /plot regenallroads");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
final HybridPlotManager manager = (HybridPlotManager) PS.get().getPlotManager(world);
|
final HybridPlotManager manager = (HybridPlotManager) PS.get().getPlotManager(world);
|
||||||
manager.createRoadEast(plotworld, plot);
|
manager.createRoadEast(plotworld, plot);
|
||||||
manager.createRoadSouth(plotworld, plot);
|
manager.createRoadSouth(plotworld, plot);
|
||||||
|
@ -36,20 +36,16 @@ category = CommandCategory.DEBUG,
|
|||||||
requiredType = RequiredType.CONSOLE,
|
requiredType = RequiredType.CONSOLE,
|
||||||
usage = "/plot debugsavetest",
|
usage = "/plot debugsavetest",
|
||||||
description = "This command will force the recreation of all plots in the DB")
|
description = "This command will force the recreation of all plots in the DB")
|
||||||
public class DebugSaveTest extends SubCommand
|
public class DebugSaveTest extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
final ArrayList<Plot> plots = new ArrayList<Plot>();
|
final ArrayList<Plot> plots = new ArrayList<Plot>();
|
||||||
plots.addAll(PS.get().getPlots());
|
plots.addAll(PS.get().getPlots());
|
||||||
MainUtil.sendMessage(null, "&6Starting `DEBUGSAVETEST`");
|
MainUtil.sendMessage(null, "&6Starting `DEBUGSAVETEST`");
|
||||||
DBFunc.createPlotsAndData(plots, new Runnable()
|
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(null, "&6Database sync finished!");
|
MainUtil.sendMessage(null, "&6Database sync finished!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -60,58 +60,44 @@ description = "Debug UUID conversion",
|
|||||||
usage = "/plot uuidconvert <lower|offline|online>",
|
usage = "/plot uuidconvert <lower|offline|online>",
|
||||||
requiredType = RequiredType.CONSOLE,
|
requiredType = RequiredType.CONSOLE,
|
||||||
category = CommandCategory.DEBUG)
|
category = CommandCategory.DEBUG)
|
||||||
public class DebugUUID extends SubCommand
|
public class DebugUUID extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
public DebugUUID()
|
public DebugUUID() {
|
||||||
{
|
requiredArguments = new Argument[] { Argument.String };
|
||||||
requiredArguments = new Argument[] {
|
|
||||||
Argument.String
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
final PlotPlayer player = null;
|
final PlotPlayer player = null;
|
||||||
|
|
||||||
final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
|
final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
|
||||||
final UUIDWrapper newWrapper;
|
final UUIDWrapper newWrapper;
|
||||||
|
|
||||||
switch (args[0].toLowerCase())
|
switch (args[0].toLowerCase()) {
|
||||||
{
|
case "lower": {
|
||||||
case "lower":
|
|
||||||
{
|
|
||||||
newWrapper = new LowerOfflineUUIDWrapper();
|
newWrapper = new LowerOfflineUUIDWrapper();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "offline":
|
case "offline": {
|
||||||
{
|
|
||||||
newWrapper = new OfflineUUIDWrapper();
|
newWrapper = new OfflineUUIDWrapper();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "online":
|
case "online": {
|
||||||
{
|
|
||||||
newWrapper = new DefaultUUIDWrapper();
|
newWrapper = new DefaultUUIDWrapper();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default: {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final Class<?> clazz = Class.forName(args[0]);
|
final Class<?> clazz = Class.forName(args[0]);
|
||||||
newWrapper = (UUIDWrapper) clazz.newInstance();
|
newWrapper = (UUIDWrapper) clazz.newInstance();
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((args.length != 2) || !args[1].equals("-o"))
|
if ((args.length != 2) || !args[1].equals("-o")) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert " + args[0] + " - o");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert " + args[0] + " - o");
|
||||||
MainUtil.sendMessage(player, "&cBe aware of the following!");
|
MainUtil.sendMessage(player, "&cBe aware of the following!");
|
||||||
MainUtil.sendMessage(player, "&8 - &cUse the database command or another method to backup your plots beforehand");
|
MainUtil.sendMessage(player, "&8 - &cUse the database command or another method to backup your plots beforehand");
|
||||||
@ -123,15 +109,13 @@ public class DebugUUID extends SubCommand
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName()))
|
if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName())) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "&cUUID mode already in use!");
|
MainUtil.sendMessage(player, "&cUUID mode already in use!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MainUtil.sendConsoleMessage("&6Beginning UUID mode conversion");
|
MainUtil.sendConsoleMessage("&6Beginning UUID mode conversion");
|
||||||
MainUtil.sendConsoleMessage("&7 - Disconnecting players");
|
MainUtil.sendConsoleMessage("&7 - Disconnecting players");
|
||||||
for (final PlotPlayer pp : UUIDHandler.getPlayers().values())
|
for (final PlotPlayer pp : UUIDHandler.getPlayers().values()) {
|
||||||
{
|
|
||||||
pp.kick("PlotSquared UUID conversion has been initiated. You may reconnect when finished.");
|
pp.kick("PlotSquared UUID conversion has been initiated. You may reconnect when finished.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,46 +131,34 @@ public class DebugUUID extends SubCommand
|
|||||||
worlds.add("world");
|
worlds.add("world");
|
||||||
final HashSet<UUID> uuids = new HashSet<>();
|
final HashSet<UUID> uuids = new HashSet<>();
|
||||||
final HashSet<String> names = new HashSet<>();
|
final HashSet<String> names = new HashSet<>();
|
||||||
for (final String worldname : worlds)
|
for (final String worldname : worlds) {
|
||||||
{
|
|
||||||
final File playerdataFolder = new File(worldname + File.separator + "playerdata");
|
final File playerdataFolder = new File(worldname + File.separator + "playerdata");
|
||||||
String[] dat = playerdataFolder.list(new FilenameFilter()
|
String[] dat = playerdataFolder.list(new FilenameFilter() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(final File f, final String s)
|
public boolean accept(final File f, final String s) {
|
||||||
{
|
|
||||||
return s.endsWith(".dat");
|
return s.endsWith(".dat");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (dat != null)
|
if (dat != null) {
|
||||||
{
|
for (final String current : dat) {
|
||||||
for (final String current : dat)
|
|
||||||
{
|
|
||||||
final String s = current.replaceAll(".dat$", "");
|
final String s = current.replaceAll(".dat$", "");
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
final UUID uuid = UUID.fromString(s);
|
final UUID uuid = UUID.fromString(s);
|
||||||
uuids.add(uuid);
|
uuids.add(uuid);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.PREFIX.s() + "Invalid playerdata: " + current);
|
MainUtil.sendMessage(plr, C.PREFIX.s() + "Invalid playerdata: " + current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final File playersFolder = new File(worldname + File.separator + "players");
|
final File playersFolder = new File(worldname + File.separator + "players");
|
||||||
dat = playersFolder.list(new FilenameFilter()
|
dat = playersFolder.list(new FilenameFilter() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(final File f, final String s)
|
public boolean accept(final File f, final String s) {
|
||||||
{
|
|
||||||
return s.endsWith(".dat");
|
return s.endsWith(".dat");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (dat != null)
|
if (dat != null) {
|
||||||
{
|
for (final String current : dat) {
|
||||||
for (final String current : dat)
|
|
||||||
{
|
|
||||||
names.add(current.replaceAll(".dat$", ""));
|
names.add(current.replaceAll(".dat$", ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,74 +167,56 @@ public class DebugUUID extends SubCommand
|
|||||||
MainUtil.sendConsoleMessage("&7 - Populating map");
|
MainUtil.sendConsoleMessage("&7 - Populating map");
|
||||||
UUID uuid2;
|
UUID uuid2;
|
||||||
final UUIDWrapper wrapper = new DefaultUUIDWrapper();
|
final UUIDWrapper wrapper = new DefaultUUIDWrapper();
|
||||||
for (UUID uuid : uuids)
|
for (UUID uuid : uuids) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
|
final OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
|
||||||
uuid = currentUUIDWrapper.getUUID(op);
|
uuid = currentUUIDWrapper.getUUID(op);
|
||||||
uuid2 = newWrapper.getUUID(op);
|
uuid2 = newWrapper.getUUID(op);
|
||||||
if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse.containsKey(uuid2))
|
if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse.containsKey(uuid2)) {
|
||||||
{
|
|
||||||
uCMap.put(uuid, uuid2);
|
uCMap.put(uuid, uuid2);
|
||||||
uCReverse.put(uuid2, uuid);
|
uCReverse.put(uuid2, uuid);
|
||||||
}
|
}
|
||||||
}
|
} catch (final Throwable e) {
|
||||||
catch (final Throwable e)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
MainUtil.sendMessage(plr, C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final String name : names)
|
for (final String name : names) {
|
||||||
{
|
|
||||||
final UUID uuid = currentUUIDWrapper.getUUID(name);
|
final UUID uuid = currentUUIDWrapper.getUUID(name);
|
||||||
uuid2 = newWrapper.getUUID(name);
|
uuid2 = newWrapper.getUUID(name);
|
||||||
if (!uuid.equals(uuid2))
|
if (!uuid.equals(uuid2)) {
|
||||||
{
|
|
||||||
uCMap.put(uuid, uuid2);
|
uCMap.put(uuid, uuid2);
|
||||||
uCReverse.put(uuid2, uuid);
|
uCReverse.put(uuid2, uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uCMap.size() == 0)
|
if (uCMap.size() == 0) {
|
||||||
{
|
|
||||||
MainUtil.sendConsoleMessage("&c - Error! Attempting to repopulate");
|
MainUtil.sendConsoleMessage("&c - Error! Attempting to repopulate");
|
||||||
for (final OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers())
|
for (final OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) {
|
||||||
{
|
if (op.getLastPlayed() != 0) {
|
||||||
if (op.getLastPlayed() != 0)
|
|
||||||
{
|
|
||||||
// String name = op.getName();
|
// String name = op.getName();
|
||||||
// StringWrapper wrap = new StringWrapper(name);
|
// StringWrapper wrap = new StringWrapper(name);
|
||||||
final UUID uuid = currentUUIDWrapper.getUUID(op);
|
final UUID uuid = currentUUIDWrapper.getUUID(op);
|
||||||
uuid2 = newWrapper.getUUID(op);
|
uuid2 = newWrapper.getUUID(op);
|
||||||
if (!uuid.equals(uuid2))
|
if (!uuid.equals(uuid2)) {
|
||||||
{
|
|
||||||
uCMap.put(uuid, uuid2);
|
uCMap.put(uuid, uuid2);
|
||||||
uCReverse.put(uuid2, uuid);
|
uCReverse.put(uuid2, uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uCMap.size() == 0)
|
if (uCMap.size() == 0) {
|
||||||
{
|
|
||||||
MainUtil.sendConsoleMessage("&cError. Failed to collect UUIDs!");
|
MainUtil.sendConsoleMessage("&cError. Failed to collect UUIDs!");
|
||||||
return false;
|
return false;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendConsoleMessage("&a - Successfully repopulated");
|
MainUtil.sendConsoleMessage("&a - Successfully repopulated");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MainUtil.sendConsoleMessage("&7 - Replacing cache");
|
MainUtil.sendConsoleMessage("&7 - Replacing cache");
|
||||||
TaskManager.runTaskAsync(new Runnable()
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
for (final Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
||||||
for (final Entry<UUID, UUID> entry : uCMap.entrySet())
|
|
||||||
{
|
|
||||||
final String name = UUIDHandler.getName(entry.getKey());
|
final String name = UUIDHandler.getName(entry.getKey());
|
||||||
if (name != null)
|
if (name != null) {
|
||||||
{
|
|
||||||
UUIDHandler.add(new StringWrapper(name), entry.getValue());
|
UUIDHandler.add(new StringWrapper(name), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,45 +224,34 @@ public class DebugUUID extends SubCommand
|
|||||||
MainUtil.sendConsoleMessage("&7 - Scanning for applicable files (uuids.txt)");
|
MainUtil.sendConsoleMessage("&7 - Scanning for applicable files (uuids.txt)");
|
||||||
|
|
||||||
final File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
|
final File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
|
||||||
if (file.exists())
|
if (file.exists()) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
|
final List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
|
||||||
for (String line : lines)
|
for (String line : lines) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
if (line.length() == 0)
|
if (line.length() == 0) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||||
final String[] split = line.split("\\|");
|
final String[] split = line.split("\\|");
|
||||||
final String name = split[0];
|
final String name = split[0];
|
||||||
if ((name.length() == 0) || (name.length() > 16) || !StringMan.isAlphanumericUnd(name))
|
if ((name.length() == 0) || (name.length() > 16) || !StringMan.isAlphanumericUnd(name)) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final UUID old = currentUUIDWrapper.getUUID(name);
|
final UUID old = currentUUIDWrapper.getUUID(name);
|
||||||
if (old == null)
|
if (old == null) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final UUID now = newWrapper.getUUID(name);
|
final UUID now = newWrapper.getUUID(name);
|
||||||
UUIDHandler.add(new StringWrapper(name), now);
|
UUIDHandler.add(new StringWrapper(name), now);
|
||||||
uCMap.put(old, now);
|
uCMap.put(old, now);
|
||||||
uCReverse.put(now, old);
|
uCReverse.put(now, old);
|
||||||
}
|
} catch (final Exception e2) {
|
||||||
catch (final Exception e2)
|
|
||||||
{
|
|
||||||
e2.printStackTrace();
|
e2.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (final IOException e) {
|
||||||
catch (final IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -318,11 +261,9 @@ public class DebugUUID extends SubCommand
|
|||||||
|
|
||||||
MainUtil.sendConsoleMessage("&7 - Updating plot objects");
|
MainUtil.sendConsoleMessage("&7 - Updating plot objects");
|
||||||
|
|
||||||
for (final Plot plot : PS.get().getPlotsRaw())
|
for (final Plot plot : PS.get().getPlotsRaw()) {
|
||||||
{
|
|
||||||
final UUID value = uCMap.get(plot.owner);
|
final UUID value = uCMap.get(plot.owner);
|
||||||
if (value != null)
|
if (value != null) {
|
||||||
{
|
|
||||||
plot.owner = value;
|
plot.owner = value;
|
||||||
}
|
}
|
||||||
plot.getTrusted().clear();
|
plot.getTrusted().clear();
|
||||||
@ -336,74 +277,54 @@ public class DebugUUID extends SubCommand
|
|||||||
|
|
||||||
MainUtil.sendConsoleMessage("&7 - Creating tables");
|
MainUtil.sendConsoleMessage("&7 - Creating tables");
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
database.createTables();
|
database.createTables();
|
||||||
if (!result)
|
if (!result) {
|
||||||
{
|
|
||||||
MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery");
|
MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery");
|
||||||
for (final Plot plot : PS.get().getPlots())
|
for (final Plot plot : PS.get().getPlots()) {
|
||||||
{
|
|
||||||
final UUID value = uCReverse.get(plot.owner);
|
final UUID value = uCReverse.get(plot.owner);
|
||||||
if (value != null)
|
if (value != null) {
|
||||||
{
|
|
||||||
plot.owner = value;
|
plot.owner = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
database.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable()
|
database.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(null, "&6Recovery was successful!");
|
MainUtil.sendMessage(null, "&6Recovery was successful!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newWrapper instanceof OfflineUUIDWrapper)
|
if (newWrapper instanceof OfflineUUIDWrapper) {
|
||||||
{
|
|
||||||
PS.get().config.set("UUID.force-lowercase", false);
|
PS.get().config.set("UUID.force-lowercase", false);
|
||||||
PS.get().config.set("UUID.offline", true);
|
PS.get().config.set("UUID.offline", true);
|
||||||
}
|
} else if (newWrapper instanceof LowerOfflineUUIDWrapper) {
|
||||||
else if (newWrapper instanceof LowerOfflineUUIDWrapper)
|
|
||||||
{
|
|
||||||
PS.get().config.set("UUID.force-lowercase", true);
|
PS.get().config.set("UUID.force-lowercase", true);
|
||||||
PS.get().config.set("UUID.offline", true);
|
PS.get().config.set("UUID.offline", true);
|
||||||
}
|
} else if (newWrapper instanceof DefaultUUIDWrapper) {
|
||||||
else if (newWrapper instanceof DefaultUUIDWrapper)
|
|
||||||
{
|
|
||||||
PS.get().config.set("UUID.force-lowercase", false);
|
PS.get().config.set("UUID.force-lowercase", false);
|
||||||
PS.get().config.set("UUID.offline", false);
|
PS.get().config.set("UUID.offline", false);
|
||||||
}
|
}
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
PS.get().config.save(PS.get().configFile);
|
PS.get().config.save(PS.get().configFile);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
MainUtil.sendConsoleMessage("Could not save configuration. It will need to be manuall set!");
|
MainUtil.sendConsoleMessage("Could not save configuration. It will need to be manuall set!");
|
||||||
}
|
}
|
||||||
|
|
||||||
MainUtil.sendConsoleMessage("&7 - Populating tables");
|
MainUtil.sendConsoleMessage("&7 - Populating tables");
|
||||||
|
|
||||||
TaskManager.runTaskAsync(new Runnable()
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
final ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
|
final ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
|
||||||
database.createPlotsAndData(plots, new Runnable()
|
database.createPlotsAndData(plots, new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.sendConsoleMessage("&aConversion complete!");
|
MainUtil.sendConsoleMessage("&aConversion complete!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -43,66 +43,56 @@ usage = "/plot delete",
|
|||||||
aliases = { "dispose", "del" },
|
aliases = { "dispose", "del" },
|
||||||
category = CommandCategory.ACTIONS,
|
category = CommandCategory.ACTIONS,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Delete extends SubCommand
|
public class Delete extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final Plot plot = MainUtil.getPlot(loc);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
|
if (plot == null) {
|
||||||
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return !sendMessage(plr, C.UNLINK_REQUIRED); }
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) { return !sendMessage(plr, C.NO_PLOT_PERMS); }
|
}
|
||||||
|
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||||
|
return !sendMessage(plr, C.UNLINK_REQUIRED);
|
||||||
|
}
|
||||||
|
if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) {
|
||||||
|
return !sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
|
}
|
||||||
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
|
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
|
||||||
if (MainUtil.runners.containsKey(plot))
|
if (MainUtil.runners.containsKey(plot)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Runnable runnable = new Runnable()
|
final Runnable runnable = new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr))) {
|
||||||
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr)))
|
|
||||||
{
|
|
||||||
final double c = pWorld.SELL_PRICE;
|
final double c = pWorld.SELL_PRICE;
|
||||||
if (c > 0d)
|
if (c > 0d) {
|
||||||
{
|
|
||||||
EconHandler.manager.depositMoney(plr, c);
|
EconHandler.manager.depositMoney(plr, c);
|
||||||
sendMessage(plr, C.ADDED_BALANCE, c + "");
|
sendMessage(plr, C.ADDED_BALANCE, c + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (plot.unclaim())
|
if (plot.unclaim()) {
|
||||||
{
|
|
||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
final boolean result = MainUtil.clearAsPlayer(plot, true, new Runnable()
|
final boolean result = MainUtil.clearAsPlayer(plot, true, new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!result)
|
if (!result) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.UNCLAIM_FAILED);
|
MainUtil.sendMessage(plr, C.UNCLAIM_FAILED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass")))
|
if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
|
||||||
{
|
|
||||||
CmdConfirm.addPending(plr, "/plot delete " + plot.id, runnable);
|
CmdConfirm.addPending(plr, "/plot delete " + plot.id, runnable);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
TaskManager.runTask(runnable);
|
TaskManager.runTask(runnable);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -36,69 +36,49 @@ import com.plotsquared.bukkit.uuid.SQLUUIDHandler;
|
|||||||
import com.plotsquared.general.commands.Argument;
|
import com.plotsquared.general.commands.Argument;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "deny", aliases = { "d" }, description = "Deny a user from a plot", usage = "/plot deny <player>", category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE)
|
||||||
command = "deny",
|
public class Deny extends SubCommand {
|
||||||
aliases = { "d" },
|
|
||||||
description = "Deny a user from a plot",
|
|
||||||
usage = "/plot deny <player>",
|
|
||||||
category = CommandCategory.ACTIONS,
|
|
||||||
requiredType = RequiredType.NONE)
|
|
||||||
public class Deny extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
public Deny()
|
public Deny() {
|
||||||
{
|
requiredArguments = new Argument[] { Argument.PlayerName };
|
||||||
requiredArguments = new Argument[] {
|
|
||||||
Argument.PlayerName
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final Plot plot = MainUtil.getPlot(loc);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
|
if (plot == null) {
|
||||||
if ((plot == null) || !plot.hasOwner())
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
{
|
}
|
||||||
|
if ((plot == null) || !plot.hasOwner()) {
|
||||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.deny"))
|
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.deny")) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
if (args[0].equalsIgnoreCase("*"))
|
if (args[0].equalsIgnoreCase("*")) {
|
||||||
{
|
|
||||||
uuid = DBFunc.everyone;
|
uuid = DBFunc.everyone;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
uuid = UUIDHandler.getUUID(args[0], null);
|
uuid = UUIDHandler.getUUID(args[0], null);
|
||||||
}
|
}
|
||||||
if (uuid == null)
|
if (uuid == null) {
|
||||||
{
|
if (UUIDHandler.implementation instanceof SQLUUIDHandler) {
|
||||||
if (UUIDHandler.implementation instanceof SQLUUIDHandler)
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER_WAIT, args[0]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER_WAIT, args[0]);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot.isOwner(uuid))
|
if (plot.isOwner(uuid)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plot.getDenied().contains(uuid))
|
if (plot.getDenied().contains(uuid)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -107,18 +87,15 @@ public class Deny extends SubCommand
|
|||||||
plot.addDenied(uuid);
|
plot.addDenied(uuid);
|
||||||
EventUtil.manager.callDenied(plr, plot, uuid, true);
|
EventUtil.manager.callDenied(plr, plot, uuid, true);
|
||||||
MainUtil.sendMessage(plr, C.DENIED_ADDED);
|
MainUtil.sendMessage(plr, C.DENIED_ADDED);
|
||||||
if (!uuid.equals(DBFunc.everyone))
|
if (!uuid.equals(DBFunc.everyone)) {
|
||||||
{
|
|
||||||
handleKick(uuid, plot);
|
handleKick(uuid, plot);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleKick(final UUID uuid, final Plot plot)
|
private void handleKick(final UUID uuid, final Plot plot) {
|
||||||
{
|
|
||||||
final PlotPlayer pp = UUIDHandler.getPlayer(uuid);
|
final PlotPlayer pp = UUIDHandler.getPlayer(uuid);
|
||||||
if ((pp != null) && plot.equals(MainUtil.getPlot(pp.getLocation())))
|
if ((pp != null) && plot.equals(MainUtil.getPlot(pp.getLocation()))) {
|
||||||
{
|
|
||||||
pp.teleport(BlockManager.manager.getSpawn(pp.getLocation().getWorld()));
|
pp.teleport(BlockManager.manager.getSpawn(pp.getLocation().getWorld()));
|
||||||
MainUtil.sendMessage(pp, C.YOU_GOT_DENIED);
|
MainUtil.sendMessage(pp, C.YOU_GOT_DENIED);
|
||||||
}
|
}
|
||||||
|
@ -34,53 +34,39 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
|||||||
import com.intellectualcrafters.plot.util.Permissions;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "done", aliases = { "submit" }, description = "Mark a plot as done", permission = "plots.done", category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE)
|
||||||
command = "done",
|
public class Done extends SubCommand {
|
||||||
aliases = { "submit" },
|
|
||||||
description = "Mark a plot as done",
|
|
||||||
permission = "plots.done",
|
|
||||||
category = CommandCategory.ACTIONS,
|
|
||||||
requiredType = RequiredType.NONE)
|
|
||||||
public class Done extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final Plot plot = MainUtil.getPlot(loc);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if ((plot == null) || !plot.hasOwner()) { return !sendMessage(plr, C.NOT_IN_PLOT); }
|
if ((plot == null) || !plot.hasOwner()) {
|
||||||
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.done"))
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
{
|
}
|
||||||
|
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.done")) {
|
||||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot.getSettings().flags.containsKey("done"))
|
if (plot.getSettings().flags.containsKey("done")) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
|
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (MainUtil.runners.containsKey(plot))
|
if (MainUtil.runners.containsKey(plot)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MainUtil.runners.put(plot, 1);
|
MainUtil.runners.put(plot, 1);
|
||||||
MainUtil.sendMessage(plr, C.GENERATING_LINK);
|
MainUtil.sendMessage(plr, C.GENERATING_LINK);
|
||||||
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>()
|
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.runners.remove(plot);
|
MainUtil.runners.remove(plot);
|
||||||
if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD))
|
if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD)) {
|
||||||
{
|
|
||||||
final Flag flag = new Flag(FlagManager.getFlag("done"), (System.currentTimeMillis() / 1000));
|
final Flag flag = new Flag(FlagManager.getFlag("done"), (System.currentTimeMillis() / 1000));
|
||||||
FlagManager.addPlotFlag(plot, flag);
|
FlagManager.addPlotFlag(plot, flag);
|
||||||
MainUtil.sendMessage(plr, C.DONE_SUCCESS);
|
MainUtil.sendMessage(plr, C.DONE_SUCCESS);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.DONE_INSUFFICIENT_COMPLEXITY);
|
MainUtil.sendMessage(plr, C.DONE_INSUFFICIENT_COMPLEXITY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,59 +16,46 @@ import com.intellectualcrafters.plot.util.SchematicHandler;
|
|||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "download", aliases = { "dl" }, category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE, description = "Download your plot", permission = "plots.download")
|
||||||
command = "download",
|
public class Download extends SubCommand {
|
||||||
aliases = { "dl" },
|
|
||||||
category = CommandCategory.ACTIONS,
|
|
||||||
requiredType = RequiredType.NONE,
|
|
||||||
description = "Download your plot",
|
|
||||||
permission = "plots.download")
|
|
||||||
public class Download extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
if (!Settings.METRICS)
|
if (!Settings.METRICS) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
|
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String world = plr.getLocation().getWorld();
|
final String world = plr.getLocation().getWorld();
|
||||||
if (!PS.get().isPlotWorld(world)) { return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); }
|
if (!PS.get().isPlotWorld(world)) {
|
||||||
|
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||||
|
}
|
||||||
final Plot plot = MainUtil.getPlot(plr.getLocation());
|
final Plot plot = MainUtil.getPlot(plr.getLocation());
|
||||||
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
|
if (plot == null) {
|
||||||
if (!plot.hasOwner())
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
{
|
}
|
||||||
|
if (!plot.hasOwner()) {
|
||||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((!plot.isOwner(plr.getUUID()) || (Settings.DOWNLOAD_REQUIRES_DONE && (FlagManager.getPlotFlag(plot, "done") != null))) && !Permissions.hasPermission(plr, "plots.admin.command.download"))
|
if ((!plot.isOwner(plr.getUUID()) || (Settings.DOWNLOAD_REQUIRES_DONE && (FlagManager.getPlotFlag(plot, "done") != null))) && !Permissions.hasPermission(plr, "plots.admin.command.download")) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (MainUtil.runners.containsKey(plot))
|
if (MainUtil.runners.containsKey(plot)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MainUtil.runners.put(plot, 1);
|
MainUtil.runners.put(plot, 1);
|
||||||
MainUtil.sendMessage(plr, C.GENERATING_LINK);
|
MainUtil.sendMessage(plr, C.GENERATING_LINK);
|
||||||
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>()
|
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
TaskManager.runTaskAsync(new Runnable()
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
final URL url = SchematicHandler.manager.upload(value, null, null);
|
final URL url = SchematicHandler.manager.upload(value, null, null);
|
||||||
if (url == null)
|
if (url == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
|
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
|
||||||
MainUtil.runners.remove(plot);
|
MainUtil.runners.remove(plot);
|
||||||
return;
|
return;
|
||||||
|
@ -46,18 +46,15 @@ description = "Manage plot flags",
|
|||||||
category = CommandCategory.ACTIONS,
|
category = CommandCategory.ACTIONS,
|
||||||
requiredType = RequiredType.NONE,
|
requiredType = RequiredType.NONE,
|
||||||
permission = "plots.flag")
|
permission = "plots.flag")
|
||||||
public class FlagCmd extends SubCommand
|
public class FlagCmd extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUsage()
|
public String getUsage() {
|
||||||
{
|
|
||||||
return super.getUsage().replaceAll("<flag>", StringMan.join(FlagManager.getFlags(), "|"));
|
return super.getUsage().replaceAll("<flag>", StringMan.join(FlagManager.getFlags(), "|"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, final String... args)
|
public boolean onCommand(final PlotPlayer player, final String... args) {
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* plot flag set fly true
|
* plot flag set fly true
|
||||||
@ -66,50 +63,40 @@ public class FlagCmd extends SubCommand
|
|||||||
* plot flag add use 2,4
|
* plot flag add use 2,4
|
||||||
* plot flag list
|
* plot flag list
|
||||||
*/
|
*/
|
||||||
if (args.length == 0)
|
if (args.length == 0) {
|
||||||
{
|
|
||||||
MainUtil.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;
|
||||||
}
|
}
|
||||||
final Location loc = player.getLocation();
|
final Location loc = player.getLocation();
|
||||||
final Plot plot = MainUtil.getPlot(loc);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if (plot == null)
|
if (plot == null) {
|
||||||
{
|
|
||||||
MainUtil.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.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.set.flag.other"))
|
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.set.flag.other")) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other");
|
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((args.length > 1) && FlagManager.isReserved(args[1]))
|
if ((args.length > 1) && FlagManager.isReserved(args[1])) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (args[0].toLowerCase())
|
switch (args[0].toLowerCase()) {
|
||||||
{
|
case "info": {
|
||||||
case "info":
|
if (!Permissions.hasPermission(player, "plots.set.flag")) {
|
||||||
{
|
|
||||||
if (!Permissions.hasPermission(player, "plots.set.flag"))
|
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final AbstractFlag af = FlagManager.getFlag(args[1]);
|
final AbstractFlag af = FlagManager.getFlag(args[1]);
|
||||||
if (af == null)
|
if (af == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||||
return false;
|
return false;
|
||||||
@ -122,92 +109,73 @@ public class FlagCmd extends SubCommand
|
|||||||
MainUtil.sendMessage(player, C.FLAG_DESC, af.getValueDesc());
|
MainUtil.sendMessage(player, C.FLAG_DESC, af.getValueDesc());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "set":
|
case "set": {
|
||||||
{
|
if (!Permissions.hasPermission(player, "plots.set.flag")) {
|
||||||
if (!Permissions.hasPermission(player, "plots.set.flag"))
|
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.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;
|
||||||
}
|
}
|
||||||
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||||
if (af == null)
|
if (af == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase()))
|
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase())) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase());
|
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Object parsed = af.parseValueRaw(value);
|
final Object parsed = af.parseValueRaw(value);
|
||||||
if (parsed == null)
|
if (parsed == null) {
|
||||||
{
|
|
||||||
MainUtil.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);
|
||||||
final boolean result = FlagManager.addPlotFlag(plot, flag);
|
final boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||||
if (!result)
|
if (!result) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, C.FLAG_ADDED);
|
MainUtil.sendMessage(player, C.FLAG_ADDED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "remove":
|
case "remove": {
|
||||||
{
|
if (!Permissions.hasPermission(player, "plots.flag.remove")) {
|
||||||
if (!Permissions.hasPermission(player, "plots.flag.remove"))
|
|
||||||
{
|
|
||||||
MainUtil.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)) {
|
||||||
{
|
|
||||||
MainUtil.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;
|
||||||
}
|
}
|
||||||
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||||
if (af == null)
|
if (af == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase());
|
final Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase());
|
||||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase()))
|
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||||
{
|
for (final String entry : args[2].split(",")) {
|
||||||
for (final String entry : args[2].split(","))
|
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) {
|
||||||
{
|
|
||||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry);
|
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (flag == null)
|
if (flag == null) {
|
||||||
{
|
|
||||||
MainUtil.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()) {
|
||||||
{
|
|
||||||
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
final String value = StringMan.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, plot.getSettings().flags.values());
|
DBFunc.setFlags(plot, plot.getSettings().flags.values());
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
final boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
|
final boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
|
||||||
if (!result)
|
if (!result) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED);
|
MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -215,30 +183,23 @@ public class FlagCmd extends SubCommand
|
|||||||
MainUtil.sendMessage(player, C.FLAG_REMOVED);
|
MainUtil.sendMessage(player, C.FLAG_REMOVED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "add":
|
case "add": {
|
||||||
{
|
if (!Permissions.hasPermission(player, "plots.flag.add")) {
|
||||||
if (!Permissions.hasPermission(player, "plots.flag.add"))
|
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.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;
|
||||||
}
|
}
|
||||||
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||||
if (af == null)
|
if (af == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase()))
|
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||||
{
|
for (final String entry : args[2].split(",")) {
|
||||||
for (final String entry : args[2].split(","))
|
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) {
|
||||||
{
|
|
||||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry);
|
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -246,23 +207,18 @@ public class FlagCmd extends SubCommand
|
|||||||
}
|
}
|
||||||
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||||
final Object parsed = af.parseValueRaw(value);
|
final Object parsed = af.parseValueRaw(value);
|
||||||
if (parsed == null)
|
if (parsed == null) {
|
||||||
{
|
|
||||||
MainUtil.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);
|
||||||
}
|
}
|
||||||
final boolean result = FlagManager.addPlotFlag(plot, flag);
|
final boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||||
if (!result)
|
if (!result) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -270,32 +226,26 @@ public class FlagCmd extends SubCommand
|
|||||||
MainUtil.sendMessage(player, C.FLAG_ADDED);
|
MainUtil.sendMessage(player, C.FLAG_ADDED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "list":
|
case "list": {
|
||||||
{
|
if (!Permissions.hasPermission(player, "plots.flag.list")) {
|
||||||
if (!Permissions.hasPermission(player, "plots.flag.list"))
|
|
||||||
{
|
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag list");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag list");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final HashMap<String, ArrayList<String>> flags = new HashMap<>();
|
final HashMap<String, ArrayList<String>> flags = new HashMap<>();
|
||||||
for (final AbstractFlag af : FlagManager.getFlags())
|
for (final AbstractFlag af : FlagManager.getFlags()) {
|
||||||
{
|
|
||||||
final 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>());
|
||||||
}
|
}
|
||||||
flags.get(type).add(af.getKey());
|
flags.get(type).add(af.getKey());
|
||||||
}
|
}
|
||||||
String message = "";
|
String message = "";
|
||||||
String prefix = "";
|
String prefix = "";
|
||||||
for (final String flag : flags.keySet())
|
for (final String flag : flags.keySet()) {
|
||||||
{
|
|
||||||
message += prefix + "&6" + flag + ": &7" + StringMan.join(flags.get(flag), ", ");
|
message += prefix + "&6" + flag + ": &7" + StringMan.join(flags.get(flag), ", ");
|
||||||
prefix = "\n";
|
prefix = "\n";
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,8 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
|||||||
import com.intellectualcrafters.plot.util.StringMan;
|
import com.intellectualcrafters.plot.util.StringMan;
|
||||||
import com.plotsquared.general.commands.Command;
|
import com.plotsquared.general.commands.Command;
|
||||||
|
|
||||||
public class GenerateDocs
|
public class GenerateDocs {
|
||||||
{
|
public static void main(final String[] args) {
|
||||||
public static void main(final String[] args)
|
|
||||||
{
|
|
||||||
MainCommand.getInstance().addCommand(new WE_Anywhere());
|
MainCommand.getInstance().addCommand(new WE_Anywhere());
|
||||||
MainCommand.getInstance().addCommand(new Cluster());
|
MainCommand.getInstance().addCommand(new Cluster());
|
||||||
final ArrayList<Command<PlotPlayer>> commands = MainCommand.getInstance().getCommands();
|
final ArrayList<Command<PlotPlayer>> commands = MainCommand.getInstance().getCommands();
|
||||||
@ -26,26 +24,21 @@ public class GenerateDocs
|
|||||||
log(" - Then do a pull request and it will be added to this page");
|
log(" - Then do a pull request and it will be added to this page");
|
||||||
log("");
|
log("");
|
||||||
log("# Contents");
|
log("# Contents");
|
||||||
for (final CommandCategory category : CommandCategory.values())
|
for (final CommandCategory category : CommandCategory.values()) {
|
||||||
{
|
|
||||||
log("###### " + category.name());
|
log("###### " + category.name());
|
||||||
for (final Command<PlotPlayer> command : MainCommand.getCommands(category, null))
|
for (final Command<PlotPlayer> command : MainCommand.getCommands(category, null)) {
|
||||||
{
|
|
||||||
log(" - [/plot " + command.getCommand() + "](https://github.com/IntellectualSites/PlotSquared/wiki/Commands#" + command.getCommand() + ") ");
|
log(" - [/plot " + command.getCommand() + "](https://github.com/IntellectualSites/PlotSquared/wiki/Commands#" + command.getCommand() + ") ");
|
||||||
}
|
}
|
||||||
log("");
|
log("");
|
||||||
}
|
}
|
||||||
log("# Commands");
|
log("# Commands");
|
||||||
for (final Command<PlotPlayer> command : commands)
|
for (final Command<PlotPlayer> command : commands) {
|
||||||
{
|
|
||||||
printCommand(command);
|
printCommand(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printCommand(final Command<PlotPlayer> command)
|
public static void printCommand(final Command<PlotPlayer> command) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final String clazz = command.getClass().getSimpleName();
|
final String clazz = command.getClass().getSimpleName();
|
||||||
final String name = command.getCommand();
|
final String name = command.getCommand();
|
||||||
|
|
||||||
@ -60,8 +53,7 @@ public class GenerateDocs
|
|||||||
|
|
||||||
log("#### Description");
|
log("#### Description");
|
||||||
log("`" + command.getDescription() + "`");
|
log("`" + command.getDescription() + "`");
|
||||||
if (comment.length() > 0)
|
if (comment.length() > 0) {
|
||||||
{
|
|
||||||
log("##### Comments");
|
log("##### Comments");
|
||||||
log("``` java");
|
log("``` java");
|
||||||
log(comment);
|
log(comment);
|
||||||
@ -71,15 +63,13 @@ public class GenerateDocs
|
|||||||
log("#### Usage");
|
log("#### Usage");
|
||||||
log("`" + command.getUsage().replaceAll("\\{label\\}", "plot") + "`");
|
log("`" + command.getUsage().replaceAll("\\{label\\}", "plot") + "`");
|
||||||
|
|
||||||
if (command.getRequiredType() != RequiredType.NONE)
|
if (command.getRequiredType() != RequiredType.NONE) {
|
||||||
{
|
|
||||||
log("#### Required callers");
|
log("#### Required callers");
|
||||||
log("`" + command.getRequiredType().name() + "`");
|
log("`" + command.getRequiredType().name() + "`");
|
||||||
}
|
}
|
||||||
|
|
||||||
final Set<String> aliases = command.getAliases();
|
final Set<String> aliases = command.getAliases();
|
||||||
if (aliases.size() > 0)
|
if (aliases.size() > 0) {
|
||||||
{
|
|
||||||
log("#### Aliases");
|
log("#### Aliases");
|
||||||
log("`" + StringMan.getString(command.getAliases()) + "`");
|
log("`" + StringMan.getString(command.getAliases()) + "`");
|
||||||
}
|
}
|
||||||
@ -87,8 +77,7 @@ public class GenerateDocs
|
|||||||
log("#### Permissions");
|
log("#### Permissions");
|
||||||
log("##### Primary");
|
log("##### Primary");
|
||||||
log(" - `" + command.getPermission() + "` ");
|
log(" - `" + command.getPermission() + "` ");
|
||||||
if (perms.size() > 0)
|
if (perms.size() > 0) {
|
||||||
{
|
|
||||||
log("");
|
log("");
|
||||||
log("##### Other");
|
log("##### Other");
|
||||||
log(" - `" + StringMan.join(perms, "`\n - `") + "`");
|
log(" - `" + StringMan.join(perms, "`\n - `") + "`");
|
||||||
@ -96,45 +85,33 @@ public class GenerateDocs
|
|||||||
log("");
|
log("");
|
||||||
log("***");
|
log("***");
|
||||||
log("");
|
log("");
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getPerms(final String cmd, final List<String> lines)
|
public static List<String> getPerms(final String cmd, final List<String> lines) {
|
||||||
{
|
|
||||||
final ArrayList<String> perms = new ArrayList<String>();
|
final ArrayList<String> perms = new ArrayList<String>();
|
||||||
final Pattern p = Pattern.compile("\"([^\"]*)\"");
|
final Pattern p = Pattern.compile("\"([^\"]*)\"");
|
||||||
for (final String line : lines)
|
for (final String line : lines) {
|
||||||
{
|
if (line.contains("Permissions.hasPermission(")) {
|
||||||
if (line.contains("Permissions.hasPermission("))
|
|
||||||
{
|
|
||||||
final Matcher m = p.matcher(line);
|
final Matcher m = p.matcher(line);
|
||||||
while (m.find())
|
while (m.find()) {
|
||||||
{
|
|
||||||
String perm = m.group(1);
|
String perm = m.group(1);
|
||||||
if (perm.endsWith("."))
|
if (perm.endsWith(".")) {
|
||||||
{
|
|
||||||
perm += "<arg>";
|
perm += "<arg>";
|
||||||
}
|
}
|
||||||
if (perm.startsWith("."))
|
if (perm.startsWith(".")) {
|
||||||
{
|
|
||||||
perms.set(perms.size() - 1, perms.get(perms.size() - 1) + perm);
|
perms.set(perms.size() - 1, perms.get(perms.size() - 1) + perm);
|
||||||
}
|
} else if (perm.contains(".")) {
|
||||||
else if (perm.contains("."))
|
|
||||||
{
|
|
||||||
perms.add(perm);
|
perms.add(perm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (cmd.toLowerCase())
|
switch (cmd.toLowerCase()) {
|
||||||
{
|
|
||||||
case "auto":
|
case "auto":
|
||||||
case "claim":
|
case "claim": {
|
||||||
{
|
|
||||||
perms.add("plots.plot.#");
|
perms.add("plots.plot.#");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -142,14 +119,11 @@ public class GenerateDocs
|
|||||||
return perms;
|
return perms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getComments(final List<String> lines)
|
public static String getComments(final List<String> lines) {
|
||||||
{
|
|
||||||
final StringBuilder result = new StringBuilder();
|
final StringBuilder result = new StringBuilder();
|
||||||
for (String line : lines)
|
for (String line : lines) {
|
||||||
{
|
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
if (line.startsWith("/** ") || line.startsWith("*/ ") || line.startsWith("* "))
|
if (line.startsWith("/** ") || line.startsWith("*/ ") || line.startsWith("* ")) {
|
||||||
{
|
|
||||||
line = (line.replaceAll("/[*][*] ", "").replaceAll("[*]/ ", "").replaceAll("[*] ", "")).trim();
|
line = (line.replaceAll("/[*][*] ", "").replaceAll("[*]/ ", "").replaceAll("[*] ", "")).trim();
|
||||||
result.append(line + "\n");
|
result.append(line + "\n");
|
||||||
}
|
}
|
||||||
@ -157,8 +131,7 @@ public class GenerateDocs
|
|||||||
return result.toString().trim();
|
return result.toString().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void log(final String s)
|
public static void log(final String s) {
|
||||||
{
|
|
||||||
System.out.println(s);
|
System.out.println(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,11 @@ package com.intellectualcrafters.plot.commands;
|
|||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "help", description = "Get this help menu", aliases = { "he" }, category = CommandCategory.INFO)
|
||||||
command = "help",
|
public class Help extends SubCommand {
|
||||||
description = "Get this help menu",
|
|
||||||
aliases = { "he" },
|
|
||||||
category = CommandCategory.INFO)
|
|
||||||
public class Help extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,63 +31,43 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
|||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "home", aliases = { "h" }, description = "Go to your plot", usage = "/plot home [id|alias]", category = CommandCategory.TELEPORT, requiredType = RequiredType.NONE)
|
||||||
command = "home",
|
public class Home extends SubCommand {
|
||||||
aliases = { "h" },
|
|
||||||
description = "Go to your plot",
|
|
||||||
usage = "/plot home [id|alias]",
|
|
||||||
category = CommandCategory.TELEPORT,
|
|
||||||
requiredType = RequiredType.NONE)
|
|
||||||
public class Home extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
private Plot isAlias(final String a)
|
private Plot isAlias(final String a) {
|
||||||
{
|
for (final Plot p : PS.get().getPlots()) {
|
||||||
for (final Plot p : PS.get().getPlots())
|
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) {
|
||||||
{
|
return p;
|
||||||
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) { return p; }
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, String[] args)
|
public boolean onCommand(final PlotPlayer plr, String[] args) {
|
||||||
{
|
|
||||||
final Set<Plot> all = PS.get().getPlots(plr);
|
final Set<Plot> all = PS.get().getPlots(plr);
|
||||||
final Iterator<Plot> iter = all.iterator();
|
final Iterator<Plot> iter = all.iterator();
|
||||||
while (iter.hasNext())
|
while (iter.hasNext()) {
|
||||||
{
|
if (!iter.next().isBasePlot()) {
|
||||||
if (!iter.next().isBasePlot())
|
|
||||||
{
|
|
||||||
iter.remove();
|
iter.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final ArrayList<Plot> plots = PS.get().sortPlotsByTemp(all);
|
final ArrayList<Plot> plots = PS.get().sortPlotsByTemp(all);
|
||||||
if (plots.size() == 1)
|
if (plots.size() == 1) {
|
||||||
{
|
|
||||||
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0));
|
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0));
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (plots.size() > 1) {
|
||||||
else if (plots.size() > 1)
|
if (args.length < 1) {
|
||||||
{
|
|
||||||
if (args.length < 1)
|
|
||||||
{
|
|
||||||
args = new String[] { "1" };
|
args = new String[] { "1" };
|
||||||
}
|
}
|
||||||
int id = 0;
|
int id = 0;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
id = Integer.parseInt(args[0]);
|
id = Integer.parseInt(args[0]);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
Plot temp;
|
Plot temp;
|
||||||
if ((temp = isAlias(args[0])) != null)
|
if ((temp = isAlias(args[0])) != null) {
|
||||||
{
|
if (temp.hasOwner()) {
|
||||||
if (temp.hasOwner())
|
if (temp.isOwner(plr.getUUID())) {
|
||||||
{
|
|
||||||
if (temp.isOwner(plr.getUUID()))
|
|
||||||
{
|
|
||||||
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
|
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -98,23 +78,19 @@ public class Home extends SubCommand
|
|||||||
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((id > (plots.size())) || (id < 1))
|
if ((id > (plots.size())) || (id < 1)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(id - 1));
|
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(id - 1));
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS);
|
MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void teleportPlayer(final PlotPlayer player, final Plot plot)
|
public void teleportPlayer(final PlotPlayer player, final Plot plot) {
|
||||||
{
|
|
||||||
MainUtil.teleportPlayer(player, player.getLocation(), plot);
|
MainUtil.teleportPlayer(player, player.getLocation(), plot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,48 +41,38 @@ usage = "/plot inbox [inbox] [delete <index>|clear|page]",
|
|||||||
permission = "plots.inbox",
|
permission = "plots.inbox",
|
||||||
category = CommandCategory.ACTIONS,
|
category = CommandCategory.ACTIONS,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Inbox extends SubCommand
|
public class Inbox extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
public void displayComments(final PlotPlayer player, final List<PlotComment> oldComments, int page)
|
public void displayComments(final PlotPlayer player, final List<PlotComment> oldComments, int page) {
|
||||||
{
|
if ((oldComments == null) || (oldComments.size() == 0)) {
|
||||||
if ((oldComments == null) || (oldComments.size() == 0))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.INBOX_EMPTY);
|
MainUtil.sendMessage(player, C.INBOX_EMPTY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final PlotComment[] comments = oldComments.toArray(new PlotComment[oldComments.size()]);
|
final PlotComment[] comments = oldComments.toArray(new PlotComment[oldComments.size()]);
|
||||||
if (page < 0)
|
if (page < 0) {
|
||||||
{
|
|
||||||
page = 0;
|
page = 0;
|
||||||
}
|
}
|
||||||
// Get the total pages
|
// Get the total pages
|
||||||
// int totalPages = ((int) Math.ceil(12 *
|
// int totalPages = ((int) Math.ceil(12 *
|
||||||
final int totalPages = (int) Math.ceil(comments.length / 12);
|
final int totalPages = (int) Math.ceil(comments.length / 12);
|
||||||
if (page > totalPages)
|
if (page > totalPages) {
|
||||||
{
|
|
||||||
page = totalPages;
|
page = totalPages;
|
||||||
}
|
}
|
||||||
// Only display 12 per page
|
// Only display 12 per page
|
||||||
int max = (page * 12) + 12;
|
int max = (page * 12) + 12;
|
||||||
if (max > comments.length)
|
if (max > comments.length) {
|
||||||
{
|
|
||||||
max = comments.length;
|
max = comments.length;
|
||||||
}
|
}
|
||||||
final StringBuilder string = new StringBuilder();
|
final StringBuilder string = new StringBuilder();
|
||||||
string.append(StringMan.replaceAll(C.COMMENT_LIST_HEADER_PAGED.s(), "%amount%", comments.length, "%cur", page + 1, "%max", totalPages + 1, "%word", "all") + "\n");
|
string.append(StringMan.replaceAll(C.COMMENT_LIST_HEADER_PAGED.s(), "%amount%", comments.length, "%cur", page + 1, "%max", totalPages + 1, "%word", "all") + "\n");
|
||||||
PlotComment c;
|
PlotComment c;
|
||||||
// This might work xD
|
// This might work xD
|
||||||
for (int x = (page * 12); x < max; x++)
|
for (int x = (page * 12); x < max; x++) {
|
||||||
{
|
|
||||||
c = comments[x];
|
c = comments[x];
|
||||||
String color;
|
String color;
|
||||||
if (player.getName().equals(c.senderName))
|
if (player.getName().equals(c.senderName)) {
|
||||||
{
|
|
||||||
color = "&a";
|
color = "&a";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
color = "&7";
|
color = "&7";
|
||||||
}
|
}
|
||||||
string.append("&8[&7#" + x + "&8][&7" + c.world + ";" + c.id + "&8][&6" + c.senderName + "&8]" + color + c.comment + "\n");
|
string.append("&8[&7#" + x + "&8][&7" + c.world + ";" + c.id + "&8][&6" + c.senderName + "&8]" + color + c.comment + "\n");
|
||||||
@ -91,43 +81,30 @@ public class Inbox extends SubCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, final String[] args)
|
public boolean onCommand(final PlotPlayer player, final String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
final Plot plot = MainUtil.getPlot(player.getLocation());
|
final Plot plot = MainUtil.getPlot(player.getLocation());
|
||||||
if (args.length == 0)
|
if (args.length == 0) {
|
||||||
{
|
|
||||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
|
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
|
||||||
for (final CommentInbox inbox : CommentManager.inboxes.values())
|
for (final CommentInbox inbox : CommentManager.inboxes.values()) {
|
||||||
{
|
if (inbox.canRead(plot, player)) {
|
||||||
if (inbox.canRead(plot, player))
|
if (!inbox.getComments(plot, new RunnableVal() {
|
||||||
{
|
|
||||||
if (!inbox.getComments(plot, new RunnableVal()
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
if (value != null) {
|
||||||
if (value != null)
|
|
||||||
{
|
|
||||||
int total = 0;
|
int total = 0;
|
||||||
int unread = 0;
|
int unread = 0;
|
||||||
for (final PlotComment comment : (ArrayList<PlotComment>) value)
|
for (final PlotComment comment : (ArrayList<PlotComment>) value) {
|
||||||
{
|
|
||||||
total++;
|
total++;
|
||||||
if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString()))
|
if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString())) {
|
||||||
{
|
|
||||||
unread++;
|
unread++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (total != 0)
|
if (total != 0) {
|
||||||
{
|
|
||||||
String color;
|
String color;
|
||||||
if (unread > 0)
|
if (unread > 0) {
|
||||||
{
|
|
||||||
color = "&c";
|
color = "&c";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
color = "";
|
color = "";
|
||||||
}
|
}
|
||||||
sendMessage(player, C.INBOX_ITEM, color + inbox.toString() + " (" + total + "/" + unread + ")");
|
sendMessage(player, C.INBOX_ITEM, color + inbox.toString() + " (" + total + "/" + unread + ")");
|
||||||
@ -136,8 +113,7 @@ public class Inbox extends SubCommand
|
|||||||
}
|
}
|
||||||
sendMessage(player, C.INBOX_ITEM, inbox.toString());
|
sendMessage(player, C.INBOX_ITEM, inbox.toString());
|
||||||
}
|
}
|
||||||
}))
|
})) {
|
||||||
{
|
|
||||||
sendMessage(player, C.INBOX_ITEM, inbox.toString());
|
sendMessage(player, C.INBOX_ITEM, inbox.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,52 +121,39 @@ public class Inbox extends SubCommand
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
||||||
if (inbox == null)
|
if (inbox == null) {
|
||||||
{
|
|
||||||
sendMessage(player, C.INVALID_INBOX, StringMan.join(CommentManager.inboxes.keySet(), ", "));
|
sendMessage(player, C.INVALID_INBOX, StringMan.join(CommentManager.inboxes.keySet(), ", "));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
player.setMeta("inbox:" + inbox.toString(), System.currentTimeMillis());
|
player.setMeta("inbox:" + inbox.toString(), System.currentTimeMillis());
|
||||||
final int page;
|
final int page;
|
||||||
if (args.length > 1)
|
if (args.length > 1) {
|
||||||
{
|
switch (args[1].toLowerCase()) {
|
||||||
switch (args[1].toLowerCase())
|
case "delete": {
|
||||||
{
|
if (!inbox.canModify(plot, player)) {
|
||||||
case "delete":
|
|
||||||
{
|
|
||||||
if (!inbox.canModify(plot, player))
|
|
||||||
{
|
|
||||||
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
|
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 3)
|
if (args.length != 3) {
|
||||||
{
|
|
||||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
|
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
|
||||||
}
|
}
|
||||||
final int index;
|
final int index;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
index = Integer.parseInt(args[2]);
|
index = Integer.parseInt(args[2]);
|
||||||
if (index < 1)
|
if (index < 1) {
|
||||||
{
|
|
||||||
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
|
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} catch (final NumberFormatException e) {
|
||||||
catch (final NumberFormatException e)
|
|
||||||
{
|
|
||||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
|
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inbox.getComments(plot, new RunnableVal()
|
if (!inbox.getComments(plot, new RunnableVal() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
final List<PlotComment> comments = (List<PlotComment>) value;
|
final List<PlotComment> comments = (List<PlotComment>) value;
|
||||||
if (index > comments.size())
|
if (index > comments.size()) {
|
||||||
{
|
|
||||||
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
|
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
|
||||||
}
|
}
|
||||||
final PlotComment comment = comments.get(index - 1);
|
final PlotComment comment = comments.get(index - 1);
|
||||||
@ -198,67 +161,50 @@ public class Inbox extends SubCommand
|
|||||||
plot.getSettings().removeComment(comment);
|
plot.getSettings().removeComment(comment);
|
||||||
MainUtil.sendMessage(player, C.COMMENT_REMOVED, comment.comment);
|
MainUtil.sendMessage(player, C.COMMENT_REMOVED, comment.comment);
|
||||||
}
|
}
|
||||||
}))
|
})) {
|
||||||
{
|
|
||||||
sendMessage(player, C.NOT_IN_PLOT);
|
sendMessage(player, C.NOT_IN_PLOT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "clear":
|
case "clear": {
|
||||||
{
|
if (!inbox.canModify(plot, player)) {
|
||||||
if (!inbox.canModify(plot, player))
|
|
||||||
{
|
|
||||||
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
|
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
|
||||||
}
|
}
|
||||||
inbox.clearInbox(plot);
|
inbox.clearInbox(plot);
|
||||||
final ArrayList<PlotComment> comments = plot.getSettings().getComments(inbox.toString());
|
final ArrayList<PlotComment> comments = plot.getSettings().getComments(inbox.toString());
|
||||||
if (comments != null)
|
if (comments != null) {
|
||||||
{
|
|
||||||
plot.getSettings().removeComments(comments);
|
plot.getSettings().removeComments(comments);
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, C.COMMENT_REMOVED, "*");
|
MainUtil.sendMessage(player, C.COMMENT_REMOVED, "*");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
default:
|
default: {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
page = Integer.parseInt(args[1]);
|
page = Integer.parseInt(args[1]);
|
||||||
}
|
} catch (final NumberFormatException e) {
|
||||||
catch (final NumberFormatException e)
|
|
||||||
{
|
|
||||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
|
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
page = 1;
|
page = 1;
|
||||||
}
|
}
|
||||||
if (!inbox.canRead(plot, player))
|
if (!inbox.canRead(plot, player)) {
|
||||||
{
|
|
||||||
sendMessage(player, C.NO_PERM_INBOX);
|
sendMessage(player, C.NO_PERM_INBOX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!inbox.getComments(plot, new RunnableVal()
|
if (!inbox.getComments(plot, new RunnableVal() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
final List<PlotComment> comments = (List<PlotComment>) value;
|
final List<PlotComment> comments = (List<PlotComment>) value;
|
||||||
displayComments(player, comments, page);
|
displayComments(player, comments, page);
|
||||||
}
|
}
|
||||||
}))
|
})) {
|
||||||
{
|
if (plot == null) {
|
||||||
if (plot == null)
|
|
||||||
{
|
|
||||||
sendMessage(player, C.NOT_IN_PLOT);
|
sendMessage(player, C.NOT_IN_PLOT);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendMessage(player, C.PLOT_UNOWNED);
|
sendMessage(player, C.PLOT_UNOWNED);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -43,57 +43,49 @@ import com.intellectualcrafters.plot.util.TaskManager;
|
|||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "info", aliases = { "i" }, description = "Display plot info", usage = "/plot info <id>", category = CommandCategory.INFO)
|
||||||
command = "info",
|
public class Info extends SubCommand {
|
||||||
aliases = { "i" },
|
|
||||||
description = "Display plot info",
|
|
||||||
usage = "/plot info <id>",
|
|
||||||
category = CommandCategory.INFO)
|
|
||||||
public class Info extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
public static String getPlayerList(final Collection<UUID> uuids)
|
public static String getPlayerList(final Collection<UUID> uuids) {
|
||||||
{
|
|
||||||
final ArrayList<UUID> l = new ArrayList<>(uuids);
|
final ArrayList<UUID> l = new ArrayList<>(uuids);
|
||||||
if ((l == null) || (l.size() < 1)) { return C.NONE.s(); }
|
if ((l == null) || (l.size() < 1)) {
|
||||||
|
return C.NONE.s();
|
||||||
|
}
|
||||||
final String c = C.PLOT_USER_LIST.s();
|
final String c = C.PLOT_USER_LIST.s();
|
||||||
final StringBuilder list = new StringBuilder();
|
final StringBuilder list = new StringBuilder();
|
||||||
for (int x = 0; x < l.size(); x++)
|
for (int x = 0; x < l.size(); x++) {
|
||||||
{
|
if ((x + 1) == l.size()) {
|
||||||
if ((x + 1) == l.size())
|
|
||||||
{
|
|
||||||
list.append(c.replace("%user%", getPlayerName(l.get(x))).replace(",", ""));
|
list.append(c.replace("%user%", getPlayerName(l.get(x))).replace(",", ""));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
list.append(c.replace("%user%", getPlayerName(l.get(x))));
|
list.append(c.replace("%user%", getPlayerName(l.get(x))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list.toString();
|
return list.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPlayerName(final UUID uuid)
|
public static String getPlayerName(final UUID uuid) {
|
||||||
{
|
if (uuid == null) {
|
||||||
if (uuid == null) { return C.UNKNOWN.s(); }
|
return C.UNKNOWN.s();
|
||||||
if (uuid.equals(DBFunc.everyone) || uuid.toString().equalsIgnoreCase(DBFunc.everyone.toString())) { return "everyone"; }
|
}
|
||||||
|
if (uuid.equals(DBFunc.everyone) || uuid.toString().equalsIgnoreCase(DBFunc.everyone.toString())) {
|
||||||
|
return "everyone";
|
||||||
|
}
|
||||||
final String name = UUIDHandler.getName(uuid);
|
final String name = UUIDHandler.getName(uuid);
|
||||||
if (name == null) { return "unknown"; }
|
if (name == null) {
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, String[] args)
|
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||||
{
|
|
||||||
String arg = null;
|
String arg = null;
|
||||||
Plot plot;
|
Plot plot;
|
||||||
if (args.length > 0)
|
if (args.length > 0) {
|
||||||
{
|
|
||||||
arg = args[0] + "";
|
arg = args[0] + "";
|
||||||
}
|
}
|
||||||
if (arg != null)
|
if (arg != null) {
|
||||||
{
|
switch (arg) {
|
||||||
switch (arg)
|
|
||||||
{
|
|
||||||
case "trusted":
|
case "trusted":
|
||||||
case "alias":
|
case "alias":
|
||||||
case "inv":
|
case "inv":
|
||||||
@ -109,48 +101,34 @@ public class Info extends SubCommand
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
plot = MainUtil.getPlotFromString(player, arg, false);
|
plot = MainUtil.getPlotFromString(player, arg, false);
|
||||||
if (args.length == 2)
|
if (args.length == 2) {
|
||||||
{
|
|
||||||
arg = args[1];
|
arg = args[1];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
arg = null;
|
arg = null;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
plot = MainUtil.getPlotFromString(player, null, false);
|
plot = MainUtil.getPlotFromString(player, null, false);
|
||||||
}
|
}
|
||||||
if ((plot == null) && (arg != null))
|
if ((plot == null) && (arg != null)) {
|
||||||
{
|
|
||||||
plot = MainUtil.getPlotFromString(player, null, false);
|
plot = MainUtil.getPlotFromString(player, null, false);
|
||||||
}
|
}
|
||||||
if (plot == null)
|
if (plot == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (arg != null)
|
if (arg != null) {
|
||||||
{
|
if (args.length == 1) {
|
||||||
if (args.length == 1)
|
|
||||||
{
|
|
||||||
args = new String[0];
|
args = new String[0];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
args = new String[] { args[1] };
|
args = new String[] { args[1] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((args.length == 1) && args[0].equalsIgnoreCase("inv"))
|
if ((args.length == 1) && args[0].equalsIgnoreCase("inv")) {
|
||||||
{
|
final PlotInventory inv = new PlotInventory(player) {
|
||||||
final PlotInventory inv = new PlotInventory(player)
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onClick(final int index)
|
public boolean onClick(final int index) {
|
||||||
{
|
|
||||||
// TODO InfoInventory not implemented yet!!!!!!!!
|
// TODO InfoInventory not implemented yet!!!!!!!!
|
||||||
// See plot rating or musicsubcommand on examples
|
// See plot rating or musicsubcommand on examples
|
||||||
return false;
|
return false;
|
||||||
@ -181,33 +159,26 @@ public class Info extends SubCommand
|
|||||||
trustedEveryone = (plot.getMembers() != null) && plot.getMembers().contains(DBFunc.everyone);
|
trustedEveryone = (plot.getMembers() != null) && plot.getMembers().contains(DBFunc.everyone);
|
||||||
}
|
}
|
||||||
// Unclaimed?
|
// Unclaimed?
|
||||||
if (!hasOwner && !containsEveryone && !trustedEveryone)
|
if (!hasOwner && !containsEveryone && !trustedEveryone) {
|
||||||
{
|
|
||||||
MainUtil.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 info = C.PLOT_INFO.s();
|
String info = C.PLOT_INFO.s();
|
||||||
if (arg != null)
|
if (arg != null) {
|
||||||
{
|
|
||||||
info = getCaption(arg);
|
info = getCaption(arg);
|
||||||
if (info == null)
|
if (info == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, "&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, &aowner&7, &arating");
|
MainUtil.sendMessage(player, "&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, &aowner&7, &arating");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
formatAndSend(info, plot.world, plot, player, true);
|
formatAndSend(info, plot.world, plot, player, true);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
formatAndSend(info, plot.world, plot, player, false);
|
formatAndSend(info, plot.world, plot, player, false);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCaption(final String string)
|
private String getCaption(final String string) {
|
||||||
{
|
switch (string) {
|
||||||
switch (string)
|
|
||||||
{
|
|
||||||
case "trusted":
|
case "trusted":
|
||||||
return C.PLOT_INFO_TRUSTED.s();
|
return C.PLOT_INFO_TRUSTED.s();
|
||||||
case "alias":
|
case "alias":
|
||||||
@ -233,8 +204,7 @@ public class Info extends SubCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void formatAndSend(String info, final String world, final Plot plot, final PlotPlayer player, final boolean full)
|
private void formatAndSend(String info, final String world, final Plot plot, final PlotPlayer player, final boolean full) {
|
||||||
{
|
|
||||||
final PlotId id = plot.id;
|
final PlotId id = plot.id;
|
||||||
final PlotId id2 = MainUtil.getTopPlot(plot).id;
|
final PlotId id2 = MainUtil.getTopPlot(plot).id;
|
||||||
final int num = MainUtil.getPlotSelectionIds(id, id2).size();
|
final int num = MainUtil.getPlotSelectionIds(id, id2).size();
|
||||||
@ -271,34 +241,26 @@ public class Info extends SubCommand
|
|||||||
info = info.replaceAll("%flags%", Matcher.quoteReplacement(flags));
|
info = info.replaceAll("%flags%", Matcher.quoteReplacement(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.");
|
||||||
if (info.contains("%rating%"))
|
if (info.contains("%rating%")) {
|
||||||
{
|
|
||||||
final String newInfo = info;
|
final String newInfo = info;
|
||||||
TaskManager.runTaskAsync(new Runnable()
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
int max = 10;
|
int max = 10;
|
||||||
if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 0))
|
if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 0)) {
|
||||||
{
|
|
||||||
max = 8;
|
max = 8;
|
||||||
}
|
}
|
||||||
String info;
|
String info;
|
||||||
if (full && (Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 1))
|
if (full && (Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 1)) {
|
||||||
{
|
|
||||||
String rating = "";
|
String rating = "";
|
||||||
String prefix = "";
|
String prefix = "";
|
||||||
final double[] ratings = MainUtil.getAverageRatings(plot);
|
final double[] ratings = MainUtil.getAverageRatings(plot);
|
||||||
for (int i = 0; i < ratings.length; i++)
|
for (int i = 0; i < ratings.length; i++) {
|
||||||
{
|
|
||||||
rating += prefix + Settings.RATING_CATEGORIES.get(i) + "=" + String.format("%.1f", ratings[i]);
|
rating += prefix + Settings.RATING_CATEGORIES.get(i) + "=" + String.format("%.1f", ratings[i]);
|
||||||
prefix = ",";
|
prefix = ",";
|
||||||
}
|
}
|
||||||
info = newInfo.replaceAll("%rating%", rating);
|
info = newInfo.replaceAll("%rating%", rating);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
info = newInfo.replaceAll("%rating%", String.format("%.1f", MainUtil.getAverageRating(plot)) + "/" + max);
|
info = newInfo.replaceAll("%rating%", String.format("%.1f", MainUtil.getAverageRating(plot)) + "/" + max);
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER);
|
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER);
|
||||||
|
@ -30,42 +30,32 @@ import com.intellectualcrafters.plot.util.Permissions;
|
|||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "kick", aliases = { "k" }, description = "Kick a player from your plot", permission = "plots.kick", category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE)
|
||||||
command = "kick",
|
public class Kick extends SubCommand {
|
||||||
aliases = { "k" },
|
|
||||||
description = "Kick a player from your plot",
|
|
||||||
permission = "plots.kick",
|
|
||||||
category = CommandCategory.ACTIONS,
|
|
||||||
requiredType = RequiredType.NONE)
|
|
||||||
public class Kick extends SubCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
final Location loc = plr.getLocation();
|
final Location loc = plr.getLocation();
|
||||||
final Plot plot = MainUtil.getPlot(loc);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
|
if (plot == null) {
|
||||||
if ((plot == null) || ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.kick")))
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
{
|
}
|
||||||
|
if ((plot == null) || ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.kick"))) {
|
||||||
MainUtil.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) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "&c/plot kick <player>");
|
MainUtil.sendMessage(plr, "&c/plot kick <player>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlotPlayer player = UUIDHandler.getPlayer(args[0]);
|
final PlotPlayer player = UUIDHandler.getPlayer(args[0]);
|
||||||
if (player == null)
|
if (player == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Location otherLoc = player.getLocation();
|
final Location otherLoc = player.getLocation();
|
||||||
if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(MainUtil.getPlot(otherLoc)))
|
if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(MainUtil.getPlot(otherLoc))) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -36,23 +36,16 @@ description = "Set or increment player plot claim limits",
|
|||||||
aliases = { "setlimit" },
|
aliases = { "setlimit" },
|
||||||
usage = "/plot limit <player> <expression>",
|
usage = "/plot limit <player> <expression>",
|
||||||
category = CommandCategory.DEBUG)
|
category = CommandCategory.DEBUG)
|
||||||
public class Limit extends SubCommand
|
public class Limit extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
public Limit()
|
public Limit() {
|
||||||
{
|
requiredArguments = new Argument[] { Argument.String, Argument.String };
|
||||||
requiredArguments = new Argument[] {
|
|
||||||
Argument.String,
|
|
||||||
Argument.String
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
final UUID uuid = UUIDHandler.getUUID(args[0], null);
|
final UUID uuid = UUIDHandler.getUUID(args[0], null);
|
||||||
if (uuid == null)
|
if (uuid == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -26,68 +26,57 @@ requiredType = RequiredType.NONE,
|
|||||||
description = "Load your plot",
|
description = "Load your plot",
|
||||||
permission = "plots.load",
|
permission = "plots.load",
|
||||||
usage = "/plot restore")
|
usage = "/plot restore")
|
||||||
public class Load extends SubCommand
|
public class Load extends SubCommand {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
if (!Settings.METRICS)
|
if (!Settings.METRICS) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
|
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String world = plr.getLocation().getWorld();
|
final String world = plr.getLocation().getWorld();
|
||||||
if (!PS.get().isPlotWorld(world)) { return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); }
|
if (!PS.get().isPlotWorld(world)) {
|
||||||
|
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||||
|
}
|
||||||
final Plot plot = MainUtil.getPlot(plr.getLocation());
|
final Plot plot = MainUtil.getPlot(plr.getLocation());
|
||||||
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
|
if (plot == null) {
|
||||||
if (!plot.hasOwner())
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
{
|
}
|
||||||
|
if (!plot.hasOwner()) {
|
||||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.load"))
|
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.load")) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (MainUtil.runners.containsKey(plot))
|
if (MainUtil.runners.containsKey(plot)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length != 0)
|
if (args.length != 0) {
|
||||||
{
|
if (args.length == 1) {
|
||||||
if (args.length == 1)
|
|
||||||
{
|
|
||||||
// TODO load save here
|
// TODO load save here
|
||||||
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
|
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
|
||||||
if (schematics == null)
|
if (schematics == null) {
|
||||||
{
|
|
||||||
// No schematics found:
|
// No schematics found:
|
||||||
MainUtil.sendMessage(plr, C.LOAD_NULL);
|
MainUtil.sendMessage(plr, C.LOAD_NULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String schem;
|
String schem;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
schem = schematics.get(Integer.parseInt(args[0]) - 1);
|
schem = schematics.get(Integer.parseInt(args[0]) - 1);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
// use /plot load <index>
|
// use /plot load <index>
|
||||||
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + schematics.size() + ")");
|
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + schematics.size() + ")");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final URL url;
|
final URL url;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
url = new URL(Settings.WEB_URL + "saves/" + plr.getUUID() + "/" + schem + ".schematic");
|
url = new URL(Settings.WEB_URL + "saves/" + plr.getUUID() + "/" + schem + ".schematic");
|
||||||
}
|
} catch (final MalformedURLException e) {
|
||||||
catch (final MalformedURLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
MainUtil.sendMessage(plr, C.LOAD_FAILED);
|
MainUtil.sendMessage(plr, C.LOAD_FAILED);
|
||||||
return false;
|
return false;
|
||||||
@ -95,30 +84,22 @@ public class Load extends SubCommand
|
|||||||
|
|
||||||
MainUtil.runners.put(plot, 1);
|
MainUtil.runners.put(plot, 1);
|
||||||
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
|
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
|
||||||
TaskManager.runTaskAsync(new Runnable()
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
final Schematic schematic = SchematicHandler.manager.getSchematic(url);
|
final Schematic schematic = SchematicHandler.manager.getSchematic(url);
|
||||||
if (schematic == null)
|
if (schematic == null) {
|
||||||
{
|
|
||||||
MainUtil.runners.remove(plot);
|
MainUtil.runners.remove(plot);
|
||||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
|
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>()
|
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
MainUtil.runners.remove(plot);
|
MainUtil.runners.remove(plot);
|
||||||
if (value)
|
if (value) {
|
||||||
{
|
|
||||||
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
|
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendMessage(plr, C.SCHEMATIC_PASTE_FAILED);
|
sendMessage(plr, C.SCHEMATIC_PASTE_FAILED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,18 +116,14 @@ public class Load extends SubCommand
|
|||||||
// list schematics
|
// list schematics
|
||||||
|
|
||||||
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
|
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
|
||||||
if (schematics == null)
|
if (schematics == null) {
|
||||||
{
|
|
||||||
MainUtil.runners.put(plot, 1);
|
MainUtil.runners.put(plot, 1);
|
||||||
TaskManager.runTaskAsync(new Runnable()
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
final List<String> schematics = SchematicHandler.manager.getSaves(plr.getUUID());
|
final List<String> schematics = SchematicHandler.manager.getSaves(plr.getUUID());
|
||||||
MainUtil.runners.remove(plot);
|
MainUtil.runners.remove(plot);
|
||||||
if ((schematics == null) || (schematics.size() == 0))
|
if ((schematics == null) || (schematics.size() == 0)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.LOAD_FAILED);
|
MainUtil.sendMessage(plr, C.LOAD_FAILED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -154,25 +131,19 @@ public class Load extends SubCommand
|
|||||||
displaySaves(plr, 0);
|
displaySaves(plr, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
displaySaves(plr, 0);
|
displaySaves(plr, 0);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displaySaves(final PlotPlayer player, final int page)
|
public void displaySaves(final PlotPlayer player, final int page) {
|
||||||
{
|
|
||||||
final List<String> schematics = (List<String>) player.getMeta("plot_schematics");
|
final List<String> schematics = (List<String>) player.getMeta("plot_schematics");
|
||||||
for (int i = 0; i < Math.min(schematics.size(), 32); i++)
|
for (int i = 0; i < Math.min(schematics.size(), 32); i++) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
final String schem = schematics.get(i);
|
final String schem = schematics.get(i);
|
||||||
final String[] split = schem.split("_");
|
final String[] split = schem.split("_");
|
||||||
if (split.length != 6)
|
if (split.length != 6) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final String time = secToTime((System.currentTimeMillis() / 1000) - (Long.parseLong(split[0])));
|
final String time = secToTime((System.currentTimeMillis() / 1000) - (Long.parseLong(split[0])));
|
||||||
@ -181,64 +152,52 @@ public class Load extends SubCommand
|
|||||||
final String size = split[4];
|
final String size = split[4];
|
||||||
final String server = split[5].replaceAll(".schematic", "");
|
final String server = split[5].replaceAll(".schematic", "");
|
||||||
String color;
|
String color;
|
||||||
if (PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", "").equals(server))
|
if (PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", "").equals(server)) {
|
||||||
{
|
|
||||||
color = "$4";
|
color = "$4";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
color = "$1";
|
color = "$1";
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, "$3[$2" + (i + 1) + "$3] " + color + time + "$3 | " + color + world + ";" + id + "$3 | " + color + size + "x" + size);
|
MainUtil.sendMessage(player, "$3[$2" + (i + 1) + "$3] " + color + time + "$3 | " + color + world + ";" + id + "$3 | " + color + size + "x" + size);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
catch (final Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, C.LOAD_LIST);
|
MainUtil.sendMessage(player, C.LOAD_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String secToTime(long time)
|
public String secToTime(long time) {
|
||||||
{
|
|
||||||
final StringBuilder toreturn = new StringBuilder();
|
final StringBuilder toreturn = new StringBuilder();
|
||||||
int years = 0;
|
int years = 0;
|
||||||
int weeks = 0;
|
int weeks = 0;
|
||||||
int days = 0;
|
int days = 0;
|
||||||
int hours = 0;
|
int hours = 0;
|
||||||
int minutes = 0;
|
int minutes = 0;
|
||||||
if (time >= 33868800)
|
if (time >= 33868800) {
|
||||||
{
|
|
||||||
years = (int) (time / 33868800);
|
years = (int) (time / 33868800);
|
||||||
time -= years * 33868800;
|
time -= years * 33868800;
|
||||||
toreturn.append(years + "y ");
|
toreturn.append(years + "y ");
|
||||||
}
|
}
|
||||||
if (time >= 604800)
|
if (time >= 604800) {
|
||||||
{
|
|
||||||
weeks = (int) (time / 604800);
|
weeks = (int) (time / 604800);
|
||||||
time -= weeks * 604800;
|
time -= weeks * 604800;
|
||||||
toreturn.append(weeks + "w ");
|
toreturn.append(weeks + "w ");
|
||||||
}
|
}
|
||||||
if (time >= 86400)
|
if (time >= 86400) {
|
||||||
{
|
|
||||||
days = (int) (time / 86400);
|
days = (int) (time / 86400);
|
||||||
time -= days * 86400;
|
time -= days * 86400;
|
||||||
toreturn.append(days + "d ");
|
toreturn.append(days + "d ");
|
||||||
}
|
}
|
||||||
if (time >= 3600)
|
if (time >= 3600) {
|
||||||
{
|
|
||||||
hours = (int) (time / 3600);
|
hours = (int) (time / 3600);
|
||||||
time -= hours * 3600;
|
time -= hours * 3600;
|
||||||
toreturn.append(hours + "h ");
|
toreturn.append(hours + "h ");
|
||||||
}
|
}
|
||||||
if (time >= 60)
|
if (time >= 60) {
|
||||||
{
|
|
||||||
minutes = (int) (time / 60);
|
minutes = (int) (time / 60);
|
||||||
time -= minutes * 60;
|
time -= minutes * 60;
|
||||||
toreturn.append(minutes + "m ");
|
toreturn.append(minutes + "m ");
|
||||||
}
|
}
|
||||||
if (toreturn.equals("") || (time > 0))
|
if (toreturn.equals("") || (time > 0)) {
|
||||||
{
|
|
||||||
toreturn.append((time) + "s ");
|
toreturn.append((time) + "s ");
|
||||||
}
|
}
|
||||||
return toreturn.toString().trim();
|
return toreturn.toString().trim();
|
||||||
|
@ -48,22 +48,18 @@ import com.plotsquared.general.commands.CommandManager;
|
|||||||
* PlotSquared command class
|
* PlotSquared command class
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class MainCommand extends CommandManager<PlotPlayer>
|
public class MainCommand extends CommandManager<PlotPlayer> {
|
||||||
{
|
|
||||||
|
|
||||||
private static MainCommand instance;
|
private static MainCommand instance;
|
||||||
|
|
||||||
public static MainCommand getInstance()
|
public static MainCommand getInstance() {
|
||||||
{
|
if (instance == null) {
|
||||||
if (instance == null)
|
|
||||||
{
|
|
||||||
instance = new MainCommand();
|
instance = new MainCommand();
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MainCommand()
|
private MainCommand() {
|
||||||
{
|
|
||||||
super(null, new ArrayList<Command<PlotPlayer>>());
|
super(null, new ArrayList<Command<PlotPlayer>>());
|
||||||
instance = this;
|
instance = this;
|
||||||
createCommand(new Buy());
|
createCommand(new Buy());
|
||||||
@ -133,29 +129,23 @@ public class MainCommand extends CommandManager<PlotPlayer>
|
|||||||
createCommand(new Done());
|
createCommand(new Done());
|
||||||
createCommand(new Continue());
|
createCommand(new Continue());
|
||||||
createCommand(new BO3());
|
createCommand(new BO3());
|
||||||
if (Settings.ENABLE_CLUSTERS)
|
if (Settings.ENABLE_CLUSTERS) {
|
||||||
{
|
|
||||||
MainCommand.getInstance().addCommand(new Cluster());
|
MainCommand.getInstance().addCommand(new Cluster());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean no_permission(final PlotPlayer player, final String permission)
|
public static boolean no_permission(final PlotPlayer player, final String permission) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(player, C.NO_PERMISSION, permission);
|
MainUtil.sendMessage(player, C.NO_PERMISSION, permission);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Command<PlotPlayer>> getCommandAndAliases(final CommandCategory category, final PlotPlayer player)
|
public static List<Command<PlotPlayer>> getCommandAndAliases(final CommandCategory category, final PlotPlayer player) {
|
||||||
{
|
|
||||||
final List<Command<PlotPlayer>> commands = new ArrayList<>();
|
final List<Command<PlotPlayer>> commands = new ArrayList<>();
|
||||||
for (final Command<PlotPlayer> command : getInstance().getCommands())
|
for (final Command<PlotPlayer> command : getInstance().getCommands()) {
|
||||||
{
|
if ((category != null) && !command.getCategory().equals(category)) {
|
||||||
if ((category != null) && !command.getCategory().equals(category))
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((player != null) && !Permissions.hasPermission(player, command.getPermission()))
|
if ((player != null) && !Permissions.hasPermission(player, command.getPermission())) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
commands.add(command);
|
commands.add(command);
|
||||||
@ -163,17 +153,13 @@ public class MainCommand extends CommandManager<PlotPlayer>
|
|||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Command<PlotPlayer>> getCommands(final CommandCategory category, final PlotPlayer player)
|
public static List<Command<PlotPlayer>> getCommands(final CommandCategory category, final PlotPlayer player) {
|
||||||
{
|
|
||||||
final List<Command<PlotPlayer>> commands = new ArrayList<>();
|
final List<Command<PlotPlayer>> commands = new ArrayList<>();
|
||||||
for (final Command<PlotPlayer> command : new HashSet<>(getInstance().getCommands()))
|
for (final Command<PlotPlayer> command : new HashSet<>(getInstance().getCommands())) {
|
||||||
{
|
if ((category != null) && !command.getCategory().equals(category)) {
|
||||||
if ((category != null) && !command.getCategory().equals(category))
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((player != null) && !Permissions.hasPermission(player, command.getPermission()))
|
if ((player != null) && !Permissions.hasPermission(player, command.getPermission())) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
commands.add(command);
|
commands.add(command);
|
||||||
@ -222,38 +208,28 @@ public class MainCommand extends CommandManager<PlotPlayer>
|
|||||||
// return help;
|
// return help;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
public static void displayHelp(final PlotPlayer player, String cat, int page, final String label)
|
public static void displayHelp(final PlotPlayer player, String cat, int page, final String label) {
|
||||||
{
|
|
||||||
CommandCategory catEnum = null;
|
CommandCategory catEnum = null;
|
||||||
if (cat != null)
|
if (cat != null) {
|
||||||
{
|
if (StringMan.isEqualIgnoreCase(cat, "all")) {
|
||||||
if (StringMan.isEqualIgnoreCase(cat, "all"))
|
|
||||||
{
|
|
||||||
catEnum = null;
|
catEnum = null;
|
||||||
}
|
} else {
|
||||||
else
|
for (final CommandCategory c : CommandCategory.values()) {
|
||||||
{
|
if (StringMan.isEqualIgnoreCaseToAny(cat, c.name(), c.toString())) {
|
||||||
for (final CommandCategory c : CommandCategory.values())
|
|
||||||
{
|
|
||||||
if (StringMan.isEqualIgnoreCaseToAny(cat, c.name(), c.toString()))
|
|
||||||
{
|
|
||||||
catEnum = c;
|
catEnum = c;
|
||||||
cat = c.name();
|
cat = c.name();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (catEnum == null)
|
if (catEnum == null) {
|
||||||
{
|
|
||||||
cat = null;
|
cat = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((cat == null) && (page == 0))
|
if ((cat == null) && (page == 0)) {
|
||||||
{
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
builder.append(C.HELP_HEADER.s());
|
builder.append(C.HELP_HEADER.s());
|
||||||
for (final CommandCategory c : CommandCategory.values())
|
for (final CommandCategory c : CommandCategory.values()) {
|
||||||
{
|
|
||||||
builder.append("\n" + StringMan.replaceAll(C.HELP_INFO_ITEM.s(), "%category%", c.toString().toLowerCase(), "%category_desc%", c.toString()));
|
builder.append("\n" + StringMan.replaceAll(C.HELP_INFO_ITEM.s(), "%category%", c.toString().toLowerCase(), "%category_desc%", c.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"));
|
||||||
@ -262,118 +238,79 @@ public class MainCommand extends CommandManager<PlotPlayer>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
page--;
|
page--;
|
||||||
new HelpMenu(player)
|
new HelpMenu(player).setCategory(catEnum).getCommands().generateMaxPages().generatePage(page, label).render();
|
||||||
.setCategory(catEnum)
|
|
||||||
.getCommands()
|
|
||||||
.generateMaxPages()
|
|
||||||
.generatePage(page, label)
|
|
||||||
.render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean onCommand(final PlotPlayer player, final String cmd, String... args)
|
public static boolean onCommand(final PlotPlayer player, final String cmd, String... args) {
|
||||||
{
|
|
||||||
int help_index = -1;
|
int help_index = -1;
|
||||||
String category = null;
|
String category = null;
|
||||||
if (args.length == 0)
|
if (args.length == 0) {
|
||||||
{
|
|
||||||
help_index = 0;
|
help_index = 0;
|
||||||
}
|
} else if (StringMan.isEqualIgnoreCaseToAny(args[0], "he", "help", "?")) {
|
||||||
else if (StringMan.isEqualIgnoreCaseToAny(args[0], "he", "help", "?"))
|
|
||||||
{
|
|
||||||
help_index = 0;
|
help_index = 0;
|
||||||
switch (args.length)
|
switch (args.length) {
|
||||||
{
|
case 3: {
|
||||||
case 3:
|
|
||||||
{
|
|
||||||
category = args[1];
|
category = args[1];
|
||||||
if (MathMan.isInteger(args[2]))
|
if (MathMan.isInteger(args[2])) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
help_index = Integer.parseInt(args[2]);
|
help_index = Integer.parseInt(args[2]);
|
||||||
}
|
} catch (final NumberFormatException e) {
|
||||||
catch (final NumberFormatException e)
|
|
||||||
{
|
|
||||||
help_index = 1;
|
help_index = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2:
|
case 2: {
|
||||||
{
|
if (MathMan.isInteger(args[1])) {
|
||||||
if (MathMan.isInteger(args[1]))
|
|
||||||
{
|
|
||||||
category = null;
|
category = null;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
help_index = Integer.parseInt(args[1]);
|
help_index = Integer.parseInt(args[1]);
|
||||||
}
|
} catch (final NumberFormatException e) {
|
||||||
catch (final NumberFormatException e)
|
|
||||||
{
|
|
||||||
help_index = 1;
|
help_index = 1;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
help_index = 1;
|
help_index = 1;
|
||||||
category = args[1];
|
category = args[1];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if ((args.length == 1) && MathMan.isInteger(args[args.length - 1])) {
|
||||||
else if ((args.length == 1) && MathMan.isInteger(args[args.length - 1]))
|
try {
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
help_index = Integer.parseInt(args[args.length - 1]);
|
help_index = Integer.parseInt(args[args.length - 1]);
|
||||||
}
|
} catch (final NumberFormatException e) {}
|
||||||
catch (final NumberFormatException e)
|
} else if (ConsolePlayer.isConsole(player) && (args.length >= 2)) {
|
||||||
{}
|
|
||||||
}
|
|
||||||
else if (ConsolePlayer.isConsole(player) && (args.length >= 2))
|
|
||||||
{
|
|
||||||
final String[] split = args[0].split(";");
|
final String[] split = args[0].split(";");
|
||||||
String world;
|
String world;
|
||||||
PlotId id;
|
PlotId id;
|
||||||
if (split.length == 2)
|
if (split.length == 2) {
|
||||||
{
|
|
||||||
world = player.getLocation().getWorld();
|
world = player.getLocation().getWorld();
|
||||||
id = PlotId.fromString(split[0] + ";" + split[1]);
|
id = PlotId.fromString(split[0] + ";" + split[1]);
|
||||||
}
|
} else if (split.length == 3) {
|
||||||
else if (split.length == 3)
|
|
||||||
{
|
|
||||||
world = split[0];
|
world = split[0];
|
||||||
id = PlotId.fromString(split[1] + ";" + split[2]);
|
id = PlotId.fromString(split[1] + ";" + split[2]);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
id = null;
|
id = null;
|
||||||
world = null;
|
world = null;
|
||||||
}
|
}
|
||||||
if ((id != null) && PS.get().isPlotWorld(world))
|
if ((id != null) && PS.get().isPlotWorld(world)) {
|
||||||
{
|
|
||||||
final Plot plot = MainUtil.getPlot(world, id);
|
final Plot plot = MainUtil.getPlot(world, id);
|
||||||
if (plot != null)
|
if (plot != null) {
|
||||||
{
|
|
||||||
player.teleport(MainUtil.getPlotCenter(plot));
|
player.teleport(MainUtil.getPlotCenter(plot));
|
||||||
args = Arrays.copyOfRange(args, 1, args.length);
|
args = Arrays.copyOfRange(args, 1, args.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (help_index != -1)
|
if (help_index != -1) {
|
||||||
{
|
|
||||||
displayHelp(player, category, help_index, cmd);
|
displayHelp(player, category, help_index, cmd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final StringBuilder builder = new StringBuilder(cmd).append(" ");
|
final StringBuilder builder = new StringBuilder(cmd).append(" ");
|
||||||
final Iterator<String> iterator = Arrays.asList(args).iterator();
|
final Iterator<String> iterator = Arrays.asList(args).iterator();
|
||||||
while (iterator.hasNext())
|
while (iterator.hasNext()) {
|
||||||
{
|
|
||||||
builder.append(iterator.next());
|
builder.append(iterator.next());
|
||||||
if (iterator.hasNext())
|
if (iterator.hasNext()) {
|
||||||
{
|
|
||||||
builder.append(" ");
|
builder.append(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -382,104 +319,76 @@ public class MainCommand extends CommandManager<PlotPlayer>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int handle(final PlotPlayer plr, final String input)
|
public int handle(final PlotPlayer plr, final String input) {
|
||||||
{
|
|
||||||
final String[] parts = input.split(" ");
|
final String[] parts = input.split(" ");
|
||||||
String[] args;
|
String[] args;
|
||||||
String label;
|
String label;
|
||||||
if (parts.length == 1)
|
if (parts.length == 1) {
|
||||||
{
|
|
||||||
label = null;
|
label = null;
|
||||||
args = new String[0];
|
args = new String[0];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
label = parts[1];
|
label = parts[1];
|
||||||
args = new String[parts.length - 2];
|
args = new String[parts.length - 2];
|
||||||
System.arraycopy(parts, 2, args, 0, args.length);
|
System.arraycopy(parts, 2, args, 0, args.length);
|
||||||
}
|
}
|
||||||
Command<PlotPlayer> cmd;
|
Command<PlotPlayer> cmd;
|
||||||
if (label != null)
|
if (label != null) {
|
||||||
{
|
|
||||||
cmd = getInstance().commands.get(label);
|
cmd = getInstance().commands.get(label);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
cmd = null;
|
cmd = null;
|
||||||
}
|
}
|
||||||
if (cmd == null)
|
if (cmd == null) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NOT_VALID_SUBCOMMAND);
|
MainUtil.sendMessage(plr, C.NOT_VALID_SUBCOMMAND);
|
||||||
{
|
{
|
||||||
final List<Command<PlotPlayer>> cmds = getCommands(null, plr);
|
final List<Command<PlotPlayer>> cmds = getCommands(null, plr);
|
||||||
if ((label == null) || (cmds.size() == 0))
|
if ((label == null) || (cmds.size() == 0)) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.DID_YOU_MEAN, "/plot help");
|
MainUtil.sendMessage(plr, C.DID_YOU_MEAN, "/plot help");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
final HashSet<String> setargs = new HashSet<>(args.length + 1);
|
final HashSet<String> setargs = new HashSet<>(args.length + 1);
|
||||||
for (final String arg : args)
|
for (final String arg : args) {
|
||||||
{
|
|
||||||
setargs.add(arg.toLowerCase());
|
setargs.add(arg.toLowerCase());
|
||||||
}
|
}
|
||||||
setargs.add(label.toLowerCase());
|
setargs.add(label.toLowerCase());
|
||||||
final String[] allargs = setargs.toArray(new String[setargs.size()]);
|
final String[] allargs = setargs.toArray(new String[setargs.size()]);
|
||||||
int best = 0;
|
int best = 0;
|
||||||
for (final Command<PlotPlayer> current : cmds)
|
for (final Command<PlotPlayer> current : cmds) {
|
||||||
{
|
if (current.getUsage() != null) {
|
||||||
if (current.getUsage() != null)
|
|
||||||
{
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (final String word : new HashSet<String>(Arrays.asList((current.getUsage() + " " + current.getPermission() + " " + current.getCategory().name()).toLowerCase()
|
for (final String word : new HashSet<String>(Arrays.asList((current.getUsage() + " " + current.getPermission() + " " + current.getCategory().name()).toLowerCase()
|
||||||
.replaceAll("\\||\\>|\\<|\\[|\\]|\\{|\\}|\\_|\\/", " ").trim().replaceAll("\\s+", " ").split(" "))))
|
.replaceAll("\\||\\>|\\<|\\[|\\]|\\{|\\}|\\_|\\/", " ").trim().replaceAll("\\s+", " ").split(" ")))) {
|
||||||
{
|
for (int i = 0; i < allargs.length; i++) {
|
||||||
for (int i = 0; i < allargs.length; i++)
|
|
||||||
{
|
|
||||||
final String arg = allargs[i];
|
final String arg = allargs[i];
|
||||||
if ((best - count - ((allargs.length - i) * 3)) >= 0)
|
if ((best - count - ((allargs.length - i) * 3)) >= 0) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (StringMan.isEqual(arg, word))
|
if (StringMan.isEqual(arg, word)) {
|
||||||
{
|
|
||||||
count += 3;
|
count += 3;
|
||||||
}
|
} else if ((word.length() > arg.length()) && word.contains(arg)) {
|
||||||
else if ((word.length() > arg.length()) && word.contains(arg))
|
|
||||||
{
|
|
||||||
count += 2;
|
count += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final String word : new HashSet<String>(Arrays.asList((current.getDescription()).toLowerCase().replaceAll("\\||\\>|\\<|\\[|\\]|\\{|\\}|\\_|\\/", " ").trim()
|
for (final String word : new HashSet<String>(Arrays.asList((current.getDescription()).toLowerCase().replaceAll("\\||\\>|\\<|\\[|\\]|\\{|\\}|\\_|\\/", " ").trim()
|
||||||
.replaceAll("\\s+", " ").split(" "))))
|
.replaceAll("\\s+", " ").split(" ")))) {
|
||||||
{
|
for (int i = 0; i < allargs.length; i++) {
|
||||||
for (int i = 0; i < allargs.length; i++)
|
|
||||||
{
|
|
||||||
final String arg = allargs[i];
|
final String arg = allargs[i];
|
||||||
if ((best - count - ((allargs.length - i) * 2)) >= 0)
|
if ((best - count - ((allargs.length - i) * 2)) >= 0) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (StringMan.isEqual(arg, word))
|
if (StringMan.isEqual(arg, word)) {
|
||||||
{
|
|
||||||
count += 2;
|
count += 2;
|
||||||
}
|
} else if ((word.length() > arg.length()) && word.contains(arg)) {
|
||||||
else if ((word.length() > arg.length()) && word.contains(arg))
|
|
||||||
{
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count > best)
|
if (count > best) {
|
||||||
{
|
|
||||||
best = count;
|
best = count;
|
||||||
cmd = current;
|
cmd = current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cmd == null)
|
if (cmd == null) {
|
||||||
{
|
|
||||||
cmd = new StringComparison<>(label, getCommandAndAliases(null, plr)).getMatchObject();
|
cmd = new StringComparison<>(label, getCommandAndAliases(null, plr)).getMatchObject();
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(plr, C.DID_YOU_MEAN, cmd.getUsage().replaceAll("\\{label\\}", parts[0]));
|
MainUtil.sendMessage(plr, C.DID_YOU_MEAN, cmd.getUsage().replaceAll("\\{label\\}", parts[0]));
|
||||||
@ -487,53 +396,39 @@ public class MainCommand extends CommandManager<PlotPlayer>
|
|||||||
}
|
}
|
||||||
return CommandHandlingOutput.NOT_FOUND;
|
return CommandHandlingOutput.NOT_FOUND;
|
||||||
}
|
}
|
||||||
if (!cmd.getRequiredType().allows(plr))
|
if (!cmd.getRequiredType().allows(plr)) {
|
||||||
{
|
if (ConsolePlayer.isConsole(plr)) {
|
||||||
if (ConsolePlayer.isConsole(plr))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.IS_CONSOLE);
|
MainUtil.sendMessage(plr, C.IS_CONSOLE);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
|
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
|
||||||
}
|
}
|
||||||
return CommandHandlingOutput.CALLER_OF_WRONG_TYPE;
|
return CommandHandlingOutput.CALLER_OF_WRONG_TYPE;
|
||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(plr, cmd.getPermission()))
|
if (!Permissions.hasPermission(plr, cmd.getPermission())) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, cmd.getPermission());
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, cmd.getPermission());
|
||||||
return CommandHandlingOutput.NOT_PERMITTED;
|
return CommandHandlingOutput.NOT_PERMITTED;
|
||||||
}
|
}
|
||||||
final Argument<?>[] requiredArguments = cmd.getRequiredArguments();
|
final Argument<?>[] requiredArguments = cmd.getRequiredArguments();
|
||||||
if ((requiredArguments != null) && (requiredArguments.length > 0))
|
if ((requiredArguments != null) && (requiredArguments.length > 0)) {
|
||||||
{
|
|
||||||
boolean success = true;
|
boolean success = true;
|
||||||
if (args.length < requiredArguments.length)
|
if (args.length < requiredArguments.length) {
|
||||||
{
|
|
||||||
success = false;
|
success = false;
|
||||||
}
|
} else {
|
||||||
else
|
for (int i = 0; i < requiredArguments.length; i++) {
|
||||||
{
|
if (requiredArguments[i].parse(args[i]) == null) {
|
||||||
for (int i = 0; i < requiredArguments.length; i++)
|
|
||||||
{
|
|
||||||
if (requiredArguments[i].parse(args[i]) == null)
|
|
||||||
{
|
|
||||||
success = false;
|
success = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!success)
|
if (!success) {
|
||||||
{
|
|
||||||
C.COMMAND_SYNTAX.send(plr, cmd.getUsage());
|
C.COMMAND_SYNTAX.send(plr, cmd.getUsage());
|
||||||
return CommandHandlingOutput.WRONG_USAGE;
|
return CommandHandlingOutput.WRONG_USAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
final boolean result = cmd.onCommand(plr, args);
|
final boolean result = cmd.onCommand(plr, args);
|
||||||
if (!result)
|
if (!result) {
|
||||||
{
|
|
||||||
cmd.getUsage();
|
cmd.getUsage();
|
||||||
// Unecessary!
|
// Unecessary!
|
||||||
// if (usage != null && !usage.isEmpty()) {
|
// if (usage != null && !usage.isEmpty()) {
|
||||||
@ -541,9 +436,7 @@ public class MainCommand extends CommandManager<PlotPlayer>
|
|||||||
// }
|
// }
|
||||||
return CommandHandlingOutput.WRONG_USAGE;
|
return CommandHandlingOutput.WRONG_USAGE;
|
||||||
}
|
}
|
||||||
}
|
} catch (final Throwable t) {
|
||||||
catch (final Throwable t)
|
|
||||||
{
|
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
return CommandHandlingOutput.ERROR;
|
return CommandHandlingOutput.ERROR;
|
||||||
}
|
}
|
||||||
|
@ -49,17 +49,14 @@ permission = "plots.merge",
|
|||||||
usage = "/plot merge [direction]",
|
usage = "/plot merge [direction]",
|
||||||
category = CommandCategory.ACTIONS,
|
category = CommandCategory.ACTIONS,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
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 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);
|
||||||
switch (i)
|
switch (i) {
|
||||||
{
|
|
||||||
case -4:
|
case -4:
|
||||||
case 0:
|
case 0:
|
||||||
case 4:
|
case 4:
|
||||||
@ -79,28 +76,25 @@ public class Merge extends SubCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
final Location loc = plr.getLocationFull();
|
final Location loc = plr.getLocationFull();
|
||||||
final Plot plot = MainUtil.getPlot(loc);
|
final Plot plot = MainUtil.getPlot(loc);
|
||||||
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
|
if (plot == null) {
|
||||||
if ((plot == null) || !plot.hasOwner())
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
{
|
}
|
||||||
|
if ((plot == null) || !plot.hasOwner()) {
|
||||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final boolean admin = Permissions.hasPermission(plr, "plots.admin.command.merge");
|
final boolean admin = Permissions.hasPermission(plr, "plots.admin.command.merge");
|
||||||
if (!plot.isOwner(plr.getUUID()) && !admin)
|
if (!plot.isOwner(plr.getUUID()) && !admin) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int direction = -1;
|
int direction = -1;
|
||||||
if (args.length == 0)
|
if (args.length == 0) {
|
||||||
{
|
switch (direction(plr.getLocationFull().getYaw())) {
|
||||||
switch (direction(plr.getLocationFull().getYaw()))
|
|
||||||
{
|
|
||||||
case "NORTH":
|
case "NORTH":
|
||||||
direction = 0;
|
direction = 0;
|
||||||
break;
|
break;
|
||||||
@ -114,26 +108,20 @@ public class Merge extends SubCommand
|
|||||||
direction = 3;
|
direction = 3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if (args[0].equalsIgnoreCase("all")) {
|
||||||
{
|
|
||||||
if (args[0].equalsIgnoreCase("all"))
|
|
||||||
{
|
|
||||||
plot.autoMerge((args.length != 2) || !args[1].equalsIgnoreCase("false"));
|
plot.autoMerge((args.length != 2) || !args[1].equalsIgnoreCase("false"));
|
||||||
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
|
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < values.length; i++)
|
for (int i = 0; i < values.length; i++) {
|
||||||
{
|
if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) {
|
||||||
if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i]))
|
|
||||||
{
|
|
||||||
direction = i;
|
direction = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (direction == -1)
|
if (direction == -1) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringMan.join(values, C.BLOCK_LIST_SEPARATER.s()));
|
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringMan.join(values, C.BLOCK_LIST_SEPARATER.s()));
|
||||||
MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(loc.getYaw())));
|
MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(loc.getYaw())));
|
||||||
return false;
|
return false;
|
||||||
@ -142,8 +130,7 @@ public class Merge extends SubCommand
|
|||||||
PlotId top = MainUtil.getTopPlot(plot).id;
|
PlotId top = MainUtil.getTopPlot(plot).id;
|
||||||
ArrayList<PlotId> selPlots;
|
ArrayList<PlotId> selPlots;
|
||||||
final String world = loc.getWorld();
|
final String world = loc.getWorld();
|
||||||
switch (direction)
|
switch (direction) {
|
||||||
{
|
|
||||||
case 0: // north = -y
|
case 0: // north = -y
|
||||||
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
|
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
|
||||||
break;
|
break;
|
||||||
@ -160,8 +147,7 @@ public class Merge extends SubCommand
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final int size = selPlots.size();
|
final int size = selPlots.size();
|
||||||
if (Permissions.hasPermissionRange(plr, "plots.merge", Settings.MAX_PLOTS) < size)
|
if (Permissions.hasPermissionRange(plr, "plots.merge", Settings.MAX_PLOTS) < size) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.merge." + size);
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.merge." + size);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -178,22 +164,18 @@ public class Merge extends SubCommand
|
|||||||
final HashSet<UUID> multiUUID = new HashSet<UUID>();
|
final HashSet<UUID> multiUUID = new HashSet<UUID>();
|
||||||
final HashSet<PlotId> multiPlots = new HashSet<>();
|
final HashSet<PlotId> multiPlots = new HashSet<>();
|
||||||
final UUID u1 = plot.owner;
|
final UUID u1 = plot.owner;
|
||||||
for (final PlotId myid : plots)
|
for (final PlotId myid : plots) {
|
||||||
{
|
|
||||||
final Plot myplot = PS.get().getPlot(world, myid);
|
final Plot myplot = PS.get().getPlot(world, myid);
|
||||||
if ((myplot == null) || (myplot.owner == null))
|
if ((myplot == null) || (myplot.owner == null)) {
|
||||||
{
|
|
||||||
MainUtil.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 UUID u2 = myplot.owner;
|
final UUID u2 = myplot.owner;
|
||||||
if (u2.equals(u1))
|
if (u2.equals(u1)) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final PlotPlayer p2 = UUIDHandler.getPlayer(u2);
|
final PlotPlayer p2 = UUIDHandler.getPlayer(u2);
|
||||||
if (p2 == null)
|
if (p2 == null) {
|
||||||
{
|
|
||||||
MainUtil.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;
|
||||||
}
|
}
|
||||||
@ -201,40 +183,30 @@ public class Merge extends SubCommand
|
|||||||
multiPlots.add(myid);
|
multiPlots.add(myid);
|
||||||
multiUUID.add(u2);
|
multiUUID.add(u2);
|
||||||
}
|
}
|
||||||
if (multiMerge)
|
if (multiMerge) {
|
||||||
{
|
if (!Permissions.hasPermission(plr, C.PERMISSION_MERGE_OTHER)) {
|
||||||
if (!Permissions.hasPermission(plr, C.PERMISSION_MERGE_OTHER))
|
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, C.PERMISSION_MERGE_OTHER.s());
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, C.PERMISSION_MERGE_OTHER.s());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (final UUID uuid : multiUUID)
|
for (final UUID uuid : multiUUID) {
|
||||||
{
|
|
||||||
final PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
|
final PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
|
||||||
CmdConfirm.addPending(accepter, C.MERGE_REQUEST_CONFIRM.s().replaceAll("%s", plr.getName()), new Runnable()
|
CmdConfirm.addPending(accepter, C.MERGE_REQUEST_CONFIRM.s().replaceAll("%s", plr.getName()), new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
final PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
|
final PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
|
||||||
multiUUID.remove(uuid);
|
multiUUID.remove(uuid);
|
||||||
if (multiUUID.size() == 0)
|
if (multiUUID.size() == 0) {
|
||||||
{
|
|
||||||
final PlotPlayer pp = UUIDHandler.getPlayer(u1);
|
final PlotPlayer pp = UUIDHandler.getPlayer(u1);
|
||||||
if (pp == null)
|
if (pp == null) {
|
||||||
{
|
|
||||||
sendMessage(accepter, C.MERGE_NOT_VALID);
|
sendMessage(accepter, C.MERGE_NOT_VALID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
|
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
|
||||||
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY)
|
if ((EconHandler.manager != null) && 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) {
|
||||||
{
|
if (EconHandler.manager.getMoney(plr) < cost) {
|
||||||
if (EconHandler.manager.getMoney(plr) < cost)
|
|
||||||
{
|
|
||||||
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
|
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -243,8 +215,7 @@ public class Merge extends SubCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
|
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
|
||||||
if (!result)
|
if (!result) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
|
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -260,14 +231,11 @@ public class Merge extends SubCommand
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
|
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
|
||||||
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY)
|
if ((EconHandler.manager != null) && 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) {
|
||||||
{
|
if (EconHandler.manager.getMoney(plr) < cost) {
|
||||||
if (EconHandler.manager.getMoney(plr) < cost)
|
|
||||||
{
|
|
||||||
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
|
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -276,8 +244,7 @@ public class Merge extends SubCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
|
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
|
||||||
if (!result)
|
if (!result) {
|
||||||
{
|
|
||||||
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
|
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user