版本更新至 4.06

新增:TLocale 新增 BOOK 类型,用于发送书本界面(代替 Language2)
新增:TLocale 新增 BAR 类型,用于发送 Bossbar(需要 BossBarAPI)
新增:TLocale#Tellraw 工具用于发送原始 json 信息
新增:TellrawJson 工具用于创建原始 json 信息
新增:VariableFormatter 工具用于变量识别
新增:ArrayUtils 新增数组修改方法
修复:Language2Book 工具失效问题
调整:JsonFormatter 工具已过时,不再维护

从该版本起不再对 1.7.10 版本进行支持与维护,任何在 1.7.10 版本内出现的问题不再修复。
1.7.10 稳定版:v3.832
This commit is contained in:
坏黑
2018-05-27 21:15:29 +08:00
parent 8a20fb7edb
commit 5843e0be04
27 changed files with 1095 additions and 464 deletions

View File

@@ -1,8 +1,10 @@
package me.skymc.taboolib.bookformatter;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import com.ilummc.tlib.bungee.api.chat.BaseComponent;
import com.ilummc.tlib.bungee.api.chat.TextComponent;
import com.ilummc.tlib.bungee.chat.ComponentSerializer;
import com.ilummc.tlib.logger.TLogger;
import com.ilummc.tlib.resources.TLocale;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -12,6 +14,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -31,11 +34,13 @@ public final class BookReflection {
private static final Method craftPlayerGetHandle;
//This method takes an enum that represents the player's hand only in versions >= 1.9
//In the other versions it only takes the nms item
/*
This method takes an enum that represents the player's hand only in versions >= 1.9
In the other versions it only takes the nms item
*/
private static final Method entityPlayerOpenBook;
//only version >= 1.9
// only version >= 1.9
private static final Object[] hands;
//Older versions
@@ -115,18 +120,22 @@ public final class BookReflection {
* @param meta the book meta to change
* @param components the pages of the book
*/
@SuppressWarnings("unchecked")//reflections = unchecked warnings
public static void setPages(BookMeta meta, BaseComponent[][] components) {
public static void setPages(BookMeta meta, BaseComponent[]... components) {
List<Object> pages = null;
try {
List<Object> pages = (List<Object>) craftMetaBookField.get(meta);
pages.clear();
for (BaseComponent[] c : components) {
final String json = ComponentSerializer.toString(c);
//System.out.println("page:" + json); //Debug
pages.add(chatSerializerA.invoke(null, json));
}
pages = (List<Object>) craftMetaBookField.get(meta);
} catch (Exception e) {
throw new UnsupportedVersionException(e);
TLogger.getGlobalLogger().error("Error while executing reflections, failed to get bookmeta (version: " + BookReflection.version + ")");
return;
}
pages.clear();
for (BaseComponent[] c : components) {
try {
pages.add(chatSerializerA.invoke(null, ComponentSerializer.toString(c)));
} catch (Exception e) {
TLogger.getGlobalLogger().error("Error while executing reflections, submit to developers the following log (version: " + BookReflection.version + ")");
e.printStackTrace();
}
}
}
@@ -136,17 +145,21 @@ public final class BookReflection {
* @param meta the book meta to change
* @param components the pages of the book
*/
@SuppressWarnings("unchecked")//reflections = unchecked warnings
public static void addPages(BookMeta meta, BaseComponent[][] components) {
public static void addPages(BookMeta meta, BaseComponent[]... components) {
List<Object> pages = null;
try {
List<Object> pages = (List<Object>) craftMetaBookField.get(meta);
for (BaseComponent[] c : components) {
final String json = ComponentSerializer.toString(c);
//System.out.println("page:" + json); //Debug
pages.add(chatSerializerA.invoke(null, json));
}
pages = (List<Object>) craftMetaBookField.get(meta);
} catch (Exception e) {
throw new UnsupportedVersionException(e);
TLogger.getGlobalLogger().error("Error while executing reflections, failed to get bookmeta (version: " + BookReflection.version + ")");
return;
}
for (BaseComponent[] c : components) {
try {
pages.add(chatSerializerA.invoke(null, ComponentSerializer.toString(c)));
} catch (Exception e) {
TLogger.getGlobalLogger().error("Error while executing reflections, submit to developers the following log (version: " + BookReflection.version + ")");
e.printStackTrace();
}
}
}

View File

@@ -1,6 +1,6 @@
package me.skymc.taboolib.bookformatter.action;
import net.md_5.bungee.api.chat.ClickEvent;
import com.ilummc.tlib.bungee.api.chat.ClickEvent;
/**
* @author sky
@@ -86,12 +86,12 @@ public interface ClickAction {
@Override
public ClickEvent.Action action() {
return null;
return action;
}
@Override
public String value() {
return null;
return value;
}
}
}

View File

@@ -1,10 +1,10 @@
package me.skymc.taboolib.bookformatter.action;
import com.ilummc.tlib.bungee.api.chat.BaseComponent;
import com.ilummc.tlib.bungee.api.chat.HoverEvent;
import com.ilummc.tlib.bungee.api.chat.TextComponent;
import me.skymc.taboolib.bookformatter.BookAchievement;
import me.skymc.taboolib.bookformatter.BookReflection;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Achievement;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
@@ -157,12 +157,12 @@ public interface HoverAction {
@Override
public HoverEvent.Action action() {
return null;
return action;
}
@Override
public BaseComponent[] value() {
return new BaseComponent[0];
return value;
}
}
}

View File

@@ -1,7 +1,7 @@
package me.skymc.taboolib.bookformatter.builder;
import com.ilummc.tlib.bungee.api.chat.BaseComponent;
import me.skymc.taboolib.bookformatter.BookReflection;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
@@ -125,4 +125,19 @@ public class BookBuilder {
book.setItemMeta(meta);
return book;
}
// *********************************
//
// Getter and Setter
//
// *********************************
public BookMeta getMeta() {
return meta;
}
public ItemStack getBook() {
return book;
}
}

View File

@@ -1,7 +1,7 @@
package me.skymc.taboolib.bookformatter.builder;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import com.ilummc.tlib.bungee.api.chat.*;
import me.skymc.taboolib.string.ArrayUtils;
import java.util.ArrayList;
import java.util.Arrays;
@@ -14,7 +14,7 @@ import java.util.List;
*/
public class PageBuilder {
private List<BaseComponent> text = new ArrayList<>();
private BaseComponent[] text = TextComponent.fromLegacyText("");
/**
* Adds a simple black-colored text to the page
@@ -22,7 +22,7 @@ public class PageBuilder {
* @return the PageBuilder's calling instance
*/
public PageBuilder add(String text) {
this.text.add(TextBuilder.of(text).build());
Arrays.stream(TextComponent.fromLegacyText(text)).forEach(component -> this.text = ArrayUtils.arrayAppend(this.text, component));
return this;
}
@@ -32,7 +32,7 @@ public class PageBuilder {
* @return the PageBuilder's calling instance
*/
public PageBuilder add(BaseComponent component) {
this.text.add(component);
this.text = ArrayUtils.arrayAppend(this.text, component);
return this;
}
@@ -42,17 +42,7 @@ public class PageBuilder {
* @return the PageBuilder's calling instance
*/
public PageBuilder add(BaseComponent... components) {
this.text.addAll(Arrays.asList(components));
return this;
}
/**
* Adds one or more components to the page
* @param components the components to add
* @return the PageBuilder's calling instance
*/
public PageBuilder add(Collection<BaseComponent> components) {
this.text.addAll(components);
Arrays.stream(components).forEach(component -> this.text = ArrayUtils.arrayAppend(this.text, component));
return this;
}
@@ -61,8 +51,7 @@ public class PageBuilder {
* @return the PageBuilder's calling instance
*/
public PageBuilder newLine() {
this.text.add(new TextComponent("\n"));
return this;
return add("\n");
}
/**
@@ -78,10 +67,9 @@ public class PageBuilder {
* @return an array of BaseComponents representing the page
*/
public BaseComponent[] build() {
return text.toArray(new BaseComponent[0]);
return text;
}
/**
* Creates a new PageBuilder instance wih the parameter as the initial text
* @param text the initial text of the page

View File

@@ -1,11 +1,8 @@
package me.skymc.taboolib.bookformatter.builder;
import com.ilummc.tlib.bungee.api.chat.*;
import me.skymc.taboolib.bookformatter.action.ClickAction;
import me.skymc.taboolib.bookformatter.action.HoverAction;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
/**
* @author sky