Search in sources :

Example 86 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class ClientCommands method setSpawnLocation.

/**
 * Sets the spawn location for the client to the current location
 * @return String containing debug information on the entity
 */
@Command(shortDescription = "Sets the spawn location for the client to the current location", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String setSpawnLocation(@Sender EntityRef sender) {
    EntityRef clientInfo = sender.getComponent(ClientComponent.class).clientInfo;
    StaticSpawnLocationComponent staticSpawnLocationComponent = new StaticSpawnLocationComponent();
    if (clientInfo.hasComponent(StaticSpawnLocationComponent.class)) {
        staticSpawnLocationComponent = clientInfo.getComponent(StaticSpawnLocationComponent.class);
    }
    staticSpawnLocationComponent.position = sender.getComponent(ClientComponent.class).character.getComponent(LocationComponent.class).getWorldPosition(new Vector3f());
    clientInfo.addOrSaveComponent(staticSpawnLocationComponent);
    return "Set spawn location to- " + staticSpawnLocationComponent.position;
}
Also used : StaticSpawnLocationComponent(org.terasology.engine.logic.players.StaticSpawnLocationComponent) Vector3f(org.joml.Vector3f) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 87 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef 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.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 88 with EntityRef

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

Example 89 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class InteractionSystem method onScreenLayerClosed.

/**
 * The method listens for the event that the user closes the screen of the current interaction target.
 * <p>
 * When it happens then it cancels the interaction.
 */
@ReceiveEvent(components = ClientComponent.class)
public void onScreenLayerClosed(ScreenLayerClosedEvent event, EntityRef container, ClientComponent clientComponent) {
    EntityRef character = clientComponent.character;
    ResourceUrn activeInteractionScreenUri = InteractionUtil.getActiveInteractionScreenUri(character);
    if ((activeInteractionScreenUri != null) && (activeInteractionScreenUri.equals(event.getClosedScreenUri()))) {
        InteractionUtil.cancelInteractionAsClient(clientComponent.character);
    }
}
Also used : ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 90 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class InteractionSystem method onActivate.

@ReceiveEvent(components = InteractionTargetComponent.class, netFilter = RegisterMode.AUTHORITY)
public void onActivate(ActivateEvent event, EntityRef target) {
    EntityRef instigator = event.getInstigator();
    CharacterComponent characterComponent = instigator.getComponent(CharacterComponent.class);
    if (characterComponent == null) {
        logger.error("Interaction start request instigator has no character component");
        return;
    }
    if (characterComponent.authorizedInteractionTarget.exists()) {
        logger.error("Interaction wasn't finished at start of next interaction");
        instigator.send(new InteractionEndEvent(characterComponent.authorizedInteractionId));
    }
    characterComponent.authorizedInteractionTarget = target;
    characterComponent.authorizedInteractionId = event.getActivationId();
    instigator.saveComponent(characterComponent);
}
Also used : CharacterComponent(org.terasology.engine.logic.characters.CharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)298 Test (org.junit.jupiter.api.Test)88 ClientComponent (org.terasology.engine.network.ClientComponent)55 Vector3f (org.joml.Vector3f)51 LocationComponent (org.terasology.engine.logic.location.LocationComponent)44 Vector3i (org.joml.Vector3i)36 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)34 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)29 StringComponent (org.terasology.unittest.stubs.StringComponent)26 NetworkComponent (org.terasology.engine.network.NetworkComponent)23 EntityData (org.terasology.protobuf.EntityData)23 Quaternionf (org.joml.Quaternionf)19 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)19 Component (org.terasology.gestalt.entitysystem.component.Component)19 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)15 Map (java.util.Map)14 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)13 BlockComponent (org.terasology.engine.world.block.BlockComponent)13 Block (org.terasology.engine.world.block.Block)11 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)10