Module "commons" is now a separate project

This commit is contained in:
filoghost 2020-08-19 14:05:10 +02:00
parent 6bd0c916c4
commit 6b21f1e4f3
105 changed files with 131 additions and 2426 deletions

View File

@ -19,8 +19,8 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>chestcommands-commons</artifactId>
<groupId>me.filoghost.fcommons</groupId>
<artifactId>fcommons</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -9,7 +9,7 @@ import me.filoghost.chestcommands.api.ConfigurableIcon;
import me.filoghost.chestcommands.api.Menu;
import me.filoghost.chestcommands.api.PlaceholderReplacer;
import me.filoghost.chestcommands.api.StaticIcon;
import me.filoghost.commons.Preconditions;
import me.filoghost.fcommons.Preconditions;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>me.filoghost.chestcommands</groupId>
<artifactId>chestcommands-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
</parent>
<artifactId>chestcommands-commons</artifactId>
<name>ChestCommands Commons</name>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,88 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.List;
public abstract class BaseJavaPlugin extends JavaPlugin {
@Override
public final void onEnable() {
try {
// checkPackageRelocation(); TODO enable later
onCheckedEnable();
} catch (PluginEnableException e) {
criticalShutdown(e.getMessage(), null);
} catch (Throwable t) {
criticalShutdown(null, t);
}
}
private void checkPackageRelocation() {
// Prevent Maven's Relocate from changing strings too
final String defaultPackage = new String(
new byte[]{'m', 'e', '.', 'f', 'i', 'l', 'o', 'g', 'h', 'o', 's', 't', '.', 'c', 'o', 'm', 'm', 'o', 'n', 's'});
// Make sure package has been relocated
if (BaseJavaPlugin.class.getPackage().getName().equals(defaultPackage)) {
throw new IllegalStateException("not relocated correctly");
}
}
protected abstract void onCheckedEnable() throws PluginEnableException;
private void criticalShutdown(String errorMessage, Throwable throwable) {
Bukkit.getConsoleSender().sendMessage(getErrorMessage(errorMessage, throwable));
Bukkit.getScheduler().runTaskLater(this, () -> {
Bukkit.getConsoleSender().sendMessage(
getFatalErrorPrefix() + "Fatal error while enabling the plugin. Check previous logs for more information.");
}, 10);
setEnabled(false);
}
protected String getErrorMessage(String errorMessage, Throwable throwable) {
List<String> output = new ArrayList<>();
if (throwable != null) {
output.add(getFatalErrorPrefix() + "Fatal unexpected error while enabling plugin:");
} else {
output.add(getFatalErrorPrefix() + "Fatal error while enabling plugin:");
}
if (throwable != null) {
output.add(" ");
output.add(CommonsUtil.getStackTraceString(throwable));
}
output.add(" ");
if (errorMessage != null) {
output.add(errorMessage);
}
output.add("The plugin has been disabled.");
output.add(" ");
return String.join("\n", output);
}
private String getFatalErrorPrefix() {
return ChatColor.DARK_RED + "[" + getDescription().getName() + "] " + ChatColor.RED;
}
public static class PluginEnableException extends Exception {
public PluginEnableException(String message) {
super(message);
}
}
}

View File

@ -1,19 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons;
import org.bukkit.ChatColor;
public final class Colors {
public static String addColors(String input) {
if (Strings.isEmpty(input)) {
return input;
}
return ChatColor.translateAlternateColorCodes('&', input);
}
}

View File

@ -1,28 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons;
import java.io.PrintWriter;
import java.io.StringWriter;
public class CommonsUtil {
public static boolean isClassLoaded(String name) {
try {
Class.forName(name);
return true;
} catch (Throwable t) {
return false;
}
}
public static String getStackTraceString(Throwable throwable) {
StringWriter stringWriter = new StringWriter();
throwable.printStackTrace(new PrintWriter(stringWriter));
return stringWriter.toString();
}
}

View File

@ -1,113 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons;
import me.filoghost.commons.collection.Registry;
import org.bukkit.Material;
import java.util.Collection;
import java.util.HashSet;
import java.util.Optional;
public final class MaterialsHelper {
// Registry of materials by numerical ID (before 1.13), name and aliases
private static final Registry<Material> MATERIALS_REGISTRY = initMaterialsRegistry();
// Materials that are considered air (with 1.13+ compatibility)
private static final Collection<Material> AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR");
@SuppressWarnings("deprecation")
private static Registry<Material> initMaterialsRegistry() {
Registry<Material> materialsRegistry = Registry.fromEnumValues(Material.class);
// Add numerical IDs in legacy versions (the Tag class was added in 1.13)
if (!CommonsUtil.isClassLoaded("org.bukkit.Tag")) {
for (Material material : Material.values()) {
materialsRegistry.put(Integer.toString(material.getId()), material);
}
}
// Add some default useful aliases (when present)
materialsRegistry.putIfEnumExists("iron bar", "IRON_FENCE");
materialsRegistry.putIfEnumExists("iron bars", "IRON_FENCE");
materialsRegistry.putIfEnumExists("glass pane", "THIN_GLASS");
materialsRegistry.putIfEnumExists("nether wart", "NETHER_STALK");
materialsRegistry.putIfEnumExists("nether warts", "NETHER_STALK");
materialsRegistry.putIfEnumExists("slab", "STEP");
materialsRegistry.putIfEnumExists("double slab", "DOUBLE_STEP");
materialsRegistry.putIfEnumExists("stone brick", "SMOOTH_BRICK");
materialsRegistry.putIfEnumExists("stone bricks", "SMOOTH_BRICK");
materialsRegistry.putIfEnumExists("stone stair", "SMOOTH_STAIRS");
materialsRegistry.putIfEnumExists("stone stairs", "SMOOTH_STAIRS");
materialsRegistry.putIfEnumExists("potato", "POTATO_ITEM");
materialsRegistry.putIfEnumExists("carrot", "CARROT_ITEM");
materialsRegistry.putIfEnumExists("brewing stand", "BREWING_STAND_ITEM");
materialsRegistry.putIfEnumExists("cauldron", "CAULDRON_ITEM");
materialsRegistry.putIfEnumExists("carrot on stick", "CARROT_STICK");
materialsRegistry.putIfEnumExists("carrot on a stick", "CARROT_STICK");
materialsRegistry.putIfEnumExists("cobblestone wall", "COBBLE_WALL");
materialsRegistry.putIfEnumExists("acacia wood stairs", "ACACIA_STAIRS");
materialsRegistry.putIfEnumExists("dark oak wood stairs", "DARK_OAK_STAIRS");
materialsRegistry.putIfEnumExists("wood slab", "WOOD_STEP");
materialsRegistry.putIfEnumExists("double wood slab", "WOOD_DOUBLE_STEP");
materialsRegistry.putIfEnumExists("repeater", "DIODE");
materialsRegistry.putIfEnumExists("piston", "PISTON_BASE");
materialsRegistry.putIfEnumExists("sticky piston", "PISTON_STICKY_BASE");
materialsRegistry.putIfEnumExists("flower pot", "FLOWER_POT_ITEM");
materialsRegistry.putIfEnumExists("wood showel", "WOOD_SPADE");
materialsRegistry.putIfEnumExists("stone showel", "STONE_SPADE");
materialsRegistry.putIfEnumExists("gold showel", "GOLD_SPADE");
materialsRegistry.putIfEnumExists("iron showel", "IRON_SPADE");
materialsRegistry.putIfEnumExists("diamond showel", "DIAMOND_SPADE");
materialsRegistry.putIfEnumExists("steak", "COOKED_BEEF");
materialsRegistry.putIfEnumExists("cooked porkchop", "GRILLED_PORK");
materialsRegistry.putIfEnumExists("raw porkchop", "PORK");
materialsRegistry.putIfEnumExists("hardened clay", "HARD_CLAY");
materialsRegistry.putIfEnumExists("huge brown mushroom", "HUGE_MUSHROOM_1");
materialsRegistry.putIfEnumExists("huge red mushroom", "HUGE_MUSHROOM_2");
materialsRegistry.putIfEnumExists("mycelium", "MYCEL");
materialsRegistry.putIfEnumExists("poppy", "RED_ROSE");
materialsRegistry.putIfEnumExists("comparator", "REDSTONE_COMPARATOR");
materialsRegistry.putIfEnumExists("skull", "SKULL_ITEM");
materialsRegistry.putIfEnumExists("head", "SKULL_ITEM");
materialsRegistry.putIfEnumExists("redstone torch", "REDSTONE_TORCH_ON");
materialsRegistry.putIfEnumExists("redstone lamp", "REDSTONE_LAMP_OFF");
materialsRegistry.putIfEnumExists("glistering melon", "SPECKLED_MELON");
materialsRegistry.putIfEnumExists("acacia leaves", "LEAVES_2");
materialsRegistry.putIfEnumExists("acacia log", "LOG_2");
materialsRegistry.putIfEnumExists("gunpowder", "SULPHUR");
materialsRegistry.putIfEnumExists("lilypad", "WATER_LILY");
materialsRegistry.putIfEnumExists("command block", "COMMAND");
materialsRegistry.putIfEnumExists("dye", "INK_SACK");
return materialsRegistry;
}
public static Optional<Material> matchMaterial(String materialName) {
return MATERIALS_REGISTRY.find(materialName);
}
private static Collection<Material> getExistingMaterials(String... materialEnumNames) {
Collection<Material> existingMaterials = new HashSet<>();
for (String materialEnumName : materialEnumNames) {
try {
existingMaterials.add(Material.valueOf(materialEnumName));
} catch (IllegalArgumentException e) {
// Ignore, not existing
}
}
return existingMaterials;
}
public static boolean isAir(Material material) {
return AIR_MATERIALS.contains(material);
}
}

View File

