Improve !info command
This commit is contained in:
parent
4d2d358175
commit
09b09b3f96
|
@ -23,7 +23,7 @@ class Commands:
|
||||||
|
|
||||||
def handle_chat(self, message):
|
def handle_chat(self, message):
|
||||||
source, sender, text = message
|
source, sender, text = message
|
||||||
reply = None
|
reply = ''
|
||||||
private = False
|
private = False
|
||||||
for_me = False
|
for_me = False
|
||||||
authed = sender == '0c123cfa-1697-4427-9413-4b645dee7ec0'
|
authed = sender == '0c123cfa-1697-4427-9413-4b645dee7ec0'
|
||||||
|
@ -244,23 +244,67 @@ class Commands:
|
||||||
tree = next(self.g.world.find_trees(pos, 50))
|
tree = next(self.g.world.find_trees(pos, 50))
|
||||||
reply = str(tree)[1:-1]
|
reply = str(tree)[1:-1]
|
||||||
|
|
||||||
## !block x y z - replies what block is at (x, y, z)
|
## !info [query] - replies with info on a coordinate, block, item, or player
|
||||||
if command == 'block':
|
if command == 'info':
|
||||||
try:
|
if not reply:
|
||||||
data = data.replace('(', ' ').replace(')', ' ').replace(',', ' ')
|
try:
|
||||||
x1, y1, z1 = [int(x) for x in data.split()]
|
check = data.replace('(', ' ').replace(')', ' ').replace(',', ' ')
|
||||||
except (AttributeError, ValueError):
|
x1, y1, z1 = [int(x) for x in check.split()]
|
||||||
reply = 'usage: !block x1 y1 z1'
|
coord = (x1, y1, z1)
|
||||||
|
block = self.g.world.block_at(*coord)
|
||||||
|
|
||||||
|
if not reply and block is None:
|
||||||
|
reply = 'coord out of range'
|
||||||
|
|
||||||
|
if not reply:
|
||||||
|
reply = 'Block: ' + blocks.BLOCKS[block] + ':' + str(block)
|
||||||
|
if blocks.PROPS[block]:
|
||||||
|
reply += ' - ' + ', '.join(['{}:{}'.format(k, v) for k, v in blocks.PROPS[block].items()])
|
||||||
|
except (AttributeError, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
if not reply:
|
if not reply:
|
||||||
coord = (x1, y1, z1)
|
try:
|
||||||
block = self.g.world.block_at(*coord)
|
check = int(data)
|
||||||
|
|
||||||
if not reply and block is None:
|
if check in blocks.BLOCKS:
|
||||||
reply = 'first coord out of range'
|
block = check
|
||||||
|
reply += 'Block: ' + blocks.BLOCKS[block] + ':' + str(block)
|
||||||
|
if blocks.PROPS[block]:
|
||||||
|
reply += ' - ' + ', '.join(['{}:{}'.format(k, v) for k, v in blocks.PROPS[block].items()])
|
||||||
|
|
||||||
if not reply:
|
if check in blocks.BLOCKS and check in items.ITEM_NAMES:
|
||||||
reply = blocks.BLOCKS[block] + ':' + str(block)
|
reply += ' / '
|
||||||
|
|
||||||
|
if check in items.ITEM_NAMES:
|
||||||
|
item = check
|
||||||
|
reply += 'Item: ' + items.ITEM_NAMES[item] + ':' + str(item)
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
check = data.lower()
|
||||||
|
if not reply and check in self.g.player_names:
|
||||||
|
uuid = self.g.player_names[check]
|
||||||
|
|
||||||
|
for p in self.g.players.values():
|
||||||
|
if p.player_uuid == uuid:
|
||||||
|
player = p
|
||||||
|
break
|
||||||
|
else: # for
|
||||||
|
reply = 'player out of range'
|
||||||
|
|
||||||
|
if not reply:
|
||||||
|
reply += 'Player: '
|
||||||
|
|
||||||
|
results = []
|
||||||
|
for k, v in player.items():
|
||||||
|
try:
|
||||||
|
results.append('{}:{}'.format(k, int(v)))
|
||||||
|
except ValueError:
|
||||||
|
results.append('{}:{}'.format(k, str(v)))
|
||||||
|
|
||||||
|
reply += ', '.join(results)
|
||||||
|
|
||||||
|
|
||||||
################# Specific commands ##########################
|
################# Specific commands ##########################
|
||||||
|
|
|
@ -493,7 +493,8 @@ class Game:
|
||||||
for action in packet.actions:
|
for action in packet.actions:
|
||||||
if isinstance(action, packet.AddPlayerAction):
|
if isinstance(action, packet.AddPlayerAction):
|
||||||
self.g.player_names[action.uuid] = action.name
|
self.g.player_names[action.uuid] = action.name
|
||||||
self.g.player_names[action.name] = action.uuid # porque no los dos?
|
self.g.player_names[action.name] = action.uuid
|
||||||
|
self.g.player_names[action.name.lower()] = action.uuid # porque no los dos?
|
||||||
|
|
||||||
def handle_update_health(self, packet):
|
def handle_update_health(self, packet):
|
||||||
print(packet)
|
print(packet)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user