From ffd29273270d5d1be14770f155ca271a23a057b0 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 14 Sep 2020 20:57:14 +0200 Subject: [PATCH] Update FCommons version to 1.1.0 --- .../chestcommands/ChestCommands.java | 13 +++++---- .../chestcommands/config/ConfigManager.java | 29 ++++++++++--------- .../config/CustomPlaceholders.java | 9 +++--- .../filoghost/chestcommands/config/Lang.java | 2 +- .../chestcommands/config/Settings.java | 9 ++++-- .../v4_0/V4_0_MenuReformatUpgradeTask.java | 6 ++-- .../v4_0/V4_0_PlaceholdersUpgradeTask.java | 2 +- .../logging/PrintableErrorCollector.java | 7 +++-- .../parsing/menu/MenuParser.java | 18 ++++++------ pom.xml | 2 +- 10 files changed, 52 insertions(+), 45 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 5f00b2b..abcea4c 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -5,10 +5,6 @@ */ package me.filoghost.chestcommands; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; import me.filoghost.chestcommands.api.internal.BackendAPI; import me.filoghost.chestcommands.command.CommandHandler; import me.filoghost.chestcommands.config.ConfigManager; @@ -31,11 +27,11 @@ import me.filoghost.chestcommands.parsing.menu.LoadedMenu; import me.filoghost.chestcommands.placeholder.PlaceholderManager; import me.filoghost.chestcommands.task.TickingTask; 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.fcommons.reflection.ReflectionUtils; import me.filoghost.updatechecker.UpdateChecker; import org.bstats.bukkit.MetricsLite; import org.bukkit.Bukkit; @@ -43,6 +39,11 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + public class ChestCommands extends BaseJavaPlugin { @@ -60,7 +61,7 @@ public class ChestCommands extends BaseJavaPlugin { @Override protected void onCheckedEnable() throws PluginEnableException { - if (!CommonsUtil.isClassLoaded("org.bukkit.inventory.ItemFlag")) { // ItemFlag was added in 1.8 + if (!ReflectionUtils.isClassLoaded("org.bukkit.inventory.ItemFlag")) { // ItemFlag was added in 1.8 if (Bukkit.getVersion().contains("(MC: 1.8)")) { throw new PluginEnableException("ChestCommands requires a more recent version of Bukkit 1.8 to run."); } else { diff --git a/plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java b/plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java index a014712..8e0c4d0 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java @@ -5,6 +5,17 @@ */ 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.fcommons.Preconditions; +import me.filoghost.fcommons.config.BaseConfigManager; +import me.filoghost.fcommons.config.ConfigLoader; +import me.filoghost.fcommons.config.FileConfig; +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; import java.nio.file.Files; @@ -14,16 +25,6 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import me.filoghost.chestcommands.logging.Errors; -import me.filoghost.chestcommands.parsing.menu.LoadedMenu; -import me.filoghost.chestcommands.parsing.menu.MenuParser; -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; public class ConfigManager extends BaseConfigManager { @@ -34,9 +35,9 @@ public class ConfigManager extends BaseConfigManager { public ConfigManager(Path rootDataFolder) { super(rootDataFolder); - settingsConfigLoader = getMappedConfigLoader("config.yml", Settings::new); + settingsConfigLoader = getMappedConfigLoader("config.yml", Settings.class); placeholdersConfigLoader = getConfigLoader("custom-placeholders.yml"); - langConfigLoader = getMappedConfigLoader("lang.yml", Lang::new); + langConfigLoader = getMappedConfigLoader("lang.yml", Lang.class); } public void tryLoadSettings(ErrorCollector errorCollector) { @@ -59,7 +60,7 @@ public class ConfigManager extends BaseConfigManager { CustomPlaceholders placeholders = new CustomPlaceholders(); try { - Config placeholdersConfig = placeholdersConfigLoader.init(); + FileConfig placeholdersConfig = placeholdersConfigLoader.init(); placeholders.load(placeholdersConfig, errorCollector); } catch (ConfigException t) { logConfigInitException(errorCollector, placeholdersConfigLoader.getFile(), t); @@ -107,7 +108,7 @@ public class ConfigManager extends BaseConfigManager { ConfigLoader menuConfigLoader = new ConfigLoader(rootDataFolder, menuFile); try { - Config menuConfig = menuConfigLoader.load(); + FileConfig menuConfig = menuConfigLoader.load(); loadedMenus.add(MenuParser.loadMenu(menuConfig, errorCollector)); } catch (ConfigException e) { logConfigInitException(errorCollector, menuConfigLoader.getFile(), e); diff --git a/plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java b/plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java index ef8b033..d0ad357 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java @@ -5,20 +5,21 @@ */ package me.filoghost.chestcommands.config; -import java.util.ArrayList; -import java.util.List; import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.placeholder.StaticPlaceholder; import me.filoghost.fcommons.Colors; -import me.filoghost.fcommons.config.Config; import me.filoghost.fcommons.config.ConfigSection; +import me.filoghost.fcommons.config.FileConfig; import me.filoghost.fcommons.logging.ErrorCollector; +import java.util.ArrayList; +import java.util.List; + public class CustomPlaceholders { private final List placeholders = new ArrayList<>(); - public void load(Config config, ErrorCollector errorCollector) { + public void load(FileConfig config, ErrorCollector errorCollector) { placeholders.clear(); ConfigSection placeholdersSection = config.getConfigSection("placeholders"); diff --git a/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java b/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java index bde5587..187901d 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java @@ -12,7 +12,7 @@ import me.filoghost.fcommons.config.mapped.modifier.ChatColors; @ChatColors @IncludeStatic -public class Lang extends MappedConfig { +public class Lang implements MappedConfig { public static String no_open_permission = "&cYou don't have permission &e{permission} &cto use this menu."; public static String default_no_icon_permission = "&cYou don't have permission for this icon."; diff --git a/plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java b/plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java index 1293638..09763e6 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java @@ -9,17 +9,20 @@ import me.filoghost.fcommons.config.mapped.IncludeStatic; import me.filoghost.fcommons.config.mapped.MappedConfig; import me.filoghost.fcommons.config.mapped.modifier.ChatColors; +import java.util.Arrays; +import java.util.List; + @ChatColors @IncludeStatic -public class Settings extends MappedConfig { +public class Settings implements MappedConfig { public static String default_color__name = "&f"; public static String default_color__lore = "&7"; public static boolean update_notifications = true; public static int anti_click_spam_delay = 200; - public Settings() { - setHeader( + public List getHeader() { + return Arrays.asList( "ChestCommands main configuration file.", "Documentation: https://filoghost.me/docs/chest-commands"); } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/V4_0_MenuReformatUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/V4_0_MenuReformatUpgradeTask.java index 3cd28a2..bb62e5b 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/V4_0_MenuReformatUpgradeTask.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/V4_0_MenuReformatUpgradeTask.java @@ -31,7 +31,7 @@ public class V4_0_MenuReformatUpgradeTask extends YamlUpgradeTask { @Override public void computeYamlChanges(Config menuConfig) { - menuConfig.setHeader(null); + menuConfig.setHeader(); for (String key : menuConfig.getKeys()) { ConfigSection section = menuConfig.getConfigSection(key); @@ -129,14 +129,14 @@ public class V4_0_MenuReformatUpgradeTask extends YamlUpgradeTask { } private void expandInlineList(ConfigSection config, String node, String separator) { - if (config.get(node).isValidAs(ConfigValueType.STRING)) { + if (config.get(node).isPresentAs(ConfigValueType.STRING)) { config.setStringList(node, splitListElements(config.getString(node), separator)); setSaveRequired(); } } private void expandSingletonList(ConfigSection config, String node) { - if (config.get(node).isValidAs(ConfigValueType.STRING)) { + if (config.get(node).isPresentAs(ConfigValueType.STRING)) { config.setStringList(node, Collections.singletonList(config.getString(node))); setSaveRequired(); } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/V4_0_PlaceholdersUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/V4_0_PlaceholdersUpgradeTask.java index 0960f76..2b5271e 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/V4_0_PlaceholdersUpgradeTask.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/V4_0_PlaceholdersUpgradeTask.java @@ -48,7 +48,7 @@ public class V4_0_PlaceholdersUpgradeTask extends UpgradeTask { } // Do NOT load the new placeholder configuration from disk, as it should only contain placeholders imported from the old file - Config newPlaceholdersConfig = new Config(newPlaceholdersConfigLoader.getFile()); + Config newPlaceholdersConfig = new Config(); List lines; try { lines = Files.readAllLines(oldPlaceholdersFile); diff --git a/plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java b/plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java index eb3e2f8..473cd9b 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java @@ -5,8 +5,6 @@ */ package me.filoghost.chestcommands.logging; -import java.util.ArrayList; -import java.util.List; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.legacy.UpgradeExecutorException; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; @@ -19,6 +17,9 @@ import me.filoghost.fcommons.logging.ErrorLog; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import java.util.ArrayList; +import java.util.List; + public class PrintableErrorCollector extends ErrorCollector { @@ -50,7 +51,7 @@ public class PrintableErrorCollector extends ErrorCollector { while (true) { if (cause instanceof ConfigSyntaxException) { message.add(cause.getMessage()); - details = ((ConfigSyntaxException) cause).getParsingErrorDetails(); + details = ((ConfigSyntaxException) cause).getSyntaxErrorDetails(); cause = null; // Do not print stacktrace for syntax exceptions } else if (cause instanceof ConfigException diff --git a/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index 00257a1..fa6a8f1 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -5,8 +5,6 @@ */ package me.filoghost.chestcommands.parsing.menu; -import java.util.ArrayList; -import java.util.List; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.DisabledAction; import me.filoghost.chestcommands.attribute.PositionAttribute; @@ -18,18 +16,20 @@ import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.parsing.icon.AttributeType; import me.filoghost.chestcommands.parsing.icon.IconSettings; 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.FileConfig; 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; +import java.util.List; + public class MenuParser { - public static LoadedMenu loadMenu(Config menuConfig, ErrorCollector errorCollector) { + public static LoadedMenu loadMenu(FileConfig menuConfig, ErrorCollector errorCollector) { MenuSettings menuSettings = loadMenuSettings(menuConfig, errorCollector); List iconSettingsList = loadIconSettingsList(menuConfig, errorCollector); @@ -88,11 +88,11 @@ public class MenuParser { } - private static MenuSettings loadMenuSettings(Config config, ErrorCollector errorCollector) { + private static MenuSettings loadMenuSettings(FileConfig config, ErrorCollector errorCollector) { ConfigSection settingsSection = config.getConfigSection(MenuSettingsNode.ROOT_SECTION); if (settingsSection == null) { errorCollector.add(Errors.Menu.missingSettingsSection(config.getSourceFile())); - settingsSection = new EmptyConfigSection(); + settingsSection = new ConfigSection(); } String title; @@ -179,7 +179,7 @@ public class MenuParser { return menuSettings; } - private static void addMenuSettingError(ErrorCollector errorCollector, Config config, String missingSetting, ConfigValueException e) { + private static void addMenuSettingError(ErrorCollector errorCollector, FileConfig config, String missingSetting, ConfigValueException e) { if (e instanceof MissingConfigValueException) { errorCollector.add(Errors.Menu.missingSetting(config.getSourceFile(), missingSetting)); } else { @@ -188,7 +188,7 @@ public class MenuParser { } - private static List loadIconSettingsList(Config config, ErrorCollector errorCollector) { + private static List loadIconSettingsList(FileConfig config, ErrorCollector errorCollector) { List iconSettingsList = new ArrayList<>(); for (String iconSectionName : config.getKeys()) { diff --git a/pom.xml b/pom.xml index aad2f46..3dfce7c 100644 --- a/pom.xml +++ b/pom.xml @@ -118,7 +118,7 @@ me.filoghost.fcommons fcommons - 1.0.0 + 1.1.0