use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class InteractionUtil method getActiveInteractionScreenUri.
/**
* @return the active interaction screen uri of the specified character.
* The method returns null if the player has no interaction screen open.
* The method is only intended to be called for the own character.
*/
public static ResourceUrn getActiveInteractionScreenUri(EntityRef character) {
CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
if (characterComponent == null) {
return null;
}
EntityRef interactionTarget = characterComponent.predictedInteractionTarget;
if (!interactionTarget.exists()) {
return null;
}
InteractionScreenComponent screenComponent = interactionTarget.getComponent(InteractionScreenComponent.class);
if (screenComponent == null) {
return null;
}
return new ResourceUrn(screenComponent.screen);
}
use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class ChatSystem method whisper.
@Command(runOnServer = true, requiredPermission = PermissionManager.CHAT_PERMISSION, shortDescription = "Sends a private message to a specified user")
public String whisper(@Sender EntityRef sender, @CommandParam(value = "user", suggester = OnlineUsernameSuggester.class) String username, @CommandParam("message") String[] message) {
String messageToString = join(message, " ");
Iterable<EntityRef> clients = entityManager.getEntitiesWith(ClientComponent.class);
EntityRef targetClient = null;
boolean unique = true;
for (EntityRef client : clients) {
ClientComponent clientComponent = client.getComponent(ClientComponent.class);
DisplayNameComponent displayNameComponent = clientComponent.clientInfo.getComponent(DisplayNameComponent.class);
if (displayNameComponent == null) {
continue;
}
if (displayNameComponent.name.equalsIgnoreCase(username)) {
if (targetClient == null) {
targetClient = client;
} else {
unique = false;
break;
}
}
}
if (!unique) {
targetClient = null;
for (EntityRef client : clients) {
ClientComponent clientComponent = client.getComponent(ClientComponent.class);
DisplayNameComponent displayNameComponent = clientComponent.clientInfo.getComponent(DisplayNameComponent.class);
if (displayNameComponent == null) {
continue;
}
if (displayNameComponent.name.equals(username)) {
if (targetClient == null) {
targetClient = client;
} else {
return FontColor.getColored("Found more users with name '" + username + "'.", ConsoleColors.ERROR);
}
}
}
}
if (targetClient == null) {
return FontColor.getColored("User with name '" + username + "' not found.", ConsoleColors.ERROR);
}
ClientComponent senderClientComponent = sender.getComponent(ClientComponent.class);
ClientComponent targetClientComponent = targetClient.getComponent(ClientComponent.class);
DisplayNameComponent targetDisplayNameComponent = targetClientComponent.clientInfo.getComponent(DisplayNameComponent.class);
String targetMessage = FontColor.getColored("*whispering* ", ConsoleColors.ERROR) + FontColor.getColored(messageToString, ConsoleColors.CHAT);
String senderMessage = "You -> " + targetDisplayNameComponent.name + ": " + FontColor.getColored(messageToString, ConsoleColors.CHAT);
targetClient.send(new ChatMessageEvent(targetMessage, senderClientComponent.clientInfo));
return senderMessage;
}
use of org.terasology.entitySystem.entity.EntityRef 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();
Vector3f offset = characterLocation.getWorldDirection();
offset.scale(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.";
}
use of org.terasology.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.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class AbstractClient method createClientInfoEntity.
private EntityRef createClientInfoEntity(EntityManager entityManager) {
EntityRef clientInfo;
clientInfo = entityManager.create("engine:clientInfo");
// mark clientInfo entities with a dedicated component
ClientInfoComponent cic = new ClientInfoComponent();
cic.playerId = getId();
clientInfo.addComponent(cic);
return clientInfo;
}
Aggregations