From 5234661fe5bd672c678c0e8ae5a81cbbc0b5b537 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Mon, 14 Nov 2016 01:43:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 282 +++++++++--------- .../pw/yumc/YumCore/bukkit/compatible/C.java | 14 +- .../yumc/YumCore/commands/CommandParse.java | 35 ++- .../yumc/YumCore/commands/annotation/Cmd.java | 4 +- .../YumCore/commands/annotation/Limit.java | 2 +- .../commands/interfaces/CommandHelpParse.java | 2 +- .../yumc/YumCore/config/ext/RemoteConfig.java | 10 +- .../config/inject/AbstractInjectConfig.java | 21 +- .../YumCore/config/inject/InjectParse.java | 2 +- .../java/pw/yumc/YumCore/kit/EntityKit.java | 59 ++-- .../java/pw/yumc/YumCore/kit/FileKit.java | 1 + .../java/pw/yumc/YumCore/kit/HashKit.java | 33 +- .../java/pw/yumc/YumCore/kit/HttpKit.java | 39 +-- src/main/java/pw/yumc/YumCore/kit/PKit.java | 6 +- src/main/java/pw/yumc/YumCore/kit/StrKit.java | 15 +- src/main/java/pw/yumc/YumCore/kit/ZipKit.java | 4 +- .../yumc/YumCore/mail/SimpleMailSender.java | 4 +- src/main/java/pw/yumc/YumCore/mail/XMail.java | 15 +- .../pw/yumc/YumCore/paste/PasteContent.java | 6 +- .../pw/yumc/YumCore/paste/PasteFormat.java | 2 +- .../pw/yumc/YumCore/paste/PasteXcode.java | 1 - .../java/pw/yumc/YumCore/paste/Pastebin.java | 22 +- .../pw/yumc/YumCore/paste/StickyNotes.java | 6 +- .../YumCore/plugin/protocollib/PacketKit.java | 2 +- .../java/pw/yumc/YumCore/reflect/Reflect.java | 95 +----- .../YumCore/reflect/ReflectException.java | 35 --- .../java/pw/yumc/YumCore/sql/DataBase.java | 17 +- .../yumc/YumCore/sql/core/DataBaseCore.java | 9 +- .../pw/yumc/YumCore/statistic/Statistics.java | 24 +- .../pw/yumc/YumCore/update/SubscribeTask.java | 10 +- 30 files changed, 287 insertions(+), 490 deletions(-) diff --git a/pom.xml b/pom.xml index 0cc1d99..fb982d7 100644 --- a/pom.xml +++ b/pom.xml @@ -1,143 +1,143 @@ - 4.0.0 - pw.yumc - YumCore - 1.1 - YumCore - - ${project.name} - - - src/main/resources - true - - - - - maven-compiler-plugin - 3.3 - - 1.7 - 1.7 - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - source - compile - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.3 - - - javadocs - package - - jar - - - false - - - - - - - - Jenkins - http://ci.yumc.pw - - - UTF-8 - UTF-8 - 开发版本 - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/groups/public/ - - - yumc-repo - http://repo.yumc.pw/content/groups/public/ - - - - - jtb - YUMC - http://repo.yumc.pw/content/repositories/yumcenter/ - - - - - org.spigotmc - spigot-api - 1.10.2-R0.1-SNAPSHOT - - - net.milkbowl.vault - Vault - 1.5.6 - - - javax.mail - mail - 1.4.7 - - - org.spigotmc - spigot1102 - 1.10.2 - system - ${project.basedir}/lib/spigot-1.10.2.jar - - - org.spigotmc - spigot188 - 1.8.8 - system - ${project.basedir}/lib/spigot-1.8.8.jar - - - org.bukkit - craftbukkit - 1.7.10 - system - ${project.basedir}/lib/craftbukkit-1.7.10.jar - - - com.comphenix.protocol - ProtocolLib - 3.6.5-SNAPSHOT - system - ${project.basedir}/lib/ProtocolLib-3.6.5-SNAPSHOT.jar - - - me.clip - PlaceholderAPI - 1.8.6 - system - ${project.basedir}/lib/PlaceholderAPI.jar - - - org.black_ixx - PlayerPoints - 2.1.4 - system - ${project.basedir}/lib/PlayerPoints.jar - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + pw.yumc + YumCore + 1.2 + YumCore + + ${project.name} + + + src/main/resources + true + + + + + maven-compiler-plugin + 3.3 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + source + compile + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + javadocs + package + + jar + + + false + + + + + + + + Jenkins + http://ci.yumc.pw + + + UTF-8 + UTF-8 + 开发版本 + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + yumc-repo + http://repo.yumc.pw/content/groups/public/ + + + + + jtb + YUMC + http://repo.yumc.pw/content/repositories/yumcenter/ + + + + + org.spigotmc + spigot-api + 1.10.2-R0.1-SNAPSHOT + + + net.milkbowl.vault + Vault + 1.5.6 + + + javax.mail + mail + 1.4.7 + + + org.spigotmc + spigot1102 + 1.10.2 + system + ${project.basedir}/lib/spigot-1.10.2.jar + + + org.spigotmc + spigot188 + 1.8.8 + system + ${project.basedir}/lib/spigot-1.8.8.jar + + + org.bukkit + craftbukkit + 1.7.10 + system + ${project.basedir}/lib/craftbukkit-1.7.10.jar + + + com.comphenix.protocol + ProtocolLib + 3.6.5-SNAPSHOT + system + ${project.basedir}/lib/ProtocolLib-3.6.5-SNAPSHOT.jar + + + me.clip + PlaceholderAPI + 1.8.6 + system + ${project.basedir}/lib/PlaceholderAPI.jar + + + org.black_ixx + PlayerPoints + 2.1.4 + system + ${project.basedir}/lib/PlayerPoints.jar + + \ No newline at end of file diff --git a/src/main/java/pw/yumc/YumCore/bukkit/compatible/C.java b/src/main/java/pw/yumc/YumCore/bukkit/compatible/C.java index 6963231..f780aa9 100644 --- a/src/main/java/pw/yumc/YumCore/bukkit/compatible/C.java +++ b/src/main/java/pw/yumc/YumCore/bukkit/compatible/C.java @@ -163,7 +163,7 @@ public class C { * ActionBar信息 */ public static void send(org.bukkit.entity.Player receivingPacket, String msg) { - Object packet = null; + Object packet; try { Object serialized = nmsChatSerializer.getMethod("a", String.class).invoke(null, "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', JSONObject.escape(msg)) + "\"}"); if (!version.contains("1_7")) { @@ -241,14 +241,14 @@ public class C { } catch (Exception e) { try { gameProfileClass = Class.forName("com.mojang.authlib.GameProfile"); - } catch (Exception e1) { + } catch (Exception ignored) { } } - gameProfileConstructor = gameProfileClass.getDeclaredConstructor(new Class[] { UUID.class, String.class }); + gameProfileConstructor = gameProfileClass.getDeclaredConstructor(UUID.class, String.class); gameProfileConstructor.setAccessible(true); Class craftServer = Bukkit.getServer().getClass(); Class craftOfflinePlayer = Class.forName(craftServer.getName().replace("CraftServer", "CraftOfflinePlayer")); - craftOfflinePlayerConstructor = craftOfflinePlayer.getDeclaredConstructor(new Class[] { craftServer, gameProfileClass }); + craftOfflinePlayerConstructor = craftOfflinePlayer.getDeclaredConstructor(craftServer, gameProfileClass); craftOfflinePlayerConstructor.setAccessible(true); // getOfflinePlayer end } catch (Exception e) { @@ -268,8 +268,8 @@ public class C { */ public static OfflinePlayer getOfflinePlayer(String playerName) { try { - Object gameProfile = gameProfileConstructor.newInstance(new Object[] { UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(Charsets.UTF_8)), playerName }); - Object offlinePlayer = craftOfflinePlayerConstructor.newInstance(new Object[] { Bukkit.getServer(), gameProfile }); + Object gameProfile = gameProfileConstructor.newInstance(UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(Charsets.UTF_8)), playerName); + Object offlinePlayer = craftOfflinePlayerConstructor.newInstance(Bukkit.getServer(), gameProfile); return (OfflinePlayer) offlinePlayer; } catch (Exception e) { return Bukkit.getOfflinePlayer(playerName); @@ -402,7 +402,7 @@ public class C { Object player = getHandle.invoke(receivingPacket); Object connection = playerConnection.get(player); Object[] actions = packetActions.getEnumConstants(); - Object packet = null; + Object packet; // Send if set if ((fadeInTime != -1) && (fadeOutTime != -1) && (stayTime != -1)) { packet = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(actions[2], diff --git a/src/main/java/pw/yumc/YumCore/commands/CommandParse.java b/src/main/java/pw/yumc/YumCore/commands/CommandParse.java index 4ee4729..7ff89de 100644 --- a/src/main/java/pw/yumc/YumCore/commands/CommandParse.java +++ b/src/main/java/pw/yumc/YumCore/commands/CommandParse.java @@ -1,20 +1,21 @@ package pw.yumc.YumCore.commands; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import pw.yumc.YumCore.bukkit.Log; -import pw.yumc.YumCore.commands.annotation.Default; -import pw.yumc.YumCore.commands.annotation.KeyValue; -import pw.yumc.YumCore.commands.annotation.Limit; -import pw.yumc.YumCore.commands.exception.CommandParseException; - import java.io.File; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.*; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import pw.yumc.YumCore.bukkit.Log; +import pw.yumc.YumCore.commands.annotation.Default; +import pw.yumc.YumCore.commands.annotation.KeyValue; +import pw.yumc.YumCore.commands.annotation.Limit; +import pw.yumc.YumCore.commands.exception.CommandParseException; + /** * 命令参数解析 * @@ -271,6 +272,8 @@ public class CommandParse { } public static class PlayerParse extends Parse { + boolean check = false; + public PlayerParse() { register(Player.class, this); } @@ -278,9 +281,16 @@ public class CommandParse { @Override public Player parse(CommandSender sender, String arg) { Player p = Bukkit.getPlayerExact(arg); - if (attrs.containsKey("check") && p == null) { throw new CommandParseException("玩家 " + arg + "不存在或不在线!"); } + if (check && p == null) { throw new CommandParseException("玩家 " + arg + " 不存在或不在线!"); } return p; } + + @Override + public Parse parseAnnotation(Annotation[] annotations) { + super.parseAnnotation(annotations); + check = attrs.containsKey("check"); + return this; + } } public static class StringParse extends Parse { @@ -303,10 +313,11 @@ public class CommandParse { @Override public Parse parseAnnotation(Annotation[] annotations) { + super.parseAnnotation(annotations); if (attrs.containsKey("option")) { options = Arrays.asList(attrs.get("option").split(",")); } - return super.parseAnnotation(annotations); + return this; } } } diff --git a/src/main/java/pw/yumc/YumCore/commands/annotation/Cmd.java b/src/main/java/pw/yumc/YumCore/commands/annotation/Cmd.java index 7096943..cd47dbb 100644 --- a/src/main/java/pw/yumc/YumCore/commands/annotation/Cmd.java +++ b/src/main/java/pw/yumc/YumCore/commands/annotation/Cmd.java @@ -61,7 +61,7 @@ public @interface Cmd { * @author 喵♂呜 * @since 2016年8月26日 下午8:55:15 */ - public enum Executor { + enum Executor { /** * 玩家 */ @@ -92,7 +92,7 @@ public @interface Cmd { UNKNOW("未知"); private String name; - private Executor(String name) { + Executor(String name) { this.name = name; } diff --git a/src/main/java/pw/yumc/YumCore/commands/annotation/Limit.java b/src/main/java/pw/yumc/YumCore/commands/annotation/Limit.java index bd58c48..83114e5 100644 --- a/src/main/java/pw/yumc/YumCore/commands/annotation/Limit.java +++ b/src/main/java/pw/yumc/YumCore/commands/annotation/Limit.java @@ -17,7 +17,7 @@ public @interface Limit { /** * @return 最大长度(最大值) */ - int max() default 255; + int max() default Integer.MAX_VALUE; /** * @return 最小长度(或最小值) diff --git a/src/main/java/pw/yumc/YumCore/commands/interfaces/CommandHelpParse.java b/src/main/java/pw/yumc/YumCore/commands/interfaces/CommandHelpParse.java index 377539d..5d101ee 100644 --- a/src/main/java/pw/yumc/YumCore/commands/interfaces/CommandHelpParse.java +++ b/src/main/java/pw/yumc/YumCore/commands/interfaces/CommandHelpParse.java @@ -14,5 +14,5 @@ public interface CommandHelpParse { * 参数 * @return 命令帮助 */ - public String parse(String str); + String parse(String str); } diff --git a/src/main/java/pw/yumc/YumCore/config/ext/RemoteConfig.java b/src/main/java/pw/yumc/YumCore/config/ext/RemoteConfig.java index 583dd4b..aaa313d 100644 --- a/src/main/java/pw/yumc/YumCore/config/ext/RemoteConfig.java +++ b/src/main/java/pw/yumc/YumCore/config/ext/RemoteConfig.java @@ -1,7 +1,6 @@ package pw.yumc.YumCore.config.ext; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; import pw.yumc.YumCore.bukkit.Log; @@ -14,7 +13,7 @@ import pw.yumc.YumCore.config.FileConfig; * @author 喵♂呜 */ public class RemoteConfig extends FileConfig { - public RemoteConfig(String url) throws MalformedURLException, IOException { + public RemoteConfig(String url) throws IOException { this(new URL(url)); } @@ -51,10 +50,9 @@ public class RemoteConfig extends FileConfig { */ public static String getYamlTag(String url, String tag, String def) { String result = def; - try { - result = getConfig(url).getString(tag); - } catch (NullPointerException e) { - // Ignore + FileConfig config = getConfig(url); + if (config != null) { + result = config.getString(tag); } return result; } diff --git a/src/main/java/pw/yumc/YumCore/config/inject/AbstractInjectConfig.java b/src/main/java/pw/yumc/YumCore/config/inject/AbstractInjectConfig.java index a8078d0..0422245 100644 --- a/src/main/java/pw/yumc/YumCore/config/inject/AbstractInjectConfig.java +++ b/src/main/java/pw/yumc/YumCore/config/inject/AbstractInjectConfig.java @@ -1,15 +1,5 @@ package pw.yumc.YumCore.config.inject; -import org.bukkit.ChatColor; -import org.bukkit.configuration.ConfigurationSection; -import pw.yumc.YumCore.bukkit.Log; -import pw.yumc.YumCore.commands.exception.CommandParseException; -import pw.yumc.YumCore.config.annotation.ConfigNode; -import pw.yumc.YumCore.config.annotation.Default; -import pw.yumc.YumCore.config.annotation.Nullable; -import pw.yumc.YumCore.config.annotation.ReadOnly; -import pw.yumc.YumCore.config.exception.ConfigParseException; - import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Modifier; @@ -17,6 +7,17 @@ import java.text.ParseException; import java.util.ArrayList; import java.util.HashMap; +import org.bukkit.ChatColor; +import org.bukkit.configuration.ConfigurationSection; + +import pw.yumc.YumCore.bukkit.Log; +import pw.yumc.YumCore.commands.exception.CommandParseException; +import pw.yumc.YumCore.config.annotation.ConfigNode; +import pw.yumc.YumCore.config.annotation.Default; +import pw.yumc.YumCore.config.annotation.Nullable; +import pw.yumc.YumCore.config.annotation.ReadOnly; +import pw.yumc.YumCore.config.exception.ConfigParseException; + /** * 抽象注入配置 * diff --git a/src/main/java/pw/yumc/YumCore/config/inject/InjectParse.java b/src/main/java/pw/yumc/YumCore/config/inject/InjectParse.java index 97985cc..de70fea 100644 --- a/src/main/java/pw/yumc/YumCore/config/inject/InjectParse.java +++ b/src/main/java/pw/yumc/YumCore/config/inject/InjectParse.java @@ -80,7 +80,7 @@ public class InjectParse { @Override public Map parse(ConfigurationSection config, String path) { - return config.getConfigurationSection(path).getValues(true); + return config.getConfigurationSection(path).getValues(false); } } diff --git a/src/main/java/pw/yumc/YumCore/kit/EntityKit.java b/src/main/java/pw/yumc/YumCore/kit/EntityKit.java index c4ce855..70b083b 100644 --- a/src/main/java/pw/yumc/YumCore/kit/EntityKit.java +++ b/src/main/java/pw/yumc/YumCore/kit/EntityKit.java @@ -1,6 +1,7 @@ package pw.yumc.YumCore.kit; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -101,9 +102,7 @@ public class EntityKit { public static Entity getEntityById(int entityId) { for (World world : Bukkit.getWorlds()) { for (Entity entity : world.getEntities()) { - if (entity.getEntityId() == entityId) { - return entity; - } + if (entity.getEntityId() == entityId) { return entity; } } } return null; @@ -130,8 +129,8 @@ public class EntityKit { public static boolean isInvisible(Entity entity) { Object ent = ReflectUtil.getHandle(entity); try { - return (boolean) ent.getClass().getMethod("isInvisible").invoke(ent); - } catch (Exception e) { + if (ent != null) { return (boolean) ent.getClass().getMethod("isInvisible").invoke(ent); } + } catch (Exception ignored) { } return false; } @@ -199,20 +198,15 @@ public class EntityKit { for (int x = xMin; x <= xMax; x++) { for (int z = zMin; z <= zMax; z++) { // Standing on SOMETHING - if (entity.getLocation().add(x, -0.5, z).getBlock().getType() != Material.AIR && !entity.getLocation().add(x, -0.5, z).getBlock().isLiquid()) { - return true; - } + if (entity.getLocation().add(x, -0.5, z).getBlock().getType() != Material.AIR && !entity.getLocation().add(x, -0.5, z).getBlock().isLiquid()) { return true; } // Inside a Lillypad - if (entity.getLocation().add(x, 0, z).getBlock().getType() == Material.WATER_LILY) { - return true; - } + if (entity.getLocation().add(x, 0, z).getBlock().getType() == Material.WATER_LILY) { return true; } // Fences/Walls Material beneath = entity.getLocation().add(x, -1.5, z).getBlock().getType(); - if (entity.getLocation().getY() % 0.5 == 0 && (beneath == Material.FENCE || beneath == Material.FENCE_GATE || beneath == Material.NETHER_FENCE || beneath == Material.COBBLE_WALL)) { - return true; - } + if (entity.getLocation().getY() % 0.5 == 0 + && (beneath == Material.FENCE || beneath == Material.FENCE_GATE || beneath == Material.NETHER_FENCE || beneath == Material.COBBLE_WALL)) { return true; } } } @@ -233,7 +227,7 @@ public class EntityKit { if (type == null) { try { type = EntityType.valueOf(str.toUpperCase()); - } catch (Exception e) { + } catch (Exception ignored) { } } } @@ -255,9 +249,11 @@ public class EntityKit { Object creature = ReflectUtil.getHandle(entity); if (_cEntityInsentient.isInstance(creature)) { Object world = ReflectUtil.getHandle(entity.getWorld()); - Object methodProfiler = world.getClass().getField("methodProfiler").get(world); - Object goalSelector = _cPathfinderGoalSelector.getConstructor(methodProfiler.getClass()).newInstance(methodProfiler); - _fgoalSelector.set(creature, goalSelector); + if (world != null) { + Object methodProfiler = world.getClass().getField("methodProfiler").get(world); + Object goalSelector = _cPathfinderGoalSelector.getConstructor(methodProfiler.getClass()).newInstance(methodProfiler); + _fgoalSelector.set(creature, goalSelector); + } } } catch (Exception e) { e.printStackTrace(); @@ -275,8 +271,10 @@ public class EntityKit { public static void setInvisible(Entity entity, boolean invisible) { Object ent = ReflectUtil.getHandle(entity); try { - ent.getClass().getMethod("setInvisible", boolean.class).invoke(ent, invisible); - } catch (Exception e) { + if (ent != null) { + ent.getClass().getMethod("setInvisible", boolean.class).invoke(ent, invisible); + } + } catch (Exception ignored) { } } @@ -309,15 +307,16 @@ public class EntityKit { if (_mPlayerConnection_Teleport == null) { _mPlayerConnection_Teleport = ReflectUtil.getMethodByNameAndParams(playerConnection.getClass(), "teleport", Location.class); } - try { - _mPlayerConnection_Teleport.invoke(playerConnection, to); - } catch (Exception ex) { - ex.printStackTrace(); + if (_mPlayerConnection_Teleport != null) { + try { + _mPlayerConnection_Teleport.invoke(playerConnection, to); + } catch (IllegalAccessException | InvocationTargetException ignored) { + } } } else { Object toWorldServer = ReflectUtil.getHandle(to.getWorld()); Object server = ReflectUtil.getHandle(Bukkit.getServer()); - if (_fWorldServer_dimension == null) { + if (_fWorldServer_dimension == null && toWorldServer != null) { for (Field field : ReflectUtil.getFieldByType(toWorldServer.getClass(), Integer.TYPE)) { int modifier = field.getModifiers(); if (Modifier.isFinal(modifier) && Modifier.isPublic(modifier)) { @@ -326,7 +325,7 @@ public class EntityKit { } } try { - _mPlayerList_MoveToWorld.invoke(server, ReflectUtil.getHandle(entity), (int) _fWorldServer_dimension.get(toWorldServer), true, to, true); + _mPlayerList_MoveToWorld.invoke(server, ReflectUtil.getHandle(entity), _fWorldServer_dimension.get(toWorldServer), true, to, true); } catch (Exception e) { e.printStackTrace(); } @@ -371,9 +370,7 @@ public class EntityKit { * 当实体在地上的时候,会稍微抬起一些 */ public static void velocity(Entity ent, Vector vec, double speed, boolean ySet, double yBase, double yAdd, double yMax, boolean groundBoost) { - if ((Double.isNaN(vec.getX())) || (Double.isNaN(vec.getY())) || (Double.isNaN(vec.getZ())) || (vec.length() == 0.0D)) { - return; - } + if ((Double.isNaN(vec.getX())) || (Double.isNaN(vec.getY())) || (Double.isNaN(vec.getZ())) || (vec.length() == 0.0D)) { return; } if (ySet) { vec.setY(yBase); @@ -396,9 +393,7 @@ public class EntityKit { } public static void walkTo(Entity entity, Location location) { - if (entity == null || location == null) { - return; - } + if (entity == null || location == null) { return; } Object nmsEntityEntity = ReflectUtil.getHandle(entity); if (!_cEntityInsentient.isInstance(nmsEntityEntity)) { entity.teleport(location); diff --git a/src/main/java/pw/yumc/YumCore/kit/FileKit.java b/src/main/java/pw/yumc/YumCore/kit/FileKit.java index 75df22d..53264a6 100644 --- a/src/main/java/pw/yumc/YumCore/kit/FileKit.java +++ b/src/main/java/pw/yumc/YumCore/kit/FileKit.java @@ -22,6 +22,7 @@ public class FileKit { public static boolean deleteDir(final CommandSender sender, final File dir) { if (dir.isDirectory()) { final String[] children = dir.list(); + if (children == null) { return false; } // 递归删除目录中的子目录下 for (final String element : children) { final File file = new File(dir, element); diff --git a/src/main/java/pw/yumc/YumCore/kit/HashKit.java b/src/main/java/pw/yumc/YumCore/kit/HashKit.java index 1746295..d8c95fa 100644 --- a/src/main/java/pw/yumc/YumCore/kit/HashKit.java +++ b/src/main/java/pw/yumc/YumCore/kit/HashKit.java @@ -1,19 +1,3 @@ -/** - * Copyright (c) 2011-2015, James Zhan 詹波 (j@126.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package pw.yumc.YumCore.kit; import java.security.MessageDigest; @@ -59,15 +43,7 @@ public class HashKit { try { StringBuilder result = new StringBuilder(); MessageDigest md = MessageDigest.getInstance(algorithm); - byte[] bytes = md.digest(srcStr.getBytes("utf-8")); - for (byte b : bytes) { - String hex = Integer.toHexString(b & 0xFF); - if (hex.length() == 1) { - result.append("0"); - } - result.append(hex); - } - return result.toString(); + return merge(result, md.digest(srcStr.getBytes("utf-8"))).toString(); } catch (Exception e) { throw new RuntimeException(e); } @@ -136,7 +112,10 @@ public class HashKit { * @return 字符串 */ private static String toHex(byte[] bytes) { - StringBuilder result = new StringBuilder(); + return merge(new StringBuilder(), bytes).toString(); + } + + private static StringBuilder merge(StringBuilder result, byte[] bytes) { for (byte b : bytes) { String hex = Integer.toHexString(b & 0xFF); if (hex.length() == 1) { @@ -144,6 +123,6 @@ public class HashKit { } result.append(hex); } - return result.toString(); + return result; } } diff --git a/src/main/java/pw/yumc/YumCore/kit/HttpKit.java b/src/main/java/pw/yumc/YumCore/kit/HttpKit.java index ca29f3b..9bd1298 100644 --- a/src/main/java/pw/yumc/YumCore/kit/HttpKit.java +++ b/src/main/java/pw/yumc/YumCore/kit/HttpKit.java @@ -1,27 +1,6 @@ -/** - * Copyright (c) 2011-2015, James Zhan 詹波 (j@126.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package pw.yumc.YumCore.kit; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; +import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; @@ -33,13 +12,7 @@ import java.security.cert.X509Certificate; import java.util.Map; import java.util.Map.Entry; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; +import javax.net.ssl.*; /** * HttpKit @@ -195,13 +168,11 @@ public class HttpKit { * @return 构建后的地址 */ private static String buildUrlWithQueryString(String url, Map queryParas) { - if (queryParas == null || queryParas.isEmpty()) { - return url; - } + if (queryParas == null || queryParas.isEmpty()) { return url; } StringBuilder sb = new StringBuilder(url); boolean isFirst; - if (url.indexOf("?") == -1) { + if (!url.contains("?")) { isFirst = true; sb.append("?"); } else { @@ -300,7 +271,7 @@ public class HttpKit { try { inputStream = conn.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, CHARSET)); - String line = null; + String line; while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } diff --git a/src/main/java/pw/yumc/YumCore/kit/PKit.java b/src/main/java/pw/yumc/YumCore/kit/PKit.java index 864780c..9cbb106 100644 --- a/src/main/java/pw/yumc/YumCore/kit/PKit.java +++ b/src/main/java/pw/yumc/YumCore/kit/PKit.java @@ -58,10 +58,8 @@ public class PKit { for (StackTraceElement element : stacktrace) { try { ClassLoader loader = Class.forName(element.getClassName(), false, PKit.class.getClassLoader()).getClassLoader(); - if (pluginMap.containsKey(loader)) { - return pluginMap.get(loader); - } - } catch (ClassNotFoundException ex) { + if (pluginMap.containsKey(loader)) { return pluginMap.get(loader); } + } catch (ClassNotFoundException ignored) { } } return null; diff --git a/src/main/java/pw/yumc/YumCore/kit/StrKit.java b/src/main/java/pw/yumc/YumCore/kit/StrKit.java index b8f1e5e..60b93e7 100644 --- a/src/main/java/pw/yumc/YumCore/kit/StrKit.java +++ b/src/main/java/pw/yumc/YumCore/kit/StrKit.java @@ -113,7 +113,7 @@ public class StrKit { * @return 字符串 */ public static String join(Object[] arr, String split) { - StringBuffer str = new StringBuffer(); + StringBuilder str = new StringBuilder(); for (Object s : arr) { str.append(s.toString()); str.append(split); @@ -148,10 +148,7 @@ public class StrKit { */ public static boolean startsWithIgnoreCase(String string, String prefix) throws IllegalArgumentException, NullPointerException { Validate.notNull(string, "Cannot check a null string for a match"); - if (string.length() < prefix.length()) { - return false; - } - return string.regionMatches(true, 0, prefix, 0, prefix.length()); + return string.length() >= prefix.length() && string.regionMatches(true, 0, prefix, 0, prefix.length()); } /** @@ -201,9 +198,7 @@ public class StrKit { * null if null String input */ public static String substring(String str, int start, int end) { - if (str == null) { - return null; - } + if (str == null) { return null; } // handle negatives if (end < 0) { @@ -219,9 +214,7 @@ public class StrKit { } // if start is greater than end, return "" - if (start > end) { - return EMPTY; - } + if (start > end) { return EMPTY; } if (start < 0) { start = 0; diff --git a/src/main/java/pw/yumc/YumCore/kit/ZipKit.java b/src/main/java/pw/yumc/YumCore/kit/ZipKit.java index 2abe2b6..a988ddf 100644 --- a/src/main/java/pw/yumc/YumCore/kit/ZipKit.java +++ b/src/main/java/pw/yumc/YumCore/kit/ZipKit.java @@ -37,7 +37,7 @@ public class ZipKit { * @throws IOException * IO异常 */ - public static void unzip(File zipFile, File destPath) throws ZipException, IOException { + public static void unzip(File zipFile, File destPath) throws IOException { unzip(zipFile, destPath, null); } @@ -53,7 +53,7 @@ public class ZipKit { * @throws IOException * IO异常 */ - public static void unzip(File zipFile, File destPath, String ext) throws ZipException, IOException { + public static void unzip(File zipFile, File destPath, String ext) throws IOException { ZipFile zipObj = new ZipFile(zipFile); Enumeration e = zipObj.entries(); while (e.hasMoreElements()) { diff --git a/src/main/java/pw/yumc/YumCore/mail/SimpleMailSender.java b/src/main/java/pw/yumc/YumCore/mail/SimpleMailSender.java index 2b0f775..7f16c9c 100644 --- a/src/main/java/pw/yumc/YumCore/mail/SimpleMailSender.java +++ b/src/main/java/pw/yumc/YumCore/mail/SimpleMailSender.java @@ -70,7 +70,7 @@ public class SimpleMailSender { * @throws AddressException * @throws MessagingException */ - public void send(SimpleMail mail, String... recipients) throws AddressException, MessagingException { + public void send(SimpleMail mail, String... recipients) throws MessagingException { // 创建mime类型邮件 MimeMessage message = new MimeMessage(session); // 设置发信人 @@ -112,7 +112,7 @@ public class SimpleMailSender { * @throws AddressException * @throws MessagingException */ - public void send(String subject, Object content, String... recipients) throws AddressException, MessagingException { + public void send(String subject, Object content, String... recipients) throws MessagingException { this.send(new SimpleMail(subject, content), recipients); } diff --git a/src/main/java/pw/yumc/YumCore/mail/XMail.java b/src/main/java/pw/yumc/YumCore/mail/XMail.java index b27744d..7bb004c 100644 --- a/src/main/java/pw/yumc/YumCore/mail/XMail.java +++ b/src/main/java/pw/yumc/YumCore/mail/XMail.java @@ -9,12 +9,7 @@ import javax.activation.DataContentHandler; import javax.activation.DataContentHandlerFactory; import javax.activation.DataHandler; import javax.activation.FileDataSource; -import javax.mail.Authenticator; -import javax.mail.BodyPart; -import javax.mail.Message; -import javax.mail.PasswordAuthentication; -import javax.mail.Session; -import javax.mail.Transport; +import javax.mail.*; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; @@ -45,9 +40,7 @@ public class XMail { @Override public DataContentHandler createDataContentHandler(String type) { DataContentHandler handler = handlers.get(type); - if (handler != null) { - return handler; - } + if (handler != null) { return handler; } System.out.println("************* Unknown Type: " + type + " *************"); return null; } @@ -66,7 +59,7 @@ public class XMail { try { DataHandler.setDataContentHandlerFactory(defaultDataContentHandlerFactory); return true; - } catch (Exception e) { + } catch (Exception ignored) { } return false; } @@ -215,7 +208,7 @@ public class XMail { Object object = field.get(null); field.set(null, null); return object; - } catch (Exception e) { + } catch (Exception ignored) { } return null; } diff --git a/src/main/java/pw/yumc/YumCore/paste/PasteContent.java b/src/main/java/pw/yumc/YumCore/paste/PasteContent.java index 6e9a739..d2848a4 100644 --- a/src/main/java/pw/yumc/YumCore/paste/PasteContent.java +++ b/src/main/java/pw/yumc/YumCore/paste/PasteContent.java @@ -29,9 +29,7 @@ public class PasteContent { * IO异常 */ public void addFile(File file) throws IOException { - if (file == null) { - throw new IllegalArgumentException("文件不得为Null!"); - } + if (file == null) { throw new IllegalArgumentException("文件不得为Null!"); } addLines(Files.readAllLines(file.toPath(), Charset.forName("UTF-8"))); } @@ -78,7 +76,7 @@ public class PasteContent { public String toString() { StringBuilder text = new StringBuilder(); for (String str : TEXT) { - text.append(str + '\n'); + text.append(str).append('\n'); } return text.toString(); } diff --git a/src/main/java/pw/yumc/YumCore/paste/PasteFormat.java b/src/main/java/pw/yumc/YumCore/paste/PasteFormat.java index c0c19de..f66b52f 100644 --- a/src/main/java/pw/yumc/YumCore/paste/PasteFormat.java +++ b/src/main/java/pw/yumc/YumCore/paste/PasteFormat.java @@ -14,7 +14,7 @@ public enum PasteFormat { String format; - private PasteFormat(String format) { + PasteFormat(String format) { this.format = format; } diff --git a/src/main/java/pw/yumc/YumCore/paste/PasteXcode.java b/src/main/java/pw/yumc/YumCore/paste/PasteXcode.java index 5a28e97..1ea22d2 100644 --- a/src/main/java/pw/yumc/YumCore/paste/PasteXcode.java +++ b/src/main/java/pw/yumc/YumCore/paste/PasteXcode.java @@ -13,7 +13,6 @@ public class PasteXcode { paste.addLine("异常提交测试!"); paste.addThrowable(new Throwable()); System.out.println(p.post(paste)); - ; } public String post(PasteContent content) { diff --git a/src/main/java/pw/yumc/YumCore/paste/Pastebin.java b/src/main/java/pw/yumc/YumCore/paste/Pastebin.java index e06f1e5..986409b 100644 --- a/src/main/java/pw/yumc/YumCore/paste/Pastebin.java +++ b/src/main/java/pw/yumc/YumCore/paste/Pastebin.java @@ -25,7 +25,6 @@ public class Pastebin { paste.addLine("异常提交测试!"); paste.addThrowable(new Throwable()); System.out.println(p.post(paste)); - ; } public String post(PasteContent content) { @@ -43,25 +42,14 @@ public class Pastebin { connection.setInstanceFollowRedirects(false); connection.setDoOutput(true); OutputStream outputStream = connection.getOutputStream(); - byte[] outByte = ("api_option=paste&api_dev_key=" - + URLEncoder.encode(this.API_KEY, "utf-8") - + "&api_paste_code=" - + URLEncoder.encode(content.toString(), "utf-8") - + "&api_paste_private=" - + URLEncoder.encode(level.getLevel(), "utf-8") - + "&api_paste_name=" - + URLEncoder.encode(name, "utf-8") - + "&api_paste_expire_date=" - + URLEncoder.encode("N", "utf-8") - + "&api_paste_format=" - + URLEncoder.encode(format.toString(), "utf-8") - + "&api_user_key=" - + URLEncoder.encode("", "utf-8")).getBytes(); + byte[] outByte = ("api_option=paste&api_dev_key=" + URLEncoder.encode(this.API_KEY, "utf-8") + "&api_paste_code=" + URLEncoder.encode(content.toString(), "utf-8") + "&api_paste_private=" + + URLEncoder.encode(level.getLevel(), "utf-8") + "&api_paste_name=" + URLEncoder.encode(name, "utf-8") + "&api_paste_expire_date=" + URLEncoder.encode("N", "utf-8") + + "&api_paste_format=" + URLEncoder.encode(format.toString(), "utf-8") + "&api_user_key=" + URLEncoder.encode("", "utf-8")).getBytes(); outputStream.write(outByte); outputStream.flush(); outputStream.close(); BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); - StringBuffer request = new StringBuffer(); + StringBuilder request = new StringBuilder(); String temp; while ((temp = br.readLine()) != null) { request.append(temp); @@ -85,7 +73,7 @@ public class Pastebin { int level; - private Private(int level) { + Private(int level) { this.level = level; } diff --git a/src/main/java/pw/yumc/YumCore/paste/StickyNotes.java b/src/main/java/pw/yumc/YumCore/paste/StickyNotes.java index 95ed6db..623b1d2 100644 --- a/src/main/java/pw/yumc/YumCore/paste/StickyNotes.java +++ b/src/main/java/pw/yumc/YumCore/paste/StickyNotes.java @@ -107,9 +107,7 @@ public class StickyNotes { result = request.toString().trim(); JSONObject object = (JSONObject) JSONValue.parse(result); object = (JSONObject) object.get("result"); - if (object.containsKey("error")) { - return object.get("error").toString(); - } + if (object.containsKey("error")) { return object.get("error").toString(); } return String.format(VIEW_URL, object.get("id"), object.get("hash")); } catch (Exception e) { e.printStackTrace(); @@ -134,7 +132,7 @@ public class StickyNotes { int expire; - private Expire(int expire) { + Expire(int expire) { this.expire = expire; } diff --git a/src/main/java/pw/yumc/YumCore/plugin/protocollib/PacketKit.java b/src/main/java/pw/yumc/YumCore/plugin/protocollib/PacketKit.java index c2905b7..aa6b0b0 100644 --- a/src/main/java/pw/yumc/YumCore/plugin/protocollib/PacketKit.java +++ b/src/main/java/pw/yumc/YumCore/plugin/protocollib/PacketKit.java @@ -19,7 +19,7 @@ import pw.yumc.YumCore.kit.PKit; * @author 喵♂呜 */ public class PacketKit { - public static boolean ENABLE = false;; + public static boolean ENABLE = false; private static ProtocolManager manager; static { diff --git a/src/main/java/pw/yumc/YumCore/reflect/Reflect.java b/src/main/java/pw/yumc/YumCore/reflect/Reflect.java index 1a67ed5..d6c830f 100644 --- a/src/main/java/pw/yumc/YumCore/reflect/Reflect.java +++ b/src/main/java/pw/yumc/YumCore/reflect/Reflect.java @@ -1,47 +1,6 @@ -/** - * Copyright (c) 2011-2013, Lukas Eder, lukas.eder@gmail.com - * All rights reserved. - * - * This software is licensed to you under the Apache License, Version 2.0 - * (the "License"); You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * . Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * . Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * . Neither the name "jOOR" nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ package pw.yumc.YumCore.reflect; -import java.lang.reflect.AccessibleObject; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.Proxy; +import java.lang.reflect.*; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Map; @@ -106,9 +65,7 @@ public class Reflect { * @return The argument object rendered accessible */ public static T accessible(final T accessible) { - if (accessible == null) { - return null; - } + if (accessible == null) { return null; } if (!accessible.isAccessible()) { accessible.setAccessible(true); @@ -140,9 +97,7 @@ public class Reflect { clazz = clazz.getSuperclass(); } } - if (field == null) { - throw new NoSuchFieldException("name is not found"); - } + if (field == null) { throw new NoSuchFieldException("name is not found"); } return field; } @@ -220,9 +175,7 @@ public class Reflect { return Float.class; } else if (char.class == type) { return Character.class; - } else if (void.class == type) { - return Void.class; - } + } else if (void.class == type) { return Void.class; } } return type; @@ -290,9 +243,7 @@ public class Reflect { * @see Object#getClass() */ private static Class[] types(final Object... values) { - if (values == null) { - return new Class[0]; - } + if (values == null) { return new Class[0]; } final Class[] result = new Class[values.length]; @@ -308,9 +259,7 @@ public class Reflect { * Unwrap an object */ private static Object unwrap(final Object object) { - if (object instanceof Reflect) { - return ((Reflect) object).get(); - } + if (object instanceof Reflect) { return ((Reflect) object).get(); } return object; } @@ -322,7 +271,6 @@ public class Reflect { * The interface type that is implemented by the proxy * @return A proxy for the wrapped object */ - @SuppressWarnings("unchecked") public

