Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完善注入式与新增死亡返回插件 #56

Merged
merged 5 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.languageServer": "Pylance",
"python.analysis.typeCheckingMode": "off",
"python.analysis.autoImportCompletions": false
"python.analysis.typeCheckingMode": "off"
}
188 changes: 101 additions & 87 deletions plugin_market/market_tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,96 +5,110 @@
"DownloadRefURL": "https://mirror.ghproxy.com/raw.githubusercontent.com/ToolDelta/ToolDelta/main/plugin_market",
"DirectoryFileURL": "https://mirror.ghproxy.com/raw.githubusercontent.com/ToolDelta/ToolDelta/main/plugin_market/directory.json",
"MarketPlugins": {
"自定义聊天栏菜单": {
"author": "SuperScript",
"version": "0.0.1",
"description": "自定义聊天栏菜单触发词触发的指令, 方便简洁",
"limit_launcher": null,
"pre-plugins": {
"聊天栏菜单": "0.0.3"
},
"plugin-type": "classic"
"自定义聊天栏菜单": {
"author": "SuperScript",
"version": "0.0.1",
"description": "自定义聊天栏菜单触发词触发的指令, 方便简洁",
"limit_launcher": null,
"pre-plugins": {
"聊天栏菜单": "0.0.3"
},
"控制台执行MCFB指令": {
"author": "SuperScript",
"version": "0.0.2",
"description": "可以在控制台让机器人执行指令, 特殊指令等",
"limit_launcher": null,
"pre-plugins": {},
"plugin-type": "classic"
"plugin-type": "classic"
},
"控制台执行MCFB指令": {
"author": "SuperScript",
"version": "0.0.2",
"description": "可以在控制台让机器人执行指令, 特殊指令等",
"limit_launcher": null,
"pre-plugins": {},
"plugin-type": "classic"
},
"@玩家": {
"author": "wling",
"version": "0.0.2",
"description": "让@更有效果!",
"limit_launcher": null,
"pre-plugins": {},
"plugin-type": "injected"
},
"井字棋": {
"author": "SuperScript/wling",
"version": "0.0.2",
"description": "娱乐小游戏: 3x3井字棋",
"limit_launcher": null,
"pre-plugins": {},
"plugin-type": "injected"
},
"清空末影箱": {
"author": "wling",
"version": "0.0.1",
"description": "还在担心玩家在末影箱藏小东西吗?直接清空末影箱!",
"limit_launcher": null,
"pre-plugins": {},
"plugin-type": "injected"
},
"简易建造": {
"author": "SuperScript",
"version": "0.0.1",
"description": "使用一些更简便的方法建造服务器",
"limit_launcher": null,
"pre-plugins": {
"聊天栏菜单": "0.0.4",
"库-基本组件API": "0.0.1"
},
"@玩家": {
"author": "wling",
"version": "0.0.2",
"description": "让@更有效果!",
"limit_launcher": null,
"pre-plugins": {
},
"plugin-type": "injected"
"plugin-type": "classic"
},
"封禁系统": {
"author": "SuperScript",
"version": "0.0.1",
"description": "服内有大哥或者熊孩子? 更方便地ban掉! 同时也是一个前置插件.",
"limit_launcher": null,
"pre-plugins": {
"聊天栏菜单": "0.0.4"
},
"井字棋": {
"author": "SuperScript/wling",
"version": "0.0.1",
"description": "娱乐小游戏: 3x3井字棋",
"limit_launcher": null,
"pre-plugins": {},
"plugin-type": "injected"
"plugin-type": "classic"
},
"库-基本组件API": {
"author": "SuperScript",
"version": "0.0.1",
"description": "所有使用基本组件API的插件的前置",
"limit_launcher": null,
"pre-plugins": {},
"plugin-type": "classic"
},
"库-世界交互": {
"author": "SuperScript",
"version": "0.0.1",
"description": "所有使用世界交互的插件的前置",
"limit_launcher": null,
"pre-plugins": {
"聊天栏菜单": "0.0.1"
},
"清空末影箱": {
"author": "wling",
"version": "0.0.1",
"description": "还在担心玩家在末影箱藏小东西吗?直接清空末影箱!",
"limit_launcher": null,
"pre-plugins": {
},
"plugin-type": "injected"
},
"简易建造": {
"author": "SuperScript",
"version": "0.0.1",
"description": "使用一些更简便的方法建造服务器",
"limit_launcher": null,
"pre-plugins": {
"聊天栏菜单": "0.0.4",
"库-基本组件API": "0.0.1"
},
"plugin-type": "classic"
},
"封禁系统": {
"author": "SuperScript",
"version": "0.0.1",
"description": "服内有大哥或者熊孩子? 更方便地ban掉! 同时也是一个前置插件.",
"limit_launcher": null,
"pre-plugins": {
"聊天栏菜单": "0.0.4"
},
"plugin-type": "classic"
},
"库-基本组件API": {
"author": "SuperScript",
"version": "0.0.1",
"description": "所有使用基本组件API的插件的前置",
"limit_launcher": null,
"pre-plugins": {},
"plugin-type": "classic"
},
"库-世界交互": {
"author": "SuperScript",
"version": "0.0.1",
"description": "所有使用世界交互的插件的前置",
"limit_launcher": null,
"pre-plugins": {
"聊天栏菜单": "0.0.1"
},
"plugin-type": "classic"
},
"聊天栏菜单": {
"author": "SuperScript",
"version": "0.0.4",
"description": "所有使用到聊天栏菜单的组件的前置组件",
"limit_launcher": null,
"pre-plugins": {},
"plugin-type": "classic"
}
"plugin-type": "classic"
},
"聊天栏菜单": {
"author": "SuperScript",
"version": "0.0.4",
"description": "所有使用到聊天栏菜单的组件的前置组件",
"limit_launcher": null,
"pre-plugins": {},
"plugin-type": "classic"
},
"死亡返回": {
"author": "wling/7912",
"version": "0.0.1",
"description": "死了啊?没事,哥们给你记着,让我帮你返回吧!",
"limit_launcher": null,
"pre-plugins": { "维度传送": "0.0.1" },
"plugin-type": "injected"
},
"维度传送": {
"author": "SuperScript",
"version": "0.0.1",
"description": "作用如其名,跨纬度传送,谁都爱",
"limit_launcher": null,
"pre-plugins": {},
"plugin-type": "injected"
}
}
}
4 changes: 2 additions & 2 deletions plugin_market/井字棋/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

__plugin_meta__ = {
"name": "井字棋",
"version": "1.0",
"author": "SuperScript",
"version": "0.0.2",
"author": "SuperScript/wling",
}
class JZQStage:
def __init__(self):
Expand Down
19 changes: 9 additions & 10 deletions plugin_market/库-基本组件API/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from tooldelta import Plugin, PluginAPI, plugins, Frame

import json, time
from tooldelta import Plugin, PluginAPI, plugins, Frame

def find_key_from_value(dic, val):
# A bad method!
Expand Down Expand Up @@ -55,7 +54,7 @@ def getScore(self, scoreboardNameToGet: str, targetNameToGet: str) -> int:
return result[targetNameToGet][scoreboardNameToGet]
except KeyError as err:
raise Exception("Failed to get score: %s" % str(err))

def getPos(self, targetNameToGet: str, timeout: float | int = 1) -> dict:
"""
获取租赁服内玩家坐标的函数
Expand Down Expand Up @@ -93,7 +92,7 @@ def getPos(self, targetNameToGet: str, timeout: float | int = 1) -> dict:
return list(result.values())[0]
else:
return result[targetNameToGet]

def getItem(self, targetName: str, itemName: str, itemSpecialID: int = -1) -> int:
"获取玩家背包内物品数量: 目标选择器, 物品ID, 特殊值 = 所有"
if (targetName not in self.game_ctrl.allplayers) and (targetName != self.game_ctrl.bot_name) and (not targetName.startswith("@a")):
Expand All @@ -105,7 +104,7 @@ def getItem(self, targetName: str, itemName: str, itemSpecialID: int = -1) -> in
return 0
else:
return int(result.OutputMessages[0].Parameters[1])

def getTarget(self, sth: str, timeout: bool | int = 5) -> list:
"获取符合目标选择器实体的列表"
if not sth.startswith("@"):
Expand All @@ -124,7 +123,7 @@ def getBlockTile(self, x: int, y: int, z: int):
return "air"
else:
return res.OutputMessages[0].Parameters[4].strip("%tile.").strip(".name")

def waitMsg(self, who: str, timeout: int = 30, exc = None):
active_basic_api: ActivatePluginAPI = active_basic_apis[0]
"""
Expand Down Expand Up @@ -152,12 +151,12 @@ def waitMsg(self, who: str, timeout: int = 30, exc = None):
raise exc
else:
return None

def getPosXYZ(self, player, timeout = 30) -> tuple[float, float, float]:
"获取玩家坐标的X, Y, Z值"
res = self.getPos(player, timeout = timeout)["position"]
return res["x"], res["y"], res["z"]

def sendresultcmd(self, cmd, timeout = 30):
"返回命令执行是否成功"
res = self.game_ctrl.sendwscmd(cmd, True, timeout).SuccessCount
Expand All @@ -182,8 +181,8 @@ def on_player_message(self, player: str, msg: str):
if player in self.waitmsg_req:
self.waitmsg_result[player] = msg
self.waitmsg_req.remove(player)

def on_player_leave(self, player: str):
if player in self.waitmsg_req:
self.waitmsg_result[player] = EXC_PLAYER_LEAVE
self.waitmsg_req.remove(player)
self.waitmsg_req.remove(player)
97 changes: 97 additions & 0 deletions plugin_market/死亡返回/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import os, time
from genericpath import isfile
from logging import config
from traceback import print_tb
from tooldelta.plugin_load.injected_plugin import player_death
from 维度传送 import tp
from tooldelta.plugin_load import player_message, tellrawText, getPos
import ujson as json

__plugin_meta__ = {
"name": "死亡返回",
"version": "0.0.1",
"author": "wling/7912",
}


LOG_DEATH_TIME = 30 # 记录最小频率 (秒)
plugin_path = r"插件配置文件/死亡返回"
config_path = plugin_path + r"/死亡位置.json"
os.makedirs(plugin_path, exist_ok=True)
if os.path.isfile(config_path):
os.makedirs(config_path, exist_ok=True)
with open(config_path, "w", encoding="utf-8") as f:
json.dump("{}", f, indent=4, ensure_ascii=False)


def translateDim(dimension):
if dimension == 0:
return "主世界"
if dimension == 1:
return "地狱"
if dimension == 2:
return "末地"
raise ValueError("维度只能是0, 1或2.")


@player_message
async def _(playername, msg):
if msg == ".backdeath":
with open(config, "r", encoding="utf-8") as f:
data = json.loads(f)
if playername not in data:
tellrawText('@a[name="%s"]' % playername, "§l§4ERROR§r", "§c未找到记录.")
return
deathData = data[playername]
tp(
'@a[name="%s"]' % playername,
x=deathData["position"]["x"],
y=deathData["position"]["y"],
z=deathData["position"]["z"],
dimension=deathData["dimension"],
)
tellrawText(
'@a[name="%s"]' % playername,
"§l死亡点记录§r",
"已传送到上次死亡点: [§l%s§r, (§l%s§r, §l%s§r, §l%s§r)]."
% (
translateDim(deathData["dimension"]),
deathData["position"]["x"],
deathData["position"]["y"],
deathData["position"]["z"],
),
)
data[playername] = deathData
with open(config_path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4, ensure_ascii=False)


@player_death()
async def _(playername):
deathTime = int(time.time())
with open(config, "r", encoding="utf-8") as f:
data = json.loads(f)
if playername not in data:
data[playername] = {}
deathData_old = data[playername]
if deathData_old:
deathTimeDelta = deathTime - deathData_old["time"]
if deathTimeDelta < LOG_DEATH_TIME:
tellrawText(
'@a[name="%s"]' % playername,
"§l§4ERROR§r",
"§c时间间隔过短, 未保存此次记录. (冷却时间: §l%d§r§cs)"
% (LOG_DEATH_TIME - deathTimeDelta),
)
return

deathData = getPos(f'@a[name="{playername}"]')
deathData["time"] = deathTime
data[playername] = deathData
with open(config_path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4, ensure_ascii=False)
tellrawText(
f'@a[name="{playername}"]',
"§l死亡点记录§r",
f"已记录死亡点: [§l{translateDim(deathData['dimension'])}§r, (§l{deathData['position']['x']}§r, §l{deathData['position']['y']}§r, §l{deathData['position']['z']}§r)], 输入§l.backdeath§r返回.",
)
Loading
Loading