diff --git a/pom.xml b/pom.xml
index 9c53f9a..8900a75 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.skymc
TabooLib
- 4.2
+ 4.21
UTF-8
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 0e88dd6..94ba081 100644
--- a/src/main/java/me/skymc/taboolib/json/tellraw/TellrawJson.java
+++ b/src/main/java/me/skymc/taboolib/json/tellraw/TellrawJson.java
@@ -4,33 +4,29 @@ import com.ilummc.tlib.bungee.api.chat.*;
import com.ilummc.tlib.bungee.chat.ComponentSerializer;
import com.ilummc.tlib.logger.TLogger;
import com.ilummc.tlib.resources.TLocale;
-import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.methods.ReflectionUtils;
import me.skymc.taboolib.nms.NMSUtils;
-import me.skymc.taboolib.other.NumberUtils;
import me.skymc.taboolib.string.ArrayUtils;
-import me.skymc.taboolib.string.VariableFormatter;
import org.bukkit.command.CommandSender;
import org.bukkit.inventory.ItemStack;
-import java.lang.reflect.Array;
import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collections;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
/**
* @Author sky
* @Since 2018-05-26 14:42json
+ * @BuilderLevel 1.2
*/
public class TellrawJson {
- private BaseComponent[] components = TextComponent.fromLegacyText("");
- private final Class> craftItemStackClazz = NMSUtils.getOBCClass("inventory.CraftItemStack");
- private final Class> nmsItemStackClazz = NMSUtils.getNMSClass("ItemStack");
- private final Class> nbtTagCompoundClazz = NMSUtils.getNMSClass("NBTTagCompound");
- private final String INVALID_ITEM = "{id:stone,tag:{display:{Name:§c* Invalid ItemStack *}}}";
+ private List components = new ArrayList<>();
+ private List componentsLatest = new ArrayList<>();
+ private static final Class> craftItemStackClazz = NMSUtils.getOBCClass("inventory.CraftItemStack");
+ private static final Class> nmsItemStackClazz = NMSUtils.getNMSClass("ItemStack");
+ private static final Class> nbtTagCompoundClazz = NMSUtils.getNMSClass("NBTTagCompound");
+ private static final String INVALID_ITEM = "{id:stone,tag:{display:{Name:§c* Invalid ItemStack *}}}";
TellrawJson() {
}
@@ -39,12 +35,16 @@ public class TellrawJson {
return new TellrawJson();
}
+ public void send(CommandSender sender) {
+ TLocale.Tellraw.send(sender, toRawMessage());
+ }
+
public String toRawMessage() {
- return ComponentSerializer.toString(components);
+ return ComponentSerializer.toString(getComponentsAll());
}
public String toLegacyText() {
- return TextComponent.toLegacyText(components);
+ return TextComponent.toLegacyText(getComponentsAll());
}
public TellrawJson newLine() {
@@ -52,52 +52,47 @@ public class TellrawJson {
}
public TellrawJson append(String text) {
- Arrays.stream(TextComponent.fromLegacyText(text)).forEach(component -> this.components = ArrayUtils.arrayAppend(this.components, component));
+ appendComponents();
+ componentsLatest.addAll(ArrayUtils.asList(TextComponent.fromLegacyText(text)));
return this;
}
public TellrawJson append(TellrawJson json) {
- BaseComponent[] newArray = new BaseComponent[components.length + json.components.length];
- System.arraycopy(components, 0, newArray, 0, components.length);
- System.arraycopy(json.components, 0, newArray, components.length, json.components.length);
- components = newArray;
+ appendComponents();
+ componentsLatest.addAll(ArrayUtils.asList(json.getComponentsAll()));
return this;
}
public TellrawJson hoverText(String text) {
- getLatestComponent().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(text).create()));
+ getLatestComponent().forEach(component -> component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(text).create())));
return this;
}
public TellrawJson hoverItem(ItemStack itemStack) {
- getLatestComponent().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(getItemComponent(itemStack)).create()));
+ getLatestComponent().forEach(component -> component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(getItemComponent(itemStack)).create())));
return this;
}
public TellrawJson clickCommand(String command) {
- getLatestComponent().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
+ getLatestComponent().forEach(component -> component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)));
return this;
}
public TellrawJson clickSuggest(String command) {
- getLatestComponent().setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
+ getLatestComponent().forEach(component -> component.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)));
return this;
}
public TellrawJson clickOpenURL(String url) {
- getLatestComponent().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
+ getLatestComponent().forEach(component -> component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)));
return this;
}
public TellrawJson clickChangePage(int page) {
- getLatestComponent().setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, String.valueOf(page)));
+ getLatestComponent().forEach(component -> component.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, String.valueOf(page))));
return this;
}
- public void send(CommandSender sender) {
- TLocale.Tellraw.send(sender, toRawMessage());
- }
-
public String getItemComponent(ItemStack itemStack) {
try {
Method asNMSCopyMethod = ReflectionUtils.getMethod(craftItemStackClazz, "asNMSCopy", ItemStack.class);
@@ -106,7 +101,7 @@ public class TellrawJson {
Object nmsItemStackObj = asNMSCopyMethod.invoke(null, itemStack);
return saveNmsItemStackMethod.invoke(nmsItemStackObj, nmsNbtTagCompoundObj).toString();
} catch (Throwable t) {
- TLogger.getGlobalLogger().error("failed to serialize itemstack to nms item: " + t.toString());
+ TLogger.getGlobalLogger().error("failed to serialize bukkit item to nms item: " + t.toString());
return INVALID_ITEM;
}
}
@@ -117,12 +112,17 @@ public class TellrawJson {
//
// *********************************
- private BaseComponent getLatestComponent() {
- return components[components.length - 1];
+ private List getLatestComponent() {
+ return componentsLatest;
}
- private void setLatestComponent(BaseComponent component) {
- components[components.length - 1] = component;
+ private void setLatestComponent(BaseComponent... component) {
+ componentsLatest.addAll(ArrayUtils.asList(component));
+ }
+
+ private void appendComponents() {
+ components.addAll(componentsLatest);
+ componentsLatest.clear();
}
// *********************************
@@ -131,12 +131,17 @@ public class TellrawJson {
//
// *********************************
- public BaseComponent[] getComponents() {
- return components;
- }
-
public void setComponents(BaseComponent[] components) {
- this.components = components;
+ this.components = ArrayUtils.asList(components);
}
+ 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]);
+ }
}
diff --git a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java
index e6da994..6625aac 100644
--- a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java
+++ b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java
@@ -3,7 +3,9 @@ package me.skymc.taboolib.listener;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.database.PlayerDataManager;
+import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.itemnbtapi.NBTItem;
+import me.skymc.taboolib.json.tellraw.TellrawJson;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.permission.PermissionUtils;
import me.skymc.taboolib.playerdata.DataUtils;
@@ -30,14 +32,19 @@ public class ListenerPlayerCommand implements Listener {
@SuppressWarnings("deprecation")
@EventHandler
public void cmd(PlayerCommandPreprocessEvent e) {
- if ("/unbreakable".equals(e.getMessage()) && PermissionUtils.hasPermission(e.getPlayer(), "taboolib.unbreakable")) {
+ if (e.getMessage().equals("/unbreakable") && PermissionUtils.hasPermission(e.getPlayer(), "taboolib.unbreakable")) {
e.setCancelled(true);
-
- NBTItem nbti = new NBTItem(e.getPlayer().getItemInHand());
- nbti.setInteger("Unbreakable", 1);
- e.getPlayer().setItemInHand(nbti.getItem());
-
+ NBTItem nbt = new NBTItem(e.getPlayer().getItemInHand());
+ nbt.setInteger("Unbreakable", 1);
+ e.getPlayer().setItemInHand(nbt.getItem());
MsgUtils.send(e.getPlayer(), "Success!");
+ } else if (e.getMessage().equals("/tellrawTest") && PermissionUtils.hasPermission(e.getPlayer(), "taboolib.tellraw")) {
+ e.setCancelled(true);
+ TellrawJson.create()
+ .append("§8[§3§lTabooLib§8] §7TellrawJson Test: §f[")
+ .append(ItemUtils.getCustomName(e.getPlayer().getItemInHand())).hoverItem(e.getPlayer().getItemInHand())
+ .append("§f]")
+ .send(e.getPlayer());
}
}
}
diff --git a/src/main/java/me/skymc/taboolib/mysql/builder/SQLExample.java b/src/main/java/me/skymc/taboolib/mysql/builder/SQLExample.java
deleted file mode 100644
index e6dc79a..0000000
--- a/src/main/java/me/skymc/taboolib/mysql/builder/SQLExample.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package me.skymc.taboolib.mysql.builder;
-
-import com.zaxxer.hikari.HikariDataSource;
-import org.bukkit.plugin.java.JavaPlugin;
-
-/**
- * @Author sky
- * @Since 2018-07-02 23:43
- */
-public class SQLExample extends JavaPlugin {
-
- private SQLHost sqlHost;
- private SQLTable sqlTable;
- private HikariDataSource dataSource;
-
- @Override
- public void onEnable() {
- int value = sqlTable.executeQuery("select * from table where username = ?")
- .dataSource(dataSource)
- .statement(statement -> statement.setString(1, "BlackSKY"))
- .resultNext(result -> result.getInt("value"))
- .run(0, 0);
-
- sqlTable.executeUpdate("statement table set value = ? where username = ?")
- .dataSource(dataSource)
- .statement(statement -> {
- statement.setInt(1, 999);
- statement.setString(2, "BlackSKY");
- }).run();
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/mysql/builder/SQLHost.java b/src/main/java/me/skymc/taboolib/mysql/builder/SQLHost.java
index 13e9c15..961985d 100644
--- a/src/main/java/me/skymc/taboolib/mysql/builder/SQLHost.java
+++ b/src/main/java/me/skymc/taboolib/mysql/builder/SQLHost.java
@@ -4,7 +4,6 @@ import com.ilummc.tlib.util.Strings;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.Plugin;
-import java.text.MessageFormat;
import java.util.Objects;
/**
diff --git a/src/main/java/me/skymc/taboolib/mysql/builder/SQLTable.java b/src/main/java/me/skymc/taboolib/mysql/builder/SQLTable.java
index 22b0b91..601195d 100644
--- a/src/main/java/me/skymc/taboolib/mysql/builder/SQLTable.java
+++ b/src/main/java/me/skymc/taboolib/mysql/builder/SQLTable.java
@@ -5,8 +5,6 @@ import me.skymc.taboolib.mysql.builder.query.RunnableQuery;
import me.skymc.taboolib.mysql.builder.query.RunnableUpdate;
import me.skymc.taboolib.string.ArrayUtils;
-import javax.sql.DataSource;
-import java.sql.Connection;
import java.util.Arrays;
/**
diff --git a/src/main/java/me/skymc/taboolib/mysql/hikari/HikariHandler.java b/src/main/java/me/skymc/taboolib/mysql/hikari/HikariHandler.java
index 410c3f5..0e5f900 100644
--- a/src/main/java/me/skymc/taboolib/mysql/hikari/HikariHandler.java
+++ b/src/main/java/me/skymc/taboolib/mysql/hikari/HikariHandler.java
@@ -6,10 +6,8 @@ import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.fileutils.ConfigUtils;
-import me.skymc.taboolib.fileutils.FileUtils;
import me.skymc.taboolib.mysql.builder.SQLHost;
import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.configuration.file.YamlConfiguration;
import javax.sql.DataSource;
import java.util.concurrent.ConcurrentHashMap;