Search in sources :

Example 41 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class BlockCommands method listBlocks.

@Command(shortDescription = "List all available blocks\nYou can filter by adding the beginning of words after the" + "commands, e.g.: \"listBlocks engine: core:\" will list all blocks from the engine and core module", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String listBlocks(@CommandParam(value = "startsWith", required = false) String[] startsWith) {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("Used Blocks");
    stringBuilder.append(Console.NEW_LINE);
    stringBuilder.append("-----------");
    stringBuilder.append(Console.NEW_LINE);
    List<BlockUri> registeredBlocks = sortItems(blockManager.listRegisteredBlockUris());
    for (BlockUri blockUri : registeredBlocks) {
        if (!uriStartsWithAnyString(blockUri.toString(), startsWith)) {
            continue;
        }
        stringBuilder.append(blockUri.toString());
        stringBuilder.append(Console.NEW_LINE);
    }
    stringBuilder.append(Console.NEW_LINE);
    stringBuilder.append("Available Blocks");
    stringBuilder.append(Console.NEW_LINE);
    stringBuilder.append("----------------");
    stringBuilder.append(Console.NEW_LINE);
    List<BlockUri> availableBlocks = sortItems(blockExplorer.getAvailableBlockFamilies());
    for (BlockUri blockUri : availableBlocks) {
        if (!uriStartsWithAnyString(blockUri.toString(), startsWith)) {
            continue;
        }
        stringBuilder.append(blockUri.toString());
        stringBuilder.append(Console.NEW_LINE);
    }
    return stringBuilder.toString();
}
Also used : BlockUri(org.terasology.world.block.BlockUri) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 42 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class BindCommands method bindKey.

@Command(shortDescription = "Maps a key to a function", requiredPermission = PermissionManager.NO_PERMISSION)
public String bindKey(@CommandParam("key") String key, @CommandParam("function") String bind) {
    Input keyInput = Keyboard.Key.find(key);
    if (keyInput != null) {
        bindsManager.linkBindButtonToKey(keyInput.getId(), new SimpleUri(bind));
        StringBuilder builder = new StringBuilder();
        builder.append("Mapped ").append(keyInput.getDisplayName()).append(" to action ");
        builder.append(bind);
        return builder.toString();
    }
    throw new IllegalArgumentException("Unknown key: " + key);
}
Also used : Input(org.terasology.input.Input) SimpleUri(org.terasology.engine.SimpleUri) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 43 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class ChatSystem method say.

@Command(runOnServer = true, requiredPermission = PermissionManager.CHAT_PERMISSION, shortDescription = "Sends a message to all other players")
public String say(@Sender EntityRef sender, @CommandParam(value = "message") String[] message) {
    String messageToString = join(message, " ");
    logger.debug("Received chat message from {} : '{}'", sender, messageToString);
    for (EntityRef client : entityManager.getEntitiesWith(ClientComponent.class)) {
        client.send(new ChatMessageEvent(messageToString, sender.getComponent(ClientComponent.class).clientInfo));
    }
    return "Message sent";
}
Also used : EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 44 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class MethodCommand method registerAvailable.

/**
 * Registers all available command methods annotated with {@link org.terasology.logic.console.commandSystem.annotations.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.utilities.reflection.SpecificAccessibleObject) Command(org.terasology.logic.console.commandSystem.annotations.Command) Method(java.lang.reflect.Method)

Example 45 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class ClientCommands method setSpawnLocation.

/**
 * Sets the spawn location for the client to the current location
 * @return String containing debug information on the entity
 */
@Command(shortDescription = "Sets the spawn location for the client to the current location", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String setSpawnLocation(@Sender EntityRef sender) {
    EntityRef clientInfo = sender.getComponent(ClientComponent.class).clientInfo;
    StaticSpawnLocationComponent staticSpawnLocationComponent = new StaticSpawnLocationComponent();
    if (clientInfo.hasComponent(StaticSpawnLocationComponent.class)) {
        staticSpawnLocationComponent = clientInfo.getComponent(StaticSpawnLocationComponent.class);
    }
    staticSpawnLocationComponent.position = sender.getComponent(ClientComponent.class).character.getComponent(LocationComponent.class).getWorldPosition();
    clientInfo.addOrSaveComponent(staticSpawnLocationComponent);
    return "Set spawn location to- " + staticSpawnLocationComponent.position;
}
Also used : StaticSpawnLocationComponent(org.terasology.logic.players.StaticSpawnLocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Aggregations

Command (org.terasology.logic.console.commandSystem.annotations.Command)76 ClientComponent (org.terasology.network.ClientComponent)48 EntityRef (org.terasology.entitySystem.entity.EntityRef)28 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)16 Vector3f (org.terasology.math.geom.Vector3f)14 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)11 LocationComponent (org.terasology.logic.location.LocationComponent)10 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)9 ResourceUrn (org.terasology.assets.ResourceUrn)8 Prefab (org.terasology.entitySystem.prefab.Prefab)6 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)6 SimpleUri (org.terasology.engine.SimpleUri)5 BlockFamily (org.terasology.world.block.family.BlockFamily)4 Map (java.util.Map)3 AnatomyComponent (org.terasology.anatomy.component.AnatomyComponent)3 SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)3 DropItemEvent (org.terasology.logic.inventory.events.DropItemEvent)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2