Skip to content
Open
Show file tree
Hide file tree
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 @@ -754,7 +754,7 @@ public LaunchOptions.Builder getLaunchOptions(String version, JavaRuntime javaVe
try {
String jsonText = Files.readString(json);
ModpackConfiguration<?> modpackConfiguration = JsonUtils.GSON.fromJson(jsonText, ModpackConfiguration.class);
ModpackProvider provider = ModpackHelper.getProviderByType(modpackConfiguration.getType());
ModpackProvider provider = ModpackHelper.getProviderByType(modpackConfiguration.type());
if (provider != null) provider.injectLaunchOptions(jsonText, builder);
} catch (IOException | JsonParseException e) {
LOG.warning("Failed to parse modpack configuration file " + json, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public HMCLModpackInstallTask(HMCLGameRepository repository, Path zipFile, Modpa
if (Files.exists(json)) {
config = JsonUtils.fromJsonFile(json, ModpackConfiguration.typeOf(Modpack.class));

if (!HMCLModpackProvider.INSTANCE.getName().equals(config.getType()))
if (!HMCLModpackProvider.INSTANCE.getName().equals(config.type()))
throw new IllegalArgumentException("Version " + name + " is not a HMCL modpack. Cannot update this version.");
}
} catch (JsonParseException | IOException ignore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private void launch0() {
Task.composeAsync(() -> {
try {
ModpackConfiguration<?> configuration = ModpackHelper.readModpackConfiguration(repository.getModpackConfiguration(selectedVersion));
ModpackProvider provider = ModpackHelper.getProviderByType(configuration.getType());
ModpackProvider provider = ModpackHelper.getProviderByType(configuration.type());
if (provider == null) return null;
else return provider.createCompletionTask(dependencyManager, selectedVersion);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public SearchResult search(DownloadProvider downloadProvider, String gameVersion

int count = 0;
for (ModTranslations.Mod mod : ModTranslations.getTranslationsByRepositoryType(getType()).searchMod(searchFilter)) {
String englishSearchFilter = String.join(" ", StringUtils.tokenize(StringUtils.isNotBlank(mod.getSubname()) ? mod.getSubname() : mod.getName()));
String englishSearchFilter = String.join(" ", StringUtils.tokenize(StringUtils.isNotBlank(mod.subname()) ? mod.subname() : mod.name()));
if (StringUtils.isNotBlank(englishSearchFilter)) {
englishSearchFiltersSet.add(englishSearchFilter);
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public SearchResult search(DownloadProvider downloadProvider, String gameVersion
}

ModTranslations.Mod chineseTranslation = ModTranslations.getTranslationsByRepositoryType(getType()).getModByCurseForgeId(remoteAddon.slug());
if (chineseTranslation != null && !StringUtils.isBlank(chineseTranslation.getName()) && StringUtils.containsChinese(chineseTranslation.getName())) {
if (chineseTranslation != null && !StringUtils.isBlank(chineseTranslation.name()) && StringUtils.containsChinese(chineseTranslation.name())) {
searchResultArray[chineseIndex++] = remoteAddon;
} else {
searchResultArray[englishIndex--] = remoteAddon;
Expand All @@ -95,10 +95,10 @@ public SearchResult search(DownloadProvider downloadProvider, String gameVersion
StringUtils.LevCalculator levCalculator = new StringUtils.LevCalculator();
return new SearchResult(Stream.concat(Arrays.stream(searchResultArray, 0, chineseIndex).map(remoteMod -> {
ModTranslations.Mod chineseRemoteMod = ModTranslations.getTranslationsByRepositoryType(getType()).getModByCurseForgeId(remoteMod.slug());
if (chineseRemoteMod == null || StringUtils.isBlank(chineseRemoteMod.getName()) || !StringUtils.containsChinese(chineseRemoteMod.getName())) {
if (chineseRemoteMod == null || StringUtils.isBlank(chineseRemoteMod.name()) || !StringUtils.containsChinese(chineseRemoteMod.name())) {
return Pair.pair(remoteMod, Integer.MAX_VALUE);
}
String chineseRemoteModName = chineseRemoteMod.getName();
String chineseRemoteModName = chineseRemoteMod.name();
if (searchFilter.isEmpty() || chineseRemoteModName.isEmpty()) {
return Pair.pair(remoteMod, Math.max(searchFilter.length(), chineseRemoteModName.length()));
}
Expand Down
8 changes: 4 additions & 4 deletions HMCL/src/main/java/org/jackhuang/hmcl/game/ModpackHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ else if (modpack.getManifest() instanceof McbbsModpackManifest)
}

public static Task<Void> getUpdateTask(HMCLGameRepository repository, ServerModpackManifest manifest, Charset charset, String name, ModpackConfiguration<?> configuration) throws UnsupportedModpackException {
switch (configuration.getType()) {
switch (configuration.type()) {
case ServerModpackRemoteInstallTask.MODPACK_TYPE:
return new ModpackUpdateTask(repository, name, new ServerModpackRemoteInstallTask(repository.getDependency(), manifest, name))
.thenComposeAsync(repository.refreshVersionsAsync())
Expand All @@ -248,7 +248,7 @@ public static Task<Void> getUpdateTask(HMCLGameRepository repository, ServerModp

public static Task<?> getUpdateTask(HMCLGameRepository repository, Path zipFile, Charset charset, String name, ModpackConfiguration<?> configuration) throws UnsupportedModpackException, ManuallyCreatedModpackException, MismatchedModpackTypeException {
Modpack modpack = ModpackHelper.readModpackManifest(zipFile, charset);
ModpackProvider provider = getProviderByType(configuration.getType());
ModpackProvider provider = getProviderByType(configuration.type());
if (provider == null) {
throw new UnsupportedModpackException();
}
Expand Down Expand Up @@ -350,7 +350,7 @@ private static Task<Void> createMultiMCPostInstallTask(HMCLGameRepository reposi
private static Task<Void> createMcbbsPostInstallTask(HMCLGameRepository repository, McbbsModpackManifest manifest, String version) {
return Task.runAsync(Schedulers.javafx(), () -> {
GameSettings.Effective effective = repository.getEffectiveGameSettings(version);
if (manifest.getLaunchInfo().getMinMemory() > effective.getMaxMemory()) {
if (manifest.launchInfo().minMemory() > effective.getMaxMemory()) {
GameSettings.Instance setting = Objects.requireNonNull(repository.getInstanceGameSettingsOrCreate(version));
setting.getOverrideProperties().addAll(List.of(
GameSettings.PROPERTY_AUTO_MEMORY,
Expand All @@ -360,7 +360,7 @@ private static Task<Void> createMcbbsPostInstallTask(HMCLGameRepository reposito
));
setting.autoMemoryProperty().setValue(effective.get(GameSettings::autoMemoryProperty));
setting.minMemoryProperty().setValue(effective.get(GameSettings::minMemoryProperty));
setting.maxMemoryProperty().setValue(manifest.getLaunchInfo().getMinMemory());
setting.maxMemoryProperty().setValue(manifest.launchInfo().minMemory());
setting.permSizeProperty().setValue(effective.get(GameSettings::permSizeProperty));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public RemoteModpackPage(WizardController controller) {
return;
}

nameProperty.set(manifest.getName());
versionProperty.set(manifest.getVersion());
authorProperty.set(manifest.getAuthor());
nameProperty.set(manifest.name());
versionProperty.set(manifest.version());
authorProperty.set(manifest.author());

HMCLGameRepository repository = controller.getSettings().get(ModpackPage.REPOSITORY);
String name = controller.getSettings().get(MODPACK_NAME);
Expand All @@ -63,14 +63,14 @@ public RemoteModpackPage(WizardController controller) {
txtModpackName.setDisable(true);
} else {
// trim: https://github.com/HMCL-dev/HMCL/issues/962
txtModpackName.setText(manifest.getName().trim());
txtModpackName.setText(manifest.name().trim());
txtModpackName.getValidators().addAll(
new RequiredValidator(),
new Validator(i18n("install.new_game.already_exists"), str -> !repository.versionIdConflicts(str)),
new Validator(i18n("install.new_game.malformed"), HMCLGameRepository::isValidVersionId));
}

btnDescription.setVisible(StringUtils.isNotBlank(manifest.getDescription()));
btnDescription.setVisible(StringUtils.isNotBlank(manifest.description()));
}

@Override
Expand All @@ -85,7 +85,7 @@ protected void onInstall() {
}

protected void onDescribe() {
Controllers.navigate(new WebPage(i18n("modpack.description"), manifest.getDescription()));
Controllers.navigate(new WebPage(i18n("modpack.description"), manifest.description()));
}

public static final SettingsMap.Key<ServerModpackManifest> MODPACK_SERVER_MANIFEST = new SettingsMap.Key<>("MODPACK_SERVER_MANIFEST");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ record Result(@Nullable String gameVersion, @Nullable String tag) {
String modPackVersion = null;
try {
ModpackConfiguration<?> config = repository.readModpackConfiguration(id);
modPackVersion = config != null ? config.getVersion() : null;
modPackVersion = config != null ? config.version() : null;
} catch (IOException e) {
LOG.warning("Failed to read modpack configuration from " + id, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ final class ModInfoDialog extends JFXDialogLayout {
getActions().add(officialPageButton);
}

if (modInfo.getModTranslations() == null || StringUtils.isBlank(modInfo.getModTranslations().getMcmod())) {
if (modInfo.getModTranslations() == null || StringUtils.isBlank(modInfo.getModTranslations().mcmod())) {
JFXHyperlink searchButton = new JFXHyperlink(i18n("mods.mcmod.search"));
searchButton.setOnAction(e -> {
fireEvent(new DialogCloseEvent());
Expand Down Expand Up @@ -576,7 +576,7 @@ protected void updateControl(ModInfoObject dataItem, boolean empty) {

String displayName = modInfo.getName();
if (modTranslations != null && I18n.isUseChinese()) {
String chineseName = modTranslations.getName();
String chineseName = modTranslations.name();
if (StringUtils.containsChinese(chineseName)) {
if (StringUtils.containsEmoji(chineseName)) {
StringBuilder builder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.jackhuang.hmcl.util.logging.Logger.LOG;
import static org.jackhuang.hmcl.util.Pair.pair;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;

/**
* Parser for mod_data.txt
Expand All @@ -40,13 +43,13 @@ public enum ModTranslations {
MOD("/assets/mod_data.txt") {
@Override
public String getMcmodUrl(Mod mod) {
return String.format("https://www.mcmod.cn/class/%s.html", mod.getMcmod());
return String.format("https://www.mcmod.cn/class/%s.html", mod.mcmod());
}
},
MODPACK("/assets/modpack_data.txt") {
@Override
public String getMcmodUrl(Mod mod) {
return String.format("https://www.mcmod.cn/modpack/%s.html", mod.getMcmod());
return String.format("https://www.mcmod.cn/modpack/%s.html", mod.mcmod());
}
},
EMPTY("") {
Expand Down Expand Up @@ -118,7 +121,7 @@ private static String cleanSubname(String subname) {
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(
ModTranslations.class.getResourceAsStream(resourceName), StandardCharsets.UTF_8))) {
return this.mods = reader.lines().filter(line -> !line.startsWith("#")).map(Mod::new).toList();
return this.mods = reader.lines().filter(line -> !line.startsWith("#")).map(Mod::fromLine).toList();
} catch (Exception e) {
LOG.warning("Failed to load " + resourceName, e);
return this.mods = List.of();
Expand All @@ -138,7 +141,7 @@ private static String cleanSubname(String subname) {
List<Mod> mods = getMods();
modIdMap = new HashMap<>(mods.size());
for (Mod mod : mods) {
for (String id : mod.getModIds()) {
for (String id : mod.modIds()) {
if (StringUtils.isNotBlank(id)) {
modIdMap.putIfAbsent(id, mod);
}
Expand All @@ -162,7 +165,7 @@ private static String cleanSubname(String subname) {

List<Mod> mods = getMods();
for (Mod mod : mods) {
String subname = cleanSubname(mod.getSubname());
String subname = cleanSubname(mod.subname());
if (StringUtils.isNotBlank(subname)) {
subnameMap.putIfAbsent(subname, mod);
}
Expand All @@ -185,8 +188,8 @@ private static String cleanSubname(String subname) {
List<Mod> mods = getMods();
curseForgeMap = new HashMap<>(mods.size());
for (Mod mod : mods) {
if (StringUtils.isNotBlank(mod.getCurseforge())) {
curseForgeMap.putIfAbsent(mod.getCurseforge(), mod);
if (StringUtils.isNotBlank(mod.curseforge())) {
curseForgeMap.putIfAbsent(mod.curseforge(), mod);
}
}

Expand All @@ -209,17 +212,17 @@ private static String cleanSubname(String subname) {
keywords = new ArrayList<>();
int maxKeywordLength = -1;
for (Mod mod : mods) {
if (StringUtils.isNotBlank(mod.getName())) {
keywords.add(pair(mod.getName(), mod));
maxKeywordLength = Math.max(maxKeywordLength, mod.getName().length());
if (StringUtils.isNotBlank(mod.name())) {
keywords.add(pair(mod.name(), mod));
maxKeywordLength = Math.max(maxKeywordLength, mod.name().length());
}
if (StringUtils.isNotBlank(mod.getSubname())) {
keywords.add(pair(mod.getSubname(), mod));
maxKeywordLength = Math.max(maxKeywordLength, mod.getSubname().length());
if (StringUtils.isNotBlank(mod.subname())) {
keywords.add(pair(mod.subname(), mod));
maxKeywordLength = Math.max(maxKeywordLength, mod.subname().length());
}
if (StringUtils.isNotBlank(mod.getAbbr())) {
keywords.add(pair(mod.getAbbr(), mod));
maxKeywordLength = Math.max(maxKeywordLength, mod.getAbbr().length());
if (StringUtils.isNotBlank(mod.abbr())) {
keywords.add(pair(mod.abbr(), mod));
maxKeywordLength = Math.max(maxKeywordLength, mod.abbr().length());
}
}

Expand Down Expand Up @@ -250,7 +253,7 @@ public Mod getMod(String id, String subname) {
subname = cleanSubname(subname);
if (StringUtils.isNotBlank(subname)) {
Mod mod = getSubnameMap().get(subname);
if (mod != null && (StringUtils.isBlank(id) || mod.getModIds().contains(id)))
if (mod != null && (StringUtils.isBlank(id) || mod.modIds().contains(id)))
return mod;
}

Expand Down Expand Up @@ -282,35 +285,14 @@ public List<Mod> searchMod(String query) {
.toList();
}

public static final class Mod {
private final String curseforge;
private final String mcmod;
private final List<String> modIds;
private final String name;
private final String subname;
private final String abbr;
public record Mod(String curseforge, String mcmod, List<String> modIds, String name, String subname, String abbr) {

public Mod(String line) {
public static Mod fromLine(String line) {
String[] items = line.split(";", -1);
if (items.length != 6) {
throw new IllegalArgumentException("Illegal mod data line, 6 items expected " + line);
}

curseforge = items[0];
mcmod = items[1];
modIds = List.of(items[2].split(","));
name = items[3];
subname = items[4];
abbr = items[5];
}

public Mod(String curseforge, String mcmod, List<String> modIds, String name, String subname, String abbr) {
this.curseforge = curseforge;
this.mcmod = mcmod;
this.modIds = modIds;
this.name = name;
this.subname = subname;
this.abbr = abbr;
return new Mod(items[0], items[1], List.of(items[2].split(",")), items[3], items[4], items[5]);
}

public String getDisplayName() {
Expand All @@ -324,29 +306,5 @@ public String getDisplayName() {
}
return builder.toString();
}

public String getCurseforge() {
return curseforge;
}

public String getMcmod() {
return mcmod;
}

public List<String> getModIds() {
return modIds;
}

public String getName() {
return name;
}

public String getSubname() {
return subname;
}

public String getAbbr() {
return abbr;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ private void search() {
LocalAddonFile.Description description = resourcePack.getDescription();
Stream<String> descriptionParts = description == null
? Stream.empty()
: description.getParts().stream().map(LocalAddonFile.Description.Part::getText);
: description.parts().stream().map(LocalAddonFile.Description.Part::text);
if (predicate.test(resourcePack.getFileNameWithExtension())
|| predicate.test(resourcePack.getFileName())
|| descriptionParts.anyMatch(predicate)) {
Expand Down
Loading