From 21a203356f6e6f8d304d61fbe9d393adc7d845bc Mon Sep 17 00:00:00 2001 From: Gravita Date: Fri, 7 May 2021 19:25:04 +0700 Subject: [PATCH] [FEATURE] Manual create ClientProfile --- .../command/hash/DownloadClientCommand.java | 37 ++- .../command/hash/SaveProfilesCommand.java | 98 +++++- .../gravit/launcher/api/SystemService.java | 4 +- .../client/ClientLauncherEntryPoint.java | 8 +- .../client/ClientLauncherProcess.java | 2 +- .../launcher/profiles/ClientProfile.java | 299 +++++++++--------- .../profiles/ClientProfileBuilder.java | 198 ++++++++++++ .../profiles/optional/OptionalTrigger.java | 15 + 8 files changed, 481 insertions(+), 180 deletions(-) create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileBuilder.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java index 760aa109..8efa22c4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java @@ -1,6 +1,8 @@ package pro.gravit.launchserver.command.hash; import com.google.gson.JsonElement; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launchserver.LaunchServer; @@ -19,6 +21,8 @@ public final class DownloadClientCommand extends Command { + private transient final Logger logger = LogManager.getLogger(); + public DownloadClientCommand(LaunchServer server) { super(server); } @@ -42,31 +46,34 @@ public void invoke(String... args) throws IOException, CommandException { Path clientDir = server.updatesDir.resolve(args[1]); // Create client dir - LogHelper.subInfo("Creating client dir: '%s'", dirName); + logger.info("Creating client dir: '{}'", dirName); Files.createDirectory(clientDir); // Download required client - LogHelper.subInfo("Downloading client, it may take some time"); + logger.info("Downloading client, it may take some time"); //HttpDownloader.downloadZip(server.mirrorManager.getDefaultMirror().getClientsURL(version.name), clientDir); server.mirrorManager.downloadZip(clientDir, "clients/%s.zip", versionName); // Create profile file - LogHelper.subInfo("Creaing profile file: '%s'", dirName); + logger.info("Creaing profile file: '{}'", dirName); ClientProfile client; - String profilePath = String.format("pro/gravit/launchserver/defaults/profile%s.cfg", versionName); - try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL(profilePath))) { - client = Launcher.gsonManager.configGson.fromJson(reader, ClientProfile.class); - } catch (IOException e) { + try { + ClientProfile.Version version = ClientProfile.Version.byName(versionName); + if(version.compareTo(ClientProfile.Version.MC164) <= 0) { + logger.warn("Minecraft 1.6.4 and below not supported. Use at your own risk"); + } + client = SaveProfilesCommand.makeProfile(version, dirName, SaveProfilesCommand.getMakeProfileOptionsFromDir(clientDir, version)); + } catch (Throwable e) { JsonElement clientJson = server.mirrorManager.jsonRequest(null, "GET", "clients/%s.json", versionName); client = Launcher.gsonManager.configGson.fromJson(clientJson, ClientProfile.class); - } - client.setTitle(dirName); - client.setDir(dirName); - client.setUUID(UUID.randomUUID()); - if (client.getServers() != null) { - ClientProfile.ServerProfile serverProfile = client.getDefaultServerProfile(); - if (serverProfile != null) { - serverProfile.name = dirName; + client.setTitle(dirName); + client.setDir(dirName); + client.setUUID(UUID.randomUUID()); + if (client.getServers() != null) { + ClientProfile.ServerProfile serverProfile = client.getDefaultServerProfile(); + if (serverProfile != null) { + serverProfile.name = dirName; + } } } try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir, diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java index 745d5f76..a2313d15 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java @@ -1,8 +1,11 @@ package pro.gravit.launchserver.command.hash; import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.profiles.ClientProfileBuilder; import pro.gravit.launcher.profiles.optional.OptionalFile; +import pro.gravit.launcher.profiles.optional.OptionalTrigger; import pro.gravit.launcher.profiles.optional.actions.*; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; @@ -14,16 +17,103 @@ import java.io.Writer; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.UUID; +import java.util.*; public class SaveProfilesCommand extends Command { public SaveProfilesCommand(LaunchServer server) { super(server); } + public enum MakeProfileOption { + LAUNCHWRAPPER, VANILLA, FORGE, FABRIC, LITELOADER + } + + public static ClientProfile makeProfile(ClientProfile.Version version, String title, MakeProfileOption... options) { + ClientProfileBuilder builder = new ClientProfileBuilder(); + builder.setVersion(version.name); + builder.setDir(title); + builder.setAssetDir("asset"+version.name); + builder.setAssetIndex(version.name); + builder.setInfo("Информация о сервере"); + builder.setTitle(title); + builder.setUuid(UUID.randomUUID()); + builder.setMainClass(getMainClassByVersion(version, options)); + builder.setServers(List.of(new ClientProfile.ServerProfile(title, "localhost", 25535))); + // ------------ + builder.setUpdateVerify(List.of("libraries", "natives", "minecraft.jar", "forge.jar", "liteloader.jar", "mods")); + builder.setClassPath(List.of("libraries", "minecraft.jar", "forge.jar", "liteloader.jar")); + builder.setUpdate(List.of("servers.dat")); + List jvmArgs = new ArrayList<>(4); + Set optionals = new HashSet<>(); + jvmArgs.add("-XX:+DisableAttachMechanism"); + // Official Mojang launcher java arguments + jvmArgs.add("-XX:+UseG1GC"); + jvmArgs.add("XX:+UnlockExperimentalVMOptions"); + jvmArgs.add("-XX:G1NewSizePercent=20"); + jvmArgs.add("-XX:MaxGCPauseMillis=50"); + jvmArgs.add("-XX:G1HeapRegionSize=32M"); + // ----------- + if(version.compareTo(ClientProfile.Version.MC1122) > 0) { + jvmArgs.add("-Djava.library.path=natives"); + if(optionContains(options, MakeProfileOption.FORGE)) { + builder.setClassLoaderConfig(ClientProfile.ClassLoaderConfig.AGENT); + } + OptionalFile optionalMacOs = new OptionalFile(); + optionalMacOs.name = "MacOSArgs"; + optionalMacOs.actions = new ArrayList<>(1); + optionalMacOs.actions.add(new OptionalActionJvmArgs(List.of("-XstartOnFirstThread"))); + optionalMacOs.triggers = new OptionalTrigger[]{ new OptionalTrigger(OptionalTrigger.TriggerType.OS_TYPE, 2) }; + optionals.add(optionalMacOs); + } + jvmArgs.add("-Dfml.ignorePatchDiscrepancies=true"); + jvmArgs.add("-Dfml.ignoreInvalidMinecraftCertificates=true"); + builder.setJvmArgs(jvmArgs); + builder.setUpdateOptional(optionals); + List clientArgs = new ArrayList<>(); + if(optionContains(options, MakeProfileOption.LAUNCHWRAPPER)) { + if(optionContains(options, MakeProfileOption.LITELOADER)) { + clientArgs.add("--tweakClass"); + clientArgs.add("com.mumfrey.liteloader.launch.LiteLoaderTweaker"); + } + if(optionContains(options, MakeProfileOption.FORGE)) { + clientArgs.add("--tweakClass"); + if(version.compareTo(ClientProfile.Version.MC1710) > 0) { + clientArgs.add("net.minecraftforge.fml.common.launcher.FMLTweaker"); + } else { + clientArgs.add("cpw.mods.fml.common.launcher.FMLTweaker"); + } + } + } + builder.setClientArgs(clientArgs); + + return builder.createClientProfile(); + } + + private static boolean optionContains(MakeProfileOption[] options, MakeProfileOption option) { + return Arrays.stream(options).anyMatch(e -> e == option); + } + + public static String getMainClassByVersion(ClientProfile.Version version, MakeProfileOption... options) { + if(optionContains(options, MakeProfileOption.LAUNCHWRAPPER)) { + return "net.minecraft.launchwrapper.Launch"; + } + return "net.minecraft.client.main.Main"; + } + + public static MakeProfileOption[] getMakeProfileOptionsFromDir(Path dir, ClientProfile.Version version) { + List options = new ArrayList<>(2); + if(Files.exists(dir.resolve("forge.jar"))) { + options.add(MakeProfileOption.FORGE); + } + if(Files.exists(dir.resolve("liteloader.jar"))) { + options.add(MakeProfileOption.LITELOADER); + } + if(version.compareTo(ClientProfile.Version.MC112) <= 0) { + options.add(MakeProfileOption.LAUNCHWRAPPER); + } + return options.toArray(new MakeProfileOption[0]); + } + @SuppressWarnings("deprecation") public static void saveProfile(ClientProfile profile, Path path) throws IOException { if (profile.getUUID() == null) profile.setUUID(UUID.randomUUID()); diff --git a/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java b/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java index 998f1696..427c6275 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java +++ b/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java @@ -15,9 +15,9 @@ public static void exit(int code) { public static void setSecurityManager(SecurityManager s) { LogHelper.debug("Try set security manager %s", s == null ? "null" : s.getClass().getName()); - if (AuthService.profile == null || AuthService.profile.securityManagerConfig == ClientProfile.SecurityManagerConfig.NONE) + if (AuthService.profile == null || AuthService.profile.getSecurityManagerConfig() == ClientProfile.SecurityManagerConfig.NONE) return; - if (AuthService.profile.securityManagerConfig == ClientProfile.SecurityManagerConfig.CLIENT) { + if (AuthService.profile.getSecurityManagerConfig() == ClientProfile.SecurityManagerConfig.CLIENT) { System.setSecurityManager(s); } //TODO NEXT diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index 5c5aa8c6..cb06b805 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -84,7 +84,7 @@ public static void main(String[] args) throws Throwable { LauncherGuardManager.initGuard(true); LogHelper.debug("Reading ClientLauncher params"); ClientLauncherProcess.ClientParams params = readParams(new InetSocketAddress("127.0.0.1", Launcher.getConfig().clientPort)); - if (params.profile.classLoaderConfig != ClientProfile.ClassLoaderConfig.AGENT) { + if (params.profile.getClassLoaderConfig() != ClientProfile.ClassLoaderConfig.AGENT) { LauncherEngine.verifyNoAgent(); } ClientProfile profile = params.profile; @@ -129,7 +129,7 @@ public static void main(String[] args) throws Throwable { LogHelper.error(e); } }; - if (params.profile.classLoaderConfig == ClientProfile.ClassLoaderConfig.LAUNCHER) { + if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.LAUNCHER) { ClientClassLoader classLoader = new ClientClassLoader(classpath.toArray(new URL[0]), ClassLoader.getSystemClassLoader()); ClientLauncherEntryPoint.classLoader = classLoader; Thread.currentThread().setContextClassLoader(classLoader); @@ -141,7 +141,7 @@ public static void main(String[] args) throws Throwable { ClientService.nativePath = classLoader.nativePath; classLoader.addURL(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toUri().toURL()); ClientService.baseURLs = classLoader.getURLs(); - } else if (params.profile.classLoaderConfig == ClientProfile.ClassLoaderConfig.AGENT) { + } else if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.AGENT) { ClientLauncherEntryPoint.classLoader = ClassLoader.getSystemClassLoader(); classpath.add(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toUri().toURL()); for (URL url : classpath) { @@ -155,7 +155,7 @@ public static void main(String[] args) throws Throwable { ClientService.classLoader = classLoader; ClientService.baseURLs = classpath.toArray(new URL[0]); } - if(params.profile.runtimeInClientConfig != ClientProfile.RuntimeInClientConfig.NONE) { + if(params.profile.getRuntimeInClientConfig() != ClientProfile.RuntimeInClientConfig.NONE) { CommonHelper.newThread("Client Launcher Thread", true, () -> { try { engine.start(args); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java index abbe497d..1eeb60a7 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java @@ -117,7 +117,7 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException { processArgs.add(executeFile.toString()); processArgs.addAll(jvmArgs); //ADD CLASSPATH - if (params.profile.classLoaderConfig == ClientProfile.ClassLoaderConfig.AGENT) { + if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.AGENT) { processArgs.add("-javaagent:".concat(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toAbsolutePath().toString())); } if (useLegacyJavaClassPathProperty) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index 9cdd16e5..3deceaa7 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -15,52 +15,58 @@ import java.util.*; public final class ClientProfile implements Comparable { - - public static final boolean profileCaseSensitive = Boolean.getBoolean("launcher.clientProfile.caseSensitive"); private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher( new String[0], new String[]{"indexes", "objects"}, new String[0]); - // Updater and client watch service + @LauncherNetworkAPI - private final List update = new ArrayList<>(); + private String title; @LauncherNetworkAPI - private final List updateExclusions = new ArrayList<>(); - @LauncherNetworkAPI - private final List updateShared = new ArrayList<>(); - @LauncherNetworkAPI - private final List updateVerify = new ArrayList<>(); - @LauncherNetworkAPI - private final Set updateOptional = new HashSet<>(); - @LauncherNetworkAPI - private final List jvmArgs = new ArrayList<>(); - @LauncherNetworkAPI - private final List classPath = new ArrayList<>(); - @LauncherNetworkAPI - private final List altClassPath = new ArrayList<>(); - @LauncherNetworkAPI - private final List clientArgs = new ArrayList<>(); - @LauncherNetworkAPI - private final List compatClasses = new ArrayList<>(); - @LauncherNetworkAPI - private final Map properties = new HashMap<>(); - @LauncherNetworkAPI - private final List servers = new ArrayList<>(1); - @LauncherNetworkAPI - public SecurityManagerConfig securityManagerConfig = SecurityManagerConfig.CLIENT; - @LauncherNetworkAPI - public ClassLoaderConfig classLoaderConfig = ClassLoaderConfig.LAUNCHER; - @LauncherNetworkAPI - public SignedClientConfig signedClientConfig = SignedClientConfig.NONE; - @LauncherNetworkAPI - public RuntimeInClientConfig runtimeInClientConfig = RuntimeInClientConfig.NONE; - // Version + private UUID uuid; @LauncherNetworkAPI private String version; @LauncherNetworkAPI - private String assetIndex; + private String info; @LauncherNetworkAPI private String dir; @LauncherNetworkAPI + private int sortIndex; + @LauncherNetworkAPI + private String assetIndex; + @LauncherNetworkAPI private String assetDir; + // Updater and client watch service + @LauncherNetworkAPI + private List update; + @LauncherNetworkAPI + private List updateExclusions; + @LauncherNetworkAPI + private List updateShared; + @LauncherNetworkAPI + private List updateVerify; + @LauncherNetworkAPI + private Set updateOptional; + @LauncherNetworkAPI + private List jvmArgs; + @LauncherNetworkAPI + private List classPath; + @LauncherNetworkAPI + private List altClassPath; + @LauncherNetworkAPI + private List clientArgs; + @LauncherNetworkAPI + private List compatClasses; + @LauncherNetworkAPI + private Map properties; + @LauncherNetworkAPI + private List servers; + @LauncherNetworkAPI + private SecurityManagerConfig securityManagerConfig; + @LauncherNetworkAPI + private ClassLoaderConfig classLoaderConfig; + @LauncherNetworkAPI + private SignedClientConfig signedClientConfig; + @LauncherNetworkAPI + private RuntimeInClientConfig runtimeInClientConfig; @LauncherNetworkAPI private int recommendJavaVersion = 8; @LauncherNetworkAPI @@ -71,21 +77,6 @@ public final class ClientProfile implements Comparable { private boolean warnMissJavaVersion = true; @LauncherNetworkAPI private ProfileDefaultSettings settings = new ProfileDefaultSettings(); - // Client - @LauncherNetworkAPI - private int sortIndex; - @LauncherNetworkAPI - private UUID uuid; - @LauncherNetworkAPI - private String title; - @LauncherNetworkAPI - private String info; - @Deprecated - @LauncherNetworkAPI - private String serverAddress; - @Deprecated - @LauncherNetworkAPI - private int serverPort; @LauncherNetworkAPI private boolean updateFastCheck; // Client launcher @@ -181,42 +172,22 @@ public int getRecommendJavaVersion() { return recommendJavaVersion; } - public void setRecommendJavaVersion(int recommendJavaVersion) { - this.recommendJavaVersion = recommendJavaVersion; - } - public int getMinJavaVersion() { return minJavaVersion; } - public void setMinJavaVersion(int minJavaVersion) { - this.minJavaVersion = minJavaVersion; - } - public int getMaxJavaVersion() { return maxJavaVersion; } - public void setMaxJavaVersion(int maxJavaVersion) { - this.maxJavaVersion = maxJavaVersion; - } - public boolean isWarnMissJavaVersion() { return warnMissJavaVersion; } - public void setWarnMissJavaVersion(boolean warnMissJavaVersion) { - this.warnMissJavaVersion = warnMissJavaVersion; - } - public ProfileDefaultSettings getSettings() { return settings; } - public void setSettings(ProfileDefaultSettings settings) { - this.settings = settings; - } - public void updateOptionalGraph() { for (OptionalFile file : updateOptional) { if (file.dependenciesFile != null) { @@ -234,6 +205,8 @@ public void updateOptionalGraph() { } } + + @Deprecated public OptionalFile getOptionalFile(String file, OptionalType type) { for (OptionalFile f : updateOptional) @@ -251,90 +224,6 @@ public Collection getShared() { return updateShared; } - @Deprecated - public void markOptional(OptionalFile file) { - - if (file.mark) return; - file.mark = true; - file.watchEvent(true); - if (file.dependencies != null) { - for (OptionalFile dep : file.dependencies) { - if (dep.dependenciesCount == null) dep.dependenciesCount = new HashSet<>(); - dep.dependenciesCount.add(file); - markOptional(dep); - } - } - if (file.conflict != null) { - for (OptionalFile conflict : file.conflict) { - unmarkOptional(conflict); - } - } - } - - @Deprecated - public void unmarkOptional(OptionalFile file) { - if (!file.mark) return; - file.mark = false; - file.watchEvent(false); - if (file.dependenciesCount != null) { - for (OptionalFile f : file.dependenciesCount) { - if (f.isPreset) continue; - unmarkOptional(f); - } - file.dependenciesCount.clear(); - file.dependenciesCount = null; - } - if (file.dependencies != null) { - for (OptionalFile f : file.dependencies) { - if (!f.mark) continue; - if (f.dependenciesCount == null) { - unmarkOptional(f); - } else if (f.dependenciesCount.size() <= 1) { - f.dependenciesCount.clear(); - f.dependenciesCount = null; - unmarkOptional(f); - } - } - } - } - - @Deprecated - public void pushOptionalFile(HashedDir dir, boolean digest) { - for (OptionalFile opt : updateOptional) { - if (opt.type.equals(OptionalType.FILE) && !opt.mark) { - for (String file : opt.list) - dir.removeR(file); - } - } - } - - @Deprecated - public void pushOptionalJvmArgs(Collection jvmArgs1) { - for (OptionalFile opt : updateOptional) { - if (opt.type.equals(OptionalType.JVMARGS) && opt.mark) { - jvmArgs1.addAll(Arrays.asList(opt.list)); - } - } - } - - @Deprecated - public void pushOptionalClientArgs(Collection clientArgs1) { - for (OptionalFile opt : updateOptional) { - if (opt.type.equals(OptionalType.CLIENTARGS) && opt.mark) { - clientArgs1.addAll(Arrays.asList(opt.list)); - } - } - } - - @Deprecated - public void pushOptionalClassPath(pushOptionalClassPathCallback callback) throws IOException { - for (OptionalFile opt : updateOptional) { - if (opt.type.equals(OptionalType.CLASSPATH) && opt.mark) { - callback.run(opt.list); - } - } - } - public int getServerPort() { ServerProfile profile = getDefaultServerProfile(); return profile == null ? 25565 : profile.serverPort; @@ -485,6 +374,40 @@ public int hashCode() { return Objects.hash(uuid); } + public SecurityManagerConfig getSecurityManagerConfig() { + return securityManagerConfig; + } + + public void setSecurityManagerConfig(SecurityManagerConfig securityManagerConfig) { + this.securityManagerConfig = securityManagerConfig; + } + + public ClassLoaderConfig getClassLoaderConfig() { + return classLoaderConfig; + } + + public void setClassLoaderConfig(ClassLoaderConfig classLoaderConfig) { + this.classLoaderConfig = classLoaderConfig; + } + + public SignedClientConfig getSignedClientConfig() { + return signedClientConfig; + } + + public void setSignedClientConfig(SignedClientConfig signedClientConfig) { + this.signedClientConfig = signedClientConfig; + } + + public RuntimeInClientConfig getRuntimeInClientConfig() { + return runtimeInClientConfig; + } + + public void setRuntimeInClientConfig(RuntimeInClientConfig runtimeInClientConfig) { + this.runtimeInClientConfig = runtimeInClientConfig; + } + + + public enum Version { MC125("1.2.5", 29), MC147("1.4.7", 51), @@ -575,6 +498,22 @@ public static class ServerProfile { public InetSocketAddress toSocketAddress() { return InetSocketAddress.createUnresolved(serverAddress, serverPort); } + + public ServerProfile() { + } + + public ServerProfile(String name, String serverAddress, int serverPort) { + this.name = name; + this.serverAddress = serverAddress; + this.serverPort = serverPort; + } + + public ServerProfile(String name, String serverAddress, int serverPort, boolean isDefault) { + this.name = name; + this.serverAddress = serverAddress; + this.serverPort = serverPort; + this.isDefault = isDefault; + } } public static class ProfileDefaultSettings { @@ -583,4 +522,56 @@ public static class ProfileDefaultSettings { public boolean fullScreen; } + public ClientProfile() { + update = new ArrayList<>(); + updateExclusions = new ArrayList<>(); + updateShared = new ArrayList<>(); + updateVerify = new ArrayList<>(); + updateOptional = new HashSet<>(); + jvmArgs = new ArrayList<>(); + classPath = new ArrayList<>(); + altClassPath = new ArrayList<>(); + clientArgs = new ArrayList<>(); + compatClasses = new ArrayList<>(); + properties = new HashMap<>(); + servers = new ArrayList<>(1); + securityManagerConfig = SecurityManagerConfig.CLIENT; + classLoaderConfig = ClassLoaderConfig.LAUNCHER; + signedClientConfig = SignedClientConfig.NONE; + runtimeInClientConfig = RuntimeInClientConfig.NONE; + } + + public ClientProfile(List update, List updateExclusions, List updateShared, List updateVerify, Set updateOptional, List jvmArgs, List classPath, List altClassPath, List clientArgs, List compatClasses, Map properties, List servers, SecurityManagerConfig securityManagerConfig, ClassLoaderConfig classLoaderConfig, SignedClientConfig signedClientConfig, RuntimeInClientConfig runtimeInClientConfig, String version, String assetIndex, String dir, String assetDir, int recommendJavaVersion, int minJavaVersion, int maxJavaVersion, boolean warnMissJavaVersion, ProfileDefaultSettings settings, int sortIndex, UUID uuid, String title, String info, boolean updateFastCheck, String mainClass) { + this.update = update; + this.updateExclusions = updateExclusions; + this.updateShared = updateShared; + this.updateVerify = updateVerify; + this.updateOptional = updateOptional; + this.jvmArgs = jvmArgs; + this.classPath = classPath; + this.altClassPath = altClassPath; + this.clientArgs = clientArgs; + this.compatClasses = compatClasses; + this.properties = properties; + this.servers = servers; + this.securityManagerConfig = securityManagerConfig; + this.classLoaderConfig = classLoaderConfig; + this.signedClientConfig = signedClientConfig; + this.runtimeInClientConfig = runtimeInClientConfig; + this.version = version; + this.assetIndex = assetIndex; + this.dir = dir; + this.assetDir = assetDir; + this.recommendJavaVersion = recommendJavaVersion; + this.minJavaVersion = minJavaVersion; + this.maxJavaVersion = maxJavaVersion; + this.warnMissJavaVersion = warnMissJavaVersion; + this.settings = settings; + this.sortIndex = sortIndex; + this.uuid = uuid; + this.title = title; + this.info = info; + this.updateFastCheck = updateFastCheck; + this.mainClass = mainClass; + } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileBuilder.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileBuilder.java new file mode 100644 index 00000000..32a17dd6 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileBuilder.java @@ -0,0 +1,198 @@ +package pro.gravit.launcher.profiles; + +import pro.gravit.launcher.profiles.optional.OptionalFile; + +import java.util.*; + +public class ClientProfileBuilder { + private List update = new ArrayList<>(); + private List updateExclusions = new ArrayList<>(); + private List updateShared = new ArrayList<>(); + private List updateVerify = new ArrayList<>(); + private Set updateOptional = new HashSet<>(); + private List jvmArgs = new ArrayList<>(); + private List classPath = new ArrayList<>(); + private List altClassPath = new ArrayList<>(); + private List clientArgs = new ArrayList<>(); + private List compatClasses = new ArrayList<>(); + private Map properties = new HashMap<>(); + private List servers = new ArrayList<>(); + private ClientProfile.SecurityManagerConfig securityManagerConfig = ClientProfile.SecurityManagerConfig.LAUNCHER; + private ClientProfile.ClassLoaderConfig classLoaderConfig = ClientProfile.ClassLoaderConfig.LAUNCHER; + private ClientProfile.SignedClientConfig signedClientConfig = ClientProfile.SignedClientConfig.NONE; + private ClientProfile.RuntimeInClientConfig runtimeInClientConfig = ClientProfile.RuntimeInClientConfig.NONE; + private String version; + private String assetIndex; + private String dir; + private String assetDir; + private int recommendJavaVersion = 8; + private int minJavaVersion = 8; + private int maxJavaVersion = 999; + private boolean warnMissJavaVersion = true; + private ClientProfile.ProfileDefaultSettings settings = new ClientProfile.ProfileDefaultSettings(); + private int sortIndex; + private UUID uuid; + private String title; + private String info; + private boolean updateFastCheck = true; + private String mainClass; + + public ClientProfileBuilder setUpdate(List update) { + this.update = update; + return this; + } + + public ClientProfileBuilder setUpdateExclusions(List updateExclusions) { + this.updateExclusions = updateExclusions; + return this; + } + + public ClientProfileBuilder setUpdateShared(List updateShared) { + this.updateShared = updateShared; + return this; + } + + public ClientProfileBuilder setUpdateVerify(List updateVerify) { + this.updateVerify = updateVerify; + return this; + } + + public ClientProfileBuilder setUpdateOptional(Set updateOptional) { + this.updateOptional = updateOptional; + return this; + } + + public ClientProfileBuilder setJvmArgs(List jvmArgs) { + this.jvmArgs = jvmArgs; + return this; + } + + public ClientProfileBuilder setClassPath(List classPath) { + this.classPath = classPath; + return this; + } + + public ClientProfileBuilder setAltClassPath(List altClassPath) { + this.altClassPath = altClassPath; + return this; + } + + public ClientProfileBuilder setClientArgs(List clientArgs) { + this.clientArgs = clientArgs; + return this; + } + + public ClientProfileBuilder setCompatClasses(List compatClasses) { + this.compatClasses = compatClasses; + return this; + } + + public ClientProfileBuilder setProperties(Map properties) { + this.properties = properties; + return this; + } + + public ClientProfileBuilder setServers(List servers) { + this.servers = servers; + return this; + } + + public ClientProfileBuilder setSecurityManagerConfig(ClientProfile.SecurityManagerConfig securityManagerConfig) { + this.securityManagerConfig = securityManagerConfig; + return this; + } + + public ClientProfileBuilder setClassLoaderConfig(ClientProfile.ClassLoaderConfig classLoaderConfig) { + this.classLoaderConfig = classLoaderConfig; + return this; + } + + public ClientProfileBuilder setSignedClientConfig(ClientProfile.SignedClientConfig signedClientConfig) { + this.signedClientConfig = signedClientConfig; + return this; + } + + public ClientProfileBuilder setRuntimeInClientConfig(ClientProfile.RuntimeInClientConfig runtimeInClientConfig) { + this.runtimeInClientConfig = runtimeInClientConfig; + return this; + } + + public ClientProfileBuilder setVersion(String version) { + this.version = version; + return this; + } + + public ClientProfileBuilder setAssetIndex(String assetIndex) { + this.assetIndex = assetIndex; + return this; + } + + public ClientProfileBuilder setDir(String dir) { + this.dir = dir; + return this; + } + + public ClientProfileBuilder setAssetDir(String assetDir) { + this.assetDir = assetDir; + return this; + } + + public ClientProfileBuilder setRecommendJavaVersion(int recommendJavaVersion) { + this.recommendJavaVersion = recommendJavaVersion; + return this; + } + + public ClientProfileBuilder setMinJavaVersion(int minJavaVersion) { + this.minJavaVersion = minJavaVersion; + return this; + } + + public ClientProfileBuilder setMaxJavaVersion(int maxJavaVersion) { + this.maxJavaVersion = maxJavaVersion; + return this; + } + + public ClientProfileBuilder setWarnMissJavaVersion(boolean warnMissJavaVersion) { + this.warnMissJavaVersion = warnMissJavaVersion; + return this; + } + + public ClientProfileBuilder setSettings(ClientProfile.ProfileDefaultSettings settings) { + this.settings = settings; + return this; + } + + public ClientProfileBuilder setSortIndex(int sortIndex) { + this.sortIndex = sortIndex; + return this; + } + + public ClientProfileBuilder setUuid(UUID uuid) { + this.uuid = uuid; + return this; + } + + public ClientProfileBuilder setTitle(String title) { + this.title = title; + return this; + } + + public ClientProfileBuilder setInfo(String info) { + this.info = info; + return this; + } + + public ClientProfileBuilder setUpdateFastCheck(boolean updateFastCheck) { + this.updateFastCheck = updateFastCheck; + return this; + } + + public ClientProfileBuilder setMainClass(String mainClass) { + this.mainClass = mainClass; + return this; + } + + public ClientProfile createClientProfile() { + return new ClientProfile(update, updateExclusions, updateShared, updateVerify, updateOptional, jvmArgs, classPath, altClassPath, clientArgs, compatClasses, properties, servers, securityManagerConfig, classLoaderConfig, signedClientConfig, runtimeInClientConfig, version, assetIndex, dir, assetDir, recommendJavaVersion, minJavaVersion, maxJavaVersion, warnMissJavaVersion, settings, sortIndex, uuid, title, info, updateFastCheck, mainClass); + } +} \ No newline at end of file diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalTrigger.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalTrigger.java index f260af50..83f180a9 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalTrigger.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalTrigger.java @@ -8,6 +8,21 @@ public class OptionalTrigger { public long value; public long compareMode = 0; + public OptionalTrigger() { + } + + public OptionalTrigger(TriggerType type, long value) { + this.type = type; + this.value = value; + } + + public OptionalTrigger(TriggerType type, boolean need, long value, long compareMode) { + this.type = type; + this.need = need; + this.value = value; + this.compareMode = compareMode; + } + public boolean isTriggered() { long test; switch (type) {