use of org.terasology.engine.logic.common.DisplayNameComponent 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.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 + "'");
}
use of org.terasology.engine.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class MovementDebugCommands method teleportAllPlayersToPlayer.
@Command(shortDescription = "Teleport all users to specified user", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String teleportAllPlayersToPlayer(@CommandParam("username") String username) {
Vector3f vPlayerLocation = new Vector3f();
boolean bPlayerLocationWasFound = false;
EntityRef playerEntity = null;
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)) {
LocationComponent locationComponent = clientEntity.getComponent(LocationComponent.class);
if (locationComponent != null) {
vPlayerLocation = locationComponent.getWorldPosition(new Vector3f());
bPlayerLocationWasFound = true;
playerEntity = clientEntity;
}
break;
}
}
if (!bPlayerLocationWasFound) {
throw new IllegalArgumentException("No such user '" + username + "'");
}
MovementMode playerMovementMode = MovementMode.NONE;
ClientComponent clientInfo = playerEntity.getComponent(ClientComponent.class);
if (clientInfo != null) {
CharacterMovementComponent playerMovementComponent = clientInfo.character.getComponent(CharacterMovementComponent.class);
if (playerMovementComponent != null) {
playerMovementMode = playerMovementComponent.mode;
}
}
for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
if (clientComp != null) {
clientComp.character.send(new CharacterTeleportEvent(vPlayerLocation));
CharacterMovementComponent characterMovementComponent = clientComp.character.getComponent(CharacterMovementComponent.class);
if (characterMovementComponent != null && playerMovementMode != MovementMode.NONE && playerMovementMode != characterMovementComponent.mode) {
clientComp.character.send(new SetMovementModeEvent(playerMovementMode));
}
}
}
return "All possible players teleported to " + username + " and set to " + playerMovementMode;
}
use of org.terasology.engine.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class MovementDebugCommands method teleportMeToPlayer.
@Command(shortDescription = "Teleport to player", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String teleportMeToPlayer(@Sender EntityRef sender, @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)) {
LocationComponent locationComponent = clientEntity.getComponent(LocationComponent.class);
if (locationComponent != null) {
Vector3f vLocation = locationComponent.getWorldPosition(new Vector3f());
ClientComponent clientComp = sender.getComponent(ClientComponent.class);
if (clientComp != null) {
clientComp.character.send(new CharacterTeleportEvent(vLocation));
return "Teleporting you to " + username + " at " + vLocation.x + " " + vLocation.y + " " + vLocation.z;
}
}
}
}
throw new IllegalArgumentException("No such user '" + username + "'");
}
use of org.terasology.engine.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class PlayerUtil method getColoredPlayerName.
public static String getColoredPlayerName(EntityRef from) {
DisplayNameComponent displayInfo = from.getComponent(DisplayNameComponent.class);
ColorComponent colorInfo = from.getComponent(ColorComponent.class);
String playerName = (displayInfo != null) ? displayInfo.name : "Unknown";
if (colorInfo != null) {
playerName = FontColor.getColored(playerName, colorInfo.color);
}
return playerName;
}
Aggregations