Hey,
Im currently writing a quick afk manager api and I thought it would be good to add a "On Player AFK" listener and reverse.
Couldnt understand it from wikis
Create own listener
Re: Create own listener
Hey !
I have one solution but i don't know if it's the best xD.
If i m not wrong :)
I have one solution but i don't know if it's the best xD.
Syntax: Select all
## listeners.py
## IMPORTS
from listeners import ListenerManager
from listeners import ListenerManagerDecorator
## ALL DECLARATION
__all__ = (
'OnPlayerAfk',
)
class OnPlayerAfk(ListenerManagerDecorator):
manager = ListenerManager()
Syntax: Select all
from .listeners import OnPlayerAfk
# In your fonction which check afk
def _on_afk_check():
OnPlayerAfk.manager.notify(player=player)
@OnPlayerAfk
def _on_player_afk(player):
# Do something
If i m not wrong :)
Re: Create own listener
Yep, that's exactly how you do it.
Re: Create own listener
Why do we need that __all__ or what is it function?
Re: Create own listener
The __all__ attribute allows python to know what to define when trying to import from a module.
Doing:
Would import all things from the <module> but only define values which are named from inside the iterable.
You can still do:
The * is just a way of checking what is inside __all__
Doing:
Syntax: Select all
from <module> import *
Would import all things from the <module> but only define values which are named from inside the iterable.
You can still do:
Syntax: Select all
from <module> import <object>
The * is just a way of checking what is inside __all__
Re: Create own listener
To clarify it: you don't need it, but it's commonly used when creating modules to prevent cluttering your namespace when you import everything with the asterisk.
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 17 guests