From 8be1dd54bb17b3ba3e20960aa3c3f696d09facf7 Mon Sep 17 00:00:00 2001 From: nshah25 <68348722+nshah25@users.noreply.github.com> Date: Mon, 3 May 2021 16:07:09 -0400 Subject: Add player statistics to API (#5193) * Fixed issue #5166 Co-authored-by: 12xx12 <44411062+12xx12@users.noreply.github.com> Co-authored-by: Tiger Wang --- src/BlockEntities/BeaconEntity.cpp | 4 ++-- src/BlockEntities/BrewingstandEntity.cpp | 2 +- src/BlockEntities/ChestEntity.cpp | 4 ++-- src/BlockEntities/DropSpenserEntity.cpp | 4 ++-- src/BlockEntities/EnderChestEntity.cpp | 2 +- src/BlockEntities/FlowerPotEntity.cpp | 2 +- src/BlockEntities/FurnaceEntity.cpp | 2 +- src/BlockEntities/HopperEntity.cpp | 2 +- src/BlockEntities/JukeboxEntity.cpp | 3 ++- src/BlockEntities/NoteEntity.cpp | 2 +- 10 files changed, 14 insertions(+), 13 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index 6a7916dd1..87d25e57a 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -206,7 +206,7 @@ void cBeaconEntity::UpdateBeacon(void) (std::abs(Distance.z) <= 20) ) { - a_Player.AwardAchievement(Statistic::AchFullBeacon); + a_Player.AwardAchievement(CustomStatistic::AchFullBeacon); } return false; } @@ -313,7 +313,7 @@ bool cBeaconEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) bool cBeaconEntity::UsedBy(cPlayer * a_Player) { - a_Player->GetStatManager().AddValue(Statistic::InteractWithBeacon); + a_Player->GetStatistics().Custom[CustomStatistic::InteractWithBeacon]++; cWindow * Window = GetWindow(); if (Window == nullptr) diff --git a/src/BlockEntities/BrewingstandEntity.cpp b/src/BlockEntities/BrewingstandEntity.cpp index bdac1b327..ff7b49821 100644 --- a/src/BlockEntities/BrewingstandEntity.cpp +++ b/src/BlockEntities/BrewingstandEntity.cpp @@ -145,7 +145,7 @@ bool cBrewingstandEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) bool cBrewingstandEntity::UsedBy(cPlayer * a_Player) { - a_Player->GetStatManager().AddValue(Statistic::InteractWithBrewingstand); + a_Player->GetStatistics().Custom[CustomStatistic::InteractWithBrewingstand]++; cWindow * Window = GetWindow(); if (Window == nullptr) diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp index c2c31b30a..11146bf46 100644 --- a/src/BlockEntities/ChestEntity.cpp +++ b/src/BlockEntities/ChestEntity.cpp @@ -204,11 +204,11 @@ bool cChestEntity::UsedBy(cPlayer * a_Player) if (m_BlockType == E_BLOCK_CHEST) { - a_Player->GetStatManager().AddValue(Statistic::OpenChest); + a_Player->GetStatistics().Custom[CustomStatistic::OpenChest]++; } else // E_BLOCK_TRAPPED_CHEST { - a_Player->GetStatManager().AddValue(Statistic::TriggerTrappedChest); + a_Player->GetStatistics().Custom[CustomStatistic::TriggerTrappedChest]++; } auto & PrimaryChest = GetPrimaryChest(); diff --git a/src/BlockEntities/DropSpenserEntity.cpp b/src/BlockEntities/DropSpenserEntity.cpp index 814b0c147..b067e1081 100644 --- a/src/BlockEntities/DropSpenserEntity.cpp +++ b/src/BlockEntities/DropSpenserEntity.cpp @@ -163,11 +163,11 @@ bool cDropSpenserEntity::UsedBy(cPlayer * a_Player) { if (m_BlockType == E_BLOCK_DISPENSER) { - a_Player->GetStatManager().AddValue(Statistic::InspectDispenser); + a_Player->GetStatistics().Custom[CustomStatistic::InspectDispenser]++; } else // E_BLOCK_DROPPER { - a_Player->GetStatManager().AddValue(Statistic::InspectDropper); + a_Player->GetStatistics().Custom[CustomStatistic::InspectDropper]++; } cWindow * Window = GetWindow(); diff --git a/src/BlockEntities/EnderChestEntity.cpp b/src/BlockEntities/EnderChestEntity.cpp index efc5dce4f..ba9ca5609 100644 --- a/src/BlockEntities/EnderChestEntity.cpp +++ b/src/BlockEntities/EnderChestEntity.cpp @@ -62,7 +62,7 @@ bool cEnderChestEntity::UsedBy(cPlayer * a_Player) return false; } - a_Player->GetStatManager().AddValue(Statistic::OpenEnderchest); + a_Player->GetStatistics().Custom[CustomStatistic::OpenEnderchest]++; // If the window is not created, open it anew: cWindow * Window = GetWindow(); diff --git a/src/BlockEntities/FlowerPotEntity.cpp b/src/BlockEntities/FlowerPotEntity.cpp index bc936c246..df14acc8e 100644 --- a/src/BlockEntities/FlowerPotEntity.cpp +++ b/src/BlockEntities/FlowerPotEntity.cpp @@ -50,7 +50,7 @@ bool cFlowerPotEntity::UsedBy(cPlayer * a_Player) return false; } - a_Player->GetStatManager().AddValue(Statistic::PotFlower); + a_Player->GetStatistics().Custom[CustomStatistic::PotFlower]++; cItem SelectedItem = a_Player->GetInventory().GetEquippedItem(); if (IsFlower(SelectedItem.m_ItemType, SelectedItem.m_ItemDamage)) diff --git a/src/BlockEntities/FurnaceEntity.cpp b/src/BlockEntities/FurnaceEntity.cpp index d36b19791..8ca539170 100644 --- a/src/BlockEntities/FurnaceEntity.cpp +++ b/src/BlockEntities/FurnaceEntity.cpp @@ -127,7 +127,7 @@ bool cFurnaceEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) bool cFurnaceEntity::UsedBy(cPlayer * a_Player) { - a_Player->GetStatManager().AddValue(Statistic::InteractWithFurnace); + a_Player->GetStatistics().Custom[CustomStatistic::InteractWithFurnace]++; cWindow * Window = GetWindow(); if (Window == nullptr) diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 82e07f6a0..1e5c59c94 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -113,7 +113,7 @@ void cHopperEntity::SendTo(cClientHandle & a_Client) bool cHopperEntity::UsedBy(cPlayer * a_Player) { - a_Player->GetStatManager().AddValue(Statistic::InspectHopper); + a_Player->GetStatistics().Custom[CustomStatistic::InspectHopper]++; // If the window is not created, open it anew: cWindow * Window = GetWindow(); diff --git a/src/BlockEntities/JukeboxEntity.cpp b/src/BlockEntities/JukeboxEntity.cpp index b99d9d39c..065f9cb46 100644 --- a/src/BlockEntities/JukeboxEntity.cpp +++ b/src/BlockEntities/JukeboxEntity.cpp @@ -65,7 +65,8 @@ bool cJukeboxEntity::UsedBy(cPlayer * a_Player) const cItem & HeldItem = a_Player->GetEquippedItem(); if (PlayRecord(HeldItem.m_ItemType)) { - a_Player->GetStatManager().AddValue(Statistic::PlayRecord); + a_Player->GetStatistics().Custom[CustomStatistic::PlayRecord]++; + if (!a_Player->IsGameModeCreative()) { a_Player->GetInventory().RemoveOneEquippedItem(); diff --git a/src/BlockEntities/NoteEntity.cpp b/src/BlockEntities/NoteEntity.cpp index 419d084b2..b4696f7b1 100644 --- a/src/BlockEntities/NoteEntity.cpp +++ b/src/BlockEntities/NoteEntity.cpp @@ -34,7 +34,7 @@ void cNoteEntity::CopyFrom(const cBlockEntity & a_Src) bool cNoteEntity::UsedBy(cPlayer * a_Player) { - a_Player->GetStatManager().AddValue(Statistic::TuneNoteblock); + a_Player->GetStatistics().Custom[CustomStatistic::TuneNoteblock]++; IncrementNote(); MakeSound(); return true; -- cgit v1.2.3