mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-21 01:38:51 +00:00
feat: 优化代码 添加配置初始化
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
8914c7c12f
commit
5234661fe5
282
pom.xml
282
pom.xml
@ -1,143 +1,143 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>YumCore</artifactId>
|
||||
<version>1.1</version>
|
||||
<name>YumCore</name>
|
||||
<build>
|
||||
<finalName>${project.name}</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>source</id><!--指定一个名字 -->
|
||||
<phase>compile</phase><!--在编译阶段生成source包 -->
|
||||
<goals>
|
||||
<goal>jar</goal><!--指定生成的文件为jar包 -->
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>javadocs</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<failOnError>false</failOnError>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<ciManagement>
|
||||
<system>Jenkins</system>
|
||||
<url>http://ci.yumc.pw</url>
|
||||
</ciManagement>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<env.GIT_COMMIT>开发版本</env.GIT_COMMIT>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>yumc-repo</id>
|
||||
<url>http://repo.yumc.pw/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>jtb</id>
|
||||
<name>YUMC</name>
|
||||
<url>http://repo.yumc.pw/content/repositories/yumcenter/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>1.5.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>1.4.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot1102</artifactId>
|
||||
<version>1.10.2</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/spigot-1.10.2.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot188</artifactId>
|
||||
<version>1.8.8</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/spigot-1.8.8.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.7.10</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/craftbukkit-1.7.10.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>3.6.5-SNAPSHOT</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/ProtocolLib-3.6.5-SNAPSHOT.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>PlaceholderAPI</artifactId>
|
||||
<version>1.8.6</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/PlaceholderAPI.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.black_ixx</groupId>
|
||||
<artifactId>PlayerPoints</artifactId>
|
||||
<version>2.1.4</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/PlayerPoints.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>YumCore</artifactId>
|
||||
<version>1.2</version>
|
||||
<name>YumCore</name>
|
||||
<build>
|
||||
<finalName>${project.name}</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>source</id><!--指定一个名字 -->
|
||||
<phase>compile</phase><!--在编译阶段生成source包 -->
|
||||
<goals>
|
||||
<goal>jar</goal><!--指定生成的文件为jar包 -->
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>javadocs</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<failOnError>false</failOnError>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<ciManagement>
|
||||
<system>Jenkins</system>
|
||||
<url>http://ci.yumc.pw</url>
|
||||
</ciManagement>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<env.GIT_COMMIT>开发版本</env.GIT_COMMIT>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>yumc-repo</id>
|
||||
<url>http://repo.yumc.pw/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>jtb</id>
|
||||
<name>YUMC</name>
|
||||
<url>http://repo.yumc.pw/content/repositories/yumcenter/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>1.5.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>1.4.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot1102</artifactId>
|
||||
<version>1.10.2</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/spigot-1.10.2.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot188</artifactId>
|
||||
<version>1.8.8</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/spigot-1.8.8.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.7.10</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/craftbukkit-1.7.10.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>3.6.5-SNAPSHOT</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/ProtocolLib-3.6.5-SNAPSHOT.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>PlaceholderAPI</artifactId>
|
||||
<version>1.8.6</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/PlaceholderAPI.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.black_ixx</groupId>
|
||||
<artifactId>PlayerPoints</artifactId>
|
||||
<version>2.1.4</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/PlayerPoints.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -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<? extends Server> 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],
|
||||
|
@ -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<Player> {
|
||||
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<Player> parseAnnotation(Annotation[] annotations) {
|
||||
super.parseAnnotation(annotations);
|
||||
check = attrs.containsKey("check");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringParse extends Parse<String> {
|
||||
@ -303,10 +313,11 @@ public class CommandParse {
|
||||
|
||||
@Override
|
||||
public Parse<String> parseAnnotation(Annotation[] annotations) {
|
||||
super.parseAnnotation(annotations);
|
||||
if (attrs.containsKey("option")) {
|
||||
options = Arrays.asList(attrs.get("option").split(","));
|
||||
}
|
||||
return super.parseAnnotation(annotations);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public @interface Limit {
|
||||
/**
|
||||
* @return 最大长度(最大值)
|
||||
*/
|
||||
int max() default 255;
|
||||
int max() default Integer.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* @return 最小长度(或最小值)
|
||||
|
@ -14,5 +14,5 @@ public interface CommandHelpParse {
|
||||
* 参数
|
||||
* @return 命令帮助
|
||||
*/
|
||||
public String parse(String str);
|
||||
String parse(String str);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
* 抽象注入配置
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<String, String> 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");
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
* <code>null</code> 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;
|
||||
|
@ -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<? extends ZipEntry> e = zipObj.entries();
|
||||
while (e.hasMoreElements()) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public enum PasteFormat {
|
||||
|
||||
String format;
|
||||
|
||||
private PasteFormat(String format) {
|
||||
PasteFormat(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ public class PasteXcode {
|
||||
paste.addLine("异常提交测试!");
|
||||
paste.addThrowable(new Throwable());
|
||||
System.out.println(p.post(paste));
|
||||
;
|
||||
}
|
||||
|
||||
public String post(PasteContent content) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 extends AccessibleObject> 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> P as(final Class<P> 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<String, Reflect> fields() {
|
||||
final Map<String, Reflect> result = new LinkedHashMap<String, Reflect>();
|
||||
final Map<String, Reflect> result = new LinkedHashMap<>();
|
||||
|
||||
for (final Field field : type().getFields()) {
|
||||
if (!isClass ^ Modifier.isStatic(field.getModifiers())) {
|
||||
@ -596,7 +538,6 @@ public class Reflect {
|
||||
* @param <T>
|
||||
* A convenience generic parameter for automatic unsafe casting
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T get() {
|
||||
return (T) object;
|
||||
}
|
||||
@ -618,7 +559,7 @@ public class Reflect {
|
||||
* @see #field(String)
|
||||
*/
|
||||
public <T> T get(final String name) throws ReflectException {
|
||||
return field(name).<T> 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() + ".");
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user