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);
}
}
Aggregations