Update FCommons version to 1.1.0

This commit is contained in:
filoghost 2020-09-14 20:57:14 +02:00
parent 7e7b5d5427
commit ffd2927327
10 changed files with 52 additions and 45 deletions

View File

@ -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 {

View File

@ -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);

View File

@ -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<StaticPlaceholder> placeholders = new ArrayList<>();
public void load(Config config, ErrorCollector errorCollector) {
public void load(FileConfig config, ErrorCollector errorCollector) {
placeholders.clear();
ConfigSection placeholdersSection = config.getConfigSection("placeholders");

View File

@ -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.";

View File

@ -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<String> getHeader() {
return Arrays.asList(
"ChestCommands main configuration file.",
"Documentation: https://filoghost.me/docs/chest-commands");
}

View File

@ -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();
}

View File

@ -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<String> lines;
try {
lines = Files.readAllLines(oldPlaceholdersFile);

View File

@ -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

View File

@ -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<IconSettings> 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<IconSettings> loadIconSettingsList(Config config, ErrorCollector errorCollector) {
private static List<IconSettings> loadIconSettingsList(FileConfig config, ErrorCollector errorCollector) {
List<IconSettings> iconSettingsList = new ArrayList<>();
for (String iconSectionName : config.getKeys()) {

View File

@ -118,7 +118,7 @@
<dependency>
<groupId>me.filoghost.fcommons</groupId>
<artifactId>fcommons</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
</dependency>
<dependency>