mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-14 19:55:52 -07:00
SPIGOT-2540: Add nullability annotations to entire Bukkit API
By: Darkyenus <darkyenus@gmail.com>
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package org.bukkit.configuration;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -20,7 +23,7 @@ public interface Configuration extends ConfigurationSection {
|
||||
* @param value Value to set the default to.
|
||||
* @throws IllegalArgumentException Thrown if path is null.
|
||||
*/
|
||||
public void addDefault(String path, Object value);
|
||||
public void addDefault(@NotNull String path, @Nullable Object value);
|
||||
|
||||
/**
|
||||
* Sets the default values of the given paths as provided.
|
||||
@@ -32,7 +35,7 @@ public interface Configuration extends ConfigurationSection {
|
||||
* @param defaults A map of Path{@literal ->}Values to add to defaults.
|
||||
* @throws IllegalArgumentException Thrown if defaults is null.
|
||||
*/
|
||||
public void addDefaults(Map<String, Object> defaults);
|
||||
public void addDefaults(@NotNull Map<String, Object> defaults);
|
||||
|
||||
/**
|
||||
* Sets the default values of the given paths as provided.
|
||||
@@ -49,7 +52,7 @@ public interface Configuration extends ConfigurationSection {
|
||||
* @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);
|
||||
public void addDefaults(@NotNull Configuration defaults);
|
||||
|
||||
/**
|
||||
* Sets the source of all default values for this {@link Configuration}.
|
||||
@@ -60,7 +63,7 @@ public interface Configuration extends ConfigurationSection {
|
||||
* @param defaults New source of default values for this configuration.
|
||||
* @throws IllegalArgumentException Thrown if defaults is null or this.
|
||||
*/
|
||||
public void setDefaults(Configuration defaults);
|
||||
public void setDefaults(@NotNull Configuration defaults);
|
||||
|
||||
/**
|
||||
* Gets the source {@link Configuration} for this configuration.
|
||||
@@ -71,6 +74,7 @@ public interface Configuration extends ConfigurationSection {
|
||||
*
|
||||
* @return Configuration source for default values, or null if none exist.
|
||||
*/
|
||||
@Nullable
|
||||
public Configuration getDefaults();
|
||||
|
||||
/**
|
||||
@@ -80,5 +84,6 @@ public interface Configuration extends ConfigurationSection {
|
||||
*
|
||||
* @return Options for this configuration
|
||||
*/
|
||||
@NotNull
|
||||
public ConfigurationOptions options();
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.configuration;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Various settings for controlling the input and output of a {@link
|
||||
* Configuration}
|
||||
@@ -9,7 +11,7 @@ public class ConfigurationOptions {
|
||||
private boolean copyDefaults = false;
|
||||
private final Configuration configuration;
|
||||
|
||||
protected ConfigurationOptions(Configuration configuration) {
|
||||
protected ConfigurationOptions(@NotNull Configuration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@@ -18,6 +20,7 @@ public class ConfigurationOptions {
|
||||
*
|
||||
* @return Parent configuration
|
||||
*/
|
||||
@NotNull
|
||||
public Configuration configuration() {
|
||||
return configuration;
|
||||
}
|
||||
@@ -45,6 +48,7 @@ public class ConfigurationOptions {
|
||||
* @param value Path separator
|
||||
* @return This object, for chaining
|
||||
*/
|
||||
@NotNull
|
||||
public ConfigurationOptions pathSeparator(char value) {
|
||||
this.pathSeparator = value;
|
||||
return this;
|
||||
@@ -83,6 +87,7 @@ public class ConfigurationOptions {
|
||||
* @param value Whether or not defaults are directly copied
|
||||
* @return This object, for chaining
|
||||
*/
|
||||
@NotNull
|
||||
public ConfigurationOptions copyDefaults(boolean value) {
|
||||
this.copyDefaults = value;
|
||||
return this;
|
||||
|
@@ -9,6 +9,8 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a section of a {@link Configuration}
|
||||
@@ -28,6 +30,7 @@ public interface ConfigurationSection {
|
||||
* list.
|
||||
* @return Set of keys contained within this ConfigurationSection.
|
||||
*/
|
||||
@NotNull
|
||||
public Set<String> getKeys(boolean deep);
|
||||
|
||||
/**
|
||||
@@ -44,6 +47,7 @@ public interface ConfigurationSection {
|
||||
* list.
|
||||
* @return Map of keys and values of this section.
|
||||
*/
|
||||
@NotNull
|
||||
public Map<String, Object> getValues(boolean deep);
|
||||
|
||||
/**
|
||||
@@ -57,7 +61,7 @@ public interface ConfigurationSection {
|
||||
* default or being set.
|
||||
* @throws IllegalArgumentException Thrown when path is null.
|
||||
*/
|
||||
public boolean contains(String path);
|
||||
public boolean contains(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Checks if this {@link ConfigurationSection} contains the given path.
|
||||
@@ -76,7 +80,7 @@ public interface ConfigurationSection {
|
||||
* value exist and the boolean parameter for this method is true.
|
||||
* @throws IllegalArgumentException Thrown when path is null.
|
||||
*/
|
||||
public boolean contains(String path, boolean ignoreDefault);
|
||||
public boolean contains(@NotNull String path, boolean ignoreDefault);
|
||||
|
||||
/**
|
||||
* Checks if this {@link ConfigurationSection} has a value set for the
|
||||
@@ -90,7 +94,7 @@ public interface ConfigurationSection {
|
||||
* having a default.
|
||||
* @throws IllegalArgumentException Thrown when path is null.
|
||||
*/
|
||||
public boolean isSet(String path);
|
||||
public boolean isSet(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the path of this {@link ConfigurationSection} from its root {@link
|
||||
@@ -107,6 +111,7 @@ public interface ConfigurationSection {
|
||||
*
|
||||
* @return Path of this section relative to its root
|
||||
*/
|
||||
@Nullable
|
||||
public String getCurrentPath();
|
||||
|
||||
/**
|
||||
@@ -118,6 +123,7 @@ public interface ConfigurationSection {
|
||||
*
|
||||
* @return Name of this section
|
||||
*/
|
||||
@NotNull
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
@@ -132,6 +138,7 @@ public interface ConfigurationSection {
|
||||
*
|
||||
* @return Root configuration containing this section.
|
||||
*/
|
||||
@Nullable
|
||||
public Configuration getRoot();
|
||||
|
||||
/**
|
||||
@@ -145,6 +152,7 @@ public interface ConfigurationSection {
|
||||
*
|
||||
* @return Parent section containing this section.
|
||||
*/
|
||||
@Nullable
|
||||
public ConfigurationSection getParent();
|
||||
|
||||
/**
|
||||
@@ -157,7 +165,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the Object to get.
|
||||
* @return Requested Object.
|
||||
*/
|
||||
public Object get(String path);
|
||||
@Nullable
|
||||
public Object get(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested Object by path, returning a default value if not
|
||||
@@ -171,7 +180,8 @@ public interface ConfigurationSection {
|
||||
* @param def The default value to return if the path is not found.
|
||||
* @return Requested Object.
|
||||
*/
|
||||
public Object get(String path, Object def);
|
||||
@Nullable
|
||||
public Object get(@NotNull String path, @Nullable Object def);
|
||||
|
||||
/**
|
||||
* Sets the specified path to the given value.
|
||||
@@ -187,7 +197,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the object to set.
|
||||
* @param value New value to set the path to.
|
||||
*/
|
||||
public void set(String path, Object value);
|
||||
public void set(@NotNull String path, @Nullable Object value);
|
||||
|
||||
/**
|
||||
* Creates an empty {@link ConfigurationSection} at the specified path.
|
||||
@@ -199,7 +209,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path to create the section at.
|
||||
* @return Newly created section
|
||||
*/
|
||||
public ConfigurationSection createSection(String path);
|
||||
@NotNull
|
||||
public ConfigurationSection createSection(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Creates a {@link ConfigurationSection} at the specified path, with
|
||||
@@ -213,7 +224,8 @@ public interface ConfigurationSection {
|
||||
* @param map The values to used.
|
||||
* @return Newly created section
|
||||
*/
|
||||
public ConfigurationSection createSection(String path, Map<?, ?> map);
|
||||
@NotNull
|
||||
public ConfigurationSection createSection(@NotNull String path, @NotNull Map<?, ?> map);
|
||||
|
||||
// Primitives
|
||||
/**
|
||||
@@ -226,7 +238,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the String to get.
|
||||
* @return Requested String.
|
||||
*/
|
||||
public String getString(String path);
|
||||
@Nullable
|
||||
public String getString(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested String by path, returning a default value if not
|
||||
@@ -241,7 +254,8 @@ public interface ConfigurationSection {
|
||||
* not a String.
|
||||
* @return Requested String.
|
||||
*/
|
||||
public String getString(String path, String def);
|
||||
@Nullable
|
||||
public String getString(@NotNull String path, @Nullable String def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a String.
|
||||
@@ -254,7 +268,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the String to check.
|
||||
* @return Whether or not the specified path is a String.
|
||||
*/
|
||||
public boolean isString(String path);
|
||||
public boolean isString(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested int by path.
|
||||
@@ -266,7 +280,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the int to get.
|
||||
* @return Requested int.
|
||||
*/
|
||||
public int getInt(String path);
|
||||
public int getInt(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested int by path, returning a default value if not found.
|
||||
@@ -280,7 +294,7 @@ public interface ConfigurationSection {
|
||||
* not an int.
|
||||
* @return Requested int.
|
||||
*/
|
||||
public int getInt(String path, int def);
|
||||
public int getInt(@NotNull String path, int def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is an int.
|
||||
@@ -293,7 +307,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the int to check.
|
||||
* @return Whether or not the specified path is an int.
|
||||
*/
|
||||
public boolean isInt(String path);
|
||||
public boolean isInt(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested boolean by path.
|
||||
@@ -305,7 +319,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the boolean to get.
|
||||
* @return Requested boolean.
|
||||
*/
|
||||
public boolean getBoolean(String path);
|
||||
public boolean getBoolean(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested boolean by path, returning a default value if not
|
||||
@@ -320,7 +334,7 @@ public interface ConfigurationSection {
|
||||
* not a boolean.
|
||||
* @return Requested boolean.
|
||||
*/
|
||||
public boolean getBoolean(String path, boolean def);
|
||||
public boolean getBoolean(@NotNull String path, boolean def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a boolean.
|
||||
@@ -333,7 +347,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the boolean to check.
|
||||
* @return Whether or not the specified path is a boolean.
|
||||
*/
|
||||
public boolean isBoolean(String path);
|
||||
public boolean isBoolean(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested double by path.
|
||||
@@ -345,7 +359,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the double to get.
|
||||
* @return Requested double.
|
||||
*/
|
||||
public double getDouble(String path);
|
||||
public double getDouble(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested double by path, returning a default value if not
|
||||
@@ -360,7 +374,7 @@ public interface ConfigurationSection {
|
||||
* not a double.
|
||||
* @return Requested double.
|
||||
*/
|
||||
public double getDouble(String path, double def);
|
||||
public double getDouble(@NotNull String path, double def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a double.
|
||||
@@ -373,7 +387,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the double to check.
|
||||
* @return Whether or not the specified path is a double.
|
||||
*/
|
||||
public boolean isDouble(String path);
|
||||
public boolean isDouble(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested long by path.
|
||||
@@ -385,7 +399,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the long to get.
|
||||
* @return Requested long.
|
||||
*/
|
||||
public long getLong(String path);
|
||||
public long getLong(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested long by path, returning a default value if not
|
||||
@@ -400,7 +414,7 @@ public interface ConfigurationSection {
|
||||
* not a long.
|
||||
* @return Requested long.
|
||||
*/
|
||||
public long getLong(String path, long def);
|
||||
public long getLong(@NotNull String path, long def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a long.
|
||||
@@ -413,7 +427,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the long to check.
|
||||
* @return Whether or not the specified path is a long.
|
||||
*/
|
||||
public boolean isLong(String path);
|
||||
public boolean isLong(@NotNull String path);
|
||||
|
||||
// Java
|
||||
/**
|
||||
@@ -426,7 +440,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the List to get.
|
||||
* @return Requested List.
|
||||
*/
|
||||
public List<?> getList(String path);
|
||||
@Nullable
|
||||
public List<?> getList(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested List by path, returning a default value if not
|
||||
@@ -441,7 +456,8 @@ public interface ConfigurationSection {
|
||||
* not a List.
|
||||
* @return Requested List.
|
||||
*/
|
||||
public List<?> getList(String path, List<?> def);
|
||||
@Nullable
|
||||
public List<?> getList(@NotNull String path, @Nullable List<?> def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a List.
|
||||
@@ -454,7 +470,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the List to check.
|
||||
* @return Whether or not the specified path is a List.
|
||||
*/
|
||||
public boolean isList(String path);
|
||||
public boolean isList(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested List of String by path.
|
||||
@@ -469,7 +485,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the List to get.
|
||||
* @return Requested List of String.
|
||||
*/
|
||||
public List<String> getStringList(String path);
|
||||
@NotNull
|
||||
public List<String> getStringList(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested List of Integer by path.
|
||||
@@ -484,7 +501,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the List to get.
|
||||
* @return Requested List of Integer.
|
||||
*/
|
||||
public List<Integer> getIntegerList(String path);
|
||||
@NotNull
|
||||
public List<Integer> getIntegerList(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested List of Boolean by path.
|
||||
@@ -499,7 +517,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the List to get.
|
||||
* @return Requested List of Boolean.
|
||||
*/
|
||||
public List<Boolean> getBooleanList(String path);
|
||||
@NotNull
|
||||
public List<Boolean> getBooleanList(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested List of Double by path.
|
||||
@@ -514,7 +533,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the List to get.
|
||||
* @return Requested List of Double.
|
||||
*/
|
||||
public List<Double> getDoubleList(String path);
|
||||
@NotNull
|
||||
public List<Double> getDoubleList(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested List of Float by path.
|
||||
@@ -529,7 +549,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the List to get.
|
||||
* @return Requested List of Float.
|
||||
*/
|
||||
public List<Float> getFloatList(String path);
|
||||
@NotNull
|
||||
public List<Float> getFloatList(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested List of Long by path.
|
||||
@@ -544,7 +565,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the List to get.
|
||||
* @return Requested List of Long.
|
||||
*/
|
||||
public List<Long> getLongList(String path);
|
||||
@NotNull
|
||||
public List<Long> getLongList(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested List of Byte by path.
|
||||
@@ -559,7 +581,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the List to get.
|
||||
* @return Requested List of Byte.
|
||||
*/
|
||||
public List<Byte> getByteList(String path);
|
||||
@NotNull
|
||||
public List<Byte> getByteList(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested List of Character by path.
|
||||
@@ -574,7 +597,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the List to get.
|
||||
* @return Requested List of Character.
|
||||
*/
|
||||
public List<Character> getCharacterList(String path);
|
||||
@NotNull
|
||||
public List<Character> getCharacterList(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested List of Short by path.
|
||||
@@ -589,7 +613,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the List to get.
|
||||
* @return Requested List of Short.
|
||||
*/
|
||||
public List<Short> getShortList(String path);
|
||||
@NotNull
|
||||
public List<Short> getShortList(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested List of Maps by path.
|
||||
@@ -604,7 +629,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the List to get.
|
||||
* @return Requested List of Maps.
|
||||
*/
|
||||
public List<Map<?, ?>> getMapList(String path);
|
||||
@NotNull
|
||||
public List<Map<?, ?>> getMapList(@NotNull String path);
|
||||
|
||||
// Bukkit
|
||||
/**
|
||||
@@ -620,7 +646,8 @@ public interface ConfigurationSection {
|
||||
* @param clazz the type of {@link ConfigurationSerializable}
|
||||
* @return Requested {@link ConfigurationSerializable} object
|
||||
*/
|
||||
public <T extends ConfigurationSerializable> T getSerializable(String path, Class<T> clazz);
|
||||
@Nullable
|
||||
public <T extends ConfigurationSerializable> T getSerializable(@NotNull String path, @NotNull Class<T> clazz);
|
||||
|
||||
/**
|
||||
* Gets the requested {@link ConfigurationSerializable} object at the given
|
||||
@@ -637,7 +664,8 @@ public interface ConfigurationSection {
|
||||
* the path
|
||||
* @return Requested {@link ConfigurationSerializable} object
|
||||
*/
|
||||
public <T extends ConfigurationSerializable> T getSerializable(String path, Class<T> clazz, T def);
|
||||
@Nullable
|
||||
public <T extends ConfigurationSerializable> T getSerializable(@NotNull String path, @NotNull Class<T> clazz, @Nullable T def);
|
||||
|
||||
/**
|
||||
* Gets the requested Vector by path.
|
||||
@@ -649,7 +677,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the Vector to get.
|
||||
* @return Requested Vector.
|
||||
*/
|
||||
public Vector getVector(String path);
|
||||
@Nullable
|
||||
public Vector getVector(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested {@link Vector} by path, returning a default value if
|
||||
@@ -664,7 +693,8 @@ public interface ConfigurationSection {
|
||||
* not a Vector.
|
||||
* @return Requested Vector.
|
||||
*/
|
||||
public Vector getVector(String path, Vector def);
|
||||
@Nullable
|
||||
public Vector getVector(@NotNull String path, @Nullable Vector def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a Vector.
|
||||
@@ -677,7 +707,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the Vector to check.
|
||||
* @return Whether or not the specified path is a Vector.
|
||||
*/
|
||||
public boolean isVector(String path);
|
||||
public boolean isVector(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested OfflinePlayer by path.
|
||||
@@ -690,7 +720,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the OfflinePlayer to get.
|
||||
* @return Requested OfflinePlayer.
|
||||
*/
|
||||
public OfflinePlayer getOfflinePlayer(String path);
|
||||
@Nullable
|
||||
public OfflinePlayer getOfflinePlayer(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested {@link OfflinePlayer} by path, returning a default
|
||||
@@ -705,7 +736,8 @@ public interface ConfigurationSection {
|
||||
* not an OfflinePlayer.
|
||||
* @return Requested OfflinePlayer.
|
||||
*/
|
||||
public OfflinePlayer getOfflinePlayer(String path, OfflinePlayer def);
|
||||
@Nullable
|
||||
public OfflinePlayer getOfflinePlayer(@NotNull String path, @Nullable OfflinePlayer def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is an OfflinePlayer.
|
||||
@@ -718,7 +750,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the OfflinePlayer to check.
|
||||
* @return Whether or not the specified path is an OfflinePlayer.
|
||||
*/
|
||||
public boolean isOfflinePlayer(String path);
|
||||
public boolean isOfflinePlayer(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested ItemStack by path.
|
||||
@@ -730,7 +762,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the ItemStack to get.
|
||||
* @return Requested ItemStack.
|
||||
*/
|
||||
public ItemStack getItemStack(String path);
|
||||
@Nullable
|
||||
public ItemStack getItemStack(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested {@link ItemStack} by path, returning a default value
|
||||
@@ -745,7 +778,8 @@ public interface ConfigurationSection {
|
||||
* not an ItemStack.
|
||||
* @return Requested ItemStack.
|
||||
*/
|
||||
public ItemStack getItemStack(String path, ItemStack def);
|
||||
@Nullable
|
||||
public ItemStack getItemStack(@NotNull String path, @Nullable ItemStack def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is an ItemStack.
|
||||
@@ -758,7 +792,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the ItemStack to check.
|
||||
* @return Whether or not the specified path is an ItemStack.
|
||||
*/
|
||||
public boolean isItemStack(String path);
|
||||
public boolean isItemStack(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested Color by path.
|
||||
@@ -770,7 +804,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the Color to get.
|
||||
* @return Requested Color.
|
||||
*/
|
||||
public Color getColor(String path);
|
||||
@Nullable
|
||||
public Color getColor(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested {@link Color} by path, returning a default value if
|
||||
@@ -785,7 +820,8 @@ public interface ConfigurationSection {
|
||||
* not a Color.
|
||||
* @return Requested Color.
|
||||
*/
|
||||
public Color getColor(String path, Color def);
|
||||
@Nullable
|
||||
public Color getColor(@NotNull String path, @Nullable Color def);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a Color.
|
||||
@@ -798,7 +834,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the Color to check.
|
||||
* @return Whether or not the specified path is a Color.
|
||||
*/
|
||||
public boolean isColor(String path);
|
||||
public boolean isColor(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the requested ConfigurationSection by path.
|
||||
@@ -811,7 +847,8 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the ConfigurationSection to get.
|
||||
* @return Requested ConfigurationSection.
|
||||
*/
|
||||
public ConfigurationSection getConfigurationSection(String path);
|
||||
@Nullable
|
||||
public ConfigurationSection getConfigurationSection(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Checks if the specified path is a ConfigurationSection.
|
||||
@@ -825,7 +862,7 @@ public interface ConfigurationSection {
|
||||
* @param path Path of the ConfigurationSection to check.
|
||||
* @return Whether or not the specified path is a ConfigurationSection.
|
||||
*/
|
||||
public boolean isConfigurationSection(String path);
|
||||
public boolean isConfigurationSection(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Gets the equivalent {@link ConfigurationSection} from the default
|
||||
@@ -837,6 +874,7 @@ public interface ConfigurationSection {
|
||||
*
|
||||
* @return Equivalent section in root configuration
|
||||
*/
|
||||
@Nullable
|
||||
public ConfigurationSection getDefaultSection();
|
||||
|
||||
/**
|
||||
@@ -857,5 +895,5 @@ public interface ConfigurationSection {
|
||||
* @param value Value to set the default to.
|
||||
* @throws IllegalArgumentException Thrown if path is null.
|
||||
*/
|
||||
public void addDefault(String path, Object value);
|
||||
public void addDefault(@NotNull String path, @Nullable Object value);
|
||||
}
|
||||
|
@@ -3,6 +3,8 @@ package org.bukkit.configuration;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This is a {@link Configuration} implementation that does not save or load
|
||||
@@ -25,12 +27,12 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
||||
* @param defaults Default value provider
|
||||
* @throws IllegalArgumentException Thrown if defaults is null
|
||||
*/
|
||||
public MemoryConfiguration(Configuration defaults) {
|
||||
public MemoryConfiguration(@Nullable Configuration defaults) {
|
||||
this.defaults = defaults;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefault(String path, Object value) {
|
||||
public void addDefault(@NotNull String path, @Nullable Object value) {
|
||||
Validate.notNull(path, "Path may not be null");
|
||||
|
||||
if (defaults == null) {
|
||||
@@ -40,7 +42,7 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
||||
defaults.set(path, value);
|
||||
}
|
||||
|
||||
public void addDefaults(Map<String, Object> defaults) {
|
||||
public void addDefaults(@NotNull Map<String, Object> defaults) {
|
||||
Validate.notNull(defaults, "Defaults may not be null");
|
||||
|
||||
for (Map.Entry<String, Object> entry : defaults.entrySet()) {
|
||||
@@ -48,27 +50,30 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
||||
}
|
||||
}
|
||||
|
||||
public void addDefaults(Configuration defaults) {
|
||||
public void addDefaults(@NotNull Configuration defaults) {
|
||||
Validate.notNull(defaults, "Defaults may not be null");
|
||||
|
||||
addDefaults(defaults.getValues(true));
|
||||
}
|
||||
|
||||
public void setDefaults(Configuration defaults) {
|
||||
public void setDefaults(@NotNull Configuration defaults) {
|
||||
Validate.notNull(defaults, "Defaults may not be null");
|
||||
|
||||
this.defaults = defaults;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Configuration getDefaults() {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ConfigurationSection getParent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MemoryConfigurationOptions options() {
|
||||
if (options == null) {
|
||||
options = new MemoryConfigurationOptions(this);
|
||||
|
@@ -1,25 +1,30 @@
|
||||
package org.bukkit.configuration;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Various settings for controlling the input and output of a {@link
|
||||
* MemoryConfiguration}
|
||||
*/
|
||||
public class MemoryConfigurationOptions extends ConfigurationOptions {
|
||||
protected MemoryConfigurationOptions(MemoryConfiguration configuration) {
|
||||
protected MemoryConfigurationOptions(@NotNull MemoryConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MemoryConfiguration configuration() {
|
||||
return (MemoryConfiguration) super.configuration();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MemoryConfigurationOptions copyDefaults(boolean value) {
|
||||
super.copyDefaults(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MemoryConfigurationOptions pathSeparator(char value) {
|
||||
super.pathSeparator(value);
|
||||
|
@@ -15,6 +15,8 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A type of {@link ConfigurationSection} that is stored in memory.
|
||||
@@ -56,7 +58,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
* @throws IllegalArgumentException Thrown is parent or path is null, or
|
||||
* if parent contains no root Configuration.
|
||||
*/
|
||||
protected MemorySection(ConfigurationSection parent, String path) {
|
||||
protected MemorySection(@NotNull ConfigurationSection parent, @NotNull String path) {
|
||||
Validate.notNull(parent, "Parent cannot be null");
|
||||
Validate.notNull(path, "Path cannot be null");
|
||||
|
||||
@@ -69,6 +71,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
this.fullPath = createPath(parent, path);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<String> getKeys(boolean deep) {
|
||||
Set<String> result = new LinkedHashSet<String>();
|
||||
|
||||
@@ -86,6 +89,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<String, Object> getValues(boolean deep) {
|
||||
Map<String, Object> result = new LinkedHashMap<String, Object>();
|
||||
|
||||
@@ -103,15 +107,15 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean contains(String path) {
|
||||
public boolean contains(@NotNull String path) {
|
||||
return contains(path, false);
|
||||
}
|
||||
|
||||
public boolean contains(String path, boolean ignoreDefault) {
|
||||
public boolean contains(@NotNull String path, boolean ignoreDefault) {
|
||||
return ((ignoreDefault) ? get(path, null) : get(path)) != null;
|
||||
}
|
||||
|
||||
public boolean isSet(String path) {
|
||||
public boolean isSet(@NotNull String path) {
|
||||
Configuration root = getRoot();
|
||||
if (root == null) {
|
||||
return false;
|
||||
@@ -122,23 +126,27 @@ public class MemorySection implements ConfigurationSection {
|
||||
return get(path, null) != null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getCurrentPath() {
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Configuration getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ConfigurationSection getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void addDefault(String path, Object value) {
|
||||
public void addDefault(@NotNull String path, @Nullable Object value) {
|
||||
Validate.notNull(path, "Path cannot be null");
|
||||
|
||||
Configuration root = getRoot();
|
||||
@@ -151,6 +159,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
root.addDefault(createPath(this, path), value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ConfigurationSection getDefaultSection() {
|
||||
Configuration root = getRoot();
|
||||
Configuration defaults = root == null ? null : root.getDefaults();
|
||||
@@ -164,7 +173,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void set(String path, Object value) {
|
||||
public void set(@NotNull String path, @Nullable Object value) {
|
||||
Validate.notEmpty(path, "Cannot set to an empty path");
|
||||
|
||||
Configuration root = getRoot();
|
||||
@@ -203,11 +212,13 @@ public class MemorySection implements ConfigurationSection {
|
||||
}
|
||||
}
|
||||
|
||||
public Object get(String path) {
|
||||
@Nullable
|
||||
public Object get(@NotNull String path) {
|
||||
return get(path, getDefault(path));
|
||||
}
|
||||
|
||||
public Object get(String path, Object def) {
|
||||
@Nullable
|
||||
public Object get(@NotNull String path, @Nullable Object def) {
|
||||
Validate.notNull(path, "Path cannot be null");
|
||||
|
||||
if (path.length() == 0) {
|
||||
@@ -239,7 +250,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
return section.get(key, def);
|
||||
}
|
||||
|
||||
public ConfigurationSection createSection(String path) {
|
||||
@NotNull
|
||||
public ConfigurationSection createSection(@NotNull String path) {
|
||||
Validate.notEmpty(path, "Cannot create section at empty path");
|
||||
Configuration root = getRoot();
|
||||
if (root == null) {
|
||||
@@ -270,7 +282,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
return section.createSection(key);
|
||||
}
|
||||
|
||||
public ConfigurationSection createSection(String path, Map<?, ?> map) {
|
||||
@NotNull
|
||||
public ConfigurationSection createSection(@NotNull String path, @NotNull Map<?, ?> map) {
|
||||
ConfigurationSection section = createSection(path);
|
||||
|
||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||
@@ -285,98 +298,103 @@ public class MemorySection implements ConfigurationSection {
|
||||
}
|
||||
|
||||
// Primitives
|
||||
public String getString(String path) {
|
||||
@Nullable
|
||||
public String getString(@NotNull String path) {
|
||||
Object def = getDefault(path);
|
||||
return getString(path, def != null ? def.toString() : null);
|
||||
}
|
||||
|
||||
public String getString(String path, String def) {
|
||||
@Nullable
|
||||
public String getString(@NotNull String path, @Nullable String def) {
|
||||
Object val = get(path, def);
|
||||
return (val != null) ? val.toString() : def;
|
||||
}
|
||||
|
||||
public boolean isString(String path) {
|
||||
public boolean isString(@NotNull String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof String;
|
||||
}
|
||||
|
||||
public int getInt(String path) {
|
||||
public int getInt(@NotNull String path) {
|
||||
Object def = getDefault(path);
|
||||
return getInt(path, (def instanceof Number) ? toInt(def) : 0);
|
||||
}
|
||||
|
||||
public int getInt(String path, int def) {
|
||||
public int getInt(@NotNull String path, int def) {
|
||||
Object val = get(path, def);
|
||||
return (val instanceof Number) ? toInt(val) : def;
|
||||
}
|
||||
|
||||
public boolean isInt(String path) {
|
||||
public boolean isInt(@NotNull String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof Integer;
|
||||
}
|
||||
|
||||
public boolean getBoolean(String path) {
|
||||
public boolean getBoolean(@NotNull String path) {
|
||||
Object def = getDefault(path);
|
||||
return getBoolean(path, (def instanceof Boolean) ? (Boolean) def : false);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String path, boolean def) {
|
||||
public boolean getBoolean(@NotNull String path, boolean def) {
|
||||
Object val = get(path, def);
|
||||
return (val instanceof Boolean) ? (Boolean) val : def;
|
||||
}
|
||||
|
||||
public boolean isBoolean(String path) {
|
||||
public boolean isBoolean(@NotNull String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof Boolean;
|
||||
}
|
||||
|
||||
public double getDouble(String path) {
|
||||
public double getDouble(@NotNull String path) {
|
||||
Object def = getDefault(path);
|
||||
return getDouble(path, (def instanceof Number) ? toDouble(def) : 0);
|
||||
}
|
||||
|
||||
public double getDouble(String path, double def) {
|
||||
public double getDouble(@NotNull String path, double def) {
|
||||
Object val = get(path, def);
|
||||
return (val instanceof Number) ? toDouble(val) : def;
|
||||
}
|
||||
|
||||
public boolean isDouble(String path) {
|
||||
public boolean isDouble(@NotNull String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof Double;
|
||||
}
|
||||
|
||||
public long getLong(String path) {
|
||||
public long getLong(@NotNull String path) {
|
||||
Object def = getDefault(path);
|
||||
return getLong(path, (def instanceof Number) ? toLong(def) : 0);
|
||||
}
|
||||
|
||||
public long getLong(String path, long def) {
|
||||
public long getLong(@NotNull String path, long def) {
|
||||
Object val = get(path, def);
|
||||
return (val instanceof Number) ? toLong(val) : def;
|
||||
}
|
||||
|
||||
public boolean isLong(String path) {
|
||||
public boolean isLong(@NotNull String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof Long;
|
||||
}
|
||||
|
||||
// Java
|
||||
public List<?> getList(String path) {
|
||||
@Nullable
|
||||
public List<?> getList(@NotNull String path) {
|
||||
Object def = getDefault(path);
|
||||
return getList(path, (def instanceof List) ? (List<?>) def : null);
|
||||
}
|
||||
|
||||
public List<?> getList(String path, List<?> def) {
|
||||
@Nullable
|
||||
public List<?> getList(@NotNull String path, @Nullable List<?> def) {
|
||||
Object val = get(path, def);
|
||||
return (List<?>) ((val instanceof List) ? val : def);
|
||||
}
|
||||
|
||||
public boolean isList(String path) {
|
||||
public boolean isList(@NotNull String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof List;
|
||||
}
|
||||
|
||||
public List<String> getStringList(String path) {
|
||||
@NotNull
|
||||
public List<String> getStringList(@NotNull String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
if (list == null) {
|
||||
@@ -394,7 +412,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Integer> getIntegerList(String path) {
|
||||
@NotNull
|
||||
public List<Integer> getIntegerList(@NotNull String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
if (list == null) {
|
||||
@@ -421,7 +440,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Boolean> getBooleanList(String path) {
|
||||
@NotNull
|
||||
public List<Boolean> getBooleanList(@NotNull String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
if (list == null) {
|
||||
@@ -445,7 +465,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Double> getDoubleList(String path) {
|
||||
@NotNull
|
||||
public List<Double> getDoubleList(@NotNull String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
if (list == null) {
|
||||
@@ -472,7 +493,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Float> getFloatList(String path) {
|
||||
@NotNull
|
||||
public List<Float> getFloatList(@NotNull String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
if (list == null) {
|
||||
@@ -499,7 +521,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Long> getLongList(String path) {
|
||||
@NotNull
|
||||
public List<Long> getLongList(@NotNull String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
if (list == null) {
|
||||
@@ -526,7 +549,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Byte> getByteList(String path) {
|
||||
@NotNull
|
||||
public List<Byte> getByteList(@NotNull String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
if (list == null) {
|
||||
@@ -553,7 +577,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Character> getCharacterList(String path) {
|
||||
@NotNull
|
||||
public List<Character> getCharacterList(@NotNull String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
if (list == null) {
|
||||
@@ -579,7 +604,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Short> getShortList(String path) {
|
||||
@NotNull
|
||||
public List<Short> getShortList(@NotNull String path) {
|
||||
List<?> list = getList(path);
|
||||
|
||||
if (list == null) {
|
||||
@@ -606,7 +632,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Map<?, ?>> getMapList(String path) {
|
||||
@NotNull
|
||||
public List<Map<?, ?>> getMapList(@NotNull String path) {
|
||||
List<?> list = getList(path);
|
||||
List<Map<?, ?>> result = new ArrayList<Map<?, ?>>();
|
||||
|
||||
@@ -624,69 +651,80 @@ public class MemorySection implements ConfigurationSection {
|
||||
}
|
||||
|
||||
// Bukkit
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends ConfigurationSerializable> T getSerializable(String path, Class<T> clazz) {
|
||||
public <T extends ConfigurationSerializable> T getSerializable(@NotNull String path, @NotNull Class<T> clazz) {
|
||||
Validate.notNull(clazz, "ConfigurationSerializable class cannot be null");
|
||||
Object def = getDefault(path);
|
||||
return getSerializable(path, clazz, (def != null && clazz.isInstance(def)) ? clazz.cast(def) : null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends ConfigurationSerializable> T getSerializable(String path, Class<T> clazz, T def) {
|
||||
public <T extends ConfigurationSerializable> T getSerializable(@NotNull String path, @NotNull Class<T> clazz, @Nullable T def) {
|
||||
Validate.notNull(clazz, "ConfigurationSerializable class cannot be null");
|
||||
Object val = get(path);
|
||||
return (val != null && clazz.isInstance(val)) ? clazz.cast(val) : def;
|
||||
}
|
||||
|
||||
public Vector getVector(String path) {
|
||||
@Nullable
|
||||
public Vector getVector(@NotNull String path) {
|
||||
return getSerializable(path, Vector.class);
|
||||
}
|
||||
|
||||
public Vector getVector(String path, Vector def) {
|
||||
@Nullable
|
||||
public Vector getVector(@NotNull String path, @Nullable Vector def) {
|
||||
return getSerializable(path, Vector.class, def);
|
||||
}
|
||||
|
||||
public boolean isVector(String path) {
|
||||
public boolean isVector(@NotNull String path) {
|
||||
return getSerializable(path, Vector.class) != null;
|
||||
}
|
||||
|
||||
public OfflinePlayer getOfflinePlayer(String path) {
|
||||
@Nullable
|
||||
public OfflinePlayer getOfflinePlayer(@NotNull String path) {
|
||||
return getSerializable(path, OfflinePlayer.class);
|
||||
}
|
||||
|
||||
public OfflinePlayer getOfflinePlayer(String path, OfflinePlayer def) {
|
||||
@Nullable
|
||||
public OfflinePlayer getOfflinePlayer(@NotNull String path, @Nullable OfflinePlayer def) {
|
||||
return getSerializable(path, OfflinePlayer.class, def);
|
||||
}
|
||||
|
||||
public boolean isOfflinePlayer(String path) {
|
||||
public boolean isOfflinePlayer(@NotNull String path) {
|
||||
return getSerializable(path, OfflinePlayer.class) != null;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(String path) {
|
||||
@Nullable
|
||||
public ItemStack getItemStack(@NotNull String path) {
|
||||
return getSerializable(path, ItemStack.class);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(String path, ItemStack def) {
|
||||
@Nullable
|
||||
public ItemStack getItemStack(@NotNull String path, @Nullable ItemStack def) {
|
||||
return getSerializable(path, ItemStack.class, def);
|
||||
}
|
||||
|
||||
public boolean isItemStack(String path) {
|
||||
public boolean isItemStack(@NotNull String path) {
|
||||
return getSerializable(path, ItemStack.class) != null;
|
||||
}
|
||||
|
||||
public Color getColor(String path) {
|
||||
@Nullable
|
||||
public Color getColor(@NotNull String path) {
|
||||
return getSerializable(path, Color.class);
|
||||
}
|
||||
|
||||
public Color getColor(String path, Color def) {
|
||||
@Nullable
|
||||
public Color getColor(@NotNull String path, @Nullable Color def) {
|
||||
return getSerializable(path, Color.class, def);
|
||||
}
|
||||
|
||||
public boolean isColor(String path) {
|
||||
public boolean isColor(@NotNull String path) {
|
||||
return getSerializable(path, Color.class) != null;
|
||||
}
|
||||
|
||||
public ConfigurationSection getConfigurationSection(String path) {
|
||||
@Nullable
|
||||
public ConfigurationSection getConfigurationSection(@NotNull String path) {
|
||||
Object val = get(path, null);
|
||||
if (val != null) {
|
||||
return (val instanceof ConfigurationSection) ? (ConfigurationSection) val : null;
|
||||
@@ -696,19 +734,20 @@ public class MemorySection implements ConfigurationSection {
|
||||
return (val instanceof ConfigurationSection) ? createSection(path) : null;
|
||||
}
|
||||
|
||||
public boolean isConfigurationSection(String path) {
|
||||
public boolean isConfigurationSection(@NotNull String path) {
|
||||
Object val = get(path);
|
||||
return val instanceof ConfigurationSection;
|
||||
}
|
||||
|
||||
protected boolean isPrimitiveWrapper(Object input) {
|
||||
protected boolean isPrimitiveWrapper(@Nullable 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;
|
||||
}
|
||||
|
||||
protected Object getDefault(String path) {
|
||||
@Nullable
|
||||
protected Object getDefault(@NotNull String path) {
|
||||
Validate.notNull(path, "Path cannot be null");
|
||||
|
||||
Configuration root = getRoot();
|
||||
@@ -716,7 +755,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
return (defaults == null) ? null : defaults.get(createPath(this, path));
|
||||
}
|
||||
|
||||
protected void mapChildrenKeys(Set<String> output, ConfigurationSection section, boolean deep) {
|
||||
protected void mapChildrenKeys(@NotNull Set<String> output, @NotNull ConfigurationSection section, boolean deep) {
|
||||
if (section instanceof MemorySection) {
|
||||
MemorySection sec = (MemorySection) section;
|
||||
|
||||
@@ -737,7 +776,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
}
|
||||
}
|
||||
|
||||
protected void mapChildrenValues(Map<String, Object> output, ConfigurationSection section, boolean deep) {
|
||||
protected void mapChildrenValues(@NotNull Map<String, Object> output, @NotNull ConfigurationSection section, boolean deep) {
|
||||
if (section instanceof MemorySection) {
|
||||
MemorySection sec = (MemorySection) section;
|
||||
|
||||
@@ -775,7 +814,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
* @param key Name of the specified section.
|
||||
* @return Full path of the section from its root.
|
||||
*/
|
||||
public static String createPath(ConfigurationSection section, String key) {
|
||||
@NotNull
|
||||
public static String createPath(@NotNull ConfigurationSection section, @Nullable String key) {
|
||||
return createPath(section, key, (section == null) ? null : section.getRoot());
|
||||
}
|
||||
|
||||
@@ -791,7 +831,8 @@ public class MemorySection implements ConfigurationSection {
|
||||
* @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) {
|
||||
@NotNull
|
||||
public static String createPath(@NotNull ConfigurationSection section, @Nullable String key, @Nullable ConfigurationSection relativeTo) {
|
||||
Validate.notNull(section, "Cannot create path without a section");
|
||||
Configuration root = section.getRoot();
|
||||
if (root == null) {
|
||||
|
@@ -19,6 +19,8 @@ import java.io.Writer;
|
||||
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This is a base class for all File based implementations of {@link
|
||||
@@ -39,7 +41,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
*
|
||||
* @param defaults Default value provider
|
||||
*/
|
||||
public FileConfiguration(Configuration defaults) {
|
||||
public FileConfiguration(@Nullable Configuration defaults) {
|
||||
super(defaults);
|
||||
}
|
||||
|
||||
@@ -58,7 +60,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* any reason.
|
||||
* @throws IllegalArgumentException Thrown when file is null.
|
||||
*/
|
||||
public void save(File file) throws IOException {
|
||||
public void save(@NotNull File file) throws IOException {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
|
||||
Files.createParentDirs(file);
|
||||
@@ -89,7 +91,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* any reason.
|
||||
* @throws IllegalArgumentException Thrown when file is null.
|
||||
*/
|
||||
public void save(String file) throws IOException {
|
||||
public void save(@NotNull String file) throws IOException {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
|
||||
save(new File(file));
|
||||
@@ -100,6 +102,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
*
|
||||
* @return String containing this configuration.
|
||||
*/
|
||||
@NotNull
|
||||
public abstract String saveToString();
|
||||
|
||||
/**
|
||||
@@ -120,7 +123,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* a valid Configuration.
|
||||
* @throws IllegalArgumentException Thrown when file is null.
|
||||
*/
|
||||
public void load(File file) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||
public void load(@NotNull File file) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
|
||||
final FileInputStream stream = new FileInputStream(file);
|
||||
@@ -141,7 +144,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* represent a valid Configuration
|
||||
* @throws IllegalArgumentException thrown when reader is null
|
||||
*/
|
||||
public void load(Reader reader) throws IOException, InvalidConfigurationException {
|
||||
public void load(@NotNull Reader reader) throws IOException, InvalidConfigurationException {
|
||||
BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@@ -178,7 +181,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* a valid Configuration.
|
||||
* @throws IllegalArgumentException Thrown when file is null.
|
||||
*/
|
||||
public void load(String file) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||
public void load(@NotNull String file) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
|
||||
load(new File(file));
|
||||
@@ -199,7 +202,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* invalid.
|
||||
* @throws IllegalArgumentException Thrown if contents is null.
|
||||
*/
|
||||
public abstract void loadFromString(String contents) throws InvalidConfigurationException;
|
||||
public abstract void loadFromString(@NotNull String contents) throws InvalidConfigurationException;
|
||||
|
||||
/**
|
||||
* Compiles the header for this {@link FileConfiguration} and returns the
|
||||
@@ -211,8 +214,10 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
*
|
||||
* @return Compiled header
|
||||
*/
|
||||
@NotNull
|
||||
protected abstract String buildHeader();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FileConfigurationOptions options() {
|
||||
if (options == null) {
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package org.bukkit.configuration.file;
|
||||
|
||||
import org.bukkit.configuration.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Various settings for controlling the input and output of a {@link
|
||||
@@ -10,21 +12,24 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||
private String header = null;
|
||||
private boolean copyHeader = true;
|
||||
|
||||
protected FileConfigurationOptions(MemoryConfiguration configuration) {
|
||||
protected FileConfigurationOptions(@NotNull MemoryConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FileConfiguration configuration() {
|
||||
return (FileConfiguration) super.configuration();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FileConfigurationOptions copyDefaults(boolean value) {
|
||||
super.copyDefaults(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FileConfigurationOptions pathSeparator(char value) {
|
||||
super.pathSeparator(value);
|
||||
@@ -45,6 +50,7 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||
*
|
||||
* @return Header
|
||||
*/
|
||||
@Nullable
|
||||
public String header() {
|
||||
return header;
|
||||
}
|
||||
@@ -64,7 +70,8 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||
* @param value New header
|
||||
* @return This object, for chaining
|
||||
*/
|
||||
public FileConfigurationOptions header(String value) {
|
||||
@NotNull
|
||||
public FileConfigurationOptions header(@Nullable String value) {
|
||||
this.header = value;
|
||||
return this;
|
||||
}
|
||||
@@ -110,6 +117,7 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||
* @param value Whether or not to copy the header
|
||||
* @return This object, for chaining
|
||||
*/
|
||||
@NotNull
|
||||
public FileConfigurationOptions copyHeader(boolean value) {
|
||||
copyHeader = value;
|
||||
|
||||
|
@@ -12,6 +12,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
@@ -28,6 +29,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
private final Representer yamlRepresenter = new YamlRepresenter();
|
||||
private final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String saveToString() {
|
||||
yamlOptions.setIndent(options().indent());
|
||||
@@ -45,7 +47,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFromString(String contents) throws InvalidConfigurationException {
|
||||
public void loadFromString(@NotNull String contents) throws InvalidConfigurationException {
|
||||
Validate.notNull(contents, "Contents cannot be null");
|
||||
|
||||
Map<?, ?> input;
|
||||
@@ -67,7 +69,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
protected void convertMapsToSections(Map<?, ?> input, ConfigurationSection section) {
|
||||
protected void convertMapsToSections(@NotNull Map<?, ?> input, @NotNull ConfigurationSection section) {
|
||||
for (Map.Entry<?, ?> entry : input.entrySet()) {
|
||||
String key = entry.getKey().toString();
|
||||
Object value = entry.getValue();
|
||||
@@ -80,7 +82,8 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
protected String parseHeader(String input) {
|
||||
@NotNull
|
||||
protected String parseHeader(@NotNull String input) {
|
||||
String[] lines = input.split("\r?\n", -1);
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean readingHeader = true;
|
||||
@@ -109,6 +112,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String buildHeader() {
|
||||
String header = options().header();
|
||||
@@ -147,6 +151,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public YamlConfigurationOptions options() {
|
||||
if (options == null) {
|
||||
@@ -169,7 +174,8 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
* @return Resulting configuration
|
||||
* @throws IllegalArgumentException Thrown if file is null
|
||||
*/
|
||||
public static YamlConfiguration loadConfiguration(File file) {
|
||||
@NotNull
|
||||
public static YamlConfiguration loadConfiguration(@NotNull File file) {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
@@ -197,7 +203,8 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
* @return resulting configuration
|
||||
* @throws IllegalArgumentException Thrown if stream is null
|
||||
*/
|
||||
public static YamlConfiguration loadConfiguration(Reader reader) {
|
||||
@NotNull
|
||||
public static YamlConfiguration loadConfiguration(@NotNull Reader reader) {
|
||||
Validate.notNull(reader, "Stream cannot be null");
|
||||
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package org.bukkit.configuration.file;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Various settings for controlling the input and output of a {@link
|
||||
@@ -9,33 +11,38 @@ import org.apache.commons.lang.Validate;
|
||||
public class YamlConfigurationOptions extends FileConfigurationOptions {
|
||||
private int indent = 2;
|
||||
|
||||
protected YamlConfigurationOptions(YamlConfiguration configuration) {
|
||||
protected YamlConfigurationOptions(@NotNull YamlConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public YamlConfiguration configuration() {
|
||||
return (YamlConfiguration) super.configuration();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public YamlConfigurationOptions copyDefaults(boolean value) {
|
||||
super.copyDefaults(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public YamlConfigurationOptions pathSeparator(char value) {
|
||||
super.pathSeparator(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public YamlConfigurationOptions header(String value) {
|
||||
public YamlConfigurationOptions header(@Nullable String value) {
|
||||
super.header(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public YamlConfigurationOptions copyHeader(boolean value) {
|
||||
super.copyHeader(value);
|
||||
@@ -61,6 +68,7 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
|
||||
* @param value New indent
|
||||
* @return This object, for chaining
|
||||
*/
|
||||
@NotNull
|
||||
public YamlConfigurationOptions indent(int value) {
|
||||
Validate.isTrue(value >= 2, "Indent must be at least 2 characters");
|
||||
Validate.isTrue(value <= 9, "Indent cannot be greater than 9 characters");
|
||||
|
@@ -3,6 +3,8 @@ package org.bukkit.configuration.file;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
@@ -17,8 +19,10 @@ public class YamlConstructor extends SafeConstructor {
|
||||
}
|
||||
|
||||
private class ConstructCustomObject extends ConstructYamlMap {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object construct(Node node) {
|
||||
public Object construct(@NotNull Node node) {
|
||||
if (node.isTwoStepsConstruction()) {
|
||||
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
|
||||
}
|
||||
@@ -42,7 +46,7 @@ public class YamlConstructor extends SafeConstructor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void construct2ndStep(Node node, Object object) {
|
||||
public void construct2ndStep(@NotNull Node node, @NotNull Object object) {
|
||||
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
@@ -18,15 +19,19 @@ public class YamlRepresenter extends Representer {
|
||||
}
|
||||
|
||||
private class RepresentConfigurationSection extends RepresentMap {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Node representData(Object data) {
|
||||
public Node representData(@NotNull Object data) {
|
||||
return super.representData(((ConfigurationSection) data).getValues(false));
|
||||
}
|
||||
}
|
||||
|
||||
private class RepresentConfigurationSerializable extends RepresentMap {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Node representData(Object data) {
|
||||
public Node representData(@NotNull Object data) {
|
||||
ConfigurationSerializable serializable = (ConfigurationSerializable) data;
|
||||
Map<String, Object> values = new LinkedHashMap<String, Object>();
|
||||
values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass()));
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.configuration.serialization;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -31,5 +33,6 @@ public interface ConfigurationSerializable {
|
||||
*
|
||||
* @return Map containing the current state of this class
|
||||
*/
|
||||
@NotNull
|
||||
public Map<String, Object> serialize();
|
||||
}
|
||||
|
@@ -21,6 +21,8 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Utility class for storing and retrieving classes for {@link Configuration}.
|
||||
@@ -43,11 +45,12 @@ public class ConfigurationSerialization {
|
||||
registerClass(BoundingBox.class);
|
||||
}
|
||||
|
||||
protected ConfigurationSerialization(Class<? extends ConfigurationSerializable> clazz) {
|
||||
protected ConfigurationSerialization(@NotNull Class<? extends ConfigurationSerializable> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
protected Method getMethod(String name, boolean isStatic) {
|
||||
@Nullable
|
||||
protected Method getMethod(@NotNull String name, boolean isStatic) {
|
||||
try {
|
||||
Method method = clazz.getDeclaredMethod(name, Map.class);
|
||||
|
||||
@@ -66,6 +69,7 @@ public class ConfigurationSerialization {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Constructor<? extends ConfigurationSerializable> getConstructor() {
|
||||
try {
|
||||
return clazz.getConstructor(Map.class);
|
||||
@@ -76,7 +80,8 @@ public class ConfigurationSerialization {
|
||||
}
|
||||
}
|
||||
|
||||
protected ConfigurationSerializable deserializeViaMethod(Method method, Map<String, ?> args) {
|
||||
@Nullable
|
||||
protected ConfigurationSerializable deserializeViaMethod(@NotNull Method method, @NotNull Map<String, ?> args) {
|
||||
try {
|
||||
ConfigurationSerializable result = (ConfigurationSerializable) method.invoke(null, args);
|
||||
|
||||
@@ -95,7 +100,8 @@ public class ConfigurationSerialization {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected ConfigurationSerializable deserializeViaCtor(Constructor<? extends ConfigurationSerializable> ctor, Map<String, ?> args) {
|
||||
@Nullable
|
||||
protected ConfigurationSerializable deserializeViaCtor(@NotNull Constructor<? extends ConfigurationSerializable> ctor, @NotNull Map<String, ?> args) {
|
||||
try {
|
||||
return ctor.newInstance(args);
|
||||
} catch (Throwable ex) {
|
||||
@@ -108,7 +114,8 @@ public class ConfigurationSerialization {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ConfigurationSerializable deserialize(Map<String, ?> args) {
|
||||
@Nullable
|
||||
public ConfigurationSerializable deserialize(@NotNull Map<String, ?> args) {
|
||||
Validate.notNull(args, "Args must not be null");
|
||||
|
||||
ConfigurationSerializable result = null;
|
||||
@@ -156,7 +163,8 @@ public class ConfigurationSerialization {
|
||||
* @param clazz Class to deserialize into
|
||||
* @return New instance of the specified class
|
||||
*/
|
||||
public static ConfigurationSerializable deserializeObject(Map<String, ?> args, Class<? extends ConfigurationSerializable> clazz) {
|
||||
@Nullable
|
||||
public static ConfigurationSerializable deserializeObject(@NotNull Map<String, ?> args, @NotNull Class<? extends ConfigurationSerializable> clazz) {
|
||||
return new ConfigurationSerialization(clazz).deserialize(args);
|
||||
}
|
||||
|
||||
@@ -174,7 +182,8 @@ public class ConfigurationSerialization {
|
||||
* @param args Arguments for deserialization
|
||||
* @return New instance of the specified class
|
||||
*/
|
||||
public static ConfigurationSerializable deserializeObject(Map<String, ?> args) {
|
||||
@Nullable
|
||||
public static ConfigurationSerializable deserializeObject(@NotNull Map<String, ?> args) {
|
||||
Class<? extends ConfigurationSerializable> clazz = null;
|
||||
|
||||
if (args.containsKey(SERIALIZED_TYPE_KEY)) {
|
||||
@@ -205,7 +214,7 @@ public class ConfigurationSerialization {
|
||||
*
|
||||
* @param clazz Class to register
|
||||
*/
|
||||
public static void registerClass(Class<? extends ConfigurationSerializable> clazz) {
|
||||
public static void registerClass(@NotNull Class<? extends ConfigurationSerializable> clazz) {
|
||||
DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);
|
||||
|
||||
if (delegate == null) {
|
||||
@@ -222,7 +231,7 @@ 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(@NotNull Class<? extends ConfigurationSerializable> clazz, @NotNull String alias) {
|
||||
aliases.put(alias, clazz);
|
||||
}
|
||||
|
||||
@@ -231,7 +240,7 @@ public class ConfigurationSerialization {
|
||||
*
|
||||
* @param alias Alias to unregister
|
||||
*/
|
||||
public static void unregisterClass(String alias) {
|
||||
public static void unregisterClass(@NotNull String alias) {
|
||||
aliases.remove(alias);
|
||||
}
|
||||
|
||||
@@ -241,7 +250,7 @@ public class ConfigurationSerialization {
|
||||
*
|
||||
* @param clazz Class to unregister
|
||||
*/
|
||||
public static void unregisterClass(Class<? extends ConfigurationSerializable> clazz) {
|
||||
public static void unregisterClass(@NotNull Class<? extends ConfigurationSerializable> clazz) {
|
||||
while (aliases.values().remove(clazz)) {
|
||||
;
|
||||
}
|
||||
@@ -254,7 +263,8 @@ public class ConfigurationSerialization {
|
||||
* @param alias Alias of the serializable
|
||||
* @return Registered class, or null if not found
|
||||
*/
|
||||
public static Class<? extends ConfigurationSerializable> getClassByAlias(String alias) {
|
||||
@Nullable
|
||||
public static Class<? extends ConfigurationSerializable> getClassByAlias(@NotNull String alias) {
|
||||
return aliases.get(alias);
|
||||
}
|
||||
|
||||
@@ -265,7 +275,8 @@ public class ConfigurationSerialization {
|
||||
* @param clazz Class to get alias for
|
||||
* @return Alias to use for the class
|
||||
*/
|
||||
public static String getAlias(Class<? extends ConfigurationSerializable> clazz) {
|
||||
@NotNull
|
||||
public static String getAlias(@NotNull Class<? extends ConfigurationSerializable> clazz) {
|
||||
DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);
|
||||
|
||||
if (delegate != null) {
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.configuration.serialization;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -18,5 +20,6 @@ public @interface DelegateDeserialization {
|
||||
*
|
||||
* @return Delegate class
|
||||
*/
|
||||
@NotNull
|
||||
public Class<? extends ConfigurationSerializable> value();
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.configuration.serialization;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -30,5 +32,6 @@ public @interface SerializableAs {
|
||||
*
|
||||
* @return Name to serialize the class as.
|
||||
*/
|
||||
@NotNull
|
||||
public String value();
|
||||
}
|
||||
|
Reference in New Issue
Block a user