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 --- Server/Plugins/APIDump/APIDesc.lua | 415 +++++++++++++++++++++++++++++--- Server/Plugins/APIDump/main_APIDump.lua | 12 +- 2 files changed, 392 insertions(+), 35 deletions(-) (limited to 'Server/Plugins/APIDump') diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 888ce9aef..0e616a35c 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -10245,27 +10245,17 @@ a_Player:OpenWindow(Window); }, Notes = "Returns the full color code to be used for this player's messages (based on their rank). Prefix player messages with this code.", }, - GetDraggingItem = - { - Returns = - { - { - Type = "cItem", - }, - }, - Notes = "Returns the item the player is dragging in a UI window." - }, - GetPrefix = + GetCurrentXp = { Returns = { { - Type = "string", + Type = "number", }, }, - Notes = "Returns the prefix to player names for messages (based on their rank), may contain @ format codes.", + Notes = "Returns the current amount of XP", }, - GetSuffix = + GetCustomName = { Returns = { @@ -10273,27 +10263,17 @@ a_Player:OpenWindow(Window); Type = "string", }, }, - Notes = "Returns the suffix to player names for messages (based on their rank), may contain @ format codes.", - }, - GetCurrentXp = - { - Returns = - { - { - Type = "number", - }, - }, - Notes = "Returns the current amount of XP", + Notes = "Returns the custom name of this player. If the player hasn't a custom name, it will return an empty string.", }, - GetCustomName = + GetDraggingItem = { Returns = { { - Type = "string", + Type = "cItem", }, }, - Notes = "Returns the custom name of this player. If the player hasn't a custom name, it will return an empty string.", + Notes = "Returns the item the player is dragging in a UI window." }, GetEffectiveGameMode = { @@ -10489,6 +10469,16 @@ a_Player:OpenWindow(Window); }, Notes = "Returns the name that is used in the playerlist.", }, + GetPrefix = + { + Returns = + { + { + Type = "string", + }, + }, + Notes = "Returns the prefix to player names for messages (based on their rank), may contain @ format codes.", + }, GetRestrictions = { Returns = @@ -10519,6 +10509,26 @@ a_Player:OpenWindow(Window); }, Notes = "Returns the player's current set of skin part flags. This is a bitwise OR of various {{Globals#eSkinPart|eSkinPart}} constants. Note that HasSkinPart may be easier to use in most situations.", }, + GetStatistics = + { + Returns = + { + { + Type = "StatisticsManager", + }, + }, + Notes = "Returns the player's statistics manager." + }, + GetSuffix = + { + Returns = + { + { + Type = "string", + }, + }, + Notes = "Returns the suffix to player names for messages (based on their rank), may contain @ format codes.", + }, GetTeam = { Returns = @@ -13219,7 +13229,41 @@ end Include = { "wt.*" }, } }, -- ConstantGroups - }, -- cWindow + }, + StatisticsManager = + { + Desc = [[ + This class provides a store for various types of player statistics. The store will be read and sent to the client when the Statistics button is pressed. + ]], + Variables = + { + Custom = + { + Type = "Map of {{CustomStatistic}} to number", + Notes = "Gets or sets the value of a custom statistic.", + }, + }, + AdditionalInfo = + { + { + Header = "Example usage", + Contents = [[ + Each store is a table, keyed by the statistic that the entry tracks, with value typically representing the number of times the event happened: +
+function ModifyPlayerFurnaceInteractions(Player)
+	local Statistics = Player:GetStatistics()
+
+	if (Statistics.Custom[CustomStatistic.WalkOneCm] > 10) then
+		Statistics.Custom[CustomStatistic.InteractWithFurnace] = 1337
+	end
+
+	-- Next time the player presses Statistics they will see the updated value for furnace interactions.
+end
+
+ ]], + }, + }, + }, BannerPattern = { @@ -13700,6 +13744,319 @@ end }, } }, + CustomStatistic = + { + Desc = [[ + An enumeration of statistics of the custom type to be used with the {{StatisticsManager#Custom|Custom}} statistics store. + ]], + Constants = + { + AnimalsBred = + { + Notes = "", + }, + AviateOneCm = + { + Notes = "", + }, + BellRing = + { + Notes = "", + }, + BoatOneCm = + { + Notes = "", + }, + CleanArmor = + { + Notes = "", + }, + CleanBanner = + { + Notes = "", + }, + CleanShulkerBox = + { + Notes = "", + }, + ClimbOneCm = + { + Notes = "", + }, + CrouchOneCm = + { + Notes = "", + }, + DamageAbsorbed = + { + Notes = "", + }, + DamageBlockedByShield = + { + Notes = "", + }, + DamageDealt = + { + Notes = "", + }, + DamageDealtAbsorbed = + { + Notes = "", + }, + DamageDealtResisted = + { + Notes = "", + }, + DamageResisted = + { + Notes = "", + }, + DamageTaken = + { + Notes = "", + }, + Deaths = + { + Notes = "", + }, + Drop = + { + Notes = "", + }, + EatCakeSlice = + { + Notes = "", + }, + EnchantItem = + { + Notes = "", + }, + FallOneCm = + { + Notes = "", + }, + FillCauldron = + { + Notes = "", + }, + FishCaught = + { + Notes = "", + }, + FlyOneCm = + { + Notes = "", + }, + HorseOneCm = + { + Notes = "", + }, + InspectDispenser = + { + Notes = "", + }, + InspectDropper = + { + Notes = "", + }, + InspectHopper = + { + Notes = "", + }, + InteractWithAnvil = + { + Notes = "", + }, + InteractWithBeacon = + { + Notes = "", + }, + InteractWithBlastFurnace = + { + Notes = "", + }, + InteractWithBrewingstand = + { + Notes = "", + }, + InteractWithCampfire = + { + Notes = "", + }, + InteractWithCartographyTable = + { + Notes = "", + }, + InteractWithCraftingTable = + { + Notes = "", + }, + InteractWithFurnace = + { + Notes = "", + }, + InteractWithGrindstone = + { + Notes = "", + }, + InteractWithLectern = + { + Notes = "", + }, + InteractWithLoom = + { + Notes = "", + }, + InteractWithSmithingTable = + { + Notes = "", + }, + InteractWithSmoker = + { + Notes = "", + }, + InteractWithStonecutter = + { + Notes = "", + }, + JunkFished = + { + Notes = "", + }, + Jump = + { + Notes = "", + }, + LeaveGame = + { + Notes = "", + }, + MinecartOneCm = + { + Notes = "", + }, + MobKills = + { + Notes = "", + }, + OpenBarrel = + { + Notes = "", + }, + OpenChest = + { + Notes = "", + }, + OpenEnderchest = + { + Notes = "", + }, + OpenShulkerBox = + { + Notes = "", + }, + PigOneCm = + { + Notes = "", + }, + PlayNoteblock = + { + Notes = "", + }, + PlayOneMinute = + { + Notes = "", + }, + PlayRecord = + { + Notes = "", + }, + PlayerKills = + { + Notes = "", + }, + PotFlower = + { + Notes = "", + }, + RaidTrigger = + { + Notes = "", + }, + RaidWin = + { + Notes = "", + }, + SleepInBed = + { + Notes = "", + }, + SneakTime = + { + Notes = "", + }, + SprintOneCm = + { + Notes = "", + }, + StriderOneCm = + { + Notes = "", + }, + SwimOneCm = + { + Notes = "", + }, + TalkedToVillager = + { + Notes = "", + }, + TargetHit = + { + Notes = "", + }, + TimeSinceDeath = + { + Notes = "", + }, + TimeSinceRest = + { + Notes = "", + }, + TradedWithVillager = + { + Notes = "", + }, + TreasureFished = + { + Notes = "", + }, + TriggerTrappedChest = + { + Notes = "", + }, + TuneNoteblock = + { + Notes = "", + }, + UseCauldron = + { + Notes = "", + }, + WalkOnWaterOneCm = + { + Notes = "", + }, + WalkOneCm = + { + Notes = "", + }, + WalkUnderWaterOneCm = + { + Notes = "", + }, + }, + }, Globals = { Desc = [[ diff --git a/Server/Plugins/APIDump/main_APIDump.lua b/Server/Plugins/APIDump/main_APIDump.lua index f92abb932..61dd1e66c 100644 --- a/Server/Plugins/APIDump/main_APIDump.lua +++ b/Server/Plugins/APIDump/main_APIDump.lua @@ -52,7 +52,6 @@ end - --- Returns the API currently detected from the global environment local function CreateAPITables() --[[ @@ -121,14 +120,15 @@ local function CreateAPITables() end -- Member variables: + local GetField = a_ClassObj[".get"]; local SetField = a_ClassObj[".set"] or {}; - if ((a_ClassObj[".get"] ~= nil) and (type(a_ClassObj[".get"]) == "table")) then - for k in pairs(a_ClassObj[".get"]) do - if (SetField[k] == nil) then - -- It is a read-only variable, add it as a constant: + if ((GetField ~= nil) and (type(GetField) == "table")) then + for k, v in pairs(GetField) do + if ((SetField[k] == nil) and ((type(v) ~= "table") or (v["__newindex"] == nil))) then + -- It is a read-only variable or array, add it as a constant: table.insert(res.Constants, {Name = k, Value = ""}); else - -- It is a read-write variable, add it as a variable: + -- It is a read-write variable or array, add it as a variable: table.insert(res.Variables, { Name = k }); end end -- cgit v1.2.3