@ -1,49 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons;
import org.bukkit.Material;
public final class Preconditions {
public static void notNull(Object object, String objectName) {
if (object == null) {
throw new NullPointerException(objectName + " cannot be null");
}
}
public static void checkArgument(boolean expression, String errorMessage) {
if (!expression) {
throw new IllegalArgumentException(errorMessage);
}
}
public static void checkState(boolean expression, String errorMessage) {
if (!expression) {
throw new IllegalStateException(errorMessage);
}
}
public static void checkIndex(int index, int size, String objectName) {
checkArgument(size >= 0, "size cannot be negative");
if (index < 0) {
throw new IndexOutOfBoundsException(objectName + " (" + index + ") cannot be negative");
}
if (index >= size) {
throw new IndexOutOfBoundsException(objectName + " (" + index + ") must be less than size (" + size + ")");
}
}
public static void checkArgumentNotAir(Material material, String objectName) {
notNull(material, objectName);
if (MaterialsHelper.isAir(material)) {
throw new IllegalArgumentException(objectName + " cannot be " + material);
}
}
}

View File

@ -1,89 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons;
public final class Strings {
public static String[] trimmedSplit(String string, String pattern) {
return trimmedSplit(string, pattern, 0);
}
public static String[] trimmedSplit(String string, String pattern, int limit) {
String[] output = string.split(pattern, limit);
for (int i = 0; i < output.length; i++) {
output[i] = output[i].trim();
}
return output;
}
public static String stripChars(String string, char... charsToRemove) {
if (isEmpty(string) || charsToRemove.length == 0) {
return string;
}
StringBuilder result = new StringBuilder(string.length());
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
if (!arrayContains(charsToRemove, c)) {
result.append(c);
}
}
return result.toString();
}
private static boolean arrayContains(char[] array, char valueToFind) {
for (char c : array) {
if (c == valueToFind) {
return true;
}
}
return false;
}
public static String capitalizeFully(String string) {
if (isEmpty(string)) {
return string;
}
string = string.toLowerCase();
int length = string.length();
StringBuilder result = new StringBuilder(length);
boolean capitalizeNext = true;
for (int i = 0; i < length; i++) {
char c = string.charAt(i);
if (Character.isWhitespace(c)) {
result.append(c);
capitalizeNext = true;
} else if (capitalizeNext) {
result.append(Character.toTitleCase(c));
capitalizeNext = false;
} else {
result.append(c);
}
}
return result.toString();
}
public static String capitalizeFirst(String string) {
if (isEmpty(string)) {
return string;
}
return Character.toTitleCase(string.charAt(0)) + string.substring(1);
}
public static boolean isEmpty(String string) {
return string == null || string.isEmpty();
}
}

View File

@ -1,90 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.collection;
import me.filoghost.commons.Preconditions;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class CaseInsensitiveMap<V> implements Map<String, V> {
private final Map<String, V> delegate;
public CaseInsensitiveMap() {
this.delegate = new HashMap<>();
}
@Override
public V put(String key, V value) {
return delegate.put(getLowercaseKey(key), value);
}
@Override
public V get(Object key) {
return delegate.get(getLowercaseKey(key));
}
@Override
public boolean containsKey(Object key) {
return delegate.containsKey(getLowercaseKey(key));
}
@Override
public V remove(Object key) {
return delegate.remove(getLowercaseKey(key));
}
@Override
public int size() {
return delegate.size();
}
@Override
public boolean isEmpty() {
return delegate.isEmpty();
}
@Override
public boolean containsValue(Object value) {
return delegate.containsValue(value);
}
@Override
public void putAll(Map<? extends String, ? extends V> map) {
map.forEach(this::put);
}
@Override
public void clear() {
delegate.clear();
}
@Override
public Set<String> keySet() {
return Collections.unmodifiableSet(delegate.keySet());
}
@Override
public Collection<V> values() {
return Collections.unmodifiableCollection(delegate.values());
}
@Override
public Set<Entry<String, V>> entrySet() {
return Collections.unmodifiableSet(delegate.entrySet());
}
private String getLowercaseKey(Object key) {
Preconditions.notNull(key, "key");
Preconditions.checkArgument(key instanceof String, "key must be a string");
return ((String) key).toLowerCase();
}
}

View File

@ -1,68 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.collection;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
public final class CollectionUtils {
public static <E> List<E> copy(List<E> list) {
if (list != null) {
return new ArrayList<>(list);
} else {
return null;
}
}
public static <K, V> Map<K, V> copy(Map<K, V> map) {
if (map != null) {
return new HashMap<>(map);
} else {
return null;
}
}
public static <E> ImmutableList<E> immutableCopy(List<E> list) {
if (list != null) {
return ImmutableList.copyOf(list);
} else {
return null;
}
}
public static <A, B> List<B> transform(List<A> list, Function<A, B> transformFunction) {
if (list == null) {
return null;
}
List<B> result = new ArrayList<>(list.size());
for (A element : list) {
result.add(transformFunction.apply(element));
}
return result;
}
public static <A, B> ImmutableList<B> transformImmutable(List<A> list, Function<A, B> transformFunction) {
if (list == null) {
return null;
}
ImmutableList.Builder<B> builder = ImmutableList.builder();
for (A element : list) {
builder.add(transformFunction.apply(element));
}
return builder.build();
}
public static <E> List<E> replaceNulls(List<E> list, E replacement) {
return transform(list, element -> element != null ? element : replacement);
}
}

View File

@ -1,83 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.collection;
import me.filoghost.commons.Preconditions;
import me.filoghost.commons.Strings;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
public class Registry<T> {
// Characters to ignore when searching enums by name
private static final char[] KEY_IGNORE_CHARS = {'-', '_', ' '};
private final Class<T> valuesType;
private final Map<String, T> valuesMap;
public static <T extends Enum<T>> Registry<T> fromEnumValues(Class<T> enumClass) {
Registry<T> registry = new Registry<>(enumClass);
registry.putAll(enumClass.getEnumConstants(), Enum::name);
return registry;
}
public static <T> Registry<T> fromValues(T[] values, Function<T, String> toKeyFunction) {
Registry<T> registry = new Registry<>(null);
registry.putAll(values, toKeyFunction);
return registry;
}
private Registry(Class<T> valuesType) {
this.valuesType = valuesType;
this.valuesMap = new HashMap<>();
}
public Optional<T> find(String key) {
if (key == null) {
return Optional.empty();
}
return Optional.ofNullable(valuesMap.get(toKeyFormat(key)));
}
public void putIfEnumExists(String key, String enumValueName) {
Preconditions.checkState(valuesType.isEnum(), "value type is not an enum");
try {
@SuppressWarnings({ "unchecked", "rawtypes" })
T enumValue = (T) Enum.valueOf((Class<Enum>) valuesType, enumValueName);
put(key, enumValue);
} catch (IllegalArgumentException e) {
// Ignore, enum value doesn't exist
}
}
private void putAll(T[] enumValues, Function<T, String> toKeyFunction) {
for (T enumValue : enumValues) {
valuesMap.put(toKeyFormat(toKeyFunction.apply(enumValue)), enumValue);
}
}
public void put(String key, T enumValue) {
valuesMap.put(toKeyFormat(key), enumValue);
}
private String toKeyFormat(String enumValueName) {
return Strings.stripChars(enumValueName, KEY_IGNORE_CHARS).toLowerCase();
}
@Override
public String toString() {
return "Registry [type=" + valuesType + ", values=" + valuesMap + "]";
}
}

View File

@ -1,16 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.command;
public class CommandException extends RuntimeException {
private static final long serialVersionUID = 1L;
public CommandException(String msg) {
super(msg);
}
}

View File

@ -1,64 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.command;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Wrapper for the default command executor.
*/
public abstract class CommandFramework implements CommandExecutor {
private final String label;
public CommandFramework(String label) {
this.label = label;
}
public abstract void execute(CommandSender sender, String label, String[] args);
/**
* Default implementation of Bukkit's command executor.
*/
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
try {
execute(sender, label, args);
} catch (CommandException ex) {
if (ex.getMessage() != null && !ex.getMessage().isEmpty()) {
// Use RED by default
sender.sendMessage(ChatColor.RED + ex.getMessage());
}
}
return true;
}
/**
* Register a command through the framework.
*/
public static boolean register(JavaPlugin plugin, CommandFramework command) {
PluginCommand pluginCommand = plugin.getCommand(command.label);
if (pluginCommand == null) {
return false;
}
pluginCommand.setExecutor(command);
return true;
}
}

View File

@ -1,28 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.command;
public class CommandValidate {
public static void notNull(Object o, String msg) {
if (o == null) {
throw new CommandException(msg);
}
}
public static void isTrue(boolean b, String msg) {
if (!b) {
throw new CommandException(msg);
}
}
public static void minLength(Object[] array, int minLength, String msg) {
if (array.length < minLength) {
throw new CommandException(msg);
}
}
}

View File

@ -1,42 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config;
import me.filoghost.commons.config.mapped.MappedConfig;
import me.filoghost.commons.config.mapped.MappedConfigLoader;
import java.nio.file.Path;
import java.util.function.Supplier;
public class BaseConfigManager {
protected final Path rootDataFolder;
public BaseConfigManager(Path rootDataFolder) {
this.rootDataFolder = rootDataFolder;
}
public Path getRootDataFolder() {
return rootDataFolder;
}
public ConfigLoader getConfigLoader(String fileName) {
return getConfigLoader(rootDataFolder.resolve(fileName));
}
public ConfigLoader getConfigLoader(Path configPath) {
return new ConfigLoader(rootDataFolder, configPath);
}
public <T extends MappedConfig> MappedConfigLoader<T> getMappedConfigLoader(String fileName, Supplier<T> mappedObjectConstructor) {
return getMappedConfigLoader(rootDataFolder.resolve(fileName), mappedObjectConstructor);
}
public <T extends MappedConfig> MappedConfigLoader<T> getMappedConfigLoader(Path configPath, Supplier<T> mappedObjectConstructor) {
return new MappedConfigLoader<>(rootDataFolder, configPath, mappedObjectConstructor);
}
}

