diff --git a/src/main/resources/Addons/TabooLibDeprecated b/src/main/resources/Addons/TabooLibDeprecated index bf21513..7074699 100644 Binary files a/src/main/resources/Addons/TabooLibDeprecated and b/src/main/resources/Addons/TabooLibDeprecated differ diff --git a/src/main/scala/com/ilummc/tlib/bungee/api/chat/TranslatableComponent.java b/src/main/scala/com/ilummc/tlib/bungee/api/chat/TranslatableComponent.java index 796b749..23e3864 100644 --- a/src/main/scala/com/ilummc/tlib/bungee/api/chat/TranslatableComponent.java +++ b/src/main/scala/com/ilummc/tlib/bungee/api/chat/TranslatableComponent.java @@ -69,11 +69,11 @@ public final class TranslatableComponent extends BaseComponent { * Creates a translatable component with the passed substitutions * * @param translate the translation key - * @param with the {@link java.lang.String}s and + * @param with the {@link String}s and * {@link BaseComponent}s to use into the * translation * @see #translate - * @see #setWith(java.util.List) + * @see #setWith(List) */ public TranslatableComponent(String translate, Object... with) { setTranslate(translate); diff --git a/src/main/scala/me/skymc/taboolib/Main.java b/src/main/scala/me/skymc/taboolib/Main.java index 627ab6e..bd37d87 100644 --- a/src/main/scala/me/skymc/taboolib/Main.java +++ b/src/main/scala/me/skymc/taboolib/Main.java @@ -7,6 +7,7 @@ import com.ilummc.tlib.util.IO; import com.ilummc.tlib.util.Strings; import me.skymc.taboolib.database.GlobalDataManager; import me.skymc.taboolib.database.PlayerDataManager; +import me.skymc.taboolib.economy.EcoUtils; import me.skymc.taboolib.fileutils.ConfigUtils; import me.skymc.taboolib.fileutils.FileUtils; import me.skymc.taboolib.listener.TListenerHandler; @@ -16,8 +17,6 @@ import me.skymc.taboolib.other.NumberUtils; import me.skymc.taboolib.playerdata.DataUtils; import me.skymc.taboolib.socket.TabooLibClient; import me.skymc.taboolib.socket.TabooLibServer; -import me.skymc.taboolib.string.language2.Language2; -import net.milkbowl.vault.economy.Economy; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.Plugin; @@ -45,11 +44,9 @@ public class Main extends JavaPlugin { } private static Plugin inst; - private static Economy economy; private static File playerDataFolder; private static File serverDataFolder; private static StorageType storageType = StorageType.LOCAL; - private static Language2 exampleLanguage2; private static boolean disable = false; private static boolean started = false; private static boolean isInternetOnline = false; @@ -138,8 +135,6 @@ public class Main extends JavaPlugin { }.runTask(this); // 启动 started = true; - // 载入语言文件 - exampleLanguage2 = new Language2("Language2", this); } @Override @@ -198,14 +193,6 @@ public class Main extends JavaPlugin { return "§8[§3§lTabooLib§8] §7"; } - public static net.milkbowl.vault.economy.Economy getEconomy() { - return economy; - } - - public static void setEconomy(Economy economy) { - Main.economy = economy; - } - public static File getPlayerDataFolder() { return playerDataFolder; } @@ -222,26 +209,10 @@ public class Main extends JavaPlugin { return disable; } - public static MySQLConnection getConnection() { - return null; - } - - public static Language2 getExampleLanguage2() { - return exampleLanguage2; - } - public static boolean isStarted() { return started; } - public static Random getRandom() { - return NumberUtils.getRandom(); - } - - public static String getTablePrefix() { - return inst.getConfig().getString("MYSQL.PREFIX"); - } - public static boolean isInternetOnline() { return isInternetOnline; } @@ -254,6 +225,26 @@ public class Main extends JavaPlugin { return TLib.getTLib().getLibsFolder().listFiles().length > 0; } + @Deprecated + public static Random getRandom() { + return NumberUtils.getRandom(); + } + + @Deprecated + public static String getTablePrefix() { + return inst.getConfig().getString("MYSQL.PREFIX"); + } + + @Deprecated + public static MySQLConnection getConnection() { + return null; + } + + @Deprecated + public static net.milkbowl.vault.economy.Economy getEconomy() { + return EcoUtils.getEconomy(); + } + // ********************************* // // Private Setter diff --git a/src/main/scala/me/skymc/taboolib/TabooLibLoader.java b/src/main/scala/me/skymc/taboolib/TabooLibLoader.java index 8d4ada2..8048b8f 100644 --- a/src/main/scala/me/skymc/taboolib/TabooLibLoader.java +++ b/src/main/scala/me/skymc/taboolib/TabooLibLoader.java @@ -160,11 +160,13 @@ public class TabooLibLoader implements Listener { } static void setupAddons() { - TabooLib.instance().saveResource("Addons/TabooLibDeprecated", true); + File origin = new File(TabooLib.instance().getDataFolder(), "Addons/TabooLibDeprecated.jar"); + origin.delete(); // 傻逼 Gradle 的 shadow 插件会将所有 jar 排除 // https://github.com/johnrengelman/shadow/issues/276 + TabooLib.instance().saveResource("Addons/TabooLibDeprecated", true); File from = new File(TabooLib.instance().getDataFolder(), "Addons/TabooLibDeprecated"); - from.renameTo(new File(TabooLib.instance().getDataFolder(), "Addons/TabooLibDeprecated.jar")); + from.renameTo(origin); from.delete(); File file = new File(TabooLib.instance().getDataFolder(), "Addons"); if (file.exists()) { diff --git a/src/main/scala/me/skymc/taboolib/bstats/Metrics.java b/src/main/scala/me/skymc/taboolib/bstats/Metrics.java index 3685992..89db7bf 100644 --- a/src/main/scala/me/skymc/taboolib/bstats/Metrics.java +++ b/src/main/scala/me/skymc/taboolib/bstats/Metrics.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.Callable; import java.util.logging.Level; @@ -171,7 +172,7 @@ public class Metrics { } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(outputStream); - gzip.write(str.getBytes("UTF-8")); + gzip.write(str.getBytes(StandardCharsets.UTF_8)); gzip.close(); return outputStream.toByteArray(); } @@ -262,7 +263,7 @@ public class Metrics { playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed } int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; - String bukkitVersion = org.bukkit.Bukkit.getVersion(); + String bukkitVersion = Bukkit.getVersion(); bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1); // OS/Java specific data diff --git a/src/main/scala/me/skymc/taboolib/common/serialize/DoNotSerialize.java b/src/main/scala/me/skymc/taboolib/common/serialize/DoNotSerialize.java new file mode 100644 index 0000000..cd72c13 --- /dev/null +++ b/src/main/scala/me/skymc/taboolib/common/serialize/DoNotSerialize.java @@ -0,0 +1,16 @@ +package me.skymc.taboolib.common.serialize; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @Author sky + * @Since 2018-10-05 12:11 + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface DoNotSerialize { + +} \ No newline at end of file diff --git a/src/main/scala/me/skymc/taboolib/common/serialize/TSerializable.java b/src/main/scala/me/skymc/taboolib/common/serialize/TSerializable.java index 2529adf..f57ae2a 100644 --- a/src/main/scala/me/skymc/taboolib/common/serialize/TSerializable.java +++ b/src/main/scala/me/skymc/taboolib/common/serialize/TSerializable.java @@ -1,20 +1,34 @@ package me.skymc.taboolib.common.serialize; +import java.nio.charset.StandardCharsets; +import java.util.Base64; + /** * @Author 坏黑 * @Since 2019-03-08 17:28 */ public interface TSerializable { - void read(String fieldName, String value); + default void read(String fieldName, String value) { + } - String write(String fieldName, Object value); + default String write(String fieldName, Object value) { + return null; + } - default void read(String value) { - TSerializer.read(this, value); + default Object read(String value) { + return TSerializer.read(this, value); } default String write() { return TSerializer.write(this); } + + default Object readBase64(String value) { + return TSerializer.read(this, new String(Base64.getDecoder().decode(value), StandardCharsets.UTF_8)); + } + + default String writeBase64() { + return Base64.getEncoder().encodeToString(TSerializer.write(this).getBytes(StandardCharsets.UTF_8)); + } } \ No newline at end of file diff --git a/src/main/scala/me/skymc/taboolib/common/serialize/TSerializer.java b/src/main/scala/me/skymc/taboolib/common/serialize/TSerializer.java index d89ce4b..95b385d 100644 --- a/src/main/scala/me/skymc/taboolib/common/serialize/TSerializer.java +++ b/src/main/scala/me/skymc/taboolib/common/serialize/TSerializer.java @@ -30,6 +30,9 @@ public class TSerializer { try { Field declaredField = serializable.getClass().getDeclaredField(jsonElementEntry.getKey()); declaredField.setAccessible(true); + if (declaredField.isAnnotationPresent(DoNotSerialize.class)) { + continue; + } Optional serializer = Arrays.stream(TSerializerElementGeneral.values()).filter(serializerElements -> serializerElements.getSerializer().matches(declaredField.getType())).findFirst(); if (serializer.isPresent()) { declaredField.set(serializable, serializer.get().getSerializer().read(jsonElementEntry.getValue().getAsString())); @@ -56,13 +59,13 @@ public class TSerializer { JsonObject serializeObject = new JsonObject(); for (Field declaredField : serializable.getClass().getDeclaredFields()) { try { - if (!Modifier.isStatic(declaredField.getModifiers())) { + if (!declaredField.isAnnotationPresent(DoNotSerialize.class) && !Modifier.isStatic(declaredField.getModifiers())) { declaredField.setAccessible(true); - Optional serializer = Arrays.stream(TSerializerElementGeneral.values()).filter(serializerElements -> serializerElements.getSerializer().matches(declaredField.getType())).findFirst(); Object o = declaredField.get(serializable); if (o == null) { continue; } + Optional serializer = Arrays.stream(TSerializerElementGeneral.values()).filter(serializerElements -> serializerElements.getSerializer().matches(declaredField.getType())).findFirst(); if (serializer.isPresent()) { serializeObject.addProperty(declaredField.getName(), serializer.get().getSerializer().write(o)); } else { diff --git a/src/main/scala/me/skymc/taboolib/common/serialize/TSerializerElement.java b/src/main/scala/me/skymc/taboolib/common/serialize/TSerializerElement.java index 3232eab..e660389 100644 --- a/src/main/scala/me/skymc/taboolib/common/serialize/TSerializerElement.java +++ b/src/main/scala/me/skymc/taboolib/common/serialize/TSerializerElement.java @@ -8,7 +8,7 @@ public interface TSerializerElement { T read(String value); - String write(Object value); + String write(T value); boolean matches(Class objectClass); diff --git a/src/main/scala/me/skymc/taboolib/common/serialize/TSerializerExample.java b/src/main/scala/me/skymc/taboolib/common/serialize/TSerializerExample.java index 1d5d8a5..d80333b 100644 --- a/src/main/scala/me/skymc/taboolib/common/serialize/TSerializerExample.java +++ b/src/main/scala/me/skymc/taboolib/common/serialize/TSerializerExample.java @@ -1,9 +1,11 @@ package me.skymc.taboolib.common.serialize; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import java.util.Collection; import java.util.List; +import java.util.Map; /** * @Author 坏黑 @@ -17,13 +19,13 @@ public class TSerializerExample { // 修改参数 date.number = 100; // 序列化 - String value = date.write(); + String value = date.writeBase64(); // 打印 System.out.println(value); // 创建新的对象 SimpleData dataCopy = new SimpleData(); // 反序列化 - dataCopy.read(value); + dataCopy.readBase64(value); // 打印 System.out.println(dataCopy); } @@ -38,13 +40,24 @@ public class TSerializerExample { * 基本类型不需要手动进行序列化 * 包含: String、int、short、long、double、float、boolean、ItemStack、Location */ - private String text; - private int number; + private String text = "123"; + private int number = 100; + /** * 特殊类型需要进行手动序列化 - * 本工具提供了基本容器的序列化方法 + * 标注 @TSerializeCollection 或 @TSerializeMap 来进行自动序列化(未完成) */ - private List list = Lists.newArrayList(); +// @TSerializeCollection + private List list = Lists.newArrayList(1.0, 2.0, 3.0); + +// @TSerializeMap + private Map map = ImmutableMap.of("abc", "def"); + + /** + * 跳过序列化 + */ + @DoNotSerialize + private String ignoreSerialize = "aaa"; /** * 基本类型不会执行以下两个方法 @@ -52,23 +65,16 @@ public class TSerializerExample { */ @Override public void read(String fieldName, String value) { - switch (fieldName) { - case "list": { - // List 类型可以直接通过 TSerializer 提供的预设方法进行反序列化 - TSerializer.readCollection(list, value, TSerializerElementGeneral.DOUBLE); - break; - } - default: + if (fieldName.equals("list")) { + // List 类型可以直接通过 TSerializer 提供的预设方法进行反序列化 + TSerializer.readCollection(list, value, TSerializerElementGeneral.DOUBLE); } } @Override public String write(String fieldName, Object value) { - switch (fieldName) { - case "list": { - // 序列化同理 - return TSerializer.writeCollection((Collection) value, TSerializerElementGeneral.DOUBLE); - } + if (fieldName.equals("list")) { + return TSerializer.writeCollection((Collection) value, TSerializerElementGeneral.DOUBLE); } return null; } @@ -79,6 +85,7 @@ public class TSerializerExample { "text='" + text + '\'' + ", number=" + number + ", list=" + list + + ", ignoreSerialize='" + ignoreSerialize + '\'' + '}'; } } diff --git a/src/main/scala/me/skymc/taboolib/common/serialize/container/TSerializeCollection.java b/src/main/scala/me/skymc/taboolib/common/serialize/container/TSerializeCollection.java new file mode 100644 index 0000000..8b3a3f2 --- /dev/null +++ b/src/main/scala/me/skymc/taboolib/common/serialize/container/TSerializeCollection.java @@ -0,0 +1,24 @@ +package me.skymc.taboolib.common.serialize.container; + +import me.skymc.taboolib.common.serialize.TSerializerElement; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.ArrayList; +import java.util.Collection; + +/** + * @Author sky + * @Since 2018-10-05 12:11 + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface TSerializeCollection { + + Class type() default ArrayList.class; + + Class element() default TSerializerElement.class; + +} \ No newline at end of file diff --git a/src/main/scala/me/skymc/taboolib/common/serialize/container/TSerializeMap.java b/src/main/scala/me/skymc/taboolib/common/serialize/container/TSerializeMap.java new file mode 100644 index 0000000..520d33f --- /dev/null +++ b/src/main/scala/me/skymc/taboolib/common/serialize/container/TSerializeMap.java @@ -0,0 +1,20 @@ +package me.skymc.taboolib.common.serialize.container; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.HashMap; +import java.util.Map; + +/** + * @Author sky + * @Since 2018-10-05 12:11 + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface TSerializeMap { + + Class type() default HashMap.class; + +} \ No newline at end of file diff --git a/src/main/scala/me/skymc/taboolib/listener/TListenerHandler.java b/src/main/scala/me/skymc/taboolib/listener/TListenerHandler.java index 4471817..f79bbe0 100644 --- a/src/main/scala/me/skymc/taboolib/listener/TListenerHandler.java +++ b/src/main/scala/me/skymc/taboolib/listener/TListenerHandler.java @@ -47,7 +47,7 @@ public class TListenerHandler implements Listener { */ public static void setupListener(Plugin plugin) { for (Class pluginClass : TabooLibLoader.getPluginClassSafely(plugin)) { - if (org.bukkit.event.Listener.class.isAssignableFrom(pluginClass) && pluginClass.isAnnotationPresent(TListener.class)) { + if (Listener.class.isAssignableFrom(pluginClass) && pluginClass.isAnnotationPresent(TListener.class)) { try { TListener tListener = pluginClass.getAnnotation(TListener.class); // 检查注册条件 diff --git a/src/main/scala/me/skymc/taboolib/mysql/builder/SQLColumn.java b/src/main/scala/me/skymc/taboolib/mysql/builder/SQLColumn.java index d8debe1..d154939 100644 --- a/src/main/scala/me/skymc/taboolib/mysql/builder/SQLColumn.java +++ b/src/main/scala/me/skymc/taboolib/mysql/builder/SQLColumn.java @@ -32,9 +32,7 @@ public class SQLColumn extends IColumn { /** * CHAR 类型常用构造器 - * - * @param columnType - * @param columnName + * new SQLColumn(SQLColumnType.CHAR, 1, "data"); */ public SQLColumn(SQLColumnType columnType, int m, String columnName) { this(columnType, m, 0, columnName, null); @@ -56,6 +54,10 @@ public class SQLColumn extends IColumn { this(columnType, 0, 0, columnName, defaultValue); } + public SQLColumn(SQLColumnType columnType, String columnName, Object defaultValue, SQLColumnOption... columnOptions) { + this(columnType, 0, 0, columnName, defaultValue, columnOptions); + } + /** * 完整构造器 * diff --git a/src/main/scala/me/skymc/taboolib/mysql/builder/SQLTable.java b/src/main/scala/me/skymc/taboolib/mysql/builder/SQLTable.java index 4e3412d..159e046 100644 --- a/src/main/scala/me/skymc/taboolib/mysql/builder/SQLTable.java +++ b/src/main/scala/me/skymc/taboolib/mysql/builder/SQLTable.java @@ -49,11 +49,11 @@ public class SQLTable { } public String deleteQuery() { - return Strings.replaceWithOrder("drop table if exists `{0}`" + tableName); + return Strings.replaceWithOrder("drop table if exists `{0}`", tableName); } public String cleanQuery() { - return Strings.replaceWithOrder("delete from `{0}`" + tableName); + return Strings.replaceWithOrder("delete from `{0}`", tableName); } public String truncateQuery() { diff --git a/src/main/scala/me/skymc/taboolib/mysql/builder/query/RunnableQuery.java b/src/main/scala/me/skymc/taboolib/mysql/builder/query/RunnableQuery.java index e76479f..c3f016d 100644 --- a/src/main/scala/me/skymc/taboolib/mysql/builder/query/RunnableQuery.java +++ b/src/main/scala/me/skymc/taboolib/mysql/builder/query/RunnableQuery.java @@ -19,6 +19,7 @@ public class RunnableQuery { private TaskStatement statement; private TaskResult result; private TaskResult resultNext; + private TaskResult resultAutoNext; private Connection connection; private boolean autoClose; private String query; @@ -47,6 +48,11 @@ public class RunnableQuery { return this; } + public RunnableQuery resultAutoNext(TaskResult result) { + this.resultAutoNext = result; + return this; + } + public RunnableQuery connection(Connection connection) { return connection(connection, false); } @@ -113,6 +119,12 @@ public class RunnableQuery { return resultNext.execute(resultSet); } else if (result != null) { return result.execute(resultSet); + } else if (resultAutoNext != null) { + Object result = null; + while (resultSet.next()) { + result = resultAutoNext.execute(resultSet); + } + return result; } else { return null; } diff --git a/src/main/scala/me/skymc/taboolib/mysql/sqlite/SQLiteColumn.java b/src/main/scala/me/skymc/taboolib/mysql/sqlite/SQLiteColumn.java index 4b7098b..c28cf07 100644 --- a/src/main/scala/me/skymc/taboolib/mysql/sqlite/SQLiteColumn.java +++ b/src/main/scala/me/skymc/taboolib/mysql/sqlite/SQLiteColumn.java @@ -30,16 +30,6 @@ public class SQLiteColumn extends IColumn { this(columnType, 0, 0, columnName, null); } - /** - * CHAR 类型常用构造器 - * - * @param columnType - * @param columnName - */ - public SQLiteColumn(SQLiteColumnType columnType, int m, String columnName) { - this(columnType, m, 0, columnName, null); - } - /** * 主键 类型常用构造器 * new SQLColumn(SQLiteColumnType.TEXT, "username", SQLiteColumnOption.PRIMARY_KEY, SQLiteColumnOption.AUTO_INCREMENT); @@ -56,6 +46,10 @@ public class SQLiteColumn extends IColumn { this(columnType, 0, 0, columnName, defaultValue); } + public SQLiteColumn(SQLiteColumnType columnType, String columnName, Object defaultValue, SQLiteColumnOption... columnOptions) { + this(columnType, 0, 0, columnName, defaultValue, columnOptions); + } + /** * 完整构造器 * diff --git a/src/main/scala/me/skymc/taboolib/sound/SoundPack.java b/src/main/scala/me/skymc/taboolib/sound/SoundPack.java index aad0c6c..255914c 100644 --- a/src/main/scala/me/skymc/taboolib/sound/SoundPack.java +++ b/src/main/scala/me/skymc/taboolib/sound/SoundPack.java @@ -9,8 +9,8 @@ import org.bukkit.entity.Player; public class SoundPack { private Sound sound; - private float a; - private float b; + private Float a; + private Float b; private int delay; /** @@ -70,11 +70,11 @@ public class SoundPack { return sound; } - public float getA() { + public Float getA() { return a; } - public float getB() { + public Float getB() { return b; }