mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-22 01:48:50 +00:00
feat: 优化代码 添加配置初始化
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
8914c7c12f
commit
5234661fe5
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>YumCore</artifactId>
|
<artifactId>YumCore</artifactId>
|
||||||
<version>1.1</version>
|
<version>1.2</version>
|
||||||
<name>YumCore</name>
|
<name>YumCore</name>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.name}</finalName>
|
<finalName>${project.name}</finalName>
|
||||||
|
@ -163,7 +163,7 @@ public class C {
|
|||||||
* ActionBar信息
|
* ActionBar信息
|
||||||
*/
|
*/
|
||||||
public static void send(org.bukkit.entity.Player receivingPacket, String msg) {
|
public static void send(org.bukkit.entity.Player receivingPacket, String msg) {
|
||||||
Object packet = null;
|
Object packet;
|
||||||
try {
|
try {
|
||||||
Object serialized = nmsChatSerializer.getMethod("a", String.class).invoke(null, "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', JSONObject.escape(msg)) + "\"}");
|
Object serialized = nmsChatSerializer.getMethod("a", String.class).invoke(null, "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', JSONObject.escape(msg)) + "\"}");
|
||||||
if (!version.contains("1_7")) {
|
if (!version.contains("1_7")) {
|
||||||
@ -241,14 +241,14 @@ public class C {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
try {
|
try {
|
||||||
gameProfileClass = Class.forName("com.mojang.authlib.GameProfile");
|
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);
|
gameProfileConstructor.setAccessible(true);
|
||||||
Class<? extends Server> craftServer = Bukkit.getServer().getClass();
|
Class<? extends Server> craftServer = Bukkit.getServer().getClass();
|
||||||
Class<?> craftOfflinePlayer = Class.forName(craftServer.getName().replace("CraftServer", "CraftOfflinePlayer"));
|
Class<?> craftOfflinePlayer = Class.forName(craftServer.getName().replace("CraftServer", "CraftOfflinePlayer"));
|
||||||
craftOfflinePlayerConstructor = craftOfflinePlayer.getDeclaredConstructor(new Class[] { craftServer, gameProfileClass });
|
craftOfflinePlayerConstructor = craftOfflinePlayer.getDeclaredConstructor(craftServer, gameProfileClass);
|
||||||
craftOfflinePlayerConstructor.setAccessible(true);
|
craftOfflinePlayerConstructor.setAccessible(true);
|
||||||
// getOfflinePlayer end
|
// getOfflinePlayer end
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -268,8 +268,8 @@ public class C {
|
|||||||
*/
|
*/
|
||||||
public static OfflinePlayer getOfflinePlayer(String playerName) {
|
public static OfflinePlayer getOfflinePlayer(String playerName) {
|
||||||
try {
|
try {
|
||||||
Object gameProfile = gameProfileConstructor.newInstance(new Object[] { UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(Charsets.UTF_8)), playerName });
|
Object gameProfile = gameProfileConstructor.newInstance(UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(Charsets.UTF_8)), playerName);
|
||||||
Object offlinePlayer = craftOfflinePlayerConstructor.newInstance(new Object[] { Bukkit.getServer(), gameProfile });
|
Object offlinePlayer = craftOfflinePlayerConstructor.newInstance(Bukkit.getServer(), gameProfile);
|
||||||
return (OfflinePlayer) offlinePlayer;
|
return (OfflinePlayer) offlinePlayer;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Bukkit.getOfflinePlayer(playerName);
|
return Bukkit.getOfflinePlayer(playerName);
|
||||||
@ -402,7 +402,7 @@ public class C {
|
|||||||
Object player = getHandle.invoke(receivingPacket);
|
Object player = getHandle.invoke(receivingPacket);
|
||||||
Object connection = playerConnection.get(player);
|
Object connection = playerConnection.get(player);
|
||||||
Object[] actions = packetActions.getEnumConstants();
|
Object[] actions = packetActions.getEnumConstants();
|
||||||
Object packet = null;
|
Object packet;
|
||||||
// Send if set
|
// Send if set
|
||||||
if ((fadeInTime != -1) && (fadeOutTime != -1) && (stayTime != -1)) {
|
if ((fadeInTime != -1) && (fadeOutTime != -1) && (stayTime != -1)) {
|
||||||
packet = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(actions[2],
|
packet = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(actions[2],
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
package pw.yumc.YumCore.commands;
|
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.io.File;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
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> {
|
public static class PlayerParse extends Parse<Player> {
|
||||||
|
boolean check = false;
|
||||||
|
|
||||||
public PlayerParse() {
|
public PlayerParse() {
|
||||||
register(Player.class, this);
|
register(Player.class, this);
|
||||||
}
|
}
|
||||||
@ -278,9 +281,16 @@ public class CommandParse {
|
|||||||
@Override
|
@Override
|
||||||
public Player parse(CommandSender sender, String arg) {
|
public Player parse(CommandSender sender, String arg) {
|
||||||
Player p = Bukkit.getPlayerExact(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;
|
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> {
|
public static class StringParse extends Parse<String> {
|
||||||
@ -303,10 +313,11 @@ public class CommandParse {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Parse<String> parseAnnotation(Annotation[] annotations) {
|
public Parse<String> parseAnnotation(Annotation[] annotations) {
|
||||||
|
super.parseAnnotation(annotations);
|
||||||
if (attrs.containsKey("option")) {
|
if (attrs.containsKey("option")) {
|
||||||
options = Arrays.asList(attrs.get("option").split(","));
|
options = Arrays.asList(attrs.get("option").split(","));
|
||||||
}
|
}
|
||||||
return super.parseAnnotation(annotations);
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ public @interface Cmd {
|
|||||||
* @author 喵♂呜
|
* @author 喵♂呜
|
||||||
* @since 2016年8月26日 下午8:55:15
|
* @since 2016年8月26日 下午8:55:15
|
||||||
*/
|
*/
|
||||||
public enum Executor {
|
enum Executor {
|
||||||
/**
|
/**
|
||||||
* 玩家
|
* 玩家
|
||||||
*/
|
*/
|
||||||
@ -92,7 +92,7 @@ public @interface Cmd {
|
|||||||
UNKNOW("未知");
|
UNKNOW("未知");
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private Executor(String name) {
|
Executor(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ public @interface Limit {
|
|||||||
/**
|
/**
|
||||||
* @return 最大长度(最大值)
|
* @return 最大长度(最大值)
|
||||||
*/
|
*/
|
||||||
int max() default 255;
|
int max() default Integer.MAX_VALUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 最小长度(或最小值)
|
* @return 最小长度(或最小值)
|
||||||
|
@ -14,5 +14,5 @@ public interface CommandHelpParse {
|
|||||||
* 参数
|
* 参数
|
||||||
* @return 命令帮助
|
* @return 命令帮助
|
||||||
*/
|
*/
|
||||||
public String parse(String str);
|
String parse(String str);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package pw.yumc.YumCore.config.ext;
|
package pw.yumc.YumCore.config.ext;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
@ -14,7 +13,7 @@ import pw.yumc.YumCore.config.FileConfig;
|
|||||||
* @author 喵♂呜
|
* @author 喵♂呜
|
||||||
*/
|
*/
|
||||||
public class RemoteConfig extends FileConfig {
|
public class RemoteConfig extends FileConfig {
|
||||||
public RemoteConfig(String url) throws MalformedURLException, IOException {
|
public RemoteConfig(String url) throws IOException {
|
||||||
this(new URL(url));
|
this(new URL(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,10 +50,9 @@ public class RemoteConfig extends FileConfig {
|
|||||||
*/
|
*/
|
||||||
public static String getYamlTag(String url, String tag, String def) {
|
public static String getYamlTag(String url, String tag, String def) {
|
||||||
String result = def;
|
String result = def;
|
||||||
try {
|
FileConfig config = getConfig(url);
|
||||||
result = getConfig(url).getString(tag);
|
if (config != null) {
|
||||||
} catch (NullPointerException e) {
|
result = config.getString(tag);
|
||||||
// Ignore
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,5 @@
|
|||||||
package pw.yumc.YumCore.config.inject;
|
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.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@ -17,6 +7,17 @@ import java.text.ParseException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
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
|
@Override
|
||||||
public Map parse(ConfigurationSection config, String path) {
|
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;
|
package pw.yumc.YumCore.kit;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
@ -101,9 +102,7 @@ public class EntityKit {
|
|||||||
public static Entity getEntityById(int entityId) {
|
public static Entity getEntityById(int entityId) {
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
for (Entity entity : world.getEntities()) {
|
for (Entity entity : world.getEntities()) {
|
||||||
if (entity.getEntityId() == entityId) {
|
if (entity.getEntityId() == entityId) { return entity; }
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -130,8 +129,8 @@ public class EntityKit {
|
|||||||
public static boolean isInvisible(Entity entity) {
|
public static boolean isInvisible(Entity entity) {
|
||||||
Object ent = ReflectUtil.getHandle(entity);
|
Object ent = ReflectUtil.getHandle(entity);
|
||||||
try {
|
try {
|
||||||
return (boolean) ent.getClass().getMethod("isInvisible").invoke(ent);
|
if (ent != null) { return (boolean) ent.getClass().getMethod("isInvisible").invoke(ent); }
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -199,20 +198,15 @@ public class EntityKit {
|
|||||||
for (int x = xMin; x <= xMax; x++) {
|
for (int x = xMin; x <= xMax; x++) {
|
||||||
for (int z = zMin; z <= zMax; z++) {
|
for (int z = zMin; z <= zMax; z++) {
|
||||||
// Standing on SOMETHING
|
// Standing on SOMETHING
|
||||||
if (entity.getLocation().add(x, -0.5, z).getBlock().getType() != Material.AIR && !entity.getLocation().add(x, -0.5, z).getBlock().isLiquid()) {
|
if (entity.getLocation().add(x, -0.5, z).getBlock().getType() != Material.AIR && !entity.getLocation().add(x, -0.5, z).getBlock().isLiquid()) { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inside a Lillypad
|
// Inside a Lillypad
|
||||||
if (entity.getLocation().add(x, 0, z).getBlock().getType() == Material.WATER_LILY) {
|
if (entity.getLocation().add(x, 0, z).getBlock().getType() == Material.WATER_LILY) { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fences/Walls
|
// Fences/Walls
|
||||||
Material beneath = entity.getLocation().add(x, -1.5, z).getBlock().getType();
|
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)) {
|
if (entity.getLocation().getY() % 0.5 == 0
|
||||||
return true;
|
&& (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) {
|
if (type == null) {
|
||||||
try {
|
try {
|
||||||
type = EntityType.valueOf(str.toUpperCase());
|
type = EntityType.valueOf(str.toUpperCase());
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,10 +249,12 @@ public class EntityKit {
|
|||||||
Object creature = ReflectUtil.getHandle(entity);
|
Object creature = ReflectUtil.getHandle(entity);
|
||||||
if (_cEntityInsentient.isInstance(creature)) {
|
if (_cEntityInsentient.isInstance(creature)) {
|
||||||
Object world = ReflectUtil.getHandle(entity.getWorld());
|
Object world = ReflectUtil.getHandle(entity.getWorld());
|
||||||
|
if (world != null) {
|
||||||
Object methodProfiler = world.getClass().getField("methodProfiler").get(world);
|
Object methodProfiler = world.getClass().getField("methodProfiler").get(world);
|
||||||
Object goalSelector = _cPathfinderGoalSelector.getConstructor(methodProfiler.getClass()).newInstance(methodProfiler);
|
Object goalSelector = _cPathfinderGoalSelector.getConstructor(methodProfiler.getClass()).newInstance(methodProfiler);
|
||||||
_fgoalSelector.set(creature, goalSelector);
|
_fgoalSelector.set(creature, goalSelector);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -275,8 +271,10 @@ public class EntityKit {
|
|||||||
public static void setInvisible(Entity entity, boolean invisible) {
|
public static void setInvisible(Entity entity, boolean invisible) {
|
||||||
Object ent = ReflectUtil.getHandle(entity);
|
Object ent = ReflectUtil.getHandle(entity);
|
||||||
try {
|
try {
|
||||||
|
if (ent != null) {
|
||||||
ent.getClass().getMethod("setInvisible", boolean.class).invoke(ent, invisible);
|
ent.getClass().getMethod("setInvisible", boolean.class).invoke(ent, invisible);
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,15 +307,16 @@ public class EntityKit {
|
|||||||
if (_mPlayerConnection_Teleport == null) {
|
if (_mPlayerConnection_Teleport == null) {
|
||||||
_mPlayerConnection_Teleport = ReflectUtil.getMethodByNameAndParams(playerConnection.getClass(), "teleport", Location.class);
|
_mPlayerConnection_Teleport = ReflectUtil.getMethodByNameAndParams(playerConnection.getClass(), "teleport", Location.class);
|
||||||
}
|
}
|
||||||
|
if (_mPlayerConnection_Teleport != null) {
|
||||||
try {
|
try {
|
||||||
_mPlayerConnection_Teleport.invoke(playerConnection, to);
|
_mPlayerConnection_Teleport.invoke(playerConnection, to);
|
||||||
} catch (Exception ex) {
|
} catch (IllegalAccessException | InvocationTargetException ignored) {
|
||||||
ex.printStackTrace();
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Object toWorldServer = ReflectUtil.getHandle(to.getWorld());
|
Object toWorldServer = ReflectUtil.getHandle(to.getWorld());
|
||||||
Object server = ReflectUtil.getHandle(Bukkit.getServer());
|
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)) {
|
for (Field field : ReflectUtil.getFieldByType(toWorldServer.getClass(), Integer.TYPE)) {
|
||||||
int modifier = field.getModifiers();
|
int modifier = field.getModifiers();
|
||||||
if (Modifier.isFinal(modifier) && Modifier.isPublic(modifier)) {
|
if (Modifier.isFinal(modifier) && Modifier.isPublic(modifier)) {
|
||||||
@ -326,7 +325,7 @@ public class EntityKit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
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) {
|
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)) {
|
if ((Double.isNaN(vec.getX())) || (Double.isNaN(vec.getY())) || (Double.isNaN(vec.getZ())) || (vec.length() == 0.0D)) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ySet) {
|
if (ySet) {
|
||||||
vec.setY(yBase);
|
vec.setY(yBase);
|
||||||
@ -396,9 +393,7 @@ public class EntityKit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void walkTo(Entity entity, Location location) {
|
public static void walkTo(Entity entity, Location location) {
|
||||||
if (entity == null || location == null) {
|
if (entity == null || location == null) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
Object nmsEntityEntity = ReflectUtil.getHandle(entity);
|
Object nmsEntityEntity = ReflectUtil.getHandle(entity);
|
||||||
if (!_cEntityInsentient.isInstance(nmsEntityEntity)) {
|
if (!_cEntityInsentient.isInstance(nmsEntityEntity)) {
|
||||||
entity.teleport(location);
|
entity.teleport(location);
|
||||||
|
@ -22,6 +22,7 @@ public class FileKit {
|
|||||||
public static boolean deleteDir(final CommandSender sender, final File dir) {
|
public static boolean deleteDir(final CommandSender sender, final File dir) {
|
||||||
if (dir.isDirectory()) {
|
if (dir.isDirectory()) {
|
||||||
final String[] children = dir.list();
|
final String[] children = dir.list();
|
||||||
|
if (children == null) { return false; }
|
||||||
// 递归删除目录中的子目录下
|
// 递归删除目录中的子目录下
|
||||||
for (final String element : children) {
|
for (final String element : children) {
|
||||||
final File file = new File(dir, element);
|
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;
|
package pw.yumc.YumCore.kit;
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@ -59,15 +43,7 @@ public class HashKit {
|
|||||||
try {
|
try {
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
MessageDigest md = MessageDigest.getInstance(algorithm);
|
MessageDigest md = MessageDigest.getInstance(algorithm);
|
||||||
byte[] bytes = md.digest(srcStr.getBytes("utf-8"));
|
return merge(result, md.digest(srcStr.getBytes("utf-8"))).toString();
|
||||||
for (byte b : bytes) {
|
|
||||||
String hex = Integer.toHexString(b & 0xFF);
|
|
||||||
if (hex.length() == 1) {
|
|
||||||
result.append("0");
|
|
||||||
}
|
|
||||||
result.append(hex);
|
|
||||||
}
|
|
||||||
return result.toString();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -136,7 +112,10 @@ public class HashKit {
|
|||||||
* @return 字符串
|
* @return 字符串
|
||||||
*/
|
*/
|
||||||
private static String toHex(byte[] bytes) {
|
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) {
|
for (byte b : bytes) {
|
||||||
String hex = Integer.toHexString(b & 0xFF);
|
String hex = Integer.toHexString(b & 0xFF);
|
||||||
if (hex.length() == 1) {
|
if (hex.length() == 1) {
|
||||||
@ -144,6 +123,6 @@ public class HashKit {
|
|||||||
}
|
}
|
||||||
result.append(hex);
|
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;
|
package pw.yumc.YumCore.kit;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
@ -33,13 +12,7 @@ import java.security.cert.X509Certificate;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.*;
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HttpKit
|
* HttpKit
|
||||||
@ -195,13 +168,11 @@ public class HttpKit {
|
|||||||
* @return 构建后的地址
|
* @return 构建后的地址
|
||||||
*/
|
*/
|
||||||
private static String buildUrlWithQueryString(String url, Map<String, String> queryParas) {
|
private static String buildUrlWithQueryString(String url, Map<String, String> queryParas) {
|
||||||
if (queryParas == null || queryParas.isEmpty()) {
|
if (queryParas == null || queryParas.isEmpty()) { return url; }
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder(url);
|
StringBuilder sb = new StringBuilder(url);
|
||||||
boolean isFirst;
|
boolean isFirst;
|
||||||
if (url.indexOf("?") == -1) {
|
if (!url.contains("?")) {
|
||||||
isFirst = true;
|
isFirst = true;
|
||||||
sb.append("?");
|
sb.append("?");
|
||||||
} else {
|
} else {
|
||||||
@ -300,7 +271,7 @@ public class HttpKit {
|
|||||||
try {
|
try {
|
||||||
inputStream = conn.getInputStream();
|
inputStream = conn.getInputStream();
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, CHARSET));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, CHARSET));
|
||||||
String line = null;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
sb.append(line).append("\n");
|
sb.append(line).append("\n");
|
||||||
}
|
}
|
||||||
|
@ -58,10 +58,8 @@ public class PKit {
|
|||||||
for (StackTraceElement element : stacktrace) {
|
for (StackTraceElement element : stacktrace) {
|
||||||
try {
|
try {
|
||||||
ClassLoader loader = Class.forName(element.getClassName(), false, PKit.class.getClassLoader()).getClassLoader();
|
ClassLoader loader = Class.forName(element.getClassName(), false, PKit.class.getClassLoader()).getClassLoader();
|
||||||
if (pluginMap.containsKey(loader)) {
|
if (pluginMap.containsKey(loader)) { return pluginMap.get(loader); }
|
||||||
return pluginMap.get(loader);
|
} catch (ClassNotFoundException ignored) {
|
||||||
}
|
|
||||||
} catch (ClassNotFoundException ex) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -113,7 +113,7 @@ public class StrKit {
|
|||||||
* @return 字符串
|
* @return 字符串
|
||||||
*/
|
*/
|
||||||
public static String join(Object[] arr, String split) {
|
public static String join(Object[] arr, String split) {
|
||||||
StringBuffer str = new StringBuffer();
|
StringBuilder str = new StringBuilder();
|
||||||
for (Object s : arr) {
|
for (Object s : arr) {
|
||||||
str.append(s.toString());
|
str.append(s.toString());
|
||||||
str.append(split);
|
str.append(split);
|
||||||
@ -148,10 +148,7 @@ public class StrKit {
|
|||||||
*/
|
*/
|
||||||
public static boolean startsWithIgnoreCase(String string, String prefix) throws IllegalArgumentException, NullPointerException {
|
public static boolean startsWithIgnoreCase(String string, String prefix) throws IllegalArgumentException, NullPointerException {
|
||||||
Validate.notNull(string, "Cannot check a null string for a match");
|
Validate.notNull(string, "Cannot check a null string for a match");
|
||||||
if (string.length() < prefix.length()) {
|
return string.length() >= prefix.length() && string.regionMatches(true, 0, prefix, 0, prefix.length());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return string.regionMatches(true, 0, prefix, 0, prefix.length());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -201,9 +198,7 @@ public class StrKit {
|
|||||||
* <code>null</code> if null String input
|
* <code>null</code> if null String input
|
||||||
*/
|
*/
|
||||||
public static String substring(String str, int start, int end) {
|
public static String substring(String str, int start, int end) {
|
||||||
if (str == null) {
|
if (str == null) { return null; }
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle negatives
|
// handle negatives
|
||||||
if (end < 0) {
|
if (end < 0) {
|
||||||
@ -219,9 +214,7 @@ public class StrKit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if start is greater than end, return ""
|
// if start is greater than end, return ""
|
||||||
if (start > end) {
|
if (start > end) { return EMPTY; }
|
||||||
return EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
start = 0;
|
start = 0;
|
||||||
|
@ -37,7 +37,7 @@ public class ZipKit {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* IO异常
|
* 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);
|
unzip(zipFile, destPath, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ public class ZipKit {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* IO异常
|
* 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);
|
ZipFile zipObj = new ZipFile(zipFile);
|
||||||
Enumeration<? extends ZipEntry> e = zipObj.entries();
|
Enumeration<? extends ZipEntry> e = zipObj.entries();
|
||||||
while (e.hasMoreElements()) {
|
while (e.hasMoreElements()) {
|
||||||
|
@ -70,7 +70,7 @@ public class SimpleMailSender {
|
|||||||
* @throws AddressException
|
* @throws AddressException
|
||||||
* @throws MessagingException
|
* @throws MessagingException
|
||||||
*/
|
*/
|
||||||
public void send(SimpleMail mail, String... recipients) throws AddressException, MessagingException {
|
public void send(SimpleMail mail, String... recipients) throws MessagingException {
|
||||||
// 创建mime类型邮件
|
// 创建mime类型邮件
|
||||||
MimeMessage message = new MimeMessage(session);
|
MimeMessage message = new MimeMessage(session);
|
||||||
// 设置发信人
|
// 设置发信人
|
||||||
@ -112,7 +112,7 @@ public class SimpleMailSender {
|
|||||||
* @throws AddressException
|
* @throws AddressException
|
||||||
* @throws MessagingException
|
* @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);
|
this.send(new SimpleMail(subject, content), recipients);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,12 +9,7 @@ import javax.activation.DataContentHandler;
|
|||||||
import javax.activation.DataContentHandlerFactory;
|
import javax.activation.DataContentHandlerFactory;
|
||||||
import javax.activation.DataHandler;
|
import javax.activation.DataHandler;
|
||||||
import javax.activation.FileDataSource;
|
import javax.activation.FileDataSource;
|
||||||
import javax.mail.Authenticator;
|
import javax.mail.*;
|
||||||
import javax.mail.BodyPart;
|
|
||||||
import javax.mail.Message;
|
|
||||||
import javax.mail.PasswordAuthentication;
|
|
||||||
import javax.mail.Session;
|
|
||||||
import javax.mail.Transport;
|
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
import javax.mail.internet.MimeBodyPart;
|
import javax.mail.internet.MimeBodyPart;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
@ -45,9 +40,7 @@ public class XMail {
|
|||||||
@Override
|
@Override
|
||||||
public DataContentHandler createDataContentHandler(String type) {
|
public DataContentHandler createDataContentHandler(String type) {
|
||||||
DataContentHandler handler = handlers.get(type);
|
DataContentHandler handler = handlers.get(type);
|
||||||
if (handler != null) {
|
if (handler != null) { return handler; }
|
||||||
return handler;
|
|
||||||
}
|
|
||||||
System.out.println("************* Unknown Type: " + type + " *************");
|
System.out.println("************* Unknown Type: " + type + " *************");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -66,7 +59,7 @@ public class XMail {
|
|||||||
try {
|
try {
|
||||||
DataHandler.setDataContentHandlerFactory(defaultDataContentHandlerFactory);
|
DataHandler.setDataContentHandlerFactory(defaultDataContentHandlerFactory);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -215,7 +208,7 @@ public class XMail {
|
|||||||
Object object = field.get(null);
|
Object object = field.get(null);
|
||||||
field.set(null, null);
|
field.set(null, null);
|
||||||
return object;
|
return object;
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,7 @@ public class PasteContent {
|
|||||||
* IO异常
|
* IO异常
|
||||||
*/
|
*/
|
||||||
public void addFile(File file) throws IOException {
|
public void addFile(File file) throws IOException {
|
||||||
if (file == null) {
|
if (file == null) { throw new IllegalArgumentException("文件不得为Null!"); }
|
||||||
throw new IllegalArgumentException("文件不得为Null!");
|
|
||||||
}
|
|
||||||
addLines(Files.readAllLines(file.toPath(), Charset.forName("UTF-8")));
|
addLines(Files.readAllLines(file.toPath(), Charset.forName("UTF-8")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +76,7 @@ public class PasteContent {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder text = new StringBuilder();
|
StringBuilder text = new StringBuilder();
|
||||||
for (String str : TEXT) {
|
for (String str : TEXT) {
|
||||||
text.append(str + '\n');
|
text.append(str).append('\n');
|
||||||
}
|
}
|
||||||
return text.toString();
|
return text.toString();
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public enum PasteFormat {
|
|||||||
|
|
||||||
String format;
|
String format;
|
||||||
|
|
||||||
private PasteFormat(String format) {
|
PasteFormat(String format) {
|
||||||
this.format = format;
|
this.format = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ public class PasteXcode {
|
|||||||
paste.addLine("异常提交测试!");
|
paste.addLine("异常提交测试!");
|
||||||
paste.addThrowable(new Throwable());
|
paste.addThrowable(new Throwable());
|
||||||
System.out.println(p.post(paste));
|
System.out.println(p.post(paste));
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String post(PasteContent content) {
|
public String post(PasteContent content) {
|
||||||
|
@ -25,7 +25,6 @@ public class Pastebin {
|
|||||||
paste.addLine("异常提交测试!");
|
paste.addLine("异常提交测试!");
|
||||||
paste.addThrowable(new Throwable());
|
paste.addThrowable(new Throwable());
|
||||||
System.out.println(p.post(paste));
|
System.out.println(p.post(paste));
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String post(PasteContent content) {
|
public String post(PasteContent content) {
|
||||||
@ -43,25 +42,14 @@ public class Pastebin {
|
|||||||
connection.setInstanceFollowRedirects(false);
|
connection.setInstanceFollowRedirects(false);
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
OutputStream outputStream = connection.getOutputStream();
|
OutputStream outputStream = connection.getOutputStream();
|
||||||
byte[] outByte = ("api_option=paste&api_dev_key="
|
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(this.API_KEY, "utf-8")
|
+ 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_code="
|
+ "&api_paste_format=" + URLEncoder.encode(format.toString(), "utf-8") + "&api_user_key=" + URLEncoder.encode("", "utf-8")).getBytes();
|
||||||
+ 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.write(outByte);
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
StringBuffer request = new StringBuffer();
|
StringBuilder request = new StringBuilder();
|
||||||
String temp;
|
String temp;
|
||||||
while ((temp = br.readLine()) != null) {
|
while ((temp = br.readLine()) != null) {
|
||||||
request.append(temp);
|
request.append(temp);
|
||||||
@ -85,7 +73,7 @@ public class Pastebin {
|
|||||||
|
|
||||||
int level;
|
int level;
|
||||||
|
|
||||||
private Private(int level) {
|
Private(int level) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,9 +107,7 @@ public class StickyNotes {
|
|||||||
result = request.toString().trim();
|
result = request.toString().trim();
|
||||||
JSONObject object = (JSONObject) JSONValue.parse(result);
|
JSONObject object = (JSONObject) JSONValue.parse(result);
|
||||||
object = (JSONObject) object.get("result");
|
object = (JSONObject) object.get("result");
|
||||||
if (object.containsKey("error")) {
|
if (object.containsKey("error")) { return object.get("error").toString(); }
|
||||||
return object.get("error").toString();
|
|
||||||
}
|
|
||||||
return String.format(VIEW_URL, object.get("id"), object.get("hash"));
|
return String.format(VIEW_URL, object.get("id"), object.get("hash"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -134,7 +132,7 @@ public class StickyNotes {
|
|||||||
|
|
||||||
int expire;
|
int expire;
|
||||||
|
|
||||||
private Expire(int expire) {
|
Expire(int expire) {
|
||||||
this.expire = expire;
|
this.expire = expire;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import pw.yumc.YumCore.kit.PKit;
|
|||||||
* @author 喵♂呜
|
* @author 喵♂呜
|
||||||
*/
|
*/
|
||||||
public class PacketKit {
|
public class PacketKit {
|
||||||
public static boolean ENABLE = false;;
|
public static boolean ENABLE = false;
|
||||||
private static ProtocolManager manager;
|
private static ProtocolManager manager;
|
||||||
|
|
||||||
static {
|
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;
|
package pw.yumc.YumCore.reflect;
|
||||||
|
|
||||||
import java.lang.reflect.AccessibleObject;
|
import java.lang.reflect.*;
|
||||||
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.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -106,9 +65,7 @@ public class Reflect {
|
|||||||
* @return The argument object rendered accessible
|
* @return The argument object rendered accessible
|
||||||
*/
|
*/
|
||||||
public static <T extends AccessibleObject> T accessible(final T accessible) {
|
public static <T extends AccessibleObject> T accessible(final T accessible) {
|
||||||
if (accessible == null) {
|
if (accessible == null) { return null; }
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!accessible.isAccessible()) {
|
if (!accessible.isAccessible()) {
|
||||||
accessible.setAccessible(true);
|
accessible.setAccessible(true);
|
||||||
@ -140,9 +97,7 @@ public class Reflect {
|
|||||||
clazz = clazz.getSuperclass();
|
clazz = clazz.getSuperclass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (field == null) {
|
if (field == null) { throw new NoSuchFieldException("name is not found"); }
|
||||||
throw new NoSuchFieldException("name is not found");
|
|
||||||
}
|
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,9 +175,7 @@ public class Reflect {
|
|||||||
return Float.class;
|
return Float.class;
|
||||||
} else if (char.class == type) {
|
} else if (char.class == type) {
|
||||||
return Character.class;
|
return Character.class;
|
||||||
} else if (void.class == type) {
|
} else if (void.class == type) { return Void.class; }
|
||||||
return Void.class;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
@ -290,9 +243,7 @@ public class Reflect {
|
|||||||
* @see Object#getClass()
|
* @see Object#getClass()
|
||||||
*/
|
*/
|
||||||
private static Class<?>[] types(final Object... values) {
|
private static Class<?>[] types(final Object... values) {
|
||||||
if (values == null) {
|
if (values == null) { return new Class[0]; }
|
||||||
return new Class[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
final Class<?>[] result = new Class[values.length];
|
final Class<?>[] result = new Class[values.length];
|
||||||
|
|
||||||
@ -308,9 +259,7 @@ public class Reflect {
|
|||||||
* Unwrap an object
|
* Unwrap an object
|
||||||
*/
|
*/
|
||||||
private static Object unwrap(final Object object) {
|
private static Object unwrap(final Object object) {
|
||||||
if (object instanceof Reflect) {
|
if (object instanceof Reflect) { return ((Reflect) object).get(); }
|
||||||
return ((Reflect) object).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
@ -322,7 +271,6 @@ public class Reflect {
|
|||||||
* The interface type that is implemented by the proxy
|
* The interface type that is implemented by the proxy
|
||||||
* @return A proxy for the wrapped object
|
* @return A proxy for the wrapped object
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <P> P as(final Class<P> proxyType) {
|
public <P> P as(final Class<P> proxyType) {
|
||||||
final boolean isMap = (object instanceof Map);
|
final boolean isMap = (object instanceof Map);
|
||||||
final InvocationHandler handler = new InvocationHandler() {
|
final InvocationHandler handler = new InvocationHandler() {
|
||||||
@ -506,9 +454,7 @@ public class Reflect {
|
|||||||
// signature if primitive argument types are converted to their wrappers
|
// signature if primitive argument types are converted to their wrappers
|
||||||
catch (final NoSuchMethodException e) {
|
catch (final NoSuchMethodException e) {
|
||||||
for (final Constructor<?> constructor : type().getConstructors()) {
|
for (final Constructor<?> constructor : type().getConstructors()) {
|
||||||
if (match(constructor.getParameterTypes(), types)) {
|
if (match(constructor.getParameterTypes(), types)) { return on(constructor, args); }
|
||||||
return on(constructor, args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ReflectException(e);
|
throw new ReflectException(e);
|
||||||
@ -520,11 +466,7 @@ public class Reflect {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(final Object obj) {
|
||||||
if (obj instanceof Reflect) {
|
return obj instanceof Reflect && object.equals(((Reflect) obj).get());
|
||||||
return object.equals(((Reflect) obj).get());
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -579,7 +521,7 @@ public class Reflect {
|
|||||||
* @return A map containing field names and wrapped values.
|
* @return A map containing field names and wrapped values.
|
||||||
*/
|
*/
|
||||||
public Map<String, Reflect> fields() {
|
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()) {
|
for (final Field field : type().getFields()) {
|
||||||
if (!isClass ^ Modifier.isStatic(field.getModifiers())) {
|
if (!isClass ^ Modifier.isStatic(field.getModifiers())) {
|
||||||
@ -596,7 +538,6 @@ public class Reflect {
|
|||||||
* @param <T>
|
* @param <T>
|
||||||
* A convenience generic parameter for automatic unsafe casting
|
* A convenience generic parameter for automatic unsafe casting
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T> T get() {
|
public <T> T get() {
|
||||||
return (T) object;
|
return (T) object;
|
||||||
}
|
}
|
||||||
@ -618,7 +559,7 @@ public class Reflect {
|
|||||||
* @see #field(String)
|
* @see #field(String)
|
||||||
*/
|
*/
|
||||||
public <T> T get(final String name) throws ReflectException {
|
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()
|
* @see Object#getClass()
|
||||||
*/
|
*/
|
||||||
public Class<?> type() {
|
public Class<?> type() {
|
||||||
if (isClass) {
|
if (isClass) { return (Class<?>) object; }
|
||||||
return (Class<?>) object;
|
|
||||||
}
|
|
||||||
return object.getClass();
|
return object.getClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -722,9 +661,7 @@ public class Reflect {
|
|||||||
private boolean match(final Class<?>[] declaredTypes, final Class<?>[] actualTypes) {
|
private boolean match(final Class<?>[] declaredTypes, final Class<?>[] actualTypes) {
|
||||||
if (declaredTypes.length == actualTypes.length) {
|
if (declaredTypes.length == actualTypes.length) {
|
||||||
for (int i = 0; i < actualTypes.length; i++) {
|
for (int i = 0; i < actualTypes.length; i++) {
|
||||||
if (!wrapper(declaredTypes[i]).isAssignableFrom(wrapper(actualTypes[i]))) {
|
if (!wrapper(declaredTypes[i]).isAssignableFrom(wrapper(actualTypes[i]))) { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -744,16 +681,12 @@ public class Reflect {
|
|||||||
// first priority: find a public method with a "similar" signature in class hierarchy
|
// 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
|
// similar interpreted in when primitive argument types are converted to their wrappers
|
||||||
for (final Method method : type.getMethods()) {
|
for (final Method method : type.getMethods()) {
|
||||||
if (isSimilarSignature(method, name, types)) {
|
if (isSimilarSignature(method, name, types)) { return method; }
|
||||||
return method;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// second priority: find a non-public method with a "similar" signature on declaring class
|
// second priority: find a non-public method with a "similar" signature on declaring class
|
||||||
for (final Method method : type.getDeclaredMethods()) {
|
for (final Method method : type.getDeclaredMethods()) {
|
||||||
if (isSimilarSignature(method, name, types)) {
|
if (isSimilarSignature(method, name, types)) { return method; }
|
||||||
return method;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NoSuchMethodException("No similar method " + name + " with params " + Arrays.toString(types) + " could be found on type " + type() + ".");
|
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;
|
package pw.yumc.YumCore.reflect;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
package pw.yumc.YumCore.sql;
|
package pw.yumc.YumCore.sql;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DatabaseMetaData;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -253,7 +248,7 @@ public class DataBase {
|
|||||||
while (dbresult.next()) {
|
while (dbresult.next()) {
|
||||||
KeyValue kv = new KeyValue();
|
KeyValue kv = new KeyValue();
|
||||||
for (String col : fields.getKeys()) {
|
for (String col : fields.getKeys()) {
|
||||||
kv.add(col, dbresult.getString(col.toString()));
|
kv.add(col, dbresult.getString(col));
|
||||||
}
|
}
|
||||||
kvlist.add(kv);
|
kvlist.add(kv);
|
||||||
}
|
}
|
||||||
@ -305,7 +300,7 @@ public class DataBase {
|
|||||||
while (dbresult.next()) {
|
while (dbresult.next()) {
|
||||||
KeyValue kv = new KeyValue();
|
KeyValue kv = new KeyValue();
|
||||||
for (String col : fields) {
|
for (String col : fields) {
|
||||||
kv.add(col, dbresult.getString(col.toString()));
|
kv.add(col, dbresult.getString(col));
|
||||||
}
|
}
|
||||||
kvlist.add(kv);
|
kvlist.add(kv);
|
||||||
}
|
}
|
||||||
@ -330,9 +325,7 @@ public class DataBase {
|
|||||||
String sql = "SELECT " + fields + " FROM " + tableName + " WHERE " + selConditions.toWhereString() + " limit 1";
|
String sql = "SELECT " + fields + " FROM " + tableName + " WHERE " + selConditions.toWhereString() + " limit 1";
|
||||||
try {
|
try {
|
||||||
ResultSet dbresult = this.dataBaseCore.query(sql);
|
ResultSet dbresult = this.dataBaseCore.query(sql);
|
||||||
if (dbresult.next()) {
|
if (dbresult.next()) { return dbresult.getString(fields); }
|
||||||
return dbresult.getString(fields);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sqlerr(sql, e);
|
sqlerr(sql, e);
|
||||||
}
|
}
|
||||||
@ -459,7 +452,7 @@ public class DataBase {
|
|||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
con.setAutoCommit(true);
|
con.setAutoCommit(true);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package pw.yumc.YumCore.sql.core;
|
package pw.yumc.YumCore.sql.core;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
|
|
||||||
@ -95,8 +91,7 @@ public abstract class DataBaseCore {
|
|||||||
public ResultSet query(String sql) throws SQLException {
|
public ResultSet query(String sql) throws SQLException {
|
||||||
debug(sql);
|
debug(sql);
|
||||||
Statement st = getStatement();
|
Statement st = getStatement();
|
||||||
ResultSet result = st.executeQuery(sql);
|
return st.executeQuery(sql);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,11 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
package pw.yumc.YumCore.statistic;
|
package pw.yumc.YumCore.statistic;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -75,7 +71,7 @@ public class Statistics {
|
|||||||
Field field = pluginClassLoader.getClass().getDeclaredField("plugin");
|
Field field = pluginClassLoader.getClass().getDeclaredField("plugin");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
plugin = (JavaPlugin) field.get(pluginClassLoader);
|
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);
|
config = YamlConfiguration.loadConfiguration(configfile);
|
||||||
initFile(config);
|
initFile(config);
|
||||||
} catch (IOException e) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
this.guid = config.getString("guid");
|
this.guid = config.getString("guid");
|
||||||
this.debug = config.getBoolean("debug", false);
|
this.debug = config.getBoolean("debug", false);
|
||||||
@ -133,7 +129,7 @@ public class Statistics {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static String postData(String url, String param) throws IOException {
|
public static String postData(String url, String param) throws IOException {
|
||||||
PrintWriter out = null;
|
PrintWriter out;
|
||||||
String result = "";
|
String result = "";
|
||||||
URL realUrl = new URL(url);
|
URL realUrl = new URL(url);
|
||||||
// 打开和URL之间的连接
|
// 打开和URL之间的连接
|
||||||
@ -153,15 +149,13 @@ public class Statistics {
|
|||||||
out.write(param);
|
out.write(param);
|
||||||
// flush输出流的缓冲
|
// flush输出流的缓冲
|
||||||
out.flush();
|
out.flush();
|
||||||
String response = "";
|
String response;
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), UTF_8));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), UTF_8));
|
||||||
while ((response = reader.readLine()) != null) {
|
while ((response = reader.readLine()) != null) {
|
||||||
result += response;
|
result += response;
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
if (out != null) {
|
|
||||||
out.close();
|
out.close();
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,9 +202,7 @@ public class Statistics {
|
|||||||
* @return 是否运行成功.
|
* @return 是否运行成功.
|
||||||
*/
|
*/
|
||||||
public boolean start() {
|
public boolean start() {
|
||||||
if (task != null || !plugin.isEnabled()) {
|
if (task != null || !plugin.isEnabled()) { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
timer = new StatisticsTimer();
|
timer = new StatisticsTimer();
|
||||||
// 开启TPS统计线程
|
// 开启TPS统计线程
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, timer, 0, 20);
|
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, timer, 0, 20);
|
||||||
@ -285,7 +277,7 @@ public class Statistics {
|
|||||||
public double getAverageTPS() {
|
public double getAverageTPS() {
|
||||||
double avg = 0.0D;
|
double avg = 0.0D;
|
||||||
for (Double f : history) {
|
for (Double f : history) {
|
||||||
avg += f.doubleValue();
|
avg += f;
|
||||||
}
|
}
|
||||||
return avg / history.size();
|
return avg / history.size();
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,6 @@ public class SubscribeTask implements Runnable {
|
|||||||
File file = null;
|
File file = null;
|
||||||
ClassLoader cl = plugin.getClass().getClassLoader();
|
ClassLoader cl = plugin.getClass().getClassLoader();
|
||||||
if ((cl instanceof URLClassLoader)) {
|
if ((cl instanceof URLClassLoader)) {
|
||||||
@SuppressWarnings("resource")
|
|
||||||
URLClassLoader ucl = (URLClassLoader) cl;
|
URLClassLoader ucl = (URLClassLoader) cl;
|
||||||
URL url = ucl.getURLs()[0];
|
URL url = ucl.getURLs()[0];
|
||||||
try {
|
try {
|
||||||
@ -203,8 +202,7 @@ public class SubscribeTask implements Runnable {
|
|||||||
int idx = 0;
|
int idx = 0;
|
||||||
int minLength = Math.min(va1.length, va2.length);// 取最小长度值
|
int minLength = Math.min(va1.length, va2.length);// 取最小长度值
|
||||||
int diff = 0;
|
int diff = 0;
|
||||||
while (idx < minLength
|
while (idx < minLength && (diff = va1[idx].length() - va2[idx].length()) == 0// 先比较长度
|
||||||
&& (diff = va1[idx].length() - va2[idx].length()) == 0// 先比较长度
|
|
||||||
&& (diff = va1[idx].compareTo(va2[idx])) == 0) {// 再比较字符
|
&& (diff = va1[idx].compareTo(va2[idx])) == 0) {// 再比较字符
|
||||||
++idx;
|
++idx;
|
||||||
}
|
}
|
||||||
@ -227,15 +225,13 @@ public class SubscribeTask implements Runnable {
|
|||||||
if (target.exists()) {
|
if (target.exists()) {
|
||||||
try {
|
try {
|
||||||
PluginDescriptionFile desc = instance.getPluginLoader().getPluginDescription(target);
|
PluginDescriptionFile desc = instance.getPluginLoader().getPluginDescription(target);
|
||||||
if (!needUpdate(result, desc.getVersion().split("-")[0])) {
|
if (!needUpdate(result, desc.getVersion().split("-")[0])) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
target.delete();
|
target.delete();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
debug(e);
|
debug(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String durl = null;
|
String durl;
|
||||||
if (isMaven) {
|
if (isMaven) {
|
||||||
durl = String.format(maven, instance.getClass().getPackage().getName().replaceAll("\\.", "/"), result, instance.getName());
|
durl = String.format(maven, instance.getClass().getPackage().getName().replaceAll("\\.", "/"), result, instance.getName());
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user