View File

@ -1,41 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config;
import me.filoghost.commons.Preconditions;
import org.bukkit.configuration.file.YamlConfiguration;
import java.nio.file.Path;
public class Config extends ConfigSection {
private final YamlConfiguration yaml;
private final Path sourceFile;
public Config(Path sourceFile) {
this(new YamlConfiguration(), sourceFile);
}
public Config(YamlConfiguration yaml, Path sourceFile) {
super(yaml);
Preconditions.notNull(sourceFile, "sourceFile");
this.yaml = yaml;
this.sourceFile = sourceFile;
}
public Path getSourceFile() {
return sourceFile;
}
public String saveToString() {
return yaml.saveToString();
}
public void setHeader(String value) {
yaml.options().header(value);
}
}

View File

@ -1,61 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config;
import me.filoghost.commons.config.mapped.MappedConfig;
import me.filoghost.commons.config.mapped.MappedField;
import me.filoghost.commons.config.mapped.converter.Converter;
import java.nio.file.Path;
public class ConfigErrors {
public static final String readIOException = "I/O exception while reading file";
public static final String createDefaultIOException = "I/O exception while creating default file";
public static final String writeDataIOException = "I/O exception while writing data to file";
public static final String invalidYamlSyntax = "invalid YAML syntax";
public static final String valueNotSet = "value is not set";
public static final String valueNotList = "value is not a list";
public static final String valueNotBoolean = "value is not a boolean";
public static final String valueNotNumber = "value is not a number";
public static final String valueNotString = "value is not a string";
public static final String valueNotSection = "value is not a configuration section";
public static String createParentFolderIOException(Path rootDataFolder, Path folder) {
return "I/O exception while creating parent directory \"" + formatPath(rootDataFolder, folder) + "\"";
}
public static String mapperInitError(MappedConfig mappedConfig) {
return "couldn't initialize config mapper for class \"" + mappedConfig.getClass() + "\"";
}
public static String fieldReadError(MappedConfig mappedConfig) {
return "couldn't read field values from class \"" + mappedConfig.getClass() + "\"";
}
public static String fieldInjectError(MappedConfig mappedConfig) {
return "couldn't inject fields values in class \"" + mappedConfig.getClass() + "\"";
}
public static String mapperFieldCannotBeNull(MappedField mappedField) {
return "mapped field \"" + mappedField.getFieldName() + "\" cannot be null by default";
}
public static String converterFailed(Object value, Converter converter) {
return "value of type \"" + value.getClass() + "\" couldn't be converted by \"" + converter.getClass() + "\"";
}
public static String formatPath(Path rootDataFolder, Path path) {
if (path.startsWith(rootDataFolder)) {
// Remove root data folder prefix
return path.subpath(rootDataFolder.getNameCount(), path.getNameCount()).toString();
} else {
return path.toString();
}
}
}

View File

@ -1,130 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config;
import me.filoghost.commons.Preconditions;
import me.filoghost.commons.config.exception.ConfigLoadException;
import me.filoghost.commons.config.exception.ConfigSaveException;
import me.filoghost.commons.config.exception.ConfigSyntaxException;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
public class ConfigLoader {
private final Path rootDataFolder;
private final Path file;
public ConfigLoader(Path rootDataFolder, Path file) {
Preconditions.checkArgument(file.startsWith(rootDataFolder), "file \"" + file + "\" must be inside \"" + rootDataFolder + "\"");
this.rootDataFolder = rootDataFolder;
this.file = file;
}
public Config init() throws ConfigSaveException, ConfigLoadException {
createDefault();
return load();
}
public void createDefault() throws ConfigSaveException {
if (fileExists()) {
return;
}
createParentDirectory();
Path relativeConfigPath = rootDataFolder.relativize(file);
String internalJarPath = toInternalJarPath(relativeConfigPath);
try (InputStream defaultFile = getInternalResource(internalJarPath)) {
if (defaultFile != null) {
Files.copy(defaultFile, file);
} else {
Files.createFile(file);
}
} catch (IOException e) {
throw new ConfigSaveException(ConfigErrors.createDefaultIOException, e);
}
}
private String toInternalJarPath(Path path) {
return StreamSupport.stream(path.spliterator(), false)
.map(Path::toString)
.collect(Collectors.joining("/", "/", ""));
}
private InputStream getInternalResource(String internalJarPath) throws IOException {
Preconditions.notNull(internalJarPath, "internalJarPath");
URL resourceURL = getClass().getResource(internalJarPath);
if (resourceURL == null) {
return null;
}
URLConnection connection = resourceURL.openConnection();
connection.setUseCaches(false);
return connection.getInputStream();
}
public boolean fileExists() {
return Files.isRegularFile(file);
}
public Config load() throws ConfigLoadException {
Preconditions.checkState(fileExists(), "\"" + file + "\" doesn't exist or is not a regular file");
YamlConfiguration yaml = new YamlConfiguration();
try (BufferedReader reader = Files.newBufferedReader(file)) {
yaml.load(reader);
} catch (IOException e) {
throw new ConfigLoadException(ConfigErrors.readIOException, e);
} catch (InvalidConfigurationException e) {
throw new ConfigSyntaxException(ConfigErrors.invalidYamlSyntax, e);
}
return new Config(yaml, file);
}
public void save(Config config) throws ConfigSaveException {
createParentDirectory();
String data = config.saveToString();
try (BufferedWriter writer = Files.newBufferedWriter(file)) {
writer.write(data);
} catch (IOException e) {
throw new ConfigSaveException(ConfigErrors.writeDataIOException, e);
}
}
private void createParentDirectory() throws ConfigSaveException {
if (file.getParent() != null) {
try {
Files.createDirectories(file.getParent());
} catch (IOException e) {
throw new ConfigSaveException(ConfigErrors.createParentFolderIOException(rootDataFolder, file.getParent()), e);
}
}
}
public Path getFile() {
return file;
}
}

View File

@ -1,12 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config;
public interface ConfigPath {
String getConfigPath();
}

View File

@ -1,188 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config;
import me.filoghost.commons.Preconditions;
import me.filoghost.commons.config.exception.InvalidConfigValueException;
import me.filoghost.commons.config.exception.MissingConfigValueException;
import org.bukkit.configuration.ConfigurationSection;
import java.util.List;
import java.util.Set;
public class ConfigSection {
private final ConfigurationSection yamlSection;
public ConfigSection(ConfigurationSection yamlSection) {
Preconditions.notNull(yamlSection, "yamlSection");
this.yamlSection = yamlSection;
}
public ConfigValue get(String path) {
return ConfigValue.fromRawConfigValue(getRawValue(path));
}
public <T> T get(String path, ConfigValueType<T> configValueType) {
return getOrDefault(path, configValueType, null);
}
public <T> T getRequired(String path, ConfigValueType<T> configValueType) throws MissingConfigValueException, InvalidConfigValueException {
return configValueType.fromConfigValueRequired(getRawValue(path));
}
public <T> T getOrDefault(String path, ConfigValueType<T> configValueType, T defaultValue) {
return configValueType.fromConfigValueOrDefault(getRawValue(path), defaultValue);
}
public <T> void set(String path, ConfigValue configValue) {
setRawValue(path, configValue.getRawConfigValue());
}
public <T> void set(String path, ConfigValueType<T> configValueType, T value) {
setRawValue(path, configValueType.toConfigValue(value));
}
public boolean contains(String path) {
return getRawValue(path) != null;
}
public void remove(String path) {
setRawValue(path, null);
}
public ConfigSection createSection(String path) {
return new ConfigSection(yamlSection.createSection(path));
}
public Set<String> getKeys() {
return yamlSection.getKeys(false);
}
private Object getRawValue(String path) {
return yamlSection.get(path, null);
}
private void setRawValue(String path, Object value) {
Preconditions.checkArgument(!(value instanceof ConfigurationSection), "cannot set ConfigurationSection as value");
yamlSection.set(path, value);
}
protected ConfigurationSection getInternalYamlSection() {
return yamlSection;
}
/*
* Convenience getRequired{TYPE} alias methods
*/
public String getRequiredString(String path) throws MissingConfigValueException, InvalidConfigValueException {
return getRequired(path, ConfigValueType.STRING);
}
public boolean getRequiredBoolean(String path) throws MissingConfigValueException, InvalidConfigValueException {
return getRequired(path, ConfigValueType.BOOLEAN);
}
public int getRequiredInt(String path) throws MissingConfigValueException, InvalidConfigValueException {
return getRequired(path, ConfigValueType.INTEGER);
}
public double getRequiredDouble(String path) throws MissingConfigValueException, InvalidConfigValueException {
return getRequired(path, ConfigValueType.DOUBLE);
}
public List<String> getRequiredStringList(String path) throws MissingConfigValueException, InvalidConfigValueException {
return getRequired(path, ConfigValueType.STRING_LIST);
}
public ConfigSection getRequiredConfigSection(String path) throws MissingConfigValueException, InvalidConfigValueException {
return getRequired(path, ConfigValueType.CONFIG_SECTION);
}
/*
* Convenience get{TYPE} (without defaults) alias methods
*/
public String getString(String path) {
return getOrDefault(path, ConfigValueType.STRING, null);
}
public boolean getBoolean(String path) {
return getOrDefault(path, ConfigValueType.BOOLEAN, false);
}
public int getInt(String path) {
return getOrDefault(path, ConfigValueType.INTEGER, 0);
}
public double getDouble(String path) {
return getOrDefault(path, ConfigValueType.DOUBLE, 0.0);
}
public List<String> getStringList(String path) {
return getOrDefault(path, ConfigValueType.STRING_LIST, null);
}
public ConfigSection getConfigSection(String path) {
return getOrDefault(path, ConfigValueType.CONFIG_SECTION, null);
}
/*
* Convenience get{TYPE} (with defaults) alias methods
*/
public String getString(String path, String defaultValue) {
return getOrDefault(path, ConfigValueType.STRING, defaultValue);
}
public boolean getBoolean(String path, boolean defaultValue) {
return getOrDefault(path, ConfigValueType.BOOLEAN, defaultValue);
}
public int getInt(String path, int defaultValue) {
return getOrDefault(path, ConfigValueType.INTEGER, defaultValue);
}
public double getDouble(String path, double defaultValue) {
return getOrDefault(path, ConfigValueType.DOUBLE, defaultValue);
}
public List<String> getStringList(String path, List<String> defaultValue) {
return getOrDefault(path, ConfigValueType.STRING_LIST, defaultValue);
}
public ConfigSection getConfigSection(String path, ConfigSection defaultValue) {
return getOrDefault(path, ConfigValueType.CONFIG_SECTION, defaultValue);
}
/*
* Convenience set{TYPE} alias methods
*/
public void setString(String path, String value) {
set(path, ConfigValueType.STRING, value);
}
public void setBoolean(String path, boolean value) {
set(path, ConfigValueType.BOOLEAN, value);
}
public void setInt(String path, int value) {
set(path, ConfigValueType.INTEGER, value);
}
public void setDouble(String path, double value) {
set(path, ConfigValueType.DOUBLE, value);
}
public void setStringList(String path, List<String> value) {
set(path, ConfigValueType.STRING_LIST, value);
}
public void setConfigSection(String path, ConfigSection value) {
set(path, ConfigValueType.CONFIG_SECTION, value);
}
}

