ObjectiveArgument.java
net.minecraft.commands.arguments.ObjectiveArgument
信息
- 全限定名:net.minecraft.commands.arguments.ObjectiveArgument
- 类型:public class
- 包:net.minecraft.commands.arguments
- 源码路径:src/main/java/net/minecraft/commands/arguments/ObjectiveArgument.java
- 起始行号:L19
- 实现:ArgumentType
- 职责:
TODO
字段/常量
-
EXAMPLES- 类型:
Collection<String> - 修饰符:
private static final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
ERROR_OBJECTIVE_NOT_FOUND- 类型:
DynamicCommandExceptionType - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
ERROR_OBJECTIVE_READ_ONLY- 类型:
DynamicCommandExceptionType - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static ObjectiveArgument objective() @ L28
- 方法名:objective
- 源码定位:L28
- 返回类型:ObjectiveArgument
- 修饰符:public static
参数:
- 无
说明:
TODO
public static Objective getObjective(CommandContext<CommandSourceStack> context, String name) @ L32
- 方法名:getObjective
- 源码定位:L32
- 返回类型:Objective
- 修饰符:public static
参数:
- context: CommandContext
- name: String
说明:
TODO
public static Objective getWritableObjective(CommandContext<CommandSourceStack> context, String name) @ L43
- 方法名:getWritableObjective
- 源码定位:L43
- 返回类型:Objective
- 修饰符:public static
参数:
- context: CommandContext
- name: String
说明:
TODO
public String parse(StringReader reader) @ L52
- 方法名:parse
- 源码定位:L52
- 返回类型:String
- 修饰符:public
参数:
- reader: StringReader
说明:
TODO
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) @ L56
- 方法名:listSuggestions
- 源码定位:L56
- 返回类型:
CompletableFuture - 修饰符:public
参数:
- context: CommandContext
- builder: SuggestionsBuilder
说明:
TODO
public Collection<String> getExamples() @ L66
- 方法名:getExamples
- 源码定位:L66
- 返回类型:Collection
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public class ObjectiveArgument implements ArgumentType<String> {
private static final Collection<String> EXAMPLES = Arrays.asList("foo", "*", "012");
private static final DynamicCommandExceptionType ERROR_OBJECTIVE_NOT_FOUND = new DynamicCommandExceptionType(
name -> Component.translatableEscape("arguments.objective.notFound", name)
);
private static final DynamicCommandExceptionType ERROR_OBJECTIVE_READ_ONLY = new DynamicCommandExceptionType(
name -> Component.translatableEscape("arguments.objective.readonly", name)
);
public static ObjectiveArgument objective() {
return new ObjectiveArgument();
}
public static Objective getObjective(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
String id = context.getArgument(name, String.class);
Scoreboard scoreboard = context.getSource().getServer().getScoreboard();
Objective objective = scoreboard.getObjective(id);
if (objective == null) {
throw ERROR_OBJECTIVE_NOT_FOUND.create(id);
} else {
return objective;
}
}
public static Objective getWritableObjective(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
Objective objective = getObjective(context, name);
if (objective.getCriteria().isReadOnly()) {
throw ERROR_OBJECTIVE_READ_ONLY.create(objective.getName());
} else {
return objective;
}
}
public String parse(StringReader reader) throws CommandSyntaxException {
return reader.readUnquotedString();
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
S rawSource = context.getSource();
if (rawSource instanceof CommandSourceStack source) {
return SharedSuggestionProvider.suggest(source.getServer().getScoreboard().getObjectiveNames(), builder);
} else {
return rawSource instanceof SharedSuggestionProvider source ? source.customSuggestion(context) : Suggestions.empty();
}
}
@Override
public Collection<String> getExamples() {
return EXAMPLES;
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SharedSuggestionProvider.suggest()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatableEscape()
- 引用位置:
-
- 引用位置:
返回值
- 引用位置: