use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class EntitySystemSetupUtil method registerComponents.
static void registerComponents(ComponentLibrary library, ModuleEnvironment environment) {
for (Class<? extends Component> componentType : environment.getSubtypesOf(Component.class)) {
if (componentType.getAnnotation(DoNotAutoRegister.class) == null && !componentType.isInterface() && !Modifier.isAbstract(componentType.getModifiers())) {
String componentName = MetadataUtil.getComponentClassName(componentType);
Name componentModuleName = verifyNotNull(environment.getModuleProviding(componentType), "Could not find module for %s %s", componentName, componentType);
library.register(new ResourceUrn(componentModuleName.toString(), componentName), componentType);
}
}
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class ComponentSystemManager method loadSystems.
public void loadSystems(ModuleEnvironment environment, NetworkMode netMode) {
DisplayDevice display = context.get(DisplayDevice.class);
boolean isHeadless = display.isHeadless();
ListMultimap<Name, Class<?>> systemsByModule = ArrayListMultimap.create();
for (Class<?> type : environment.getTypesAnnotatedWith(RegisterSystem.class)) {
if (!ComponentSystem.class.isAssignableFrom(type)) {
logger.error("Cannot load {}, must be a subclass of ComponentSystem", type.getSimpleName());
continue;
}
Name moduleId = environment.getModuleProviding(type);
RegisterSystem registerInfo = type.getAnnotation(RegisterSystem.class);
if (registerInfo.value().isValidFor(netMode.isAuthority(), isHeadless) && areOptionalRequirementsContained(registerInfo, environment)) {
systemsByModule.put(moduleId, type);
}
}
for (Module module : environment.getModulesOrderedByDependencies()) {
for (Class<?> system : systemsByModule.get(module.getId())) {
String id = module.getId() + ":" + system.getSimpleName();
logger.debug("Registering system {}", id);
if (checkOptionalDependenciesPresent(system)) {
tryToLoadSystem(system, id);
} else {
logger.warn("Skip system {} for loading - possibly missing optional dependencies", id);
}
}
}
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class CoreCommands method spawnPrefab.
/**
* Spawns an instance of a prefab in the world
*
* @param sender Sender of command
* @param prefabName String containing prefab name
* @return String containing final message
*/
@Command(shortDescription = "Spawns an instance of a prefab in the world", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String spawnPrefab(@Sender EntityRef sender, @CommandParam("prefabId") String prefabName) {
ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
Vector3f spawnPos = characterLocation.getWorldPosition(new Vector3f());
Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
offset.mul(2);
spawnPos.add(offset);
Vector3f dir = characterLocation.getWorldDirection(new Vector3f());
dir.y = 0;
if (dir.lengthSquared() > 0.001f) {
dir.normalize();
} else {
dir.set(Direction.FORWARD.asVector3f());
}
return Assets.getPrefab(prefabName).map(prefab -> {
LocationComponent loc = prefab.getComponent(LocationComponent.class);
if (loc != null) {
entityManager.create(prefab, spawnPos);
return "Done";
} else {
return "Prefab cannot be spawned (no location component)";
}
}).orElse("Unknown prefab");
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class CyclingTabCompletionEngine method complete.
@Override
public String complete(String rawCommand) {
if (rawCommand.length() <= 0) {
reset();
previousMessage = new Message("Type 'help' to list all commands.");
console.addMessage(previousMessage);
return null;
} else if (query == null) {
query = rawCommand;
}
String commandNameRaw = console.processCommandName(query);
Name commandName = new Name(commandNameRaw);
List<String> commandParameters = console.processParameters(query);
ConsoleCommand command = console.getCommand(commandName);
int suggestedIndex = commandParameters.size() + (query.charAt(query.length() - 1) == ' ' ? 1 : 0);
Set<String> matches = findMatches(commandName, commandParameters, command, suggestedIndex);
if (matches == null || matches.size() <= 0) {
return query;
}
if (previousMatches == null || !matches.equals(Sets.newHashSet(previousMatches))) {
reset(false);
if (matches.size() == 1) {
return generateResult(matches.iterator().next(), commandName, commandParameters, suggestedIndex);
}
/* if (matches.length > MAX_CYCLES) {
console.addMessage(new Message("Too many hits, please refine your search"));
return query;
}*/
// TODO Find out a better way to handle too many results while returning useful information
previousMatches = Lists.newArrayList(matches);
Collections.sort(previousMatches);
}
StringBuilder matchMessageString = new StringBuilder();
for (int i = 0; i < previousMatches.size(); i++) {
if (i > 0) {
matchMessageString.append(' ');
}
String match = previousMatches.get(i);
if (selectionIndex == i) {
match = FontColor.getColored(match, ConsoleColors.COMMAND);
}
matchMessageString.append(match);
}
Message matchMessage = new Message(matchMessageString.toString());
String suggestion = previousMatches.get(selectionIndex);
if (previousMessage != null) {
console.replaceMessage(previousMessage, matchMessage);
} else {
console.addMessage(matchMessage);
}
previousMessage = matchMessage;
selectionIndex = (selectionIndex + 1) % previousMatches.size();
return generateResult(suggestion, commandName, commandParameters, suggestedIndex);
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class ConsoleImpl method registerCommand.
/**
* Registers a {@link ConsoleCommand}.
*
* @param command The command to be registered
*/
@Override
public void registerCommand(ConsoleCommand command) {
Name commandName = command.getName();
if (commandRegistry.containsKey(commandName)) {
logger.warn("Command with name '{}' already registered by class '{}', skipping '{}'", commandName, commandRegistry.get(commandName).getSource().getClass().getCanonicalName(), command.getSource().getClass().getCanonicalName());
} else {
commandRegistry.put(commandName, command);
logger.debug("Command '{}' successfully registered for class '{}'.", commandName, command.getSource().getClass().getCanonicalName());
}
}
Aggregations