View File

@ -1,56 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config;
import me.filoghost.commons.Preconditions;
import me.filoghost.commons.config.exception.InvalidConfigValueException;
import me.filoghost.commons.config.exception.MissingConfigValueException;
public class ConfigValue {
private static final ConfigValue EMPTY = new ConfigValue(null);
private final Object rawConfigValue;
public static <T> ConfigValue of(ConfigValueType<T> valueType, T value) {
Preconditions.notNull(valueType, "valueType");
Preconditions.notNull(value, "value");
return new ConfigValue(valueType.toConfigValue(value));
}
protected static ConfigValue fromRawConfigValue(Object rawConfigValue) {
if (rawConfigValue != null) {
return new ConfigValue(rawConfigValue);
} else {
return EMPTY;
}
}
private ConfigValue(Object rawConfigValue) {
this.rawConfigValue = rawConfigValue;
}
protected Object getRawConfigValue() {
return rawConfigValue;
}
public <T> T as(ConfigValueType<T> valueType) {
return valueType.fromConfigValueOrDefault(rawConfigValue, null);
}
public <T> T asRequired(ConfigValueType<T> valueType) throws MissingConfigValueException, InvalidConfigValueException {
return valueType.fromConfigValueRequired(rawConfigValue);
}
public <T> T asOrDefault(ConfigValueType<T> valueType, T defaultValue) {
return valueType.fromConfigValueOrDefault(rawConfigValue, defaultValue);
}
public boolean isValidAs(ConfigValueType<?> configValueType) {
return configValueType.isValidConfigValue(rawConfigValue);
}
}

View File

@ -1,138 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config;
import me.filoghost.commons.config.exception.InvalidConfigValueException;
import me.filoghost.commons.config.exception.MissingConfigValueException;
import org.bukkit.configuration.ConfigurationSection;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
public class ConfigValueType<T> {
public static final ConfigValueType<String> STRING = new ConfigValueType<>(
(Object value) -> value instanceof String || value instanceof Number || value instanceof Boolean || value instanceof Character,
(Object value) -> value.toString(),
(String value) -> value,
ConfigErrors.valueNotString
);
public static final ConfigValueType<Boolean> BOOLEAN = new ConfigValueType<>(
(Object value) -> value instanceof Boolean,
(Object value) -> (Boolean) value,
(Boolean value) -> value,
ConfigErrors.valueNotBoolean
);
public static final ConfigValueType<Long> LONG = newNumberType(Number::longValue);
public static final ConfigValueType<Integer> INTEGER = newNumberType(Number::intValue);
public static final ConfigValueType<Short> SHORT = newNumberType(Number::shortValue);
public static final ConfigValueType<Byte> BYTE = newNumberType(Number::byteValue);
public static final ConfigValueType<Double> DOUBLE = newNumberType(Number::doubleValue);
public static final ConfigValueType<Float> FLOAT = newNumberType(Number::floatValue);
public static final ConfigValueType<List<String>> STRING_LIST = newListType(STRING);
public static final ConfigValueType<List<Integer>> INTEGER_LIST = newListType(INTEGER);
public static final ConfigValueType<List<?>> LIST = new ConfigValueType<>(
(Object value) -> value instanceof List,
(Object value) -> (List<?>) value,
(List<?> value) -> value,
ConfigErrors.valueNotList
);
public static final ConfigValueType<ConfigSection> CONFIG_SECTION = new ConfigValueType<>(
(Object value) -> value instanceof ConfigurationSection,
(Object value) -> new ConfigSection((ConfigurationSection) value),
(ConfigSection value) -> value.getInternalYamlSection(),
ConfigErrors.valueNotSection
);
private final Predicate<Object> isValidConfigValueFunction;
private final Function<Object, T> fromConfigValueFunction;
private final Function<T, Object> toConfigValueFunction;
private final String notConvertibleErrorMessage;
public ConfigValueType(
Predicate<Object> isConvertibleFunction,
Function<Object, T> fromConfigValueFunction,
Function<T, Object> toConfigValueFunction,
String notConvertibleErrorMessage) {
this.isValidConfigValueFunction = isConvertibleFunction;
this.fromConfigValueFunction = fromConfigValueFunction;
this.toConfigValueFunction = toConfigValueFunction;
this.notConvertibleErrorMessage = notConvertibleErrorMessage;
}
protected boolean isValidConfigValue(Object rawConfigValue) {
return rawConfigValue != null && isValidConfigValueFunction.test(rawConfigValue);
}
protected T fromConfigValueRequired(Object rawConfigValue) throws MissingConfigValueException, InvalidConfigValueException {
if (rawConfigValue == null) {
throw new MissingConfigValueException(ConfigErrors.valueNotSet);
}
if (isValidConfigValueFunction.test(rawConfigValue)) {
return fromConfigValueFunction.apply(rawConfigValue);
} else {
throw new InvalidConfigValueException(notConvertibleErrorMessage);
}
}
protected T fromConfigValueOrDefault(Object rawConfigValue, T defaultValue) {
if (rawConfigValue == null) {
return defaultValue;
}
if (isValidConfigValueFunction.test(rawConfigValue)) {
return fromConfigValueFunction.apply(rawConfigValue);
} else {
return defaultValue;
}
}
protected Object toConfigValue(T value) {
if (value != null) {
return toConfigValueFunction.apply(value);
} else {
return null;
}
}
private static <T extends Number> ConfigValueType<T> newNumberType(Function<Number, T> toTypeFunction) {
return new ConfigValueType<>(
(Object value) -> value instanceof Number,
(Object value) -> toTypeFunction.apply((Number) value),
(T value) -> value,
ConfigErrors.valueNotNumber
);
}
private static <T> ConfigValueType<List<T>> newListType(ConfigValueType<T> elementType) {
return new ConfigValueType<>(
(Object value) -> value instanceof List,
(Object value) -> {
List<T> result = new ArrayList<>();
for (Object element : ((List<?>) value)) {
if (elementType.isValidConfigValueFunction.test(element)) {
result.add(elementType.fromConfigValueFunction.apply(element));
}
}
return result;
},
(List<T> value) -> value,
ConfigErrors.valueNotList
);
}
}

View File

@ -1,16 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config;
import org.bukkit.configuration.MemoryConfiguration;
public class EmptyConfigSection extends ConfigSection {
public EmptyConfigSection() {
super(new MemoryConfiguration());
}
}

View File

