Search in sources :

Example 6 with GamePlayStatsComponent

use of org.terasology.engine.telemetry.GamePlayStatsComponent in project Terasology by MovingBlocks.

the class BlockItemSystem method recordBlockPlaced.

private void recordBlockPlaced(ActivateEvent event, BlockFamily block) {
    EntityRef instigator = event.getInstigator();
    String blockName = block.getDisplayName();
    if (instigator.hasComponent(GamePlayStatsComponent.class)) {
        GamePlayStatsComponent gamePlayStatsComponent = instigator.getComponent(GamePlayStatsComponent.class);
        Map<String, Integer> blockPlacedMap = gamePlayStatsComponent.blockPlacedMap;
        if (blockPlacedMap.containsKey(blockName)) {
            blockPlacedMap.put(blockName, blockPlacedMap.get(blockName) + 1);
        } else {
            blockPlacedMap.put(blockName, 1);
        }
        instigator.saveComponent(gamePlayStatsComponent);
    } else {
        GamePlayStatsComponent gamePlayStatsComponent = new GamePlayStatsComponent();
        Map<String, Integer> blockPlacedMap = gamePlayStatsComponent.blockPlacedMap;
        blockPlacedMap.put(blockName, 1);
        instigator.addOrSaveComponent(gamePlayStatsComponent);
    }
}
Also used : GamePlayStatsComponent(org.terasology.engine.telemetry.GamePlayStatsComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Aggregations

EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)6 GamePlayStatsComponent (org.terasology.engine.telemetry.GamePlayStatsComponent)6 LocalPlayer (org.terasology.engine.logic.players.LocalPlayer)4 Map (java.util.Map)1 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)1 BlockComponent (org.terasology.engine.world.block.BlockComponent)1