Skip to content

Commit

Permalink
Merge pull request #157 from cuberite/PlayerSelectionChangedHook
Browse files Browse the repository at this point in the history
Implemented OnPlayerSelectionChanged callback
  • Loading branch information
NiLSPACE authored Aug 4, 2024
2 parents 72ab743 + 6fb98c1 commit dd99ca6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Api/Manage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}


Expand Down
9 changes: 8 additions & 1 deletion Classes/PlayerSelection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dd99ca6

Please sign in to comment.