Add support for chat commands

This commit is contained in:
2020-09-08 17:51:27 -06:00
parent 100b4da80d
commit a76d02d53c
3 changed files with 70 additions and 18 deletions

10
bot.py
View File

@@ -177,14 +177,10 @@ def bot(global_state):
g.chunks = ChunksManager(g.mcdata)
g.chunks.register(g.connection)
g.chat = ChatManager()
g.chat.register(g.connection)
g.connection.connect()
def packet_wrapper(handler):
def wrapper(packet):
print('Wrapper:', handler)
handler(packet, g)
return wrapper
@@ -197,6 +193,10 @@ def bot(global_state):
h3 = packet_wrapper(packet_handlers.handle_block_change)
g.connection.register_packet_listener(h3, BlockChangePacket)
g.chat = ChatManager(g)
h4 = packet_wrapper(packet_handlers.handle_chat)
g.chat.set_handler(h4)
try:
while not g.pos:
time.sleep(TICK)
@@ -207,9 +207,7 @@ def bot(global_state):
time.sleep(TICK)
print('Chunks loaded.')
print('init..')
init(g)
print('done init')
while g.running:
tick(g)