use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class RegisterMods method step.
@Override
public boolean step() {
if (applyModulesThread != null) {
if (!applyModulesThread.isAlive()) {
if (oldEnvironment != null) {
oldEnvironment.close();
}
return true;
}
return false;
} else {
ModuleManager moduleManager = context.get(ModuleManager.class);
List<Name> moduleIds = gameManifest.getModules().stream().map(NameVersion::getName).collect(Collectors.toCollection(ArrayList::new));
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(moduleIds);
if (result.isSuccess()) {
oldEnvironment = moduleManager.getEnvironment();
ModuleEnvironment env = moduleManager.loadEnvironment(result.getModules(), true);
for (Module moduleInfo : env.getModulesOrderedByDependencies()) {
logger.info("Activating module: {}:{}", moduleInfo.getId(), moduleInfo.getVersion());
}
EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
applyModulesThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
applyModulesThread.start();
return false;
} else {
logger.warn("Missing at least one required module (or dependency) from the following list: {}", moduleIds);
context.get(GameEngine.class).changeState(new StateMainMenu("Missing required module or dependency"));
return true;
}
}
}
use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class ModuleManager method loadAndConfigureEngineModule.
/**
* Load and configure the engine module.
* <p>
* The engine module is the parts of the engine which are available to be called directly
* from other modules. Unlike other modules, engine classes are on the classpath and not
* restricted by the ModuleClassLoader.
* <p>
* This function is static so it can be tested without needing a ModuleManager instance.
*
* @param moduleFactory used to create the module
* @param classesOnClasspathsToAddToEngine added to the module's reflections manifest
*/
static Module loadAndConfigureEngineModule(ModuleFactory moduleFactory, List<Class<?>> classesOnClasspathsToAddToEngine) {
// Start by creating a gestalt Module for the Java package `org.terasology.engine`.
Module packageModule = moduleFactory.createPackageModule("org.terasology.engine");
// We need to add reflections from our subsystems and other classes.
Reflections packageReflections = packageModule.getModuleManifest();
ConfigurationBuilder config = reflectionsConfigurationFrom(packageReflections);
Collection<File> classPaths = new HashSet<>(packageModule.getClasspaths());
for (Class<?> aClass : classesOnClasspathsToAddToEngine) {
URL url = ClasspathHelper.forClass(aClass);
// include this in reflections scan
config.addUrls(url);
// also include in Module.moduleClasspaths
classPaths.add(urlToFile(url));
}
if (!config.getUrls().isEmpty()) {
Reflections reflectionsWithSubsystems = new Reflections(config);
packageReflections.merge(reflectionsWithSubsystems);
}
// TODO: expand the ModuleFactory interface to make this whole thing less awkward
return new Module(packageModule.getMetadata(), packageModule.getResources(), classPaths, packageReflections, clazz -> packageModule.getClassPredicate().test(clazz) || config.getUrls().contains(ClasspathHelper.forClass(clazz)));
}
use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class JoinServer method step.
@Override
public boolean step() {
if (applyModuleThread != null) {
if (!applyModuleThread.isAlive()) {
if (oldEnvironment != null) {
oldEnvironment.close();
}
return true;
}
return false;
} else if (joinStatus.getStatus() == JoinStatus.Status.COMPLETE) {
Server server = networkSystem.getServer();
ServerInfoMessage serverInfo = networkSystem.getServer().getInfo();
// If no GameName, use Server IP Address
if (serverInfo.getGameName().length() > 0) {
gameManifest.setTitle(serverInfo.getGameName());
} else {
gameManifest.setTitle(server.getRemoteAddress());
}
for (WorldInfo worldInfo : serverInfo.getWorldInfoList()) {
gameManifest.addWorld(worldInfo);
}
Map<String, Short> blockMap = Maps.newHashMap();
for (Entry<Integer, String> entry : serverInfo.getBlockIds().entrySet()) {
String name = entry.getValue();
short id = entry.getKey().shortValue();
Short oldId = blockMap.put(name, id);
if (oldId != null && oldId != id) {
logger.warn("Overwriting Id {} for {} with Id {}", oldId, name, id);
}
}
gameManifest.setRegisteredBlockFamilies(serverInfo.getRegisterBlockFamilyList());
gameManifest.setBlockIdMap(blockMap);
gameManifest.setTime(networkSystem.getServer().getInfo().getTime());
ModuleManager moduleManager = context.get(ModuleManager.class);
Set<Module> moduleSet = Sets.newLinkedHashSet();
for (NameVersion moduleInfo : networkSystem.getServer().getInfo().getModuleList()) {
Module module = moduleManager.getRegistry().getModule(moduleInfo.getName(), moduleInfo.getVersion());
if (module == null) {
StateMainMenu mainMenu = new StateMainMenu("Missing required module: " + moduleInfo);
context.get(GameEngine.class).changeState(mainMenu);
return false;
} else {
logger.info("Activating module: {}:{}", moduleInfo.getName(), moduleInfo.getVersion());
gameManifest.addModule(module.getId(), module.getVersion());
moduleSet.add(module);
}
}
oldEnvironment = moduleManager.getEnvironment();
moduleManager.loadEnvironment(moduleSet, true);
context.get(Game.class).load(gameManifest);
EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
applyModuleThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
applyModuleThread.start();
return false;
} else if (joinStatus.getStatus() == JoinStatus.Status.FAILED) {
StateMainMenu mainMenu = new StateMainMenu("Failed to connect to server: " + joinStatus.getErrorMessage());
context.get(GameEngine.class).changeState(mainMenu);
networkSystem.shutdown();
}
return false;
}
use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class ModuleInstaller method call.
@Override
public List<Module> call() throws Exception {
Map<URI, Path> filesToDownload = getDownloadUrls(moduleList);
logger.info("Started downloading {} modules", filesToDownload.size());
MultiFileDownloader downloader = new MultiFileDownloader(filesToDownload, downloadProgressListener);
List<Path> downloadedModulesPaths = downloader.call();
logger.info("Module download completed, loading the new modules...");
List<Module> newInstalledModules = new ArrayList<>(downloadedModulesPaths.size());
for (Path filePath : downloadedModulesPaths) {
try {
Module module = moduleManager.registerArchiveModule(filePath);
newInstalledModules.add(module);
} catch (IOException e) {
logger.warn("Could not load module {}", filePath.getFileName(), e);
}
}
logger.info("Finished loading the downloaded modules");
return newInstalledModules;
}
use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class ModuleManager method loadEnvironment.
public ModuleEnvironment loadEnvironment(Set<Module> modules, boolean asPrimary) {
Set<Module> finalModules = Sets.newLinkedHashSet(modules);
finalModules.add(engineModule);
ModuleEnvironment newEnvironment;
boolean permissiveSecurityEnabled = Boolean.parseBoolean(System.getProperty(SystemConfig.PERMISSIVE_SECURITY_ENABLED_PROPERTY));
if (permissiveSecurityEnabled) {
newEnvironment = new ModuleEnvironment(finalModules, wrappingPermissionProviderFactory);
} else {
newEnvironment = new ModuleEnvironment(finalModules, permissionProviderFactory);
}
if (asPrimary) {
environment = newEnvironment;
}
return newEnvironment;
}
Aggregations