feat: 完善MiaoChat的PAPI的替换

merge/2/HEAD
coding 2018-05-16 16:09:26 +00:00
parent d2ebd8fa7e
commit 9819a82265
1 changed files with 14 additions and 12 deletions

View File

@ -11,6 +11,7 @@ var server = require('api/server');
var fs = require('fs'); var fs = require('fs');
var tellraw = require('tellraw'); var tellraw = require('tellraw');
var papi = require('papi');
var utils = require('utils') var utils = require('utils')
var description = { var description = {
@ -190,29 +191,30 @@ function sendChat(player, plain, callback) {
chat_format.format_list.forEach(function setStyle(format) { chat_format.format_list.forEach(function setStyle(format) {
var style = style_formats[format]; var style = style_formats[format];
if (style) { if (style) {
tr.then(style.text); tr.then(replace(player, style.text));
if (style.hover) { if (style.hover) {
tr.tip(style.hover); tr.tip(replace(player, style.hover));
} }
if (style.click && style.click.type && style.click.command) { if (style.click && style.click.type && style.click.command) {
var command = replace(player, style.click.command)
switch (style.click.type) { switch (style.click.type) {
case "COMMAND": case "COMMAND":
tr.command(style.click.command); tr.command(command);
break; break;
case "OPENURL": case "OPENURL":
tr.link(style.click.command); tr.link(command);
break; break;
case "SUGGEST": case "SUGGEST":
tr.suggest(style.click.command); tr.suggest(command);
break; break;
default: default:
} }
} }
} else { } else {
tr.then(format); tr.then(replace(player, format));
} }
}) })
tr.then(plain).sendAll(); tr.then(replace(player, plain)).sendAll();
} }
function getChatFormat(player) { function getChatFormat(player) {
@ -225,19 +227,19 @@ function getChatFormat(player) {
return null; return null;
} }
function replace(target) { function replace(player, target) {
if (toString.call(target) === "[object Array]") { if (toString.call(target) === "[object Array]") {
for (var i in target) { for (var i in target) {
target[i] = replaceStr(target[i]); target[i] = replaceStr(player, target[i]);
} }
} else { } else {
target = replaceStr(target); target = replaceStr(player, target);
} }
return target; return target;
} }
function replaceStr(target) { function replaceStr(player, target) {
return target; return papi.$(player, target);
} }
function disable() { function disable() {