mirror of
https://github.com/tanyaofei/minecraft-fakeplayer.git
synced 2025-07-14 05:12:23 +08:00
优化代码
This commit is contained in:
parent
d55ec96dff
commit
e4f6f45c94
@ -149,7 +149,7 @@ public abstract class CommandSupports {
|
|||||||
if (!config.options().contains(arg)) {
|
if (!config.options().contains(arg)) {
|
||||||
throw CustomArgument.CustomArgumentException.fromString(i18n.asString("fakeplayer.command.config.set.error.invalid-value"));
|
throw CustomArgument.CustomArgumentException.fromString(i18n.asString("fakeplayer.command.config.set.error.invalid-value"));
|
||||||
}
|
}
|
||||||
return config.converter().apply(arg);
|
return config.parser().apply(arg);
|
||||||
}).replaceSuggestions(ArgumentSuggestions.stringsAsync(info -> CompletableFuture.supplyAsync(() -> {
|
}).replaceSuggestions(ArgumentSuggestions.stringsAsync(info -> CompletableFuture.supplyAsync(() -> {
|
||||||
var config = Objects.requireNonNull((Config<?>) info.previousArgs().get(configNodeName));
|
var config = Objects.requireNonNull((Config<?>) info.previousArgs().get(configNodeName));
|
||||||
var arg = info.currentArg().toLowerCase();
|
var arg = info.currentArg().toLowerCase();
|
||||||
|
@ -38,7 +38,7 @@ public class UserConfigManager {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
return config.defaultValue();
|
return config.defaultValue();
|
||||||
}
|
}
|
||||||
return config.converter().apply(value);
|
return config.parser().apply(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,7 +61,7 @@ public class UserConfigManager {
|
|||||||
if (key == null || !key.hasPermission(player)) {
|
if (key == null || !key.hasPermission(player)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
values.put(key, key.converter().apply(config.value()));
|
values.put(key, key.parser().apply(config.value()));
|
||||||
}
|
}
|
||||||
return new Configs(values);
|
return new Configs(values);
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import java.util.function.Function;
|
|||||||
* @param translationKey 翻译 key
|
* @param translationKey 翻译 key
|
||||||
* @param defaultValue 默认值
|
* @param defaultValue 默认值
|
||||||
* @param options 可选值
|
* @param options 可选值
|
||||||
* @param converter 转换器
|
* @param parser 转换器
|
||||||
* @param accessor 访问器, 访问或者设置假人当前配置
|
* @param accessor 访问器, 访问或者设置假人当前配置
|
||||||
*/
|
*/
|
||||||
public record Config<T>(
|
public record Config<T>(
|
||||||
@ -45,7 +45,7 @@ public record Config<T>(
|
|||||||
String permission,
|
String permission,
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Function<String, T> converter,
|
Function<String, T> parser,
|
||||||
|
|
||||||
@UnknownNullability
|
@UnknownNullability
|
||||||
Accessor<T> accessor
|
Accessor<T> accessor
|
||||||
|
Loading…
Reference in New Issue
Block a user