1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-22 01:48:50 +00:00

fix: 调整异常捕获

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-09-19 16:19:03 +08:00
parent 5cfd7a1b2a
commit b559c6f756
2 changed files with 36 additions and 38 deletions

View File

@ -52,9 +52,9 @@ public class C {
getHandle = typeCraftPlayer.getMethod("getHandle");
playerConnection = typeNMSPlayer.getField("playerConnection");
sendPacket = typePlayerConnection.getMethod("sendPacket", Class.forName(a("Packet")));
} catch (final Throwable e) {
} catch (final Exception e) {
Log.warning(C.class.getSimpleName() + " 兼容性工具初始化失败 可能造成部分功能不可用!");
e.printStackTrace();
Log.debug(e);
}
}
@ -225,7 +225,7 @@ public class C {
}
}
// getOnlinePlayers end
} catch (NoSuchMethodException | SecurityException e) {
} catch (final Exception e) {
Log.warning(Player.class.getSimpleName() + "兼容性工具初始化失败 可能造成部分功能不可用!");
}
try {
@ -246,6 +246,7 @@ public class C {
craftOfflinePlayerConstructor.setAccessible(true);
// getOfflinePlayer end
} catch (final Exception e) {
Log.debug(e);
}
}
@ -261,7 +262,7 @@ public class C {
final Object gameProfile = gameProfileConstructor.newInstance(new Object[] { UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(Charsets.UTF_8)), playerName });
final Object offlinePlayer = craftOfflinePlayerConstructor.newInstance(new Object[] { Bukkit.getServer(), gameProfile });
return (OfflinePlayer) offlinePlayer;
} catch (final Throwable e) {
} catch (final Exception e) {
return Bukkit.getOfflinePlayer(playerName);
}
}
@ -274,7 +275,7 @@ public class C {
public static Collection<? extends org.bukkit.entity.Player> getOnlinePlayers() {
try {
return Arrays.asList((org.bukkit.entity.Player[]) getOnlinePlayers.invoke(null));
} catch (final Throwable e) {
} catch (final Exception e) {
return Bukkit.getOnlinePlayers();
}
}
@ -399,13 +400,13 @@ public class C {
Object serialized = nmsChatSerializer.getMethod("a", String.class).invoke(null, "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', title) + "\"}");
packet = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent).newInstance(actions[0], serialized);
sendPacket.invoke(connection, packet);
if (subtitle != "") {
if (!"".equals(subtitle)) {
// Send subtitle if present
serialized = nmsChatSerializer.getMethod("a", String.class).invoke(null, "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', subtitle) + "\"}");
packet = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent).newInstance(actions[1], serialized);
sendPacket.invoke(connection, packet);
}
} catch (final Throwable e) {
} catch (final Exception e) {
e.printStackTrace();
}
}

View File

@ -130,40 +130,37 @@ public class Statistics {
* @param param
* 请求参数
* @return 所代表远程资源的响应结果
* @throws IOException
*/
public static String postData(final String url, final String param) {
public static String postData(final String url, final String param) throws IOException {
PrintWriter out = null;
String result = "";
try {
final URL realUrl = new URL(url);
// 打开和URL之间的连接
final URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("Accept", "*/*");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36");
// 设置超时时间 10秒
conn.setReadTimeout(10000);
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.write(param);
// flush输出流的缓冲
out.flush();
String response = "";
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), UTF_8));
while ((response = reader.readLine()) != null) {
result += response;
}
reader.close();
} catch (final Exception e) {
} finally {
if (out != null) {
out.close();
}
final URL realUrl = new URL(url);
// 打开和URL之间的连接
final URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("Accept", "*/*");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36");
// 设置超时时间 10秒
conn.setReadTimeout(10000);
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.write(param);
// flush输出流的缓冲
out.flush();
String response = "";
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), UTF_8));
while ((response = reader.readLine()) != null) {
result += response;
}
reader.close();
if (out != null) {
out.close();
}
return result;
}