From 41e53b9165501a8970d5bda53e2ad36f50e349c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Thu, 10 May 2018 00:44:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=BD=E4=BB=A4=E7=B3=BB=E7=BB=9F=E9=87=8D?= =?UTF-8?q?=E5=81=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ilummc/tlib/annotations/Dependency.java | 8 +- .../ilummc/tlib/bean/PropertyTypeAdaptor.java | 4 +- .../tlib/bungee/api/chat/TextComponent.java | 2 +- .../bungee/chat/TextComponentSerializer.java | 11 +- .../ilummc/tlib/compat/PlaceholderHook.java | 3 +- .../com/ilummc/tlib/filter/TLoggerFilter.java | 7 +- .../ilummc/tlib/inject/TConfigWatcher.java | 1 - .../com/ilummc/tlib/util/asm/AsmAnalyser.java | 6 +- src/main/java/me/skymc/taboolib/Main.java | 21 +- .../taboolib/bookformatter/BookFormatter.java | 5 +- .../bookformatter/builder/BookBuilder.java | 9 +- .../bookformatter/builder/PageBuilder.java | 6 +- .../me/skymc/taboolib/client/LogClient.java | 11 +- .../skymc/taboolib/commands/MainCommands.java | 65 -- .../skymc/taboolib/commands/SubCommand.java | 1 + .../commands/TabooLibMainCommand.java | 755 ++++++++++++++++++ .../commands/internal/BaseMainCommand.java | 162 ++++ ...mmandExecutor.java => BaseSubCommand.java} | 17 +- ...InternalCommand.java => IMainCommand.java} | 7 +- .../commands/internal/ISubCommand.java | 44 + .../commands/internal/InternalArgument.java | 29 - .../internal/InternalCommandExecutor.java | 111 --- .../commands/internal/InternalSubCommand.java | 20 - .../internal/InternalSubCommandType.java | 11 - .../internal/type/CommandArgument.java | 52 ++ .../internal/type/CommandRegister.java | 18 + .../commands/internal/type/CommandType.java | 11 + ...nd.java => TabooLibPluginMainCommand.java} | 40 +- .../taboolib/commands/sub/ImportCommand.java | 50 -- .../commands/sub/cycle/CycleCommand.java | 31 - .../commands/sub/shell/ShellCommand.java | 27 - .../{sub => taboolib}/AttributesCommand.java | 2 +- .../cycle => taboolib}/CycleInfoCommand.java | 10 +- .../cycle => taboolib}/CycleListCommand.java | 13 +- .../cycle => taboolib}/CycleResetCommand.java | 10 +- .../CycleUpdateCommand.java | 10 +- .../{sub => taboolib}/EnchantCommand.java | 2 +- .../{sub => taboolib}/FlagCommand.java | 2 +- .../commands/taboolib/ImportCommand.java | 50 ++ .../{sub => taboolib}/InfoCommand.java | 2 +- .../{sub => taboolib}/ItemCommand.java | 2 +- .../ItemListCommand.java | 8 +- .../{sub => taboolib}/PotionCommand.java | 2 +- .../{sub => taboolib}/SaveCommand.java | 5 +- .../shell => taboolib}/ShellLoadCommand.java | 6 +- .../ShellUnloadCommand.java | 2 +- .../{sub => taboolib}/SlotCommand.java | 2 +- .../sounds => taboolib}/SoundsCommand.java | 10 +- .../{sub => taboolib}/TagDeleteCommand.java | 6 +- .../commands/taboolib/TagDisplayCommand.java | 41 + .../{sub => taboolib}/TagPrefixCommand.java | 10 +- .../{sub => taboolib}/TagSuffixCommand.java | 3 +- .../{sub => taboolib}/VariableGetCommand.java | 2 +- .../{sub => taboolib}/VariableSetCommand.java | 2 +- .../listener/ListenerItemListCommand.java} | 4 +- .../listener/ListenerSoundsCommand.java} | 4 +- .../cooldown/seconds/CooldownUtils2.java | 4 +- .../me/skymc/taboolib/csvutils/CsvWriter.java | 42 +- .../taboolib/database/GlobalDataManager.java | 18 +- .../taboolib/database/PlayerDataManager.java | 1 - .../enchantment/EnchantmentUtils.java | 4 +- .../itag/AsyncPlayerReceiveNameTagEvent.java | 85 ++ .../itag/PlayerReceiveNameTagEvent.java | 57 ++ .../skymc/taboolib/fileutils/ConfigUtils.java | 1 - .../skymc/taboolib/fileutils/FileUtils.java | 1 - .../skymc/taboolib/inventory/ItemUtils.java | 8 +- .../taboolib/itemnbtapi/NBTCompound.java | 4 +- .../taboolib/jsonformatter/JSONFormatter.java | 2 +- .../jsonformatter/hover/ShowItemEvent.java | 17 +- .../taboolib/listener/ListenerNetWork.java | 7 +- .../listener/ListenerPlayerCommand.java | 11 +- .../taboolib/listener/ListenerPlayerQuit.java | 3 +- .../taboolib/methods/ReflectionUtils.java | 4 +- .../skymc/taboolib/mysql/MysqlConnection.java | 8 +- .../mysql/protect/MySQLConnection.java | 6 +- .../java/me/skymc/taboolib/nms/NMSUtil19.java | 26 +- .../skymc/taboolib/nms/item/DabItemUtils.java | 19 +- .../taboolib/nms/item/IDabItemUtils.java | 9 +- .../me/skymc/taboolib/particle/EffLib.java | 19 +- .../skymc/taboolib/particle/ParticlePack.java | 3 +- .../taboolib/permission/PermissionUtils.java | 5 +- .../me/skymc/taboolib/player/PlayerUtils.java | 4 +- .../skymc/taboolib/playerdata/DataUtils.java | 1 - .../me/skymc/taboolib/plugin/PluginUtils.java | 4 +- .../skymc/taboolib/regen/WorldGuardUtils.java | 7 +- .../skymc/taboolib/skript/SkriptHandler.java | 5 +- .../expression/ExpressionItemCache.java | 5 +- .../expression/ExpressionTabooCodeItem.java | 5 +- .../skymc/taboolib/string/LanguagePack.java | 11 +- .../skymc/taboolib/string/LanguageUtils.java | 7 +- .../taboolib/string/language2/Language2.java | 1 - .../skymc/taboolib/string/obfuscated/FZ.java | 6 +- .../java/me/skymc/taboolib/team/TagAPI.java | 150 ++++ .../me/skymc/taboolib/update/UpdateTask.java | 1 - .../skymc/tlm/command/sub/TLMInvCommand.java | 17 +- .../skymc/tlm/command/sub/TLMKitCommand.java | 15 +- .../skymc/tlm/command/sub/TLMListCommand.java | 3 +- .../tlm/command/sub/TLMReloadCommand.java | 3 +- .../tlm/module/sub/ModuleCommandChanger.java | 3 +- src/main/resources/lang/zh_CN.yml | 105 ++- 100 files changed, 1765 insertions(+), 707 deletions(-) create mode 100644 src/main/java/me/skymc/taboolib/commands/TabooLibMainCommand.java create mode 100644 src/main/java/me/skymc/taboolib/commands/internal/BaseMainCommand.java rename src/main/java/me/skymc/taboolib/commands/internal/{InternalSubCommandExecutor.java => BaseSubCommand.java} (71%) rename src/main/java/me/skymc/taboolib/commands/internal/{InternalCommand.java => IMainCommand.java} (57%) create mode 100644 src/main/java/me/skymc/taboolib/commands/internal/ISubCommand.java delete mode 100644 src/main/java/me/skymc/taboolib/commands/internal/InternalArgument.java delete mode 100644 src/main/java/me/skymc/taboolib/commands/internal/InternalCommandExecutor.java delete mode 100644 src/main/java/me/skymc/taboolib/commands/internal/InternalSubCommand.java delete mode 100644 src/main/java/me/skymc/taboolib/commands/internal/InternalSubCommandType.java create mode 100644 src/main/java/me/skymc/taboolib/commands/internal/type/CommandArgument.java create mode 100644 src/main/java/me/skymc/taboolib/commands/internal/type/CommandRegister.java create mode 100644 src/main/java/me/skymc/taboolib/commands/internal/type/CommandType.java rename src/main/java/me/skymc/taboolib/commands/plugin/{TabooLibPluginCommand.java => TabooLibPluginMainCommand.java} (82%) delete mode 100644 src/main/java/me/skymc/taboolib/commands/sub/ImportCommand.java delete mode 100644 src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java delete mode 100644 src/main/java/me/skymc/taboolib/commands/sub/shell/ShellCommand.java rename src/main/java/me/skymc/taboolib/commands/{sub => taboolib}/AttributesCommand.java (93%) rename src/main/java/me/skymc/taboolib/commands/{sub/cycle => taboolib}/CycleInfoCommand.java (94%) rename src/main/java/me/skymc/taboolib/commands/{sub/cycle => taboolib}/CycleListCommand.java (64%) rename src/main/java/me/skymc/taboolib/commands/{sub/cycle => taboolib}/CycleResetCommand.java (94%) rename src/main/java/me/skymc/taboolib/commands/{sub/cycle => taboolib}/CycleUpdateCommand.java (93%) rename src/main/java/me/skymc/taboolib/commands/{sub => taboolib}/EnchantCommand.java (93%) rename src/main/java/me/skymc/taboolib/commands/{sub => taboolib}/FlagCommand.java (93%) create mode 100644 src/main/java/me/skymc/taboolib/commands/taboolib/ImportCommand.java rename src/main/java/me/skymc/taboolib/commands/{sub => taboolib}/InfoCommand.java (96%) rename src/main/java/me/skymc/taboolib/commands/{sub => taboolib}/ItemCommand.java (97%) rename src/main/java/me/skymc/taboolib/commands/{sub/itemlist => taboolib}/ItemListCommand.java (61%) rename src/main/java/me/skymc/taboolib/commands/{sub => taboolib}/PotionCommand.java (94%) rename src/main/java/me/skymc/taboolib/commands/{sub => taboolib}/SaveCommand.java (97%) rename src/main/java/me/skymc/taboolib/commands/{sub/shell => taboolib}/ShellLoadCommand.java (77%) rename src/main/java/me/skymc/taboolib/commands/{sub/shell => taboolib}/ShellUnloadCommand.java (95%) rename src/main/java/me/skymc/taboolib/commands/{sub => taboolib}/SlotCommand.java (93%) rename src/main/java/me/skymc/taboolib/commands/{sub/sounds => taboolib}/SoundsCommand.java (55%) rename src/main/java/me/skymc/taboolib/commands/{sub => taboolib}/TagDeleteCommand.java (88%) create mode 100644 src/main/java/me/skymc/taboolib/commands/taboolib/TagDisplayCommand.java rename src/main/java/me/skymc/taboolib/commands/{sub => taboolib}/TagPrefixCommand.java (92%) rename src/main/java/me/skymc/taboolib/commands/{sub => taboolib}/TagSuffixCommand.java (93%) rename src/main/java/me/skymc/taboolib/commands/{sub => taboolib}/VariableGetCommand.java (96%) rename src/main/java/me/skymc/taboolib/commands/{sub => taboolib}/VariableSetCommand.java (96%) rename src/main/java/me/skymc/taboolib/commands/{sub/itemlist/listener/ItemLibraryPatch.java => taboolib/listener/ListenerItemListCommand.java} (97%) rename src/main/java/me/skymc/taboolib/commands/{sub/sounds/listener/SoundsLibraryPatch.java => taboolib/listener/ListenerSoundsCommand.java} (97%) create mode 100644 src/main/java/me/skymc/taboolib/events/itag/AsyncPlayerReceiveNameTagEvent.java create mode 100644 src/main/java/me/skymc/taboolib/events/itag/PlayerReceiveNameTagEvent.java create mode 100644 src/main/java/me/skymc/taboolib/team/TagAPI.java diff --git a/src/main/java/com/ilummc/tlib/annotations/Dependency.java b/src/main/java/com/ilummc/tlib/annotations/Dependency.java index 0f00aca..9c706c9 100644 --- a/src/main/java/com/ilummc/tlib/annotations/Dependency.java +++ b/src/main/java/com/ilummc/tlib/annotations/Dependency.java @@ -1,13 +1,9 @@ package com.ilummc.tlib.annotations; -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 com.ilummc.tlib.dependency.TDependency; +import java.lang.annotation.*; + @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Repeatable(Dependencies.class) diff --git a/src/main/java/com/ilummc/tlib/bean/PropertyTypeAdaptor.java b/src/main/java/com/ilummc/tlib/bean/PropertyTypeAdaptor.java index 0a52b19..f802433 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/bungee/api/chat/TextComponent.java b/src/main/java/com/ilummc/tlib/bungee/api/chat/TextComponent.java index eadaef7..28d935c 100644 --- a/src/main/java/com/ilummc/tlib/bungee/api/chat/TextComponent.java +++ b/src/main/java/com/ilummc/tlib/bungee/api/chat/TextComponent.java @@ -5,7 +5,7 @@ package com.ilummc.tlib.bungee.api.chat; -import com.ilummc.tlib.bungee.api.*; +import com.ilummc.tlib.bungee.api.ChatColor; import java.beans.ConstructorProperties; import java.util.ArrayList; diff --git a/src/main/java/com/ilummc/tlib/bungee/chat/TextComponentSerializer.java b/src/main/java/com/ilummc/tlib/bungee/chat/TextComponentSerializer.java index bd9b53f..9fccef9 100644 --- a/src/main/java/com/ilummc/tlib/bungee/chat/TextComponentSerializer.java +++ b/src/main/java/com/ilummc/tlib/bungee/chat/TextComponentSerializer.java @@ -5,14 +5,9 @@ package com.ilummc.tlib.bungee.chat; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import com.ilummc.tlib.bungee.api.chat.*; +import com.google.gson.*; +import com.ilummc.tlib.bungee.api.chat.BaseComponent; +import com.ilummc.tlib.bungee.api.chat.TextComponent; import java.lang.reflect.Type; import java.util.List; diff --git a/src/main/java/com/ilummc/tlib/compat/PlaceholderHook.java b/src/main/java/com/ilummc/tlib/compat/PlaceholderHook.java index e5ee889..c0b26c8 100644 --- a/src/main/java/com/ilummc/tlib/compat/PlaceholderHook.java +++ b/src/main/java/com/ilummc/tlib/compat/PlaceholderHook.java @@ -1,11 +1,10 @@ package com.ilummc.tlib.compat; +import me.clip.placeholderapi.PlaceholderAPI; 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; diff --git a/src/main/java/com/ilummc/tlib/filter/TLoggerFilter.java b/src/main/java/com/ilummc/tlib/filter/TLoggerFilter.java index 140347a..af72083 100644 --- a/src/main/java/com/ilummc/tlib/filter/TLoggerFilter.java +++ b/src/main/java/com/ilummc/tlib/filter/TLoggerFilter.java @@ -27,9 +27,6 @@ public class TLoggerFilter implements Filter { } return false; } - else if (e.getMessage().contains("Enabled plugin with unregistered PluginClassLoader")) { - return false; - } - return true; - } + else return !e.getMessage().contains("Enabled plugin with unregistered PluginClassLoader"); + } } diff --git a/src/main/java/com/ilummc/tlib/inject/TConfigWatcher.java b/src/main/java/com/ilummc/tlib/inject/TConfigWatcher.java index f364ada..34d67b0 100644 --- a/src/main/java/com/ilummc/tlib/inject/TConfigWatcher.java +++ b/src/main/java/com/ilummc/tlib/inject/TConfigWatcher.java @@ -11,7 +11,6 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; 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 2cb58b8..58ce0d5 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 3ed028a..b8e2d82 100644 --- a/src/main/java/me/skymc/taboolib/Main.java +++ b/src/main/java/me/skymc/taboolib/Main.java @@ -3,13 +3,13 @@ package me.skymc.taboolib; import com.ilummc.tlib.TLib; import me.skymc.taboolib.anvil.AnvilContainerAPI; import me.skymc.taboolib.bstats.Metrics; -import me.skymc.taboolib.commands.MainCommands; -import me.skymc.taboolib.commands.internal.InternalCommandExecutor; +import me.skymc.taboolib.commands.TabooLibMainCommand; +import me.skymc.taboolib.commands.internal.BaseMainCommand; import me.skymc.taboolib.commands.language.Language2Command; import me.skymc.taboolib.commands.locale.TabooLibLocaleCommand; -import me.skymc.taboolib.commands.plugin.TabooLibPluginCommand; -import me.skymc.taboolib.commands.sub.itemlist.listener.ItemLibraryPatch; -import me.skymc.taboolib.commands.sub.sounds.listener.SoundsLibraryPatch; +import me.skymc.taboolib.commands.plugin.TabooLibPluginMainCommand; +import me.skymc.taboolib.commands.taboolib.listener.ListenerItemListCommand; +import me.skymc.taboolib.commands.taboolib.listener.ListenerSoundsCommand; import me.skymc.taboolib.database.GlobalDataManager; import me.skymc.taboolib.database.PlayerDataManager; import me.skymc.taboolib.economy.EcoUtils; @@ -31,6 +31,7 @@ import me.skymc.taboolib.skript.SkriptHandler; import me.skymc.taboolib.string.StringUtils; import me.skymc.taboolib.string.language2.Language2; import me.skymc.taboolib.support.SupportPlaceholder; +import me.skymc.taboolib.team.TagAPI; import me.skymc.taboolib.team.TagUtils; import me.skymc.taboolib.timecycle.TimeCycleManager; import me.skymc.taboolib.update.UpdateTask; @@ -201,11 +202,11 @@ public class Main extends JavaPlugin implements Listener { @Override public void onEnable() { // 注册指令 - getCommand("taboolib").setExecutor(new MainCommands()); getCommand("language2").setExecutor(new Language2Command()); getCommand("taboolibrarymodule").setExecutor(new TLMCommands()); getCommand("tabooliblocale").setExecutor(new TabooLibLocaleCommand()); - InternalCommandExecutor.createCommandExecutor("taboolibplugin", new TabooLibPluginCommand()); + BaseMainCommand.createCommandExecutor("taboolib", new TabooLibMainCommand()); + BaseMainCommand.createCommandExecutor("taboolibplugin", new TabooLibPluginMainCommand()); // 注册监听 registerListener(); @@ -225,6 +226,8 @@ public class Main extends JavaPlugin implements Listener { exampleLanguage2 = new Language2("Language2", this); // 注册脚本 SkriptHandler.getInst(); + // 注册昵称 + TagAPI.inst(); // 启动数据库储存方法 if (getStorageType() == StorageType.SQL) { @@ -344,8 +347,8 @@ public class Main extends JavaPlugin implements Listener { getServer().getPluginManager().registerEvents(new AnvilContainerAPI(), this); getServer().getPluginManager().registerEvents(new ListenerPluginDisable(), this); getServer().getPluginManager().registerEvents(new PlayerDataManager(), this); - getServer().getPluginManager().registerEvents(new ItemLibraryPatch(), this); - getServer().getPluginManager().registerEvents(new SoundsLibraryPatch(), this); + getServer().getPluginManager().registerEvents(new ListenerItemListCommand(), this); + getServer().getPluginManager().registerEvents(new ListenerSoundsCommand(), this); if (TabooLib.getVerint() > 10700) { getServer().getPluginManager().registerEvents(new EntityUtils(), this); diff --git a/src/main/java/me/skymc/taboolib/bookformatter/BookFormatter.java b/src/main/java/me/skymc/taboolib/bookformatter/BookFormatter.java index 2f9ff1b..0931219 100644 --- a/src/main/java/me/skymc/taboolib/bookformatter/BookFormatter.java +++ b/src/main/java/me/skymc/taboolib/bookformatter/BookFormatter.java @@ -1,13 +1,12 @@ 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/builder/BookBuilder.java b/src/main/java/me/skymc/taboolib/bookformatter/builder/BookBuilder.java index 474f3a2..3c639ed 100644 --- a/src/main/java/me/skymc/taboolib/bookformatter/builder/BookBuilder.java +++ b/src/main/java/me/skymc/taboolib/bookformatter/builder/BookBuilder.java @@ -1,12 +1,11 @@ package me.skymc.taboolib.bookformatter.builder; -import java.util.List; - -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BookMeta; - import me.skymc.taboolib.bookformatter.BookReflection; import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; + +import java.util.List; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/bookformatter/builder/PageBuilder.java b/src/main/java/me/skymc/taboolib/bookformatter/builder/PageBuilder.java index cf0861b..73e7ced 100644 --- a/src/main/java/me/skymc/taboolib/bookformatter/builder/PageBuilder.java +++ b/src/main/java/me/skymc/taboolib/bookformatter/builder/PageBuilder.java @@ -1,13 +1,13 @@ package me.skymc.taboolib.bookformatter.builder; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.TextComponent; - /** * @author sky * @since 2018-03-08 22:36:58 diff --git a/src/main/java/me/skymc/taboolib/client/LogClient.java b/src/main/java/me/skymc/taboolib/client/LogClient.java index 7893563..5fce466 100644 --- a/src/main/java/me/skymc/taboolib/client/LogClient.java +++ b/src/main/java/me/skymc/taboolib/client/LogClient.java @@ -1,14 +1,9 @@ package me.skymc.taboolib.client; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Font; -import java.text.SimpleDateFormat; - -import javax.swing.JFrame; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; +import javax.swing.*; import javax.swing.border.BevelBorder; +import java.awt.*; +import java.text.SimpleDateFormat; @Deprecated public class LogClient extends JFrame { diff --git a/src/main/java/me/skymc/taboolib/commands/MainCommands.java b/src/main/java/me/skymc/taboolib/commands/MainCommands.java index c35e6cf..e69de29 100644 --- a/src/main/java/me/skymc/taboolib/commands/MainCommands.java +++ b/src/main/java/me/skymc/taboolib/commands/MainCommands.java @@ -1,65 +0,0 @@ -package me.skymc.taboolib.commands; - -import com.ilummc.tlib.resources.TLocale; -import me.skymc.taboolib.commands.sub.*; -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 org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; - -public class MainCommands implements CommandExecutor { - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (args.length == 0 || "help".equalsIgnoreCase(args[0])) { - TLocale.sendTo(sender, "COMMANDS.TABOOLIB.HELP", label); - } else if ("save".equalsIgnoreCase(args[0])) { - new SaveCommand(sender, args); - } else if ("enchants".equalsIgnoreCase(args[0])) { - new EnchantCommand(sender, args); - } else if ("potions".equalsIgnoreCase(args[0])) { - new PotionCommand(sender, args); - } else if ("flags".equalsIgnoreCase(args[0])) { - new FlagCommand(sender, args); - } else if ("attributes".equalsIgnoreCase(args[0])) { - new AttributesCommand(sender, args); - } else if ("slots".equalsIgnoreCase(args[0])) { - new SlotCommand(sender, args); - } else if ("importdata".equalsIgnoreCase(args[0])) { - new ImportCommand(sender, args); - } else if ("iteminfo".equalsIgnoreCase(args[0])) { - new InfoCommand(sender, args); - } else if ("itemlist".equalsIgnoreCase(args[0])) { - new ItemListCommand(sender, args); - } else if ("item".equalsIgnoreCase(args[0]) || "i".equalsIgnoreCase(args[0])) { - new ItemCommand(sender, args); - } else if ("setvariable".equalsIgnoreCase(args[0])) { - new VariableSetCommand(sender, args); - } else if ("getvariable".equalsIgnoreCase(args[0])) { - new VariableGetCommand(sender, args); - } else if ("shell".equalsIgnoreCase(args[0]) || "s".equalsIgnoreCase(args[0])) { - new ShellCommand(sender, args); - } else if ("cycle".equalsIgnoreCase(args[0]) || "c".equalsIgnoreCase(args[0])) { - new CycleCommand(sender, args); - } else if ("sounds".equalsIgnoreCase(args[0])) { - new SoundsCommand(sender, args); - } else if ("tagprefix".equalsIgnoreCase(args[0])) { - new TagPrefixCommand(sender, args); - } else if ("tagsuffix".equalsIgnoreCase(args[0])) { - new TagSuffixCommand(sender, args); - } else if ("tagdelete".equalsIgnoreCase(args[0])) { - new TagDeleteCommand(sender, args); - } else if ("itemreload".equalsIgnoreCase(args[0]) || "ireload".equalsIgnoreCase(args[0])) { - ItemUtils.reloadItemCache(); - ItemUtils.reloadItemName(); - TLocale.sendTo(sender, "COMMANDS.RELOAD.SUCCESS-NORMAL"); - } else { - TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN"); - } - return true; - } -} diff --git a/src/main/java/me/skymc/taboolib/commands/SubCommand.java b/src/main/java/me/skymc/taboolib/commands/SubCommand.java index 9082192..a4397bb 100644 --- a/src/main/java/me/skymc/taboolib/commands/SubCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/SubCommand.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; import java.util.stream.Collectors; import java.util.stream.IntStream; +@Deprecated public abstract class SubCommand { public CommandSender sender; diff --git a/src/main/java/me/skymc/taboolib/commands/TabooLibMainCommand.java b/src/main/java/me/skymc/taboolib/commands/TabooLibMainCommand.java new file mode 100644 index 0000000..e21c576 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/TabooLibMainCommand.java @@ -0,0 +1,755 @@ +package me.skymc.taboolib.commands; + +import com.ilummc.tlib.resources.TLocale; +import me.skymc.taboolib.commands.internal.BaseMainCommand; +import me.skymc.taboolib.commands.internal.BaseSubCommand; +import me.skymc.taboolib.commands.internal.type.CommandArgument; +import me.skymc.taboolib.commands.internal.type.CommandRegister; +import me.skymc.taboolib.commands.taboolib.*; +import me.skymc.taboolib.inventory.ItemUtils; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +/** + * @Author sky + * @Since 2018-05-09 21:38 + */ +public class TabooLibMainCommand extends BaseMainCommand { + + @Override + public String getCommandTitle() { + return TLocale.asString("COMMANDS.TABOOLIB.COMMAND-TITLE"); + } + + @CommandRegister(priority = 1) + void save() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "save"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.SAVE.DESCRIPTION"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[]{new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.SAVE.ARGUMENTS.0"))}; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new SaveCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 2) + void item() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "item"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.ITEM.DESCRIPTION"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[]{ + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.ITEM.ARGUMENTS.0")), + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.ITEM.ARGUMENTS.1"), false), + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.ITEM.ARGUMENTS.2"), false) + }; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new ItemCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 3) + void itemInfo() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "itemInfo"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.ITEMLIST.DESCRIPTION"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[0]; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new ItemListCommand(sender, args); + } + }); + } + + @CommandRegister(priority = 4) + void itemReload() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "itemReload"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.ITEMRELOAD.DESCRIPTION"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[0]; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + ItemUtils.reloadItemCache(); + ItemUtils.reloadItemName(); + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.ITEMRELOAD.SUCCESS-RELOAD"); + } + }); + } + + @CommandRegister(priority = 5) + void emptyLine1() { + registerSubCommand(null); + } + + @CommandRegister(priority = 6) + void attributes() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "attributes"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.ATTRIBUTES.DESCRIPTION"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[0]; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new AttributesCommand(sender, args); + } + }); + } + + @CommandRegister(priority = 7) + void enchants() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "enchants"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.ENCHANTS.DESCRIPTION"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[0]; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new EnchantCommand(sender, args); + } + }); + } + + @CommandRegister(priority = 8) + void potions() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "potions"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.POTIONS.DESCRIPTION"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[0]; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new PotionCommand(sender, args); + } + }); + } + + @CommandRegister(priority = 9) + void flags() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "flags"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.FLAGS.DESCRIPTION"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[0]; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new FlagCommand(sender, args); + } + }); + } + + @CommandRegister(priority = 10) + void slots() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "slots"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.SLOTS.DESCRIPTION"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[0]; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new AttributesCommand(sender, args); + } + }); + } + + @CommandRegister(priority = 11) + void sounds() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "sounds"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.SOUNDS.DESCRIPTION"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[0]; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new SoundsCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 12) + void emptyLine2() { + registerSubCommand(null); + } + + @CommandRegister(priority = 13) + void getVariable() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "getVariable"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.VARIABLE.DESCRIPTION.GET"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[]{ + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.VARIABLE.ARGUMENTS.GET.0")), + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.VARIABLE.ARGUMENTS.GET.1")) + }; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new VariableGetCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 13.1) + void setVariable() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "setVariable"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.VARIABLE.DESCRIPTION.SET"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[]{ + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.VARIABLE.ARGUMENTS.SET.0")), + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.VARIABLE.ARGUMENTS.SET.1")), + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.VARIABLE.ARGUMENTS.SET.2")) + }; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new VariableSetCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 13.2) + void emptyLine3() { + registerSubCommand(null); + } + + @CommandRegister(priority = 13.3) + void cycleList() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "cycleList"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.TIMECYCLE.DESCRIPTION.LIST"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[0]; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new CycleListCommand(sender, args); + } + }); + } + + @CommandRegister(priority = 14) + void cycleInfo() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "cycleInfo"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.TIMECYCLE.DESCRIPTION.INFO"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[]{ + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.TIMECYCLE.ARGUMENTS.INFO.0")) + }; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new CycleInfoCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 15) + void cycleReset() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "cycleReset"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.TIMECYCLE.DESCRIPTION.RESET"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[]{ + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.TIMECYCLE.ARGUMENTS.RESET.0")) + }; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new CycleResetCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 16) + void cycleUpdate() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "cycleUpdate"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.TIMECYCLE.DESCRIPTION.UPDATE"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[]{ + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.TIMECYCLE.ARGUMENTS.UPDATE.0")) + }; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new CycleUpdateCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 17) + void emptyLine4() { + registerSubCommand(null); + } + + @CommandRegister(priority = 18) + void shellLoad() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "shellLoad"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.JAVASHELL.DESCRIPTION.LOAD"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[]{ + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.JAVASHELL.ARGUMENTS.LOAD.0")) + }; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new ShellLoadCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 19) + void shellUnload() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "shellUnload"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.JAVASHELL.DESCRIPTION.UNLOAD"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[]{ + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.JAVASHELL.ARGUMENTS.UNLOAD.0")) + }; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new ShellUnloadCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 20) + void emptyLine5() { + registerSubCommand(null); + } + + @CommandRegister(priority = 20.5) + void tagDisplay() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "tagDisplay"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.PLAYERTAG.DESCRIPTION.DISPLAY"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[]{ + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.PLAYERTAG.ARGUMENTS.DISPLAY.0")), + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.PLAYERTAG.ARGUMENTS.DISPLAY.1")) + }; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new TagDisplayCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 21) + void tagPrefix() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "tagPrefix"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.PLAYERTAG.DESCRIPTION.PREFIX"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[]{ + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.PLAYERTAG.ARGUMENTS.PREFIX.0")), + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.PLAYERTAG.ARGUMENTS.PREFIX.1")) + }; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new TagPrefixCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 22) + void tagSuffix() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "tagSuffix"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.PLAYERTAG.DESCRIPTION.SUFFIX"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[]{ + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.PLAYERTAG.ARGUMENTS.SUFFIX.0")), + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.PLAYERTAG.ARGUMENTS.SUFFIX.1")) + }; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new TagSuffixCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 23) + void tagDelete() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "tagDelete"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.PLAYERTAG.DESCRIPTION.DELETE"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[]{ + new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.PLAYERTAG.ARGUMENTS.DELETE.0")) + }; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new TagDeleteCommand(sender, args); + } + + @Override + public boolean ignoredLabel() { + return false; + } + }); + } + + @CommandRegister(priority = 24) + void emptyLine6() { + registerSubCommand(null); + } + + @CommandRegister(priority = 25) + void importData() { + registerSubCommand(new BaseSubCommand() { + + @Override + public String getLabel() { + return "importData"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TABOOLIB.IMPORTDATA.DESCRIPTION"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[0]; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + new ImportCommand(sender, args); + } + }); + } +} diff --git a/src/main/java/me/skymc/taboolib/commands/internal/BaseMainCommand.java b/src/main/java/me/skymc/taboolib/commands/internal/BaseMainCommand.java new file mode 100644 index 0000000..0aa3af3 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/internal/BaseMainCommand.java @@ -0,0 +1,162 @@ +package me.skymc.taboolib.commands.internal; + +import com.google.common.base.Preconditions; +import com.ilummc.tlib.resources.TLocale; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.TabooLib; +import me.skymc.taboolib.commands.internal.type.CommandRegister; +import me.skymc.taboolib.commands.internal.type.CommandType; +import me.skymc.taboolib.string.ArrayUtils; +import me.skymc.taboolib.string.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.*; +import org.bukkit.scheduler.BukkitRunnable; + +import java.lang.reflect.Method; +import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.stream.Collectors; + +/** + * @Author sky + * @Since 2018-05-07 21:38 + */ +public abstract class BaseMainCommand implements IMainCommand, CommandExecutor, TabExecutor { + + private PluginCommand registerCommand; + private List> linkClasses = new CopyOnWriteArrayList<>(); + private List subCommands = new CopyOnWriteArrayList<>(); + + public static BaseMainCommand createCommandExecutor(String command, BaseMainCommand baseMainCommand) { + Preconditions.checkArgument(Bukkit.getPluginCommand(command) != null, "PluginCommand \"" + command + "\"not found"); + Preconditions.checkArgument(baseMainCommand != null, "Executor cannot be null"); + Preconditions.checkArgument(baseMainCommand.getClass() != BaseMainCommand.class, "Executor can not be \"BaseMainCommand.class\""); + baseMainCommand.setRegisterCommand(Bukkit.getPluginCommand(command)); + baseMainCommand.getRegisterCommand().setExecutor(baseMainCommand); + baseMainCommand.getRegisterCommand().setTabCompleter(baseMainCommand); + baseMainCommand.getLinkClasses().add(baseMainCommand.getClass()); + loadCommandRegister(baseMainCommand); + return baseMainCommand; + } + + public static void loadCommandRegister(BaseMainCommand baseMainCommand) { + List methods = new ArrayList<>(); + baseMainCommand.getLinkClasses().forEach(clazz -> Arrays.stream(clazz.getDeclaredMethods()).filter(method -> method.getAnnotation(CommandRegister.class) != null).forEach(methods::add)); + if (methods.size() > 0) { + methods.sort(Comparator.comparingDouble(a -> a.getAnnotation(CommandRegister.class).priority())); + methods.forEach(x -> { + try { + x.setAccessible(true); + x.invoke(baseMainCommand); + } catch (Exception ignored) { + } + }); + } + if (methods.size() > 0) { + TLocale.Logger.info("COMMANDS.INTERNAL.COMMAND-REGISTER", baseMainCommand.getRegisterCommand().getPlugin().getName(), baseMainCommand.getRegisterCommand().getName(), String.valueOf(methods.size())); + } + } + + public void setRegisterCommand(PluginCommand registerCommand) { + this.registerCommand = registerCommand; + } + + public PluginCommand getRegisterCommand() { + return registerCommand; + } + + public List> getLinkClasses() { + return linkClasses; + } + + public List getSubCommands() { + return subCommands; + } + + public void registerSubCommand(BaseSubCommand subCommand) { + if (subCommand != null) { + Preconditions.checkArgument(subCommand.getLabel() != null, "Command label can not be null"); + Preconditions.checkArgument(subCommand.getDescription() != null, "Command description can not be null"); + Preconditions.checkArgument(subCommand.getArguments() != null, "Command arguments can not be null"); + } + subCommands.add(subCommand); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length == 0) { + helpCommand(sender, label); + } else { + for (BaseSubCommand subCommand : subCommands) { + if (subCommand == null || !args[0].equalsIgnoreCase(subCommand.getLabel())) { + continue; + } + if (!isConfirmType(sender, subCommand.getType())) { + TLocale.sendTo(sender, "COMMANDS.INTERNAL.ONLY-PLAYER", args[0], TLocale.asString("COMMANDS.INTERNAL.TYPE-" + subCommand.getType())); + return true; + } + String[] subCommandArgs = ArrayUtils.removeFirst(args); + if (subCommand.isParameterConform(subCommandArgs)) { + subCommand.onCommand(sender, command, label, subCommand.ignoredLabel() ? subCommandArgs : args); + } else { + TLocale.sendTo(sender, "COMMANDS.INTERNAL.ERROR-USAGE", args[0], subCommand.getCommandString(label)); + } + return true; + } + new BukkitRunnable() { + + @Override + public void run() { + List commandCompute = subCommands.stream().filter(Objects::nonNull).sorted((b, a) -> Double.compare(StringUtils.similarDegree(args[0], a.getLabel()), StringUtils.similarDegree(args[0], b.getLabel()))).collect(Collectors.toList()); + if (commandCompute.size() > 0) { + TLocale.sendTo(sender, "COMMANDS.INTERNAL.ERROR-COMMAND", args[0], commandCompute.get(0).getCommandString(label).trim()); + } + } + }.runTaskAsynchronously(Main.getInst()); + } + return true; + } + + @Override + public List onTabComplete(CommandSender commandSender, Command command, String s, String[] args) { + return args.length == 1 ? subCommands.stream().filter(internalCommandExecutor -> internalCommandExecutor != null && (args[0].isEmpty() || internalCommandExecutor.getLabel().startsWith(args[0]))).map(ISubCommand::getLabel).collect(Collectors.toList()) : null; + } + + @Override + public String toString() { + return "registerCommand=" + "BaseMainCommand{" + registerCommand + ", linkClasses=" + linkClasses + ", subCommands=" + subCommands + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof BaseMainCommand)) { + return false; + } + BaseMainCommand that = (BaseMainCommand) o; + return Objects.equals(getLinkClasses(), that.getLinkClasses()) && Objects.equals(getRegisterCommand(), that.getRegisterCommand()) && Objects.equals(getSubCommands(), that.getSubCommands()); + } + + @Override + public int hashCode() { + return Objects.hash(getRegisterCommand(), getLinkClasses(), getSubCommands()); + } + + private String getEmptyLine() { + return TabooLib.getVerint() < 10800 ? "~" : ""; + } + + private boolean isConfirmType(CommandSender sender, CommandType commandType) { + return commandType == CommandType.ALL || sender instanceof ConsoleCommandSender && commandType == CommandType.CONSOLE; + } + + private void helpCommand(CommandSender sender, String label) { + sender.sendMessage(getEmptyLine()); + sender.sendMessage(getCommandTitle()); + sender.sendMessage(getEmptyLine()); + subCommands.stream().map(subCommand -> subCommand == null ? getEmptyLine() : subCommand.getCommandString(label)).forEach(sender::sendMessage); + sender.sendMessage(getEmptyLine()); + } +} diff --git a/src/main/java/me/skymc/taboolib/commands/internal/InternalSubCommandExecutor.java b/src/main/java/me/skymc/taboolib/commands/internal/BaseSubCommand.java similarity index 71% rename from src/main/java/me/skymc/taboolib/commands/internal/InternalSubCommandExecutor.java rename to src/main/java/me/skymc/taboolib/commands/internal/BaseSubCommand.java index 799d71f..a7307b1 100644 --- a/src/main/java/me/skymc/taboolib/commands/internal/InternalSubCommandExecutor.java +++ b/src/main/java/me/skymc/taboolib/commands/internal/BaseSubCommand.java @@ -1,15 +1,22 @@ package me.skymc.taboolib.commands.internal; +import me.skymc.taboolib.commands.internal.type.CommandArgument; +import me.skymc.taboolib.commands.internal.type.CommandType; + import java.util.stream.IntStream; /** * @author Bkm016 * @since 2018-04-17 */ -public abstract class InternalSubCommandExecutor implements InternalSubCommand { +public abstract class BaseSubCommand implements ISubCommand { - public InternalSubCommandType getType() { - return InternalSubCommandType.ALL; + public CommandType getType() { + return CommandType.ALL; + } + + public boolean ignoredLabel() { + return true; } public boolean requiredPlayer() { @@ -27,7 +34,7 @@ public abstract class InternalSubCommandExecutor implements InternalSubCommand { stringBuilder.append(" "); stringBuilder.append(getLabel()); stringBuilder.append(" "); - for (InternalArgument parameter : getArguments()) { + for (CommandArgument parameter : getArguments()) { stringBuilder.append(parameter.toString()); stringBuilder.append(" "); } @@ -35,4 +42,4 @@ public abstract class InternalSubCommandExecutor implements InternalSubCommand { stringBuilder.append(getDescription()); return stringBuilder.toString(); } -} +} \ No newline at end of file diff --git a/src/main/java/me/skymc/taboolib/commands/internal/InternalCommand.java b/src/main/java/me/skymc/taboolib/commands/internal/IMainCommand.java similarity index 57% rename from src/main/java/me/skymc/taboolib/commands/internal/InternalCommand.java rename to src/main/java/me/skymc/taboolib/commands/internal/IMainCommand.java index 47a689e..f280e1d 100644 --- a/src/main/java/me/skymc/taboolib/commands/internal/InternalCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/internal/IMainCommand.java @@ -4,8 +4,13 @@ package me.skymc.taboolib.commands.internal; * @Author sky * @Since 2018-05-07 21:36 */ -public interface InternalCommand { +public interface IMainCommand { + /** + * 指令标题 + * + * @return 文本 + */ String getCommandTitle(); } diff --git a/src/main/java/me/skymc/taboolib/commands/internal/ISubCommand.java b/src/main/java/me/skymc/taboolib/commands/internal/ISubCommand.java new file mode 100644 index 0000000..b9c2d07 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/internal/ISubCommand.java @@ -0,0 +1,44 @@ +package me.skymc.taboolib.commands.internal; + +import me.skymc.taboolib.commands.internal.type.CommandArgument; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +/** + * @author Bkm016 + * @since 2018-04-17 + */ +public interface ISubCommand { + + /** + * 指令名 + * + * @return 文本 + */ + String getLabel(); + + /** + * 指令描述 + * + * @return 文本 + */ + String getDescription(); + + /** + * 指令参数 + * + * @return {@link CommandArgument} + */ + CommandArgument[] getArguments(); + + /** + * 指令执行方法 + * + * @param sender 指令使用者 + * @param command 指令对象 + * @param label 主命令 + * @param args 参数(不含主命令及子命令) + */ + void onCommand(CommandSender sender, Command command, String label, String[] args); + +} diff --git a/src/main/java/me/skymc/taboolib/commands/internal/InternalArgument.java b/src/main/java/me/skymc/taboolib/commands/internal/InternalArgument.java deleted file mode 100644 index d03869b..0000000 --- a/src/main/java/me/skymc/taboolib/commands/internal/InternalArgument.java +++ /dev/null @@ -1,29 +0,0 @@ -package me.skymc.taboolib.commands.internal; - -/** - * @author Bkm016 - * @since 2018-04-17 - */ -public class InternalArgument { - - private String name; - private boolean required; - - public String getName() { - return name; - } - - public boolean isRequired() { - return required; - } - - public InternalArgument(String name, boolean required) { - this.name = name; - this.required = required; - } - - @Override - public String toString() { - return required ? "§7[§8" + name + "§7]" : "§7<§8" + name + "§7>"; - } -} diff --git a/src/main/java/me/skymc/taboolib/commands/internal/InternalCommandExecutor.java b/src/main/java/me/skymc/taboolib/commands/internal/InternalCommandExecutor.java deleted file mode 100644 index 23d8408..0000000 --- a/src/main/java/me/skymc/taboolib/commands/internal/InternalCommandExecutor.java +++ /dev/null @@ -1,111 +0,0 @@ -package me.skymc.taboolib.commands.internal; - -import com.ilummc.tlib.resources.TLocale; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.TabooLib; -import me.skymc.taboolib.string.ArrayUtils; -import me.skymc.taboolib.string.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.command.*; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -/** - * @Author sky - * @Since 2018-05-07 21:38 - */ -public abstract class InternalCommandExecutor implements InternalCommand, CommandExecutor, TabExecutor { - - private InternalCommandExecutor subExecutor; - private List subCommandExecutors = new ArrayList<>(); - - public static InternalCommandExecutor createCommandExecutor(String command, InternalCommandExecutor internalCommandExecutor) { - assert Bukkit.getPluginCommand(command) == null : "PluginCommand \"" + command + "\"not found"; - assert internalCommandExecutor != null : "Executor can not be null"; - assert internalCommandExecutor.getCommandTitle() != null : "Executor title can not be null"; - assert internalCommandExecutor.getClass() != InternalCommandExecutor.class : "SubExecutor can not be \"InternalCommandExecutor.class\""; - internalCommandExecutor.setSubExecutor(internalCommandExecutor); - Bukkit.getPluginCommand(command).setExecutor(internalCommandExecutor); - Bukkit.getPluginCommand(command).setTabCompleter(internalCommandExecutor); - return internalCommandExecutor; - } - - public void setSubExecutor(InternalCommandExecutor subExecutor) { - this.subExecutor = subExecutor; - } - - public InternalCommandExecutor getSubExecutor() { - return subExecutor; - } - - public List getSubCommandExecutors() { - return subCommandExecutors; - } - - public void registerSubCommandExecutor(InternalSubCommandExecutor subCommandExecutor) { - assert subCommandExecutor.getLabel() != null : "Command label can not be null"; - assert subCommandExecutor.getDescription() != null : "Command description can not be null"; - assert subCommandExecutor.getArguments() != null : "Command arguments can not be null"; - subCommandExecutors.add(subCommandExecutor); - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (args.length == 0) { - helpCommand(sender, label); - } else { - for (InternalSubCommandExecutor subCommand : subCommandExecutors) { - if (subCommand == null || !args[0].equalsIgnoreCase(subCommand.getLabel())) { - continue; - } - if (!isConfirmType(sender, subCommand.getType())) { - TLocale.sendTo(sender, "COMMANDS.INTERNAL.ONLY-PLAYER", args[0], TLocale.asString("COMMANDS.INTERNAL.TYPE-" + subCommand.getType())); - return true; - } - String[] subCommandArgs = ArrayUtils.removeFirst(args); - if (subCommand.isParameterConform(subCommandArgs)) { - subCommand.onCommand(sender, command, label, subCommandArgs); - } else { - TLocale.sendTo(sender, "COMMANDS.INTERNAL.ERROR-USAGE", args[0], subCommand.getCommandString(label)); - } - return true; - } - new BukkitRunnable() { - - @Override - public void run() { - List commandCompute = subCommandExecutors.stream().filter(Objects::nonNull).sorted((b, a) -> Double.compare(StringUtils.similarDegree(args[0], a.getLabel()), StringUtils.similarDegree(args[0], b.getLabel()))).collect(Collectors.toList()); - if (commandCompute.size() > 0) { - TLocale.sendTo(sender, "COMMANDS.INTERNAL.ERROR-COMMAND", args[0], commandCompute.get(0).getCommandString(label).trim()); - } - } - }.runTaskAsynchronously(Main.getInst()); - } - return true; - } - - @Override - public List onTabComplete(CommandSender commandSender, Command command, String s, String[] args) { - return args.length == 1 ? subCommandExecutors.stream().filter(internalCommandExecutor -> internalCommandExecutor != null && (args[0].isEmpty() || internalCommandExecutor.getLabel().startsWith(args[0]))).map(InternalSubCommand::getLabel).collect(Collectors.toList()) : null; - } - - private String getEmptyLine() { - return TabooLib.getVerint() < 10800 ? "~" : ""; - } - - private void helpCommand(CommandSender sender, String label) { - sender.sendMessage(getEmptyLine()); - sender.sendMessage(subExecutor.getCommandTitle()); - sender.sendMessage(getEmptyLine()); - subCommandExecutors.stream().map(subCommand -> subCommand == null ? getEmptyLine() : subCommand.getCommandString(label)).forEach(sender::sendMessage); - sender.sendMessage(getEmptyLine()); - } - - private boolean isConfirmType(CommandSender sender, InternalSubCommandType commandType) { - return commandType == InternalSubCommandType.ALL || sender instanceof ConsoleCommandSender && commandType == InternalSubCommandType.CONSOLE; - } -} diff --git a/src/main/java/me/skymc/taboolib/commands/internal/InternalSubCommand.java b/src/main/java/me/skymc/taboolib/commands/internal/InternalSubCommand.java deleted file mode 100644 index 4a9e93c..0000000 --- a/src/main/java/me/skymc/taboolib/commands/internal/InternalSubCommand.java +++ /dev/null @@ -1,20 +0,0 @@ -package me.skymc.taboolib.commands.internal; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; - -/** - * @author Bkm016 - * @since 2018-04-17 - */ -public interface InternalSubCommand { - - String getLabel(); - - String getDescription(); - - InternalArgument[] getArguments(); - - void onCommand(CommandSender sender, Command command, String label, String[] args); - -} diff --git a/src/main/java/me/skymc/taboolib/commands/internal/InternalSubCommandType.java b/src/main/java/me/skymc/taboolib/commands/internal/InternalSubCommandType.java deleted file mode 100644 index 2845060..0000000 --- a/src/main/java/me/skymc/taboolib/commands/internal/InternalSubCommandType.java +++ /dev/null @@ -1,11 +0,0 @@ -package me.skymc.taboolib.commands.internal; - -/** - * @author Bkm016 - * @since 2018-04-17 - */ -public enum InternalSubCommandType { - - CONSOLE, PLAYER, ALL - -} diff --git a/src/main/java/me/skymc/taboolib/commands/internal/type/CommandArgument.java b/src/main/java/me/skymc/taboolib/commands/internal/type/CommandArgument.java new file mode 100644 index 0000000..bbd52ac --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/internal/type/CommandArgument.java @@ -0,0 +1,52 @@ +package me.skymc.taboolib.commands.internal.type; + +import java.util.Objects; + +/** + * @author Bkm016 + * @since 2018-04-17 + */ +public class CommandArgument { + + private String name; + private boolean required; + + public String getName() { + return name; + } + + public boolean isRequired() { + return required; + } + + public CommandArgument(String name) { + this(name, true); + } + + public CommandArgument(String name, boolean required) { + this.name = name; + this.required = required; + } + + @Override + public String toString() { + return required ? "§7[§8" + name + "§7]" : "§7<§8" + name + "§7>"; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof CommandArgument)) { + return false; + } + CommandArgument that = (CommandArgument) o; + return Objects.equals(getName(), that.getName()) && isRequired() == that.isRequired(); + } + + @Override + public int hashCode() { + return Objects.hash(getName(), isRequired()); + } +} diff --git a/src/main/java/me/skymc/taboolib/commands/internal/type/CommandRegister.java b/src/main/java/me/skymc/taboolib/commands/internal/type/CommandRegister.java new file mode 100644 index 0000000..7463738 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/internal/type/CommandRegister.java @@ -0,0 +1,18 @@ +package me.skymc.taboolib.commands.internal.type; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @Author sky + * @Since 2018-05-09 22:38 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface CommandRegister { + + double priority() default 0; + +} diff --git a/src/main/java/me/skymc/taboolib/commands/internal/type/CommandType.java b/src/main/java/me/skymc/taboolib/commands/internal/type/CommandType.java new file mode 100644 index 0000000..957c300 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/internal/type/CommandType.java @@ -0,0 +1,11 @@ +package me.skymc.taboolib.commands.internal.type; + +/** + * @author Bkm016 + * @since 2018-04-17 + */ +public enum CommandType { + + CONSOLE, PLAYER, ALL + +} diff --git a/src/main/java/me/skymc/taboolib/commands/plugin/TabooLibPluginCommand.java b/src/main/java/me/skymc/taboolib/commands/plugin/TabooLibPluginMainCommand.java similarity index 82% rename from src/main/java/me/skymc/taboolib/commands/plugin/TabooLibPluginCommand.java rename to src/main/java/me/skymc/taboolib/commands/plugin/TabooLibPluginMainCommand.java index e5f348a..cf29a86 100644 --- a/src/main/java/me/skymc/taboolib/commands/plugin/TabooLibPluginCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/plugin/TabooLibPluginMainCommand.java @@ -2,9 +2,9 @@ package me.skymc.taboolib.commands.plugin; import com.google.common.base.Joiner; import com.ilummc.tlib.resources.TLocale; -import me.skymc.taboolib.commands.internal.InternalArgument; -import me.skymc.taboolib.commands.internal.InternalCommandExecutor; -import me.skymc.taboolib.commands.internal.InternalSubCommandExecutor; +import me.skymc.taboolib.commands.internal.BaseMainCommand; +import me.skymc.taboolib.commands.internal.BaseSubCommand; +import me.skymc.taboolib.commands.internal.type.CommandArgument; import me.skymc.taboolib.plugin.PluginUtils; import me.skymc.taboolib.string.ArrayUtils; import org.bukkit.Bukkit; @@ -20,9 +20,9 @@ import java.util.stream.Collectors; * @Author sky * @Since 2018-05-07 20:14 */ -public class TabooLibPluginCommand extends InternalCommandExecutor { +public class TabooLibPluginMainCommand extends BaseMainCommand { - public TabooLibPluginCommand() { + public TabooLibPluginMainCommand() { listCommand(); infoCommand(); loadCommand(); @@ -36,7 +36,7 @@ public class TabooLibPluginCommand extends InternalCommandExecutor { } void loadCommand() { - registerSubCommandExecutor(new InternalSubCommandExecutor() { + registerSubCommand(new BaseSubCommand() { @Override public String getLabel() { @@ -49,8 +49,8 @@ public class TabooLibPluginCommand extends InternalCommandExecutor { } @Override - public InternalArgument[] getArguments() { - return new InternalArgument[]{new InternalArgument(TLocale.asString("COMMANDS.TPLUGIN.LOAD.ARGUMENTS.0"), true)}; + public CommandArgument[] getArguments() { + return new CommandArgument[]{new CommandArgument(TLocale.asString("COMMANDS.TPLUGIN.LOAD.ARGUMENTS.0"), true)}; } @Override @@ -74,7 +74,7 @@ public class TabooLibPluginCommand extends InternalCommandExecutor { } void unloadCommand() { - registerSubCommandExecutor(new InternalSubCommandExecutor() { + registerSubCommand(new BaseSubCommand() { @Override public String getLabel() { @@ -87,8 +87,8 @@ public class TabooLibPluginCommand extends InternalCommandExecutor { } @Override - public InternalArgument[] getArguments() { - return new InternalArgument[]{new InternalArgument(TLocale.asString("COMMANDS.TPLUGIN.UNLOAD.ARGUMENTS.0"), true)}; + public CommandArgument[] getArguments() { + return new CommandArgument[]{new CommandArgument(TLocale.asString("COMMANDS.TPLUGIN.UNLOAD.ARGUMENTS.0"), true)}; } @Override @@ -115,7 +115,7 @@ public class TabooLibPluginCommand extends InternalCommandExecutor { } void reloadCommand() { - registerSubCommandExecutor(new InternalSubCommandExecutor() { + registerSubCommand(new BaseSubCommand() { @Override public String getLabel() { @@ -128,8 +128,8 @@ public class TabooLibPluginCommand extends InternalCommandExecutor { } @Override - public InternalArgument[] getArguments() { - return new InternalArgument[]{new InternalArgument(TLocale.asString("COMMANDS.TPLUGIN.RELOAD.ARGUMENTS.0"), true)}; + public CommandArgument[] getArguments() { + return new CommandArgument[]{new CommandArgument(TLocale.asString("COMMANDS.TPLUGIN.RELOAD.ARGUMENTS.0"), true)}; } @Override @@ -149,7 +149,7 @@ public class TabooLibPluginCommand extends InternalCommandExecutor { } void infoCommand() { - registerSubCommandExecutor(new InternalSubCommandExecutor() { + registerSubCommand(new BaseSubCommand() { @Override public String getLabel() { @@ -162,8 +162,8 @@ public class TabooLibPluginCommand extends InternalCommandExecutor { } @Override - public InternalArgument[] getArguments() { - return new InternalArgument[]{new InternalArgument(TLocale.asString("COMMANDS.TPLUGIN.INFO.ARGUMENTS.0"), true)}; + public CommandArgument[] getArguments() { + return new CommandArgument[]{new CommandArgument(TLocale.asString("COMMANDS.TPLUGIN.INFO.ARGUMENTS.0"), true)}; } @Override @@ -189,7 +189,7 @@ public class TabooLibPluginCommand extends InternalCommandExecutor { } void listCommand() { - registerSubCommandExecutor(new InternalSubCommandExecutor() { + registerSubCommand(new BaseSubCommand() { @Override public String getLabel() { @@ -202,8 +202,8 @@ public class TabooLibPluginCommand extends InternalCommandExecutor { } @Override - public InternalArgument[] getArguments() { - return new InternalArgument[0]; + public CommandArgument[] getArguments() { + return new CommandArgument[0]; } @Override diff --git a/src/main/java/me/skymc/taboolib/commands/sub/ImportCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/ImportCommand.java deleted file mode 100644 index 25d519b..0000000 --- a/src/main/java/me/skymc/taboolib/commands/sub/ImportCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -package me.skymc.taboolib.commands.sub; - -import com.ilummc.tlib.resources.TLocale; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.Main.StorageType; -import me.skymc.taboolib.commands.SubCommand; -import me.skymc.taboolib.fileutils.ConfigUtils; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.File; -import java.util.Objects; - -public class ImportCommand extends SubCommand { - - public ImportCommand(CommandSender sender, String[] args) { - super(sender, args); - - if (isPlayer()) { - TLocale.sendTo(sender, "COMMANDS.GLOBAL.ONLY-PLAYER"); - return; - } - - if (Main.getStorageType() == StorageType.LOCAL) { - TLocale.Logger.warn("COMMANDS.GLOBAL.ONLY-STORAGE-SQL"); - return; - } - - TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.CLEARING"); - Main.getConnection().truncateTable(Main.getTablePrefix() + "_playerdata"); - - if (!Main.getPlayerDataFolder().exists()) { - TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.EMPTYDATA"); - return; - } - - int size = Objects.requireNonNull(Main.getPlayerDataFolder().listFiles()).length; - TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.IMPORTING-START", String.valueOf(size)); - - int loop = 1; - for (File file : Objects.requireNonNull(Main.getPlayerDataFolder().listFiles())) { - Main.getConnection().intoValue(Main.getTablePrefix() + "_playerdata", file.getName().replace(".yml", ""), ConfigUtils.encodeYAML(YamlConfiguration.loadConfiguration(file))); - TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.IMPORTING-PROGRESS", file.getName().replace(".yml", ""), String.valueOf(loop), String.valueOf(size)); - loop++; - } - - TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.SUCCESS"); - } - -} 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 deleted file mode 100644 index 890fd82..0000000 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java +++ /dev/null @@ -1,31 +0,0 @@ -package me.skymc.taboolib.commands.sub.cycle; - -import com.ilummc.tlib.resources.TLocale; -import me.skymc.taboolib.commands.SubCommand; -import org.bukkit.command.CommandSender; - -public class CycleCommand extends SubCommand { - - public CycleCommand(CommandSender sender, String[] args) { - super(sender, args); - if (args.length > 1) { - if ("list".equalsIgnoreCase(args[1])) { - new CycleListCommand(sender, args); - } else if ("info".equalsIgnoreCase(args[1])) { - new CycleInfoCommand(sender, args); - } else if ("reset".equalsIgnoreCase(args[1])) { - new CycleResetCommand(sender, args); - } else if ("update".equalsIgnoreCase(args[1])) { - new CycleUpdateCommand(sender, args); - } - } else { - TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN"); - } - } - - @Override - public boolean command() { - return true; - } - -} 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 deleted file mode 100644 index d2f417d..0000000 --- a/src/main/java/me/skymc/taboolib/commands/sub/shell/ShellCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -package me.skymc.taboolib.commands.sub.shell; - -import com.ilummc.tlib.resources.TLocale; -import me.skymc.taboolib.commands.SubCommand; -import org.bukkit.command.CommandSender; - -public class ShellCommand extends SubCommand { - - public ShellCommand(CommandSender sender, String[] args) { - super(sender, args); - if (args.length > 1) { - if ("load".equalsIgnoreCase(args[1])) { - new ShellLoadCommand(sender, args); - } else if ("unload".equalsIgnoreCase(args[1])) { - new ShellUnloadCommand(sender, args); - } - } else { - TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN"); - } - } - - @Override - public boolean command() { - return true; - } - -} diff --git a/src/main/java/me/skymc/taboolib/commands/sub/AttributesCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/AttributesCommand.java similarity index 93% rename from src/main/java/me/skymc/taboolib/commands/sub/AttributesCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/AttributesCommand.java index cec88d4..1ec3bf4 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/AttributesCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/AttributesCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/CycleInfoCommand.java similarity index 94% rename from src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/CycleInfoCommand.java index 9312e4e..6ddacae 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/CycleInfoCommand.java @@ -1,15 +1,13 @@ -package me.skymc.taboolib.commands.sub.cycle; - -import java.util.concurrent.TimeUnit; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; -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/taboolib/CycleListCommand.java similarity index 64% rename from src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/CycleListCommand.java index 67c867a..63561e5 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/CycleListCommand.java @@ -1,18 +1,9 @@ -package me.skymc.taboolib.commands.sub.cycle; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; -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.inventory.ItemFlag; - -import java.util.Arrays; +import org.bukkit.command.CommandSender; public class CycleListCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleResetCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/CycleResetCommand.java similarity index 94% rename from src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleResetCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/CycleResetCommand.java index 6430043..9816e72 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleResetCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/CycleResetCommand.java @@ -1,18 +1,16 @@ -package me.skymc.taboolib.commands.sub.cycle; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; -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; -import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.timecycle.TimeCycle; import me.skymc.taboolib.timecycle.TimeCycleEvent; import me.skymc.taboolib.timecycle.TimeCycleInitializeEvent; import me.skymc.taboolib.timecycle.TimeCycleManager; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.scheduler.BukkitRunnable; public class CycleResetCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/CycleUpdateCommand.java similarity index 93% rename from src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/CycleUpdateCommand.java index 1c4bb91..ad646da 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/CycleUpdateCommand.java @@ -1,17 +1,15 @@ -package me.skymc.taboolib.commands.sub.cycle; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; -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; -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/EnchantCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/EnchantCommand.java similarity index 93% rename from src/main/java/me/skymc/taboolib/commands/sub/EnchantCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/EnchantCommand.java index 2ea2d18..b0331eb 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/EnchantCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/EnchantCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; diff --git a/src/main/java/me/skymc/taboolib/commands/sub/FlagCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/FlagCommand.java similarity index 93% rename from src/main/java/me/skymc/taboolib/commands/sub/FlagCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/FlagCommand.java index c2f0675..05af222 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/FlagCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/FlagCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; diff --git a/src/main/java/me/skymc/taboolib/commands/taboolib/ImportCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/ImportCommand.java new file mode 100644 index 0000000..077e847 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/ImportCommand.java @@ -0,0 +1,50 @@ +package me.skymc.taboolib.commands.taboolib; + +import com.ilummc.tlib.resources.TLocale; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.Main.StorageType; +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.fileutils.ConfigUtils; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.util.Objects; + +public class ImportCommand extends SubCommand { + + public ImportCommand(CommandSender sender, String[] args) { + super(sender, args); + + if (isPlayer()) { + TLocale.sendTo(sender, "COMMANDS.GLOBAL.ONLY-PLAYER"); + return; + } + + if (Main.getStorageType() == StorageType.LOCAL) { + TLocale.Logger.warn("COMMANDS.GLOBAL.ONLY-STORAGE-SQL"); + return; + } + + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.CLEARING"); + Main.getConnection().truncateTable(Main.getTablePrefix() + "_playerdata"); + + if (!Main.getPlayerDataFolder().exists()) { + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.EMPTYDATA"); + return; + } + + int size = Objects.requireNonNull(Main.getPlayerDataFolder().listFiles()).length; + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.IMPORTING-START", String.valueOf(size)); + + int loop = 1; + for (File file : Objects.requireNonNull(Main.getPlayerDataFolder().listFiles())) { + Main.getConnection().intoValue(Main.getTablePrefix() + "_playerdata", file.getName().replace(".yml", ""), ConfigUtils.encodeYAML(YamlConfiguration.loadConfiguration(file))); + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.IMPORTING-PROGRESS", file.getName().replace(".yml", ""), String.valueOf(loop), String.valueOf(size)); + loop++; + } + + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.SUCCESS"); + } + +} diff --git a/src/main/java/me/skymc/taboolib/commands/sub/InfoCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/InfoCommand.java similarity index 96% rename from src/main/java/me/skymc/taboolib/commands/sub/InfoCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/InfoCommand.java index 2a26603..7890de1 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/InfoCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/InfoCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; diff --git a/src/main/java/me/skymc/taboolib/commands/sub/ItemCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/ItemCommand.java similarity index 97% rename from src/main/java/me/skymc/taboolib/commands/sub/ItemCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/ItemCommand.java index 54d0cc8..7d13386 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/ItemCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/ItemCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; diff --git a/src/main/java/me/skymc/taboolib/commands/sub/itemlist/ItemListCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/ItemListCommand.java similarity index 61% rename from src/main/java/me/skymc/taboolib/commands/sub/itemlist/ItemListCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/ItemListCommand.java index 3101bc3..dcf062d 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/itemlist/ItemListCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/ItemListCommand.java @@ -1,7 +1,7 @@ -package me.skymc.taboolib.commands.sub.itemlist; +package me.skymc.taboolib.commands.taboolib; import me.skymc.taboolib.commands.SubCommand; -import me.skymc.taboolib.commands.sub.itemlist.listener.ItemLibraryPatch; +import me.skymc.taboolib.commands.taboolib.listener.ListenerItemListCommand; import me.skymc.taboolib.other.NumberUtils; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -16,9 +16,9 @@ public class ItemListCommand extends SubCommand { super(sender, args); if (isPlayer()) { if (args.length == 1) { - ItemLibraryPatch.openInventory((Player) sender, 1); + ListenerItemListCommand.openInventory((Player) sender, 1); } else { - ItemLibraryPatch.openInventory((Player) sender, NumberUtils.getInteger(args[1])); + ListenerItemListCommand.openInventory((Player) sender, NumberUtils.getInteger(args[1])); } } } diff --git a/src/main/java/me/skymc/taboolib/commands/sub/PotionCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/PotionCommand.java similarity index 94% rename from src/main/java/me/skymc/taboolib/commands/sub/PotionCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/PotionCommand.java index f7d7720..cdd3e3c 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/PotionCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/PotionCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; diff --git a/src/main/java/me/skymc/taboolib/commands/sub/SaveCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/SaveCommand.java similarity index 97% rename from src/main/java/me/skymc/taboolib/commands/sub/SaveCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/SaveCommand.java index bc8da08..37946e4 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/SaveCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/SaveCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.Main; @@ -15,6 +15,9 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +/** + * @author sky + */ public class SaveCommand extends SubCommand { public SaveCommand(CommandSender sender, String[] args) { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/shell/ShellLoadCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/ShellLoadCommand.java similarity index 77% rename from src/main/java/me/skymc/taboolib/commands/sub/shell/ShellLoadCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/ShellLoadCommand.java index 9512366..3b82d16 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/shell/ShellLoadCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/ShellLoadCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub.shell; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; @@ -12,13 +12,13 @@ public class ShellLoadCommand extends SubCommand { public ShellLoadCommand(CommandSender sender, String[] args) { super(sender, args); if (args.length < 3) { - TLocale.sendTo(sender, "COMMANDS.TABOOLIB.JAVASHELL.INVALID-NAME"); + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.JAVASHELL.INVALID-NAME"); return; } File file = new File(JavaShell.getScriptFolder(), args[2].contains(".java") ? args[2] : args[2] + ".java"); if (!file.exists()) { - TLocale.sendTo(sender, "COMMANDS.TABOOLIB.JAVASHELL.INVALID-SHELL", args[2]); + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.JAVASHELL.INVALID-SHELL", args[2]); return; } diff --git a/src/main/java/me/skymc/taboolib/commands/sub/shell/ShellUnloadCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/ShellUnloadCommand.java similarity index 95% rename from src/main/java/me/skymc/taboolib/commands/sub/shell/ShellUnloadCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/ShellUnloadCommand.java index acc4981..17c7628 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/shell/ShellUnloadCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/ShellUnloadCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub.shell; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; diff --git a/src/main/java/me/skymc/taboolib/commands/sub/SlotCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/SlotCommand.java similarity index 93% rename from src/main/java/me/skymc/taboolib/commands/sub/SlotCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/SlotCommand.java index b2edb2d..4897a70 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/SlotCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/SlotCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; diff --git a/src/main/java/me/skymc/taboolib/commands/sub/sounds/SoundsCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/SoundsCommand.java similarity index 55% rename from src/main/java/me/skymc/taboolib/commands/sub/sounds/SoundsCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/SoundsCommand.java index 9c2ea65..2d2f63f 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/sounds/SoundsCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/SoundsCommand.java @@ -1,7 +1,7 @@ -package me.skymc.taboolib.commands.sub.sounds; +package me.skymc.taboolib.commands.taboolib; import me.skymc.taboolib.commands.SubCommand; -import me.skymc.taboolib.commands.sub.sounds.listener.SoundsLibraryPatch; +import me.skymc.taboolib.commands.taboolib.listener.ListenerSoundsCommand; import me.skymc.taboolib.other.NumberUtils; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -16,11 +16,11 @@ public class SoundsCommand extends SubCommand { super(sender, args); if (isPlayer()) { if (args.length == 1) { - SoundsLibraryPatch.openInventory((Player) sender, 1, null); + ListenerSoundsCommand.openInventory((Player) sender, 1, null); } else if (args.length == 2) { - SoundsLibraryPatch.openInventory((Player) sender, NumberUtils.getInteger(args[1]), null); + ListenerSoundsCommand.openInventory((Player) sender, NumberUtils.getInteger(args[1]), null); } else { - SoundsLibraryPatch.openInventory((Player) sender, NumberUtils.getInteger(args[1]), args[2]); + ListenerSoundsCommand.openInventory((Player) sender, NumberUtils.getInteger(args[1]), args[2]); } } } diff --git a/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/TagDeleteCommand.java similarity index 88% rename from src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/TagDeleteCommand.java index 7a067f6..25d9869 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/TagDeleteCommand.java @@ -1,8 +1,8 @@ -package me.skymc.taboolib.commands.sub; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; -import me.skymc.taboolib.message.MsgUtils; +import me.skymc.taboolib.team.TagAPI; import me.skymc.taboolib.team.TagManager; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -28,6 +28,8 @@ public class TagDeleteCommand extends SubCommand { } TagManager.getInst().removeData(player); + TagAPI.removePlayerDisplayName(player); + if (sender instanceof Player) { TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.SUCCESS-DELETE", args[1]); } diff --git a/src/main/java/me/skymc/taboolib/commands/taboolib/TagDisplayCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/TagDisplayCommand.java new file mode 100644 index 0000000..d093513 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/TagDisplayCommand.java @@ -0,0 +1,41 @@ +package me.skymc.taboolib.commands.taboolib; + +import com.ilummc.tlib.resources.TLocale; +import me.clip.placeholderapi.PlaceholderAPI; +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.team.TagAPI; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * @author sky + * @since 2018-03-19 23:13:35 + */ +public class TagDisplayCommand extends SubCommand { + + public TagDisplayCommand(CommandSender sender, String[] args) { + super(sender, args); + if (args.length < 3) { + TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN"); + return; + } + + Player player = Bukkit.getPlayerExact(args[1]); + if (player == null) { + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.INVALID-PLAYER", args[1]); + return; + } + + String value = getArgs(2).replace("&", "§"); + if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { + value = PlaceholderAPI.setPlaceholders(player, value); + } + + TagAPI.setPlayerDisplayName(player, value); + if (sender instanceof Player) { + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.SUCCESS-DISPLAY-SET", args[1], value); + } + } + +} diff --git a/src/main/java/me/skymc/taboolib/commands/sub/TagPrefixCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/TagPrefixCommand.java similarity index 92% rename from src/main/java/me/skymc/taboolib/commands/sub/TagPrefixCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/TagPrefixCommand.java index cd8a0bb..f52533f 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/TagPrefixCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/TagPrefixCommand.java @@ -1,15 +1,13 @@ -package me.skymc.taboolib.commands.sub; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; +import me.clip.placeholderapi.PlaceholderAPI; +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.team.TagManager; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import me.clip.placeholderapi.PlaceholderAPI; -import me.skymc.taboolib.commands.SubCommand; -import me.skymc.taboolib.message.MsgUtils; -import me.skymc.taboolib.team.TagManager; - /** * @author sky * @since 2018-03-19 23:13:35 diff --git a/src/main/java/me/skymc/taboolib/commands/sub/TagSuffixCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/TagSuffixCommand.java similarity index 93% rename from src/main/java/me/skymc/taboolib/commands/sub/TagSuffixCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/TagSuffixCommand.java index 72ff6ed..39aa825 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/TagSuffixCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/TagSuffixCommand.java @@ -1,9 +1,8 @@ -package me.skymc.taboolib.commands.sub; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.clip.placeholderapi.PlaceholderAPI; 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; diff --git a/src/main/java/me/skymc/taboolib/commands/sub/VariableGetCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/VariableGetCommand.java similarity index 96% rename from src/main/java/me/skymc/taboolib/commands/sub/VariableGetCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/VariableGetCommand.java index 836718c..ec338b6 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/VariableGetCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/VariableGetCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; diff --git a/src/main/java/me/skymc/taboolib/commands/sub/VariableSetCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/VariableSetCommand.java similarity index 96% rename from src/main/java/me/skymc/taboolib/commands/sub/VariableSetCommand.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/VariableSetCommand.java index 543adfc..1e7c257 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/VariableSetCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/VariableSetCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub; +package me.skymc.taboolib.commands.taboolib; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; diff --git a/src/main/java/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java b/src/main/java/me/skymc/taboolib/commands/taboolib/listener/ListenerItemListCommand.java similarity index 97% rename from src/main/java/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/listener/ListenerItemListCommand.java index 6ddbd9a..d7cc2e0 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/listener/ListenerItemListCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub.itemlist.listener; +package me.skymc.taboolib.commands.taboolib.listener; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.inventory.InventoryUtil; @@ -23,7 +23,7 @@ import java.util.List; * @author sky * @since 2018年2月4日 下午4:35:00 */ -public class ItemLibraryPatch implements Listener { +public class ListenerItemListCommand implements Listener { /** * 打开物品库界面 diff --git a/src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java b/src/main/java/me/skymc/taboolib/commands/taboolib/listener/ListenerSoundsCommand.java similarity index 97% rename from src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java rename to src/main/java/me/skymc/taboolib/commands/taboolib/listener/ListenerSoundsCommand.java index 515e07e..91e7f56 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/listener/ListenerSoundsCommand.java @@ -1,4 +1,4 @@ -package me.skymc.taboolib.commands.sub.sounds.listener; +package me.skymc.taboolib.commands.taboolib.listener; import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.inventory.InventoryUtil; @@ -24,7 +24,7 @@ import java.util.stream.Collectors; * @author sky * @since 2018年2月4日 下午4:35:00 */ -public class SoundsLibraryPatch implements Listener { +public class ListenerSoundsCommand implements Listener { public static void openInventory(Player player, int page, String search) { if (page < 1) { 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 9fa4638..91cfcdf 100644 --- a/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownUtils2.java +++ b/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownUtils2.java @@ -1,7 +1,5 @@ package me.skymc.taboolib.cooldown.seconds; -import java.util.concurrent.ConcurrentHashMap; - import com.ilummc.tlib.resources.TLocale; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -9,6 +7,8 @@ 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/CsvWriter.java b/src/main/java/me/skymc/taboolib/csvutils/CsvWriter.java index 26f87fd..16923a2 100644 --- a/src/main/java/me/skymc/taboolib/csvutils/CsvWriter.java +++ b/src/main/java/me/skymc/taboolib/csvutils/CsvWriter.java @@ -121,27 +121,6 @@ public class CsvWriter { this.userSettings.ForceQualifier = forceQualifier; } - public static String replace(final String s, final String s2, final String s3) { - final int length = s2.length(); - int i = s.indexOf(s2); - if (i > -1) { - final StringBuilder sb = new StringBuilder(); - int n; - for (n = 0; i != -1; i = s.indexOf(s2, n)) { - sb.append(s, n, i); - sb.append(s3); - n = i + length; - } - sb.append(s.substring(n)); - return sb.toString(); - } - return s; - } - - public void write(final String s) throws IOException { - this.write(s, false); - } - public void write(String s, final boolean b) throws IOException { this.checkClosed(); this.checkInit(); @@ -202,6 +181,10 @@ public class CsvWriter { this.firstColumn = false; } + public void write(final String s) throws IOException { + this.write(s, false); + } + public void writeComment(final String s) throws IOException { this.checkClosed(); this.checkInit(); @@ -215,6 +198,23 @@ public class CsvWriter { this.firstColumn = true; } + public static String replace(final String s, final String s2, final String s3) { + final int length = s2.length(); + int i = s.indexOf(s2); + if (i > -1) { + final StringBuilder sb = new StringBuilder(); + int n; + for (n = 0; i != -1; i = s.indexOf(s2, n)) { + sb.append(s, n, i); + sb.append(s3); + n = i + length; + } + sb.append(s.substring(n)); + return sb.toString(); + } + return s; + } + public void writeRecord(final String[] array) throws IOException { this.writeRecord(array, false); } diff --git a/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java b/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java index b8a5c63..a61da6c 100644 --- a/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java +++ b/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java @@ -1,20 +1,18 @@ package me.skymc.taboolib.database; +import com.ilummc.tlib.resources.TLocale; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.Main.StorageType; +import me.skymc.taboolib.TabooLib; +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; -import com.ilummc.tlib.resources.TLocale; -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; - public class GlobalDataManager { public static FileConfiguration data = DataUtils.addPluginData("TabooLibrary-Variable.yml", null); diff --git a/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java b/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java index 8db0ff4..51d2f09 100644 --- a/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java +++ b/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java @@ -7,7 +7,6 @@ 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 org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.configuration.file.FileConfiguration; diff --git a/src/main/java/me/skymc/taboolib/enchantment/EnchantmentUtils.java b/src/main/java/me/skymc/taboolib/enchantment/EnchantmentUtils.java index 2a16d17..c1d05cc 100644 --- a/src/main/java/me/skymc/taboolib/enchantment/EnchantmentUtils.java +++ b/src/main/java/me/skymc/taboolib/enchantment/EnchantmentUtils.java @@ -1,9 +1,9 @@ package me.skymc.taboolib.enchantment; -import java.lang.reflect.Field; - import org.bukkit.enchantments.Enchantment; +import java.lang.reflect.Field; + public class EnchantmentUtils { public static void setAcceptingNew(boolean value) { diff --git a/src/main/java/me/skymc/taboolib/events/itag/AsyncPlayerReceiveNameTagEvent.java b/src/main/java/me/skymc/taboolib/events/itag/AsyncPlayerReceiveNameTagEvent.java new file mode 100644 index 0000000..6d765de --- /dev/null +++ b/src/main/java/me/skymc/taboolib/events/itag/AsyncPlayerReceiveNameTagEvent.java @@ -0,0 +1,85 @@ +package me.skymc.taboolib.events.itag; + +import com.google.common.base.Preconditions; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import java.util.UUID; + +/** + * @author md_5 + */ +public class AsyncPlayerReceiveNameTagEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + private final Player player; + private final Player namedPlayer; + private String tag; + private UUID UUID; + private boolean tagModified; + private boolean UUIDModified; + + public Player getPlayer() { + return player; + } + + public Player getNamedPlayer() { + return namedPlayer; + } + + public String getTag() { + return tag; + } + + public java.util.UUID getUUID() { + return UUID; + } + + public boolean isTagModified() { + return tagModified; + } + + public boolean isUUIDModified() { + return UUIDModified; + } + + public AsyncPlayerReceiveNameTagEvent(Player who, Player namedPlayer, String initialName, UUID uuid) { + Preconditions.checkNotNull(who, "who"); + Preconditions.checkNotNull(namedPlayer, "namedPlayer"); + Preconditions.checkNotNull(initialName, "initialName"); + Preconditions.checkNotNull(uuid, "uuid"); + + this.player = who; + this.namedPlayer = namedPlayer; + this.tag = initialName; + this.tagModified = namedPlayer.getName().equals(initialName); + this.UUID = uuid; + } + + public boolean setTag(String tag) { + Preconditions.checkNotNull(tag, "tag"); + + this.tag = tag; + this.tagModified = true; + + return tag.length() < 16; + } + + public void setUUID(UUID uuid) { + Preconditions.checkNotNull(uuid, "uuid"); + + this.UUID = uuid; + this.UUIDModified = true; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/me/skymc/taboolib/events/itag/PlayerReceiveNameTagEvent.java b/src/main/java/me/skymc/taboolib/events/itag/PlayerReceiveNameTagEvent.java new file mode 100644 index 0000000..7ea835e --- /dev/null +++ b/src/main/java/me/skymc/taboolib/events/itag/PlayerReceiveNameTagEvent.java @@ -0,0 +1,57 @@ +package me.skymc.taboolib.events.itag; + +import com.google.common.base.Preconditions; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +/** + * @author md_5 + */ +public class PlayerReceiveNameTagEvent extends PlayerEvent { + + private static final HandlerList handlers = new HandlerList(); + private final Player namedPlayer; + private String tag; + private boolean modified; + + public Player getNamedPlayer() { + return namedPlayer; + } + + public String getTag() { + return tag; + } + + public boolean isModified() { + return modified; + } + + public PlayerReceiveNameTagEvent(Player who, Player namedPlayer, String initialName) { + super(who); + Preconditions.checkNotNull(who, "who"); + Preconditions.checkNotNull(namedPlayer, "namedPlayer"); + Preconditions.checkNotNull(initialName, "initialName"); + + this.namedPlayer = namedPlayer; + this.tag = initialName; + } + + public boolean setTag(String tag) { + Preconditions.checkNotNull(tag, "tag"); + + this.tag = tag; + this.modified = true; + + return tag.length() < 16; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java b/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java index c076fc1..4e886e0 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java @@ -2,7 +2,6 @@ package me.skymc.taboolib.fileutils; import com.google.common.collect.Maps; import com.google.common.io.Files; -import com.ilummc.tlib.TLib; import com.ilummc.tlib.bean.Property; import com.ilummc.tlib.resources.TLocale; import com.ilummc.tlib.util.Ref; diff --git a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java index c329cc3..19d2587 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java @@ -1,7 +1,6 @@ package me.skymc.taboolib.fileutils; import ch.njol.util.Closeable; -import me.skymc.taboolib.message.MsgUtils; import org.apache.commons.io.IOUtils; import java.io.*; diff --git a/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java b/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java index 2c25197..1ccf48c 100644 --- a/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java +++ b/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java @@ -9,7 +9,6 @@ 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 org.bukkit.Color; @@ -29,10 +28,10 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import java.io.File; +import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; -import java.util.Objects; import java.util.stream.IntStream; public class ItemUtils { @@ -128,7 +127,7 @@ public class ItemUtils { finalItemsFolder.mkdir(); } // 检查固定物品库中的物品 - Arrays.stream(Objects.requireNonNull(finalItemsFolder.listFiles())).forEach(file -> loadItemsFile(file, true)); + Arrays.stream(finalItemsFolder.listFiles()).forEach(file -> loadItemsFile(file, true)); TLocale.Logger.info("ITEM-UTILS.SUCCESS-LOAD-CACHES", String.valueOf(itemCaches.size() + itemCachesFinal.size())); } @@ -274,8 +273,9 @@ public class ItemUtils { return "generic.armor"; case "luck": return "generic.luck"; + default: + return null; } - return null; } /** diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTCompound.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTCompound.java index 8819bf4..a5b9887 100644 --- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTCompound.java +++ b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTCompound.java @@ -1,9 +1,9 @@ package me.skymc.taboolib.itemnbtapi; -import java.util.Set; - import me.skymc.taboolib.TabooLib; +import java.util.Set; + public class NBTCompound { private String compundName; diff --git a/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java b/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java index b06d456..b6ddeac 100644 --- a/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java +++ b/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java @@ -356,7 +356,7 @@ public class JSONFormatter { private class Builder { - private StringBuilder sb = new StringBuilder(""); + private StringBuilder sb = new StringBuilder(); private boolean bold = false, italic = false, magic = false, strikethrough = false, underline = false, changed = false; public Builder() { 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 8509f4a..863294c 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,17 @@ package me.skymc.taboolib.jsonformatter.hover; -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; +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; public class ShowItemEvent extends HoverEvent{ diff --git a/src/main/java/me/skymc/taboolib/listener/ListenerNetWork.java b/src/main/java/me/skymc/taboolib/listener/ListenerNetWork.java index 0f5b2b3..619c842 100644 --- a/src/main/java/me/skymc/taboolib/listener/ListenerNetWork.java +++ b/src/main/java/me/skymc/taboolib/listener/ListenerNetWork.java @@ -1,11 +1,10 @@ package me.skymc.taboolib.listener; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; - import me.skymc.taboolib.Main; import me.skymc.taboolib.message.MsgUtils; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; import pw.yumc.Yum.events.PluginNetworkEvent; /** diff --git a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java index 3594e56..603f4ce 100644 --- a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java +++ b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java @@ -1,11 +1,5 @@ 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; @@ -13,6 +7,11 @@ 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/ListenerPlayerQuit.java b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java index 94a580a..066e77c 100644 --- a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java +++ b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java @@ -1,12 +1,11 @@ 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/methods/ReflectionUtils.java b/src/main/java/me/skymc/taboolib/methods/ReflectionUtils.java index b25e364..6b2c54a 100644 --- a/src/main/java/me/skymc/taboolib/methods/ReflectionUtils.java +++ b/src/main/java/me/skymc/taboolib/methods/ReflectionUtils.java @@ -1,5 +1,7 @@ package me.skymc.taboolib.methods; +import org.bukkit.Bukkit; + import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -7,8 +9,6 @@ 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 5669936..f1ae225 100644 --- a/src/main/java/me/skymc/taboolib/mysql/MysqlConnection.java +++ b/src/main/java/me/skymc/taboolib/mysql/MysqlConnection.java @@ -3,7 +3,7 @@ package me.skymc.taboolib.mysql; import java.sql.*; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.*; +import java.util.concurrent.Executors; @Deprecated public class MysqlConnection { @@ -103,7 +103,7 @@ public class MysqlConnection { return; } - StringBuilder stringBuilder = new StringBuilder(""); + StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < list.length; i++) { if (i + 1 < list.length) { @@ -130,8 +130,8 @@ public class MysqlConnection { return; } - StringBuilder listbuilder = new StringBuilder(""); - StringBuilder valuebuilder = new StringBuilder(""); + StringBuilder listbuilder = new StringBuilder(); + StringBuilder valuebuilder = new StringBuilder(); for (int i = 0; i < list.length; i++) { if (i + 1 < list.length) { 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 7994c7c..c39b0c3 100644 --- a/src/main/java/me/skymc/taboolib/mysql/protect/MySQLConnection.java +++ b/src/main/java/me/skymc/taboolib/mysql/protect/MySQLConnection.java @@ -5,11 +5,7 @@ import com.ilummc.tlib.util.Strings; import me.skymc.taboolib.Main; import org.bukkit.plugin.Plugin; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.*; /** diff --git a/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java b/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java index de900f4..efc8234 100644 --- a/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java +++ b/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java @@ -1,24 +1,7 @@ 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.Bukkit; -import org.bukkit.DyeColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Server; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.block.BlockFace; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.MemorySection; @@ -32,6 +15,13 @@ 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/item/DabItemUtils.java b/src/main/java/me/skymc/taboolib/nms/item/DabItemUtils.java index a89c12a..dad63d1 100644 --- a/src/main/java/me/skymc/taboolib/nms/item/DabItemUtils.java +++ b/src/main/java/me/skymc/taboolib/nms/item/DabItemUtils.java @@ -1,15 +1,5 @@ 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; @@ -17,6 +7,15 @@ 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 d30aaa5..c24b652 100644 --- a/src/main/java/me/skymc/taboolib/nms/item/IDabItemUtils.java +++ b/src/main/java/me/skymc/taboolib/nms/item/IDabItemUtils.java @@ -1,14 +1,13 @@ 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/particle/EffLib.java b/src/main/java/me/skymc/taboolib/particle/EffLib.java index 6c71c35..c65df27 100644 --- a/src/main/java/me/skymc/taboolib/particle/EffLib.java +++ b/src/main/java/me/skymc/taboolib/particle/EffLib.java @@ -1,5 +1,14 @@ 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; @@ -9,16 +18,6 @@ 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/particle/ParticlePack.java b/src/main/java/me/skymc/taboolib/particle/ParticlePack.java index 13dc2f0..039c06c 100644 --- a/src/main/java/me/skymc/taboolib/particle/ParticlePack.java +++ b/src/main/java/me/skymc/taboolib/particle/ParticlePack.java @@ -1,8 +1,7 @@ package me.skymc.taboolib.particle; -import org.bukkit.Location; - import me.skymc.taboolib.TabooLib; +import org.bukkit.Location; public class ParticlePack { diff --git a/src/main/java/me/skymc/taboolib/permission/PermissionUtils.java b/src/main/java/me/skymc/taboolib/permission/PermissionUtils.java index b6588e1..10fd367 100644 --- a/src/main/java/me/skymc/taboolib/permission/PermissionUtils.java +++ b/src/main/java/me/skymc/taboolib/permission/PermissionUtils.java @@ -1,10 +1,9 @@ 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/player/PlayerUtils.java b/src/main/java/me/skymc/taboolib/player/PlayerUtils.java index 6452a61..76ce71e 100644 --- a/src/main/java/me/skymc/taboolib/player/PlayerUtils.java +++ b/src/main/java/me/skymc/taboolib/player/PlayerUtils.java @@ -1,13 +1,13 @@ package me.skymc.taboolib.player; -import java.util.HashSet; - import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.HashSet; + @SuppressWarnings("deprecation") public class PlayerUtils { diff --git a/src/main/java/me/skymc/taboolib/playerdata/DataUtils.java b/src/main/java/me/skymc/taboolib/playerdata/DataUtils.java index 74ed3ff..54687f5 100644 --- a/src/main/java/me/skymc/taboolib/playerdata/DataUtils.java +++ b/src/main/java/me/skymc/taboolib/playerdata/DataUtils.java @@ -5,7 +5,6 @@ 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 org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.configuration.file.FileConfiguration; diff --git a/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java b/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java index 72dc5e8..a592f4c 100644 --- a/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java +++ b/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java @@ -265,11 +265,11 @@ public class PluginUtils { } pluginManager.disablePlugin(plugin); - if (plugins != null && plugins.contains(plugin)) { + if (plugins != null) { plugins.remove(plugin); } - if (names != null && names.containsKey(name)) { + if (names != null) { names.remove(name); } diff --git a/src/main/java/me/skymc/taboolib/regen/WorldGuardUtils.java b/src/main/java/me/skymc/taboolib/regen/WorldGuardUtils.java index 0985731..d0ad421 100644 --- a/src/main/java/me/skymc/taboolib/regen/WorldGuardUtils.java +++ b/src/main/java/me/skymc/taboolib/regen/WorldGuardUtils.java @@ -1,11 +1,10 @@ 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/skript/SkriptHandler.java b/src/main/java/me/skymc/taboolib/skript/SkriptHandler.java index 9df2f0d..9b88a78 100644 --- a/src/main/java/me/skymc/taboolib/skript/SkriptHandler.java +++ b/src/main/java/me/skymc/taboolib/skript/SkriptHandler.java @@ -1,12 +1,11 @@ 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/ExpressionItemCache.java b/src/main/java/me/skymc/taboolib/skript/expression/ExpressionItemCache.java index 747114f..761f8c2 100644 --- a/src/main/java/me/skymc/taboolib/skript/expression/ExpressionItemCache.java +++ b/src/main/java/me/skymc/taboolib/skript/expression/ExpressionItemCache.java @@ -1,13 +1,12 @@ 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.taboolib.inventory.ItemUtils; +import org.bukkit.event.Event; +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 df51680..566305a 100644 --- a/src/main/java/me/skymc/taboolib/skript/expression/ExpressionTabooCodeItem.java +++ b/src/main/java/me/skymc/taboolib/skript/expression/ExpressionTabooCodeItem.java @@ -1,13 +1,12 @@ 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/LanguagePack.java b/src/main/java/me/skymc/taboolib/string/LanguagePack.java index 98e7c80..6ea3efc 100644 --- a/src/main/java/me/skymc/taboolib/string/LanguagePack.java +++ b/src/main/java/me/skymc/taboolib/string/LanguagePack.java @@ -1,17 +1,16 @@ package me.skymc.taboolib.string; +import me.skymc.taboolib.message.MsgUtils; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.Plugin; + import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; - -import me.skymc.taboolib.message.MsgUtils; - @Deprecated public class LanguagePack { diff --git a/src/main/java/me/skymc/taboolib/string/LanguageUtils.java b/src/main/java/me/skymc/taboolib/string/LanguageUtils.java index 199e61f..2e4d935 100644 --- a/src/main/java/me/skymc/taboolib/string/LanguageUtils.java +++ b/src/main/java/me/skymc/taboolib/string/LanguageUtils.java @@ -1,13 +1,12 @@ 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/Language2.java b/src/main/java/me/skymc/taboolib/string/language2/Language2.java index 11c50cd..0e5ec1c 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/Language2.java +++ b/src/main/java/me/skymc/taboolib/string/language2/Language2.java @@ -9,7 +9,6 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import java.io.File; -import java.io.FileNotFoundException; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/string/obfuscated/FZ.java b/src/main/java/me/skymc/taboolib/string/obfuscated/FZ.java index 3e647bd..1d02cbe 100644 --- a/src/main/java/me/skymc/taboolib/string/obfuscated/FZ.java +++ b/src/main/java/me/skymc/taboolib/string/obfuscated/FZ.java @@ -4,7 +4,7 @@ package me.skymc.taboolib.string.obfuscated; public class FZ { public static String toByte(final String string) { - final StringBuilder sb = new StringBuilder(""); + final StringBuilder sb = new StringBuilder(); final byte[] bs = string.getBytes(); byte[] array; for (int length = (array = bs).length, i = 0; i < length; ++i) { @@ -33,7 +33,7 @@ public class FZ { } public static String load(final String string, final int power) { - final StringBuilder sb = new StringBuilder(""); + final StringBuilder sb = new StringBuilder(); char[] charArray; for (int length = (charArray = string.toCharArray()).length, j = 0; j < length; ++j) { int i; @@ -46,7 +46,7 @@ public class FZ { public static String load2(final String string, final int power) { final String[] value = string.split("#"); - final StringBuilder sb = new StringBuilder(""); + final StringBuilder sb = new StringBuilder(); String[] array; for (int length = (array = value).length, j = 0; j < length; ++j) { final String c = array[j]; diff --git a/src/main/java/me/skymc/taboolib/team/TagAPI.java b/src/main/java/me/skymc/taboolib/team/TagAPI.java new file mode 100644 index 0000000..c2d2677 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/team/TagAPI.java @@ -0,0 +1,150 @@ +package me.skymc.taboolib.team; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.wrappers.EnumWrappers; +import com.comphenix.protocol.wrappers.PlayerInfoData; +import com.comphenix.protocol.wrappers.WrappedGameProfile; +import com.google.common.base.Preconditions; +import com.ilummc.tlib.bungee.api.ChatColor; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.events.itag.AsyncPlayerReceiveNameTagEvent; +import me.skymc.taboolib.events.itag.PlayerReceiveNameTagEvent; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.*; +import java.util.stream.IntStream; + +/** + * @Author sky + * @Since 2018-05-09 21:03 + */ +public class TagAPI implements Listener { + + private static final int[] uuidSplit = new int[]{0, 8, 12, 16, 20, 32}; + + private static boolean loaded = false; + private static HashMap entityIdMap = new HashMap<>(); + private static HashMap playerData = new HashMap<>(); + + TagAPI() { + } + + public static void inst() { + assert !loaded : "TagAPI is already instanced!"; + loaded = true; + + Bukkit.getServer().getOnlinePlayers().forEach(player -> entityIdMap.put(player.getEntityId(), player)); + Bukkit.getPluginManager().registerEvents(new TagAPI(), Main.getInst()); + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(Main.getInst(), PacketType.Play.Server.PLAYER_INFO) { + + @Override + public void onPacketSending(PacketEvent event) { + if (event.getPacket().getPlayerInfoAction().read(0) != EnumWrappers.PlayerInfoAction.ADD_PLAYER) { + return; + } + + List newPlayerInfo = new ArrayList<>(); + for (PlayerInfoData playerInfo : event.getPacket().getPlayerInfoDataLists().read(0)) { + Player player; + if (playerInfo == null || playerInfo.getProfile() == null || (player = Bukkit.getServer().getPlayer(playerInfo.getProfile().getUUID())) == null) { + // Unknown Player + newPlayerInfo.add(playerInfo); + continue; + } + newPlayerInfo.add(new PlayerInfoData(getSentName(player.getEntityId(), playerInfo.getProfile(), event.getPlayer()), playerInfo.getPing(), playerInfo.getGameMode(), playerInfo.getDisplayName())); + } + event.getPacket().getPlayerInfoDataLists().write(0, newPlayerInfo); + } + }); + } + + public static String getPlayerDisplayName(Player player) { + return playerData.getOrDefault(player.getUniqueId(), player.getName()); + } + + public static void setPlayerDisplayName(Player player, String name) { + String nameColored = ChatColor.translateAlternateColorCodes('&', name); + player.setDisplayName(nameColored); + player.setPlayerListName(nameColored); + playerData.put(player.getUniqueId(), nameColored); + + Bukkit.getScheduler().runTask(Main.getInst(), () -> refreshPlayer(player)); + } + + public static void removePlayerDisplayName(Player player) { + player.setDisplayName(null); + player.setPlayerListName(null); + playerData.remove(player.getUniqueId()); + + Bukkit.getScheduler().runTask(Main.getInst(), () -> refreshPlayer(player)); + } + + public static void refreshPlayer(Player player) { + Preconditions.checkState(Main.getInst().isEnabled(), "Not Enabled!"); + Preconditions.checkNotNull(player, "player"); + + player.getWorld().getPlayers().forEach(playerFor -> refreshPlayer(player, playerFor)); + } + + public static void refreshPlayer(final Player player, final Player forWhom) { + Preconditions.checkState(Main.getInst().isEnabled(), "Not Enabled!"); + Preconditions.checkNotNull(player, "player"); + Preconditions.checkNotNull(forWhom, "forWhom"); + + if (player != forWhom && player.getWorld() == forWhom.getWorld() && forWhom.canSee(player)) { + forWhom.hidePlayer(player); + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.getInst(), () -> forWhom.showPlayer(player), 2); + } + } + + public static void refreshPlayer(Player player, Set forWhom) { + Preconditions.checkState(Main.getInst().isEnabled(), "Not Enabled!"); + Preconditions.checkNotNull(player, "player"); + Preconditions.checkNotNull(forWhom, "forWhom"); + + forWhom.forEach(playerFor -> refreshPlayer(player, playerFor)); + } + + private static WrappedGameProfile getSentName(int sentEntityId, WrappedGameProfile sent, Player destinationPlayer) { + Preconditions.checkState(Bukkit.getServer().isPrimaryThread(), "Can only process events on main thread."); + + Player namedPlayer = entityIdMap.get(sentEntityId); + if (namedPlayer == null) { + // They probably were dead when we reloaded + return sent; + } + + PlayerReceiveNameTagEvent oldEvent = new PlayerReceiveNameTagEvent(destinationPlayer, namedPlayer, sent.getName()); + Bukkit.getServer().getPluginManager().callEvent(oldEvent); + + StringBuilder builtUUID = new StringBuilder(); + if (!sent.getId().contains("-")) { + IntStream.range(0, uuidSplit.length - 1).forEach(i -> builtUUID.append(sent.getId(), uuidSplit[i], uuidSplit[i + 1]).append("-")); + } else { + builtUUID.append(sent.getId()); + } + + AsyncPlayerReceiveNameTagEvent newEvent = new AsyncPlayerReceiveNameTagEvent(destinationPlayer, namedPlayer, oldEvent.getTag(), UUID.fromString(builtUUID.toString())); + Bukkit.getServer().getPluginManager().callEvent(newEvent); + + return new WrappedGameProfile(newEvent.getUUID(), newEvent.getTag().substring(0, Math.min(newEvent.getTag().length(), 16))); + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + entityIdMap.put(event.getPlayer().getEntityId(), event.getPlayer()); + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + entityIdMap.remove(event.getPlayer().getEntityId()); + } +} diff --git a/src/main/java/me/skymc/taboolib/update/UpdateTask.java b/src/main/java/me/skymc/taboolib/update/UpdateTask.java index fbcb12c..7deb383 100644 --- a/src/main/java/me/skymc/taboolib/update/UpdateTask.java +++ b/src/main/java/me/skymc/taboolib/update/UpdateTask.java @@ -6,7 +6,6 @@ import com.ilummc.tlib.resources.TLocale; 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; /** diff --git a/src/main/java/me/skymc/tlm/command/sub/TLMInvCommand.java b/src/main/java/me/skymc/tlm/command/sub/TLMInvCommand.java index e611c38..f6f1b06 100644 --- a/src/main/java/me/skymc/tlm/command/sub/TLMInvCommand.java +++ b/src/main/java/me/skymc/tlm/command/sub/TLMInvCommand.java @@ -1,21 +1,20 @@ package me.skymc.tlm.command.sub; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.tlm.TLM; import me.skymc.tlm.inventory.TLMInventoryHolder; import me.skymc.tlm.module.TabooLibraryModule; import me.skymc.tlm.module.sub.ModuleInventorySave; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import java.util.List; /** * @author sky 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 42ded4d..fa22444 100644 --- a/src/main/java/me/skymc/tlm/command/sub/TLMKitCommand.java +++ b/src/main/java/me/skymc/tlm/command/sub/TLMKitCommand.java @@ -1,17 +1,16 @@ package me.skymc.tlm.command.sub; -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 me.skymc.taboolib.commands.SubCommand; import me.skymc.tlm.TLM; import me.skymc.tlm.module.TabooLibraryModule; import me.skymc.tlm.module.sub.ModuleKits; +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; /** * @author sky diff --git a/src/main/java/me/skymc/tlm/command/sub/TLMListCommand.java b/src/main/java/me/skymc/tlm/command/sub/TLMListCommand.java index 2d8afea..42a0906 100644 --- a/src/main/java/me/skymc/tlm/command/sub/TLMListCommand.java +++ b/src/main/java/me/skymc/tlm/command/sub/TLMListCommand.java @@ -1,10 +1,9 @@ package me.skymc.tlm.command.sub; -import org.bukkit.command.CommandSender; - import me.skymc.taboolib.commands.SubCommand; import me.skymc.tlm.module.ITabooLibraryModule; import me.skymc.tlm.module.TabooLibraryModule; +import org.bukkit.command.CommandSender; /** * @author sky diff --git a/src/main/java/me/skymc/tlm/command/sub/TLMReloadCommand.java b/src/main/java/me/skymc/tlm/command/sub/TLMReloadCommand.java index fa82fd6..05fdbd8 100644 --- a/src/main/java/me/skymc/tlm/command/sub/TLMReloadCommand.java +++ b/src/main/java/me/skymc/tlm/command/sub/TLMReloadCommand.java @@ -1,12 +1,11 @@ package me.skymc.tlm.command.sub; -import org.bukkit.command.CommandSender; - import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.message.MsgUtils; import me.skymc.tlm.TLM; import me.skymc.tlm.module.ITabooLibraryModule; import me.skymc.tlm.module.TabooLibraryModule; +import org.bukkit.command.CommandSender; /** * @author sky diff --git a/src/main/java/me/skymc/tlm/module/sub/ModuleCommandChanger.java b/src/main/java/me/skymc/tlm/module/sub/ModuleCommandChanger.java index b23a059..186c72c 100644 --- a/src/main/java/me/skymc/tlm/module/sub/ModuleCommandChanger.java +++ b/src/main/java/me/skymc/tlm/module/sub/ModuleCommandChanger.java @@ -1,12 +1,11 @@ package me.skymc.tlm.module.sub; +import me.skymc.tlm.module.ITabooLibraryModule; 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.tlm.module.ITabooLibraryModule; - /** * @author sky * @since 2018年2月22日 下午1:32:29 diff --git a/src/main/resources/lang/zh_CN.yml b/src/main/resources/lang/zh_CN.yml index c4649cd..25c7489 100644 --- a/src/main/resources/lang/zh_CN.yml +++ b/src/main/resources/lang/zh_CN.yml @@ -121,6 +121,7 @@ COMMANDS: - '&8[&3&lTabooLib&8] §7指令 §f{0} §7不存在' - '&8[&3&lTabooLib&8] §7你可能想要:' - '&8[&3&lTabooLib&8] §7{1}' + COMMAND-REGISTER: '&7自动为插件 &f{0} &7的命令 &f{1} &7注册 &f{2} &7条子命令' PARAMETER: UNKNOWN: '&8[&3&lTabooLib&8] &4指令错误' INSUFFICIENT: '&8[&3&lTabooLib&8] &4参数不足' @@ -129,41 +130,11 @@ COMMANDS: SUCCESS-NORMAL: '&8[&3&lTabooLib&8] &7重载成功' SUCCESS-ELAPSED-TIME: '&8[&3&lTabooLib&8] &7重载成功, 耗时: &f{0} ms' TABOOLIB: - HELP: - - '' - - '§b§l----- §3§lTaooLib Commands §b§l-----' - - '' - - '&f /{0} save §8[§7名称§8] &6- §e保存手中物品' - - '&f /{0} item §8[§7名称§8] §8<§7玩家§8> §8<§7数量§8> &6- §e给予玩家物品' - - '&f /{0} iteminfo &6- §e查看物品信息' - - '&f /{0} itemlist &6- §e查看所有物品' - - '&f /{0} itemreload &6- §e重载物品缓存' - - '' - - '&f /{0} attributes &6- §e查看所有属性' - - '&f /{0} enchants &6- §e查看所有附魔' - - '&f /{0} potions &6- §e查看所有药水' - - '&f /{0} flags &6- §e查看所有标签' - - '&f /{0} slots &6- §e查看所有部位' - - '&f /{0} sounds &6- §e查看所有音效' - - '' - - '&f /{0} getvariable §8[§7-s|a§8] §8[§7键§8] &6- §e查看变量' - - '&f /{0} setvariable §8[§7-s|a§8] §8[§7键§8] §8[§7值§8] &6- §e更改变量' - - '' - - '&f /{0} cycle list &6- §e列出所有时间检查器' - - '&f /{0} cycle info §8[§7名称§8] &6- §e查询检查器信息' - - '&f /{0} cycle reset §8[§7名称§8] &6- §e初始化时间检查器' - - '&f /{0} cycle update §8[§7名称§8] &6- §e更新时间检查器' - - '' - - '&f /{0} shell load §8[§7名称§8] &6- §e载入某个脚本' - - '&f /{0} shell unload §8[§7名称§8] &6- §e卸载某个脚本' - - '' - - '&f /{0} tagprefix §8[§7名称§8] §8[§7文本§8] &6- §e设置玩家头顶前缀' - - '&f /{0} tagsuffix §8[§7名称§8] §8[§7文本§8] &6- §e设置玩家头顶后缀' - - '&f /{0} tagdelete §8[§7名称§8] &6- §e删除玩家称号数据' - - '' - - '&f /{0} importdata &6- §4向数据库导入本地数据 §8(该操作将会清空数据库)' - - '' + COMMAND-TITLE: '§b§l----- §3§lTabooLib Commands §b§l-----' SAVE: + DESCRIPTION: '载入插件' + ARGUMENTS: + 0: '名称' INVALID-NAME: '&8[&3&lTabooLib&8] &4请输入正确的名称' INVALID-ITEM: '&8[&3&lTabooLib&8] &4请手持正确的物品' INVALID-ITEM-FINAL-EXISTS: '&8[&3&lTabooLib&8] &4该名称所对应的物品保存于固定物品库中, 无法覆盖' @@ -172,34 +143,81 @@ COMMANDS: GUIDE-QUIT: '&8[&3&lTabooLib&8] &7退出引导' SUCCESS: '&8[&3&lTabooLib&8] &7物品 &f{0} &7已替换' ITEM: + DESCRIPTION: '给予玩家物品' + ARGUMENTS: + 0: '名称' + 1: '玩家' + 2: '数量' INVALID-NAME: '&8[&3&lTabooLib&8] &4请输入正确的名称' INVALID-ITEM: '&8[&3&lTabooLib&8] &4物品 &c{0} &4不存在' INVALID-PLAYER: '&8[&3&lTabooLib&8] &4玩家 &c{0} &4不在线' INVALID-NUMBER: '&8[&3&lTabooLib&8] &4数量必须大于0' SUCCESS: '&8[&3&lTabooLib&8] &7物品已发送至玩家 &f{0} &7的背包中' + ITEMRELOAD: + DESCRIPTION: '重载物品缓存' + SUCCESS-RELOAD: '&8[&3&lTabooLib&8] &7重载成功' VARIABLE: + DESCRIPTION: + GET: '查看变量' + SET: '设置变量' + ARGUMENTS: + GET: + 0: '-s|-a' + 1: '键' + SET: + 0: '-s|-a' + 1: '键' + 2: '值' WRITE-ERROR-TYPE: '&8[&3&lTabooLib&8] &4请输入正确的写入方式: &c-s&4、&c-a' WRITE-SUCCESS: '&8[&3&lTabooLib&8] &7写入完成, 耗时: &f{0} &7(ms)' READ-ERROR-TYPE: '&8[&3&lTabooLib&8] &4请输入正确的写入方式: &c-s&4、&c-a' READ-RESULT: '&8[&3&lTabooLib&8] &7变量 &f{0} &7的值为: &f{1}' READ-SUCCESS: '&8[&3&lTabooLib&8] &7写入完成, 耗时: &f{0} &7(ms)' IMPORTDATA: + DESCRIPTION: '§4向数据库导入本地数据 §8(该操作将会清空数据库)' CLEARING: '&8[&3&lTabooLib&8] &7正在清空数据库...' EMPTYDATA: '&8[&3&lTabooLib&8] &4没有玩家数据可以导入' IMPORTING-START: '&8[&3&lTabooLib&8] &7开始导入 &f{0} &7项玩家数据' IMPORTING-PROGRESS: '&8[&3&lTabooLib&8] &7导入玩家数据: &f{0} &7进度: &f{1}/{2}' SUCCESS: '&8[&3&lTabooLib&8] &7导入完成' JAVASHELL: + DESCRIPTION: + LOAD: '载入脚本' + UNLOAD: '卸载脚本' + ARGUMENTS: + LOAD: + 0: '名称' + UNLOAD: + 0: '名称' INVALID-NAME: '&8[&3&lTabooLib&8] &4请输入正确的名称' INVALID-SHELL: '&8[&3&lTabooLib&8] &4脚本 &c{0} &4不存在' SUCCESS-LOAD: '&8[&3&lTabooLib&8] &7脚本 &f{0} &7已载入' SUCCESS-UNLOAD: '&8[&3&lTabooLib&8] &7脚本 &f{0} &7已卸载' PLAYERTAG: + DESCRIPTION: + DISPLAY: '设置玩家展示名称' + PREFIX: '设置玩家头顶前缀' + SUFFIX: '设置玩家头顶后缀' + DELETE: '删除玩家称号数据' + ARGUMENTS: + DISPLAY: + 0: '玩家' + 1: '文本' + PREFIX: + 0: '玩家' + 1: '文本' + SUFFIX: + 0: '玩家' + 1: '文本' + DELETE: + 0: '玩家' INVALID-PLAYER: '&8[&3&lTabooLib&8] &4玩家 &c{0} &4不在线' + SUCCESS-DISPLAY-SET: '&8[&3&lTabooLib&8] &7设置玩家 &f{0} &7的名称为 &f{1}' SUCCESS-PREFIX-SET: '&8[&3&lTabooLib&8] &7设置玩家 &f{0} &7的前缀为 &f{1}' SUCCESS-SUFFIX-SET: '&8[&3&lTabooLib&8] &7设置玩家 &f{0} &7的后缀为 &f{1}' SUCCESS-DELETE: '&8[&3&lTabooLib&8] &7删除玩家 &f{0} &7的称号数据' INFO: + DESCRIPTION: '查看物品信息' INVALID-ITEM: '&8[&3&lTabooLib&8] &4请手持正确的物品' ITEM-INFO: - ==: JSON @@ -225,6 +243,7 @@ COMMANDS: nbt: hover: '{3}' ITEMLIST: + DESCRIPTION: '查看所有物品' MENU: TITLE: '物品库 {0}' NEXT: '§f上一页' @@ -234,6 +253,7 @@ COMMANDS: - '§f§m ' - '§f序列号: §8{0}' SOUNDS: + DESCRIPTION: '查看所有音效' MENU: TITLE: '音效库 {0}' NEXT: '§f上一页' @@ -255,6 +275,18 @@ COMMANDS: hover: 点击复制音效 suggest: '{0}' TIMECYCLE: + DESCRIPTION: + LIST: '列出所有时间检查器' + INFO: '查询检查器信息' + RESET: '初始化时间检查器' + UPDATE: '更新时间检查器' + ARGUMENTS: + INFO: + 0: '名称' + RESET: + 0: '名称' + UPDATE: + 0: '名称' INVALID-CYCLE: '&8[&3&lTabooLib&8] &4检查器 &c{0} &4不存在' CYCLE-UPDATE: '&8[&3&lTabooLib&8] &7检查器 &f{0} &7已更新' CYCLE-RESET: '&8[&3&lTabooLib&8] &7检查器 &f{0} &7初始化完成' @@ -281,6 +313,7 @@ COMMANDS: FOOT: - '' ATTRIBUTES: + DESCRIPTION: '查看所有属性' HEAD: - '' - '§b§l----- §3§lItemStack Attributes §b§l-----' @@ -295,6 +328,7 @@ COMMANDS: FOOT: - '' ENCHANTS: + DESCRIPTION: '查看所有附魔' HEAD: - '' - '§b§l----- §3§lItemStack Enchantments §b§l-----' @@ -309,6 +343,7 @@ COMMANDS: FOOT: - '' POTIONS: + DESCRIPTION: '查看所有药水' HEAD: - '' - '§b§l----- §3§lItemStack PotionEffects §b§l-----' @@ -323,6 +358,7 @@ COMMANDS: FOOT: - '' FLAGS: + DESCRIPTION: '查看所有标签' HEAD: - '' - '§b§l----- §3§lItemStack Flags §b§l-----' @@ -337,6 +373,7 @@ COMMANDS: FOOT: - '' SLOTS: + DESCRIPTION: '查看所有部位' HEAD: - '' - '§b§l----- §3§lItemStack Slots §b§l-----'