Closed walksanatora closed 3 years ago
Moved __init__
out of the folder and renamed to the former folders name
Ok that broke __path__
in the event handler (classes.plugin.event)
fixed the __path__
problem replaced with os.path.dirname(os.path.realpath(__file__))
and re-squashed it
Let's see what @Geolykt thinks
Don't use
__init__.py
for your code
i tried moving plugins.event and plugins.api into the plugins file but the implementation i tried didn't work
(i made a class and copied/pasted the code into the class in plugins)
plugins.api worked fine because it only imports and has no dependencies from inside the same file, as in plugins.event since i have _ functions in there that are for internal use to avoid copying code it wouldn't work, i even tried event._save_()
as a example but it wouldn't find it within the events
class, i tried making it a __init__
for the class but that wouldn't be a refactor as you would have to call plugins.event() in order to use it but that happens nowhere in the rest of the project
im going to push with my __init__.py
fix fyi
ok
wait wth
So apparently we reverted each others commits. I've sent you the files via Discord, to avoid further confusion.
everything should be fixed now
fixed the formatting things now it should be ready for merge
I want to do some more extensive testing, which will probably happen on Wednesday. I know that @Geolykt will probably also want to test plugin development.
Not working as intended for me (no plugins - default install):
[2021-07-05 16:10:43,275 - INFO - NETWORK_THREAD] <emeric987> a
Unhandled Error
Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/twisted/python/log.py", line 101, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/usr/lib/python3.9/site-packages/twisted/python/log.py", line 85, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/usr/lib/python3.9/site-packages/twisted/python/context.py", line 118, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/lib/python3.9/site-packages/twisted/python/context.py", line 83, in callWithContext
return func(*args, **kw)
--- <exception caught here> ---
File "/usr/lib/python3.9/site-packages/twisted/internet/posixbase.py", line 687, in _doReadOrWrite
why = selectable.doRead()
File "/usr/lib/python3.9/site-packages/twisted/internet/tcp.py", line 246, in doRead
return self._dataReceived(data)
File "/usr/lib/python3.9/site-packages/twisted/internet/tcp.py", line 251, in _dataReceived
rval = self.protocol.dataReceived(data)
File "/home/Geolykt/.local/lib/python3.9/site-packages/quarry/net/protocol.py", line 86, in dataReceived
return self.data_received(data)
File "/home/Geolykt/.local/lib/python3.9/site-packages/quarry/net/protocol.py", line 247, in data_received
self.packet_received(buff, name)
File "/home/Geolykt/.local/lib/python3.9/site-packages/quarry/net/protocol.py", line 269, in packet_received
dispatched = self.dispatch((name,), buff)
File "/home/Geolykt/.local/lib/python3.9/site-packages/quarry/net/protocol.py", line 28, in dispatch
handler(buff)
File "/home/Geolykt/git/McPy/classes/network/Connection.py", line 97, in packet_chat_message
out = event.fire("chat",self.display_name,p_text)
File "/home/Geolykt/git/McPy/classes/plugins/event.py", line 50, in fire
for func in _events_[event]:
builtins.KeyError: 'chat'
[2021-07-05 16:10:43,332 - INFO - NETWORK_THREAD] emeric987 has left.
It's odd that it seemed to work for me, and not for you. It must be a discrepancy in WSL or something along those lines. I will double check whenever I get back to my main computer, as well as test for macOS and Windows support.
I mean it is quite clear that the affected line (https://github.com/mcpyproject/McPy/pull/75/files#diff-0b65522506fa3e05cb5fa70bf642c6f0216e1f2fab3ae8790950b60429dc4412R50) can only be wrong - though it is beyond me to why it is the case by default
i am confused as to how the chat
event could be missing
because when the classes.network.connection
is imported it is loaded here
in which it was commented
the positioning looks rather arbitrary for me i will retry in a moment when i reboot into windows and check if the error persist
I know - yet it somehow is missing. Perhaps the load order matters?
But wouldn't the code from the top if the file be loaded/ran first then when the function is called the code from above should all ready have setup the chat event
probably
ok after a quick test
using python 3.8 in linux and python 3.9 in windows (python 3.9 is broken for me currently: specifically psutil
since it was installed via apt) I have determined the problem to be with python 3.8 (possibly), @Geolykt what python version were you using when you were testing.
i have noted on discord i notice 3 options
classes.plugin.event.registerEvent
and automatically register events when called (either via event.fire
or event.register
)registerEvent
, iirc also event.register
does create events, i did this because the chat
event was not being created so i did it automatically forgetting that it should be registering at the top of the file)@Geolykt what python version were you using when you were testing.
python3.9-3.9.5-2.fc34
I'll recuse myself from this PR, since this feature has baffled me since #67.
I dont get what that means
It means that i won't take part in the review. i will support whatever ntoskrnl and Geolykt decide
Personally not a huge fan of how this is laid out (especially the code in __init.py__
). Also in non-compliance with PEP8 and pretty stale.
begins to work on #67 currently implements a Event handler (classes.plugin.event) begins implementing a API (literally just a shortcut to sending a chat message, classes.plugin.api) loading and unloading of plugins making of plugins folder if it doesen't exist
example plugin which fires a "command" event if it cant find a command if any receiver of the command event returns true it means the command has executed and works https://pastebin.com/eR0sM2fH