Settings.java
net.minecraft.server.dedicated.Settings
信息
- 全限定名:net.minecraft.server.dedicated.Settings
- 类型:public abstract class
- 包:net.minecraft.server.dedicated
- 源码路径:src/main/java/net/minecraft/server/dedicated/Settings.java
- 起始行号:L26
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
properties- 类型:
Properties - 修饰符:
protected final - 源码定位:
L28 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.server.dedicated.Settings.MutableValue- 类型:
class - 修饰符:
public - 源码定位:
L188 - 说明:
TODO
- 类型:
构造器
public Settings(Properties properties) @ L30
- 构造器名:Settings
- 源码定位:L30
- 修饰符:public
参数:
- properties: Properties
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static Properties loadFromFile(Path file) @ L34
- 方法名:loadFromFile
- 源码定位:L34
- 返回类型:Properties
- 修饰符:public static
参数:
- file: Path
说明:
TODO
public void store(Path output) @ L67
- 方法名:store
- 源码定位:L67
- 返回类型:void
- 修饰符:public
参数:
- output: Path
说明:
TODO
private static <V extends Number> Function<String,V> wrapNumberDeserializer(Function<String,V> inner) @ L75
- 方法名:wrapNumberDeserializer
- 源码定位:L75
- 返回类型:
Function<String,V> - 修饰符:private static
参数:
- inner: Function<String,V>
说明:
TODO
protected static <V> Function<String,V> dispatchNumberOrString(IntFunction<V> intDeserializer, Function<String,V> stringDeserializer) @ L85
- 方法名:dispatchNumberOrString
- 源码定位:L85
- 返回类型:
Function<String,V> - 修饰符:protected static
参数:
- intDeserializer: IntFunction
- stringDeserializer: Function<String,V>
说明:
TODO
private String getStringRaw(String key) @ L97
- 方法名:getStringRaw
- 源码定位:L97
- 返回类型:String
- 修饰符:private
参数:
- key: String
说明:
TODO
protected <V> V getLegacy(String key, Function<String,V> deserializer) @ L101
- 方法名:getLegacy
- 源码定位:L101
- 返回类型:
V - 修饰符:protected
参数:
- key: String
- deserializer: Function<String,V>
说明:
TODO
protected <V> V get(String key, Function<String,V> deserializer, Function<V,String> serializer, V defaultValue) @ L111
- 方法名:get
- 源码定位:L111
- 返回类型:
V - 修饰符:protected
参数:
- key: String
- deserializer: Function<String,V>
- serializer: Function<V,String>
- defaultValue: V
说明:
TODO
protected <V> Settings<T>.MutableValue<V> getMutable(String key, Function<String,V> deserializer, Function<V,String> serializer, V defaultValue) @ L118
- 方法名:getMutable
- 源码定位:L118
- 返回类型:
Settings .MutableValue - 修饰符:protected
参数:
- key: String
- deserializer: Function<String,V>
- serializer: Function<V,String>
- defaultValue: V
说明:
TODO
protected <V> V get(String key, Function<String,V> deserializer, UnaryOperator<V> validator, Function<V,String> serializer, V defaultValue) @ L125
- 方法名:get
- 源码定位:L125
- 返回类型:
V - 修饰符:protected
参数:
- key: String
- deserializer: Function<String,V>
- validator: UnaryOperator
- serializer: Function<V,String>
- defaultValue: V
说明:
TODO
protected <V> V get(String key, Function<String,V> deserializer, V defaultValue) @ L132
- 方法名:get
- 源码定位:L132
- 返回类型:
V - 修饰符:protected
参数:
- key: String
- deserializer: Function<String,V>
- defaultValue: V
说明:
TODO
protected <V> Settings<T>.MutableValue<V> getMutable(String key, Function<String,V> deserializer, V defaultValue) @ L136
- 方法名:getMutable
- 源码定位:L136
- 返回类型:
Settings .MutableValue - 修饰符:protected
参数:
- key: String
- deserializer: Function<String,V>
- defaultValue: V
说明:
TODO
protected String get(String key, String defaultValue) @ L140
- 方法名:get
- 源码定位:L140
- 返回类型:String
- 修饰符:protected
参数:
- key: String
- defaultValue: String
说明:
TODO
protected String getLegacyString(String key) @ L144
- 方法名:getLegacyString
- 源码定位:L144
- 返回类型:String
- 修饰符:protected
参数:
- key: String
说明:
TODO
protected int get(String key, int defaultValue) @ L148
- 方法名:get
- 源码定位:L148
- 返回类型:int
- 修饰符:protected
参数:
- key: String
- defaultValue: int
说明:
TODO
protected Settings<T>.MutableValue<Integer> getMutable(String key, int defaultValue) @ L152
- 方法名:getMutable
- 源码定位:L152
- 返回类型:Settings
.MutableValue - 修饰符:protected
参数:
- key: String
- defaultValue: int
说明:
TODO
protected Settings<T>.MutableValue<String> getMutable(String key, String defaultValue) @ L156
- 方法名:getMutable
- 源码定位:L156
- 返回类型:Settings
.MutableValue - 修饰符:protected
参数:
- key: String
- defaultValue: String
说明:
TODO
protected int get(String key, UnaryOperator<Integer> validator, int defaultValue) @ L160
- 方法名:get
- 源码定位:L160
- 返回类型:int
- 修饰符:protected
参数:
- key: String
- validator: UnaryOperator
- defaultValue: int
说明:
TODO
protected long get(String key, long defaultValue) @ L164
- 方法名:get
- 源码定位:L164
- 返回类型:long
- 修饰符:protected
参数:
- key: String
- defaultValue: long
说明:
TODO
protected boolean get(String key, boolean defaultValue) @ L168
- 方法名:get
- 源码定位:L168
- 返回类型:boolean
- 修饰符:protected
参数:
- key: String
- defaultValue: boolean
说明:
TODO
protected Settings<T>.MutableValue<Boolean> getMutable(String key, boolean defaultValue) @ L172
- 方法名:getMutable
- 源码定位:L172
- 返回类型:Settings
.MutableValue - 修饰符:protected
参数:
- key: String
- defaultValue: boolean
说明:
TODO
protected Boolean getLegacyBoolean(String key) @ L176
- 方法名:getLegacyBoolean
- 源码定位:L176
- 返回类型:Boolean
- 修饰符:protected
参数:
- key: String
说明:
TODO
protected Properties cloneProperties() @ L180
- 方法名:cloneProperties
- 源码定位:L180
- 返回类型:Properties
- 修饰符:protected
参数:
- 无
说明:
TODO
protected abstract T reload(RegistryAccess registryAccess, Properties properties) @ L186
- 方法名:reload
- 源码定位:L186
- 返回类型:T
- 修饰符:protected abstract
参数:
- registryAccess: RegistryAccess
- properties: Properties
说明:
TODO
代码
public abstract class Settings<T extends Settings<T>> {
private static final Logger LOGGER = LogUtils.getLogger();
protected final Properties properties;
public Settings(Properties properties) {
this.properties = properties;
}
public static Properties loadFromFile(Path file) {
try {
try {
Properties var13;
try (InputStream is = Files.newInputStream(file)) {
CharsetDecoder reportingUtf8Decoder = StandardCharsets.UTF_8
.newDecoder()
.onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT);
Properties properties = new Properties();
properties.load(new InputStreamReader(is, reportingUtf8Decoder));
var13 = properties;
}
return var13;
} catch (CharacterCodingException var9) {
LOGGER.info("Failed to load properties as UTF-8 from file {}, trying ISO_8859_1", file);
Properties var4;
try (Reader reader = Files.newBufferedReader(file, StandardCharsets.ISO_8859_1)) {
Properties properties = new Properties();
properties.load(reader);
var4 = properties;
}
return var4;
}
} catch (IOException var10) {
LOGGER.error("Failed to load properties from file: {}", file, var10);
return new Properties();
}
}
public void store(Path output) {
try (Writer os = Files.newBufferedWriter(output, StandardCharsets.UTF_8)) {
this.properties.store(os, "Minecraft server properties");
} catch (IOException var7) {
LOGGER.error("Failed to store properties to file: {}", output);
}
}
private static <V extends Number> Function<String, @Nullable V> wrapNumberDeserializer(Function<String, V> inner) {
return s -> {
try {
return inner.apply(s);
} catch (NumberFormatException var3) {
return null;
}
};
}
protected static <V> Function<String, @Nullable V> dispatchNumberOrString(
IntFunction<@Nullable V> intDeserializer, Function<String, @Nullable V> stringDeserializer
) {
return s -> {
try {
return intDeserializer.apply(Integer.parseInt(s));
} catch (NumberFormatException var4) {
return stringDeserializer.apply(s);
}
};
}
private @Nullable String getStringRaw(String key) {
return (String)this.properties.get(key);
}
protected <V> @Nullable V getLegacy(String key, Function<String, V> deserializer) {
String value = this.getStringRaw(key);
if (value == null) {
return null;
} else {
this.properties.remove(key);
return deserializer.apply(value);
}
}
protected <V> V get(String key, Function<String, @Nullable V> deserializer, Function<V, String> serializer, V defaultValue) {
String value = this.getStringRaw(key);
V result = MoreObjects.firstNonNull(value != null ? deserializer.apply(value) : null, defaultValue);
this.properties.put(key, serializer.apply(result));
return result;
}
protected <V> Settings<T>.MutableValue<V> getMutable(String key, Function<String, @Nullable V> deserializer, Function<V, String> serializer, V defaultValue) {
String value = this.getStringRaw(key);
V result = MoreObjects.firstNonNull(value != null ? deserializer.apply(value) : null, defaultValue);
this.properties.put(key, serializer.apply(result));
return this.new MutableValue<>(key, result, serializer);
}
protected <V> V get(String key, Function<String, @Nullable V> deserializer, UnaryOperator<V> validator, Function<V, String> serializer, V defaultValue) {
return this.get(key, s -> {
V result = deserializer.apply(s);
return result != null ? validator.apply(result) : null;
}, serializer, defaultValue);
}
protected <V> V get(String key, Function<String, V> deserializer, V defaultValue) {
return this.get(key, deserializer, Objects::toString, defaultValue);
}
protected <V> Settings<T>.MutableValue<V> getMutable(String key, Function<String, V> deserializer, V defaultValue) {
return this.getMutable(key, deserializer, Objects::toString, defaultValue);
}
protected String get(String key, String defaultValue) {
return this.get(key, Function.identity(), Function.identity(), defaultValue);
}
protected @Nullable String getLegacyString(String key) {
return this.getLegacy(key, Function.identity());
}
protected int get(String key, int defaultValue) {
return this.get(key, wrapNumberDeserializer(Integer::parseInt), Integer.valueOf(defaultValue));
}
protected Settings<T>.MutableValue<Integer> getMutable(String key, int defaultValue) {
return this.getMutable(key, wrapNumberDeserializer(Integer::parseInt), defaultValue);
}
protected Settings<T>.MutableValue<String> getMutable(String key, String defaultValue) {
return this.getMutable(key, String::new, defaultValue);
}
protected int get(String key, UnaryOperator<Integer> validator, int defaultValue) {
return this.get(key, wrapNumberDeserializer(Integer::parseInt), validator, Objects::toString, defaultValue);
}
protected long get(String key, long defaultValue) {
return this.get(key, wrapNumberDeserializer(Long::parseLong), defaultValue);
}
protected boolean get(String key, boolean defaultValue) {
return this.get(key, Boolean::valueOf, defaultValue);
}
protected Settings<T>.MutableValue<Boolean> getMutable(String key, boolean defaultValue) {
return this.getMutable(key, Boolean::valueOf, defaultValue);
}
protected @Nullable Boolean getLegacyBoolean(String key) {
return this.getLegacy(key, Boolean::valueOf);
}
protected Properties cloneProperties() {
Properties result = new Properties();
result.putAll(this.properties);
return result;
}
protected abstract T reload(final RegistryAccess registryAccess, final Properties properties);
public class MutableValue<V> implements Supplier<V> {
private final String key;
private final V value;
private final Function<V, String> serializer;
private MutableValue(String key, V value, Function<V, String> serializer) {
Objects.requireNonNull(Settings.this);
super();
this.key = key;
this.value = value;
this.serializer = serializer;
}
@Override
public V get() {
return this.value;
}
public T update(RegistryAccess registryAccess, V value) {
Properties properties = Settings.this.cloneProperties();
properties.put(this.key, this.serializer.apply(value));
return Settings.this.reload(registryAccess, properties);
}
}
}引用的其他类
- RegistryAccess
- 引用位置:
参数
- 引用位置: