use of forestry.api.modules.ForestryModule in project ForestryMC by ForestryMC.
the class ForestryModules method isModuleEnabled.
@Override
public boolean isModuleEnabled(IForestryModule module) {
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
String comment = ForestryPluginUtil.getComment(module);
Property prop = getModulesConfig().get(CONFIG_CATEGORY, info.moduleID(), true, comment);
return prop.getBoolean();
}
use of forestry.api.modules.ForestryModule in project ForestryMC by ForestryMC.
the class ForestryPluginUtil method getForestryModules.
public static Map<String, List<IForestryModule>> getForestryModules(ASMDataTable asmDataTable) {
List<IForestryModule> instances = getInstances(asmDataTable, ForestryModule.class, IForestryModule.class);
Map<String, List<IForestryModule>> modules = new LinkedHashMap<>();
for (IForestryModule module : instances) {
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
modules.computeIfAbsent(info.containerID(), k -> new ArrayList<>()).add(module);
}
return modules;
}
use of forestry.api.modules.ForestryModule in project ForestryMC by ForestryMC.
the class ModuleManager method configureModules.
private static void configureModules(Map<String, List<IForestryModule>> modules) {
Locale locale = Locale.getDefault();
Locale.setDefault(Locale.ENGLISH);
Set<ResourceLocation> toLoad = new HashSet<>();
Set<IForestryModule> modulesToLoad = new HashSet<>();
ImmutableList<IForestryModule> allModules = ImmutableList.copyOf(modules.values().stream().flatMap(Collection::stream).collect(Collectors.toList()));
for (IModuleContainer container : moduleContainers.values()) {
String containerID = container.getID();
List<IForestryModule> containerModules = modules.get(containerID);
Configuration config = container.getModulesConfig();
config.load();
config.addCustomCategoryComment(CONFIG_CATEGORY, "Disabling these modules can greatly change how the mod functions.\n" + "Your mileage may vary, please report any issues.");
IForestryModule coreModule = getModuleCore(containerModules);
if (coreModule != null) {
containerModules.remove(coreModule);
containerModules.add(0, coreModule);
} else {
Log.debug("Could not find core module for the module container: {}", containerID);
}
Iterator<IForestryModule> iterator = containerModules.iterator();
while (iterator.hasNext()) {
IForestryModule module = iterator.next();
if (!container.isAvailable()) {
iterator.remove();
Log.info("Module disabled: {}", module);
continue;
}
if (module.canBeDisabled()) {
if (!container.isModuleEnabled(module)) {
configDisabledModules.add(module);
iterator.remove();
Log.info("Module disabled: {}", module);
continue;
}
if (!module.isAvailable()) {
iterator.remove();
Log.info("Module {} failed to load: {}", module, module.getFailMessage());
continue;
}
}
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
toLoad.add(new ResourceLocation(containerID, info.moduleID()));
modulesToLoad.add(module);
}
}
// Check Dependencies
Iterator<IForestryModule> iterator;
boolean changed;
do {
changed = false;
iterator = modulesToLoad.iterator();
while (iterator.hasNext()) {
IForestryModule module = iterator.next();
Set<ResourceLocation> dependencies = module.getDependencyUids();
if (!toLoad.containsAll(dependencies)) {
iterator.remove();
changed = true;
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
String moduleId = info.moduleID();
toLoad.remove(new ResourceLocation(moduleId));
Log.warning("Module {} is missing dependencies: {}", moduleId, dependencies);
}
}
} while (changed);
// Sort Modules
do {
changed = false;
iterator = modulesToLoad.iterator();
while (iterator.hasNext()) {
IForestryModule module = iterator.next();
if (sortedModules.keySet().containsAll(module.getDependencyUids())) {
iterator.remove();
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
sortedModules.put(new ResourceLocation(info.containerID(), info.moduleID()), module);
changed = true;
break;
}
}
} while (changed);
for (IModuleContainer container : moduleContainers.values()) {
Configuration config = container.getModulesConfig();
if (config.hasChanged()) {
config.save();
}
}
loadedModules.addAll(sortedModules.values());
unloadedModules.addAll(allModules);
unloadedModules.removeAll(sortedModules.values());
for (IModuleContainer container : moduleContainers.values()) {
Collection<IForestryModule> loadedModules = sortedModules.values().stream().filter(m -> {
ForestryModule info = m.getClass().getAnnotation(ForestryModule.class);
return info.containerID().equals(container.getID());
}).collect(Collectors.toList());
Collection<IForestryModule> unloadedModules = ModuleManager.unloadedModules.stream().filter(m -> {
ForestryModule info = m.getClass().getAnnotation(ForestryModule.class);
return info.containerID().equals(container.getID());
}).collect(Collectors.toList());
container.onConfiguredModules(loadedModules, unloadedModules);
}
ForestryAPI.enabledModules = new HashSet<>();
ForestryAPI.enabledPlugins = new HashSet<>();
for (IForestryModule module : sortedModules.values()) {
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
ForestryAPI.enabledModules.add(new ResourceLocation(info.containerID(), info.moduleID()));
if (module instanceof BlankForestryModule) {
ForestryAPI.enabledPlugins.add(info.containerID() + "." + info.moduleID());
}
}
Locale.setDefault(locale);
}
use of forestry.api.modules.ForestryModule in project ForestryMC by ForestryMC.
the class ForestryCompatPlugins method isModuleEnabled.
@Override
public boolean isModuleEnabled(IForestryModule module) {
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
String comment = ForestryPluginUtil.getComment(module);
Property prop = getModulesConfig().get(CONFIG_CATEGORY, info.moduleID(), true, comment);
return prop.getBoolean();
}
use of forestry.api.modules.ForestryModule in project ForestryMC by ForestryMC.
the class CommandModules method makeListEntry.
private static String makeListEntry(IForestryModule module) {
String entry = module.isAvailable() ? TextFormatting.GREEN.toString() : TextFormatting.RED.toString();
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
if (info != null) {
entry += info.moduleID();
if (!info.version().isEmpty()) {
entry += " (" + info.version() + ")";
}
} else {
entry += "???";
}
return entry;
}
Aggregations