Add public distance chat command
This commit is contained in:
1 parent
492238aa22
commit
d62e745fa6
3 files changed
+39
-1
No files matched your search
@@ -116,6 +116,27 @@ class Commands:
|
||||
if command == 'pos':
|
||||
reply = str(utils.pint(self.g.pos))[1:-1] + ', ' + self.g.dimension
|
||||
|
||||
## !dist - replies with the distance to the requesting player
|
||||
if command == 'dist':
|
||||
sender_ids = {str(sender), str(reply_target)}
|
||||
player_names = self.g.get('player_names') or {}
|
||||
for alias in tuple(sender_ids):
|
||||
linked_id = player_names.get(alias)
|
||||
if linked_id is None:
|
||||
linked_id = player_names.get(alias.lower())
|
||||
if linked_id is not None:
|
||||
sender_ids.add(str(linked_id))
|
||||
player = next((candidate
|
||||
for candidate in (self.g.get('players') or {}).values()
|
||||
if str(candidate.get('player_uuid', '')) in sender_ids),
|
||||
None)
|
||||
if player is None or self.g.get('pos') is None:
|
||||
reply = 'cannot find your position; you may be out of range'
|
||||
else:
|
||||
player_position = (player.x, player.y, player.z)
|
||||
distance = utils.phyp(self.g.pos, player_position)
|
||||
reply = 'you are {:.1f} blocks away'.format(distance)
|
||||
|
||||
## !health - replies with health, hunger, and saturation
|
||||
if command == 'health':
|
||||
if not self.g.get('health_update_received'):
|
||||
|
||||
Reference in new issue
Block a user