Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private static LocalModFile fromEmbeddedMod(ModManager modManager, Path modFile,
throw new IOException();
}

private static ModLoaderType analyzeLoader(Toml toml, String modID, ModLoaderType loader) throws IOException {
private static ModLoaderType analyzeLoader(Toml toml, String modID, ModLoaderType loader) {
List<HashMap<String, Object>> dependencies = null;
try {
dependencies = toml.getList("dependencies." + modID);
Expand Down Expand Up @@ -332,11 +332,11 @@ private static ModLoaderType analyzeLoader(Toml toml, String modID, ModLoaderTyp
}
}

if (result == loader)
if (result != null) {
if (result != loader)
LOG.warning("Loader mismatch for mod " + modID + ", found " + result + ", expecting " + loader);
return result;
else if (result != null)
throw new IOException("Loader mismatch");
else {
} else {
LOG.warning("Cannot determine the mod loader for mod " + modID + ", expected " + loader);
return loader;
}
Comment on lines +335 to 342
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了使代码结构更扁平化、可读性更强,可以考虑重构此处的 if-else 逻辑。通过先处理 resultnull 的情况(即使用 "guard clause"),可以减少代码的嵌套层级。

此外,建议使用参数化日志来代替字符串拼接,以提高性能和可读性。

        if (result == null) {
            LOG.warning("Cannot determine the mod loader for mod {}, expected {}", modID, loader);
            return loader;
        }

        if (result != loader) {
            LOG.warning("Loader mismatch for mod {}, found {}, expecting {}", modID, result, loader);
        }
        return result;

Expand Down