From b49a779859fc50806fbd058df8fedccafa2683bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Sun, 22 Apr 2018 22:12:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ilummc/tlib/ExampleMain.java | 5 +- src/main/java/com/ilummc/tlib/TLib.java | 117 +++++------ .../com/ilummc/tlib/annotations/Config.java | 4 +- .../ilummc/tlib/annotations/Dependency.java | 8 +- .../com/ilummc/tlib/annotations/Logger.java | 4 +- .../ilummc/tlib/bean/PropertyTypeAdaptor.java | 4 +- .../ilummc/tlib/compat/PlaceholderHook.java | 41 ++++ .../com/ilummc/tlib/config/TLibConfig.java | 23 +++ .../ilummc/tlib/dependency/TDependency.java | 27 +-- .../tlib/dependency/TDependencyLoader.java | 4 +- .../com/ilummc/tlib/filter/TLoggerFilter.java | 32 ++++ .../ilummc/tlib/inject/TConfigInjector.java | 36 ++-- .../ilummc/tlib/inject/TConfigWatcher.java | 11 +- .../tlib/inject/TDependencyInjector.java | 173 +++++++++++++++++ .../ilummc/tlib/inject/TPluginManager.java | 181 ++++++++++++++++++ .../com/ilummc/tlib/resources/TLocale.java | 71 ++++--- .../tlib/resources/TLocaleInstance.java | 98 ++++++++++ .../ilummc/tlib/resources/TLocaleLoader.java | 104 ++++++++++ .../tlib/resources/TLocaleSendable.java | 25 +++ .../tlib/resources/type/TLocaleText.java | 107 +++++++++++ .../tlib/resources/type/TLocaleTitle.java | 83 ++++++++ src/main/java/com/ilummc/tlib/util/Ref.java | 30 ++- .../java/com/ilummc/tlib/util/TLogger.java | 20 +- .../com/ilummc/tlib/util/asm/AsmAnalyser.java | 6 +- src/main/java/me/skymc/taboolib/Main.java | 28 ++- src/main/java/me/skymc/taboolib/TabooLib.java | 78 ++------ .../taboolib/anvil/AnvilContainerAPI.java | 9 +- .../versions/AnvilContainer_V1_11_R1.java | 8 +- .../versions/AnvilContainer_V1_8_R3.java | 8 +- .../anvil/versions/AnvilContainer_V1_9_4.java | 8 +- .../bookformatter/BookAchievement.java | 37 +++- .../taboolib/bookformatter/BookFormatter.java | 6 +- .../bookformatter/BookReflection.java | 19 +- .../me/skymc/taboolib/bstats/Metrics.java | 33 ++-- .../skymc/taboolib/commands/MainCommands.java | 23 ++- .../locale/TabooLibLocaleCommand.java | 75 ++++++++ .../commands/sub/AttributesCommand.java | 5 +- .../taboolib/commands/sub/HelpCommand.java | 15 +- .../taboolib/commands/sub/InfoCommand.java | 7 +- .../taboolib/commands/sub/SaveCommand.java | 2 +- .../taboolib/commands/sub/SlotCommand.java | 5 +- .../commands/sub/TagDeleteCommand.java | 7 +- .../commands/sub/cycle/CycleCommand.java | 3 +- .../commands/sub/cycle/CycleInfoCommand.java | 7 +- .../commands/sub/cycle/CycleListCommand.java | 5 +- .../sub/cycle/CycleUpdateCommand.java | 7 +- .../itemlist/listener/ItemLibraryPatch.java | 13 +- .../commands/sub/shell/ShellCommand.java | 3 +- .../sounds/listener/SoundsLibraryPatch.java | 9 +- .../taboolib/cooldown/CooldownUtils.java | 5 +- .../cooldown/seconds/CooldownUtils2.java | 4 +- .../me/skymc/taboolib/csvutils/CsvReader.java | 10 +- .../me/skymc/taboolib/csvutils/CsvWriter.java | 7 +- .../me/skymc/taboolib/damage/DamageUtils.java | 5 +- .../taboolib/database/GlobalDataManager.java | 15 +- .../taboolib/database/PlayerDataManager.java | 21 +- .../skymc/taboolib/display/ActionUtils.java | 5 +- .../me/skymc/taboolib/display/TitleUtils.java | 4 +- .../me/skymc/taboolib/entity/EntityTag.java | 9 +- .../taboolib/events/CustomBookOpenEvent.java | 5 +- .../skymc/taboolib/events/DefaultEvent2.java | 7 +- .../skymc/taboolib/fileutils/ConfigUtils.java | 23 ++- .../skymc/taboolib/fileutils/EncodeUtils.java | 9 +- .../skymc/taboolib/fileutils/FileUtils.java | 36 ++-- .../me/skymc/taboolib/fileutils/LogUtils.java | 9 +- .../skymc/taboolib/inventory/DropUtils.java | 3 +- .../taboolib/inventory/InventoryUtil.java | 6 +- .../skymc/taboolib/inventory/ItemUtils.java | 33 ++-- .../inventory/speciaitem/SpecialItem.java | 13 +- .../itemnbtapi/NBTReflectionUtil.java | 19 +- .../taboolib/javascript/JavaScriptUtils.java | 9 +- .../skymc/taboolib/javashell/JavaShell.java | 21 +- .../taboolib/javashell/utils/JarUtils.java | 15 +- .../me/skymc/taboolib/json/JSONObject.java | 8 +- .../me/skymc/taboolib/json/JSONTokener.java | 7 +- .../taboolib/jsonformatter/JSONFormatter.java | 19 +- .../jsonformatter/hover/ShowItemEvent.java | 17 +- .../listener/ListenerPlayerCommand.java | 11 +- .../taboolib/listener/ListenerPlayerJump.java | 5 +- .../taboolib/listener/ListenerPlayerQuit.java | 3 +- .../listener/ListenerPluginDisable.java | 15 +- .../skymc/taboolib/message/ChatCatcher.java | 7 +- .../taboolib/methods/ReflectionUtils.java | 4 +- .../skymc/taboolib/mysql/MysqlConnection.java | 6 +- .../me/skymc/taboolib/mysql/MysqlUtils.java | 9 +- .../mysql/protect/MySQLConnection.java | 17 +- .../java/me/skymc/taboolib/nms/NMSUtil18.java | 26 +-- .../java/me/skymc/taboolib/nms/NMSUtil19.java | 26 ++- .../java/me/skymc/taboolib/nms/NMSUtils.java | 4 +- .../skymc/taboolib/nms/item/DabItemUtils.java | 19 +- .../taboolib/nms/item/IDabItemUtils.java | 9 +- .../taboolib/nms/item/impl/_164ItemUtils.java | 26 ++- .../nms/item/impl/_1710ItemUtils.java | 26 ++- .../taboolib/nms/item/impl/_194ItemUtils.java | 25 ++- .../me/skymc/taboolib/other/WeightUtils.java | 4 +- .../me/skymc/taboolib/packet/PacketUtils.java | 5 +- .../me/skymc/taboolib/particle/EffLib.java | 19 +- .../taboolib/permission/PermissionUtils.java | 5 +- .../skymc/taboolib/playerdata/DataUtils.java | 19 +- .../me/skymc/taboolib/plugin/PluginUtils.java | 33 ++-- .../skymc/taboolib/regen/WorldGuardUtils.java | 7 +- .../taboolib/scoreboard/ScoreboardUtil.java | 10 +- .../skymc/taboolib/skript/SkriptHandler.java | 5 +- .../expression/ExpressionTabooCodeItem.java | 5 +- .../me/skymc/taboolib/string/Language.java | 18 +- .../skymc/taboolib/string/LanguageUtils.java | 7 +- .../string/language2/Language2Format.java | 17 +- .../string/language2/Language2Value.java | 13 +- .../language2/value/Language2Action.java | 13 +- .../string/language2/value/Language2Book.java | 25 +-- .../string/language2/value/Language2Json.java | 15 +- .../language2/value/Language2Json2.java | 25 +-- .../string/language2/value/Language2Text.java | 11 +- .../language2/value/Language2Title.java | 11 +- .../taboolib/support/SupportPlaceholder.java | 5 +- .../taboolib/support/SupportWorldGuard.java | 9 +- .../me/skymc/taboolib/team/TagManager.java | 9 +- .../taboolib/timecycle/TimeCycleManager.java | 15 +- .../me/skymc/taboolib/update/UpdateTask.java | 18 +- src/main/java/me/skymc/tlm/TLM.java | 3 +- .../skymc/tlm/annotation/DisableConfig.java | 6 +- .../skymc/tlm/command/sub/TLMKitCommand.java | 13 +- .../skymc/tlm/module/TabooLibraryModule.java | 11 +- .../me/skymc/tlm/module/sub/ModuleKits.java | 13 +- .../skymc/tlm/module/sub/ModuleTimeCycle.java | 11 +- src/main/resources/config.yml | 5 +- 126 files changed, 1896 insertions(+), 705 deletions(-) create mode 100644 src/main/java/com/ilummc/tlib/compat/PlaceholderHook.java create mode 100644 src/main/java/com/ilummc/tlib/config/TLibConfig.java create mode 100644 src/main/java/com/ilummc/tlib/filter/TLoggerFilter.java create mode 100644 src/main/java/com/ilummc/tlib/inject/TDependencyInjector.java create mode 100644 src/main/java/com/ilummc/tlib/inject/TPluginManager.java create mode 100644 src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java create mode 100644 src/main/java/com/ilummc/tlib/resources/TLocaleLoader.java create mode 100644 src/main/java/com/ilummc/tlib/resources/TLocaleSendable.java create mode 100644 src/main/java/com/ilummc/tlib/resources/type/TLocaleText.java create mode 100644 src/main/java/com/ilummc/tlib/resources/type/TLocaleTitle.java create mode 100644 src/main/java/me/skymc/taboolib/commands/locale/TabooLibLocaleCommand.java diff --git a/src/main/java/com/ilummc/tlib/ExampleMain.java b/src/main/java/com/ilummc/tlib/ExampleMain.java index ed4022f..3ac4877 100644 --- a/src/main/java/com/ilummc/tlib/ExampleMain.java +++ b/src/main/java/com/ilummc/tlib/ExampleMain.java @@ -1,9 +1,10 @@ package com.ilummc.tlib; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + import com.ilummc.tlib.annotations.Config; import com.ilummc.tlib.bean.Property; -import org.bukkit.Bukkit; -import org.bukkit.plugin.java.JavaPlugin; @Config(name = "cfg.yml", charset = "GBK") public class ExampleMain extends JavaPlugin { diff --git a/src/main/java/com/ilummc/tlib/TLib.java b/src/main/java/com/ilummc/tlib/TLib.java index a235b22..4b5514b 100644 --- a/src/main/java/com/ilummc/tlib/TLib.java +++ b/src/main/java/com/ilummc/tlib/TLib.java @@ -1,105 +1,76 @@ package com.ilummc.tlib; -import com.ilummc.tlib.annotations.Config; -import com.ilummc.tlib.annotations.Dependency; -import com.ilummc.tlib.annotations.Logger; -import com.ilummc.tlib.compat.PlaceholderApiHook; -import com.ilummc.tlib.inject.DependencyInjector; -import com.ilummc.tlib.inject.TConfigWatcher; -import com.ilummc.tlib.inject.TLibPluginManager; -import com.ilummc.tlib.resources.LocaleLoader; -import com.ilummc.tlib.resources.TLocale; -import com.ilummc.tlib.util.TLogger; -import me.skymc.taboolib.Main; -import org.bukkit.Bukkit; - import java.io.File; import java.lang.reflect.Field; +import org.bukkit.Bukkit; + +import com.ilummc.tlib.annotations.Dependency; +import com.ilummc.tlib.compat.PlaceholderHook; +import com.ilummc.tlib.config.TLibConfig; +import com.ilummc.tlib.filter.TLoggerFilter; +import com.ilummc.tlib.inject.TConfigWatcher; +import com.ilummc.tlib.inject.TDependencyInjector; +import com.ilummc.tlib.inject.TPluginManager; +import com.ilummc.tlib.resources.TLocaleLoader; +import com.ilummc.tlib.util.TLogger; + +import lombok.Getter; +import me.skymc.taboolib.Main; + @Dependency(type = Dependency.Type.LIBRARY, maven = "org.ow2.asm:asm:6.1.1") @Dependency(type = Dependency.Type.LIBRARY, maven = "com.zaxxer:HikariCP:3.1.0") @Dependency(type = Dependency.Type.LIBRARY, maven = "org.slf4j:slf4j-api:1.7.25") public class TLib { + @Getter private static TLib tLib; - @Logger("§8[§3§lTabooLib§8][§r{1}§8] §f{2}") - private TLogger tLogger = new TLogger("§8[§3§lTabooLib§8][§r{1}§8] §f{2}", Main.getInst(), TLogger.FINE); + @Getter + private TLogger logger = new TLogger("§8[§3§lTabooLib§8][§r{1}§8] §f{2}", Main.getInst(), TLogger.FINE); + @Getter private TLibConfig config; + @Getter private TConfigWatcher configWatcher = new TConfigWatcher(); + + @Getter + private File libsFolder; private TLib() { - } - - public TLibConfig getConfig() { - return config; - } - - public TLogger getLogger() { - return tLogger; - } - - public TConfigWatcher getConfigWatcher() { - return configWatcher; - } - - public static TLib getTLib() { - return tLib; - } - - public static void injectPluginManager() { - // 注入 PluginLoader 用于加载依赖 - try { - Field field = Bukkit.getServer().getClass().getDeclaredField("pluginManager"); - field.setAccessible(true); - field.set(Bukkit.getServer(), new TLibPluginManager()); - } catch (NoSuchFieldException | IllegalAccessException e) { - e.printStackTrace(); - } + libsFolder = new File(Main.getInst().getDataFolder(), "/libs"); + if (!libsFolder.exists()) { + libsFolder.mkdirs(); + } } public static void init() { - new File(Main.getInst().getDataFolder(), "/libs").mkdirs(); tLib = new TLib(); - LocaleLoader.init(); - PlaceholderApiHook.init(); - DependencyInjector.inject(Main.getInst(), tLib); - if (Bukkit.getPluginManager() instanceof TLibPluginManager) + + TLoggerFilter.init(); + TLocaleLoader.init(); + PlaceholderHook.init(); + TDependencyInjector.inject(Main.getInst(), tLib); + + if (Bukkit.getPluginManager() instanceof TPluginManager) { tLib.getLogger().info("注入成功"); - else + } else { tLib.getLogger().fatal("注入失败"); - TLocale.sendToConsole("test1"); - TLocale.sendToConsole("test2"); - TLocale.sendToConsole("test3"); - TLocale.sendToConsole("test4.node1", "Hello", "world"); + } } public static void unload() { tLib.getConfigWatcher().unregisterAll(); - DependencyInjector.eject(Main.getInst(), tLib); + TDependencyInjector.eject(Main.getInst(), tLib); } - - @Config(name = "tlib.yml", listenChanges = true, readOnly = false) - public static class TLibConfig { - - private int downloadPoolSize = 4; - - public int getDownloadPoolSize() { - return downloadPoolSize; - } - - private String[] locale = {"zh_CN", "en_US"}; - - public String[] getLocale() { - return locale; - } - - private boolean enablePapiByDefault = false; - - public boolean isEnablePapiByDefault() { - return enablePapiByDefault; + + public static void injectPluginManager() { + try { + Field field = Bukkit.getServer().getClass().getDeclaredField("pluginManager"); + field.setAccessible(true); + field.set(Bukkit.getServer(), new TPluginManager()); + } catch (NoSuchFieldException | IllegalAccessException ignored) { } } } diff --git a/src/main/java/com/ilummc/tlib/annotations/Config.java b/src/main/java/com/ilummc/tlib/annotations/Config.java index 62af121..87b6aa3 100644 --- a/src/main/java/com/ilummc/tlib/annotations/Config.java +++ b/src/main/java/com/ilummc/tlib/annotations/Config.java @@ -1,13 +1,13 @@ package com.ilummc.tlib.annotations; -import com.ilummc.tlib.util.Ref; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Modifier; +import com.ilummc.tlib.util.Ref; + @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface Config { diff --git a/src/main/java/com/ilummc/tlib/annotations/Dependency.java b/src/main/java/com/ilummc/tlib/annotations/Dependency.java index 9c706c9..0f00aca 100644 --- a/src/main/java/com/ilummc/tlib/annotations/Dependency.java +++ b/src/main/java/com/ilummc/tlib/annotations/Dependency.java @@ -1,8 +1,12 @@ package com.ilummc.tlib.annotations; -import com.ilummc.tlib.dependency.TDependency; +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; -import java.lang.annotation.*; +import com.ilummc.tlib.dependency.TDependency; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) diff --git a/src/main/java/com/ilummc/tlib/annotations/Logger.java b/src/main/java/com/ilummc/tlib/annotations/Logger.java index bec8bc5..af54460 100644 --- a/src/main/java/com/ilummc/tlib/annotations/Logger.java +++ b/src/main/java/com/ilummc/tlib/annotations/Logger.java @@ -1,12 +1,12 @@ package com.ilummc.tlib.annotations; -import com.ilummc.tlib.util.TLogger; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import com.ilummc.tlib.util.TLogger; + @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface Logger { diff --git a/src/main/java/com/ilummc/tlib/bean/PropertyTypeAdaptor.java b/src/main/java/com/ilummc/tlib/bean/PropertyTypeAdaptor.java index f802433..0a52b19 100644 --- a/src/main/java/com/ilummc/tlib/bean/PropertyTypeAdaptor.java +++ b/src/main/java/com/ilummc/tlib/bean/PropertyTypeAdaptor.java @@ -1,12 +1,12 @@ package com.ilummc.tlib.bean; +import java.lang.reflect.Type; + import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; -import java.lang.reflect.Type; - public class PropertyTypeAdaptor implements JsonDeserializer { @Override diff --git a/src/main/java/com/ilummc/tlib/compat/PlaceholderHook.java b/src/main/java/com/ilummc/tlib/compat/PlaceholderHook.java new file mode 100644 index 0000000..520044e --- /dev/null +++ b/src/main/java/com/ilummc/tlib/compat/PlaceholderHook.java @@ -0,0 +1,41 @@ +package com.ilummc.tlib.compat; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.clip.placeholderapi.PlaceholderAPI; + +public abstract class PlaceholderHook { + + private static PlaceholderHook impl; + + public static void init() { + if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) + impl = new PlaceholderImpl(); + else impl = new AbstractImpl(); + } + + public static String replace(CommandSender sender, String text) { + return sender instanceof Player ? impl.replace(((Player) sender), text) : text; + } + + abstract String replace(Player player, String text); + + private static class PlaceholderImpl extends PlaceholderHook { + + @Override + String replace(Player player, String text) { + return PlaceholderAPI.setPlaceholders(player, text); + } + } + + private static class AbstractImpl extends PlaceholderHook { + + @Override + String replace(Player player, String text) { + return text; + } + } + +} diff --git a/src/main/java/com/ilummc/tlib/config/TLibConfig.java b/src/main/java/com/ilummc/tlib/config/TLibConfig.java new file mode 100644 index 0000000..744d9f0 --- /dev/null +++ b/src/main/java/com/ilummc/tlib/config/TLibConfig.java @@ -0,0 +1,23 @@ +package com.ilummc.tlib.config; + +import com.ilummc.tlib.annotations.Config; + +/** + * @author sky + * @since 2018-04-22 14:31:11 + */ +@Config(name = "tlib.yml", listenChanges = true, readOnly = false) +public class TLibConfig { + + private String[] locale = {"zh_CN", "en_US"}; + + public String[] getLocale() { + return locale; + } + + private boolean enablePlaceholderHookByDefault = false; + + public boolean isEnablePlaceholderHookByDefault() { + return enablePlaceholderHookByDefault; + } +} diff --git a/src/main/java/com/ilummc/tlib/dependency/TDependency.java b/src/main/java/com/ilummc/tlib/dependency/TDependency.java index ab8b631..61e86a1 100644 --- a/src/main/java/com/ilummc/tlib/dependency/TDependency.java +++ b/src/main/java/com/ilummc/tlib/dependency/TDependency.java @@ -1,12 +1,13 @@ package com.ilummc.tlib.dependency; +import java.io.File; +import java.util.concurrent.atomic.AtomicBoolean; + import com.ilummc.eagletdl.EagletTask; import com.ilummc.eagletdl.ProgressEvent; import com.ilummc.tlib.TLib; -import me.skymc.taboolib.Main; -import java.io.File; -import java.util.concurrent.atomic.AtomicBoolean; +import me.skymc.taboolib.Main; public class TDependency { @@ -43,8 +44,9 @@ public class TDependency { if (downloadMaven(repo, arr[0], arr[1], arr[2], file, url)) { TDependencyLoader.addToPath(Main.getInst(), file); return true; - } else + } else { return false; + } } } return false; @@ -60,14 +62,10 @@ public class TDependency { new EagletTask() .url(link) .file(target) - .setThreads(TLib.getTLib().getConfig().getDownloadPoolSize()) - .setOnError(event -> { - }) - .setOnConnected(event -> TLib.getTLib().getLogger().info(" 正在下载 " + String.join(":", - new String[]{groupId, artifactId, version}) + - " 大小 " + ProgressEvent.format(event.getContentLength()))) - .setOnProgress(event -> TLib.getTLib().getLogger().info(" 下载速度 " + event.getSpeedFormatted() - + " 进度 " + event.getPercentageFormatted())) + .setThreads(getDownloadPoolSize()) + .setOnError(event -> {}) + .setOnConnected(event -> TLib.getTLib().getLogger().info(" 正在下载 " + String.join(":", new String[]{groupId, artifactId, version}) + " 大小 " + ProgressEvent.format(event.getContentLength()))) + .setOnProgress(event -> TLib.getTLib().getLogger().info(" 下载速度 " + event.getSpeedFormatted() + " 进度 " + event.getPercentageFormatted())) .setOnComplete(event -> { if (event.isSuccess()) { TLib.getTLib().getLogger().info(" 下载 " + String.join(":", new String[]{groupId, artifactId, version}) + " 完成"); @@ -79,5 +77,8 @@ public class TDependency { }).start().waitUntil(); return !failed.get(); } - + + private static int getDownloadPoolSize() { + return Main.getInst().getConfig().contains("DOWNLOAD-POOL-SIZE") ? Main.getInst().getConfig().getInt("DOWNLOAD-POOL-SIZE") : 4; + } } diff --git a/src/main/java/com/ilummc/tlib/dependency/TDependencyLoader.java b/src/main/java/com/ilummc/tlib/dependency/TDependencyLoader.java index 3c52502..3db37f7 100644 --- a/src/main/java/com/ilummc/tlib/dependency/TDependencyLoader.java +++ b/src/main/java/com/ilummc/tlib/dependency/TDependencyLoader.java @@ -1,7 +1,5 @@ package com.ilummc.tlib.dependency; -import org.bukkit.plugin.Plugin; - import java.io.File; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -9,6 +7,8 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import org.bukkit.plugin.Plugin; + public class TDependencyLoader { public static synchronized void addToPath(Plugin plugin, URL url) { diff --git a/src/main/java/com/ilummc/tlib/filter/TLoggerFilter.java b/src/main/java/com/ilummc/tlib/filter/TLoggerFilter.java new file mode 100644 index 0000000..a3db470 --- /dev/null +++ b/src/main/java/com/ilummc/tlib/filter/TLoggerFilter.java @@ -0,0 +1,32 @@ +package com.ilummc.tlib.filter; + +import java.util.Arrays; +import java.util.logging.Filter; +import java.util.logging.LogRecord; + +import org.bukkit.Bukkit; + +/** + * @author Bkm016 + * @since 2018-04-22 + */ +public class TLoggerFilter implements Filter { + + public static void init() { + Bukkit.getLogger().setFilter(new TLoggerFilter()); + } + + @Override + public boolean isLoggable(LogRecord e) { + if (e.getMessage().contains("Cannot load configuration from stream")) { + StackTraceElement[] elements = Thread.currentThread().getStackTrace(); + for (StackTraceElement element : elements) { + if (element.getClassName().contains("ConfigUtils")) { + System.out.println(Arrays.asList(e.getParameters())); + } + } + return false; + } + return true; + } +} diff --git a/src/main/java/com/ilummc/tlib/inject/TConfigInjector.java b/src/main/java/com/ilummc/tlib/inject/TConfigInjector.java index 7a14c74..e2cbd02 100644 --- a/src/main/java/com/ilummc/tlib/inject/TConfigInjector.java +++ b/src/main/java/com/ilummc/tlib/inject/TConfigInjector.java @@ -1,5 +1,25 @@ package com.ilummc.tlib.inject; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Field; +import java.nio.charset.Charset; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.Validate; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.configuration.serialization.ConfigurationSerializable; +import org.bukkit.configuration.serialization.ConfigurationSerialization; +import org.bukkit.plugin.Plugin; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; + import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.io.Files; @@ -9,24 +29,10 @@ import com.google.gson.annotations.SerializedName; import com.ilummc.tlib.TLib; import com.ilummc.tlib.annotations.Config; import com.ilummc.tlib.bean.Property; -import org.apache.commons.lang3.Validate; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.configuration.serialization.ConfigurationSerializable; -import org.bukkit.configuration.serialization.ConfigurationSerialization; -import org.bukkit.plugin.Plugin; -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Field; -import java.nio.charset.Charset; -import java.util.*; -import java.util.stream.Collectors; public class TConfigInjector { - public static void fixUnicode(YamlConfiguration configuration) { + public static void fixUnicode(FileConfiguration configuration) { try { Field field = YamlConfiguration.class.getDeclaredField("yamlOptions"); field.setAccessible(true); diff --git a/src/main/java/com/ilummc/tlib/inject/TConfigWatcher.java b/src/main/java/com/ilummc/tlib/inject/TConfigWatcher.java index 8327b96..bfb013c 100644 --- a/src/main/java/com/ilummc/tlib/inject/TConfigWatcher.java +++ b/src/main/java/com/ilummc/tlib/inject/TConfigWatcher.java @@ -1,11 +1,12 @@ package com.ilummc.tlib.inject; -import com.ilummc.tlib.TLib; -import org.apache.commons.lang3.tuple.Triple; - import java.io.File; import java.io.IOException; -import java.nio.file.*; +import java.nio.file.FileSystems; +import java.nio.file.StandardWatchEventKinds; +import java.nio.file.WatchEvent; +import java.nio.file.WatchKey; +import java.nio.file.WatchService; import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -14,6 +15,8 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; +import org.apache.commons.lang3.tuple.Triple; + public class TConfigWatcher { private ScheduledExecutorService service = Executors.newScheduledThreadPool(1); diff --git a/src/main/java/com/ilummc/tlib/inject/TDependencyInjector.java b/src/main/java/com/ilummc/tlib/inject/TDependencyInjector.java new file mode 100644 index 0000000..da78271 --- /dev/null +++ b/src/main/java/com/ilummc/tlib/inject/TDependencyInjector.java @@ -0,0 +1,173 @@ +package com.ilummc.tlib.inject; + +import java.io.File; +import java.lang.reflect.Field; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import com.ilummc.tlib.TLib; +import com.ilummc.tlib.annotations.Config; +import com.ilummc.tlib.annotations.Dependencies; +import com.ilummc.tlib.annotations.Dependency; +import com.ilummc.tlib.annotations.Logger; +import com.ilummc.tlib.annotations.PluginInstance; +import com.ilummc.tlib.dependency.TDependency; +import com.ilummc.tlib.resources.TLocaleLoader; +import com.ilummc.tlib.util.Ref; +import com.ilummc.tlib.util.TLogger; + +public class TDependencyInjector { + + public static void inject(Plugin plugin, Object o) { + injectDependencies(plugin, o); + injectLogger(plugin, o); + injectConfig(plugin, o); + injectPluginInstance(plugin, o); + TLocaleLoader.load(plugin, true); + } + + static void injectOnEnable(Plugin plugin) { + inject(plugin, plugin); + } + + static void onDisable(Plugin plugin) { + eject(plugin, plugin); + } + + public static void eject(Plugin plugin, Object o) { + try { + ejectConfig(plugin, o); + } catch (Throwable ignored) { + } + } + + private static void ejectConfig(Plugin plugin, Object o) { + for (Field field : Ref.getDeclaredFields(o.getClass())) { + Config config; + if ((config = field.getType().getAnnotation(Config.class)) != null && config.saveOnExit()) { + try { + field.setAccessible(true); + TConfigInjector.saveConfig(plugin, field.get(o)); + TLib.getTLib().getLogger().info("插件 " + plugin + " 的配置 " + config.name() + " 已保存"); + } catch (Exception e) { + TLib.getTLib().getLogger().warn("插件 " + plugin + " 的配置 " + config.name() + " 保存失败"); + e.printStackTrace(); + } + } + } + } + + private static void injectConfig(Plugin plugin, Object o) { + for (Field field : Ref.getDeclaredFields(o.getClass())) { + try { + Config config; + if ((config = field.getType().getAnnotation(Config.class)) != null) { + field.setAccessible(true); + Object obj = TConfigInjector.loadConfig(plugin, field.getType()); + if (obj != null) { + TLib.getTLib().getLogger().info("插件 " + plugin.getName() + " 的 " + config.name() + " 配置文件成功加载"); + field.set(o, obj); + if (config.listenChanges()) { + TLib.getTLib().getLogger().info("开始监听插件 " + plugin.getName() + " 的 " + config.name() + " 配置文件"); + TLib.getTLib().getConfigWatcher().addOnListen( + new File(plugin.getDataFolder(), config.name()), + obj, + object -> { + try { + Object newObj = TConfigInjector.loadConfig(plugin, object.getClass()); + for (Field f : newObj.getClass().getDeclaredFields()) { + f.setAccessible(true); + f.set(obj, f.get(newObj)); + } + TLib.getTLib().getLogger().info("插件 " + plugin.getName() + " 的 " + config.name() + " 配置文件成功重载"); + } catch (Exception ignored) { + TLib.getTLib().getLogger().warn("插件 " + plugin.getName() + " 的 " + config.name() + " 配置文件重载时发生错误"); + } + } + ); + } + } + } + } catch (Exception ignored) { + } + } + } + + private static void injectLogger(Plugin plugin, Object o) { + for (Field field : Ref.getDeclaredFields(o.getClass())) { + try { + Logger logger; + if ((logger = field.getAnnotation(Logger.class)) != null) { + field.getType().asSubclass(TLogger.class); + TLogger tLogger = new TLogger(logger.value(), plugin, logger.level()); + if (!field.isAccessible()) + field.setAccessible(true); + field.set(o, tLogger); + } + } catch (Exception ignored2) { + } + } + } + + private static void injectPluginInstance(Plugin plugin, Object o) { + for (Field field : Ref.getDeclaredFields(o.getClass())) { + try { + PluginInstance instance; + if ((instance = field.getAnnotation(PluginInstance.class)) != null) { + if (!field.isAccessible()) + field.setAccessible(true); + field.getType().asSubclass(JavaPlugin.class); + Plugin pl; + if ((pl = Bukkit.getPluginManager().getPlugin(instance.value())) == null) { + if (!TDependency.requestPlugin(instance.value())) { + TLib.getTLib().getLogger().warn(plugin.getName() + " 所需的依赖插件 " + instance.value() + " 自动加载失败"); + return; + } else { + pl = Bukkit.getPluginManager().getPlugin(instance.value()); + } + } + if (pl != null) + field.set(o, pl); + } + } catch (Exception ignored) { + } + } + } + + private static void injectDependencies(Plugin plugin, Object o) { + Dependency[] dependencies = new Dependency[0]; + { + Dependencies d = o.getClass().getAnnotation(Dependencies.class); + if (d != null) { + dependencies = d.value(); + } + Dependency d2 = o.getClass().getAnnotation(Dependency.class); + if (d2 != null) { + dependencies = new Dependency[]{d2}; + } + } + if (dependencies.length != 0) { + TLib.getTLib().getLogger().info("正在加载 " + plugin.getName() + " 插件所需的依赖"); + for (Dependency dependency : dependencies) { + if (dependency.type() == Dependency.Type.PLUGIN) { + if (TDependency.requestPlugin(dependency.plugin())) { + TLib.getTLib().getLogger().info(" " + plugin.getName() + " 请求的插件 " + dependency.plugin() + " 加载成功。"); + } else { + TLib.getTLib().getLogger().warn(" " + plugin.getName() + " 请求的插件 " + dependency.plugin() + " 加载失败。"); + } + } + if (dependency.type() == Dependency.Type.LIBRARY) { + if (TDependency.requestLib(dependency.maven(), dependency.mavenRepo(), dependency.url())) { + TLib.getTLib().getLogger().info(" " + plugin.getName() + " 请求的库文件 " + String.join(":", dependency.maven()) + " 加载成功。"); + } else { + TLib.getTLib().getLogger().warn(" " + plugin.getName() + " 请求的库文件 " + String.join(":", dependency.maven()) + " 加载失败。"); + } + } + } + TLib.getTLib().getLogger().info("依赖加载完成"); + } + } + +} diff --git a/src/main/java/com/ilummc/tlib/inject/TPluginManager.java b/src/main/java/com/ilummc/tlib/inject/TPluginManager.java new file mode 100644 index 0000000..54b2318 --- /dev/null +++ b/src/main/java/com/ilummc/tlib/inject/TPluginManager.java @@ -0,0 +1,181 @@ +package com.ilummc.tlib.inject; + +import java.io.File; +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.event.Event; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.permissions.Permissible; +import org.bukkit.permissions.Permission; +import org.bukkit.plugin.EventExecutor; +import org.bukkit.plugin.InvalidDescriptionException; +import org.bukkit.plugin.InvalidPluginException; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginLoader; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.UnknownDependencyException; + +import me.skymc.taboolib.Main; + +public class TPluginManager implements PluginManager { + + private final PluginManager instance; + + private final Main main = (Main) Main.getInst(); + + public TPluginManager() { + instance = Bukkit.getPluginManager(); + } + + @Override + public void registerInterface(Class aClass) throws IllegalArgumentException { + instance.registerInterface(aClass); + } + + @Override + public Plugin getPlugin(String s) { + return instance.getPlugin(s); + } + + @Override + public Plugin[] getPlugins() { + return instance.getPlugins(); + } + + @Override + public boolean isPluginEnabled(String s) { + return instance.isPluginEnabled(s); + } + + @Override + public boolean isPluginEnabled(Plugin plugin) { + return instance.isPluginEnabled(plugin); + } + + @Override + public Plugin loadPlugin(File file) throws InvalidPluginException, InvalidDescriptionException, UnknownDependencyException { + return instance.loadPlugin(file); + } + + @Override + public Plugin[] loadPlugins(File file) { + return instance.loadPlugins(file); + } + + @Override + public void disablePlugins() { + for (Plugin plugin : getPlugins()) { + if (plugin != main) disablePlugin(plugin); + } + disablePlugin(main); + } + + @Override + public void clearPlugins() { + instance.clearPlugins(); + } + + @Override + public void callEvent(Event event) throws IllegalStateException { + instance.callEvent(event); + } + + @Override + public void registerEvents(Listener listener, Plugin plugin) { + instance.registerEvents(listener, plugin); + } + + @Override + public void registerEvent(Class aClass, Listener listener, EventPriority eventPriority, EventExecutor eventExecutor, Plugin plugin) { + instance.registerEvent(aClass, listener, eventPriority, eventExecutor, plugin); + } + + @Override + public void registerEvent(Class aClass, Listener listener, EventPriority eventPriority, EventExecutor eventExecutor, Plugin plugin, boolean b) { + instance.registerEvent(aClass, listener, eventPriority, eventExecutor, plugin, b); + } + + @Override + public void enablePlugin(Plugin plugin) { + TDependencyInjector.injectOnEnable(plugin); + instance.enablePlugin(plugin); + } + + @Override + public void disablePlugin(Plugin plugin) { + TDependencyInjector.onDisable(plugin); + instance.disablePlugin(plugin); + } + + @Override + public Permission getPermission(String s) { + return instance.getPermission(s); + } + + @Override + public void addPermission(Permission permission) { + instance.addPermission(permission); + } + + @Override + public void removePermission(Permission permission) { + instance.removePermission(permission); + } + + @Override + public void removePermission(String s) { + instance.removePermission(s); + } + + @Override + public Set getDefaultPermissions(boolean b) { + return instance.getDefaultPermissions(b); + } + + @Override + public void recalculatePermissionDefaults(Permission permission) { + instance.recalculatePermissionDefaults(permission); + } + + @Override + public void subscribeToPermission(String s, Permissible permissible) { + instance.subscribeToPermission(s, permissible); + } + + @Override + public void unsubscribeFromPermission(String s, Permissible permissible) { + instance.unsubscribeFromPermission(s, permissible); + } + + @Override + public Set getPermissionSubscriptions(String s) { + return instance.getPermissionSubscriptions(s); + } + + @Override + public void subscribeToDefaultPerms(boolean b, Permissible permissible) { + instance.subscribeToDefaultPerms(b, permissible); + } + + @Override + public void unsubscribeFromDefaultPerms(boolean b, Permissible permissible) { + instance.unsubscribeFromDefaultPerms(b, permissible); + } + + @Override + public Set getDefaultPermSubscriptions(boolean b) { + return instance.getDefaultPermSubscriptions(b); + } + + @Override + public Set getPermissions() { + return instance.getPermissions(); + } + + @Override + public boolean useTimings() { + return instance.useTimings(); + } +} diff --git a/src/main/java/com/ilummc/tlib/resources/TLocale.java b/src/main/java/com/ilummc/tlib/resources/TLocale.java index 99fc5ca..8842d60 100644 --- a/src/main/java/com/ilummc/tlib/resources/TLocale.java +++ b/src/main/java/com/ilummc/tlib/resources/TLocale.java @@ -1,54 +1,69 @@ package com.ilummc.tlib.resources; -import com.ilummc.tlib.util.Ref; +import java.lang.reflect.Field; + import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -import java.lang.reflect.Field; +import com.google.common.base.Strings; +import com.ilummc.tlib.TLib; +import com.ilummc.tlib.util.Ref; + +import me.skymc.taboolib.Main; +import me.skymc.taboolib.TabooLib; public final class TLocale { private TLocale() { throw new AssertionError(); } + + private static JavaPlugin getCallerPlugin(Class callerClass) { + try { + Field pluginField = callerClass.getClassLoader().getClass().getDeclaredField("plugin"); + pluginField.setAccessible(true); + return (JavaPlugin) pluginField.get(callerClass.getClassLoader()); + } catch (Exception ignored) { + TLib.getTLib().getLogger().error("无效的语言文件发送形式: &4" + callerClass.getName()); + } + return (JavaPlugin) Main.getInst(); + } private static void sendTo(String path, CommandSender sender, String[] args, Class callerClass) { - try { - Field pluginField = callerClass.getClassLoader().getClass().getDeclaredField("plugin"); - pluginField.setAccessible(true); - JavaPlugin plugin = (JavaPlugin) pluginField.get(callerClass.getClassLoader()); - if (args.length == 0) - LocaleLoader.sendTo(plugin, path, sender); - else - LocaleLoader.sendTo(plugin, path, sender, args); - } catch (Exception e) { - e.printStackTrace(); - } + TLocaleLoader.sendTo(getCallerPlugin(callerClass), path, sender, args); } - - public static void sendTo(String path, CommandSender sender, String... args) { - Ref.getCallerClass(3).ifPresent(clazz -> sendTo(path, sender, args, clazz)); + + private static String asString(String path, String[] args, Class callerClass) { + return TLocaleLoader.asString(getCallerPlugin(callerClass), path); } - - public static void sendTo(String path, CommandSender sender) { - Ref.getCallerClass(3).ifPresent(clazz -> sendTo(path, sender, new String[0], clazz)); + + public static void sendToConsole(String path, String... args) { + Ref.getCallerClass(3).ifPresent(clazz -> sendTo(path, Bukkit.getConsoleSender(), args, clazz)); } public static void sendTo(CommandSender sender, String path, String... args) { Ref.getCallerClass(3).ifPresent(clazz -> sendTo(path, sender, args, clazz)); } - - public static void sendTo(CommandSender sender, String path) { - Ref.getCallerClass(3).ifPresent(clazz -> sendTo(path, sender, new String[0], clazz)); + + public static void sendTo(String path, CommandSender sender, String... args) { + Ref.getCallerClass(3).ifPresent(clazz -> sendTo(path, sender, args, clazz)); } - public static void sendToConsole(String path, String... args) { - Ref.getCallerClass(3).ifPresent(clazz -> sendTo(path, Bukkit.getConsoleSender(), args, clazz)); + public static String asString(String path, String... args) { + try { + return asString(path, args, Ref.getCallerClass(3).get()); + } catch (Exception e) { + TLib.getTLib().getLogger().error("语言文件获取失败: " + path); + TLib.getTLib().getLogger().error("原因: " + e.getMessage()); + return "§4<" + path + "§4>"; + } } - - public static void sendToConsole(String path) { - Ref.getCallerClass(3).ifPresent(clazz -> sendTo(path, Bukkit.getConsoleSender(), new String[0], clazz)); + + public static void reload() { + Ref.getCallerClass(3).ifPresent(clazz -> TLocaleLoader.load(getCallerPlugin(clazz), false)); } - } diff --git a/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java b/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java new file mode 100644 index 0000000..591aa4a --- /dev/null +++ b/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java @@ -0,0 +1,98 @@ +package com.ilummc.tlib.resources; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; +import java.util.stream.Collectors; + +import javax.annotation.concurrent.ThreadSafe; + +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +import com.google.common.collect.ImmutableList; +import com.ilummc.tlib.TLib; +import com.ilummc.tlib.resources.type.TLocaleText; + +@ThreadSafe +@SuppressWarnings("rawtypes") +class TLocaleInstance { + + TLocaleInstance() { + } + + void sendTo(String path, CommandSender sender) { + try { + map.getOrDefault(path, ImmutableList.of(TLocaleSendable.getEmpty(path))).forEach(sendable -> sendable.sendTo(sender)); + } catch (Exception e) { + TLib.getTLib().getLogger().error("语言文件发送失败: " + path); + TLib.getTLib().getLogger().error("原因: " + e.getMessage()); + } + } + + void sendTo(String path, CommandSender sender, String... args) { + try { + map.getOrDefault(path, ImmutableList.of(TLocaleSendable.getEmpty(path))).forEach(sendable -> sendable.sendTo(sender, args)); + } catch (Exception e) { + TLib.getTLib().getLogger().error("语言文件发送失败: " + path); + TLib.getTLib().getLogger().error("原因: " + e.getMessage()); + } + } + + String asString(String path) { + return map.getOrDefault(path, ImmutableList.of(TLocaleSendable.getEmpty(path))).get(0).asString(); + } + + void load(FileConfiguration configuration) { + configuration.getKeys(false).forEach(s -> { + Object object = configuration.get(s); + if (object instanceof ConfigurationSection) { + loadRecursively(s, (ConfigurationSection) object); + } + else if (object instanceof TLocaleSendable) { + map.put(s, Collections.singletonList((TLocaleSendable) object)); + } + else if (object instanceof List && !((List) object).isEmpty()) { + map.put(s, ((List) object).stream().map(TO_SENDABLE).collect(Collectors.toList())); + } + else { + map.put(s, Collections.singletonList(TLocaleText.of(String.valueOf(object)))); + } + }); + } + + private static final Function TO_SENDABLE = o -> { + if (o instanceof TLocaleSendable) { + return ((TLocaleSendable) o); + } else if (o instanceof String) { + return TLocaleText.of(((String) o)); + } else { + return TLocaleText.of(String.valueOf(o)); + } + }; + + private final Map> map = new ConcurrentHashMap<>(); + + private void loadRecursively(String path, ConfigurationSection section) { + section.getKeys(false).forEach(s -> { + Object object = section.get(path + "." + s); + if (object instanceof ConfigurationSection) { + loadRecursively(path + "." + s, (ConfigurationSection) object); + } + else if (object instanceof TLocaleSendable) { + map.put(path + "." + s, Collections.singletonList((TLocaleSendable) object)); + } + else if (object instanceof List && !((List) object).isEmpty()) { + map.put(path + "." + s, ((List) object).stream().map(TO_SENDABLE).collect(Collectors.toList())); + } + else { + map.put(path + "." + s, Collections.singletonList(TLocaleText.of(String.valueOf(object)))); + } + }); + } + +} diff --git a/src/main/java/com/ilummc/tlib/resources/TLocaleLoader.java b/src/main/java/com/ilummc/tlib/resources/TLocaleLoader.java new file mode 100644 index 0000000..2397547 --- /dev/null +++ b/src/main/java/com/ilummc/tlib/resources/TLocaleLoader.java @@ -0,0 +1,104 @@ +package com.ilummc.tlib.resources; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.channels.FileChannel; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.StandardOpenOption; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.configuration.serialization.ConfigurationSerialization; +import org.bukkit.plugin.Plugin; + +import com.ilummc.tlib.TLib; +import com.ilummc.tlib.inject.TConfigInjector; +import com.ilummc.tlib.resources.type.TLocaleText; + +import me.skymc.taboolib.Main; +import me.skymc.taboolib.fileutils.ConfigUtils; +import me.skymc.taboolib.fileutils.FileUtils; + +public class TLocaleLoader { + + private static final Map map = new HashMap<>(); + + static void sendTo(Plugin plugin, String path, CommandSender sender, String... args) { + Optional.ofNullable(map.get(plugin.getName())).ifPresent(localeInstance -> localeInstance.sendTo(path, sender, args)); + } + + static String asString(Plugin plugin, String path) { + return Optional.ofNullable(map.get(plugin.getName())).get().asString(path); + } + + public static void init() { + ConfigurationSerialization.registerClass(TLocaleText.class, "TEXT"); + } + + public static void load(Plugin plugin, boolean ignoreLoaded) { + try { + if ((!ignoreLoaded || !map.containsKey(plugin.getName())) && plugin == Main.getInst() || plugin.getDescription().getDepend().contains("TabooLib") || plugin.getDescription().getSoftDepend().contains("TabooLib")) { + InputStream inputStream = null; + File file = null; + String lang = null; + for (String s : TLib.getTLib().getConfig().getLocale()) { + lang = s; + file = new File(plugin.getDataFolder(), "/lang/" + s + ".yml"); + if (file.exists()) { + inputStream = Files.newInputStream(file.toPath(), StandardOpenOption.READ); + break; + } else if ((inputStream = plugin.getClass().getResourceAsStream("/lang/" + s + ".yml")) != null) { + break; + } + } + if (inputStream == null) { + TLib.getTLib().getLogger().error("语言文件加载失败"); + return; + } + if (!file.exists()) { + file.getParentFile().mkdirs(); + file.createNewFile(); + saveResource(inputStream, file); + } + TLib.getTLib().getLogger().info("尝试加载 " + lang + ".yml 作为语言文件"); + FileConfiguration configuration = ConfigUtils.load(plugin, file); + TLocaleInstance localeInstance = new TLocaleInstance(); + localeInstance.load(configuration); + map.put(plugin.getName(), localeInstance); + TConfigInjector.fixUnicode(configuration); + TLib.getTLib().getLogger().info("成功加载 " + lang + " 语言文件"); + } + } catch (Exception e) { + TLib.getTLib().getLogger().error("载入语言文件发生异常:" + e.toString()); + } + } + + private static void saveResource(InputStream inputStream, File file) { + FileOutputStream fileOutputStream = null; + try { + byte[] data = FileUtils.read(inputStream); + fileOutputStream = new FileOutputStream(file); + fileOutputStream.write(data); + } catch (Exception e) { + TLib.getTLib().getLogger().error("资源文件写入失败: " + file); + TLib.getTLib().getLogger().error("原因: " + e.getMessage()); + } finally { + try { + if (fileOutputStream != null) { + fileOutputStream.close(); + } + } catch (Exception ignored) { + } + } + } +} diff --git a/src/main/java/com/ilummc/tlib/resources/TLocaleSendable.java b/src/main/java/com/ilummc/tlib/resources/TLocaleSendable.java new file mode 100644 index 0000000..e00b9d1 --- /dev/null +++ b/src/main/java/com/ilummc/tlib/resources/TLocaleSendable.java @@ -0,0 +1,25 @@ +package com.ilummc.tlib.resources; + +import org.bukkit.command.CommandSender; + +public interface TLocaleSendable { + + public static TLocaleSendable getEmpty(String path) { + return new TLocaleSendable() { + + @Override + public void sendTo(CommandSender sender, String... args) { + sender.sendMessage("§4<" + path + "§4>"); + } + + @Override + public String asString(String... args) { + return "§4<" + path + "§4>"; + } + }; + } + + void sendTo(CommandSender sender, String... args); + + String asString(String... args); +} diff --git a/src/main/java/com/ilummc/tlib/resources/type/TLocaleText.java b/src/main/java/com/ilummc/tlib/resources/type/TLocaleText.java new file mode 100644 index 0000000..875dbee --- /dev/null +++ b/src/main/java/com/ilummc/tlib/resources/type/TLocaleText.java @@ -0,0 +1,107 @@ +package com.ilummc.tlib.resources.type; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +import javax.annotation.concurrent.Immutable; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.serialization.ConfigurationSerializable; +import org.bukkit.configuration.serialization.SerializableAs; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import com.ilummc.tlib.TLib; +import com.ilummc.tlib.compat.PlaceholderHook; +import com.ilummc.tlib.resources.TLocaleSendable; +import com.ilummc.tlib.util.Strings; + +@Immutable +@SerializableAs("TEXT") +@SuppressWarnings({"unchecked", "rawtypes"}) +public class TLocaleText implements TLocaleSendable, ConfigurationSerializable { + + private final Object text; + + private final boolean usePlaceholder; + + private TLocaleText(Object text, boolean usePlaceholder) { + this.usePlaceholder = usePlaceholder; + if (text instanceof String) { + this.text = text; + } + else if (text instanceof List) { + this.text = ImmutableList.copyOf(((List) text)); + } + else { + throw new IllegalArgumentException("Param 'text' can only be an instance of String or String[] or List"); + } + } + + private String replaceMsg(CommandSender sender, String s) { + return usePlaceholder ? PlaceholderHook.replace(sender, s) : s; + } + + @Override + public void sendTo(CommandSender sender, String... args) { + if (text instanceof String) { + sender.sendMessage(replaceMsg(sender, Strings.replaceWithOrder((String) text, args))); + } + else if (text instanceof List) { + ((List) text).forEach(s -> sender.sendMessage(replaceMsg(sender, Strings.replaceWithOrder(String.valueOf(s), args)))); + } + } + + @Override + public String asString(String... args) { + return Strings.replaceWithOrder((String) text, args); + } + + @Override + public String toString() { + if (text instanceof String[]) { + return Arrays.toString((String[]) text); + } else { + return text.toString(); + } + } + + @Override + public Map serialize() { + if (usePlaceholder) { + return Maps.newHashMap(ImmutableMap.of("text", text, "papi", true)); + } + return Maps.newHashMap(ImmutableMap.of("text", text)); + } + + public static TLocaleText valueOf(Map map) { + if (map.containsKey("text")) { + Object object = map.get("text"); + Object objPapi = map.getOrDefault("papi", TLib.getTLib().getConfig().isEnablePlaceholderHookByDefault()); + boolean papi = objPapi instanceof Boolean ? (boolean) objPapi : objPapi instanceof String && objPapi.equals("true"); + if (object instanceof List) { + return new TLocaleText(((List) object).stream() + .map(s -> ChatColor.translateAlternateColorCodes('&', s)) + .collect(Collectors.toList()), papi); + } + else if (object instanceof String[]) { + return new TLocaleText(Arrays.stream(((String[]) object)) + .map(s -> ChatColor.translateAlternateColorCodes('&', s)) + .collect(Collectors.toList()), papi); + } + else { + return new TLocaleText(ChatColor.translateAlternateColorCodes('&', Objects.toString(object)), papi); + } + } + return new TLocaleText("§cError chat message loaded.", TLib.getTLib().getConfig().isEnablePlaceholderHookByDefault()); + } + + public static TLocaleText of(String s) { + return new TLocaleText(ChatColor.translateAlternateColorCodes('&', s), TLib.getTLib().getConfig().isEnablePlaceholderHookByDefault()); + } +} diff --git a/src/main/java/com/ilummc/tlib/resources/type/TLocaleTitle.java b/src/main/java/com/ilummc/tlib/resources/type/TLocaleTitle.java new file mode 100644 index 0000000..ee8c808 --- /dev/null +++ b/src/main/java/com/ilummc/tlib/resources/type/TLocaleTitle.java @@ -0,0 +1,83 @@ +package com.ilummc.tlib.resources.type; + +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.concurrent.Immutable; + +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.serialization.ConfigurationSerializable; +import org.bukkit.configuration.serialization.SerializableAs; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import com.ilummc.tlib.TLib; +import com.ilummc.tlib.resources.TLocaleSendable; + +import lombok.Data; +import lombok.Getter; +import net.minecraft.server.v1_11_R1.EntityEvoker.e; + +/** + * @author Bkm016 + * @since 2018-04-22 + */ + +@Immutable +@SerializableAs("TITLE") +@Data +public class TLocaleTitle implements TLocaleSendable, ConfigurationSerializable { + + private String title; + private String subtitle; + private int fadein; + private int fadeout; + private int stay; + + private boolean usePlaceholder; + + private TLocaleTitle(boolean usePlaceholder) { + this.usePlaceholder = usePlaceholder; + } + + @Override + public void sendTo(CommandSender sender, String... args) { + // TODO Auto-generated method stub + } + + @Override + public String asString(String... args) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Map serialize() { + HashMap map = Maps.newHashMap(); + map.put("papi", usePlaceholder); + map.put("title", title); + map.put("subtitle", subtitle); + map.put("fadein", fadein); + map.put("fadeout", fadeout); + map.put("stay", stay); + return map; + } + + public static TLocaleTitle valueOf(Map map) { + TLocaleTitle title; + try { + title = new TLocaleTitle((boolean) map.getOrDefault("papi", TLib.getTLib().getConfig().isEnablePlaceholderHookByDefault())); + title.setTitle((String) map.getOrDefault("title", "")); + title.setSubtitle((String) map.getOrDefault("subtitle", "")); + title.setFadein((int) map.getOrDefault("fadein", 10)); + title.setFadeout((int) map.getOrDefault("fadeout", 10)); + title.setStay((int) map.getOrDefault("stay", 10)); + } catch (Exception e) { + title = new TLocaleTitle(false); + title.setTitle("§4Load failed!"); + title.setSubtitle("§c" + e.getMessage()); + } + return title; + } + +} diff --git a/src/main/java/com/ilummc/tlib/util/Ref.java b/src/main/java/com/ilummc/tlib/util/Ref.java index 3aa0990..8e83627 100644 --- a/src/main/java/com/ilummc/tlib/util/Ref.java +++ b/src/main/java/com/ilummc/tlib/util/Ref.java @@ -1,16 +1,24 @@ package com.ilummc.tlib.util; +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +import javax.annotation.concurrent.ThreadSafe; + +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; + import com.ilummc.tlib.TLib; import com.ilummc.tlib.util.asm.AsmAnalyser; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassWriter; -import sun.reflect.Reflection; -import javax.annotation.concurrent.ThreadSafe; -import java.lang.reflect.Field; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; +import sun.reflect.Reflection; @ThreadSafe public class Ref { @@ -62,7 +70,7 @@ public class Ref { public static Optional> getCallerClass(int depth) { return Optional.ofNullable(CallerClass.impl.getCallerClass(depth + 1)); } - + private static abstract class CallerClass { private static CallerClass impl; @@ -79,7 +87,9 @@ public class Ref { abstract Class getCallerClass(int i); private static class ReflectionImpl extends CallerClass { - @Override + + @SuppressWarnings({ "deprecation", "restriction" }) + @Override Class getCallerClass(int i) { return Reflection.getCallerClass(i); } diff --git a/src/main/java/com/ilummc/tlib/util/TLogger.java b/src/main/java/com/ilummc/tlib/util/TLogger.java index 325e430..bbbe2bf 100644 --- a/src/main/java/com/ilummc/tlib/util/TLogger.java +++ b/src/main/java/com/ilummc/tlib/util/TLogger.java @@ -1,9 +1,11 @@ package com.ilummc.tlib.util; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.plugin.Plugin; + import lombok.Getter; import lombok.Setter; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; public class TLogger { @@ -27,37 +29,37 @@ public class TLogger { public void verbose(String msg) { if (level <= VERBOSE) - Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§f全部", msg)); + Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§f全部", ChatColor.translateAlternateColorCodes('&', msg))); } public void finest(String msg) { if (level <= FINEST) - Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§e良好", msg)); + Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§e良好", ChatColor.translateAlternateColorCodes('&', msg))); } public void fine(String msg) { if (level <= FINE) - Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§a正常", msg)); + Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§a正常", ChatColor.translateAlternateColorCodes('&', msg))); } public void info(String msg) { if (level <= INFO) - Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§b信息", msg)); + Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§b信息", ChatColor.translateAlternateColorCodes('&', msg))); } public void warn(String msg) { if (level <= WARN) - Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§6警告", "§6" + msg)); + Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§6警告", "§6" + ChatColor.translateAlternateColorCodes('&', msg))); } public void error(String msg) { if (level <= ERROR) - Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§c错误", "§c" + msg)); + Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§c错误", "§c" + ChatColor.translateAlternateColorCodes('&', msg))); } public void fatal(String msg) { if (level <= FATAL) - Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§4致命错误", "§4" + msg)); + Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§4致命错误", "§4" + ChatColor.translateAlternateColorCodes('&', msg))); } } diff --git a/src/main/java/com/ilummc/tlib/util/asm/AsmAnalyser.java b/src/main/java/com/ilummc/tlib/util/asm/AsmAnalyser.java index 70d6937..9a42734 100644 --- a/src/main/java/com/ilummc/tlib/util/asm/AsmAnalyser.java +++ b/src/main/java/com/ilummc/tlib/util/asm/AsmAnalyser.java @@ -1,12 +1,12 @@ package com.ilummc.tlib.util.asm; +import java.util.ArrayList; +import java.util.List; + import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Opcodes; -import java.util.ArrayList; -import java.util.List; - public class AsmAnalyser extends ClassVisitor implements Opcodes { private final List fields = new ArrayList<>(); diff --git a/src/main/java/me/skymc/taboolib/Main.java b/src/main/java/me/skymc/taboolib/Main.java index cd6b530..9dd4698 100644 --- a/src/main/java/me/skymc/taboolib/Main.java +++ b/src/main/java/me/skymc/taboolib/Main.java @@ -1,6 +1,17 @@ package me.skymc.taboolib; +import java.io.File; +import java.util.Random; + +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; + import com.ilummc.tlib.TLib; + import lombok.Getter; import lombok.Setter; import me.skymc.taboolib.anvil.AnvilContainerAPI; @@ -8,6 +19,7 @@ import me.skymc.taboolib.bstats.Metrics; import me.skymc.taboolib.client.LogClient; import me.skymc.taboolib.commands.MainCommands; import me.skymc.taboolib.commands.language.Language2Command; +import me.skymc.taboolib.commands.locale.TabooLibLocaleCommand; import me.skymc.taboolib.commands.sub.itemlist.listener.ItemLibraryPatch; import me.skymc.taboolib.commands.sub.sounds.listener.SoundsLibraryPatch; import me.skymc.taboolib.database.GlobalDataManager; @@ -18,7 +30,11 @@ import me.skymc.taboolib.fileutils.ConfigUtils; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.inventory.speciaitem.SpecialItem; import me.skymc.taboolib.javashell.JavaShell; -import me.skymc.taboolib.listener.*; +import me.skymc.taboolib.listener.ListenerNetWork; +import me.skymc.taboolib.listener.ListenerPlayerCommand; +import me.skymc.taboolib.listener.ListenerPlayerJump; +import me.skymc.taboolib.listener.ListenerPlayerQuit; +import me.skymc.taboolib.listener.ListenerPluginDisable; import me.skymc.taboolib.message.ChatCatcher; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.mysql.protect.MySQLConnection; @@ -38,15 +54,6 @@ import me.skymc.tlm.TLM; import me.skymc.tlm.command.TLMCommands; import me.skymc.tlm.module.TabooLibraryModule; import net.milkbowl.vault.economy.Economy; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.event.Listener; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitRunnable; - -import java.io.File; -import java.util.Random; @SuppressWarnings("deprecation") public class Main extends JavaPlugin implements Listener { @@ -162,6 +169,7 @@ public class Main extends JavaPlugin implements Listener { getCommand("taboolib").setExecutor(new MainCommands()); getCommand("language2").setExecutor(new Language2Command()); getCommand("taboolibrarymodule").setExecutor(new TLMCommands()); + getCommand("tabooliblocale").setExecutor(new TabooLibLocaleCommand()); // 注册监听 registerListener(); diff --git a/src/main/java/me/skymc/taboolib/TabooLib.java b/src/main/java/me/skymc/taboolib/TabooLib.java index d218a54..2f5cf19 100644 --- a/src/main/java/me/skymc/taboolib/TabooLib.java +++ b/src/main/java/me/skymc/taboolib/TabooLib.java @@ -1,42 +1,35 @@ package me.skymc.taboolib; -import me.skymc.taboolib.playerdata.DataUtils; -import net.md_5.bungee.api.ChatColor; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; - import java.util.UUID; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; + +import me.skymc.taboolib.playerdata.DataUtils; +import net.md_5.bungee.api.ChatColor; + public class TabooLib { - /** - * 获取插件版本 - * - * @return - */ + public static void debug(Plugin plugin, String... args) { + if (Main.getInst().getConfig().getBoolean("DEBUG")) { + for (String var : args) { + Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[TabooLib - DEBUG][" + plugin.getName() + "] " + ChatColor.RED + var); + } + } + } + public static double getPluginVersion() { try { return Double.valueOf(Main.getInst().getDescription().getVersion()); - } - catch (Exception e) { + } catch (Exception e) { return 0D; } } - /** - * 获取 NMS 版本 - * - * @return - */ public static String getVersion() { return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; } - /** - * 获取服务器 UID - * - * @return - */ public static String getServerUID() { if (!DataUtils.getPluginData("TabooLibrary", null).contains("serverUID")) { DataUtils.getPluginData("TabooLibrary", null).set("serverUID", UUID.randomUUID().toString()); @@ -44,53 +37,24 @@ public class TabooLib { return DataUtils.getPluginData("TabooLibrary", null).getString("serverUID"); } - /** - * 重置服务器 UID - */ public static void resetServerUID() { DataUtils.getPluginData("TabooLibrary", null).set("serverUID", UUID.randomUUID().toString()); } - /** - * 向后台发送 DEBUG 信息 - * - * @param plugin - * @param ss - */ - public static void debug(Plugin plugin, String... ss) { - if (Main.getInst().getConfig().getBoolean("DEBUG")) { - for (String s : ss) { - // [00:42:41 INFO]: [TabooLib - DEBUG][TabooPlugin] Example bug message - Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[TabooLib - DEBUG][" + plugin.getName() + "] " + ChatColor.RED + s); - } - } - } - - /** - * 获取 NMS 版本(数字) - * - * @return - */ public static int getVerint() { if (getVersion().startsWith("v1_7")) { return 10700; - } - else if (getVersion().startsWith("v1_8")) { + } else if (getVersion().startsWith("v1_8")) { return 10800; - } - else if (getVersion().startsWith("v1_9")) { + } else if (getVersion().startsWith("v1_9")) { return 10900; - } - else if (getVersion().startsWith("v1_10")) { + } else if (getVersion().startsWith("v1_10")) { return 11000; - } - else if (getVersion().startsWith("v1_11")) { + } else if (getVersion().startsWith("v1_11")) { return 11100; - } - else if (getVersion().startsWith("v1_12")) { + } else if (getVersion().startsWith("v1_12")) { return 11200; - } - else if (getVersion().startsWith("v1_13")) { + } else if (getVersion().startsWith("v1_13")) { return 11300; } return 0; diff --git a/src/main/java/me/skymc/taboolib/anvil/AnvilContainerAPI.java b/src/main/java/me/skymc/taboolib/anvil/AnvilContainerAPI.java index dc1fc87..b0fbdd0 100644 --- a/src/main/java/me/skymc/taboolib/anvil/AnvilContainerAPI.java +++ b/src/main/java/me/skymc/taboolib/anvil/AnvilContainerAPI.java @@ -1,6 +1,9 @@ package me.skymc.taboolib.anvil; -import me.skymc.taboolib.anvil.versions.AnvilContainer_V1_9_4; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Sound; @@ -15,9 +18,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import me.skymc.taboolib.anvil.versions.AnvilContainer_V1_9_4; public class AnvilContainerAPI implements Listener{ diff --git a/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_11_R1.java b/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_11_R1.java index b9c1b08..4c6c656 100644 --- a/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_11_R1.java +++ b/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_11_R1.java @@ -1,9 +1,15 @@ package me.skymc.taboolib.anvil.versions; -import net.minecraft.server.v1_11_R1.*; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import net.minecraft.server.v1_11_R1.BlockPosition; +import net.minecraft.server.v1_11_R1.ChatMessage; +import net.minecraft.server.v1_11_R1.ContainerAnvil; +import net.minecraft.server.v1_11_R1.EntityHuman; +import net.minecraft.server.v1_11_R1.EntityPlayer; +import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow; + public class AnvilContainer_V1_11_R1 extends ContainerAnvil { public AnvilContainer_V1_11_R1(EntityHuman player) diff --git a/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_8_R3.java b/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_8_R3.java index 196ff3b..f5c0117 100644 --- a/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_8_R3.java +++ b/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_8_R3.java @@ -1,9 +1,15 @@ package me.skymc.taboolib.anvil.versions; -import net.minecraft.server.v1_8_R3.*; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.ChatMessage; +import net.minecraft.server.v1_8_R3.ContainerAnvil; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow; + public class AnvilContainer_V1_8_R3 extends ContainerAnvil { public AnvilContainer_V1_8_R3(EntityHuman player) diff --git a/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_9_4.java b/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_9_4.java index 6c0a1c0..33a80f5 100644 --- a/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_9_4.java +++ b/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_9_4.java @@ -1,9 +1,15 @@ package me.skymc.taboolib.anvil.versions; -import net.minecraft.server.v1_9_R2.*; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; import org.bukkit.entity.Player; +import net.minecraft.server.v1_9_R2.BlockPosition; +import net.minecraft.server.v1_9_R2.ChatMessage; +import net.minecraft.server.v1_9_R2.ContainerAnvil; +import net.minecraft.server.v1_9_R2.EntityHuman; +import net.minecraft.server.v1_9_R2.EntityPlayer; +import net.minecraft.server.v1_9_R2.PacketPlayOutOpenWindow; + public class AnvilContainer_V1_9_4 extends ContainerAnvil { public AnvilContainer_V1_9_4(EntityHuman player) diff --git a/src/main/java/me/skymc/taboolib/bookformatter/BookAchievement.java b/src/main/java/me/skymc/taboolib/bookformatter/BookAchievement.java index c2b143e..ea1c284 100644 --- a/src/main/java/me/skymc/taboolib/bookformatter/BookAchievement.java +++ b/src/main/java/me/skymc/taboolib/bookformatter/BookAchievement.java @@ -1,10 +1,43 @@ package me.skymc.taboolib.bookformatter; -import org.bukkit.Achievement; +import static org.bukkit.Achievement.ACQUIRE_IRON; +import static org.bukkit.Achievement.BAKE_CAKE; +import static org.bukkit.Achievement.BOOKCASE; +import static org.bukkit.Achievement.BREED_COW; +import static org.bukkit.Achievement.BREW_POTION; +import static org.bukkit.Achievement.BUILD_BETTER_PICKAXE; +import static org.bukkit.Achievement.BUILD_FURNACE; +import static org.bukkit.Achievement.BUILD_HOE; +import static org.bukkit.Achievement.BUILD_PICKAXE; +import static org.bukkit.Achievement.BUILD_SWORD; +import static org.bukkit.Achievement.BUILD_WORKBENCH; +import static org.bukkit.Achievement.COOK_FISH; +import static org.bukkit.Achievement.DIAMONDS_TO_YOU; +import static org.bukkit.Achievement.ENCHANTMENTS; +import static org.bukkit.Achievement.END_PORTAL; +import static org.bukkit.Achievement.EXPLORE_ALL_BIOMES; +import static org.bukkit.Achievement.FLY_PIG; +import static org.bukkit.Achievement.FULL_BEACON; +import static org.bukkit.Achievement.GET_BLAZE_ROD; +import static org.bukkit.Achievement.GET_DIAMONDS; +import static org.bukkit.Achievement.GHAST_RETURN; +import static org.bukkit.Achievement.KILL_COW; +import static org.bukkit.Achievement.KILL_ENEMY; +import static org.bukkit.Achievement.KILL_WITHER; +import static org.bukkit.Achievement.MAKE_BREAD; +import static org.bukkit.Achievement.MINE_WOOD; +import static org.bukkit.Achievement.NETHER_PORTAL; +import static org.bukkit.Achievement.ON_A_RAIL; +import static org.bukkit.Achievement.OPEN_INVENTORY; +import static org.bukkit.Achievement.OVERKILL; +import static org.bukkit.Achievement.OVERPOWERED; +import static org.bukkit.Achievement.SNIPE_SKELETON; +import static org.bukkit.Achievement.SPAWN_WITHER; +import static org.bukkit.Achievement.THE_END; import java.util.HashMap; -import static org.bukkit.Achievement.*; +import org.bukkit.Achievement; public final class BookAchievement { diff --git a/src/main/java/me/skymc/taboolib/bookformatter/BookFormatter.java b/src/main/java/me/skymc/taboolib/bookformatter/BookFormatter.java index ccf735b..2f9ff1b 100644 --- a/src/main/java/me/skymc/taboolib/bookformatter/BookFormatter.java +++ b/src/main/java/me/skymc/taboolib/bookformatter/BookFormatter.java @@ -1,13 +1,13 @@ package me.skymc.taboolib.bookformatter; -import me.skymc.taboolib.bookformatter.builder.BookBuilder; -import me.skymc.taboolib.events.CustomBookOpenEvent; - import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import me.skymc.taboolib.bookformatter.builder.BookBuilder; +import me.skymc.taboolib.events.CustomBookOpenEvent; + @SuppressWarnings("deprecation") public final class BookFormatter { diff --git a/src/main/java/me/skymc/taboolib/bookformatter/BookReflection.java b/src/main/java/me/skymc/taboolib/bookformatter/BookReflection.java index 2cbde2f..bb22245 100644 --- a/src/main/java/me/skymc/taboolib/bookformatter/BookReflection.java +++ b/src/main/java/me/skymc/taboolib/bookformatter/BookReflection.java @@ -1,14 +1,5 @@ package me.skymc.taboolib.bookformatter; -import lombok.Getter; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.TextComponent; -import net.md_5.bungee.chat.ComponentSerializer; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BookMeta; - import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -17,6 +8,16 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; + +import lombok.Getter; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.chat.ComponentSerializer; + /** * The NMS helper for all the Book-API */ diff --git a/src/main/java/me/skymc/taboolib/bstats/Metrics.java b/src/main/java/me/skymc/taboolib/bstats/Metrics.java index c5067ed..cb2f721 100644 --- a/src/main/java/me/skymc/taboolib/bstats/Metrics.java +++ b/src/main/java/me/skymc/taboolib/bstats/Metrics.java @@ -1,5 +1,25 @@ package me.skymc.taboolib.bstats; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.logging.Level; +import java.util.zip.GZIPOutputStream; + +import javax.net.ssl.HttpsURLConnection; + import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -9,19 +29,6 @@ import org.bukkit.plugin.java.JavaPlugin; import org.json.simple.JSONArray; import org.json.simple.JSONObject; -import javax.net.ssl.HttpsURLConnection; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.util.*; -import java.util.concurrent.Callable; -import java.util.logging.Level; -import java.util.zip.GZIPOutputStream; - /** * bStats collects some data for plugin authors. * diff --git a/src/main/java/me/skymc/taboolib/commands/MainCommands.java b/src/main/java/me/skymc/taboolib/commands/MainCommands.java index b6765c0..3e6704b 100644 --- a/src/main/java/me/skymc/taboolib/commands/MainCommands.java +++ b/src/main/java/me/skymc/taboolib/commands/MainCommands.java @@ -1,15 +1,30 @@ package me.skymc.taboolib.commands; -import me.skymc.taboolib.commands.sub.*; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +import me.skymc.taboolib.commands.sub.AttributesCommand; +import me.skymc.taboolib.commands.sub.EnchantCommand; +import me.skymc.taboolib.commands.sub.FlagCommand; +import me.skymc.taboolib.commands.sub.HelpCommand; +import me.skymc.taboolib.commands.sub.ImportCommand; +import me.skymc.taboolib.commands.sub.InfoCommand; +import me.skymc.taboolib.commands.sub.ItemCommand; +import me.skymc.taboolib.commands.sub.PotionCommand; +import me.skymc.taboolib.commands.sub.SaveCommand; +import me.skymc.taboolib.commands.sub.SlotCommand; +import me.skymc.taboolib.commands.sub.TagDeleteCommand; +import me.skymc.taboolib.commands.sub.TagPrefixCommand; +import me.skymc.taboolib.commands.sub.TagSuffixCommand; +import me.skymc.taboolib.commands.sub.VariableGetCommand; +import me.skymc.taboolib.commands.sub.VariableSetCommand; import me.skymc.taboolib.commands.sub.cycle.CycleCommand; import me.skymc.taboolib.commands.sub.itemlist.ItemListCommand; import me.skymc.taboolib.commands.sub.shell.ShellCommand; import me.skymc.taboolib.commands.sub.sounds.SoundsCommand; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.message.MsgUtils; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; public class MainCommands implements CommandExecutor{ diff --git a/src/main/java/me/skymc/taboolib/commands/locale/TabooLibLocaleCommand.java b/src/main/java/me/skymc/taboolib/commands/locale/TabooLibLocaleCommand.java new file mode 100644 index 0000000..f1294b4 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/locale/TabooLibLocaleCommand.java @@ -0,0 +1,75 @@ +package me.skymc.taboolib.commands.locale; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.ilummc.tlib.resources.TLocale; + +/** + * @author sky + * @since 2018-04-22 14:36:28 + */ +public class TabooLibLocaleCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command arg1, String label, String[] args) { + if (args.length == 0) { + TLocale.sendTo(sender, "commands-taboolocale-helps", label); + } + else if (args[0].equalsIgnoreCase("send")) { + send(sender, args); + } + else if (args[0].equalsIgnoreCase("reload")) { + reload(sender); + } + else { + TLocale.sendTo(sender, "commands-taboolocale-invalid"); + } + return true; + } + + void send(CommandSender sender, String[] args) { + if (args.length < 3) { + TLocale.sendTo(sender, "commands-taboolocale-send-empty"); + return; + } + + List target = new ArrayList<>(); + if (args[1].equalsIgnoreCase("all")) { + target.addAll(Bukkit.getOnlinePlayers()); + } else { + Player player = Bukkit.getPlayerExact(args[1]); + if (player == null) { + TLocale.sendTo(sender, "commands-taboolocale-send-offline", args[1]); + return; + } + target.add(player); + } + + if (args.length > 3) { + String[] vars = new String[args.length - 3]; + for (int i = 3 ; i < args.length ; i++) { + vars[i - 3] = args[i]; + } + target.forEach(x -> TLocale.sendTo(x, args[2], vars)); + } else { + target.forEach(x -> TLocale.sendTo(x, args[2])); + } + + if (sender instanceof Player) { + TLocale.sendTo(sender, "commands-taboolocale-send-success"); + } + } + + void reload(CommandSender sender) { + TLocale.reload(); + TLocale.sendTo(sender, "commands-taboolocale-reload"); + } + +} diff --git a/src/main/java/me/skymc/taboolib/commands/sub/AttributesCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/AttributesCommand.java index 04fbb24..48ab718 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/AttributesCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/AttributesCommand.java @@ -1,11 +1,12 @@ package me.skymc.taboolib.commands.sub; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.jsonformatter.JSONFormatter; import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class AttributesCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java index e5ac754..7a9e611 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java @@ -1,17 +1,18 @@ package me.skymc.taboolib.commands.sub; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map.Entry; + +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.jsonformatter.JSONFormatter; import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map.Entry; public class HelpCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/InfoCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/InfoCommand.java index 5defc7b..01c13ac 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/InfoCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/InfoCommand.java @@ -1,5 +1,9 @@ package me.skymc.taboolib.commands.sub; +import org.bukkit.Material; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.itemnbtapi.NBTItem; @@ -8,9 +12,6 @@ import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.hover.ShowItemEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; import me.skymc.taboolib.message.MsgUtils; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class InfoCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/SaveCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/SaveCommand.java index e398335..ef62f08 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/SaveCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/SaveCommand.java @@ -11,8 +11,8 @@ import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.fileutils.ConfigUtils; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.message.ChatCatcher; -import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.message.ChatCatcher.Catcher; +import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.playerdata.DataUtils; public class SaveCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/SlotCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/SlotCommand.java index 5c4daba..57d8627 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/SlotCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/SlotCommand.java @@ -1,11 +1,12 @@ package me.skymc.taboolib.commands.sub; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.jsonformatter.JSONFormatter; import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class SlotCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java index dc09dfc..674200a 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java @@ -1,11 +1,12 @@ package me.skymc.taboolib.commands.sub; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.team.TagManager; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java index d085c9e..7427bf9 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java @@ -1,8 +1,9 @@ package me.skymc.taboolib.commands.sub.cycle; +import org.bukkit.command.CommandSender; + import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.message.MsgUtils; -import org.bukkit.command.CommandSender; public class CycleCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java index 2feb7d1..8579c08 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java @@ -1,13 +1,14 @@ package me.skymc.taboolib.commands.sub.cycle; +import java.util.concurrent.TimeUnit; + +import org.bukkit.command.CommandSender; + import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.other.DateUtils; import me.skymc.taboolib.timecycle.TimeCycle; import me.skymc.taboolib.timecycle.TimeCycleManager; -import org.bukkit.command.CommandSender; - -import java.util.concurrent.TimeUnit; public class CycleInfoCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java index 1bc2ae7..ba6da82 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java @@ -1,13 +1,14 @@ package me.skymc.taboolib.commands.sub.cycle; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.jsonformatter.JSONFormatter; import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; import me.skymc.taboolib.timecycle.TimeCycle; import me.skymc.taboolib.timecycle.TimeCycleManager; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class CycleListCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java index 86a6c09..b16ac82 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java @@ -1,5 +1,9 @@ package me.skymc.taboolib.commands.sub.cycle; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.scheduler.BukkitRunnable; + import me.skymc.taboolib.Main; import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.database.GlobalDataManager; @@ -7,9 +11,6 @@ import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.timecycle.TimeCycle; import me.skymc.taboolib.timecycle.TimeCycleEvent; import me.skymc.taboolib.timecycle.TimeCycleManager; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.scheduler.BukkitRunnable; public class CycleUpdateCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java b/src/main/java/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java index da13e59..6ba40ae 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java @@ -1,7 +1,10 @@ package me.skymc.taboolib.commands.sub.itemlist.listener; -import me.skymc.taboolib.inventory.InventoryUtil; -import me.skymc.taboolib.inventory.ItemUtils; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; + import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -13,10 +16,8 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; +import me.skymc.taboolib.inventory.InventoryUtil; +import me.skymc.taboolib.inventory.ItemUtils; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/commands/sub/shell/ShellCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/shell/ShellCommand.java index 3690404..9150f31 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/shell/ShellCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/shell/ShellCommand.java @@ -1,8 +1,9 @@ package me.skymc.taboolib.commands.sub.shell; +import org.bukkit.command.CommandSender; + import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.message.MsgUtils; -import org.bukkit.command.CommandSender; public class ShellCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java b/src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java index 55b043e..e37ac1e 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java @@ -1,7 +1,8 @@ package me.skymc.taboolib.commands.sub.sounds.listener; -import me.skymc.taboolib.inventory.InventoryUtil; -import me.skymc.taboolib.inventory.ItemUtils; +import java.util.Arrays; +import java.util.HashMap; + import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Sound; @@ -14,8 +15,8 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import java.util.Arrays; -import java.util.HashMap; +import me.skymc.taboolib.inventory.InventoryUtil; +import me.skymc.taboolib.inventory.ItemUtils; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java b/src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java index 102506a..10c5e90 100644 --- a/src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java +++ b/src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java @@ -1,13 +1,14 @@ package me.skymc.taboolib.cooldown; -import me.skymc.taboolib.message.MsgUtils; +import java.util.concurrent.ConcurrentHashMap; + import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.plugin.Plugin; -import java.util.concurrent.ConcurrentHashMap; +import me.skymc.taboolib.message.MsgUtils; @Deprecated public class CooldownUtils implements Listener { diff --git a/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownUtils2.java b/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownUtils2.java index a467759..565eeac 100644 --- a/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownUtils2.java +++ b/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownUtils2.java @@ -1,13 +1,13 @@ package me.skymc.taboolib.cooldown.seconds; +import java.util.concurrent.ConcurrentHashMap; + import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.plugin.Plugin; -import java.util.concurrent.ConcurrentHashMap; - public class CooldownUtils2 implements Listener { private static ConcurrentHashMap packlist = new ConcurrentHashMap<>(); diff --git a/src/main/java/me/skymc/taboolib/csvutils/CsvReader.java b/src/main/java/me/skymc/taboolib/csvutils/CsvReader.java index b40f5cd..fdc1eb9 100644 --- a/src/main/java/me/skymc/taboolib/csvutils/CsvReader.java +++ b/src/main/java/me/skymc/taboolib/csvutils/CsvReader.java @@ -1,6 +1,14 @@ package me.skymc.taboolib.csvutils; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; import java.nio.charset.Charset; import java.text.NumberFormat; import java.util.HashMap; diff --git a/src/main/java/me/skymc/taboolib/csvutils/CsvWriter.java b/src/main/java/me/skymc/taboolib/csvutils/CsvWriter.java index 7df96a9..8547c74 100644 --- a/src/main/java/me/skymc/taboolib/csvutils/CsvWriter.java +++ b/src/main/java/me/skymc/taboolib/csvutils/CsvWriter.java @@ -1,6 +1,11 @@ package me.skymc.taboolib.csvutils; -import java.io.*; +import java.io.BufferedWriter; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; import java.nio.charset.Charset; public class CsvWriter diff --git a/src/main/java/me/skymc/taboolib/damage/DamageUtils.java b/src/main/java/me/skymc/taboolib/damage/DamageUtils.java index 9a865dc..45c6837 100644 --- a/src/main/java/me/skymc/taboolib/damage/DamageUtils.java +++ b/src/main/java/me/skymc/taboolib/damage/DamageUtils.java @@ -1,11 +1,12 @@ package me.skymc.taboolib.damage; -import me.skymc.taboolib.TabooLib; +import java.lang.reflect.InvocationTargetException; + import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import java.lang.reflect.InvocationTargetException; +import me.skymc.taboolib.TabooLib; public class DamageUtils { diff --git a/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java b/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java index 74b6fdb..0f4183c 100644 --- a/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java +++ b/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java @@ -1,17 +1,18 @@ package me.skymc.taboolib.database; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.concurrent.ConcurrentHashMap; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.scheduler.BukkitRunnable; + import me.skymc.taboolib.Main; import me.skymc.taboolib.Main.StorageType; import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.playerdata.DataUtils; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.concurrent.ConcurrentHashMap; public class GlobalDataManager { diff --git a/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java b/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java index 8355004..0a87f65 100644 --- a/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java +++ b/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java @@ -1,12 +1,9 @@ package me.skymc.taboolib.database; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.Main.StorageType; -import me.skymc.taboolib.events.PlayerLoadedEvent; -import me.skymc.taboolib.exception.PlayerOfflineException; -import me.skymc.taboolib.fileutils.ConfigUtils; -import me.skymc.taboolib.fileutils.FileUtils; -import me.skymc.taboolib.message.MsgUtils; +import java.io.File; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.configuration.file.FileConfiguration; @@ -18,9 +15,13 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scheduler.BukkitRunnable; -import java.io.File; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.Main.StorageType; +import me.skymc.taboolib.events.PlayerLoadedEvent; +import me.skymc.taboolib.exception.PlayerOfflineException; +import me.skymc.taboolib.fileutils.ConfigUtils; +import me.skymc.taboolib.fileutils.FileUtils; +import me.skymc.taboolib.message.MsgUtils; public class PlayerDataManager implements Listener { diff --git a/src/main/java/me/skymc/taboolib/display/ActionUtils.java b/src/main/java/me/skymc/taboolib/display/ActionUtils.java index 92a8d03..b9ef334 100644 --- a/src/main/java/me/skymc/taboolib/display/ActionUtils.java +++ b/src/main/java/me/skymc/taboolib/display/ActionUtils.java @@ -1,10 +1,11 @@ package me.skymc.taboolib.display; -import me.skymc.taboolib.TabooLib; +import java.lang.reflect.Constructor; + import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import java.lang.reflect.Constructor; +import me.skymc.taboolib.TabooLib; public class ActionUtils { diff --git a/src/main/java/me/skymc/taboolib/display/TitleUtils.java b/src/main/java/me/skymc/taboolib/display/TitleUtils.java index 296686c..5cafc30 100644 --- a/src/main/java/me/skymc/taboolib/display/TitleUtils.java +++ b/src/main/java/me/skymc/taboolib/display/TitleUtils.java @@ -1,9 +1,9 @@ package me.skymc.taboolib.display; -import org.bukkit.entity.Player; - import java.lang.reflect.Constructor; +import org.bukkit.entity.Player; + public class TitleUtils { private static void sendPacket(Player player, Object packet) diff --git a/src/main/java/me/skymc/taboolib/entity/EntityTag.java b/src/main/java/me/skymc/taboolib/entity/EntityTag.java index 7a2821e..ce32a0d 100644 --- a/src/main/java/me/skymc/taboolib/entity/EntityTag.java +++ b/src/main/java/me/skymc/taboolib/entity/EntityTag.java @@ -1,13 +1,14 @@ package me.skymc.taboolib.entity; -import me.skymc.taboolib.Main; -import org.bukkit.entity.Entity; -import org.bukkit.scheduler.BukkitRunnable; - import java.util.List; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import org.bukkit.entity.Entity; +import org.bukkit.scheduler.BukkitRunnable; + +import me.skymc.taboolib.Main; + /** * 伪 - MetaData * diff --git a/src/main/java/me/skymc/taboolib/events/CustomBookOpenEvent.java b/src/main/java/me/skymc/taboolib/events/CustomBookOpenEvent.java index 6a806a7..1195671 100644 --- a/src/main/java/me/skymc/taboolib/events/CustomBookOpenEvent.java +++ b/src/main/java/me/skymc/taboolib/events/CustomBookOpenEvent.java @@ -1,13 +1,14 @@ package me.skymc.taboolib.events; -import lombok.Getter; -import lombok.Setter; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; +import lombok.Getter; +import lombok.Setter; + /** * The event called when a book is opened trough this Util */ diff --git a/src/main/java/me/skymc/taboolib/events/DefaultEvent2.java b/src/main/java/me/skymc/taboolib/events/DefaultEvent2.java index d2a86bb..324609b 100644 --- a/src/main/java/me/skymc/taboolib/events/DefaultEvent2.java +++ b/src/main/java/me/skymc/taboolib/events/DefaultEvent2.java @@ -1,8 +1,9 @@ package me.skymc.taboolib.events; -import org.bukkit.event.player.*; -import org.bukkit.entity.*; -import org.bukkit.event.*; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; public class DefaultEvent2 extends PlayerEvent { diff --git a/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java b/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java index 0c1490f..225cc30 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java @@ -1,13 +1,21 @@ package me.skymc.taboolib.fileutils; -import com.google.common.base.Charsets; -import me.skymc.taboolib.message.MsgUtils; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.StringReader; + +import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; -import java.io.*; +import com.google.common.base.Charsets; +import com.ilummc.tlib.TLib; + +import me.skymc.taboolib.message.MsgUtils; public class ConfigUtils { @@ -43,12 +51,13 @@ public class ConfigUtils { */ public static FileConfiguration load(Plugin plugin, File file) { YamlConfiguration yaml = new YamlConfiguration(); + try { yaml = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8)); - } catch (FileNotFoundException e) { - MsgUtils.warn("配置文件载入失败!"); - MsgUtils.warn("插件: &4" + plugin.getName()); - MsgUtils.warn("文件: &4" + file.getName()); + } catch (Exception e) { + TLib.getTLib().getLogger().error("配置文件载入失败!"); + TLib.getTLib().getLogger().error("插件: &4" + plugin.getName()); + TLib.getTLib().getLogger().error("文件: &4" + file); } return yaml; } diff --git a/src/main/java/me/skymc/taboolib/fileutils/EncodeUtils.java b/src/main/java/me/skymc/taboolib/fileutils/EncodeUtils.java index e0c43b7..13e1672 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/EncodeUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/EncodeUtils.java @@ -1,6 +1,13 @@ package me.skymc.taboolib.fileutils; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FilenameFilter; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; diff --git a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java index e8fa55c..3f28a21 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java @@ -1,13 +1,22 @@ package me.skymc.taboolib.fileutils; -import me.skymc.taboolib.message.MsgUtils; - -import java.io.*; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.nio.channels.FileChannel; +import ch.njol.util.Closeable; +import me.skymc.taboolib.message.MsgUtils; + public class FileUtils { public static String ip() { @@ -282,13 +291,7 @@ public class FileUtils { } } - /** - * 读取字节 - * - * @param in - * @return - */ - private static byte[] read(InputStream in) { + public static byte[] read(InputStream in) { byte[] buffer = new byte[1024]; int len = 0; ByteArrayOutputStream bos = new ByteArrayOutputStream(); @@ -296,11 +299,18 @@ public class FileUtils { while((len = in.read(buffer)) != -1) { bos.write(buffer, 0, len); } - bos.close(); } - catch (Exception e) { - e.printStackTrace(); + catch (Exception ignored) { } return bos.toByteArray(); } + + public static void close(Closeable closeable) { + try { + if (closeable != null) { + closeable.close(); + } + } catch (Exception ignored) { + } + } } diff --git a/src/main/java/me/skymc/taboolib/fileutils/LogUtils.java b/src/main/java/me/skymc/taboolib/fileutils/LogUtils.java index 07d57e1..3915139 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/LogUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/LogUtils.java @@ -1,13 +1,14 @@ package me.skymc.taboolib.fileutils; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.other.DateUtils; -import org.bukkit.plugin.Plugin; - import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; +import org.bukkit.plugin.Plugin; + +import me.skymc.taboolib.Main; +import me.skymc.taboolib.other.DateUtils; + @Deprecated public class LogUtils { diff --git a/src/main/java/me/skymc/taboolib/inventory/DropUtils.java b/src/main/java/me/skymc/taboolib/inventory/DropUtils.java index 25aa4bb..3392a17 100644 --- a/src/main/java/me/skymc/taboolib/inventory/DropUtils.java +++ b/src/main/java/me/skymc/taboolib/inventory/DropUtils.java @@ -1,12 +1,13 @@ package me.skymc.taboolib.inventory; -import me.skymc.taboolib.other.NumberUtils; import org.bukkit.Location; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; +import me.skymc.taboolib.other.NumberUtils; + public class DropUtils { public static Item drop(Player player, ItemStack itemStack, double bulletSpread, double radius) { diff --git a/src/main/java/me/skymc/taboolib/inventory/InventoryUtil.java b/src/main/java/me/skymc/taboolib/inventory/InventoryUtil.java index f435c7c..6bea382 100644 --- a/src/main/java/me/skymc/taboolib/inventory/InventoryUtil.java +++ b/src/main/java/me/skymc/taboolib/inventory/InventoryUtil.java @@ -1,12 +1,12 @@ package me.skymc.taboolib.inventory; +import java.util.Arrays; +import java.util.LinkedList; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import java.util.Arrays; -import java.util.LinkedList; - public class InventoryUtil { public final static LinkedList SLOT_OF_CENTENTS = new LinkedList<>(Arrays.asList( diff --git a/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java b/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java index 5f4420b..4f85c9d 100644 --- a/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java +++ b/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java @@ -1,17 +1,10 @@ package me.skymc.taboolib.inventory; -import lombok.Getter; -import me.clip.placeholderapi.PlaceholderAPI; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.TabooLib; -import me.skymc.taboolib.fileutils.ConfigUtils; -import me.skymc.taboolib.itemnbtapi.NBTItem; -import me.skymc.taboolib.itemnbtapi.NBTList; -import me.skymc.taboolib.itemnbtapi.NBTListCompound; -import me.skymc.taboolib.itemnbtapi.NBTType; -import me.skymc.taboolib.message.MsgUtils; -import me.skymc.taboolib.other.NumberUtils; -import me.skymc.taboolib.string.Language; +import java.io.File; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; @@ -28,10 +21,18 @@ import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import java.io.File; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; +import lombok.Getter; +import me.clip.placeholderapi.PlaceholderAPI; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.TabooLib; +import me.skymc.taboolib.fileutils.ConfigUtils; +import me.skymc.taboolib.itemnbtapi.NBTItem; +import me.skymc.taboolib.itemnbtapi.NBTList; +import me.skymc.taboolib.itemnbtapi.NBTListCompound; +import me.skymc.taboolib.itemnbtapi.NBTType; +import me.skymc.taboolib.message.MsgUtils; +import me.skymc.taboolib.other.NumberUtils; +import me.skymc.taboolib.string.Language; public class ItemUtils { diff --git a/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItem.java b/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItem.java index 6623df2..044a470 100644 --- a/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItem.java +++ b/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItem.java @@ -1,9 +1,8 @@ package me.skymc.taboolib.inventory.speciaitem; -import lombok.Getter; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.inventory.ItemUtils; -import me.skymc.taboolib.message.MsgUtils; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -13,8 +12,10 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.plugin.Plugin; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; +import lombok.Getter; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.inventory.ItemUtils; +import me.skymc.taboolib.message.MsgUtils; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTReflectionUtil.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTReflectionUtil.java index 4ae8545..e53893d 100644 --- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTReflectionUtil.java +++ b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTReflectionUtil.java @@ -1,14 +1,5 @@ package me.skymc.taboolib.itemnbtapi; -import me.skymc.taboolib.TabooLib; -import me.skymc.taboolib.itemnbtapi.utils.GsonWrapper; -import me.skymc.taboolib.itemnbtapi.utils.MethodNames; -import me.skymc.taboolib.message.MsgUtils; -import org.bukkit.Bukkit; -import org.bukkit.block.BlockState; -import org.bukkit.entity.Entity; -import org.bukkit.inventory.ItemStack; - import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; @@ -17,6 +8,16 @@ import java.lang.reflect.Method; import java.util.Set; import java.util.Stack; +import org.bukkit.Bukkit; +import org.bukkit.block.BlockState; +import org.bukkit.entity.Entity; +import org.bukkit.inventory.ItemStack; + +import me.skymc.taboolib.TabooLib; +import me.skymc.taboolib.itemnbtapi.utils.GsonWrapper; +import me.skymc.taboolib.itemnbtapi.utils.MethodNames; +import me.skymc.taboolib.message.MsgUtils; + // TODO: finish codestyle cleanup -sgdc3 public class NBTReflectionUtil { diff --git a/src/main/java/me/skymc/taboolib/javascript/JavaScriptUtils.java b/src/main/java/me/skymc/taboolib/javascript/JavaScriptUtils.java index ea982a4..ee79a93 100644 --- a/src/main/java/me/skymc/taboolib/javascript/JavaScriptUtils.java +++ b/src/main/java/me/skymc/taboolib/javascript/JavaScriptUtils.java @@ -1,14 +1,15 @@ package me.skymc.taboolib.javascript; -import me.skymc.taboolib.Main; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; import javax.script.Invocable; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; + +import me.skymc.taboolib.Main; public class JavaScriptUtils { diff --git a/src/main/java/me/skymc/taboolib/javashell/JavaShell.java b/src/main/java/me/skymc/taboolib/javashell/JavaShell.java index 86fa9d1..fc6d40d 100644 --- a/src/main/java/me/skymc/taboolib/javashell/JavaShell.java +++ b/src/main/java/me/skymc/taboolib/javashell/JavaShell.java @@ -1,10 +1,11 @@ package me.skymc.taboolib.javashell; -import lombok.Getter; -import lombok.Setter; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.javashell.utils.JarUtils; -import me.skymc.taboolib.message.MsgUtils; +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.HashMap; + import org.apache.commons.lang.ArrayUtils; import org.bukkit.Bukkit; import org.bukkit.event.HandlerList; @@ -12,11 +13,11 @@ import org.bukkit.event.Listener; import org.bukkit.plugin.RegisteredListener; import org.bukkit.scheduler.BukkitRunnable; -import java.io.File; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.HashMap; +import lombok.Getter; +import lombok.Setter; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.javashell.utils.JarUtils; +import me.skymc.taboolib.message.MsgUtils; public class JavaShell { diff --git a/src/main/java/me/skymc/taboolib/javashell/utils/JarUtils.java b/src/main/java/me/skymc/taboolib/javashell/utils/JarUtils.java index 18fd574..df6d0da 100644 --- a/src/main/java/me/skymc/taboolib/javashell/utils/JarUtils.java +++ b/src/main/java/me/skymc/taboolib/javashell/utils/JarUtils.java @@ -1,9 +1,12 @@ package me.skymc.taboolib.javashell.utils; -import me.skymc.taboolib.message.MsgUtils; -import org.bukkit.Bukkit; - -import java.io.*; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; @@ -12,6 +15,10 @@ import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; +import org.bukkit.Bukkit; + +import me.skymc.taboolib.message.MsgUtils; + public class JarUtils { public static boolean extractFromJar(final String fileName, final String dest) throws IOException { diff --git a/src/main/java/me/skymc/taboolib/json/JSONObject.java b/src/main/java/me/skymc/taboolib/json/JSONObject.java index e038225..7007bf7 100644 --- a/src/main/java/me/skymc/taboolib/json/JSONObject.java +++ b/src/main/java/me/skymc/taboolib/json/JSONObject.java @@ -6,7 +6,13 @@ import java.io.Writer; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.*; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; @SuppressWarnings({"rawtypes", "unchecked"}) public class JSONObject { diff --git a/src/main/java/me/skymc/taboolib/json/JSONTokener.java b/src/main/java/me/skymc/taboolib/json/JSONTokener.java index 08f184b..dd68f9e 100644 --- a/src/main/java/me/skymc/taboolib/json/JSONTokener.java +++ b/src/main/java/me/skymc/taboolib/json/JSONTokener.java @@ -1,7 +1,12 @@ package me.skymc.taboolib.json; -import java.io.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; public class JSONTokener { diff --git a/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java b/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java index f8ab044..df230f3 100644 --- a/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java +++ b/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java @@ -1,20 +1,21 @@ package me.skymc.taboolib.jsonformatter; -import me.skymc.taboolib.json.JSONArray; -import me.skymc.taboolib.json.JSONObject; -import me.skymc.taboolib.jsonformatter.click.ClickEvent; -import me.skymc.taboolib.jsonformatter.hover.HoverEvent; -import me.skymc.taboolib.nms.NMSUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import me.skymc.taboolib.json.JSONArray; +import me.skymc.taboolib.json.JSONObject; +import me.skymc.taboolib.jsonformatter.click.ClickEvent; +import me.skymc.taboolib.jsonformatter.hover.HoverEvent; +import me.skymc.taboolib.nms.NMSUtils; + public class JSONFormatter { private JSONArray ja = new JSONArray(); diff --git a/src/main/java/me/skymc/taboolib/jsonformatter/hover/ShowItemEvent.java b/src/main/java/me/skymc/taboolib/jsonformatter/hover/ShowItemEvent.java index 863294c..8509f4a 100644 --- a/src/main/java/me/skymc/taboolib/jsonformatter/hover/ShowItemEvent.java +++ b/src/main/java/me/skymc/taboolib/jsonformatter/hover/ShowItemEvent.java @@ -1,18 +1,19 @@ package me.skymc.taboolib.jsonformatter.hover; -import me.skymc.taboolib.TabooLib; -import me.skymc.taboolib.inventory.ItemUtils; -import me.skymc.taboolib.json.JSONObject; -import me.skymc.taboolib.nms.item.DabItemUtils; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.skymc.taboolib.TabooLib; +import me.skymc.taboolib.inventory.ItemUtils; +import me.skymc.taboolib.json.JSONObject; +import me.skymc.taboolib.nms.item.DabItemUtils; + public class ShowItemEvent extends HoverEvent{ private JSONObject object = new JSONObject(); diff --git a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java index 4f92e24..c1a339f 100644 --- a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java +++ b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java @@ -1,5 +1,11 @@ package me.skymc.taboolib.listener; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.server.ServerCommandEvent; + import me.skymc.taboolib.Main; import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.database.PlayerDataManager; @@ -7,11 +13,6 @@ import me.skymc.taboolib.itemnbtapi.NBTItem; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.permission.PermissionUtils; import me.skymc.taboolib.playerdata.DataUtils; -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.server.ServerCommandEvent; public class ListenerPlayerCommand implements Listener { diff --git a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerJump.java b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerJump.java index d0d4fa1..c8306c8 100644 --- a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerJump.java +++ b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerJump.java @@ -1,6 +1,7 @@ package me.skymc.taboolib.listener; -import me.skymc.taboolib.events.PlayerJumpEvent; +import java.util.HashMap; + import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -12,7 +13,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.HashMap; +import me.skymc.taboolib.events.PlayerJumpEvent; public class ListenerPlayerJump implements Listener diff --git a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java index 066e77c..94a580a 100644 --- a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java +++ b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java @@ -1,11 +1,12 @@ package me.skymc.taboolib.listener; -import me.skymc.taboolib.playerdata.DataUtils; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; +import me.skymc.taboolib.playerdata.DataUtils; + public class ListenerPlayerQuit implements Listener{ @EventHandler (priority = EventPriority.MONITOR) diff --git a/src/main/java/me/skymc/taboolib/listener/ListenerPluginDisable.java b/src/main/java/me/skymc/taboolib/listener/ListenerPluginDisable.java index 95f9a60..119744d 100644 --- a/src/main/java/me/skymc/taboolib/listener/ListenerPluginDisable.java +++ b/src/main/java/me/skymc/taboolib/listener/ListenerPluginDisable.java @@ -1,17 +1,18 @@ package me.skymc.taboolib.listener; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.scheduler.BukkitRunnable; + import me.skymc.taboolib.Main; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.mysql.MysqlUtils; import me.skymc.taboolib.mysql.protect.MySQLConnection; import me.skymc.taboolib.timecycle.TimeCycleManager; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.server.PluginDisableEvent; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.ArrayList; -import java.util.List; public class ListenerPluginDisable implements Listener { diff --git a/src/main/java/me/skymc/taboolib/message/ChatCatcher.java b/src/main/java/me/skymc/taboolib/message/ChatCatcher.java index 60be8b6..2ed8bad 100644 --- a/src/main/java/me/skymc/taboolib/message/ChatCatcher.java +++ b/src/main/java/me/skymc/taboolib/message/ChatCatcher.java @@ -1,14 +1,15 @@ package me.skymc.taboolib.message; -import lombok.Getter; +import java.util.HashMap; +import java.util.LinkedList; + import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.HashMap; -import java.util.LinkedList; +import lombok.Getter; public class ChatCatcher implements Listener { diff --git a/src/main/java/me/skymc/taboolib/methods/ReflectionUtils.java b/src/main/java/me/skymc/taboolib/methods/ReflectionUtils.java index 6b2c54a..b25e364 100644 --- a/src/main/java/me/skymc/taboolib/methods/ReflectionUtils.java +++ b/src/main/java/me/skymc/taboolib/methods/ReflectionUtils.java @@ -1,7 +1,5 @@ package me.skymc.taboolib.methods; -import org.bukkit.Bukkit; - import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -9,6 +7,8 @@ import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; +import org.bukkit.Bukkit; + /** * ReflectionUtils *

diff --git a/src/main/java/me/skymc/taboolib/mysql/MysqlConnection.java b/src/main/java/me/skymc/taboolib/mysql/MysqlConnection.java index e22b8a3..8f28b04 100644 --- a/src/main/java/me/skymc/taboolib/mysql/MysqlConnection.java +++ b/src/main/java/me/skymc/taboolib/mysql/MysqlConnection.java @@ -1,6 +1,10 @@ package me.skymc.taboolib.mysql; -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/me/skymc/taboolib/mysql/MysqlUtils.java b/src/main/java/me/skymc/taboolib/mysql/MysqlUtils.java index ebfe373..a1534bb 100644 --- a/src/main/java/me/skymc/taboolib/mysql/MysqlUtils.java +++ b/src/main/java/me/skymc/taboolib/mysql/MysqlUtils.java @@ -1,12 +1,13 @@ package me.skymc.taboolib.mysql; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.Plugin; + import me.skymc.taboolib.Main; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.mysql.protect.MySQLConnection; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.plugin.Plugin; - -import java.util.concurrent.CopyOnWriteArrayList; public class MysqlUtils { diff --git a/src/main/java/me/skymc/taboolib/mysql/protect/MySQLConnection.java b/src/main/java/me/skymc/taboolib/mysql/protect/MySQLConnection.java index 565f328..c76d65d 100644 --- a/src/main/java/me/skymc/taboolib/mysql/protect/MySQLConnection.java +++ b/src/main/java/me/skymc/taboolib/mysql/protect/MySQLConnection.java @@ -1,16 +1,21 @@ package me.skymc.taboolib.mysql.protect; -import lombok.Getter; -import lombok.Setter; -import me.skymc.taboolib.Main; -import org.bukkit.plugin.Plugin; - -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import org.bukkit.plugin.Plugin; + +import lombok.Getter; +import lombok.Setter; +import me.skymc.taboolib.Main; + public class MySQLConnection { @Getter diff --git a/src/main/java/me/skymc/taboolib/nms/NMSUtil18.java b/src/main/java/me/skymc/taboolib/nms/NMSUtil18.java index 274cf6f..70c1b2d 100644 --- a/src/main/java/me/skymc/taboolib/nms/NMSUtil18.java +++ b/src/main/java/me/skymc/taboolib/nms/NMSUtil18.java @@ -1,16 +1,5 @@ package me.skymc.taboolib.nms; -import org.bukkit.*; -import org.bukkit.block.BlockFace; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - import java.io.InputStream; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -20,6 +9,21 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import org.bukkit.Bukkit; +import org.bukkit.DyeColor; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.block.BlockFace; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + @SuppressWarnings({ "rawtypes", "unchecked" }) @Deprecated public class NMSUtil18 { diff --git a/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java b/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java index 4437f76..09b2a4c 100644 --- a/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java +++ b/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java @@ -1,7 +1,24 @@ package me.skymc.taboolib.nms; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.logging.Level; + import org.apache.commons.lang.StringUtils; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.DyeColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Server; +import org.bukkit.World; import org.bukkit.block.BlockFace; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.MemorySection; @@ -15,13 +32,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.util.Vector; -import java.io.InputStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.*; -import java.util.logging.Level; - @SuppressWarnings({ "rawtypes", "unchecked" }) @Deprecated public class NMSUtil19 { diff --git a/src/main/java/me/skymc/taboolib/nms/NMSUtils.java b/src/main/java/me/skymc/taboolib/nms/NMSUtils.java index c68b463..2541858 100644 --- a/src/main/java/me/skymc/taboolib/nms/NMSUtils.java +++ b/src/main/java/me/skymc/taboolib/nms/NMSUtils.java @@ -1,12 +1,12 @@ package me.skymc.taboolib.nms; -import org.bukkit.Bukkit; - import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import org.bukkit.Bukkit; + public class NMSUtils { public static String getVersion(){ diff --git a/src/main/java/me/skymc/taboolib/nms/item/DabItemUtils.java b/src/main/java/me/skymc/taboolib/nms/item/DabItemUtils.java index dad63d1..a89c12a 100644 --- a/src/main/java/me/skymc/taboolib/nms/item/DabItemUtils.java +++ b/src/main/java/me/skymc/taboolib/nms/item/DabItemUtils.java @@ -1,5 +1,15 @@ package me.skymc.taboolib.nms.item; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Map; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + import me.skymc.taboolib.Main; import me.skymc.taboolib.json.JSONArray; import me.skymc.taboolib.json.JSONObject; @@ -7,15 +17,6 @@ import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.nms.item.impl._164ItemUtils; import me.skymc.taboolib.nms.item.impl._1710ItemUtils; import me.skymc.taboolib.nms.item.impl._194ItemUtils; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.lang.reflect.Method; -import java.util.List; -import java.util.Map; public class DabItemUtils { diff --git a/src/main/java/me/skymc/taboolib/nms/item/IDabItemUtils.java b/src/main/java/me/skymc/taboolib/nms/item/IDabItemUtils.java index c24b652..d30aaa5 100644 --- a/src/main/java/me/skymc/taboolib/nms/item/IDabItemUtils.java +++ b/src/main/java/me/skymc/taboolib/nms/item/IDabItemUtils.java @@ -1,13 +1,14 @@ package me.skymc.taboolib.nms.item; -import me.skymc.taboolib.json.JSONArray; -import me.skymc.taboolib.json.JSONObject; -import org.bukkit.inventory.ItemStack; - import java.lang.reflect.Method; import java.util.List; import java.util.Map; +import org.bukkit.inventory.ItemStack; + +import me.skymc.taboolib.json.JSONArray; +import me.skymc.taboolib.json.JSONObject; + public interface IDabItemUtils{ //@formatter:off diff --git a/src/main/java/me/skymc/taboolib/nms/item/impl/_164ItemUtils.java b/src/main/java/me/skymc/taboolib/nms/item/impl/_164ItemUtils.java index 9f92980..98ef84d 100644 --- a/src/main/java/me/skymc/taboolib/nms/item/impl/_164ItemUtils.java +++ b/src/main/java/me/skymc/taboolib/nms/item/impl/_164ItemUtils.java @@ -1,19 +1,27 @@ package me.skymc.taboolib.nms.item.impl; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + import me.skymc.taboolib.json.JSONArray; import me.skymc.taboolib.json.JSONObject; import me.skymc.taboolib.nms.NMSUtils; import me.skymc.taboolib.nms.item.IDabItemUtils; import me.skymc.taboolib.nms.nbt.NBTConstants; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.*; -import java.util.Map.Entry; public class _164ItemUtils implements IDabItemUtils{ diff --git a/src/main/java/me/skymc/taboolib/nms/item/impl/_1710ItemUtils.java b/src/main/java/me/skymc/taboolib/nms/item/impl/_1710ItemUtils.java index 8914883..6392b8e 100644 --- a/src/main/java/me/skymc/taboolib/nms/item/impl/_1710ItemUtils.java +++ b/src/main/java/me/skymc/taboolib/nms/item/impl/_1710ItemUtils.java @@ -1,19 +1,27 @@ package me.skymc.taboolib.nms.item.impl; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + import me.skymc.taboolib.json.JSONArray; import me.skymc.taboolib.json.JSONObject; import me.skymc.taboolib.nms.NMSUtils; import me.skymc.taboolib.nms.item.IDabItemUtils; import me.skymc.taboolib.nms.nbt.NBTConstants; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.*; -import java.util.Map.Entry; public class _1710ItemUtils implements IDabItemUtils{ diff --git a/src/main/java/me/skymc/taboolib/nms/item/impl/_194ItemUtils.java b/src/main/java/me/skymc/taboolib/nms/item/impl/_194ItemUtils.java index aab3be4..3ee5c7a 100644 --- a/src/main/java/me/skymc/taboolib/nms/item/impl/_194ItemUtils.java +++ b/src/main/java/me/skymc/taboolib/nms/item/impl/_194ItemUtils.java @@ -1,19 +1,26 @@ package me.skymc.taboolib.nms.item.impl; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + import me.skymc.taboolib.json.JSONArray; import me.skymc.taboolib.json.JSONObject; import me.skymc.taboolib.nms.NMSUtils; import me.skymc.taboolib.nms.item.IDabItemUtils; import me.skymc.taboolib.nms.nbt.NBTConstants; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.*; -import java.util.Map.Entry; public class _194ItemUtils implements IDabItemUtils{ diff --git a/src/main/java/me/skymc/taboolib/other/WeightUtils.java b/src/main/java/me/skymc/taboolib/other/WeightUtils.java index 3083104..0a9bb7e 100644 --- a/src/main/java/me/skymc/taboolib/other/WeightUtils.java +++ b/src/main/java/me/skymc/taboolib/other/WeightUtils.java @@ -1,9 +1,9 @@ package me.skymc.taboolib.other; -import me.skymc.taboolib.object.WeightCategory; - import java.util.List; +import me.skymc.taboolib.object.WeightCategory; + public class WeightUtils { public static String getStringByWeight(List categorys) { diff --git a/src/main/java/me/skymc/taboolib/packet/PacketUtils.java b/src/main/java/me/skymc/taboolib/packet/PacketUtils.java index 2624085..ddfdebb 100644 --- a/src/main/java/me/skymc/taboolib/packet/PacketUtils.java +++ b/src/main/java/me/skymc/taboolib/packet/PacketUtils.java @@ -1,11 +1,12 @@ package me.skymc.taboolib.packet; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.WrappedDataWatcher; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; public class PacketUtils { diff --git a/src/main/java/me/skymc/taboolib/particle/EffLib.java b/src/main/java/me/skymc/taboolib/particle/EffLib.java index 4da1f84..1cc9a29 100644 --- a/src/main/java/me/skymc/taboolib/particle/EffLib.java +++ b/src/main/java/me/skymc/taboolib/particle/EffLib.java @@ -1,14 +1,5 @@ package me.skymc.taboolib.particle; -import me.skymc.taboolib.methods.ReflectionUtils; -import me.skymc.taboolib.methods.ReflectionUtils.PackageType; -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -18,6 +9,16 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import me.skymc.taboolib.methods.ReflectionUtils; +import me.skymc.taboolib.methods.ReflectionUtils.PackageType; + /** * ParticleEffect Library *

diff --git a/src/main/java/me/skymc/taboolib/permission/PermissionUtils.java b/src/main/java/me/skymc/taboolib/permission/PermissionUtils.java index 10fd367..b6588e1 100644 --- a/src/main/java/me/skymc/taboolib/permission/PermissionUtils.java +++ b/src/main/java/me/skymc/taboolib/permission/PermissionUtils.java @@ -1,9 +1,10 @@ package me.skymc.taboolib.permission; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; + import me.skymc.taboolib.Main; import net.milkbowl.vault.permission.Permission; -import org.bukkit.entity.Player; -import org.bukkit.plugin.RegisteredServiceProvider; public class PermissionUtils { diff --git a/src/main/java/me/skymc/taboolib/playerdata/DataUtils.java b/src/main/java/me/skymc/taboolib/playerdata/DataUtils.java index 5b612f5..774e380 100644 --- a/src/main/java/me/skymc/taboolib/playerdata/DataUtils.java +++ b/src/main/java/me/skymc/taboolib/playerdata/DataUtils.java @@ -1,10 +1,10 @@ package me.skymc.taboolib.playerdata; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.database.PlayerDataManager; -import me.skymc.taboolib.exception.PlayerOfflineException; -import me.skymc.taboolib.fileutils.FileUtils; -import me.skymc.taboolib.message.MsgUtils; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.configuration.file.FileConfiguration; @@ -14,10 +14,11 @@ import org.bukkit.event.Listener; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.plugin.Plugin; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.concurrent.ConcurrentHashMap; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.database.PlayerDataManager; +import me.skymc.taboolib.exception.PlayerOfflineException; +import me.skymc.taboolib.fileutils.FileUtils; +import me.skymc.taboolib.message.MsgUtils; public class DataUtils implements Listener { diff --git a/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java b/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java index d5374c5..5794f6c 100644 --- a/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java +++ b/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java @@ -1,23 +1,34 @@ package me.skymc.taboolib.plugin; -import com.google.common.base.Joiner; -import me.skymc.taboolib.Main; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Field; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.SortedSet; +import java.util.logging.Level; +import java.util.logging.Logger; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.PluginCommand; import org.bukkit.command.SimpleCommandMap; import org.bukkit.event.Event; -import org.bukkit.plugin.*; +import org.bukkit.plugin.InvalidDescriptionException; +import org.bukkit.plugin.InvalidPluginException; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.RegisteredListener; -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Field; -import java.net.URLClassLoader; -import java.util.*; -import java.util.Map.Entry; -import java.util.logging.Level; -import java.util.logging.Logger; +import com.google.common.base.Joiner; + +import me.skymc.taboolib.Main; public class PluginUtils { diff --git a/src/main/java/me/skymc/taboolib/regen/WorldGuardUtils.java b/src/main/java/me/skymc/taboolib/regen/WorldGuardUtils.java index d0ad421..0985731 100644 --- a/src/main/java/me/skymc/taboolib/regen/WorldGuardUtils.java +++ b/src/main/java/me/skymc/taboolib/regen/WorldGuardUtils.java @@ -1,10 +1,11 @@ package me.skymc.taboolib.regen; +import java.util.Map; + +import org.bukkit.Location; + import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import org.bukkit.Location; - -import java.util.Map; @Deprecated public class WorldGuardUtils { diff --git a/src/main/java/me/skymc/taboolib/scoreboard/ScoreboardUtil.java b/src/main/java/me/skymc/taboolib/scoreboard/ScoreboardUtil.java index f7331e8..2d96946 100644 --- a/src/main/java/me/skymc/taboolib/scoreboard/ScoreboardUtil.java +++ b/src/main/java/me/skymc/taboolib/scoreboard/ScoreboardUtil.java @@ -1,15 +1,15 @@ package me.skymc.taboolib.scoreboard; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Scoreboard; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Scoreboard; + public class ScoreboardUtil { private ScoreboardUtil() { } diff --git a/src/main/java/me/skymc/taboolib/skript/SkriptHandler.java b/src/main/java/me/skymc/taboolib/skript/SkriptHandler.java index 9b88a78..9df2f0d 100644 --- a/src/main/java/me/skymc/taboolib/skript/SkriptHandler.java +++ b/src/main/java/me/skymc/taboolib/skript/SkriptHandler.java @@ -1,11 +1,12 @@ package me.skymc.taboolib.skript; +import org.bukkit.Bukkit; +import org.bukkit.inventory.ItemStack; + import ch.njol.skript.Skript; import ch.njol.skript.lang.ExpressionType; import me.skymc.taboolib.skript.expression.ExpressionItemCache; import me.skymc.taboolib.skript.expression.ExpressionTabooCodeItem; -import org.bukkit.Bukkit; -import org.bukkit.inventory.ItemStack; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/skript/expression/ExpressionTabooCodeItem.java b/src/main/java/me/skymc/taboolib/skript/expression/ExpressionTabooCodeItem.java index 566305a..df51680 100644 --- a/src/main/java/me/skymc/taboolib/skript/expression/ExpressionTabooCodeItem.java +++ b/src/main/java/me/skymc/taboolib/skript/expression/ExpressionTabooCodeItem.java @@ -1,12 +1,13 @@ package me.skymc.taboolib.skript.expression; +import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; + import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; import me.skymc.taboocode.TabooCodeItem; -import org.bukkit.event.Event; -import org.bukkit.inventory.ItemStack; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/string/Language.java b/src/main/java/me/skymc/taboolib/string/Language.java index db5dea2..f81c70b 100644 --- a/src/main/java/me/skymc/taboolib/string/Language.java +++ b/src/main/java/me/skymc/taboolib/string/Language.java @@ -1,13 +1,5 @@ package me.skymc.taboolib.string; -import com.google.common.base.Charsets; -import me.skymc.taboolib.message.MsgUtils; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -15,6 +7,16 @@ import java.io.InputStreamReader; import java.util.Collections; import java.util.List; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import com.google.common.base.Charsets; + +import me.skymc.taboolib.message.MsgUtils; + public class Language { private FileConfiguration conf = null; diff --git a/src/main/java/me/skymc/taboolib/string/LanguageUtils.java b/src/main/java/me/skymc/taboolib/string/LanguageUtils.java index 2e4d935..199e61f 100644 --- a/src/main/java/me/skymc/taboolib/string/LanguageUtils.java +++ b/src/main/java/me/skymc/taboolib/string/LanguageUtils.java @@ -1,12 +1,13 @@ package me.skymc.taboolib.string; -import me.skymc.taboolib.message.MsgUtils; -import org.bukkit.plugin.Plugin; - import java.io.File; import java.util.Collections; import java.util.List; +import org.bukkit.plugin.Plugin; + +import me.skymc.taboolib.message.MsgUtils; + @Deprecated public class LanguageUtils { diff --git a/src/main/java/me/skymc/taboolib/string/language2/Language2Format.java b/src/main/java/me/skymc/taboolib/string/language2/Language2Format.java index ccb1dff..b2ecc8b 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/Language2Format.java +++ b/src/main/java/me/skymc/taboolib/string/language2/Language2Format.java @@ -1,15 +1,20 @@ package me.skymc.taboolib.string.language2; -import lombok.Getter; -import me.skymc.taboolib.string.language2.value.*; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import org.bukkit.entity.Player; + +import lombok.Getter; +import me.skymc.taboolib.string.language2.value.Language2Action; +import me.skymc.taboolib.string.language2.value.Language2Book; +import me.skymc.taboolib.string.language2.value.Language2Json; +import me.skymc.taboolib.string.language2.value.Language2Json2; +import me.skymc.taboolib.string.language2.value.Language2Sound; +import me.skymc.taboolib.string.language2.value.Language2Text; +import me.skymc.taboolib.string.language2.value.Language2Title; + /** * @author sky * @since 2018-03-08 22:45:56 diff --git a/src/main/java/me/skymc/taboolib/string/language2/Language2Value.java b/src/main/java/me/skymc/taboolib/string/language2/Language2Value.java index fddf89e..9f2abd5 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/Language2Value.java +++ b/src/main/java/me/skymc/taboolib/string/language2/Language2Value.java @@ -1,14 +1,19 @@ package me.skymc.taboolib.string.language2; -import lombok.Getter; -import me.skymc.taboolib.string.language2.value.Language2Text; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map.Entry; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.*; -import java.util.Map.Entry; +import lombok.Getter; +import me.skymc.taboolib.string.language2.value.Language2Text; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Action.java b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Action.java index 9ac909e..10ede35 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Action.java +++ b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Action.java @@ -1,5 +1,12 @@ package me.skymc.taboolib.string.language2.value; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + import lombok.Getter; import me.skymc.taboolib.Main; import me.skymc.taboolib.TabooLib; @@ -8,12 +15,6 @@ import me.skymc.taboolib.other.NumberUtils; import me.skymc.taboolib.string.language2.Language2Format; import me.skymc.taboolib.string.language2.Language2Line; import me.skymc.taboolib.string.language2.Language2Value; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.List; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Book.java b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Book.java index b59586f..7a0957e 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Book.java +++ b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Book.java @@ -1,5 +1,18 @@ package me.skymc.taboolib.string.language2.value; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + import lombok.Getter; import me.skymc.taboolib.bookformatter.BookFormatter; import me.skymc.taboolib.bookformatter.action.ClickAction; @@ -12,18 +25,6 @@ import me.skymc.taboolib.other.NumberUtils; import me.skymc.taboolib.string.language2.Language2Format; import me.skymc.taboolib.string.language2.Language2Line; import me.skymc.taboolib.string.language2.Language2Value; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Json.java b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Json.java index 9dd12a4..36d5ed2 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Json.java +++ b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Json.java @@ -1,5 +1,13 @@ package me.skymc.taboolib.string.language2.value; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + import lombok.Getter; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.jsonformatter.JSONFormatter; @@ -13,13 +21,6 @@ import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; import me.skymc.taboolib.string.language2.Language2Format; import me.skymc.taboolib.string.language2.Language2Line; import me.skymc.taboolib.string.language2.Language2Value; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import java.util.List; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Json2.java b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Json2.java index 40b1503..843cb87 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Json2.java +++ b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Json2.java @@ -1,5 +1,18 @@ package me.skymc.taboolib.string.language2.value; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + import lombok.Getter; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.jsonformatter.JSONFormatter; @@ -13,18 +26,6 @@ import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; import me.skymc.taboolib.string.language2.Language2Format; import me.skymc.taboolib.string.language2.Language2Line; import me.skymc.taboolib.string.language2.Language2Value; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Text.java b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Text.java index 2c66ed6..270cd05 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Text.java +++ b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Text.java @@ -1,14 +1,15 @@ package me.skymc.taboolib.string.language2.value; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + import lombok.Getter; import me.skymc.taboolib.string.language2.Language2Format; import me.skymc.taboolib.string.language2.Language2Line; import me.skymc.taboolib.string.language2.Language2Value; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Title.java b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Title.java index 372d6e9..aa6894a 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Title.java +++ b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Title.java @@ -1,16 +1,17 @@ package me.skymc.taboolib.string.language2.value; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + import lombok.Getter; import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.display.TitleUtils; import me.skymc.taboolib.string.language2.Language2Format; import me.skymc.taboolib.string.language2.Language2Line; import me.skymc.taboolib.string.language2.Language2Value; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import java.util.List; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/support/SupportPlaceholder.java b/src/main/java/me/skymc/taboolib/support/SupportPlaceholder.java index 0272787..34e13b9 100644 --- a/src/main/java/me/skymc/taboolib/support/SupportPlaceholder.java +++ b/src/main/java/me/skymc/taboolib/support/SupportPlaceholder.java @@ -1,12 +1,13 @@ package me.skymc.taboolib.support; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + import me.clip.placeholderapi.external.EZPlaceholderHook; import me.skymc.taboolib.database.GlobalDataManager; import me.skymc.tlm.TLM; import me.skymc.tlm.module.TabooLibraryModule; import me.skymc.tlm.module.sub.ModuleKits; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; public class SupportPlaceholder extends EZPlaceholderHook { diff --git a/src/main/java/me/skymc/taboolib/support/SupportWorldGuard.java b/src/main/java/me/skymc/taboolib/support/SupportWorldGuard.java index 503bec6..e326e33 100644 --- a/src/main/java/me/skymc/taboolib/support/SupportWorldGuard.java +++ b/src/main/java/me/skymc/taboolib/support/SupportWorldGuard.java @@ -1,15 +1,16 @@ package me.skymc.taboolib.support; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import java.util.Collection; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import java.util.Collection; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; public class SupportWorldGuard { diff --git a/src/main/java/me/skymc/taboolib/team/TagManager.java b/src/main/java/me/skymc/taboolib/team/TagManager.java index 5d37efa..997a487 100644 --- a/src/main/java/me/skymc/taboolib/team/TagManager.java +++ b/src/main/java/me/skymc/taboolib/team/TagManager.java @@ -1,8 +1,7 @@ package me.skymc.taboolib.team; -import lombok.Getter; -import lombok.Setter; -import me.skymc.taboolib.Main; +import java.util.HashMap; + import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -12,7 +11,9 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; -import java.util.HashMap; +import lombok.Getter; +import lombok.Setter; +import me.skymc.taboolib.Main; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/timecycle/TimeCycleManager.java b/src/main/java/me/skymc/taboolib/timecycle/TimeCycleManager.java index a5a705b..a9f0270 100644 --- a/src/main/java/me/skymc/taboolib/timecycle/TimeCycleManager.java +++ b/src/main/java/me/skymc/taboolib/timecycle/TimeCycleManager.java @@ -1,16 +1,17 @@ package me.skymc.taboolib.timecycle; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.database.GlobalDataManager; -import me.skymc.taboolib.message.MsgUtils; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; - import java.util.Collection; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; + +import me.skymc.taboolib.Main; +import me.skymc.taboolib.database.GlobalDataManager; +import me.skymc.taboolib.message.MsgUtils; + public class TimeCycleManager { /** diff --git a/src/main/java/me/skymc/taboolib/update/UpdateTask.java b/src/main/java/me/skymc/taboolib/update/UpdateTask.java index 3b9bc1c..0c1c5f1 100644 --- a/src/main/java/me/skymc/taboolib/update/UpdateTask.java +++ b/src/main/java/me/skymc/taboolib/update/UpdateTask.java @@ -1,13 +1,14 @@ package me.skymc.taboolib.update; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.bukkit.scheduler.BukkitRunnable; + import me.skymc.taboolib.Main; import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.fileutils.FileUtils; import me.skymc.taboolib.message.MsgUtils; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * @author sky @@ -23,19 +24,18 @@ public class UpdateTask { @Override public void run() { - // 是否禁用 if (!Main.getInst().getConfig().getBoolean("UPDATE-CHECK")) { return; } - String value = FileUtils.getStringFromURL("https://github.com/Bkm016/TabooLib/releases", 1024); + if (value == null) { + return; + } Pattern pattern = Pattern.compile(""); Matcher matcher = pattern.matcher(value); if (matcher.find()) { - // 最新版本 double newVersion = Double.valueOf(matcher.group(1)); - // 如果是最新版 - if (TabooLib.getPluginVersion() == newVersion) { + if (TabooLib.getPluginVersion() >= newVersion) { MsgUtils.send("插件已是最新版, 无需更新!"); } else { diff --git a/src/main/java/me/skymc/tlm/TLM.java b/src/main/java/me/skymc/tlm/TLM.java index 7495c49..cff3dce 100644 --- a/src/main/java/me/skymc/tlm/TLM.java +++ b/src/main/java/me/skymc/tlm/TLM.java @@ -1,5 +1,7 @@ package me.skymc.tlm; +import org.bukkit.configuration.file.FileConfiguration; + import lombok.Getter; import me.skymc.taboolib.Main; import me.skymc.taboolib.fileutils.ConfigUtils; @@ -10,7 +12,6 @@ import me.skymc.tlm.module.sub.ModuleCommandChanger; import me.skymc.tlm.module.sub.ModuleInventorySave; import me.skymc.tlm.module.sub.ModuleKits; import me.skymc.tlm.module.sub.ModuleTimeCycle; -import org.bukkit.configuration.file.FileConfiguration; /** * @author sky diff --git a/src/main/java/me/skymc/tlm/annotation/DisableConfig.java b/src/main/java/me/skymc/tlm/annotation/DisableConfig.java index 091301e..83b8a2a 100644 --- a/src/main/java/me/skymc/tlm/annotation/DisableConfig.java +++ b/src/main/java/me/skymc/tlm/annotation/DisableConfig.java @@ -1,11 +1,11 @@ package me.skymc.tlm.annotation; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + @Retention(RUNTIME) @Target(TYPE) public @interface DisableConfig { diff --git a/src/main/java/me/skymc/tlm/command/sub/TLMKitCommand.java b/src/main/java/me/skymc/tlm/command/sub/TLMKitCommand.java index 65055e9..42949ee 100644 --- a/src/main/java/me/skymc/tlm/command/sub/TLMKitCommand.java +++ b/src/main/java/me/skymc/tlm/command/sub/TLMKitCommand.java @@ -1,16 +1,17 @@ package me.skymc.tlm.command.sub; -import me.skymc.taboolib.commands.SubCommand; -import me.skymc.tlm.TLM; -import me.skymc.tlm.module.TabooLibraryModule; -import me.skymc.tlm.module.sub.ModuleKits; +import java.util.HashMap; +import java.util.List; + import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import java.util.HashMap; -import java.util.List; +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.tlm.TLM; +import me.skymc.tlm.module.TabooLibraryModule; +import me.skymc.tlm.module.sub.ModuleKits; /** * @author sky diff --git a/src/main/java/me/skymc/tlm/module/TabooLibraryModule.java b/src/main/java/me/skymc/tlm/module/TabooLibraryModule.java index e1d9216..ae1dd5c 100644 --- a/src/main/java/me/skymc/tlm/module/TabooLibraryModule.java +++ b/src/main/java/me/skymc/tlm/module/TabooLibraryModule.java @@ -1,15 +1,16 @@ package me.skymc.tlm.module; -import me.skymc.taboolib.Main; -import me.skymc.tlm.annotation.DisableConfig; +import java.io.File; +import java.util.HashMap; +import java.util.Set; + import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.Listener; -import java.io.File; -import java.util.HashMap; -import java.util.Set; +import me.skymc.taboolib.Main; +import me.skymc.tlm.annotation.DisableConfig; /** * @author sky diff --git a/src/main/java/me/skymc/tlm/module/sub/ModuleKits.java b/src/main/java/me/skymc/tlm/module/sub/ModuleKits.java index 250e12a..cdaed64 100644 --- a/src/main/java/me/skymc/tlm/module/sub/ModuleKits.java +++ b/src/main/java/me/skymc/tlm/module/sub/ModuleKits.java @@ -1,17 +1,18 @@ package me.skymc.tlm.module.sub; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.other.DateUtils; import me.skymc.taboolib.other.NumberUtils; import me.skymc.taboolib.playerdata.DataUtils; import me.skymc.tlm.module.ITabooLibraryModule; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; -import java.util.List; /** * @author sky diff --git a/src/main/java/me/skymc/tlm/module/sub/ModuleTimeCycle.java b/src/main/java/me/skymc/tlm/module/sub/ModuleTimeCycle.java index a367941..7e52f22 100644 --- a/src/main/java/me/skymc/tlm/module/sub/ModuleTimeCycle.java +++ b/src/main/java/me/skymc/tlm/module/sub/ModuleTimeCycle.java @@ -1,5 +1,11 @@ package me.skymc.tlm.module.sub; +import java.util.Calendar; + +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + import me.skymc.taboolib.Main; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.other.DateUtils; @@ -9,11 +15,6 @@ import me.skymc.taboolib.timecycle.TimeCycleEvent; import me.skymc.taboolib.timecycle.TimeCycleInitializeEvent; import me.skymc.taboolib.timecycle.TimeCycleManager; import me.skymc.tlm.module.ITabooLibraryModule; -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -import java.util.Calendar; /** * @author sky diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index eff92f7..b7c6087 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -21,6 +21,9 @@ DEBUG: false # 离线模式下将不会下载依赖 OFFLINE-MODE: false +# 下载依赖时启用的线程数 +DOWNLOAD-POOL-SIZE: 4 + # 是否启用更新检测 UPDATE-CHECK: true @@ -62,4 +65,4 @@ MYSQL: PluginData: # 检查更新间隔(单位:秒) # 检查变量是否被其他服务器更新 - CHECK-DELAY: 30 \ No newline at end of file + CHECK-DELAY: 5 \ No newline at end of file