Search in sources :

Example 1 with PermissionConfig

use of org.terasology.engine.config.PermissionConfig 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.engine.config.PermissionConfig) ClientComponent(org.terasology.engine.network.ClientComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Aggregations

PermissionConfig (org.terasology.engine.config.PermissionConfig)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)1 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)1 ClientComponent (org.terasology.engine.network.ClientComponent)1