Search in sources :

Example 41 with ClientComponent

use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.

the class CoreCommands method bulkDrop.

@Command(shortDescription = "Mass-drops the desired block however many times the player indicates", helpText = "First parameter indicates which block to drop, second parameter how many", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String bulkDrop(@Sender EntityRef sender, @CommandParam("blockName") String blockName, @CommandParam("value") int value) {
    // This is a loop which gives the particular amount of block the player wants to spawn
    ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
    LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
    Vector3f spawnPos = characterLocation.getWorldPosition(new Vector3f());
    Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
    offset.mul(3);
    spawnPos.add(5, 10, 0);
    BlockFamily block = blockManager.getBlockFamily(blockName);
    if (block == null) {
        return "Sorry, your block is not found";
    }
    BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
    if (value > 5000) {
        return "Value exceeds the maximum limit of 5000 blocks. your value: " + value + " blocks";
    }
    for (int i = 0; i < value; i++) {
        EntityRef blockItem = blockItemFactory.newInstance(block);
        blockItem.send(new DropItemEvent(spawnPos));
    }
    // this returns the block you have spawned and the amount
    return "Dropped " + value + " " + blockName + " Blocks :)";
}
Also used : DropItemEvent(org.terasology.engine.logic.inventory.events.DropItemEvent) Vector3f(org.joml.Vector3f) BlockItemFactory(org.terasology.engine.world.block.items.BlockItemFactory) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand)

Example 42 with ClientComponent

use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.

the class CoreCommands method spawnBlock.

/**
 * Spawns a block in front of the player
 *
 * @param sender    Sender of command
 * @param blockName String containing name of block to spawn
 * @return String containg final message
 */
@Command(shortDescription = "Spawns a block in front of the player", helpText = "Spawns the specified block as a " + "item in front of the player. You can simply pick it up.", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String spawnBlock(@Sender EntityRef sender, @CommandParam("blockName") String blockName) {
    ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
    LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
    Vector3f spawnPos = characterLocation.getWorldPosition(new Vector3f());
    Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
    offset.mul(3);
    spawnPos.add(offset);
    BlockFamily block = blockManager.getBlockFamily(blockName);
    if (block == null) {
        return "";
    }
    BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
    EntityRef blockItem = blockItemFactory.newInstance(block);
    blockItem.send(new DropItemEvent(spawnPos));
    return "Spawned block.";
}
Also used : DropItemEvent(org.terasology.engine.logic.inventory.events.DropItemEvent) Vector3f(org.joml.Vector3f) BlockItemFactory(org.terasology.engine.world.block.items.BlockItemFactory) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand)

Example 43 with ClientComponent

use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.

the class PlayerNameTagSystem method onDisplayNameChange.

@ReceiveEvent
public void onDisplayNameChange(OnChangedComponent event, EntityRef clientInfoEntity, DisplayNameComponent displayNameComponent, ClientInfoComponent clientInfoComp) {
    EntityRef clientEntity = clientInfoComp.client;
    if (!clientEntity.exists()) {
        // offline players aren't visible: nothing to do
        return;
    }
    ClientComponent clientComponent = clientEntity.getComponent(ClientComponent.class);
    if (clientComponent == null) {
        // the character is not owned by a client (no other player)
        return;
    }
    EntityRef characterEntity = clientComponent.character;
    if (characterEntity == null || !characterEntity.exists()) {
        // player has no character, nothing to do
        return;
    }
    NameTagComponent nameTagComponent = characterEntity.getComponent(NameTagComponent.class);
    if (nameTagComponent == null) {
        // local players don't have a name tag
        return;
    }
    nameTagComponent.text = displayNameComponent.name;
    characterEntity.saveComponent(nameTagComponent);
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 44 with ClientComponent

use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.

the class PlayerNameTagSystem method onCharacterActivation.

/**
 * Listening for {@link OnPlayerSpawnedEvent} does not work, as it is an
 * authority event that does not get processed at clients. That is why we listen for the activation.
 */
@ReceiveEvent(components = CharacterComponent.class)
public void onCharacterActivation(OnActivatedComponent event, EntityRef characterEntity, CharacterComponent characterComponent) {
    EntityRef ownerEntity = networkSystem.getOwnerEntity(characterEntity);
    if (ownerEntity == null) {
        // NPC
        return;
    }
    ClientComponent clientComponent = ownerEntity.getComponent(ClientComponent.class);
    if (clientComponent == null) {
        // the character is not owned by a client (no other player)
        return;
    }
    if (clientComponent.local) {
        // the character belongs to the local player and does not need a name tag
        return;
    }
    EntityRef clientInfoEntity = clientComponent.clientInfo;
    DisplayNameComponent displayNameComponent = clientInfoEntity.getComponent(DisplayNameComponent.class);
    if (displayNameComponent == null) {
        logger.debug("Cannot create name tag for client without DisplayNameComponent");
        return;
    }
    String name = displayNameComponent.name;
    float yOffset = characterComponent.nameTagOffset;
    ColorComponent colorComponent = clientInfoEntity.getComponent(ColorComponent.class);
    final Color color = colorComponent != null ? colorComponent.color : Color.WHITE;
    characterEntity.upsertComponent(NameTagComponent.class, maybeNameTag -> {
        NameTagComponent nameTagComponent = maybeNameTag.orElse(new NameTagComponent());
        nameTagComponent.text = name;
        nameTagComponent.textColor = color;
        nameTagComponent.yOffset = yOffset;
        return nameTagComponent;
    });
}
Also used : DisplayNameComponent(org.terasology.engine.logic.common.DisplayNameComponent) ColorComponent(org.terasology.engine.network.ColorComponent) Color(org.terasology.nui.Color) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 45 with ClientComponent

use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.

the class PermissionCommands method givePermission.

@Command(shortDescription = "Gives specified permission to player", helpText = "Gives specified permission to player", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String givePermission(@CommandParam(value = "player", suggester = UsernameSuggester.class) String player, @CommandParam("permission") String permission, @Sender EntityRef requester) {
    boolean permissionGiven = false;
    ClientComponent requesterClientComponent = requester.getComponent(ClientComponent.class);
    EntityRef requesterClientInfo = requesterClientComponent.clientInfo;
    if (!permissionManager.hasPermission(requesterClientInfo, permission)) {
        return String.format("You can't give the permission %s because you don't have it yourself", permission);
    }
    for (EntityRef client : entityManager.getEntitiesWith(ClientComponent.class)) {
        ClientComponent clientComponent = client.getComponent(ClientComponent.class);
        if (clientHasName(clientComponent, player)) {
            permissionManager.addPermission(clientComponent.clientInfo, permission);
            permissionGiven = true;
        }
    }
    if (permissionGiven) {
        return "Permission " + permission + " added to player " + player;
    } else {
        return "Unable to find player " + player;
    }
}
Also used : 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

ClientComponent (org.terasology.engine.network.ClientComponent)54 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)30 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)27 Vector3f (org.joml.Vector3f)13 LocationComponent (org.terasology.engine.logic.location.LocationComponent)13 CharacterMovementComponent (org.terasology.engine.logic.characters.CharacterMovementComponent)11 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)10 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)8 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)6 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)6 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)4 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)4 BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)4 Quaternionf (org.joml.Quaternionf)3 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)3 LocalPlayer (org.terasology.engine.logic.players.LocalPlayer)3 Client (org.terasology.engine.network.Client)3 Vector3ic (org.joml.Vector3ic)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 AliveCharacterComponent (org.terasology.engine.logic.characters.AliveCharacterComponent)2