CommandSourceStack.java
net.minecraft.commands.CommandSourceStack
信息
- 全限定名:net.minecraft.commands.CommandSourceStack
- 类型:public class
- 包:net.minecraft.commands
- 源码路径:src/main/java/net/minecraft/commands/CommandSourceStack.java
- 起始行号:L51
- 实现:SharedSuggestionProvider, ExecutionCommandSource
- 职责:
TODO
字段/常量
-
ERROR_NOT_PLAYER- 类型:
SimpleCommandExceptionType - 修饰符:
public static final - 源码定位:
L52 - 说明:
TODO
- 类型:
-
ERROR_NOT_ENTITY- 类型:
SimpleCommandExceptionType - 修饰符:
public static final - 源码定位:
L53 - 说明:
TODO
- 类型:
-
source- 类型:
CommandSource - 修饰符:
private final - 源码定位:
L54 - 说明:
TODO
- 类型:
-
worldPosition- 类型:
Vec3 - 修饰符:
private final - 源码定位:
L55 - 说明:
TODO
- 类型:
-
level- 类型:
ServerLevel - 修饰符:
private final - 源码定位:
L56 - 说明:
TODO
- 类型:
-
permissions- 类型:
PermissionSet - 修饰符:
private final - 源码定位:
L57 - 说明:
TODO
- 类型:
-
textName- 类型:
String - 修饰符:
private final - 源码定位:
L58 - 说明:
TODO
- 类型:
-
displayName- 类型:
Component - 修饰符:
private final - 源码定位:
L59 - 说明:
TODO
- 类型:
-
server- 类型:
MinecraftServer - 修饰符:
private final - 源码定位:
L60 - 说明:
TODO
- 类型:
-
silent- 类型:
boolean - 修饰符:
private final - 源码定位:
L61 - 说明:
TODO
- 类型:
-
entity- 类型:
Entity - 修饰符:
private final - 源码定位:
L62 - 说明:
TODO
- 类型:
-
resultCallback- 类型:
CommandResultCallback - 修饰符:
private final - 源码定位:
L63 - 说明:
TODO
- 类型:
-
anchor- 类型:
EntityAnchorArgument.Anchor - 修饰符:
private final - 源码定位:
L64 - 说明:
TODO
- 类型:
-
rotation- 类型:
Vec2 - 修饰符:
private final - 源码定位:
L65 - 说明:
TODO
- 类型:
-
signingContext- 类型:
CommandSigningContext - 修饰符:
private final - 源码定位:
L66 - 说明:
TODO
- 类型:
-
chatMessageChainer- 类型:
TaskChainer - 修饰符:
private final - 源码定位:
L67 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public CommandSourceStack(CommandSource source, Vec3 position, Vec2 rotation, ServerLevel level, PermissionSet permissions, String textName, Component displayName, MinecraftServer server, Entity entity) @ L69
- 构造器名:CommandSourceStack
- 源码定位:L69
- 修饰符:public
参数:
- source: CommandSource
- position: Vec3
- rotation: Vec2
- level: ServerLevel
- permissions: PermissionSet
- textName: String
- displayName: Component
- server: MinecraftServer
- entity: Entity
说明:
TODO
private CommandSourceStack(CommandSource source, Vec3 position, Vec2 rotation, ServerLevel level, PermissionSet permissions, String textName, Component displayName, MinecraftServer server, Entity entity, boolean silent, CommandResultCallback resultCallback, EntityAnchorArgument.Anchor anchor, CommandSigningContext signingContext, TaskChainer chatMessageChainer) @ L98
- 构造器名:CommandSourceStack
- 源码定位:L98
- 修饰符:private
参数:
- source: CommandSource
- position: Vec3
- rotation: Vec2
- level: ServerLevel
- permissions: PermissionSet
- textName: String
- displayName: Component
- server: MinecraftServer
- entity: Entity
- silent: boolean
- resultCallback: CommandResultCallback
- anchor: EntityAnchorArgument.Anchor
- signingContext: CommandSigningContext
- chatMessageChainer: TaskChainer
说明:
TODO
方法
下面的方法块按源码顺序生成。
public CommandSourceStack withSource(CommandSource source) @ L130
- 方法名:withSource
- 源码定位:L130
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- source: CommandSource
说明:
TODO
public CommandSourceStack withEntity(Entity entity) @ L151
- 方法名:withEntity
- 源码定位:L151
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- entity: Entity
说明:
TODO
public CommandSourceStack withPosition(Vec3 pos) @ L172
- 方法名:withPosition
- 源码定位:L172
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- pos: Vec3
说明:
TODO
public CommandSourceStack withRotation(Vec2 rotation) @ L193
- 方法名:withRotation
- 源码定位:L193
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- rotation: Vec2
说明:
TODO
public CommandSourceStack withCallback(CommandResultCallback resultCallback) @ L214
- 方法名:withCallback
- 源码定位:L214
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- resultCallback: CommandResultCallback
说明:
TODO
public CommandSourceStack withCallback(CommandResultCallback newCallback, BinaryOperator<CommandResultCallback> combiner) @ L235
- 方法名:withCallback
- 源码定位:L235
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- newCallback: CommandResultCallback
- combiner: BinaryOperator
说明:
TODO
public CommandSourceStack withSuppressedOutput() @ L240
- 方法名:withSuppressedOutput
- 源码定位:L240
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- 无
说明:
TODO
public CommandSourceStack withPermission(PermissionSet permissions) @ L261
- 方法名:withPermission
- 源码定位:L261
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- permissions: PermissionSet
说明:
TODO
public CommandSourceStack withMaximumPermission(PermissionSet newPermissions) @ L282
- 方法名:withMaximumPermission
- 源码定位:L282
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- newPermissions: PermissionSet
说明:
TODO
public CommandSourceStack withAnchor(EntityAnchorArgument.Anchor anchor) @ L286
- 方法名:withAnchor
- 源码定位:L286
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- anchor: EntityAnchorArgument.Anchor
说明:
TODO
public CommandSourceStack withLevel(ServerLevel level) @ L307
- 方法名:withLevel
- 源码定位:L307
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- level: ServerLevel
说明:
TODO
public CommandSourceStack facing(Entity entity, EntityAnchorArgument.Anchor anchor) @ L332
- 方法名:facing
- 源码定位:L332
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- entity: Entity
- anchor: EntityAnchorArgument.Anchor
说明:
TODO
public CommandSourceStack facing(Vec3 pos) @ L336
- 方法名:facing
- 源码定位:L336
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- pos: Vec3
说明:
TODO
public CommandSourceStack withSigningContext(CommandSigningContext signingContext, TaskChainer chatMessageChainer) @ L347
- 方法名:withSigningContext
- 源码定位:L347
- 返回类型:CommandSourceStack
- 修饰符:public
参数:
- signingContext: CommandSigningContext
- chatMessageChainer: TaskChainer
说明:
TODO
public Component getDisplayName() @ L368
- 方法名:getDisplayName
- 源码定位:L368
- 返回类型:Component
- 修饰符:public
参数:
- 无
说明:
TODO
public String getTextName() @ L372
- 方法名:getTextName
- 源码定位:L372
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public PermissionSet permissions() @ L376
- 方法名:permissions
- 源码定位:L376
- 返回类型:PermissionSet
- 修饰符:public
参数:
- 无
说明:
TODO
public Vec3 getPosition() @ L381
- 方法名:getPosition
- 源码定位:L381
- 返回类型:Vec3
- 修饰符:public
参数:
- 无
说明:
TODO
public ServerLevel getLevel() @ L385
- 方法名:getLevel
- 源码定位:L385
- 返回类型:ServerLevel
- 修饰符:public
参数:
- 无
说明:
TODO
public Entity getEntity() @ L389
- 方法名:getEntity
- 源码定位:L389
- 返回类型:Entity
- 修饰符:public
参数:
- 无
说明:
TODO
public Entity getEntityOrException() @ L393
- 方法名:getEntityOrException
- 源码定位:L393
- 返回类型:Entity
- 修饰符:public
参数:
- 无
说明:
TODO
public ServerPlayer getPlayerOrException() @ L401
- 方法名:getPlayerOrException
- 源码定位:L401
- 返回类型:ServerPlayer
- 修饰符:public
参数:
- 无
说明:
TODO
public ServerPlayer getPlayer() @ L409
- 方法名:getPlayer
- 源码定位:L409
- 返回类型:ServerPlayer
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean isPlayer() @ L413
- 方法名:isPlayer
- 源码定位:L413
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public Vec2 getRotation() @ L417
- 方法名:getRotation
- 源码定位:L417
- 返回类型:Vec2
- 修饰符:public
参数:
- 无
说明:
TODO
public MinecraftServer getServer() @ L421
- 方法名:getServer
- 源码定位:L421
- 返回类型:MinecraftServer
- 修饰符:public
参数:
- 无
说明:
TODO
public EntityAnchorArgument.Anchor getAnchor() @ L425
- 方法名:getAnchor
- 源码定位:L425
- 返回类型:EntityAnchorArgument.Anchor
- 修饰符:public
参数:
- 无
说明:
TODO
public CommandSigningContext getSigningContext() @ L429
- 方法名:getSigningContext
- 源码定位:L429
- 返回类型:CommandSigningContext
- 修饰符:public
参数:
- 无
说明:
TODO
public TaskChainer getChatMessageChainer() @ L433
- 方法名:getChatMessageChainer
- 源码定位:L433
- 返回类型:TaskChainer
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean shouldFilterMessageTo(ServerPlayer receiver) @ L437
- 方法名:shouldFilterMessageTo
- 源码定位:L437
- 返回类型:boolean
- 修饰符:public
参数:
- receiver: ServerPlayer
说明:
TODO
public void sendChatMessage(OutgoingChatMessage message, boolean filtered, ChatType.Bound chatType) @ L442
- 方法名:sendChatMessage
- 源码定位:L442
- 返回类型:void
- 修饰符:public
参数:
- message: OutgoingChatMessage
- filtered: boolean
- chatType: ChatType.Bound
说明:
TODO
public void sendSystemMessage(Component message) @ L453
- 方法名:sendSystemMessage
- 源码定位:L453
- 返回类型:void
- 修饰符:public
参数:
- message: Component
说明:
TODO
public void sendSuccess(Supplier<Component> messageSupplier, boolean broadcast) @ L464
- 方法名:sendSuccess
- 源码定位:L464
- 返回类型:void
- 修饰符:public
参数:
- messageSupplier: Supplier
- broadcast: boolean
说明:
TODO
private void broadcastToAdmins(Component message) @ L479
- 方法名:broadcastToAdmins
- 源码定位:L479
- 返回类型:void
- 修饰符:private
参数:
- message: Component
说明:
TODO
public void sendFailure(Component message) @ L495
- 方法名:sendFailure
- 源码定位:L495
- 返回类型:void
- 修饰符:public
参数:
- message: Component
说明:
TODO
public CommandResultCallback callback() @ L501
- 方法名:callback
- 源码定位:L501
- 返回类型:CommandResultCallback
- 修饰符:public
参数:
- 无
说明:
TODO
public Collection<String> getOnlinePlayerNames() @ L506
- 方法名:getOnlinePlayerNames
- 源码定位:L506
- 返回类型:Collection
- 修饰符:public
参数:
- 无
说明:
TODO
public Collection<String> getAllTeams() @ L511
- 方法名:getAllTeams
- 源码定位:L511
- 返回类型:Collection
- 修饰符:public
参数:
- 无
说明:
TODO
public Stream<Identifier> getAvailableSounds() @ L516
- 方法名:getAvailableSounds
- 源码定位:L516
- 返回类型:Stream
- 修饰符:public
参数:
- 无
说明:
TODO
public CompletableFuture<Suggestions> customSuggestion(CommandContext<?> context) @ L521
- 方法名:customSuggestion
- 源码定位:L521
- 返回类型:CompletableFuture
- 修饰符:public
参数:
- context: CommandContext<?>
说明:
TODO
public CompletableFuture<Suggestions> suggestRegistryElements(ResourceKey<?extends Registry<?>> key, SharedSuggestionProvider.ElementSuggestionType elements, SuggestionsBuilder builder, CommandContext<?> context) @ L526
- 方法名:suggestRegistryElements
- 源码定位:L526
- 返回类型:CompletableFuture
- 修饰符:public
参数:
- key: ResourceKey>
- elements: SharedSuggestionProvider.ElementSuggestionType
- builder: SuggestionsBuilder
- context: CommandContext<?>
说明:
TODO
private Optional<?extends HolderLookup<?>> getLookup(ResourceKey<?extends Registry<?>> key) @ L543
- 方法名:getLookup
- 源码定位:L543
- 返回类型:Optional>
- 修饰符:private
参数:
- key: ResourceKey>
说明:
TODO
public Set<ResourceKey<Level>> levels() @ L548
- 方法名:levels
- 源码定位:L548
- 返回类型:Set<ResourceKey
> - 修饰符:public
参数:
- 无
说明:
TODO
public RegistryAccess registryAccess() @ L553
- 方法名:registryAccess
- 源码定位:L553
- 返回类型:RegistryAccess
- 修饰符:public
参数:
- 无
说明:
TODO
public FeatureFlagSet enabledFeatures() @ L558
- 方法名:enabledFeatures
- 源码定位:L558
- 返回类型:FeatureFlagSet
- 修饰符:public
参数:
- 无
说明:
TODO
public CommandDispatcher<CommandSourceStack> dispatcher() @ L563
- 方法名:dispatcher
- 源码定位:L563
- 返回类型:CommandDispatcher
- 修饰符:public
参数:
- 无
说明:
TODO
public void handleError(CommandExceptionType type, Message message, boolean forked, TraceCallbacks tracer) @ L568
- 方法名:handleError
- 源码定位:L568
- 返回类型:void
- 修饰符:public
参数:
- type: CommandExceptionType
- message: Message
- forked: boolean
- tracer: TraceCallbacks
说明:
TODO
public boolean isSilent() @ L579
- 方法名:isSilent
- 源码定位:L579
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public class CommandSourceStack implements SharedSuggestionProvider, ExecutionCommandSource<CommandSourceStack> {
public static final SimpleCommandExceptionType ERROR_NOT_PLAYER = new SimpleCommandExceptionType(Component.translatable("permissions.requires.player"));
public static final SimpleCommandExceptionType ERROR_NOT_ENTITY = new SimpleCommandExceptionType(Component.translatable("permissions.requires.entity"));
private final CommandSource source;
private final Vec3 worldPosition;
private final ServerLevel level;
private final PermissionSet permissions;
private final String textName;
private final Component displayName;
private final MinecraftServer server;
private final boolean silent;
private final @Nullable Entity entity;
private final CommandResultCallback resultCallback;
private final EntityAnchorArgument.Anchor anchor;
private final Vec2 rotation;
private final CommandSigningContext signingContext;
private final TaskChainer chatMessageChainer;
public CommandSourceStack(
CommandSource source,
Vec3 position,
Vec2 rotation,
ServerLevel level,
PermissionSet permissions,
String textName,
Component displayName,
MinecraftServer server,
@Nullable Entity entity
) {
this(
source,
position,
rotation,
level,
permissions,
textName,
displayName,
server,
entity,
false,
CommandResultCallback.EMPTY,
EntityAnchorArgument.Anchor.FEET,
CommandSigningContext.ANONYMOUS,
TaskChainer.immediate(server)
);
}
private CommandSourceStack(
CommandSource source,
Vec3 position,
Vec2 rotation,
ServerLevel level,
PermissionSet permissions,
String textName,
Component displayName,
MinecraftServer server,
@Nullable Entity entity,
boolean silent,
CommandResultCallback resultCallback,
EntityAnchorArgument.Anchor anchor,
CommandSigningContext signingContext,
TaskChainer chatMessageChainer
) {
this.source = source;
this.worldPosition = position;
this.level = level;
this.silent = silent;
this.entity = entity;
this.permissions = permissions;
this.textName = textName;
this.displayName = displayName;
this.server = server;
this.resultCallback = resultCallback;
this.anchor = anchor;
this.rotation = rotation;
this.signingContext = signingContext;
this.chatMessageChainer = chatMessageChainer;
}
public CommandSourceStack withSource(CommandSource source) {
return this.source == source
? this
: new CommandSourceStack(
source,
this.worldPosition,
this.rotation,
this.level,
this.permissions,
this.textName,
this.displayName,
this.server,
this.entity,
this.silent,
this.resultCallback,
this.anchor,
this.signingContext,
this.chatMessageChainer
);
}
public CommandSourceStack withEntity(Entity entity) {
return this.entity == entity
? this
: new CommandSourceStack(
this.source,
this.worldPosition,
this.rotation,
this.level,
this.permissions,
entity.getPlainTextName(),
entity.getDisplayName(),
this.server,
entity,
this.silent,
this.resultCallback,
this.anchor,
this.signingContext,
this.chatMessageChainer
);
}
public CommandSourceStack withPosition(Vec3 pos) {
return this.worldPosition.equals(pos)
? this
: new CommandSourceStack(
this.source,
pos,
this.rotation,
this.level,
this.permissions,
this.textName,
this.displayName,
this.server,
this.entity,
this.silent,
this.resultCallback,
this.anchor,
this.signingContext,
this.chatMessageChainer
);
}
public CommandSourceStack withRotation(Vec2 rotation) {
return this.rotation.equals(rotation)
? this
: new CommandSourceStack(
this.source,
this.worldPosition,
rotation,
this.level,
this.permissions,
this.textName,
this.displayName,
this.server,
this.entity,
this.silent,
this.resultCallback,
this.anchor,
this.signingContext,
this.chatMessageChainer
);
}
public CommandSourceStack withCallback(CommandResultCallback resultCallback) {
return Objects.equals(this.resultCallback, resultCallback)
? this
: new CommandSourceStack(
this.source,
this.worldPosition,
this.rotation,
this.level,
this.permissions,
this.textName,
this.displayName,
this.server,
this.entity,
this.silent,
resultCallback,
this.anchor,
this.signingContext,
this.chatMessageChainer
);
}
public CommandSourceStack withCallback(CommandResultCallback newCallback, BinaryOperator<CommandResultCallback> combiner) {
CommandResultCallback newCompositeCallback = combiner.apply(this.resultCallback, newCallback);
return this.withCallback(newCompositeCallback);
}
public CommandSourceStack withSuppressedOutput() {
return !this.silent && !this.source.alwaysAccepts()
? new CommandSourceStack(
this.source,
this.worldPosition,
this.rotation,
this.level,
this.permissions,
this.textName,
this.displayName,
this.server,
this.entity,
true,
this.resultCallback,
this.anchor,
this.signingContext,
this.chatMessageChainer
)
: this;
}
public CommandSourceStack withPermission(PermissionSet permissions) {
return permissions == this.permissions
? this
: new CommandSourceStack(
this.source,
this.worldPosition,
this.rotation,
this.level,
permissions,
this.textName,
this.displayName,
this.server,
this.entity,
this.silent,
this.resultCallback,
this.anchor,
this.signingContext,
this.chatMessageChainer
);
}
public CommandSourceStack withMaximumPermission(PermissionSet newPermissions) {
return this.withPermission(this.permissions.union(newPermissions));
}
public CommandSourceStack withAnchor(EntityAnchorArgument.Anchor anchor) {
return anchor == this.anchor
? this
: new CommandSourceStack(
this.source,
this.worldPosition,
this.rotation,
this.level,
this.permissions,
this.textName,
this.displayName,
this.server,
this.entity,
this.silent,
this.resultCallback,
anchor,
this.signingContext,
this.chatMessageChainer
);
}
public CommandSourceStack withLevel(ServerLevel level) {
if (level == this.level) {
return this;
} else {
double scale = DimensionType.getTeleportationScale(this.level.dimensionType(), level.dimensionType());
Vec3 pos = new Vec3(this.worldPosition.x * scale, this.worldPosition.y, this.worldPosition.z * scale);
return new CommandSourceStack(
this.source,
pos,
this.rotation,
level,
this.permissions,
this.textName,
this.displayName,
this.server,
this.entity,
this.silent,
this.resultCallback,
this.anchor,
this.signingContext,
this.chatMessageChainer
);
}
}
public CommandSourceStack facing(Entity entity, EntityAnchorArgument.Anchor anchor) {
return this.facing(anchor.apply(entity));
}
public CommandSourceStack facing(Vec3 pos) {
Vec3 from = this.anchor.apply(this);
double xd = pos.x - from.x;
double yd = pos.y - from.y;
double zd = pos.z - from.z;
double sd = Math.sqrt(xd * xd + zd * zd);
float xRot = Mth.wrapDegrees((float)(-(Mth.atan2(yd, sd) * 180.0F / (float)Math.PI)));
float yRot = Mth.wrapDegrees((float)(Mth.atan2(zd, xd) * 180.0F / (float)Math.PI) - 90.0F);
return this.withRotation(new Vec2(xRot, yRot));
}
public CommandSourceStack withSigningContext(CommandSigningContext signingContext, TaskChainer chatMessageChainer) {
return signingContext == this.signingContext && chatMessageChainer == this.chatMessageChainer
? this
: new CommandSourceStack(
this.source,
this.worldPosition,
this.rotation,
this.level,
this.permissions,
this.textName,
this.displayName,
this.server,
this.entity,
this.silent,
this.resultCallback,
this.anchor,
signingContext,
chatMessageChainer
);
}
public Component getDisplayName() {
return this.displayName;
}
public String getTextName() {
return this.textName;
}
@Override
public PermissionSet permissions() {
return this.permissions;
}
public Vec3 getPosition() {
return this.worldPosition;
}
public ServerLevel getLevel() {
return this.level;
}
public @Nullable Entity getEntity() {
return this.entity;
}
public Entity getEntityOrException() throws CommandSyntaxException {
if (this.entity == null) {
throw ERROR_NOT_ENTITY.create();
} else {
return this.entity;
}
}
public ServerPlayer getPlayerOrException() throws CommandSyntaxException {
if (this.entity instanceof ServerPlayer player) {
return player;
} else {
throw ERROR_NOT_PLAYER.create();
}
}
public @Nullable ServerPlayer getPlayer() {
return this.entity instanceof ServerPlayer player ? player : null;
}
public boolean isPlayer() {
return this.entity instanceof ServerPlayer;
}
public Vec2 getRotation() {
return this.rotation;
}
public MinecraftServer getServer() {
return this.server;
}
public EntityAnchorArgument.Anchor getAnchor() {
return this.anchor;
}
public CommandSigningContext getSigningContext() {
return this.signingContext;
}
public TaskChainer getChatMessageChainer() {
return this.chatMessageChainer;
}
public boolean shouldFilterMessageTo(ServerPlayer receiver) {
ServerPlayer player = this.getPlayer();
return receiver == player ? false : player != null && player.isTextFilteringEnabled() || receiver.isTextFilteringEnabled();
}
public void sendChatMessage(OutgoingChatMessage message, boolean filtered, ChatType.Bound chatType) {
if (!this.silent) {
ServerPlayer player = this.getPlayer();
if (player != null) {
player.sendChatMessage(message, filtered, chatType);
} else {
this.source.sendSystemMessage(chatType.decorate(message.content()));
}
}
}
public void sendSystemMessage(Component message) {
if (!this.silent) {
ServerPlayer player = this.getPlayer();
if (player != null) {
player.sendSystemMessage(message);
} else {
this.source.sendSystemMessage(message);
}
}
}
public void sendSuccess(Supplier<Component> messageSupplier, boolean broadcast) {
boolean shouldSendSystemMessage = this.source.acceptsSuccess() && !this.silent;
boolean shouldBroadcast = broadcast && this.source.shouldInformAdmins() && !this.silent;
if (shouldSendSystemMessage || shouldBroadcast) {
Component message = messageSupplier.get();
if (shouldSendSystemMessage) {
this.source.sendSystemMessage(message);
}
if (shouldBroadcast) {
this.broadcastToAdmins(message);
}
}
}
private void broadcastToAdmins(Component message) {
Component broadcast = Component.translatable("chat.type.admin", this.getDisplayName(), message).withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC);
GameRules gameRules = this.level.getGameRules();
if (gameRules.get(GameRules.SEND_COMMAND_FEEDBACK)) {
for (ServerPlayer player : this.server.getPlayerList().getPlayers()) {
if (player.commandSource() != this.source && this.server.getPlayerList().isOp(player.nameAndId())) {
player.sendSystemMessage(broadcast);
}
}
}
if (this.source != this.server && gameRules.get(GameRules.LOG_ADMIN_COMMANDS)) {
this.server.sendSystemMessage(broadcast);
}
}
public void sendFailure(Component message) {
if (this.source.acceptsFailure() && !this.silent) {
this.source.sendSystemMessage(Component.empty().append(message).withStyle(ChatFormatting.RED));
}
}
@Override
public CommandResultCallback callback() {
return this.resultCallback;
}
@Override
public Collection<String> getOnlinePlayerNames() {
return Lists.newArrayList(this.server.getPlayerNames());
}
@Override
public Collection<String> getAllTeams() {
return this.server.getScoreboard().getTeamNames();
}
@Override
public Stream<Identifier> getAvailableSounds() {
return BuiltInRegistries.SOUND_EVENT.stream().map(SoundEvent::location);
}
@Override
public CompletableFuture<Suggestions> customSuggestion(CommandContext<?> context) {
return Suggestions.empty();
}
@Override
public CompletableFuture<Suggestions> suggestRegistryElements(
ResourceKey<? extends Registry<?>> key, SharedSuggestionProvider.ElementSuggestionType elements, SuggestionsBuilder builder, CommandContext<?> context
) {
if (key == Registries.RECIPE) {
return SharedSuggestionProvider.suggestResource(this.server.getRecipeManager().getRecipes().stream().map(e -> e.id().identifier()), builder);
} else if (key == Registries.ADVANCEMENT) {
Collection<AdvancementHolder> advancements = this.server.getAdvancements().getAllAdvancements();
return SharedSuggestionProvider.suggestResource(advancements.stream().map(AdvancementHolder::id), builder);
} else {
return this.getLookup(key).map(registry -> {
this.suggestRegistryElements((HolderLookup<?>)registry, elements, builder);
return builder.buildFuture();
}).orElseGet(Suggestions::empty);
}
}
private Optional<? extends HolderLookup<?>> getLookup(ResourceKey<? extends Registry<?>> key) {
Optional<? extends Registry<?>> lookup = this.registryAccess().lookup(key);
return lookup.isPresent() ? lookup : this.server.reloadableRegistries().lookup().lookup(key);
}
@Override
public Set<ResourceKey<Level>> levels() {
return this.server.levelKeys();
}
@Override
public RegistryAccess registryAccess() {
return this.server.registryAccess();
}
@Override
public FeatureFlagSet enabledFeatures() {
return this.level.enabledFeatures();
}
@Override
public CommandDispatcher<CommandSourceStack> dispatcher() {
return this.getServer().getFunctions().getDispatcher();
}
@Override
public void handleError(CommandExceptionType type, Message message, boolean forked, @Nullable TraceCallbacks tracer) {
if (tracer != null) {
tracer.onError(message.getString());
}
if (!forked) {
this.sendFailure(ComponentUtils.fromMessage(message));
}
}
@Override
public boolean isSilent() {
return this.silent;
}
}引用的其他类
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
实现
- 引用位置:
-
- 引用位置:
参数/实现/方法调用 - 关联成员:
SharedSuggestionProvider.suggestResource()
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/方法调用/返回值 - 关联成员:
Component.empty(), Component.translatable()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ComponentUtils.fromMessage()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Mth.atan2(), Mth.wrapDegrees()
- 引用位置:
-
- 引用位置:
参数/字段/方法调用/返回值 - 关联成员:
TaskChainer.immediate()
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
DimensionType.getTeleportationScale()
- 引用位置:
-
- 引用位置:
参数/字段/构造调用/返回值 - 关联成员:
Vec2()
- 引用位置:
-
- 引用位置:
参数/字段/构造调用/返回值 - 关联成员:
Vec3()
- 引用位置: