added loadFromString and saveToString, also nullable methods

Former-commit-id: 229b84875f9ff34faa3073d43b3c776b9d389254
This commit is contained in:
portlek committed 2019-12-13 15:17:43 +03:00
1 parent d54f574022
commit 20324eaedb
2 files changed
+32 -7

No files matched your search

@@ -3,6 +3,7 @@ package org.maxgamer.quickshop.File;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
@@ -92,15 +93,26 @@ public abstract class FileEnvelope implements IFile {
}
}
@NotNull
@Override
public String saveToString() {
return fileConfiguration.saveToString();
}
@Override
public void loadFromString(@NotNull String data) throws InvalidConfigurationException {
fileConfiguration.loadFromString(data);
}
@Nullable
@Override
public Object get(@NotNull String path) {
return fileConfiguration.get(path);
}
@NotNull
@Nullable
@Override
public Object get(@NotNull String path, @NotNull Object fallback) {
public Object get(@NotNull String path, @Nullable Object fallback) {
final Object object = fileConfiguration.get(path, fallback);
if (object == null) {
@@ -163,7 +175,7 @@ public abstract class FileEnvelope implements IFile {
}
@Override
public void set(@NotNull String path, @NotNull Object object) {
public void set(@NotNull String path, @Nullable Object object) {
fileConfiguration.set(path, object);
save();
}
@@ -2,6 +2,7 @@ package org.maxgamer.quickshop.File;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -31,6 +32,18 @@ public interface IFile {
*/
void save();
/**
* @return the string of the file
*/
@NotNull
String saveToString();
/**
* Loads from the data
* @param data the data
*/
void loadFromString(@NotNull String data) throws InvalidConfigurationException;
/**
* Gets the object
*
@@ -45,10 +58,10 @@ public interface IFile {
*
* @param path object path to get
* @param fallback fallback object to get if path does not exist
* @return if path does not exist returns fallback object else the path object
* @return if path does not exist returns fallback object
*/
@NotNull
Object get(@NotNull String path, @NotNull Object fallback);
@Nullable
Object get(@NotNull String path, @Nullable Object fallback);
/**
* Gets or sets the object
@@ -122,7 +135,7 @@ public interface IFile {
* @param path object path to set
* @param object {@link Object}
*/
void set(@NotNull final String path, @NotNull final Object object);
void set(@NotNull final String path, @Nullable final Object object);
/**
* Gets string list