use of me.deecaad.core.file.SerializerInstancer 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.SerializerInstancer in project MechanicsMain by WeaponMechanics.
the class MechanicsCore method onEnable.
@Override
public void onEnable() {
debug.debug("Loading config.yml");
if (!getDataFolder().exists() || getDataFolder().listFiles() == null || getDataFolder().listFiles().length == 0) {
try {
FileUtil.copyResourcesTo(getClassLoader().getResource("MechanicsCore"), getDataFolder().toPath());
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
FileUtil.ensureDefaults(getClassLoader(), "MechanicsCore/config.yml", new File(getDataFolder(), "config.yml"));
try {
List<?> serializers = new SerializerInstancer(new JarFile(getFile())).createAllInstances(getClassLoader());
// noinspection unchecked
serializersList = (List<Serializer<?>>) serializers;
} catch (IOException e) {
e.printStackTrace();
}
// don't exist in 1.10 and lower.
if (ReflectionUtil.getMCVersion() >= 11) {
Bukkit.getPluginManager().registerEvents(EquipListener.SINGLETON, this);
}
Bukkit.getPluginManager().registerEvents(new ItemCraftListener(), this);
}
Aggregations