-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Yaml): Bukkit Yaml Configuration implementation.
- Loading branch information
1 parent
6ef3d45
commit 43ec2e0
Showing
18 changed files
with
2,877 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.georgev22.api.yaml; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Represents a source of configurable options and settings | ||
*/ | ||
public interface Configuration extends ConfigurationSection { | ||
/** | ||
* Sets the default value of the given path as provided. | ||
* <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> | ||
* If value is null, the value will be removed from the default | ||
* Configuration source. | ||
* | ||
* @param path Path of the value to set. | ||
* @param value Value to set the default to. | ||
* @throws IllegalArgumentException Thrown if path is null. | ||
*/ | ||
public void addDefault(String path, Object value); | ||
|
||
/** | ||
* Sets the default values of the given paths as provided. | ||
* <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. | ||
* | ||
* @param defaults A map of Path->Values to add to defaults. | ||
* @throws IllegalArgumentException Thrown if defaults is null. | ||
*/ | ||
public void addDefaults(Map<String, Object> defaults); | ||
|
||
/** | ||
* Sets the default values of the given paths as provided. | ||
* <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> | ||
* This method will not hold a reference to the specified Configuration, | ||
* nor will it automatically update if that Configuration ever changes. If | ||
* you require this, you should set the default source with {@link | ||
* #setDefaults(Configuration)}. | ||
* | ||
* @param defaults A configuration holding a list of defaults to copy. | ||
* @throws IllegalArgumentException Thrown if defaults is null or this. | ||
*/ | ||
public void addDefaults(Configuration defaults); | ||
|
||
/** | ||
* Sets the source of all default values for this {@link Configuration}. | ||
* <p> | ||
* If a previous source was set, or previous default values were defined, | ||
* then they will not be copied to the new source. | ||
* | ||
* @param defaults New source of default values for this configuration. | ||
* @throws IllegalArgumentException Thrown if defaults is null or this. | ||
*/ | ||
public void setDefaults(Configuration defaults); | ||
|
||
/** | ||
* Gets the source {@link Configuration} for this configuration. | ||
* <p> | ||
* If no configuration source was set, but default values were added, then | ||
* a {@link MemoryConfiguration} will be returned. If no source was set | ||
* and no defaults were set, then this method will return null. | ||
* | ||
* @return Configuration source for default values, or null if none exist. | ||
*/ | ||
public Configuration getDefaults(); | ||
|
||
/** | ||
* Gets the {@link ConfigurationOptions} for this {@link Configuration}. | ||
* <p> | ||
* All setters through this method are chainable. | ||
* | ||
* @return Options for this configuration | ||
*/ | ||
public ConfigurationOptions options(); | ||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/com/georgev22/api/yaml/ConfigurationOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.georgev22.api.yaml; | ||
|
||
/** | ||
* Various settings for controlling the input and output of a {@link | ||
* Configuration} | ||
*/ | ||
public class ConfigurationOptions { | ||
private char pathSeparator = '.'; | ||
private boolean copyDefaults = false; | ||
private final Configuration configuration; | ||
|
||
protected ConfigurationOptions(Configuration configuration) { | ||
this.configuration = configuration; | ||
} | ||
|
||
/** | ||
* Returns the {@link Configuration} that this object is responsible for. | ||
* | ||
* @return Parent configuration | ||
*/ | ||
public Configuration configuration() { | ||
return configuration; | ||
} | ||
|
||
/** | ||
* Gets the char that will be used to separate {@link | ||
* ConfigurationSection}s | ||
* <p> | ||
* This value does not affect how the {@link Configuration} is stored, | ||
* only in how you access the data. The default value is '.'. | ||
* | ||
* @return Path separator | ||
*/ | ||
public char pathSeparator() { | ||
return pathSeparator; | ||
} | ||
|
||
/** | ||
* Sets the char that will be used to separate {@link | ||
* ConfigurationSection}s | ||
* <p> | ||
* This value does not affect how the {@link Configuration} is stored, | ||
* only in how you access the data. The default value is '.'. | ||
* | ||
* @param value Path separator | ||
* @return This object, for chaining | ||
*/ | ||
public ConfigurationOptions pathSeparator(char value) { | ||
this.pathSeparator = value; | ||
return this; | ||
} | ||
|
||
/** | ||
* Checks if the {@link Configuration} should copy values from its default | ||
* {@link Configuration} directly. | ||
* <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, | ||
* {@link ConfigurationSection#contains(java.lang.String)} will always | ||
* return the same value as {@link | ||
* ConfigurationSection#isSet(java.lang.String)}. The default value is | ||
* false. | ||
* | ||
* @return Whether or not defaults are directly copied | ||
*/ | ||
public boolean copyDefaults() { | ||
return copyDefaults; | ||
} | ||
|
||
/** | ||
* Sets if the {@link Configuration} should copy values from its default | ||
* {@link Configuration} directly. | ||
* <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, | ||
* {@link ConfigurationSection#contains(java.lang.String)} will always | ||
* return the same value as {@link | ||
* ConfigurationSection#isSet(java.lang.String)}. The default value is | ||
* false. | ||
* | ||
* @param value Whether or not defaults are directly copied | ||
* @return This object, for chaining | ||
*/ | ||
public ConfigurationOptions copyDefaults(boolean value) { | ||
this.copyDefaults = value; | ||
return this; | ||
} | ||
} |
Oops, something went wrong.