1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-22 01:48:50 +00:00

fix: 修复值为进行Json转义的问题

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-09-14 12:06:33 +08:00
parent d39dc2020b
commit 12c8890834
4 changed files with 22 additions and 9 deletions

View File

@ -14,7 +14,8 @@ import org.bukkit.inventory.meta.ItemMeta;
import pw.yumc.YumCore.bukkit.Log;
/**
*
* 物品序列化类
*
* @since 2016年9月9日 下午3:47:17
* @author
*/
@ -31,7 +32,7 @@ public abstract class ItemSerialize {
public static String $(final ItemStack item) {
final String result = itemSerialize.parse(item);
Log.debug(String.format("%s物品序列化结果: %s", itemSerialize.getName(), result));
Log.d("%s物品序列化结果: %s", itemSerialize.getName(), result);
return result;
}
@ -76,7 +77,7 @@ public abstract class ItemSerialize {
@Override
public String parse(final ItemStack item) {
try {
return new JsonBuilder((nmsSaveNBTMethod.invoke(asNMSCopyMethod.invoke(null, item), nmsNBTTagCompound.newInstance()).toString())).toString();
return nmsSaveNBTMethod.invoke(asNMSCopyMethod.invoke(null, item), nmsNBTTagCompound.newInstance()).toString();
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException e) {
itemSerialize = new Manual();
return itemSerialize.parse(item);
@ -168,7 +169,7 @@ public abstract class ItemSerialize {
* @return 物品字符串
*/
private String serialize(final ItemStack item) {
final JsonBuilder json = new JsonBuilder("{");
final StringBuffer json = new StringBuffer("{");
json.append(String.format("id:\"%s\",Damage:\"%s\"", item.getTypeId(), item.getDurability()));
if (item.getAmount() > 1) {
json.append(String.format(",Count:%s", item.getAmount()));

View File

@ -1,5 +1,11 @@
package pw.yumc.YumCore.tellraw;
/**
* Json构建
*
* @since 2016年9月14日 上午11:55:36
* @author
*/
public class JsonBuilder {
public static final String[] REPLACEMENT_CHARS;
static {
@ -59,6 +65,10 @@ public class JsonBuilder {
json.deleteCharAt(json.length() - 1);
}
public boolean isEmpty() {
return json.length() == 0;
}
public int length() {
return json.length();
}

View File

@ -14,7 +14,7 @@ public class MessagePart {
/**
* 消息文本
*/
public String text = "";
public String text;
/**
* 点击操作
*/
@ -59,18 +59,18 @@ public class MessagePart {
*/
public void writeJson(final StringBuffer str) {
str.append("{");
str.append(String.format(TEXT_FORMAT, text));
str.append(String.format(TEXT_FORMAT, new JsonBuilder(text)));
if (clickActionName != null) {
str.append(",");
str.append(String.format(CLICK_FORMAT, clickActionName, clickActionData));
str.append(String.format(CLICK_FORMAT, clickActionName, new JsonBuilder(clickActionData)));
}
if (hoverActionName != null) {
str.append(",");
str.append(String.format(HOVER_FORMAT, hoverActionName, hoverActionData));
str.append(String.format(HOVER_FORMAT, hoverActionName, new JsonBuilder(hoverActionData)));
}
if (insertionData != null) {
str.append(",");
str.append(String.format(INSERT_FORMAT, insertionData));
str.append(String.format(INSERT_FORMAT, new JsonBuilder(insertionData)));
}
str.append("}");
}

View File

@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.bukkit.compatible.C;
@ -276,6 +277,7 @@ public class Tellraw {
messagePart.writeJson(msg);
}
msg.append("]");
Log.debug(msg.toString());
return msg.toString();
}