[FIX] Duplicate profileUUID error

This commit is contained in:
Gravita 2021-05-04 18:08:13 +07:00
parent e5f714e0f5
commit ae82964a24
3 changed files with 22 additions and 8 deletions

View file

@ -122,7 +122,7 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab
public LaunchServerConfig config; public LaunchServerConfig config;
public volatile Map<String, HashedDir> updatesDirMap; public volatile Map<String, HashedDir> updatesDirMap;
// Updates and profiles // Updates and profiles
private volatile List<ClientProfile> profilesList; private volatile Set<ClientProfile> profilesList;
public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, LaunchServerConfig config, LaunchServerRuntimeConfig runtimeConfig, LaunchServerConfigManager launchServerConfigManager, LaunchServerModulesManager modulesManager, KeyAgreementManager keyAgreementManager, CommandHandler commandHandler, CertificateManager certificateManager) throws IOException { public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, LaunchServerConfig config, LaunchServerRuntimeConfig runtimeConfig, LaunchServerConfigManager launchServerConfigManager, LaunchServerModulesManager modulesManager, KeyAgreementManager keyAgreementManager, CommandHandler commandHandler, CertificateManager certificateManager) throws IOException {
this.dir = directories.dir; this.dir = directories.dir;
@ -297,12 +297,12 @@ public void close() throws Exception {
logger.info("LaunchServer stopped"); logger.info("LaunchServer stopped");
} }
public List<ClientProfile> getProfiles() { public Set<ClientProfile> getProfiles() {
return profilesList; return profilesList;
} }
public void setProfiles(List<ClientProfile> profilesList) { public void setProfiles(Set<ClientProfile> profilesList) {
this.profilesList = Collections.unmodifiableList(profilesList); this.profilesList = Collections.unmodifiableSet(profilesList);
} }
public HashedDir getUpdateDir(String name) { public HashedDir getUpdateDir(String name) {
@ -385,7 +385,7 @@ public void syncProfilesDir() throws IOException {
// Sort and set new profiles // Sort and set new profiles
newProfies.sort(Comparator.comparing(a -> a)); newProfies.sort(Comparator.comparing(a -> a));
profilesList = Collections.unmodifiableList(newProfies); profilesList = Set.copyOf(newProfies);
if (pingServerManager != null) if (pingServerManager != null)
pingServerManager.syncServers(); pingServerManager.syncServers();
} }

View file

@ -9,6 +9,7 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
public class ProfilesResponse extends SimpleResponse { public class ProfilesResponse extends SimpleResponse {
@Override @Override
@ -24,7 +25,7 @@ public void execute(ChannelHandlerContext ctx, Client client) {
} }
List<ClientProfile> profileList; List<ClientProfile> profileList;
List<ClientProfile> serverProfiles = server.getProfiles(); Set<ClientProfile> serverProfiles = server.getProfiles();
if (server.config.protectHandler instanceof ProfilesProtectHandler) { if (server.config.protectHandler instanceof ProfilesProtectHandler) {
ProfilesProtectHandler protectHandler = (ProfilesProtectHandler) server.config.protectHandler; ProfilesProtectHandler protectHandler = (ProfilesProtectHandler) server.config.protectHandler;
profileList = new ArrayList<>(4); profileList = new ArrayList<>(4);
@ -34,7 +35,7 @@ public void execute(ChannelHandlerContext ctx, Client client) {
} }
} }
} else { } else {
profileList = serverProfiles; profileList = List.copyOf(serverProfiles);
} }
sendResult(new ProfilesRequestEvent(profileList)); sendResult(new ProfilesRequestEvent(profileList));
} }

View file

@ -379,7 +379,7 @@ public boolean isUpdateFastCheck() {
@Override @Override
public String toString() { public String toString() {
return title; return String.format("%s (%s)", title, uuid);
} }
public UUID getUUID() { public UUID getUUID() {
@ -472,6 +472,19 @@ public List<String> getCompatClasses() {
return Collections.unmodifiableList(compatClasses); return Collections.unmodifiableList(compatClasses);
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClientProfile profile = (ClientProfile) o;
return Objects.equals(uuid, profile.uuid);
}
@Override
public int hashCode() {
return Objects.hash(uuid);
}
public enum Version { public enum Version {
MC125("1.2.5", 29), MC125("1.2.5", 29),
MC147("1.4.7", 51), MC147("1.4.7", 51),