TitleCommand.java
net.minecraft.server.commands.TitleCommand
信息
- 全限定名:net.minecraft.server.commands.TitleCommand
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/TitleCommand.java
- 起始行号:L25
- 职责:
TODO
字段/常量
- 无
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) @ L26
- 方法名:register
- 源码定位:L26
- 返回类型:void
- 修饰符:public static
参数:
- dispatcher: CommandDispatcher
- context: CommandBuildContext
说明:
TODO
private static int clearTitle(CommandSourceStack source, Collection<ServerPlayer> targets) @ L104
- 方法名:clearTitle
- 源码定位:L104
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- targets: Collection
说明:
TODO
private static int resetTitle(CommandSourceStack source, Collection<ServerPlayer> targets) @ L120
- 方法名:resetTitle
- 源码定位:L120
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- targets: Collection
说明:
TODO
private static int showTitle(CommandSourceStack source, Collection<ServerPlayer> targets, Component title, String type, Function<Component,Packet<?>> factory) @ L136
- 方法名:showTitle
- 源码定位:L136
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- targets: Collection
- title: Component
- type: String
- factory: Function<Component,Packet<?>>
说明:
TODO
private static int setTimes(CommandSourceStack source, Collection<ServerPlayer> targets, int fadeIn, int stay, int fadeOut) @ L153
- 方法名:setTimes
- 源码定位:L153
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- targets: Collection
- fadeIn: int
- stay: int
- fadeOut: int
说明:
TODO
代码
public class TitleCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) {
dispatcher.register(
Commands.literal("title")
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
.then(
Commands.argument("targets", EntityArgument.players())
.then(Commands.literal("clear").executes(c -> clearTitle(c.getSource(), EntityArgument.getPlayers(c, "targets"))))
.then(Commands.literal("reset").executes(c -> resetTitle(c.getSource(), EntityArgument.getPlayers(c, "targets"))))
.then(
Commands.literal("title")
.then(
Commands.argument("title", ComponentArgument.textComponent(context))
.executes(
c -> showTitle(
c.getSource(),
EntityArgument.getPlayers(c, "targets"),
ComponentArgument.getRawComponent(c, "title"),
"title",
ClientboundSetTitleTextPacket::new
)
)
)
)
.then(
Commands.literal("subtitle")
.then(
Commands.argument("title", ComponentArgument.textComponent(context))
.executes(
c -> showTitle(
c.getSource(),
EntityArgument.getPlayers(c, "targets"),
ComponentArgument.getRawComponent(c, "title"),
"subtitle",
ClientboundSetSubtitleTextPacket::new
)
)
)
)
.then(
Commands.literal("actionbar")
.then(
Commands.argument("title", ComponentArgument.textComponent(context))
.executes(
c -> showTitle(
c.getSource(),
EntityArgument.getPlayers(c, "targets"),
ComponentArgument.getRawComponent(c, "title"),
"actionbar",
ClientboundSetActionBarTextPacket::new
)
)
)
)
.then(
Commands.literal("times")
.then(
Commands.argument("fadeIn", TimeArgument.time())
.then(
Commands.argument("stay", TimeArgument.time())
.then(
Commands.argument("fadeOut", TimeArgument.time())
.executes(
c -> setTimes(
c.getSource(),
EntityArgument.getPlayers(c, "targets"),
IntegerArgumentType.getInteger(c, "fadeIn"),
IntegerArgumentType.getInteger(c, "stay"),
IntegerArgumentType.getInteger(c, "fadeOut")
)
)
)
)
)
)
)
);
}
private static int clearTitle(CommandSourceStack source, Collection<ServerPlayer> targets) {
ClientboundClearTitlesPacket packet = new ClientboundClearTitlesPacket(false);
for (ServerPlayer player : targets) {
player.connection.send(packet);
}
if (targets.size() == 1) {
source.sendSuccess(() -> Component.translatable("commands.title.cleared.single", targets.iterator().next().getDisplayName()), true);
} else {
source.sendSuccess(() -> Component.translatable("commands.title.cleared.multiple", targets.size()), true);
}
return targets.size();
}
private static int resetTitle(CommandSourceStack source, Collection<ServerPlayer> targets) {
ClientboundClearTitlesPacket packet = new ClientboundClearTitlesPacket(true);
for (ServerPlayer player : targets) {
player.connection.send(packet);
}
if (targets.size() == 1) {
source.sendSuccess(() -> Component.translatable("commands.title.reset.single", targets.iterator().next().getDisplayName()), true);
} else {
source.sendSuccess(() -> Component.translatable("commands.title.reset.multiple", targets.size()), true);
}
return targets.size();
}
private static int showTitle(
CommandSourceStack source, Collection<ServerPlayer> targets, Component title, String type, Function<Component, Packet<?>> factory
) throws CommandSyntaxException {
for (ServerPlayer player : targets) {
player.connection
.send(factory.apply(ComponentUtils.resolve(ResolutionContext.builder().withSource(source).withEntityOverride(player).build(), title)));
}
if (targets.size() == 1) {
source.sendSuccess(() -> Component.translatable("commands.title.show." + type + ".single", targets.iterator().next().getDisplayName()), true);
} else {
source.sendSuccess(() -> Component.translatable("commands.title.show." + type + ".multiple", targets.size()), true);
}
return targets.size();
}
private static int setTimes(CommandSourceStack source, Collection<ServerPlayer> targets, int fadeIn, int stay, int fadeOut) {
ClientboundSetTitlesAnimationPacket packet = new ClientboundSetTitlesAnimationPacket(fadeIn, stay, fadeOut);
for (ServerPlayer player : targets) {
player.connection.send(packet);
}
if (targets.size() == 1) {
source.sendSuccess(() -> Component.translatable("commands.title.times.single", targets.iterator().next().getDisplayName()), true);
} else {
source.sendSuccess(() -> Component.translatable("commands.title.times.multiple", targets.size()), true);
}
return targets.size();
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.argument(), Commands.hasPermission(), Commands.literal()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ComponentArgument.getRawComponent(), ComponentArgument.textComponent()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
EntityArgument.getPlayers(), EntityArgument.players()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
TimeArgument.time()
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ComponentUtils.resolve()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ResolutionContext.builder()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
ClientboundClearTitlesPacket()
- 引用位置:
-
ClientboundSetTitlesAnimationPacket
- 引用位置:
构造调用 - 关联成员:
ClientboundSetTitlesAnimationPacket()
- 引用位置:
-
- 引用位置:
参数
- 引用位置: