use of me.deecaad.core.file.FileReader in project MechanicsMain by WeaponMechanics.
the class WeaponMechanics method loadConfig.
void loadConfig() {
debug.debug("Loading and serializing config");
try {
List<?> serializers = new SerializerInstancer(new JarFile(getFile())).createAllInstances(getClassLoader());
// noinspection unchecked
MechanicsCore.addSerializers(getPlugin(), (List<Serializer<?>>) serializers);
} catch (IOException e) {
e.printStackTrace();
return;
}
if (configurations == null) {
configurations = new LinkedConfig();
} else {
configurations.clear();
}
List<IValidator> validators = null;
try {
// Find all validators in WeaponMechanics
validators = new JarInstancer(new JarFile(getFile())).createAllInstances(IValidator.class, getClassLoader(), true);
} catch (IOException e) {
e.printStackTrace();
}
// Fill configuration mappings (except config.yml)
Configuration temp = new FileReader(debug, MechanicsCore.getListOfSerializers(), validators).fillAllFiles(getDataFolder(), "config.yml");
try {
configurations.add(temp);
} catch (DuplicateKeyException e) {
debug.error("Error loading config: " + e.getMessage());
}
}
use of me.deecaad.core.file.FileReader in project MechanicsMain by WeaponMechanics.
the class WeaponMechanics method writeFiles.
void writeFiles() {
// Create files
if (!getDataFolder().exists() || getDataFolder().listFiles() == null || getDataFolder().listFiles().length == 0) {
debug.info("Copying files from jar (This process may take up to 30 seconds during the first load!)");
try {
FileUtil.copyResourcesTo(getClassLoader().getResource("WeaponMechanics"), getDataFolder().toPath());
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
try {
// TODO bad programmars comment out broken code
// FileUtil.ensureDefaults(getClassLoader(), "WeaponMechanics/config.yml", new File(getDataFolder(), "config.yml"));
} catch (YAMLException e) {
debug.error("WeaponMechanics jar corruption... This is most likely caused by using /reload after building jar!");
}
// Fill config.yml mappings
File configyml = new File(getDataFolder(), "config.yml");
if (configyml.exists()) {
List<IValidator> validators = new ArrayList<>();
// No need for other validators here as this is only for config.yml
validators.add(new HitBox());
FileReader basicConfigurationReader = new FileReader(debug, null, validators);
Configuration filledMap = basicConfigurationReader.fillOneFile(configyml);
basicConfiguration = basicConfigurationReader.usePathToSerializersAndValidators(filledMap);
} else {
// Just creates empty map to prevent other issues
basicConfiguration = new LinkedConfig();
debug.log(LogLevel.WARN, "Could not locate config.yml?", "Make sure it exists in path " + getDataFolder() + "/config.yml");
}
// Ensure that the resource pack exists in the folder
if (basicConfiguration.getBool("Resource_Pack_Download.Enabled")) {
String link = basicConfiguration.getString("Resource_Pack_Download.Link");
int connection = basicConfiguration.getInt("Resource_Pack_Download.Connection_Timeout");
int read = basicConfiguration.getInt("Resource_Pack_Download.Read_Timeout");
File pack = new File(getDataFolder(), "WeaponMechanicsResourcePack.zip");
if (!pack.exists()) {
FileUtil.downloadFile(pack, link, connection, read);
}
}
}
Aggregations