CLI 工具
此处所指的CLI工具是支持玩家在mc游戏的聊天框中通过点击文本来交互的一种技术。
例如(这里先借用DominionDocs的图片来演示CLI): 
准备工作
使用MSL开发CLI工具需要提前了解tellraw命令的用法:https://zh.minecraft.wiki/w/命令/tellraw?variant=zh-cn
在高版本MC中,tellraw命令的格式转变为SNBT格式:https://zh.minecraft.wiki/w/SNBT格式?variant=zh
制造CLI工具之前,建议先安装MyCommand插件:https://www.spigotmc.org/resources/mycommand.22272/
以下所有tellraw均以高版本SNBT格式书写。
原理
run_command
tellraw的run_command只支持斜杠命令。
当使用/tellraw @a {color:"aqua",text:"返回出生点",click_event:{action:"run_command",command:"/csd"}}命令时,玩家聊天窗口会出现一个天蓝色的返回出生点,当玩家点击该文本后,就会执行/csd命令。但此时有个极大的问题:
/csd是MSL里插件的命令,没有在mc中注册,原版mc是认为这是一个未知命令,将会弹出窗口提示玩家该命令可能无法执行,需要手动点击执行才可以,非常影响体验。
此时,就可以用MyCommand插件在mc中注册一个空命令/csd解决该问题。
MyCommand
关于热重载
无论是使用MyCommand自身提供的reload命令还是用plugman重载MyCommand都不能成功注册,必须重启服务器。
例如上面的问题,可以直接打开mc服务器位置/plugins/MyCommand/commands/examples.yml,全部删掉,留下(按需调整,可设置多个,permission无论是否为true都能拉起msl事件,但如果不给予玩家权限则玩家仍然需要手动点击执行):
back_csd:
command: /csd
type: TEXT
text: []
permission-required: true
permission-node: ps.csd
permission-error: "&a$player! , &2You can't use this command!"
register: true示例:!.玩家系统
TIP
不提倡多个plugin_executeCommand连用
此处直接粘贴某服务器玩家系统代码,未做修改:
function Index(player) {
plugin_executeCommand(`tellraw ${player} {text:"=[玩家系统]========================================",color:"green"}`);
plugin_executeCommand(`tellraw ${player} {text:" "}`);
plugin_executeCommand(`tellraw ${player} {text:" 亲爱的${player},欢迎您使用HC玩家系统,菜单:",color:"aqua","bold":true}`);
plugin_executeCommand(`tellraw ${player} {text:" 祝愿2026年参加中考、高考的考生一切顺利!",color:"red","bold":true}`);
plugin_executeCommand(`tellraw ${player} {text:" "}`);
plugin_executeCommand(`tellraw ${player} {text:" ⬛ 每日签到",color:"gold",click_event:{action:"run_command",command:"/reward"},extra:[{text:" ⬛ 诅咒急救",color:"gold",click_event:{action:"run_command",command:"/csd removeSolt"}}]}`);
plugin_executeCommand(`tellraw ${player} {text:" ⬛ 领地系统",color:"gold",click_event:{action:"run_command",command:"/dom"},extra:[{text:" ⬛ 自定称号",color:"gold",click_event:{action:"run_command",command:"/csd guiPrefix"}}]}`);
plugin_executeCommand(`tellraw ${player} {text:" ⬛ 翻垃圾桶",color:"gold",click_event:{action:"run_command",command:"/wtc globaltrash"}}`);
plugin_executeCommand(`tellraw ${player} {text:" "}`);
plugin_executeCommand(`tellraw ${player} {text:" 加QQ群",color:"aqua",click_event:{action:"open_url",url:"https://qm.qq.com/q/xAaPA9iwEg"}, extra:[{text:" | 官网",color:"aqua",click_event:{action:"open_url",url:"https://qm.qq.com/q/xAaPA9iwEg"}},{text:" | 出生点",color:"aqua",click_event:{action:"run_command",command:"/csd"}}]}`);
plugin_executeCommand(`tellraw ${player} {text:" "}`);
plugin_executeCommand(`tellraw ${player} {text:"================================================",color:"green"}`);
}
plugin_registerCommand("!.", (player)=>{
setTimeout(()=>{Index(player)}, 100);
})
plugin_registerCommand("/csd", (player)=>{
plugin_executeCommand(`tp ${player} 2166 78 1899`)
})
function doYouKnow() {
plugin_executeCommand(`tellraw @a {text:"=[你知道吗]========================================",color:"green"}`);
plugin_executeCommand(`tellraw @a {text:" "}`);
plugin_executeCommand(`tellraw @a {text:" 在聊天栏发送 ",color:"aqua",extra:[{text:" !. ",color:"blue"},{text:"能打开玩家菜单,发送",color:"aqua"},{text:" !赞助 ",color:"blue"},{text:"能获得点券哦~",color:"aqua"}]}`);
plugin_executeCommand(`tellraw @a {text:" "}`);
plugin_executeCommand(`tellraw @a {text:"================================================",color:"green"}`);
}
function doYouKnow2() {
plugin_executeCommand(`tellraw @a {text:"=[重要提示]========================================",color:"green"}`);
plugin_executeCommand(`tellraw @a {text:" "}`);
plugin_executeCommand(`tellraw @a {text:" 使用玩家系统【诅咒急救】时,一定要注意看提示!!",color:"aqua"}`);
plugin_executeCommand(`tellraw @a {text:" "}`);
plugin_executeCommand(`tellraw @a {text:"================================================",color:"green"}`);
}
plugin_registerCommand(`/csd guiPrefix`, (player)=>{
plugin_executeCommand(`tellraw ${player} {text:"=[自定称号]========================================",color:"green"}`);
plugin_executeCommand(`tellraw ${player} {text:" "}`);
plugin_executeCommand(`tellraw ${player} {text:" 请输入指令来设置自定称号(指令中不要含有尖括号):",color:"aqua","bold":true}`);
plugin_executeCommand(`tellraw ${player} {text:" /csd prefix <称号>",color:"aqua"}`);
plugin_executeCommand(`tellraw ${player} {text:" "}`);
plugin_executeCommand(`tellraw ${player} {text:"================================================",color:"green"}`);
})
setInterval(doYouKnow, 1000 * 60 * 10)
setInterval(doYouKnow2, 1000 * 60 * 20)
function removeSolt(player) {
plugin_executeCommand(`tellraw ${player} {text:"=[诅咒急救]========================================",color:"green"}`);
plugin_executeCommand(`tellraw ${player} {text:" "}`);
plugin_executeCommand(`tellraw ${player} {text:" 我们将清空你的背包第一行第一格槽位,请提前移走!",color:"red","bold":true}`);
plugin_executeCommand(`tellraw ${player} {text:" 按E键一共四行,从上往下从左往右第一个!!",color:"red","bold":true}`);
plugin_executeCommand(`tellraw ${player} {text:" 在下方选择你要调整的装备,我们将会把他转移到你背包第一格。",color:"red","bold":true}`);
plugin_executeCommand(`tellraw ${player} {text:" "}`);
plugin_executeCommand(`tellraw ${player} {text:" 头盔",color:"aqua",click_event:{action:"run_command",command:"/csd removeSolt head"},extra:[{text:" 胸甲",color:"aqua",click_event:{action:"run_command",command:"/csd removeSolt chest"}},{text:" 护腿",color:"aqua",click_event:{action:"run_command",command:"/csd removeSolt legs"}},{text:" 靴子",color:"aqua",click_event:{action:"run_command",command:"/csd removeSolt feet"}}]}`);
plugin_executeCommand(`tellraw ${player} {text:" "}`);
plugin_executeCommand(`tellraw ${player} {text:"================================================",color:"green"}`);
}
// 提取重复的警告提示,确保醒目提醒不丢失
function sendRemoveSuccessMessages(player) {
plugin_executeCommand(`tellraw ${player} {color:"green",text:"已成功替换你的背包槽位,请不要继续点击,否则将变为空气。"}`);
plugin_executeCommand(`tellraw ${player} {color:"green",text:"已成功替换你的背包槽位,请不要继续点击,否则将变为空气。"}`);
plugin_executeCommand(`tellraw ${player} {color:"green",text:"已成功替换你的背包槽位,请不要继续点击,否则将变为空气。"}`);
plugin_executeCommand(`tellraw ${player} {color:"green",text:"如果要继续替换其他装甲,请重新移动背包第一格,否则概不负责!!"}`);
plugin_executeCommand(`tellraw ${player} {color:"green",text:"如果要继续替换其他装甲,请重新移动背包第一格,否则概不负责!!"}`);
plugin_executeCommand(`tellraw ${player} {color:"green",text:"如果要继续替换其他装甲,请重新移动背包第一格,否则概不负责!!"}`);
}
plugin_registerCommand("/csd removeSolt", removeSolt);
plugin_registerCommand("/csd removeSolt head", (player) => {
plugin_executeCommand(`minecraft:item replace entity ${player} inventory.0 with air`);
plugin_executeCommand(`minecraft:item replace entity ${player} inventory.0 from entity ${player} armor.head`);
plugin_executeCommand(`minecraft:item replace entity ${player} armor.head with air`);
sendRemoveSuccessMessages(player);
})
plugin_registerCommand("/csd removeSolt chest", (player) => {
plugin_executeCommand(`minecraft:item replace entity ${player} inventory.0 with air`);
plugin_executeCommand(`minecraft:item replace entity ${player} inventory.0 from entity ${player} armor.chest`);
plugin_executeCommand(`minecraft:item replace entity ${player} armor.chest with air`);
sendRemoveSuccessMessages(player);
})
plugin_registerCommand("/csd removeSolt legs", (player) => {
plugin_executeCommand(`minecraft:item replace entity ${player} inventory.0 with air`);
plugin_executeCommand(`minecraft:item replace entity ${player} inventory.0 from entity ${player} armor.legs`);
plugin_executeCommand(`minecraft:item replace entity ${player} armor.legs with air`);
sendRemoveSuccessMessages(player);
})
plugin_registerCommand("/csd removeSolt feet", (player) => {
plugin_executeCommand(`minecraft:item replace entity ${player} inventory.0 with air`);
plugin_executeCommand(`minecraft:item replace entity ${player} inventory.0 from entity ${player} armor.feet`);
plugin_executeCommand(`minecraft:item replace entity ${player} armor.feet with air`);
sendRemoveSuccessMessages(player);
})
plugin_registerCommand("!赞助", (player) => {
plugin_executeCommand(`ban ${player} 永久封禁,原因:赞助`);
setTimeout(()=>{
plugin_executeCommand(`unban ${player}`);
}, 10000);
})