Skip to content

Commit

Permalink
fix: 修复更新检测,抛弃Gson
Browse files Browse the repository at this point in the history
  • Loading branch information
0XPYEX0 committed Aug 10, 2024
1 parent 279729a commit 6cbf778
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ repositories {
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT'
compileOnly 'net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT'
compileOnly 'com.google.code.gson:gson:2.8.9'
implementation 'org.ow2.asm:asm:9.7'
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/xpyex/module/cnusername/CnUsername.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public static void premain(final String agentArgs, final Instrumentation inst) {
} catch (Exception e) {
Logging.warning("添加补丁失败");
e.printStackTrace();
Logging.warning("建议服务器启动后手动封禁CS-CoreLib玩家名");
}
UpdateChecker.check();
Logging.info("等待Minecraft加载...");
inst.addTransformer(new ClassFileTransformer() {
@Override
Expand All @@ -85,7 +87,6 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
case ClassVisitorAllowedCharacters.CLASS_PATH:
Logging.setLogger(ProxyServer.getInstance().getLogger()); //BungeeCord Logger
visitor = new ClassVisitorAllowedCharacters(className, writer, agentArgs);
UpdateChecker.check(); //此时Gson必然已加载,顺便检查更新
break;
case ClassVisitorCraftPlayerProfile.CLASS_PATH:
visitor = new ClassVisitorCraftPlayerProfile(className, writer, agentArgs);
Expand All @@ -94,7 +95,6 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
case ClassVisitorLoginListener.CLASS_PATH_SPIGOT:
case ClassVisitorLoginListener.CLASS_PATH_YARN:
visitor = new ClassVisitorLoginListener(className, writer, agentArgs);
UpdateChecker.check(); //此时Gson必然已加载,顺便检查更新
break;
case ClassVisitorStringReader.CLASS_PATH:
visitor = new ClassVisitorStringReader(className, writer);
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/me/xpyex/module/cnusername/UpdateChecker.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.xpyex.module.cnusername;

import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -27,11 +25,14 @@ public static void check() {
URLConnection connection = new URL(api).openConnection();
connection.setConnectTimeout(5000); //5s超时

JsonObject result = new GsonBuilder().disableHtmlEscaping().create().fromJson(new String(readInputStream(connection.getInputStream())), JsonObject.class);
String result = new String(readInputStream(connection.getInputStream())).replace("\n", "");

if (!("v" + version).equalsIgnoreCase(result.get("tag_name").getAsString())) {
Logging.info("发现新版本: " + result.get("tag_name").getAsString());
Logging.info("更新内容: " + result.get("body").getAsString());
String tagNameAfter = result.substring(result.indexOf("\"tag_name\":") + 11);
String tagName = tagNameAfter.substring(0, tagNameAfter.indexOf(",")).trim().replace(",", "").replace("\"", "");
String body = result.substring(result.indexOf("\"body\":") + 7).replace("]", "").replace("\"", "").trim();
if (!("v" + version).equalsIgnoreCase(tagName)) {
Logging.info("发现新版本: " + tagName);
Logging.info("更新内容: " + body);
Logging.info("下载地址(Github): https://github.com/0XPYEX0/CnUsername/releases");
}
} catch (Throwable e) {
Expand Down

0 comments on commit 6cbf778

Please sign in to comment.