mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-12-21 06:51:19 +08:00
Fix VersionData getFilteredDependencies and isRecommended
This commit is contained in:
parent
710030a5e6
commit
1538fd9738
@ -3,10 +3,13 @@ package io.papermc.hangar.model;
|
||||
import io.papermc.hangar.db.model.ProjectVersionTagsTable;
|
||||
import io.papermc.hangar.model.generated.Dependency;
|
||||
import io.papermc.hangar.service.VersionService;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -16,6 +19,14 @@ public enum Platform {
|
||||
WATERFALL("Waterfall", PlatformCategory.PROXY_CATEGORY, 1, "waterfall", TagColor.WATERFALL, "https://papermc.io/downloads#Waterfall"),
|
||||
VELOCITY("Velocity", PlatformCategory.PROXY_CATEGORY, 1, "velocity", TagColor.VELOCITY, "https://www.velocitypowered.com/downloads");
|
||||
|
||||
private static final Map<String, Platform> PLATFORMS_BY_DEPENDENDY = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (Platform platform : values()) {
|
||||
PLATFORMS_BY_DEPENDENDY.put(platform.dependencyId, platform);
|
||||
}
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final PlatformCategory platformCategory;
|
||||
private final int priority;
|
||||
@ -102,6 +113,11 @@ public enum Platform {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Platform getByDependencyId(String dependencyId) {
|
||||
return PLATFORMS_BY_DEPENDENDY.get(dependencyId.toLowerCase());
|
||||
}
|
||||
|
||||
public static List<ProjectVersionTagsTable> createPlatformTags(VersionService versionService, long versionId, List<Dependency> dependencies) {
|
||||
return versionService.insertTags(getGhostTags(versionId, dependencies));
|
||||
}
|
||||
|
@ -6,12 +6,10 @@ import io.papermc.hangar.db.model.ProjectsTable;
|
||||
import io.papermc.hangar.model.Platform;
|
||||
import io.papermc.hangar.model.generated.Dependency;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class VersionData {
|
||||
|
||||
@ -50,11 +48,18 @@ public class VersionData {
|
||||
}
|
||||
|
||||
public Map<Dependency, ProjectsTable> getFilteredDependencies() {
|
||||
List<String> platformIds = Arrays.stream(Platform.getValues()).map(Platform::getDependencyId).collect(Collectors.toList());
|
||||
return dependencies.entrySet().stream().filter(entry -> !platformIds.contains(entry.getKey().getPluginId())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
|
||||
// Value is nullable, so we can't use Collectors#toMap
|
||||
Map<Dependency, ProjectsTable> map = new HashMap<>();
|
||||
for (Entry<Dependency, ProjectsTable> entry : dependencies.entrySet()) {
|
||||
if (Platform.getByDependencyId(entry.getKey().getPluginId()) == null) { // Exclude the platform dependency
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public boolean isRecommended() {
|
||||
return p.getProject().getRecommendedVersionId() == v.getId();
|
||||
final Long recommendedVersionId = p.getProject().getRecommendedVersionId();
|
||||
return recommendedVersionId != null && recommendedVersionId == v.getId();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user