use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class MethodCommand method registerAvailable.
/**
* Registers all available command methods annotated with {@link Command}.
*/
public static void registerAvailable(Object provider, Console console, Context context) {
Predicate<? super Method> predicate = Predicates.<Method>and(ReflectionUtils.withModifier(Modifier.PUBLIC), ReflectionUtils.withAnnotation(Command.class));
Set<Method> commandMethods = ReflectionUtils.getAllMethods(provider.getClass(), predicate);
for (Method method : commandMethods) {
if (!hasSenderAnnotation(method)) {
logger.error("Command {} provided by {} contains a EntityRef without @Sender annotation, may cause a " + "NullPointerException", method.getName(), provider.getClass().getSimpleName());
}
logger.debug("Registering command method {} in class {}", method.getName(), method.getDeclaringClass().getCanonicalName());
try {
SpecificAccessibleObject<Method> specificMethod = new SpecificAccessibleObject<>(method, provider);
MethodCommand command = referringTo(specificMethod, context);
console.registerCommand(command);
logger.debug("Registered command method {} in class {}", method.getName(), method.getDeclaringClass().getCanonicalName());
} catch (RuntimeException t) {
logger.error("Failed to load command method {} in class {}", method.getName(), method.getDeclaringClass().getCanonicalName(), t);
}
}
}
use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class ThirdPersonRemoteClientSystem method setRemotePlayersHeldItemMountPointTranslations.
@Command(shortDescription = "Sets the held item mount point translation for remote characters")
public void setRemotePlayersHeldItemMountPointTranslations(@CommandParam("x") float x, @CommandParam("y") float y, @CommandParam("z") float z) {
for (EntityRef remotePlayer : entityManager.getEntitiesWith(RemotePersonHeldItemMountPointComponent.class)) {
RemotePersonHeldItemMountPointComponent remoteMountPointComponent = remotePlayer.getComponent(RemotePersonHeldItemMountPointComponent.class);
remoteMountPointComponent.translate.set(x, y, z);
}
}
use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class ThirdPersonRemoteClientSystem method setRemotePlayersHeldItemMountPointRotations.
@Command(shortDescription = "Sets the held item mount point rotation for remote characters")
public void setRemotePlayersHeldItemMountPointRotations(@CommandParam("x") float x, @CommandParam("y") float y, @CommandParam("z") float z) {
for (EntityRef remotePlayer : entityManager.getEntitiesWith(RemotePersonHeldItemMountPointComponent.class)) {
RemotePersonHeldItemMountPointComponent remoteMountPointComponent = remotePlayer.getComponent(RemotePersonHeldItemMountPointComponent.class);
remoteMountPointComponent.rotateDegrees.set(x, y, z);
}
}
use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class MovementDebugCommands method playerHeight.
@Command(shortDescription = "Sets the height of the player", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String playerHeight(@Sender EntityRef entity, @CommandParam("height") float newHeight) {
if (newHeight > 0.5 && newHeight <= 20) {
ClientComponent client = entity.getComponent(ClientComponent.class);
if (client != null) {
EntityRef character = client.character;
CharacterMovementComponent movement = client.character.getComponent(CharacterMovementComponent.class);
if (movement != null) {
float currentHeight = movement.height;
ScaleToRequest scaleRequest = new ScaleToRequest(newHeight);
character.send(scaleRequest);
return "Height of player set to " + newHeight + " (was " + currentHeight + ")";
}
}
} else {
return "Invalid input. Accepted values: [1 to 25]";
}
return "";
}
use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class MovementDebugCommands method hjump.
@Command(shortDescription = "Jump really high", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String hjump(@Sender EntityRef client) {
ClientComponent clientComp = client.getComponent(ClientComponent.class);
CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
if (move != null) {
move.jumpSpeed = 75f;
clientComp.character.saveComponent(move);
return "High-jump mode activated";
}
return "";
}
Aggregations