mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Reformat code
This commit is contained in:
@ -18,7 +18,7 @@ processResources {
|
||||
}
|
||||
}
|
||||
|
||||
jar.archiveName="plotsquared-api-${project.parent.version}.jar"
|
||||
jar.archiveName = "plotsquared-api-${project.parent.version}.jar"
|
||||
jar.destinationDir = file '../mvn/com/plotsquared/plotsquared-api/' + project.parent.version
|
||||
task createPom << {
|
||||
pom {
|
||||
@ -43,10 +43,10 @@ task copyFiles {
|
||||
from "../mvn/com/plotsquared/plotsquared-api/${project.parent.version}/"
|
||||
into '../mvn/com/plotsquared/plotsquared-api/latest/'
|
||||
include('*.jar')
|
||||
rename ("plotsquared-api-${project.parent.version}.jar", 'plotsquared-api-latest.jar')
|
||||
rename("plotsquared-api-${project.parent.version}.jar", 'plotsquared-api-latest.jar')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
build.finalizedBy(copyFiles)
|
||||
copyFiles.dependsOn(createPom)
|
||||
copyFiles.dependsOn(createPom)
|
||||
|
@ -8,23 +8,23 @@ import java.util.Map;
|
||||
public interface Configuration extends ConfigurationSection {
|
||||
/**
|
||||
* Sets the default value of the given path as provided.
|
||||
*
|
||||
* <p>
|
||||
* <p>If no source {@link Configuration} was provided as a default
|
||||
* collection, then a new {@link MemoryConfiguration} will be created to
|
||||
* hold the new default value.</p>
|
||||
*
|
||||
* <p>
|
||||
* <p>If value is null, the value will be removed from the default
|
||||
* Configuration source.</p>
|
||||
*
|
||||
* @param path Path of the value to set.
|
||||
* @param path Path of the value to set.
|
||||
* @param value Value to set the default to.
|
||||
* @throws IllegalArgumentException Thrown if path is null.
|
||||
*/
|
||||
@Override void addDefault(String path, Object value);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the default values of the given paths as provided.
|
||||
*
|
||||
* <p>
|
||||
* <p>If no source {@link Configuration} was provided as a default
|
||||
* collection, then a new {@link MemoryConfiguration} will be created to
|
||||
* hold the new default values.</p>
|
||||
@ -33,14 +33,14 @@ public interface Configuration extends ConfigurationSection {
|
||||
* @throws IllegalArgumentException Thrown if defaults is null.
|
||||
*/
|
||||
void addDefaults(Map<String, Object> defaults);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the default values of the given paths as provided.
|
||||
*
|
||||
* <p>
|
||||
* <p>If no source {@link Configuration} was provided as a default
|
||||
* collection, then a new {@link MemoryConfiguration} will be created to
|
||||
* hold the new default value.</p>
|
||||
*
|
||||
* <p>
|
||||
* <p>This method will not hold a reference to the specified Configuration,
|
||||
* nor will it automatically update if that Configuration ever changes. If
|
||||
* you check this, you should set the default source with {@link
|
||||
@ -50,10 +50,10 @@ public interface Configuration extends ConfigurationSection {
|
||||
* @throws IllegalArgumentException Thrown if defaults is null or this.
|
||||
*/
|
||||
void addDefaults(Configuration defaults);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the source {@link Configuration} for this configuration.
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* If no configuration source was set, but default values were added, then
|
||||
* a {@link MemoryConfiguration} will be returned. If no source was set
|
||||
@ -62,10 +62,10 @@ public interface Configuration extends ConfigurationSection {
|
||||
* @return Configuration source for default values, or null if none exist.
|
||||
*/
|
||||
Configuration getDefaults();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the source of all default values for this {@link Configuration}.
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* If a previous source was set, or previous default values were defined,
|
||||
* then they will not be copied to the new source.</p>
|
||||
@ -77,7 +77,7 @@ public interface Configuration extends ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the {@link ConfigurationOptions} for this {@link Configuration}.
|
||||
*
|
||||
* <p>
|
||||
* <p>All setters through this method are chainable.</p>
|
||||
*
|
||||
* @return Options for this configuration
|
||||
|
@ -8,11 +8,11 @@ class ConfigurationOptions {
|
||||
private final Configuration configuration;
|
||||
private char pathSeparator = '.';
|
||||
private boolean copyDefaults = false;
|
||||
|
||||
|
||||
protected ConfigurationOptions(Configuration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the {@link Configuration} that this object is responsible for.
|
||||
*
|
||||
@ -21,11 +21,11 @@ class ConfigurationOptions {
|
||||
public Configuration configuration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the char that will be used to separate {@link
|
||||
* ConfigurationSection}s.
|
||||
*
|
||||
* <p>
|
||||
* <p>This value does not affect how the {@link Configuration} is stored,
|
||||
* only in how you access the data. The default value is '.'.
|
||||
*
|
||||
@ -34,11 +34,11 @@ class ConfigurationOptions {
|
||||
public char pathSeparator() {
|
||||
return pathSeparator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the char that will be used to separate {@link
|
||||
* ConfigurationSection}s.
|
||||
*
|
||||
* <p>
|
||||
* <p>This value does not affect how the {@link Configuration} is stored,
|
||||
* only in how you access the data. The default value is '.'.
|
||||
*
|
||||
@ -49,11 +49,11 @@ class ConfigurationOptions {
|
||||
pathSeparator = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the {@link Configuration} should copy values from its default
|
||||
* {@link Configuration} directly.
|
||||
*
|
||||
* <p>
|
||||
* <p>If this is true, all values in the default Configuration will be
|
||||
* directly copied, making it impossible to distinguish between values
|
||||
* that were set and values that are provided by default. As a result,
|
||||
@ -67,11 +67,11 @@ class ConfigurationOptions {
|
||||
public boolean copyDefaults() {
|
||||
return copyDefaults;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets if the {@link Configuration} should copy values from its default
|
||||
* {@link Configuration} directly.
|
||||
*
|
||||
* <p>
|
||||
* <p>If this is true, all values in the default Configuration will be
|
||||
* directly copied, making it impossible to distinguish between values
|
||||
* that were set and values that are provided by default. As a result,
|
||||
|
@ -11,45 +11,45 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets a set containing all keys in this section.
|
||||
*
|
||||
* <p>
|
||||
* <p>If deep is set to true, then this will contain all the keys within any
|
||||
* child {@link ConfigurationSection}s (and their children, etc). These
|
||||
* will be in a valid path notation for you to use.
|
||||
*
|
||||
* <p>
|
||||
* <p>If deep is set to false, then this will contain only the keys of any
|
||||
* direct children, and not their own children.
|
||||
*
|
||||
* @param deep Whether or not to get a deep list, as opposed to a shallow
|
||||
* list.
|
||||
* list.
|
||||
* @return Set of keys contained within this ConfigurationSection.
|
||||
*/
|
||||
Set<String> getKeys(boolean deep);
|
||||
|
||||
/**
|
||||
* Gets a Map containing all keys and their values for this section.
|
||||
*
|
||||
* <p>
|
||||
* <p>If deep is set to true, then this will contain all the keys and values
|
||||
* within any child {@link ConfigurationSection}s (and their children,
|
||||
* etc). These keys will be in a valid path notation for you to use.
|
||||
*
|
||||
* <p>
|
||||
* <p>If deep is set to false, then this will contain only the keys and
|
||||
* values of any direct children, and not their own children.
|
||||
*
|
||||
* @param deep Whether or not to get a deep list, as opposed to a shallow
|
||||
* list.
|
||||
* list.
|
||||
* @return Map of keys and values of this section.
|
||||
*/
|
||||
Map<String, Object> getValues(boolean deep);
|
||||
|
||||
/**
|
||||
* Checks if this {@link ConfigurationSection} contains the given path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the value for the requested path does not exist but a default value
|
||||
* has been specified, this will return true.
|
||||
*
|
||||
* @param path Path to check for existence.
|
||||
* @return True if this section contains the requested path, either via
|
||||
* default or being set.
|
||||
* default or being set.
|
||||
* @throws IllegalArgumentException Thrown when path is {@code null}.
|
||||
*/
|
||||
boolean contains(String path);
|
||||
@ -57,13 +57,13 @@ public interface ConfigurationSection {
|
||||
/**
|
||||
* Checks if this {@link ConfigurationSection} has a value set for the
|
||||
* given path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the value for the requested path does not exist but a default value
|
||||
* has been specified, this will still return false.
|
||||
*
|
||||
* @param path Path to check for existence.
|
||||
* @return True if this section contains the requested path, regardless of
|
||||
* having a default.
|
||||
* having a default.
|
||||
* @throws IllegalArgumentException Thrown when path is {@code null}.
|
||||
*/
|
||||
boolean isSet(String path);
|
||||
@ -71,14 +71,14 @@ public interface ConfigurationSection {
|
||||
/**
|
||||
* Gets the path of this {@link ConfigurationSection} from its root {@link
|
||||
* Configuration}.
|
||||
*
|
||||
* <p>
|
||||
* <p>For any {@link Configuration} themselves, this will return an empty
|
||||
* string.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the section is no longer contained within its root for any reason,
|
||||
* such as being replaced with a different value,
|
||||
* this may return {@code null}.
|
||||
*
|
||||
* <p>
|
||||
* <p>To retrieve the single name of this section, that is, the final part
|
||||
* of the path returned by this method, you may use {@link #getName()}.
|
||||
*
|
||||
@ -89,7 +89,7 @@ public interface ConfigurationSection {
|
||||
/**
|
||||
* Gets the name of this individual {@link ConfigurationSection}, in the
|
||||
* path.
|
||||
*
|
||||
* <p>
|
||||
* <p>This will always be the final part of {@link #getCurrentPath()}, unless
|
||||
* the section is orphaned.
|
||||
*
|
||||
@ -100,10 +100,10 @@ public interface ConfigurationSection {
|
||||
/**
|
||||
* Gets the root {@link Configuration} that contains this {@link
|
||||
* ConfigurationSection}
|
||||
*
|
||||
* <p>
|
||||
* <p>For any {@link Configuration} themselves, this will return its own
|
||||
* object.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the section is no longer contained within its root for any reason,
|
||||
* such as being replaced with a different value,
|
||||
* this may return {@code null}.
|
||||
@ -115,10 +115,10 @@ public interface ConfigurationSection {
|
||||
/**
|
||||
* Gets the parent {@link ConfigurationSection} that directly contains
|
||||
* this {@link ConfigurationSection}.
|
||||
*
|
||||
* <p>
|
||||
* <p>For any {@link Configuration} themselves, this will return
|
||||
* {@code null}.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the section is no longer contained within its parent for any
|
||||
* reason, such as being replaced with a different value, this may
|
||||
* return {@code null}.
|
||||
@ -129,7 +129,7 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested Object by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the Object does not exist but a default value has been specified,
|
||||
* this will return the default value. If the Object does not exist and no
|
||||
* default value was specified, this will return {@code null}.
|
||||
@ -142,12 +142,12 @@ public interface ConfigurationSection {
|
||||
/**
|
||||
* Gets the requested Object by path, returning a default value if not
|
||||
* found.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the Object does not exist then the specified default value will
|
||||
* returned regardless of if a default has been identified in the root
|
||||
* {@link Configuration}.
|
||||
*
|
||||
* @param path Path of the Object to get.
|
||||
* @param path Path of the Object to get.
|
||||
* @param defaultValue The default value to return if the path is not found.
|
||||
* @return Requested Object.
|
||||
*/
|
||||
@ -155,23 +155,23 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Sets the specified path to the given value.
|
||||
*
|
||||
* <p>
|
||||
* <p>If value is {@code null}, the entry will be removed. Any
|
||||
* existing entry will be replaced, regardless of what the new value is.
|
||||
*
|
||||
* <p>
|
||||
* <p>Some implementations may have limitations on what you may store. See
|
||||
* their individual javadoc for details. No implementations should allow
|
||||
* you to store {@link Configuration}s or {@link ConfigurationSection}s,
|
||||
* please use {@link #createSection(String)} for that.
|
||||
*
|
||||
* @param path Path of the object to set.
|
||||
* @param path Path of the object to set.
|
||||
* @param value New value to set the path to.
|
||||
*/
|
||||
void set(String path, Object value);
|
||||
|
||||
/**
|
||||
* Creates an empty {@link ConfigurationSection} at the specified path.
|
||||
*
|
||||
* <p>
|
||||
* <p>Any value that was previously set at this path will be overwritten. If
|
||||
* the previous value was itself a {@link ConfigurationSection}, it will
|
||||
* be orphaned.
|
||||
@ -184,13 +184,13 @@ public interface ConfigurationSection {
|
||||
/**
|
||||
* Creates a {@link ConfigurationSection} at the specified path, with
|
||||
* specified values.
|
||||
*
|
||||
* <p>
|
||||
* <p>Any value that was previously set at this path will be overwritten. If
|
||||
* the previous value was itself a {@link ConfigurationSection}, it will
|
||||
* be orphaned.
|
||||
*
|
||||
* @param path Path to create the section at.
|
||||
* @param map The values to used.
|
||||
* @param map The values to used.
|
||||
* @return Newly created section
|
||||
*/
|
||||
ConfigurationSection createSection(String path, Map<?, ?> map);
|
||||
@ -199,7 +199,7 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested String by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the String does not exist but a default value has been specified,
|
||||
* this will return the default value. If the String does not exist and no
|
||||
* default value was specified, this will return {@code null}.
|
||||
@ -212,21 +212,21 @@ public interface ConfigurationSection {
|
||||
/**
|
||||
* Gets the requested String by path, returning a default value if not
|
||||
* found.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the String does not exist then the specified default value will
|
||||
* returned regardless of if a default has been identified in the root
|
||||
* {@link Configuration}.
|
||||
*
|
||||
* @param path Path of the String to get.
|
||||
* @param def The default value to return if the path is not found or is
|
||||
* not a String.
|
||||
* @param def The default value to return if the path is not found or is
|
||||
* not a String.
|
||||
* @return Requested String.
|
||||
*/
|
||||
String getString(String path, String def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a String.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the path exists but is not a String, this will return false. If
|
||||
* the path does not exist, this will return false. If the path does not
|
||||
* exist but a default value has been specified, this will check if that
|
||||
@ -239,7 +239,7 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested int by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the int does not exist but a default value has been specified, this
|
||||
* will return the default value. If the int does not exist and no default
|
||||
* value was specified, this will return 0.
|
||||
@ -251,21 +251,21 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested int by path, returning a default value if not found.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the int does not exist then the specified default value will
|
||||
* returned regardless of if a default has been identified in the root
|
||||
* {@link Configuration}.
|
||||
*
|
||||
* @param path Path of the int to get.
|
||||
* @param def The default value to return if the path is not found or is
|
||||
* not an int.
|
||||
* @param def The default value to return if the path is not found or is
|
||||
* not an int.
|
||||
* @return Requested int.
|
||||
*/
|
||||
int getInt(String path, int def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is an int.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the path exists but is not a int, this will return false. If the
|
||||
* path does not exist, this will return false. If the path does not exist
|
||||
* but a default value has been specified, this will check if that default
|
||||
@ -278,7 +278,7 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested boolean by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the boolean does not exist but a default value has been specified,
|
||||
* this will return the default value. If the boolean does not exist and
|
||||
* no default value was specified, this will return false.
|
||||
@ -291,21 +291,21 @@ public interface ConfigurationSection {
|
||||
/**
|
||||
* Gets the requested boolean by path, returning a default value if not
|
||||
* found.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the boolean does not exist then the specified default value will
|
||||
* returned regardless of if a default has been identified in the root
|
||||
* {@link Configuration}.
|
||||
*
|
||||
* @param path Path of the boolean to get.
|
||||
* @param path Path of the boolean to get.
|
||||
* @param defaultValue The default value to return if the path is not found or is
|
||||
* not a boolean.
|
||||
* not a boolean.
|
||||
* @return Requested boolean.
|
||||
*/
|
||||
boolean getBoolean(String path, boolean defaultValue);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a boolean.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the path exists but is not a boolean, this will return false. If the
|
||||
* path does not exist, this will return false. If the path does not exist
|
||||
* but a default value has been specified, this will check if that default
|
||||
@ -318,7 +318,7 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested double by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the double does not exist but a default value has been specified,
|
||||
* this will return the default value. If the double does not exist and no
|
||||
* default value was specified, this will return 0.
|
||||
@ -331,21 +331,21 @@ public interface ConfigurationSection {
|
||||
/**
|
||||
* Gets the requested double by path, returning a default value if not
|
||||
* found.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the double does not exist then the specified default value will
|
||||
* returned regardless of if a default has been identified in the root
|
||||
* {@link Configuration}.
|
||||
*
|
||||
* @param path Path of the double to get.
|
||||
* @param path Path of the double to get.
|
||||
* @param defaultValue The default value to return if the path is not found or is
|
||||
* not a double.
|
||||
* not a double.
|
||||
* @return Requested double.
|
||||
*/
|
||||
double getDouble(String path, double defaultValue);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a double.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the path exists but is not a double, this will return false. If the
|
||||
* path does not exist, this will return false. If the path does not exist
|
||||
* but a default value has been specified, this will check if that default
|
||||
@ -358,7 +358,7 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested long by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the long does not exist but a default value has been specified, this
|
||||
* will return the default value. If the long does not exist and no
|
||||
* default value was specified, this will return 0.
|
||||
@ -371,21 +371,21 @@ public interface ConfigurationSection {
|
||||
/**
|
||||
* Gets the requested long by path, returning a default value if not
|
||||
* found.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the long does not exist then the specified default value will
|
||||
* returned regardless of if a default has been identified in the root
|
||||
* {@link Configuration}.
|
||||
*
|
||||
* @param path Path of the long to get.
|
||||
* @param def The default value to return if the path is not found or is
|
||||
* not a long.
|
||||
* @param def The default value to return if the path is not found or is
|
||||
* not a long.
|
||||
* @return Requested long.
|
||||
*/
|
||||
long getLong(String path, long def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a long.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the path exists but is not a long, this will return false. If the
|
||||
* path does not exist, this will return false. If the path does not exist
|
||||
* but a default value has been specified, this will check if that default
|
||||
@ -400,7 +400,7 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested List by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the List does not exist but a default value has been specified, this
|
||||
* will return the default value. If the List does not exist and no
|
||||
* default value was specified, this will return null.
|
||||
@ -413,21 +413,21 @@ public interface ConfigurationSection {
|
||||
/**
|
||||
* Gets the requested List by path, returning a default value if not
|
||||
* found.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the List does not exist then the specified default value will
|
||||
* returned regardless of if a default has been identified in the root
|
||||
* {@link Configuration}.
|
||||
*
|
||||
* @param path Path of the List to get.
|
||||
* @param def The default value to return if the path is not found or is
|
||||
* not a List.
|
||||
* @param def The default value to return if the path is not found or is
|
||||
* not a List.
|
||||
* @return Requested List.
|
||||
*/
|
||||
List<?> getList(String path, List<?> def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a List.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the path exists but is not a List, this will return false. If the
|
||||
* path does not exist, this will return false. If the path does not exist
|
||||
* but a default value has been specified, this will check if that default
|
||||
@ -440,11 +440,11 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested List of String by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the List does not exist but a default value has been specified,
|
||||
* this will return the default value. If the List does not exist and no
|
||||
* default value was specified, this will return an empty List.
|
||||
*
|
||||
* <p>
|
||||
* <p>This method will attempt to cast any values into a String if possible,
|
||||
* but may miss any values out if they are not compatible.
|
||||
*
|
||||
@ -455,11 +455,11 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested List of Integer by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the List does not exist but a default value has been specified,
|
||||
* this will return the default value. If the List does not exist and no
|
||||
* default value was specified, this will return an empty List.
|
||||
*
|
||||
* <p>
|
||||
* <p>This method will attempt to cast any values into a Integer if
|
||||
* possible, but may miss any values out if they are not compatible.
|
||||
*
|
||||
@ -470,11 +470,11 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested List of Boolean by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the List does not exist but a default value has been specified,
|
||||
* this will return the default value. If the List does not exist and no
|
||||
* default value was specified, this will return an empty List.
|
||||
*
|
||||
* <p>
|
||||
* <p>This method will attempt to cast any values into a Boolean if
|
||||
* possible, but may miss any values out if they are not compatible.
|
||||
*
|
||||
@ -485,11 +485,11 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested List of Double by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the List does not exist but a default value has been specified,
|
||||
* this will return the default value. If the List does not exist and no
|
||||
* default value was specified, this will return an empty List.
|
||||
*
|
||||
* <p>
|
||||
* <p>This method will attempt to cast any values into a Double if possible,
|
||||
* but may miss any values out if they are not compatible.
|
||||
*
|
||||
@ -500,11 +500,11 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested List of Float by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the List does not exist but a default value has been specified,
|
||||
* this will return the default value. If the List does not exist and no
|
||||
* default value was specified, this will return an empty List.
|
||||
*
|
||||
* <p>
|
||||
* <p>This method will attempt to cast any values into a Float if possible,
|
||||
* but may miss any values out if they are not compatible.
|
||||
*
|
||||
@ -515,11 +515,11 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested List of Long by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the List does not exist but a default value has been specified,
|
||||
* this will return the default value. If the List does not exist and no
|
||||
* default value was specified, this will return an empty List.
|
||||
*
|
||||
* <p>
|
||||
* <p>This method will attempt to cast any values into a Long if possible,
|
||||
* but may miss any values out if they are not compatible.
|
||||
*
|
||||
@ -530,11 +530,11 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested List of Byte by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the List does not exist but a default value has been specified,
|
||||
* this will return the default value. If the List does not exist and no
|
||||
* default value was specified, this will return an empty List.
|
||||
*
|
||||
* <p>
|
||||
* <p>This method will attempt to cast any values into a Byte if possible,
|
||||
* but may miss any values out if they are not compatible.
|
||||
*
|
||||
@ -545,11 +545,11 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested List of Character by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the List does not exist but a default value has been specified,
|
||||
* this will return the default value. If the List does not exist and no
|
||||
* default value was specified, this will return an empty List.
|
||||
*
|
||||
* <p>
|
||||
* <p>This method will attempt to cast any values into a Character if
|
||||
* possible, but may miss any values out if they are not compatible.
|
||||
*
|
||||
@ -560,11 +560,11 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested List of Short by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the List does not exist but a default value has been specified,
|
||||
* this will return the default value. If the List does not exist and no
|
||||
* default value was specified, this will return an empty List.
|
||||
*
|
||||
* <p>
|
||||
* <p>This method will attempt to cast any values into a Short if
|
||||
* possible, but may miss any values out if they are not compatible.
|
||||
*
|
||||
@ -575,7 +575,7 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested List of Maps by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the List does not exist but a default value has been specified,
|
||||
* this will return the default value. If the List does not exist and no
|
||||
* default value was specified, this will return an empty List.
|
||||
@ -589,7 +589,7 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Gets the requested ConfigurationSection by path.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the ConfigurationSection does not exist but a default value has
|
||||
* been specified, this will return the default value. If the
|
||||
* ConfigurationSection does not exist and no default value was specified,
|
||||
@ -602,7 +602,7 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a ConfigurationSection.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the path exists but is not a ConfigurationSection, this will return
|
||||
* false. If the path does not exist, this will return false. If the path
|
||||
* does not exist but a default value has been specified, this will check
|
||||
@ -617,7 +617,7 @@ public interface ConfigurationSection {
|
||||
/**
|
||||
* Gets the equivalent {@link ConfigurationSection} from the default
|
||||
* {@link Configuration} defined in {@link #getRoot()}.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the root contains no defaults, or the defaults doesn't contain a
|
||||
* value for this path, or the value at this path is not a {@link
|
||||
* ConfigurationSection} then this will return {@code null}.
|
||||
@ -628,19 +628,19 @@ public interface ConfigurationSection {
|
||||
|
||||
/**
|
||||
* Sets the default value in the root at the given path as provided.
|
||||
*
|
||||
* <p>
|
||||
* <p>If no source {@link Configuration} was provided as a default
|
||||
* collection, then a new {@link MemoryConfiguration} will be created to
|
||||
* hold the new default value.
|
||||
*
|
||||
* <p>
|
||||
* <p>If value is {@code null}, the value will be removed from the
|
||||
* default Configuration source.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the value as returned by {@link #getDefaultSection()} is
|
||||
* {@code null}, then this will create a new section at the path,
|
||||
* replacing anything that may have existed there previously.
|
||||
*
|
||||
* @param path Path of the value to set
|
||||
* @param path Path of the value to set
|
||||
* @param value Value to set the default to
|
||||
* @throws IllegalArgumentException Thrown if path is {@code null}
|
||||
*/
|
||||
|
@ -3,15 +3,15 @@ package com.intellectualcrafters.configuration;
|
||||
/**
|
||||
* Exception thrown when attempting to load an invalid {@link Configuration}.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class InvalidConfigurationException extends Exception {
|
||||
|
||||
@SuppressWarnings("serial") public class InvalidConfigurationException extends Exception {
|
||||
|
||||
/**
|
||||
* Creates a new instance of InvalidConfigurationException without a
|
||||
* message or cause.
|
||||
*/
|
||||
public InvalidConfigurationException() {}
|
||||
|
||||
public InvalidConfigurationException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of InvalidConfigurationException with the
|
||||
* specified message.
|
||||
@ -21,7 +21,7 @@ public class InvalidConfigurationException extends Exception {
|
||||
public InvalidConfigurationException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an instance of InvalidConfigurationException with the
|
||||
* specified cause.
|
||||
@ -31,13 +31,13 @@ public class InvalidConfigurationException extends Exception {
|
||||
public InvalidConfigurationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an instance of InvalidConfigurationException with the
|
||||
* specified message and cause.
|
||||
*
|
||||
* @param cause The cause of the exception.
|
||||
* @param msg The details of the exception.
|
||||
* @param msg The details of the exception.
|
||||
*/
|
||||
public InvalidConfigurationException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
|
@ -10,12 +10,13 @@ import java.util.Map;
|
||||
public class MemoryConfiguration extends MemorySection implements Configuration {
|
||||
protected Configuration defaults;
|
||||
protected MemoryConfigurationOptions options;
|
||||
|
||||
|
||||
/**
|
||||
* Creates an empty {@link MemoryConfiguration} with no default values.
|
||||
*/
|
||||
public MemoryConfiguration() {}
|
||||
|
||||
public MemoryConfiguration() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty {@link MemoryConfiguration} using the specified {@link
|
||||
* Configuration} as a source for all default values.
|
||||
@ -26,49 +27,42 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
||||
public MemoryConfiguration(Configuration defaults) {
|
||||
this.defaults = defaults;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefault(String path, Object value) {
|
||||
|
||||
@Override public void addDefault(String path, Object value) {
|
||||
if (this.defaults == null) {
|
||||
this.defaults = new MemoryConfiguration();
|
||||
}
|
||||
|
||||
this.defaults.set(path, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefaults(Map<String, Object> defaults) {
|
||||
|
||||
@Override public void addDefaults(Map<String, Object> defaults) {
|
||||
for (Map.Entry<String, Object> entry : defaults.entrySet()) {
|
||||
addDefault(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefaults(Configuration defaults) {
|
||||
|
||||
@Override public void addDefaults(Configuration defaults) {
|
||||
addDefaults(defaults.getValues(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration getDefaults() {
|
||||
|
||||
@Override public Configuration getDefaults() {
|
||||
return this.defaults;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaults(Configuration defaults) {
|
||||
@Override public void setDefaults(Configuration defaults) {
|
||||
if (defaults == null) {
|
||||
throw new NullPointerException("Defaults may not be null");
|
||||
}
|
||||
|
||||
this.defaults = defaults;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSection getParent() {
|
||||
|
||||
@Override public ConfigurationSection getParent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemoryConfigurationOptions options() {
|
||||
|
||||
@Override public MemoryConfigurationOptions options() {
|
||||
if (this.options == null) {
|
||||
this.options = new MemoryConfigurationOptions(this);
|
||||
}
|
||||
|
@ -8,20 +8,17 @@ public class MemoryConfigurationOptions extends ConfigurationOptions {
|
||||
protected MemoryConfigurationOptions(MemoryConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemoryConfiguration configuration() {
|
||||
|
||||
@Override public MemoryConfiguration configuration() {
|
||||
return (MemoryConfiguration) super.configuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemoryConfigurationOptions copyDefaults(boolean value) {
|
||||
|
||||
@Override public MemoryConfigurationOptions copyDefaults(boolean value) {
|
||||
super.copyDefaults(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemoryConfigurationOptions pathSeparator(char value) {
|
||||
|
||||
@Override public MemoryConfigurationOptions pathSeparator(char value) {
|
||||
super.pathSeparator(value);
|
||||
return this;
|
||||
}
|
||||
|
@ -1,11 +1,6 @@
|
||||
package com.intellectualcrafters.configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A type of {@link ConfigurationSection} that is stored in memory.
|
||||
@ -21,16 +16,17 @@ public class MemorySection implements ConfigurationSection {
|
||||
/**
|
||||
* Creates an empty MemorySection for use as a root {@link Configuration}
|
||||
* section.
|
||||
*
|
||||
* <p>
|
||||
* <p>Note that calling this without being yourself a {@link Configuration}
|
||||
* will throw an exception!
|
||||
*
|
||||
* @throws IllegalStateException Thrown if this is not a {@link
|
||||
* Configuration} root.
|
||||
* Configuration} root.
|
||||
*/
|
||||
protected MemorySection() {
|
||||
if (!(this instanceof Configuration)) {
|
||||
throw new IllegalStateException("Cannot construct a root MemorySection when not a Configuration");
|
||||
throw new IllegalStateException(
|
||||
"Cannot construct a root MemorySection when not a Configuration");
|
||||
}
|
||||
|
||||
this.path = "";
|
||||
@ -43,10 +39,10 @@ public class MemorySection implements ConfigurationSection {
|
||||
* Creates an empty MemorySection with the specified parent and path.
|
||||
*
|
||||
* @param parent Parent section that contains this own section.
|
||||
* @param path Path that you may access this section from via the root
|
||||
* {@link Configuration}.
|
||||
* @param path Path that you may access this section from via the root
|
||||
* {@link Configuration}.
|
||||
* @throws IllegalArgumentException Thrown is parent or path is null, or
|
||||
* if parent contains no root Configuration.
|
||||
* if parent contains no root Configuration.
|
||||
*/
|
||||
protected MemorySection(ConfigurationSection parent, String path) {
|
||||
this.path = path;
|
||||
@ -117,12 +113,12 @@ public class MemorySection implements ConfigurationSection {
|
||||
/**
|
||||
* Creates a full path to the given {@link ConfigurationSection} from its
|
||||
* root {@link Configuration}.
|
||||
*
|
||||
* <p>
|
||||
* <p>You may use this method for any given {@link ConfigurationSection}, not
|
||||
* only {@link MemorySection}.
|
||||
*
|
||||
* @param section Section to create a path for.
|
||||
* @param key Name of the specified section.
|
||||
* @param key Name of the specified section.
|
||||
* @return Full path of the section from its root.
|
||||
*/
|
||||
public static String createPath(ConfigurationSection section, String key) {
|
||||
@ -132,16 +128,17 @@ public class MemorySection implements ConfigurationSection {
|
||||
/**
|
||||
* Creates a relative path to the given {@link ConfigurationSection} from
|
||||
* the given relative section.
|
||||
*
|
||||
* <p>
|
||||
* <p>You may use this method for any given {@link ConfigurationSection}, not
|
||||
* only {@link MemorySection}.
|
||||
*
|
||||
* @param section Section to create a path for.
|
||||
* @param key Name of the specified section.
|
||||
* @param section Section to create a path for.
|
||||
* @param key Name of the specified section.
|
||||
* @param relativeTo Section to create the path relative to.
|
||||
* @return Full path of the section from its root.
|
||||
*/
|
||||
public static String createPath(ConfigurationSection section, String key, ConfigurationSection relativeTo) {
|
||||
public static String createPath(ConfigurationSection section, String key,
|
||||
ConfigurationSection relativeTo) {
|
||||
Configuration root = section.getRoot();
|
||||
if (root == null) {
|
||||
throw new IllegalStateException("Cannot create path without a root");
|
||||
@ -149,7 +146,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
char separator = root.options().pathSeparator();
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (ConfigurationSection parent = section; (parent != null) && (parent != relativeTo); parent = parent.getParent()) {
|
||||
for (ConfigurationSection parent = section;
|
||||
(parent != null) && (parent != relativeTo); parent = parent.getParent()) {
|
||||
if (builder.length() > 0) {
|
||||
builder.insert(0, separator);
|
||||
}
|
||||
@ -168,8 +166,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys(boolean deep) {
|
||||
@Override public Set<String> getKeys(boolean deep) {
|
||||
Set<String> result = new LinkedHashSet<>();
|
||||
|
||||
Configuration root = getRoot();
|
||||
@ -186,8 +183,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getValues(boolean deep) {
|
||||
@Override public Map<String, Object> getValues(boolean deep) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
|
||||
Configuration root = getRoot();
|
||||
@ -204,13 +200,11 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String path) {
|
||||
@Override public boolean contains(String path) {
|
||||
return get(path) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSet(String path) {
|
||||
@Override public boolean isSet(String path) {
|
||||
Configuration root = getRoot();
|
||||
if (root == null) {
|
||||
return false;
|
||||
@ -221,40 +215,35 @@ public class MemorySection implements ConfigurationSection {
|
||||
return get(path, null) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentPath() {
|
||||
@Override public String getCurrentPath() {
|
||||
return this.fullPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
@Override public String getName() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration getRoot() {
|
||||
@Override public Configuration getRoot() {
|
||||
return this.root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSection getParent() {
|
||||
@Override public ConfigurationSection getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefault(String path, Object value) {
|
||||
@Override public void addDefault(String path, Object value) {
|
||||
Configuration root = getRoot();
|
||||
if (root == null) {
|
||||
throw new IllegalStateException("Cannot add default without root");
|
||||
}
|
||||
if (root == this) {
|
||||
throw new UnsupportedOperationException("Unsupported addDefault(String, Object) implementation");
|
||||
throw new UnsupportedOperationException(
|
||||
"Unsupported addDefault(String, Object) implementation");
|
||||
}
|
||||
root.addDefault(createPath(this, path), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSection getDefaultSection() {
|
||||
@Override public ConfigurationSection getDefaultSection() {
|
||||
Configuration root = getRoot();
|
||||
Configuration defaults = root == null ? null : root.getDefaults();
|
||||
|
||||
@ -267,8 +256,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(String path, Object value) {
|
||||
@Override public void set(String path, Object value) {
|
||||
Configuration root = getRoot();
|
||||
if (root == null) {
|
||||
throw new IllegalStateException("Cannot use section without a root");
|
||||
@ -302,13 +290,11 @@ public class MemorySection implements ConfigurationSection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String path) {
|
||||
@Override public Object get(String path) {
|
||||
return get(path, getDefault(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String path, Object defaultValue) {
|
||||
@Override public Object get(String path, Object defaultValue) {
|
||||
if (path == null) {
|
||||
throw new NullPointerException("Path cannot be null");
|
||||
}
|
||||
@ -347,8 +333,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return section.get(key, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSection createSection(String path) {
|
||||
@Override public ConfigurationSection createSection(String path) {
|
||||
Configuration root = getRoot();
|
||||
if (root == null) {
|
||||
throw new IllegalStateException("Cannot create section without a root");
|
||||
@ -379,8 +364,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return section.createSection(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSection createSection(String path, Map<?, ?> map) {
|
||||
@Override public ConfigurationSection createSection(String path, Map<?, ?> map) {
|
||||
ConfigurationSection section = createSection(path);
|
||||
|
||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||
@ -395,14 +379,12 @@ public class MemorySection implements ConfigurationSection {
|
||||
}
|
||||
|
||||
// Primitives
|
||||
@Override
|
||||
public String getString(String path) {
|
||||
@Override public String getString(String path) {
|
||||
Object def = getDefault(path);
|
||||
return getString(path, def != null ? def.toString() : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String path, String def) {
|
||||
@Override public String getString(String path, String def) {
|
||||
Object val = get(path, def);
|
||||
if (val != null) {
|
||||
return val.toString();
|
||||
@ -411,32 +393,27 @@ public class MemorySection implements ConfigurationSection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString(String path) {
|
||||
@Override public boolean isString(String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof String;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(String path) {
|
||||
@Override public int getInt(String path) {
|
||||
Object def = getDefault(path);
|
||||
return getInt(path, toInt(def, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(String path, int def) {
|
||||
@Override public int getInt(String path, int def) {
|
||||
Object val = get(path, def);
|
||||
return toInt(val, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInt(String path) {
|
||||
@Override public boolean isInt(String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof Integer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String path) {
|
||||
@Override public boolean getBoolean(String path) {
|
||||
Object def = getDefault(path);
|
||||
if (def instanceof Boolean) {
|
||||
return getBoolean(path, (Boolean) def);
|
||||
@ -445,8 +422,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String path, boolean defaultValue) {
|
||||
@Override public boolean getBoolean(String path, boolean defaultValue) {
|
||||
Object val = get(path, defaultValue);
|
||||
if (val instanceof Boolean) {
|
||||
return (Boolean) val;
|
||||
@ -455,69 +431,58 @@ public class MemorySection implements ConfigurationSection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoolean(String path) {
|
||||
@Override public boolean isBoolean(String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof Boolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble(String path) {
|
||||
@Override public double getDouble(String path) {
|
||||
Object def = getDefault(path);
|
||||
return getDouble(path, toDouble(def, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble(String path, double defaultValue) {
|
||||
@Override public double getDouble(String path, double defaultValue) {
|
||||
Object val = get(path, defaultValue);
|
||||
return toDouble(val, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDouble(String path) {
|
||||
@Override public boolean isDouble(String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof Double;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong(String path) {
|
||||
@Override public long getLong(String path) {
|
||||
Object def = getDefault(path);
|
||||
return getLong(path, toLong(def, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong(String path, long def) {
|
||||
@Override public long getLong(String path, long def) {
|
||||
Object val = get(path, def);
|
||||
return toLong(val, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLong(String path) {
|
||||
@Override public boolean isLong(String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof Long;
|
||||
}
|
||||
|
||||
// Java
|
||||
@Override
|
||||
public List<?> getList(String path) {
|
||||
@Override public List<?> getList(String path) {
|
||||
Object def = getDefault(path);
|
||||
return getList(path, def instanceof List ? (List<?>) def : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> getList(String path, List<?> def) {
|
||||
@Override public List<?> getList(String path, List<?> def) {
|
||||
Object val = get(path, def);
|
||||
return (List<?>) ((val instanceof List) ? val : def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isList(String path) {
|
||||
@Override public boolean isList(String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof List;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getStringList(String path) {
|
||||
@Override public List<String> getStringList(String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
if (list == null) {
|
||||
@ -535,8 +500,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getIntegerList(String path) {
|
||||
@Override public List<Integer> getIntegerList(String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
List<Integer> result = new ArrayList<>();
|
||||
@ -559,8 +523,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Boolean> getBooleanList(String path) {
|
||||
@Override public List<Boolean> getBooleanList(String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
List<Boolean> result = new ArrayList<>();
|
||||
@ -580,8 +543,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Double> getDoubleList(String path) {
|
||||
@Override public List<Double> getDoubleList(String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
List<Double> result = new ArrayList<>();
|
||||
@ -604,8 +566,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Float> getFloatList(String path) {
|
||||
@Override public List<Float> getFloatList(String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
List<Float> result = new ArrayList<>();
|
||||
@ -628,8 +589,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getLongList(String path) {
|
||||
@Override public List<Long> getLongList(String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
List<Long> result = new ArrayList<>();
|
||||
@ -652,8 +612,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Byte> getByteList(String path) {
|
||||
@Override public List<Byte> getByteList(String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
List<Byte> result = new ArrayList<>();
|
||||
@ -676,8 +635,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Character> getCharacterList(String path) {
|
||||
@Override public List<Character> getCharacterList(String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
List<Character> result = new ArrayList<>();
|
||||
@ -699,8 +657,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Short> getShortList(String path) {
|
||||
@Override public List<Short> getShortList(String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
List<Short> result = new ArrayList<>();
|
||||
@ -723,8 +680,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<?, ?>> getMapList(String path) {
|
||||
@Override public List<Map<?, ?>> getMapList(String path) {
|
||||
List<?> list = getList(path);
|
||||
List<Map<?, ?>> result = new ArrayList<>();
|
||||
|
||||
@ -737,8 +693,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSection getConfigurationSection(String path) {
|
||||
@Override public ConfigurationSection getConfigurationSection(String path) {
|
||||
Object val = get(path, null);
|
||||
if (val != null) {
|
||||
return (val instanceof ConfigurationSection) ? (ConfigurationSection) val : null;
|
||||
@ -748,21 +703,15 @@ public class MemorySection implements ConfigurationSection {
|
||||
return (val instanceof ConfigurationSection) ? createSection(path) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfigurationSection(String path) {
|
||||
@Override public boolean isConfigurationSection(String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof ConfigurationSection;
|
||||
}
|
||||
|
||||
protected boolean isPrimitiveWrapper(Object input) {
|
||||
return (input instanceof Integer)
|
||||
|| (input instanceof Boolean)
|
||||
|| (input instanceof Character)
|
||||
|| (input instanceof Byte)
|
||||
|| (input instanceof Short)
|
||||
|| (input instanceof Double)
|
||||
|| (input instanceof Long)
|
||||
|| (input instanceof Float);
|
||||
return (input instanceof Integer) || (input instanceof Boolean)
|
||||
|| (input instanceof Character) || (input instanceof Byte) || (input instanceof Short)
|
||||
|| (input instanceof Double) || (input instanceof Long) || (input instanceof Float);
|
||||
}
|
||||
|
||||
protected Object getDefault(String path) {
|
||||
@ -792,7 +741,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
}
|
||||
}
|
||||
|
||||
protected void mapChildrenValues(Map<String, Object> output, ConfigurationSection section, boolean deep) {
|
||||
protected void mapChildrenValues(Map<String, Object> output, ConfigurationSection section,
|
||||
boolean deep) {
|
||||
if (section instanceof MemorySection) {
|
||||
MemorySection sec = (MemorySection) section;
|
||||
|
||||
@ -814,13 +764,14 @@ public class MemorySection implements ConfigurationSection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
Configuration root = getRoot();
|
||||
if (root == null) {
|
||||
return getClass().getSimpleName() + "[path='" + getCurrentPath() + "', root='" + null + "']";
|
||||
return getClass().getSimpleName() + "[path='" + getCurrentPath() + "', root='" + null
|
||||
+ "']";
|
||||
} else {
|
||||
return getClass().getSimpleName() + "[path='" + getCurrentPath() + "', root='" + root.getClass().getSimpleName() + "']";
|
||||
return getClass().getSimpleName() + "[path='" + getCurrentPath() + "', root='" + root
|
||||
.getClass().getSimpleName() + "']";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,7 @@ import com.intellectualcrafters.configuration.Configuration;
|
||||
import com.intellectualcrafters.configuration.InvalidConfigurationException;
|
||||
import com.intellectualcrafters.configuration.MemoryConfiguration;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
@ -25,8 +16,9 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
/**
|
||||
* Creates an empty {@link FileConfiguration} with no default values.
|
||||
*/
|
||||
FileConfiguration() {}
|
||||
|
||||
FileConfiguration() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty {@link FileConfiguration} using the specified {@link
|
||||
* Configuration} as a source for all default values.
|
||||
@ -36,20 +28,20 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
public FileConfiguration(Configuration defaults) {
|
||||
super(defaults);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves this {@link FileConfiguration} to the specified location.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the file does not exist, it will be created. If already exists, it
|
||||
* will be overwritten. If it cannot be overwritten or created, an
|
||||
* exception will be thrown.
|
||||
*
|
||||
* <p>
|
||||
* <p>This method will save using the system default encoding, or possibly
|
||||
* using UTF8.
|
||||
*
|
||||
* @param file File to save to.
|
||||
* @throws IOException Thrown when the given file cannot be written to for
|
||||
* any reason.
|
||||
* any reason.
|
||||
*/
|
||||
public void save(File file) throws IOException {
|
||||
File parent = file.getParentFile();
|
||||
@ -59,7 +51,8 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
|
||||
String data = saveToString();
|
||||
|
||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
|
||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file),
|
||||
StandardCharsets.UTF_8)) {
|
||||
writer.write(data);
|
||||
}
|
||||
}
|
||||
@ -70,49 +63,51 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* @return String containing this configuration.
|
||||
*/
|
||||
public abstract String saveToString();
|
||||
|
||||
|
||||
/**
|
||||
* Loads this {@link FileConfiguration} from the specified location.
|
||||
*
|
||||
* <p>
|
||||
* <p>All the values contained within this configuration will be removed,
|
||||
* leaving only settings and defaults, and the new values will be loaded
|
||||
* from the given file.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the file cannot be loaded for any reason, an exception will be
|
||||
* thrown.
|
||||
*
|
||||
* @param file File to load from.
|
||||
* @throws FileNotFoundException Thrown when the given file cannot be
|
||||
* opened.
|
||||
* @throws IOException Thrown when the given file cannot be read.
|
||||
* @throws FileNotFoundException Thrown when the given file cannot be
|
||||
* opened.
|
||||
* @throws IOException Thrown when the given file cannot be read.
|
||||
* @throws InvalidConfigurationException Thrown when the given file is not
|
||||
* a valid Configuration.
|
||||
* @throws IllegalArgumentException Thrown when file is null.
|
||||
* a valid Configuration.
|
||||
* @throws IllegalArgumentException Thrown when file is null.
|
||||
*/
|
||||
public void load(File file) throws IOException, InvalidConfigurationException {
|
||||
|
||||
FileInputStream stream = new FileInputStream(file);
|
||||
|
||||
|
||||
load(new InputStreamReader(stream, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads this {@link FileConfiguration} from the specified reader.
|
||||
*
|
||||
* <p>
|
||||
* <p>All the values contained within this configuration will be removed,
|
||||
* leaving only settings and defaults, and the new values will be loaded
|
||||
* from the given stream.
|
||||
*
|
||||
* @param reader the reader to load from
|
||||
* @throws IOException thrown when underlying reader throws an IOException
|
||||
* @throws IOException thrown when underlying reader throws an IOException
|
||||
* @throws InvalidConfigurationException thrown when the reader does not
|
||||
* represent a valid Configuration
|
||||
* represent a valid Configuration
|
||||
*/
|
||||
public void load(Reader reader) throws IOException, InvalidConfigurationException {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
try (BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader)) {
|
||||
try (BufferedReader input = reader instanceof BufferedReader ?
|
||||
(BufferedReader) reader :
|
||||
new BufferedReader(reader)) {
|
||||
String line;
|
||||
|
||||
while ((line = input.readLine()) != null) {
|
||||
@ -120,30 +115,30 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
builder.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
loadFromString(builder.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads this {@link FileConfiguration} from the specified string, as
|
||||
* opposed to from file.
|
||||
*
|
||||
* <p>
|
||||
* <p>All the values contained within this configuration will be removed,
|
||||
* leaving only settings and defaults, and the new values will be loaded
|
||||
* from the given string.
|
||||
*
|
||||
* <p>
|
||||
* <p>If the string is invalid in any way, an exception will be thrown.
|
||||
*
|
||||
* @param contents Contents of a Configuration to load.
|
||||
* @throws InvalidConfigurationException Thrown if the specified string is
|
||||
* invalid.
|
||||
* invalid.
|
||||
*/
|
||||
public abstract void loadFromString(String contents) throws InvalidConfigurationException;
|
||||
|
||||
|
||||
/**
|
||||
* Compiles the header for this {@link FileConfiguration} and returns the
|
||||
* result.
|
||||
*
|
||||
* <p>
|
||||
* <p>This will use the header from {@link #options()} -> {@link
|
||||
* FileConfigurationOptions#header()}, respecting the rules of {@link
|
||||
* FileConfigurationOptions#copyHeader()} if set.
|
||||
@ -151,9 +146,8 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* @return Compiled header
|
||||
*/
|
||||
protected abstract String buildHeader();
|
||||
|
||||
@Override
|
||||
public FileConfigurationOptions options() {
|
||||
|
||||
@Override public FileConfigurationOptions options() {
|
||||
if (this.options == null) {
|
||||
this.options = new FileConfigurationOptions(this);
|
||||
}
|
||||
|
@ -11,37 +11,34 @@ import com.intellectualcrafters.configuration.MemoryConfigurationOptions;
|
||||
public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||
private String header = null;
|
||||
private boolean copyHeader = true;
|
||||
|
||||
|
||||
protected FileConfigurationOptions(MemoryConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileConfiguration configuration() {
|
||||
|
||||
@Override public FileConfiguration configuration() {
|
||||
return (FileConfiguration) super.configuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileConfigurationOptions copyDefaults(boolean value) {
|
||||
|
||||
@Override public FileConfigurationOptions copyDefaults(boolean value) {
|
||||
super.copyDefaults(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileConfigurationOptions pathSeparator(char value) {
|
||||
|
||||
@Override public FileConfigurationOptions pathSeparator(char value) {
|
||||
super.pathSeparator(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the header that will be applied to the top of the saved output.
|
||||
*
|
||||
* <p>
|
||||
* <p>This header will be commented out and applied directly at the top of
|
||||
* the generated output of the {@link FileConfiguration}. It is not
|
||||
* required to include a newline at the end of the header as it will
|
||||
* automatically be applied, but you may include one if you wish for extra
|
||||
* spacing.
|
||||
*
|
||||
* <p>
|
||||
* <p>{@code null} is a valid value which will indicate that no header]
|
||||
* is to be applied. The default value is {@code null}.
|
||||
*
|
||||
@ -50,16 +47,16 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||
public String header() {
|
||||
return header;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the header that will be applied to the top of the saved output.
|
||||
*
|
||||
* <p>
|
||||
* <p>This header will be commented out and applied directly at the top of
|
||||
* the generated output of the {@link FileConfiguration}. It is not
|
||||
* required to include a newline at the end of the header as it will
|
||||
* automatically be applied, but you may include one if you wish for extra
|
||||
* spacing.
|
||||
*
|
||||
* <p>
|
||||
* <p>{@code null} is a valid value which will indicate that no header
|
||||
* is to be applied.
|
||||
*
|
||||
@ -70,20 +67,20 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||
header = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets whether or not the header should be copied from a default source.
|
||||
*
|
||||
* <p>
|
||||
* <p>If this is true, if a default {@link FileConfiguration} is passed to
|
||||
* {@link FileConfiguration#setDefaults(Configuration)}
|
||||
* then upon saving it will use the header from that config, instead of
|
||||
* the one provided here.
|
||||
*
|
||||
* <p>
|
||||
* <p>If no default is set on the configuration, or the default is not of
|
||||
* type FileConfiguration, or that config has no header ({@link #header()}
|
||||
* returns null) then the header specified in this configuration will be
|
||||
* used.
|
||||
*
|
||||
* <p>
|
||||
* <p>Defaults to true.
|
||||
*
|
||||
* @return Whether or not to copy the header
|
||||
@ -91,20 +88,20 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||
public boolean copyHeader() {
|
||||
return copyHeader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets whether or not the header should be copied from a default source.
|
||||
*
|
||||
* <p>
|
||||
* <p>If this is true, if a default {@link FileConfiguration} is passed to
|
||||
* {@link FileConfiguration#setDefaults(Configuration)}
|
||||
* then upon saving it will use the header from that config, instead of
|
||||
* the one provided here.
|
||||
*
|
||||
* <p>
|
||||
* <p>If no default is set on the configuration, or the default is not of
|
||||
* type FileConfiguration, or that config has no header ({@link #header()}
|
||||
* returns null) then the header specified in this configuration will be
|
||||
* used.
|
||||
*
|
||||
* <p>
|
||||
* <p>Defaults to true.
|
||||
*
|
||||
* @param value Whether or not to copy the header
|
||||
@ -112,7 +109,7 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||
*/
|
||||
public FileConfigurationOptions copyHeader(boolean value) {
|
||||
copyHeader = value;
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
|
||||
/**
|
||||
* Creates a new {@link YamlConfiguration}, loading from the given file.
|
||||
*
|
||||
* <p>
|
||||
* <p>Any errors loading the Configuration will be logged and then ignored.
|
||||
* If the specified input is not a valid config, a blank config will be
|
||||
* returned.
|
||||
*
|
||||
* <p>
|
||||
* <p>The encoding used may follow the system dependent default.
|
||||
*
|
||||
* @param file Input file
|
||||
@ -64,8 +64,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String saveToString() {
|
||||
@Override public String saveToString() {
|
||||
yamlOptions.setIndent(options().indent());
|
||||
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
@ -79,9 +78,8 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
|
||||
return header + dump;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFromString(String contents) throws InvalidConfigurationException {
|
||||
|
||||
@Override public void loadFromString(String contents) throws InvalidConfigurationException {
|
||||
|
||||
Map<?, ?> input;
|
||||
try {
|
||||
@ -101,7 +99,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
convertMapsToSections(input, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void convertMapsToSections(Map<?, ?> input, ConfigurationSection section) {
|
||||
for (Map.Entry<?, ?> entry : input.entrySet()) {
|
||||
String key = entry.getKey().toString();
|
||||
@ -114,7 +112,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected String parseHeader(String input) {
|
||||
String[] lines = input.split("\r?\n", -1);
|
||||
StringBuilder result = new StringBuilder();
|
||||
@ -143,9 +141,8 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String buildHeader() {
|
||||
|
||||
@Override protected String buildHeader() {
|
||||
String header = options().header();
|
||||
|
||||
if (options().copyHeader()) {
|
||||
@ -182,8 +179,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public YamlConfigurationOptions options() {
|
||||
@Override public YamlConfigurationOptions options() {
|
||||
if (options == null) {
|
||||
options = new YamlConfigurationOptions(this);
|
||||
}
|
||||
|
@ -6,43 +6,38 @@ package com.intellectualcrafters.configuration.file;
|
||||
*/
|
||||
public class YamlConfigurationOptions extends FileConfigurationOptions {
|
||||
private int indent = 2;
|
||||
|
||||
|
||||
YamlConfigurationOptions(YamlConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YamlConfiguration configuration() {
|
||||
|
||||
@Override public YamlConfiguration configuration() {
|
||||
return (YamlConfiguration) super.configuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public YamlConfigurationOptions copyDefaults(boolean value) {
|
||||
|
||||
@Override public YamlConfigurationOptions copyDefaults(boolean value) {
|
||||
super.copyDefaults(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YamlConfigurationOptions pathSeparator(char value) {
|
||||
|
||||
@Override public YamlConfigurationOptions pathSeparator(char value) {
|
||||
super.pathSeparator(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YamlConfigurationOptions header(String value) {
|
||||
|
||||
@Override public YamlConfigurationOptions header(String value) {
|
||||
super.header(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YamlConfigurationOptions copyHeader(boolean value) {
|
||||
|
||||
@Override public YamlConfigurationOptions copyHeader(boolean value) {
|
||||
super.copyHeader(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets how much spaces should be used to indent each line.
|
||||
*
|
||||
* <p>
|
||||
* <p>The minimum value this may be is 2, and the maximum is 9.
|
||||
*
|
||||
* @return How much to indent by
|
||||
@ -50,10 +45,10 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
|
||||
public int indent() {
|
||||
return indent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets how much spaces should be used to indent each line.
|
||||
*
|
||||
* <p>
|
||||
* <p>The minimum value this may be is 2, and the maximum is 9.
|
||||
*
|
||||
* @param value New indent
|
||||
@ -66,7 +61,7 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
|
||||
if (value > 9) {
|
||||
throw new IllegalArgumentException("Indent cannot be greater than 9 characters");
|
||||
}
|
||||
|
||||
|
||||
indent = value;
|
||||
return this;
|
||||
}
|
||||
|
@ -10,38 +10,36 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class YamlConstructor extends SafeConstructor {
|
||||
|
||||
|
||||
YamlConstructor() {
|
||||
yamlConstructors.put(Tag.MAP, new ConstructCustomObject());
|
||||
}
|
||||
|
||||
|
||||
private class ConstructCustomObject extends ConstructYamlMap {
|
||||
@Override
|
||||
public Object construct(final Node node) {
|
||||
@Override public Object construct(final Node node) {
|
||||
if (node.isTwoStepsConstruction()) {
|
||||
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
|
||||
}
|
||||
|
||||
|
||||
final Map<?, ?> raw = (Map<?, ?>) super.construct(node);
|
||||
|
||||
|
||||
if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
|
||||
final Map<String, Object> typed = new LinkedHashMap<>(raw.size());
|
||||
for (final Map.Entry<?, ?> entry : raw.entrySet()) {
|
||||
typed.put(entry.getKey().toString(), entry.getValue());
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
return ConfigurationSerialization.deserializeObject(typed);
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
throw new YAMLException("Could not deserialize object", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return raw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void construct2ndStep(final Node node, final Object object) {
|
||||
|
||||
@Override public void construct2ndStep(final Node node, final Object object) {
|
||||
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
|
||||
}
|
||||
}
|
||||
|
@ -13,24 +13,25 @@ class YamlRepresenter extends Representer {
|
||||
|
||||
YamlRepresenter() {
|
||||
this.multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection());
|
||||
this.multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());
|
||||
this.multiRepresenters
|
||||
.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());
|
||||
}
|
||||
|
||||
private class RepresentConfigurationSection extends RepresentMap {
|
||||
|
||||
@Override
|
||||
public Node representData(Object data) {
|
||||
@Override public Node representData(Object data) {
|
||||
return super.representData(((ConfigurationSection) data).getValues(false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class RepresentConfigurationSerializable extends RepresentMap {
|
||||
|
||||
@Override
|
||||
public Node representData(Object data) {
|
||||
@Override public Node representData(Object data) {
|
||||
ConfigurationSerializable serializable = (ConfigurationSerializable) data;
|
||||
Map<String, Object> values = new LinkedHashMap<>();
|
||||
values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass()));
|
||||
values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY,
|
||||
ConfigurationSerialization.getAlias(serializable.getClass()));
|
||||
values.putAll(serializable.serialize());
|
||||
|
||||
return super.representData(values);
|
||||
|
@ -21,10 +21,10 @@ import java.util.Map;
|
||||
* @see SerializableAs
|
||||
*/
|
||||
public interface ConfigurationSerializable {
|
||||
|
||||
|
||||
/**
|
||||
* Creates a Map representation of this class.
|
||||
*
|
||||
* <p>
|
||||
* <p>This class must provide a method to restore this class, as defined in
|
||||
* the {@link ConfigurationSerializable} interface javadoc.
|
||||
*
|
||||
|
@ -17,7 +17,8 @@ import java.util.logging.Logger;
|
||||
public class ConfigurationSerialization {
|
||||
|
||||
public static final String SERIALIZED_TYPE_KEY = "==";
|
||||
private static final Map<String, Class<? extends ConfigurationSerializable>> aliases = new HashMap<>();
|
||||
private static final Map<String, Class<? extends ConfigurationSerializable>> aliases =
|
||||
new HashMap<>();
|
||||
private final Class<? extends ConfigurationSerializable> clazz;
|
||||
|
||||
protected ConfigurationSerialization(Class<? extends ConfigurationSerializable> clazz) {
|
||||
@ -27,31 +28,32 @@ public class ConfigurationSerialization {
|
||||
/**
|
||||
* Attempts to deserialize the given arguments into a new instance of the
|
||||
* given class.
|
||||
*
|
||||
* <p>
|
||||
* <p>The class must implement {@link ConfigurationSerializable}, including
|
||||
* the extra methods as specified in the javadoc of
|
||||
* ConfigurationSerializable.</p>
|
||||
*
|
||||
* <p>
|
||||
* <p>If a new instance could not be made, an example being the class not
|
||||
* fully implementing the interface, null will be returned.</p>
|
||||
*
|
||||
* @param args Arguments for deserialization
|
||||
* @param args Arguments for deserialization
|
||||
* @param clazz Class to deserialize into
|
||||
* @return New instance of the specified class
|
||||
*/
|
||||
public static ConfigurationSerializable deserializeObject(Map<String, ?> args, Class<? extends ConfigurationSerializable> clazz) {
|
||||
public static ConfigurationSerializable deserializeObject(Map<String, ?> args,
|
||||
Class<? extends ConfigurationSerializable> clazz) {
|
||||
return new ConfigurationSerialization(clazz).deserialize(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to deserialize the given arguments into a new instance of the
|
||||
*
|
||||
* <p>
|
||||
* given class.
|
||||
* <p>
|
||||
* The class must implement {@link ConfigurationSerializable}, including
|
||||
* the extra methods as specified in the javadoc of
|
||||
* ConfigurationSerializable.</p>
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* If a new instance could not be made, an example being the class not
|
||||
* fully implementing the interface, null will be returned.</p>
|
||||
@ -71,14 +73,16 @@ public class ConfigurationSerialization {
|
||||
}
|
||||
clazz = getClassByAlias(alias);
|
||||
if (clazz == null) {
|
||||
throw new IllegalArgumentException("Specified class does not exist ('" + alias + "')");
|
||||
throw new IllegalArgumentException(
|
||||
"Specified class does not exist ('" + alias + "')");
|
||||
}
|
||||
} catch (ClassCastException ex) {
|
||||
ex.fillInStackTrace();
|
||||
throw ex;
|
||||
}
|
||||
} 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 + "')");
|
||||
}
|
||||
|
||||
return new ConfigurationSerialization(clazz).deserialize(args);
|
||||
@ -107,7 +111,8 @@ public class ConfigurationSerialization {
|
||||
* @param alias Alias to register as
|
||||
* @see SerializableAs
|
||||
*/
|
||||
public static void registerClass(Class<? extends ConfigurationSerializable> clazz, String alias) {
|
||||
public static void registerClass(Class<? extends ConfigurationSerializable> clazz,
|
||||
String alias) {
|
||||
aliases.put(alias, clazz);
|
||||
}
|
||||
|
||||
@ -127,7 +132,8 @@ public class ConfigurationSerialization {
|
||||
* @param clazz Class to unregister
|
||||
*/
|
||||
public static void unregisterClass(Class<? extends ConfigurationSerializable> clazz) {
|
||||
while (aliases.values().remove(clazz)) {}
|
||||
while (aliases.values().remove(clazz)) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,32 +201,35 @@ public class ConfigurationSerialization {
|
||||
|
||||
protected ConfigurationSerializable deserializeViaMethod(Method method, Map<String, ?> args) {
|
||||
try {
|
||||
ConfigurationSerializable result = (ConfigurationSerializable) method.invoke(null, args);
|
||||
ConfigurationSerializable result =
|
||||
(ConfigurationSerializable) method.invoke(null, args);
|
||||
|
||||
if (result == null) {
|
||||
Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE,
|
||||
"Could not call method '" + method.toString() + "' of " + this.clazz + " for deserialization: method returned null");
|
||||
"Could not call method '" + method.toString() + "' of " + this.clazz
|
||||
+ " for deserialization: method returned null");
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ex) {
|
||||
Logger.getLogger(ConfigurationSerialization.class.getName())
|
||||
.log(Level.SEVERE, "Could not call method '" + method.toString() + "' of " + this.clazz
|
||||
+ " for deserialization",
|
||||
ex instanceof InvocationTargetException ? ex.getCause() : ex);
|
||||
Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE,
|
||||
"Could not call method '" + method.toString() + "' of " + this.clazz
|
||||
+ " for deserialization",
|
||||
ex instanceof InvocationTargetException ? ex.getCause() : ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected ConfigurationSerializable deserializeViaCtor(Constructor<? extends ConfigurationSerializable> ctor, Map<String, ?> args) {
|
||||
protected ConfigurationSerializable deserializeViaCtor(
|
||||
Constructor<? extends ConfigurationSerializable> ctor, Map<String, ?> args) {
|
||||
try {
|
||||
return ctor.newInstance(args);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException ex) {
|
||||
Logger.getLogger(ConfigurationSerialization.class.getName())
|
||||
.log(Level.SEVERE, "Could not call constructor '" + ctor.toString() + "' of " + this.clazz
|
||||
+ " for deserialization",
|
||||
ex instanceof InvocationTargetException ? ex.getCause() : ex);
|
||||
Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE,
|
||||
"Could not call constructor '" + ctor.toString() + "' of " + this.clazz
|
||||
+ " for deserialization",
|
||||
ex instanceof InvocationTargetException ? ex.getCause() : ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -9,8 +9,7 @@ import java.lang.annotation.Target;
|
||||
* Applies to a {@link ConfigurationSerializable} that will delegate all
|
||||
* deserialization to another {@link ConfigurationSerializable}.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE)
|
||||
public @interface DelegateDeserialization {
|
||||
/**
|
||||
* Which class should be used as a delegate for this classes
|
||||
|
@ -19,9 +19,7 @@ import java.lang.annotation.Target;
|
||||
*
|
||||
* @see ConfigurationSerialization#registerClass(Class, String)
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface SerializableAs {
|
||||
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface SerializableAs {
|
||||
/**
|
||||
* This is the name your class will be stored and retrieved as.
|
||||
* <p>
|
||||
|
@ -27,13 +27,11 @@ public final class ByteArrayTag extends Tag {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getValue() {
|
||||
@Override public byte[] getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
StringBuilder hex = new StringBuilder();
|
||||
for (byte b : this.value) {
|
||||
String hexDigits = Integer.toHexString(b).toUpperCase();
|
||||
|
@ -27,13 +27,11 @@ public final class ByteTag extends Tag {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte getValue() {
|
||||
@Override public Byte getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
String name = getName();
|
||||
String append = "";
|
||||
if (name != null && !name.isEmpty()) {
|
||||
|
@ -36,15 +36,13 @@ public final class CompoundTag extends Tag {
|
||||
* Returns whether this compound tag contains the given key.
|
||||
*
|
||||
* @param key the given key
|
||||
*
|
||||
* @return true if the tag contains the given key
|
||||
*/
|
||||
public boolean containsKey(String key) {
|
||||
return this.value.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Tag> getValue() {
|
||||
@Override public Map<String, Tag> getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@ -52,7 +50,6 @@ public final class CompoundTag extends Tag {
|
||||
* Return a new compound tag with the given values.
|
||||
*
|
||||
* @param value the value
|
||||
*
|
||||
* @return the new compound tag
|
||||
*/
|
||||
public CompoundTag setValue(Map<String, Tag> value) {
|
||||
@ -75,12 +72,11 @@ public final class CompoundTag extends Tag {
|
||||
|
||||
/**
|
||||
* Get a byte array named with the given key.
|
||||
*
|
||||
* <p>
|
||||
* <p> If the key does not exist or its value is not a byte array
|
||||
* tag, then an empty byte array will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return a byte array
|
||||
*/
|
||||
public byte[] getByteArray(String key) {
|
||||
@ -97,7 +93,6 @@ public final class CompoundTag extends Tag {
|
||||
* {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return a byte
|
||||
*/
|
||||
public byte getByte(String key) {
|
||||
@ -114,7 +109,6 @@ public final class CompoundTag extends Tag {
|
||||
* {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return a double
|
||||
*/
|
||||
public double getDouble(String key) {
|
||||
@ -131,7 +125,6 @@ public final class CompoundTag extends Tag {
|
||||
* its value is not a number, then {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return a double
|
||||
*/
|
||||
public double asDouble(String key) {
|
||||
@ -158,7 +151,6 @@ public final class CompoundTag extends Tag {
|
||||
* {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return a float
|
||||
*/
|
||||
public float getFloat(String key) {
|
||||
@ -175,7 +167,6 @@ public final class CompoundTag extends Tag {
|
||||
* tag, then an empty array will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return an int array
|
||||
*/
|
||||
public int[] getIntArray(String key) {
|
||||
@ -192,7 +183,6 @@ public final class CompoundTag extends Tag {
|
||||
* {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return an int
|
||||
*/
|
||||
public int getInt(String key) {
|
||||
@ -209,7 +199,6 @@ public final class CompoundTag extends Tag {
|
||||
* its value is not a number, then {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return an int
|
||||
*/
|
||||
public int asInt(String key) {
|
||||
@ -236,7 +225,6 @@ public final class CompoundTag extends Tag {
|
||||
* then an empty list will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return a list of tags
|
||||
*/
|
||||
public List<Tag> getList(String key) {
|
||||
@ -253,7 +241,6 @@ public final class CompoundTag extends Tag {
|
||||
* tag, then an empty tag list will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return a tag list instance
|
||||
*/
|
||||
public ListTag getListTag(String key) {
|
||||
@ -273,11 +260,10 @@ public final class CompoundTag extends Tag {
|
||||
* @param key the key
|
||||
* @param listType the class of the contained type
|
||||
* @param <T> the type of list
|
||||
*
|
||||
* @return a list of tags
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Tag> List<T> getList(String key, Class<T> listType) {
|
||||
@SuppressWarnings("unchecked") public <T extends Tag> List<T> getList(String key,
|
||||
Class<T> listType) {
|
||||
Tag tag = this.value.get(key);
|
||||
if (tag instanceof ListTag) {
|
||||
ListTag listTag = (ListTag) tag;
|
||||
@ -296,7 +282,6 @@ public final class CompoundTag extends Tag {
|
||||
* {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return a long
|
||||
*/
|
||||
public long getLong(String key) {
|
||||
@ -313,7 +298,6 @@ public final class CompoundTag extends Tag {
|
||||
* its value is not a number, then {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return a long
|
||||
*/
|
||||
public long asLong(String key) {
|
||||
@ -340,7 +324,6 @@ public final class CompoundTag extends Tag {
|
||||
* {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return a short
|
||||
*/
|
||||
public short getShort(String key) {
|
||||
@ -357,7 +340,6 @@ public final class CompoundTag extends Tag {
|
||||
* {@code ""} will be returned. </p>
|
||||
*
|
||||
* @param key the key
|
||||
*
|
||||
* @return a string
|
||||
*/
|
||||
public String getString(String key) {
|
||||
@ -369,17 +351,18 @@ public final class CompoundTag extends Tag {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
String name = getName();
|
||||
String append = "";
|
||||
if (name != null && !name.isEmpty()) {
|
||||
append = "(\"" + getName() + "\")";
|
||||
}
|
||||
StringBuilder bldr = new StringBuilder();
|
||||
bldr.append("TAG_Compound").append(append).append(": ").append(this.value.size()).append(" entries\r\n{\r\n");
|
||||
bldr.append("TAG_Compound").append(append).append(": ").append(this.value.size())
|
||||
.append(" entries\r\n{\r\n");
|
||||
for (Map.Entry<String, Tag> entry : this.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("}");
|
||||
return bldr.toString();
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.intellectualcrafters.jnbt;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Helps create compound tags.
|
||||
*/
|
||||
@ -43,7 +43,6 @@ public class CompoundTagBuilder {
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder put(String key, Tag value) {
|
||||
@ -58,7 +57,6 @@ public class CompoundTagBuilder {
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putByteArray(String key, byte[] value) {
|
||||
@ -70,7 +68,6 @@ public class CompoundTagBuilder {
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putByte(String key, byte value) {
|
||||
@ -82,7 +79,6 @@ public class CompoundTagBuilder {
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putDouble(String key, double value) {
|
||||
@ -94,7 +90,6 @@ public class CompoundTagBuilder {
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putFloat(String key, float value) {
|
||||
@ -106,7 +101,6 @@ public class CompoundTagBuilder {
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putIntArray(String key, int[] value) {
|
||||
@ -118,7 +112,6 @@ public class CompoundTagBuilder {
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putInt(String key, int value) {
|
||||
@ -130,7 +123,6 @@ public class CompoundTagBuilder {
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putLong(String key, long value) {
|
||||
@ -142,7 +134,6 @@ public class CompoundTagBuilder {
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putShort(String key, short value) {
|
||||
@ -154,7 +145,6 @@ public class CompoundTagBuilder {
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putString(String key, String value) {
|
||||
@ -165,7 +155,6 @@ public class CompoundTagBuilder {
|
||||
* Put all the entries from the given map into this map.
|
||||
*
|
||||
* @param value the map of tags
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putAll(Map<String, ? extends Tag> value) {
|
||||
@ -189,7 +178,6 @@ public class CompoundTagBuilder {
|
||||
* Build a new compound tag with this builder's entries.
|
||||
*
|
||||
* @param name the name of the tag
|
||||
*
|
||||
* @return the created compound tag
|
||||
*/
|
||||
public CompoundTag build(String name) {
|
||||
|
@ -27,13 +27,11 @@ public final class DoubleTag extends Tag {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getValue() {
|
||||
@Override public Double getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
String name = getName();
|
||||
String append = "";
|
||||
if (name != null && !name.isEmpty()) {
|
||||
|
@ -8,15 +8,14 @@ public final class EndTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*/
|
||||
public EndTag() {}
|
||||
public EndTag() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
@Override public Object getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
return "TAG_End";
|
||||
}
|
||||
}
|
||||
|
@ -27,13 +27,11 @@ public final class FloatTag extends Tag {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getValue() {
|
||||
@Override public Float getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
String name = getName();
|
||||
String append = "";
|
||||
if (name != null && !name.isEmpty()) {
|
||||
|
@ -31,13 +31,11 @@ public final class IntArrayTag extends Tag {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getValue() {
|
||||
@Override public int[] getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
StringBuilder hex = new StringBuilder();
|
||||
for (int b : this.value) {
|
||||
String hexDigits = Integer.toHexString(b).toUpperCase();
|
||||
|
@ -27,13 +27,11 @@ public final class IntTag extends Tag {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
@Override public Integer getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
String name = getName();
|
||||
String append = "";
|
||||
if (name != null && !name.isEmpty()) {
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.intellectualcrafters.jnbt;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* The {@code TAG_List} tag.
|
||||
*/
|
||||
@ -49,8 +49,7 @@ public final class ListTag extends Tag {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> getValue() {
|
||||
@Override public List<Tag> getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@ -58,7 +57,6 @@ public final class ListTag extends Tag {
|
||||
* Create a new list tag with this tag's name and type.
|
||||
*
|
||||
* @param list the new list
|
||||
*
|
||||
* @return a new list tag
|
||||
*/
|
||||
public ListTag setValue(List<Tag> list) {
|
||||
@ -69,7 +67,6 @@ public final class ListTag extends Tag {
|
||||
* Get the tag if it exists at the given index.
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return the tag or null
|
||||
*/
|
||||
public Tag getIfExists(int index) {
|
||||
@ -85,7 +82,6 @@ public final class ListTag extends Tag {
|
||||
* array tag, then an empty byte array will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return a byte array
|
||||
*/
|
||||
public byte[] getByteArray(int index) {
|
||||
@ -102,7 +98,6 @@ public final class ListTag extends Tag {
|
||||
* {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return a byte
|
||||
*/
|
||||
public byte getByte(int index) {
|
||||
@ -119,7 +114,6 @@ public final class ListTag extends Tag {
|
||||
* then {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return a double
|
||||
*/
|
||||
public double getDouble(int index) {
|
||||
@ -136,7 +130,6 @@ public final class ListTag extends Tag {
|
||||
* exist or its value is not a number, then {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return a double
|
||||
*/
|
||||
public double asDouble(int index) {
|
||||
@ -163,7 +156,6 @@ public final class ListTag extends Tag {
|
||||
* then {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return a float
|
||||
*/
|
||||
public float getFloat(int index) {
|
||||
@ -180,7 +172,6 @@ public final class ListTag extends Tag {
|
||||
* array tag, then an empty array will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return an int array
|
||||
*/
|
||||
public int[] getIntArray(int index) {
|
||||
@ -197,7 +188,6 @@ public final class ListTag extends Tag {
|
||||
* {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return an int
|
||||
*/
|
||||
public int getInt(int index) {
|
||||
@ -214,7 +204,6 @@ public final class ListTag extends Tag {
|
||||
* or its value is not a number, then {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return an int
|
||||
*/
|
||||
public int asInt(int index) {
|
||||
@ -241,7 +230,6 @@ public final class ListTag extends Tag {
|
||||
* tag, then an empty list will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return a list of tags
|
||||
*/
|
||||
public List<Tag> getList(int index) {
|
||||
@ -258,7 +246,6 @@ public final class ListTag extends Tag {
|
||||
* tag, then an empty tag list will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return a tag list instance
|
||||
*/
|
||||
public ListTag getListTag(int index) {
|
||||
@ -278,11 +265,10 @@ public final class ListTag extends Tag {
|
||||
* @param index the index
|
||||
* @param listType the class of the contained type
|
||||
* @param <T> the NBT type
|
||||
*
|
||||
* @return a list of tags
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Tag> List<T> getList(int index, Class<T> listType) {
|
||||
@SuppressWarnings("unchecked") public <T extends Tag> List<T> getList(int index,
|
||||
Class<T> listType) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof ListTag) {
|
||||
ListTag listTag = (ListTag) tag;
|
||||
@ -301,7 +287,6 @@ public final class ListTag extends Tag {
|
||||
* {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return a long
|
||||
*/
|
||||
public long getLong(int index) {
|
||||
@ -318,7 +303,6 @@ public final class ListTag extends Tag {
|
||||
* or its value is not a number, then {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return a long
|
||||
*/
|
||||
public long asLong(int index) {
|
||||
@ -345,7 +329,6 @@ public final class ListTag extends Tag {
|
||||
* then {@code 0} will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return a short
|
||||
*/
|
||||
public short getShort(int index) {
|
||||
@ -362,7 +345,6 @@ public final class ListTag extends Tag {
|
||||
* then {@code ""} will be returned. </p>
|
||||
*
|
||||
* @param index the index
|
||||
*
|
||||
* @return a string
|
||||
*/
|
||||
public String getString(int index) {
|
||||
@ -374,17 +356,16 @@ public final class ListTag extends Tag {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
String name = getName();
|
||||
String append = "";
|
||||
if (name != null && !name.isEmpty()) {
|
||||
append = "(\"" + getName() + "\")";
|
||||
}
|
||||
StringBuilder bldr = new StringBuilder();
|
||||
bldr.append("TAG_List").append(append).append(": ").append(this.value.size()).append(" entries of type ")
|
||||
.append(NBTUtils.getTypeName(this.type))
|
||||
.append("\r\n{\r\n");
|
||||
bldr.append("TAG_List").append(append).append(": ").append(this.value.size())
|
||||
.append(" entries of type ").append(NBTUtils.getTypeName(this.type))
|
||||
.append("\r\n{\r\n");
|
||||
for (Tag t : this.value) {
|
||||
bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.intellectualcrafters.jnbt;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Helps create list tags.
|
||||
*/
|
||||
@ -30,7 +30,6 @@ public class ListTagBuilder {
|
||||
* Create a new builder instance.
|
||||
*
|
||||
* @param type
|
||||
*
|
||||
* @return a new builder
|
||||
*/
|
||||
public static ListTagBuilder create(Class<? extends Tag> type) {
|
||||
@ -42,11 +41,9 @@ public class ListTagBuilder {
|
||||
*
|
||||
* @param entries
|
||||
* @param <T>
|
||||
*
|
||||
* @return a new builder
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T extends Tag> ListTagBuilder createWith(T... entries) {
|
||||
@SafeVarargs public static <T extends Tag> ListTagBuilder createWith(T... entries) {
|
||||
checkNotNull(entries);
|
||||
if (entries.length == 0) {
|
||||
throw new IllegalArgumentException("This method needs an array of at least one entry");
|
||||
@ -66,13 +63,14 @@ public class ListTagBuilder {
|
||||
* Add the given tag.
|
||||
*
|
||||
* @param value the tag
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public ListTagBuilder add(Tag value) {
|
||||
checkNotNull(value);
|
||||
if (!this.type.isInstance(value)) {
|
||||
throw new IllegalArgumentException(value.getClass().getCanonicalName() + " is not of expected type " + this.type.getCanonicalName());
|
||||
throw new IllegalArgumentException(
|
||||
value.getClass().getCanonicalName() + " is not of expected type " + this.type
|
||||
.getCanonicalName());
|
||||
}
|
||||
this.entries.add(value);
|
||||
return this;
|
||||
@ -82,7 +80,6 @@ public class ListTagBuilder {
|
||||
* Add all the tags in the given list.
|
||||
*
|
||||
* @param value a list of tags
|
||||
*
|
||||
* @return this object
|
||||
*/
|
||||
public ListTagBuilder addAll(Collection<? extends Tag> value) {
|
||||
@ -106,7 +103,6 @@ public class ListTagBuilder {
|
||||
* Build a new list tag with this builder's entries.
|
||||
*
|
||||
* @param name the name of the tag
|
||||
*
|
||||
* @return the created list tag
|
||||
*/
|
||||
public ListTag build(String name) {
|
||||
|
@ -27,13 +27,11 @@ public final class LongTag extends Tag {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getValue() {
|
||||
@Override public Long getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
String name = getName();
|
||||
String append = "";
|
||||
if (name != null && !name.isEmpty()) {
|
||||
|
@ -9,22 +9,21 @@ import java.nio.charset.StandardCharsets;
|
||||
public final class NBTConstants {
|
||||
|
||||
public static final Charset CHARSET = StandardCharsets.UTF_8;
|
||||
public static final int TYPE_END = 0, TYPE_BYTE = 1, TYPE_SHORT = 2, TYPE_INT = 3, TYPE_LONG = 4, TYPE_FLOAT = 5, TYPE_DOUBLE = 6,
|
||||
TYPE_BYTE_ARRAY = 7, TYPE_STRING = 8, TYPE_LIST = 9,
|
||||
TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11;
|
||||
public static final int TYPE_END = 0, TYPE_BYTE = 1, TYPE_SHORT = 2, TYPE_INT = 3, TYPE_LONG =
|
||||
4, TYPE_FLOAT = 5, TYPE_DOUBLE = 6, TYPE_BYTE_ARRAY = 7, TYPE_STRING = 8, TYPE_LIST = 9,
|
||||
TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11;
|
||||
|
||||
/**
|
||||
* Default private constructor.
|
||||
*/
|
||||
private NBTConstants() {}
|
||||
private NBTConstants() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a type ID to its corresponding {@link Tag} class.
|
||||
*
|
||||
* @param id type ID
|
||||
*
|
||||
* @return tag class
|
||||
*
|
||||
* @throws IllegalArgumentException thrown if the tag ID is not valid
|
||||
*/
|
||||
public static Class<? extends Tag> getClassFromType(int id) {
|
||||
|
@ -24,7 +24,6 @@ public final class NBTInputStream implements Closeable {
|
||||
* Creates a new {@code NBTInputStream}, which will source its data from the specified input stream.
|
||||
*
|
||||
* @param is the input stream
|
||||
*
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
public NBTInputStream(InputStream is) {
|
||||
@ -35,7 +34,6 @@ public final class NBTInputStream implements Closeable {
|
||||
* Reads an NBT tag from the stream.
|
||||
*
|
||||
* @return The tag that was read.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public Tag readTag() throws IOException {
|
||||
@ -46,7 +44,6 @@ public final class NBTInputStream implements Closeable {
|
||||
* Reads an NBT tag from the stream.
|
||||
*
|
||||
* @return The tag that was read.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public Tag readTag(int maxDepth) throws IOException {
|
||||
@ -57,9 +54,7 @@ public final class NBTInputStream implements Closeable {
|
||||
* Reads an NBT from the stream.
|
||||
*
|
||||
* @param depth the depth of this tag
|
||||
*
|
||||
* @return The tag that was read.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private Tag readTag(int depth, int maxDepth) throws IOException {
|
||||
@ -85,9 +80,7 @@ public final class NBTInputStream implements Closeable {
|
||||
* @param type the type
|
||||
* @param name the name
|
||||
* @param depth the depth
|
||||
*
|
||||
* @return the tag
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private Tag readTagPayload(int type, String name, int depth, int maxDepth) throws IOException {
|
||||
@ -98,7 +91,8 @@ public final class NBTInputStream implements Closeable {
|
||||
switch (type) {
|
||||
case NBTConstants.TYPE_END:
|
||||
if (depth == 0) {
|
||||
throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
|
||||
throw new IOException(
|
||||
"TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
|
||||
} else {
|
||||
return new EndTag();
|
||||
}
|
||||
@ -185,8 +179,7 @@ public final class NBTInputStream implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
@Override public void close() throws IOException {
|
||||
this.is.close();
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import java.util.List;
|
||||
/**
|
||||
* This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
||||
* {@code Tag} objects to an underlying {@code OutputStream}.
|
||||
*
|
||||
* <p>
|
||||
* <p> The NBT format was created by Markus Persson, and the specification may
|
||||
* be found at @linktourl http://www.minecraft.net/docs/NBT.txt
|
||||
* </p>
|
||||
@ -28,7 +28,6 @@ public final class NBTOutputStream implements Closeable {
|
||||
* specified underlying output stream.
|
||||
*
|
||||
* @param os The output stream.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public NBTOutputStream(OutputStream os) {
|
||||
@ -39,7 +38,6 @@ public final class NBTOutputStream implements Closeable {
|
||||
* Writes a tag.
|
||||
*
|
||||
* @param tag The tag to write.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public void writeTag(Tag tag) throws IOException {
|
||||
@ -59,7 +57,6 @@ public final class NBTOutputStream implements Closeable {
|
||||
* Writes tag payload.
|
||||
*
|
||||
* @param tag The tag.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private void writeTagPayload(Tag tag) throws IOException {
|
||||
@ -110,7 +107,6 @@ public final class NBTOutputStream implements Closeable {
|
||||
* Writes a {@code TAG_Byte} tag.
|
||||
*
|
||||
* @param tag The tag.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private void writeByteTagPayload(ByteTag tag) throws IOException {
|
||||
@ -121,7 +117,6 @@ public final class NBTOutputStream implements Closeable {
|
||||
* Writes a {@code TAG_Byte_Array} tag.
|
||||
*
|
||||
* @param tag The tag.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private void writeByteArrayTagPayload(ByteArrayTag tag) throws IOException {
|
||||
@ -134,7 +129,6 @@ public final class NBTOutputStream implements Closeable {
|
||||
* Writes a {@code TAG_Compound} tag.
|
||||
*
|
||||
* @param tag The tag.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private void writeCompoundTagPayload(CompoundTag tag) throws IOException {
|
||||
@ -148,7 +142,6 @@ public final class NBTOutputStream implements Closeable {
|
||||
* Writes a {@code TAG_List} tag.
|
||||
*
|
||||
* @param tag The tag.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private void writeListTagPayload(ListTag tag) throws IOException {
|
||||
@ -166,7 +159,6 @@ public final class NBTOutputStream implements Closeable {
|
||||
* Writes a {@code TAG_String} tag.
|
||||
*
|
||||
* @param tag The tag.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private void writeStringTagPayload(StringTag tag) throws IOException {
|
||||
@ -179,7 +171,6 @@ public final class NBTOutputStream implements Closeable {
|
||||
* Writes a {@code TAG_Double} tag.
|
||||
*
|
||||
* @param tag The tag.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private void writeDoubleTagPayload(DoubleTag tag) throws IOException {
|
||||
@ -190,7 +181,6 @@ public final class NBTOutputStream implements Closeable {
|
||||
* Writes a {@code TAG_Float} tag.
|
||||
*
|
||||
* @param tag The tag.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private void writeFloatTagPayload(FloatTag tag) throws IOException {
|
||||
@ -201,7 +191,6 @@ public final class NBTOutputStream implements Closeable {
|
||||
* Writes a {@code TAG_Long} tag.
|
||||
*
|
||||
* @param tag The tag.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private void writeLongTagPayload(LongTag tag) throws IOException {
|
||||
@ -212,7 +201,6 @@ public final class NBTOutputStream implements Closeable {
|
||||
* Writes a {@code TAG_Int} tag.
|
||||
*
|
||||
* @param tag The tag.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private void writeIntTagPayload(IntTag tag) throws IOException {
|
||||
@ -223,7 +211,6 @@ public final class NBTOutputStream implements Closeable {
|
||||
* Writes a {@code TAG_Short} tag.
|
||||
*
|
||||
* @param tag The tag.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private void writeShortTagPayload(ShortTag tag) throws IOException {
|
||||
@ -247,13 +234,13 @@ public final class NBTOutputStream implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
@Override public void close() throws IOException {
|
||||
this.os.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush output.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void flush() throws IOException {
|
||||
|
@ -10,13 +10,13 @@ public final class NBTUtils {
|
||||
/**
|
||||
* Default private constructor.
|
||||
*/
|
||||
private NBTUtils() {}
|
||||
private NBTUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type name of a tag.
|
||||
*
|
||||
* @param clazz the tag class
|
||||
*
|
||||
* @return The type name.
|
||||
*/
|
||||
public static String getTypeName(Class<? extends Tag> clazz) {
|
||||
@ -53,9 +53,7 @@ public final class NBTUtils {
|
||||
* Gets the type code of a tag class.
|
||||
*
|
||||
* @param clazz the tag class
|
||||
*
|
||||
* @return The type code.
|
||||
*
|
||||
* @throws IllegalArgumentException if the tag class is invalid.
|
||||
*/
|
||||
public static int getTypeCode(Class<? extends Tag> clazz) {
|
||||
@ -92,9 +90,7 @@ public final class NBTUtils {
|
||||
* Gets the class of a type of tag.
|
||||
*
|
||||
* @param type the type
|
||||
*
|
||||
* @return The class.
|
||||
*
|
||||
* @throws IllegalArgumentException if the tag type is invalid.
|
||||
*/
|
||||
public static Class<? extends Tag> getTypeClass(int type) {
|
||||
@ -135,17 +131,17 @@ public final class NBTUtils {
|
||||
* @param key the key to look for
|
||||
* @param expected the expected NBT class type
|
||||
* @param <T>
|
||||
*
|
||||
* @return child tag
|
||||
*/
|
||||
public static <T extends Tag> T getChildTag(Map<String, Tag> items, String key, Class<T> expected)
|
||||
throws IllegalArgumentException {
|
||||
public static <T extends Tag> T getChildTag(Map<String, Tag> items, String key,
|
||||
Class<T> expected) throws IllegalArgumentException {
|
||||
if (!items.containsKey(key)) {
|
||||
throw new IllegalArgumentException("Missing a \"" + key + "\" tag");
|
||||
}
|
||||
Tag tag = items.get(key);
|
||||
if (!expected.isInstance(tag)) {
|
||||
throw new IllegalArgumentException(key + " tag is not of tag type " + expected.getName());
|
||||
throw new IllegalArgumentException(
|
||||
key + " tag is not of tag type " + expected.getName());
|
||||
}
|
||||
return expected.cast(tag);
|
||||
}
|
||||
|
@ -27,13 +27,11 @@ public final class ShortTag extends Tag {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short getValue() {
|
||||
@Override public Short getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
String name = getName();
|
||||
String append = "";
|
||||
if (name != null && !name.isEmpty()) {
|
||||
|
@ -31,13 +31,11 @@ public final class StringTag extends Tag {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
@Override public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
String name = getName();
|
||||
String append = "";
|
||||
if (name != null && !name.isEmpty()) {
|
||||
|
@ -4,13 +4,13 @@ package com.intellectualcrafters.json;
|
||||
* This provides static methods to convert comma delimited text into a JSONArray, and to covert a JSONArray into comma
|
||||
* delimited text. Comma delimited text is a very popular format for data interchange. It is understood by most
|
||||
* database, spreadsheet, and organizer programs.
|
||||
*
|
||||
* <p>
|
||||
* Each row of text represents a row in a table or a data record. Each row ends with a NEWLINE character. Each row
|
||||
* contains one or more values. Values are separated by commas. A value can contain any character except for comma,
|
||||
* unless is is wrapped in single quotes or double quotes.
|
||||
*
|
||||
* <p>
|
||||
* The first row usually contains the names of the columns.
|
||||
*
|
||||
* <p>
|
||||
* A comma delimited list can be converted into a JSONArray of JSONObjects. The names for the elements in the
|
||||
* JSONObjects can be taken from the names in the first row.
|
||||
*
|
||||
@ -23,9 +23,7 @@ public class CDL {
|
||||
* Get the next value. The value can be wrapped in quotes. The value can be empty.
|
||||
*
|
||||
* @param x A JSONTokener of the source text.
|
||||
*
|
||||
* @return The value string, or null if empty.
|
||||
*
|
||||
* @throws JSONException if the quoted string is badly formed.
|
||||
*/
|
||||
private static String getValue(JSONTokener x) throws JSONException {
|
||||
@ -66,9 +64,7 @@ public class CDL {
|
||||
* Produce a JSONArray of strings from a row of comma delimited values.
|
||||
*
|
||||
* @param x A JSONTokener of the source text.
|
||||
*
|
||||
* @return A JSONArray of strings.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
|
||||
@ -102,9 +98,7 @@ public class CDL {
|
||||
* @param names A JSONArray of names. This is commonly obtained from the first row of a comma delimited text file
|
||||
* using the rowToJSONArray method.
|
||||
* @param x A JSONTokener of the source text.
|
||||
*
|
||||
* @return A JSONObject combining the names and values.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x) throws JSONException {
|
||||
@ -117,7 +111,6 @@ public class CDL {
|
||||
* Troublesome characters may be removed.
|
||||
*
|
||||
* @param ja A JSONArray of strings.
|
||||
*
|
||||
* @return A string ending in NEWLINE.
|
||||
*/
|
||||
public static String rowToString(JSONArray ja) {
|
||||
@ -129,8 +122,9 @@ public class CDL {
|
||||
Object object = ja.opt(i);
|
||||
if (object != null) {
|
||||
String string = object.toString();
|
||||
if (!string.isEmpty() && ((string.indexOf(',') >= 0) || (string.indexOf('\n') >= 0) || (string.indexOf('\r') >= 0) || (
|
||||
string.indexOf(0) >= 0) || (string.charAt(0) == '"'))) {
|
||||
if (!string.isEmpty() && ((string.indexOf(',') >= 0) || (string.indexOf('\n') >= 0)
|
||||
|| (string.indexOf('\r') >= 0) || (string.indexOf(0) >= 0) || (string.charAt(0)
|
||||
== '"'))) {
|
||||
sb.append('"');
|
||||
int length = string.length();
|
||||
for (int j = 0; j < length; j += 1) {
|
||||
@ -153,9 +147,7 @@ public class CDL {
|
||||
* Produce a JSONArray of JSONObjects from a comma delimited text string, using the first row as a source of names.
|
||||
*
|
||||
* @param string The comma delimited text.
|
||||
*
|
||||
* @return A JSONArray of JSONObjects.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(String string) throws JSONException {
|
||||
@ -166,9 +158,7 @@ public class CDL {
|
||||
* Produce a JSONArray of JSONObjects from a comma delimited text string, using the first row as a source of names.
|
||||
*
|
||||
* @param x The JSONTokener containing the comma delimited text.
|
||||
*
|
||||
* @return A JSONArray of JSONObjects.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(JSONTokener x) throws JSONException {
|
||||
@ -181,9 +171,7 @@ public class CDL {
|
||||
*
|
||||
* @param names A JSONArray of strings.
|
||||
* @param string The comma delimited text.
|
||||
*
|
||||
* @return A JSONArray of JSONObjects.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(JSONArray names, String string) throws JSONException {
|
||||
@ -196,9 +184,7 @@ public class CDL {
|
||||
*
|
||||
* @param names A JSONArray of strings.
|
||||
* @param x A JSONTokener of the source text.
|
||||
*
|
||||
* @return A JSONArray of JSONObjects.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(JSONArray names, JSONTokener x) throws JSONException {
|
||||
@ -224,9 +210,7 @@ public class CDL {
|
||||
* inspecting the first JSONObject.
|
||||
*
|
||||
* @param ja A JSONArray of JSONObjects.
|
||||
*
|
||||
* @return A comma delimited text.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(JSONArray ja) throws JSONException {
|
||||
@ -246,9 +230,7 @@ public class CDL {
|
||||
*
|
||||
* @param names A JSONArray of strings.
|
||||
* @param ja A JSONArray of JSONObjects.
|
||||
*
|
||||
* @return A comma delimited text.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(JSONArray names, JSONArray ja) throws JSONException {
|
||||
|
@ -16,7 +16,6 @@ public class Cookie {
|
||||
* encode '=' and ';' because we must. We encode '%' and '+' because they are meta characters in URL encoding.
|
||||
*
|
||||
* @param string The source string.
|
||||
*
|
||||
* @return The escaped result.
|
||||
*/
|
||||
public static String escape(final String string) {
|
||||
@ -36,7 +35,7 @@ public class Cookie {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a cookie specification string into a JSONObject. The string will contain a name value pair separated by
|
||||
* '='. The name and the value will be unescaped, possibly converting '+' and '%' sequences. The cookie properties
|
||||
@ -46,9 +45,7 @@ public class Cookie {
|
||||
* JSONObject.
|
||||
*
|
||||
* @param string The cookie specification string.
|
||||
*
|
||||
* @return A JSONObject containing "name", "value", and possibly other members.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||
@ -76,16 +73,14 @@ public class Cookie {
|
||||
}
|
||||
return jo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a JSONObject into a cookie specification string. The JSONObject must contain "name" and "value" members.
|
||||
* If the JSONObject contains "expires", "domain", "path", or "secure" members, they will be appended to the cookie
|
||||
* specification string. All other members are ignored.
|
||||
*
|
||||
* @param jo A JSONObject
|
||||
*
|
||||
* @return A cookie specification string
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(final JSONObject jo) throws JSONException {
|
||||
@ -105,13 +100,12 @@ public class Cookie {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert {@code %}<i>hh</i> sequences to single characters, and convert plus to space.
|
||||
*
|
||||
* @param string A string that may contain {@code +} <small>(plus)</small> and <code>%</code><i>hh</i>
|
||||
* sequences.
|
||||
*
|
||||
* @return The unescaped string.
|
||||
*/
|
||||
public static String unescape(final String string) {
|
||||
|
@ -13,14 +13,12 @@ public class CookieList {
|
||||
* Convert a cookie list into a JSONObject. A cookie list is a sequence of name/value pairs. The names are separated
|
||||
* from the values by '='. The pairs are separated by ';'. The names and the values will be unescaped, possibly
|
||||
* converting '+' and '%' sequences.
|
||||
*
|
||||
* <p>
|
||||
* To add a cookie to a cooklist, cookielistJSONObject.put(cookieJSONObject.getString("name"),
|
||||
* cookieJSONObject.getString("value"));
|
||||
*
|
||||
* @param string A cookie list string
|
||||
*
|
||||
* @return A JSONObject
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||
@ -34,16 +32,14 @@ public class CookieList {
|
||||
}
|
||||
return jo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a JSONObject into a cookie list. A cookie list is a sequence of name/value pairs. The names are separated
|
||||
* from the values by '='. The pairs are separated by ';'. The characters '%', '+', '=', and ';' in the names and
|
||||
* values are replaced by "%hh".
|
||||
*
|
||||
* @param jo A JSONObject
|
||||
*
|
||||
* @return A cookie list string
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(final JSONObject jo) throws JSONException {
|
||||
|
@ -13,7 +13,7 @@ public class HTTP {
|
||||
* Carriage return/line feed.
|
||||
*/
|
||||
public static final String CRLF = "\r\n";
|
||||
|
||||
|
||||
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||
final JSONObject jo = new JSONObject();
|
||||
final HTTPTokener x = new HTTPTokener(string);
|
||||
@ -40,11 +40,11 @@ public class HTTP {
|
||||
}
|
||||
return jo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a JSONObject into an HTTP header. A request header must contain
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* <pre>
|
||||
* {
|
||||
* Method: "POST" (for example),
|
||||
@ -52,10 +52,10 @@ public class HTTP {
|
||||
* "HTTP-Version": "HTTP/1.1" (for example)
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* A response header must contain
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* <pre>
|
||||
* {
|
||||
* "HTTP-Version": "HTTP/1.1" (for example),
|
||||
@ -63,13 +63,11 @@ public class HTTP {
|
||||
* "Reason-Phrase": "OK" (for example)
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* Any other members of the JSONObject will be output as HTTP fields. The result will end with two CRLF pairs.
|
||||
*
|
||||
* @param jo A JSONObject
|
||||
*
|
||||
* @return An HTTP header string.
|
||||
*
|
||||
* @throws JSONException if the object does not contain enough information.
|
||||
*/
|
||||
public static String toString(final JSONObject jo) throws JSONException {
|
||||
@ -96,7 +94,9 @@ public class HTTP {
|
||||
sb.append(CRLF);
|
||||
while (keys.hasNext()) {
|
||||
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(": ");
|
||||
sb.append(jo.getString(string));
|
||||
|
@ -15,12 +15,11 @@ public class HTTPTokener extends JSONTokener {
|
||||
public HTTPTokener(final String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the next token or string. This is used in parsing HTTP headers.
|
||||
*
|
||||
* @return A String.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public String nextToken() throws JSONException {
|
||||
@ -32,7 +31,7 @@ public class HTTPTokener extends JSONTokener {
|
||||
} while (Character.isWhitespace(c));
|
||||
if ((c == '"') || (c == '\'')) {
|
||||
q = c;
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
c = next();
|
||||
if (c < ' ') {
|
||||
throw syntaxError("Unterminated string.");
|
||||
@ -43,7 +42,7 @@ public class HTTPTokener extends JSONTokener {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
if ((c == 0) || Character.isWhitespace(c)) {
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -14,16 +14,16 @@ import java.util.Map;
|
||||
* accessing the values by index, and {@code put} methods for adding or replacing values. The values can be any of
|
||||
* these types: {@code Boolean}, {@code JSONArray}, {@code JSONObject}, {@code Number},
|
||||
* {@code String}, or the {@code JSONObject.NULL object}.
|
||||
*
|
||||
* <p>
|
||||
* <p>The constructor can convert a JSON text into a Java object. The {@code toString} method converts to JSON text.
|
||||
*
|
||||
* <p>
|
||||
* <p>A {@code get} method returns a value if one can be found, and throws an exception if one cannot be found. An
|
||||
* {@code opt} method returns a default value instead of throwing an exception, and so is useful for obtaining
|
||||
* optional values.
|
||||
*
|
||||
* <p>
|
||||
* <p>The generic {@code get()} and {@code opt()} methods return an object which you can cast or query for type.
|
||||
* There are also typed {@code get} and {@code opt} methods that do type checking and type coercion for you.
|
||||
*
|
||||
* <p>
|
||||
* <p>The texts produced by the {@code toString} methods strictly conform to JSON syntax rules. The constructors are
|
||||
* more forgiving in the texts they will accept: <ul> <li>An extra {@code ,} <small>(comma)</small> may appear
|
||||
* just before the closing bracket.</li> <li>The {@code null} value will be inserted when there is {@code ,}
|
||||
@ -41,19 +41,18 @@ public class JSONArray {
|
||||
* The arrayList where the JSONArray's properties are kept.
|
||||
*/
|
||||
private final ArrayList<Object> myArrayList;
|
||||
|
||||
|
||||
/**
|
||||
* Construct an empty JSONArray.
|
||||
*/
|
||||
public JSONArray() {
|
||||
this.myArrayList = new ArrayList<Object>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct a JSONArray from a JSONTokener.
|
||||
*
|
||||
* @param x A JSONTokener
|
||||
*
|
||||
* @throws JSONException If there is a syntax error.
|
||||
*/
|
||||
public JSONArray(JSONTokener x) throws JSONException {
|
||||
@ -63,7 +62,7 @@ public class JSONArray {
|
||||
}
|
||||
if (x.nextClean() != ']') {
|
||||
x.back();
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
if (x.nextClean() == ',') {
|
||||
x.back();
|
||||
this.myArrayList.add(JSONObject.NULL);
|
||||
@ -86,19 +85,18 @@ public class JSONArray {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct a JSONArray from a source JSON text.
|
||||
*
|
||||
* @param source A string that begins with {@code [} <small>(left bracket)</small> and ends with
|
||||
* {@code ]} <small>(right bracket)</small>.
|
||||
*
|
||||
* @throws JSONException If there is a syntax error.
|
||||
*/
|
||||
public JSONArray(String source) throws JSONException {
|
||||
this(new JSONTokener(source));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct a JSONArray from a Collection.
|
||||
*
|
||||
@ -112,7 +110,7 @@ public class JSONArray {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct a JSONArray from an array
|
||||
*
|
||||
@ -126,17 +124,16 @@ public class JSONArray {
|
||||
this.put(JSONObject.wrap(Array.get(array, i)));
|
||||
}
|
||||
} 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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the object value associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return An object value.
|
||||
*
|
||||
* @throws JSONException If there is no value for the index.
|
||||
*/
|
||||
public Object get(int index) throws JSONException {
|
||||
@ -146,69 +143,67 @@ public class JSONArray {
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the boolean value associated with an index. The string values "true" and "false" are converted to boolean.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return The truth.
|
||||
*
|
||||
* @throws JSONException If there is no value for the index or if the value is not convertible to boolean.
|
||||
*/
|
||||
public boolean getBoolean(int index) throws JSONException {
|
||||
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;
|
||||
} else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) {
|
||||
} else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object)
|
||||
.equalsIgnoreCase("true"))) {
|
||||
return true;
|
||||
}
|
||||
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the double value associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return The value.
|
||||
*
|
||||
* @throws JSONException If the key is not found or if the value cannot be converted to a number.
|
||||
*/
|
||||
public double getDouble(int index) throws JSONException {
|
||||
Object object = get(index);
|
||||
try {
|
||||
return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object);
|
||||
return object instanceof Number ?
|
||||
((Number) object).doubleValue() :
|
||||
Double.parseDouble((String) object);
|
||||
} catch (NumberFormatException ignored) {
|
||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the int value associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return The value.
|
||||
*
|
||||
* @throws JSONException If the key is not found or if the value is not a number.
|
||||
*/
|
||||
public int getInt(int index) throws JSONException {
|
||||
Object object = get(index);
|
||||
try {
|
||||
return object instanceof Number ? ((Number) object).intValue() : Integer.parseInt((String) object);
|
||||
return object instanceof Number ?
|
||||
((Number) object).intValue() :
|
||||
Integer.parseInt((String) object);
|
||||
} catch (NumberFormatException ignored) {
|
||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the JSONArray associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return A JSONArray value.
|
||||
*
|
||||
* @throws JSONException If there is no value for the index. or if the value is not a JSONArray
|
||||
*/
|
||||
public JSONArray getJSONArray(int index) throws JSONException {
|
||||
@ -218,14 +213,12 @@ public class JSONArray {
|
||||
}
|
||||
throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the JSONObject associated with an index.
|
||||
*
|
||||
* @param index subscript
|
||||
*
|
||||
* @return A JSONObject value.
|
||||
*
|
||||
* @throws JSONException If there is no value for the index or if the value is not a JSONObject
|
||||
*/
|
||||
public JSONObject getJSONObject(int index) throws JSONException {
|
||||
@ -235,32 +228,30 @@ public class JSONArray {
|
||||
}
|
||||
throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the long value associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return The value.
|
||||
*
|
||||
* @throws JSONException If the key is not found or if the value cannot be converted to a number.
|
||||
*/
|
||||
public long getLong(int index) throws JSONException {
|
||||
Object object = get(index);
|
||||
try {
|
||||
return object instanceof Number ? ((Number) object).longValue() : Long.parseLong((String) object);
|
||||
return object instanceof Number ?
|
||||
((Number) object).longValue() :
|
||||
Long.parseLong((String) object);
|
||||
} catch (NumberFormatException ignored) {
|
||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the string associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return A string value.
|
||||
*
|
||||
* @throws JSONException If there is no string value for the index.
|
||||
*/
|
||||
public String getString(int index) throws JSONException {
|
||||
@ -270,26 +261,23 @@ public class JSONArray {
|
||||
}
|
||||
throw new JSONException("JSONArray[" + index + "] not a string.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if the value is null.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return true if the value at the index is null, or if there is no value.
|
||||
*/
|
||||
public boolean isNull(int index) {
|
||||
return JSONObject.NULL.equals(opt(index));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a string from the contents of this JSONArray. The {@code separator} string is inserted between each
|
||||
* element. Warning: This method assumes that the data structure is acyclical.
|
||||
*
|
||||
* @param separator A string that will be inserted between the elements.
|
||||
*
|
||||
* @return a string.
|
||||
*
|
||||
* @throws JSONException If the array contains an invalid number.
|
||||
*/
|
||||
public String join(String separator) throws JSONException {
|
||||
@ -303,7 +291,7 @@ public class JSONArray {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the number of elements in the JSONArray, included nulls.
|
||||
*
|
||||
@ -312,37 +300,34 @@ public class JSONArray {
|
||||
public int length() {
|
||||
return this.myArrayList.size();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the optional object value associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return An object value, or null if there is no object at that index.
|
||||
*/
|
||||
public Object opt(int index) {
|
||||
return ((index < 0) || (index >= length())) ? null : this.myArrayList.get(index);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the optional boolean value associated with an index. It returns false if there is no value at that index, or
|
||||
* if the value is not Boolean.TRUE or the String "true".
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return The truth.
|
||||
*/
|
||||
public boolean optBoolean(int index) {
|
||||
return this.optBoolean(index, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the optional boolean value associated with an index. It returns the defaultValue if there is no value at that
|
||||
* index or if it is not a Boolean or the String "true" or "false" (case insensitive).
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @param defaultValue A boolean default.
|
||||
*
|
||||
* @return The truth.
|
||||
*/
|
||||
public boolean optBoolean(int index, boolean defaultValue) {
|
||||
@ -352,26 +337,24 @@ public class JSONArray {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the optional double value associated with an index. NaN is returned if there is no value for the index, or if
|
||||
* the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return The value.
|
||||
*/
|
||||
public double optDouble(int index) {
|
||||
return this.optDouble(index, Double.NaN);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the optional double value associated with an index. The defaultValue is returned if there is no value for the
|
||||
* index, or if the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index subscript
|
||||
* @param defaultValue The default value.
|
||||
*
|
||||
* @return The value.
|
||||
*/
|
||||
public double optDouble(int index, double defaultValue) {
|
||||
@ -381,26 +364,24 @@ public class JSONArray {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the optional int value associated with an index. Zero is returned if there is no value for the index, or if
|
||||
* the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return The value.
|
||||
*/
|
||||
public int optInt(int index) {
|
||||
return this.optInt(index, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the optional int value associated with an index. The defaultValue is returned if there is no value for the
|
||||
* index, or if the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @param defaultValue The default value.
|
||||
*
|
||||
* @return The value.
|
||||
*/
|
||||
public int optInt(int index, int defaultValue) {
|
||||
@ -410,52 +391,48 @@ public class JSONArray {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the optional JSONArray associated with an index.
|
||||
*
|
||||
* @param index subscript
|
||||
*
|
||||
* @return A JSONArray value, or null if the index has no value, or if the value is not a JSONArray.
|
||||
*/
|
||||
public JSONArray optJSONArray(int index) {
|
||||
Object o = opt(index);
|
||||
return o instanceof JSONArray ? (JSONArray) o : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the optional JSONObject associated with an index. Null is returned if the key is not found, or null if the
|
||||
* index has no value, or if the value is not a JSONObject.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return A JSONObject value.
|
||||
*/
|
||||
public JSONObject optJSONObject(int index) {
|
||||
Object o = opt(index);
|
||||
return o instanceof JSONObject ? (JSONObject) o : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the optional long value associated with an index. Zero is returned if there is no value for the index, or if
|
||||
* the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return The value.
|
||||
*/
|
||||
public long optLong(int index) {
|
||||
return this.optLong(index, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the optional long value associated with an index. The defaultValue
|
||||
* is returned if there is no value for the index, or if the value is not a
|
||||
* number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @param defaultValue The default value.
|
||||
*
|
||||
* @return The value.
|
||||
*/
|
||||
public long optLong(int index, long defaultValue) {
|
||||
@ -465,66 +442,60 @@ public class JSONArray {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the optional string value associated with an index. It returns an
|
||||
* empty string if there is no value at that index. If the value is not a
|
||||
* string and is not null, then it is converted to a string.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
*
|
||||
* @return A String value.
|
||||
*/
|
||||
public String optString(int index) {
|
||||
return this.optString(index, "");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the optional string associated with an index. The defaultValue is
|
||||
* returned if the key is not found.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @param defaultValue The default value.
|
||||
*
|
||||
* @return A String value.
|
||||
*/
|
||||
public String optString(int index, String defaultValue) {
|
||||
Object object = opt(index);
|
||||
return JSONObject.NULL.equals(object) ? defaultValue : object.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append a boolean value. This increases the array's length by one.
|
||||
*
|
||||
* @param value A boolean value.
|
||||
*
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(boolean value) {
|
||||
this.put(value ? Boolean.TRUE : Boolean.FALSE);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put a value in the JSONArray, where the value will be a JSONArray which
|
||||
* is produced from a Collection.
|
||||
*
|
||||
* @param value A Collection value.
|
||||
*
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(Collection<Object> value) {
|
||||
this.put(new JSONArray(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append a double value. This increases the array's length by one.
|
||||
*
|
||||
* @param value A double value.
|
||||
*
|
||||
* @return this.
|
||||
*
|
||||
* @throws JSONException if the value is not finite.
|
||||
*/
|
||||
public JSONArray put(double value) throws JSONException {
|
||||
@ -533,90 +504,82 @@ public class JSONArray {
|
||||
this.put(d);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append an int value. This increases the array's length by one.
|
||||
*
|
||||
* @param value An int value.
|
||||
*
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(int value) {
|
||||
this.put(Integer.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append an long value. This increases the array's length by one.
|
||||
*
|
||||
* @param value A long value.
|
||||
*
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(long value) {
|
||||
this.put(Long.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put a value in the JSONArray, where the value will be a JSONObject which
|
||||
* is produced from a Map.
|
||||
*
|
||||
* @param value A Map value.
|
||||
*
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(Map<String, Object> value) {
|
||||
this.put(new JSONObject(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append an object value. This increases the array's length by one.
|
||||
*
|
||||
* @param value An object value. The value should be a Boolean, Double,
|
||||
* Integer, JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
|
||||
*
|
||||
* Integer, JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(Object value) {
|
||||
this.myArrayList.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put or replace a boolean value in the JSONArray. If the index is greater than the length of the JSONArray, then
|
||||
* null elements will be added as necessary to pad it out.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value A boolean value.
|
||||
*
|
||||
* @return this.
|
||||
*
|
||||
* @throws JSONException If the index is negative.
|
||||
*/
|
||||
public JSONArray put(int index, boolean value) throws JSONException {
|
||||
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put a value in the JSONArray, where the value will be a JSONArray which
|
||||
* is produced from a Collection.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value A Collection value.
|
||||
*
|
||||
* @return this.
|
||||
*
|
||||
* @throws JSONException If the index is negative or if the value is not
|
||||
* finite.
|
||||
* finite.
|
||||
*/
|
||||
public JSONArray put(int index, Collection<Object> value) throws JSONException {
|
||||
this.put(index, new JSONArray(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put or replace a double value. If the index is greater than the length
|
||||
* of the JSONArray, then null elements will be added as necessary to pad
|
||||
@ -624,66 +587,58 @@ public class JSONArray {
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value A double value.
|
||||
*
|
||||
* @return this.
|
||||
*
|
||||
* @throws JSONException If the index is negative or if the value is not
|
||||
* finite.
|
||||
* finite.
|
||||
*/
|
||||
public JSONArray put(int index, double value) throws JSONException {
|
||||
this.put(index, new Double(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put or replace an int value. If the index is greater than the length of the JSONArray, then null elements will be
|
||||
* added as necessary to pad it out.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value An int value.
|
||||
*
|
||||
* @return this.
|
||||
*
|
||||
* @throws JSONException If the index is negative.
|
||||
*/
|
||||
public JSONArray put(int index, int value) throws JSONException {
|
||||
this.put(index, Integer.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put or replace a long value. If the index is greater than the length of the JSONArray, then null elements will be
|
||||
* added as necessary to pad it out.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value A long value.
|
||||
*
|
||||
* @return this.
|
||||
*
|
||||
* @throws JSONException If the index is negative.
|
||||
*/
|
||||
public JSONArray put(int index, long value) throws JSONException {
|
||||
this.put(index, Long.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put a value in the JSONArray, where the value will be a JSONObject that
|
||||
* is produced from a Map.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value The Map value.
|
||||
*
|
||||
* @return this.
|
||||
*
|
||||
* @throws JSONException If the index is negative or if the the value is an
|
||||
* invalid number.
|
||||
* invalid number.
|
||||
*/
|
||||
public JSONArray put(int index, Map<String, Object> value) throws JSONException {
|
||||
this.put(index, new JSONObject(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put or replace an object value in the JSONArray. If the index is greater than the length of the JSONArray, then
|
||||
* null elements will be added as necessary to pad it out.
|
||||
@ -691,9 +646,7 @@ public class JSONArray {
|
||||
* @param index The subscript.
|
||||
* @param value The value to put into the array. The value should be a Boolean, Double, Integer, JSONArray,
|
||||
* JSONObject, Long, or String, or the JSONObject.NULL object.
|
||||
*
|
||||
* @return this.
|
||||
*
|
||||
* @throws JSONException If the index is negative or if the the value is an invalid number.
|
||||
*/
|
||||
public JSONArray put(int index, Object value) throws JSONException {
|
||||
@ -711,23 +664,21 @@ public class JSONArray {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an index and close the hole.
|
||||
*
|
||||
* @param index The index of the element to be removed.
|
||||
*
|
||||
* @return The value that was associated with the index, or null if there was no value.
|
||||
*/
|
||||
public Object remove(int index) {
|
||||
return (index >= 0) && (index < length()) ? this.myArrayList.remove(index) : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if two JSONArrays are similar. They must contain similar sequences.
|
||||
*
|
||||
* @param other The other JSONArray
|
||||
*
|
||||
* @return true if they are equal
|
||||
*/
|
||||
public boolean similar(Object other) {
|
||||
@ -755,14 +706,12 @@ public class JSONArray {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Produce a JSONObject by combining a JSONArray of names with the values of this JSONArray.
|
||||
*
|
||||
* @param names A JSONArray containing a list of key strings. These will be paired with the values.
|
||||
*
|
||||
* @return A JSONObject, or null if there are no names or if this JSONArray has no values.
|
||||
*
|
||||
* @throws JSONException If any of the names are null.
|
||||
*/
|
||||
public JSONObject toJSONObject(JSONArray names) throws JSONException {
|
||||
@ -775,35 +724,32 @@ public class JSONArray {
|
||||
}
|
||||
return jo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a JSON text of this JSONArray. For compactness, no unnecessary whitespace is added. If it is not possible to
|
||||
* produce a syntactically correct JSON text then null will be returned instead. This could occur if the array
|
||||
* contains an invalid number.
|
||||
*
|
||||
* <p>
|
||||
* Warning: This method assumes that the data structure is acyclical.
|
||||
*
|
||||
* @return a printable, displayable, transmittable representation of the array.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
try {
|
||||
return this.toString(0);
|
||||
} catch (JSONException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a prettyprinted JSON text of this JSONArray. Warning: This method assumes that the data structure is
|
||||
* acyclical.
|
||||
*
|
||||
* @param indentFactor The number of spaces to add to each level of indentation.
|
||||
*
|
||||
* @return a printable, displayable, transmittable representation of the object, beginning with
|
||||
* {@code [} <small>(left bracket)</small> and ending with {@code ]} <small>(right
|
||||
* bracket)</small>.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public String toString(int indentFactor) throws JSONException {
|
||||
@ -812,30 +758,27 @@ public class JSONArray {
|
||||
return this.write(sw, indentFactor, 0).toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added.
|
||||
*
|
||||
* <p>
|
||||
* Warning: This method assumes that the data structure is acyclical.
|
||||
*
|
||||
* @return The writer.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public Writer write(Writer writer) throws JSONException {
|
||||
return this.write(writer, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added.
|
||||
*
|
||||
* <p>
|
||||
* Warning: This method assumes that the data structure is acyclical.
|
||||
*
|
||||
* @param indentFactor The number of spaces to add to each level of indentation.
|
||||
* @param indent The indention of the top level.
|
||||
*
|
||||
* @return The writer.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
Writer write(Writer writer, int indentFactor, int indent) throws JSONException {
|
||||
|
@ -9,7 +9,7 @@ package com.intellectualcrafters.json;
|
||||
public class JSONException extends RuntimeException {
|
||||
private static final long serialVersionUID = 0;
|
||||
private Throwable cause;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a JSONException with an explanatory message.
|
||||
*
|
||||
@ -18,7 +18,7 @@ public class JSONException extends RuntimeException {
|
||||
public JSONException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new JSONException with the specified cause.
|
||||
*
|
||||
@ -28,14 +28,13 @@ public class JSONException extends RuntimeException {
|
||||
super(cause.getMessage());
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the cause of this exception or null if the cause is nonexistent or unknown.
|
||||
*
|
||||
* @return the cause of this exception or null if the cause is nonexistent or unknown.
|
||||
*/
|
||||
@Override
|
||||
public Throwable getCause() {
|
||||
@Override public Throwable getCause() {
|
||||
return cause;
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,11 @@ public class JSONML {
|
||||
* @param x The XMLTokener containing the source string.
|
||||
* @param arrayForm true if array form, false if object form.
|
||||
* @param ja The JSONArray that is containing the current tag or null if we are at the outermost level.
|
||||
*
|
||||
* @return A JSONArray if the value is the outermost tag, otherwise null.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
private static Object parse(XMLTokener x, boolean arrayForm, JSONArray ja) throws JSONException {
|
||||
private static Object parse(XMLTokener x, boolean arrayForm, JSONArray ja)
|
||||
throws JSONException {
|
||||
String attribute;
|
||||
char c;
|
||||
String closeTag = null;
|
||||
@ -47,7 +46,8 @@ public class JSONML {
|
||||
// Close tag </
|
||||
token = x.nextToken();
|
||||
if (!(token instanceof String)) {
|
||||
throw new JSONException("Expected a closing name instead of '" + token + "'.");
|
||||
throw new JSONException(
|
||||
"Expected a closing name instead of '" + token + "'.");
|
||||
}
|
||||
if (x.nextToken() != XML.GT) {
|
||||
throw x.syntaxError("Misshaped close tag");
|
||||
@ -110,7 +110,7 @@ public class JSONML {
|
||||
}
|
||||
}
|
||||
token = null;
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
if (token == null) {
|
||||
token = x.nextToken();
|
||||
}
|
||||
@ -119,7 +119,8 @@ public class JSONML {
|
||||
}
|
||||
// attribute = value
|
||||
attribute = (String) token;
|
||||
if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) {
|
||||
if (!arrayForm && ("tagName".equals(attribute) || "childNode"
|
||||
.equals(attribute))) {
|
||||
throw x.syntaxError("Reserved attribute.");
|
||||
}
|
||||
token = x.nextToken();
|
||||
@ -157,7 +158,8 @@ public class JSONML {
|
||||
closeTag = (String) parse(x, arrayForm, newja);
|
||||
if (closeTag != null) {
|
||||
if (!closeTag.equals(tagName)) {
|
||||
throw x.syntaxError("Mismatched '" + tagName + "' and '" + closeTag + "'");
|
||||
throw x.syntaxError(
|
||||
"Mismatched '" + tagName + "' and '" + closeTag + "'");
|
||||
}
|
||||
tagName = null;
|
||||
if (!arrayForm && (newja.length() > 0)) {
|
||||
@ -180,22 +182,20 @@ public class JSONML {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONArray using the JsonML transform. Each
|
||||
* XML tag is represented as a JSONArray in which the first element is the tag name. If the tag has attributes, then
|
||||
* the second element will be JSONObject containing the name/value pairs. If the tag contains children, then strings
|
||||
*
|
||||
* @param string The source string.
|
||||
*
|
||||
* @return A JSONArray containing the structured data from the XML string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(String string) throws JSONException {
|
||||
return toJSONArray(new XMLTokener(string));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONArray using the JsonML transform. Each
|
||||
* XML tag is represented as a JSONArray in which the first element is the tag name. If the tag has attributes, then
|
||||
@ -204,58 +204,50 @@ public class JSONML {
|
||||
* are ignored.
|
||||
*
|
||||
* @param x An XMLTokener.
|
||||
*
|
||||
* @return A JSONArray containing the structured data from the XML string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(XMLTokener x) throws JSONException {
|
||||
return (JSONArray) parse(x, true, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML transform. Each
|
||||
* XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes
|
||||
* will be in the JSONObject as properties. If the tag contains children, the object will have a "childNodes"
|
||||
* property which will be an array of strings and JsonML JSONObjects.
|
||||
*
|
||||
* <p>
|
||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
||||
*
|
||||
* @param x An XMLTokener of the XML source text.
|
||||
*
|
||||
* @return A JSONObject containing the structured data from the XML string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(XMLTokener x) throws JSONException {
|
||||
return (JSONObject) parse(x, false, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML transform. Each
|
||||
* XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes
|
||||
* will be in the JSONObject as properties. If the tag contains children, the object will have a "childNodes"
|
||||
* property which will be an array of strings and JsonML JSONObjects.
|
||||
*
|
||||
* <p>
|
||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
||||
*
|
||||
* @param string The XML source text.
|
||||
*
|
||||
* @return A JSONObject containing the structured data from the XML string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(String string) throws JSONException {
|
||||
return toJSONObject(new XMLTokener(string));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reverse the JSONML transformation, making an XML text from a JSONArray.
|
||||
*
|
||||
* @param ja A JSONArray.
|
||||
*
|
||||
* @return An XML string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(JSONArray ja) throws JSONException {
|
||||
@ -323,16 +315,14 @@ public class JSONML {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reverse the JSONML transformation, making an XML text from a JSONObject. The JSONObject must contain a "tagName"
|
||||
* property. If it has children, then it must have a "childNodes" property containing an array of objects. The other
|
||||
* properties are attributes with string values.
|
||||
*
|
||||
* @param jo A JSONObject.
|
||||
*
|
||||
* @return An XML string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(JSONObject jo) throws JSONException {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,28 +6,28 @@ import java.io.StringWriter;
|
||||
* JSONStringer provides a quick and convenient way of producing JSON text. The texts produced strictly conform to JSON
|
||||
* syntax rules. No whitespace is added, so the results are ready for transmission or storage. Each instance of
|
||||
* JSONStringer can produce one JSON text.
|
||||
*
|
||||
* <p>
|
||||
* A JSONStringer instance provides a <code>value</code> method for appending values to the text, and a <code>key</code>
|
||||
* method for adding keys before values in objects. There are <code>array</code> and <code>endArray</code> methods that
|
||||
* make and bound array values, and <code>object</code> and <code>endObject</code> methods which make and bound object
|
||||
* values. All of these methods return the JSONWriter instance, permitting cascade style. For example,
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* <pre>
|
||||
* myString = new JSONStringer().object().key("JSON").value("Hello,
|
||||
* World!").endObject().toString();
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* which produces the string
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* <pre>
|
||||
* {"JSON":"Hello, World!"}
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* The first method called must be <code>array</code> or <code>object</code>. There are no methods for adding commas or
|
||||
* colons. JSONStringer adds them for you. Objects and arrays can be nested up to 20 levels deep.
|
||||
*
|
||||
* <p>
|
||||
* This can sometimes be easier than using a JSONObject to build a string.
|
||||
*
|
||||
* @author JSON.org
|
||||
@ -40,7 +40,7 @@ public class JSONStringer extends JSONWriter {
|
||||
public JSONStringer() {
|
||||
super(new StringWriter());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the JSON text. This method is used to obtain the product of the JSONStringer instance. It will return
|
||||
* <code>null</code> if there was a problem in the construction of the JSON text (such as the calls to
|
||||
@ -48,8 +48,7 @@ public class JSONStringer extends JSONWriter {
|
||||
*
|
||||
* @return The JSON text.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
return mode == 'd' ? writer.toString() : null;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,6 @@
|
||||
package com.intellectualcrafters.json;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* A JSONTokener takes a source string and extracts characters and tokens from it. It is used by the JSONObject and
|
||||
@ -22,7 +17,7 @@ public class JSONTokener {
|
||||
private long line;
|
||||
private char previous;
|
||||
private boolean usePrevious;
|
||||
|
||||
|
||||
/**
|
||||
* Construct a JSONTokener from a Reader.
|
||||
*
|
||||
@ -37,7 +32,7 @@ public class JSONTokener {
|
||||
character = 1;
|
||||
line = 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct a JSONTokener from an InputStream.
|
||||
*
|
||||
@ -46,7 +41,7 @@ public class JSONTokener {
|
||||
public JSONTokener(final InputStream inputStream) throws JSONException {
|
||||
this(new InputStreamReader(inputStream));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct a JSONTokener from a string.
|
||||
*
|
||||
@ -55,12 +50,11 @@ public class JSONTokener {
|
||||
public JSONTokener(final String s) {
|
||||
this(new StringReader(s));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the hex value of a character (base16).
|
||||
*
|
||||
* @param c A character between '0' and '9' or between 'A' and 'F' or between 'a' and 'f'.
|
||||
*
|
||||
* @return An int between 0 and 15, or -1 if c was not a hex digit.
|
||||
*/
|
||||
public static int dehexchar(final char c) {
|
||||
@ -75,7 +69,7 @@ public class JSONTokener {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@ -89,11 +83,11 @@ public class JSONTokener {
|
||||
usePrevious = true;
|
||||
eof = false;
|
||||
}
|
||||
|
||||
|
||||
public boolean end() {
|
||||
return eof && !usePrevious;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if the source string still contains characters that next() can consume.
|
||||
*
|
||||
@ -107,7 +101,7 @@ public class JSONTokener {
|
||||
back();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the next character in the source string.
|
||||
*
|
||||
@ -142,14 +136,12 @@ public class JSONTokener {
|
||||
previous = (char) c;
|
||||
return previous;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Consume the next character, and check that it matches a specified character.
|
||||
*
|
||||
* @param c The character to match.
|
||||
*
|
||||
* @return The character.
|
||||
*
|
||||
* @throws JSONException if the character does not match.
|
||||
*/
|
||||
public char next(final char c) throws JSONException {
|
||||
@ -159,14 +151,12 @@ public class JSONTokener {
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the next n characters.
|
||||
*
|
||||
* @param n The number of characters to take.
|
||||
*
|
||||
* @return A string of n characters.
|
||||
*
|
||||
* @throws JSONException Substring bounds error if there are not n characters remaining in the source string.
|
||||
*/
|
||||
public String next(final int n) throws JSONException {
|
||||
@ -184,38 +174,35 @@ public class JSONTokener {
|
||||
}
|
||||
return new String(chars);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the next char in the string, skipping whitespace.
|
||||
*
|
||||
* @return A character, or 0 if there are no more characters.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public char nextClean() throws JSONException {
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
final char c = this.next();
|
||||
if ((c == 0) || (c > ' ')) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the characters up to the next close quote character. Backslash processing is done. The formal JSON format
|
||||
* does not allow strings in single quotes, but an implementation is allowed to accept them.
|
||||
*
|
||||
* @param quote The quoting character, either <code>"</code> <small>(double quote)</small> or <code>'</code>
|
||||
* <small>(single quote)</small>.
|
||||
*
|
||||
* @return A String.
|
||||
*
|
||||
* @throws JSONException Unterminated string.
|
||||
*/
|
||||
public String nextString(final char quote) throws JSONException {
|
||||
char c;
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
c = this.next();
|
||||
switch (c) {
|
||||
case 0:
|
||||
@ -261,17 +248,16 @@ public class JSONTokener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the text up but not including the specified character or the end of line, whichever comes first.
|
||||
*
|
||||
* @param delimiter A delimiter character.
|
||||
*
|
||||
* @return A string.
|
||||
*/
|
||||
public String nextTo(final char delimiter) throws JSONException {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
final char c = this.next();
|
||||
if ((c == delimiter) || (c == 0) || (c == '\n') || (c == '\r')) {
|
||||
if (c != 0) {
|
||||
@ -282,19 +268,18 @@ public class JSONTokener {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the text up but not including one of the specified delimiter characters or the end of line, whichever comes
|
||||
* first.
|
||||
*
|
||||
* @param delimiters A set of delimiter characters.
|
||||
*
|
||||
* @return A string, trimmed.
|
||||
*/
|
||||
public String nextTo(final String delimiters) throws JSONException {
|
||||
char c;
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
c = this.next();
|
||||
if ((delimiters.indexOf(c) >= 0) || (c == 0) || (c == '\n') || (c == '\r')) {
|
||||
if (c != 0) {
|
||||
@ -305,13 +290,12 @@ public class JSONTokener {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the next value. The value can be a Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
|
||||
* JSONObject.NULL object.
|
||||
*
|
||||
* @return An object.
|
||||
*
|
||||
* @throws JSONException If syntax error.
|
||||
*/
|
||||
public Object nextValue() throws JSONException {
|
||||
@ -347,13 +331,12 @@ public class JSONTokener {
|
||||
}
|
||||
return JSONObject.stringToValue(string);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Skip characters until the next character is the requested character. If the requested character is not found, no
|
||||
* characters are skipped.
|
||||
*
|
||||
* @param to A character to skip to.
|
||||
*
|
||||
* @return The requested character, or zero if the requested character is not found.
|
||||
*/
|
||||
public char skipTo(final char to) throws JSONException {
|
||||
@ -379,25 +362,23 @@ public class JSONTokener {
|
||||
back();
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a JSONException to signal a syntax error.
|
||||
*
|
||||
* @param message The error message.
|
||||
*
|
||||
* @return A JSONException object, suitable for throwing
|
||||
*/
|
||||
public JSONException syntaxError(final String message) {
|
||||
return new JSONException(message + toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a printable string of this JSONTokener.
|
||||
*
|
||||
* @return " at {index} [character {character} line {line}]"
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
return " at " + index + " [character " + character + " line " + line + "]";
|
||||
}
|
||||
}
|
||||
|
@ -7,27 +7,27 @@ import java.io.Writer;
|
||||
* JSONWriter provides a quick and convenient way of producing JSON text. The texts produced strictly conform to JSON
|
||||
* syntax rules. No whitespace is added, so the results are ready for transmission or storage. Each instance of
|
||||
* JSONWriter can produce one JSON text.
|
||||
*
|
||||
* <p>
|
||||
* A JSONWriter instance provides a <code>value</code> method for appending values to the text, and a <code>key</code>
|
||||
* method for adding keys before values in objects. There are <code>array</code> and <code>endArray</code> methods that
|
||||
* make and bound array values, and <code>object</code> and <code>endObject</code> methods which make and bound object
|
||||
* values. All of these methods return the JSONWriter instance, permitting a cascade style. For example,
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* <pre>
|
||||
* new JSONWriter(myWriter).object().key("JSON").value("Hello, World!").endObject();
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* which writes
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* <pre>
|
||||
* {"JSON":"Hello, World!"}
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* The first method called must be <code>array</code> or <code>object</code>. There are no methods for adding commas or
|
||||
* colons. JSONWriter adds them for you. Objects and arrays can be nested up to 20 levels deep.
|
||||
*
|
||||
* <p>
|
||||
* This can sometimes be easier than using a JSONObject to build a string.
|
||||
*
|
||||
* @author JSON.org
|
||||
@ -55,7 +55,7 @@ public class JSONWriter {
|
||||
* The stack top index. A value of 0 indicates that the stack is empty.
|
||||
*/
|
||||
private int top;
|
||||
|
||||
|
||||
/**
|
||||
* Make a fresh JSONWriter. It can be used to build one JSON text.
|
||||
*/
|
||||
@ -66,14 +66,12 @@ public class JSONWriter {
|
||||
top = 0;
|
||||
writer = w;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append a value.
|
||||
*
|
||||
* @param string A string value.
|
||||
*
|
||||
* @return this
|
||||
*
|
||||
* @throws JSONException If the value is out of sequence.
|
||||
*/
|
||||
private JSONWriter append(final String string) throws JSONException {
|
||||
@ -97,13 +95,12 @@ public class JSONWriter {
|
||||
}
|
||||
throw new JSONException("Value out of sequence.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Begin appending a new array. All values until the balancing <code>endArray</code> will be appended to this array.
|
||||
* The <code>endArray</code> method must be called to mark the array's end.
|
||||
*
|
||||
* @return this
|
||||
*
|
||||
* @throws JSONException If the nesting is too deep, or if the object is started in the wrong place (for example as
|
||||
* a key or after the end of the outermost array or object).
|
||||
*/
|
||||
@ -116,15 +113,13 @@ public class JSONWriter {
|
||||
}
|
||||
throw new JSONException("Misplaced array.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* End something.
|
||||
*
|
||||
* @param mode Mode
|
||||
* @param c Closing character
|
||||
*
|
||||
* @return this
|
||||
*
|
||||
* @throws JSONException If unbalanced.
|
||||
*/
|
||||
private JSONWriter end(final char mode, final char c) throws JSONException {
|
||||
@ -140,37 +135,33 @@ public class JSONWriter {
|
||||
comma = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* End an array. This method most be called to balance calls to <code>array</code>.
|
||||
*
|
||||
* @return this
|
||||
*
|
||||
* @throws JSONException If incorrectly nested.
|
||||
*/
|
||||
public JSONWriter endArray() throws JSONException {
|
||||
return end('a', ']');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* End an object. This method most be called to balance calls to <code>object</code>.
|
||||
*
|
||||
* @return this
|
||||
*
|
||||
* @throws JSONException If incorrectly nested.
|
||||
*/
|
||||
public JSONWriter endObject() throws JSONException {
|
||||
return end('k', '}');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append a key. The key will be associated with the next value. In an object, every value must be preceded by a
|
||||
* key.
|
||||
*
|
||||
* @param string A key string.
|
||||
*
|
||||
* @return this
|
||||
*
|
||||
* @throws JSONException If the key is out of place. For example, keys do not belong in arrays or if the key is
|
||||
* null.
|
||||
*/
|
||||
@ -195,13 +186,12 @@ public class JSONWriter {
|
||||
}
|
||||
throw new JSONException("Misplaced key.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Begin appending a new object. All keys and values until the balancing <code>endObject</code> will be appended to
|
||||
* this object. The <code>endObject</code> method must be called to mark the object's end.
|
||||
*
|
||||
* @return this
|
||||
*
|
||||
* @throws JSONException If the nesting is too deep, or if the object is started in the wrong place (for example as
|
||||
* a key or after the end of the outermost array or object).
|
||||
*/
|
||||
@ -217,12 +207,11 @@ public class JSONWriter {
|
||||
}
|
||||
throw new JSONException("Misplaced object.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pop an array or object scope.
|
||||
*
|
||||
* @param c The scope to close.
|
||||
*
|
||||
* @throws JSONException If nesting is wrong.
|
||||
*/
|
||||
private void pop(final char c) throws JSONException {
|
||||
@ -236,12 +225,11 @@ public class JSONWriter {
|
||||
top -= 1;
|
||||
mode = top == 0 ? 'd' : stack[top - 1] == null ? 'a' : 'k';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Push an array or object scope.
|
||||
*
|
||||
* @param jo The scope to open.
|
||||
*
|
||||
* @throws JSONException If nesting is too deep.
|
||||
*/
|
||||
private void push(final JSONObject jo) throws JSONException {
|
||||
@ -252,54 +240,46 @@ public class JSONWriter {
|
||||
mode = jo == null ? 'a' : 'k';
|
||||
top += 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append either the value <code>true</code> or the value <code>false</code> .
|
||||
*
|
||||
* @param b A boolean.
|
||||
*
|
||||
* @return this
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public JSONWriter value(final boolean b) throws JSONException {
|
||||
return append(b ? "true" : "false");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append a double value.
|
||||
*
|
||||
* @param d A double.
|
||||
*
|
||||
* @return this
|
||||
*
|
||||
* @throws JSONException If the number is not finite.
|
||||
*/
|
||||
public JSONWriter value(final double d) throws JSONException {
|
||||
return this.value(new Double(d));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append a long value.
|
||||
*
|
||||
* @param l A long.
|
||||
*
|
||||
* @return this
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public JSONWriter value(final long l) throws JSONException {
|
||||
return append(Long.toString(l));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append an object value.
|
||||
*
|
||||
* @param object The object to append. It can be null, or a Boolean, Number, String, JSONObject, or JSONArray, or an
|
||||
* object that implements JSONString.
|
||||
*
|
||||
* @return this
|
||||
*
|
||||
* @throws JSONException If the value is out of sequence.
|
||||
*/
|
||||
public JSONWriter value(final Object object) throws JSONException {
|
||||
|
@ -5,22 +5,22 @@ package com.intellectualcrafters.json;
|
||||
* byte. The last byte of a character never has the MSB reset. Every byte that is not the last byte has the MSB set. Kim
|
||||
* stands for "Keep it minimal". A Unicode character is never longer than 3 bytes. Every byte contributes 7 bits to the
|
||||
* character. ASCII is unmodified.
|
||||
*
|
||||
* <p>
|
||||
* Kim UTF-8 one byte U+007F U+007F two bytes U+3FFF U+07FF three bytes U+10FFF U+FFFF four bytes U+10FFFF
|
||||
*
|
||||
* <p>
|
||||
* Characters in the ranges U+0800..U+3FFF and U+10000..U+10FFFF will be one byte smaller when encoded in Kim compared
|
||||
* to UTF-8.
|
||||
*
|
||||
* <p>
|
||||
* Kim is beneficial when using scripts such as Old South Arabian, Aramaic, Avestan, Balinese, Batak, Bopomofo,
|
||||
* Buginese, Buhid, Carian, Cherokee, Coptic, Cyrillic, Deseret, Egyptian Hieroglyphs, Ethiopic, Georgian, Glagolitic,
|
||||
* Gothic, Hangul Jamo, Hanunoo, Hiragana, Kanbun, Kaithi, Kannada, Katakana, Kharoshthi, Khmer, Lao, Lepcha, Limbu,
|
||||
* Lycian, Lydian, Malayalam, Mandaic, Meroitic, Miao, Mongolian, Myanmar, New Tai Lue, Ol Chiki, Old Turkic, Oriya,
|
||||
* Osmanya, Pahlavi, Parthian, Phags-Pa, Phoenician, Samaritan, Sharada, Sinhala, Sora Sompeng, Tagalog, Tagbanwa,
|
||||
* Takri, Tai Le, Tai Tham, Tamil, Telugu, Thai, Tibetan, Tifinagh, UCAS.
|
||||
*
|
||||
* <p>
|
||||
* A kim object can be constructed from an ordinary UTF-16 string, or from a byte array. A kim object can produce a
|
||||
* UTF-16 string.
|
||||
*
|
||||
* <p>
|
||||
* As with UTF-8, it is possible to detect character boundaries within a byte sequence. UTF-8 is one of the world's
|
||||
* great inventions. While Kim is more efficient, it is not clear that it is worth the expense of transition.
|
||||
*
|
||||
@ -43,7 +43,7 @@ public class Kim {
|
||||
* The memoization of toString().
|
||||
*/
|
||||
private String string = null;
|
||||
|
||||
|
||||
/**
|
||||
* Make a kim from a portion of a byte array.
|
||||
*
|
||||
@ -70,7 +70,7 @@ public class Kim {
|
||||
hashcode += sum << 16;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a kim from a byte array.
|
||||
*
|
||||
@ -80,7 +80,7 @@ public class Kim {
|
||||
public Kim(final byte[] bytes, final int length) {
|
||||
this(bytes, 0, length);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a new kim from a substring of an existing kim. The coordinates are in byte units, not character units.
|
||||
*
|
||||
@ -91,12 +91,11 @@ public class Kim {
|
||||
public Kim(final Kim kim, final int from, final int thru) {
|
||||
this(kim.bytes, from, thru);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a kim from a string.
|
||||
*
|
||||
* @param string The string.
|
||||
*
|
||||
* @throws JSONException if surrogate pair mismatch.
|
||||
*/
|
||||
public Kim(final String string) throws JSONException {
|
||||
@ -151,7 +150,8 @@ public class Kim {
|
||||
} else {
|
||||
if ((character >= 0xD800) && (character <= 0xDBFF)) {
|
||||
i += 1;
|
||||
character = (((character & 0x3FF) << 10) | (string.charAt(i) & 0x3FF)) + 65536;
|
||||
character =
|
||||
(((character & 0x3FF) << 10) | (string.charAt(i) & 0x3FF)) + 65536;
|
||||
}
|
||||
b = 0x80 | (character >>> 14);
|
||||
bytes[at] = (byte) b;
|
||||
@ -173,14 +173,12 @@ public class Kim {
|
||||
hashcode += sum << 16;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of bytes needed to contain the character in Kim format.
|
||||
*
|
||||
* @param character a Unicode character between 0 and 0x10FFFF.
|
||||
*
|
||||
* @return 1, 2, or 3
|
||||
*
|
||||
* @throws JSONException if the character is not representable in a kim.
|
||||
*/
|
||||
public static int characterSize(final int character) throws JSONException {
|
||||
@ -189,15 +187,14 @@ public class Kim {
|
||||
}
|
||||
return character <= 0x7F ? 1 : character <= 0x3FFF ? 2 : 3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the character at the specified index. The index refers to byte values and ranges from 0 to length - 1.
|
||||
* The index of the next character is at index + Kim.characterSize(kim.characterAt(index)).
|
||||
*
|
||||
* @param at the index of the char value. The first character is at 0.
|
||||
*
|
||||
* @throws JSONException if at does not point to a valid character.
|
||||
* @return a Unicode character between 0 and 0x10FFFF.
|
||||
* @throws JSONException if at does not point to a valid character.
|
||||
*/
|
||||
public int characterAt(final int at) throws JSONException {
|
||||
final int c = get(at);
|
||||
@ -214,35 +211,33 @@ public class Kim {
|
||||
} else {
|
||||
final int c2 = get(at + 2);
|
||||
character = ((c & 0x7F) << 14) | ((c1 & 0x7F) << 7) | c2;
|
||||
if (((c2 & 0x80) == 0) && (character > 0x3FFF) && (character <= 0x10FFFF) && ((character < 0xD800) || (character > 0xDFFF))) {
|
||||
if (((c2 & 0x80) == 0) && (character > 0x3FFF) && (character <= 0x10FFFF) && (
|
||||
(character < 0xD800) || (character > 0xDFFF))) {
|
||||
return character;
|
||||
}
|
||||
}
|
||||
throw new JSONException("Bad character at " + at);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy the contents of this kim to a byte array.
|
||||
*
|
||||
* @param bytes A byte array of sufficient size.
|
||||
* @param at The position within the byte array to take the byes.
|
||||
*
|
||||
* @return The position immediately after the copy.
|
||||
*/
|
||||
public int copy(final byte[] bytes, final int at) {
|
||||
System.arraycopy(this.bytes, 0, bytes, at, length);
|
||||
return at + length;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Two kim objects containing exactly the same bytes in the same order are equal to each other.
|
||||
*
|
||||
* @param obj the other kim with which to compare.
|
||||
*
|
||||
* @return true if this and obj are both kim objects containing identical byte sequences.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
@Override public boolean equals(final Object obj) {
|
||||
if (!(obj instanceof Kim)) {
|
||||
return false;
|
||||
}
|
||||
@ -255,14 +250,12 @@ public class Kim {
|
||||
}
|
||||
return java.util.Arrays.equals(bytes, that.bytes);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a byte from a kim.
|
||||
*
|
||||
* @param at The position of the byte. The first byte is at 0.
|
||||
*
|
||||
* @return The byte.
|
||||
*
|
||||
* @throws JSONException if there is no byte at that position.
|
||||
*/
|
||||
public int get(final int at) throws JSONException {
|
||||
@ -271,25 +264,22 @@ public class Kim {
|
||||
}
|
||||
return (bytes[at]) & 0xFF;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a hash code value for the kim.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
@Override public int hashCode() {
|
||||
return hashcode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Produce a UTF-16 String from this kim. The number of codepoints in the string will not be greater than the number
|
||||
* of bytes in the kim, although it could be less.
|
||||
*
|
||||
* @return The string. A kim memoizes its string representation.
|
||||
*
|
||||
* @throws JSONException if the kim is not valid.
|
||||
*/
|
||||
@Override
|
||||
public String toString() throws JSONException {
|
||||
@Override public String toString() throws JSONException {
|
||||
if (string == null) {
|
||||
int c;
|
||||
int length = 0;
|
||||
|
@ -15,12 +15,11 @@ public class Property {
|
||||
* Converts a property file object into a JSONObject. The property file object is a table of name value pairs.
|
||||
*
|
||||
* @param properties java.util.Properties
|
||||
*
|
||||
* @return JSONObject
|
||||
*
|
||||
* @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();
|
||||
if ((properties != null) && !properties.isEmpty()) {
|
||||
final Enumeration enumProperties = properties.propertyNames();
|
||||
@ -31,14 +30,12 @@ public class Property {
|
||||
}
|
||||
return jo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts the JSONObject into a property file object.
|
||||
*
|
||||
* @param jo JSONObject
|
||||
*
|
||||
* @return java.util.Properties
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static Properties toProperties(final JSONObject jo) throws JSONException {
|
||||
|
@ -46,12 +46,11 @@ class XML {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throw an exception if the string contains whitespace. Whitespace is not allowed in tagNames and attributes.
|
||||
*
|
||||
* @param string A string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
static void noSpace(String string) throws JSONException {
|
||||
@ -65,19 +64,18 @@ class XML {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scan the content following the named tag, attaching it to the context.
|
||||
*
|
||||
* @param x The XMLTokener containing the source string.
|
||||
* @param context The JSONObject that will include the new material.
|
||||
* @param name The tag name.
|
||||
*
|
||||
* @return true if the close tag is processed.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
private static boolean parse(XMLTokener x, JSONObject context, String name) throws JSONException {
|
||||
private static boolean parse(XMLTokener x, JSONObject context, String name)
|
||||
throws JSONException {
|
||||
// Test for and skip past these forms:
|
||||
// <!-- ... -->
|
||||
// <! ... >
|
||||
@ -147,7 +145,7 @@ class XML {
|
||||
String tagName = (String) token;
|
||||
token = null;
|
||||
JSONObject jsonobject = new JSONObject();
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
if (token == null) {
|
||||
token = x.nextToken();
|
||||
}
|
||||
@ -178,7 +176,7 @@ class XML {
|
||||
return false;
|
||||
// Content, between <...> and </...>
|
||||
} else if (token == GT) {
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
token = x.nextContent();
|
||||
if (token == null) {
|
||||
if (tagName != null) {
|
||||
@ -195,7 +193,8 @@ class XML {
|
||||
if (parse(x, jsonobject, tagName)) {
|
||||
if (jsonobject.length() == 0) {
|
||||
context.accumulate(tagName, "");
|
||||
} else if ((jsonobject.length() == 1) && (jsonobject.opt("content") != null)) {
|
||||
} else if ((jsonobject.length() == 1) && (jsonobject.opt("content")
|
||||
!= null)) {
|
||||
context.accumulate(tagName, jsonobject.opt("content"));
|
||||
} else {
|
||||
context.accumulate(tagName, jsonobject);
|
||||
@ -210,14 +209,13 @@ class XML {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Try to convert a string into a number, boolean, or null. If the string can't be converted, return the string.
|
||||
* This is much less ambitious than JSONObject.stringToValue, especially because it does not attempt to convert plus
|
||||
* forms, octal forms, hex forms, or E forms lacking decimal points.
|
||||
*
|
||||
* @param string A String.
|
||||
*
|
||||
* @return A simple JSON value.
|
||||
*/
|
||||
static Object stringToValue(String string) {
|
||||
@ -245,7 +243,8 @@ class XML {
|
||||
if (value.toString().equals(string)) {
|
||||
return value;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {}
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
@ -258,28 +257,24 @@ class XML {
|
||||
}
|
||||
return jo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a JSONObject into a well-formed, element-normal XML string.
|
||||
*
|
||||
* @param object A JSONObject.
|
||||
*
|
||||
* @return A string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(Object object) throws JSONException {
|
||||
return toString(object, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a JSONObject into a well-formed, element-normal XML string.
|
||||
*
|
||||
* @param object A JSONObject.
|
||||
* @param tagName The optional name of the enclosing tag.
|
||||
*
|
||||
* @return A string.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(Object object, String tagName) throws JSONException {
|
||||
@ -369,8 +364,11 @@ class XML {
|
||||
return sb.toString();
|
||||
} else {
|
||||
string = escape(object.toString());
|
||||
return (tagName == null) ? '"' + string + '"' :
|
||||
string.isEmpty() ? '<' + tagName + "/>" : '<' + tagName + '>' + string + "</" + tagName + '>';
|
||||
return (tagName == null) ?
|
||||
'"' + string + '"' :
|
||||
string.isEmpty() ?
|
||||
'<' + tagName + "/>" :
|
||||
'<' + tagName + '>' + string + "</" + tagName + '>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ public class XMLTokener extends JSONTokener {
|
||||
* The table of entity values. It initially contains Character values for amp, apos, gt, lt, quot.
|
||||
*/
|
||||
public static final HashMap<String, Character> entity;
|
||||
|
||||
static {
|
||||
entity = new HashMap<>(8);
|
||||
entity.put("amp", XML.AMP);
|
||||
@ -21,7 +22,7 @@ public class XMLTokener extends JSONTokener {
|
||||
entity.put("lt", XML.LT);
|
||||
entity.put("quot", XML.QUOT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct an XMLTokener from a string.
|
||||
*
|
||||
@ -30,36 +31,35 @@ public class XMLTokener extends JSONTokener {
|
||||
public XMLTokener(final String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the text in the CDATA block.
|
||||
*
|
||||
* @return The string up to the <code>]]></code>.
|
||||
*
|
||||
* @throws JSONException If the <code>]]></code> is not found.
|
||||
*/
|
||||
public String nextCDATA() throws JSONException {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
char c = next();
|
||||
if (end()) {
|
||||
throw syntaxError("Unclosed CDATA");
|
||||
}
|
||||
sb.append(c);
|
||||
int 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);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the next XML outer token, trimming whitespace. There are two kinds of tokens: the '<' character which begins
|
||||
* a markup tag, and the content text between markup tags.
|
||||
*
|
||||
* @return A string, or a '<' Character, or null if there is no more source text.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public Object nextContent() throws JSONException {
|
||||
@ -74,7 +74,7 @@ public class XMLTokener extends JSONTokener {
|
||||
return XML.LT;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
if ((c == '<') || (c == 0)) {
|
||||
back();
|
||||
return sb.toString().trim();
|
||||
@ -87,20 +87,18 @@ public class XMLTokener extends JSONTokener {
|
||||
c = next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the next entity. These entities are translated to Characters: <code>& " > <
|
||||
* "</code>.
|
||||
*
|
||||
* @param ampersand An ampersand character.
|
||||
*
|
||||
* @return A Character or an entity String if the entity is not recognized.
|
||||
*
|
||||
* @throws JSONException If missing ';' in XML entity.
|
||||
*/
|
||||
public Object nextEntity(final char ampersand) throws JSONException {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
final char c = next();
|
||||
if (Character.isLetterOrDigit(c) || (c == '#')) {
|
||||
sb.append(Character.toLowerCase(c));
|
||||
@ -114,13 +112,12 @@ public class XMLTokener extends JSONTokener {
|
||||
final Object object = entity.get(string);
|
||||
return object != null ? object : ampersand + string + ';';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the next XML meta token. This is used for skipping over <!...> and <?...?> structures.
|
||||
*
|
||||
* @return Syntax characters (<code>< > / = ! ?</code>) are returned as Character, and strings and names are
|
||||
* returned as Boolean. We don't care what the values actually are.
|
||||
*
|
||||
* @throws JSONException If a string is not properly closed or if the XML is badly structured.
|
||||
*/
|
||||
public Object nextMeta() throws JSONException {
|
||||
@ -147,7 +144,7 @@ public class XMLTokener extends JSONTokener {
|
||||
case '"':
|
||||
case '\'':
|
||||
q = c;
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
c = next();
|
||||
if (c == 0) {
|
||||
throw syntaxError("Unterminated string");
|
||||
@ -157,7 +154,7 @@ public class XMLTokener extends JSONTokener {
|
||||
}
|
||||
}
|
||||
default:
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
c = next();
|
||||
if (Character.isWhitespace(c)) {
|
||||
return Boolean.TRUE;
|
||||
@ -178,13 +175,12 @@ public class XMLTokener extends JSONTokener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the next XML Token. These tokens are found inside of angle brackets. It may be one of these characters:
|
||||
* <code>/ >= ! ?</code> or it may be a string wrapped in single quotes or double quotes, or it may be a name.
|
||||
*
|
||||
* @return a String or a Character.
|
||||
*
|
||||
* @throws JSONException If the XML is not well formed.
|
||||
*/
|
||||
public Object nextToken() throws JSONException {
|
||||
@ -209,12 +205,12 @@ public class XMLTokener extends JSONTokener {
|
||||
return XML.BANG;
|
||||
case '?':
|
||||
return XML.QUEST;
|
||||
// Quoted string
|
||||
// Quoted string
|
||||
case '"':
|
||||
case '\'':
|
||||
q = c;
|
||||
sb = new StringBuilder();
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
c = next();
|
||||
if (c == 0) {
|
||||
throw syntaxError("Unterminated string");
|
||||
@ -231,7 +227,7 @@ public class XMLTokener extends JSONTokener {
|
||||
default:
|
||||
// Name
|
||||
sb = new StringBuilder();
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
sb.append(c);
|
||||
c = next();
|
||||
if (Character.isWhitespace(c)) {
|
||||
@ -257,13 +253,12 @@ public class XMLTokener extends JSONTokener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Skip characters until past the requested string. If it is not found, we are left at the end of the source with a
|
||||
* result of false.
|
||||
*
|
||||
* @param to A string to skip past.
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public boolean skipPast(final String to) throws JSONException {
|
||||
@ -283,7 +278,7 @@ public class XMLTokener extends JSONTokener {
|
||||
circle[i] = c;
|
||||
}
|
||||
/* We will loop, possibly for all of the remaining characters. */
|
||||
for (int offset = 0; ;) {
|
||||
for (int offset = 0; ; ) {
|
||||
int j = offset;
|
||||
boolean b = true;
|
||||
/* Compare the circle buffer with the to string. */
|
||||
|
@ -5,17 +5,7 @@ import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
||||
import com.intellectualcrafters.plot.logger.ILogger;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.AbstractTitle;
|
||||
import com.intellectualcrafters.plot.util.ChatManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.intellectualcrafters.plot.util.block.QueueProvider;
|
||||
|
||||
import java.io.File;
|
||||
@ -25,24 +15,28 @@ public interface IPlotMain extends ILogger {
|
||||
|
||||
/**
|
||||
* Log a message to console.
|
||||
*
|
||||
* @param message The message to log
|
||||
*/
|
||||
void log(String message);
|
||||
|
||||
/**
|
||||
* Get the `PlotSquared` directory.
|
||||
*
|
||||
* @return The plugin directory
|
||||
*/
|
||||
File getDirectory();
|
||||
|
||||
/**
|
||||
* Get the directory containing all the worlds.
|
||||
*
|
||||
* @return The directory containing the worlds
|
||||
*/
|
||||
File getWorldContainer();
|
||||
|
||||
/**
|
||||
* Wrap a player into a PlotPlayer object.
|
||||
*
|
||||
* @param player The player to convert to a PlotPlayer
|
||||
* @return A PlotPlayer
|
||||
*/
|
||||
@ -50,57 +44,65 @@ public interface IPlotMain extends ILogger {
|
||||
|
||||
/**
|
||||
* Disable the implementation.
|
||||
*
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>If a full disable isn't feasibly, just disable what it can.
|
||||
* <li>If a full disable isn't feasibly, just disable what it can.
|
||||
* </ul>
|
||||
*/
|
||||
void disable();
|
||||
|
||||
/**
|
||||
* Get the version of the PlotSquared being used.
|
||||
*
|
||||
* @return the plugin version
|
||||
*/
|
||||
int[] getPluginVersion();
|
||||
|
||||
/**
|
||||
* Get the version of the PlotSquared being used as a string.
|
||||
*
|
||||
* @return the plugin version as a string
|
||||
*/
|
||||
String getPluginVersionString();
|
||||
|
||||
/**
|
||||
* Usually PlotSquared
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getPluginName();
|
||||
|
||||
/**
|
||||
* Get the version of Minecraft that is running.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int[] getServerVersion();
|
||||
|
||||
/**
|
||||
* Get the NMS package prefix.
|
||||
*
|
||||
* @return The NMS package prefix
|
||||
*/
|
||||
String getNMSPackage();
|
||||
|
||||
/**
|
||||
* Get the schematic handler.
|
||||
*
|
||||
* @return The {@link SchematicHandler}
|
||||
*/
|
||||
SchematicHandler initSchematicHandler();
|
||||
|
||||
/**
|
||||
* Get the Chat Manager.
|
||||
*
|
||||
* @return The {@link ChatManager}
|
||||
*/
|
||||
ChatManager initChatManager();
|
||||
|
||||
/**
|
||||
* The task manager will run and manage Minecraft tasks.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
TaskManager getTaskManager();
|
||||
@ -142,42 +144,49 @@ public interface IPlotMain extends ILogger {
|
||||
|
||||
/**
|
||||
* Get the economy provider.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
EconHandler getEconomyHandler();
|
||||
|
||||
/**
|
||||
* Get the {@link com.intellectualcrafters.plot.util.block.QueueProvider} class.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
QueueProvider initBlockQueue();
|
||||
|
||||
/**
|
||||
* Get the {@link WorldUtil} class.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
WorldUtil initWorldUtil();
|
||||
|
||||
/**
|
||||
* Get the EventUtil class.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
EventUtil initEventUtil();
|
||||
|
||||
/**
|
||||
* Get the chunk manager.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
ChunkManager initChunkManager();
|
||||
|
||||
/**
|
||||
* Get the {@link SetupUtils} class.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
SetupUtils initSetupUtils();
|
||||
|
||||
/**
|
||||
* Get {@link HybridUtils} class.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
HybridUtils initHybridUtils();
|
||||
@ -189,6 +198,7 @@ public interface IPlotMain extends ILogger {
|
||||
|
||||
/**
|
||||
* If a world is already loaded, set the generator (use NMS if required).
|
||||
*
|
||||
* @param world The world to set the generator
|
||||
*/
|
||||
void setGenerator(String world);
|
||||
@ -196,6 +206,7 @@ public interface IPlotMain extends ILogger {
|
||||
/**
|
||||
* Get the {@link UUIDHandlerImplementation} which will cache and
|
||||
* provide UUIDs.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
UUIDHandlerImplementation initUUIDHandler();
|
||||
@ -203,6 +214,7 @@ public interface IPlotMain extends ILogger {
|
||||
/**
|
||||
* Get the {@link InventoryUtil} class (used for implementation specific
|
||||
* inventory guis).
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
InventoryUtil initInventoryUtil();
|
||||
@ -210,18 +222,21 @@ public interface IPlotMain extends ILogger {
|
||||
/**
|
||||
* Run the converter for the implementation (not necessarily PlotMe, just
|
||||
* any plugin that we can convert from).
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean initPlotMeConverter();
|
||||
|
||||
/**
|
||||
* Unregister a PlotPlayer from cache e.g. if they have logged off.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
void unregister(PlotPlayer player);
|
||||
|
||||
/**
|
||||
* Get the generator wrapper for a world (world) and generator (name).
|
||||
*
|
||||
* @param world
|
||||
* @param name
|
||||
* @return
|
||||
@ -244,12 +259,14 @@ public interface IPlotMain extends ILogger {
|
||||
|
||||
/**
|
||||
* Usually HybridGen
|
||||
*
|
||||
* @return Default implementation generator
|
||||
*/
|
||||
IndependentPlotGenerator getDefaultGenerator();
|
||||
|
||||
/**
|
||||
* Get the class that will manage player titles.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
AbstractTitle initTitleManager();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,6 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
public enum Platform {
|
||||
Bukkit,
|
||||
Sponge,
|
||||
Spigot,
|
||||
Cauldron
|
||||
Bukkit, Sponge, Spigot, Cauldron
|
||||
|
||||
}
|
||||
|
@ -11,15 +11,6 @@ public class PlotVersion {
|
||||
this.build = build;
|
||||
}
|
||||
|
||||
public static PlotVersion tryParse(String version) {
|
||||
try {
|
||||
return new PlotVersion(version);
|
||||
} catch (Exception ignore) {
|
||||
ignore.printStackTrace();
|
||||
return new PlotVersion(0, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public PlotVersion(String version) {
|
||||
String[] split = version.substring(version.indexOf('=') + 1).split("-");
|
||||
if (split[0].equals("unknown")) {
|
||||
@ -30,7 +21,7 @@ public class PlotVersion {
|
||||
this.year = Integer.parseInt(date[0]);
|
||||
this.month = Integer.parseInt(date[1]);
|
||||
this.day = Integer.parseInt(date[2]);
|
||||
if(split[1].equals("SNAPSHOT")) { // fallback when compiling with Maven
|
||||
if (split[1].equals("SNAPSHOT")) { // fallback when compiling with Maven
|
||||
this.hash = 0;
|
||||
this.build = 0;
|
||||
} else {
|
||||
@ -39,12 +30,21 @@ public class PlotVersion {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(hash == 0 && build == 0) {
|
||||
public static PlotVersion tryParse(String version) {
|
||||
try {
|
||||
return new PlotVersion(version);
|
||||
} catch (Exception ignore) {
|
||||
ignore.printStackTrace();
|
||||
return new PlotVersion(0, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
if (hash == 0 && build == 0) {
|
||||
return "PlotSquared-" + year + "." + month + "." + day + "-SNAPSHOT";
|
||||
} else {
|
||||
return "PlotSquared-" + year + "." + month + "." + day + "-" + Integer.toHexString(hash) + "-" + build;
|
||||
return "PlotSquared-" + year + "." + month + "." + day + "-" + Integer.toHexString(hash)
|
||||
+ "-" + build;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -16,7 +17,9 @@ public class Updater {
|
||||
|
||||
public String getChanges() {
|
||||
if (changes == null) {
|
||||
try (Scanner scanner = new Scanner(new URL("http://empcraft.com/plots/cl?" + Integer.toHexString(PS.get().getVersion().hash)).openStream(), "UTF-8")) {
|
||||
try (Scanner scanner = new Scanner(new URL(
|
||||
"http://empcraft.com/plots/cl?" + Integer.toHexString(PS.get().getVersion().hash))
|
||||
.openStream(), "UTF-8")) {
|
||||
changes = scanner.useDelimiter("\\A").next();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -35,7 +38,8 @@ public class Updater {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String downloadUrl = "https://ci.athion.net/job/PlotSquared/lastSuccessfulBuild/artifact/target/PlotSquared-%platform%-%version%.jar";
|
||||
String downloadUrl =
|
||||
"https://ci.athion.net/job/PlotSquared/lastSuccessfulBuild/artifact/target/PlotSquared-%platform%-%version%.jar";
|
||||
String versionUrl = "http://empcraft.com/plots/version.php?%platform%";
|
||||
URL url = new URL(versionUrl.replace("%platform%", platform));
|
||||
try (Scanner reader = new Scanner(url.openStream())) {
|
||||
@ -43,12 +47,15 @@ public class Updater {
|
||||
PlotVersion version = new PlotVersion(versionString);
|
||||
if (version.isNewer(newVersion != null ? newVersion : currentVersion)) {
|
||||
newVersion = version;
|
||||
URL download = new URL(downloadUrl.replaceAll("%platform%", platform).replaceAll("%version%", versionString));
|
||||
URL download = new URL(downloadUrl.replaceAll("%platform%", platform)
|
||||
.replaceAll("%version%", versionString));
|
||||
try (ReadableByteChannel rbc = Channels.newChannel(download.openStream())) {
|
||||
File jarFile = PS.get().getJarFile();
|
||||
|
||||
File finalFile = new File(jarFile.getParent(), "update" + File.separator + jarFile.getName());
|
||||
File outFile = new File(jarFile.getParent(), "update" + File.separator + jarFile.getName().replace(".jar", ".part"));
|
||||
File finalFile = new File(jarFile.getParent(),
|
||||
"update" + File.separator + jarFile.getName());
|
||||
File outFile = new File(jarFile.getParent(),
|
||||
"update" + File.separator + jarFile.getName().replace(".jar", ".part"));
|
||||
boolean exists = outFile.exists();
|
||||
if (exists) {
|
||||
outFile.delete();
|
||||
@ -63,11 +70,14 @@ public class Updater {
|
||||
}
|
||||
outFile.renameTo(finalFile);
|
||||
PS.debug("Updated PlotSquared to " + versionString);
|
||||
MainUtil.sendAdmin("&7Restart to update PlotSquared with these changes: &c/plot changelog &7or&c " + "http://empcraft.com/plots/cl?" + Integer.toHexString(currentVersion.hash));
|
||||
MainUtil.sendAdmin(
|
||||
"&7Restart to update PlotSquared with these changes: &c/plot changelog &7or&c "
|
||||
+ "http://empcraft.com/plots/cl?" + Integer
|
||||
.toHexString(currentVersion.hash));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,24 +16,20 @@ import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "add",
|
||||
description = "Allow a user to build while you are online",
|
||||
usage = "/plot add <player>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
permission = "plots.add",
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "add", description = "Allow a user to build while you are online", usage = "/plot add <player>", category = CommandCategory.SETTINGS, permission = "plots.add", requiredType = RequiredType.NONE)
|
||||
public class Add extends Command {
|
||||
|
||||
public Add() {
|
||||
super(MainCommand.getInstance(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
@Override public void execute(final PlotPlayer player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
final Plot plot = check(player.getCurrentPlot(), C.NOT_IN_PLOT);
|
||||
checkTrue(plot.hasOwner(), C.PLOT_UNOWNED);
|
||||
checkTrue(plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_TRUST), C.NO_PLOT_PERMS);
|
||||
checkTrue(plot.isOwner(player.getUUID()) || Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_TRUST), C.NO_PLOT_PERMS);
|
||||
checkTrue(args.length == 1, C.COMMAND_SYNTAX, getUsage());
|
||||
final Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
|
||||
checkTrue(!uuids.isEmpty(), C.INVALID_PLAYER, args[0]);
|
||||
@ -41,7 +37,9 @@ public class Add extends Command {
|
||||
int size = plot.getTrusted().size() + plot.getMembers().size();
|
||||
while (iter.hasNext()) {
|
||||
UUID uuid = iter.next();
|
||||
if (uuid == DBFunc.everyone && !(Permissions.hasPermission(player, C.PERMISSION_TRUST_EVERYONE) || Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
||||
if (uuid == DBFunc.everyone && !(
|
||||
Permissions.hasPermission(player, C.PERMISSION_TRUST_EVERYONE) || Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
||||
MainUtil.sendMessage(player, C.INVALID_PLAYER, MainUtil.getName(uuid));
|
||||
iter.remove();
|
||||
continue;
|
||||
@ -59,7 +57,8 @@ public class Add extends Command {
|
||||
size += plot.getTrusted().contains(uuid) ? 0 : 1;
|
||||
}
|
||||
checkTrue(!uuids.isEmpty(), null);
|
||||
checkTrue(size <= plot.getArea().MAX_PLOT_MEMBERS || Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_TRUST), C.PLOT_MAX_MEMBERS);
|
||||
checkTrue(size <= plot.getArea().MAX_PLOT_MEMBERS || Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_TRUST), C.PLOT_MAX_MEMBERS);
|
||||
confirm.run(this, new Runnable() {
|
||||
@Override // Success
|
||||
public void run() {
|
||||
@ -78,4 +77,4 @@ public class Add extends Command {
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,70 +12,65 @@ import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "setalias",
|
||||
permission = "plots.alias",
|
||||
description = "Set the plot name",
|
||||
usage = "/plot alias <set|remove> <alias>",
|
||||
aliases = {"alias", "sa", "name", "rename", "setname", "seta", "nameplot"},
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "setalias", permission = "plots.alias", description = "Set the plot name", usage = "/plot alias <set|remove> <alias>", aliases = {
|
||||
"alias", "sa", "name", "rename", "setname", "seta",
|
||||
"nameplot"}, category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE)
|
||||
public class Alias extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
|
||||
if (args.length == 0) {
|
||||
C.COMMAND_SYNTAX.send(player, "/plot alias <set|remove> <value>");
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
|
||||
if (args.length == 0) {
|
||||
C.COMMAND_SYNTAX.send(player, "/plot alias <set|remove> <value>");
|
||||
return false;
|
||||
}
|
||||
|
||||
Location loc = player.getLocation();
|
||||
|
||||
Location loc = player.getLocation();
|
||||
Plot plot = loc.getPlotAbs();
|
||||
if (plot == null) {
|
||||
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
|
||||
|
||||
if (!plot.hasOwner()) {
|
||||
sendMessage(player, C.PLOT_NOT_CLAIMED);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!plot.isOwner(player.getUUID())) {
|
||||
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
boolean result = false;
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "set":
|
||||
if (args.length != 2) {
|
||||
C.COMMAND_SYNTAX.send(player, "/plot alias <set> <value>");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(canExecuteCommand(player, C.PERMISSION_ALIAS_SET, false) || canExecuteCommand(player, C.PERMISSION_ALIAS_SET_OBSOLETE, false)) {
|
||||
result = setAlias(player, plot, args[1]);
|
||||
} else {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION);
|
||||
}
|
||||
|
||||
break;
|
||||
case "remove":
|
||||
if(canExecuteCommand(player, C.PERMISSION_ALIAS_REMOVE, true)) {
|
||||
result = removeAlias(player, plot);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
C.COMMAND_SYNTAX.send(player, "/plot alias <set|remove> <alias>");
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "set":
|
||||
if (args.length != 2) {
|
||||
C.COMMAND_SYNTAX.send(player, "/plot alias <set> <value>");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (canExecuteCommand(player, C.PERMISSION_ALIAS_SET, false) || canExecuteCommand(
|
||||
player, C.PERMISSION_ALIAS_SET_OBSOLETE, false)) {
|
||||
result = setAlias(player, plot, args[1]);
|
||||
} else {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION);
|
||||
}
|
||||
|
||||
break;
|
||||
case "remove":
|
||||
if (canExecuteCommand(player, C.PERMISSION_ALIAS_REMOVE, true)) {
|
||||
result = removeAlias(player, plot);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
C.COMMAND_SYNTAX.send(player, "/plot alias <set|remove> <alias>");
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private boolean setAlias(PlotPlayer player, Plot plot, String alias) {
|
||||
if (alias.isEmpty()) {
|
||||
C.COMMAND_SYNTAX.send(player, "/plot alias <set> <value>");
|
||||
@ -107,20 +102,20 @@ public class Alias extends SubCommand {
|
||||
MainUtil.sendMessage(player, C.ALIAS_SET_TO.s().replaceAll("%alias%", alias));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private boolean removeAlias(PlotPlayer player, Plot plot) {
|
||||
plot.setAlias(null);
|
||||
MainUtil.sendMessage(player, C.ALIAS_REMOVED.s());
|
||||
return true;
|
||||
plot.setAlias(null);
|
||||
MainUtil.sendMessage(player, C.ALIAS_REMOVED.s());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private boolean canExecuteCommand(PlotPlayer player, C caption, boolean sendMessage) {
|
||||
if (!Permissions.hasPermission(player, caption)) {
|
||||
if(sendMessage) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if (!Permissions.hasPermission(player, caption)) {
|
||||
if (sendMessage) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -6,42 +6,19 @@ import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Configuration;
|
||||
import com.intellectualcrafters.plot.generator.AugmentedUtils;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotMessage;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal3;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@CommandDeclaration(command = "area",
|
||||
permission = "plots.area",
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.NONE,
|
||||
description = "Create a new PlotArea",
|
||||
aliases = "world",
|
||||
usage = "/plot area <create|info|list|tp|regen>",
|
||||
confirmation = true)
|
||||
@CommandDeclaration(command = "area", permission = "plots.area", category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.NONE, description = "Create a new PlotArea", aliases = "world", usage = "/plot area <create|info|list|tp|regen>", confirmation = true)
|
||||
public class Area extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
if (args.length == 0) {
|
||||
C.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return false;
|
||||
@ -56,48 +33,58 @@ public class Area extends SubCommand {
|
||||
}
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
C.COMMAND_SYNTAX.send(player, "/plot area create [world[:id]] [<modifier>=<value>]...");
|
||||
C.COMMAND_SYNTAX
|
||||
.send(player, "/plot area create [world[:id]] [<modifier>=<value>]...");
|
||||
return false;
|
||||
case 2:
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "pos1": { // Set position 1
|
||||
HybridPlotWorld area = player.getMeta("area_create_area");
|
||||
if (area == null) {
|
||||
C.COMMAND_SYNTAX.send(player, "/plot area create [world[:id]] [<modifier>=<value>]...");
|
||||
C.COMMAND_SYNTAX.send(player,
|
||||
"/plot area create [world[:id]] [<modifier>=<value>]...");
|
||||
return false;
|
||||
}
|
||||
Location location = player.getLocation();
|
||||
player.setMeta("area_pos1", location);
|
||||
C.SET_ATTRIBUTE.send(player, "area_pos1", location.getX() + "," + location.getZ());
|
||||
MainUtil.sendMessage(player, "You will now set pos2: /plot area create pos2"
|
||||
C.SET_ATTRIBUTE.send(player, "area_pos1",
|
||||
location.getX() + "," + location.getZ());
|
||||
MainUtil.sendMessage(player,
|
||||
"You will now set pos2: /plot area create pos2"
|
||||
+ "\nNote: The chosen plot size may result in the created area not exactly matching your second position.");
|
||||
return true;
|
||||
}
|
||||
case "pos2": // Set position 2 and finish creation for type=2 (partial)
|
||||
final HybridPlotWorld area = player.getMeta("area_create_area");
|
||||
if (area == null) {
|
||||
C.COMMAND_SYNTAX.send(player, "/plot area create [world[:id]] [<modifier>=<value>]...");
|
||||
C.COMMAND_SYNTAX.send(player,
|
||||
"/plot area create [world[:id]] [<modifier>=<value>]...");
|
||||
return false;
|
||||
}
|
||||
Location pos1 = player.getLocation();
|
||||
Location pos2 = player.getMeta("area_pos1");
|
||||
int dx = Math.abs(pos1.getX() - pos2.getX());
|
||||
int dz = Math.abs(pos1.getZ() - pos2.getZ());
|
||||
int numX = Math.max(1, (dx + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE);
|
||||
int numZ = Math.max(1, (dz + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE);
|
||||
int numX = Math.max(1,
|
||||
(dx + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE);
|
||||
int numZ = Math.max(1,
|
||||
(dz + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE);
|
||||
int ddx = dx - (numX * area.SIZE - area.ROAD_WIDTH);
|
||||
int ddz = dz - (numZ * area.SIZE - area.ROAD_WIDTH);
|
||||
int bx = Math.min(pos1.getX(), pos2.getX()) + ddx;
|
||||
int bz = Math.min(pos1.getZ(), pos2.getZ()) + ddz;
|
||||
int tx = Math.max(pos1.getX(), pos2.getX()) - ddx;
|
||||
int tz = Math.max(pos1.getZ(), pos2.getZ()) - ddz;
|
||||
int lower = (area.ROAD_WIDTH & 1) == 0 ? area.ROAD_WIDTH / 2 - 1 : area.ROAD_WIDTH / 2;
|
||||
int lower = (area.ROAD_WIDTH & 1) == 0 ?
|
||||
area.ROAD_WIDTH / 2 - 1 :
|
||||
area.ROAD_WIDTH / 2;
|
||||
final int offsetX = bx - (area.ROAD_WIDTH == 0 ? 0 : lower);
|
||||
final int offsetZ = bz - (area.ROAD_WIDTH == 0 ? 0 : lower);
|
||||
final RegionWrapper region = new RegionWrapper(bx, tx, bz, tz);
|
||||
Set<PlotArea> areas = PS.get().getPlotAreas(area.worldname, region);
|
||||
if (!areas.isEmpty()) {
|
||||
C.CLUSTER_INTERSECTION.send(player, areas.iterator().next().toString());
|
||||
C.CLUSTER_INTERSECTION
|
||||
.send(player, areas.iterator().next().toString());
|
||||
return false;
|
||||
}
|
||||
final SetupObject object = new SetupObject();
|
||||
@ -110,10 +97,11 @@ public class Area extends SubCommand {
|
||||
object.plotManager = PS.imp().getPluginName();
|
||||
object.setupGenerator = PS.imp().getPluginName();
|
||||
object.step = area.getSettingNodes();
|
||||
final String path = "worlds." + area.worldname + ".areas." + area.id + '-' + object.min + '-' + object.max;
|
||||
final String path =
|
||||
"worlds." + area.worldname + ".areas." + area.id + '-'
|
||||
+ object.min + '-' + object.max;
|
||||
Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
if (offsetX != 0) {
|
||||
PS.get().worlds.set(path + ".road.offset.x", offsetX);
|
||||
}
|
||||
@ -126,20 +114,25 @@ public class Area extends SubCommand {
|
||||
C.SETUP_FINISHED.send(player);
|
||||
player.teleport(WorldUtil.IMP.getSpawn(world));
|
||||
if (area.TERRAIN != 3) {
|
||||
ChunkManager.largeRegionTask(world, region, new RunnableVal<ChunkLoc>() {
|
||||
@Override
|
||||
public void run(ChunkLoc value) {
|
||||
AugmentedUtils.generate(world, value.x, value.z, null);
|
||||
}
|
||||
}, null);
|
||||
ChunkManager.largeRegionTask(world, region,
|
||||
new RunnableVal<ChunkLoc>() {
|
||||
@Override public void run(ChunkLoc value) {
|
||||
AugmentedUtils
|
||||
.generate(world, value.x, value.z,
|
||||
null);
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
} else {
|
||||
MainUtil.sendMessage(player, "An error occurred while creating the world: " + area.worldname);
|
||||
MainUtil.sendMessage(player,
|
||||
"An error occurred while creating the world: "
|
||||
+ area.worldname);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (hasConfirmation(player)) {
|
||||
CmdConfirm.addPending(player, getCommandString() + " create pos2 (Creates world)", run);
|
||||
CmdConfirm.addPending(player,
|
||||
getCommandString() + " create pos2 (Creates world)", run);
|
||||
} else {
|
||||
run.run();
|
||||
}
|
||||
@ -155,7 +148,8 @@ public class Area extends SubCommand {
|
||||
id = null;
|
||||
}
|
||||
object.world = split[0];
|
||||
final HybridPlotWorld pa = new HybridPlotWorld(object.world, id, PS.get().IMP.getDefaultGenerator(), null, null);
|
||||
final HybridPlotWorld pa = new HybridPlotWorld(object.world, id,
|
||||
PS.get().IMP.getDefaultGenerator(), null, null);
|
||||
PlotArea other = PS.get().getPlotArea(pa.worldname, id);
|
||||
if (other != null && Objects.equals(pa.id, other.id)) {
|
||||
C.SETUP_WORLD_TAKEN.send(player, pa.toString());
|
||||
@ -170,7 +164,8 @@ public class Area extends SubCommand {
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
String[] pair = args[i].split("=");
|
||||
if (pair.length != 2) {
|
||||
C.COMMAND_SYNTAX.send(player, getCommandString() + " create [world[:id]] [<modifier>=<value>]...");
|
||||
C.COMMAND_SYNTAX.send(player, getCommandString()
|
||||
+ " create [world[:id]] [<modifier>=<value>]...");
|
||||
return false;
|
||||
}
|
||||
switch (pair[0].toLowerCase()) {
|
||||
@ -216,7 +211,8 @@ public class Area extends SubCommand {
|
||||
object.type = pa.TYPE;
|
||||
break;
|
||||
default:
|
||||
C.COMMAND_SYNTAX.send(player, getCommandString() + " create [world[:id]] [<modifier>=<value>]...");
|
||||
C.COMMAND_SYNTAX.send(player, getCommandString()
|
||||
+ " create [world[:id]] [<modifier>=<value>]...");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -226,13 +222,13 @@ public class Area extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
String path = "worlds." + pa.worldname;
|
||||
if (!PS.get().worlds.contains(path)) {
|
||||
PS.get().worlds.createSection(path);
|
||||
}
|
||||
ConfigurationSection section = PS.get().worlds.getConfigurationSection(path);
|
||||
ConfigurationSection section =
|
||||
PS.get().worlds.getConfigurationSection(path);
|
||||
pa.saveConfiguration(section);
|
||||
pa.loadConfiguration(section);
|
||||
object.plotManager = PS.imp().getPluginName();
|
||||
@ -242,7 +238,9 @@ public class Area extends SubCommand {
|
||||
C.SETUP_FINISHED.send(player);
|
||||
player.teleport(WorldUtil.IMP.getSpawn(world));
|
||||
} else {
|
||||
MainUtil.sendMessage(player, "An error occurred while creating the world: " + pa.worldname);
|
||||
MainUtil.sendMessage(player,
|
||||
"An error occurred while creating the world: "
|
||||
+ pa.worldname);
|
||||
}
|
||||
try {
|
||||
PS.get().worlds.save(PS.get().worldsFile);
|
||||
@ -252,14 +250,16 @@ public class Area extends SubCommand {
|
||||
}
|
||||
};
|
||||
if (hasConfirmation(player)) {
|
||||
CmdConfirm.addPending(player, getCommandString() + ' ' + StringMan.join(args, " "), run);
|
||||
CmdConfirm.addPending(player,
|
||||
getCommandString() + ' ' + StringMan.join(args, " "), run);
|
||||
} else {
|
||||
run.run();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (pa.id == null) {
|
||||
C.COMMAND_SYNTAX.send(player, getCommandString() + " create [world[:id]] [<modifier>=<value>]...");
|
||||
C.COMMAND_SYNTAX.send(player, getCommandString()
|
||||
+ " create [world[:id]] [<modifier>=<value>]...");
|
||||
return false;
|
||||
}
|
||||
if (WorldUtil.IMP.isWorld(pa.worldname)) {
|
||||
@ -273,7 +273,9 @@ public class Area extends SubCommand {
|
||||
player.teleport(WorldUtil.IMP.getSpawn(pa.worldname));
|
||||
}
|
||||
player.setMeta("area_create_area", pa);
|
||||
MainUtil.sendMessage(player, "$1Go to the first corner and use: $2 " + getCommandString() + " create pos1");
|
||||
MainUtil.sendMessage(player,
|
||||
"$1Go to the first corner and use: $2 " + getCommandString()
|
||||
+ " create pos1");
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
@ -321,15 +323,12 @@ public class Area extends SubCommand {
|
||||
percent = claimed == 0 ? 0 : 100d * claimed / Integer.MAX_VALUE;
|
||||
region = "N/A";
|
||||
}
|
||||
String value = "&r$1NAME: " + name
|
||||
+ "\n$1Type: $2" + area.TYPE
|
||||
+ "\n$1Terrain: $2" + area.TERRAIN
|
||||
+ "\n$1Usage: $2" + String.format("%.2f", percent) + '%'
|
||||
+ "\n$1Claimed: $2" + claimed
|
||||
+ "\n$1Clusters: $2" + clusters
|
||||
+ "\n$1Region: $2" + region
|
||||
+ "\n$1Generator: $2" + generator;
|
||||
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER.s() + '\n' + value + '\n' + C.PLOT_INFO_FOOTER.s(), false);
|
||||
String value = "&r$1NAME: " + name + "\n$1Type: $2" + area.TYPE + "\n$1Terrain: $2"
|
||||
+ area.TERRAIN + "\n$1Usage: $2" + String.format("%.2f", percent) + '%'
|
||||
+ "\n$1Claimed: $2" + claimed + "\n$1Clusters: $2" + clusters + "\n$1Region: $2"
|
||||
+ region + "\n$1Generator: $2" + generator;
|
||||
MainUtil.sendMessage(player,
|
||||
C.PLOT_INFO_HEADER.s() + '\n' + value + '\n' + C.PLOT_INFO_FOOTER.s(), false);
|
||||
return true;
|
||||
}
|
||||
case "l":
|
||||
@ -353,44 +352,45 @@ public class Area extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
ArrayList<PlotArea> areas = new ArrayList<>(PS.get().getPlotAreas());
|
||||
paginate(player, areas, 8, page, new RunnableVal3<Integer, PlotArea, PlotMessage>() {
|
||||
@Override
|
||||
public void run(Integer i, PlotArea area, PlotMessage message) {
|
||||
String name;
|
||||
double percent;
|
||||
int claimed = area.getPlotCount();
|
||||
int clusters = area.getClusters().size();
|
||||
String region;
|
||||
String generator = String.valueOf(area.getGenerator());
|
||||
if (area.TYPE == 2) {
|
||||
PlotId min = area.getMin();
|
||||
PlotId max = area.getMax();
|
||||
name = area.worldname + ';' + area.id + ';' + min + ';' + max;
|
||||
int size = (max.x - min.x + 1) * (max.y - min.y + 1);
|
||||
percent = claimed == 0 ? 0 : size / (double) claimed;
|
||||
region = area.getRegion().toString();
|
||||
} else {
|
||||
name = area.worldname;
|
||||
percent = claimed == 0 ? 0 : Short.MAX_VALUE * Short.MAX_VALUE / (double) claimed;
|
||||
region = "N/A";
|
||||
}
|
||||
PlotMessage tooltip = new PlotMessage()
|
||||
.text("Claimed=").color("$1").text(String.valueOf(claimed)).color("$2")
|
||||
.text("\nUsage=").color("$1").text(String.format("%.2f", percent) + '%').color("$2")
|
||||
.text("\nClusters=").color("$1").text(String.valueOf(clusters)).color("$2")
|
||||
.text("\nRegion=").color("$1").text(region).color("$2")
|
||||
paginate(player, areas, 8, page,
|
||||
new RunnableVal3<Integer, PlotArea, PlotMessage>() {
|
||||
@Override public void run(Integer i, PlotArea area, PlotMessage message) {
|
||||
String name;
|
||||
double percent;
|
||||
int claimed = area.getPlotCount();
|
||||
int clusters = area.getClusters().size();
|
||||
String region;
|
||||
String generator = String.valueOf(area.getGenerator());
|
||||
if (area.TYPE == 2) {
|
||||
PlotId min = area.getMin();
|
||||
PlotId max = area.getMax();
|
||||
name = area.worldname + ';' + area.id + ';' + min + ';' + max;
|
||||
int size = (max.x - min.x + 1) * (max.y - min.y + 1);
|
||||
percent = claimed == 0 ? 0 : size / (double) claimed;
|
||||
region = area.getRegion().toString();
|
||||
} else {
|
||||
name = area.worldname;
|
||||
percent = claimed == 0 ?
|
||||
0 :
|
||||
Short.MAX_VALUE * Short.MAX_VALUE / (double) claimed;
|
||||
region = "N/A";
|
||||
}
|
||||
PlotMessage tooltip = new PlotMessage().text("Claimed=").color("$1")
|
||||
.text(String.valueOf(claimed)).color("$2").text("\nUsage=")
|
||||
.color("$1").text(String.format("%.2f", percent) + '%').color("$2")
|
||||
.text("\nClusters=").color("$1").text(String.valueOf(clusters))
|
||||
.color("$2").text("\nRegion=").color("$1").text(region).color("$2")
|
||||
.text("\nGenerator=").color("$1").text(generator).color("$2");
|
||||
|
||||
// type / terrain
|
||||
String visit = "/plot area tp " + area.toString();
|
||||
message.text("[").color("$3")
|
||||
.text(String.valueOf(i)).command(visit).tooltip(visit).color("$1")
|
||||
.text("]").color("$3")
|
||||
.text(' ' + name).tooltip(tooltip).command(getCommandString() + " info " + area).color("$1").text(" - ")
|
||||
.color("$2")
|
||||
// type / terrain
|
||||
String visit = "/plot area tp " + area.toString();
|
||||
message.text("[").color("$3").text(String.valueOf(i)).command(visit)
|
||||
.tooltip(visit).color("$1").text("]").color("$3").text(' ' + name)
|
||||
.tooltip(tooltip).command(getCommandString() + " info " + area)
|
||||
.color("$1").text(" - ").color("$2")
|
||||
.text(area.TYPE + ":" + area.TERRAIN).color("$3");
|
||||
}
|
||||
}, "/plot area list", C.AREA_LIST_HEADER_PAGED.s());
|
||||
}
|
||||
}, "/plot area list", C.AREA_LIST_HEADER_PAGED.s());
|
||||
return true;
|
||||
case "regen":
|
||||
case "clear":
|
||||
@ -406,20 +406,20 @@ public class Area extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (area.TYPE != 2) {
|
||||
MainUtil.sendMessage(player, "$4Stop the server and delete: " + area.worldname + "/region");
|
||||
MainUtil.sendMessage(player,
|
||||
"$4Stop the server and delete: " + area.worldname + "/region");
|
||||
return false;
|
||||
}
|
||||
ChunkManager.largeRegionTask(area.worldname, area.getRegion(), new RunnableVal<ChunkLoc>() {
|
||||
@Override
|
||||
public void run(ChunkLoc value) {
|
||||
AugmentedUtils.generate(area.worldname, value.x, value.z, null);
|
||||
}
|
||||
}, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
player.sendMessage("Regen complete");
|
||||
}
|
||||
});
|
||||
ChunkManager
|
||||
.largeRegionTask(area.worldname, area.getRegion(), new RunnableVal<ChunkLoc>() {
|
||||
@Override public void run(ChunkLoc value) {
|
||||
AugmentedUtils.generate(area.worldname, value.x, value.z, null);
|
||||
}
|
||||
}, new Runnable() {
|
||||
@Override public void run() {
|
||||
player.sendMessage("Regen complete");
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
case "goto":
|
||||
@ -445,17 +445,20 @@ public class Area extends SubCommand {
|
||||
center = WorldUtil.IMP.getSpawn(area.worldname);
|
||||
} else {
|
||||
RegionWrapper region = area.getRegion();
|
||||
center = new Location(area.worldname, region.minX + (region.maxX - region.minX) / 2, 0,
|
||||
region.minZ + (region.maxZ - region.minZ) / 2);
|
||||
center.setY(1 + WorldUtil.IMP.getHighestBlock(area.worldname, center.getX(), center.getZ()));
|
||||
center =
|
||||
new Location(area.worldname, region.minX + (region.maxX - region.minX) / 2,
|
||||
0, region.minZ + (region.maxZ - region.minZ) / 2);
|
||||
center.setY(1 + WorldUtil.IMP
|
||||
.getHighestBlock(area.worldname, center.getX(), center.getZ()));
|
||||
}
|
||||
player.teleport(center);
|
||||
return true;
|
||||
case "delete":
|
||||
case "remove":
|
||||
MainUtil.sendMessage(player, "$1World creation settings may be stored in multiple locations:"
|
||||
+ "\n$3 - $2Bukkit bukkit.yml"
|
||||
+ "\n$3 - $2" + PS.imp().getPluginName() + " settings.yml"
|
||||
MainUtil.sendMessage(player,
|
||||
"$1World creation settings may be stored in multiple locations:"
|
||||
+ "\n$3 - $2Bukkit bukkit.yml" + "\n$3 - $2" + PS.imp().getPluginName()
|
||||
+ " settings.yml"
|
||||
+ "\n$3 - $2Multiverse worlds.yml (or any world management plugin)"
|
||||
+ "\n$1Stop the server and delete it from these locations.");
|
||||
return true;
|
||||
|
@ -4,43 +4,167 @@ import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Expression;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.ByteArrayUtilities;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Set;
|
||||
|
||||
@CommandDeclaration(command = "auto",
|
||||
permission = "plots.auto",
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE,
|
||||
description = "Claim the nearest plot",
|
||||
aliases = "a",
|
||||
usage = "/plot auto [length,width]")
|
||||
@CommandDeclaration(command = "auto", permission = "plots.auto", category = CommandCategory.CLAIMING, requiredType = RequiredType.NONE, description = "Claim the nearest plot", aliases = "a", usage = "/plot auto [length,width]")
|
||||
public class Auto extends SubCommand {
|
||||
|
||||
@Deprecated
|
||||
public static PlotId getNextPlotId(PlotId id, int step) {
|
||||
@Deprecated public static PlotId getNextPlotId(PlotId id, int step) {
|
||||
return id.getNextId(step);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
private static boolean checkAllowedPlots(PlotPlayer player, PlotArea plotarea,
|
||||
@Nullable Integer allowed_plots, int size_x, int size_z) {
|
||||
if (allowed_plots == null)
|
||||
allowed_plots = player.getAllowedPlots();
|
||||
int currentPlots =
|
||||
Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(plotarea.worldname);
|
||||
int diff = currentPlots - allowed_plots;
|
||||
if (diff + size_x * size_z > 0) {
|
||||
if (diff < 0) {
|
||||
MainUtil.sendMessage(player, C.CANT_CLAIM_MORE_PLOTS_NUM, -diff + "");
|
||||
return false;
|
||||
} else if (player.hasPersistentMeta("grantedPlots")) {
|
||||
int grantedPlots =
|
||||
ByteArrayUtilities.bytesToInteger(player.getPersistentMeta("grantedPlots"));
|
||||
if (grantedPlots - diff < size_x * size_z) {
|
||||
player.removePersistentMeta("grantedPlots");
|
||||
MainUtil.sendMessage(player, C.CANT_CLAIM_MORE_PLOTS);
|
||||
return false;
|
||||
} else {
|
||||
int left = grantedPlots - diff - size_x * size_z;
|
||||
if (left == 0) {
|
||||
player.removePersistentMeta("grantedPlots");
|
||||
} else {
|
||||
player.setPersistentMeta("grantedPlots",
|
||||
ByteArrayUtilities.integerToBytes(left));
|
||||
}
|
||||
MainUtil.sendMessage(player, C.REMOVED_GRANTED_PLOT, "" + left,
|
||||
"" + (grantedPlots - left));
|
||||
}
|
||||
} else {
|
||||
MainUtil.sendMessage(player, C.CANT_CLAIM_MORE_PLOTS);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next plot id (spiral out from 0,0)
|
||||
*
|
||||
* @param start
|
||||
* @return
|
||||
*/
|
||||
@Deprecated public static PlotId getNextPlot(PlotId start) {
|
||||
int plots;
|
||||
PlotId center;
|
||||
center = new PlotId(0, 0);
|
||||
plots = Integer.MAX_VALUE;
|
||||
PlotId currentId;
|
||||
for (int i = 0; i < plots; i++) {
|
||||
if (start == null) {
|
||||
start = new PlotId(0, 0);
|
||||
} else {
|
||||
start = start.getNextId(1);
|
||||
}
|
||||
currentId = new PlotId(center.x + start.x, center.y + start.y);
|
||||
return currentId;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport the player home, or claim a new plot
|
||||
*
|
||||
* @param player
|
||||
* @param area
|
||||
* @param start
|
||||
* @param schem
|
||||
*/
|
||||
public static void homeOrAuto(final PlotPlayer player, final PlotArea area, PlotId start,
|
||||
final String schem) {
|
||||
Set<Plot> plots = player.getPlots();
|
||||
if (!plots.isEmpty()) {
|
||||
plots.iterator().next().teleportPlayer(player);
|
||||
} else {
|
||||
autoClaimSafe(player, area, start, schem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Claim a new plot for a player
|
||||
*
|
||||
* @param player
|
||||
* @param area
|
||||
* @param start
|
||||
* @param schem
|
||||
*/
|
||||
public static void autoClaimSafe(final PlotPlayer player, final PlotArea area, PlotId start,
|
||||
final String schem) {
|
||||
autoClaimSafe(player, area, start, schem, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Claim a new plot for a player
|
||||
*
|
||||
* @param player
|
||||
* @param area
|
||||
* @param start
|
||||
* @param schem
|
||||
*/
|
||||
public static void autoClaimSafe(final PlotPlayer player, final PlotArea area, PlotId start,
|
||||
final String schem, @Nullable Integer allowed_plots) {
|
||||
player.setMeta(Auto.class.getName(), true);
|
||||
autoClaimFromDatabase(player, area, start, new RunnableVal<Plot>() {
|
||||
@Override public void run(final Plot plot) {
|
||||
TaskManager.IMP.sync(new RunnableVal<Object>() {
|
||||
@Override public void run(Object ignore) {
|
||||
player.deleteMeta(Auto.class.getName());
|
||||
if (plot == null) {
|
||||
MainUtil.sendMessage(player, C.NO_FREE_PLOTS);
|
||||
} else if (checkAllowedPlots(player, area, allowed_plots, 1, 1)) {
|
||||
plot.claim(player, true, schem, false);
|
||||
if (area.AUTO_MERGE) {
|
||||
plot.autoMerge(-1, Integer.MAX_VALUE, player.getUUID(), true);
|
||||
}
|
||||
} else {
|
||||
DBFunc.delete(plot);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void autoClaimFromDatabase(final PlotPlayer player, final PlotArea area,
|
||||
PlotId start, final RunnableVal<Plot> whenDone) {
|
||||
final Plot plot = area.getNextFreePlot(player, start);
|
||||
if (plot == null) {
|
||||
whenDone.run(null);
|
||||
return;
|
||||
}
|
||||
whenDone.value = plot;
|
||||
plot.owner = player.getUUID();
|
||||
DBFunc.createPlotSafe(plot, whenDone, new Runnable() {
|
||||
@Override public void run() {
|
||||
autoClaimFromDatabase(player, area, plot.getId(), whenDone);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
PlotArea plotarea = player.getApplicablePlotArea();
|
||||
if (plotarea == null) {
|
||||
if (EconHandler.manager != null) {
|
||||
for (PlotArea area : PS.get().getPlotAreaManager().getAllPlotAreas()) {
|
||||
if (EconHandler.manager.hasPermission(area.worldname, player.getName(), "plots.auto")) {
|
||||
if (EconHandler.manager
|
||||
.hasPermission(area.worldname, player.getName(), "plots.auto")) {
|
||||
if (plotarea != null) {
|
||||
plotarea = null;
|
||||
break;
|
||||
@ -84,25 +208,32 @@ public class Auto extends SubCommand {
|
||||
}
|
||||
}
|
||||
if (size_x * size_z > Settings.Claim.MAX_AUTO_AREA) {
|
||||
MainUtil.sendMessage(player, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.Claim.MAX_AUTO_AREA + "");
|
||||
MainUtil.sendMessage(player, C.CANT_CLAIM_MORE_PLOTS_NUM,
|
||||
Settings.Claim.MAX_AUTO_AREA + "");
|
||||
return false;
|
||||
}
|
||||
final int allowed_plots = player.getAllowedPlots();
|
||||
if (player.getMeta(Auto.class.getName(), false) || !checkAllowedPlots(player, plotarea, allowed_plots, size_x, size_z)) return false;
|
||||
if (player.getMeta(Auto.class.getName(), false) || !checkAllowedPlots(player, plotarea,
|
||||
allowed_plots, size_x, size_z))
|
||||
return false;
|
||||
|
||||
if (schematic != null && !schematic.isEmpty()) {
|
||||
if (!plotarea.SCHEMATICS.contains(schematic.toLowerCase())) {
|
||||
sendMessage(player, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_CLAIM_SCHEMATIC.f(schematic)) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLAIM_SCHEMATIC.f(schematic));
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_CLAIM_SCHEMATIC.f(schematic))
|
||||
&& !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION,
|
||||
C.PERMISSION_CLAIM_SCHEMATIC.f(schematic));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (EconHandler.manager != null && plotarea.USE_ECONOMY) {
|
||||
Expression<Double> costExp = plotarea.PRICES.get("claim");
|
||||
double cost = costExp.evaluate((double) (Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(plotarea.worldname)));
|
||||
double cost = costExp.evaluate((double) (Settings.Limit.GLOBAL ?
|
||||
player.getPlotCount() :
|
||||
player.getPlotCount(plotarea.worldname)));
|
||||
cost = (size_x * size_z) * cost;
|
||||
if (cost > 0d) {
|
||||
if (EconHandler.manager.getMoney(player) < cost) {
|
||||
@ -134,7 +265,8 @@ public class Auto extends SubCommand {
|
||||
plot.claim(player, teleport, null);
|
||||
}
|
||||
}
|
||||
if (!plotarea.mergePlots(MainUtil.getPlotSelectionIds(start, end), true, true)) {
|
||||
if (!plotarea
|
||||
.mergePlots(MainUtil.getPlotSelectionIds(start, end), true, true)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
@ -144,135 +276,4 @@ public class Auto extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean checkAllowedPlots(PlotPlayer player, PlotArea plotarea, @Nullable Integer allowed_plots, int size_x, int size_z) {
|
||||
if (allowed_plots == null)
|
||||
allowed_plots = player.getAllowedPlots();
|
||||
int currentPlots = Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(plotarea.worldname);
|
||||
int diff = currentPlots - allowed_plots;
|
||||
if (diff + size_x * size_z > 0) {
|
||||
if (diff < 0) {
|
||||
MainUtil.sendMessage(player, C.CANT_CLAIM_MORE_PLOTS_NUM, -diff + "");
|
||||
return false;
|
||||
} else if (player.hasPersistentMeta("grantedPlots")) {
|
||||
int grantedPlots = ByteArrayUtilities.bytesToInteger(player.getPersistentMeta("grantedPlots"));
|
||||
if (grantedPlots - diff < size_x * size_z) {
|
||||
player.removePersistentMeta("grantedPlots");
|
||||
MainUtil.sendMessage(player, C.CANT_CLAIM_MORE_PLOTS);
|
||||
return false;
|
||||
} else {
|
||||
int left = grantedPlots - diff - size_x * size_z;
|
||||
if (left == 0) {
|
||||
player.removePersistentMeta("grantedPlots");
|
||||
} else {
|
||||
player.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(left));
|
||||
}
|
||||
MainUtil.sendMessage(player, C.REMOVED_GRANTED_PLOT, "" + left, "" + (grantedPlots - left));
|
||||
}
|
||||
} else {
|
||||
MainUtil.sendMessage(player, C.CANT_CLAIM_MORE_PLOTS);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next plot id (spiral out from 0,0)
|
||||
* @param start
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public static PlotId getNextPlot(PlotId start) {
|
||||
int plots;
|
||||
PlotId center;
|
||||
center = new PlotId(0, 0);
|
||||
plots = Integer.MAX_VALUE;
|
||||
PlotId currentId;
|
||||
for (int i = 0; i < plots; i++) {
|
||||
if (start == null) {
|
||||
start = new PlotId(0, 0);
|
||||
} else {
|
||||
start = start.getNextId(1);
|
||||
}
|
||||
currentId = new PlotId(center.x + start.x, center.y + start.y);
|
||||
return currentId;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport the player home, or claim a new plot
|
||||
* @param player
|
||||
* @param area
|
||||
* @param start
|
||||
* @param schem
|
||||
*/
|
||||
public static void homeOrAuto(final PlotPlayer player, final PlotArea area, PlotId start, final String schem) {
|
||||
Set<Plot> plots = player.getPlots();
|
||||
if (!plots.isEmpty()) {
|
||||
plots.iterator().next().teleportPlayer(player);
|
||||
} else {
|
||||
autoClaimSafe(player, area, start, schem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Claim a new plot for a player
|
||||
* @param player
|
||||
* @param area
|
||||
* @param start
|
||||
* @param schem
|
||||
*/
|
||||
public static void autoClaimSafe(final PlotPlayer player, final PlotArea area, PlotId start, final String schem) {
|
||||
autoClaimSafe(player, area, start, schem, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Claim a new plot for a player
|
||||
* @param player
|
||||
* @param area
|
||||
* @param start
|
||||
* @param schem
|
||||
*/
|
||||
public static void autoClaimSafe(final PlotPlayer player, final PlotArea area, PlotId start, final String schem, @Nullable Integer allowed_plots) {
|
||||
player.setMeta(Auto.class.getName(), true);
|
||||
autoClaimFromDatabase(player, area, start, new RunnableVal<Plot>() {
|
||||
@Override
|
||||
public void run(final Plot plot) {
|
||||
TaskManager.IMP.sync(new RunnableVal<Object>() {
|
||||
@Override
|
||||
public void run(Object ignore) {
|
||||
player.deleteMeta(Auto.class.getName());
|
||||
if (plot == null) {
|
||||
MainUtil.sendMessage(player, C.NO_FREE_PLOTS);
|
||||
} else if (checkAllowedPlots(player, area, allowed_plots, 1, 1)) {
|
||||
plot.claim(player, true, schem, false);
|
||||
if (area.AUTO_MERGE) {
|
||||
plot.autoMerge(-1, Integer.MAX_VALUE, player.getUUID(), true);
|
||||
}
|
||||
} else {
|
||||
DBFunc.delete(plot);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void autoClaimFromDatabase(final PlotPlayer player, final PlotArea area, PlotId start, final RunnableVal<Plot> whenDone) {
|
||||
final Plot plot = area.getNextFreePlot(player, start);
|
||||
if (plot == null) {
|
||||
whenDone.run(null);
|
||||
return;
|
||||
}
|
||||
whenDone.value = plot;
|
||||
plot.owner = player.getUUID();
|
||||
DBFunc.createPlotSafe(plot, whenDone, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
autoClaimFromDatabase(player, area, plot.getId(), whenDone);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,8 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(command = "bo3",
|
||||
aliases = {"bo2"},
|
||||
description = "Mark a plot as done",
|
||||
permission = "plots.bo3",
|
||||
category = CommandCategory.SCHEMATIC,
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "bo3", aliases = {
|
||||
"bo2"}, description = "Mark a plot as done", permission = "plots.bo3", category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE)
|
||||
public class BO3 extends SubCommand {
|
||||
|
||||
public void noArgs(PlotPlayer player) {
|
||||
@ -22,14 +18,14 @@ public class BO3 extends SubCommand {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot bo3 import <file>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
Location loc = player.getLocation();
|
||||
Plot plot = loc.getPlotAbs();
|
||||
if (plot == null || !plot.hasOwner()) {
|
||||
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_BO3)) {
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_BO3)) {
|
||||
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
|
@ -8,21 +8,16 @@ import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "setbiome",
|
||||
permission = "plots.set.biome",
|
||||
description = "Set the plot biome",
|
||||
usage = "/plot biome [biome]",
|
||||
aliases = {"biome", "sb", "setb", "b"},
|
||||
category = CommandCategory.APPEARANCE,
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "setbiome", permission = "plots.set.biome", description = "Set the plot biome", usage = "/plot biome [biome]", aliases = {
|
||||
"biome", "sb", "setb",
|
||||
"b"}, category = CommandCategory.APPEARANCE, requiredType = RequiredType.NONE)
|
||||
public class Biome extends SetCommand {
|
||||
|
||||
@Override
|
||||
public boolean set(final PlotPlayer player, final Plot plot, final String value) {
|
||||
@Override public boolean set(final PlotPlayer player, final Plot plot, final String value) {
|
||||
int biome = WorldUtil.IMP.getBiomeFromString(value);
|
||||
if (biome == -1) {
|
||||
String biomes = StringMan.join(WorldUtil.IMP.getBiomeList(), C.BLOCK_LIST_SEPARATER.s());
|
||||
String biomes =
|
||||
StringMan.join(WorldUtil.IMP.getBiomeList(), C.BLOCK_LIST_SEPARATER.s());
|
||||
C.NEED_BIOME.send(player);
|
||||
MainUtil.sendMessage(player, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + biomes);
|
||||
return false;
|
||||
@ -33,8 +28,7 @@ public class Biome extends SetCommand {
|
||||
}
|
||||
plot.addRunning();
|
||||
plot.setBiome(value.toUpperCase(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
plot.removeRunning();
|
||||
MainUtil.sendMessage(player, C.BIOME_SET_TO.s() + value.toLowerCase());
|
||||
}
|
||||
|
@ -15,21 +15,16 @@ import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "buy",
|
||||
description = "Buy the plot you are standing on",
|
||||
usage = "/plot buy",
|
||||
permission = "plots.buy",
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "buy", description = "Buy the plot you are standing on", usage = "/plot buy", permission = "plots.buy", category = CommandCategory.CLAIMING, requiredType = RequiredType.NONE)
|
||||
public class Buy extends Command {
|
||||
|
||||
public Buy() {
|
||||
super(MainCommand.getInstance(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
@Override public void execute(final PlotPlayer player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
check(EconHandler.manager, C.ECON_DISABLED);
|
||||
final Plot plot;
|
||||
if (args.length != 0) {
|
||||
@ -41,7 +36,8 @@ public class Buy extends Command {
|
||||
checkTrue(plot.hasOwner(), C.PLOT_UNOWNED);
|
||||
checkTrue(!plot.isOwner(player.getUUID()), C.CANNOT_BUY_OWN);
|
||||
Set<Plot> plots = plot.getConnectedPlots();
|
||||
checkTrue(player.getPlotCount() + plots.size() <= player.getAllowedPlots(), C.CANT_CLAIM_MORE_PLOTS);
|
||||
checkTrue(player.getPlotCount() + plots.size() <= player.getAllowedPlots(),
|
||||
C.CANT_CLAIM_MORE_PLOTS);
|
||||
Optional<Double> flag = plot.getFlag(Flags.PRICE);
|
||||
if (!flag.isPresent()) {
|
||||
throw new CommandException(C.NOT_FOR_SALE);
|
||||
@ -53,7 +49,8 @@ public class Buy extends Command {
|
||||
@Override // Success
|
||||
public void run() {
|
||||
C.REMOVED_BALANCE.send(player, price);
|
||||
EconHandler.manager.depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), price);
|
||||
EconHandler.manager
|
||||
.depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), price);
|
||||
PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
|
||||
if (owner != null) {
|
||||
C.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price);
|
||||
|
@ -5,31 +5,26 @@ import com.intellectualcrafters.plot.Updater;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "changelog",
|
||||
permission = "plots.admin.command.changelog",
|
||||
description = "View the changelog",
|
||||
usage = "/plot changelog",
|
||||
requiredType = RequiredType.NONE,
|
||||
aliases = {"cl"},
|
||||
category = CommandCategory.ADMINISTRATION)
|
||||
public class Changelog extends SubCommand {
|
||||
@CommandDeclaration(command = "changelog", permission = "plots.admin.command.changelog", description = "View the changelog", usage = "/plot changelog", requiredType = RequiredType.NONE, aliases = {
|
||||
"cl"}, category = CommandCategory.ADMINISTRATION) public class Changelog extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
try {
|
||||
Updater updater = PS.get().getUpdater();
|
||||
String changes = updater != null ? updater.getChanges() : null;
|
||||
if (changes == null) {
|
||||
try (Scanner scanner = new Scanner(new URL("http://empcraft.com/plots/cl?" + Integer.toHexString(PS.get().getVersion().hash)).openStream(), "UTF-8")) {
|
||||
try (Scanner scanner = new Scanner(new URL("http://empcraft.com/plots/cl?" + Integer
|
||||
.toHexString(PS.get().getVersion().hash)).openStream(), "UTF-8")) {
|
||||
changes = scanner.useDelimiter("\\A").next();
|
||||
}
|
||||
}
|
||||
changes = changes.replaceAll("#([0-9]+)", "github.com/IntellectualSites/PlotSquared/pulls/$1");
|
||||
changes = changes
|
||||
.replaceAll("#([0-9]+)", "github.com/IntellectualSites/PlotSquared/pulls/$1");
|
||||
MainUtil.sendMessage(player, changes);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@ -3,17 +3,10 @@ package com.intellectualcrafters.plot.commands;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "chat",
|
||||
description = "Toggle plot chat on or off",
|
||||
usage = "/plot chat [on|off]",
|
||||
permission = "plots.chat",
|
||||
category = CommandCategory.CHAT,
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "chat", description = "Toggle plot chat on or off", usage = "/plot chat [on|off]", permission = "plots.chat", category = CommandCategory.CHAT, requiredType = RequiredType.NONE)
|
||||
public class Chat extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
MainCommand.getInstance().toggle.chat(this, player, new String[0], null, null);
|
||||
return true;
|
||||
}
|
||||
|
@ -3,28 +3,17 @@ package com.intellectualcrafters.plot.commands;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Expression;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.ByteArrayUtilities;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(command = "claim",
|
||||
aliases = "c",
|
||||
description = "Claim the current plot you're standing on",
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.claim", usage = "/plot claim")
|
||||
@CommandDeclaration(command = "claim", aliases = "c", description = "Claim the current plot you're standing on", category = CommandCategory.CLAIMING, requiredType = RequiredType.NONE, permission = "plots.claim", usage = "/plot claim")
|
||||
public class Claim extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
String schematic = "";
|
||||
if (args.length >= 1) {
|
||||
schematic = args[0];
|
||||
@ -34,11 +23,13 @@ public class Claim extends SubCommand {
|
||||
if (plot == null) {
|
||||
return sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
int currentPlots = Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(loc.getWorld());
|
||||
int currentPlots =
|
||||
Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(loc.getWorld());
|
||||
int grants = 0;
|
||||
if (currentPlots >= player.getAllowedPlots()) {
|
||||
if (player.hasPersistentMeta("grantedPlots")) {
|
||||
grants = ByteArrayUtilities.bytesToInteger(player.getPersistentMeta("grantedPlots"));
|
||||
grants =
|
||||
ByteArrayUtilities.bytesToInteger(player.getPersistentMeta("grantedPlots"));
|
||||
if (grants <= 0) {
|
||||
player.removePersistentMeta("grantedPlots");
|
||||
return sendMessage(player, C.CANT_CLAIM_MORE_PLOTS);
|
||||
@ -56,7 +47,8 @@ public class Claim extends SubCommand {
|
||||
if (!area.SCHEMATICS.contains(schematic.toLowerCase())) {
|
||||
return sendMessage(player, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
||||
}
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_CLAIM_SCHEMATIC.f(schematic)) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) {
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_CLAIM_SCHEMATIC.f(schematic))
|
||||
&& !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) {
|
||||
return sendMessage(player, C.NO_SCHEMATIC_PERMISSION, schematic);
|
||||
}
|
||||
}
|
||||
@ -80,7 +72,8 @@ public class Claim extends SubCommand {
|
||||
if (grants == 1) {
|
||||
player.removePersistentMeta("grantedPlots");
|
||||
} else {
|
||||
player.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grants - 1));
|
||||
player.setPersistentMeta("grantedPlots",
|
||||
ByteArrayUtilities.integerToBytes(grants - 1));
|
||||
}
|
||||
sendMessage(player, C.REMOVED_GRANTED_PLOT, "1", "" + (grants - 1));
|
||||
}
|
||||
@ -88,11 +81,9 @@ public class Claim extends SubCommand {
|
||||
plot.owner = player.getUUID();
|
||||
final String finalSchematic = schematic;
|
||||
DBFunc.createPlotSafe(plot, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
TaskManager.IMP.sync(new RunnableVal<Object>() {
|
||||
@Override
|
||||
public void run(Object value) {
|
||||
@Override public void run(Object value) {
|
||||
plot.claim(player, true, finalSchematic, false);
|
||||
if (area.AUTO_MERGE) {
|
||||
plot.autoMerge(-1, Integer.MAX_VALUE, player.getUUID(), true);
|
||||
@ -101,8 +92,7 @@ public class Claim extends SubCommand {
|
||||
});
|
||||
}
|
||||
}, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
sendMessage(player, C.PLOT_NOT_CLAIMED);
|
||||
}
|
||||
});
|
||||
|
@ -14,13 +14,7 @@ import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
|
||||
import com.plotsquared.general.commands.Command;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(command = "clear",
|
||||
description = "Clear a plot",
|
||||
permission = "plots.clear",
|
||||
category = CommandCategory.APPEARANCE,
|
||||
usage = "/plot clear",
|
||||
aliases = "reset",
|
||||
confirmation = true)
|
||||
@CommandDeclaration(command = "clear", description = "Clear a plot", permission = "plots.clear", category = CommandCategory.APPEARANCE, usage = "/plot clear", aliases = "reset", confirmation = true)
|
||||
public class Clear extends Command {
|
||||
|
||||
// Note: To clear a specific plot use /plot <plot> clear
|
||||
@ -30,24 +24,24 @@ public class Clear extends Command {
|
||||
super(MainCommand.getInstance(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
@Override public void execute(final PlotPlayer player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
checkTrue(args.length == 0, C.COMMAND_SYNTAX, getUsage());
|
||||
final Plot plot = check(player.getCurrentPlot(), C.NOT_IN_PLOT);
|
||||
checkTrue(plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_CLEAR), C.NO_PLOT_PERMS);
|
||||
checkTrue(plot.isOwner(player.getUUID()) || Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_CLEAR), C.NO_PLOT_PERMS);
|
||||
checkTrue(plot.getRunning() == 0, C.WAIT_FOR_TIMER);
|
||||
checkTrue(!Settings.Done.RESTRICT_BUILDING || !Flags.DONE.isSet(plot) || Permissions.hasPermission(player, C.PERMISSION_CONTINUE), C.DONE_ALREADY_DONE);
|
||||
checkTrue(!Settings.Done.RESTRICT_BUILDING || !Flags.DONE.isSet(plot) || Permissions
|
||||
.hasPermission(player, C.PERMISSION_CONTINUE), C.DONE_ALREADY_DONE);
|
||||
confirm.run(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
final long start = System.currentTimeMillis();
|
||||
boolean result = plot.clear(true, false, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
plot.unlink();
|
||||
GlobalBlockQueue.IMP.addTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
plot.removeRunning();
|
||||
// If the state changes, then mark it as no longer done
|
||||
if (plot.getFlag(Flags.DONE).isPresent()) {
|
||||
@ -56,7 +50,8 @@ public class Clear extends Command {
|
||||
if (plot.getFlag(Flags.ANALYSIS).isPresent()) {
|
||||
FlagManager.removePlotFlag(plot, Flags.ANALYSIS);
|
||||
}
|
||||
MainUtil.sendMessage(player, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
||||
MainUtil.sendMessage(player, C.CLEARING_DONE,
|
||||
"" + (System.currentTimeMillis() - start));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -4,32 +4,21 @@ import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(command = "cluster",
|
||||
aliases = "clusters",
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.cluster",
|
||||
description = "Manage a plot cluster")
|
||||
@CommandDeclaration(command = "cluster", aliases = "clusters", category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.NONE, permission = "plots.cluster", description = "Manage a plot cluster")
|
||||
public class Cluster extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
|
||||
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
|
||||
if (args.length == 0) {
|
||||
@ -83,10 +72,13 @@ public class Cluster extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (args.length != 4) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot cluster create <name> <id-bot> <id-top>");
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX,
|
||||
"/plot cluster create <name> <id-bot> <id-top>");
|
||||
return false;
|
||||
}
|
||||
int currentClusters = Settings.Limit.GLOBAL ? player.getClusterCount() : player.getPlotCount(player.getLocation().getWorld());
|
||||
int currentClusters = Settings.Limit.GLOBAL ?
|
||||
player.getClusterCount() :
|
||||
player.getPlotCount(player.getLocation().getWorld());
|
||||
if (currentClusters >= player.getAllowedPlots()) {
|
||||
return sendMessage(player, C.CANT_CLAIM_MORE_CLUSTERS);
|
||||
}
|
||||
@ -125,7 +117,8 @@ public class Cluster extends SubCommand {
|
||||
UUID uuid = player.getUUID();
|
||||
for (Plot plot : plots) {
|
||||
if (!plot.isOwner(uuid)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_CREATE_OTHER);
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION,
|
||||
C.PERMISSION_CLUSTER_CREATE_OTHER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -139,9 +132,11 @@ public class Cluster extends SubCommand {
|
||||
} else {
|
||||
current = player.getPlayerClusterCount(player.getLocation().getWorld());
|
||||
}
|
||||
int allowed = Permissions.hasPermissionRange(player, C.PERMISSION_CLUSTER_SIZE, Settings.Limit.MAX_PLOTS);
|
||||
int allowed = Permissions.hasPermissionRange(player, C.PERMISSION_CLUSTER_SIZE,
|
||||
Settings.Limit.MAX_PLOTS);
|
||||
if (current + cluster.getArea() > allowed) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_SIZE + "." + (current + cluster.getArea()));
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION,
|
||||
C.PERMISSION_CLUSTER_SIZE + "." + (current + cluster.getArea()));
|
||||
return false;
|
||||
}
|
||||
// create cluster
|
||||
@ -192,7 +187,8 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
if (!cluster.owner.equals(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_DELETE_OTHER)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_DELETE_OTHER);
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION,
|
||||
C.PERMISSION_CLUSTER_DELETE_OTHER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -207,7 +203,8 @@ public class Cluster extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (args.length != 3) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot cluster resize <pos1> <pos2>");
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX,
|
||||
"/plot cluster resize <pos1> <pos2>");
|
||||
return false;
|
||||
}
|
||||
// check pos1 / pos2
|
||||
@ -234,7 +231,8 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
if (!cluster.hasHelperRights(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_RESIZE_OTHER)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_RESIZE_OTHER);
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION,
|
||||
C.PERMISSION_CLUSTER_RESIZE_OTHER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -244,21 +242,24 @@ public class Cluster extends SubCommand {
|
||||
MainUtil.sendMessage(player, C.CLUSTER_INTERSECTION, intersect.getName());
|
||||
return false;
|
||||
}
|
||||
HashSet<Plot> existing = area.getPlotSelectionOwned(cluster.getP1(), cluster.getP2());
|
||||
HashSet<Plot> existing =
|
||||
area.getPlotSelectionOwned(cluster.getP1(), cluster.getP2());
|
||||
HashSet<Plot> newPlots = area.getPlotSelectionOwned(pos1, pos2);
|
||||
HashSet<Plot> removed = (HashSet<Plot>) existing.clone();
|
||||
removed.removeAll(newPlots);
|
||||
// Check expand / shrink
|
||||
if (!removed.isEmpty()) {
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_RESIZE_SHRINK)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_RESIZE_SHRINK);
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION,
|
||||
C.PERMISSION_CLUSTER_RESIZE_SHRINK);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
newPlots.removeAll(existing);
|
||||
if (!newPlots.isEmpty()) {
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_RESIZE_EXPAND)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_RESIZE_EXPAND);
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION,
|
||||
C.PERMISSION_CLUSTER_RESIZE_EXPAND);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -270,9 +271,11 @@ public class Cluster extends SubCommand {
|
||||
current = player.getPlayerClusterCount(player.getLocation().getWorld());
|
||||
}
|
||||
current -= cluster.getArea() + (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y);
|
||||
int allowed = Permissions.hasPermissionRange(player, C.PERMISSION_CLUSTER, Settings.Limit.MAX_PLOTS);
|
||||
int allowed = Permissions
|
||||
.hasPermissionRange(player, C.PERMISSION_CLUSTER, Settings.Limit.MAX_PLOTS);
|
||||
if (current + cluster.getArea() > allowed) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER.s() + "." + (current + cluster.getArea()));
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION,
|
||||
C.PERMISSION_CLUSTER.s() + "." + (current + cluster.getArea()));
|
||||
return false;
|
||||
}
|
||||
// resize cluster
|
||||
@ -303,7 +306,8 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
if (!cluster.hasHelperRights(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_INVITE_OTHER)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_INVITE_OTHER);
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION,
|
||||
C.PERMISSION_CLUSTER_INVITE_OTHER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -347,7 +351,8 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
if (!cluster.hasHelperRights(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_KICK_OTHER)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_KICK_OTHER);
|
||||
MainUtil
|
||||
.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_KICK_OTHER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -358,7 +363,8 @@ public class Cluster extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
// Can't kick if the player is yourself, the owner, or not added to the cluster
|
||||
if (uuid.equals(player.getUUID()) || uuid.equals(cluster.owner) || !cluster.isAdded(uuid)) {
|
||||
if (uuid.equals(player.getUUID()) || uuid.equals(cluster.owner) || !cluster
|
||||
.isAdded(uuid)) {
|
||||
MainUtil.sendMessage(player, C.CANNOT_KICK_PLAYER, cluster.getName());
|
||||
return false;
|
||||
}
|
||||
@ -372,7 +378,8 @@ public class Cluster extends SubCommand {
|
||||
if (player2 != null) {
|
||||
MainUtil.sendMessage(player2, C.CLUSTER_REMOVED, cluster.getName());
|
||||
}
|
||||
for (Plot plot : new ArrayList<>(PS.get().getPlots(player2.getLocation().getWorld(), uuid))) {
|
||||
for (Plot plot : new ArrayList<>(
|
||||
PS.get().getPlots(player2.getLocation().getWorld(), uuid))) {
|
||||
PlotCluster current = plot.getCluster();
|
||||
if (current != null && current.equals(cluster)) {
|
||||
plot.unclaim();
|
||||
@ -425,7 +432,8 @@ public class Cluster extends SubCommand {
|
||||
cluster.invited.remove(uuid);
|
||||
DBFunc.removeInvited(cluster, uuid);
|
||||
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
|
||||
for (Plot plot : new ArrayList<>(PS.get().getPlots(player.getLocation().getWorld(), uuid))) {
|
||||
for (Plot plot : new ArrayList<>(
|
||||
PS.get().getPlots(player.getLocation().getWorld(), uuid))) {
|
||||
PlotCluster current = plot.getCluster();
|
||||
if (current != null && current.equals(cluster)) {
|
||||
player.getLocation().getWorld();
|
||||
@ -443,7 +451,8 @@ public class Cluster extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (args.length != 3) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX,
|
||||
"/plot cluster helpers <add|remove> <player>");
|
||||
return false;
|
||||
}
|
||||
PlotArea area = player.getApplicablePlotArea();
|
||||
@ -470,7 +479,8 @@ public class Cluster extends SubCommand {
|
||||
DBFunc.removeHelper(cluster, uuid);
|
||||
return MainUtil.sendMessage(player, C.CLUSTER_REMOVED_HELPER);
|
||||
}
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX,
|
||||
"/plot cluster helpers <add|remove> <player>");
|
||||
return false;
|
||||
}
|
||||
case "spawn":
|
||||
@ -497,7 +507,8 @@ public class Cluster extends SubCommand {
|
||||
UUID uuid = player.getUUID();
|
||||
if (!cluster.isAdded(uuid)) {
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_TP_OTHER)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_TP_OTHER);
|
||||
MainUtil
|
||||
.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_TP_OTHER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -540,7 +551,8 @@ public class Cluster extends SubCommand {
|
||||
owner = "unknown";
|
||||
}
|
||||
String name = cluster.getName();
|
||||
String size = (cluster.getP2().x - cluster.getP1().x + 1) + "x" + (cluster.getP2().y - cluster.getP1().y + 1);
|
||||
String size = (cluster.getP2().x - cluster.getP1().x + 1) + "x" + (
|
||||
cluster.getP2().y - cluster.getP1().y + 1);
|
||||
String rights = cluster.isAdded(player.getUUID()) + "";
|
||||
String message = C.CLUSTER_INFO.s();
|
||||
message = message.replaceAll("%id%", id);
|
||||
@ -573,7 +585,8 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
if (!cluster.hasHelperRights(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_SETHOME_OTHER)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_SETHOME_OTHER);
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION,
|
||||
C.PERMISSION_CLUSTER_SETHOME_OTHER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -581,7 +594,8 @@ public class Cluster extends SubCommand {
|
||||
Location relative = player.getLocation().subtract(base.getX(), 0, base.getZ());
|
||||
BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ());
|
||||
cluster.settings.setPosition(blockloc);
|
||||
DBFunc.setPosition(cluster, relative.getX() + "," + relative.getY() + "," + relative.getZ());
|
||||
DBFunc.setPosition(cluster,
|
||||
relative.getX() + "," + relative.getY() + "," + relative.getZ());
|
||||
return MainUtil.sendMessage(player, C.POSITION_SET);
|
||||
}
|
||||
MainUtil.sendMessage(player, C.CLUSTER_AVAILABLE_ARGS);
|
||||
|
@ -8,39 +8,31 @@ public enum CommandCategory {
|
||||
* Claiming CommandConfig.
|
||||
* Such as: /plot claim
|
||||
*/
|
||||
CLAIMING("Claiming"),
|
||||
/**
|
||||
CLAIMING("Claiming"), /**
|
||||
* Teleportation CommandConfig.
|
||||
* Such as: /plot visit
|
||||
*/
|
||||
TELEPORT("Teleport"),
|
||||
/**
|
||||
TELEPORT("Teleport"), /**
|
||||
* Protection.
|
||||
*/
|
||||
SETTINGS("Protection"),
|
||||
/**
|
||||
SETTINGS("Protection"), /**
|
||||
* Chat.
|
||||
*/
|
||||
CHAT("Chat"),
|
||||
/**
|
||||
CHAT("Chat"), /**
|
||||
* Web.
|
||||
*/
|
||||
SCHEMATIC("Web"),
|
||||
/**
|
||||
SCHEMATIC("Web"), /**
|
||||
* Cosmetic.
|
||||
*/
|
||||
APPEARANCE("Cosmetic"),
|
||||
/**
|
||||
APPEARANCE("Cosmetic"), /**
|
||||
* Information CommandConfig.
|
||||
* Such as: /plot info
|
||||
*/
|
||||
INFO("Info"),
|
||||
/**
|
||||
INFO("Info"), /**
|
||||
* Debug CommandConfig.
|
||||
* Such as: /plot debug
|
||||
*/
|
||||
DEBUG("Debug"),
|
||||
/**
|
||||
DEBUG("Debug"), /**
|
||||
* Administration commands.
|
||||
*/
|
||||
ADMINISTRATION("Admin");
|
||||
@ -48,6 +40,7 @@ public enum CommandCategory {
|
||||
* The category name (Readable).
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@ -57,8 +50,7 @@ public enum CommandCategory {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
@ -16,23 +16,20 @@ import com.plotsquared.general.commands.CommandDeclaration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@CommandDeclaration(command = "comment",
|
||||
aliases = {"msg"},
|
||||
description = "Comment on a plot",
|
||||
category = CommandCategory.CHAT,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.comment")
|
||||
@CommandDeclaration(command = "comment", aliases = {
|
||||
"msg"}, description = "Comment on a plot", category = CommandCategory.CHAT, requiredType = RequiredType.NONE, permission = "plots.comment")
|
||||
public class Comment extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
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;
|
||||
}
|
||||
CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
||||
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;
|
||||
}
|
||||
Location loc = player.getLocation();
|
||||
@ -44,7 +41,8 @@ public class Comment extends SubCommand {
|
||||
plot = loc.getPlotAbs();
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
index = 2;
|
||||
@ -54,11 +52,14 @@ public class Comment extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
String message = StringMan.join(Arrays.copyOfRange(args, index, args.length), " ");
|
||||
PlotComment comment = new PlotComment(loc.getWorld(), id, message, player.getName(), inbox.toString(), System.currentTimeMillis());
|
||||
PlotComment comment =
|
||||
new PlotComment(loc.getWorld(), id, message, player.getName(), inbox.toString(),
|
||||
System.currentTimeMillis());
|
||||
boolean result = inbox.addComment(plot, comment);
|
||||
if (!result) {
|
||||
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;
|
||||
}
|
||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||
|
@ -11,25 +11,16 @@ import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@CommandDeclaration(command = "condense",
|
||||
permission = "plots.admin",
|
||||
description = "Condense a plotworld",
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.CONSOLE)
|
||||
@CommandDeclaration(command = "condense", permission = "plots.admin", description = "Condense a plotworld", category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.CONSOLE)
|
||||
public class Condense extends SubCommand {
|
||||
|
||||
public static boolean TASK = false;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
if (args.length != 2 && args.length != 3) {
|
||||
MainUtil.sendMessage(player, "/plot condense <area> <start|stop|info> [radius]");
|
||||
return false;
|
||||
@ -42,7 +33,8 @@ public class Condense extends SubCommand {
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "start": {
|
||||
if (args.length == 2) {
|
||||
MainUtil.sendMessage(player, "/plot condense " + area.toString() + " start <radius>");
|
||||
MainUtil.sendMessage(player,
|
||||
"/plot condense " + area.toString() + " start <radius>");
|
||||
return false;
|
||||
}
|
||||
if (Condense.TASK) {
|
||||
@ -112,14 +104,14 @@ public class Condense extends SubCommand {
|
||||
}
|
||||
MainUtil.sendMessage(player, "TASK STARTED...");
|
||||
Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
if (!Condense.TASK) {
|
||||
MainUtil.sendMessage(player, "TASK CANCELLED.");
|
||||
}
|
||||
if (allPlots.isEmpty()) {
|
||||
Condense.TASK = false;
|
||||
MainUtil.sendMessage(player, "TASK COMPLETE. PLEASE VERIFY THAT NO NEW PLOTS HAVE BEEN CLAIMED DURING TASK.");
|
||||
MainUtil.sendMessage(player,
|
||||
"TASK COMPLETE. PLEASE VERIFY THAT NO NEW PLOTS HAVE BEEN CLAIMED DURING TASK.");
|
||||
return;
|
||||
}
|
||||
final Runnable task = this;
|
||||
@ -134,10 +126,10 @@ public class Condense extends SubCommand {
|
||||
i++;
|
||||
final AtomicBoolean result = new AtomicBoolean(false);
|
||||
result.set(origin.move(possible, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
if (result.get()) {
|
||||
MainUtil.sendMessage(player, "Moving: " + origin + " -> " + possible);
|
||||
MainUtil.sendMessage(player,
|
||||
"Moving: " + origin + " -> " + possible);
|
||||
TaskManager.runTaskLater(task, 1);
|
||||
}
|
||||
}
|
||||
@ -170,7 +162,8 @@ public class Condense extends SubCommand {
|
||||
return true;
|
||||
case "info":
|
||||
if (args.length == 2) {
|
||||
MainUtil.sendMessage(player, "/plot condense " + area.toString() + " info <radius>");
|
||||
MainUtil.sendMessage(player,
|
||||
"/plot condense " + area.toString() + " info <radius>");
|
||||
return false;
|
||||
}
|
||||
if (!MathMan.isInteger(args[2])) {
|
||||
@ -193,18 +186,21 @@ public class Condense extends SubCommand {
|
||||
MainUtil.sendMessage(player, "=== INPUT EVAL ===");
|
||||
MainUtil.sendMessage(player, "INPUT RADIUS: " + radius);
|
||||
MainUtil.sendMessage(player, "ESTIMATED MOVES: " + userMove);
|
||||
MainUtil.sendMessage(player, "ESTIMATED TIME: No idea, times will drastically change based on the system performance and load");
|
||||
MainUtil.sendMessage(player,
|
||||
"ESTIMATED TIME: No idea, times will drastically change based on the system performance and load");
|
||||
MainUtil.sendMessage(player, "&e - Radius is measured in plot width");
|
||||
return true;
|
||||
}
|
||||
MainUtil.sendMessage(player, "/plot condense " + area.worldname + " <start|stop|info> [radius]");
|
||||
MainUtil.sendMessage(player,
|
||||
"/plot condense " + area.worldname + " <start|stop|info> [radius]");
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<PlotId> getPlots(Collection<Plot> plots, int radius) {
|
||||
HashSet<PlotId> outside = new HashSet<>();
|
||||
for (Plot plot : plots) {
|
||||
if (plot.getId().x > radius || plot.getId().x < -radius || plot.getId().y > radius || plot.getId().y < -radius) {
|
||||
if (plot.getId().x > radius || plot.getId().x < -radius || plot.getId().y > radius
|
||||
|| plot.getId().y < -radius) {
|
||||
outside.add(plot.getId());
|
||||
}
|
||||
}
|
||||
|
@ -9,21 +9,18 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(command = "confirm",
|
||||
permission = "plots.use",
|
||||
description = "Confirm an action",
|
||||
category = CommandCategory.INFO)
|
||||
@CommandDeclaration(command = "confirm", permission = "plots.use", description = "Confirm an action", category = CommandCategory.INFO)
|
||||
public class Confirm extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
CmdInstance command = CmdConfirm.getPending(player);
|
||||
if (command == null) {
|
||||
MainUtil.sendMessage(player, C.FAILED_CONFIRM);
|
||||
return false;
|
||||
}
|
||||
CmdConfirm.removePending(player);
|
||||
if ((System.currentTimeMillis() - command.timestamp) > Settings.Confirmation.CONFIRMATION_TIMEOUT_SECONDS * 1000) {
|
||||
if ((System.currentTimeMillis() - command.timestamp)
|
||||
> Settings.Confirmation.CONFIRMATION_TIMEOUT_SECONDS * 1000) {
|
||||
MainUtil.sendMessage(player, C.EXPIRED_CONFIRM);
|
||||
return false;
|
||||
}
|
||||
|
@ -9,21 +9,16 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "continue",
|
||||
description = "Continue a plot that was previously marked as done",
|
||||
permission = "plots.continue",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "continue", description = "Continue a plot that was previously marked as done", permission = "plots.continue", category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE)
|
||||
public class Continue extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
Plot plot = player.getCurrentPlot();
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_CONTINUE)) {
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_CONTINUE)) {
|
||||
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
@ -32,7 +27,8 @@ public class Continue extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
int size = plot.getConnectedPlots().size();
|
||||
if (Settings.Done.COUNTS_TOWARDS_LIMIT && (player.getAllowedPlots() < player.getPlotCount() + size)) {
|
||||
if (Settings.Done.COUNTS_TOWARDS_LIMIT && (player.getAllowedPlots()
|
||||
< player.getPlotCount() + size)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_ADMIN_COMMAND_CONTINUE);
|
||||
return false;
|
||||
}
|
||||
|
@ -8,24 +8,18 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "copy",
|
||||
permission = "plots.copy",
|
||||
aliases = {"copypaste"},
|
||||
category = CommandCategory.CLAIMING,
|
||||
description = "Copy a plot",
|
||||
usage = "/plot copy <X;Z>",
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "copy", permission = "plots.copy", aliases = {
|
||||
"copypaste"}, category = CommandCategory.CLAIMING, description = "Copy a plot", usage = "/plot copy <X;Z>", requiredType = RequiredType.NONE)
|
||||
public class Copy extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
Location loc = player.getLocation();
|
||||
Plot plot1 = loc.getPlotAbs();
|
||||
if (plot1 == null) {
|
||||
return !MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot1.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN.s())) {
|
||||
if (!plot1.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN.s())) {
|
||||
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
@ -47,8 +41,7 @@ public class Copy extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (plot1.copy(plot2, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
MainUtil.sendMessage(player, C.COPY_SUCCESS);
|
||||
}
|
||||
})) {
|
||||
|
@ -9,18 +9,11 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "createroadschematic",
|
||||
aliases = {"crs"},
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.createroadschematic",
|
||||
description = "Add a road schematic to your world using the roads around your current plot",
|
||||
usage = "/plot createroadschematic")
|
||||
@CommandDeclaration(command = "createroadschematic", aliases = {
|
||||
"crs"}, category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.NONE, permission = "plots.createroadschematic", description = "Add a road schematic to your world using the roads around your current plot", usage = "/plot createroadschematic")
|
||||
public class CreateRoadSchematic extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
Location loc = player.getLocation();
|
||||
Plot plot = loc.getPlotAbs();
|
||||
if (plot == null) {
|
||||
@ -30,7 +23,8 @@ public class CreateRoadSchematic extends SubCommand {
|
||||
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
|
||||
}
|
||||
HybridUtils.manager.setupRoadSchematic(plot);
|
||||
MainUtil.sendMessage(player, "$1Saved new road schematic. To test the road, fly to a few other plots and use /plot debugroadregen");
|
||||
MainUtil.sendMessage(player,
|
||||
"$1Saved new road schematic. To test the road, fly to a few other plots and use /plot debugroadregen");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.intellectualcrafters.plot.object.worlds.SinglePlotArea;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
@ -21,20 +22,14 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "database",
|
||||
aliases = {"convert"},
|
||||
category = CommandCategory.ADMINISTRATION,
|
||||
permission = "plots.database",
|
||||
description = "Convert/Backup Storage",
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
usage = "/plot database [area] <sqlite|mysql|import>")
|
||||
@CommandDeclaration(command = "database", aliases = {
|
||||
"convert"}, category = CommandCategory.ADMINISTRATION, permission = "plots.database", description = "Convert/Backup Storage", requiredType = RequiredType.CONSOLE, usage = "/plot database [area] <sqlite|mysql|import>")
|
||||
public class Database extends SubCommand {
|
||||
|
||||
public static void insertPlots(final SQLManager manager, final List<Plot> plots, final PlotPlayer player) {
|
||||
public static void insertPlots(final SQLManager manager, final List<Plot> plots,
|
||||
final PlotPlayer player) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
try {
|
||||
ArrayList<Plot> ps = new ArrayList<>();
|
||||
for (Plot p : plots) {
|
||||
@ -42,22 +37,21 @@ public class Database extends SubCommand {
|
||||
}
|
||||
MainUtil.sendMessage(player, "&6Starting...");
|
||||
manager.createPlotsAndData(ps, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
MainUtil.sendMessage(player, "&6Database conversion finished!");
|
||||
manager.close();
|
||||
}
|
||||
});
|
||||
} catch (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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(player, "/plot database [area] <sqlite|mysql|import>");
|
||||
return false;
|
||||
@ -81,17 +75,20 @@ public class Database extends SubCommand {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "import":
|
||||
if (args.length < 2) {
|
||||
MainUtil.sendMessage(player, "/plot database import <sqlite file> [prefix]");
|
||||
MainUtil
|
||||
.sendMessage(player, "/plot database import <sqlite file> [prefix]");
|
||||
return false;
|
||||
}
|
||||
File file = MainUtil.getFile(PS.get().IMP.getDirectory(), args[1].endsWith(".db") ? args[1] : args[1] + ".db");
|
||||
File file = MainUtil.getFile(PS.get().IMP.getDirectory(),
|
||||
args[1].endsWith(".db") ? args[1] : args[1] + ".db");
|
||||
if (!file.exists()) {
|
||||
MainUtil.sendMessage(player, "&6Database does not exist: " + file);
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(player, "&6Starting...");
|
||||
implementation = new SQLite(file);
|
||||
SQLManager manager = new SQLManager(implementation, args.length == 3 ? args[2] : "", true);
|
||||
SQLManager manager =
|
||||
new SQLManager(implementation, args.length == 3 ? args[2] : "", true);
|
||||
HashMap<String, HashMap<PlotId, Plot>> map = manager.getPlots();
|
||||
plots = new ArrayList<>();
|
||||
for (Entry<String, HashMap<PlotId, Plot>> entry : map.entrySet()) {
|
||||
@ -106,9 +103,12 @@ public class Database extends SubCommand {
|
||||
if (newPlot != null) {
|
||||
PlotId newId = newPlot.getId();
|
||||
PlotId id = plot.getId();
|
||||
File worldFile = new File(PS.imp().getWorldContainer(), id.toCommaSeparatedString());
|
||||
File worldFile = new File(PS.imp().getWorldContainer(),
|
||||
id.toCommaSeparatedString());
|
||||
if (worldFile.exists()) {
|
||||
File newFile = new File(PS.imp().getWorldContainer(), newId.toCommaSeparatedString());
|
||||
File newFile =
|
||||
new File(PS.imp().getWorldContainer(),
|
||||
newId.toCommaSeparatedString());
|
||||
worldFile.renameTo(newFile);
|
||||
}
|
||||
id.x = newId.x;
|
||||
@ -119,7 +119,8 @@ public class Database extends SubCommand {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, "Skipping duplicate plot: " + plot + " | id=" + plot.temp);
|
||||
MainUtil.sendMessage(player,
|
||||
"Skipping duplicate plot: " + plot + " | id=" + plot.temp);
|
||||
continue;
|
||||
}
|
||||
plot.setArea(pa);
|
||||
@ -135,15 +136,15 @@ public class Database extends SubCommand {
|
||||
}
|
||||
}
|
||||
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
MainUtil.sendMessage(player, "&6Database conversion finished!");
|
||||
}
|
||||
});
|
||||
return true;
|
||||
case "mysql":
|
||||
if (args.length < 6) {
|
||||
return MainUtil.sendMessage(player, "/plot database mysql [host] [port] [username] [password] [database] {prefix}");
|
||||
return MainUtil.sendMessage(player,
|
||||
"/plot database mysql [host] [port] [username] [password] [database] {prefix}");
|
||||
}
|
||||
String host = args[1];
|
||||
String port = args[2];
|
||||
@ -159,7 +160,8 @@ public class Database extends SubCommand {
|
||||
if (args.length < 2) {
|
||||
return MainUtil.sendMessage(player, "/plot database sqlite [file]");
|
||||
}
|
||||
File sqliteFile = MainUtil.getFile(PS.get().IMP.getDirectory(), args[1] + ".db");
|
||||
File sqliteFile =
|
||||
MainUtil.getFile(PS.get().IMP.getDirectory(), args[1] + ".db");
|
||||
implementation = new SQLite(sqliteFile);
|
||||
break;
|
||||
default:
|
||||
@ -171,15 +173,18 @@ public class Database extends SubCommand {
|
||||
return true;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
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();
|
||||
MainUtil.sendMessage(player, "&d==== End of stacktrace ====");
|
||||
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;
|
||||
}
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
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();
|
||||
MainUtil.sendMessage(player, "&d==== End of stacktrace ====");
|
||||
MainUtil.sendMessage(player, "$1Please make sure you are using the correct arguments!");
|
||||
|
@ -7,15 +7,10 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(command = "debug",
|
||||
category = CommandCategory.DEBUG,
|
||||
description = "Show debug information",
|
||||
usage = "/plot debug [msg]",
|
||||
permission = "plots.admin")
|
||||
@CommandDeclaration(command = "debug", category = CommandCategory.DEBUG, description = "Show debug information", usage = "/plot debug [msg]", permission = "plots.admin")
|
||||
public class Debug extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
if ((args.length > 0) && args[0].equalsIgnoreCase("msg")) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
for (C caption : C.values()) {
|
||||
@ -30,7 +25,8 @@ public class Debug extends SubCommand {
|
||||
String section = C.DEBUG_SECTION.s();
|
||||
information.append(header);
|
||||
information.append(getSection(section, "PlotArea"));
|
||||
information.append(getLine(line, "Plot Worlds", StringMan.join(PS.get().getPlotAreas(), ", ")));
|
||||
information
|
||||
.append(getLine(line, "Plot Worlds", StringMan.join(PS.get().getPlotAreas(), ", ")));
|
||||
information.append(getLine(line, "Owned Plots", PS.get().getPlots().size()));
|
||||
information.append(getSection(section, "Messages"));
|
||||
information.append(getLine(line, "Total Messages", C.values().length));
|
||||
|
@ -8,19 +8,12 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "debugallowunsafe",
|
||||
description = "Allow unsafe actions until toggled off",
|
||||
usage = "/plot debugallowunsafe",
|
||||
category = CommandCategory.DEBUG,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.debugallowunsafe")
|
||||
@CommandDeclaration(command = "debugallowunsafe", description = "Allow unsafe actions until toggled off", usage = "/plot debugallowunsafe", category = CommandCategory.DEBUG, requiredType = RequiredType.NONE, permission = "plots.debugallowunsafe")
|
||||
public class DebugAllowUnsafe extends SubCommand {
|
||||
|
||||
public static final List<UUID> unsafeAllowed = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
|
||||
if (unsafeAllowed.contains(player.getUUID())) {
|
||||
unsafeAllowed.remove(player.getUUID());
|
||||
|
@ -4,14 +4,7 @@ import com.google.common.collect.BiMap;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
@ -22,23 +15,16 @@ import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "debugclaimtest",
|
||||
description = "If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot signs. "
|
||||
+ "Execution time may vary",
|
||||
category = CommandCategory.DEBUG,
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
permission = "plots.debugclaimtest")
|
||||
@CommandDeclaration(command = "debugclaimtest", description =
|
||||
"If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot signs. "
|
||||
+ "Execution time may vary", category = CommandCategory.DEBUG, requiredType = RequiredType.CONSOLE, permission = "plots.debugclaimtest")
|
||||
public class DebugClaimTest extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
if (args.length < 3) {
|
||||
return !MainUtil
|
||||
.sendMessage(
|
||||
null,
|
||||
"If you accidentally delete your database, this command will attempt to restore all plots based on the data from the "
|
||||
+ "plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
|
||||
return !MainUtil.sendMessage(null,
|
||||
"If you accidentally delete your database, this command will attempt to restore all plots based on the data from the "
|
||||
+ "plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
|
||||
}
|
||||
PlotArea area = PS.get().getPlotAreaByString(args[0]);
|
||||
if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) {
|
||||
@ -53,11 +39,13 @@ public class DebugClaimTest extends SubCommand {
|
||||
max = PlotId.fromString(args[2]);
|
||||
} catch (Exception ignored) {
|
||||
return !MainUtil.sendMessage(player,
|
||||
"&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.");
|
||||
}
|
||||
MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: &7Beginning sign to plot conversion. This may take a while...");
|
||||
MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
|
||||
MainUtil.sendMessage(player,
|
||||
"&3Sign Block&8->&3Plot&8: &7Beginning sign to plot conversion. This may take a while...");
|
||||
MainUtil.sendMessage(player,
|
||||
"&3Sign Block&8->&3Plot&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
|
||||
PlotManager manager = area.getPlotManager();
|
||||
ArrayList<Plot> plots = new ArrayList<>();
|
||||
for (PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
|
||||
@ -80,8 +68,10 @@ public class DebugClaimTest extends SubCommand {
|
||||
BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
|
||||
UUID uuid = map.get(new StringWrapper(line));
|
||||
if (uuid == null) {
|
||||
for (Map.Entry<StringWrapper, UUID> stringWrapperUUIDEntry : map.entrySet()) {
|
||||
if (stringWrapperUUIDEntry.getKey().value.toLowerCase().startsWith(line.toLowerCase())) {
|
||||
for (Map.Entry<StringWrapper, UUID> stringWrapperUUIDEntry : map
|
||||
.entrySet()) {
|
||||
if (stringWrapperUUIDEntry.getKey().value.toLowerCase()
|
||||
.startsWith(line.toLowerCase())) {
|
||||
uuid = stringWrapperUUIDEntry.getValue();
|
||||
break;
|
||||
}
|
||||
@ -91,20 +81,22 @@ public class DebugClaimTest extends SubCommand {
|
||||
uuid = UUIDHandler.getUUID(line, null);
|
||||
}
|
||||
if (uuid != null) {
|
||||
MainUtil.sendMessage(player, " - &aFound plot: " + plot.getId() + " : " + line);
|
||||
MainUtil
|
||||
.sendMessage(player, " - &aFound plot: " + plot.getId() + " : " + line);
|
||||
plot.setOwner(uuid);
|
||||
plots.add(plot);
|
||||
} else {
|
||||
MainUtil.sendMessage(player, " - &cInvalid PlayerName: " + plot.getId() + " : " + line);
|
||||
MainUtil.sendMessage(player,
|
||||
" - &cInvalid PlayerName: " + plot.getId() + " : " + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!plots.isEmpty()) {
|
||||
MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: &7Updating '" + plots.size() + "' plots!");
|
||||
MainUtil.sendMessage(player,
|
||||
"&3Sign Block&8->&3Plot&8: &7Updating '" + plots.size() + "' plots!");
|
||||
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
MainUtil.sendMessage(player, "&6Database update finished!");
|
||||
}
|
||||
});
|
||||
|
@ -8,71 +8,37 @@ import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotMessage;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal2;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal3;
|
||||
import com.intellectualcrafters.plot.util.AbstractTitle;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
|
||||
import com.intellectualcrafters.plot.util.expiry.ExpireManager;
|
||||
import com.intellectualcrafters.plot.util.expiry.PlotAnalysis;
|
||||
import com.plotsquared.general.commands.Command;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
import com.plotsquared.listener.WEManager;
|
||||
|
||||
import javax.script.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.script.Bindings;
|
||||
import javax.script.ScriptContext;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
import javax.script.SimpleScriptContext;
|
||||
import java.util.*;
|
||||
|
||||
@CommandDeclaration(command = "debugexec",
|
||||
permission = "plots.admin",
|
||||
description = "Mutli-purpose debug command",
|
||||
aliases = {"exec", "$"},
|
||||
category = CommandCategory.DEBUG)
|
||||
public class DebugExec extends SubCommand {
|
||||
@CommandDeclaration(command = "debugexec", permission = "plots.admin", description = "Mutli-purpose debug command", aliases = {
|
||||
"exec", "$"}, category = CommandCategory.DEBUG) public class DebugExec extends SubCommand {
|
||||
private ScriptEngine engine;
|
||||
private Bindings scope;
|
||||
|
||||
public DebugExec() {
|
||||
try {
|
||||
if (PS.get() != null) {
|
||||
File file = new File(PS.get().IMP.getDirectory(), Settings.Paths.SCRIPTS + File.separator + "start.js");
|
||||
File file = new File(PS.get().IMP.getDirectory(),
|
||||
Settings.Paths.SCRIPTS + File.separator + "start.js");
|
||||
if (file.exists()) {
|
||||
init();
|
||||
String script = StringMan.join(Files
|
||||
.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + Settings.Paths.SCRIPTS), "start.js"),
|
||||
StandardCharsets.UTF_8),
|
||||
System.getProperty("line.separator"));
|
||||
String script = StringMan.join(Files.readLines(new File(new File(
|
||||
PS.get().IMP.getDirectory() + File.separator + Settings.Paths.SCRIPTS),
|
||||
"start.js"), StandardCharsets.UTF_8), System.getProperty("line.separator"));
|
||||
this.scope.put("THIS", this);
|
||||
this.scope.put("PlotPlayer", ConsolePlayer.getConsole());
|
||||
this.engine.eval(script, this.scope);
|
||||
@ -148,10 +114,11 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
List<String> allowed_params =
|
||||
Arrays.asList("analyze", "calibrate-analysis", "remove-flag", "stop-expire", "start-expire", "seen", "list-scripts", "start-rgar", "stop-rgar", "help", "addcmd", "runasync", "run", "allcmd", "all");
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
List<String> allowed_params = Arrays
|
||||
.asList("analyze", "calibrate-analysis", "remove-flag", "stop-expire", "start-expire",
|
||||
"seen", "list-scripts", "start-rgar", "stop-rgar", "help", "addcmd", "runasync",
|
||||
"run", "allcmd", "all");
|
||||
if (args.length > 0) {
|
||||
String arg = args[0].toLowerCase();
|
||||
String script;
|
||||
@ -170,19 +137,20 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
MainUtil.sendMessage(player, "$1Starting task...");
|
||||
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
|
||||
@Override
|
||||
public void run(PlotAnalysis value) {
|
||||
MainUtil.sendMessage(player, "$1Done: $2Use $3/plot debugexec analyze$2 for more information");
|
||||
@Override public void run(PlotAnalysis value) {
|
||||
MainUtil.sendMessage(player,
|
||||
"$1Done: $2Use $3/plot debugexec analyze$2 for more information");
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
case "calibrate-analysis":
|
||||
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)");
|
||||
"$1<threshold> $2= $1The percentage of plots you want to clear (100 clears 100% of plots so no point calibrating "
|
||||
+ "it)");
|
||||
return false;
|
||||
}
|
||||
double threshold;
|
||||
@ -190,12 +158,12 @@ public class DebugExec extends SubCommand {
|
||||
threshold = Integer.parseInt(args[1]) / 100d;
|
||||
} catch (NumberFormatException ignored) {
|
||||
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;
|
||||
}
|
||||
PlotAnalysis.calcOptimalModifiers(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
MainUtil.sendMessage(player, "$1Thank you for calibrating plot expiry");
|
||||
}
|
||||
}, threshold);
|
||||
@ -207,7 +175,8 @@ public class DebugExec extends SubCommand {
|
||||
return MainUtil.sendMessage(player, "Cancelled task.");
|
||||
case "remove-flag":
|
||||
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;
|
||||
}
|
||||
String flag = args[1];
|
||||
@ -220,7 +189,8 @@ public class DebugExec extends SubCommand {
|
||||
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
|
||||
case "start-rgar": {
|
||||
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;
|
||||
}
|
||||
PlotArea area = PS.get().getPlotAreaByString(args[1]);
|
||||
@ -230,12 +200,14 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
boolean result;
|
||||
if (HybridUtils.regions != null) {
|
||||
result = HybridUtils.manager.scheduleRoadUpdate(area, HybridUtils.regions, 0);
|
||||
result =
|
||||
HybridUtils.manager.scheduleRoadUpdate(area, HybridUtils.regions, 0);
|
||||
} else {
|
||||
result = HybridUtils.manager.scheduleRoadUpdate(area, 0);
|
||||
}
|
||||
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 true;
|
||||
@ -267,7 +239,8 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
|
||||
if (op == null || op.getLastPlayed() == 0) {
|
||||
return MainUtil.sendMessage(player, "Player hasn't connected before: " + args[1]);
|
||||
return MainUtil
|
||||
.sendMessage(player, "Player hasn't connected before: " + args[1]);
|
||||
}
|
||||
Timestamp stamp = new Timestamp(op.getLastPlayed());
|
||||
Date date = new Date(stamp.getTime());
|
||||
@ -281,18 +254,21 @@ public class DebugExec extends SubCommand {
|
||||
case "he":
|
||||
case "?":
|
||||
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;
|
||||
case "addcmd":
|
||||
try {
|
||||
final String cmd = StringMan.join(Files
|
||||
.readLines(MainUtil.getFile(new File(PS.get().IMP.getDirectory() + File.separator + Settings.Paths.SCRIPTS),
|
||||
args[1]),
|
||||
StandardCharsets.UTF_8),
|
||||
System.getProperty("line.separator"));
|
||||
new Command(MainCommand.getInstance(), true, args[1].split("\\.")[0], null, RequiredType.NONE, CommandCategory.DEBUG) {
|
||||
@Override
|
||||
public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
|
||||
final String cmd = StringMan.join(Files.readLines(MainUtil.getFile(new File(
|
||||
PS.get().IMP.getDirectory() + File.separator + Settings.Paths.SCRIPTS),
|
||||
args[1]), StandardCharsets.UTF_8),
|
||||
System.getProperty("line.separator"));
|
||||
new Command(MainCommand.getInstance(), true, args[1].split("\\.")[0], null,
|
||||
RequiredType.NONE, CommandCategory.DEBUG) {
|
||||
@Override public void execute(PlotPlayer player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
try {
|
||||
DebugExec.this.scope.put("PlotPlayer", player);
|
||||
DebugExec.this.scope.put("args", args);
|
||||
@ -306,18 +282,18 @@ public class DebugExec extends SubCommand {
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec addcmd <file>");
|
||||
MainUtil
|
||||
.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec addcmd <file>");
|
||||
return false;
|
||||
}
|
||||
case "runasync":
|
||||
async = true;
|
||||
case "run":
|
||||
try {
|
||||
script = StringMan.join(Files
|
||||
.readLines(MainUtil.getFile(new File(PS.get().IMP.getDirectory() + File.separator + Settings.Paths.SCRIPTS),
|
||||
args[1]),
|
||||
StandardCharsets.UTF_8),
|
||||
System.getProperty("line.separator"));
|
||||
script = StringMan.join(Files.readLines(MainUtil.getFile(new File(
|
||||
PS.get().IMP.getDirectory() + File.separator + Settings.Paths.SCRIPTS),
|
||||
args[1]), StandardCharsets.UTF_8),
|
||||
System.getProperty("line.separator"));
|
||||
if (args.length > 2) {
|
||||
HashMap<String, String> replacements = new HashMap<>();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
@ -331,7 +307,8 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
break;
|
||||
case "list-scripts":
|
||||
String path = PS.get().IMP.getDirectory() + File.separator + Settings.Paths.SCRIPTS;
|
||||
String path =
|
||||
PS.get().IMP.getDirectory() + File.separator + Settings.Paths.SCRIPTS;
|
||||
File folder = new File(path);
|
||||
File[] filesArray = folder.listFiles();
|
||||
|
||||
@ -351,18 +328,20 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
|
||||
List<File> allFiles = Arrays.asList(filesArray);
|
||||
paginate(player, allFiles, 8, page, new RunnableVal3<Integer, File, PlotMessage>() {
|
||||
paginate(player, allFiles, 8, page,
|
||||
new RunnableVal3<Integer, File, PlotMessage>() {
|
||||
|
||||
@Override
|
||||
public void run(Integer i, File file, PlotMessage message) {
|
||||
String name = file.getName();
|
||||
message.text("[").color("$3").text(String.valueOf(i)).color("$1").text("]").color("$3").text(' ' + name).color("$1");
|
||||
}
|
||||
}, "/plot debugexec list-scripts", "List of scripts");
|
||||
@Override public void run(Integer i, File file, PlotMessage message) {
|
||||
String name = file.getName();
|
||||
message.text("[").color("$3").text(String.valueOf(i)).color("$1")
|
||||
.text("]").color("$3").text(' ' + name).color("$1");
|
||||
}
|
||||
}, "/plot debugexec list-scripts", "List of scripts");
|
||||
return true;
|
||||
case "allcmd":
|
||||
if (args.length < 3) {
|
||||
C.COMMAND_SYNTAX.send(player, "/plot debugexec allcmd <condition> <command>");
|
||||
C.COMMAND_SYNTAX
|
||||
.send(player, "/plot debugexec allcmd <condition> <command>");
|
||||
return false;
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
@ -392,7 +371,9 @@ public class DebugExec extends SubCommand {
|
||||
init();
|
||||
this.scope.put("_2", params);
|
||||
this.scope.put("_3", cmd);
|
||||
script = "_1=PS.getBasePlots().iterator();while(_1.hasNext()){plot=_1.next();if(" + args[1]
|
||||
script =
|
||||
"_1=PS.getBasePlots().iterator();while(_1.hasNext()){plot=_1.next();if("
|
||||
+ args[1]
|
||||
+ "){PlotPlayer.setMeta(\"location\",plot.getBottomAbs());PlotPlayer.setMeta(\"lastplot\",plot);_3.onCommand"
|
||||
+ "(PlotPlayer,_2)}}";
|
||||
|
||||
@ -402,9 +383,10 @@ public class DebugExec extends SubCommand {
|
||||
C.COMMAND_SYNTAX.send(player, "/plot debugexec all <condition> <code>");
|
||||
return false;
|
||||
}
|
||||
script = "_1=PS.getBasePlots().iterator();while(_1.hasNext()){plot=_1.next();if(" + args[1] + "){" + StringMan
|
||||
.join(Arrays.copyOfRange(args, 2, args.length), " ")
|
||||
+ "}}";
|
||||
script =
|
||||
"_1=PS.getBasePlots().iterator();while(_1.hasNext()){plot=_1.next();if("
|
||||
+ args[1] + "){" + StringMan
|
||||
.join(Arrays.copyOfRange(args, 2, args.length), " ") + "}}";
|
||||
|
||||
break;
|
||||
default:
|
||||
@ -421,8 +403,7 @@ public class DebugExec extends SubCommand {
|
||||
if (async) {
|
||||
final String toExec = script;
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
long start = System.currentTimeMillis();
|
||||
Object result = null;
|
||||
try {
|
||||
|
@ -16,21 +16,14 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "debugfixflags",
|
||||
usage = "/plot debugfixflags <world>",
|
||||
permission = "plots.debugfixflags",
|
||||
description = "Attempt to fix all flags for a world",
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
category = CommandCategory.DEBUG)
|
||||
@CommandDeclaration(command = "debugfixflags", usage = "/plot debugfixflags <world>", permission = "plots.debugfixflags", description = "Attempt to fix all flags for a world", requiredType = RequiredType.CONSOLE, category = CommandCategory.DEBUG)
|
||||
public class DebugFixFlags extends SubCommand {
|
||||
|
||||
public DebugFixFlags() {
|
||||
super(Argument.String);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
PlotArea area = PS.get().getPlotAreaByString(args[0]);
|
||||
if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[0]);
|
||||
|
@ -13,22 +13,19 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.plotsquared.general.commands.Command;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "debugimportworlds",
|
||||
permission = "plots.admin",
|
||||
description = "Import worlds by player name",
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
category = CommandCategory.TELEPORT)
|
||||
@CommandDeclaration(command = "debugimportworlds", permission = "plots.admin", description = "Import worlds by player name", requiredType = RequiredType.CONSOLE, category = CommandCategory.TELEPORT)
|
||||
public class DebugImportWorlds extends Command {
|
||||
public DebugImportWorlds() {
|
||||
super(MainCommand.getInstance(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
@Override public void execute(PlotPlayer player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
// UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8))
|
||||
PlotAreaManager pam = PS.get().getPlotAreaManager();
|
||||
if (!(pam instanceof SinglePlotAreaManager)) {
|
||||
@ -43,7 +40,8 @@ public class DebugImportWorlds extends Command {
|
||||
if (!WorldUtil.IMP.isWorld(name) && PlotId.fromString(name) == null) {
|
||||
UUID uuid = UUIDHandler.getUUID(name, null);
|
||||
if (uuid == null) {
|
||||
uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
||||
uuid =
|
||||
UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
while (new File(container, id.toCommaSeparatedString()).exists()) {
|
||||
id = Auto.getNextPlotId(id, 1);
|
||||
|
@ -5,17 +5,10 @@ import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "debugloadtest",
|
||||
permission = "plots.debugloadtest",
|
||||
description = "This debug command will force the reload of all plots in the DB",
|
||||
usage = "/plot debugloadtest",
|
||||
category = CommandCategory.DEBUG,
|
||||
requiredType = RequiredType.CONSOLE)
|
||||
@CommandDeclaration(command = "debugloadtest", permission = "plots.debugloadtest", description = "This debug command will force the reload of all plots in the DB", usage = "/plot debugloadtest", category = CommandCategory.DEBUG, requiredType = RequiredType.CONSOLE)
|
||||
public class DebugLoadTest extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
PS.get().plots_tmp = DBFunc.getPlots();
|
||||
return true;
|
||||
}
|
||||
|
@ -13,41 +13,39 @@ import com.plotsquared.general.commands.CommandDeclaration;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@CommandDeclaration(command = "debugpaste",
|
||||
aliases = "dp", usage = "/plot debugpaste",
|
||||
description = "Upload settings.yml, worlds.yml, commands.yml and latest.log to www.hastebin.com",
|
||||
permission = "plots.debugpaste",
|
||||
category = CommandCategory.DEBUG)
|
||||
@CommandDeclaration(command = "debugpaste", aliases = "dp", usage = "/plot debugpaste", description = "Upload settings.yml, worlds.yml, commands.yml and latest.log to www.hastebin.com", permission = "plots.debugpaste", category = CommandCategory.DEBUG)
|
||||
public class DebugPaste extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
try {
|
||||
String settingsYML = HastebinUtility.upload(PS.get().configFile);
|
||||
String worldsYML = HastebinUtility.upload(PS.get().worldsFile);
|
||||
String commandsYML = HastebinUtility.upload(PS.get().commandsFile);
|
||||
String latestLOG;
|
||||
try {
|
||||
latestLOG = HastebinUtility.upload(new File(PS.get().IMP.getDirectory(), "../../logs/latest.log"));
|
||||
latestLOG = HastebinUtility
|
||||
.upload(new File(PS.get().IMP.getDirectory(), "../../logs/latest.log"));
|
||||
} catch (IOException ignored) {
|
||||
MainUtil.sendMessage(player, "&clatest.log is too big to be pasted, will ignore");
|
||||
MainUtil.sendMessage(player,
|
||||
"&clatest.log is too big to be pasted, will ignore");
|
||||
latestLOG = "too big :(";
|
||||
}
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append(
|
||||
"# Welcome to this paste\n# It is meant to provide us at IntellectualSites with better information about your "
|
||||
+ "problem\n\n# We will start with some informational files\n");
|
||||
"# Welcome to this paste\n# It is meant to provide us at IntellectualSites with better information about your "
|
||||
+ "problem\n\n# We will start with some informational files\n");
|
||||
b.append("links.settings_yml: ").append(settingsYML).append('\n');
|
||||
b.append("links.worlds_yml: ").append(worldsYML).append('\n');
|
||||
b.append("links.commands_yml: ").append(commandsYML).append('\n');
|
||||
b.append("links.latest_log: ").append(latestLOG).append('\n');
|
||||
b.append("\n# Server Information\n");
|
||||
int[] sVersion = PS.get().IMP.getServerVersion();
|
||||
b.append("version.server: ").append(sVersion[0]).append('.').append(sVersion[1]).append('.').append(sVersion[2]).append('\n');
|
||||
b.append("online_mode: ").append(UUIDHandler.getUUIDWrapper()).append(';').append(!Settings.UUID.OFFLINE).append('\n');
|
||||
b.append("version.server: ").append(sVersion[0]).append('.').append(sVersion[1])
|
||||
.append('.').append(sVersion[2]).append('\n');
|
||||
b.append("online_mode: ").append(UUIDHandler.getUUIDWrapper()).append(';')
|
||||
.append(!Settings.UUID.OFFLINE).append('\n');
|
||||
b.append("plugins:");
|
||||
for (String id : PS.get().IMP.getPluginIds()) {
|
||||
String[] split = id.split(":");
|
||||
@ -55,21 +53,26 @@ public class DebugPaste extends SubCommand {
|
||||
String enabled = split.length == 2 ? split[1] : "unknown";
|
||||
String name = split2[0];
|
||||
String version = split2.length == 2 ? split2[1] : "unknown";
|
||||
b.append("\n ").append(name).append(":\n ").append("version: '").append(version).append('\'').append("\n enabled: ")
|
||||
.append(enabled);
|
||||
b.append("\n ").append(name).append(":\n ").append("version: '")
|
||||
.append(version).append('\'').append("\n enabled: ").append(enabled);
|
||||
}
|
||||
b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n");
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
b.append("memory.free: ").append(runtime.freeMemory()).append('\n');
|
||||
b.append("memory.max: ").append(runtime.maxMemory()).append('\n');
|
||||
b.append("java.specification.version: '").append(System.getProperty("java.specification.version")).append("'\n");
|
||||
b.append("java.vendor: '").append(System.getProperty("java.vendor")).append("'\n");
|
||||
b.append("java.version: '").append(System.getProperty("java.version")).append("'\n");
|
||||
b.append("java.specification.version: '")
|
||||
.append(System.getProperty("java.specification.version")).append("'\n");
|
||||
b.append("java.vendor: '").append(System.getProperty("java.vendor"))
|
||||
.append("'\n");
|
||||
b.append("java.version: '").append(System.getProperty("java.version"))
|
||||
.append("'\n");
|
||||
b.append("os.arch: '").append(System.getProperty("os.arch")).append("'\n");
|
||||
b.append("os.name: '").append(System.getProperty("os.name")).append("'\n");
|
||||
b.append("os.version: '").append(System.getProperty("os.version")).append("'\n\n");
|
||||
b.append("os.version: '").append(System.getProperty("os.version"))
|
||||
.append("'\n\n");
|
||||
b.append("# Okay :D Great. You are now ready to create your bug report!");
|
||||
b.append("\n# You can do so at https://github.com/IntellectualSites/PlotSquared/issues");
|
||||
b.append(
|
||||
"\n# You can do so at https://github.com/IntellectualSites/PlotSquared/issues");
|
||||
|
||||
String link = HastebinUtility.upload(b.toString());
|
||||
player.sendMessage(C.DEBUG_REPORT_CREATED.s().replace("%url%", link));
|
||||
|
@ -4,26 +4,15 @@ import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotManager;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "debugroadregen",
|
||||
usage = "/plot debugroadregen",
|
||||
requiredType = RequiredType.NONE,
|
||||
description = "Regenerate all roads based on the road schematic",
|
||||
category = CommandCategory.DEBUG,
|
||||
permission = "plots.debugroadregen")
|
||||
@CommandDeclaration(command = "debugroadregen", usage = "/plot debugroadregen", requiredType = RequiredType.NONE, description = "Regenerate all roads based on the road schematic", category = CommandCategory.DEBUG, permission = "plots.debugroadregen")
|
||||
public class DebugRoadRegen extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
Location loc = player.getLocation();
|
||||
PlotArea plotArea = loc.getPlotArea();
|
||||
if (!(plotArea instanceof HybridPlotWorld)) {
|
||||
@ -45,14 +34,17 @@ public class DebugRoadRegen extends SubCommand {
|
||||
}
|
||||
boolean result = HybridUtils.manager.regenerateRoad(plotArea, chunk, extend);
|
||||
MainUtil.sendMessage(player,
|
||||
"&6Regenerating chunk: " + chunk.x + ',' + chunk.z + "\n&6 - Result: " + (result ? "&aSuccess" : "&cFailed"));
|
||||
"&6Regenerating chunk: " + chunk.x + ',' + chunk.z + "\n&6 - Result: " + (result ?
|
||||
"&aSuccess" :
|
||||
"&cFailed"));
|
||||
MainUtil.sendMessage(player, "&cTo regenerate all roads: /plot regenallroads");
|
||||
} else {
|
||||
HybridPlotManager manager = (HybridPlotManager) plotArea.getPlotManager();
|
||||
manager.createRoadEast(plotArea, plot);
|
||||
manager.createRoadSouth(plotArea, plot);
|
||||
manager.createRoadSouthEast(plotArea, plot);
|
||||
MainUtil.sendMessage(player, "&6Regenerating plot south/east roads: " + plot.getId() + "\n&6 - Result: &aSuccess");
|
||||
MainUtil.sendMessage(player, "&6Regenerating plot south/east roads: " + plot.getId()
|
||||
+ "\n&6 - Result: &aSuccess");
|
||||
MainUtil.sendMessage(player, "&cTo regenerate all roads: /plot regenallroads");
|
||||
}
|
||||
return true;
|
||||
|
@ -9,23 +9,15 @@ import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "debugsavetest",
|
||||
permission = "plots.debugsavetest",
|
||||
category = CommandCategory.DEBUG,
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
usage = "/plot debugsavetest",
|
||||
description = "This command will force the recreation of all plots in the DB")
|
||||
@CommandDeclaration(command = "debugsavetest", permission = "plots.debugsavetest", category = CommandCategory.DEBUG, requiredType = RequiredType.CONSOLE, usage = "/plot debugsavetest", description = "This command will force the recreation of all plots in the DB")
|
||||
public class DebugSaveTest extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
ArrayList<Plot> plots = new ArrayList<Plot>();
|
||||
plots.addAll(PS.get().getPlots());
|
||||
MainUtil.sendMessage(player, "&6Starting `DEBUGSAVETEST`");
|
||||
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
MainUtil.sendMessage(player, "&6Database sync finished!");
|
||||
}
|
||||
});
|
||||
|
@ -2,31 +2,16 @@ package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Expression;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "delete",
|
||||
permission = "plots.delete",
|
||||
description = "Delete a plot",
|
||||
usage = "/plot delete",
|
||||
aliases = {"dispose", "del", "reset"},
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE,
|
||||
confirmation = true)
|
||||
@CommandDeclaration(command = "delete", permission = "plots.delete", description = "Delete a plot", usage = "/plot delete", aliases = {
|
||||
"dispose", "del",
|
||||
"reset"}, category = CommandCategory.CLAIMING, requiredType = RequiredType.NONE, confirmation = true)
|
||||
public class Delete extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
|
||||
Location loc = player.getLocation();
|
||||
final Plot plot = loc.getPlotAbs();
|
||||
@ -36,23 +21,23 @@ public class Delete extends SubCommand {
|
||||
if (!plot.hasOwner()) {
|
||||
return !sendMessage(player, C.PLOT_UNOWNED);
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DELETE)) {
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DELETE)) {
|
||||
return !sendMessage(player, C.NO_PLOT_PERMS);
|
||||
}
|
||||
final PlotArea plotArea = plot.getArea();
|
||||
final java.util.Set<Plot> plots = plot.getConnectedPlots();
|
||||
final int currentPlots = Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(loc.getWorld());
|
||||
final int currentPlots =
|
||||
Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(loc.getWorld());
|
||||
Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
if (plot.getRunning() > 0) {
|
||||
MainUtil.sendMessage(player, C.WAIT_FOR_TIMER);
|
||||
return;
|
||||
}
|
||||
final long start = System.currentTimeMillis();
|
||||
boolean result = plot.deletePlot(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
plot.removeRunning();
|
||||
if ((EconHandler.manager != null) && plotArea.USE_ECONOMY) {
|
||||
Expression<Double> valueExr = plotArea.PRICES.get("sell");
|
||||
@ -62,7 +47,8 @@ public class Delete extends SubCommand {
|
||||
sendMessage(player, C.ADDED_BALANCE, String.valueOf(value));
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, C.DELETING_DONE, System.currentTimeMillis() - start);
|
||||
MainUtil.sendMessage(player, C.DELETING_DONE,
|
||||
System.currentTimeMillis() - start);
|
||||
}
|
||||
});
|
||||
if (result) {
|
||||
|
@ -6,12 +6,7 @@ import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.PlotGameMode;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.plotsquared.general.commands.Argument;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@ -19,20 +14,15 @@ import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(command = "deny",
|
||||
aliases = {"d", "ban"},
|
||||
description = "Deny a user from a plot",
|
||||
usage = "/plot deny <player>",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "deny", aliases = {"d",
|
||||
"ban"}, description = "Deny a user from a plot", usage = "/plot deny <player>", category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE)
|
||||
public class Deny extends SubCommand {
|
||||
|
||||
public Deny() {
|
||||
super(Argument.PlayerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlotAbs();
|
||||
@ -43,7 +33,8 @@ public class Deny extends SubCommand {
|
||||
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DENY)) {
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DENY)) {
|
||||
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
@ -55,7 +46,9 @@ public class Deny extends SubCommand {
|
||||
Iterator<UUID> iter = uuids.iterator();
|
||||
while (iter.hasNext()) {
|
||||
UUID uuid = iter.next();
|
||||
if (uuid == DBFunc.everyone && !(Permissions.hasPermission(player, C.PERMISSION_DENY_EVERYONE) || Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DENY))) {
|
||||
if (uuid == DBFunc.everyone && !(
|
||||
Permissions.hasPermission(player, C.PERMISSION_DENY_EVERYONE) || Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DENY))) {
|
||||
MainUtil.sendMessage(player, C.INVALID_PLAYER, MainUtil.getName(uuid));
|
||||
continue;
|
||||
}
|
||||
@ -105,7 +98,8 @@ public class Deny extends SubCommand {
|
||||
Location spawn = WorldUtil.IMP.getSpawn(loc.getWorld());
|
||||
MainUtil.sendMessage(player, C.YOU_GOT_DENIED);
|
||||
if (plot.equals(spawn.getPlot())) {
|
||||
Location newSpawn = WorldUtil.IMP.getSpawn(PS.get().getPlotAreaManager().getAllWorlds()[0]);
|
||||
Location newSpawn =
|
||||
WorldUtil.IMP.getSpawn(PS.get().getPlotAreaManager().getAllWorlds()[0]);
|
||||
if (plot.equals(newSpawn.getPlot())) {
|
||||
// Kick from server if you can't be teleported to spawn
|
||||
player.kick(C.YOU_GOT_DENIED.s());
|
||||
|
@ -8,18 +8,12 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "setdescription",
|
||||
permission = "plots.set.desc",
|
||||
description = "Set the plot description",
|
||||
usage = "/plot desc <description>",
|
||||
aliases = {"desc", "setdesc", "setd", "description"},
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "setdescription", permission = "plots.set.desc", description = "Set the plot description", usage = "/plot desc <description>", aliases = {
|
||||
"desc", "setdesc", "setd",
|
||||
"description"}, category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE)
|
||||
public class Desc extends SetCommand {
|
||||
|
||||
@Override
|
||||
public boolean set(PlotPlayer player, Plot plot, String desc) {
|
||||
@Override public boolean set(PlotPlayer player, Plot plot, String desc) {
|
||||
if (desc.isEmpty()) {
|
||||
plot.removeFlag(Flags.DESCRIPTION);
|
||||
MainUtil.sendMessage(player, C.DESC_UNSET);
|
||||
|
@ -14,22 +14,18 @@ import com.intellectualcrafters.plot.util.expiry.ExpireManager;
|
||||
import com.intellectualcrafters.plot.util.expiry.PlotAnalysis;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(command = "done",
|
||||
aliases = {"submit"},
|
||||
description = "Mark a plot as done",
|
||||
permission = "plots.done",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "done", aliases = {
|
||||
"submit"}, description = "Mark a plot as done", permission = "plots.done", category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE)
|
||||
public class Done extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
Location loc = player.getLocation();
|
||||
final Plot plot = loc.getPlotAbs();
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DONE)) {
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DONE)) {
|
||||
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
@ -49,10 +45,10 @@ public class Done extends SubCommand {
|
||||
plot.removeRunning();
|
||||
} else {
|
||||
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
|
||||
@Override
|
||||
public void run(PlotAnalysis value) {
|
||||
@Override public void run(PlotAnalysis value) {
|
||||
plot.removeRunning();
|
||||
boolean result = value.getComplexity(doneRequirements) <= doneRequirements.THRESHOLD;
|
||||
boolean result =
|
||||
value.getComplexity(doneRequirements) <= doneRequirements.THRESHOLD;
|
||||
finish(plot, player, result);
|
||||
}
|
||||
});
|
||||
|
@ -8,27 +8,16 @@ import com.intellectualcrafters.plot.flag.Flags;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.BO3Handler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
@CommandDeclaration(usage = "/plot download [schematic|bo3|world]",
|
||||
command = "download",
|
||||
aliases = {"dl"},
|
||||
category = CommandCategory.SCHEMATIC,
|
||||
requiredType = RequiredType.NONE,
|
||||
description = "Download your plot",
|
||||
permission = "plots.download")
|
||||
@CommandDeclaration(usage = "/plot download [schematic|bo3|world]", command = "download", aliases = {
|
||||
"dl"}, category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE, description = "Download your plot", permission = "plots.download")
|
||||
public class Download extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
String world = player.getLocation().getWorld();
|
||||
if (!PS.get().hasPlotArea(world)) {
|
||||
return !sendMessage(player, C.NOT_IN_PLOT_WORLD);
|
||||
@ -41,12 +30,13 @@ public class Download extends SubCommand {
|
||||
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if ((Settings.Done.REQUIRED_FOR_DOWNLOAD && (!plot.getFlag(Flags.DONE).isPresent())) && !Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DOWNLOAD)) {
|
||||
if ((Settings.Done.REQUIRED_FOR_DOWNLOAD && (!plot.getFlag(Flags.DONE).isPresent()))
|
||||
&& !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DOWNLOAD)) {
|
||||
MainUtil.sendMessage(player, C.DONE_NOT_DONE);
|
||||
return false;
|
||||
}
|
||||
if ((!plot.isOwner(player.getUUID())) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN.s())) {
|
||||
if ((!plot.isOwner(player.getUUID())) && !Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN.s())) {
|
||||
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
@ -54,19 +44,18 @@ public class Download extends SubCommand {
|
||||
MainUtil.sendMessage(player, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
if (args.length == 0 || (args.length == 1 && StringMan.isEqualIgnoreCaseToAny(args[0], "sch", "schem", "schematic"))) {
|
||||
if (args.length == 0 || (args.length == 1 && StringMan
|
||||
.isEqualIgnoreCaseToAny(args[0], "sch", "schem", "schematic"))) {
|
||||
if (plot.getVolume() > Integer.MAX_VALUE) {
|
||||
C.SCHEMATIC_TOO_LARGE.send(player);
|
||||
return false;
|
||||
}
|
||||
plot.addRunning();
|
||||
SchematicHandler.manager.getCompoundTag(plot, new RunnableVal<CompoundTag>() {
|
||||
@Override
|
||||
public void run(CompoundTag value) {
|
||||
@Override public void run(CompoundTag value) {
|
||||
plot.removeRunning();
|
||||
SchematicHandler.manager.upload(value, null, null, new RunnableVal<URL>() {
|
||||
@Override
|
||||
public void run(URL url) {
|
||||
@Override public void run(URL url) {
|
||||
if (url == null) {
|
||||
MainUtil.sendMessage(player, C.GENERATING_LINK_FAILED);
|
||||
return;
|
||||
@ -76,7 +65,8 @@ public class Download extends SubCommand {
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (args.length == 1 && StringMan.isEqualIgnoreCaseToAny(args[0], "bo3", "bo2", "b03", "b02")) {
|
||||
} else if (args.length == 1 && StringMan
|
||||
.isEqualIgnoreCaseToAny(args[0], "bo3", "bo2", "b03", "b02")) {
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_DOWNLOAD_BO3)) {
|
||||
C.NO_PERMISSION.send(player, C.PERMISSION_DOWNLOAD_BO3);
|
||||
return false;
|
||||
@ -87,8 +77,7 @@ public class Download extends SubCommand {
|
||||
}
|
||||
plot.addRunning();
|
||||
BO3Handler.upload(plot, null, null, new RunnableVal<URL>() {
|
||||
@Override
|
||||
public void run(URL url) {
|
||||
@Override public void run(URL url) {
|
||||
plot.removeRunning();
|
||||
if (url == null) {
|
||||
MainUtil.sendMessage(player, C.GENERATING_LINK_FAILED);
|
||||
@ -97,7 +86,8 @@ public class Download extends SubCommand {
|
||||
MainUtil.sendMessage(player, url.toString());
|
||||
}
|
||||
});
|
||||
} else if (args.length == 1 && StringMan.isEqualIgnoreCaseToAny(args[0], "mcr", "world", "mca")) {
|
||||
} else if (args.length == 1 && StringMan
|
||||
.isEqualIgnoreCaseToAny(args[0], "mcr", "world", "mca")) {
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_DOWNLOAD_WORLD)) {
|
||||
C.NO_PERMISSION.send(player, C.PERMISSION_DOWNLOAD_WORLD);
|
||||
return false;
|
||||
@ -106,8 +96,7 @@ public class Download extends SubCommand {
|
||||
plot.addRunning();
|
||||
WorldUtil.IMP.saveWorld(world);
|
||||
WorldUtil.IMP.upload(plot, null, null, new RunnableVal<URL>() {
|
||||
@Override
|
||||
public void run(URL url) {
|
||||
@Override public void run(URL url) {
|
||||
plot.removeRunning();
|
||||
if (url == null) {
|
||||
MainUtil.sendMessage(player, C.GENERATING_LINK_FAILED);
|
||||
|
@ -14,14 +14,8 @@ import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "setflag",
|
||||
aliases = {"f", "flag", "setf", "setflag"},
|
||||
usage = "/plot flag <set|remove|add|list|info> <flag> <value>",
|
||||
description = "Set plot flags",
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.NONE,
|
||||
permission = "plots.flag")
|
||||
@CommandDeclaration(command = "setflag", aliases = {"f", "flag", "setf",
|
||||
"setflag"}, usage = "/plot flag <set|remove|add|list|info> <flag> <value>", description = "Set plot flags", category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, permission = "plots.flag")
|
||||
public class FlagCmd extends SubCommand {
|
||||
|
||||
private boolean checkPermValue(PlotPlayer player, Flag flag, String key, String value) {
|
||||
@ -33,17 +27,19 @@ public class FlagCmd extends SubCommand {
|
||||
int numeric = Integer.parseInt(value);
|
||||
perm = perm.substring(0, perm.length() - value.length() - 1);
|
||||
if (numeric > 0) {
|
||||
int checkRange = PS.get().getPlatform().equalsIgnoreCase("bukkit") ? numeric : Settings.Limit.MAX_PLOTS;
|
||||
int checkRange = PS.get().getPlatform().equalsIgnoreCase("bukkit") ?
|
||||
numeric :
|
||||
Settings.Limit.MAX_PLOTS;
|
||||
return player.hasPermissionRange(perm, checkRange) >= numeric;
|
||||
}
|
||||
|
||||
} catch (NumberFormatException ignore) {}
|
||||
} catch (NumberFormatException ignore) {
|
||||
}
|
||||
}
|
||||
return Permissions.hasPermission(player, perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
|
||||
/*
|
||||
* plot flag set fly true
|
||||
@ -66,7 +62,8 @@ public class FlagCmd extends SubCommand {
|
||||
sendMessage(player, C.PLOT_NOT_CLAIMED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_SET_FLAG_OTHER)) {
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||
.hasPermission(player, C.PERMISSION_SET_FLAG_OTHER)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_OTHER);
|
||||
return false;
|
||||
}
|
||||
@ -76,7 +73,8 @@ public class FlagCmd extends SubCommand {
|
||||
if (flag == null || flag.isReserved()) {
|
||||
boolean suggested = false;
|
||||
try {
|
||||
StringComparison<Flag<?>> stringComparison = new StringComparison<>(args[1], Flags.getFlags());
|
||||
StringComparison<Flag<?>> stringComparison =
|
||||
new StringComparison<>(args[1], Flags.getFlags());
|
||||
String best = stringComparison.getBestMatch();
|
||||
if (best != null) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG_SUGGESTED, best);
|
||||
@ -118,7 +116,8 @@ public class FlagCmd extends SubCommand {
|
||||
}
|
||||
String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||
if (!checkPermValue(player, flag, args[1], value)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), value.toLowerCase()));
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY_VALUE
|
||||
.f(args[1].toLowerCase(), value.toLowerCase()));
|
||||
return false;
|
||||
}
|
||||
Object parsed = flag.parseValue(value);
|
||||
@ -140,24 +139,29 @@ public class FlagCmd extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, C.PERMISSION_SET_FLAG_KEY.f(args[1].toLowerCase()))) {
|
||||
if (!Permissions
|
||||
.hasPermission(player, C.PERMISSION_SET_FLAG_KEY.f(args[1].toLowerCase()))) {
|
||||
if (args.length != 3) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY.f(args[1].toLowerCase()));
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION,
|
||||
C.PERMISSION_SET_FLAG_KEY.f(args[1].toLowerCase()));
|
||||
return false;
|
||||
}
|
||||
for (String entry : args[2].split(",")) {
|
||||
if (!checkPermValue(player, flag, args[1], entry)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry));
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION,
|
||||
C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (args.length == 3 && flag instanceof ListFlag) {
|
||||
String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||
Optional<? extends Collection> flag1 = plot.getFlag((Flag<? extends Collection<?>>) flag);
|
||||
Optional<? extends Collection> flag1 =
|
||||
plot.getFlag((Flag<? extends Collection<?>>) flag);
|
||||
if (flag1.isPresent()) {
|
||||
boolean o = flag1.get().removeAll((Collection) flag.parseValue(value));
|
||||
if (o) {
|
||||
@ -176,9 +180,9 @@ public class FlagCmd extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(flag == Flags.TIME) {
|
||||
if (flag == Flags.TIME) {
|
||||
player.setTime(Long.MAX_VALUE);
|
||||
} else if(flag == Flags.WEATHER) {
|
||||
} else if (flag == Flags.WEATHER) {
|
||||
player.setWeather(PlotWeather.RESET);
|
||||
}
|
||||
MainUtil.sendMessage(player, C.FLAG_REMOVED);
|
||||
@ -190,12 +194,14 @@ public class FlagCmd extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
for (String entry : args[2].split(",")) {
|
||||
if (!checkPermValue(player, flag, args[1], entry)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry));
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION,
|
||||
C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -207,7 +213,8 @@ public class FlagCmd extends SubCommand {
|
||||
}
|
||||
Object val = parsed;
|
||||
if (flag instanceof ListFlag) {
|
||||
Optional<? extends Collection> flag1 = plot.getFlag((Flag<? extends Collection<?>>) flag);
|
||||
Optional<? extends Collection> flag1 =
|
||||
plot.getFlag((Flag<? extends Collection<?>>) flag);
|
||||
if (flag1.isPresent()) {
|
||||
boolean o = flag1.get().addAll((Collection) parsed);
|
||||
if (o) {
|
||||
|
@ -22,16 +22,17 @@ public class GenerateDocs {
|
||||
List<Command> commands = MainCommand.getInstance().getCommands();
|
||||
GenerateDocs.log("### Want to document some commands?");
|
||||
GenerateDocs.log(" - This page is automatically generated");
|
||||
GenerateDocs.log(" - Fork the project and add a javadoc comment to one of the command classes");
|
||||
GenerateDocs
|
||||
.log(" - Fork the project and add a javadoc comment to one of the command classes");
|
||||
GenerateDocs.log(" - Then do a pull request and it will be added to this page");
|
||||
GenerateDocs.log("");
|
||||
GenerateDocs.log("# Contents");
|
||||
for (CommandCategory category : CommandCategory.values()) {
|
||||
GenerateDocs.log("###### " + category.name());
|
||||
for (Command command : MainCommand.getInstance().getCommands(category, null)) {
|
||||
GenerateDocs
|
||||
.log(" - [/plot " + command.getId() + "](https://github.com/IntellectualSites/PlotSquared/wiki/Commands#" + command.getId()
|
||||
+ ") ");
|
||||
GenerateDocs.log(" - [/plot " + command.getId()
|
||||
+ "](https://github.com/IntellectualSites/PlotSquared/wiki/Commands#" + command
|
||||
.getId() + ") ");
|
||||
}
|
||||
GenerateDocs.log("");
|
||||
}
|
||||
@ -48,11 +49,12 @@ public class GenerateDocs {
|
||||
|
||||
// Header
|
||||
String source =
|
||||
"https://github.com/IntellectualSites/PlotSquared/tree/master/Core/src/main/java/com/intellectualcrafters/plot/commands/" + clazz
|
||||
+ ".java";
|
||||
"https://github.com/IntellectualSites/PlotSquared/tree/master/Core/src/main/java/com/intellectualcrafters/plot/commands/"
|
||||
+ clazz + ".java";
|
||||
GenerateDocs.log("## [" + name.toUpperCase() + "](" + source + ") ");
|
||||
|
||||
File file = new File("Core/src/main/java/com/intellectualcrafters/plot/commands/" + clazz + ".java");
|
||||
File file = new File(
|
||||
"Core/src/main/java/com/intellectualcrafters/plot/commands/" + clazz + ".java");
|
||||
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
|
||||
List<String> perms = GenerateDocs.getPerms(name, lines);
|
||||
List<String> usages = GenerateDocs.getUsage(name, lines);
|
||||
@ -123,7 +125,8 @@ public class GenerateDocs {
|
||||
prefix = " <arg> ";
|
||||
}
|
||||
if (usage.length() != 0) {
|
||||
usages.add(usage.toString().trim().replaceAll(" ", " ").replaceAll("\\{label\\}", "plot"));
|
||||
usages.add(usage.toString().trim().replaceAll(" ", " ")
|
||||
.replaceAll("\\{label\\}", "plot"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -203,7 +206,9 @@ public class GenerateDocs {
|
||||
for (String line : lines) {
|
||||
line = line.trim();
|
||||
if (line.startsWith("/** ") || line.startsWith("*/ ") || line.startsWith("* ")) {
|
||||
line = line.replaceAll("/[*][*] ", "").replaceAll("[*]/ ", "").replaceAll("[*] ", "").trim();
|
||||
line =
|
||||
line.replaceAll("/[*][*] ", "").replaceAll("[*]/ ", "").replaceAll("[*] ", "")
|
||||
.trim();
|
||||
result.append(line + '\n');
|
||||
}
|
||||
}
|
||||
|
@ -12,22 +12,19 @@ import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.general.commands.Command;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "grant",
|
||||
category = CommandCategory.CLAIMING,
|
||||
usage = "/plot grant <check|add> [player]",
|
||||
permission = "plots.grant",
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "grant", category = CommandCategory.CLAIMING, usage = "/plot grant <check|add> [player]", permission = "plots.grant", requiredType = RequiredType.NONE)
|
||||
public class Grant extends Command {
|
||||
|
||||
public Grant() {
|
||||
super(MainCommand.getInstance(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
@Override public void execute(final PlotPlayer player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
checkTrue(args.length >= 1 && args.length <= 2, C.COMMAND_SYNTAX, getUsage());
|
||||
final String arg0 = args[0].toLowerCase();
|
||||
switch (arg0) {
|
||||
@ -40,19 +37,21 @@ public class Grant extends Command {
|
||||
if (args.length > 2) {
|
||||
break;
|
||||
}
|
||||
final UUID uuid = args.length == 2 ? UUIDHandler.getUUIDFromString(args[1]) : player.getUUID();
|
||||
final UUID uuid =
|
||||
args.length == 2 ? UUIDHandler.getUUIDFromString(args[1]) : player.getUUID();
|
||||
if (uuid == null) {
|
||||
C.INVALID_PLAYER.send(player, args[1]);
|
||||
return;
|
||||
}
|
||||
MainUtil.getPersistentMeta(uuid, "grantedPlots", new RunnableVal<byte[]>() {
|
||||
@Override
|
||||
public void run(byte[] array) {
|
||||
@Override public void run(byte[] array) {
|
||||
if (arg0.equals("check")) { // check
|
||||
int granted = array == null ? 0 : ByteArrayUtilities.bytesToInteger(array);
|
||||
int granted =
|
||||
array == null ? 0 : ByteArrayUtilities.bytesToInteger(array);
|
||||
C.GRANTED_PLOTS.send(player, granted);
|
||||
} else { // add
|
||||
int amount = 1 + (array == null ? 0 : ByteArrayUtilities.bytesToInteger(array));
|
||||
int amount =
|
||||
1 + (array == null ? 0 : ByteArrayUtilities.bytesToInteger(array));
|
||||
boolean replace = array != null;
|
||||
String key = "grantedPlots";
|
||||
byte[] rawData = ByteArrayUtilities.integerToBytes(amount);
|
||||
|
@ -11,24 +11,20 @@ import com.intellectualcrafters.plot.util.helpmenu.HelpMenu;
|
||||
import com.plotsquared.general.commands.Command;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(command = "help",
|
||||
description = "Get this help menu",
|
||||
aliases = {"he", "?"},
|
||||
category = CommandCategory.INFO,
|
||||
usage="help [category|#]",
|
||||
permission="plots.use")
|
||||
@CommandDeclaration(command = "help", description = "Get this help menu", aliases = {"he",
|
||||
"?"}, category = CommandCategory.INFO, usage = "help [category|#]", permission = "plots.use")
|
||||
public class Help extends Command {
|
||||
public Help(Command parent) {
|
||||
super(parent, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecute(PlotPlayer player, boolean message) {
|
||||
@Override public boolean canExecute(PlotPlayer player, boolean message) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
|
||||
@Override public void execute(PlotPlayer player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
displayHelp(player, null, 0);
|
||||
@ -80,15 +76,18 @@ public class Help extends Command {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(C.HELP_HEADER.s());
|
||||
for (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"));
|
||||
builder.append("\n" + C.HELP_FOOTER.s());
|
||||
MainUtil.sendMessage(player, builder.toString(), false);
|
||||
return;
|
||||
}
|
||||
page--;
|
||||
new HelpMenu(player).setCategory(catEnum).getCommands().generateMaxPages().generatePage(page, getParent().toString()).render();
|
||||
new HelpMenu(player).setCategory(catEnum).getCommands().generateMaxPages()
|
||||
.generatePage(page, getParent().toString()).render();
|
||||
}
|
||||
}
|
||||
|
@ -15,13 +15,7 @@ import com.plotsquared.general.commands.CommandDeclaration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "inbox",
|
||||
description = "Review the comments for a plot",
|
||||
usage = "/plot inbox [inbox] [delete <index>|clear|page]",
|
||||
permission = "plots.inbox",
|
||||
category = CommandCategory.CHAT,
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "inbox", description = "Review the comments for a plot", usage = "/plot inbox [inbox] [delete <index>|clear|page]", permission = "plots.inbox", category = CommandCategory.CHAT, requiredType = RequiredType.NONE)
|
||||
public class Inbox extends SubCommand {
|
||||
|
||||
public void displayComments(PlotPlayer player, List<PlotComment> oldComments, int page) {
|
||||
@ -46,8 +40,8 @@ public class Inbox extends SubCommand {
|
||||
}
|
||||
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');
|
||||
.replaceAll(C.COMMENT_LIST_HEADER_PAGED.s(), "%amount%", comments.length, "%cur",
|
||||
page + 1, "%max", totalPages + 1, "%word", "all") + '\n');
|
||||
|
||||
// This might work xD
|
||||
for (int x = page * 12; x < max; x++) {
|
||||
@ -58,14 +52,14 @@ public class Inbox extends SubCommand {
|
||||
} else {
|
||||
color = "&7";
|
||||
}
|
||||
string.append("&8[&7#").append(x + 1).append("&8][&7").append(comment.world).append(';').append(comment.id).append("&8][&6")
|
||||
.append(comment.senderName).append("&8]").append(color).append(comment.comment).append('\n');
|
||||
string.append("&8[&7#").append(x + 1).append("&8][&7").append(comment.world).append(';')
|
||||
.append(comment.id).append("&8][&6").append(comment.senderName).append("&8]")
|
||||
.append(color).append(comment.comment).append('\n');
|
||||
}
|
||||
MainUtil.sendMessage(player, string.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
final Plot plot = player.getCurrentPlot();
|
||||
if (plot == null) {
|
||||
sendMessage(player, C.NOT_IN_PLOT);
|
||||
@ -76,18 +70,19 @@ public class Inbox extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
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()) {
|
||||
if (inbox.canRead(plot, player)) {
|
||||
if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
|
||||
@Override
|
||||
public void run(List<PlotComment> value) {
|
||||
@Override public void run(List<PlotComment> value) {
|
||||
if (value != null) {
|
||||
int total = 0;
|
||||
int unread = 0;
|
||||
for (PlotComment comment : value) {
|
||||
total++;
|
||||
if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString())) {
|
||||
if (comment.timestamp > CommentManager
|
||||
.getTimestamp(player, inbox.toString())) {
|
||||
unread++;
|
||||
}
|
||||
}
|
||||
@ -98,7 +93,9 @@ public class Inbox extends SubCommand {
|
||||
} else {
|
||||
color = "";
|
||||
}
|
||||
sendMessage(player, C.INBOX_ITEM, color + inbox.toString() + " (" + total + '/' + unread + ')');
|
||||
sendMessage(player, C.INBOX_ITEM,
|
||||
color + inbox.toString() + " (" + total + '/' + unread
|
||||
+ ')');
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -113,7 +110,8 @@ public class Inbox extends SubCommand {
|
||||
}
|
||||
final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
||||
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;
|
||||
}
|
||||
player.setMeta("inbox:" + inbox.toString(), System.currentTimeMillis());
|
||||
@ -126,7 +124,8 @@ public class Inbox extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
try {
|
||||
@ -136,13 +135,13 @@ public class Inbox extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
|
||||
sendMessage(player, C.COMMAND_SYNTAX,
|
||||
"/plot inbox " + inbox.toString() + " delete <index>");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
|
||||
@Override
|
||||
public void run(List<PlotComment> value) {
|
||||
@Override public void run(List<PlotComment> value) {
|
||||
if (index > value.size()) {
|
||||
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
|
||||
return;
|
||||
@ -162,7 +161,8 @@ public class Inbox extends SubCommand {
|
||||
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
|
||||
}
|
||||
inbox.clearInbox(plot);
|
||||
Optional<ArrayList<PlotComment>> comments = plot.getSettings().getComments(inbox.toString());
|
||||
Optional<ArrayList<PlotComment>> comments =
|
||||
plot.getSettings().getComments(inbox.toString());
|
||||
if (comments.isPresent()) {
|
||||
plot.getSettings().removeComments(comments.get());
|
||||
}
|
||||
@ -172,7 +172,8 @@ public class Inbox extends SubCommand {
|
||||
try {
|
||||
page = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ignored) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -184,8 +185,7 @@ public class Inbox extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
|
||||
@Override
|
||||
public void run(List<PlotComment> value) {
|
||||
@Override public void run(List<PlotComment> value) {
|
||||
displayComments(player, value, page);
|
||||
}
|
||||
})) {
|
||||
|
@ -2,26 +2,17 @@ package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.expiry.ExpireManager;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(command = "info",
|
||||
aliases = "i",
|
||||
description = "Display plot info",
|
||||
usage = "/plot info <id>",
|
||||
category = CommandCategory.INFO)
|
||||
@CommandDeclaration(command = "info", aliases = "i", description = "Display plot info", usage = "/plot info <id>", category = CommandCategory.INFO)
|
||||
public class Info extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
Plot plot;
|
||||
String arg;
|
||||
if (args.length > 0) {
|
||||
@ -65,13 +56,12 @@ public class Info extends SubCommand {
|
||||
if (args.length == 1) {
|
||||
args = new String[0];
|
||||
} else {
|
||||
args = new String[]{args[1]};
|
||||
args = new String[] {args[1]};
|
||||
}
|
||||
}
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("inv")) {
|
||||
PlotInventory inv = new PlotInventory(player) {
|
||||
@Override
|
||||
public boolean onClick(int index) {
|
||||
@Override public boolean onClick(int index) {
|
||||
// TODO InfoInventory not implemented yet!!!!!!!!
|
||||
// See plot rating or musicsubcommand on examples
|
||||
return false;
|
||||
@ -79,21 +69,24 @@ public class Info extends SubCommand {
|
||||
};
|
||||
UUID uuid = player.getUUID();
|
||||
String name = MainUtil.getName(plot.owner);
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cPlot Info", "&cID: &6" + plot.getId().toString(),
|
||||
"&cOwner: &6" + name,
|
||||
"&cAlias: &6" + plot.getAlias(),
|
||||
"&cBiome: &6" + plot.getBiome().replaceAll("_", "").toLowerCase(),
|
||||
"&cCan Build: &6" + plot.isAdded(uuid),
|
||||
"&cSeen: &6" + MainUtil.secToTime((int) (ExpireManager.IMP.getAge(plot) / 1000)),
|
||||
"&cIs Denied: &6" + plot.isDenied(uuid)));
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cTrusted", "&cAmount: &6" + plot.getTrusted().size(),
|
||||
"&8Click to view a list of the trusted users"));
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cMembers", "&cAmount: &6" + plot.getMembers().size(),
|
||||
"&8Click to view a list of plot members"));
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cDenied", "&cDenied", "&cAmount: &6" + plot.getDenied().size(),
|
||||
"&8Click to view a list of denied players"));
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cFlags", "&cFlags", "&cAmount: &6" + plot.getFlags().size(),
|
||||
"&8Click to view a list of plot flags"));
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cPlot Info",
|
||||
"&cID: &6" + plot.getId().toString(), "&cOwner: &6" + name,
|
||||
"&cAlias: &6" + plot.getAlias(),
|
||||
"&cBiome: &6" + plot.getBiome().replaceAll("_", "").toLowerCase(),
|
||||
"&cCan Build: &6" + plot.isAdded(uuid),
|
||||
"&cSeen: &6" + MainUtil.secToTime((int) (ExpireManager.IMP.getAge(plot) / 1000)),
|
||||
"&cIs Denied: &6" + plot.isDenied(uuid)));
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cTrusted",
|
||||
"&cAmount: &6" + plot.getTrusted().size(),
|
||||
"&8Click to view a list of the trusted users"));
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cMembers",
|
||||
"&cAmount: &6" + plot.getMembers().size(),
|
||||
"&8Click to view a list of plot members"));
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cDenied", "&cDenied",
|
||||
"&cAmount: &6" + plot.getDenied().size(),
|
||||
"&8Click to view a list of denied players"));
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cFlags", "&cFlags",
|
||||
"&cAmount: &6" + plot.getFlags().size(), "&8Click to view a list of plot flags"));
|
||||
inv.openInventory();
|
||||
return true;
|
||||
}
|
||||
@ -103,7 +96,8 @@ public class Info extends SubCommand {
|
||||
boolean trustedEveryone = plot.getMembers().contains(DBFunc.everyone);
|
||||
// Unclaimed?
|
||||
if (!hasOwner && !containsEveryone && !trustedEveryone) {
|
||||
MainUtil.sendMessage(player, C.PLOT_INFO_UNCLAIMED, plot.getId().x + ";" + plot.getId().y);
|
||||
MainUtil
|
||||
.sendMessage(player, C.PLOT_INFO_UNCLAIMED, plot.getId().x + ";" + plot.getId().y);
|
||||
return true;
|
||||
}
|
||||
String info = C.PLOT_INFO.s();
|
||||
@ -112,8 +106,8 @@ public class Info extends SubCommand {
|
||||
info = getCaption(arg);
|
||||
if (info == null) {
|
||||
MainUtil.sendMessage(player,
|
||||
"&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &aseen&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, "
|
||||
+ "&aowner&7, &arating");
|
||||
"&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &aseen&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, "
|
||||
+ "&aowner&7, &arating");
|
||||
return false;
|
||||
}
|
||||
full = true;
|
||||
@ -121,9 +115,9 @@ public class Info extends SubCommand {
|
||||
full = false;
|
||||
}
|
||||
MainUtil.format(info, plot, player, full, new RunnableVal<String>() {
|
||||
@Override
|
||||
public void run(String value) {
|
||||
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER.s() + '\n' + value + '\n' + C.PLOT_INFO_FOOTER.s(), false);
|
||||
@Override public void run(String value) {
|
||||
MainUtil.sendMessage(player,
|
||||
C.PLOT_INFO_HEADER.s() + '\n' + value + '\n' + C.PLOT_INFO_FOOTER.s(), false);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
@ -17,27 +17,22 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(command = "kick",
|
||||
aliases = {"k"},
|
||||
description = "Kick a player from your plot",
|
||||
permission = "plots.kick",
|
||||
usage = "<player>",
|
||||
category = CommandCategory.TELEPORT,
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "kick", aliases = {
|
||||
"k"}, description = "Kick a player from your plot", permission = "plots.kick", usage = "<player>", category = CommandCategory.TELEPORT, requiredType = RequiredType.NONE)
|
||||
public class Kick extends SubCommand {
|
||||
|
||||
public Kick() {
|
||||
super(Argument.PlayerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlot();
|
||||
if (plot == null) {
|
||||
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
if ((!plot.hasOwner() || !plot.isOwner(player.getUUID())) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_KICK)) {
|
||||
if ((!plot.hasOwner() || !plot.isOwner(player.getUUID())) && !Permissions
|
||||
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_KICK)) {
|
||||
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
@ -50,7 +45,8 @@ public class Kick extends SubCommand {
|
||||
for (UUID uuid : uuids) {
|
||||
if (uuid == DBFunc.everyone) {
|
||||
for (PlotPlayer pp : plot.getPlayersInPlot()) {
|
||||
if (pp == player || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_ENTRY_DENIED)) {
|
||||
if (pp == player || Permissions
|
||||
.hasPermission(pp, C.PERMISSION_ADMIN_ENTRY_DENIED)) {
|
||||
continue;
|
||||
}
|
||||
players.add(pp);
|
||||
@ -79,7 +75,8 @@ public class Kick extends SubCommand {
|
||||
Location spawn = WorldUtil.IMP.getSpawn(location.getWorld());
|
||||
C.YOU_GOT_KICKED.send(player2);
|
||||
if (plot.equals(spawn.getPlot())) {
|
||||
Location newSpawn = WorldUtil.IMP.getSpawn(PS.get().getPlotAreaManager().getAllWorlds()[0]);
|
||||
Location newSpawn =
|
||||
WorldUtil.IMP.getSpawn(PS.get().getPlotAreaManager().getAllWorlds()[0]);
|
||||
if (plot.equals(newSpawn.getPlot())) {
|
||||
// Kick from server if you can't be teleported to spawn
|
||||
player2.kick(C.YOU_GOT_KICKED.s());
|
||||
|
@ -9,20 +9,18 @@ import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.plotsquared.general.commands.Command;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(command = "leave",
|
||||
description = "Leave a plot",
|
||||
permission = "plots.leave",
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE)
|
||||
@CommandDeclaration(command = "leave", description = "Leave a plot", permission = "plots.leave", category = CommandCategory.CLAIMING, requiredType = RequiredType.NONE)
|
||||
public class Leave extends Command {
|
||||
public Leave() {
|
||||
super(MainCommand.getInstance(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
@Override public void execute(PlotPlayer player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
final Plot plot = check(player.getCurrentPlot(), C.NOT_IN_PLOT);
|
||||
checkTrue(plot.hasOwner(), C.PLOT_UNOWNED);
|
||||
checkTrue(plot.isAdded(player.getUUID()), C.NO_PLOT_PERMS);
|
||||
@ -45,4 +43,4 @@ public class Leave extends Command {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user