|
18 | 18 | package net.raphimc.viaproxy.protocoltranslator.viaproxy; |
19 | 19 |
|
20 | 20 | import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; |
21 | | -import joptsimple.OptionException; |
22 | | -import joptsimple.OptionParser; |
23 | | -import joptsimple.OptionSet; |
24 | | -import joptsimple.OptionSpec; |
25 | 21 | import net.lenni0451.optconfig.ConfigContext; |
26 | 22 | import net.lenni0451.optconfig.ConfigLoader; |
27 | 23 | import net.lenni0451.optconfig.annotations.*; |
28 | | -import net.lenni0451.optconfig.index.ClassIndexer; |
29 | | -import net.lenni0451.optconfig.index.ConfigType; |
30 | | -import net.lenni0451.optconfig.index.types.ConfigOption; |
31 | | -import net.lenni0451.optconfig.index.types.SectionIndex; |
32 | 24 | import net.lenni0451.optconfig.migrate.ConfigMigrator; |
33 | 25 | import net.lenni0451.optconfig.provider.ConfigProvider; |
34 | | -import net.raphimc.viaproxy.ViaProxy; |
35 | | -import net.raphimc.viaproxy.cli.BetterHelpFormatter; |
36 | | -import net.raphimc.viaproxy.cli.HelpRequestedException; |
37 | | -import net.raphimc.viaproxy.plugins.events.PostOptionsParseEvent; |
38 | | -import net.raphimc.viaproxy.plugins.events.PreOptionsParseEvent; |
39 | 26 | import net.raphimc.viaproxy.protocoltranslator.ProtocolTranslator; |
40 | 27 | import net.raphimc.viaproxy.saves.impl.accounts.Account; |
41 | 28 | import net.raphimc.viaproxy.util.AddressUtil; |
|
46 | 33 | import java.net.SocketAddress; |
47 | 34 | import java.util.HashMap; |
48 | 35 | import java.util.Map; |
49 | | -import java.util.Stack; |
50 | 36 |
|
51 | 37 | @OptConfig(header = "ViaProxy configuration file", version = 2) |
52 | 38 | @Migrator(from = 1, to = 2, migrator = ViaProxyConfig.Migrator1To2.class) |
@@ -76,76 +62,6 @@ public static ViaProxyConfig create(final File configFile) { |
76 | 62 | } |
77 | 63 | } |
78 | 64 |
|
79 | | - @SuppressWarnings("UnstableApiUsage") |
80 | | - public void loadFromArguments(final String[] args) throws Exception { |
81 | | - final OptionParser optionParser = new OptionParser(); |
82 | | - final OptionSpec<Void> optionHelp = optionParser.accepts("help").forHelp(); |
83 | | - final OptionSpec<Void> optionListVersions = optionParser.accepts("list-versions", "Lists all supported server/target versions").forHelp(); |
84 | | - |
85 | | - final Map<OptionSpec<Object>, ConfigOption> optionMap = new HashMap<>(); |
86 | | - final Stack<SectionIndex> stack = new Stack<>(); |
87 | | - final ConfigLoader<ViaProxyConfig> configLoader = new ConfigLoader<>(ViaProxyConfig.class); |
88 | | - stack.push(ClassIndexer.indexClass(ConfigType.INSTANCED, ViaProxyConfig.class, configLoader.getConfigOptions().getClassAccessFactory())); |
89 | | - while (!stack.isEmpty()) { |
90 | | - final SectionIndex index = stack.pop(); |
91 | | - stack.addAll(index.getSubSections().values()); |
92 | | - |
93 | | - for (ConfigOption option : index.getOptions()) { |
94 | | - if (index.getSubSections().containsKey(option)) continue; |
95 | | - |
96 | | - Object defaultValue = option.getFieldAccess().getValue(this); |
97 | | - if (option.getTypeSerializer() != null) { |
98 | | - defaultValue = option.createTypeSerializer(configLoader, ViaProxyConfig.class, this).serialize(defaultValue); |
99 | | - } |
100 | | - final OptionSpec<Object> cliOption = optionParser.accepts(option.getName()).withRequiredArg().ofType((Class<Object>) defaultValue.getClass()).defaultsTo(defaultValue); |
101 | | - optionMap.put(cliOption, option); |
102 | | - } |
103 | | - } |
104 | | - |
105 | | - try { |
106 | | - ViaProxy.EVENT_MANAGER.call(new PreOptionsParseEvent(optionParser)); |
107 | | - final OptionSet options = optionParser.parse(args); |
108 | | - if (options.has(optionHelp)) { |
109 | | - throw new HelpRequestedException(); |
110 | | - } else if (options.has(optionListVersions)) { |
111 | | - Logger.LOGGER.info("=== Supported Server Versions ==="); |
112 | | - for (ProtocolVersion version : ProtocolVersion.getProtocols()) { |
113 | | - Logger.LOGGER.info(version.getName()); |
114 | | - } |
115 | | - Logger.LOGGER.info("==================================="); |
116 | | - System.exit(0); |
117 | | - } |
118 | | - |
119 | | - if (options.has("minecraft-account-index")) { |
120 | | - this.getBackend().setAuthMethod(AuthMethod.ACCOUNT); |
121 | | - } |
122 | | - for (Map.Entry<OptionSpec<Object>, ConfigOption> entry : optionMap.entrySet()) { |
123 | | - final ConfigOption option = entry.getValue(); |
124 | | - if (options.has(entry.getKey())) { |
125 | | - Object value = options.valueOf(entry.getKey()); |
126 | | - if (option.getTypeSerializer() != null) { |
127 | | - value = option.createTypeSerializer(configLoader, ViaProxyConfig.class, this).deserialize((Class<Object>) option.getFieldAccess().getType(), value); |
128 | | - } |
129 | | - if (option.getValidator() != null) { |
130 | | - value = option.getValidator().invoke(this, value); |
131 | | - } |
132 | | - option.getFieldAccess().setValue(this, value); |
133 | | - } |
134 | | - } |
135 | | - |
136 | | - ViaProxy.EVENT_MANAGER.call(new PostOptionsParseEvent(options)); |
137 | | - return; |
138 | | - } catch (OptionException e) { |
139 | | - Logger.LOGGER.fatal("Error parsing CLI options: " + e.getMessage()); |
140 | | - } catch (HelpRequestedException ignored) { |
141 | | - } |
142 | | - |
143 | | - optionParser.formatHelpWith(new BetterHelpFormatter()); |
144 | | - optionParser.printHelpOn(Logger.SYSOUT); |
145 | | - Logger.LOGGER.info("For a more detailed description of the options, please refer to the viaproxy.yml file."); |
146 | | - System.exit(1); |
147 | | - } |
148 | | - |
149 | 65 | public void save() { |
150 | 66 | try { |
151 | 67 | this.configContext.save(); |
|
0 commit comments