From 9585dab04d6f924900cb2f401069d13bf449e952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Wed, 29 Aug 2018 14:10:31 +0800 Subject: [PATCH] =?UTF-8?q?TabooLib=20v4.22=20+=20=E8=B0=83=E6=95=B4=20Tel?= =?UTF-8?q?lrawJson=20+=20=E4=BF=AE=E5=A4=8D=20SimpleCommandBuilder=20?= =?UTF-8?q?=E7=A9=BA=E6=8C=87=E9=92=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../commands/builder/SimpleCommandBuilder.java | 8 ++++++-- .../me/skymc/taboolib/json/tellraw/TellrawJson.java | 13 +++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 8900a75..995be96 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.skymc TabooLib - 4.21 + 4.22 UTF-8 diff --git a/src/main/java/me/skymc/taboolib/commands/builder/SimpleCommandBuilder.java b/src/main/java/me/skymc/taboolib/commands/builder/SimpleCommandBuilder.java index 656cb56..9e7efbd 100644 --- a/src/main/java/me/skymc/taboolib/commands/builder/SimpleCommandBuilder.java +++ b/src/main/java/me/skymc/taboolib/commands/builder/SimpleCommandBuilder.java @@ -19,6 +19,9 @@ import java.util.List; */ public class SimpleCommandBuilder { + public static final CompleterTab EMPTY_COMPLETER_TAB = ((sender, args) -> new ArrayList<>()); + public static final CompleterCommand EMPTY_COMPLETER_COMMAND = ((sender, args) -> false); + private final String command; private final Plugin plugin; private String description; @@ -26,8 +29,8 @@ public class SimpleCommandBuilder { private List aliases; private String permission; private String permissionMessage; - private CompleterCommand completerCommand; - private CompleterTab completerTab; + private CompleterTab completerTab = EMPTY_COMPLETER_TAB; + private CompleterCommand completerCommand = EMPTY_COMPLETER_COMMAND; SimpleCommandBuilder(String command, Plugin plugin) { this.command = command; @@ -78,6 +81,7 @@ public class SimpleCommandBuilder { public SimpleCommandBuilder build() { Preconditions.checkNotNull(completerCommand, "缺少 \"CompleterCommand\" 部分"); + Preconditions.checkNotNull(completerTab, "缺少 \"CompleterTab\" 部分"); TCommandHandler.registerPluginCommand( plugin, command, diff --git a/src/main/java/me/skymc/taboolib/json/tellraw/TellrawJson.java b/src/main/java/me/skymc/taboolib/json/tellraw/TellrawJson.java index 94ba081..ba2e288 100644 --- a/src/main/java/me/skymc/taboolib/json/tellraw/TellrawJson.java +++ b/src/main/java/me/skymc/taboolib/json/tellraw/TellrawJson.java @@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemStack; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * @Author sky @@ -93,6 +94,12 @@ public class TellrawJson { return this; } + public BaseComponent[] getComponentsAll() { + List components = this.components.stream().filter(component -> !(component instanceof TextComponent) || !((TextComponent) component).getText().isEmpty()).collect(Collectors.toList()); + this.componentsLatest.stream().filter(component -> !(component instanceof TextComponent) || !((TextComponent) component).getText().isEmpty()).forEach(components::add); + return components.toArray(new BaseComponent[0]); + } + public String getItemComponent(ItemStack itemStack) { try { Method asNMSCopyMethod = ReflectionUtils.getMethod(craftItemStackClazz, "asNMSCopy", ItemStack.class); @@ -138,10 +145,4 @@ public class TellrawJson { public BaseComponent[] getComponents() { return components.toArray(new BaseComponent[0]); } - - public BaseComponent[] getComponentsAll() { - List components = new ArrayList<>(this.components); - components.addAll(componentsLatest); - return components.toArray(new BaseComponent[0]); - } }