use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class MethodCommand method referringTo.
/**
* Creates a new {@code ReferencedCommand} to a specific method annotated with {@link Command}.
*
* @param specificMethod The method to reference to
* @return The command reference object created
*/
public static MethodCommand referringTo(SpecificAccessibleObject<Method> specificMethod, Context context) {
Method method = specificMethod.getAccessibleObject();
Command commandAnnotation = method.getAnnotation(Command.class);
Preconditions.checkNotNull(commandAnnotation);
String nameString = commandAnnotation.value();
if (nameString.length() <= 0) {
nameString = method.getName();
}
Name name = new Name(nameString);
return new MethodCommand(name, commandAnnotation.requiredPermission(), commandAnnotation.runOnServer(), commandAnnotation.shortDescription(), commandAnnotation.helpText(), specificMethod, context);
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class CoreCommands method dumpEntities.
/**
* Writes out information on entities having specific components to a text file for debugging
* If no component names provided - writes out information on all entities
*
* @param componentNames string contains one or several component names, if more then one name
* provided - they must be braced with double quotes and all names separated
* by space
* @return String containing information about number of entities saved
* @throws IOException thrown when error with saving file occures
*/
@Command(shortDescription = "Writes out information on all entities to a JSON file for debugging", helpText = "Writes entity information out into a file named \"<timestamp>-entityDump.json\"." + " Supports list of component names, which will be used to only save entities that contains" + " one or more of those components. Names should be separated by spaces.")
public String dumpEntities(@CommandParam(value = "componentNames", required = false) String... componentNames) throws IOException {
int savedEntityCount;
EngineEntityManager engineEntityManager = (EngineEntityManager) entityManager;
PrefabSerializer prefabSerializer = new PrefabSerializer(engineEntityManager.getComponentLibrary(), engineEntityManager.getTypeSerializerLibrary());
WorldDumper worldDumper = new WorldDumper(engineEntityManager, prefabSerializer);
Path outFile = PathManager.getInstance().getHomePath().resolve(Instant.now() + "-entityDump.json");
if (componentNames.length == 0) {
savedEntityCount = worldDumper.save(outFile);
} else {
List<Class<? extends Component>> filterComponents = Arrays.stream(componentNames).map(// Trim off whitespace
String::trim).filter(// Remove empty strings
o -> !o.isEmpty()).map(// All component class names end with "component"
o -> o.toLowerCase().endsWith("component") ? o : o + "component").map(o -> Streams.stream(moduleManager.getEnvironment().getSubtypesOf(Component.class)).filter(e -> e.getSimpleName().equalsIgnoreCase(o)).findFirst()).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
if (!filterComponents.isEmpty()) {
savedEntityCount = worldDumper.save(outFile, filterComponents);
} else {
return "Could not find components matching given names";
}
}
return "Number of entities saved: " + savedEntityCount;
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class ServerConnectionHandler method sendModules.
private void sendModules(List<NetData.ModuleRequest> moduleRequestList) {
for (NetData.ModuleRequest request : moduleRequestList) {
NetData.ModuleDataHeader.Builder result = NetData.ModuleDataHeader.newBuilder();
result.setId(request.getModuleId());
Module module = moduleManager.getEnvironment().get(new Name(request.getModuleId()));
if (!(module.getResources() instanceof ArchiveFileSource)) {
// TODO: gestaltv7 restore module downloading for maximum possibles
result.setError("Module not available for download");
} else {
FileReference fileReference = module.getResources().getFiles().iterator().next();
try (InputStream stream = fileReference.open()) {
ByteString byteString = ByteString.readFrom(stream, 1024);
channelHandlerContext.channel().write(NetData.NetMessage.newBuilder().setModuleData(NetData.ModuleData.newBuilder().setModule(byteString)).build());
result.setVersion(module.getVersion().toString());
result.setSize(byteString.size());
channelHandlerContext.channel().write(NetData.NetMessage.newBuilder().setModuleDataHeader(result).build());
} catch (IOException e) {
logger.error("Error sending module", e);
channelHandlerContext.channel().close();
break;
}
}
}
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class ServerInfoMessageImpl method getModuleList.
@Override
public List<NameVersion> getModuleList() {
List<NameVersion> result = Lists.newArrayList();
for (NetData.ModuleInfo moduleInfo : info.getModuleList()) {
if (!moduleInfo.hasModuleId() || !moduleInfo.hasModuleVersion()) {
logger.error("Received incomplete module info");
} else {
Name id = new Name(moduleInfo.getModuleId());
Version version = new Version(moduleInfo.getModuleVersion());
result.add(new NameVersion(id, version));
}
}
return result;
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class ModuleEnvironmentSandbox method isValidTypeHandlerDeclaration.
@Override
public <T> boolean isValidTypeHandlerDeclaration(TypeInfo<T> type, TypeHandler<T> typeHandler) {
Name moduleDeclaringHandler = getModuleProviding(typeHandler.getClass());
// TODO: Possibly find better way to refer to engine module
if (moduleDeclaringHandler == null || moduleDeclaringHandler.equals(new Name("engine"))) {
return true;
}
if (type.getRawType().getClassLoader() == null) {
// Modules cannot specify handlers for builtin classes
return false;
}
Name moduleDeclaringType = getModuleProviding(type.getRawType());
// Both the type and the handler must come from the same module
return Objects.equals(moduleDeclaringType, moduleDeclaringHandler);
}
Aggregations