-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHere.py
109 lines (96 loc) · 3.26 KB
/
Here.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
import json
import re
PLUGIN_METADATA = {
'id': 'here',
'version': '1.0.0',
'name': 'Carpet Feature Helper',
'author': [
'Fallen_Breath',
'nathan21hz'
],
'link': 'https://github.com/TISUnion/Here'
}
# set it to 0 to disable hightlight
# 将其设为0以禁用高亮
HIGHLIGHT_TIME = 15
here_user = 0
def process_coordinate(text):
data = text[1:-1].replace('d', '').split(', ')
data = [(x + 'E0').split('E') for x in data]
return tuple([float(e[0]) * 10 ** int(e[1]) for e in data])
def process_dimension(text):
return text.replace(re.match(r'[\w ]+: ', text).group(), '', 1)
def display(server, name, position, dimension):
x, y, z = position
dimension_convert = {
'minecraft:overworld': '0',
'"minecraft:overworld"': '0',
'minecraft:the_nether': '-1',
'"minecraft:the_nether"': '-1',
'minecraft:the_end': '1',
'"minecraft:the_end"': '1'
}
dimension_color = {
'0': '§2',
'-1': '§4',
'1': '§5'
}
dimension_display = {
'0': {'translate': 'createWorld.customize.preset.overworld'},
'-1': {'translate': 'advancements.nether.root.title'},
'1': {'translate': 'advancements.end.root.title'}
}
if dimension in dimension_convert: # convert from 1.16 format to pre 1.16 format
dimension = dimension_convert[dimension]
texts = [
'',
{
'text': '§e{}'.format(name),
'clickEvent':
{
'action': 'run_command',
'value': '/execute at {0} run tp {0}'.format(name)
}
},
'§r @ ',
# hacky fix for voxelmap yeeting text color in translated text
dimension_color[dimension],
dimension_display[dimension],
' §b[x:{}, y:{}, z:{}]§r'.format(int(x), int(y), int(z))
]
if dimension in ['0', '-1']: # coordinate convertion between overworld and nether
dimension_opposite = '-1' if dimension == '0' else '0'
x, z = (x / 8, z / 8) if dimension == '0' else (x * 8, z * 8)
texts.extend([
' §7->§r ',
dimension_color[dimension_opposite],
dimension_display[dimension_opposite],
' ({}, {}, {})'.format(int(x), int(y), int(z))
])
server.execute('tellraw @a {}'.format(json.dumps(texts)))
global HIGHLIGHT_TIME
if HIGHLIGHT_TIME > 0:
server.execute(
'effect give {} minecraft:glowing {} 0 true'.format(name, HIGHLIGHT_TIME))
def on_info(server, info):
global here_user
if info.is_player and info.content == '!!here':
if hasattr(server, 'MCDR') and server.is_rcon_running():
name = info.player
position = process_coordinate(re.search(r'\[.*\]', server.rcon_query('data get entity {} Pos'.format(name))).group())
dimension = process_dimension(server.rcon_query('data get entity {} Dimension'.format(name)))
display(server, name, position, dimension)
else:
here_user += 1
server.execute('data get entity ' + info.player)
if not info.is_player and here_user > 0 and re.match(r'\w+ has the following entity data: ', info.content) is not None:
name = info.content.split(' ')[0]
dimension = re.search(r'(?<= Dimension: )(.*?),',
info.content).group().replace('"', '').replace(',', '')
position_str = re.search(r'(?<=Pos: )\[.*?\]', info.content).group()
position = process_coordinate(position_str)
display(server, name, position, dimension)
here_user -= 1
def on_load(server, old):
server.register_help_message('!!here', '广播坐标并高亮玩家')