@ -1,18 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.exception;
public class ConfigException extends Exception {
public ConfigException(String message) {
super(message);
}
public ConfigException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -1,18 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.exception;
public class ConfigLoadException extends ConfigException {
public ConfigLoadException(String message, Throwable cause) {
super(message, cause);
}
public ConfigLoadException(String message) {
super(message);
}
}

View File

@ -1,14 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.exception;
public class ConfigSaveException extends ConfigException {
public ConfigSaveException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -1,23 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.exception;
import org.bukkit.configuration.InvalidConfigurationException;
public class ConfigSyntaxException extends ConfigLoadException {
private final String parsingErrorDetails;
public ConfigSyntaxException(String message, InvalidConfigurationException cause) {
super(message, cause);
this.parsingErrorDetails = cause.getMessage();
}
public String getParsingErrorDetails() {
return parsingErrorDetails;
}
}

View File

@ -1,14 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.exception;
public abstract class ConfigValueException extends ConfigException {
public ConfigValueException(String message) {
super(message);
}
}

View File

@ -1,14 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.exception;
public class ConverterCastException extends ConfigException {
public ConverterCastException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -1,14 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.exception;
public class InvalidConfigValueException extends ConfigValueException {
public InvalidConfigValueException(String message) {
super(message);
}
}

View File

@ -1,14 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.exception;
public class MissingConfigValueException extends ConfigValueException {
public MissingConfigValueException(String message) {
super(message);
}
}

View File

@ -1,174 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped;
import com.google.common.collect.ImmutableList;
import me.filoghost.commons.config.ConfigErrors;
import me.filoghost.commons.config.ConfigSection;
import me.filoghost.commons.config.ConfigValue;
import me.filoghost.commons.config.ConfigValueType;
import me.filoghost.commons.config.exception.ConfigLoadException;
import me.filoghost.commons.config.exception.ConverterCastException;
import me.filoghost.commons.config.mapped.converter.BooleanConverter;
import me.filoghost.commons.config.mapped.converter.Converter;
import me.filoghost.commons.config.mapped.converter.DoubleConverter;
import me.filoghost.commons.config.mapped.converter.IntegerConverter;
import me.filoghost.commons.config.mapped.converter.ListConverter;
import me.filoghost.commons.config.mapped.converter.StringConverter;
import me.filoghost.commons.config.mapped.modifier.ChatColorsModifier;
import me.filoghost.commons.config.mapped.modifier.ValueModifier;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class ConfigMapper {
private static final List<Converter> CONVERTERS = ImmutableList.of(
new DoubleConverter(),
new IntegerConverter(),
new BooleanConverter(),
new StringConverter(),
new ListConverter()
);
private static final List<ValueModifier<?, ?>> VALUE_MODIFIERS = ImmutableList.of(
new ChatColorsModifier()
);
private final MappedConfig mappedObject;
private final ConfigSection config;
private final List<MappedField> mappedFields;
public ConfigMapper(MappedConfig mappedObject, ConfigSection config) throws ReflectiveOperationException {
this.mappedObject = mappedObject;
this.config = config;
this.mappedFields = getMappableFields(mappedObject.getClass());
}
private List<MappedField> getMappableFields(Class<?> type) throws ReflectiveOperationException {
Field[] declaredFields;
List<MappedField> mappedFields = new ArrayList<>();
try {
declaredFields = type.getDeclaredFields();
for (Field field : declaredFields) {
if (isMappable(field)) {
mappedFields.add(new MappedField(field));
}
}
} catch (Throwable t) {
throw new ReflectiveOperationException(t);
}
return mappedFields;
}
private boolean isMappable(Field field) {
int modifiers = field.getModifiers();
boolean includeStatic = field.isAnnotationPresent(IncludeStatic.class)
|| field.getDeclaringClass().isAnnotationPresent(IncludeStatic.class);
return (!Modifier.isStatic(modifiers) || includeStatic)
|| !Modifier.isTransient(modifiers)
|| !Modifier.isFinal(modifiers);
}
public Map<MappedField, Object> getFieldValues() throws ReflectiveOperationException {
Map<MappedField, Object> mappedFieldValues = new HashMap<>();
for (MappedField mappedField : mappedFields) {
Object defaultValue = mappedField.getFromObject(mappedObject);
if (defaultValue == null) {
throw new ReflectiveOperationException(ConfigErrors.mapperFieldCannotBeNull(mappedField));
}
mappedFieldValues.put(mappedField, defaultValue);
}
return mappedFieldValues;
}
public Map<String, ConfigValue> toConfigValues(Map<MappedField, Object> fieldValues) throws ConfigLoadException {
Map<String, ConfigValue> configValues = new HashMap<>();
for (Entry<MappedField, Object> entry : fieldValues.entrySet()) {
MappedField mappedField = entry.getKey();
Object defaultValue = entry.getValue();
Converter converter = findConverter(mappedField.getFieldType());
try {
configValues.put(mappedField.getConfigPath(), converter.toConfigValue(mappedField, defaultValue));
} catch (ConverterCastException e) {
throw new ConfigLoadException("error while converting field \"" + mappedField.getFieldName() + "\"", e);
}
}
return configValues;
}
public boolean addMissingConfigValues(Map<String, ConfigValue> defaultValues) {
boolean modified = false;
for (Entry<String, ConfigValue> entry : defaultValues.entrySet()) {
String path = entry.getKey();
ConfigValue defaultValue = entry.getValue();
if (!config.contains(path)) {
modified = true;
config.set(path, defaultValue);
}
}
return modified;
}
public void injectObjectFields() throws ReflectiveOperationException {
for (MappedField mappedField : mappedFields) {
injectObjectField(mappedField);
}
}
private void injectObjectField(MappedField mappedField) throws ReflectiveOperationException {
Type[] genericTypes = mappedField.getGenericTypes();
Converter converter = findConverter(mappedField.getFieldType());
ConfigValueType<?> configValueType = converter.getConfigValueType(genericTypes);
Object fieldValue = config.get(mappedField.getConfigPath(), configValueType);
for (Annotation annotation : mappedField.getAnnotations()) {
fieldValue = applyValueModifiers(fieldValue, annotation);
}
mappedField.setToObject(mappedObject, fieldValue);
}
private Object applyValueModifiers(Object fieldValue, Annotation annotation) {
for (ValueModifier<?, ?> modifier : VALUE_MODIFIERS) {
if (modifier.isApplicable(annotation, fieldValue)) {
fieldValue = modifier.transform(annotation, fieldValue);
}
}
return fieldValue;
}
private Converter findConverter(Class<?> type) {
return CONVERTERS.stream()
.filter(converter -> converter.matches(type))
.findFirst()
.orElseThrow(() -> new IllegalStateException("cannot find converter for type " + type));
}
}

View File

@ -1,17 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE})
public @interface IncludeStatic {
}

View File

@ -1,24 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped;
import me.filoghost.commons.config.exception.ConfigLoadException;
public class MappedConfig {
private String header;
protected void setHeader(String... header) {
this.header = String.join("\n", header) + "\n";
}
public String getHeader() {
return header;
}
public void postLoad() throws ConfigLoadException {}
}

View File

@ -1,71 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped;
import me.filoghost.commons.config.Config;
import me.filoghost.commons.config.ConfigErrors;
import me.filoghost.commons.config.ConfigLoader;
import me.filoghost.commons.config.ConfigValue;
import me.filoghost.commons.config.exception.ConfigLoadException;
import me.filoghost.commons.config.exception.ConfigSaveException;
import java.nio.file.Path;
import java.util.Map;
import java.util.function.Supplier;
public class MappedConfigLoader<T extends MappedConfig> {
private final ConfigLoader configLoader;
private final Supplier<T> mappedObjectConstructor;
private Map<String, ConfigValue> defaultValues;
public MappedConfigLoader(Path rootDataFolder, Path configPath, Supplier<T> mappedObjectConstructor) {
this.configLoader = new ConfigLoader(rootDataFolder, configPath);
this.mappedObjectConstructor = mappedObjectConstructor;
}
public T init() throws ConfigLoadException, ConfigSaveException {
Config config = configLoader.init();
T mappedObject = mappedObjectConstructor.get();
ConfigMapper mapper;
try {
mapper = new ConfigMapper(mappedObject, config);
} catch (ReflectiveOperationException e) {
throw new ConfigLoadException(ConfigErrors.mapperInitError(mappedObject), e);
}
// Extract default values from fields
if (defaultValues == null) {
try {
defaultValues = mapper.toConfigValues(mapper.getFieldValues());
} catch (ReflectiveOperationException e) {
throw new ConfigLoadException(ConfigErrors.fieldReadError(mappedObject), e);
}
}
// Add missing values and save if necessary
boolean modified = mapper.addMissingConfigValues(defaultValues);
if (modified) {
config.setHeader(mappedObject.getHeader());
configLoader.save(config);
}
// Update the mapped object with the contents from the config
try {
mapper.injectObjectFields();
} catch (ReflectiveOperationException e) {
throw new ConfigLoadException(ConfigErrors.fieldInjectError(mappedObject), e);
}
mappedObject.postLoad();
return mappedObject;
}
public Path getFile() {
return configLoader.getFile();
}
}

View File

@ -1,87 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class MappedField {
private final Field field;
private final String configPath;
private final Type[] genericTypes;
private final List<Annotation> annotations;
public MappedField(Field field) throws ReflectiveOperationException {
this.field = field;
this.configPath = field.getName()
.replace("__", ".")
.replace("_", "-");
try {
Type genericType = field.getGenericType();
if (genericType instanceof ParameterizedType) {
this.genericTypes = ((ParameterizedType) genericType).getActualTypeArguments();
} else {
this.genericTypes = null;
}
annotations = Stream.concat(
Arrays.stream(field.getDeclaredAnnotations()),
Arrays.stream(field.getDeclaringClass().getDeclaredAnnotations()))
.collect(Collectors.toList());
} catch (Throwable t) {
throw new ReflectiveOperationException(t);
}
}
public Object getFromObject(MappedConfig mappedObject) throws ReflectiveOperationException {
try {
field.setAccessible(true);
return field.get(mappedObject);
} catch (Throwable t) {
throw new ReflectiveOperationException(t);
}
}
public void setToObject(MappedConfig mappedObject, Object fieldValue) throws ReflectiveOperationException {
try {
field.setAccessible(true);
field.set(mappedObject, fieldValue);
} catch (Throwable t) {
throw new ReflectiveOperationException(t);
}
}
public Type[] getGenericTypes() {
return genericTypes;
}
public List<Annotation> getAnnotations() {
return annotations;
}
public String getFieldName() {
return field.getName();
}
public Class<?> getFieldType() {
return field.getType();
}
public String getConfigPath() {
return configPath;
}
}

View File

@ -1,24 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped.converter;
import me.filoghost.commons.config.ConfigValueType;
import java.lang.reflect.Type;
public class BooleanConverter implements Converter {
@Override
public ConfigValueType<?> getConfigValueType(Type[] fieldGenericTypes) {
return ConfigValueType.BOOLEAN;
}
@Override
public boolean matches(Class<?> type) {
return type == Boolean.class || type == boolean.class;
}
}

View File

@ -1,38 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped.converter;
import me.filoghost.commons.config.ConfigErrors;
import me.filoghost.commons.config.ConfigValue;
import me.filoghost.commons.config.ConfigValueType;
import me.filoghost.commons.config.exception.ConverterCastException;
import me.filoghost.commons.config.mapped.MappedField;
import java.lang.reflect.Type;
public interface Converter {
ConfigValueType<?> getConfigValueType(Type[] fieldGenericTypes);
boolean matches(Class<?> type);
default ConfigValue toConfigValue(MappedField mappedField, Object value) throws ConverterCastException {
ConfigValueType<?> configValueType = getConfigValueType(mappedField.getGenericTypes());
// Assume that ConfigValueType is compatible with the value
return toTypedConfigValue(configValueType, value);
}
@SuppressWarnings("unchecked")
default <T> ConfigValue toTypedConfigValue(ConfigValueType<T> configValueType, Object value) throws ConverterCastException {
try {
return ConfigValue.of(configValueType, (T) value);
} catch (ClassCastException e) {
throw new ConverterCastException(ConfigErrors.converterFailed(value, this), e);
}
}
}

View File

@ -1,24 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped.converter;
import me.filoghost.commons.config.ConfigValueType;
import java.lang.reflect.Type;
public class DoubleConverter implements Converter {
@Override
public ConfigValueType<?> getConfigValueType(Type[] fieldGenericTypes) {
return ConfigValueType.DOUBLE;
}
@Override
public boolean matches(Class<?> type) {
return type == Double.class || type == double.class;
}
}

View File

@ -1,24 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped.converter;
import me.filoghost.commons.config.ConfigValueType;
import java.lang.reflect.Type;
public class IntegerConverter implements Converter {
@Override
public ConfigValueType<?> getConfigValueType(Type[] fieldGenericTypes) {
return ConfigValueType.INTEGER;
}
@Override
public boolean matches(Class<?> type) {
return type == Integer.class || type == int.class;
}
}

View File

@ -1,37 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped.converter;
import me.filoghost.commons.Preconditions;
import me.filoghost.commons.config.ConfigValueType;
import java.lang.reflect.Type;
import java.util.List;
public class ListConverter implements Converter {
@Override
public ConfigValueType<?> getConfigValueType(Type[] fieldGenericTypes) {
Preconditions.notNull(fieldGenericTypes, "fieldGenericTypes");
Preconditions.checkArgument(fieldGenericTypes.length == 1, "fieldGenericTypes length must be 1");
Type listType = fieldGenericTypes[0];
if (listType == Integer.class) {
return ConfigValueType.INTEGER_LIST;
} else if (listType == String.class) {
return ConfigValueType.STRING_LIST;
} else {
throw new IllegalArgumentException("unsupported list type: " + listType);
}
}
@Override
public boolean matches(Class<?> type) {
return type == List.class;
}
}

View File

@ -1,24 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped.converter;
import me.filoghost.commons.config.ConfigValueType;
import java.lang.reflect.Type;
public class StringConverter implements Converter {
@Override
public ConfigValueType<?> getConfigValueType(Type[] fieldGenericTypes) {
return ConfigValueType.STRING;
}
@Override
public boolean matches(Class<?> type) {
return type == String.class;
}
}

View File

@ -1,17 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped.modifier;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE})
public @interface ChatColors {
}

