StopSoundCommand.java
net.minecraft.server.commands.StopSoundCommand
信息
- 全限定名:net.minecraft.server.commands.StopSoundCommand
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/StopSoundCommand.java
- 起始行号:L19
- 职责:
TODO
字段/常量
- 无
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) @ L20
- 方法名:register
- 源码定位:L20
- 返回类型:void
- 修饰符:public static
参数:
- dispatcher: CommandDispatcher
说明:
TODO
private static int stopSound(CommandSourceStack source, Collection<ServerPlayer> targets, SoundSource soundSource, Identifier sound) @ L47
- 方法名:stopSound
- 源码定位:L47
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- targets: Collection
- soundSource: SoundSource
- sound: Identifier
说明:
TODO
代码
public class StopSoundCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
RequiredArgumentBuilder<CommandSourceStack, EntitySelector> target = Commands.argument("targets", EntityArgument.players())
.executes(c -> stopSound(c.getSource(), EntityArgument.getPlayers(c, "targets"), null, null))
.then(
Commands.literal("*")
.then(
Commands.argument("sound", IdentifierArgument.id())
.suggests(SuggestionProviders.cast(SuggestionProviders.AVAILABLE_SOUNDS))
.executes(c -> stopSound(c.getSource(), EntityArgument.getPlayers(c, "targets"), null, IdentifierArgument.getId(c, "sound")))
)
);
for (SoundSource source : SoundSource.values()) {
target.then(
Commands.literal(source.getName())
.executes(c -> stopSound(c.getSource(), EntityArgument.getPlayers(c, "targets"), source, null))
.then(
Commands.argument("sound", IdentifierArgument.id())
.suggests(SuggestionProviders.cast(SuggestionProviders.AVAILABLE_SOUNDS))
.executes(c -> stopSound(c.getSource(), EntityArgument.getPlayers(c, "targets"), source, IdentifierArgument.getId(c, "sound")))
)
);
}
dispatcher.register(Commands.literal("stopsound").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)).then(target));
}
private static int stopSound(CommandSourceStack source, Collection<ServerPlayer> targets, @Nullable SoundSource soundSource, @Nullable Identifier sound) {
ClientboundStopSoundPacket packet = new ClientboundStopSoundPacket(sound, soundSource);
for (ServerPlayer player : targets) {
player.connection.send(packet);
}
if (soundSource != null) {
if (sound != null) {
source.sendSuccess(
() -> Component.translatable("commands.stopsound.success.source.sound", Component.translationArg(sound), soundSource.getName()), true
);
} else {
source.sendSuccess(() -> Component.translatable("commands.stopsound.success.source.any", soundSource.getName()), true);
}
} else if (sound != null) {
source.sendSuccess(() -> Component.translatable("commands.stopsound.success.sourceless.sound", Component.translationArg(sound)), true);
} else {
source.sendSuccess(() -> Component.translatable("commands.stopsound.success.sourceless.any"), true);
}
return targets.size();
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.argument(), Commands.hasPermission(), Commands.literal()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
EntityArgument.getPlayers(), EntityArgument.players()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
IdentifierArgument.getId(), IdentifierArgument.id()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SuggestionProviders.cast()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable(), Component.translationArg()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
ClientboundStopSoundPacket()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
SoundSource.values()
- 引用位置: