Search in sources :

Example 41 with Command

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

the class ClientCommands method setWorldTime.

/**
 * Sets the current world time for the local player in days
 * @param day Float containing day to be set
 * @return String message containing message to notify user
 */
@Command(shortDescription = "Sets the current world time for the local player in days", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String setWorldTime(@CommandParam("day") float day, @Sender EntityRef sender) {
    worldProvider.getTime().setDays(day);
    sender.send(new WorldtimeResetEvent(day));
    return "World time changed";
}
Also used : WorldtimeResetEvent(org.terasology.engine.logic.players.event.WorldtimeResetEvent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 42 with Command

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

Example 43 with Command

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

the class ServerCommands method kickUserByID.

@Command(shortDescription = "Kick user by ID", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String kickUserByID(@CommandParam("userId") int userId) {
    for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
        EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
        NetworkComponent nc = clientInfo.getComponent(NetworkComponent.class);
        if (userId == nc.getNetworkId()) {
            return kick(clientEntity);
        }
    }
    throw new IllegalArgumentException("No such user with ID " + userId);
}
Also used : NetworkComponent(org.terasology.engine.network.NetworkComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 44 with Command

use of org.terasology.engine.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.engine.logic.common.DisplayNameComponent) NetworkComponent(org.terasology.engine.network.NetworkComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 45 with Command

use of org.terasology.engine.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.engine.logic.common.DisplayNameComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) 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