-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from alex3236/master
重构
- Loading branch information
Showing
6 changed files
with
82 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.idea | ||
.idea/ | ||
__pycache__/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 无法获取种子 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
) |