API change: OnPlayerPlacingBlock / OnPlayerPlacedBlock
#1
I'm currently working on a change that requires a change to the signature of the OnPlayerPlacingBlock and OnPlayerPlacedBlock hooks. Up until now the hooks were only being called as a direct response for the rclk packet, providing all the values from the packet as their parameters. However, I want to alter the logic behind the hooks to be "Any block (being) placed by the player, even indirectly", which means liquids placed by buckets, both blocks of the doors etc. These indirect placements don't have all the params that the hooks require. I don't think the hooks need those parameters anyway, and if they did, the plugin would process the rclk hook instead. So I'd like to change the signatures from:
function OnPlayerPlacingBlock(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ, BlockType, BlockMeta)
function OnPlayerPlacedBlock(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ, BlockType, BlockMeta)

to:
function OnPlayerPlacingBlock(Player, BlockX, BlockY, BlockZ, BlockType, BlockMeta)
function OnPlayerPlacedBlock(Player, BlockX, BlockY, BlockZ, BlockType, BlockMeta)
(losing the cursor and blockface parameters)

I've done a quick survey of current plugins and they don't seem to use the parameters anyway:
EssentialsSpawn ( https://github.com/tonibm19/EssentialsSp.../hooks.lua ):
- only uses the OnPlayerPlacingBlock hook and only the block coords
- will continue working without a change, although the param names won't match
Core ( https://github.com/mc-server/Core/blob/m...eblock.lua ):
- only uses the OnPlayerPlacingBlock hook and only the block coords. The face is used but only to ignore non-place operations (those won't trigger the new hooks at all)
- will need to be changed with the new API
Commandy ( https://github.com/mc-server/Commandy/bl...y_main.lua )
- only uses the OnPlayerPlacingBlock hook and only the blocktype
- will need to be changed to work with the new API
HungerGames ( https://github.com/mc-server/HungerGames.../Hooks.lua )
- plugin already defunct
- only uses the OnPlayerPlacingBlock hook and only the blocktype
- will need to be changed to work with the new API
tAuthentication ( https://github.com/bearbin/tAuthenticati...r/main.lua )
- only uses the OnPlayerPlacingBlock hook and none of the params
- will continue working without a change, although the param names won't match
PrivateBlocks ( https://github.com/madmaxoft/PrivateBloc...rState.lua )
- only uses the OnPlayerPlacingBlock hook, and only the block coords
- needs no change for the new API

This change will allow me to unify the block-placing code into a single function in the cPlayer class, even export it to Lua so that plugins can use it to impersonate players while placing blocks. It will fix these issues:
- https://github.com/mc-server/MCServer/issues/1618
- https://github.com/mc-server/Gallery/issues/45
- Players can place and scoop water and lava in other players' areas despite the Gallery plugin (not reported on GitHub yet)

The API breakage is in my opinion minimal and easily fixable for existing plugins. What do you think?
Reply
Thanks given by: sphinxc0re


Messages In This Thread
API change: OnPlayerPlacingBlock / OnPlayerPlacedBlock - by xoft - 11-28-2014, 06:08 AM



Users browsing this thread: 1 Guest(s)