From ca5262bc5b6accdf74c43e6a125e80a79a9e3f17 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Fri, 21 May 2021 19:45:04 +0200 Subject: [PATCH] Refactor Config class --- .../Minepacks/Bukkit/Database/Config.java | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java index 70f51f7..a49587d 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java @@ -30,6 +30,7 @@ import at.pcgamingfreaks.Minepacks.Bukkit.Database.Enums.ShrinkApproach; import at.pcgamingfreaks.Version; import at.pcgamingfreaks.YamlFileManager; +import at.pcgamingfreaks.YamlFileUpdateMethod; import org.bukkit.*; import org.bukkit.plugin.java.JavaPlugin; @@ -38,22 +39,23 @@ import java.io.FileNotFoundException; import java.util.*; +import java.util.stream.Collectors; public class Config extends Configuration implements DatabaseConnectionConfiguration, IUnCacheStrategyConfig { - private static final int CONFIG_VERSION = 36, UPGRADE_THRESHOLD = CONFIG_VERSION, PRE_V2_VERSION = 20; + private static final int CONFIG_VERSION = 36, PRE_V2_VERSION = 20; - public Config(JavaPlugin plugin) + public Config(final @NotNull JavaPlugin plugin) { - super(plugin, CONFIG_VERSION, UPGRADE_THRESHOLD); + super(plugin, new Version(CONFIG_VERSION)); languageKey = "Language.Language"; languageUpdateKey = "Language.UpdateMode"; } @Override - protected void doUpdate() + protected @Nullable YamlFileUpdateMethod getYamlUpdateMode() { - // Nothing to update yet + return YamlFileUpdateMethod.UPGRADE; } @Override @@ -244,7 +246,7 @@ public boolean isCommandCooldownAddOnJoinEnabled() public Collection getAllowedGameModes() { Collection gameModes = new HashSet<>(); - for(String string : getConfigE().getStringList("AllowedGameModes", new LinkedList<>())) + for(String string : getConfigE().getStringList("AllowedGameModes", new ArrayList<>(0))) { GameMode gm = null; try @@ -329,23 +331,17 @@ public boolean isItemFilterEnabled() public Collection getItemFilterMaterials() { - if(!isItemFilterEnabledNoShulker()) return new LinkedList<>(); - List stringMaterialList = getConfigE().getStringList("ItemFilter.Materials", new LinkedList<>()); + if(!isItemFilterEnabledNoShulker()) return new ArrayList<>(0); + List stringMaterialList = getConfigE().getStringList("ItemFilter.Materials", new ArrayList<>(0)); if(isItemFilterModeWhitelist()) stringMaterialList.add("air"); - Collection blacklist = new LinkedList<>(); - for(String item : stringMaterialList) - { - MinecraftMaterial mat = MinecraftMaterial.fromInput(item); - if(mat != null) blacklist.add(mat); - } - return blacklist; + return stringMaterialList.stream().map(MinecraftMaterial::fromInput).filter(Objects::nonNull).collect(Collectors.toList()); } public Set getItemFilterNames() { if(!isItemFilterEnabledNoShulker()) return new HashSet<>(); Set names = new HashSet<>(); - getConfigE().getStringList("ItemFilter.Names", new LinkedList<>()).forEach(name -> names.add(ChatColor.translateAlternateColorCodes('&', name))); + getConfigE().getStringList("ItemFilter.Names", new ArrayList<>(0)).forEach(name -> names.add(ChatColor.translateAlternateColorCodes('&', name))); return names; } @@ -353,7 +349,7 @@ public Set getItemFilterLore() { if(!isItemFilterEnabledNoShulker()) return new HashSet<>(); Set loreSet = new HashSet<>(); - getConfigE().getStringList("ItemFilter.Lore", new LinkedList<>()).forEach(lore -> loreSet.add(ChatColor.translateAlternateColorCodes('&', lore))); + getConfigE().getStringList("ItemFilter.Lore", new ArrayList<>(0)).forEach(lore -> loreSet.add(ChatColor.translateAlternateColorCodes('&', lore))); return loreSet; }