From a8db9a7dabd23011ab9eed81c0ca1429369581ec Mon Sep 17 00:00:00 2001 From: Andy Zhang <37402126+AnzhiZhang@users.noreply.github.com> Date: Thu, 30 Jun 2022 20:06:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(bot):=20=E2=9C=A8=20support=20MCDR=202.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Release-As: 0.1.0 --- bot/{Bot.py => bot/__init__.py} | 44 +++++++++++++-------------------- bot/mcdreforged.plugin.json | 11 +++++++++ 2 files changed, 28 insertions(+), 27 deletions(-) rename bot/{Bot.py => bot/__init__.py} (87%) create mode 100644 bot/mcdreforged.plugin.json diff --git a/bot/Bot.py b/bot/bot/__init__.py similarity index 87% rename from bot/Bot.py rename to bot/bot/__init__.py index 8163da3..ab8dc6e 100644 --- a/bot/Bot.py +++ b/bot/bot/__init__.py @@ -1,20 +1,11 @@ # -*- coding: utf-8 -*- +from typing import Dict + from mcdreforged.api.types import PluginServerInterface from mcdreforged.api.command import * from mcdreforged.api.rtext import * +from mcdreforged.api.utils.serializer import Serializable -PLUGIN_METADATA = { - 'id': 'bot', - 'version': '0.0.1', - 'name': 'Bot', - 'description': 'Carpet bot easy manage and set', - 'author': 'Andy Zhang', - 'link': 'https://github.com/AnzhiZhang/MCDReforgedPlugins/tree/master/.archived/Bot', - 'dependencies': { - 'config_api': '*', - 'json_data_api': '*' - } -} DIMENSIONS = { '0': 'minecraft:overworld', '-1': 'minecraft:the_nether', @@ -28,30 +19,29 @@ 'minecraft:the_nether': 'minecraft:the_nether', 'minecraft:the_end': 'minecraft:the_end' } -DEFAULT_CONFIG = { - 'gamemode': 'survival', - 'permissions': { +HELP_MESSAGE = '''§6!!bot §7显示机器人列表 +§6!!bot spawn §7生成机器人 +§6!!bot kill §7移除机器人 +§6!!bot add §7添加机器人到机器人列表 +§6!!bot remove §7从机器人列表移除机器人''' + + +class Config(Serializable): + gamemode: str = 'survival' + permissions: Dict[str,int] = { 'list': 1, 'spawn': 2, 'kill': 2, 'add': 3, 'remove': 3 } -} -HELP_MESSAGE = '''§6!!bot §7显示机器人列表 -§6!!bot spawn §7生成机器人 -§6!!bot kill §7移除机器人 -§6!!bot add §7添加机器人到机器人列表 -§6!!bot remove §7从机器人列表移除机器人''' def on_load(server: PluginServerInterface, old): - from ConfigAPI import Config - from JsonDataAPI import Json - config = Config(PLUGIN_METADATA['name'], DEFAULT_CONFIG) - data = Json(PLUGIN_METADATA['name']) - permissions = config['permissions'] - server.register_help_message('!!bot help', '显示Bot插件帮助') + config = server.load_config_simple('config.json', target_class=Config) + data = server.load_config_simple('data.json', default_config={}) + permissions = config.permissions + server.register_help_message('!!bot help', '显示 Bot 插件帮助') server.register_help_message( '!!bot', RText('显示机器人列表').c(RAction.run_command, '!!bot').h('点击显示机器人列表') diff --git a/bot/mcdreforged.plugin.json b/bot/mcdreforged.plugin.json new file mode 100644 index 0000000..8a4065b --- /dev/null +++ b/bot/mcdreforged.plugin.json @@ -0,0 +1,11 @@ +{ + "id": "bot", + "version": "0.1.0", + "name": "Bot", + "description": { + "en_us": "Manage carpet bot", + "zh_cn": "管理地毯假人" + }, + "author": "Andy Zhang", + "link": "https://github.com/AnzhiZhang/MCDReforgedPlugins/tree/master/bot" +} \ No newline at end of file