use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.
the class PlayerNameTagSystem method onCharacterActivation.
/**
* Listening for {@link org.terasology.logic.players.event.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) {
logger.warn("Can't create player based name tag for character as owner has no client component");
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.error("Can't create player based name tag for character as client info has no DisplayNameComponent");
return;
}
String name = displayNameComponent.name;
float yOffset = characterComponent.nameTagOffset;
Color color = Color.WHITE;
ColorComponent colorComponent = clientInfoEntity.getComponent(ColorComponent.class);
if (colorComponent != null) {
color = colorComponent.color;
}
NameTagComponent nameTagComponent = characterEntity.getComponent(NameTagComponent.class);
boolean newComponent = nameTagComponent == null;
if (nameTagComponent == null) {
nameTagComponent = new NameTagComponent();
}
nameTagComponent.text = name;
nameTagComponent.textColor = color;
nameTagComponent.yOffset = yOffset;
if (newComponent) {
characterEntity.addComponent(nameTagComponent);
} else {
characterEntity.saveComponent(nameTagComponent);
}
}
use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.
the class PlayerNameTagSystem method onDisplayNameChange.
@ReceiveEvent
public void onDisplayNameChange(OnChangedComponent event, EntityRef clientInfoEntity, DisplayNameComponent displayNameComponent) {
ClientInfoComponent clientInfoComp = clientInfoEntity.getComponent(ClientInfoComponent.class);
if (clientInfoComp == null) {
// not a client info object
return;
}
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) {
logger.warn("Can't update name tag as client entity lacks ClietnComponent");
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);
}
use of org.terasology.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;
}
}
use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.
the class PermissionCommands method usePermissionKey.
@Command(shortDescription = "Use an one time key to get all permissions", helpText = "The config file contains a one time key which can be used to get all permissions.", runOnServer = true, requiredPermission = PermissionManager.NO_PERMISSION)
public String usePermissionKey(@CommandParam("key") String key, @Sender EntityRef client) {
PermissionConfig permissionConfig = config.getPermission();
String expectedKey = permissionConfig.getOneTimeAuthorizationKey();
if (expectedKey != null && !expectedKey.equals("") && key.equals(expectedKey)) {
permissionConfig.setOneTimeAuthorizationKey("");
ClientComponent clientComponent = client.getComponent(ClientComponent.class);
EntityRef clientInfo = clientComponent.clientInfo;
for (String permission : findAllPermissions()) {
permissionManager.addPermission(clientInfo, permission);
}
PermissionSetComponent permissionSetComp = clientInfo.getComponent(PermissionSetComponent.class);
return "Permission key used: You have now the following permissions: " + permissionSetComp.permissions;
} else {
return "Key invalid or used";
}
}
use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.
the class CameraClientSystem method mountCamera.
private void mountCamera() {
ClientComponent clientComponent = localPlayer.getClientEntity().getComponent(ClientComponent.class);
EntityRef targetEntityForCamera = GazeAuthoritySystem.getGazeEntityForCharacter(clientComponent.character);
LocationComponent cameraLocation = clientComponent.camera.getComponent(LocationComponent.class);
// if the camera already has a location, use that as the relative position of the camera
if (cameraLocation != null) {
Location.attachChild(targetEntityForCamera, clientComponent.camera, cameraLocation.getLocalPosition(), new Quat4f(Quat4f.IDENTITY));
} else {
Location.attachChild(targetEntityForCamera, clientComponent.camera, Vector3f.zero(), new Quat4f(Quat4f.IDENTITY));
}
}
Aggregations