use of org.terasology.engine.logic.console.commandSystem.annotations.Sender 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.engine.logic.console.commandSystem.annotations.Sender in project Terasology by MovingBlocks.
the class MethodCommand method hasSenderAnnotation.
private static boolean hasSenderAnnotation(Method method) {
final Class[] paramTypes = method.getParameterTypes();
final Annotation[][] paramAnnotations = method.getParameterAnnotations();
for (int i = 0; i < paramAnnotations.length; i++) {
if (paramTypes[i].getTypeName().equals(ENTITY_REF_NAME)) {
if (paramAnnotations[i].length == 0) {
return false;
} else {
for (Annotation annotation : paramAnnotations[i]) {
if (annotation instanceof Sender) {
return true;
}
}
}
}
}
return true;
}
use of org.terasology.engine.logic.console.commandSystem.annotations.Sender in project Terasology by MovingBlocks.
the class MethodCommand method getParameterTypeFor.
private static Parameter getParameterTypeFor(Class<?> type, Annotation[] annotations, Context context) {
for (Annotation annotation : annotations) {
if (annotation instanceof CommandParam) {
CommandParam parameterAnnotation = (CommandParam) annotation;
String name = parameterAnnotation.value();
Class<? extends CommandParameterSuggester> suggesterClass = parameterAnnotation.suggester();
boolean required = parameterAnnotation.required();
CommandParameterSuggester suggester = InjectionHelper.createWithConstructorInjection(suggesterClass, context);
if (type.isArray()) {
Class<?> childType = type.getComponentType();
return CommandParameter.array(name, childType, required, suggester, context);
} else {
return CommandParameter.single(name, type, required, suggester, context);
}
} else if (annotation instanceof Sender) {
return MarkerParameters.SENDER;
}
}
return MarkerParameters.INVALID;
}
Aggregations