mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
Fix mcMMO attempting to copy out custom repair/salvage configs
This commit is contained in:
parent
978ee4a9a3
commit
640f4b0a9b
@ -10,22 +10,22 @@ import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class AutoUpdateConfigLoader extends ConfigLoader {
|
||||
public AutoUpdateConfigLoader(String relativePath, String fileName, File dataFolder) {
|
||||
public abstract class AutoUpdateLegacyConfigLoader extends LegacyConfigLoader {
|
||||
public AutoUpdateLegacyConfigLoader(String relativePath, String fileName, File dataFolder) {
|
||||
super(relativePath, fileName, dataFolder);
|
||||
}
|
||||
|
||||
public AutoUpdateConfigLoader(String fileName, File dataFolder) {
|
||||
public AutoUpdateLegacyConfigLoader(String fileName, File dataFolder) {
|
||||
super(fileName, dataFolder);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public AutoUpdateConfigLoader(String relativePath, String fileName) {
|
||||
public AutoUpdateLegacyConfigLoader(String relativePath, String fileName) {
|
||||
super(relativePath, fileName);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public AutoUpdateConfigLoader(String fileName) {
|
||||
public AutoUpdateLegacyConfigLoader(String fileName) {
|
||||
super(fileName);
|
||||
}
|
||||
|
@ -19,17 +19,7 @@ public abstract class BukkitConfig {
|
||||
protected YamlConfiguration defaultYamlConfig;
|
||||
protected YamlConfiguration config;
|
||||
protected @NotNull final File dataFolder;
|
||||
|
||||
public BukkitConfig(@NotNull String fileName, @NotNull File dataFolder) {
|
||||
mcMMO.p.getLogger().info("[config] Initializing config: " + fileName);
|
||||
this.fileName = fileName;
|
||||
this.dataFolder = dataFolder;
|
||||
configFile = new File(dataFolder, fileName);
|
||||
this.defaultYamlConfig = copyDefaultConfig();
|
||||
this.config = initConfig();
|
||||
updateFile();
|
||||
mcMMO.p.getLogger().info("[config] Config initialized: " + fileName);
|
||||
}
|
||||
private boolean savedDefaults = false;
|
||||
|
||||
public BukkitConfig(@NotNull String fileName, @NotNull File dataFolder, boolean copyDefaults) {
|
||||
mcMMO.p.getLogger().info("[config] Initializing config: " + fileName);
|
||||
@ -37,12 +27,16 @@ public abstract class BukkitConfig {
|
||||
this.fileName = fileName;
|
||||
this.dataFolder = dataFolder;
|
||||
configFile = new File(dataFolder, fileName);
|
||||
this.defaultYamlConfig = copyDefaultConfig();
|
||||
this.defaultYamlConfig = saveDefaultConfigToDisk();
|
||||
this.config = initConfig();
|
||||
updateFile();
|
||||
mcMMO.p.getLogger().info("[config] Config initialized: " + fileName);
|
||||
}
|
||||
|
||||
public BukkitConfig(@NotNull String fileName, @NotNull File dataFolder) {
|
||||
this(fileName, dataFolder, true);
|
||||
}
|
||||
|
||||
public BukkitConfig(@NotNull String fileName) {
|
||||
this(fileName, mcMMO.p.getDataFolder());
|
||||
}
|
||||
@ -55,10 +49,12 @@ public abstract class BukkitConfig {
|
||||
*/
|
||||
public void updateFile() {
|
||||
try {
|
||||
if(copyDefaults) {
|
||||
copyMissingDefaultsFromResource();
|
||||
}
|
||||
config.save(configFile);
|
||||
|
||||
if(copyDefaults && !savedDefaults) {
|
||||
copyMissingDefaultsFromResource();
|
||||
savedDefaults = true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -84,7 +80,7 @@ public abstract class BukkitConfig {
|
||||
/**
|
||||
* Copies the config from the JAR to defaults/<fileName>
|
||||
*/
|
||||
YamlConfiguration copyDefaultConfig() {
|
||||
YamlConfiguration saveDefaultConfigToDisk() {
|
||||
mcMMO.p.getLogger().info("[config] Copying default config to disk: " + fileName + " to defaults/" + fileName);
|
||||
try(InputStream inputStream = mcMMO.p.getResource(fileName)) {
|
||||
if(inputStream == null) {
|
||||
|
@ -7,20 +7,21 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ConfigLoader {
|
||||
@Deprecated
|
||||
public abstract class LegacyConfigLoader {
|
||||
protected final File configFile;
|
||||
protected final @NotNull File dataFolder;
|
||||
protected String fileName;
|
||||
protected YamlConfiguration config;
|
||||
|
||||
public ConfigLoader(String relativePath, String fileName, @NotNull File dataFolder) {
|
||||
public LegacyConfigLoader(String relativePath, String fileName, @NotNull File dataFolder) {
|
||||
this.fileName = fileName;
|
||||
this.dataFolder = dataFolder;
|
||||
configFile = new File(dataFolder, relativePath + File.separator + fileName);
|
||||
loadFile();
|
||||
}
|
||||
|
||||
public ConfigLoader(String fileName, @NotNull File dataFolder) {
|
||||
public LegacyConfigLoader(String fileName, @NotNull File dataFolder) {
|
||||
this.fileName = fileName;
|
||||
this.dataFolder = dataFolder;
|
||||
configFile = new File(dataFolder, fileName);
|
||||
@ -28,7 +29,7 @@ public abstract class ConfigLoader {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ConfigLoader(String relativePath, String fileName) {
|
||||
public LegacyConfigLoader(String relativePath, String fileName) {
|
||||
this.fileName = fileName;
|
||||
configFile = new File(mcMMO.p.getDataFolder(), relativePath + File.separator + fileName);
|
||||
this.dataFolder = mcMMO.p.getDataFolder();
|
||||
@ -36,7 +37,7 @@ public abstract class ConfigLoader {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ConfigLoader(String fileName) {
|
||||
public LegacyConfigLoader(String fileName) {
|
||||
this.fileName = fileName;
|
||||
configFile = new File(mcMMO.p.getDataFolder(), fileName);
|
||||
this.dataFolder = mcMMO.p.getDataFolder();
|
@ -29,7 +29,7 @@ public class ArmorConfigManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
modManager.registerCustomArmor(new CustomArmorConfig(fileName));
|
||||
modManager.registerCustomArmor(new CustomArmorLegacyConfig(fileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class BlockConfigManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
modManager.registerCustomBlocks(new CustomBlockConfig(fileName));
|
||||
modManager.registerCustomBlocks(new CustomBlockLegacyConfig(fileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.gmail.nossr50.config.mods;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigLoader;
|
||||
import com.gmail.nossr50.config.LegacyConfigLoader;
|
||||
import com.gmail.nossr50.datatypes.skills.ItemType;
|
||||
import com.gmail.nossr50.datatypes.skills.MaterialType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
@ -13,7 +13,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CustomArmorConfig extends ConfigLoader {
|
||||
public class CustomArmorLegacyConfig extends LegacyConfigLoader {
|
||||
public List<Material> customBoots = new ArrayList<>();
|
||||
public List<Material> customChestplates = new ArrayList<>();
|
||||
public List<Material> customHelmets = new ArrayList<>();
|
||||
@ -21,7 +21,7 @@ public class CustomArmorConfig extends ConfigLoader {
|
||||
public List<Repairable> repairables = new ArrayList<>();
|
||||
private boolean needsUpdate = false;
|
||||
|
||||
protected CustomArmorConfig(String fileName) {
|
||||
protected CustomArmorLegacyConfig(String fileName) {
|
||||
super("mods", fileName);
|
||||
loadKeys();
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.gmail.nossr50.config.mods;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigLoader;
|
||||
import com.gmail.nossr50.config.LegacyConfigLoader;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.Material;
|
||||
@ -11,7 +11,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CustomBlockConfig extends ConfigLoader {
|
||||
public class CustomBlockLegacyConfig extends LegacyConfigLoader {
|
||||
public List<Material> customExcavationBlocks = new ArrayList<>();
|
||||
public List<Material> customHerbalismBlocks = new ArrayList<>();
|
||||
public List<Material> customMiningBlocks = new ArrayList<>();
|
||||
@ -22,7 +22,7 @@ public class CustomBlockConfig extends ConfigLoader {
|
||||
public HashMap<Material, CustomBlock> customBlockMap = new HashMap<>();
|
||||
private boolean needsUpdate = false;
|
||||
|
||||
protected CustomBlockConfig(String fileName) {
|
||||
protected CustomBlockLegacyConfig(String fileName) {
|
||||
super("mods", fileName);
|
||||
loadKeys();
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.gmail.nossr50.config.mods;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigLoader;
|
||||
import com.gmail.nossr50.config.LegacyConfigLoader;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomEntity;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.apache.commons.lang.ClassUtils;
|
||||
@ -9,11 +9,11 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class CustomEntityConfig extends ConfigLoader {
|
||||
public class CustomEntityLegacyConfig extends LegacyConfigLoader {
|
||||
public HashMap<String, CustomEntity> customEntityClassMap = new HashMap<>();
|
||||
public HashMap<String, CustomEntity> customEntityTypeMap = new HashMap<>();
|
||||
|
||||
protected CustomEntityConfig(String fileName) {
|
||||
protected CustomEntityLegacyConfig(String fileName) {
|
||||
super("mods", fileName);
|
||||
loadKeys();
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.gmail.nossr50.config.mods;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigLoader;
|
||||
import com.gmail.nossr50.config.LegacyConfigLoader;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
||||
import com.gmail.nossr50.datatypes.skills.ItemType;
|
||||
import com.gmail.nossr50.datatypes.skills.MaterialType;
|
||||
@ -15,7 +15,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CustomToolConfig extends ConfigLoader {
|
||||
public class CustomToolLegacyConfig extends LegacyConfigLoader {
|
||||
public List<Material> customAxes = new ArrayList<>();
|
||||
public List<Material> customBows = new ArrayList<>();
|
||||
public List<Material> customHoes = new ArrayList<>();
|
||||
@ -26,7 +26,7 @@ public class CustomToolConfig extends ConfigLoader {
|
||||
public List<Repairable> repairables = new ArrayList<>();
|
||||
private boolean needsUpdate = false;
|
||||
|
||||
protected CustomToolConfig(String fileName) {
|
||||
protected CustomToolLegacyConfig(String fileName) {
|
||||
super("mods", fileName);
|
||||
loadKeys();
|
||||
}
|
@ -29,7 +29,7 @@ public class EntityConfigManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
modManager.registerCustomEntities(new CustomEntityConfig(fileName));
|
||||
modManager.registerCustomEntities(new CustomEntityLegacyConfig(fileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class ToolConfigManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
modManager.registerCustomTools(new CustomToolConfig(fileName));
|
||||
modManager.registerCustomTools(new CustomToolLegacyConfig(fileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.gmail.nossr50.config.skills.alchemy;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigLoader;
|
||||
import com.gmail.nossr50.config.LegacyConfigLoader;
|
||||
import com.gmail.nossr50.datatypes.skills.alchemy.AlchemyPotion;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -15,7 +15,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PotionConfig extends ConfigLoader {
|
||||
public class PotionConfig extends LegacyConfigLoader {
|
||||
private static PotionConfig instance;
|
||||
|
||||
private final List<ItemStack> concoctionsIngredientsTierOne = new ArrayList<>();
|
||||
|
@ -17,8 +17,8 @@ public class RepairConfig extends BukkitConfig {
|
||||
private final HashSet<String> notSupported;
|
||||
private List<Repairable> repairables;
|
||||
|
||||
public RepairConfig(String fileName) {
|
||||
super(fileName, false);
|
||||
public RepairConfig(String fileName, boolean copyDefaults) {
|
||||
super(fileName, copyDefaults);
|
||||
notSupported = new HashSet<>();
|
||||
loadKeys();
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public class RepairConfigManager {
|
||||
Pattern pattern = Pattern.compile("repair\\.(?:.+)\\.yml");
|
||||
File dataFolder = plugin.getDataFolder();
|
||||
|
||||
RepairConfig mainRepairConfig = new RepairConfig(REPAIR_VANILLA_YML);
|
||||
RepairConfig mainRepairConfig = new RepairConfig(REPAIR_VANILLA_YML, true);
|
||||
repairables.addAll(mainRepairConfig.getLoadedRepairables());
|
||||
|
||||
for (String fileName : dataFolder.list()) {
|
||||
@ -33,7 +33,7 @@ public class RepairConfigManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
RepairConfig rConfig = new RepairConfig(fileName);
|
||||
RepairConfig rConfig = new RepairConfig(fileName, false);
|
||||
repairables.addAll(rConfig.getLoadedRepairables());
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ public class SalvageConfig extends BukkitConfig {
|
||||
private final HashSet<String> notSupported;
|
||||
private Set<Salvageable> salvageables;
|
||||
|
||||
public SalvageConfig(String fileName) {
|
||||
super(fileName);
|
||||
public SalvageConfig(String fileName, boolean copyDefaults) {
|
||||
super(fileName, copyDefaults);
|
||||
notSupported = new HashSet<>();
|
||||
loadKeys();
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class SalvageConfigManager {
|
||||
Pattern pattern = Pattern.compile("salvage\\.(?:.+)\\.yml");
|
||||
File dataFolder = plugin.getDataFolder();
|
||||
|
||||
SalvageConfig mainSalvageConfig = new SalvageConfig(SALVAGE_VANILLA_YML);
|
||||
SalvageConfig mainSalvageConfig = new SalvageConfig(SALVAGE_VANILLA_YML, true);
|
||||
salvageables.addAll(mainSalvageConfig.getLoadedSalvageables());
|
||||
|
||||
for (String fileName : dataFolder.list()) {
|
||||
@ -34,7 +34,7 @@ public class SalvageConfigManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
SalvageConfig salvageConfig = new SalvageConfig(fileName);
|
||||
SalvageConfig salvageConfig = new SalvageConfig(fileName, false);
|
||||
salvageables.addAll(salvageConfig.getLoadedSalvageables());
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import com.gmail.nossr50.config.mods.CustomArmorConfig;
|
||||
import com.gmail.nossr50.config.mods.CustomBlockConfig;
|
||||
import com.gmail.nossr50.config.mods.CustomEntityConfig;
|
||||
import com.gmail.nossr50.config.mods.CustomToolConfig;
|
||||
import com.gmail.nossr50.config.mods.CustomArmorLegacyConfig;
|
||||
import com.gmail.nossr50.config.mods.CustomBlockLegacyConfig;
|
||||
import com.gmail.nossr50.config.mods.CustomEntityLegacyConfig;
|
||||
import com.gmail.nossr50.config.mods.CustomToolLegacyConfig;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomEntity;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
||||
@ -52,7 +52,7 @@ public class ModManager {
|
||||
private final List<Material> customSwords = new ArrayList<>();
|
||||
private final HashMap<Material, CustomTool> customToolMap = new HashMap<>();
|
||||
|
||||
public void registerCustomArmor(CustomArmorConfig config) {
|
||||
public void registerCustomArmor(CustomArmorLegacyConfig config) {
|
||||
customBoots.addAll(config.customBoots);
|
||||
customChestplates.addAll(config.customChestplates);
|
||||
customHelmets.addAll(config.customHelmets);
|
||||
@ -60,7 +60,7 @@ public class ModManager {
|
||||
repairables.addAll(config.repairables);
|
||||
}
|
||||
|
||||
public void registerCustomBlocks(CustomBlockConfig config) {
|
||||
public void registerCustomBlocks(CustomBlockLegacyConfig config) {
|
||||
customExcavationBlocks.addAll(config.customExcavationBlocks);
|
||||
customHerbalismBlocks.addAll(config.customHerbalismBlocks);
|
||||
customMiningBlocks.addAll(config.customMiningBlocks);
|
||||
@ -71,12 +71,12 @@ public class ModManager {
|
||||
customBlockMap.putAll(config.customBlockMap);
|
||||
}
|
||||
|
||||
public void registerCustomEntities(CustomEntityConfig config) {
|
||||
public void registerCustomEntities(CustomEntityLegacyConfig config) {
|
||||
customEntityClassMap.putAll(config.customEntityClassMap);
|
||||
customEntityTypeMap.putAll(config.customEntityTypeMap);
|
||||
}
|
||||
|
||||
public void registerCustomTools(CustomToolConfig config) {
|
||||
public void registerCustomTools(CustomToolLegacyConfig config) {
|
||||
customAxes.addAll(config.customAxes);
|
||||
customBows.addAll(config.customBows);
|
||||
customHoes.addAll(config.customHoes);
|
||||
|
Loading…
Reference in New Issue
Block a user