Cuberite Forum
API change in hook-adding - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: API change in hook-adding (/thread-1227.html)

Pages: 1 2 3


RE: API change in hook-adding - bearbin - 08-22-2013

Sounds good. Core is all done Smile


RE: API change in hook-adding - xoft - 08-22-2013

I don't like polluting the global namespace so much. The hooks are used so rarely that it's not worth the few saved keystrokes.

What is more intriguing is (yet another) function signature:
cPluginManager.AddHook(HOOK_TYPE);  -- CallbackFunction is assumed to be named the same as in the old API
I'm still not sure, it'd make coding easier, but it's not good for maintenance, the line doesn't say anything about the function that will be called, it'd be confusing to the beginners.


RE: API change in hook-adding - NiLSPACE - 08-22-2013

For some reason I can't add hooks. I get these errors:
Code:
[12:29:30] Plugin WorldEdit wants to add a hook (19), but it doesn't provide the callback function "OnPlayerBreakingBlock" for it. The plugin need not work properly.
[12:29:30] Stack trace:
[12:29:30]   [C](-1): AddHook
[12:29:30]   Plugins/WorldEdit/main.lua(13): ?
[12:29:30] Stack trace end
[12:29:30] Plugin WorldEdit wants to add a hook (27), but it doesn't provide the callback function "OnPlayerRightClick" for it. The plugin need not work properly.
[12:29:30] Stack trace:
[12:29:30]   [C](-1): AddHook
[12:29:30]   Plugins/WorldEdit/main.lua(14): ?
[12:29:30] Stack trace end
[12:29:30] Plugin WorldEdit wants to add a hook (27), but it doesn't provide the callback function "OnPlayerRightClick" for it. The plugin need not work properly.
[12:29:30] Stack trace:
[12:29:30]   [C](-1): AddHook
[12:29:30]   Plugins/WorldEdit/main.lua(16): ?
[12:29:30] Stack trace end
[12:29:30] Plugin WorldEdit wants to add a hook (27), but it doesn't provide the callback function "OnPlayerRightClick" for it. The plugin need not work properly.
[12:29:30] Stack trace:
[12:29:30]   [C](-1): AddHook
[12:29:30]   Plugins/WorldEdit/main.lua(17): ?
[12:29:30] Stack trace end
[12:29:30] Plugin WorldEdit wants to add a hook (23), but it doesn't provide the callback function "OnPlayerLeftClick" for it. The plugin need not work properly.
[12:29:30] Stack trace:
[12:29:30]   [C](-1): AddHook
[12:29:30]   Plugins/WorldEdit/main.lua(19): ?
[12:29:30] Stack trace end
[12:29:30] Plugin WorldEdit wants to add a hook (23), but it doesn't provide the callback function "OnPlayerLeftClick" for it. The plugin need not work properly.
[12:29:30] Stack trace:
[12:29:30]   [C](-1): AddHook
[12:29:30]   Plugins/WorldEdit/main.lua(20): ?
[12:29:30] Stack trace end
with this code:
	
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_BREAKING_BLOCK, SelectFirstPointHook); -- Add hook that gets called when selecting the first point.
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK,    SelectSecondPointHook);
	
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK,    RightClickCompassHook);
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK,    ToolsHook);
	
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK,     LeftClickCompassHook); -- Add hook OnPlayerLeftClick
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK,     SuperPickaxeHook);
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_JOINED,         OnPlayerJoined); -- Add hook OnPlayerJoined
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_ANIMATION,      OnPlayerAnimation); -- Add hook OnPlayerAnimation for left click compass
But it is fixed when I add
function OnPlayerBreakingBlock()
end
function OnPlayerRightClick()
end
function OnPlayerLeftClick()
end



RE: API change in hook-adding - xoft - 08-22-2013

And those functions, SelectFirstPointHook etc, are they defined?


RE: API change in hook-adding - NiLSPACE - 08-22-2013

Yes. They are in a different .lua file but they exist.


RE: API change in hook-adding - bearbin - 08-22-2013

Hmm, strange. Since the initialize function is called after everything has been loaded, the functions should be available as globals. They're not local, are they?


RE: API change in hook-adding - NiLSPACE - 08-22-2013

The weird thing is that the server still searches for a function with the same name as before the API change
(HOOK_PLAYER_BREAKING_BLOCK and OnPlayerBreakingBlock)
but when the server calls the hook it calls the function I said it should use
(HOOK_PLAYER_BREAKING_BLOCK and SelectFirstPointHook)


RE: API change in hook-adding - xoft - 08-22-2013

Oh, that might be the cause, the leftover code for hook function existence is based on the old API. I'll fix this later in the evening when I get home. I thought the old-named functions were called instead.


RE: API change in hook-adding - xoft - 08-23-2013

Or not. I tried calling AddHook(cPluginManager.HOOK_CHAT, HookChat) with a HookChat function defined, and everything worked fine.
Could you send your plugin to me?

I think I've fixed it. Try it now.


RE: API change in hook-adding - tonibm19 - 10-20-2013

You broke all plugins with that. Some of my plugins are not working, SignLock is not working, MCServer says it fix the call but plugins dont work.