P as(final Class

proxyType) { final boolean isMap = (object instanceof Map); final InvocationHandler handler = new InvocationHandler() { @@ -506,9 +454,7 @@ public class Reflect { // signature if primitive argument types are converted to their wrappers catch (final NoSuchMethodException e) { for (final Constructor constructor : type().getConstructors()) { - if (match(constructor.getParameterTypes(), types)) { - return on(constructor, args); - } + if (match(constructor.getParameterTypes(), types)) { return on(constructor, args); } } throw new ReflectException(e); @@ -520,11 +466,7 @@ public class Reflect { */ @Override public boolean equals(final Object obj) { - if (obj instanceof Reflect) { - return object.equals(((Reflect) obj).get()); - } - - return false; + return obj instanceof Reflect && object.equals(((Reflect) obj).get()); } /** @@ -579,7 +521,7 @@ public class Reflect { * @return A map containing field names and wrapped values. */ public Map fields() { - final Map result = new LinkedHashMap(); + final Map result = new LinkedHashMap<>(); for (final Field field : type().getFields()) { if (!isClass ^ Modifier.isStatic(field.getModifiers())) { @@ -596,7 +538,6 @@ public class Reflect { * @param * A convenience generic parameter for automatic unsafe casting */ - @SuppressWarnings("unchecked") public T get() { return (T) object; } @@ -618,7 +559,7 @@ public class Reflect { * @see #field(String) */ public T get(final String name) throws ReflectException { - return field(name). get(); + return field(name).get(); } /** @@ -681,9 +622,7 @@ public class Reflect { * @see Object#getClass() */ public Class type() { - if (isClass) { - return (Class) object; - } + if (isClass) { return (Class) object; } return object.getClass(); } @@ -722,9 +661,7 @@ public class Reflect { private boolean match(final Class[] declaredTypes, final Class[] actualTypes) { if (declaredTypes.length == actualTypes.length) { for (int i = 0; i < actualTypes.length; i++) { - if (!wrapper(declaredTypes[i]).isAssignableFrom(wrapper(actualTypes[i]))) { - return false; - } + if (!wrapper(declaredTypes[i]).isAssignableFrom(wrapper(actualTypes[i]))) { return false; } } return true; } @@ -744,16 +681,12 @@ public class Reflect { // first priority: find a public method with a "similar" signature in class hierarchy // similar interpreted in when primitive argument types are converted to their wrappers for (final Method method : type.getMethods()) { - if (isSimilarSignature(method, name, types)) { - return method; - } + if (isSimilarSignature(method, name, types)) { return method; } } // second priority: find a non-public method with a "similar" signature on declaring class for (final Method method : type.getDeclaredMethods()) { - if (isSimilarSignature(method, name, types)) { - return method; - } + if (isSimilarSignature(method, name, types)) { return method; } } throw new NoSuchMethodException("No similar method " + name + " with params " + Arrays.toString(types) + " could be found on type " + type() + "."); diff --git a/src/main/java/pw/yumc/YumCore/reflect/ReflectException.java b/src/main/java/pw/yumc/YumCore/reflect/ReflectException.java index 4f6dbc9..52ac8eb 100644 --- a/src/main/java/pw/yumc/YumCore/reflect/ReflectException.java +++ b/src/main/java/pw/yumc/YumCore/reflect/ReflectException.java @@ -1,38 +1,3 @@ -/** - * Copyright (c) 2011-2013, Lukas Eder, lukas.eder@gmail.com - * All rights reserved. - * - * This software is licensed to you under the Apache License, Version 2.0 - * (the "License"); You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * . Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * . Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * . Neither the name "jOOR" nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ package pw.yumc.YumCore.reflect; import java.lang.reflect.InvocationTargetException; diff --git a/src/main/java/pw/yumc/YumCore/sql/DataBase.java b/src/main/java/pw/yumc/YumCore/sql/DataBase.java index df07d32..078f738 100644 --- a/src/main/java/pw/yumc/YumCore/sql/DataBase.java +++ b/src/main/java/pw/yumc/YumCore/sql/DataBase.java @@ -1,11 +1,6 @@ package pw.yumc.YumCore.sql; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; @@ -253,7 +248,7 @@ public class DataBase { while (dbresult.next()) { KeyValue kv = new KeyValue(); for (String col : fields.getKeys()) { - kv.add(col, dbresult.getString(col.toString())); + kv.add(col, dbresult.getString(col)); } kvlist.add(kv); } @@ -305,7 +300,7 @@ public class DataBase { while (dbresult.next()) { KeyValue kv = new KeyValue(); for (String col : fields) { - kv.add(col, dbresult.getString(col.toString())); + kv.add(col, dbresult.getString(col)); } kvlist.add(kv); } @@ -330,9 +325,7 @@ public class DataBase { String sql = "SELECT " + fields + " FROM " + tableName + " WHERE " + selConditions.toWhereString() + " limit 1"; try { ResultSet dbresult = this.dataBaseCore.query(sql); - if (dbresult.next()) { - return dbresult.getString(fields); - } + if (dbresult.next()) { return dbresult.getString(fields); } } catch (Exception e) { sqlerr(sql, e); } @@ -459,7 +452,7 @@ public class DataBase { } finally { try { con.setAutoCommit(true); - } catch (SQLException e) { + } catch (SQLException ignored) { } } } diff --git a/src/main/java/pw/yumc/YumCore/sql/core/DataBaseCore.java b/src/main/java/pw/yumc/YumCore/sql/core/DataBaseCore.java index b56fc0a..cd79f04 100644 --- a/src/main/java/pw/yumc/YumCore/sql/core/DataBaseCore.java +++ b/src/main/java/pw/yumc/YumCore/sql/core/DataBaseCore.java @@ -1,10 +1,6 @@ package pw.yumc.YumCore.sql.core; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; import pw.yumc.YumCore.bukkit.Log; @@ -95,8 +91,7 @@ public abstract class DataBaseCore { public ResultSet query(String sql) throws SQLException { debug(sql); Statement st = getStatement(); - ResultSet result = st.executeQuery(sql); - return result; + return st.executeQuery(sql); } /** diff --git a/src/main/java/pw/yumc/YumCore/statistic/Statistics.java b/src/main/java/pw/yumc/YumCore/statistic/Statistics.java index b12ba57..5908492 100644 --- a/src/main/java/pw/yumc/YumCore/statistic/Statistics.java +++ b/src/main/java/pw/yumc/YumCore/statistic/Statistics.java @@ -3,11 +3,7 @@ */ package pw.yumc.YumCore.statistic; -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintWriter; +import java.io.*; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URL; @@ -75,7 +71,7 @@ public class Statistics { Field field = pluginClassLoader.getClass().getDeclaredField("plugin"); field.setAccessible(true); plugin = (JavaPlugin) field.get(pluginClassLoader); - } catch (NoSuchMethodException | SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + } catch (NoSuchMethodException | SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException ignored) { } } @@ -115,7 +111,7 @@ public class Statistics { } config = YamlConfiguration.loadConfiguration(configfile); initFile(config); - } catch (IOException e) { + } catch (IOException ignored) { } this.guid = config.getString("guid"); this.debug = config.getBoolean("debug", false); @@ -133,7 +129,7 @@ public class Statistics { * @throws IOException */ public static String postData(String url, String param) throws IOException { - PrintWriter out = null; + PrintWriter out; String result = ""; URL realUrl = new URL(url); // 打开和URL之间的连接 @@ -153,15 +149,13 @@ public class Statistics { out.write(param); // flush输出流的缓冲 out.flush(); - String response = ""; + String response; BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), UTF_8)); while ((response = reader.readLine()) != null) { result += response; } reader.close(); - if (out != null) { - out.close(); - } + out.close(); return result; } @@ -208,9 +202,7 @@ public class Statistics { * @return 是否运行成功. */ public boolean start() { - if (task != null || !plugin.isEnabled()) { - return true; - } + if (task != null || !plugin.isEnabled()) { return true; } timer = new StatisticsTimer(); // 开启TPS统计线程 Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, timer, 0, 20); @@ -285,7 +277,7 @@ public class Statistics { public double getAverageTPS() { double avg = 0.0D; for (Double f : history) { - avg += f.doubleValue(); + avg += f; } return avg / history.size(); } diff --git a/src/main/java/pw/yumc/YumCore/update/SubscribeTask.java b/src/main/java/pw/yumc/YumCore/update/SubscribeTask.java index e1c692b..c368af0 100644 --- a/src/main/java/pw/yumc/YumCore/update/SubscribeTask.java +++ b/src/main/java/pw/yumc/YumCore/update/SubscribeTask.java @@ -176,7 +176,6 @@ public class SubscribeTask implements Runnable { File file = null; ClassLoader cl = plugin.getClass().getClassLoader(); if ((cl instanceof URLClassLoader)) { - @SuppressWarnings("resource") URLClassLoader ucl = (URLClassLoader) cl; URL url = ucl.getURLs()[0]; try { @@ -203,8 +202,7 @@ public class SubscribeTask implements Runnable { int idx = 0; int minLength = Math.min(va1.length, va2.length);// 取最小长度值 int diff = 0; - while (idx < minLength - && (diff = va1[idx].length() - va2[idx].length()) == 0// 先比较长度 + while (idx < minLength && (diff = va1[idx].length() - va2[idx].length()) == 0// 先比较长度 && (diff = va1[idx].compareTo(va2[idx])) == 0) {// 再比较字符 ++idx; } @@ -227,15 +225,13 @@ public class SubscribeTask implements Runnable { if (target.exists()) { try { PluginDescriptionFile desc = instance.getPluginLoader().getPluginDescription(target); - if (!needUpdate(result, desc.getVersion().split("-")[0])) { - return; - } + if (!needUpdate(result, desc.getVersion().split("-")[0])) { return; } target.delete(); } catch (Exception e) { debug(e); } } - String durl = null; + String durl; if (isMaven) { durl = String.format(maven, instance.getClass().getPackage().getName().replaceAll("\\.", "/"), result, instance.getName()); } else {