View File

@ -1,27 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped.modifier;
import me.filoghost.commons.Colors;
public class ChatColorsModifier implements ValueModifier<String, ChatColors> {
@Override
public String transformChecked(ChatColors annotation, String value) {
return Colors.addColors(value);
}
@Override
public Class<ChatColors> getAnnotationType() {
return ChatColors.class;
}
@Override
public Class<String> getValueType() {
return String.class;
}
}

View File

@ -1,29 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.config.mapped.modifier;
import me.filoghost.commons.Preconditions;
import java.lang.annotation.Annotation;
public interface ValueModifier<V, A extends Annotation> {
V transformChecked(A annotation, V value);
Class<A> getAnnotationType();
Class<V> getValueType();
default boolean isApplicable(Annotation annotation, Object value) {
return getAnnotationType().isInstance(annotation) && getValueType().isInstance(value);
}
default Object transform(Annotation annotation, Object fieldValue) {
Preconditions.checkArgument(isApplicable(annotation, fieldValue), "modifier doesn't match given types");
return transformChecked(getAnnotationType().cast(annotation), getValueType().cast(fieldValue));
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.logging;
import java.util.ArrayList;
import java.util.List;
/**
* This is a class to collect all the errors found while loading a plugin.
*/
public abstract class ErrorCollector {
protected final List<ErrorLog> errors = new ArrayList<>();
public void add(String... messageParts) {
add(null, messageParts);
}
public void add(Throwable cause, String... messageParts) {
errors.add(new ErrorLog(cause, messageParts));
}
public int getErrorsCount() {
return errors.size();
}
public boolean hasErrors() {
return errors.size() > 0;
}
public abstract void logToConsole();
}

View File

@ -1,28 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.logging;
import com.google.common.collect.ImmutableList;
public class ErrorLog {
private final ImmutableList<String> message;
private final Throwable cause;
protected ErrorLog(Throwable cause, String[] message) {
this.message = ImmutableList.copyOf(message);
this.cause = cause;
}
public ImmutableList<String> getMessage() {
return message;
}
public Throwable getCause() {
return cause;
}
}

View File

@ -1,43 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.commons.logging;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Log {
private static Logger logger;
public static void setLogger(Logger logger) {
Log.logger = logger;
}
public static void info(String msg) {
info(msg, null);
}
public static void info(String msg, Throwable thrown) {
logger.log(Level.INFO, msg, thrown);
}
public static void warning(String msg) {
warning(msg, null);
}
public static void warning(String msg, Throwable thrown) {
logger.log(Level.WARNING, msg, thrown);
}
public static void severe(String msg) {
severe(msg, null);
}
public static void severe(String msg, Throwable thrown) {
logger.log(Level.SEVERE, msg, thrown);
}
}

View File

@ -49,8 +49,8 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>chestcommands-commons</artifactId>
<groupId>me.filoghost.fcommons</groupId>
<artifactId>fcommons</artifactId>
</dependency>
</dependencies>
@ -137,8 +137,8 @@
<shadedPattern>me.filoghost.chestcommands.updater</shadedPattern>
</relocation>
<relocation>
<pattern>me.filoghost.commons</pattern>
<shadedPattern>me.filoghost.chestcommands.commons</shadedPattern>
<pattern>me.filoghost.fcommons</pattern>
<shadedPattern>me.filoghost.chestcommands.fcommons</shadedPattern>
</relocation>
</relocations>
</configuration>

View File

@ -26,12 +26,12 @@ import me.filoghost.chestcommands.menu.MenuManager;
import me.filoghost.chestcommands.parsing.menu.LoadedMenu;
import me.filoghost.chestcommands.placeholder.PlaceholderManager;
import me.filoghost.chestcommands.task.TickingTask;
import me.filoghost.commons.BaseJavaPlugin;
import me.filoghost.commons.CommonsUtil;
import me.filoghost.commons.command.CommandFramework;
import me.filoghost.commons.config.ConfigLoader;
import me.filoghost.commons.logging.ErrorCollector;
import me.filoghost.commons.logging.Log;
import me.filoghost.fcommons.BaseJavaPlugin;
import me.filoghost.fcommons.CommonsUtil;
import me.filoghost.fcommons.command.CommandFramework;
import me.filoghost.fcommons.config.ConfigLoader;
import me.filoghost.fcommons.logging.ErrorCollector;
import me.filoghost.fcommons.logging.Log;
import me.filoghost.updatechecker.UpdateChecker;
import org.bstats.bukkit.MetricsLite;
import org.bukkit.Bukkit;

View File

@ -15,7 +15,7 @@ import me.filoghost.chestcommands.icon.APIStaticIcon;
import me.filoghost.chestcommands.menu.APIMenu;
import me.filoghost.chestcommands.menu.InternalMenu;
import me.filoghost.chestcommands.placeholder.PlaceholderManager;
import me.filoghost.commons.Preconditions;
import me.filoghost.fcommons.Preconditions;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

View File

@ -6,7 +6,7 @@
package me.filoghost.chestcommands.action;
import me.filoghost.chestcommands.placeholder.PlaceholderString;
import me.filoghost.commons.Colors;
import me.filoghost.fcommons.Colors;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -10,8 +10,8 @@ import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.chestcommands.parsing.NumberParser;
import me.filoghost.chestcommands.parsing.ParseException;
import me.filoghost.chestcommands.placeholder.PlaceholderString;
import me.filoghost.commons.Colors;
import me.filoghost.commons.Strings;
import me.filoghost.fcommons.Colors;
import me.filoghost.fcommons.Strings;
import org.bukkit.entity.Player;
public class DragonBarAction implements Action {

View File

@ -8,8 +8,8 @@ package me.filoghost.chestcommands.action;
import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.chestcommands.parsing.NumberParser;
import me.filoghost.chestcommands.parsing.ParseException;
import me.filoghost.commons.Strings;
import me.filoghost.commons.collection.Registry;
import me.filoghost.fcommons.Strings;
import me.filoghost.fcommons.collection.Registry;
import org.bukkit.Sound;
import org.bukkit.entity.Player;

View File

@ -6,7 +6,7 @@
package me.filoghost.chestcommands.action;
import me.filoghost.chestcommands.placeholder.PlaceholderString;
import me.filoghost.commons.Colors;
import me.filoghost.fcommons.Colors;
import org.bukkit.entity.Player;
public class SendMessageAction implements Action {

View File

@ -7,8 +7,8 @@ package me.filoghost.chestcommands.attribute;
import me.filoghost.chestcommands.config.Settings;
import me.filoghost.chestcommands.icon.InternalConfigurableIcon;
import me.filoghost.commons.Colors;
import me.filoghost.commons.collection.CollectionUtils;
import me.filoghost.fcommons.Colors;
import me.filoghost.fcommons.collection.CollectionUtils;
import java.util.List;

View File

@ -7,7 +7,7 @@ package me.filoghost.chestcommands.attribute;
import me.filoghost.chestcommands.config.Settings;
import me.filoghost.chestcommands.icon.InternalConfigurableIcon;
import me.filoghost.commons.Colors;
import me.filoghost.fcommons.Colors;
public class NameAttribute implements IconAttribute {

View File

@ -10,9 +10,9 @@ import me.filoghost.chestcommands.Permissions;
import me.filoghost.chestcommands.menu.InternalMenu;
import me.filoghost.chestcommands.menu.MenuManager;
import me.filoghost.chestcommands.util.Utils;
import me.filoghost.commons.command.CommandFramework;
import me.filoghost.commons.command.CommandValidate;
import me.filoghost.commons.logging.ErrorCollector;
import me.filoghost.fcommons.command.CommandFramework;
import me.filoghost.fcommons.command.CommandValidate;
import me.filoghost.fcommons.logging.ErrorCollector;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

View File

@ -8,13 +8,13 @@ package me.filoghost.chestcommands.config;
import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.chestcommands.parsing.menu.LoadedMenu;
import me.filoghost.chestcommands.parsing.menu.MenuParser;
import me.filoghost.commons.Preconditions;
import me.filoghost.commons.config.BaseConfigManager;
import me.filoghost.commons.config.Config;
import me.filoghost.commons.config.ConfigLoader;
import me.filoghost.commons.config.exception.ConfigException;
import me.filoghost.commons.config.mapped.MappedConfigLoader;
import me.filoghost.commons.logging.ErrorCollector;
import me.filoghost.fcommons.Preconditions;
import me.filoghost.fcommons.config.BaseConfigManager;
import me.filoghost.fcommons.config.Config;
import me.filoghost.fcommons.config.ConfigLoader;
import me.filoghost.fcommons.config.exception.ConfigException;
import me.filoghost.fcommons.config.mapped.MappedConfigLoader;
import me.filoghost.fcommons.logging.ErrorCollector;
import java.io.IOException;
import java.nio.file.FileVisitOption;

View File

@ -7,10 +7,10 @@ package me.filoghost.chestcommands.config;
import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.chestcommands.placeholder.StaticPlaceholder;
import me.filoghost.commons.Colors;
import me.filoghost.commons.config.Config;
import me.filoghost.commons.config.ConfigSection;
import me.filoghost.commons.logging.ErrorCollector;
import me.filoghost.fcommons.Colors;
import me.filoghost.fcommons.config.Config;
import me.filoghost.fcommons.config.ConfigSection;
import me.filoghost.fcommons.logging.ErrorCollector;
import java.util.ArrayList;
import java.util.List;

View File

@ -6,9 +6,9 @@
package me.filoghost.chestcommands.config;
import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.commons.config.mapped.IncludeStatic;
import me.filoghost.commons.config.mapped.MappedConfig;
import me.filoghost.commons.config.mapped.modifier.ChatColors;
import me.filoghost.fcommons.config.mapped.IncludeStatic;
import me.filoghost.fcommons.config.mapped.MappedConfig;
import me.filoghost.fcommons.config.mapped.modifier.ChatColors;
@ChatColors
@IncludeStatic

View File

@ -5,9 +5,9 @@
*/
package me.filoghost.chestcommands.config;
import me.filoghost.commons.config.mapped.IncludeStatic;
import me.filoghost.commons.config.mapped.MappedConfig;
import me.filoghost.commons.config.mapped.modifier.ChatColors;
import me.filoghost.fcommons.config.mapped.IncludeStatic;
import me.filoghost.fcommons.config.mapped.MappedConfig;
import me.filoghost.fcommons.config.mapped.modifier.ChatColors;
@ChatColors
@IncludeStatic

View File

@ -5,7 +5,7 @@
*/
package me.filoghost.chestcommands.hook;
import me.filoghost.commons.Preconditions;
import me.filoghost.fcommons.Preconditions;
public interface PluginHook {

View File

@ -5,7 +5,7 @@
*/
package me.filoghost.chestcommands.hook;
import me.filoghost.commons.Preconditions;
import me.filoghost.fcommons.Preconditions;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;

View File

@ -7,7 +7,7 @@ package me.filoghost.chestcommands.icon;
import me.filoghost.chestcommands.api.ClickHandler;
import me.filoghost.chestcommands.api.StaticIcon;
import me.filoghost.commons.Preconditions;
import me.filoghost.fcommons.Preconditions;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

View File

@ -10,9 +10,9 @@ import me.filoghost.chestcommands.placeholder.PlaceholderString;
import me.filoghost.chestcommands.placeholder.PlaceholderStringList;
import me.filoghost.chestcommands.util.nbt.parser.MojangsonParseException;
import me.filoghost.chestcommands.util.nbt.parser.MojangsonParser;
import me.filoghost.commons.Preconditions;
import me.filoghost.commons.collection.CollectionUtils;
import me.filoghost.commons.logging.Log;
import me.filoghost.fcommons.Preconditions;
import me.filoghost.fcommons.collection.CollectionUtils;
import me.filoghost.fcommons.logging.Log;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;

View File

@ -5,7 +5,7 @@
*/
package me.filoghost.chestcommands.icon;
import me.filoghost.commons.Strings;
import me.filoghost.fcommons.Strings;
import org.bukkit.entity.Player;
public class IconPermission {

View File

@ -16,8 +16,8 @@ import me.filoghost.chestcommands.icon.requirement.RequiredMoney;
import me.filoghost.chestcommands.icon.requirement.Requirement;
import me.filoghost.chestcommands.icon.requirement.item.RequiredItem;
import me.filoghost.chestcommands.icon.requirement.item.RequiredItems;
import me.filoghost.commons.Preconditions;
import me.filoghost.commons.collection.CollectionUtils;
import me.filoghost.fcommons.Preconditions;
import me.filoghost.fcommons.collection.CollectionUtils;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

View File

@ -5,8 +5,8 @@
*/
package me.filoghost.chestcommands.icon.requirement.item;
import me.filoghost.commons.MaterialsHelper;
import me.filoghost.commons.Preconditions;
import me.filoghost.fcommons.MaterialsHelper;
import me.filoghost.fcommons.Preconditions;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;

View File

@ -5,7 +5,7 @@
*/
package me.filoghost.chestcommands.icon.requirement.item;
import me.filoghost.commons.Preconditions;
import me.filoghost.fcommons.Preconditions;
import org.bukkit.Material;
public class RequiredItem {

View File

@ -5,7 +5,7 @@
*/
package me.filoghost.chestcommands.inventory;
import me.filoghost.commons.Preconditions;
import me.filoghost.fcommons.Preconditions;
/*
* Example:

View File

@ -5,7 +5,7 @@
*/
package me.filoghost.chestcommands.inventory;
import me.filoghost.commons.Preconditions;
import me.filoghost.fcommons.Preconditions;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;

View File

@ -5,7 +5,7 @@
*/
package me.filoghost.chestcommands.legacy;
import me.filoghost.commons.Preconditions;
import me.filoghost.fcommons.Preconditions;
import java.io.IOException;
import java.nio.file.Files;

View File

@ -16,9 +16,9 @@ import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuReformatUpgradeTask;
import me.filoghost.chestcommands.legacy.v4_0.v4_0_PlaceholdersUpgradeTask;
import me.filoghost.chestcommands.legacy.v4_0.v4_0_SettingsUpgradeTask;
import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.commons.collection.CollectionUtils;
import me.filoghost.commons.config.ConfigLoader;
import me.filoghost.commons.logging.Log;
import me.filoghost.fcommons.collection.CollectionUtils;
import me.filoghost.fcommons.config.ConfigLoader;
import me.filoghost.fcommons.logging.Log;
import java.io.IOException;
import java.nio.file.Path;

View File

@ -10,8 +10,8 @@ import me.filoghost.chestcommands.legacy.upgrade.Upgrade;
import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask;
import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException;
import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.commons.logging.ErrorCollector;
import me.filoghost.commons.logging.Log;
import me.filoghost.fcommons.logging.ErrorCollector;
import me.filoghost.fcommons.logging.Log;
import java.io.IOException;
import java.nio.file.Path;

View File

@ -5,9 +5,9 @@
*/
package me.filoghost.chestcommands.legacy.upgrade;
import me.filoghost.commons.config.ConfigErrors;
import me.filoghost.commons.config.exception.ConfigLoadException;
import me.filoghost.commons.config.exception.ConfigSaveException;
import me.filoghost.fcommons.config.ConfigErrors;
import me.filoghost.fcommons.config.exception.ConfigLoadException;
import me.filoghost.fcommons.config.exception.ConfigSaveException;
import java.io.IOException;
import java.nio.file.Files;

View File

@ -7,9 +7,9 @@ package me.filoghost.chestcommands.legacy.upgrade;
import me.filoghost.chestcommands.legacy.Backup;
import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.commons.Preconditions;
import me.filoghost.commons.config.exception.ConfigLoadException;
import me.filoghost.commons.config.exception.ConfigSaveException;
import me.filoghost.fcommons.Preconditions;
import me.filoghost.fcommons.config.exception.ConfigLoadException;
import me.filoghost.fcommons.config.exception.ConfigSaveException;
import java.io.IOException;
import java.nio.file.Path;

View File

@ -5,10 +5,10 @@
*/
package me.filoghost.chestcommands.legacy.upgrade;
import me.filoghost.commons.config.Config;
import me.filoghost.commons.config.ConfigLoader;
import me.filoghost.commons.config.exception.ConfigLoadException;
import me.filoghost.commons.config.exception.ConfigSaveException;
import me.filoghost.fcommons.config.Config;
import me.filoghost.fcommons.config.ConfigLoader;
import me.filoghost.fcommons.config.exception.ConfigLoadException;
import me.filoghost.fcommons.config.exception.ConfigSaveException;
import java.nio.file.Path;

View File

@ -7,7 +7,7 @@ package me.filoghost.chestcommands.legacy.v4_0;
import me.filoghost.chestcommands.config.ConfigManager;
import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask;
import me.filoghost.commons.config.Config;
import me.filoghost.fcommons.config.Config;
public class v4_0_LangUpgradeTask extends YamlUpgradeTask {

View File

@ -9,10 +9,10 @@ import me.filoghost.chestcommands.config.ConfigManager;
import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask;
import me.filoghost.chestcommands.parsing.icon.AttributeType;
import me.filoghost.chestcommands.parsing.menu.MenuSettingsNode;
import me.filoghost.commons.Strings;
import me.filoghost.commons.config.Config;
import me.filoghost.commons.config.ConfigSection;
import me.filoghost.commons.config.ConfigValueType;
import me.filoghost.fcommons.Strings;
import me.filoghost.fcommons.config.Config;
import me.filoghost.fcommons.config.ConfigSection;
import me.filoghost.fcommons.config.ConfigValueType;
import java.nio.file.Path;
import java.util.ArrayList;

View File

@ -7,12 +7,12 @@ package me.filoghost.chestcommands.legacy.v4_0;
import me.filoghost.chestcommands.config.ConfigManager;
import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask;
import me.filoghost.commons.Strings;
import me.filoghost.commons.config.Config;
import me.filoghost.commons.config.ConfigErrors;
import me.filoghost.commons.config.ConfigLoader;
import me.filoghost.commons.config.exception.ConfigLoadException;
import me.filoghost.commons.config.exception.ConfigSaveException;
import me.filoghost.fcommons.Strings;
import me.filoghost.fcommons.config.Config;
import me.filoghost.fcommons.config.ConfigErrors;
import me.filoghost.fcommons.config.ConfigLoader;
import me.filoghost.fcommons.config.exception.ConfigLoadException;
import me.filoghost.fcommons.config.exception.ConfigSaveException;
import org.apache.commons.lang.StringEscapeUtils;
import java.io.IOException;

View File

@ -7,7 +7,7 @@ package me.filoghost.chestcommands.legacy.v4_0;
import me.filoghost.chestcommands.config.ConfigManager;
import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask;
import me.filoghost.commons.config.Config;
import me.filoghost.fcommons.config.Config;
public class v4_0_SettingsUpgradeTask extends YamlUpgradeTask {

View File

@ -8,7 +8,7 @@ package me.filoghost.chestcommands.logging;
import me.filoghost.chestcommands.ChestCommands;
import me.filoghost.chestcommands.parsing.icon.AttributeType;
import me.filoghost.chestcommands.parsing.icon.IconSettings;
import me.filoghost.commons.config.ConfigErrors;
import me.filoghost.fcommons.config.ConfigErrors;
import org.bukkit.ChatColor;
import java.nio.file.Path;

View File

@ -5,7 +5,7 @@
*/
package me.filoghost.chestcommands.logging;
import me.filoghost.commons.Strings;
import me.filoghost.fcommons.Strings;
import java.util.List;

View File

@ -9,11 +9,11 @@ import me.filoghost.chestcommands.ChestCommands;
import me.filoghost.chestcommands.legacy.UpgradeExecutorException;
import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException;
import me.filoghost.chestcommands.parsing.ParseException;
import me.filoghost.commons.CommonsUtil;
import me.filoghost.commons.config.exception.ConfigException;
import me.filoghost.commons.config.exception.ConfigSyntaxException;
import me.filoghost.commons.logging.ErrorCollector;
import me.filoghost.commons.logging.ErrorLog;
import me.filoghost.fcommons.CommonsUtil;
import me.filoghost.fcommons.config.exception.ConfigException;
import me.filoghost.fcommons.config.exception.ConfigSyntaxException;
import me.filoghost.fcommons.logging.ErrorCollector;
import me.filoghost.fcommons.logging.ErrorLog;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

View File

@ -5,7 +5,7 @@
*/
package me.filoghost.chestcommands.menu;
import me.filoghost.commons.Preconditions;
import me.filoghost.fcommons.Preconditions;
import org.bukkit.plugin.Plugin;
public class APIMenu extends BaseMenu {

View File

@ -11,7 +11,7 @@ import me.filoghost.chestcommands.api.MenuView;
import me.filoghost.chestcommands.inventory.ArrayGrid;
import me.filoghost.chestcommands.inventory.DefaultMenuView;
import me.filoghost.chestcommands.inventory.Grid;
import me.filoghost.commons.Preconditions;
import me.filoghost.fcommons.Preconditions;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -10,7 +10,7 @@ import me.filoghost.chestcommands.Permissions;
import me.filoghost.chestcommands.action.Action;
import me.filoghost.chestcommands.api.MenuView;
import me.filoghost.chestcommands.config.Lang;
import me.filoghost.commons.collection.CollectionUtils;
import me.filoghost.fcommons.collection.CollectionUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

View File

@ -10,8 +10,8 @@ import me.filoghost.chestcommands.inventory.MenuInventoryHolder;
import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.chestcommands.parsing.menu.LoadedMenu;
import me.filoghost.chestcommands.parsing.menu.MenuOpenItem;
import me.filoghost.commons.collection.CaseInsensitiveMap;
import me.filoghost.commons.logging.ErrorCollector;
import me.filoghost.fcommons.collection.CaseInsensitiveMap;
import me.filoghost.fcommons.logging.ErrorCollector;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.inventory.Inventory;

View File

@ -6,8 +6,8 @@
package me.filoghost.chestcommands.parsing;
import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.commons.Strings;
import me.filoghost.commons.collection.Registry;
import me.filoghost.fcommons.Strings;
import me.filoghost.fcommons.collection.Registry;
import org.bukkit.enchantments.Enchantment;
import java.util.Optional;

View File

@ -6,8 +6,8 @@
package me.filoghost.chestcommands.parsing;
import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.commons.Strings;
import me.filoghost.commons.collection.Registry;
import me.filoghost.fcommons.Strings;
import me.filoghost.fcommons.collection.Registry;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.block.banner.Pattern;

View File

@ -6,9 +6,9 @@
package me.filoghost.chestcommands.parsing;
import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.commons.MaterialsHelper;
import me.filoghost.commons.Preconditions;
import me.filoghost.commons.Strings;
import me.filoghost.fcommons.MaterialsHelper;
import me.filoghost.fcommons.Preconditions;
import me.filoghost.fcommons.Strings;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

View File

@ -1,7 +1,7 @@
package me.filoghost.chestcommands.parsing;
import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.commons.MaterialsHelper;
import me.filoghost.fcommons.MaterialsHelper;
import org.bukkit.Material;
public class MaterialParser {

View File

@ -28,9 +28,9 @@ import me.filoghost.chestcommands.attribute.RequiredItemsAttribute;
import me.filoghost.chestcommands.attribute.SkullOwnerAttribute;
import me.filoghost.chestcommands.attribute.ViewPermissionAttribute;
import me.filoghost.chestcommands.parsing.ParseException;
import me.filoghost.commons.config.ConfigValue;
import me.filoghost.commons.config.ConfigValueType;
import me.filoghost.commons.config.exception.ConfigValueException;
import me.filoghost.fcommons.config.ConfigValue;
import me.filoghost.fcommons.config.ConfigValueType;
import me.filoghost.fcommons.config.exception.ConfigValueException;
import java.util.HashMap;
import java.util.Map;

View File

@ -10,10 +10,10 @@ import me.filoghost.chestcommands.attribute.IconAttribute;
import me.filoghost.chestcommands.icon.InternalConfigurableIcon;
import me.filoghost.chestcommands.logging.Errors;
import me.filoghost.chestcommands.parsing.ParseException;
import me.filoghost.commons.config.ConfigSection;
import me.filoghost.commons.config.ConfigValue;
import me.filoghost.commons.config.exception.ConfigValueException;
import me.filoghost.commons.logging.ErrorCollector;
import me.filoghost.fcommons.config.ConfigSection;
import me.filoghost.fcommons.config.ConfigValue;
import me.filoghost.fcommons.config.exception.ConfigValueException;
import me.filoghost.fcommons.logging.ErrorCollector;
import org.bukkit.Material;
import java.nio.file.Path;

View File

@ -7,7 +7,7 @@ package me.filoghost.chestcommands.parsing.menu;
import com.google.common.collect.ImmutableList;
import me.filoghost.chestcommands.menu.InternalMenu;
import me.filoghost.commons.collection.CollectionUtils;
import me.filoghost.fcommons.collection.CollectionUtils;
import java.nio.file.Path;
import java.util.List;

View File

@ -5,7 +5,7 @@
*/
package me.filoghost.chestcommands.parsing.menu;
import me.filoghost.commons.Preconditions;
import me.filoghost.fcommons.Preconditions;
import org.bukkit.Material;
import org.bukkit.event.block.Action;
import org.bukkit.inventory.ItemStack;

View File

@ -15,13 +15,13 @@ import me.filoghost.chestcommands.parsing.ItemStackParser;
import me.filoghost.chestcommands.parsing.ParseException;
import me.filoghost.chestcommands.parsing.icon.AttributeType;
import me.filoghost.chestcommands.parsing.icon.IconSettings;
import me.filoghost.commons.Colors;
import me.filoghost.commons.config.Config;
import me.filoghost.commons.config.ConfigSection;
import me.filoghost.commons.config.EmptyConfigSection;
import me.filoghost.commons.config.exception.ConfigValueException;
import me.filoghost.commons.config.exception.MissingConfigValueException;
import me.filoghost.commons.logging.ErrorCollector;
import me.filoghost.fcommons.Colors;
import me.filoghost.fcommons.config.Config;
import me.filoghost.fcommons.config.ConfigSection;
import me.filoghost.fcommons.config.EmptyConfigSection;
import me.filoghost.fcommons.config.exception.ConfigValueException;
import me.filoghost.fcommons.config.exception.MissingConfigValueException;
import me.filoghost.fcommons.logging.ErrorCollector;
import org.bukkit.ChatColor;
import java.util.ArrayList;

View File

@ -7,7 +7,7 @@ package me.filoghost.chestcommands.parsing.menu;
import com.google.common.collect.ImmutableList;
import me.filoghost.chestcommands.action.Action;
import me.filoghost.commons.collection.CollectionUtils;
import me.filoghost.fcommons.collection.CollectionUtils;
import java.util.List;

Some files were not shown because too many files have changed in this diff Show More