From d4910db108782de04518b061a2a8e9bd3df98fdd Mon Sep 17 00:00:00 2001 From: Izzel_Aliz Date: Sat, 24 Mar 2018 23:18:11 +0800 Subject: [PATCH] IDEA Auto Inspect --- .gradle/4.5/fileHashes/fileHashes.bin | Bin 71215 -> 71365 bytes .gradle/4.5/fileHashes/fileHashes.lock | Bin 17 -> 17 bytes .gradle/buildOutputCleanup/outputFiles.bin | Bin 18803 -> 0 bytes .idea/compiler.xml | 9 + .idea/gradle.xml | 19 + .idea/inspectionProfiles/Project_Default.xml | 36 ++ .idea/modules/TabooLib_main.iml | 148 ++++++++ .idea/modules/TabooLib_test.iml | 150 ++++++++ .idea/vcs.xml | 7 + gradle/wrapper/gradle-wrapper.properties | 3 +- src/main/java/me/skymc/taboolib/Main.java | 43 +-- src/main/java/me/skymc/taboolib/TabooLib.java | 10 +- .../taboolib/anvil/AnvilContainerAPI.java | 10 +- .../versions/AnvilContainer_V1_11_R1.java | 11 +- .../versions/AnvilContainer_V1_8_R3.java | 11 +- .../anvil/versions/AnvilContainer_V1_9_4.java | 11 +- .../me/skymc/taboolib/bstats/Metrics.java | 34 +- .../skymc/taboolib/commands/MainCommands.java | 31 +- .../skymc/taboolib/commands/SubCommand.java | 2 +- .../taboolib/commands/SubCommandExecutor.java | 6 +- .../commands/sub/AttributesCommand.java | 6 +- .../taboolib/commands/sub/HelpCommand.java | 16 +- .../taboolib/commands/sub/InfoCommand.java | 9 +- .../taboolib/commands/sub/SlotCommand.java | 6 +- .../commands/sub/TagDeleteCommand.java | 8 +- .../commands/sub/cycle/CycleCommand.java | 6 +- .../commands/sub/cycle/CycleInfoCommand.java | 13 +- .../commands/sub/cycle/CycleListCommand.java | 10 +- .../sub/cycle/CycleUpdateCommand.java | 8 +- .../itemlist/listener/ItemLibraryPatch.java | 76 ++-- .../commands/sub/shell/ShellCommand.java | 6 +- .../sounds/listener/SoundsLibraryPatch.java | 84 +++-- .../skymc/taboolib/cooldown/CooldownPack.java | 2 - .../taboolib/cooldown/CooldownUtils.java | 10 +- .../cooldown/seconds/CooldownPack2.java | 3 - .../cooldown/seconds/CooldownUtils2.java | 9 +- .../me/skymc/taboolib/csvutils/CsvReader.java | 14 +- .../me/skymc/taboolib/csvutils/CsvWriter.java | 70 ++-- .../me/skymc/taboolib/damage/DamageUtils.java | 21 +- .../me/skymc/taboolib/damage/GetKiller.java | 3 - .../taboolib/database/GlobalDataManager.java | 26 +- .../taboolib/database/PlayerDataManager.java | 27 +- .../skymc/taboolib/display/ActionUtils.java | 12 +- .../me/skymc/taboolib/display/TitleUtils.java | 32 +- .../me/skymc/taboolib/entity/EntityTag.java | 31 +- .../skymc/taboolib/events/DefaultEvent.java | 1 - .../taboolib/events/PlayerLoadedEvent.java | 1 - .../skymc/taboolib/fileutils/ConfigUtils.java | 16 +- .../skymc/taboolib/fileutils/CopyUtils.java | 2 - .../skymc/taboolib/fileutils/EncodeUtils.java | 10 +- .../skymc/taboolib/fileutils/FileUtils.java | 23 +- .../me/skymc/taboolib/fileutils/LogUtils.java | 10 +- .../skymc/taboolib/inventory/DropUtils.java | 6 +- .../taboolib/inventory/InventoryUtil.java | 33 +- .../skymc/taboolib/inventory/ItemUtils.java | 102 ++---- .../speciaitem/AbstractSpecialItem.java | 8 +- .../inventory/speciaitem/SpecialItem.java | 70 ++-- .../speciaitem/SpecialItemResult.java | 4 +- .../itemnbtapi/NBTReflectionUtil.java | 72 ++-- .../taboolib/javascript/JavaScriptUtils.java | 26 +- .../skymc/taboolib/javashell/JavaShell.java | 40 +-- .../taboolib/javashell/utils/JarUtils.java | 23 +- src/main/java/me/skymc/taboolib/json/CDL.java | 4 +- .../java/me/skymc/taboolib/json/Cookie.java | 6 +- .../me/skymc/taboolib/json/CookieList.java | 2 +- .../java/me/skymc/taboolib/json/HTTP.java | 2 +- .../me/skymc/taboolib/json/HTTPTokener.java | 2 +- .../me/skymc/taboolib/json/JSONArray.java | 10 +- .../java/me/skymc/taboolib/json/JSONML.java | 58 ++-- .../me/skymc/taboolib/json/JSONObject.java | 326 +++++++++--------- .../me/skymc/taboolib/json/JSONString.java | 2 +- .../me/skymc/taboolib/json/JSONTokener.java | 17 +- src/main/java/me/skymc/taboolib/json/XML.java | 28 +- .../me/skymc/taboolib/json/XMLTokener.java | 4 +- .../taboolib/jsonformatter/JSONFormatter.java | 33 +- .../jsonformatter/hover/ShowItemEvent.java | 27 +- .../listener/ListenerPlayerCommand.java | 21 +- .../taboolib/listener/ListenerPlayerJump.java | 13 +- .../taboolib/listener/ListenerPlayerQuit.java | 7 +- .../listener/ListenerPluginDisable.java | 16 +- .../taboolib/location/LocationUtils.java | 2 - .../skymc/taboolib/message/ChatCatcher.java | 25 +- .../skymc/taboolib/methods/MethodsUtils.java | 32 +- .../taboolib/methods/ReflectionUtils.java | 18 +- .../skymc/taboolib/mysql/MysqlConnection.java | 24 +- .../me/skymc/taboolib/mysql/MysqlUtils.java | 11 +- .../mysql/protect/MySQLConnection.java | 89 +++-- .../java/me/skymc/taboolib/nms/NMSUtil18.java | 14 +- .../java/me/skymc/taboolib/nms/NMSUtil19.java | 23 +- .../java/me/skymc/taboolib/nms/NMSUtils.java | 27 +- .../skymc/taboolib/nms/item/DabItemUtils.java | 27 +- .../taboolib/nms/item/IDabItemUtils.java | 237 ++++++++----- .../taboolib/nms/item/impl/_164ItemUtils.java | 85 ++--- .../nms/item/impl/_1710ItemUtils.java | 79 ++--- .../taboolib/nms/item/impl/_194ItemUtils.java | 80 ++--- .../me/skymc/taboolib/other/DateUtils.java | 3 - .../me/skymc/taboolib/other/NumberUtils.java | 4 +- .../me/skymc/taboolib/other/WeightUtils.java | 6 +- .../me/skymc/taboolib/packet/PacketUtils.java | 61 ++-- .../me/skymc/taboolib/particle/EffLib.java | 22 +- .../taboolib/particle/ParticleUtils.java | 3 +- .../taboolib/permission/PermissionUtils.java | 9 +- .../skymc/taboolib/playerdata/DataUtils.java | 22 +- .../me/skymc/taboolib/plugin/PluginUtils.java | 57 ++- .../skymc/taboolib/regen/WorldGuardUtils.java | 23 +- .../taboolib/scoreboard/ScoreboardUtil.java | 3 +- .../taboolib/sign/TabooSignChangeEvent.java | 5 - .../skymc/taboolib/skript/SkriptHandler.java | 6 +- .../expression/ExpressionTabooCodeItem.java | 7 +- .../me/skymc/taboolib/skull/SkullUtils.java | 3 - .../me/skymc/taboolib/sound/SoundPack.java | 1 - .../me/skymc/taboolib/string/Language.java | 23 +- .../skymc/taboolib/string/LanguageUtils.java | 16 +- .../skymc/taboolib/string/PatternUtils.java | 6 +- .../me/skymc/taboolib/string/StringUtils.java | 4 +- .../string/language2/Language2Format.java | 59 ++-- .../string/language2/Language2Line.java | 12 +- .../string/language2/Language2Value.java | 20 +- .../language2/value/Language2Action.java | 15 +- .../string/language2/value/Language2Book.java | 28 +- .../string/language2/value/Language2Json.java | 17 +- .../string/language2/value/Language2Text.java | 17 +- .../language2/value/Language2Title.java | 12 +- .../skymc/taboolib/string/obfuscated/CT.java | 38 +- .../skymc/taboolib/string/obfuscated/FZ.java | 4 +- .../taboolib/support/SupportPlaceholder.java | 7 +- .../taboolib/support/SupportWorldGuard.java | 19 +- .../me/skymc/taboolib/team/TagManager.java | 18 +- .../java/me/skymc/taboolib/team/TagUtils.java | 4 - .../me/skymc/taboolib/thread/ThreadUtils.java | 7 +- .../taboolib/timecycle/TimeCycleManager.java | 17 +- .../me/skymc/taboolib/update/UpdateTask.java | 10 +- src/main/java/me/skymc/tlm/TLM.java | 7 +- .../skymc/tlm/annotation/DisableConfig.java | 10 +- .../skymc/tlm/command/sub/TLMKitCommand.java | 24 +- .../skymc/tlm/module/ITabooLibraryModule.java | 11 +- .../skymc/tlm/module/TabooLibraryModule.java | 13 +- .../me/skymc/tlm/module/sub/ModuleKits.java | 15 +- .../skymc/tlm/module/sub/ModuleTimeCycle.java | 13 +- 139 files changed, 1714 insertions(+), 1814 deletions(-) delete mode 100644 .gradle/buildOutputCleanup/outputFiles.bin create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/modules/TabooLib_main.iml create mode 100644 .idea/modules/TabooLib_test.iml create mode 100644 .idea/vcs.xml diff --git a/.gradle/4.5/fileHashes/fileHashes.bin b/.gradle/4.5/fileHashes/fileHashes.bin index 867f5e59f899788307c921d8c9a07b962f4c0b1b..10cc8e4dadb66f7a8142a705ae20da481aa121ba 100644 GIT binary patch delta 227 zcmZ3#hUMs5mJKEnj1rqoB_x^o)i%lO+W%CI0R$Mu^f$XoS90@D?q8P}=*0vToVQiwn5*C%^bRxhZM#Lb59KeID#+^Co!x_vGW<0Q@mW1y5K z5G#VPz?1!5mCagBpSs)%XXac@76e+B6j7qB4c5=VlL@5tP<2E}IO$Gz`ul#*G5%L! k9O95K^Kzh_s7Hq9~+rl_&?w#h>Ja3&}w#_OKU+J)%(s^RusC zCl-%*eQN!1>HeCD3QPE%P0jC@erE5PY+b0_Rr5=vUnYbO=G|82sNOF9rnw+@IO}9o z^;+q=D<-vVyt7yJMCr-ZtB?2FGe>53%tQpb4-cdEX za{7`nr24w_uC$#(=aqF*^?K>OOY{Du!$@6qw{$scn(i{MaYO(C1Q0*~0R#|0009IL zKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009ILK)@8pH%<}89{3qu b4;-Su6(jsn3BK3w%I}^q_+G*5{4nPOgyHUe diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..f0879a2 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..98b6aa4 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..0f1df49 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/.idea/modules/TabooLib_main.iml b/.idea/modules/TabooLib_main.iml new file mode 100644 index 0000000..335b82b --- /dev/null +++ b/.idea/modules/TabooLib_main.iml @@ -0,0 +1,148 @@ + + + + + + + SPIGOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/TabooLib_test.iml b/.idea/modules/TabooLib_test.iml new file mode 100644 index 0000000..35e5ad7 --- /dev/null +++ b/.idea/modules/TabooLib_test.iml @@ -0,0 +1,150 @@ + + + + + + + SPIGOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..8306744 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index be280be..f01aaaa 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Sat Mar 24 22:41:19 CST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip diff --git a/src/main/java/me/skymc/taboolib/Main.java b/src/main/java/me/skymc/taboolib/Main.java index 4a28b26..f0ec280 100644 --- a/src/main/java/me/skymc/taboolib/Main.java +++ b/src/main/java/me/skymc/taboolib/Main.java @@ -1,15 +1,5 @@ package me.skymc.taboolib; -import java.io.File; -import java.util.Random; - -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.event.Listener; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitRunnable; - import lombok.Getter; import lombok.Setter; import me.skymc.taboolib.anvil.AnvilContainerAPI; @@ -19,22 +9,22 @@ import me.skymc.taboolib.commands.MainCommands; import me.skymc.taboolib.commands.language.Language2Command; import me.skymc.taboolib.commands.sub.itemlist.listener.ItemLibraryPatch; import me.skymc.taboolib.commands.sub.sounds.listener.SoundsLibraryPatch; -import me.skymc.taboolib.database.PlayerDataManager; import me.skymc.taboolib.database.GlobalDataManager; +import me.skymc.taboolib.database.PlayerDataManager; import me.skymc.taboolib.economy.EcoUtils; import me.skymc.taboolib.entity.EntityUtils; import me.skymc.taboolib.fileutils.ConfigUtils; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.inventory.speciaitem.SpecialItem; import me.skymc.taboolib.javashell.JavaShell; -import me.skymc.taboolib.listener.ListenerNetWork; -import me.skymc.taboolib.listener.ListenerPlayerCommand; -import me.skymc.taboolib.listener.ListenerPlayerQuit; -import me.skymc.taboolib.listener.ListenerPlayerJump; -import me.skymc.taboolib.listener.ListenerPluginDisable; +import me.skymc.taboolib.listener.*; import me.skymc.taboolib.message.ChatCatcher; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.mysql.protect.MySQLConnection; +import me.skymc.taboolib.nms.item.DabItemUtils; +import me.skymc.taboolib.other.NumberUtils; +import me.skymc.taboolib.permission.PermissionUtils; +import me.skymc.taboolib.playerdata.DataUtils; import me.skymc.taboolib.sign.SignUtils; import me.skymc.taboolib.skript.SkriptHandler; import me.skymc.taboolib.string.StringUtils; @@ -46,11 +36,16 @@ import me.skymc.taboolib.update.UpdateTask; import me.skymc.tlm.TLM; import me.skymc.tlm.command.TLMCommands; import me.skymc.tlm.module.TabooLibraryModule; -import me.skymc.taboolib.nms.item.DabItemUtils; -import me.skymc.taboolib.other.NumberUtils; -import me.skymc.taboolib.permission.PermissionUtils; -import me.skymc.taboolib.playerdata.DataUtils; import net.milkbowl.vault.economy.Economy; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; + +import java.io.File; +import java.util.Random; @SuppressWarnings("deprecation") public class Main extends JavaPlugin implements Listener { @@ -199,7 +194,7 @@ public class Main extends JavaPlugin implements Listener { MsgUtils.send("§7游戏版本: §f" + TabooLib.getVerint()); // 文件保存 - Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> DataUtils.saveAllCaches(), 20, 20 * 120); + Bukkit.getScheduler().runTaskTimerAsynchronously(this, DataUtils::saveAllCaches, 20, 20 * 120); Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> PlayerDataManager.saveAllCaches(true, false), 20, 20 * 60); // 插件联动 @@ -321,8 +316,8 @@ public class Main extends JavaPlugin implements Listener { getServer().getPluginManager().registerEvents(new ListenerNetWork(), this); } } - - public static enum StorageType { - LOCAL, SQL; + + public enum StorageType { + LOCAL, SQL } } diff --git a/src/main/java/me/skymc/taboolib/TabooLib.java b/src/main/java/me/skymc/taboolib/TabooLib.java index 004bda3..d218a54 100644 --- a/src/main/java/me/skymc/taboolib/TabooLib.java +++ b/src/main/java/me/skymc/taboolib/TabooLib.java @@ -1,13 +1,11 @@ package me.skymc.taboolib; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.event.Listener; -import org.bukkit.plugin.Plugin; - import me.skymc.taboolib.playerdata.DataUtils; import net.md_5.bungee.api.ChatColor; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; + +import java.util.UUID; public class TabooLib { diff --git a/src/main/java/me/skymc/taboolib/anvil/AnvilContainerAPI.java b/src/main/java/me/skymc/taboolib/anvil/AnvilContainerAPI.java index 8eb4e4e..dc1fc87 100644 --- a/src/main/java/me/skymc/taboolib/anvil/AnvilContainerAPI.java +++ b/src/main/java/me/skymc/taboolib/anvil/AnvilContainerAPI.java @@ -1,9 +1,6 @@ package me.skymc.taboolib.anvil; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - +import me.skymc.taboolib.anvil.versions.AnvilContainer_V1_9_4; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Sound; @@ -18,8 +15,9 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import me.skymc.taboolib.anvil.versions.AnvilContainer_V1_9_4; -import me.skymc.taboolib.methods.MethodsUtils; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; public class AnvilContainerAPI implements Listener{ diff --git a/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_11_R1.java b/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_11_R1.java index 3355628..b9c1b08 100644 --- a/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_11_R1.java +++ b/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_11_R1.java @@ -1,16 +1,9 @@ package me.skymc.taboolib.anvil.versions; +import net.minecraft.server.v1_11_R1.*; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import me.skymc.taboolib.methods.MethodsUtils; -import net.minecraft.server.v1_11_R1.BlockPosition; -import net.minecraft.server.v1_11_R1.ChatMessage; -import net.minecraft.server.v1_11_R1.ContainerAnvil; -import net.minecraft.server.v1_11_R1.EntityHuman; -import net.minecraft.server.v1_11_R1.EntityPlayer; -import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow; - public class AnvilContainer_V1_11_R1 extends ContainerAnvil { public AnvilContainer_V1_11_R1(EntityHuman player) @@ -31,7 +24,7 @@ public class AnvilContainer_V1_11_R1 extends ContainerAnvil { EntityPlayer player = ((CraftPlayer)p).getHandle(); AnvilContainer_V1_11_R1 container = new AnvilContainer_V1_11_R1(player); int c = player.nextContainerCounter(); - player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage("Repairing", new Object[0]), 0)); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage("Repairing"), 0)); player.activeContainer = container; player.activeContainer.windowId = c; player.activeContainer.addSlotListener(player); diff --git a/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_8_R3.java b/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_8_R3.java index 399bf61..196ff3b 100644 --- a/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_8_R3.java +++ b/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_8_R3.java @@ -1,16 +1,9 @@ package me.skymc.taboolib.anvil.versions; +import net.minecraft.server.v1_8_R3.*; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; -import me.skymc.taboolib.methods.MethodsUtils; -import net.minecraft.server.v1_8_R3.BlockPosition; -import net.minecraft.server.v1_8_R3.ChatMessage; -import net.minecraft.server.v1_8_R3.ContainerAnvil; -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.EntityPlayer; -import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow; - public class AnvilContainer_V1_8_R3 extends ContainerAnvil { public AnvilContainer_V1_8_R3(EntityHuman player) @@ -31,7 +24,7 @@ public class AnvilContainer_V1_8_R3 extends ContainerAnvil { EntityPlayer player = ((CraftPlayer)p).getHandle(); AnvilContainer_V1_8_R3 container = new AnvilContainer_V1_8_R3(player); int c = player.nextContainerCounter(); - player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage("Repairing", new Object[0]), 0)); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage("Repairing"), 0)); player.activeContainer = container; player.activeContainer.windowId = c; player.activeContainer.addSlotListener(player); diff --git a/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_9_4.java b/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_9_4.java index bd625fa..6c0a1c0 100644 --- a/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_9_4.java +++ b/src/main/java/me/skymc/taboolib/anvil/versions/AnvilContainer_V1_9_4.java @@ -1,16 +1,9 @@ package me.skymc.taboolib.anvil.versions; +import net.minecraft.server.v1_9_R2.*; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import me.skymc.taboolib.methods.MethodsUtils; -import net.minecraft.server.v1_9_R2.BlockPosition; -import net.minecraft.server.v1_9_R2.ChatMessage; -import net.minecraft.server.v1_9_R2.ContainerAnvil; -import net.minecraft.server.v1_9_R2.EntityHuman; -import net.minecraft.server.v1_9_R2.EntityPlayer; -import net.minecraft.server.v1_9_R2.PacketPlayOutOpenWindow; - public class AnvilContainer_V1_9_4 extends ContainerAnvil { public AnvilContainer_V1_9_4(EntityHuman player) @@ -31,7 +24,7 @@ public class AnvilContainer_V1_9_4 extends ContainerAnvil { EntityPlayer player = ((CraftPlayer)p).getHandle(); AnvilContainer_V1_9_4 container = new AnvilContainer_V1_9_4(player); int c = player.nextContainerCounter(); - player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage("Repairing", new Object[0]), 0)); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage("Repairing"), 0)); player.activeContainer = container; player.activeContainer.windowId = c; player.activeContainer.addSlotListener(player); diff --git a/src/main/java/me/skymc/taboolib/bstats/Metrics.java b/src/main/java/me/skymc/taboolib/bstats/Metrics.java index fe6cb02..c5067ed 100644 --- a/src/main/java/me/skymc/taboolib/bstats/Metrics.java +++ b/src/main/java/me/skymc/taboolib/bstats/Metrics.java @@ -17,13 +17,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; -import java.util.UUID; +import java.util.*; import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.zip.GZIPOutputStream; @@ -153,12 +147,7 @@ public class Metrics { } // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - submitData(); - } - }); + Bukkit.getScheduler().runTask(plugin, () -> submitData()); } }, 1000*60*5, 1000*60*30); // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start @@ -263,17 +252,14 @@ public class Metrics { data.put("plugins", pluginData); // Create a new thread for the connection to the bStats server - new Thread(new Runnable() { - @Override - public void run() { - try { - // Send the data - sendData(data); - } catch (Exception e) { - // Something went wrong! :( - if (logFailedRequests) { - plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); - } + new Thread(() -> { + try { + // Send the data + sendData(data); + } catch (Exception e) { + // Something went wrong! :( + if (logFailedRequests) { + plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); } } }).start(); diff --git a/src/main/java/me/skymc/taboolib/commands/MainCommands.java b/src/main/java/me/skymc/taboolib/commands/MainCommands.java index 724d10d..b6765c0 100644 --- a/src/main/java/me/skymc/taboolib/commands/MainCommands.java +++ b/src/main/java/me/skymc/taboolib/commands/MainCommands.java @@ -1,38 +1,15 @@ package me.skymc.taboolib.commands; -import java.util.HashMap; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import me.skymc.taboolib.Main; -import me.skymc.taboolib.TabooLib; -import me.skymc.taboolib.commands.sub.AttributesCommand; -import me.skymc.taboolib.commands.sub.EnchantCommand; -import me.skymc.taboolib.commands.sub.FlagCommand; -import me.skymc.taboolib.commands.sub.HelpCommand; -import me.skymc.taboolib.commands.sub.ImportCommand; -import me.skymc.taboolib.commands.sub.InfoCommand; -import me.skymc.taboolib.commands.sub.ItemCommand; -import me.skymc.taboolib.commands.sub.PotionCommand; -import me.skymc.taboolib.commands.sub.SaveCommand; -import me.skymc.taboolib.commands.sub.SlotCommand; -import me.skymc.taboolib.commands.sub.TagDeleteCommand; -import me.skymc.taboolib.commands.sub.TagPrefixCommand; -import me.skymc.taboolib.commands.sub.TagSuffixCommand; -import me.skymc.taboolib.commands.sub.VariableGetCommand; -import me.skymc.taboolib.commands.sub.VariableSetCommand; +import me.skymc.taboolib.commands.sub.*; import me.skymc.taboolib.commands.sub.cycle.CycleCommand; import me.skymc.taboolib.commands.sub.itemlist.ItemListCommand; import me.skymc.taboolib.commands.sub.shell.ShellCommand; import me.skymc.taboolib.commands.sub.sounds.SoundsCommand; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.message.MsgUtils; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; public class MainCommands implements CommandExecutor{ diff --git a/src/main/java/me/skymc/taboolib/commands/SubCommand.java b/src/main/java/me/skymc/taboolib/commands/SubCommand.java index 0060a59..37dea74 100644 --- a/src/main/java/me/skymc/taboolib/commands/SubCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/SubCommand.java @@ -28,7 +28,7 @@ public abstract class SubCommand { } public String getArgs(int size) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = size ; i < args.length ; i++) { sb.append(args[i]); sb.append(" "); diff --git a/src/main/java/me/skymc/taboolib/commands/SubCommandExecutor.java b/src/main/java/me/skymc/taboolib/commands/SubCommandExecutor.java index 97ff234..2633b0a 100644 --- a/src/main/java/me/skymc/taboolib/commands/SubCommandExecutor.java +++ b/src/main/java/me/skymc/taboolib/commands/SubCommandExecutor.java @@ -3,8 +3,8 @@ package me.skymc.taboolib.commands; import org.bukkit.command.CommandSender; @Deprecated -public abstract interface SubCommandExecutor { - - public abstract boolean command(CommandSender sender, String[] args); +public interface SubCommandExecutor { + + boolean command(CommandSender sender, String[] args); } diff --git a/src/main/java/me/skymc/taboolib/commands/sub/AttributesCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/AttributesCommand.java index 4fd0452..04fbb24 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/AttributesCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/AttributesCommand.java @@ -1,13 +1,11 @@ package me.skymc.taboolib.commands.sub; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFlag; - import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.jsonformatter.JSONFormatter; import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class AttributesCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java index e877de1..e5ac754 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java @@ -1,19 +1,17 @@ package me.skymc.taboolib.commands.sub; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map.Entry; - -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFlag; - import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.jsonformatter.JSONFormatter; import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map.Entry; public class HelpCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/InfoCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/InfoCommand.java index 8252fc7..5defc7b 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/InfoCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/InfoCommand.java @@ -1,11 +1,5 @@ package me.skymc.taboolib.commands.sub; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFlag; - -import me.skymc.taboolib.Main; import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.itemnbtapi.NBTItem; @@ -14,6 +8,9 @@ import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.hover.ShowItemEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; import me.skymc.taboolib.message.MsgUtils; +import org.bukkit.Material; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class InfoCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/SlotCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/SlotCommand.java index c456e93..5c4daba 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/SlotCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/SlotCommand.java @@ -1,13 +1,11 @@ package me.skymc.taboolib.commands.sub; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFlag; - import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.jsonformatter.JSONFormatter; import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class SlotCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java index 36df869..dc09dfc 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java @@ -1,13 +1,11 @@ package me.skymc.taboolib.commands.sub; -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; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java index bebea7f..d085c9e 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java @@ -1,12 +1,8 @@ package me.skymc.taboolib.commands.sub.cycle; -import java.io.File; - -import org.bukkit.command.CommandSender; - import me.skymc.taboolib.commands.SubCommand; -import me.skymc.taboolib.javashell.JavaShell; import me.skymc.taboolib.message.MsgUtils; +import org.bukkit.command.CommandSender; public class CycleCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java index a653e90..2feb7d1 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java @@ -1,20 +1,13 @@ package me.skymc.taboolib.commands.sub.cycle; -import java.util.concurrent.TimeUnit; - -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.other.DateUtils; 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.command.CommandSender; + +import java.util.concurrent.TimeUnit; public class CycleInfoCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java index 4fcb79b..1bc2ae7 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java @@ -1,19 +1,13 @@ package me.skymc.taboolib.commands.sub.cycle; -import java.io.File; -import java.util.concurrent.TimeUnit; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import me.skymc.taboolib.commands.SubCommand; -import me.skymc.taboolib.javashell.JavaShell; import me.skymc.taboolib.jsonformatter.JSONFormatter; import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; -import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.timecycle.TimeCycle; import me.skymc.taboolib.timecycle.TimeCycleManager; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class CycleListCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java index 444a362..86a6c09 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java @@ -1,17 +1,15 @@ package me.skymc.taboolib.commands.sub.cycle; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.scheduler.BukkitRunnable; - import me.skymc.taboolib.Main; import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.database.GlobalDataManager; 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 CycleUpdateCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java b/src/main/java/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java index be10817..ffc48ec 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java @@ -1,11 +1,7 @@ package me.skymc.taboolib.commands.sub.itemlist.listener; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; - +import me.skymc.taboolib.inventory.InventoryUtil; +import me.skymc.taboolib.inventory.ItemUtils; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -17,8 +13,10 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import me.skymc.taboolib.inventory.InventoryUtil; -import me.skymc.taboolib.inventory.ItemUtils; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; /** * @author sky @@ -26,49 +24,27 @@ import me.skymc.taboolib.inventory.ItemUtils; */ public class ItemLibraryPatch implements Listener { - @EventHandler - public void inventoryClick(InventoryClickEvent e) { - if (e.getInventory().getHolder() instanceof ItemLibraryHolder) { - e.setCancelled(true); - - if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR) || e.getRawSlot() >= e.getInventory().getSize()) { - return; - } - - if (e.getRawSlot() == 47) { - openInventory((Player) e.getWhoClicked(), ((ItemLibraryHolder) e.getInventory().getHolder()).PAGE - 1); - } - else if (e.getRawSlot() == 51) { - openInventory((Player) e.getWhoClicked(), ((ItemLibraryHolder) e.getInventory().getHolder()).PAGE + 1); - } - else { - e.getWhoClicked().getInventory().addItem(ItemUtils.getCacheItem(((ItemLibraryHolder) e.getInventory().getHolder()).ITEMS_DATA.get(e.getRawSlot()))); - } - } - } - /** * 打开物品库界面 - * + * * @param player * @param page */ public static void openInventory(Player player, int page) { ItemLibraryHolder holder = new ItemLibraryHolder(page); Inventory inventory = Bukkit.createInventory(holder, 54, "物品库"); - + LinkedHashMap map = new LinkedHashMap<>(); map.putAll(ItemUtils.getItemCachesFinal()); map.putAll(ItemUtils.getItemCaches()); - + int loop = 0; - Iterator iterator = map.keySet().iterator(); - while (iterator.hasNext()) { - String name = iterator.next(); + for (String name : map.keySet()) { if (loop >= (page - 1) * 28) { if (loop < page * 28) { int slot = InventoryUtil.SLOT_OF_CENTENTS.get(loop - ((page - 1) * 28)); - ItemStack item = map.get(name).clone(); { + ItemStack item = map.get(name).clone(); + { ItemMeta meta = item.getItemMeta(); List lore = meta.hasLore() ? meta.getLore() : new ArrayList<>(); lore.add("§f"); @@ -79,14 +55,13 @@ public class ItemLibraryPatch implements Listener { inventory.setItem(slot, item); } holder.ITEMS_DATA.put(slot, name); - } - else { + } else { break; } } loop++; } - + if (page > 1) { inventory.setItem(47, ItemUtils.setName(new ItemStack(Material.ARROW), "§f上一页")); } @@ -95,6 +70,29 @@ public class ItemLibraryPatch implements Listener { } player.openInventory(inventory); } + + @EventHandler + public void inventoryClick(InventoryClickEvent e) { + if (e.getInventory().getHolder() instanceof ItemLibraryHolder) { + e.setCancelled(true); + + if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR) || e.getRawSlot() >= e.getInventory().getSize()) { + return; + } + + switch (e.getRawSlot()) { + case 47: + openInventory((Player) e.getWhoClicked(), ((ItemLibraryHolder) e.getInventory().getHolder()).PAGE - 1); + break; + case 51: + openInventory((Player) e.getWhoClicked(), ((ItemLibraryHolder) e.getInventory().getHolder()).PAGE + 1); + break; + default: + e.getWhoClicked().getInventory().addItem(ItemUtils.getCacheItem(((ItemLibraryHolder) e.getInventory().getHolder()).ITEMS_DATA.get(e.getRawSlot()))); + break; + } + } + } public static class ItemLibraryHolder implements InventoryHolder { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/shell/ShellCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/shell/ShellCommand.java index 8e6c8b5..3690404 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/shell/ShellCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/shell/ShellCommand.java @@ -1,12 +1,8 @@ package me.skymc.taboolib.commands.sub.shell; -import java.io.File; - -import org.bukkit.command.CommandSender; - import me.skymc.taboolib.commands.SubCommand; -import me.skymc.taboolib.javashell.JavaShell; import me.skymc.taboolib.message.MsgUtils; +import org.bukkit.command.CommandSender; public class ShellCommand extends SubCommand { diff --git a/src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java b/src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java index 2268189..55b043e 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java @@ -1,12 +1,7 @@ package me.skymc.taboolib.commands.sub.sounds.listener; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; - +import me.skymc.taboolib.inventory.InventoryUtil; +import me.skymc.taboolib.inventory.ItemUtils; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Sound; @@ -19,8 +14,8 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import me.skymc.taboolib.inventory.InventoryUtil; -import me.skymc.taboolib.inventory.ItemUtils; +import java.util.Arrays; +import java.util.HashMap; /** * @author sky @@ -28,51 +23,23 @@ import me.skymc.taboolib.inventory.ItemUtils; */ public class SoundsLibraryPatch implements Listener { - @EventHandler - public void inventoryClick(InventoryClickEvent e) { - if (e.getInventory().getHolder() instanceof SoundLibraryHolder) { - e.setCancelled(true); - - if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR) || e.getRawSlot() >= e.getInventory().getSize()) { - return; - } - - if (e.getRawSlot() == 47) { - openInventory((Player) e.getWhoClicked(), ((SoundLibraryHolder) e.getInventory().getHolder()).PAGE - 1); - } - else if (e.getRawSlot() == 51) { - openInventory((Player) e.getWhoClicked(), ((SoundLibraryHolder) e.getInventory().getHolder()).PAGE + 1); - } - else { - Sound sound = ((SoundLibraryHolder) e.getInventory().getHolder()).SOUNDS_DATA.get(e.getRawSlot()); - if (e.getClick().isLeftClick()) { - ((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 1f); - } - else { - ((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 2f); - } - } - } - } - /** * 打开物品库界面 - * + * * @param player * @param page */ public static void openInventory(Player player, int page) { SoundLibraryHolder holder = new SoundLibraryHolder(page); Inventory inventory = Bukkit.createInventory(holder, 54, "音效库 " + page); - + int loop = 0; - Iterator iterator = Arrays.asList(Sound.values()).iterator(); - while (iterator.hasNext()) { - Sound sound = iterator.next(); + for (Sound sound : Arrays.asList(Sound.values())) { if (loop >= (page - 1) * 28) { if (loop < page * 28) { int slot = InventoryUtil.SLOT_OF_CENTENTS.get(loop - ((page - 1) * 28)); - ItemStack item = new ItemStack(Material.MAP); { + ItemStack item = new ItemStack(Material.MAP); + { ItemMeta meta = item.getItemMeta(); meta.setDisplayName("§f" + sound.name()); meta.setLore(Arrays.asList("", "§f左键: §71 音调", "§f左键: §72 音调")); @@ -80,14 +47,13 @@ public class SoundsLibraryPatch implements Listener { inventory.setItem(slot, item); } holder.SOUNDS_DATA.put(slot, sound); - } - else { + } else { break; } } loop++; } - + if (page > 1) { inventory.setItem(47, ItemUtils.setName(new ItemStack(Material.ARROW), "§f上一页")); } @@ -96,6 +62,34 @@ public class SoundsLibraryPatch implements Listener { } player.openInventory(inventory); } + + @EventHandler + public void inventoryClick(InventoryClickEvent e) { + if (e.getInventory().getHolder() instanceof SoundLibraryHolder) { + e.setCancelled(true); + + if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR) || e.getRawSlot() >= e.getInventory().getSize()) { + return; + } + + switch (e.getRawSlot()) { + case 47: + openInventory((Player) e.getWhoClicked(), ((SoundLibraryHolder) e.getInventory().getHolder()).PAGE - 1); + break; + case 51: + openInventory((Player) e.getWhoClicked(), ((SoundLibraryHolder) e.getInventory().getHolder()).PAGE + 1); + break; + default: + Sound sound = ((SoundLibraryHolder) e.getInventory().getHolder()).SOUNDS_DATA.get(e.getRawSlot()); + if (e.getClick().isLeftClick()) { + ((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 1f); + } else { + ((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 2f); + } + break; + } + } + } public static class SoundLibraryHolder implements InventoryHolder { diff --git a/src/main/java/me/skymc/taboolib/cooldown/CooldownPack.java b/src/main/java/me/skymc/taboolib/cooldown/CooldownPack.java index 363f446..8066e7e 100644 --- a/src/main/java/me/skymc/taboolib/cooldown/CooldownPack.java +++ b/src/main/java/me/skymc/taboolib/cooldown/CooldownPack.java @@ -2,8 +2,6 @@ package me.skymc.taboolib.cooldown; import java.util.HashMap; -import org.bukkit.plugin.Plugin; - @Deprecated public class CooldownPack { diff --git a/src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java b/src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java index e08ac1b..102506a 100644 --- a/src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java +++ b/src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java @@ -1,19 +1,13 @@ package me.skymc.taboolib.cooldown; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; - +import me.skymc.taboolib.message.MsgUtils; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.plugin.Plugin; -import me.skymc.taboolib.message.MsgUtils; +import java.util.concurrent.ConcurrentHashMap; @Deprecated public class CooldownUtils implements Listener { diff --git a/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownPack2.java b/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownPack2.java index b5d8ed5..3a54f60 100644 --- a/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownPack2.java +++ b/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownPack2.java @@ -2,9 +2,6 @@ package me.skymc.taboolib.cooldown.seconds; import java.util.HashMap; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; - public class CooldownPack2 { private String plugin; 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 589aadf..a467759 100644 --- a/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownUtils2.java +++ b/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownUtils2.java @@ -1,19 +1,12 @@ package me.skymc.taboolib.cooldown.seconds; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; - import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.plugin.Plugin; -import me.skymc.taboolib.message.MsgUtils; +import java.util.concurrent.ConcurrentHashMap; public class CooldownUtils2 implements Listener { diff --git a/src/main/java/me/skymc/taboolib/csvutils/CsvReader.java b/src/main/java/me/skymc/taboolib/csvutils/CsvReader.java index f6d4161..b40f5cd 100644 --- a/src/main/java/me/skymc/taboolib/csvutils/CsvReader.java +++ b/src/main/java/me/skymc/taboolib/csvutils/CsvReader.java @@ -1,9 +1,9 @@ package me.skymc.taboolib.csvutils; -import java.nio.charset.*; -import java.text.*; import java.io.*; -import java.util.*; +import java.nio.charset.Charset; +import java.text.NumberFormat; +import java.util.HashMap; public class CsvReader { @@ -503,7 +503,6 @@ public class CsvReader this.close(); throw new IOException("Maximum column length of 100,000 exceeded in column " + NumberFormat.getIntegerInstance().format(this.columnsCount) + " in record " + NumberFormat.getIntegerInstance().format(this.currentRecord) + ". Set the SafetySwitch property to false" + " if you're expecting column lengths greater than 100,000 characters to" + " avoid this error."); } - continue; } } while (this.hasMoreData && this.startedColumn); } @@ -714,7 +713,6 @@ public class CsvReader this.close(); throw new IOException("Maximum column length of 100,000 exceeded in column " + NumberFormat.getIntegerInstance().format(this.columnsCount) + " in record " + NumberFormat.getIntegerInstance().format(this.currentRecord) + ". Set the SafetySwitch property to false" + " if you're expecting column lengths greater than 100,000 characters to" + " avoid this error."); } - continue; } } while (this.hasMoreData && this.startedColumn); } @@ -880,8 +878,8 @@ public class CsvReader } this.dataBuffer.ColumnStart = this.dataBuffer.Position + 1; } - - public void endRecord() throws IOException { + + public void endRecord() { this.hasReadNextLine = true; ++this.currentRecord; } @@ -960,8 +958,8 @@ public class CsvReader if (this.initialized) { this.inputStream.close(); } + } catch (Exception ignored) { } - catch (Exception ex) {} this.inputStream = null; this.closed = true; } diff --git a/src/main/java/me/skymc/taboolib/csvutils/CsvWriter.java b/src/main/java/me/skymc/taboolib/csvutils/CsvWriter.java index 3fa4a9e..7df96a9 100644 --- a/src/main/java/me/skymc/taboolib/csvutils/CsvWriter.java +++ b/src/main/java/me/skymc/taboolib/csvutils/CsvWriter.java @@ -1,7 +1,7 @@ package me.skymc.taboolib.csvutils; -import java.nio.charset.*; import java.io.*; +import java.nio.charset.Charset; public class CsvWriter { @@ -202,14 +202,22 @@ public class CsvWriter } this.firstColumn = true; } - - public void writeRecord(final String[] array, final boolean b) throws IOException { - if (array != null && array.length > 0) { - for (int i = 0; i < array.length; ++i) { - this.write(array[i], b); + + 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.substring(n, i)); + sb.append(s3); + n = i + length; } - this.endRecord(); + sb.append(s.substring(n)); + return sb.toString(); } + return s; } public void writeRecord(final String[] array) throws IOException { @@ -247,6 +255,25 @@ public class CsvWriter this.closed = true; } } + + public void writeRecord(final String[] array, final boolean b) throws IOException { + if (array != null && array.length > 0) { + for (String anArray : array) { + this.write(anArray, b); + } + this.endRecord(); + } + } + + private void checkClosed() throws IOException { + if (this.closed) { + throw new IOException("This instance of the CsvWriter class has already been closed."); + } + } + + protected void finalize() { + this.close(false); + } private void close(final boolean b) { if (!this.closed) { @@ -257,40 +284,13 @@ public class CsvWriter if (this.initialized) { this.outputStream.close(); } + } catch (Exception ignored) { } - catch (Exception ex) {} this.outputStream = null; this.closed = true; } } - private void checkClosed() throws IOException { - if (this.closed) { - throw new IOException("This instance of the CsvWriter class has already been closed."); - } - } - - protected void finalize() { - this.close(false); - } - - 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 StringBuffer sb = new StringBuffer(); - int n; - for (n = 0; i != -1; i = s.indexOf(s2, n)) { - sb.append(s.substring(n, i)); - sb.append(s3); - n = i + length; - } - sb.append(s.substring(n)); - return sb.toString(); - } - return s; - } - private class UserSettings { public char TextQualifier; diff --git a/src/main/java/me/skymc/taboolib/damage/DamageUtils.java b/src/main/java/me/skymc/taboolib/damage/DamageUtils.java index efb21c3..9a865dc 100644 --- a/src/main/java/me/skymc/taboolib/damage/DamageUtils.java +++ b/src/main/java/me/skymc/taboolib/damage/DamageUtils.java @@ -1,12 +1,11 @@ package me.skymc.taboolib.damage; -import java.lang.reflect.InvocationTargetException; - +import me.skymc.taboolib.TabooLib; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import me.skymc.taboolib.TabooLib; +import java.lang.reflect.InvocationTargetException; public class DamageUtils { @@ -31,7 +30,7 @@ public class DamageUtils { Object localObject1 = null; try { - localObject1 = paramLivingEntity1.getClass().getDeclaredMethod("getHandle", new Class[0]).invoke(paramLivingEntity1, new Object[0]); + localObject1 = paramLivingEntity1.getClass().getDeclaredMethod("getHandle", new Class[0]).invoke(paramLivingEntity1); } catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException localIllegalAccessException1) { @@ -41,7 +40,7 @@ public class DamageUtils { Object localObject2 = null; try { - localObject2 = paramLivingEntity2.getClass().getDeclaredMethod("getHandle", new Class[0]).invoke(paramLivingEntity2, new Object[0]); + localObject2 = paramLivingEntity2.getClass().getDeclaredMethod("getHandle", new Class[0]).invoke(paramLivingEntity2); } catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException localIllegalAccessException2) { @@ -51,14 +50,12 @@ public class DamageUtils { try { Class DamageSource = nmsClass("DamageSource"); - Object localObject3 = DamageSource.getDeclaredMethod("playerAttack", new Class[] { nmsClass("EntityHuman") }).invoke(DamageSource, new Object[] { localObject1 }); - - localObject2.getClass().getDeclaredMethod("damageEntity", new Class[] { DamageSource, Float.TYPE }).invoke(localObject2, new Object[] { localObject3, Float.valueOf((float) paramDouble) }); - } - catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException localIllegalAccessException3) + Object localObject3 = DamageSource.getDeclaredMethod("playerAttack", new Class[]{nmsClass("EntityHuman")}).invoke(DamageSource, localObject1); + + localObject2.getClass().getDeclaredMethod("damageEntity", new Class[]{DamageSource, Float.TYPE}).invoke(localObject2, localObject3, (float) paramDouble); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException ignored) { - return; - } + } } private static Class nmsClass(String paramString) diff --git a/src/main/java/me/skymc/taboolib/damage/GetKiller.java b/src/main/java/me/skymc/taboolib/damage/GetKiller.java index db78004..ca9b143 100644 --- a/src/main/java/me/skymc/taboolib/damage/GetKiller.java +++ b/src/main/java/me/skymc/taboolib/damage/GetKiller.java @@ -1,12 +1,9 @@ package me.skymc.taboolib.damage; -import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.entity.EntityDeathEvent; -import me.skymc.taboolib.methods.MethodsUtils; - public class GetKiller { public static Player get(EntityDeathEvent e) { diff --git a/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java b/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java index 905b731..e825d14 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 me.skymc.taboolib.Main; +import me.skymc.taboolib.Main.StorageType; +import me.skymc.taboolib.TabooLib; +import me.skymc.taboolib.message.MsgUtils; +import me.skymc.taboolib.playerdata.DataUtils; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.scheduler.BukkitRunnable; + import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; import java.util.concurrent.ConcurrentHashMap; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.scheduler.BukkitRunnable; - -import me.skymc.taboolib.Main; -import me.skymc.taboolib.TabooLib; -import me.skymc.taboolib.message.MsgUtils; -import me.skymc.taboolib.Main.StorageType; -import me.skymc.taboolib.playerdata.DataUtils; - public class GlobalDataManager { public static FileConfiguration data = DataUtils.addPluginData("TabooLibrary-Variable.yml", null); @@ -92,7 +90,7 @@ public class GlobalDataManager { */ public static boolean contains(String name) { if (Main.getStorageType() == StorageType.SQL) { - return getVariable(name, null) == null ? false : true; + return getVariable(name, null) != null; } else { return data.contains(name.replace(":", "-")); @@ -107,7 +105,7 @@ public class GlobalDataManager { */ public static boolean containsAsynchronous(String name) { if (Main.getStorageType() == StorageType.SQL) { - return getVariableAsynchronous(name, null) == null ? false : true; + return getVariableAsynchronous(name, null) != null; } else { return contains(name); @@ -316,10 +314,6 @@ public class GlobalDataManager { @Override public void run() { - /** - * 根据正序排列获取所有变量 - * 新的变量会覆盖旧的变量 - */ LinkedList> list = Main.getConnection().getValues(Main.getTablePrefix() + "_plugindata", "id", -1, false, "name", "variable", "upgrade"); // 循环变量 for (HashMap value : list) { diff --git a/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java b/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java index 11ec5f0..8355004 100644 --- a/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java +++ b/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java @@ -1,9 +1,12 @@ package me.skymc.taboolib.database; -import java.io.File; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - +import me.skymc.taboolib.Main; +import me.skymc.taboolib.Main.StorageType; +import me.skymc.taboolib.events.PlayerLoadedEvent; +import me.skymc.taboolib.exception.PlayerOfflineException; +import me.skymc.taboolib.fileutils.ConfigUtils; +import me.skymc.taboolib.fileutils.FileUtils; +import me.skymc.taboolib.message.MsgUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.configuration.file.FileConfiguration; @@ -15,20 +18,16 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scheduler.BukkitRunnable; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.Main.StorageType; -import me.skymc.taboolib.events.PlayerLoadedEvent; -import me.skymc.taboolib.exception.PlayerOfflineException; -import me.skymc.taboolib.fileutils.ConfigUtils; -import me.skymc.taboolib.fileutils.FileUtils; -import me.skymc.taboolib.message.MsgUtils; +import java.io.File; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; public class PlayerDataManager implements Listener { private static final ConcurrentHashMap PLAYER_DATA = new ConcurrentHashMap<>(); - - public static enum UsernameType { - UUID, USERNAME; + + public enum UsernameType { + UUID, USERNAME } /** diff --git a/src/main/java/me/skymc/taboolib/display/ActionUtils.java b/src/main/java/me/skymc/taboolib/display/ActionUtils.java index 218bf4c..92a8d03 100644 --- a/src/main/java/me/skymc/taboolib/display/ActionUtils.java +++ b/src/main/java/me/skymc/taboolib/display/ActionUtils.java @@ -1,10 +1,10 @@ package me.skymc.taboolib.display; -import java.lang.reflect.Constructor; +import me.skymc.taboolib.TabooLib; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import me.skymc.taboolib.TabooLib; +import java.lang.reflect.Constructor; public class ActionUtils { @@ -12,9 +12,9 @@ public class ActionUtils { { try { - Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player, new Object[0]); + Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player); Object playerConnection = handle.getClass().getField("playerConnection").get(handle); - playerConnection.getClass().getMethod("sendPacket", new Class[] { getNMSClass("Packet") }).invoke(playerConnection, new Object[] { packet }); + playerConnection.getClass().getMethod("sendPacket", new Class[]{getNMSClass("Packet")}).invoke(playerConnection, packet); } catch (Exception ex) { @@ -43,7 +43,7 @@ public class ActionUtils { } try { - Object ab = getNMSClass("ChatComponentText").getConstructor(new Class[] { String.class }).newInstance(new Object[] { msg }); + Object ab = getNMSClass("ChatComponentText").getConstructor(new Class[]{String.class}).newInstance(msg); Constructor ac = null; Object abPacket = null; // 如果版本大于 1.11.0 @@ -53,7 +53,7 @@ public class ActionUtils { abPacket = ac.newInstance(ab, chatMessageType.getMethod("a", Byte.TYPE).invoke(null, (byte) 2)); } else { ac = getNMSClass("PacketPlayOutChat").getConstructor(getNMSClass("IChatBaseComponent"), Byte.TYPE); - abPacket = ac.newInstance(ab, Byte.valueOf((byte) 2)); + abPacket = ac.newInstance(ab, (byte) 2); } sendPacket(p, abPacket); } diff --git a/src/main/java/me/skymc/taboolib/display/TitleUtils.java b/src/main/java/me/skymc/taboolib/display/TitleUtils.java index abded02..296686c 100644 --- a/src/main/java/me/skymc/taboolib/display/TitleUtils.java +++ b/src/main/java/me/skymc/taboolib/display/TitleUtils.java @@ -1,10 +1,8 @@ package me.skymc.taboolib.display; -import java.lang.reflect.Constructor; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import me.skymc.taboolib.methods.MethodsUtils; +import java.lang.reflect.Constructor; public class TitleUtils { @@ -12,9 +10,9 @@ public class TitleUtils { { try { - Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player, new Object[0]); + Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player); Object playerConnection = handle.getClass().getField("playerConnection").get(handle); - playerConnection.getClass().getMethod("sendPacket", new Class[] { getNMSClass("Packet") }).invoke(playerConnection, new Object[] { packet }); + playerConnection.getClass().getMethod("sendPacket", new Class[]{getNMSClass("Packet")}).invoke(playerConnection, packet); } catch (Exception ex) { @@ -53,29 +51,29 @@ public class TitleUtils { if (title != null) { Object e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null); - Object chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + title + "\"}" }); - Constructor subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE }); - Object titlePacket = subtitleConstructor.newInstance(new Object[] { e, chatTitle, Integer.valueOf(fadeint), Integer.valueOf(stayt), Integer.valueOf(fadeoutt) }); + Object chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + title + "\"}"); + Constructor subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE); + Object titlePacket = subtitleConstructor.newInstance(e, chatTitle, fadeint, stayt, fadeoutt); sendPacket(p, titlePacket); e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get(null); - chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + title + "\"}" }); - subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent") }); - titlePacket = subtitleConstructor.newInstance(new Object[] { e, chatTitle }); + chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + title + "\"}"); + subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent")); + titlePacket = subtitleConstructor.newInstance(e, chatTitle); sendPacket(p, titlePacket); } if (subtitle != null) { Object e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null); - Object chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + title + "\"}" }); - Constructor subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE }); - Object subtitlePacket = subtitleConstructor.newInstance(new Object[] { e, chatSubtitle, Integer.valueOf(fadeinst), Integer.valueOf(stayst), Integer.valueOf(fadeoutst) }); + Object chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + title + "\"}"); + Constructor subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE); + Object subtitlePacket = subtitleConstructor.newInstance(e, chatSubtitle, fadeinst, stayst, fadeoutst); sendPacket(p, subtitlePacket); e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get(null); - chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + subtitle + "\"}" }); - subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE }); - subtitlePacket = subtitleConstructor.newInstance(new Object[] { e, chatSubtitle, Integer.valueOf(fadeinst), Integer.valueOf(stayst), Integer.valueOf(fadeoutst) }); + chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + subtitle + "\"}"); + subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE); + subtitlePacket = subtitleConstructor.newInstance(e, chatSubtitle, fadeinst, stayst, fadeoutst); sendPacket(p, subtitlePacket); } } diff --git a/src/main/java/me/skymc/taboolib/entity/EntityTag.java b/src/main/java/me/skymc/taboolib/entity/EntityTag.java index 8d44ae9..7a2821e 100644 --- a/src/main/java/me/skymc/taboolib/entity/EntityTag.java +++ b/src/main/java/me/skymc/taboolib/entity/EntityTag.java @@ -1,14 +1,13 @@ package me.skymc.taboolib.entity; +import me.skymc.taboolib.Main; +import org.bukkit.entity.Entity; +import org.bukkit.scheduler.BukkitRunnable; + import java.util.List; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import org.bukkit.entity.Entity; -import org.bukkit.scheduler.BukkitRunnable; - -import me.skymc.taboolib.Main; - /** * 伪 - MetaData * @@ -67,8 +66,7 @@ public class EntityTag { * * @param key 键 * @param value 值 - * @param entity 实体 - */ + */ public void set(String key, Object value, Entity... entities) { for (Entity entity : entities) set(key, value, entity); } @@ -78,8 +76,7 @@ public class EntityTag { * * @param key 键 * @param value 值 - * @param entity 实体 - */ + */ public void set(String key, Object value, List entities) { for (Entity entity : entities) set(key, value, entity); } @@ -138,11 +135,8 @@ public class EntityTag { * @return boolean */ public boolean hasKey(String key, Entity entity) { - if (contains(entity)) { - return entityData.get(entity.getUniqueId()).containsKey(key); - } - return false; - } + return contains(entity) && entityData.get(entity.getUniqueId()).containsKey(key); + } /** * 获取数据 @@ -211,12 +205,9 @@ public class EntityTag { * @return boolean */ public boolean getBoolean(String key, Entity entity) { - Object object = get(key, entity); - if (object != null) { - return (boolean) object; - } - return false; - } + Object object = get(key, entity); + return object != null && (boolean) object; + } /** * 获取数据 diff --git a/src/main/java/me/skymc/taboolib/events/DefaultEvent.java b/src/main/java/me/skymc/taboolib/events/DefaultEvent.java index afef94e..171760a 100644 --- a/src/main/java/me/skymc/taboolib/events/DefaultEvent.java +++ b/src/main/java/me/skymc/taboolib/events/DefaultEvent.java @@ -1,7 +1,6 @@ package me.skymc.taboolib.events; import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; diff --git a/src/main/java/me/skymc/taboolib/events/PlayerLoadedEvent.java b/src/main/java/me/skymc/taboolib/events/PlayerLoadedEvent.java index 4255a28..5a4f0a8 100644 --- a/src/main/java/me/skymc/taboolib/events/PlayerLoadedEvent.java +++ b/src/main/java/me/skymc/taboolib/events/PlayerLoadedEvent.java @@ -1,7 +1,6 @@ package me.skymc.taboolib.events; import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; diff --git a/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java b/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java index 9da4e34..0c1490f 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java @@ -1,21 +1,13 @@ package me.skymc.taboolib.fileutils; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStreamReader; -import java.io.StringReader; -import java.util.HashMap; - +import com.google.common.base.Charsets; +import me.skymc.taboolib.message.MsgUtils; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; -import com.google.common.base.Charsets; - -import me.skymc.taboolib.Main; -import me.skymc.taboolib.message.MsgUtils; +import java.io.*; public class ConfigUtils { @@ -47,8 +39,6 @@ public class ConfigUtils { /** * 以 UTF-8 的格式载入配置文件 * - * @param main - * @param filename * @return */ public static FileConfiguration load(Plugin plugin, File file) { diff --git a/src/main/java/me/skymc/taboolib/fileutils/CopyUtils.java b/src/main/java/me/skymc/taboolib/fileutils/CopyUtils.java index 68cf2d2..dbfaa3a 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/CopyUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/CopyUtils.java @@ -7,8 +7,6 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; -import me.skymc.taboolib.methods.MethodsUtils; - @Deprecated public class CopyUtils { diff --git a/src/main/java/me/skymc/taboolib/fileutils/EncodeUtils.java b/src/main/java/me/skymc/taboolib/fileutils/EncodeUtils.java index 96a2533..e0c43b7 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/EncodeUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/EncodeUtils.java @@ -1,13 +1,6 @@ package me.skymc.taboolib.fileutils; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FilenameFilter; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; +import java.io.*; import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; @@ -40,7 +33,6 @@ public class EncodeUtils { /** * 把指定文件或目录转换成指定的编码 * - * @param file 要转换的文件或目录 * @param fromCharsetName 源文件的编码 * @param toCharsetName 转换的编码 * @param filter 文件名过滤器 diff --git a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java index 2480c5d..e8fa55c 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java @@ -1,13 +1,12 @@ package me.skymc.taboolib.fileutils; +import me.skymc.taboolib.message.MsgUtils; + import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.nio.channels.FileChannel; -import java.util.List; - -import me.skymc.taboolib.message.MsgUtils; public class FileUtils { @@ -17,9 +16,9 @@ public class FileUtils { URL url = new URL("http://1212.ip138.com/ic.asp"); URLConnection con = url.openConnection(); ins = con.getInputStream(); - InputStreamReader isReader = new InputStreamReader(ins, "GB2312"); - BufferedReader bReader = new BufferedReader(isReader); - StringBuffer webContent = new StringBuffer(); + InputStreamReader isReader = new InputStreamReader(ins, "GB2312"); + BufferedReader bReader = new BufferedReader(isReader); + StringBuilder webContent = new StringBuilder(); String str = null; while ((str = bReader.readLine()) != null) { webContent.append(str); @@ -83,12 +82,12 @@ public class FileUtils { } if (file.isFile()) { file.delete(); - return; - } - File[] files = file.listFiles(); - for (int i = 0; i < files.length; i++) { - deleteAllFile(files[i]); - } + return; + } + File[] files = file.listFiles(); + for (File file1 : files) { + deleteAllFile(file1); + } file.delete(); } diff --git a/src/main/java/me/skymc/taboolib/fileutils/LogUtils.java b/src/main/java/me/skymc/taboolib/fileutils/LogUtils.java index 91e9bd1..07d57e1 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/LogUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/LogUtils.java @@ -1,15 +1,13 @@ package me.skymc.taboolib.fileutils; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.other.DateUtils; +import org.bukkit.plugin.Plugin; + import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; -import org.bukkit.plugin.Plugin; - -import me.skymc.taboolib.Main; -import me.skymc.taboolib.methods.MethodsUtils; -import me.skymc.taboolib.other.DateUtils; - @Deprecated public class LogUtils { diff --git a/src/main/java/me/skymc/taboolib/inventory/DropUtils.java b/src/main/java/me/skymc/taboolib/inventory/DropUtils.java index 2f62d45..25aa4bb 100644 --- a/src/main/java/me/skymc/taboolib/inventory/DropUtils.java +++ b/src/main/java/me/skymc/taboolib/inventory/DropUtils.java @@ -1,16 +1,12 @@ package me.skymc.taboolib.inventory; -import java.util.Random; - +import me.skymc.taboolib.other.NumberUtils; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -import me.skymc.taboolib.other.NumberUtils; - public class DropUtils { public static Item drop(Player player, ItemStack itemStack, double bulletSpread, double radius) { diff --git a/src/main/java/me/skymc/taboolib/inventory/InventoryUtil.java b/src/main/java/me/skymc/taboolib/inventory/InventoryUtil.java index f6b83d9..f435c7c 100644 --- a/src/main/java/me/skymc/taboolib/inventory/InventoryUtil.java +++ b/src/main/java/me/skymc/taboolib/inventory/InventoryUtil.java @@ -1,15 +1,11 @@ package me.skymc.taboolib.inventory; -import java.util.Arrays; -import java.util.LinkedList; - -import org.bukkit.Bukkit; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import me.skymc.taboolib.methods.MethodsUtils; +import java.util.Arrays; +import java.util.LinkedList; public class InventoryUtil { @@ -62,27 +58,13 @@ public class InventoryUtil { for (int i = 0; i < player.getInventory().getSize() && remove; i++) { ItemStack _item = player.getInventory().getItem(i); if (_item != null && _item.isSimilar(item)) { - /** - * 如果循环到的物品数量 小于 需要的数量 - * 则 删除物品,减少需要的数量 - */ if (_item.getAmount() < requireAmount) { player.getInventory().setItem(i, null); requireAmount -= _item.getAmount(); - } - /** - * 如果循环到的物品数量 等于 需要的数量 - * 则 删除物品,直接结束 - */ - else if (_item.getAmount() == requireAmount) { + } else if (_item.getAmount() == requireAmount) { player.getInventory().setItem(i, null); return true; - } - /** - * 如果循环到的物品数量 大于 需要的数量 - * 则扣除 需要的数量 - */ - else { + } else { _item.setAmount(_item.getAmount() - requireAmount); return true; } @@ -101,11 +83,8 @@ public class InventoryUtil { } } } - if (inventoryAmount >= amount) { - return true; - } - return false; - } + return inventoryAmount >= amount; + } @Deprecated public static boolean takeItem2(Inventory inv, ItemStack takeitem, Integer amount) { diff --git a/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java b/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java index ea6a50a..299884f 100644 --- a/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java +++ b/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java @@ -1,14 +1,17 @@ package me.skymc.taboolib.inventory; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; - -import org.bukkit.Bukkit; +import lombok.Getter; +import me.clip.placeholderapi.PlaceholderAPI; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.TabooLib; +import me.skymc.taboolib.fileutils.ConfigUtils; +import me.skymc.taboolib.itemnbtapi.NBTItem; +import me.skymc.taboolib.itemnbtapi.NBTList; +import me.skymc.taboolib.itemnbtapi.NBTListCompound; +import me.skymc.taboolib.itemnbtapi.NBTType; +import me.skymc.taboolib.message.MsgUtils; +import me.skymc.taboolib.other.NumberUtils; +import me.skymc.taboolib.string.Language; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; @@ -25,18 +28,10 @@ import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import lombok.Getter; -import me.clip.placeholderapi.PlaceholderAPI; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.TabooLib; -import me.skymc.taboolib.fileutils.ConfigUtils; -import me.skymc.taboolib.itemnbtapi.NBTItem; -import me.skymc.taboolib.itemnbtapi.NBTList; -import me.skymc.taboolib.itemnbtapi.NBTListCompound; -import me.skymc.taboolib.itemnbtapi.NBTType; -import me.skymc.taboolib.message.MsgUtils; -import me.skymc.taboolib.other.NumberUtils; -import me.skymc.taboolib.string.Language; +import java.io.File; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; public class ItemUtils { @@ -150,8 +145,7 @@ public class ItemUtils { @SuppressWarnings("deprecation") public static ItemStack item(int n, int a, int d) { - ItemStack item = new ItemStack(n, a, (short)d); - return item; + return new ItemStack(n, a, (short) d); } public static ItemStack setName(ItemStack i, String n) { @@ -180,17 +174,11 @@ public class ItemUtils { } public static boolean isName(ItemStack i, String a) { - if (!isNamed(i) || i.getItemMeta() == null || i.getItemMeta().getDisplayName() == null || !i.getItemMeta().getDisplayName().equals(a)) { - return false; - } - return true; + return isNamed(i) && i.getItemMeta() != null && i.getItemMeta().getDisplayName() != null && i.getItemMeta().getDisplayName().equals(a); } public static boolean isNameAs(ItemStack i, String a) { - if (!isNamed(i) || !i.getItemMeta().getDisplayName().contains(a)) { - return false; - } - return true; + return isNamed(i) && i.getItemMeta().getDisplayName().contains(a); } public static String asString(String args, Player placeholderPlayer) { @@ -259,27 +247,22 @@ public class ItemUtils { } public static String asAttribute(String name) { - if (name.toLowerCase().equals("damage")) { - return "generic.attackDamage"; - } - else if (name.toLowerCase().equals("attackspeed")) { - return "generic.attackSpeed"; - } - else if (name.toLowerCase().equals("health")) { - return "generic.maxHealth"; - } - else if (name.toLowerCase().equals("speed")) { - return "generic.movementSpeed"; - } - else if (name.toLowerCase().equals("knockback")) { - return "generic.knockbackResistance"; - } - else if (name.toLowerCase().equals("armor")) { - return "generic.armor"; - } - else if (name.toLowerCase().equals("luck")) { - return "generic.luck"; - } + switch (name.toLowerCase()) { + case "damage": + return "generic.attackDamage"; + case "attackspeed": + return "generic.attackSpeed"; + case "health": + return "generic.maxHealth"; + case "speed": + return "generic.movementSpeed"; + case "knockback": + return "generic.knockbackResistance"; + case "armor": + return "generic.armor"; + case "luck": + return "generic.luck"; + } return null; } @@ -290,10 +273,7 @@ public class ItemUtils { * @param a 关键字 */ public static boolean hasLore(ItemStack i, String a) { - if (!isLored(i) || !i.getItemMeta().getLore().toString().contains(a)) { - return false; - } - return true; + return isLored(i) && i.getItemMeta().getLore().toString().contains(a); } /** @@ -303,10 +283,7 @@ public class ItemUtils { * @return */ public static boolean isLored(ItemStack i) { - if (i == null || i.getItemMeta() == null || i.getItemMeta().getLore() == null) { - return false; - } - return true; + return i != null && i.getItemMeta() != null && i.getItemMeta().getLore() != null; } /** @@ -316,10 +293,7 @@ public class ItemUtils { * @return */ public static boolean isNamed(ItemStack i) { - if (i == null || i.getItemMeta() == null || i.getItemMeta().getDisplayName() == null) { - return false; - } - return true; + return i != null && i.getItemMeta() != null && i.getItemMeta().getDisplayName() != null; } /** diff --git a/src/main/java/me/skymc/taboolib/inventory/speciaitem/AbstractSpecialItem.java b/src/main/java/me/skymc/taboolib/inventory/speciaitem/AbstractSpecialItem.java index 5ec1abe..b29164a 100644 --- a/src/main/java/me/skymc/taboolib/inventory/speciaitem/AbstractSpecialItem.java +++ b/src/main/java/me/skymc/taboolib/inventory/speciaitem/AbstractSpecialItem.java @@ -8,7 +8,7 @@ import org.bukkit.plugin.Plugin; * @author sky * @since 2018年2月17日 下午8:35:42 */ -public abstract interface AbstractSpecialItem { +public interface AbstractSpecialItem { /** * 当接口被载入 @@ -25,14 +25,14 @@ public abstract interface AbstractSpecialItem { * * @return String */ - abstract String getName(); + String getName(); /** * 获取载入插件 * * @return {@link Plugin} */ - abstract Plugin getPlugin(); + Plugin getPlugin(); /** * 是否进行点击事件 @@ -42,5 +42,5 @@ public abstract interface AbstractSpecialItem { * @param cursorItem 持有物品 * @return {@link SpecialItemResult[]} */ - abstract SpecialItemResult[] isCorrectClick(Player player, ItemStack currentItem, ItemStack cursorItem); + SpecialItemResult[] isCorrectClick(Player player, ItemStack currentItem, ItemStack cursorItem); } diff --git a/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItem.java b/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItem.java index 55bd7bd..ff82d72 100644 --- a/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItem.java +++ b/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItem.java @@ -1,8 +1,9 @@ package me.skymc.taboolib.inventory.speciaitem; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - +import lombok.Getter; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.inventory.ItemUtils; +import me.skymc.taboolib.message.MsgUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -12,10 +13,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.plugin.Plugin; -import lombok.Getter; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.inventory.ItemUtils; -import me.skymc.taboolib.message.MsgUtils; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; /** * @author sky @@ -119,7 +118,7 @@ public class SpecialItem implements Listener { * 载入所有已注册接口 */ public void loadItems() { - ITEM_DATA.forEach(x -> x.onEnable()); + ITEM_DATA.forEach(AbstractSpecialItem::onEnable); isLoaded = true; } @@ -127,7 +126,7 @@ public class SpecialItem implements Listener { * 注销所有已注册接口 */ public void unloadItems() { - ITEM_DATA.forEach(x -> x.onDisable()); + ITEM_DATA.forEach(AbstractSpecialItem::onDisable); ITEM_DATA.clear(); } @@ -147,33 +146,32 @@ public class SpecialItem implements Listener { Player player = (Player) e.getWhoClicked(); for (AbstractSpecialItem specialitem : ITEM_DATA) { for (SpecialItemResult result : specialitem.isCorrectClick(player, e.getCurrentItem(), e.getCursor())) { - if (result == SpecialItemResult.CANCEL) { - e.setCancelled(true); - } - else if (result == SpecialItemResult.BREAK) { - return; - } - else if (result == SpecialItemResult.REMOVE_ITEM_CURRENT) { - e.setCurrentItem(null); - } - else if (result == SpecialItemResult.REMOVE_ITEM_CURSOR) { - e.getWhoClicked().setItemOnCursor(null); - } - else if (result == SpecialItemResult.REMOVE_ITEM_CURRENT_AMOUNT_1) { - if (e.getCurrentItem().getAmount() > 1) { - e.getCurrentItem().setAmount(e.getCurrentItem().getAmount() - 1); - } - else { - e.setCurrentItem(null); - } - } - else if (result == SpecialItemResult.REMOVE_ITEM_CURSOR_AMOUNT_1) { - if (e.getCursor().getAmount() > 1) { - e.getCursor().setAmount(e.getCursor().getAmount() - 1); - } - else { - e.getWhoClicked().setItemOnCursor(null); - } + switch (result) { + case CANCEL: + e.setCancelled(true); + break; + case BREAK: + return; + case REMOVE_ITEM_CURRENT: + e.setCurrentItem(null); + break; + case REMOVE_ITEM_CURSOR: + e.getWhoClicked().setItemOnCursor(null); + break; + case REMOVE_ITEM_CURRENT_AMOUNT_1: + if (e.getCurrentItem().getAmount() > 1) { + e.getCurrentItem().setAmount(e.getCurrentItem().getAmount() - 1); + } else { + e.setCurrentItem(null); + } + break; + case REMOVE_ITEM_CURSOR_AMOUNT_1: + if (e.getCursor().getAmount() > 1) { + e.getCursor().setAmount(e.getCursor().getAmount() - 1); + } else { + e.getWhoClicked().setItemOnCursor(null); + } + break; } } } diff --git a/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItemResult.java b/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItemResult.java index 7515522..4e06ae2 100644 --- a/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItemResult.java +++ b/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItemResult.java @@ -34,6 +34,6 @@ public enum SpecialItemResult { /** * 移除一个鼠标物品 */ - REMOVE_ITEM_CURSOR_AMOUNT_1; - + REMOVE_ITEM_CURSOR_AMOUNT_1 + } diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTReflectionUtil.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTReflectionUtil.java index 6724bbc..4ae8545 100644 --- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTReflectionUtil.java +++ b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTReflectionUtil.java @@ -1,5 +1,14 @@ package me.skymc.taboolib.itemnbtapi; +import me.skymc.taboolib.TabooLib; +import me.skymc.taboolib.itemnbtapi.utils.GsonWrapper; +import me.skymc.taboolib.itemnbtapi.utils.MethodNames; +import me.skymc.taboolib.message.MsgUtils; +import org.bukkit.Bukkit; +import org.bukkit.block.BlockState; +import org.bukkit.entity.Entity; +import org.bukkit.inventory.ItemStack; + import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; @@ -8,16 +17,6 @@ import java.lang.reflect.Method; import java.util.Set; import java.util.Stack; -import org.bukkit.Bukkit; -import org.bukkit.block.BlockState; -import org.bukkit.entity.Entity; -import org.bukkit.inventory.ItemStack; - -import me.skymc.taboolib.TabooLib; -import me.skymc.taboolib.itemnbtapi.utils.GsonWrapper; -import me.skymc.taboolib.itemnbtapi.utils.MethodNames; -import me.skymc.taboolib.message.MsgUtils; - // TODO: finish codestyle cleanup -sgdc3 public class NBTReflectionUtil { @@ -27,8 +26,7 @@ public class NBTReflectionUtil { private static Class getCraftItemStack() { try { - Class clazz = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack"); - return clazz; + return Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack"); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); return null; @@ -38,8 +36,7 @@ public class NBTReflectionUtil { @SuppressWarnings("rawtypes") private static Class getCraftEntity() { try { - Class clazz = Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftEntity"); - return clazz; + return Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftEntity"); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); return null; @@ -49,8 +46,7 @@ public class NBTReflectionUtil { @SuppressWarnings("rawtypes") protected static Class getNBTBase() { try { - Class clazz = Class.forName("net.minecraft.server." + version + ".NBTBase"); - return clazz; + return Class.forName("net.minecraft.server." + version + ".NBTBase"); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); return null; @@ -60,8 +56,7 @@ public class NBTReflectionUtil { @SuppressWarnings("rawtypes") protected static Class getNBTTagString() { try { - Class clazz = Class.forName("net.minecraft.server." + version + ".NBTTagString"); - return clazz; + return Class.forName("net.minecraft.server." + version + ".NBTTagString"); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); @@ -72,8 +67,7 @@ public class NBTReflectionUtil { @SuppressWarnings("rawtypes") protected static Class getNMSItemStack() { try { - Class clazz = Class.forName("net.minecraft.server." + version + ".ItemStack"); - return clazz; + return Class.forName("net.minecraft.server." + version + ".ItemStack"); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); @@ -84,8 +78,7 @@ public class NBTReflectionUtil { @SuppressWarnings("rawtypes") protected static Class getNBTTagCompound() { try { - Class clazz = Class.forName("net.minecraft.server." + version + ".NBTTagCompound"); - return clazz; + return Class.forName("net.minecraft.server." + version + ".NBTTagCompound"); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); @@ -96,8 +89,7 @@ public class NBTReflectionUtil { @SuppressWarnings("rawtypes") protected static Class getNBTCompressedStreamTools() { try { - Class clazz = Class.forName("net.minecraft.server." + version + ".NBTCompressedStreamTools"); - return clazz; + return Class.forName("net.minecraft.server." + version + ".NBTCompressedStreamTools"); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); @@ -108,8 +100,7 @@ public class NBTReflectionUtil { @SuppressWarnings("rawtypes") protected static Class getMojangsonParser() { try { - Class c = Class.forName("net.minecraft.server." + version + ".MojangsonParser"); - return c; + return Class.forName("net.minecraft.server." + version + ".MojangsonParser"); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); @@ -120,8 +111,7 @@ public class NBTReflectionUtil { @SuppressWarnings("rawtypes") protected static Class getTileEntity() { try { - Class clazz = Class.forName("net.minecraft.server." + version + ".TileEntity"); - return clazz; + return Class.forName("net.minecraft.server." + version + ".TileEntity"); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); @@ -132,8 +122,7 @@ public class NBTReflectionUtil { @SuppressWarnings("rawtypes") protected static Class getCraftWorld() { try { - Class clazz = Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld"); - return clazz; + return Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld"); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); @@ -186,8 +175,7 @@ public class NBTReflectionUtil { Method method; try { method = clazz.getMethod("asNMSCopy", ItemStack.class); - Object answer = method.invoke(clazz, item); - return answer; + return method.invoke(clazz, item); } catch (Exception e) { MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage()); } @@ -272,8 +260,7 @@ public class NBTReflectionUtil { Method method; try { method = clazz.getMethod("getTag"); - Object answer = method.invoke(nmsitem); - return answer; + return method.invoke(nmsitem); } catch (Exception e) { MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage()); } @@ -285,8 +272,7 @@ public class NBTReflectionUtil { @SuppressWarnings("rawtypes") Class clazz = getNMSItemStack(); try { - Object nmsstack = clazz.getConstructor(getNBTTagCompound()).newInstance(nbtcompound.getCompound()); - return nmsstack; + return clazz.getConstructor(getNBTTagCompound()).newInstance(nbtcompound.getCompound()); } catch (Exception e) { MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage()); } @@ -379,8 +365,7 @@ public class NBTReflectionUtil { Method method; try { method = c.getMethod("getCompound", String.class); - Object answer = method.invoke(compound, name); - return answer; + return method.invoke(compound, name); } catch (Exception e) { MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage()); } @@ -403,11 +388,9 @@ public class NBTReflectionUtil { method = workingtag.getClass().getMethod("set", String.class, getNBTBase()); method.invoke(workingtag, name, getNBTTagCompound().newInstance()); comp.setCompound(nbttag); - return; } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); } - return; } public static Boolean valideCompound(NBTCompound comp) { @@ -562,7 +545,6 @@ public class NBTReflectionUtil { } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); } - return; } public static byte[] getByteArray(NBTCompound comp, String key) { @@ -634,7 +616,7 @@ public class NBTReflectionUtil { Method method; try { method = workingtag.getClass().getMethod("setFloat", String.class, float.class); - method.invoke(workingtag, key, (float) f); + method.invoke(workingtag, key, f); comp.setCompound(rootnbttag); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); @@ -672,7 +654,7 @@ public class NBTReflectionUtil { Method method; try { method = workingtag.getClass().getMethod("setLong", String.class, long.class); - method.invoke(workingtag, key, (long) f); + method.invoke(workingtag, key, f); comp.setCompound(rootnbttag); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); @@ -710,7 +692,7 @@ public class NBTReflectionUtil { Method method; try { method = workingtag.getClass().getMethod("setShort", String.class, short.class); - method.invoke(workingtag, key, (short) f); + method.invoke(workingtag, key, f); comp.setCompound(rootnbttag); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); @@ -748,7 +730,7 @@ public class NBTReflectionUtil { Method method; try { method = workingtag.getClass().getMethod("setByte", String.class, byte.class); - method.invoke(workingtag, key, (byte) f); + method.invoke(workingtag, key, f); comp.setCompound(rootnbttag); } catch (Exception ex) { MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); diff --git a/src/main/java/me/skymc/taboolib/javascript/JavaScriptUtils.java b/src/main/java/me/skymc/taboolib/javascript/JavaScriptUtils.java index 8636fe9..ea982a4 100644 --- a/src/main/java/me/skymc/taboolib/javascript/JavaScriptUtils.java +++ b/src/main/java/me/skymc/taboolib/javascript/JavaScriptUtils.java @@ -1,16 +1,14 @@ package me.skymc.taboolib.javascript; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; +import me.skymc.taboolib.Main; import javax.script.Invocable; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; - -import me.skymc.taboolib.Main; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; public class JavaScriptUtils { @@ -51,13 +49,7 @@ public class JavaScriptUtils { } reader.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (ScriptException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { + } catch (NoSuchMethodException | IOException | ScriptException e) { e.printStackTrace(); } return null; @@ -76,13 +68,7 @@ public class JavaScriptUtils { } reader.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (ScriptException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { + } catch (NoSuchMethodException | IOException | ScriptException e) { e.printStackTrace(); } } diff --git a/src/main/java/me/skymc/taboolib/javashell/JavaShell.java b/src/main/java/me/skymc/taboolib/javashell/JavaShell.java index b20cf24..86fa9d1 100644 --- a/src/main/java/me/skymc/taboolib/javashell/JavaShell.java +++ b/src/main/java/me/skymc/taboolib/javashell/JavaShell.java @@ -1,12 +1,10 @@ package me.skymc.taboolib.javashell; -import java.io.File; -import java.io.FilenameFilter; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.HashMap; - +import lombok.Getter; +import lombok.Setter; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.javashell.utils.JarUtils; +import me.skymc.taboolib.message.MsgUtils; import org.apache.commons.lang.ArrayUtils; import org.bukkit.Bukkit; import org.bukkit.event.HandlerList; @@ -14,11 +12,11 @@ import org.bukkit.event.Listener; import org.bukkit.plugin.RegisteredListener; import org.bukkit.scheduler.BukkitRunnable; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.javashell.utils.JarUtils; -import me.skymc.taboolib.message.MsgUtils; -import lombok.Getter; -import lombok.Setter; +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.HashMap; public class JavaShell { @@ -50,18 +48,10 @@ public class JavaShell { File dataFolder = Main.getInst().getDataFolder(); File pluginsFolder = dataFolder.getParentFile(); File serverRoot = Bukkit.getWorldContainer(); - - File[] rootJars = serverRoot.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.toLowerCase().endsWith("jar"); - } - }); - - File[] pluginJars = pluginsFolder.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.toLowerCase().endsWith("jar"); - } - }); + + File[] rootJars = serverRoot.listFiles((dir, name) -> name.toLowerCase().endsWith("jar")); + + File[] pluginJars = pluginsFolder.listFiles((dir, name) -> name.toLowerCase().endsWith("jar")); for (File file : (File[]) ArrayUtils.addAll(rootJars, pluginJars)) { String path = file.getAbsolutePath(); @@ -123,7 +113,7 @@ public class JavaShell { if (shells.containsKey(name)) { Class clazz = shells.get(name); try { - Method disableMethod = clazz.getMethod(method, new Class[0]); + Method disableMethod = clazz.getMethod(method); if (disableMethod != null) { disableMethod.invoke(clazz.newInstance()); } diff --git a/src/main/java/me/skymc/taboolib/javashell/utils/JarUtils.java b/src/main/java/me/skymc/taboolib/javashell/utils/JarUtils.java index a1324e8..18fd574 100644 --- a/src/main/java/me/skymc/taboolib/javashell/utils/JarUtils.java +++ b/src/main/java/me/skymc/taboolib/javashell/utils/JarUtils.java @@ -1,12 +1,9 @@ package me.skymc.taboolib.javashell.utils; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import me.skymc.taboolib.message.MsgUtils; +import org.bukkit.Bukkit; + +import java.io.*; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; @@ -15,10 +12,6 @@ import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import org.bukkit.Bukkit; - -import me.skymc.taboolib.message.MsgUtils; - public class JarUtils { public static boolean extractFromJar(final String fileName, final String dest) throws IOException { @@ -51,7 +44,7 @@ public class JarUtils { return false; } - private final static void copyInputStream(final InputStream in, final OutputStream out) throws IOException { + private static void copyInputStream(final InputStream in, final OutputStream out) throws IOException { try { final byte[] buff = new byte[4096]; int n; @@ -88,13 +81,13 @@ public class JarUtils { } } - public static void addClassPath(final URL url) throws IOException { + public static void addClassPath(final URL url) { final URLClassLoader sysloader = (URLClassLoader) Bukkit.class.getClassLoader(); final Class sysclass = URLClassLoader.class; try { - final Method method = sysclass.getDeclaredMethod("addURL", new Class[] { URL.class }); + final Method method = sysclass.getDeclaredMethod("addURL", URL.class); method.setAccessible(true); - method.invoke(sysloader, new Object[] { url }); + method.invoke(sysloader, url); } catch (Throwable t) { MsgUtils.warn("无法添加添加 &4" + url + "&c 到运行库"); MsgUtils.warn(t.getMessage()); diff --git a/src/main/java/me/skymc/taboolib/json/CDL.java b/src/main/java/me/skymc/taboolib/json/CDL.java index f6f1236..e5fa3da 100644 --- a/src/main/java/me/skymc/taboolib/json/CDL.java +++ b/src/main/java/me/skymc/taboolib/json/CDL.java @@ -69,7 +69,7 @@ public class CDL { } public static String rowToString(JSONArray ja) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < ja.length(); i += 1) { if (i > 0) { sb.append(','); @@ -146,7 +146,7 @@ public class CDL { if (names == null || names.length() == 0) { return null; } - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < ja.length(); i += 1) { JSONObject jo = ja.optJSONObject(i); if (jo != null) { diff --git a/src/main/java/me/skymc/taboolib/json/Cookie.java b/src/main/java/me/skymc/taboolib/json/Cookie.java index 88cfd52..5e0d431 100644 --- a/src/main/java/me/skymc/taboolib/json/Cookie.java +++ b/src/main/java/me/skymc/taboolib/json/Cookie.java @@ -5,7 +5,7 @@ public class Cookie { public static String escape(String string) { char c; String s = string.trim(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int length = s.length(); for (int i = 0; i < length; i += 1) { c = s.charAt(i); @@ -47,7 +47,7 @@ public class Cookie { } public static String toString(JSONObject jo) throws JSONException { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(escape(jo.getString("name"))); sb.append("="); @@ -72,7 +72,7 @@ public class Cookie { public static String unescape(String string) { int length = string.length(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < length; ++i) { char c = string.charAt(i); if (c == '+') { diff --git a/src/main/java/me/skymc/taboolib/json/CookieList.java b/src/main/java/me/skymc/taboolib/json/CookieList.java index f5890a7..9bf43bb 100644 --- a/src/main/java/me/skymc/taboolib/json/CookieList.java +++ b/src/main/java/me/skymc/taboolib/json/CookieList.java @@ -21,7 +21,7 @@ public class CookieList { boolean b = false; Iterator keys = jo.keys(); String string; - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); while (keys.hasNext()) { string = keys.next().toString(); if (!jo.isNull(string)) { diff --git a/src/main/java/me/skymc/taboolib/json/HTTP.java b/src/main/java/me/skymc/taboolib/json/HTTP.java index d71326a..3466b69 100644 --- a/src/main/java/me/skymc/taboolib/json/HTTP.java +++ b/src/main/java/me/skymc/taboolib/json/HTTP.java @@ -35,7 +35,7 @@ public class HTTP { public static String toString(JSONObject jo) throws JSONException { Iterator keys = jo.keys(); String string; - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if (jo.has("Status-Code") && jo.has("Reason-Phrase")) { sb.append(jo.getString("HTTP-Version")); sb.append(' '); diff --git a/src/main/java/me/skymc/taboolib/json/HTTPTokener.java b/src/main/java/me/skymc/taboolib/json/HTTPTokener.java index 6ad7f7b..a03f1c2 100644 --- a/src/main/java/me/skymc/taboolib/json/HTTPTokener.java +++ b/src/main/java/me/skymc/taboolib/json/HTTPTokener.java @@ -9,7 +9,7 @@ public class HTTPTokener extends JSONTokener { public String nextToken() throws JSONException { char c; char q; - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); do { c = next(); } while (Character.isWhitespace(c)); diff --git a/src/main/java/me/skymc/taboolib/json/JSONArray.java b/src/main/java/me/skymc/taboolib/json/JSONArray.java index 3537979..ef74a8c 100644 --- a/src/main/java/me/skymc/taboolib/json/JSONArray.java +++ b/src/main/java/me/skymc/taboolib/json/JSONArray.java @@ -6,7 +6,6 @@ import java.io.Writer; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.Map; @SuppressWarnings({"rawtypes", "unchecked"}) @@ -57,9 +56,8 @@ public class JSONArray { public JSONArray(Collection collection) { this.myArrayList = new ArrayList(); if (collection != null) { - Iterator iter = collection.iterator(); - while (iter.hasNext()) { - this.myArrayList.add(JSONObject.wrap(iter.next())); + for (Object aCollection : collection) { + this.myArrayList.add(JSONObject.wrap(aCollection)); } } } @@ -166,7 +164,7 @@ public class JSONArray { public String join(String separator) throws JSONException { int len = this.length(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i += 1) { if (i > 0) { @@ -267,7 +265,7 @@ public class JSONArray { } public JSONArray put(double value) throws JSONException { - Double d = new Double(value); + Double d = value; JSONObject.testValidity(d); this.put(d); return this; diff --git a/src/main/java/me/skymc/taboolib/json/JSONML.java b/src/main/java/me/skymc/taboolib/json/JSONML.java index 3160bc1..9f5ab21 100644 --- a/src/main/java/me/skymc/taboolib/json/JSONML.java +++ b/src/main/java/me/skymc/taboolib/json/JSONML.java @@ -40,33 +40,37 @@ public class JSONML { return token; } else if (token == XML.BANG) { c = x.next(); - if (c == '-') { - if (x.next() == '-') { - x.skipPast("-->"); - } else { - x.back(); - } - } else if (c == '[') { - token = x.nextToken(); - if (token.equals("CDATA") && x.next() == '[') { - if (ja != null) { - ja.put(x.nextCDATA()); + switch (c) { + case '-': + if (x.next() == '-') { + x.skipPast("-->"); + } else { + x.back(); } - } else { - throw x.syntaxError("Expected 'CDATA['"); - } - } else { - i = 1; - do { - token = x.nextMeta(); - if (token == null) { - throw x.syntaxError("Missing '>' after ' 0); + break; + default: + i = 1; + do { + token = x.nextMeta(); + if (token == null) { + throw x.syntaxError("Missing '>' after ' 0); + break; } } else if (token == XML.QUEST) { x.skipPast("?>"); @@ -189,7 +193,7 @@ public class JSONML { Iterator keys; int length; Object object; - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); String tagName; String value; tagName = ja.getString(0); @@ -247,7 +251,7 @@ public class JSONML { } public static String toString(JSONObject jo) throws JSONException { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int i; JSONArray ja; String key; diff --git a/src/main/java/me/skymc/taboolib/json/JSONObject.java b/src/main/java/me/skymc/taboolib/json/JSONObject.java index 8735334..e038225 100644 --- a/src/main/java/me/skymc/taboolib/json/JSONObject.java +++ b/src/main/java/me/skymc/taboolib/json/JSONObject.java @@ -6,13 +6,7 @@ import java.io.Writer; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; +import java.util.*; @SuppressWarnings({"rawtypes", "unchecked"}) public class JSONObject { @@ -42,9 +36,9 @@ public class JSONObject { public JSONObject(JSONObject jo, String[] names) { this(); - for (int i = 0; i < names.length; i += 1) { + for (String name : names) { try { - this.putOnce(names[i], jo.opt(names[i])); + this.putOnce(name, jo.opt(name)); } catch (Exception ignore) { } } @@ -97,9 +91,8 @@ public class JSONObject { public JSONObject(Map map) { this.map = new HashMap(); if (map != null) { - Iterator i = map.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry e = (Map.Entry)i.next(); + for (Object o : map.entrySet()) { + Map.Entry e = (Map.Entry) o; Object value = e.getValue(); if (value != null) { this.map.put(e.getKey(), wrap(value)); @@ -116,8 +109,7 @@ public class JSONObject { public JSONObject(Object object, String names[]) { this(); Class c = object.getClass(); - for (int i = 0; i < names.length; i += 1) { - String name = names[i]; + for (String name : names) { try { this.putOpt(name, c.getField(name).get(object)); } catch (Exception ignore) { @@ -329,22 +321,41 @@ public class JSONObject { return this.map.containsKey(key); } - public JSONObject increment(String key) throws JSONException { - Object value = this.opt(key); - if (value == null) { - this.put(key, 1); - } else if (value instanceof Integer) { - this.put(key, ((Integer)value).intValue() + 1); - } else if (value instanceof Long) { - this.put(key, ((Long)value).longValue() + 1); - } else if (value instanceof Double) { - this.put(key, ((Double)value).doubleValue() + 1); - } else if (value instanceof Float) { - this.put(key, ((Float)value).floatValue() + 1); - } else { - throw new JSONException("Unable to increment [" + quote(key) + "]."); + public static Object stringToValue(String string) { + Double d; + if (string.equals("")) { + return string; } - return this; + if (string.equalsIgnoreCase("true")) { + return Boolean.TRUE; + } + if (string.equalsIgnoreCase("false")) { + return Boolean.FALSE; + } + if (string.equalsIgnoreCase("null")) { + return JSONObject.NULL; + } + char b = string.charAt(0); + if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') { + try { + if (string.indexOf('.') > -1 || + string.indexOf('e') > -1 || string.indexOf('E') > -1) { + d = Double.valueOf(string); + if (!d.isInfinite() && !d.isNaN()) { + return d; + } + } else { + Long myLong = new Long(string); + if (myLong == myLong.intValue()) { + return myLong.intValue(); + } else { + return myLong; + } + } + } catch (Exception ignore) { + } + } + return string; } public boolean isNull(String key) { @@ -458,49 +469,39 @@ public class JSONObject { return NULL.equals(object) ? defaultValue : object.toString(); } - - private void populateMap(Object bean) { - Class klass = bean.getClass(); - boolean includeSuperClass = klass.getClassLoader() != null; - - Method[] methods = includeSuperClass - ? klass.getMethods() - : klass.getDeclaredMethods(); - for (int i = 0; i < methods.length; i += 1) { - try { - Method method = methods[i]; - if (Modifier.isPublic(method.getModifiers())) { - String name = method.getName(); - String key = ""; - if (name.startsWith("get")) { - if ("getClass".equals(name) || - "getDeclaringClass".equals(name)) { - key = ""; - } else { - key = name.substring(3); - } - } else if (name.startsWith("is")) { - key = name.substring(2); - } - if (key.length() > 0 && - Character.isUpperCase(key.charAt(0)) && - method.getParameterTypes().length == 0) { - if (key.length() == 1) { - key = key.toLowerCase(); - } else if (!Character.isUpperCase(key.charAt(1))) { - key = key.substring(0, 1).toLowerCase() + - key.substring(1); - } - - Object result = method.invoke(bean, (Object[])null); - if (result != null) { - this.map.put(key, wrap(result)); - } - } - } - } catch (Exception ignore) { - } + public static String valueToString(Object value) throws JSONException { + if (value == null || value == null) { + return "null"; } + if (value instanceof JSONString) { + Object object; + try { + object = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + if (object instanceof String) { + return (String) object; + } + throw new JSONException("Bad value from toJSONString: " + object); + } + if (value instanceof Number) { + return numberToString((Number) value); + } + if (value instanceof Boolean || value instanceof JSONObject || + value instanceof JSONArray) { + return value.toString(); + } + if (value instanceof Map) { + return new JSONObject((Map) value).toString(); + } + if (value instanceof Collection) { + return new JSONArray((Collection) value).toString(); + } + if (value.getClass().isArray()) { + return new JSONArray(value).toString(); + } + return quote(value.toString()); } public JSONObject put(String key, boolean value) throws JSONException { @@ -635,41 +636,37 @@ public class JSONObject { return this.map.remove(key); } - public static Object stringToValue(String string) { - Double d; - if (string.equals("")) { - return string; - } - if (string.equalsIgnoreCase("true")) { - return Boolean.TRUE; - } - if (string.equalsIgnoreCase("false")) { - return Boolean.FALSE; - } - if (string.equalsIgnoreCase("null")) { - return JSONObject.NULL; - } - char b = string.charAt(0); - if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') { + static Writer writeValue(Writer writer, Object value, + int indentFactor, int indent) throws JSONException, IOException { + if (value == null || value == null) { + writer.write("null"); + } else if (value instanceof JSONObject) { + ((JSONObject) value).write(writer, indentFactor, indent); + } else if (value instanceof JSONArray) { + ((JSONArray) value).write(writer, indentFactor, indent); + } else if (value instanceof Map) { + new JSONObject((Map) value).write(writer, indentFactor, indent); + } else if (value instanceof Collection) { + new JSONArray((Collection) value).write(writer, indentFactor, + indent); + } else if (value.getClass().isArray()) { + new JSONArray(value).write(writer, indentFactor, indent); + } else if (value instanceof Number) { + writer.write(numberToString((Number) value)); + } else if (value instanceof Boolean) { + writer.write(value.toString()); + } else if (value instanceof JSONString) { + Object o; try { - if (string.indexOf('.') > -1 || - string.indexOf('e') > -1 || string.indexOf('E') > -1) { - d = Double.valueOf(string); - if (!d.isInfinite() && !d.isNaN()) { - return d; - } - } else { - Long myLong = new Long(string); - if (myLong.longValue() == myLong.intValue()) { - return new Integer(myLong.intValue()); - } else { - return myLong; - } - } - } catch (Exception ignore) { + o = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); } + writer.write(o != null ? o.toString() : quote(value.toString())); + } else { + quote(value.toString(), writer); } - return string; + return writer; } public static void testValidity(Object o) throws JSONException { @@ -714,39 +711,10 @@ public class JSONObject { } } - public static String valueToString(Object value) throws JSONException { - if (value == null || value.equals(null)) { - return "null"; + static void indent(Writer writer, int indent) throws IOException { + for (int i = 0; i < indent; i += 1) { + writer.write(' '); } - if (value instanceof JSONString) { - Object object; - try { - object = ((JSONString)value).toJSONString(); - } catch (Exception e) { - throw new JSONException(e); - } - if (object instanceof String) { - return (String)object; - } - throw new JSONException("Bad value from toJSONString: " + object); - } - if (value instanceof Number) { - return numberToString((Number) value); - } - if (value instanceof Boolean || value instanceof JSONObject || - value instanceof JSONArray) { - return value.toString(); - } - if (value instanceof Map) { - return new JSONObject((Map)value).toString(); - } - if (value instanceof Collection) { - return new JSONArray((Collection)value).toString(); - } - if (value.getClass().isArray()) { - return new JSONArray(value).toString(); - } - return quote(value.toString()); } public static Object wrap(Object object) { @@ -794,43 +762,65 @@ public class JSONObject { return this.write(writer, 0, 0); } - - static final Writer writeValue(Writer writer, Object value, - int indentFactor, int indent) throws JSONException, IOException { - if (value == null || value.equals(null)) { - writer.write("null"); - } else if (value instanceof JSONObject) { - ((JSONObject) value).write(writer, indentFactor, indent); - } else if (value instanceof JSONArray) { - ((JSONArray) value).write(writer, indentFactor, indent); - } else if (value instanceof Map) { - new JSONObject((Map) value).write(writer, indentFactor, indent); - } else if (value instanceof Collection) { - new JSONArray((Collection) value).write(writer, indentFactor, - indent); - } else if (value.getClass().isArray()) { - new JSONArray(value).write(writer, indentFactor, indent); - } else if (value instanceof Number) { - writer.write(numberToString((Number) value)); - } else if (value instanceof Boolean) { - writer.write(value.toString()); - } else if (value instanceof JSONString) { - Object o; - try { - o = ((JSONString) value).toJSONString(); - } catch (Exception e) { - throw new JSONException(e); - } - writer.write(o != null ? o.toString() : quote(value.toString())); + public JSONObject increment(String key) throws JSONException { + Object value = this.opt(key); + if (value == null) { + this.put(key, 1); + } else if (value instanceof Integer) { + this.put(key, (Integer) value + 1); + } else if (value instanceof Long) { + this.put(key, (Long) value + 1); + } else if (value instanceof Double) { + this.put(key, (Double) value + 1); + } else if (value instanceof Float) { + this.put(key, (Float) value + 1); } else { - quote(value.toString(), writer); + throw new JSONException("Unable to increment [" + quote(key) + "]."); } - return writer; + return this; } - static final void indent(Writer writer, int indent) throws IOException { - for (int i = 0; i < indent; i += 1) { - writer.write(' '); + private void populateMap(Object bean) { + Class klass = bean.getClass(); + boolean includeSuperClass = klass.getClassLoader() != null; + + Method[] methods = includeSuperClass + ? klass.getMethods() + : klass.getDeclaredMethods(); + for (Method method1 : methods) { + try { + Method method = method1; + if (Modifier.isPublic(method.getModifiers())) { + String name = method.getName(); + String key = ""; + if (name.startsWith("get")) { + if ("getClass".equals(name) || + "getDeclaringClass".equals(name)) { + key = ""; + } else { + key = name.substring(3); + } + } else if (name.startsWith("is")) { + key = name.substring(2); + } + if (key.length() > 0 && + Character.isUpperCase(key.charAt(0)) && + method.getParameterTypes().length == 0) { + if (key.length() == 1) { + key = key.toLowerCase(); + } else if (!Character.isUpperCase(key.charAt(1))) { + key = key.substring(0, 1).toLowerCase() + + key.substring(1); + } + + Object result = method.invoke(bean, (Object[]) null); + if (result != null) { + this.map.put(key, wrap(result)); + } + } + } + } catch (Exception ignore) { + } } } diff --git a/src/main/java/me/skymc/taboolib/json/JSONString.java b/src/main/java/me/skymc/taboolib/json/JSONString.java index b6e78f5..c7842f6 100644 --- a/src/main/java/me/skymc/taboolib/json/JSONString.java +++ b/src/main/java/me/skymc/taboolib/json/JSONString.java @@ -2,5 +2,5 @@ package me.skymc.taboolib.json; public interface JSONString { - public String toJSONString(); + String toJSONString(); } diff --git a/src/main/java/me/skymc/taboolib/json/JSONTokener.java b/src/main/java/me/skymc/taboolib/json/JSONTokener.java index 0f671d2..08f184b 100644 --- a/src/main/java/me/skymc/taboolib/json/JSONTokener.java +++ b/src/main/java/me/skymc/taboolib/json/JSONTokener.java @@ -1,12 +1,7 @@ package me.skymc.taboolib.json; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; +import java.io.*; public class JSONTokener { @@ -30,7 +25,7 @@ public class JSONTokener { this.line = 1; } - public JSONTokener(InputStream inputStream) throws JSONException { + public JSONTokener(InputStream inputStream) { this(new InputStreamReader(inputStream)); } @@ -143,7 +138,7 @@ public class JSONTokener { public String nextString(char quote) throws JSONException { char c; - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (;;) { c = this.next(); switch (c) { @@ -192,7 +187,7 @@ public class JSONTokener { } public String nextTo(char delimiter) throws JSONException { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (;;) { char c = this.next(); if (c == delimiter || c == 0 || c == '\n' || c == '\r') { @@ -207,7 +202,7 @@ public class JSONTokener { public String nextTo(String delimiters) throws JSONException { char c; - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (;;) { c = this.next(); if (delimiters.indexOf(c) >= 0 || c == 0 || @@ -237,7 +232,7 @@ public class JSONTokener { return new JSONArray(this); } - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { sb.append(c); c = this.next(); diff --git a/src/main/java/me/skymc/taboolib/json/XML.java b/src/main/java/me/skymc/taboolib/json/XML.java index 2c9e708..7a0f8ad 100644 --- a/src/main/java/me/skymc/taboolib/json/XML.java +++ b/src/main/java/me/skymc/taboolib/json/XML.java @@ -6,26 +6,26 @@ import java.util.Iterator; @SuppressWarnings({"rawtypes"}) public class XML { - public static final Character AMP = new Character('&'); + public static final Character AMP = '&'; - public static final Character APOS = new Character('\''); + public static final Character APOS = '\''; - public static final Character BANG = new Character('!'); + public static final Character BANG = '!'; - public static final Character EQ = new Character('='); + public static final Character EQ = '='; - public static final Character GT = new Character('>'); + public static final Character GT = '>'; - public static final Character LT = new Character('<'); + public static final Character LT = '<'; - public static final Character QUEST = new Character('?'); + public static final Character QUEST = '?'; - public static final Character QUOT = new Character('"'); + public static final Character QUOT = '"'; - public static final Character SLASH = new Character('/'); + public static final Character SLASH = '/'; public static String escape(String string) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0, length = string.length(); i < length; i++) { char c = string.charAt(i); switch (c) { @@ -206,7 +206,7 @@ public class XML { return JSONObject.NULL; } if ("0".equals(string)) { - return new Integer(0); + return 0; } try { char initial = string.charAt(0); @@ -223,8 +223,8 @@ public class XML { return Double.valueOf(string); } else if (string.indexOf('e') < 0 && string.indexOf('E') < 0) { Long myLong = new Long(string); - if (myLong.longValue() == myLong.intValue()) { - return new Integer(myLong.intValue()); + if (myLong == myLong.intValue()) { + return myLong.intValue(); } else { return myLong; } @@ -250,7 +250,7 @@ public class XML { public static String toString(Object object, String tagName) throws JSONException { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int i; JSONArray ja; JSONObject jo; diff --git a/src/main/java/me/skymc/taboolib/json/XMLTokener.java b/src/main/java/me/skymc/taboolib/json/XMLTokener.java index be01ab2..c88bd4c 100644 --- a/src/main/java/me/skymc/taboolib/json/XMLTokener.java +++ b/src/main/java/me/skymc/taboolib/json/XMLTokener.java @@ -21,7 +21,7 @@ public class XMLTokener extends JSONTokener { public String nextCDATA() throws JSONException { char c; int i; - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (;;) { c = next(); if (end()) { @@ -65,7 +65,7 @@ public class XMLTokener extends JSONTokener { } public Object nextEntity(char ampersand) throws JSONException { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (;;) { char c = next(); if (Character.isLetterOrDigit(c) || c == '#') { diff --git a/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java b/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java index cb56720..f8ab044 100644 --- a/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java +++ b/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java @@ -1,27 +1,26 @@ package me.skymc.taboolib.jsonformatter; +import me.skymc.taboolib.json.JSONArray; +import me.skymc.taboolib.json.JSONObject; +import me.skymc.taboolib.jsonformatter.click.ClickEvent; +import me.skymc.taboolib.jsonformatter.hover.HoverEvent; +import me.skymc.taboolib.nms.NMSUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import me.skymc.taboolib.json.JSONArray; -import me.skymc.taboolib.json.JSONObject; -import me.skymc.taboolib.jsonformatter.click.ClickEvent; -import me.skymc.taboolib.jsonformatter.hover.HoverEvent; -import me.skymc.taboolib.nms.NMSUtils; - public class JSONFormatter { private JSONArray ja = new JSONArray(); private Builder builder = new Builder(); private String color = ""; - private List all = new ArrayList(); + private List all = new ArrayList<>(); private boolean newline = true; public JSONFormatter(){ @@ -102,7 +101,7 @@ public class JSONFormatter { } public List toJSONList(){ - List list = new ArrayList(); + List list = new ArrayList<>(); try{ for(JSONArray ja : all){ JSONObject jo = new JSONObject(); @@ -133,7 +132,7 @@ public class JSONFormatter { } public List toSerializedList(){ - List list = new ArrayList(); + List list = new ArrayList<>(); try{ for(String s : toJSONList()){ list.add(a.invoke(null, s)); @@ -255,19 +254,19 @@ public class JSONFormatter { public Object getPacket(){ try{ return ppocc.newInstance(toSerialized()); - }catch(Exception e){ + } catch (Exception ignored) { } return null; } public List getPacketList(){ - List list = new ArrayList(); + List list = new ArrayList<>(); try{ for(Object o : toSerializedList()){ list.add(ppocc.newInstance(o)); } return list; - }catch(Exception e){ + } catch (Exception ignored) { } return null; } @@ -382,7 +381,7 @@ public class JSONFormatter { public JSONObject toString(String color){ return toString(color, new BuilderHelper(){ @Override - public void add(JSONObject jo) throws Exception{ + public void add(JSONObject jo) { } }); } 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 805a334..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,20 +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.Bukkit; -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 me.skymc.taboolib.nms.item.IDabItemUtils; +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{ @@ -35,17 +32,17 @@ public class ShowItemEvent extends HoverEvent{ StringBuilder tag = new StringBuilder(); Object itemTag = getItemTag(is); if (itemTag != null) { - tag.append(",tag:" + itemTag); + tag.append(",tag:").append(itemTag); } else { ItemMeta im = is.getItemMeta(); List lore = im.hasLore() ? im.getLore() : new ArrayList<>(); Map enchants = is.getItemMeta().getEnchants(); - tag.append(",tag:{display:{Name:" + (enchants.size() > 0 ? "§b§o" : "§f") + ItemUtils.getCustomName(is)); + tag.append(",tag:{display:{Name:").append(enchants.size() > 0 ? "§b§o" : "§f").append(ItemUtils.getCustomName(is)); if (lore.size() > 0) { tag.append(",Lore:["); for (String s : lore){ - tag.append("\"" + s + "\","); + tag.append("\"").append(s).append("\","); } tag.delete(tag.length() - 1, tag.length()); tag.append("]"); @@ -57,7 +54,7 @@ public class ShowItemEvent extends HoverEvent{ } tag.append("ench:["); for (Entry e : enchants.entrySet()) { - tag.append("{id:" + e.getKey().getId() + ",lvl:" + e.getValue() + "},"); + tag.append("{id:").append(e.getKey().getId()).append(",lvl:").append(e.getValue()).append("},"); } tag.delete(tag.length() - 1, tag.length()); tag.append("]"); diff --git a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java index f6195e5..4f92e24 100644 --- a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java +++ b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerCommand.java @@ -1,26 +1,17 @@ package me.skymc.taboolib.listener; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -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; -import me.skymc.taboolib.inventory.ItemUtils; -import me.skymc.taboolib.itemnbtapi.NBTCompound; import me.skymc.taboolib.itemnbtapi.NBTItem; -import me.skymc.taboolib.jsonformatter.JSONFormatter; -import me.skymc.taboolib.jsonformatter.click.RunCommandEvent; -import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; -import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; 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 { @@ -30,7 +21,7 @@ public class ListenerPlayerCommand implements Listener { if (TabooLib.getVerint() > 10700) { e.setCancelled(true); } - Bukkit.getScheduler().runTask(Main.getInst(), () -> DataUtils.saveAllCaches()); + Bukkit.getScheduler().runTask(Main.getInst(), DataUtils::saveAllCaches); Bukkit.getScheduler().runTask(Main.getInst(), () -> PlayerDataManager.saveAllCaches(true, false)); } } diff --git a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerJump.java b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerJump.java index dfc07f3..d0d4fa1 100644 --- a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerJump.java +++ b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerJump.java @@ -1,12 +1,10 @@ package me.skymc.taboolib.listener; -import java.util.HashMap; +import me.skymc.taboolib.events.PlayerJumpEvent; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.Server; -import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -14,7 +12,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; -import me.skymc.taboolib.events.PlayerJumpEvent; +import java.util.HashMap; public class ListenerPlayerJump implements Listener @@ -31,17 +29,16 @@ public class ListenerPlayerJump { if (!this.cooldown.containsKey(event.getPlayer())) { - this.cooldown.put(event.getPlayer(), Long.valueOf(System.currentTimeMillis() + 350L)); + this.cooldown.put(event.getPlayer(), System.currentTimeMillis() + 350L); PlayerJumpEvent evt = new PlayerJumpEvent(event.isCancelled(), event.getPlayer()); Bukkit.getPluginManager().callEvent(evt); if (evt.isCancelled()) { event.setCancelled(true); } - } - else if (((Long)this.cooldown.get(event.getPlayer())).longValue() <= System.currentTimeMillis()) + } else if (this.cooldown.get(event.getPlayer()) <= System.currentTimeMillis()) { - this.cooldown.put(event.getPlayer(), Long.valueOf(System.currentTimeMillis() + 350L)); + this.cooldown.put(event.getPlayer(), System.currentTimeMillis() + 350L); PlayerJumpEvent evt = new PlayerJumpEvent(event.isCancelled(), event.getPlayer()); Bukkit.getPluginManager().callEvent(evt); diff --git a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java index 8a12c79..066e77c 100644 --- a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java +++ b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java @@ -1,15 +1,10 @@ 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.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.scheduler.BukkitRunnable; - -import me.skymc.taboolib.Main; -import me.skymc.taboolib.database.PlayerDataManager; -import me.skymc.taboolib.playerdata.DataUtils; public class ListenerPlayerQuit implements Listener{ diff --git a/src/main/java/me/skymc/taboolib/listener/ListenerPluginDisable.java b/src/main/java/me/skymc/taboolib/listener/ListenerPluginDisable.java index 51c3ccc..95f9a60 100644 --- a/src/main/java/me/skymc/taboolib/listener/ListenerPluginDisable.java +++ b/src/main/java/me/skymc/taboolib/listener/ListenerPluginDisable.java @@ -1,19 +1,17 @@ package me.skymc.taboolib.listener; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.server.PluginDisableEvent; -import org.bukkit.scheduler.BukkitRunnable; - import me.skymc.taboolib.Main; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.mysql.MysqlUtils; import me.skymc.taboolib.mysql.protect.MySQLConnection; import me.skymc.taboolib.timecycle.TimeCycleManager; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.ArrayList; +import java.util.List; public class ListenerPluginDisable implements Listener { diff --git a/src/main/java/me/skymc/taboolib/location/LocationUtils.java b/src/main/java/me/skymc/taboolib/location/LocationUtils.java index d4988f7..21ae208 100644 --- a/src/main/java/me/skymc/taboolib/location/LocationUtils.java +++ b/src/main/java/me/skymc/taboolib/location/LocationUtils.java @@ -5,8 +5,6 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -import me.skymc.taboolib.methods.MethodsUtils; - public class LocationUtils { /** diff --git a/src/main/java/me/skymc/taboolib/message/ChatCatcher.java b/src/main/java/me/skymc/taboolib/message/ChatCatcher.java index 79ee1a6..60be8b6 100644 --- a/src/main/java/me/skymc/taboolib/message/ChatCatcher.java +++ b/src/main/java/me/skymc/taboolib/message/ChatCatcher.java @@ -1,17 +1,14 @@ package me.skymc.taboolib.message; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; - -import org.bukkit.Bukkit; +import lombok.Getter; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerQuitEvent; -import lombok.Getter; +import java.util.HashMap; +import java.util.LinkedList; public class ChatCatcher implements Listener { @@ -66,13 +63,13 @@ public class ChatCatcher implements Listener { playerdata.remove(player.getName()); } } - - public abstract interface Catcher { - - public abstract Catcher before(); - - public abstract boolean after(String message); - - public abstract void cancel(); + + public interface Catcher { + + Catcher before(); + + boolean after(String message); + + void cancel(); } } diff --git a/src/main/java/me/skymc/taboolib/methods/MethodsUtils.java b/src/main/java/me/skymc/taboolib/methods/MethodsUtils.java index 5007cd4..25f3f04 100644 --- a/src/main/java/me/skymc/taboolib/methods/MethodsUtils.java +++ b/src/main/java/me/skymc/taboolib/methods/MethodsUtils.java @@ -9,11 +9,7 @@ public class MethodsUtils { public static boolean checkUser(String packagename, String current) { - if (current.substring(0, 8).equals(packagename)) - { - return true; - } - return false; + return current.substring(0, 8).equals(packagename); } @SuppressWarnings("rawtypes") @@ -23,22 +19,14 @@ public class MethodsUtils { { throw new Error("未经允许的方法调用"); } - - Class clazz = classname.getClass(); + + Class clazz = classname.getClass(); Method method = null; try { method = clazz.getDeclaredMethod(methodname, classes); method.setAccessible(true); return new Object[] { method.invoke(classname, objects) }; - } catch (SecurityException e) { - e.printStackTrace(); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { + } catch (SecurityException | InvocationTargetException | IllegalAccessException | NoSuchMethodException | IllegalArgumentException e) { e.printStackTrace(); } return null; @@ -50,21 +38,15 @@ public class MethodsUtils { { throw new Error("未经允许的方法调用"); } - - Class clazz = classname.getClass(); + + Class clazz = classname.getClass(); Field field = null; Object object = null; try { field = clazz.getDeclaredField(fieldname); field.setAccessible(true); object = field.get(classname); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } catch (SecurityException e) { - e.printStackTrace(); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { + } catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException | SecurityException e) { e.printStackTrace(); } return object; diff --git a/src/main/java/me/skymc/taboolib/methods/ReflectionUtils.java b/src/main/java/me/skymc/taboolib/methods/ReflectionUtils.java index f87f4be..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 *

