Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf29df7bce | ||
|
|
c259cb5a45 | ||
|
|
4148f55bb5 | ||
|
|
b63791c14b | ||
|
|
294dfabd54 | ||
|
|
d7f7cad863 | ||
|
|
afd8df5b48 | ||
|
|
b9d1f36604 | ||
|
|
403a7a7da8 | ||
|
|
f6fb5bcf66 | ||
|
|
194eb8b5f5 | ||
|
|
853aaca071 | ||
|
|
18dabd6bcf |
@@ -5,7 +5,6 @@ import com.sk89q.worldguard.LocalPlayer;
|
|||||||
import com.sk89q.worldguard.WorldGuard;
|
import com.sk89q.worldguard.WorldGuard;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.protection.flags.Flags;
|
import com.sk89q.worldguard.protection.flags.Flags;
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
|
||||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||||
@@ -25,7 +24,7 @@ public class AntigriefWorldGuard implements AntigriefWrapper {
|
|||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
RegionQuery query = container.createQuery();
|
RegionQuery query = container.createQuery();
|
||||||
|
|
||||||
if (query.queryState(BukkitAdapter.adapt(block.getLocation()), localPlayer, Flags.BUILD) == StateFlag.State.DENY) {
|
if (!query.testBuild(BukkitAdapter.adapt(block.getLocation()), localPlayer, Flags.BLOCK_BREAK)) {
|
||||||
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(block.getWorld()));
|
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(block.getWorld()));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -40,7 +39,7 @@ public class AntigriefWorldGuard implements AntigriefWrapper {
|
|||||||
World world = location.getWorld();
|
World world = location.getWorld();
|
||||||
Validate.notNull(world, "World cannot be null!");
|
Validate.notNull(world, "World cannot be null!");
|
||||||
|
|
||||||
if (query.queryState(BukkitAdapter.adapt(location), localPlayer, Flags.OTHER_EXPLOSION) == StateFlag.State.DENY) {
|
if (!query.testBuild(BukkitAdapter.adapt(location), localPlayer, Flags.TNT)) {
|
||||||
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(world));
|
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(world));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -53,7 +52,7 @@ public class AntigriefWorldGuard implements AntigriefWrapper {
|
|||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
RegionQuery query = container.createQuery();
|
RegionQuery query = container.createQuery();
|
||||||
|
|
||||||
if (query.queryState(BukkitAdapter.adapt(block.getLocation()), localPlayer, Flags.BLOCK_PLACE) == StateFlag.State.DENY) {
|
if (!query.testBuild(BukkitAdapter.adapt(block.getLocation()), localPlayer, Flags.BLOCK_PLACE)) {
|
||||||
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(block.getWorld()));
|
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(block.getWorld()));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -67,11 +66,11 @@ public class AntigriefWorldGuard implements AntigriefWrapper {
|
|||||||
RegionQuery query = container.createQuery();
|
RegionQuery query = container.createQuery();
|
||||||
|
|
||||||
if (victim instanceof Player) {
|
if (victim instanceof Player) {
|
||||||
if (query.queryState(BukkitAdapter.adapt(victim.getLocation()), localPlayer, Flags.PVP) == StateFlag.State.DENY) {
|
if (!query.testBuild(BukkitAdapter.adapt(victim.getLocation()), localPlayer, Flags.PVP)) {
|
||||||
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(player.getWorld()));
|
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(player.getWorld()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (query.queryState(BukkitAdapter.adapt(victim.getLocation()), localPlayer, Flags.DAMAGE_ANIMALS) == StateFlag.State.DENY) {
|
if (!query.testBuild(BukkitAdapter.adapt(victim.getLocation()), localPlayer, Flags.DAMAGE_ANIMALS)) {
|
||||||
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(player.getWorld()));
|
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(player.getWorld()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
package com.willfp.eco.internal.config;
|
package com.willfp.eco.internal.config;
|
||||||
|
|
||||||
import com.willfp.eco.util.StringUtils;
|
|
||||||
import com.willfp.eco.util.internal.PluginDependent;
|
|
||||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -19,19 +15,8 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public abstract class AbstractConfig extends PluginDependent {
|
|
||||||
/**
|
|
||||||
* The linked {@link YamlConfiguration} where values are physically stored.
|
|
||||||
*/
|
|
||||||
@Getter(AccessLevel.PUBLIC)
|
|
||||||
protected final YamlConfiguration config;
|
|
||||||
|
|
||||||
|
public abstract class AbstractConfig extends AbstractUndefinedConfig {
|
||||||
/**
|
/**
|
||||||
* The physical config file, as stored on disk.
|
* The physical config file, as stored on disk.
|
||||||
*/
|
*/
|
||||||
@@ -41,7 +26,7 @@ public abstract class AbstractConfig extends PluginDependent {
|
|||||||
/**
|
/**
|
||||||
* The full name of the config file (eg config.yml).
|
* The full name of the config file (eg config.yml).
|
||||||
*/
|
*/
|
||||||
@Getter(AccessLevel.PROTECTED)
|
@Getter
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,11 +41,6 @@ public abstract class AbstractConfig extends PluginDependent {
|
|||||||
@Getter(AccessLevel.PROTECTED)
|
@Getter(AccessLevel.PROTECTED)
|
||||||
private final Class<?> source;
|
private final Class<?> source;
|
||||||
|
|
||||||
/**
|
|
||||||
* Cached values for faster reading.
|
|
||||||
*/
|
|
||||||
private final Map<String, Object> cache = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract config.
|
* Abstract config.
|
||||||
*
|
*
|
||||||
@@ -73,10 +53,10 @@ public abstract class AbstractConfig extends PluginDependent {
|
|||||||
@NotNull final AbstractEcoPlugin plugin,
|
@NotNull final AbstractEcoPlugin plugin,
|
||||||
@NotNull final String subDirectoryPath,
|
@NotNull final String subDirectoryPath,
|
||||||
@NotNull final Class<?> source) {
|
@NotNull final Class<?> source) {
|
||||||
super(plugin);
|
super(configName, plugin);
|
||||||
|
this.name = configName + ".yml";
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.subDirectoryPath = subDirectoryPath;
|
this.subDirectoryPath = subDirectoryPath;
|
||||||
this.name = configName + ".yml";
|
|
||||||
|
|
||||||
File directory = new File(this.getPlugin().getDataFolder(), subDirectoryPath);
|
File directory = new File(this.getPlugin().getDataFolder(), subDirectoryPath);
|
||||||
if (!directory.exists()) {
|
if (!directory.exists()) {
|
||||||
@@ -88,7 +68,7 @@ public abstract class AbstractConfig extends PluginDependent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.configFile = new File(directory, this.name);
|
this.configFile = new File(directory, this.name);
|
||||||
this.config = YamlConfiguration.loadConfiguration(configFile);
|
init(YamlConfiguration.loadConfiguration(configFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createFile() {
|
private void createFile() {
|
||||||
@@ -144,7 +124,7 @@ public abstract class AbstractConfig extends PluginDependent {
|
|||||||
InputStream newIn = source.getResourceAsStream(getResourcePath());
|
InputStream newIn = source.getResourceAsStream(getResourcePath());
|
||||||
|
|
||||||
if (newIn == null) {
|
if (newIn == null) {
|
||||||
throw new NullPointerException(this.getName() + " is null?");
|
throw new NullPointerException(name + " is null?");
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
|
||||||
@@ -158,315 +138,4 @@ public abstract class AbstractConfig extends PluginDependent {
|
|||||||
|
|
||||||
return newConfig;
|
return newConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears cache.
|
|
||||||
*/
|
|
||||||
public final void clearCache() {
|
|
||||||
cache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get if the config contains a key.
|
|
||||||
*
|
|
||||||
* @param path The key to check.
|
|
||||||
* @return If contained.
|
|
||||||
*/
|
|
||||||
public boolean has(@NotNull final String path) {
|
|
||||||
return config.contains(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get configuration section from config.
|
|
||||||
*
|
|
||||||
* @param path The key to check.
|
|
||||||
* @return The configuration section. Throws NPE if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public ConfigurationSection getSection(@NotNull final String path) {
|
|
||||||
ConfigurationSection section = getSectionOrNull(path);
|
|
||||||
if (section == null) {
|
|
||||||
throw new NullPointerException("Section cannot be null!");
|
|
||||||
} else {
|
|
||||||
return section;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get configuration section from config.
|
|
||||||
*
|
|
||||||
* @param path The key to check.
|
|
||||||
* @return The configuration section, or null if not found.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public ConfigurationSection getSectionOrNull(@NotNull final String path) {
|
|
||||||
if (cache.containsKey(path)) {
|
|
||||||
return (ConfigurationSection) cache.get(path);
|
|
||||||
} else {
|
|
||||||
cache.put(path, config.getConfigurationSection(path));
|
|
||||||
return getSectionOrNull(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an integer from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or 0 if not found.
|
|
||||||
*/
|
|
||||||
public int getInt(@NotNull final String path) {
|
|
||||||
if (cache.containsKey(path)) {
|
|
||||||
return (int) cache.get(path);
|
|
||||||
} else {
|
|
||||||
cache.put(path, config.getInt(path, 0));
|
|
||||||
return getInt(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an integer from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or null if not found.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public Integer getIntOrNull(@NotNull final String path) {
|
|
||||||
if (has(path)) {
|
|
||||||
return getInt(path);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an integer from config with a specified default (not found) value.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @param def The value to default to if not found.
|
|
||||||
* @return The found value, or the default.
|
|
||||||
*/
|
|
||||||
public int getInt(@NotNull final String path,
|
|
||||||
final int def) {
|
|
||||||
if (cache.containsKey(path)) {
|
|
||||||
return (int) cache.get(path);
|
|
||||||
} else {
|
|
||||||
cache.put(path, config.getInt(path, def));
|
|
||||||
return getInt(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of integers from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public List<Integer> getInts(@NotNull final String path) {
|
|
||||||
if (cache.containsKey(path)) {
|
|
||||||
return (List<Integer>) cache.get(path);
|
|
||||||
} else {
|
|
||||||
cache.put(path, config.getIntegerList(path));
|
|
||||||
return getInts(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of integers from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or null if not found.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public List<Integer> getIntsOrNull(@NotNull final String path) {
|
|
||||||
if (has(path)) {
|
|
||||||
return getInts(path);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a boolean from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or false if not found.
|
|
||||||
*/
|
|
||||||
public boolean getBool(@NotNull final String path) {
|
|
||||||
if (cache.containsKey(path)) {
|
|
||||||
return (boolean) cache.get(path);
|
|
||||||
} else {
|
|
||||||
cache.put(path, config.getBoolean(path));
|
|
||||||
return getBool(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a boolean from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or null if not found.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public Boolean getBoolOrNull(@NotNull final String path) {
|
|
||||||
if (has(path)) {
|
|
||||||
return getBool(path);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of booleans from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public List<Boolean> getBools(@NotNull final String path) {
|
|
||||||
if (cache.containsKey(path)) {
|
|
||||||
return (List<Boolean>) cache.get(path);
|
|
||||||
} else {
|
|
||||||
cache.put(path, config.getBooleanList(path));
|
|
||||||
return getBools(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of booleans from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or null if not found.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public List<Boolean> getBoolsOrNull(@NotNull final String path) {
|
|
||||||
if (has(path)) {
|
|
||||||
return getBools(path);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a string from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or an empty string if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public String getString(@NotNull final String path) {
|
|
||||||
if (cache.containsKey(path)) {
|
|
||||||
return (String) cache.get(path);
|
|
||||||
} else {
|
|
||||||
cache.put(path, StringUtils.translate(Objects.requireNonNull(config.getString(path, ""))));
|
|
||||||
return getString(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a string from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or null if not found.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public String getStringOrNull(@NotNull final String path) {
|
|
||||||
if (has(path)) {
|
|
||||||
return getString(path);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of strings from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public List<String> getStrings(@NotNull final String path) {
|
|
||||||
if (cache.containsKey(path)) {
|
|
||||||
return (List<String>) cache.get(path);
|
|
||||||
} else {
|
|
||||||
cache.put(path, config.getStringList(path));
|
|
||||||
return getStrings(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of strings from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or null if not found.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public List<String> getStringsOrNull(@NotNull final String path) {
|
|
||||||
if (has(path)) {
|
|
||||||
return getStrings(path);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a decimal from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or 0 if not found.
|
|
||||||
*/
|
|
||||||
public double getDouble(@NotNull final String path) {
|
|
||||||
if (cache.containsKey(path)) {
|
|
||||||
return (double) cache.get(path);
|
|
||||||
} else {
|
|
||||||
cache.put(path, config.getDouble(path));
|
|
||||||
return getDouble(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a decimal from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or null if not found.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public Double getDoubleOrNull(@NotNull final String path) {
|
|
||||||
if (has(path)) {
|
|
||||||
return getDouble(path);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of decimals from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public List<Double> getDoubles(@NotNull final String path) {
|
|
||||||
if (cache.containsKey(path)) {
|
|
||||||
return (List<Double>) cache.get(path);
|
|
||||||
} else {
|
|
||||||
cache.put(path, config.getDoubleList(path));
|
|
||||||
return getDoubles(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of decimals from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or null if not found.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public List<Double> getDoublesOrNull(@NotNull final String path) {
|
|
||||||
if (has(path)) {
|
|
||||||
return getDoubles(path);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,356 @@
|
|||||||
|
package com.willfp.eco.internal.config;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.StringUtils;
|
||||||
|
import com.willfp.eco.util.internal.PluginDependent;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "unused"})
|
||||||
|
public abstract class AbstractUndefinedConfig extends PluginDependent {
|
||||||
|
/**
|
||||||
|
* The linked {@link YamlConfiguration} where values are physically stored.
|
||||||
|
*/
|
||||||
|
@Getter(AccessLevel.PUBLIC)
|
||||||
|
protected YamlConfiguration config = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cached values for faster reading.
|
||||||
|
*/
|
||||||
|
private final Map<String, Object> cache = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract config.
|
||||||
|
*
|
||||||
|
* @param configName The name of the config
|
||||||
|
* @param plugin The plugin.
|
||||||
|
*/
|
||||||
|
protected AbstractUndefinedConfig(@NotNull final String configName,
|
||||||
|
@NotNull final AbstractEcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void init(@NotNull final YamlConfiguration config) {
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears cache.
|
||||||
|
*/
|
||||||
|
public final void clearCache() {
|
||||||
|
cache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get if the config contains a key.
|
||||||
|
*
|
||||||
|
* @param path The key to check.
|
||||||
|
* @return If contained.
|
||||||
|
*/
|
||||||
|
public boolean has(@NotNull final String path) {
|
||||||
|
return config.contains(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get configuration section from config.
|
||||||
|
*
|
||||||
|
* @param path The key to check.
|
||||||
|
* @return The configuration section. Throws NPE if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public ConfigurationSection getSection(@NotNull final String path) {
|
||||||
|
ConfigurationSection section = getSectionOrNull(path);
|
||||||
|
if (section == null) {
|
||||||
|
throw new NullPointerException("Section cannot be null!");
|
||||||
|
} else {
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get configuration section from config.
|
||||||
|
*
|
||||||
|
* @param path The key to check.
|
||||||
|
* @return The configuration section, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public ConfigurationSection getSectionOrNull(@NotNull final String path) {
|
||||||
|
if (cache.containsKey(path)) {
|
||||||
|
return (ConfigurationSection) cache.get(path);
|
||||||
|
} else {
|
||||||
|
cache.put(path, config.getConfigurationSection(path));
|
||||||
|
return getSectionOrNull(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an integer from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or 0 if not found.
|
||||||
|
*/
|
||||||
|
public int getInt(@NotNull final String path) {
|
||||||
|
if (cache.containsKey(path)) {
|
||||||
|
return (int) cache.get(path);
|
||||||
|
} else {
|
||||||
|
cache.put(path, config.getInt(path, 0));
|
||||||
|
return getInt(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an integer from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Integer getIntOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getInt(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an integer from config with a specified default (not found) value.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @param def The value to default to if not found.
|
||||||
|
* @return The found value, or the default.
|
||||||
|
*/
|
||||||
|
public int getInt(@NotNull final String path,
|
||||||
|
final int def) {
|
||||||
|
if (cache.containsKey(path)) {
|
||||||
|
return (int) cache.get(path);
|
||||||
|
} else {
|
||||||
|
cache.put(path, config.getInt(path, def));
|
||||||
|
return getInt(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of integers from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public List<Integer> getInts(@NotNull final String path) {
|
||||||
|
if (cache.containsKey(path)) {
|
||||||
|
return (List<Integer>) cache.get(path);
|
||||||
|
} else {
|
||||||
|
cache.put(path, config.getIntegerList(path));
|
||||||
|
return getInts(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of integers from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public List<Integer> getIntsOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getInts(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a boolean from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or false if not found.
|
||||||
|
*/
|
||||||
|
public boolean getBool(@NotNull final String path) {
|
||||||
|
if (cache.containsKey(path)) {
|
||||||
|
return (boolean) cache.get(path);
|
||||||
|
} else {
|
||||||
|
cache.put(path, config.getBoolean(path));
|
||||||
|
return getBool(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a boolean from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Boolean getBoolOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getBool(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of booleans from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public List<Boolean> getBools(@NotNull final String path) {
|
||||||
|
if (cache.containsKey(path)) {
|
||||||
|
return (List<Boolean>) cache.get(path);
|
||||||
|
} else {
|
||||||
|
cache.put(path, config.getBooleanList(path));
|
||||||
|
return getBools(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of booleans from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public List<Boolean> getBoolsOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getBools(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a string from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or an empty string if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public String getString(@NotNull final String path) {
|
||||||
|
if (cache.containsKey(path)) {
|
||||||
|
return (String) cache.get(path);
|
||||||
|
} else {
|
||||||
|
cache.put(path, StringUtils.translate(Objects.requireNonNull(config.getString(path, ""))));
|
||||||
|
return getString(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a string from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getStringOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getString(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of strings from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public List<String> getStrings(@NotNull final String path) {
|
||||||
|
if (cache.containsKey(path)) {
|
||||||
|
return (List<String>) cache.get(path);
|
||||||
|
} else {
|
||||||
|
cache.put(path, config.getStringList(path));
|
||||||
|
return getStrings(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of strings from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public List<String> getStringsOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getStrings(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a decimal from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or 0 if not found.
|
||||||
|
*/
|
||||||
|
public double getDouble(@NotNull final String path) {
|
||||||
|
if (cache.containsKey(path)) {
|
||||||
|
return (double) cache.get(path);
|
||||||
|
} else {
|
||||||
|
cache.put(path, config.getDouble(path));
|
||||||
|
return getDouble(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a decimal from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Double getDoubleOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getDouble(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of decimals from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public List<Double> getDoubles(@NotNull final String path) {
|
||||||
|
if (cache.containsKey(path)) {
|
||||||
|
return (List<Double>) cache.get(path);
|
||||||
|
} else {
|
||||||
|
cache.put(path, config.getDoubleList(path));
|
||||||
|
return getDoubles(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of decimals from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public List<Double> getDoublesOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getDoubles(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.willfp.eco.util.config;
|
||||||
|
|
||||||
|
import com.willfp.eco.internal.config.AbstractUndefinedConfig;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public abstract class StaticOptionalConfig extends AbstractUndefinedConfig {
|
||||||
|
/**
|
||||||
|
* Config implementation for passing YamlConfigurations.
|
||||||
|
* <p>
|
||||||
|
* Does not automatically update.
|
||||||
|
*
|
||||||
|
* @param configName The name of the config
|
||||||
|
* @param plugin The plugin.
|
||||||
|
* @param config The YamlConfiguration handle.
|
||||||
|
*/
|
||||||
|
public StaticOptionalConfig(@NotNull final String configName,
|
||||||
|
@NotNull final AbstractEcoPlugin plugin,
|
||||||
|
@NotNull final YamlConfiguration config) {
|
||||||
|
super(configName, plugin);
|
||||||
|
|
||||||
|
init(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class Display {
|
public class Display {
|
||||||
/**
|
/**
|
||||||
* The prefix for lore lines.
|
* The prefix for lore lines.
|
||||||
@@ -40,6 +41,8 @@ public class Display {
|
|||||||
public void registerDisplayModule(@NotNull final DisplayModule module) {
|
public void registerDisplayModule(@NotNull final DisplayModule module) {
|
||||||
List<DisplayModule> modules = MODULES.get(module.getPriority());
|
List<DisplayModule> modules = MODULES.get(module.getPriority());
|
||||||
|
|
||||||
|
modules.removeIf(module1 -> module1.getPluginName().equalsIgnoreCase(module.getPluginName()));
|
||||||
|
|
||||||
modules.add(module);
|
modules.add(module);
|
||||||
|
|
||||||
MODULES.put(module.getPriority(), modules);
|
MODULES.put(module.getPriority(), modules);
|
||||||
@@ -57,6 +60,15 @@ public class Display {
|
|||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, Object[]> pluginVarArgs = new HashMap<>();
|
||||||
|
|
||||||
|
for (DisplayPriority priority : DisplayPriority.values()) {
|
||||||
|
List<DisplayModule> modules = MODULES.get(priority);
|
||||||
|
for (DisplayModule module : modules) {
|
||||||
|
pluginVarArgs.put(module.getPluginName(), module.generateVarArgs(itemStack));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
revert(itemStack);
|
revert(itemStack);
|
||||||
|
|
||||||
if (!itemStack.hasItemMeta()) {
|
if (!itemStack.hasItemMeta()) {
|
||||||
@@ -72,7 +84,12 @@ public class Display {
|
|||||||
for (DisplayPriority priority : DisplayPriority.values()) {
|
for (DisplayPriority priority : DisplayPriority.values()) {
|
||||||
List<DisplayModule> modules = MODULES.get(priority);
|
List<DisplayModule> modules = MODULES.get(priority);
|
||||||
for (DisplayModule module : modules) {
|
for (DisplayModule module : modules) {
|
||||||
module.display(itemStack);
|
Object[] varargs = pluginVarArgs.get(module.getPluginName());
|
||||||
|
if (varargs.length == 0) {
|
||||||
|
module.display(itemStack);
|
||||||
|
} else {
|
||||||
|
module.display(itemStack, varargs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,13 +29,51 @@ public abstract class DisplayModule extends PluginDependent {
|
|||||||
* Display an item.
|
* Display an item.
|
||||||
*
|
*
|
||||||
* @param itemStack The item.
|
* @param itemStack The item.
|
||||||
|
* @param args Optional args for display.
|
||||||
*/
|
*/
|
||||||
protected abstract void display(@NotNull ItemStack itemStack);
|
protected void display(@NotNull final ItemStack itemStack,
|
||||||
|
@NotNull final Object... args) {
|
||||||
|
// Technically optional.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display an item.
|
||||||
|
* <p>
|
||||||
|
* This method exists for parity with older plugins that don't include the varargs.
|
||||||
|
*
|
||||||
|
* @param itemStack The item.
|
||||||
|
* @deprecated Use {@link this#display(ItemStack, Object...)} instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
protected void display(@NotNull final ItemStack itemStack) {
|
||||||
|
// Technically optional.
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Revert an item.
|
* Revert an item.
|
||||||
*
|
*
|
||||||
* @param itemStack The item.
|
* @param itemStack The item.
|
||||||
*/
|
*/
|
||||||
protected abstract void revert(@NotNull ItemStack itemStack);
|
protected void revert(@NotNull final ItemStack itemStack) {
|
||||||
|
// Technically optoinal.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create varargs to pass back to itemstack after reverting, but before display.
|
||||||
|
*
|
||||||
|
* @param itemStack The itemStack.
|
||||||
|
* @return The plugin-specific varargs.
|
||||||
|
*/
|
||||||
|
protected Object[] generateVarArgs(@NotNull final ItemStack itemStack) {
|
||||||
|
return new Object[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get name of plugin.
|
||||||
|
*
|
||||||
|
* @return The plugin name.
|
||||||
|
*/
|
||||||
|
final String getPluginName() {
|
||||||
|
return super.getPlugin().getPluginName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
version = 4.0.0
|
version = 4.2.0
|
||||||
plugin-name = eco
|
plugin-name = eco
|
||||||
Reference in New Issue
Block a user