我给你写了个修复的,你可以参考一下
[MD]```js
// 扭扭舞插件
// 版本: 1.0
// 作者: 例外 QQ1961674817
const PLUGIN_NAME = "TwistDance";
const PLUGIN_VERSION = "1.0.1";
// 扭扭舞动画配置
const TWIST_DANCE_ANIMATIONS = [
'playanimation {playerName} animation.minecart.move.v1.0 none 0 "q.is_sneaking?(v.rail_rotation.z=7*math.sin(q.life_time*600);v.rail_offset.y=1.15):(v.rail_rotation.z=0;v.rail_rotation.y=1.555;);" twist_anim1',
'playanimation {playerName} animation.warden.move none 0 "q.is_sneaking?(v.body_z_rot=12*math.sin(q.life_time*600)):(v.body_z_rot=0;);" twist_anim2',
'playanimation {playerName} animation.ender_dragon.neck_head_movement none 1 "q.is_sneaking?(v.head_position_x=0.1*math.sin(q.life_time*600);v.head_rotation_z=3.5*math.cos(q.life_time*599.7)):(v.head_position_x=0;);" twist_anim3',
'playanimation {playerName} animation.parrot.dance none 0 "v.dance.y=0;q.is_sneaking?(v.dance.x=2*math.sin(q.life_time*600);):(v.dance.x=0;);" twist_anim4',
'playanimation {playerName} animation.ender_dragon.neck_head_movement none 0 "v.head_rotation_x=q.target_x_rotation;v.head_rotation_y=q.target_y_rotation;!q.is_sneaking?(v.head_rotation_z=0;);" twist_anim5'
];
// 停止动画的命令 - 使用相同的控制器名称覆盖原动画,重置为基础姿势
const STOP_DANCE_ANIMATIONS = [
'playanimation {playerName} animation.humanoid.base_pose none 0.1 "" twist_anim1',
'playanimation {playerName} animation.humanoid.base_pose none 0.1 "" twist_anim2',
'playanimation {playerName} animation.humanoid.base_pose none 0.1 "" twist_anim3',
'playanimation {playerName} animation.humanoid.base_pose none 0.1 "" twist_anim4',
'playanimation {playerName} animation.humanoid.base_pose none 0.1 "" twist_anim5'
];
let playerDanceStatus = {};
let config = null;
function initConfig() {
try {
config = new JsonConfigFile("plugins/TwistDance/config.json");
// 初始化
config.init("enabled", true);
config.init("permissions", {
useCommand: 0,
adminCommand: 1
});
config.init("messages", {
danceEnabled: "§a扭扭舞已启动!潜行开始扭动吧~",
danceDisabled: "§c扭扭舞已停止!",
pluginDisabled: "§c扭扭舞功能已被管理员禁用",
noPermission: "§c你没有权限使用此命令",
alreadyEnabled: "§e你的扭扭舞已经在进行中了!",
alreadyDisabled: "§e你的扭扭舞本来就是关闭的!",
stopTip: "§e由于技术限制,请退出游戏来关闭扭扭舞"
});
config.init("effects", {
enableSound: false,
enableParticles: true,
enableTitle: true
});
log(`[${PLUGIN_NAME}] 配置文件加载完成`);
} catch (e) {
log(`[${PLUGIN_NAME}] 配置文件加载失败: ${e}`);
// 创建默认配置对象
config = {
get: function(key) {
const defaults = {
enabled: true,
permissions: { useCommand: 0, adminCommand: 1 },
messages: {
danceEnabled: "§a扭扭舞已启动!潜行开始扭动吧~",
danceDisabled: "§c扭扭舞已停止!",
pluginDisabled: "§c扭扭舞功能已被管理员禁用",
noPermission: "§c你没有权限使用此命令",
alreadyEnabled: "§e你的扭扭舞已经在进行中了!",
alreadyDisabled: "§e你的扭扭舞本来就是关闭的!",
stopTip: "§e由于技术限制,请退出游戏来关闭扭扭舞"
},
effects: { enableSound: false, enableParticles: true, enableTitle: true }
};
return defaults[key];
},
set: function(key, value) { return true; },
reload: function() { return true; }
};
}
}
function getPlayerDanceStatus(xuid) {
return playerDanceStatus[xuid] || false;
}
function setPlayerDanceStatus(xuid, enabled) {
playerDanceStatus[xuid] = enabled;
}
// 启动扭扭舞
function enableTwistDance(player) {
try {
// 执行所有命令
TWIST_DANCE_ANIMATIONS.forEach(cmd => {
let playerCmd = cmd.replace('{playerName}', player.realName);
mc.runcmd(playerCmd);
});
setPlayerDanceStatus(player.xuid, true);
// 发送消息
let message = config.get("messages").danceEnabled;
if (typeof message !== 'string') {
message = "§a扭扭舞已启动!潜行开始扭动吧~";
}
if (config.get("effects").enableTitle) {
player.setTitle("§a扭扭舞启动", 2, 10, 40, 10);
}
player.tell(message, 5);
// 生成粒子效果
if (config.get("effects").enableParticles) {
try {
mc.spawnParticle(player.pos, "minecraft:heart_particle");
} catch (e) {
}
}
log(`[${PLUGIN_NAME}] 玩家 ${player.realName} 启动了扭扭舞`);
return true;
} catch (e) {
player.tell(`§c启动扭扭舞失败: ${e}`, 5);
log(`[${PLUGIN_NAME}] 启动扭扭舞失败: ${e}`);
return false;
}
}
// 停止
function disableTwistDance(player) {
try {
// 执行停止动画命令,用基础姿势覆盖扭扭舞动画
STOP_DANCE_ANIMATIONS.forEach(cmd => {
let playerCmd = cmd.replace('{playerName}', player.realName);
mc.runcmd(playerCmd);
});
setPlayerDanceStatus(player.xuid, false);
// 发送消息
let message = config.get("messages").danceDisabled;
if (typeof message !== 'string') {
message = "§c扭扭舞已停止!";
}
if (config.get("effects").enableTitle) {
player.setTitle("§c扭扭舞已停止", 2, 10, 40, 10);
}
player.tell(message, 5);
log(`[${PLUGIN_NAME}] 玩家 ${player.realName} 停止了扭扭舞`);
return true;
} catch (e) {
player.tell(`§c停止扭扭舞失败: ${e}`, 5);
log(`[${PLUGIN_NAME}] 停止扭扭舞失败: ${e}`);
return false;
}
}
function toggleTwistDance(player) {
let currentStatus = getPlayerDanceStatus(player.xuid);
if (currentStatus) {
return disableTwistDance(player);
} else {
return enableTwistDance(player);
}
}
// 创建扭扭舞控制表单
function createTwistDanceForm(player) {
let form = mc.newSimpleForm();
form.setTitle("§d扭扭舞控制器");
let isEnabled = getPlayerDanceStatus(player.xuid);
let statusText = isEnabled ? "§a已启用" : "§c已停用";
form.setContent(`§e当前扭扭舞状态: ${statusText}\n\n潜行时会触发扭扭舞动画效果\n包含身体摇摆、头部摆动等多种动作`);
form.addButton("§a启动扭扭舞");
form.addButton("§c停止扭扭舞");
form.addButton("§e查看状态");
form.addButton("关闭面板");
return form;
}
function handleFormSubmit(player, id) {
if (id == null) return;
switch (id) {
case 0:
if (getPlayerDanceStatus(player.xuid)) {
let alreadyEnabledMsg = config.get("messages").alreadyEnabled;
if (typeof alreadyEnabledMsg !== 'string') {
alreadyEnabledMsg = "§e你的扭扭舞已经在进行中了!";
}
player.tell(alreadyEnabledMsg, 5);
} else {
enableTwistDance(player);
}
break;
case 1: // 停止
if (!getPlayerDanceStatus(player.xuid)) {
let alreadyDisabledMsg = config.get("messages").alreadyDisabled;
if (typeof alreadyDisabledMsg !== 'string') {
alreadyDisabledMsg = "§e你的扭扭舞本来就是关闭的!";
}
player.tell(alreadyDisabledMsg, 5);
} else {
disableTwistDance(player);
}
break;
case 2:
let status = getPlayerDanceStatus(player.xuid);
let statusMsg = status ? "§a启用中" : "§c已停用";
player.tell(`§e=== 扭扭舞状态 ===`, 0);
player.tell(`§e状态: ${statusMsg}`, 0);
player.tell(`§e玩家: §b${player.realName}`, 0);
player.tell("提示: 潜行时触发动画效果", 0);
break;
case 3:
player.tell("面板已关闭", 5);
break;
}
}
// 注册命令
function registerCommands() {
// 主命令
mc.regPlayerCmd("twist", "扭扭舞控制", (player, args) => {
if (!config.get("enabled")) {
player.tell(config.get("messages").pluginDisabled, 5);
return;
}
if (config.get("permissions").useCommand == 1 && !player.isOP()) {
player.tell(config.get("messages").noPermission, 5);
return;
}
if (args.length == 0) {
// 打开GUI
let form = createTwistDanceForm(player);
player.sendForm(form, (player, id) => {
handleFormSubmit(player, id);
});
return;
}
let subCmd = args[0].toLowerCase();
switch (subCmd) {
case "on":
case "start":
case "enable":
if (getPlayerDanceStatus(player.xuid)) {
player.tell(config.get("messages").alreadyEnabled, 5);
} else {
enableTwistDance(player);
}
break;
case "off":
case "stop":
case "disable":
if (!getPlayerDanceStatus(player.xuid)) {
let alreadyDisabledMsg = config.get("messages").alreadyDisabled;
if (typeof alreadyDisabledMsg !== 'string') {
alreadyDisabledMsg = "§e你的扭扭舞本来就是关闭的!";
}
player.tell(alreadyDisabledMsg, 5);
} else {
disableTwistDance(player);
}
break;
case "toggle":
if (getPlayerDanceStatus(player.xuid)) {
disableTwistDance(player);
} else {
enableTwistDance(player);
}
break;
case "status":
let status = getPlayerDanceStatus(player.xuid);
let statusMsg = status ? "§a启用中" : "§c已停用";
player.tell(`§e你的扭扭舞状态: ${statusMsg}`, 5);
break;
case "help":
player.tell("§e=== 扭扭舞命令帮助 ===", 0);
player.tell("§a/twist - 打开扭扭舞控制面板", 0);
player.tell("§a/twist on - 启动扭扭舞", 0);
player.tell("§a/twist off - 停止扭扭舞", 0);
player.tell("§a/twist toggle - 切换扭扭舞状态", 0);
player.tell("§a/twist status - 查看当前状态", 0);
player.tell("§a/twist help - 显示此帮助", 0);
if (player.isOP()) {
player.tell("§c=== 管理员命令 ===", 0);
player.tell("§c/twist admin reload - 重载配置", 0);
player.tell("§c/twist admin toggle - 开关插件", 0);
player.tell("§c/twist admin list - 查看所有玩家状态", 0);
}
break;
case "admin":
if (!player.isOP()) {
player.tell(config.get("messages").noPermission, 5);
return;
}
if (args.length < 2) {
player.tell("§c用法: /twist admin <reload|toggle|list>", 5);
return;
}
let adminCmd = args[1].toLowerCase();
switch (adminCmd) {
case "reload":
if (config.reload) {
config.reload();
}
player.tell("§a配置文件已重载", 5);
break;
case "toggle":
let enabled = !config.get("enabled");
if (config.set) {
config.set("enabled", enabled);
}
player.tell(`§a插件已${enabled ? "启用" : "禁用"}`, 5);
break;
case "list":
player.tell("§e=== 扭扭舞玩家状态 ===", 0);
let count = 0;
for (let xuid in playerDanceStatus) {
let playerName = data.xuid2name(xuid) || "未知玩家";
let status = playerDanceStatus[xuid];
let statusText = status ? "§a启用" : "§c停用";
player.tell(`§b${playerName} §7- ${statusText}`, 0);
count++;
}
if (count == 0) {
player.tell("暂无玩家使用扭扭舞", 0);
} else {
player.tell(`§e总计: ${count} 个玩家`, 0);
}
break;
default:
player.tell("§c未知的管理员命令: " + adminCmd, 5);
break;
}
break;
default:
player.tell("§c未知命令,使用 /twist help 查看帮助", 5);
break;
}
}, 0);
mc.regPlayerCmd("dance", "扭扭舞控制(别名)", (player, args) => {
if (args.length == 0) {
let form = createTwistDanceForm(player);
player.sendForm(form, (player, id) => {
handleFormSubmit(player, id);
});
} else {
player.tell("使用 /twist " + args.join(" ") + " 来执行命令", 5);
}
}, 0);
}
mc.listen("onLeft", (player) => {
if (getPlayerDanceStatus(player.xuid)) {
setPlayerDanceStatus(player.xuid, false);
log(`[${PLUGIN_NAME}] 玩家 ${player.realName} 离开游戏,扭扭舞已自动关闭`);
}
delete playerDanceStatus[player.xuid];
});
// 插件初始化
mc.listen("onServerStarted", () => {
log(`[${PLUGIN_NAME}] v${PLUGIN_VERSION} 正在加载...`);
initConfig();
registerCommands();
log(`[${PLUGIN_NAME}] v${PLUGIN_VERSION} 加载完成!`);
log(`[${PLUGIN_NAME}] 使用 /twist 或 /dance 命令控制扭扭舞`);
});
// 插件信息输出
log(`[${PLUGIN_NAME}] 插件作者: 例外QQ:1961674817`);
log(`[${PLUGIN_NAME}] 插件描述: 让玩家可以自由开关扭扭舞动画效果`);
```
[/MD]