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

feat: 补全Doc 添加静态创建方法

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-08-11 01:00:02 +08:00
parent ffd2d25db6
commit 66324bd307

View File

@ -17,11 +17,52 @@ import org.bukkit.entity.Player;
public class Tellraw { public class Tellraw {
List<MessagePart> messageParts = new ArrayList<>(); List<MessagePart> 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) { public Tellraw command(final String command) {
onClick("run_command", command); onClick("run_command", command);
return this; return this;
} }
/**
* 发送Tellraw
*
* @param sender
* 命令发送者
*/
public void send(final CommandSender sender) { public void send(final CommandSender sender) {
if (sender instanceof Player) { if (sender instanceof Player) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName() + " " + toJsonString()); 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) { public Tellraw suggest(final String command) {
onClick("suggest_command", command); onClick("suggest_command", command);
return this; return this;
@ -43,9 +91,6 @@ public class Tellraw {
* @return {@link Tellraw} * @return {@link Tellraw}
*/ */
public Tellraw then(final MessagePart part) { public Tellraw then(final MessagePart part) {
if (!latest().hasText()) {
throw new IllegalStateException("previous message part has no text");
}
messageParts.add(part); messageParts.add(part);
return this; return this;
} }
@ -62,11 +107,23 @@ public class Tellraw {
return this; return this;
} }
/**
* 悬浮消息
*
* @param text
* 文本
* @return {@link Tellraw}
*/
public Tellraw tip(final String text) { public Tellraw tip(final String text) {
onHover("show_text", text); onHover("show_text", text);
return this; return this;
} }
/**
* 转换成Json串
*
* @return Json串
*/
public String toJsonString() { public String toJsonString() {
final StringBuffer msg = new StringBuffer(); final StringBuffer msg = new StringBuffer();
msg.append("[\"\""); msg.append("[\"\"");
@ -99,7 +156,7 @@ public class Tellraw {
public String toOldMessageFormat() { public String toOldMessageFormat() {
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
for (final MessagePart part : messageParts) { for (final MessagePart part : messageParts) {
result.append(part.text); result.append(ChatColor.stripColor(part.text));
} }
return result.toString(); return result.toString();
} }