Search in sources :

Example 16 with Command

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

the class PermissionCommands method usePermissionKey.

@Command(shortDescription = "Use an one time key to get all permissions", helpText = "The config file contains a one time key which can be used to get all permissions.", runOnServer = true, requiredPermission = PermissionManager.NO_PERMISSION)
public String usePermissionKey(@CommandParam("key") String key, @Sender EntityRef client) {
    PermissionConfig permissionConfig = config.getPermission();
    String expectedKey = permissionConfig.getOneTimeAuthorizationKey();
    if (expectedKey != null && !expectedKey.equals("") && key.equals(expectedKey)) {
        permissionConfig.setOneTimeAuthorizationKey("");
        ClientComponent clientComponent = client.getComponent(ClientComponent.class);
        EntityRef clientInfo = clientComponent.clientInfo;
        for (String permission : findAllPermissions()) {
            permissionManager.addPermission(clientInfo, permission);
        }
        PermissionSetComponent permissionSetComp = clientInfo.getComponent(PermissionSetComponent.class);
        return "Permission key used: You have now the following permissions: " + permissionSetComp.permissions;
    } else {
        return "Key invalid or used";
    }
}
Also used : PermissionConfig(org.terasology.config.PermissionConfig) ClientComponent(org.terasology.network.ClientComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 17 with Command

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

the class FirstPersonClientSystem method setFirstPersonheldItemMountPointRotation.

@Command(shortDescription = "Sets the held item mount point rotation for the first person view")
public void setFirstPersonheldItemMountPointRotation(@CommandParam("x") float x, @CommandParam("y") float y, @CommandParam("z") float z) {
    FirstPersonHeldItemMountPointComponent newComponent = localPlayer.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
    if (newComponent != null) {
        newComponent.rotateDegrees = new Vector3f(x, y, z);
        ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent.newInstance(), localPlayer.getCameraEntity(), newComponent);
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 18 with Command

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

the class FirstPersonClientSystem method setFirstPersonheldItemMountPointTranslation.

@Command(shortDescription = "Sets the held item mount point translation for the first person view")
public void setFirstPersonheldItemMountPointTranslation(@CommandParam("x") float x, @CommandParam("y") float y, @CommandParam("z") float z) {
    FirstPersonHeldItemMountPointComponent newComponent = localPlayer.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
    if (newComponent != null) {
        newComponent.translate = new Vector3f(x, y, z);
        ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent.newInstance(), localPlayer.getCameraEntity(), newComponent);
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 19 with Command

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

the class ChatSystem method whisper.

@Command(runOnServer = true, requiredPermission = PermissionManager.CHAT_PERMISSION, shortDescription = "Sends a private message to a specified user")
public String whisper(@Sender EntityRef sender, @CommandParam(value = "user", suggester = OnlineUsernameSuggester.class) String username, @CommandParam("message") String[] message) {
    String messageToString = join(message, " ");
    Iterable<EntityRef> clients = entityManager.getEntitiesWith(ClientComponent.class);
    EntityRef targetClient = null;
    boolean unique = true;
    for (EntityRef client : clients) {
        ClientComponent clientComponent = client.getComponent(ClientComponent.class);
        DisplayNameComponent displayNameComponent = clientComponent.clientInfo.getComponent(DisplayNameComponent.class);
        if (displayNameComponent == null) {
            continue;
        }
        if (displayNameComponent.name.equalsIgnoreCase(username)) {
            if (targetClient == null) {
                targetClient = client;
            } else {
                unique = false;
                break;
            }
        }
    }
    if (!unique) {
        targetClient = null;
        for (EntityRef client : clients) {
            ClientComponent clientComponent = client.getComponent(ClientComponent.class);
            DisplayNameComponent displayNameComponent = clientComponent.clientInfo.getComponent(DisplayNameComponent.class);
            if (displayNameComponent == null) {
                continue;
            }
            if (displayNameComponent.name.equals(username)) {
                if (targetClient == null) {
                    targetClient = client;
                } else {
                    return FontColor.getColored("Found more users with name '" + username + "'.", ConsoleColors.ERROR);
                }
            }
        }
    }
    if (targetClient == null) {
        return FontColor.getColored("User with name '" + username + "' not found.", ConsoleColors.ERROR);
    }
    ClientComponent senderClientComponent = sender.getComponent(ClientComponent.class);
    ClientComponent targetClientComponent = targetClient.getComponent(ClientComponent.class);
    DisplayNameComponent targetDisplayNameComponent = targetClientComponent.clientInfo.getComponent(DisplayNameComponent.class);
    String targetMessage = FontColor.getColored("*whispering* ", ConsoleColors.ERROR) + FontColor.getColored(messageToString, ConsoleColors.CHAT);
    String senderMessage = "You -> " + targetDisplayNameComponent.name + ": " + FontColor.getColored(messageToString, ConsoleColors.CHAT);
    targetClient.send(new ChatMessageEvent(targetMessage, senderClientComponent.clientInfo));
    return senderMessage;
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 20 with Command

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

the class MethodCommand method referringTo.

/**
 * Creates a new {@code ReferencedCommand} to a specific method
 * annotated with {@link org.terasology.logic.console.commandSystem.annotations.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);
}
Also used : Command(org.terasology.logic.console.commandSystem.annotations.Command) Method(java.lang.reflect.Method) Name(org.terasology.naming.Name)

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