Search in sources :

Example 6 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent 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 7 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.

the class ServerCommands method renameUser.

@Command(shortDescription = "Rename a user", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String renameUser(@CommandParam(value = "userName", suggester = UsernameSuggester.class) String userName, @CommandParam(value = "newUserName") String newUserName) {
    Iterable<EntityRef> clientInfoEntities = entityManager.getEntitiesWith(ClientInfoComponent.class);
    for (EntityRef clientInfo : clientInfoEntities) {
        DisplayNameComponent nameComp = clientInfo.getComponent(DisplayNameComponent.class);
        if (newUserName.equalsIgnoreCase(nameComp.name)) {
            throw new IllegalArgumentException("New user name is already in use");
        }
    }
    for (EntityRef clientInfo : clientInfoEntities) {
        DisplayNameComponent nameComp = clientInfo.getComponent(DisplayNameComponent.class);
        if (userName.equalsIgnoreCase(nameComp.name)) {
            nameComp.name = newUserName;
            clientInfo.saveComponent(nameComp);
            return "User " + userName + " has been renamed to " + newUserName;
        }
    }
    throw new IllegalArgumentException("No such user '" + userName + "'");
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 8 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.

the class AbstractClient method addOrSetDisplayNameComponent.

private void addOrSetDisplayNameComponent(EntityRef clientInfo, String name) {
    DisplayNameComponent component = clientInfo.getComponent(DisplayNameComponent.class);
    if (component != null) {
        component.name = name;
        clientInfo.saveComponent(component);
    } else {
        component = new DisplayNameComponent();
        component.name = name;
        clientInfo.addComponent(component);
    }
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent)

Example 9 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.

the class AbstractClient method findNamesOfOtherPlayers.

private Set<String> findNamesOfOtherPlayers(EntityManager entityManager, EntityRef player) {
    Set<String> otherNames = new HashSet<>();
    for (EntityRef clientInfo : entityManager.getEntitiesWith(ClientInfoComponent.class)) {
        if (!clientInfo.equals(player)) {
            DisplayNameComponent displayInfo = clientInfo.getComponent(DisplayNameComponent.class);
            String usedName = displayInfo.name;
            otherNames.add(usedName);
        }
    }
    return otherNames;
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) HashSet(java.util.HashSet)

Example 10 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.

the class BlockItemFactory method newInstance.

public EntityRef newInstance(BlockFamily blockFamily, EntityRef blockEntity) {
    if (blockFamily == null) {
        return EntityRef.NULL;
    }
    EntityBuilder builder = entityManager.newBuilder("engine:blockItemBase");
    if (blockFamily.getArchetypeBlock().getLuminance() > 0) {
        builder.addComponent(new LightComponent());
    }
    // Copy the components from block prefab into the block item
    for (Component component : blockEntity.iterateComponents()) {
        if (component.getClass().getAnnotation(AddToBlockBasedItem.class) != null) {
            builder.addComponent(entityManager.getComponentLibrary().copy(component));
        }
    }
    DisplayNameComponent displayNameComponent = builder.getComponent(DisplayNameComponent.class);
    if (displayNameComponent != null) {
        displayNameComponent.name = blockFamily.getDisplayName();
    }
    ItemComponent item = builder.getComponent(ItemComponent.class);
    if (blockFamily.getArchetypeBlock().isStackable()) {
        item.stackId = "block:" + blockFamily.getURI().toString();
        item.stackCount = (byte) 1;
    }
    BlockItemComponent blockItem = builder.getComponent(BlockItemComponent.class);
    blockItem.blockFamily = blockFamily;
    return builder.build();
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) ItemComponent(org.terasology.logic.inventory.ItemComponent) LightComponent(org.terasology.rendering.logic.LightComponent) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) LightComponent(org.terasology.rendering.logic.LightComponent) ItemComponent(org.terasology.logic.inventory.ItemComponent) Component(org.terasology.entitySystem.Component) DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent)

Aggregations

DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)23 EntityRef (org.terasology.entitySystem.entity.EntityRef)17 ClientComponent (org.terasology.network.ClientComponent)13 Command (org.terasology.logic.console.commandSystem.annotations.Command)9 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)4 LocationComponent (org.terasology.logic.location.LocationComponent)4 Vector3f (org.terasology.math.geom.Vector3f)4 Component (org.terasology.entitySystem.Component)2 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)2 Prefab (org.terasology.entitySystem.prefab.Prefab)2 ItemComponent (org.terasology.logic.inventory.ItemComponent)2 PlayerCharacterComponent (org.terasology.logic.players.PlayerCharacterComponent)2 ColorComponent (org.terasology.network.ColorComponent)2 LightComponent (org.terasology.rendering.logic.LightComponent)2 HashSet (java.util.HashSet)1 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)1 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)1 MovementMode (org.terasology.logic.characters.MovementMode)1 SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)1 Client (org.terasology.network.Client)1