From 1feb0fb855e7bc69660a2fb3f3f0a2cb8aa35fe7 Mon Sep 17 00:00:00 2001 From: Niels Date: Thu, 13 Jun 2024 15:49:11 +0200 Subject: [PATCH 1/2] Implemented OnPlayerSelectionChanged callback --- Api/Manage.lua | 6 ++++-- Classes/PlayerSelection.lua | 9 ++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Api/Manage.lua b/Api/Manage.lua index ccdc401..305286c 100644 --- a/Api/Manage.lua +++ b/Api/Manage.lua @@ -12,8 +12,10 @@ g_Hooks = { ["OnAreaChanged"] = {}, -- Signature: function(a_AffectedAreaCuboid, a_Player, a_World, a_Operation) ["OnAreaCopied"] = {}, -- Signature: function(a_Player, a_World, a_CopiedAreaCuboid) ["OnAreaCopying"] = {}, -- Signature: function(a_Player, a_World, a_CopiedAreaCuboid) - ["OnPlayerSelectionChanging"] = {}, -- Signature: function(a_Player, a_PosX, a_PosY, a_PosZ, a_PointNr) - ["OnPlayerSelectionChanged"] = {}, -- Signature: function(a_Player, a_PosX, a_PosY, a_PosZ, a_PointNr) + ["OnPlayerSelectionChanged"] = {}, -- Signature: function(a_Player, a_Cuboid, a_PointNr) a_PointNr is nil if the entire selection changed. + + -- Not implemented + ["OnPlayerSelectionChanging"] = {}, -- Signature: function(a_Player, a_Cuboid, a_PointNr) a_PointNr is nil if the entire selection changed. } diff --git a/Classes/PlayerSelection.lua b/Classes/PlayerSelection.lua index 4e269e4..03f5d3c 100644 --- a/Classes/PlayerSelection.lua +++ b/Classes/PlayerSelection.lua @@ -334,7 +334,14 @@ end -- a_PointChanged is optional, assigned to the point that has just changed -- If nil, the entire selection is assumed changed function cPlayerSelection:NotifySelectionChanged(a_PointChanged) - -- TODO: Call the registered callbacks + -- TODO: Call the OnPlayerSelectionChangING callback to prevent selection changes. + + -- Call the player selection changed callback to notify other plugins of the selection change. + self.PlayerState:DoWithPlayer(function(a_Player) + local cuboid = cCuboid() + cuboid:Assign(self.Cuboid) + CallHook("OnPlayerSelectionChanged", a_Player, cuboid, a_PointChanged) + end); -- Set the player's WECUI, if present: if (self.PlayerState.IsWECUIActivated) then From 6fb98c108441a43dc1209c9996e9dfc02c0cb917 Mon Sep 17 00:00:00 2001 From: Niels Date: Thu, 13 Jun 2024 15:51:31 +0200 Subject: [PATCH 2/2] Fixed style --- Classes/PlayerSelection.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/PlayerSelection.lua b/Classes/PlayerSelection.lua index 03f5d3c..97d9100 100644 --- a/Classes/PlayerSelection.lua +++ b/Classes/PlayerSelection.lua @@ -334,8 +334,8 @@ end -- a_PointChanged is optional, assigned to the point that has just changed -- If nil, the entire selection is assumed changed function cPlayerSelection:NotifySelectionChanged(a_PointChanged) - -- TODO: Call the OnPlayerSelectionChangING callback to prevent selection changes. - + -- TODO: Call the OnPlayerSelectionChangING callback to prevent selection changes. + -- Call the player selection changed callback to notify other plugins of the selection change. self.PlayerState:DoWithPlayer(function(a_Player) local cuboid = cCuboid()