From 6d6a592f070d5779bdde345f52252d0da6a41a93 Mon Sep 17 00:00:00 2001 From: Zachy Date: Mon, 13 Aug 2018 01:57:16 +0100 Subject: [PATCH] Add decorator for register_packet_listener() --- minecraft/networking/connection.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/minecraft/networking/connection.py b/minecraft/networking/connection.py index 4a40da7..e1b75db 100644 --- a/minecraft/networking/connection.py +++ b/minecraft/networking/connection.py @@ -187,6 +187,15 @@ class Connection(object): else: self._outgoing_packet_queue.append(packet) + def listener(self, *packet_types, **kwds): + """ + Shorthand decorator to register a function as a packet listener. + """ + def _method_func(method): + self.register_packet_listener(method, *packet_types, **kwds) + + return _method_func + def register_packet_listener(self, method, *packet_types, **kwds): """ Registers a listener method which will be notified when a packet of