use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class CoreCommands method bulkDrop.
@Command(shortDescription = "Mass-drops the desired block however many times the player indicates", helpText = "First parameter indicates which block to drop, second parameter how many", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String bulkDrop(@Sender EntityRef sender, @CommandParam("blockName") String blockName, @CommandParam("value") int value) {
// This is a loop which gives the particular amount of block the player wants to spawn
ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
Vector3f spawnPos = characterLocation.getWorldPosition(new Vector3f());
Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
offset.mul(3);
spawnPos.add(5, 10, 0);
BlockFamily block = blockManager.getBlockFamily(blockName);
if (block == null) {
return "Sorry, your block is not found";
}
BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
if (value > 5000) {
return "Value exceeds the maximum limit of 5000 blocks. your value: " + value + " blocks";
}
for (int i = 0; i < value; i++) {
EntityRef blockItem = blockItemFactory.newInstance(block);
blockItem.send(new DropItemEvent(spawnPos));
}
// this returns the block you have spawned and the amount
return "Dropped " + value + " " + blockName + " Blocks :)";
}
use of org.terasology.engine.network.ClientComponent 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(new Vector3f());
Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
offset.mul(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.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class PlayerNameTagSystem method onDisplayNameChange.
@ReceiveEvent
public void onDisplayNameChange(OnChangedComponent event, EntityRef clientInfoEntity, DisplayNameComponent displayNameComponent, ClientInfoComponent clientInfoComp) {
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) {
// the character is not owned by a client (no other player)
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.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class PlayerNameTagSystem method onCharacterActivation.
/**
* Listening for {@link 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) {
// the character is not owned by a client (no other player)
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.debug("Cannot create name tag for client without DisplayNameComponent");
return;
}
String name = displayNameComponent.name;
float yOffset = characterComponent.nameTagOffset;
ColorComponent colorComponent = clientInfoEntity.getComponent(ColorComponent.class);
final Color color = colorComponent != null ? colorComponent.color : Color.WHITE;
characterEntity.upsertComponent(NameTagComponent.class, maybeNameTag -> {
NameTagComponent nameTagComponent = maybeNameTag.orElse(new NameTagComponent());
nameTagComponent.text = name;
nameTagComponent.textColor = color;
nameTagComponent.yOffset = yOffset;
return nameTagComponent;
});
}
use of org.terasology.engine.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;
}
}
Aggregations