mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
@ -29,9 +29,6 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
||||
|
||||
@Override
|
||||
public void addDefault(String path, Object value) {
|
||||
if (path == null) {
|
||||
throw new NullPointerException("Path may not be null");
|
||||
}
|
||||
if (this.defaults == null) {
|
||||
this.defaults = new MemoryConfiguration();
|
||||
}
|
||||
@ -41,10 +38,6 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
||||
|
||||
@Override
|
||||
public void addDefaults(Map<String, Object> defaults) {
|
||||
if (defaults == null) {
|
||||
throw new NullPointerException("Defaults may not be null");
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Object> entry : defaults.entrySet()) {
|
||||
addDefault(entry.getKey(), entry.getValue());
|
||||
}
|
||||
@ -52,10 +45,6 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
||||
|
||||
@Override
|
||||
public void addDefaults(Configuration defaults) {
|
||||
if (defaults == null) {
|
||||
throw new NullPointerException("Defaults may not be null");
|
||||
}
|
||||
|
||||
addDefaults(defaults.getValues(true));
|
||||
}
|
||||
|
||||
|
@ -49,13 +49,6 @@ public class MemorySection implements ConfigurationSection {
|
||||
* if parent contains no root Configuration.
|
||||
*/
|
||||
protected MemorySection(ConfigurationSection parent, String path) {
|
||||
if (parent == null) {
|
||||
throw new NullPointerException("Parent may not be null");
|
||||
}
|
||||
if (path == null) {
|
||||
throw new NullPointerException("Path may not be null");
|
||||
}
|
||||
|
||||
this.path = path;
|
||||
this.parent = parent;
|
||||
this.root = parent.getRoot();
|
||||
@ -133,7 +126,7 @@ public class MemorySection implements ConfigurationSection {
|
||||
* @return Full path of the section from its root.
|
||||
*/
|
||||
public static String createPath(ConfigurationSection section, String key) {
|
||||
return createPath(section, key, (section == null) ? null : section.getRoot());
|
||||
return createPath(section, key, section.getRoot());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,9 +142,6 @@ public class MemorySection implements ConfigurationSection {
|
||||
* @return Full path of the section from its root.
|
||||
*/
|
||||
public static String createPath(ConfigurationSection section, String key, ConfigurationSection relativeTo) {
|
||||
if (section == null) {
|
||||
throw new NullPointerException("Cannot create path without a section");
|
||||
}
|
||||
Configuration root = section.getRoot();
|
||||
if (root == null) {
|
||||
throw new IllegalStateException("Cannot create path without a root");
|
||||
@ -253,10 +243,6 @@ public class MemorySection implements ConfigurationSection {
|
||||
|
||||
@Override
|
||||
public void addDefault(String path, Object value) {
|
||||
if (path == null) {
|
||||
throw new NullPointerException("Path cannot be null");
|
||||
}
|
||||
|
||||
Configuration root = getRoot();
|
||||
if (root == null) {
|
||||
throw new IllegalStateException("Cannot add default without root");
|
||||
@ -283,10 +269,6 @@ public class MemorySection implements ConfigurationSection {
|
||||
|
||||
@Override
|
||||
public void set(String path, Object value) {
|
||||
if (path == null) {
|
||||
throw new NullPointerException("Cannot set to an empty path");
|
||||
}
|
||||
|
||||
Configuration root = getRoot();
|
||||
if (root == null) {
|
||||
throw new IllegalStateException("Cannot use section without a root");
|
||||
@ -367,9 +349,6 @@ public class MemorySection implements ConfigurationSection {
|
||||
|
||||
@Override
|
||||
public ConfigurationSection createSection(String path) {
|
||||
if (path == null) {
|
||||
throw new NullPointerException("Cannot create section at empty path");
|
||||
}
|
||||
Configuration root = getRoot();
|
||||
if (root == null) {
|
||||
throw new IllegalStateException("Cannot create section without a root");
|
||||
@ -787,10 +766,6 @@ public class MemorySection implements ConfigurationSection {
|
||||
}
|
||||
|
||||
protected Object getDefault(String path) {
|
||||
if (path == null) {
|
||||
throw new NullPointerException("Path may not be null");
|
||||
}
|
||||
|
||||
Configuration root = getRoot();
|
||||
Configuration defaults = root == null ? null : root.getDefaults();
|
||||
return (defaults == null) ? null : defaults.get(createPath(this, path));
|
||||
|
@ -87,9 +87,6 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* @throws IllegalArgumentException Thrown when file is null.
|
||||
*/
|
||||
public void load(File file) throws IOException, InvalidConfigurationException {
|
||||
if (file == null) {
|
||||
throw new NullPointerException("File cannot be null");
|
||||
}
|
||||
|
||||
FileInputStream stream = new FileInputStream(file);
|
||||
|
||||
@ -123,33 +120,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
|
||||
loadFromString(builder.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads this {@link FileConfiguration} from the specified location.
|
||||
*
|
||||
* <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>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 InvalidConfigurationException Thrown when the given file is not
|
||||
* a valid Configuration.
|
||||
* @throws IllegalArgumentException Thrown when file is null.
|
||||
*/
|
||||
public void load(String file) throws IOException, InvalidConfigurationException {
|
||||
if (file == null) {
|
||||
throw new NullPointerException("File cannot be null");
|
||||
}
|
||||
|
||||
load(new File(file));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads this {@link FileConfiguration} from the specified string, as
|
||||
* opposed to from file.
|
||||
|
@ -11,7 +11,6 @@ import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Map;
|
||||
@ -38,13 +37,8 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
*
|
||||
* @param file Input file
|
||||
* @return Resulting configuration
|
||||
* @throws IllegalArgumentException Thrown if file is null
|
||||
*/
|
||||
public static YamlConfiguration loadConfiguration(File file) {
|
||||
if (file == null) {
|
||||
throw new NullPointerException("File cannot be null");
|
||||
}
|
||||
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
|
||||
try {
|
||||
@ -70,34 +64,6 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link YamlConfiguration}, loading from the given reader.
|
||||
*
|
||||
* <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.
|
||||
*
|
||||
* @param reader input
|
||||
* @return resulting configuration
|
||||
* @throws IllegalArgumentException Thrown if stream is null
|
||||
*/
|
||||
public static YamlConfiguration loadConfiguration(Reader reader) {
|
||||
if (reader == null) {
|
||||
throw new NullPointerException("Reader cannot be null");
|
||||
}
|
||||
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
|
||||
try {
|
||||
config.load(reader);
|
||||
} catch (IOException | InvalidConfigurationException ex) {
|
||||
PS.debug("Cannot load configuration from stream");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String saveToString() {
|
||||
yamlOptions.setIndent(options().indent());
|
||||
@ -116,9 +82,6 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
|
||||
@Override
|
||||
public void loadFromString(String contents) throws InvalidConfigurationException {
|
||||
if (contents == null) {
|
||||
throw new NullPointerException("Contents cannot be null");
|
||||
}
|
||||
|
||||
Map<?, ?> input;
|
||||
try {
|
||||
|
@ -19,16 +19,16 @@ public class TeleportDenyFlag extends EnumFlag {
|
||||
result = !plot.getTrusted().contains(player.getUUID());
|
||||
break;
|
||||
case "members":
|
||||
result =!plot.getMembers().contains(player.getUUID());
|
||||
result = !plot.getMembers().contains(player.getUUID());
|
||||
break;
|
||||
case "nonmembers":
|
||||
result =!plot.isAdded(player.getUUID());
|
||||
result = !plot.isAdded(player.getUUID());
|
||||
break;
|
||||
case "nontrusted":
|
||||
result =!plot.getTrusted().contains(player.getUUID()) && !plot.isOwner(player.getUUID());
|
||||
result = !plot.getTrusted().contains(player.getUUID()) && !plot.isOwner(player.getUUID());
|
||||
break;
|
||||
case "nonowners":
|
||||
result =!plot.isOwner(player.getUUID());
|
||||
result = !plot.isOwner(player.getUUID());
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
|
@ -4,6 +4,7 @@ import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -12,11 +13,31 @@ public abstract class CommentInbox {
|
||||
@Override
|
||||
public abstract String toString();
|
||||
|
||||
public abstract boolean canRead(Plot plot, PlotPlayer player);
|
||||
public boolean canRead(Plot plot, PlotPlayer player) {
|
||||
if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) {
|
||||
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract boolean canWrite(Plot plot, PlotPlayer player);
|
||||
public boolean canWrite(Plot plot, PlotPlayer player) {
|
||||
if (plot == null) {
|
||||
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
|
||||
}
|
||||
return Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
|
||||
.hasPermission(player, "plots.inbox.write." + toString() + ".other"));
|
||||
}
|
||||
|
||||
public abstract boolean canModify(Plot plot, PlotPlayer player);
|
||||
public boolean canModify(Plot plot, PlotPlayer player) {
|
||||
if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) {
|
||||
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -3,9 +3,7 @@ package com.intellectualcrafters.plot.object.comment;
|
||||
import com.google.common.base.Optional;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -13,35 +11,6 @@ import java.util.List;
|
||||
|
||||
public class InboxOwner extends CommentInbox {
|
||||
|
||||
@Override
|
||||
public boolean canRead(Plot plot, PlotPlayer player) {
|
||||
if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) {
|
||||
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(Plot plot, PlotPlayer player) {
|
||||
if (plot == null) {
|
||||
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
|
||||
}
|
||||
return Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
|
||||
.hasPermission(player, "plots.inbox.write." + toString() + ".other"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canModify(Plot plot, PlotPlayer player) {
|
||||
if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) {
|
||||
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
|
||||
Optional<ArrayList<PlotComment>> comments = plot.getSettings().getComments(toString());
|
||||
|
@ -3,45 +3,14 @@ package com.intellectualcrafters.plot.object.comment;
|
||||
import com.google.common.base.Optional;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InboxPublic extends CommentInbox {
|
||||
|
||||
@Override
|
||||
public boolean canRead(Plot plot, PlotPlayer player) {
|
||||
if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) {
|
||||
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(Plot plot, PlotPlayer player) {
|
||||
if (plot == null) {
|
||||
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
|
||||
}
|
||||
return Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
|
||||
.hasPermission(player, "plots.inbox.write." + toString() + ".other"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canModify(Plot plot, PlotPlayer player) {
|
||||
if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) {
|
||||
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
|
||||
Optional<ArrayList<PlotComment>> comments = plot.getSettings().getComments(toString());
|
||||
|
@ -2,45 +2,13 @@ package com.intellectualcrafters.plot.object.comment;
|
||||
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class InboxReport extends CommentInbox {
|
||||
|
||||
@Override
|
||||
public boolean canRead(Plot plot, PlotPlayer player) {
|
||||
if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) {
|
||||
if (plot.isOwner(player.getUUID()) || Permissions
|
||||
.hasPermission(player, "plots.inbox.read." + toString() + ".other")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(Plot plot, PlotPlayer player) {
|
||||
if (plot == null) {
|
||||
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
|
||||
}
|
||||
return Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
|
||||
.hasPermission(player, "plots.inbox.write." + toString() + ".other"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canModify(Plot plot, PlotPlayer player) {
|
||||
if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) {
|
||||
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getComments(Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
|
||||
DBFunc.getComments(null, toString(), new RunnableVal<List<PlotComment>>() {
|
||||
|
Reference in New Issue
Block a user