Added listener decorator documentation (#161)

* added decorator example to connection.rst

since decorators are more pythonic, it was put in front of the register method.

* Expanded listener decorator docstring

* changed autofunction to autodecorator

* removed whitespace in empty line

* remvoed trailing whitespace

i didn't even edit there WTF
This commit is contained in:
laundmo authored and GitHub committed 2020-08-17 17:49:25 +02:00
1 parent ff9a0813b6
commit 2947aa6619
2 files changed
+26 -2

No files matched your search

+21 -1
View File
@@ -39,7 +39,26 @@ multiple protocol versions.
Listening for Certain Packets
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Let's look at how to listen for certain packets, the relevant method being
Let's look at how to listen for certain packets, the relevant decorator being
A decorator can be used to register a packet listener:
.. autodecorator:: Connection.listener
Example usage::
connection = Connection(options.address, options.port, auth_token=auth_token)
connection.connect()
from minecraft.networking.packets.clientbound.play import ChatMessagePacket
@connection.listener(ChatMessagePacket)
def print_chat(chat_packet):
print "Position: " + str(chat_packet.position)
print "Data: " + chat_packet.json_data
Altenatively, packet listeners can also be registered seperate from the function definition.
.. automethod:: Connection.register_packet_listener
@@ -57,6 +76,7 @@ An example of this can be found in the ``start.py`` headless client, it is recre
The field names ``position`` and ``json_data`` are inferred by again looking at the definition attribute as before
.. autoclass:: minecraft.networking.packets.clientbound.play.ChatMessagePacket
:undoc-members:
:inherited-members: