From 66324bd307bda52e23e5b951f4bf78a430fe641e Mon Sep 17 00:00:00 2001 From: 502647092 Date: Thu, 11 Aug 2016 01:00:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=A8Doc=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=9D=99=E6=80=81=E5=88=9B=E5=BB=BA=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../java/pw/yumc/YumCore/tellraw/Tellraw.java | 65 +++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/src/main/java/pw/yumc/YumCore/tellraw/Tellraw.java b/src/main/java/pw/yumc/YumCore/tellraw/Tellraw.java index b896f71..a155bbf 100644 --- a/src/main/java/pw/yumc/YumCore/tellraw/Tellraw.java +++ b/src/main/java/pw/yumc/YumCore/tellraw/Tellraw.java @@ -17,11 +17,52 @@ import org.bukkit.entity.Player; public class Tellraw { List messageParts = new ArrayList<>(); + public Tellraw() { + this(""); + } + + public Tellraw(final String text) { + then("text"); + } + + /** + * 创建Tellraw + * + * @return {@link Tellraw} + */ + public static Tellraw create() { + return new Tellraw(); + } + + /** + * 创建Tellraw + * + * @param text + * 文本 + * @return {@link Tellraw} + */ + public static Tellraw create(final String text) { + return new Tellraw(text); + } + + /** + * 执行命令 + * + * @param command + * 命令 + * @return {@link Tellraw} + */ public Tellraw command(final String command) { onClick("run_command", command); return this; } + /** + * 发送Tellraw + * + * @param sender + * 命令发送者 + */ public void send(final CommandSender sender) { if (sender instanceof Player) { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName() + " " + toJsonString()); @@ -30,6 +71,13 @@ public class Tellraw { } } + /** + * 补全命令 + * + * @param command + * 命令 + * @return {@link Tellraw} + */ public Tellraw suggest(final String command) { onClick("suggest_command", command); return this; @@ -43,9 +91,6 @@ public class Tellraw { * @return {@link Tellraw} */ public Tellraw then(final MessagePart part) { - if (!latest().hasText()) { - throw new IllegalStateException("previous message part has no text"); - } messageParts.add(part); return this; } @@ -62,11 +107,23 @@ public class Tellraw { return this; } + /** + * 悬浮消息 + * + * @param text + * 文本 + * @return {@link Tellraw} + */ public Tellraw tip(final String text) { onHover("show_text", text); return this; } + /** + * 转换成Json串 + * + * @return Json串 + */ public String toJsonString() { final StringBuffer msg = new StringBuffer(); msg.append("[\"\""); @@ -99,7 +156,7 @@ public class Tellraw { public String toOldMessageFormat() { final StringBuilder result = new StringBuilder(); for (final MessagePart part : messageParts) { - result.append(part.text); + result.append(ChatColor.stripColor(part.text)); } return result.toString(); }