@@ -60,7 +60,6 @@ public final class ReflectionUtils { * @return The constructor of the desired target class with the specified parameter types * @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found * @throws ClassNotFoundException ClassNotFoundException If the desired target class with the specified name and package cannot be found - * @see #getClass(String, PackageType) * @see #getConstructor(Class, Class...) */ public static Constructor getConstructor(String className, PackageType packageType, Class... parameterTypes) throws NoSuchMethodException, ClassNotFoundException { @@ -96,7 +95,6 @@ public final class ReflectionUtils { * @throws InvocationTargetException If the desired constructor cannot be invoked * @throws NoSuchMethodException If the desired constructor with the specified arguments cannot be found * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found - * @see #getClass(String, PackageType) * @see #instantiateObject(Class, Object...) */ public static Object instantiateObject(String className, PackageType packageType, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { @@ -135,7 +133,6 @@ public final class ReflectionUtils { * @return The method of the desired target class with the specified name and parameter types * @throws NoSuchMethodException If the desired method of the desired target class with the specified name and parameter types cannot be found * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found - * @see #getClass(String, PackageType) * @see #getMethod(Class, String, Class...) */ public static Method getMethod(String className, PackageType packageType, String methodName, Class... parameterTypes) throws NoSuchMethodException, ClassNotFoundException { @@ -193,7 +190,6 @@ public final class ReflectionUtils { * @throws InvocationTargetException If the desired method cannot be invoked on the target object * @throws NoSuchMethodException If the desired method of the desired target class with the specified name and arguments cannot be found * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found - * @see #getClass(String, PackageType) * @see #invokeMethod(Object, Class, String, Object...) */ public static Object invokeMethod(Object instance, String className, PackageType packageType, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { @@ -380,7 +376,7 @@ public final class ReflectionUtils { * * @param path Path of the package */ - private PackageType(String path) { + PackageType(String path) { this.path = path; } @@ -390,7 +386,7 @@ public final class ReflectionUtils { * @param parent Parent package of the package * @param path Path of the package */ - private PackageType(PackageType parent, String path) { + PackageType(PackageType parent, String path) { this(parent + "." + path); } @@ -448,7 +444,7 @@ public final class ReflectionUtils { DOUBLE(double.class, Double.class), BOOLEAN(boolean.class, Boolean.class); - private static final Map, DataType> CLASS_MAP = new HashMap, DataType>(); + private static final Map, DataType> CLASS_MAP = new HashMap<>(); private final Class primitive; private final Class reference; @@ -466,7 +462,7 @@ public final class ReflectionUtils { * @param primitive Primitive class of this data type * @param reference Reference class of this data type */ - private DataType(Class primitive, Class reference) { + DataType(Class primitive, Class reference) { this.primitive = primitive; this.reference = reference; } @@ -554,7 +550,6 @@ public final class ReflectionUtils { /** * Returns the primitive class array of the given object array * - * @param object Given object array * @return The primitive class array */ public static Class[] getPrimitive(Object[] objects) { @@ -569,7 +564,6 @@ public final class ReflectionUtils { /** * Returns the reference class array of the given object array * - * @param object Given object array * @return The reference class array */ public static Class[] getReference(Object[] objects) { diff --git a/src/main/java/me/skymc/taboolib/mysql/MysqlConnection.java b/src/main/java/me/skymc/taboolib/mysql/MysqlConnection.java index 0aff42d..e22b8a3 100644 --- a/src/main/java/me/skymc/taboolib/mysql/MysqlConnection.java +++ b/src/main/java/me/skymc/taboolib/mysql/MysqlConnection.java @@ -1,17 +1,9 @@ package me.skymc.taboolib.mysql; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; import java.util.ArrayList; import java.util.List; -import org.bukkit.configuration.file.FileConfiguration; - -import com.mysql.jdbc.PreparedStatement; - @Deprecated public class MysqlConnection { @@ -56,8 +48,6 @@ public class MysqlConnection { } Thread.sleep(30000); - } catch (SQLException e) { - e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } @@ -120,10 +110,10 @@ public class MysqlConnection { for (int i = 0 ; i < list.length ; i++) { if (i + 1 < list.length) { - stringBuilder.append("`" + checkString(list[i]) + "` varchar(255), "); + stringBuilder.append("`").append(checkString(list[i])).append("` varchar(255), "); } else { - stringBuilder.append("`" + checkString(list[i]) + "` varchar(255)"); + stringBuilder.append("`").append(checkString(list[i])).append("` varchar(255)"); } } String url = "CREATE TABLE IF NOT EXISTS `" + table + "` ( " + stringBuilder + " )"; @@ -150,12 +140,12 @@ public class MysqlConnection { for (int i = 0 ; i < list.length ; i++) { if (i + 1 < list.length) { - listbuilder.append("`" + checkString(list[i]) + "`, "); - valuebuilder.append("'" + checkString(values[i]) + "', "); + listbuilder.append("`").append(checkString(list[i])).append("`, "); + valuebuilder.append("'").append(checkString(values[i])).append("', "); } else { - listbuilder.append("`" + checkString(list[i]) + "`"); - valuebuilder.append("'" + checkString(values[i]) + "'"); + listbuilder.append("`").append(checkString(list[i])).append("`"); + valuebuilder.append("'").append(checkString(values[i])).append("'"); } } diff --git a/src/main/java/me/skymc/taboolib/mysql/MysqlUtils.java b/src/main/java/me/skymc/taboolib/mysql/MysqlUtils.java index b76a16a..ebfe373 100644 --- a/src/main/java/me/skymc/taboolib/mysql/MysqlUtils.java +++ b/src/main/java/me/skymc/taboolib/mysql/MysqlUtils.java @@ -1,15 +1,12 @@ package me.skymc.taboolib.mysql; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.plugin.Plugin; - import me.skymc.taboolib.Main; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.mysql.protect.MySQLConnection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.Plugin; + +import java.util.concurrent.CopyOnWriteArrayList; public class MysqlUtils { diff --git a/src/main/java/me/skymc/taboolib/mysql/protect/MySQLConnection.java b/src/main/java/me/skymc/taboolib/mysql/protect/MySQLConnection.java index 601da3d..13046fb 100644 --- a/src/main/java/me/skymc/taboolib/mysql/protect/MySQLConnection.java +++ b/src/main/java/me/skymc/taboolib/mysql/protect/MySQLConnection.java @@ -1,20 +1,15 @@ package me.skymc.taboolib.mysql.protect; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; - -import org.bukkit.plugin.Plugin; - import lombok.Getter; import lombok.Setter; import me.skymc.taboolib.Main; +import org.bukkit.plugin.Plugin; + +import java.sql.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; public class MySQLConnection { @@ -69,25 +64,19 @@ public class MySQLConnection { connect(); // 断线检测 - recheckThread = new Thread(new Runnable() { - - @Override - public void run() { - while (!Main.isDisable()) { - try { - Thread.sleep(getReCheckSeconds() * 1000); - - if (connection == null) { - print("警告! 数据库尚未连接, 请检查配置文件后重启服务器! (" + (plugin.getName()) + ")"); - continue; - } - else { - isExists("taboolib"); - } - } catch (Exception e) { - print("数据库命令执行出错"); - print("错误原因: " + e.getMessage()); + recheckThread = new Thread(() -> { + while (!Main.isDisable()) { + try { + Thread.sleep(getReCheckSeconds() * 1000); + + if (connection == null) { + print("警告! 数据库尚未连接, 请检查配置文件后重启服务器! (" + (plugin.getName()) + ")"); + } else { + isExists("taboolib"); } + } catch (Exception e) { + print("数据库命令执行出错"); + print("错误原因: " + e.getMessage()); } } }); @@ -266,7 +255,7 @@ public class MySQLConnection { */ public boolean intoValue(String name, Object... values) { StringBuilder sb = new StringBuilder(); - for (int i = 0 ; i < values.length ; i++) { + for (Object value : values) { sb.append("?, "); } PreparedStatement pstmt = null; @@ -300,7 +289,7 @@ public class MySQLConnection { public boolean createTable(String name, Column... columns) { StringBuilder sb = new StringBuilder(); for (Column column : columns) { - sb.append(column.toString() + ", "); + sb.append(column.toString()).append(", "); } return execute("create table if not exists " + name + " (id int(1) not null primary key auto_increment, " + sb.substring(0, sb.length() - 2) + ")"); } @@ -316,9 +305,9 @@ public class MySQLConnection { StringBuilder sb = new StringBuilder(); for (String column : columns) { if (!column.contains("/")) { - sb.append("`" + column + "` text, "); + sb.append("`").append(column).append("` text, "); } else { - sb.append("`" + column.split("/")[0] + "` " + column.split("/")[1] + ", "); + sb.append("`").append(column.split("/")[0]).append("` ").append(column.split("/")[1]).append(", "); } } return execute("create table if not exists " + name + " (id int(1) not null primary key auto_increment, " + sb.substring(0, sb.length() - 2) + ")"); @@ -749,25 +738,25 @@ public class MySQLConnection { return false; } } - - public static enum ColumnInteger { - - TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT; + + public enum ColumnInteger { + + TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT } - - public static enum ColumnFloat { - - FLOAT, DOUBLE; + + public enum ColumnFloat { + + FLOAT, DOUBLE } - - public static enum ColumnChar { - - CHAR, VARCHAR; + + public enum ColumnChar { + + CHAR, VARCHAR } - - public static enum ColumnString { - - TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT; + + public enum ColumnString { + + TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT } public static class Column { diff --git a/src/main/java/me/skymc/taboolib/nms/NMSUtil18.java b/src/main/java/me/skymc/taboolib/nms/NMSUtil18.java index c31f568..274cf6f 100644 --- a/src/main/java/me/skymc/taboolib/nms/NMSUtil18.java +++ b/src/main/java/me/skymc/taboolib/nms/NMSUtil18.java @@ -1,10 +1,6 @@ package me.skymc.taboolib.nms; -import org.bukkit.Bukkit; -import org.bukkit.DyeColor; -import org.bukkit.Location; -import org.bukkit.Server; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.block.BlockFace; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.enchantments.Enchantment; @@ -915,7 +911,7 @@ public class NMSUtil18 { // Testing Glow API based on ItemMetadata storage Object bukkitData = createNode(stack, "bukkit"); class_NBTTagCompound_setBooleanMethod.invoke(bukkitData, "glow", true); - } catch (Throwable ex) { + } catch (Throwable ignored) { } } @@ -939,7 +935,7 @@ public class NMSUtil18 { if (bukkitData != null) { class_NBTTagCompound_setBooleanMethod.invoke(bukkitData, "glow", false); } - } catch (Throwable ex) { + } catch (Throwable ignored) { } } @@ -960,7 +956,7 @@ public class NMSUtil18 { unbreakableFlag = class_NBTTagByte_legacy_constructor.newInstance("", (byte) 1); } class_NBTTagCompound_setMethod.invoke(tagObject, "Unbreakable", unbreakableFlag); - } catch (Throwable ex) { + } catch (Throwable ignored) { } } @@ -985,7 +981,7 @@ public class NMSUtil18 { hideFlag = class_NBTTagByte_legacy_constructor.newInstance("", flags); } class_NBTTagCompound_setMethod.invoke(tagObject, "HideFlags", hideFlag); - } catch (Throwable ex) { + } catch (Throwable ignored) { } } diff --git a/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java b/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java index ac5a67f..4437f76 100644 --- a/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java +++ b/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java @@ -1,12 +1,7 @@ package me.skymc.taboolib.nms; 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; @@ -24,12 +19,7 @@ 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.*; import java.util.logging.Level; @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -1139,8 +1129,7 @@ public class NMSUtil19 { } public static boolean hasMeta(ItemStack stack, String tag) { - if (NMSUtil19.isEmpty(stack)) return false; - return getNode(stack, tag) != null; + return !NMSUtil19.isEmpty(stack) && getNode(stack, tag) != null; } public static Object getTag(ItemStack itemStack) { @@ -1474,7 +1463,7 @@ public class NMSUtil19 { Object tagObject = getTag(craft); if (tagObject == null) return false; unbreakableFlag = getMetaBoolean(tagObject, "Unbreakable"); - } catch (Throwable ex) { + } catch (Throwable ignored) { } @@ -1493,7 +1482,7 @@ public class NMSUtil19 { Object unbreakableFlag = null; unbreakableFlag = class_NBTTagByte_constructor.newInstance((byte) 1); class_NBTTagCompound_setMethod.invoke(tagObject, "Unbreakable", unbreakableFlag); - } catch (Throwable ex) { + } catch (Throwable ignored) { } } @@ -1514,7 +1503,7 @@ public class NMSUtil19 { Object hideFlag = null; hideFlag = class_NBTTagByte_constructor.newInstance(flags); class_NBTTagCompound_setMethod.invoke(tagObject, "HideFlags", hideFlag); - } catch (Throwable ex) { + } catch (Throwable ignored) { } } diff --git a/src/main/java/me/skymc/taboolib/nms/NMSUtils.java b/src/main/java/me/skymc/taboolib/nms/NMSUtils.java index 9cfb28b..c68b463 100644 --- a/src/main/java/me/skymc/taboolib/nms/NMSUtils.java +++ b/src/main/java/me/skymc/taboolib/nms/NMSUtils.java @@ -1,14 +1,11 @@ package me.skymc.taboolib.nms; +import org.bukkit.Bukkit; + import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Entity; public class NMSUtils { @@ -34,7 +31,7 @@ public class NMSUtils { for(String s : strings){ try{ return getClassWithException(s); - }catch(Exception e){ + } catch (Exception ignored) { } } return null; @@ -43,7 +40,7 @@ public class NMSUtils { public static Class getClassSilent(String name){ try{ return getClassWithException(name); - }catch(Exception e){ + } catch (Exception ignored) { } return null; } @@ -64,7 +61,7 @@ public class NMSUtils { public static Class getNMSClassSilent(String className){ try{ return getNMSClassWithException(className); - }catch(Exception e){ + } catch (Exception ignored) { } return null; } @@ -101,7 +98,7 @@ public class NMSUtils { public static Class getOBCClassSilent(String className){ try{ return getOBCClassWithException(className); - }catch(Exception e){ + } catch (Exception ignored) { } return null; } @@ -175,7 +172,7 @@ public class NMSUtils { for(String name : names){ try{ return getFieldWithException(clazz, name); - }catch(Exception e){ + } catch (Exception ignored) { } } return null; @@ -184,7 +181,7 @@ public class NMSUtils { public static Field getFieldSilent(Class clazz, String name){ try{ return getFieldWithException(clazz, name); - }catch(Exception e){ + } catch (Exception ignored) { } return null; } @@ -193,7 +190,7 @@ public class NMSUtils { for(String name : names){ try{ return getFieldWithException(clazz, name); - }catch(Exception e){ + } catch (Exception ignored) { } } return null; @@ -298,7 +295,7 @@ public class NMSUtils { public static Method getMethodSilent(Class clazz, String name, Class... args){ try{ return getMethodWithException(clazz, name, args); - }catch(Exception e){ + } catch (Exception ignored) { } return null; } @@ -331,7 +328,7 @@ public class NMSUtils { public static Class getInnerClassSilent(Class c, String className){ try{ return getInnerClassWithException(c, className); - }catch(Exception e){ + } catch (Exception ignored) { } return null; } @@ -353,7 +350,7 @@ public class NMSUtils { public static Constructor getConstructorSilent(Class clazz, Class... args){ try{ return getConstructor(clazz, args); - }catch(Exception e){ + } catch (Exception ignored) { } return null; } 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 9bf0060..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,22 +1,21 @@ package me.skymc.taboolib.nms.item; -import java.lang.reflect.Method; -import java.util.List; -import java.util.Map; - +import me.skymc.taboolib.Main; +import me.skymc.taboolib.json.JSONArray; +import me.skymc.taboolib.json.JSONObject; +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 me.skymc.taboolib.Main; -import me.skymc.taboolib.json.JSONArray; -import me.skymc.taboolib.json.JSONObject; -import me.skymc.taboolib.message.MsgUtils; -import me.skymc.taboolib.nms.item.impl._194ItemUtils; -import me.skymc.taboolib.nms.item.impl._164ItemUtils; -import me.skymc.taboolib.nms.item.impl._1710ItemUtils; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Map; public class DabItemUtils { @@ -32,21 +31,21 @@ public class DabItemUtils { inst.convertItemStackToJSON(is); MsgUtils.send("载入 1.9.4 Spigot 物品工具成功!"); return inst; - }catch(Exception e){ + } catch (Exception ignored) { } try{ _1710ItemUtils inst = new _1710ItemUtils(); inst.convertItemStackToJSON(is); MsgUtils.send("载入 1.7.10 Cauldron 物品工具成功!"); return inst; - }catch(Exception e){ + } catch (Exception ignored) { } try{ IDabItemUtils inst = new _164ItemUtils(); inst.convertItemStackToJSON(is); MsgUtils.send("载入 1.6.4 Cauldron 物品工具成功!"); return inst; - }catch(Exception e){ + } catch (Exception ignored) { } MsgUtils.send("&4物品工具载入失败, 插件已关闭!"); Bukkit.getPluginManager().disablePlugin(Main.getInst()); 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 81e59d0..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,102 +1,171 @@ 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 - public boolean hasBanner(); - public Object getNMSCopy(ItemStack is) throws Exception; - public boolean hasTag(Object is) throws Exception; - public ItemStack asCraftMirror(Object nis) throws Exception; - public ItemStack asBukkitCopy(Object nmis) throws Exception; - public String getName(ItemStack is); - public Object getItem(Object nis) throws Exception; - public Method getA(); - public String getRawName(ItemStack is); - public String getItemName(ItemStack is); - public Object getRegistry(); - public String getMinecraftName(ItemStack is); - public Object getTag(Object is) throws Exception; - public void setTag(Object is, Object tag1) throws Exception; - public boolean isEmpty(Object tag) throws Exception; - public Object getMap(Object tag) throws Exception; - public void set(Object tag, String key, Object value) throws Exception; - public void setString(Object tag, String key, String value) throws Exception; - public void setShort(Object tag, String key, short value) throws Exception; - public void setInt(Object tag, String key, int i) throws Exception; - public void setDouble(Object tag, String key, double d) throws Exception; - public void setLong(Object tag, String key, long l) throws Exception; - public boolean hasKey(Object tag, String key) throws Exception; - public Object get(Object tag, String key) throws Exception; - public String getString(Object tag, String key) throws Exception; - public int getInt(Object tag, String key) throws Exception; - public double getDouble(Object tag, String key) throws Exception; - public long getLong(Object tag, String key) throws Exception; - public short getShort(Object tag, String key) throws Exception; - public Object getNewNBTTagCompound() throws Exception; - public boolean hasAttributeModifiersKey(Object tag) throws Exception; - public Object getList(Object tag) throws Exception; - public Object getList(Object tag, String name, int id) throws Exception; - public boolean getUnbreakable(Object tag) throws Exception; - public void setUnbreakable(Object tag, boolean value) throws Exception; - public Object getNewNBTTagList() throws Exception; - public void addToList(Object taglist, Object nbt) throws Exception; - public int getSize(Object list) throws Exception; - public Object get(Object tlist, int i) throws Exception; - public Object getNewNBTTagByte(byte value) throws Exception; - public Object getNewNBTTagByteArray(byte[] value) throws Exception; - public Object getData(Object nbt) throws Exception; - public Object createData(Object value) throws Exception; - public Map convertCompoundTagToValueMap(Object nbt) throws Exception; - public List convertListTagToValueList(Object nbttl) throws Exception; - public Object convertValueMapToCompoundTag(Map map) throws Exception; - public Object convertValueListToListTag(List list) throws Exception; + boolean hasBanner(); + + Object getNMSCopy(ItemStack is) throws Exception; + + boolean hasTag(Object is) throws Exception; + + ItemStack asCraftMirror(Object nis) throws Exception; + + ItemStack asBukkitCopy(Object nmis) throws Exception; + + String getName(ItemStack is); + + Object getItem(Object nis) throws Exception; + + Method getA(); + + String getRawName(ItemStack is); + + String getItemName(ItemStack is); + + Object getRegistry(); + + String getMinecraftName(ItemStack is); + + Object getTag(Object is) throws Exception; + + void setTag(Object is, Object tag1) throws Exception; + + boolean isEmpty(Object tag) throws Exception; + + Object getMap(Object tag) throws Exception; + + void set(Object tag, String key, Object value) throws Exception; + + void setString(Object tag, String key, String value) throws Exception; + + void setShort(Object tag, String key, short value) throws Exception; + + void setInt(Object tag, String key, int i) throws Exception; + + void setDouble(Object tag, String key, double d) throws Exception; + + void setLong(Object tag, String key, long l) throws Exception; + + boolean hasKey(Object tag, String key) throws Exception; + + Object get(Object tag, String key) throws Exception; + + String getString(Object tag, String key) throws Exception; + + int getInt(Object tag, String key) throws Exception; + + double getDouble(Object tag, String key) throws Exception; + + long getLong(Object tag, String key) throws Exception; + + short getShort(Object tag, String key) throws Exception; + + Object getNewNBTTagCompound() throws Exception; + + boolean hasAttributeModifiersKey(Object tag) throws Exception; + + Object getList(Object tag) throws Exception; + + Object getList(Object tag, String name, int id) throws Exception; + + boolean getUnbreakable(Object tag) throws Exception; + + void setUnbreakable(Object tag, boolean value) throws Exception; + + Object getNewNBTTagList() throws Exception; + + void addToList(Object taglist, Object nbt) throws Exception; + + int getSize(Object list) throws Exception; + + Object get(Object tlist, int i) throws Exception; + + Object getNewNBTTagByte(byte value) throws Exception; + + Object getNewNBTTagByteArray(byte[] value) throws Exception; + + Object getData(Object nbt) throws Exception; + + Object createData(Object value) throws Exception; + + Map convertCompoundTagToValueMap(Object nbt) throws Exception; + + List convertListTagToValueList(Object nbttl) throws Exception; + + Object convertValueMapToCompoundTag(Map map) throws Exception; + + Object convertValueListToListTag(List list) throws Exception; @Deprecated - public void convertListTagToJSON(Object nbttl, JSONArray ja, JSONArray helper) throws Exception; - public void convertListTagToJSON(Object nbttl, JSONArray ja) throws Exception; + void convertListTagToJSON(Object nbttl, JSONArray ja, JSONArray helper) throws Exception; + + void convertListTagToJSON(Object nbttl, JSONArray ja) throws Exception; @Deprecated - public void convertCompoundTagToJSON(Object nbt, JSONObject jo, JSONObject helper) throws Exception; - public void convertCompoundTagToJSON(Object nbt, JSONObject jo) throws Exception; + void convertCompoundTagToJSON(Object nbt, JSONObject jo, JSONObject helper) throws Exception; + + void convertCompoundTagToJSON(Object nbt, JSONObject jo) throws Exception; @Deprecated - public Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception; - public Object convertJSONToCompoundTag(JSONObject jo) throws Exception; + Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception; + + Object convertJSONToCompoundTag(JSONObject jo) throws Exception; @Deprecated - public Object convertJSONToListTag(JSONArray ja, JSONArray helper) throws Exception; - public Object convertJSONToListTag(JSONArray ja) throws Exception; + Object convertJSONToListTag(JSONArray ja, JSONArray helper) throws Exception; + + Object convertJSONToListTag(JSONArray ja) throws Exception; @Deprecated - public Object getDataJSON(String key, Object nbt, JSONObject jo, JSONObject helper) throws Exception; - public JSONArray getDataJSON(Object nbt) throws Exception; + Object getDataJSON(String key, Object nbt, JSONObject jo, JSONObject helper) throws Exception; + + JSONArray getDataJSON(Object nbt) throws Exception; @Deprecated - public Object getDataJSON(Object nbt, JSONArray ja, JSONArray helper) throws Exception; + Object getDataJSON(Object nbt, JSONArray ja, JSONArray helper) throws Exception; @Deprecated - public Object createDataJSON(String key, JSONObject jo, JSONObject helper) throws Exception; - public Object createDataJSON(String key, JSONObject jo) throws Exception; - public byte getByte(Object o); - public short getShort(Object o); - public int getInt(Object o); - public double getDouble(Object o); - public float getFloat(Object o); - public long getLong(Object o); + Object createDataJSON(String key, JSONObject jo, JSONObject helper) throws Exception; + + Object createDataJSON(String key, JSONObject jo) throws Exception; + + byte getByte(Object o); + + short getShort(Object o); + + int getInt(Object o); + + double getDouble(Object o); + + float getFloat(Object o); + + long getLong(Object o); @Deprecated - public Object createDataJSON(int key, JSONArray jo, JSONArray helper) throws Exception; - public Object createDataJSON(int key, JSONArray jo) throws Exception; - public boolean compareBaseTag(Object tag, Object tag1) throws Exception; - public boolean compareCompoundTag(Object tag, Object tag1) throws Exception; - public boolean compareListTag(Object tag, Object tag1) throws Exception; - public boolean compare(ItemStack is1, ItemStack is2); - public boolean canMerge(ItemStack add, ItemStack to); - public boolean isModified(ItemStack is); - public void sortByMaterial(List items); - public void sortByName(List items); - public void sortByAmount(List items); - public ItemStack convertJSONToItemStack(JSONObject jo) throws Exception; - public JSONObject convertItemStackToJSON(ItemStack is) throws Exception; + Object createDataJSON(int key, JSONArray jo, JSONArray helper) throws Exception; + + Object createDataJSON(int key, JSONArray jo) throws Exception; + + boolean compareBaseTag(Object tag, Object tag1) throws Exception; + + boolean compareCompoundTag(Object tag, Object tag1) throws Exception; + + boolean compareListTag(Object tag, Object tag1) throws Exception; + + boolean compare(ItemStack is1, ItemStack is2); + + boolean canMerge(ItemStack add, ItemStack to); + + boolean isModified(ItemStack is); + + void sortByMaterial(List items); + + void sortByName(List items); + + void sortByAmount(List items); + + ItemStack convertJSONToItemStack(JSONObject jo) throws Exception; + + JSONObject convertItemStackToJSON(ItemStack is) throws Exception; } diff --git a/src/main/java/me/skymc/taboolib/nms/item/impl/_164ItemUtils.java b/src/main/java/me/skymc/taboolib/nms/item/impl/_164ItemUtils.java index 9d468cb..9f92980 100644 --- a/src/main/java/me/skymc/taboolib/nms/item/impl/_164ItemUtils.java +++ b/src/main/java/me/skymc/taboolib/nms/item/impl/_164ItemUtils.java @@ -1,26 +1,19 @@ package me.skymc.taboolib.nms.item.impl; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.UUID; - +import me.skymc.taboolib.json.JSONArray; +import me.skymc.taboolib.json.JSONObject; +import me.skymc.taboolib.nms.NMSUtils; +import me.skymc.taboolib.nms.item.IDabItemUtils; +import me.skymc.taboolib.nms.nbt.NBTConstants; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import me.skymc.taboolib.json.*; -import me.skymc.taboolib.nms.NMSUtils; -import me.skymc.taboolib.nms.item.IDabItemUtils; -import me.skymc.taboolib.nms.nbt.NBTConstants; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.*; +import java.util.Map.Entry; public class _164ItemUtils implements IDabItemUtils{ @@ -30,7 +23,7 @@ public class _164ItemUtils implements IDabItemUtils{ try{ Material m = Material.valueOf("BANNER"); if(m != null){ return true; } - }catch(Exception e){ + } catch (Exception ignored) { } return false; } @@ -110,7 +103,7 @@ public class _164ItemUtils implements IDabItemUtils{ public Object getRegistry(){ try{ return NMSUtils.getFieldSilent(ni, "REGISTRY", "field_150901_e").get(null); - }catch(Exception e){ + } catch (Exception ignored) { } return null; } @@ -376,7 +369,7 @@ public class _164ItemUtils implements IDabItemUtils{ @SuppressWarnings({ "unchecked" }) public Map convertCompoundTagToValueMap(Object nbt) throws Exception{ - Map ret = new HashMap(); + Map ret = new HashMap<>(); Map map = (Map)getMap(nbt); for(Entry e : map.entrySet()){ Object nbti = e.getValue(); @@ -390,7 +383,7 @@ public class _164ItemUtils implements IDabItemUtils{ @SuppressWarnings("unchecked") public List convertListTagToValueList(Object nbttl) throws Exception{ - List ret = new ArrayList(); + List ret = new ArrayList<>(); List list = (List)nbtld.get(nbttl); for(Object e : list){ Object data = getData(e); @@ -402,7 +395,7 @@ public class _164ItemUtils implements IDabItemUtils{ } public Object convertValueMapToCompoundTag(Map map) throws Exception{ - Map value = new HashMap(); + Map value = new HashMap<>(); for(Entry e : map.entrySet()){ value.put(e.getKey(), createData(e.getValue())); } @@ -412,14 +405,14 @@ public class _164ItemUtils implements IDabItemUtils{ } public Object convertValueListToListTag(List list) throws Exception{ - List value = new ArrayList(); + List value = new ArrayList<>(); for(Object e : list){ value.add(createData(e)); } Object ret = getNewNBTTagList(); nbttcm.set(ret, value); if(value.size() > 0){ - nbtlt.set(ret, (byte)gti.invoke(value.get(0))); + nbtlt.set(ret, gti.invoke(value.get(0))); } return ret; } @@ -475,7 +468,7 @@ public class _164ItemUtils implements IDabItemUtils{ @Deprecated @SuppressWarnings("unchecked") public Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception{ - Map value = new HashMap(); + Map value = new HashMap<>(); Iterator it = jo.keys(); while(it.hasNext()){ String e = it.next(); @@ -488,7 +481,7 @@ public class _164ItemUtils implements IDabItemUtils{ @SuppressWarnings("unchecked") public Object convertJSONToCompoundTag(JSONObject jo) throws Exception{ - Map value = new HashMap(); + Map value = new HashMap<>(); Iterator it = jo.keys(); while(it.hasNext()){ String e = it.next(); @@ -509,7 +502,7 @@ public class _164ItemUtils implements IDabItemUtils{ Object ret = getNewNBTTagList(); nbtld.set(ret, value); if(value.size() > 0){ - nbtlt.set(ret, (byte)gti.invoke(value.get(0))); + nbtlt.set(ret, gti.invoke(value.get(0))); } return ret; } @@ -523,7 +516,7 @@ public class _164ItemUtils implements IDabItemUtils{ Object ret = getNewNBTTagList(); nbtld.set(ret, value); if(value.size() > 0){ - nbtlt.set(ret, (byte)gti.invoke(value.get(0))); + nbtlt.set(ret, gti.invoke(value.get(0))); } return ret; } @@ -742,7 +735,7 @@ public class _164ItemUtils implements IDabItemUtils{ public Object createDataJSON(String key, JSONObject jo) throws Exception{ JSONArray j = jo.getJSONArray(key); Object ret = null; - int i = (int)j.getInt(0); + int i = j.getInt(0); switch(i){ case NBTConstants.TYPE_COMPOUND: ret = convertJSONToCompoundTag(j.getJSONObject(1)); @@ -889,7 +882,7 @@ public class _164ItemUtils implements IDabItemUtils{ public Object createDataJSON(int key, JSONArray jo) throws Exception{ JSONArray j = jo.getJSONArray(key); Object ret = null; - int i = (int)j.getInt(0); + int i = j.getInt(0); switch(i){ case NBTConstants.TYPE_COMPOUND: ret = convertJSONToCompoundTag(j.getJSONObject(1)); @@ -970,7 +963,7 @@ public class _164ItemUtils implements IDabItemUtils{ case NBTConstants.TYPE_BYTE_ARRAY: byte[] ba = (byte[])nbtbad.get(tag); byte[] ba1 = (byte[])nbtbad.get(tag1); - return ba.equals(ba1); + return Arrays.equals(ba, ba1); case NBTConstants.TYPE_STRING: String st = (String)nbtstd.get(tag); String st1 = (String)nbtstd.get(tag1); @@ -983,7 +976,7 @@ public class _164ItemUtils implements IDabItemUtils{ case NBTConstants.TYPE_INT_ARRAY: int[] ia = (int[])nbtiad.get(tag); int[] ia1 = (int[])nbtiad.get(tag); - return ia.equals(ia1); + return Arrays.equals(ia, ia1); } return false; } @@ -1028,8 +1021,7 @@ public class _164ItemUtils implements IDabItemUtils{ cont = true; break; } - ; - } + } if(!cont) return false; } @@ -1041,7 +1033,7 @@ public class _164ItemUtils implements IDabItemUtils{ } public Map getAttributes(Object attribs) throws Exception{ - Map r = new HashMap(); + Map r = new HashMap<>(); for(int i = 0; i < getSize(attribs); i++){ Object compound = g.invoke(attribs, i); Object attrib = a.invoke(null, compound); @@ -1058,23 +1050,18 @@ public class _164ItemUtils implements IDabItemUtils{ public boolean compare(ItemStack is1, ItemStack is2){ if(is1.getType().equals(is2.getType())){ if(is1.getDurability() == is2.getDurability()){ - try{ + try { Object nis1 = getNMSCopy(is1); Object nis2 = getNMSCopy(is2); Object tis1 = getTag(nis1); Object tis2 = getTag(nis2); - if(tis1 != null && tis2 == null){ - if(isEmpty(tis1)) - return true; - return false; + if (tis1 != null && tis2 == null) { + return isEmpty(tis1); } - if(tis1 == null && tis2 != null){ - if(isEmpty(tis2)) - return true; - return false; + if (tis1 == null && tis2 != null) { + return isEmpty(tis2); } - if(tis1 == null && tis2 == null){ return true; } - return compareCompoundTag(tis1, tis2); + return tis1 == null && tis2 == null || compareCompoundTag(tis1, tis2); }catch(Exception e){ e.printStackTrace(); } @@ -1095,7 +1082,7 @@ public class _164ItemUtils implements IDabItemUtils{ } public void sortByMaterial(List items){ - Collections.sort(items, new MaterialComparator()); + items.sort(new MaterialComparator()); } public class MaterialComparator implements Comparator{ @@ -1106,7 +1093,7 @@ public class _164ItemUtils implements IDabItemUtils{ } public void sortByName(List items){ - Collections.sort(items, new NameComparator()); + items.sort(new NameComparator()); } public class NameComparator implements Comparator{ @@ -1123,7 +1110,7 @@ public class _164ItemUtils implements IDabItemUtils{ } public void sortByAmount(List items){ - Collections.sort(items, new AmountComparator()); + items.sort(new AmountComparator()); } public class AmountComparator implements Comparator{ diff --git a/src/main/java/me/skymc/taboolib/nms/item/impl/_1710ItemUtils.java b/src/main/java/me/skymc/taboolib/nms/item/impl/_1710ItemUtils.java index 1ff302b..8914883 100644 --- a/src/main/java/me/skymc/taboolib/nms/item/impl/_1710ItemUtils.java +++ b/src/main/java/me/skymc/taboolib/nms/item/impl/_1710ItemUtils.java @@ -1,25 +1,19 @@ package me.skymc.taboolib.nms.item.impl; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - +import me.skymc.taboolib.json.JSONArray; +import me.skymc.taboolib.json.JSONObject; +import me.skymc.taboolib.nms.NMSUtils; +import me.skymc.taboolib.nms.item.IDabItemUtils; +import me.skymc.taboolib.nms.nbt.NBTConstants; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import me.skymc.taboolib.json.*; -import me.skymc.taboolib.nms.NMSUtils; -import me.skymc.taboolib.nms.item.IDabItemUtils; -import me.skymc.taboolib.nms.nbt.NBTConstants; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.*; +import java.util.Map.Entry; public class _1710ItemUtils implements IDabItemUtils{ @@ -29,7 +23,7 @@ public class _1710ItemUtils implements IDabItemUtils{ try{ Material m = Material.valueOf("BANNER"); if(m != null){ return true; } - }catch(Exception e){ + } catch (Exception ignored) { } return false; } @@ -109,7 +103,7 @@ public class _1710ItemUtils implements IDabItemUtils{ public Object getRegistry(){ try{ return NMSUtils.getFieldSilent(ni, "REGISTRY", "field_150901_e").get(null); - }catch(Exception e){ + } catch (Exception ignored) { } return null; } @@ -374,7 +368,7 @@ public class _1710ItemUtils implements IDabItemUtils{ @SuppressWarnings({ "unchecked" }) public Map convertCompoundTagToValueMap(Object nbt) throws Exception{ - Map ret = new HashMap(); + Map ret = new HashMap<>(); Map map = (Map)getMap(nbt); for(Entry e : map.entrySet()){ Object nbti = e.getValue(); @@ -388,7 +382,7 @@ public class _1710ItemUtils implements IDabItemUtils{ @SuppressWarnings("unchecked") public List convertListTagToValueList(Object nbttl) throws Exception{ - List ret = new ArrayList(); + List ret = new ArrayList<>(); List list = (List)nbtld.get(nbttl); for(Object e : list){ Object data = getData(e); @@ -400,7 +394,7 @@ public class _1710ItemUtils implements IDabItemUtils{ } public Object convertValueMapToCompoundTag(Map map) throws Exception{ - Map value = new HashMap(); + Map value = new HashMap<>(); for(Entry e : map.entrySet()){ value.put(e.getKey(), createData(e.getValue())); } @@ -410,14 +404,14 @@ public class _1710ItemUtils implements IDabItemUtils{ } public Object convertValueListToListTag(List list) throws Exception{ - List value = new ArrayList(); + List value = new ArrayList<>(); for(Object e : list){ value.add(createData(e)); } Object ret = getNewNBTTagList(); nbttcm.set(ret, value); if(value.size() > 0){ - nbtlt.set(ret, (byte)gti.invoke(value.get(0))); + nbtlt.set(ret, gti.invoke(value.get(0))); } return ret; } @@ -473,7 +467,7 @@ public class _1710ItemUtils implements IDabItemUtils{ @Deprecated @SuppressWarnings("unchecked") public Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception{ - Map value = new HashMap(); + Map value = new HashMap<>(); Iterator it = jo.keys(); while(it.hasNext()){ String e = it.next(); @@ -486,7 +480,7 @@ public class _1710ItemUtils implements IDabItemUtils{ @SuppressWarnings("unchecked") public Object convertJSONToCompoundTag(JSONObject jo) throws Exception{ - Map value = new HashMap(); + Map value = new HashMap<>(); Iterator it = jo.keys(); while(it.hasNext()){ String e = it.next(); @@ -507,7 +501,7 @@ public class _1710ItemUtils implements IDabItemUtils{ Object ret = getNewNBTTagList(); nbtld.set(ret, value); if(value.size() > 0){ - nbtlt.set(ret, (byte)gti.invoke(value.get(0))); + nbtlt.set(ret, gti.invoke(value.get(0))); } return ret; } @@ -521,7 +515,7 @@ public class _1710ItemUtils implements IDabItemUtils{ Object ret = getNewNBTTagList(); nbtld.set(ret, value); if(value.size() > 0){ - nbtlt.set(ret, (byte)gti.invoke(value.get(0))); + nbtlt.set(ret, gti.invoke(value.get(0))); } return ret; } @@ -740,7 +734,7 @@ public class _1710ItemUtils implements IDabItemUtils{ public Object createDataJSON(String key, JSONObject jo) throws Exception{ JSONArray j = jo.getJSONArray(key); Object ret = null; - int i = (int)j.getInt(0); + int i = j.getInt(0); switch(i){ case NBTConstants.TYPE_COMPOUND: ret = convertJSONToCompoundTag(j.getJSONObject(1)); @@ -887,7 +881,7 @@ public class _1710ItemUtils implements IDabItemUtils{ public Object createDataJSON(int key, JSONArray jo) throws Exception{ JSONArray j = jo.getJSONArray(key); Object ret = null; - int i = (int)j.getInt(0); + int i = j.getInt(0); switch(i){ case NBTConstants.TYPE_COMPOUND: ret = convertJSONToCompoundTag(j.getJSONObject(1)); @@ -968,7 +962,7 @@ public class _1710ItemUtils implements IDabItemUtils{ case NBTConstants.TYPE_BYTE_ARRAY: byte[] ba = (byte[])nbtbad.get(tag); byte[] ba1 = (byte[])nbtbad.get(tag1); - return ba.equals(ba1); + return Arrays.equals(ba, ba1); case NBTConstants.TYPE_STRING: String st = (String)nbtstd.get(tag); String st1 = (String)nbtstd.get(tag1); @@ -981,7 +975,7 @@ public class _1710ItemUtils implements IDabItemUtils{ case NBTConstants.TYPE_INT_ARRAY: int[] ia = (int[])nbtiad.get(tag); int[] ia1 = (int[])nbtiad.get(tag); - return ia.equals(ia1); + return Arrays.equals(ia, ia1); } return false; } @@ -1027,23 +1021,18 @@ public class _1710ItemUtils implements IDabItemUtils{ public boolean compare(ItemStack is1, ItemStack is2){ if(is1.getType().equals(is2.getType())){ if(is1.getDurability() == is2.getDurability()){ - try{ + try { Object nis1 = getNMSCopy(is1); Object nis2 = getNMSCopy(is2); Object tis1 = getTag(nis1); Object tis2 = getTag(nis2); - if(tis1 != null && tis2 == null){ - if(isEmpty(tis1)) - return true; - return false; + if (tis1 != null && tis2 == null) { + return isEmpty(tis1); } - if(tis1 == null && tis2 != null){ - if(isEmpty(tis2)) - return true; - return false; + if (tis1 == null && tis2 != null) { + return isEmpty(tis2); } - if(tis1 == null && tis2 == null){ return true; } - return compareCompoundTag(tis1, tis2); + return tis1 == null && tis2 == null || compareCompoundTag(tis1, tis2); }catch(Exception e){ e.printStackTrace(); } @@ -1064,7 +1053,7 @@ public class _1710ItemUtils implements IDabItemUtils{ } public void sortByMaterial(List items){ - Collections.sort(items, new MaterialComparator()); + items.sort(new MaterialComparator()); } public class MaterialComparator implements Comparator{ @@ -1075,7 +1064,7 @@ public class _1710ItemUtils implements IDabItemUtils{ } public void sortByName(List items){ - Collections.sort(items, new NameComparator()); + items.sort(new NameComparator()); } public class NameComparator implements Comparator{ @@ -1092,7 +1081,7 @@ public class _1710ItemUtils implements IDabItemUtils{ } public void sortByAmount(List items){ - Collections.sort(items, new AmountComparator()); + items.sort(new AmountComparator()); } public class AmountComparator implements Comparator{ diff --git a/src/main/java/me/skymc/taboolib/nms/item/impl/_194ItemUtils.java b/src/main/java/me/skymc/taboolib/nms/item/impl/_194ItemUtils.java index 8bc912b..aab3be4 100644 --- a/src/main/java/me/skymc/taboolib/nms/item/impl/_194ItemUtils.java +++ b/src/main/java/me/skymc/taboolib/nms/item/impl/_194ItemUtils.java @@ -1,25 +1,19 @@ package me.skymc.taboolib.nms.item.impl; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - +import me.skymc.taboolib.json.JSONArray; +import me.skymc.taboolib.json.JSONObject; +import me.skymc.taboolib.nms.NMSUtils; +import me.skymc.taboolib.nms.item.IDabItemUtils; +import me.skymc.taboolib.nms.nbt.NBTConstants; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import me.skymc.taboolib.json.*; -import me.skymc.taboolib.nms.NMSUtils; -import me.skymc.taboolib.nms.item.IDabItemUtils; -import me.skymc.taboolib.nms.nbt.NBTConstants; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.*; +import java.util.Map.Entry; public class _194ItemUtils implements IDabItemUtils{ @@ -29,7 +23,7 @@ public class _194ItemUtils implements IDabItemUtils{ try{ Material m = Material.valueOf("BANNER"); if(m != null){ return true; } - }catch(Exception e){ + } catch (Exception ignored) { } return false; } @@ -113,7 +107,7 @@ public class _194ItemUtils implements IDabItemUtils{ public Object getRegistry(){ try{ return NMSUtils.getFieldSilent(ni, "REGISTRY").get(null); - }catch(Exception e){ + } catch (Exception ignored) { } return null; } @@ -375,7 +369,7 @@ public class _194ItemUtils implements IDabItemUtils{ @SuppressWarnings({ "unchecked" }) public Map convertCompoundTagToValueMap(Object nbt) throws Exception{ - Map ret = new HashMap(); + Map ret = new HashMap<>(); Map map = (Map)getMap(nbt); for(Entry e : map.entrySet()){ Object nbti = e.getValue(); @@ -389,7 +383,7 @@ public class _194ItemUtils implements IDabItemUtils{ @SuppressWarnings("unchecked") public List convertListTagToValueList(Object nbttl) throws Exception{ - List ret = new ArrayList(); + List ret = new ArrayList<>(); List list = (List)nbtld.get(nbttl); for(Object e : list){ Object data = getData(e); @@ -401,7 +395,7 @@ public class _194ItemUtils implements IDabItemUtils{ } public Object convertValueMapToCompoundTag(Map map) throws Exception{ - Map value = new HashMap(); + Map value = new HashMap<>(); for(Entry e : map.entrySet()){ value.put(e.getKey(), createData(e.getValue())); } @@ -411,14 +405,14 @@ public class _194ItemUtils implements IDabItemUtils{ } public Object convertValueListToListTag(List list) throws Exception{ - List value = new ArrayList(); + List value = new ArrayList<>(); for(Object e : list){ value.add(createData(e)); } Object ret = getNewNBTTagList(); nbttcm.set(ret, value); if(value.size() > 0){ - nbtlt.set(ret, (byte)gti.invoke(value.get(0))); + nbtlt.set(ret, gti.invoke(value.get(0))); } return ret; } @@ -474,7 +468,7 @@ public class _194ItemUtils implements IDabItemUtils{ @SuppressWarnings("unchecked") @Deprecated public Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception{ - Map value = new HashMap(); + Map value = new HashMap<>(); Iterator it = jo.keys(); while(it.hasNext()){ String e = it.next(); @@ -487,7 +481,7 @@ public class _194ItemUtils implements IDabItemUtils{ @SuppressWarnings("unchecked") public Object convertJSONToCompoundTag(JSONObject jo) throws Exception{ - Map value = new HashMap(); + Map value = new HashMap<>(); Iterator it = jo.keys(); while(it.hasNext()){ String e = it.next(); @@ -508,7 +502,7 @@ public class _194ItemUtils implements IDabItemUtils{ Object ret = getNewNBTTagList(); nbtld.set(ret, value); if(value.size() > 0){ - nbtlt.set(ret, (byte)gti.invoke(value.get(0))); + nbtlt.set(ret, gti.invoke(value.get(0))); } return ret; } @@ -522,7 +516,7 @@ public class _194ItemUtils implements IDabItemUtils{ Object ret = getNewNBTTagList(); nbtld.set(ret, value); if(value.size() > 0){ - nbtlt.set(ret, (byte)gti.invoke(value.get(0))); + nbtlt.set(ret, gti.invoke(value.get(0))); } return ret; } @@ -743,7 +737,7 @@ public class _194ItemUtils implements IDabItemUtils{ public Object createDataJSON(String key, JSONObject jo) throws Exception{ JSONArray j = jo.getJSONArray(key); Object ret = null; - int i = (int)j.getInt(0); + int i = j.getInt(0); switch(i){ case NBTConstants.TYPE_COMPOUND: ret = convertJSONToCompoundTag(j.getJSONObject(1)); @@ -891,7 +885,7 @@ public class _194ItemUtils implements IDabItemUtils{ public Object createDataJSON(int key, JSONArray jo) throws Exception{ JSONArray j = jo.getJSONArray(key); Object ret = null; - int i = (int)j.getInt(0); + int i = j.getInt(0); switch(i){ case NBTConstants.TYPE_COMPOUND: ret = convertJSONToCompoundTag(j.getJSONObject(1)); @@ -972,7 +966,7 @@ public class _194ItemUtils implements IDabItemUtils{ case NBTConstants.TYPE_BYTE_ARRAY: byte[] ba = (byte[])nbtbad.get(tag); byte[] ba1 = (byte[])nbtbad.get(tag1); - return ba.equals(ba1); + return Arrays.equals(ba, ba1); case NBTConstants.TYPE_STRING: String st = (String)nbtstd.get(tag); String st1 = (String)nbtstd.get(tag1); @@ -985,7 +979,7 @@ public class _194ItemUtils implements IDabItemUtils{ case NBTConstants.TYPE_INT_ARRAY: int[] ia = (int[])nbtiad.get(tag); int[] ia1 = (int[])nbtiad.get(tag); - return ia.equals(ia1); + return Arrays.equals(ia, ia1); } return false; } @@ -1030,7 +1024,6 @@ public class _194ItemUtils implements IDabItemUtils{ cont = true; break; } - ; } if(!cont) return false; @@ -1041,23 +1034,18 @@ public class _194ItemUtils implements IDabItemUtils{ public boolean compare(ItemStack is1, ItemStack is2){ if(is1.getType().equals(is2.getType())){ if(is1.getDurability() == is2.getDurability()){ - try{ + try { Object nis1 = getNMSCopy(is1); Object nis2 = getNMSCopy(is2); Object tis1 = getTag(nis1); Object tis2 = getTag(nis2); - if(tis1 != null && tis2 == null){ - if(isEmpty(tis1)) - return true; - return false; + if (tis1 != null && tis2 == null) { + return isEmpty(tis1); } - if(tis1 == null && tis2 != null){ - if(isEmpty(tis2)) - return true; - return false; + if (tis1 == null && tis2 != null) { + return isEmpty(tis2); } - if(tis1 == null && tis2 == null){ return true; } - return compareCompoundTag(tis1, tis2); + return tis1 == null && tis2 == null || compareCompoundTag(tis1, tis2); }catch(Exception e){ e.printStackTrace(); } @@ -1078,7 +1066,7 @@ public class _194ItemUtils implements IDabItemUtils{ } public void sortByMaterial(List items){ - Collections.sort(items, new MaterialComparator()); + items.sort(new MaterialComparator()); } public class MaterialComparator implements Comparator{ @@ -1089,7 +1077,7 @@ public class _194ItemUtils implements IDabItemUtils{ } public void sortByName(List items){ - Collections.sort(items, new NameComparator()); + items.sort(new NameComparator()); } public class NameComparator implements Comparator{ @@ -1106,7 +1094,7 @@ public class _194ItemUtils implements IDabItemUtils{ } public void sortByAmount(List items){ - Collections.sort(items, new AmountComparator()); + items.sort(new AmountComparator()); } public class AmountComparator implements Comparator{ diff --git a/src/main/java/me/skymc/taboolib/other/DateUtils.java b/src/main/java/me/skymc/taboolib/other/DateUtils.java index a48c4f3..4f8d5fa 100644 --- a/src/main/java/me/skymc/taboolib/other/DateUtils.java +++ b/src/main/java/me/skymc/taboolib/other/DateUtils.java @@ -4,9 +4,6 @@ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.plugin.java.JavaPlugin; - public class DateUtils { /** diff --git a/src/main/java/me/skymc/taboolib/other/NumberUtils.java b/src/main/java/me/skymc/taboolib/other/NumberUtils.java index f8ed298..695cada 100644 --- a/src/main/java/me/skymc/taboolib/other/NumberUtils.java +++ b/src/main/java/me/skymc/taboolib/other/NumberUtils.java @@ -3,8 +3,6 @@ package me.skymc.taboolib.other; import java.text.DecimalFormat; import java.util.Random; -import me.skymc.taboolib.methods.MethodsUtils; - public class NumberUtils { private static Random rand = new Random(); @@ -25,7 +23,7 @@ public class NumberUtils { @Deprecated public static boolean getChance(int a) { - return getRandom() <= a ? true : false; + return getRandom() <= a; } public static int getRandomInteger(Number l, Number u) { diff --git a/src/main/java/me/skymc/taboolib/other/WeightUtils.java b/src/main/java/me/skymc/taboolib/other/WeightUtils.java index 657d721..3083104 100644 --- a/src/main/java/me/skymc/taboolib/other/WeightUtils.java +++ b/src/main/java/me/skymc/taboolib/other/WeightUtils.java @@ -1,11 +1,9 @@ package me.skymc.taboolib.other; -import java.util.List; -import java.util.Random; - -import me.skymc.taboolib.Main; import me.skymc.taboolib.object.WeightCategory; +import java.util.List; + public class WeightUtils { public static String getStringByWeight(List categorys) { diff --git a/src/main/java/me/skymc/taboolib/packet/PacketUtils.java b/src/main/java/me/skymc/taboolib/packet/PacketUtils.java index aae1a85..2624085 100644 --- a/src/main/java/me/skymc/taboolib/packet/PacketUtils.java +++ b/src/main/java/me/skymc/taboolib/packet/PacketUtils.java @@ -1,12 +1,11 @@ package me.skymc.taboolib.packet; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.WrappedDataWatcher; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; public class PacketUtils { @@ -20,33 +19,35 @@ public class PacketUtils { packet.getIntegers().write(0, entity.getEntityId()); WrappedDataWatcher watcher = new WrappedDataWatcher(); WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(Byte.class); - if (status == EntityStatus.FIRE) { - watcher.setObject(0, serializer, (byte) 0x01); - } - else if (status == EntityStatus.CROUCHED) { - watcher.setObject(0, serializer, (byte) 0x02); - } - else if (status == EntityStatus.UNUSED1) { - watcher.setObject(0, serializer, (byte) 0x04); - } - else if (status == EntityStatus.SPRINTING) { - watcher.setObject(0, serializer, (byte) 0x08); - } - else if (status == EntityStatus.UNUSED2) { - watcher.setObject(0, serializer, (byte) 0x10); - } - else if (status == EntityStatus.INVISIBLE) { - watcher.setObject(0, serializer, (byte) 0x20); - } - else if (status == EntityStatus.GLOWING) { - watcher.setObject(0, serializer, (byte) 0x40); - } - else if (status == EntityStatus.ELYTRA) { - watcher.setObject(0, serializer, (byte) 0x80); - } - else { - watcher.setObject(0, serializer, (byte) 0x00); - } + switch (status) { + case FIRE: + watcher.setObject(0, serializer, (byte) 0x01); + break; + case CROUCHED: + watcher.setObject(0, serializer, (byte) 0x02); + break; + case UNUSED1: + watcher.setObject(0, serializer, (byte) 0x04); + break; + case SPRINTING: + watcher.setObject(0, serializer, (byte) 0x08); + break; + case UNUSED2: + watcher.setObject(0, serializer, (byte) 0x10); + break; + case INVISIBLE: + watcher.setObject(0, serializer, (byte) 0x20); + break; + case GLOWING: + watcher.setObject(0, serializer, (byte) 0x40); + break; + case ELYTRA: + watcher.setObject(0, serializer, (byte) 0x80); + break; + default: + watcher.setObject(0, serializer, (byte) 0x00); + break; + } packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects()); try { for (Player player : players) { diff --git a/src/main/java/me/skymc/taboolib/particle/EffLib.java b/src/main/java/me/skymc/taboolib/particle/EffLib.java index 39e6f27..4da1f84 100644 --- a/src/main/java/me/skymc/taboolib/particle/EffLib.java +++ b/src/main/java/me/skymc/taboolib/particle/EffLib.java @@ -1,5 +1,7 @@ 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; @@ -7,9 +9,6 @@ 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; - import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -406,8 +405,8 @@ public enum EffLib { */ SWEEP_ATTACK("sweepAttack", 45, 9); - private static final Map NAME_MAP = new HashMap(); - private static final Map ID_MAP = new HashMap(); + private static final Map NAME_MAP = new HashMap<>(); + private static final Map ID_MAP = new HashMap<>(); private final String name; private final int id; private final int requiredVersion; @@ -429,7 +428,7 @@ public enum EffLib { * @param requiredVersion Version which is required (1.x) * @param properties Properties of this particle effect */ - private EffLib(String name, int id, int requiredVersion, ParticleProperty... properties) { + EffLib(String name, int id, int requiredVersion, ParticleProperty... properties) { this.name = name; this.id = id; this.requiredVersion = requiredVersion; @@ -478,10 +477,7 @@ public enum EffLib { * @return Whether the particle effect is supported or not */ public boolean isSupported() { - if (requiredVersion == -1) { - return true; - } - return ParticlePacket.getVersion() >= requiredVersion; + return requiredVersion == -1 || ParticlePacket.getVersion() >= requiredVersion; } /** @@ -933,7 +929,7 @@ public enum EffLib { * @author DarkBlade12 * @since 1.7 */ - public static enum ParticleProperty { + public enum ParticleProperty { /** * The particle effect requires water to be displayed */ @@ -949,7 +945,7 @@ public enum EffLib { /** * The particle effect uses the offsets as color values */ - COLORABLE; + COLORABLE } /** @@ -1393,7 +1389,6 @@ public enum EffLib { * @param longDistance Indicates whether the maximum distance is increased from 256 to 65536 * @param data Data of the effect * @throws IllegalArgumentException If the speed is lower than 0 - * @see #ParticleEffect(ParticleEffect, float, float, float, float, int, boolean, ParticleData) */ public ParticlePacket(EffLib effect, Vector direction, float speed, boolean longDistance, ParticleData data) throws IllegalArgumentException { this(effect, (float) direction.getX(), (float) direction.getY(), (float) direction.getZ(), speed, 0, longDistance, data); @@ -1405,7 +1400,6 @@ public enum EffLib { * @param effect Particle effect * @param color Color of the particle * @param longDistance Indicates whether the maximum distance is increased from 256 to 65536 - * @see #ParticleEffect(ParticleEffect, float, float, float, float, int, boolean, ParticleData) */ public ParticlePacket(EffLib effect, ParticleColor color, boolean longDistance) { this(effect, color.getValueX(), color.getValueY(), color.getValueZ(), 1, 0, longDistance, null); diff --git a/src/main/java/me/skymc/taboolib/particle/ParticleUtils.java b/src/main/java/me/skymc/taboolib/particle/ParticleUtils.java index 16016d0..6420b4e 100644 --- a/src/main/java/me/skymc/taboolib/particle/ParticleUtils.java +++ b/src/main/java/me/skymc/taboolib/particle/ParticleUtils.java @@ -1,7 +1,8 @@ package me.skymc.taboolib.particle; -import org.bukkit.*; import org.bukkit.Color; +import org.bukkit.Effect; +import org.bukkit.Location; public class ParticleUtils { diff --git a/src/main/java/me/skymc/taboolib/permission/PermissionUtils.java b/src/main/java/me/skymc/taboolib/permission/PermissionUtils.java index 8c3f244..10fd367 100644 --- a/src/main/java/me/skymc/taboolib/permission/PermissionUtils.java +++ b/src/main/java/me/skymc/taboolib/permission/PermissionUtils.java @@ -1,22 +1,17 @@ package me.skymc.taboolib.permission; -import net.milkbowl.vault.economy.Economy; +import me.skymc.taboolib.Main; import net.milkbowl.vault.permission.Permission; - -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.RegisteredServiceProvider; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.message.MsgUtils; - public class PermissionUtils { private static Permission perms; public static void loadRegisteredServiceProvider() { RegisteredServiceProvider rsp = Main.getInst().getServer().getServicesManager().getRegistration(Permission.class); - perms = (Permission) rsp.getProvider(); + perms = rsp.getProvider(); } public static Permission getPermission() { diff --git a/src/main/java/me/skymc/taboolib/playerdata/DataUtils.java b/src/main/java/me/skymc/taboolib/playerdata/DataUtils.java index c54a5da..5b612f5 100644 --- a/src/main/java/me/skymc/taboolib/playerdata/DataUtils.java +++ b/src/main/java/me/skymc/taboolib/playerdata/DataUtils.java @@ -1,15 +1,12 @@ package me.skymc.taboolib.playerdata; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.HashMap; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - +import me.skymc.taboolib.Main; +import me.skymc.taboolib.database.PlayerDataManager; +import me.skymc.taboolib.exception.PlayerOfflineException; +import me.skymc.taboolib.fileutils.FileUtils; +import me.skymc.taboolib.message.MsgUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; -import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.EventHandler; @@ -17,11 +14,10 @@ import org.bukkit.event.Listener; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.plugin.Plugin; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.database.PlayerDataManager; -import me.skymc.taboolib.exception.PlayerOfflineException; -import me.skymc.taboolib.fileutils.FileUtils; -import me.skymc.taboolib.message.MsgUtils; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; public class DataUtils implements Listener { diff --git a/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java b/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java index a02dc36..d5374c5 100644 --- a/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java +++ b/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java @@ -1,31 +1,34 @@ package me.skymc.taboolib.plugin; -import org.bukkit.*; -import com.google.common.base.*; - +import com.google.common.base.Joiner; import me.skymc.taboolib.Main; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.PluginCommand; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.event.Event; +import org.bukkit.plugin.*; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Field; +import java.net.URLClassLoader; import java.util.*; import java.util.Map.Entry; - -import org.bukkit.command.*; -import java.net.*; -import java.util.logging.*; -import java.io.*; -import org.bukkit.plugin.*; -import org.bukkit.event.*; -import java.lang.reflect.*; +import java.util.logging.Level; +import java.util.logging.Logger; public class PluginUtils { public static String consolidateStrings(final String[] args, final int start) { - String ret = args[start]; + StringBuilder ret = new StringBuilder(args[start]); if (args.length > start + 1) { for (int i = start + 1; i < args.length; ++i) { - ret = ret + " " + args[i]; + ret.append(" ").append(args[i]); } } - return ret; + return ret.toString(); } public static void enable(final Plugin plugin) { @@ -83,7 +86,7 @@ public class PluginUtils } public static List getPluginNames(final boolean fullName) { - final List plugins = new ArrayList(); + final List plugins = new ArrayList<>(); for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) { plugins.add(fullName ? plugin.getDescription().getFullName() : plugin.getName()); } @@ -99,7 +102,7 @@ public class PluginUtils } public static String getUsages(final Plugin plugin) { - final List parsedCommands = new ArrayList(); + final List parsedCommands = new ArrayList<>(); final Map> commands = plugin.getDescription().getCommands(); if (commands != null) { for (final Entry> thisEntry : commands.entrySet()) { @@ -116,9 +119,9 @@ public class PluginUtils @SuppressWarnings("unchecked") public static List findByCommand(final String command) { - final List plugins = new ArrayList(); + final List plugins = new ArrayList<>(); for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) { - final Map> commands = (Map>)plugin.getDescription().getCommands(); + final Map> commands = plugin.getDescription().getCommands(); if (commands != null) { for (final Map.Entry> commandNext : commands.entrySet()) { if (commandNext.getKey().equalsIgnoreCase(command)) { @@ -156,7 +159,7 @@ public class PluginUtils } public static boolean isIgnored(final String plugin) { - return plugin.equalsIgnoreCase(Main.getInst().getName()) ? true : false; + return plugin.equalsIgnoreCase(Main.getInst().getName()); } private static String load(final Plugin plugin) { @@ -248,11 +251,7 @@ public class PluginUtils final Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands"); knownCommandsField.setAccessible(true); commands = (Map)knownCommandsField.get(commandMap); - } - catch (NoSuchFieldException e) { - return "failed"; - } - catch (IllegalAccessException e2) { + } catch (NoSuchFieldException | IllegalAccessException e) { return "failed"; } } @@ -265,13 +264,7 @@ public class PluginUtils } if (listeners != null && reloadlisteners) { for (final SortedSet set : listeners.values()) { - final Iterator it = set.iterator(); - while (it.hasNext()) { - final RegisteredListener value = it.next(); - if (value.getPlugin() == plugin) { - it.remove(); - } - } + set.removeIf(value -> value.getPlugin() == plugin); } } if (commandMap != null) { @@ -283,7 +276,7 @@ public class PluginUtils if (c.getPlugin() != plugin) { continue; } - c.unregister((CommandMap)commandMap); + c.unregister(commandMap); it2.remove(); } } diff --git a/src/main/java/me/skymc/taboolib/regen/WorldGuardUtils.java b/src/main/java/me/skymc/taboolib/regen/WorldGuardUtils.java index 8032b09..d0ad421 100644 --- a/src/main/java/me/skymc/taboolib/regen/WorldGuardUtils.java +++ b/src/main/java/me/skymc/taboolib/regen/WorldGuardUtils.java @@ -1,12 +1,10 @@ package me.skymc.taboolib.regen; -import java.util.Iterator; -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 { @@ -17,15 +15,12 @@ public class WorldGuardUtils { int z = (int) loc.getZ(); Map regens = WorldGuardPlugin.inst().getRegionManager(loc.getWorld()).getRegions(); - Iterator i = regens.keySet().iterator(); - while (i.hasNext()) - { - ProtectedRegion regen = regens.get(i.next()); - if (regen.contains(x, y, z)) - { - return regen.getId(); - } - } + for (String s : regens.keySet()) { + ProtectedRegion regen = regens.get(s); + if (regen.contains(x, y, z)) { + return regen.getId(); + } + } return null; } } diff --git a/src/main/java/me/skymc/taboolib/scoreboard/ScoreboardUtil.java b/src/main/java/me/skymc/taboolib/scoreboard/ScoreboardUtil.java index 8e7ab51..f7331e8 100644 --- a/src/main/java/me/skymc/taboolib/scoreboard/ScoreboardUtil.java +++ b/src/main/java/me/skymc/taboolib/scoreboard/ScoreboardUtil.java @@ -45,8 +45,7 @@ public class ScoreboardUtil public static HashMap cutRanked(HashMap content) { - HashMap elements = new HashMap<>(); - elements.putAll(content); + HashMap elements = new HashMap<>(content); while(elements.size() > 15) { diff --git a/src/main/java/me/skymc/taboolib/sign/TabooSignChangeEvent.java b/src/main/java/me/skymc/taboolib/sign/TabooSignChangeEvent.java index 3b29db4..2a5b36e 100644 --- a/src/main/java/me/skymc/taboolib/sign/TabooSignChangeEvent.java +++ b/src/main/java/me/skymc/taboolib/sign/TabooSignChangeEvent.java @@ -1,15 +1,10 @@ package me.skymc.taboolib.sign; -import java.util.UUID; - import org.bukkit.block.Block; import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import net.minecraft.server.v1_9_R2.BlockBanner; - @Deprecated public class TabooSignChangeEvent extends Event diff --git a/src/main/java/me/skymc/taboolib/skript/SkriptHandler.java b/src/main/java/me/skymc/taboolib/skript/SkriptHandler.java index c22ba39..9b88a78 100644 --- a/src/main/java/me/skymc/taboolib/skript/SkriptHandler.java +++ b/src/main/java/me/skymc/taboolib/skript/SkriptHandler.java @@ -1,13 +1,11 @@ package me.skymc.taboolib.skript; -import org.bukkit.Bukkit; -import org.bukkit.Sound; -import org.bukkit.inventory.ItemStack; - import ch.njol.skript.Skript; import ch.njol.skript.lang.ExpressionType; import me.skymc.taboolib.skript.expression.ExpressionItemCache; import me.skymc.taboolib.skript.expression.ExpressionTabooCodeItem; +import org.bukkit.Bukkit; +import org.bukkit.inventory.ItemStack; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/skript/expression/ExpressionTabooCodeItem.java b/src/main/java/me/skymc/taboolib/skript/expression/ExpressionTabooCodeItem.java index 38e407c..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,15 +1,12 @@ package me.skymc.taboolib.skript.expression; -import java.lang.reflect.Method; - -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/skull/SkullUtils.java b/src/main/java/me/skymc/taboolib/skull/SkullUtils.java index 8d97fef..569048f 100644 --- a/src/main/java/me/skymc/taboolib/skull/SkullUtils.java +++ b/src/main/java/me/skymc/taboolib/skull/SkullUtils.java @@ -3,12 +3,9 @@ package me.skymc.taboolib.skull; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; -import org.bukkit.SkullType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; -import me.skymc.taboolib.methods.MethodsUtils; - public class SkullUtils { public static ItemStack getItme(OfflinePlayer p ) { diff --git a/src/main/java/me/skymc/taboolib/sound/SoundPack.java b/src/main/java/me/skymc/taboolib/sound/SoundPack.java index cd4ef92..52cdacf 100644 --- a/src/main/java/me/skymc/taboolib/sound/SoundPack.java +++ b/src/main/java/me/skymc/taboolib/sound/SoundPack.java @@ -1,7 +1,6 @@ package me.skymc.taboolib.sound; import org.bukkit.Sound; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; public class SoundPack { diff --git a/src/main/java/me/skymc/taboolib/string/Language.java b/src/main/java/me/skymc/taboolib/string/Language.java index 8385b92..db5dea2 100644 --- a/src/main/java/me/skymc/taboolib/string/Language.java +++ b/src/main/java/me/skymc/taboolib/string/Language.java @@ -1,24 +1,19 @@ package me.skymc.taboolib.string; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; - +import com.google.common.base.Charsets; +import me.skymc.taboolib.message.MsgUtils; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import com.google.common.base.Charsets; - -import me.skymc.taboolib.fileutils.FileUtils; -import me.skymc.taboolib.message.MsgUtils; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.util.Collections; +import java.util.List; public class Language { @@ -86,7 +81,7 @@ public class Language { public List getList(String key) { if (conf == null || conf.getString(key) == null) { - return Arrays.asList("§4[Language \"" + key + "\" Not Found]"); + return Collections.singletonList("§4[Language \"" + key + "\" Not Found]"); } List list = conf.getStringList(key); for (int i = 0 ; i < list.size() ; i++) { diff --git a/src/main/java/me/skymc/taboolib/string/LanguageUtils.java b/src/main/java/me/skymc/taboolib/string/LanguageUtils.java index bff6258..2e4d935 100644 --- a/src/main/java/me/skymc/taboolib/string/LanguageUtils.java +++ b/src/main/java/me/skymc/taboolib/string/LanguageUtils.java @@ -1,17 +1,11 @@ package me.skymc.taboolib.string; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; - -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; +import me.skymc.taboolib.message.MsgUtils; import org.bukkit.plugin.Plugin; -import me.skymc.taboolib.message.MsgUtils; +import java.io.File; +import java.util.Collections; +import java.util.List; @Deprecated public class LanguageUtils { @@ -27,7 +21,7 @@ public class LanguageUtils { if (l.getLanguage().containsKey(key)) { return l.getLanguage().get(key); } - return Arrays.asList(""); + return Collections.singletonList(""); } public static void saveLanguageFile(String name, Plugin plugin) { diff --git a/src/main/java/me/skymc/taboolib/string/PatternUtils.java b/src/main/java/me/skymc/taboolib/string/PatternUtils.java index 5420769..0eeeea3 100644 --- a/src/main/java/me/skymc/taboolib/string/PatternUtils.java +++ b/src/main/java/me/skymc/taboolib/string/PatternUtils.java @@ -11,13 +11,13 @@ public class PatternUtils { public static String doubleNumber3 = "((?:\\-|\\+)?\\d+(?:\\.\\d+)?)"; public static String consolidateStrings(final String[] args, final int start) { - String ret = args[start]; + StringBuilder ret = new StringBuilder(args[start]); if (args.length > start + 1) { for (int i = start + 1; i < args.length; ++i) { - ret = ret + " " + args[i]; + ret.append(" ").append(args[i]); } } - return ret; + return ret.toString(); } } diff --git a/src/main/java/me/skymc/taboolib/string/StringUtils.java b/src/main/java/me/skymc/taboolib/string/StringUtils.java index 5e77799..37648e4 100644 --- a/src/main/java/me/skymc/taboolib/string/StringUtils.java +++ b/src/main/java/me/skymc/taboolib/string/StringUtils.java @@ -23,8 +23,8 @@ public class StringUtils { private static String bytesToHexString(byte[] bytes) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < bytes.length; i++) { - String hex = Integer.toHexString(0xFF & bytes[i]); + for (byte aByte : bytes) { + String hex = Integer.toHexString(0xFF & aByte); if (hex.length() == 1) { sb.append('0'); } diff --git a/src/main/java/me/skymc/taboolib/string/language2/Language2Format.java b/src/main/java/me/skymc/taboolib/string/language2/Language2Format.java index a79f46b..a2ebcf0 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/Language2Format.java +++ b/src/main/java/me/skymc/taboolib/string/language2/Language2Format.java @@ -1,20 +1,13 @@ package me.skymc.taboolib.string.language2; +import lombok.Getter; +import me.skymc.taboolib.string.language2.value.*; +import org.bukkit.entity.Player; + import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import lombok.Getter; -import me.skymc.taboolib.string.language2.value.Language2Action; -import me.skymc.taboolib.string.language2.value.Language2Book; -import me.skymc.taboolib.string.language2.value.Language2Json; -import me.skymc.taboolib.string.language2.value.Language2Sound; -import me.skymc.taboolib.string.language2.value.Language2Text; -import me.skymc.taboolib.string.language2.value.Language2Title; - /** * @author sky * @since 2018-03-08 22:45:56 @@ -110,27 +103,29 @@ public class Language2Format implements Language2Line { list = language2Value.setPlaceholder(list, player); // 大标题 - if (type == Language2Type.TITLE) { - language2Lines.add(new Language2Title(this, list)); - } - // 小标题 - else if (type == Language2Type.ACTION) { - language2Lines.add(new Language2Action(this, list)); - } - // JSON - else if (type == Language2Type.JSON) { - language2Lines.add(new Language2Json(this, list, player)); - } - // 音效 - else if (type == Language2Type.SOUND) { - language2Lines.add(new Language2Sound(this, list)); - } - // 书本 - else if (type == Language2Type.BOOK) { - language2Lines.add(new Language2Book(this, list, player)); - } - else { - language2Lines.add(new Language2Text(this, list)); + switch (type) { + case TITLE: + language2Lines.add(new Language2Title(this, list)); + break; + // 小标题 + case ACTION: + language2Lines.add(new Language2Action(this, list)); + break; + // JSON + case JSON: + language2Lines.add(new Language2Json(this, list, player)); + break; + // 音效 + case SOUND: + language2Lines.add(new Language2Sound(this, list)); + break; + // 书本 + case BOOK: + language2Lines.add(new Language2Book(this, list, player)); + break; + default: + language2Lines.add(new Language2Text(this, list)); + break; } // 清理数据 diff --git a/src/main/java/me/skymc/taboolib/string/language2/Language2Line.java b/src/main/java/me/skymc/taboolib/string/language2/Language2Line.java index 47940be..fb0c640 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/Language2Line.java +++ b/src/main/java/me/skymc/taboolib/string/language2/Language2Line.java @@ -1,17 +1,15 @@ package me.skymc.taboolib.string.language2; -import java.util.List; - import org.bukkit.entity.Player; /** * @author sky * @since 2018-03-08 23:36:22 */ -public abstract interface Language2Line { - - abstract void send(Player player); - - abstract void console(); +public interface Language2Line { + + void send(Player player); + + void console(); } diff --git a/src/main/java/me/skymc/taboolib/string/language2/Language2Value.java b/src/main/java/me/skymc/taboolib/string/language2/Language2Value.java index b88ba24..d56ff03 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/Language2Value.java +++ b/src/main/java/me/skymc/taboolib/string/language2/Language2Value.java @@ -1,24 +1,20 @@ package me.skymc.taboolib.string.language2; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map.Entry; - +import lombok.Getter; +import me.skymc.taboolib.string.language2.value.Language2Text; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import lombok.Getter; -import me.skymc.taboolib.string.language2.value.Language2Text; +import java.util.*; +import java.util.Map.Entry; /** * @author sky * @since 2018年2月13日 下午3:05:15 */ -public class Language2Value extends Object { +public class Language2Value { @Getter private Language2 language; @@ -41,13 +37,13 @@ public class Language2Value extends Object { public Language2Value(Language2 language, String languageKey) { // 如果语言文件不存在 if (language == null || languageKey == null) { - languageValue = Arrays.asList(ChatColor.DARK_RED + "[]"); + languageValue = Collections.singletonList(ChatColor.DARK_RED + "[]"); return; } // 如果语言文本不存在 if (!language.getConfiguration().contains(languageKey)) { - languageValue = Arrays.asList(ChatColor.DARK_RED + "[]"); + languageValue = Collections.singletonList(ChatColor.DARK_RED + "[]"); return; } @@ -148,7 +144,7 @@ public class Language2Value extends Object { return setPlaceholder(text.getText(), null); } else { - return Arrays.asList(languageValue.size() == 0 ? ChatColor.DARK_RED + "[]" : setPlaceholder(languageValue.get(0), null)); + return Collections.singletonList(languageValue.size() == 0 ? ChatColor.DARK_RED + "[]" : setPlaceholder(languageValue.get(0), null)); } } diff --git a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Action.java b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Action.java index 78972b3..9ac909e 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Action.java +++ b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Action.java @@ -1,22 +1,19 @@ package me.skymc.taboolib.string.language2.value; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - import lombok.Getter; import me.skymc.taboolib.Main; import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.display.ActionUtils; -import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.other.NumberUtils; import me.skymc.taboolib.string.language2.Language2Format; import me.skymc.taboolib.string.language2.Language2Line; import me.skymc.taboolib.string.language2.Language2Value; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.List; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Book.java b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Book.java index 9545e24..b59586f 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Book.java +++ b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Book.java @@ -1,19 +1,5 @@ package me.skymc.taboolib.string.language2.value; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - import lombok.Getter; import me.skymc.taboolib.bookformatter.BookFormatter; import me.skymc.taboolib.bookformatter.action.ClickAction; @@ -26,6 +12,18 @@ import me.skymc.taboolib.other.NumberUtils; import me.skymc.taboolib.string.language2.Language2Format; import me.skymc.taboolib.string.language2.Language2Line; import me.skymc.taboolib.string.language2.Language2Value; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * @author sky @@ -104,7 +102,7 @@ public class Language2Book implements Language2Line { // 获取文本 StringBuilder sb = new StringBuilder(); for (int i = 1 ; i < line_split.length ; i++) { - sb.append(line_split[i] + optionFullName); + sb.append(line_split[i]).append(optionFullName); } // 更改文本 line = sb.substring(0, sb.length() - optionFullName.length()); diff --git a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Json.java b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Json.java index 5b1303f..9dd12a4 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Json.java +++ b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Json.java @@ -1,14 +1,5 @@ package me.skymc.taboolib.string.language2.value; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - import lombok.Getter; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.jsonformatter.JSONFormatter; @@ -22,6 +13,13 @@ import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; import me.skymc.taboolib.string.language2.Language2Format; import me.skymc.taboolib.string.language2.Language2Line; import me.skymc.taboolib.string.language2.Language2Value; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.List; /** * @author sky @@ -143,7 +141,6 @@ public class Language2Json implements Language2Line { * 追加 JSON 内容 * * @param current 文本 - * @param clickevent 点击动作 * @param hoverEvent 显示动作 */ private void append(String current, ClickEvent clickEvent, HoverEvent hoverEvent) { diff --git a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Text.java b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Text.java index 1c8a1f1..2c66ed6 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Text.java +++ b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Text.java @@ -1,17 +1,14 @@ package me.skymc.taboolib.string.language2.value; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - import lombok.Getter; -import me.skymc.taboolib.sound.SoundPack; import me.skymc.taboolib.string.language2.Language2Format; import me.skymc.taboolib.string.language2.Language2Line; import me.skymc.taboolib.string.language2.Language2Value; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; /** * @author sky @@ -28,9 +25,7 @@ public class Language2Text implements Language2Line { public Language2Text(Language2Format format, List list) { this.value = format.getLanguage2Value(); // 遍历文本 - for (String line : list) { - text.add(line); - } + text.addAll(list); } @Override diff --git a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Title.java b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Title.java index 2a01d62..372d6e9 100644 --- a/src/main/java/me/skymc/taboolib/string/language2/value/Language2Title.java +++ b/src/main/java/me/skymc/taboolib/string/language2/value/Language2Title.java @@ -1,18 +1,16 @@ package me.skymc.taboolib.string.language2.value; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - import lombok.Getter; import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.display.TitleUtils; import me.skymc.taboolib.string.language2.Language2Format; import me.skymc.taboolib.string.language2.Language2Line; import me.skymc.taboolib.string.language2.Language2Value; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import java.util.List; /** * @author sky diff --git a/src/main/java/me/skymc/taboolib/string/obfuscated/CT.java b/src/main/java/me/skymc/taboolib/string/obfuscated/CT.java index b6aba85..f2d4596 100644 --- a/src/main/java/me/skymc/taboolib/string/obfuscated/CT.java +++ b/src/main/java/me/skymc/taboolib/string/obfuscated/CT.java @@ -3,10 +3,21 @@ package me.skymc.taboolib.string.obfuscated; import javax.xml.bind.DatatypeConverter; public class CT { - - public static enum CodeType { - BASE64, - BINARY; + + public static String decode(CodeType type, String string) { + switch (type) { + case BASE64: { + return new String(DatatypeConverter.parseBase64Binary(string)); + } + case BINARY: { + StringBuilder text = new StringBuilder(); + for (String segment : string.split(" ")) { + text.append(Character.toString((char) Integer.parseInt(segment, 2))); + } + return text.toString(); + } + } + return ""; } public static String encode(CodeType type, String string) { @@ -29,21 +40,10 @@ public class CT { } return ""; } - - public static String decode(CodeType type, String string) { - switch (type) { - case BASE64: { - return new String(DatatypeConverter.parseBase64Binary(string)); - } - case BINARY: { - StringBuilder text = new StringBuilder(); - for (String segment: string.split(" ")) { - text.append(new Character((char) Integer.parseInt(segment, 2)).toString()); - } - return text.toString(); - } - } - return ""; + + public enum CodeType { + BASE64, + BINARY } } 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 bc9d482..3e647bd 100644 --- a/src/main/java/me/skymc/taboolib/string/obfuscated/FZ.java +++ b/src/main/java/me/skymc/taboolib/string/obfuscated/FZ.java @@ -9,7 +9,7 @@ public class FZ { byte[] array; for (int length = (array = bs).length, i = 0; i < length; ++i) { final byte b = array[i]; - sb.append(String.valueOf(b) + "#"); + sb.append(String.valueOf(b)).append("#"); } return sb.toString(); } @@ -39,7 +39,7 @@ public class FZ { int i; final char c = (char)(i = charArray[j]); i *= power; - sb.append(String.valueOf(i) + "#"); + sb.append(String.valueOf(i)).append("#"); } return sb.toString(); } diff --git a/src/main/java/me/skymc/taboolib/support/SupportPlaceholder.java b/src/main/java/me/skymc/taboolib/support/SupportPlaceholder.java index 1d75fe9..0272787 100644 --- a/src/main/java/me/skymc/taboolib/support/SupportPlaceholder.java +++ b/src/main/java/me/skymc/taboolib/support/SupportPlaceholder.java @@ -1,13 +1,12 @@ package me.skymc.taboolib.support; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - import me.clip.placeholderapi.external.EZPlaceholderHook; import me.skymc.taboolib.database.GlobalDataManager; import me.skymc.tlm.TLM; import me.skymc.tlm.module.TabooLibraryModule; import me.skymc.tlm.module.sub.ModuleKits; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; public class SupportPlaceholder extends EZPlaceholderHook { @@ -21,7 +20,7 @@ public class SupportPlaceholder extends EZPlaceholderHook { String[] value = args.split("_"); StringBuilder sb = new StringBuilder(); for (int i = 1; i < value.length ; i++) { - sb.append(value[i] + "_"); + sb.append(value[i]).append("_"); } return GlobalDataManager.getVariableAsynchronous(sb.substring(0, sb.length() - 1), ""); } diff --git a/src/main/java/me/skymc/taboolib/support/SupportWorldGuard.java b/src/main/java/me/skymc/taboolib/support/SupportWorldGuard.java index bfa5511..503bec6 100644 --- a/src/main/java/me/skymc/taboolib/support/SupportWorldGuard.java +++ b/src/main/java/me/skymc/taboolib/support/SupportWorldGuard.java @@ -1,12 +1,15 @@ package me.skymc.taboolib.support; -import com.sk89q.worldguard.bukkit.*; -import org.bukkit.plugin.*; -import com.sk89q.worldguard.protection.managers.*; -import com.sk89q.worldguard.protection.regions.*; -import java.util.*; -import org.bukkit.entity.*; -import org.bukkit.*; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.util.Collection; public class SupportWorldGuard { @@ -34,7 +37,7 @@ public class SupportWorldGuard public final Collection getRegionIDs(final World world) { final RegionManager regionManager = this.getRegionManager(world); - return (Collection)regionManager.getRegions().keySet(); + return regionManager.getRegions().keySet(); } public final Collection getRegions(final World world) { diff --git a/src/main/java/me/skymc/taboolib/team/TagManager.java b/src/main/java/me/skymc/taboolib/team/TagManager.java index 366fc81..5d37efa 100644 --- a/src/main/java/me/skymc/taboolib/team/TagManager.java +++ b/src/main/java/me/skymc/taboolib/team/TagManager.java @@ -1,7 +1,8 @@ package me.skymc.taboolib.team; -import java.util.HashMap; - +import lombok.Getter; +import lombok.Setter; +import me.skymc.taboolib.Main; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -11,9 +12,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; -import lombok.Getter; -import lombok.Setter; -import me.skymc.taboolib.Main; +import java.util.HashMap; /** * @author sky @@ -88,14 +87,9 @@ public class TagManager implements Listener { * @return {@link PlayerData} */ private PlayerData getPlayerData(Player player) { - PlayerData data = playerdata.get(player.getName()); - if (data == null) { - data = new PlayerData(player.getName()); - playerdata.put(player.getName(), data); - } - return data; + return playerdata.computeIfAbsent(player.getName(), k -> new PlayerData(player.getName())); } - + /** * 删除该玩家的称号数据 * diff --git a/src/main/java/me/skymc/taboolib/team/TagUtils.java b/src/main/java/me/skymc/taboolib/team/TagUtils.java index e9d96a9..b3a6680 100644 --- a/src/main/java/me/skymc/taboolib/team/TagUtils.java +++ b/src/main/java/me/skymc/taboolib/team/TagUtils.java @@ -1,14 +1,10 @@ package me.skymc.taboolib.team; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; -import me.skymc.taboolib.message.MsgUtils; -import me.skymc.taboolib.methods.MethodsUtils; - /** * @author sky * @since 2018-03-17 21:36:52 diff --git a/src/main/java/me/skymc/taboolib/thread/ThreadUtils.java b/src/main/java/me/skymc/taboolib/thread/ThreadUtils.java index 4633651..a1e67fe 100644 --- a/src/main/java/me/skymc/taboolib/thread/ThreadUtils.java +++ b/src/main/java/me/skymc/taboolib/thread/ThreadUtils.java @@ -1,11 +1,11 @@ package me.skymc.taboolib.thread; -import java.util.*; +import java.util.LinkedList; public class ThreadUtils { private static PoolWorker[] threads; - private static LinkedList queue = new LinkedList<>(); + private static final LinkedList queue = new LinkedList<>(); /** * 构造方法 @@ -63,8 +63,7 @@ public class ThreadUtils { // 等待任务 try { queue.wait(); - } - catch (InterruptedException e) { + } catch (InterruptedException ignored) { } } diff --git a/src/main/java/me/skymc/taboolib/timecycle/TimeCycleManager.java b/src/main/java/me/skymc/taboolib/timecycle/TimeCycleManager.java index 184efa1..a5a705b 100644 --- a/src/main/java/me/skymc/taboolib/timecycle/TimeCycleManager.java +++ b/src/main/java/me/skymc/taboolib/timecycle/TimeCycleManager.java @@ -1,18 +1,15 @@ package me.skymc.taboolib.timecycle; -import java.util.Collection; -import java.util.HashMap; -import java.util.concurrent.ConcurrentHashMap; - -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; - import me.skymc.taboolib.Main; import me.skymc.taboolib.database.GlobalDataManager; import me.skymc.taboolib.message.MsgUtils; -import me.skymc.taboolib.playerdata.DataUtils; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.Collection; +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; public class TimeCycleManager { diff --git a/src/main/java/me/skymc/taboolib/update/UpdateTask.java b/src/main/java/me/skymc/taboolib/update/UpdateTask.java index 1178911..3b9bc1c 100644 --- a/src/main/java/me/skymc/taboolib/update/UpdateTask.java +++ b/src/main/java/me/skymc/taboolib/update/UpdateTask.java @@ -1,15 +1,13 @@ package me.skymc.taboolib.update; -import java.io.File; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.bukkit.scheduler.BukkitRunnable; - import me.skymc.taboolib.Main; import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.fileutils.FileUtils; import me.skymc.taboolib.message.MsgUtils; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * @author sky diff --git a/src/main/java/me/skymc/tlm/TLM.java b/src/main/java/me/skymc/tlm/TLM.java index cb1eb8f..7495c49 100644 --- a/src/main/java/me/skymc/tlm/TLM.java +++ b/src/main/java/me/skymc/tlm/TLM.java @@ -1,8 +1,5 @@ package me.skymc.tlm; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.FileConfiguration; - import lombok.Getter; import me.skymc.taboolib.Main; import me.skymc.taboolib.fileutils.ConfigUtils; @@ -13,6 +10,7 @@ import me.skymc.tlm.module.sub.ModuleCommandChanger; import me.skymc.tlm.module.sub.ModuleInventorySave; import me.skymc.tlm.module.sub.ModuleKits; import me.skymc.tlm.module.sub.ModuleTimeCycle; +import org.bukkit.configuration.file.FileConfiguration; /** * @author sky @@ -82,8 +80,7 @@ public class TLM { language = new Language2(config.getString("Language"), Main.getInst()); } catch (Exception e) { MsgUtils.warn("语言文件不存在: &4" + config.getString("Language")); - return; - } + } } /** diff --git a/src/main/java/me/skymc/tlm/annotation/DisableConfig.java b/src/main/java/me/skymc/tlm/annotation/DisableConfig.java index 43f6f25..091301e 100644 --- a/src/main/java/me/skymc/tlm/annotation/DisableConfig.java +++ b/src/main/java/me/skymc/tlm/annotation/DisableConfig.java @@ -1,17 +1,13 @@ package me.skymc.tlm.annotation; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - import java.lang.annotation.Retention; import java.lang.annotation.Target; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + @Retention(RUNTIME) @Target(TYPE) -/** - * @author sky - * @since 2018年2月22日 下午3:59:30 - */ public @interface DisableConfig { } diff --git a/src/main/java/me/skymc/tlm/command/sub/TLMKitCommand.java b/src/main/java/me/skymc/tlm/command/sub/TLMKitCommand.java index 2e9d413..65055e9 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 @@ -36,15 +35,13 @@ public class TLMKitCommand extends SubCommand { // 判断命令 if (args.length == 1) { TLM.getInst().getLanguage().get("KIT-EMPTY").send(sender); - return; - } + } else if (args[1].equalsIgnoreCase("list")) { // 判断权限 if (!sender.hasPermission("taboolib.kit.list")) { TLM.getInst().getLanguage().get("NOPERMISSION-KIT-LIST").send(sender); - return; - } + } else { TLM.getInst().getLanguage().get("KIT-LIST") .addPlaceholder("$kits", moduleKits.getConfig().getConfigurationSection("Kits").getKeys(false).toString()) @@ -158,8 +155,7 @@ public class TLMKitCommand extends SubCommand { // 玩家不存在 if (player == null) { TLM.getInst().getLanguage().get("KIT-OFFLINE").addPlaceholder("$name", args[3]).send(sender); - return; - } + } else { moduleKits.setPlayerReward(player, args[2], false); TLM.getInst().getLanguage().get("KIT-RESET-PLAYER").addPlaceholder("$kit", args[2]).addPlaceholder("$player", player.getName()).send(sender); diff --git a/src/main/java/me/skymc/tlm/module/ITabooLibraryModule.java b/src/main/java/me/skymc/tlm/module/ITabooLibraryModule.java index 860c8c1..bc081f9 100644 --- a/src/main/java/me/skymc/tlm/module/ITabooLibraryModule.java +++ b/src/main/java/me/skymc/tlm/module/ITabooLibraryModule.java @@ -6,15 +6,16 @@ import org.bukkit.configuration.file.FileConfiguration; * @author sky * @since 2018年2月17日 下午11:22:42 */ -public abstract interface ITabooLibraryModule { +public interface ITabooLibraryModule { default void onEnable() {} default void onDisable() {} - - default void onReload() {}; - - abstract String getName(); + + default void onReload() { + } + + String getName(); default FileConfiguration getConfig() { return TabooLibraryModule.getInst().getConfig(this); diff --git a/src/main/java/me/skymc/tlm/module/TabooLibraryModule.java b/src/main/java/me/skymc/tlm/module/TabooLibraryModule.java index 3f92e9f..e1d9216 100644 --- a/src/main/java/me/skymc/tlm/module/TabooLibraryModule.java +++ b/src/main/java/me/skymc/tlm/module/TabooLibraryModule.java @@ -1,16 +1,15 @@ package me.skymc.tlm.module; -import java.io.File; -import java.util.HashMap; -import java.util.Set; - +import me.skymc.taboolib.Main; +import me.skymc.tlm.annotation.DisableConfig; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.Listener; -import me.skymc.taboolib.Main; -import me.skymc.tlm.annotation.DisableConfig; +import java.io.File; +import java.util.HashMap; +import java.util.Set; /** * @author sky @@ -53,7 +52,7 @@ public class TabooLibraryModule { } public void unloadModules() { - TLM_MODULE.keySet().forEach(x -> x.onDisable()); + TLM_MODULE.keySet().forEach(ITabooLibraryModule::onDisable); } public void reloadConfig() { diff --git a/src/main/java/me/skymc/tlm/module/sub/ModuleKits.java b/src/main/java/me/skymc/tlm/module/sub/ModuleKits.java index 2910cef..250e12a 100644 --- a/src/main/java/me/skymc/tlm/module/sub/ModuleKits.java +++ b/src/main/java/me/skymc/tlm/module/sub/ModuleKits.java @@ -1,20 +1,17 @@ package me.skymc.tlm.module.sub; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import lombok.Getter; -import me.skymc.taboolib.database.PlayerDataManager; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.other.DateUtils; import me.skymc.taboolib.other.NumberUtils; import me.skymc.taboolib.playerdata.DataUtils; import me.skymc.tlm.module.ITabooLibraryModule; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.List; /** * @author sky diff --git a/src/main/java/me/skymc/tlm/module/sub/ModuleTimeCycle.java b/src/main/java/me/skymc/tlm/module/sub/ModuleTimeCycle.java index 63766b5..a367941 100644 --- a/src/main/java/me/skymc/tlm/module/sub/ModuleTimeCycle.java +++ b/src/main/java/me/skymc/tlm/module/sub/ModuleTimeCycle.java @@ -1,13 +1,5 @@ package me.skymc.tlm.module.sub; -import java.util.Calendar; -import java.util.Date; - -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.scheduler.BukkitRunnable; - import me.skymc.taboolib.Main; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.other.DateUtils; @@ -17,6 +9,11 @@ import me.skymc.taboolib.timecycle.TimeCycleEvent; import me.skymc.taboolib.timecycle.TimeCycleInitializeEvent; import me.skymc.taboolib.timecycle.TimeCycleManager; import me.skymc.tlm.module.ITabooLibraryModule; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.util.Calendar; /** * @author sky