diff --git a/code_version.txt b/code_version.txt new file mode 100644 index 0000000..027934e --- /dev/null +++ b/code_version.txt @@ -0,0 +1 @@ +0.11.1 \ No newline at end of file diff --git a/fabric/origin/fabric.gradle b/fabric/origin/fabric.gradle index 2439834..314dfcd 100644 --- a/fabric/origin/fabric.gradle +++ b/fabric/origin/fabric.gradle @@ -11,14 +11,7 @@ repositories { url "https://maven.kituin.fun/releases" } } -def getVersionFromFile() { - def versionFile = file('../../version.txt') - if (versionFile.exists()) { - return versionFile.text.trim() - } else { - throw new Exception("Version file not found: ${versionFile.absolutePath}") as Throwable - } -} + ext.includeMod = { String localOverrideKey, Object dep -> File file = file("../.${localOverrideKey}-local"); if (file.exists()) { @@ -28,7 +21,17 @@ ext.includeMod = { String localOverrideKey, Object dep -> } dependencies.include(dep) } -def mod_version = getVersionFromFile() +def getVersionFromFile(String f) { + def versionFile = file(f) + if (versionFile.exists()) { + return versionFile.text.trim() + } else { + throw new Exception("Version file not found: ${versionFile.absolutePath}") as Throwable + } +} + +def code_version = getVersionFromFile('../../code_version.txt') +def mod_version = getVersionFromFile('../../version.txt') version = mod_version + "+" + project.minecraft_version + "+fabric" group = project.maven_group @@ -48,7 +51,7 @@ dependencies { includeMod "fabric-api", fabricApi.module(project.command_api, project.fabric_version) includeMod "fabric-api", fabricApi.module("fabric-lifecycle-events-v1", project.fabric_version) - include modImplementation("io.github.kituin:ChatImageCode:${project.code_version}") + include modImplementation("io.github.kituin:ChatImageCode:${code_version}") include modImplementation("io.github.kituin:ActionLib:${project.action_version}-fabric") modApi("com.terraformersmc:modmenu:${project.modmenu_version}") { transitive false } } diff --git a/forge/origin/build.gradle b/forge/origin/build.gradle index 4f30e45..9586997 100644 --- a/forge/origin/build.gradle +++ b/forge/origin/build.gradle @@ -17,8 +17,8 @@ plugins { apply plugin: 'org.spongepowered.mixin' apply plugin: 'org.parchmentmc.librarian.forgegradle' -def getVersionFromFile() { - def versionFile = file('../../version.txt') +def getVersionFromFile(String f) { + def versionFile = file(f) if (versionFile.exists()) { return versionFile.text.trim() } else { @@ -26,7 +26,8 @@ def getVersionFromFile() { } } -def mod_version = getVersionFromFile() +def code_version = getVersionFromFile('../../code_version.txt') +def mod_version = getVersionFromFile('../../version.txt') version = mod_version + "+" + project.minecraft_version + "+forge" def targetJavaVersion = project.targetJavaVersion.toInteger() @@ -166,8 +167,8 @@ dependencies { // implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency - implementation "io.github.kituin:ChatImageCode:${project.code_version}" - jarJar(group: 'io.github.kituin', name: 'ChatImageCode', version: "${project.code_version}"){ + implementation "io.github.kituin:ChatImageCode:${code_version}" + jarJar(group: 'io.github.kituin', name: 'ChatImageCode', version: "${code_version}"){ jarJar.ranged(it, '[0.9.2,1.0)') } jarJar(group: 'io.github.kituin', name: 'ActionLib', version: "${project.action_version}-forge"){ diff --git a/forge/origin/src/main/java/io/github/kituin/chatimage/network/ChatImagePacket.java b/forge/origin/src/main/java/io/github/kituin/chatimage/network/ChatImagePacket.java index 5bb0105..03edfa4 100644 --- a/forge/origin/src/main/java/io/github/kituin/chatimage/network/ChatImagePacket.java +++ b/forge/origin/src/main/java/io/github/kituin/chatimage/network/ChatImagePacket.java @@ -58,20 +58,14 @@ public static void loadFromServer(String url) { */ public static void serverFileChannelReceived(#ServerPlayer# player, String res) { ChatImageIndex title = gson.fromJson(res, ChatImageIndex.class); - HashMap blocks = SERVER_BLOCK_CACHE.containsKey(title.url) ? SERVER_BLOCK_CACHE.get(title.url) : new HashMap<>(); - blocks.put(title.index, res); - SERVER_BLOCK_CACHE.put(title.url, blocks); - FILE_COUNT_MAP.put(title.url, title.total); + HashMap blocks = SERVER_BLOCK_CACHE.createBlock(title, res); LOGGER.info("[FileChannel->Server:" + title.index + "/" + title.total + "]" + title.url); if (title.total == blocks.size()) { - if (USER_CACHE_MAP.containsKey(title.url)) { - // 通知之前请求但是没图片的客户端 - List names = USER_CACHE_MAP.get(title.url); - for (String uuid : names) { - FileBackChannel.sendToPlayer(new FileInfoChannelPacket("true->" + title.url), player.server.getPlayerList().getPlayer(UUID.fromString(uuid))); - LOGGER.info("[echo to client(" + uuid + ")]" + title.url); - } - USER_CACHE_MAP.put(title.url, Lists.newArrayList()); + List names = SERVER_BLOCK_CACHE.getUsers(title.url); + // 通知之前请求但是没图片的客户端 + for (String uuid : names) { + FileBackChannel.sendToPlayer(new FileInfoChannelPacket("true->" + title.url), player.server.getPlayerList().getPlayer(UUID.fromString(uuid))); + LOGGER.info("[echo to client(" + uuid + ")]" + title.url); } LOGGER.info("[FileChannel->Server]" + title.url); } @@ -108,28 +102,23 @@ public static void clientFileInfoChannelReceived(String data){ } public static void serverFileInfoChannelReceived(#ServerPlayer# player, String url) { - if (SERVER_BLOCK_CACHE.containsKey(url) && FILE_COUNT_MAP.containsKey(url)) { - HashMap list = SERVER_BLOCK_CACHE.get(url); - Integer total = FILE_COUNT_MAP.get(url); - if (total == list.size()) { - // 服务器存在缓存图片,直接发送给客户端 - for (Map.Entry entry : list.entrySet()) { - LOGGER.debug("[GetFileChannel->Client:{}/{}]{}", entry.getKey(), list.size() - 1, url); - DownloadFileChannel.sendToPlayer(new DownloadFileChannelPacket(entry.getValue()), player); - } - LOGGER.info("[GetFileChannel->Client]{}", url); - return; + HashMap list = SERVER_BLOCK_CACHE.getBlock(url); + if (list != null) { + // 服务器存在缓存图片,直接发送给客户端 + for (Map.Entry entry : list.entrySet()) { + LOGGER.debug("[GetFileChannel->Client:{}/{}]{}", entry.getKey(), list.size() - 1, url); + DownloadFileChannel.sendToPlayer(new DownloadFileChannelPacket(entry.getValue()), player); } + LOGGER.info("[GetFileChannel->Client]{}", url); + return; } //通知客户端无文件 FileBackChannel.sendToPlayer(new FileInfoChannelPacket("null->" + url), player); LOGGER.error("[GetFileChannel]not found in server:{}", url); // 记录uuid,后续有文件了推送 - List names = USER_CACHE_MAP.containsKey(url) ? USER_CACHE_MAP.get(url) : Lists.newArrayList(); if (player != null) { - names.add(player.getStringUUID()); + SERVER_BLOCK_CACHE.tryAddUser(url, player.getStringUUID()); } - USER_CACHE_MAP.put(url, names); LOGGER.info("[GetFileChannel]记录uuid:{}", player.getStringUUID()); LOGGER.info("[not found in server]{}", url); } diff --git a/neoforge/origin/build.gradle b/neoforge/origin/build.gradle index 5e8214f..d1cdda0 100644 --- a/neoforge/origin/build.gradle +++ b/neoforge/origin/build.gradle @@ -6,8 +6,8 @@ plugins { id 'net.neoforged.gradle.userdev' version '7.0.164' } -def getVersionFromFile() { - def versionFile = file('../../version.txt') +def getVersionFromFile(String f) { + def versionFile = file(f) if (versionFile.exists()) { return versionFile.text.trim() } else { @@ -15,21 +15,22 @@ def getVersionFromFile() { } } -def mod_version = getVersionFromFile() -version = mod_version + "+" + project.minecraft_version + "+neoforge" +def code_version = getVersionFromFile('../../code_version.txt') +def mod_version = getVersionFromFile('../../version.txt') +version = mod_version + "+" + project.minecraft_version + "+neoforge" group = mod_group_id repositories { mavenLocal() mavenCentral() - flatDir{ + flatDir { dirs 'libs' } maven { url "https://mvn.cloud.alipay.com/nexus/content/repositories/open/" } - maven{ + maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } @@ -50,7 +51,7 @@ base { java.toolchain.languageVersion = JavaLanguageVersion.of(project.targetJavaVersion) jarJar.enable() -tasks.named ('jarJar') { +tasks.named('jarJar') { archiveClassifier.set('') destinationDirectory = file("../../ChatImage-jar/${mod_version}") } @@ -137,12 +138,12 @@ dependencies { // Example mod dependency using a file as dependency // implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar") - implementation "io.github.kituin:ChatImageCode:${project.code_version}" - jarJar(group: 'io.github.kituin', name: 'ChatImageCode', version: "${project.code_version}"){ + implementation "io.github.kituin:ChatImageCode:${code_version}" + jarJar(group: 'io.github.kituin', name: 'ChatImageCode', version: "${code_version}") { jarJar.ranged(it, '[0.9.2,1.0)') } implementation "io.github.kituin:ActionLib:${project.action_version}" - jarJar(group: 'io.github.kituin', name: 'ActionLib', version: "${project.action_version}"){ + jarJar(group: 'io.github.kituin', name: 'ActionLib', version: "${project.action_version}") { jarJar.ranged(it, '[1.9.1,2.0)') } // Example project dependency using a sister or child project: @@ -177,8 +178,8 @@ tasks.withType(ProcessResources).configureEach { // ELSE // filesMatching(['META-INF/neoforge.mods.toml']) { // END IF - expand replaceProperties - } + expand replaceProperties +} } // Example configuration to allow publishing using the maven-publish plugin