ServerFunctionManager.java
net.minecraft.server.ServerFunctionManager
信息
- 全限定名:net.minecraft.server.ServerFunctionManager
- 类型:public class
- 包:net.minecraft.server
- 源码路径:src/main/java/net/minecraft/server/ServerFunctionManager.java
- 起始行号:L22
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
TICK_FUNCTION_TAG- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
LOAD_FUNCTION_TAG- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
server- 类型:
MinecraftServer - 修饰符:
private final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
ticking- 类型:
List<CommandFunction<CommandSourceStack>> - 修饰符:
private - 源码定位:
L27 - 说明:
TODO
- 类型:
-
postReload- 类型:
boolean - 修饰符:
private - 源码定位:
L28 - 说明:
TODO
- 类型:
-
library- 类型:
ServerFunctionLibrary - 修饰符:
private - 源码定位:
L29 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public ServerFunctionManager(MinecraftServer server, ServerFunctionLibrary library) @ L31
- 构造器名:ServerFunctionManager
- 源码定位:L31
- 修饰符:public
参数:
- server: MinecraftServer
- library: ServerFunctionLibrary
说明:
TODO
方法
下面的方法块按源码顺序生成。
public CommandDispatcher<CommandSourceStack> getDispatcher() @ L37
- 方法名:getDispatcher
- 源码定位:L37
- 返回类型:CommandDispatcher
- 修饰符:public
参数:
- 无
说明:
TODO
public void tick() @ L41
- 方法名:tick
- 源码定位:L41
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
private void executeTagFunctions(Collection<CommandFunction<CommandSourceStack>> functions, Identifier loadFunctionTag) @ L53
- 方法名:executeTagFunctions
- 源码定位:L53
- 返回类型:void
- 修饰符:private
参数:
- functions: Collection<CommandFunction
> - loadFunctionTag: Identifier
说明:
TODO
public void execute(CommandFunction<CommandSourceStack> functionIn, CommandSourceStack sender) @ L63
- 方法名:execute
- 源码定位:L63
- 返回类型:void
- 修饰符:public
参数:
- functionIn: CommandFunction
- sender: CommandSourceStack
说明:
TODO
public void replaceLibrary(ServerFunctionLibrary library) @ L80
- 方法名:replaceLibrary
- 源码定位:L80
- 返回类型:void
- 修饰符:public
参数:
- library: ServerFunctionLibrary
说明:
TODO
private void postReload(ServerFunctionLibrary library) @ L85
- 方法名:postReload
- 源码定位:L85
- 返回类型:void
- 修饰符:private
参数:
- library: ServerFunctionLibrary
说明:
TODO
public CommandSourceStack getGameLoopSender() @ L90
- 方法名:getGameLoopSender
- 源码定位:L90
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- 无
说明:
TODO
public Optional<CommandFunction<CommandSourceStack>> get(Identifier id) @ L94
- 方法名:get
- 源码定位:L94
- 返回类型:Optional<CommandFunction
> - 修饰符:public
参数:
- id: Identifier
说明:
TODO
public List<CommandFunction<CommandSourceStack>> getTag(Identifier id) @ L98
- 方法名:getTag
- 源码定位:L98
- 返回类型:List<CommandFunction
> - 修饰符:public
参数:
- id: Identifier
说明:
TODO
public Iterable<Identifier> getFunctionNames() @ L102
- 方法名:getFunctionNames
- 源码定位:L102
- 返回类型:Iterable
- 修饰符:public
参数:
- 无
说明:
TODO
public Iterable<Identifier> getTagNames() @ L106
- 方法名:getTagNames
- 源码定位:L106
- 返回类型:Iterable
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public class ServerFunctionManager {
private static final Logger LOGGER = LogUtils.getLogger();
private static final Identifier TICK_FUNCTION_TAG = Identifier.withDefaultNamespace("tick");
private static final Identifier LOAD_FUNCTION_TAG = Identifier.withDefaultNamespace("load");
private final MinecraftServer server;
private List<CommandFunction<CommandSourceStack>> ticking = ImmutableList.of();
private boolean postReload;
private ServerFunctionLibrary library;
public ServerFunctionManager(MinecraftServer server, ServerFunctionLibrary library) {
this.server = server;
this.library = library;
this.postReload(library);
}
public CommandDispatcher<CommandSourceStack> getDispatcher() {
return this.server.getCommands().getDispatcher();
}
public void tick() {
if (this.server.tickRateManager().runsNormally()) {
if (this.postReload) {
this.postReload = false;
Collection<CommandFunction<CommandSourceStack>> functions = this.library.getTag(LOAD_FUNCTION_TAG);
this.executeTagFunctions(functions, LOAD_FUNCTION_TAG);
}
this.executeTagFunctions(this.ticking, TICK_FUNCTION_TAG);
}
}
private void executeTagFunctions(Collection<CommandFunction<CommandSourceStack>> functions, Identifier loadFunctionTag) {
Profiler.get().push(loadFunctionTag::toString);
for (CommandFunction<CommandSourceStack> function : functions) {
this.execute(function, this.getGameLoopSender());
}
Profiler.get().pop();
}
public void execute(CommandFunction<CommandSourceStack> functionIn, CommandSourceStack sender) {
ProfilerFiller profiler = Profiler.get();
profiler.push(() -> "function " + functionIn.id());
try {
InstantiatedFunction<CommandSourceStack> function = functionIn.instantiate(null, this.getDispatcher());
Commands.executeCommandInContext(
sender, context -> ExecutionContext.queueInitialFunctionCall(context, function, sender, CommandResultCallback.EMPTY)
);
} catch (FunctionInstantiationException var9) {
} catch (Exception var10) {
LOGGER.warn("Failed to execute function {}", functionIn.id(), var10);
} finally {
profiler.pop();
}
}
public void replaceLibrary(ServerFunctionLibrary library) {
this.library = library;
this.postReload(library);
}
private void postReload(ServerFunctionLibrary library) {
this.ticking = List.copyOf(library.getTag(TICK_FUNCTION_TAG));
this.postReload = true;
}
public CommandSourceStack getGameLoopSender() {
return this.server.createCommandSourceStack().withPermission(LevelBasedPermissionSet.GAMEMASTER).withSuppressedOutput();
}
public Optional<CommandFunction<CommandSourceStack>> get(Identifier id) {
return this.library.getFunction(id);
}
public List<CommandFunction<CommandSourceStack>> getTag(Identifier id) {
return this.library.getTag(id);
}
public Iterable<Identifier> getFunctionNames() {
return this.library.getFunctions().keySet();
}
public Iterable<Identifier> getTagNames() {
return this.library.getAvailableTags();
}
}引用的其他类
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.executeCommandInContext()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ExecutionContext.queueInitialFunctionCall()
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数/字段/方法调用/返回值 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Profiler.get()
- 引用位置: