PathType enum
Пакет: com.hypixel.hytale.server.core
Файл: com/hypixel/hytale/server/core/Options.java
Поля (1)
| Модификаторы | Тип | Имя |
|---|---|---|
|
FILE,
DIR,
DIR_OR_ZIP, |
ANY |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core;
class="kw">import com.hypixel.hytale.common.util.PathUtil;
class="kw">import com.hypixel.hytale.common.util.java.ManifestUtil;
class="kw">import com.hypixel.hytale.logger.backend.HytaleLoggerBackend;
class="kw">import com.hypixel.hytale.server.core.io.transport.TransportType;
class="kw">import com.hypixel.hytale.server.core.universe.world.ValidationOption;
class="kw">import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
class="kw">import java.io.IOException;
class="kw">import java.net.InetSocketAddress;
class="kw">import java.nio.file.Files;
class="kw">import java.nio.file.InvalidPathException;
class="kw">import java.nio.file.Path;
class="kw">import java.nio.file.Paths;
class="kw">import java.util.HashMap;
class="kw">import java.util.List;
class="kw">import java.util.Locale;
class="kw">import java.util.Map;
class="kw">import java.util.UUID;
class="kw">import java.util.Map.Entry;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import joptsimple.OptionParser;
class="kw">import joptsimple.OptionSet;
class="kw">import joptsimple.OptionSpec;
class="kw">import joptsimple.ValueConversionException;
class="kw">import joptsimple.ValueConverter;
class="kw">public class Options {
class="kw">public class="kw">static class="kw">final OptionParser PARSER = new OptionParser();
class="kw">public class="kw">static class="kw">final OptionSpec<Void> HELP = PARSER.accepts("help", "Print's this message.").forHelp();
class="kw">public class="kw">static class="kw">final OptionSpec<Void> VERSION = PARSER.accepts("version", "Prints version information.");
class="kw">public class="kw">static class="kw">final OptionSpec<Void> BARE = PARSER.accepts(
"bare",
"Runs the server bare. For example without loading worlds, binding to ports or creating directories. (Note: Plugins will still be loaded which may not respect this flag)"
);
class="kw">public class="kw">static class="kw">final OptionSpec<Void> BOOTSTRAP = PARSER.accepts(
"bootstrap",
"Runs the server in bootstrap mode. Only the plugins required to authenticate and download the full server payload are loaded; use '/update download' to populate the current directory with Assets.zip, start.sh/bat and the Server/ JAR layout. Implies --bare."
);
class="kw">public class="kw">static class="kw">final OptionSpec<Entry<String, Level>> LOG_LEVELS = PARSER.accepts("log", "Sets the logger level.")
.withRequiredArg()
.withValuesSeparatedBy(',')
.withValuesConvertedBy(new Options.LevelValueConverter());
class="kw">public class="kw">static class="kw">final OptionSpec<InetSocketAddress> BIND = PARSER.acceptsAll(List.of("b", "bind"), "Port to listen on")
.withRequiredArg()
.withValuesSeparatedBy(',')
.withValuesConvertedBy(new Options.SocketAddressValueConverter())
.defaultsTo(new InetSocketAddress(5520), new InetSocketAddress[0]);
class="kw">public class="kw">static class="kw">final OptionSpec<TransportType> TRANSPORT = PARSER.acceptsAll(List.of("t", "transport"), "Transport type")
.withRequiredArg()
.ofType(TransportType.class)
.defaultsTo(TransportType.QUIC, new TransportType[0]);
class="kw">public class="kw">static class="kw">final OptionSpec<Void> DISABLE_CPB_BUILD = PARSER.accepts("disable-cpb-build", "Disables building of compact prefab buffers");
class="kw">public class="kw">static class="kw">final OptionSpec<Path> PREFAB_CACHE_DIRECTORY = PARSER.accepts("prefab-cache", "Prefab cache directory for immutable assets")
.withRequiredArg()
.withValuesConvertedBy(new Options.PathConverter(Options.PathConverter.PathType.ANY));
class="kw">public class="kw">static class="kw">final OptionSpec<Path> ASSET_DIRECTORY = PARSER.acceptsAll(List.of("assets"), "Asset directory")
.withRequiredArg()
.withValuesConvertedBy(new Options.PathConverter(Options.PathConverter.PathType.DIR_OR_ZIP))
.defaultsTo(Paths.get("../HytaleAssets"), new Path[0]);
class="kw">public class="kw">static class="kw">final OptionSpec<Path> MODS_DIRECTORIES = PARSER.acceptsAll(List.of("mods"), "Additional mods directories")
.withRequiredArg()
.withValuesSeparatedBy(',')
.withValuesConvertedBy(new Options.PathConverter(Options.PathConverter.PathType.DIR));
class="kw">public class="kw">static class="kw">final OptionSpec<Void> ACCEPT_EARLY_PLUGINS = PARSER.accepts(
"accept-early-plugins", "You acknowledge that loading early plugins is unsupported and may cause stability issues."
);
class="kw">public class="kw">static class="kw">final OptionSpec<Path> EARLY_PLUGIN_DIRECTORIES = PARSER.accepts("early-plugins", "Additional early plugin directories to load from")
.withRequiredArg()
.withValuesSeparatedBy(',')
.withValuesConvertedBy(new Options.PathConverter(Options.PathConverter.PathType.DIR));
class="kw">public class="kw">static class="kw">final OptionSpec<Void> VALIDATE_ASSETS = PARSER.accepts(
"validate-assets", "Causes the server to exit with an error code if any assets are invalid."
);
class="kw">public class="kw">static class="kw">final OptionSpec<ValidationOption> VALIDATE_PREFABS = PARSER.accepts(
"validate-prefabs", "Causes the server to exit with an error code if any prefabs are invalid."
)
.withOptionalArg()
.withValuesSeparatedBy(',')
.ofType(ValidationOption.class);
class="kw">public class="kw">static class="kw">final OptionSpec<Void> VALIDATE_WORLD_GEN = PARSER.accepts(
"validate-world-gen", "Causes the server to exit with an error code if class="kw">default world gen is invalid."
);
class="kw">public class="kw">static class="kw">final OptionSpec<Void> SHUTDOWN_AFTER_VALIDATE = PARSER.accepts(
"shutdown-after-validate", "Automatically shutdown the server after asset and/or prefab validation."
);
class="kw">public class="kw">static class="kw">final OptionSpec<Path> GENERATE_ASSET_SCHEMA = PARSER.accepts(
"generate-asset-schema", "Generate asset JSON schemas to the specified directory and exit"
)
.withRequiredArg()
.withValuesConvertedBy(new Options.PathConverter(Options.PathConverter.PathType.ANY));
class="kw">public class="kw">static class="kw">final OptionSpec<Path> GENERATE_CONFIG_SCHEMA = PARSER.accepts(
"generate-config-schema", "Generate config JSON schemas to the specified directory and exit"
)
.withRequiredArg()
.withValuesConvertedBy(new Options.PathConverter(Options.PathConverter.PathType.ANY));
class="kw">public class="kw">static class="kw">final OptionSpec<Path> WORLD_GEN_DIRECTORY = PARSER.accepts("world-gen", "World gen directory")
.withRequiredArg()
.withValuesConvertedBy(new Options.PathConverter(Options.PathConverter.PathType.DIR));
class="kw">public class="kw">static class="kw">final OptionSpec<Void> DISABLE_FILE_WATCHER = PARSER.accepts("disable-file-watcher");
class="kw">public class="kw">static class="kw">final OptionSpec<Void> DISABLE_SENTRY = PARSER.accepts("disable-sentry");
class="kw">public class="kw">static class="kw">final OptionSpec<Void> DISABLE_ASSET_COMPARE = PARSER.accepts("disable-asset-compare");
class="kw">public class="kw">static class="kw">final OptionSpec<Void> BACKUP = PARSER.accepts("backup");
class="kw">public class="kw">static class="kw">final OptionSpec<Integer> BACKUP_FREQUENCY_MINUTES = PARSER.accepts("backup-frequency")
.withRequiredArg()
.ofType(Integer.class)
.defaultsTo(30, new Integer[0]);
class="kw">public class="kw">static class="kw">final OptionSpec<Path> BACKUP_DIRECTORY = PARSER.accepts("backup-dir")
.requiredIf(BACKUP, new OptionSpec[0])
.withRequiredArg()
.withValuesConvertedBy(new Options.PathConverter(Options.PathConverter.PathType.DIR));
class="kw">public class="kw">static class="kw">final OptionSpec<Integer> BACKUP_MAX_COUNT = PARSER.accepts("backup-max-count")
.withRequiredArg()
.ofType(Integer.class)
.defaultsTo(5, new Integer[0]);
class="kw">public class="kw">static class="kw">final OptionSpec<Integer> BACKUP_ARCHIVE_MAX_COUNT = PARSER.accepts("backup-archive-max-count")
.withRequiredArg()
.ofType(Integer.class)
.defaultsTo(5, new Integer[0]);
class="kw">public class="kw">static class="kw">final OptionSpec<Void> SINGLEPLAYER = PARSER.accepts("singleplayer");
class="kw">public class="kw">static class="kw">final OptionSpec<String> OWNER_NAME = PARSER.accepts("owner-name").withRequiredArg();
class="kw">public class="kw">static class="kw">final OptionSpec<UUID> OWNER_UUID = PARSER.accepts("owner-uuid").withRequiredArg().withValuesConvertedBy(new Options.UUIDConverter());
class="kw">public class="kw">static class="kw">final OptionSpec<Integer> CLIENT_PID = PARSER.accepts("client-pid").withRequiredArg().ofType(Integer.class);
class="kw">public class="kw">static class="kw">final OptionSpec<Path> UNIVERSE = PARSER.accepts("universe")
.withRequiredArg()
.withValuesConvertedBy(new Options.PathConverter(Options.PathConverter.PathType.DIR));
class="kw">public class="kw">static class="kw">final OptionSpec<Void> EVENT_DEBUG = PARSER.accepts("event-debug");
class="kw">public class="kw">static class="kw">final OptionSpec<Boolean> FORCE_NETWORK_FLUSH = PARSER.accepts("force-network-flush")
.withRequiredArg()
.ofType(Boolean.class)
.defaultsTo(true, new Boolean[0]);
class="kw">public class="kw">static class="kw">final OptionSpec<Map<String, Path>> MIGRATIONS = PARSER.accepts("migrations", "The migrations to run")
.withRequiredArg()
.withValuesConvertedBy(new Options.StringToPathMapConverter());
class="kw">public class="kw">static class="kw">final OptionSpec<String> MIGRATE_WORLDS = PARSER.accepts("migrate-worlds", "Worlds to migrate")
.availableIf(MIGRATIONS, new OptionSpec[0])
.withRequiredArg()
.withValuesSeparatedBy(',');
class="kw">public class="kw">static class="kw">final OptionSpec<String> BOOT_COMMAND = PARSER.accepts(
"boot-command", "Runs command on boot. If multiple commands are provided they are executed synchronously in order."
)
.withRequiredArg()
.withValuesSeparatedBy(',');
class="kw">public class="kw">static class="kw">final OptionSpec<Void> IGNORE_BROKEN_MODS = PARSER.accepts(
"ignore-broken-mods", "Ignores broken mods, attempting to allow the server to boot even if one fails to load"
);
class="kw">public class="kw">static class="kw">final String ALLOW_SELF_OP_COMMAND_STRING = "allow-op";
class="kw">public class="kw">static class="kw">final OptionSpec<Void> ALLOW_SELF_OP_COMMAND = PARSER.accepts("allow-op");
class="kw">public class="kw">static class="kw">final OptionSpec<Options.AuthMode> AUTH_MODE = PARSER.accepts("auth-mode", "Authentication mode")
.withRequiredArg()
.withValuesConvertedBy(new Options.AuthModeConverter())
.defaultsTo(Options.AuthMode.AUTHENTICATED, new Options.AuthMode[0]);
class="kw">public class="kw">static class="kw">final OptionSpec<String> SESSION_TOKEN = PARSER.accepts("session-token", "Session token for Session Service API")
.withRequiredArg()
.ofType(String.class);
class="kw">public class="kw">static class="kw">final OptionSpec<String> IDENTITY_TOKEN = PARSER.accepts("identity-token", "Identity token (JWT)").withRequiredArg().ofType(String.class);
class="kw">public class="kw">static class="kw">final OptionSpec<Void> VERIFY_WORLDS = PARSER.accepts("verify-worlds", "Verify all worlds and then exits");
class="kw">public class="kw">static class="kw">final OptionSpec<Options.RecoveryMode> RECOVERY_MODE = PARSER.accepts(
"recovery-mode", "How to handle broken chunks when encountered during recovery"
)
.availableIf(VERIFY_WORLDS, new OptionSpec[0])
.withRequiredArg()
.ofType(Options.RecoveryMode.class);
class="kw">private class="kw">static OptionSet optionSet;
class="kw">public Options() {
}
class="kw">public class="kw">static OptionSet getOptionSet() {
class="kw">return optionSet;
}
class="kw">public class="kw">static boolean isBare() {
class="kw">return optionSet.has(BARE) || optionSet.has(BOOTSTRAP);
}
class="kw">public class="kw">static <T> T getOrDefault(OptionSpec<T> var0, @Nonnull OptionSet var1, T var2) {
class="kw">return (T)(!var1.has(var0) ? var2 : var1.valueOf(var0));
}
class="kw">public class="kw">static boolean parse(String[] var0) class="kw">throws IOException {
optionSet = PARSER.parse(var0);
if (optionSet.has(HELP)) {
PARSER.printHelpOn(System.out);
class="kw">return true;
}
if (optionSet.has(VERSION)) {
String var4 = ManifestUtil.getImplementationVersion();
String var7 = ManifestUtil.getPatchline();
String var10 = "release";
if ("release".equals(var7)) {
System.out.println("HytaleServer v" + var4 + " (" + var7 + ")");
} else {
System.out.println("HytaleServer v" + var4 + " (" + var7 + ", " + var10 + ")");
}
class="kw">return true;
} else {
List var1 = optionSet.nonOptionArguments();
if (!var1.isEmpty()) {
System.err.println("Unknown arguments: " + var1);
System.exit(1);
class="kw">return true;
}
if (optionSet.has(LOG_LEVELS)) {
HytaleLoggerBackend.loadLevels(optionSet.valuesOf(LOG_LEVELS));
} else if (optionSet.has(SHUTDOWN_AFTER_VALIDATE)) {
HytaleLoggerBackend.loadLevels(List.of(Map.entry("", Level.WARNING)));
}
for (Path var3 : optionSet.valuesOf(ASSET_DIRECTORY)) {
PathUtil.addTrustedRoot(var3);
}
for (Path var8 : optionSet.valuesOf(MODS_DIRECTORIES)) {
PathUtil.addTrustedRoot(var8);
}
for (Path var9 : optionSet.valuesOf(EARLY_PLUGIN_DIRECTORIES)) {
PathUtil.addTrustedRoot(var9);
}
if (optionSet.has(WORLD_GEN_DIRECTORY)) {
PathUtil.addTrustedRoot((Path)optionSet.valueOf(WORLD_GEN_DIRECTORY));
}
if (optionSet.has(BACKUP_DIRECTORY)) {
PathUtil.addTrustedRoot((Path)optionSet.valueOf(BACKUP_DIRECTORY));
}
if (optionSet.has(UNIVERSE)) {
PathUtil.addTrustedRoot((Path)optionSet.valueOf(UNIVERSE));
}
class="kw">return false;
}
}
class="kw">public enum AuthMode {
AUTHENTICATED,
OFFLINE,
INSECURE;
AuthMode() {
}
}
class="kw">private class="kw">static class AuthModeConverter class="kw">implements ValueConverter<Options.AuthMode> {
class="kw">private AuthModeConverter() {
}
class="kw">public Options.AuthMode convert(String var1) {
class="kw">return Options.AuthMode.valueOf(var1.toUpperCase(Locale.ROOT));
}
class="kw">public Class<? class="kw">extends Options.AuthMode> valueType() {
class="kw">return Options.AuthMode.class;
}
class="kw">public String valuePattern() {
class="kw">return "authenticated|offline|insecure";
}
}
class="kw">public class="kw">static class LevelValueConverter class="kw">implements ValueConverter<Entry<String, Level>> {
class="kw">private class="kw">static class="kw">final Entry<String, Level> ENTRY = Map.entry("", Level.ALL);
class="kw">public LevelValueConverter() {
}
@Nonnull
class="kw">public Entry<String, Level> convert(@Nonnull String var1) {
if (!var1.contains(":")) {
class="kw">return Map.entry("", Level.parse(var1.toUpperCase(Locale.ROOT)));
}
String[] var2 = var1.split(":", -1);
class="kw">return Map.entry(var2[0], Level.parse(var2[1].toUpperCase(Locale.ROOT)));
}
@Nonnull
class="kw">public Class<Entry<String, Level>> valueType() {
class="kw">return (Class<Entry<String, Level>>)ENTRY.getClass();
}
@Nullable
class="kw">public String valuePattern() {
class="kw">return null;
}
}
class="kw">public class="kw">static class PathConverter class="kw">implements ValueConverter<Path> {
class="kw">private class="kw">final Options.PathConverter.PathType pathType;
class="kw">public PathConverter(Options.PathConverter.PathType var1) {
this.pathType = var1;
}
@Nonnull
class="kw">public Path convert(@Nonnull String var1) {
try {
Path var2 = PathUtil.get(var1);
if (Files.exists(var2)) {
class="kw">switch (this.pathType) {
case FILE:
if (!Files.isRegularFile(var2)) {
throw new ValueConversionException("Path must be a file!");
}
break;
case DIR:
if (!Files.isDirectory(var2)) {
throw new ValueConversionException("Path must be a directory!");
}
break;
case DIR_OR_ZIP:
if (!Files.isDirectory(var2) && (!Files.exists(var2) || !var2.getFileName().toString().endsWith(".zip"))) {
throw new ValueConversionException("Path must be a directory or zip!");
}
}
}
class="kw">return var2;
} catch (InvalidPathException var3) {
throw new ValueConversionException("Failed to parse '" + var1 + "' to path!", var3);
}
}
@Nonnull
class="kw">public Class<? class="kw">extends Path> valueType() {
class="kw">return Path.class;
}
@Nullable
class="kw">public String valuePattern() {
class="kw">return null;
}
class="kw">public enum PathType {
FILE,
DIR,
DIR_OR_ZIP,
ANY;
PathType() {
}
}
}
class="kw">public enum RecoveryMode {
FROM_BACKUP_OR_REGENERATE,
REGENERATE;
RecoveryMode() {
}
}
class="kw">public class="kw">static class SocketAddressValueConverter class="kw">implements ValueConverter<InetSocketAddress> {
class="kw">public SocketAddressValueConverter() {
}
@Nonnull
class="kw">public InetSocketAddress convert(@Nonnull String var1) {
if (var1.contains(":")) {
String[] var2 = var1.split(":", -1);
class="kw">return new InetSocketAddress(var2[0], Integer.parseInt(var2[1]));
}
try {
class="kw">return new InetSocketAddress(Integer.parseInt(var1));
} catch (NumberFormatException var3) {
class="kw">return new InetSocketAddress(var1, 5520);
}
}
@Nonnull
class="kw">public Class<? class="kw">extends InetSocketAddress> valueType() {
class="kw">return InetSocketAddress.class;
}
@Nullable
class="kw">public String valuePattern() {
class="kw">return null;
}
}
class="kw">public class="kw">static class StringToPathMapConverter class="kw">implements ValueConverter<Map<String, Path>> {
class="kw">private class="kw">static class="kw">final Map<String, Level> MAP = new Object2ObjectOpenHashMap();
class="kw">public StringToPathMapConverter() {
}
@Nonnull
class="kw">public Map<String, Path> convert(@Nonnull String var1) {
HashMap var2 = new HashMap<>();
String[] var3 = var1.split(",", 0);
for (String var7 : var3) {
String[] var8 = var7.split("=", 0);
if (var8.length == 2) {
if (var2.containsKey(var8[0])) {
throw new ValueConversionException("String '" + var8[0] + "' has already been specified!");
}
Path var9 = PathUtil.get(var8[1]);
if (!Files.exists(var9)) {
throw new ValueConversionException("No file found for '" + var8[1] + "'!");
}
var2.put(var8[0], var9);
}
}
class="kw">return var2;
}
@Nonnull
class="kw">public Class<Map<String, Path>> valueType() {
class="kw">return (Class<Map<String, Path>>)MAP.getClass();
}
@Nullable
class="kw">public String valuePattern() {
class="kw">return null;
}
}
class="kw">public class="kw">static class UUIDConverter class="kw">implements ValueConverter<UUID> {
class="kw">public UUIDConverter() {
}
@Nonnull
class="kw">public UUID convert(@Nonnull String var1) {
class="kw">return UUID.fromString(var1);
}
@Nonnull
class="kw">public Class<? class="kw">extends UUID> valueType() {
class="kw">return UUID.class;
}
@Nullable
class="kw">public String valuePattern() {
class="kw">return null;
}
}
}