Skip to content

Commit 88ebb5b

Browse files
committed
use RText & add seed cache
1 parent 5e0abfa commit 88ebb5b

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

mcdreforged.plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "seed",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"name": "Seed",
55
"description": "Get world seed quickly!",
66
"author": [

seed/__init__.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,41 @@
44

55
get_seed = False
66

7+
seed: str = '0'
8+
79

810
def on_load(server: ServerInterface, old_module):
911
global server_inst
1012
server_inst = server
13+
1114
server.register_command(Literal('!!seed').runs(run))
1215
server.register_help_message('!!seed', server.tr('seed.help_msg'))
1316

1417

1518
def run():
16-
global get_seed
17-
get_seed = True
18-
server_inst.execute('seed')
19+
global get_seed, seed
20+
if seed == '0':
21+
get_seed = True
22+
server_inst.execute('seed')
23+
else:
24+
print_seed(seed)
1925

2026

2127
# reference code https://github.com/MCDReforged/Seed
2228
def on_info(server: ServerInterface, info: Info):
23-
global get_seed
29+
global get_seed, seed
2430
if info.content.startswith('Seed: [') and get_seed:
2531
seed = info.content.split('[')[1].split(']')[0]
26-
server.execute(
27-
'tellraw @a [{"text":"' + server_inst.tr('seed.get_seed') + ' [","color":"yellow"},{"text":"' + seed + '","color":"green","insertion":"' + seed + '","clickEvent":{"action":"copy_to_clipboard","value":"'+ seed + '"},"hoverEvent":{"action":"show_text","value":"' + server_inst.tr('seed.copy_to_clipboard') + '"}},{"text":"]","color":"yellow"}]')
32+
print_seed(seed)
2833
get_seed = False
34+
35+
36+
def print_seed(value: str):
37+
server_inst.tell('@a',
38+
RTextList(
39+
RText(server_inst.tr('seed.get_seed'), color=RColor.yellow),
40+
RText('[', color=RColor.white),
41+
RText(value, color=RColor.green, styles=RStyle.underlined).set_hover_text(
42+
server_inst.tr('seed.copy_to_clipboard')).set_click_event(RAction.copy_to_clipboard, value),
43+
RText(']', color=RColor.white))
44+
)

0 commit comments

Comments
 (0)