TabooLib v4.22

+ 调整 TellrawJson
+ 修复 SimpleCommandBuilder 空指针问题
This commit is contained in:
坏黑 2018-08-29 14:10:31 +08:00
parent 07f8101c13
commit 9585dab04d
3 changed files with 14 additions and 9 deletions

View File

@ -6,7 +6,7 @@
<groupId>me.skymc</groupId> <groupId>me.skymc</groupId>
<artifactId>TabooLib</artifactId> <artifactId>TabooLib</artifactId>
<version>4.21</version> <version>4.22</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -19,6 +19,9 @@ import java.util.List;
*/ */
public class SimpleCommandBuilder { 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 String command;
private final Plugin plugin; private final Plugin plugin;
private String description; private String description;
@ -26,8 +29,8 @@ public class SimpleCommandBuilder {
private List<String> aliases; private List<String> aliases;
private String permission; private String permission;
private String permissionMessage; private String permissionMessage;
private CompleterCommand completerCommand; private CompleterTab completerTab = EMPTY_COMPLETER_TAB;
private CompleterTab completerTab; private CompleterCommand completerCommand = EMPTY_COMPLETER_COMMAND;
SimpleCommandBuilder(String command, Plugin plugin) { SimpleCommandBuilder(String command, Plugin plugin) {
this.command = command; this.command = command;
@ -78,6 +81,7 @@ public class SimpleCommandBuilder {
public SimpleCommandBuilder build() { public SimpleCommandBuilder build() {
Preconditions.checkNotNull(completerCommand, "缺少 \"CompleterCommand\" 部分"); Preconditions.checkNotNull(completerCommand, "缺少 \"CompleterCommand\" 部分");
Preconditions.checkNotNull(completerTab, "缺少 \"CompleterTab\" 部分");
TCommandHandler.registerPluginCommand( TCommandHandler.registerPluginCommand(
plugin, plugin,
command, command,

View File

@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* @Author sky * @Author sky
@ -93,6 +94,12 @@ public class TellrawJson {
return this; return this;
} }
public BaseComponent[] getComponentsAll() {
List<BaseComponent> 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) { public String getItemComponent(ItemStack itemStack) {
try { try {
Method asNMSCopyMethod = ReflectionUtils.getMethod(craftItemStackClazz, "asNMSCopy", ItemStack.class); Method asNMSCopyMethod = ReflectionUtils.getMethod(craftItemStackClazz, "asNMSCopy", ItemStack.class);
@ -138,10 +145,4 @@ public class TellrawJson {
public BaseComponent[] getComponents() { public BaseComponent[] getComponents() {
return components.toArray(new BaseComponent[0]); return components.toArray(new BaseComponent[0]);
} }
public BaseComponent[] getComponentsAll() {
List<BaseComponent> components = new ArrayList<>(this.components);
components.addAll(componentsLatest);
return components.toArray(new BaseComponent[0]);
}
} }