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;
}
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";
}
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 + "'");
}
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);
}
}
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);
}
Aggregations