Search in sources :

Example 21 with Command

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);
        }
    }
}
Also used : SpecificAccessibleObject(org.terasology.engine.utilities.reflection.SpecificAccessibleObject) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) Method(java.lang.reflect.Method)

Example 22 with Command

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);
    }
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 23 with Command

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);
    }
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 24 with Command

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 "";
}
Also used : CharacterMovementComponent(org.terasology.engine.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.engine.network.ClientComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ScaleToRequest(org.terasology.engine.logic.characters.events.ScaleToRequest) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 25 with Command

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 "";
}
Also used : CharacterMovementComponent(org.terasology.engine.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.engine.network.ClientComponent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Aggregations

Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)67 ClientComponent (org.terasology.engine.network.ClientComponent)42 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)35 Vector3f (org.joml.Vector3f)16 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)16 CharacterMovementComponent (org.terasology.engine.logic.characters.CharacterMovementComponent)11 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)10 LocationComponent (org.terasology.engine.logic.location.LocationComponent)10 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)9 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)6 Map (java.util.Map)5 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)5 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)5 BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 List (java.util.List)3 Locale (java.util.Locale)3