Search in sources :

Example 51 with Command

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

the class CoreCommands method editSkin.

/**
 * Opens the NUI editor for a ui skin
 * @param uri String containing name of ui skin
 * @return String containing final message
 */
@Command(shortDescription = "Opens the NUI editor for a ui skin", requiredPermission = PermissionManager.NO_PERMISSION)
public String editSkin(@CommandParam(value = "uri", suggester = SkinSuggester.class) String uri) {
    if (!nuiSkinEditorSystem.isEditorActive()) {
        nuiSkinEditorSystem.toggleEditor();
    }
    Set<ResourceUrn> urns = assetManager.resolve(uri, UISkin.class);
    switch(urns.size()) {
        case 0:
            return String.format("No asset found for screen '%s'", uri);
        case 1:
            ResourceUrn urn = urns.iterator().next();
            ((NUISkinEditorScreen) nuiManager.getScreen(NUISkinEditorScreen.ASSET_URI)).selectAsset(urn);
            return "Success";
        default:
            return String.format("Multiple matches for screen '%s': {%s}", uri, Arrays.toString(urns.toArray()));
    }
}
Also used : NUISkinEditorScreen(org.terasology.rendering.nui.editor.layers.NUISkinEditorScreen) ResourceUrn(org.terasology.assets.ResourceUrn) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Example 52 with Command

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

the class CoreCommands method setLanguage.

/**
 * Change the UI language
 * @param langTag String containing language code to change
 * @return String containing language or if not recognized error message
 */
@Command(shortDescription = "Changes the UI language")
public String setLanguage(@CommandParam("language-tag") String langTag) {
    Locale locale = Locale.forLanguageTag(langTag);
    TranslationProject proj = translationSystem.getProject(new SimpleUri("engine:menu"));
    // Try if language exists
    if (proj.getAvailableLocales().contains(locale)) {
        config.getSystem().setLocale(locale);
        nuiManager.invalidate();
        String nat = translationSystem.translate("${engine:menu#this-language-native}", locale);
        String eng = translationSystem.translate("${engine:menu#this-language-English}", locale);
        return String.format("Language set to %s (%s)", nat, eng);
    } else {
        return "Unrecognized locale! Try one of: " + proj.getAvailableLocales();
    }
}
Also used : Locale(java.util.Locale) TranslationProject(org.terasology.i18n.TranslationProject) SimpleUri(org.terasology.engine.SimpleUri) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Example 53 with Command

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

the class ServerCommands method shutdownServer.

@Command(shortDescription = "Shutdown the server", runOnServer = true, requiredPermission = PermissionManager.SERVER_MANAGEMENT_PERMISSION)
public String shutdownServer(@Sender EntityRef sender) {
    // TODO: verify permissions of sender
    EntityRef clientInfo = sender.getComponent(ClientComponent.class).clientInfo;
    DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
    logger.info("Shutdown triggered by {}", name.name);
    gameEngine.shutdown();
    return "Server shutdown triggered";
}
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 54 with Command

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

the class ServerCommands method listUsers.

@Command(shortDescription = "List users", requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String listUsers() {
    StringBuilder stringBuilder = new StringBuilder();
    for (EntityRef clientInfo : entityManager.getEntitiesWith(ClientInfoComponent.class)) {
        DisplayNameComponent dnc = clientInfo.getComponent(DisplayNameComponent.class);
        NetworkComponent nc = clientInfo.getComponent(NetworkComponent.class);
        String playerText = PlayerUtil.getColoredPlayerName(clientInfo);
        String line = String.format("%s - %s (%d)", playerText, dnc.description, nc.getNetworkId());
        stringBuilder.append(line);
        stringBuilder.append(Console.NEW_LINE);
    }
    return stringBuilder.toString();
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) NetworkComponent(org.terasology.network.NetworkComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 55 with Command

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

the class ServerCommands method kickUser.

@Command(shortDescription = "Kick user by name", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String kickUser(@CommandParam("username") String username) {
    for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
        EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
        DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
        if (username.equalsIgnoreCase(name.name)) {
            return kick(clientEntity);
        }
    }
    throw new IllegalArgumentException("No such user '" + username + "'");
}
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)

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