Skip to content

Commit

Permalink
Merge pull request #1 from alex3236/master
Browse files Browse the repository at this point in the history
重构
  • Loading branch information
OptiJava authored Feb 26, 2023
2 parents 88ebb5b + e8d37b6 commit f9bbfd6
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 42 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea
.idea/
__pycache__/
.vscode/
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# Seed

!!seed can get world seed
!!seed to get world seed.

## Preview

![image](https://user-images.githubusercontent.com/106148777/221347169-1764fb31-db0c-40e5-82cf-77c1915a638c.png)

## Configure

`config/seed/config.json`
- `command`: Command to get seed in console
- `parser`: Parser for the command result

The default configuration already supports most server software (without plugin/mods).

## More

(yes, a very simple plugin
This plugn was inspired by [`MCDReforged/Seed`](https://github.com/MCDReforged/Seed)
8 changes: 5 additions & 3 deletions lang/en_us.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
seed:
help_msg: Get world seed quickly!
get_seed: 'Seed:'
copy_to_clipboard: Click to copy to clipboard
help_msg: Get world seed
get_seed: 'Seed: '
copy_to_clipboard: Click to copy to clipboard
failed: Failed to get seed

8 changes: 5 additions & 3 deletions lang/zh_cn.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
seed:
help_msg: 更快速的获取服务器种子!
get_seed: 服务器种子:
copy_to_clipboard: 点击复制到剪贴板
help_msg: 获取世界种子
get_seed: 种子:
copy_to_clipboard: 点击复制到剪贴板
failed: 无法获取种子

4 changes: 2 additions & 2 deletions mcdreforged.plugin.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "seed",
"version": "1.0.1",
"version": "1.1.0",
"name": "Seed",
"description": "Get world seed quickly!",
"description": "Get world seed without op permission.",
"author": [
"OptiJava"
],
Expand Down
85 changes: 54 additions & 31 deletions seed/__init__.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,67 @@
import time
from typing import Optional

from mcdreforged.api.all import *
from parse import parse

server_inst: ServerInterface
getting_seed = False
seed: Optional[str] = None
config: dict = None

get_seed = False

seed: str = '0'
def on_load(server: PluginServerInterface, old_module):
global config
config = server.load_config_simple(default_config={
'command': 'seed',
'parser': 'Seed: [{}]'
})

if server.is_server_running():
get_seed(server)
server.register_command(Literal('!!seed').runs(print_seed))
server.register_help_message('!!seed', server.tr('seed.help_msg'))

def on_load(server: ServerInterface, old_module):
global server_inst
server_inst = server

server.register_command(Literal('!!seed').runs(run))
server.register_help_message('!!seed', server.tr('seed.help_msg'))
def on_server_startup(server: PluginServerInterface):
if seed is None:
get_seed(server)


def run():
global get_seed, seed
if seed == '0':
get_seed = True
server_inst.execute('seed')
@new_thread('seed')
def get_seed(server: PluginServerInterface):
global seed, getting_seed
if getting_seed:
return
else:
print_seed(seed)
getting_seed = True
if seed is None:
server.execute(config['command'])
for _ in range(50):
if seed is None:
time.sleep(0.1)
else:
getting_seed = False
return
server.logger.error(server.tr('seed.failed'))
getting_seed = False


# reference code https://github.com/MCDReforged/Seed
def on_info(server: ServerInterface, info: Info):
global get_seed, seed
if info.content.startswith('Seed: [') and get_seed:
seed = info.content.split('[')[1].split(']')[0]
print_seed(seed)
get_seed = False


def print_seed(value: str):
server_inst.tell('@a',
RTextList(
RText(server_inst.tr('seed.get_seed'), color=RColor.yellow),
RText('[', color=RColor.white),
RText(value, color=RColor.green, styles=RStyle.underlined).set_hover_text(
server_inst.tr('seed.copy_to_clipboard')).set_click_event(RAction.copy_to_clipboard, value),
RText(']', color=RColor.white))
)
global getting_seed, seed
if getting_seed:
result = parse(config['parser'], info.content)
if result:
seed = result[0]


def print_seed(source: CommandSource):
if seed is None:
source.reply(RText(RTextMCDRTranslation('seed.failed'), RColor.red))
source.reply(RTextList(
RTextMCDRTranslation('seed.get_seed', RColor.yellow),
RText('[', RColor.white),
RText(seed, RColor.green, RStyle.underlined).
h(RTextMCDRTranslation('seed.copy_to_clipboard')).
c(RAction.copy_to_clipboard, seed),
RText(']', RColor.white))
)

0 comments on commit f9bbfd6

Please sign in to comment.