mirror of
https://github.com/ammaraskar/pyCraft.git
synced 2024-11-26 04:05:59 +01:00
Merge pull request #103 from SirGhostal/patch-2
This commit is contained in:
commit
4956d5e70d
@ -187,6 +187,16 @@ class Connection(object):
|
|||||||
else:
|
else:
|
||||||
self._outgoing_packet_queue.append(packet)
|
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
|
||||||
|
|
||||||
|
return _method_func
|
||||||
|
|
||||||
def register_packet_listener(self, method, *packet_types, **kwds):
|
def register_packet_listener(self, method, *packet_types, **kwds):
|
||||||
"""
|
"""
|
||||||
Registers a listener method which will be notified when a packet of
|
Registers a listener method which will be notified when a packet of
|
||||||
|
@ -224,26 +224,23 @@ class EarlyPacketListenerTest(ConnectTest):
|
|||||||
the early packet listener is registered afterwards.
|
the early packet listener is registered afterwards.
|
||||||
"""
|
"""
|
||||||
def _start_client(self, client):
|
def _start_client(self, client):
|
||||||
|
@client.listener(clientbound.play.JoinGamePacket)
|
||||||
def handle_join(packet):
|
def handle_join(packet):
|
||||||
assert early_handle_join.called, \
|
assert early_handle_join.called, \
|
||||||
'Ordinary listener called before early listener.'
|
'Ordinary listener called before early listener.'
|
||||||
handle_join.called = True
|
handle_join.called = True
|
||||||
handle_join.called = False
|
handle_join.called = False
|
||||||
client.register_packet_listener(
|
|
||||||
handle_join, clientbound.play.JoinGamePacket)
|
|
||||||
|
|
||||||
|
@client.listener(clientbound.play.JoinGamePacket, early=True)
|
||||||
def early_handle_join(packet):
|
def early_handle_join(packet):
|
||||||
early_handle_join.called = True
|
early_handle_join.called = True
|
||||||
client.register_packet_listener(
|
|
||||||
early_handle_join, clientbound.play.JoinGamePacket, early=True)
|
|
||||||
early_handle_join.called = False
|
early_handle_join.called = False
|
||||||
|
|
||||||
|
@client.listener(clientbound.play.DisconnectPacket)
|
||||||
def handle_disconnect(packet):
|
def handle_disconnect(packet):
|
||||||
assert early_handle_join.called, 'Early listener not called.'
|
assert early_handle_join.called, 'Early listener not called.'
|
||||||
assert handle_join.called, 'Ordinary listener not called.'
|
assert handle_join.called, 'Ordinary listener not called.'
|
||||||
raise fake_server.FakeServerTestSuccess
|
raise fake_server.FakeServerTestSuccess
|
||||||
client.register_packet_listener(
|
|
||||||
handle_disconnect, clientbound.play.DisconnectPacket)
|
|
||||||
|
|
||||||
client.connect()
|
client.connect()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user