LoggedChatMessage.java

net.minecraft.client.multiplayer.chat.LoggedChatMessage

信息

  • 全限定名:net.minecraft.client.multiplayer.chat.LoggedChatMessage
  • 类型:public interface
  • 包:net.minecraft.client.multiplayer.chat
  • 源码路径:src/main/java/net/minecraft/client/multiplayer/chat/LoggedChatMessage.java
  • 起始行号:L22
  • 继承:LoggedChatEvent
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

  • net.minecraft.client.multiplayer.chat.LoggedChatMessage.Player

    • 类型: record
    • 修饰符: public
    • 源码定位: L40
    • 说明:

      TODO

  • net.minecraft.client.multiplayer.chat.LoggedChatMessage.System

    • 类型: record
    • 修饰符: public
    • 源码定位: L94
    • 说明:

      TODO

构造器

方法

下面的方法块按源码顺序生成。

static LoggedChatMessage.Player player(GameProfile profile, PlayerChatMessage message, ChatTrustLevel trustLevel) @ L23

  • 方法名:player
  • 源码定位:L23
  • 返回类型:LoggedChatMessage.Player
  • 修饰符:static

参数:

  • profile: GameProfile
  • message: PlayerChatMessage
  • trustLevel: ChatTrustLevel

说明:

TODO

static LoggedChatMessage.System system(Component message, Instant timeStamp) @ L27

  • 方法名:system
  • 源码定位:L27
  • 返回类型:LoggedChatMessage.System
  • 修饰符:static

参数:

  • message: Component
  • timeStamp: Instant

说明:

TODO

Component toContentComponent() @ L31

  • 方法名:toContentComponent
  • 源码定位:L31
  • 返回类型:Component
  • 修饰符:package-private

参数:

说明:

TODO

default Component toNarrationComponent() @ L33

  • 方法名:toNarrationComponent
  • 源码定位:L33
  • 返回类型:Component
  • 修饰符:default

参数:

说明:

TODO

boolean canReport(UUID reportedPlayerId) @ L37

  • 方法名:canReport
  • 源码定位:L37
  • 返回类型:boolean
  • 修饰符:package-private

参数:

  • reportedPlayerId: UUID

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public interface LoggedChatMessage extends LoggedChatEvent {
    static LoggedChatMessage.Player player(GameProfile profile, PlayerChatMessage message, ChatTrustLevel trustLevel) {
        return new LoggedChatMessage.Player(profile, message, trustLevel);
    }
 
    static LoggedChatMessage.System system(Component message, Instant timeStamp) {
        return new LoggedChatMessage.System(message, timeStamp);
    }
 
    Component toContentComponent();
 
    default Component toNarrationComponent() {
        return this.toContentComponent();
    }
 
    boolean canReport(UUID reportedPlayerId);
 
    @OnlyIn(Dist.CLIENT)
    public record Player(GameProfile profile, PlayerChatMessage message, ChatTrustLevel trustLevel) implements LoggedChatMessage {
        public static final MapCodec<LoggedChatMessage.Player> CODEC = RecordCodecBuilder.mapCodec(
            i -> i.group(
                    ExtraCodecs.AUTHLIB_GAME_PROFILE.fieldOf("profile").forGetter(LoggedChatMessage.Player::profile),
                    PlayerChatMessage.MAP_CODEC.forGetter(LoggedChatMessage.Player::message),
                    ChatTrustLevel.CODEC.optionalFieldOf("trust_level", ChatTrustLevel.SECURE).forGetter(LoggedChatMessage.Player::trustLevel)
                )
                .apply(i, LoggedChatMessage.Player::new)
        );
        private static final DateTimeFormatter TIME_FORMATTER = Util.localizedDateFormatter(FormatStyle.SHORT);
 
        @Override
        public Component toContentComponent() {
            if (!this.message.filterMask().isEmpty()) {
                Component filtered = this.message.filterMask().applyWithFormatting(this.message.signedContent());
                return (Component)(filtered != null ? filtered : Component.empty());
            } else {
                return this.message.decoratedContent();
            }
        }
 
        @Override
        public Component toNarrationComponent() {
            Component content = this.toContentComponent();
            Component time = this.getTimeComponent();
            return Component.translatable("gui.chatSelection.message.narrate", this.profile.name(), content, time);
        }
 
        public Component toHeadingComponent() {
            Component time = this.getTimeComponent();
            return Component.translatable("gui.chatSelection.heading", this.profile.name(), time);
        }
 
        private Component getTimeComponent() {
            ZonedDateTime dateTime = ZonedDateTime.ofInstant(this.message.timeStamp(), ZoneId.systemDefault());
            return Component.literal(dateTime.format(TIME_FORMATTER)).withStyle(ChatFormatting.ITALIC, ChatFormatting.GRAY);
        }
 
        @Override
        public boolean canReport(UUID reportedPlayerId) {
            return this.message.hasSignatureFrom(reportedPlayerId);
        }
 
        public UUID profileId() {
            return this.profile.id();
        }
 
        @Override
        public LoggedChatEvent.Type type() {
            return LoggedChatEvent.Type.PLAYER;
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    public record System(Component message, Instant timeStamp) implements LoggedChatMessage {
        public static final MapCodec<LoggedChatMessage.System> CODEC = RecordCodecBuilder.mapCodec(
            i -> i.group(
                    ComponentSerialization.CODEC.fieldOf("message").forGetter(LoggedChatMessage.System::message),
                    ExtraCodecs.INSTANT_ISO8601.fieldOf("time_stamp").forGetter(LoggedChatMessage.System::timeStamp)
                )
                .apply(i, LoggedChatMessage.System::new)
        );
 
        @Override
        public Component toContentComponent() {
            return this.message;
        }
 
        @Override
        public boolean canReport(UUID reportedPlayerId) {
            return false;
        }
 
        @Override
        public LoggedChatEvent.Type type() {
            return LoggedChatEvent.Type.SYSTEM;
        }
    }
}

引用的其他类

  • ChatTrustLevel

    • 引用位置: 参数
  • LoggedChatEvent

    • 引用位置: 继承
  • Component

    • 引用位置: 参数/方法调用/返回值
    • 关联成员: Component.empty(), Component.literal(), Component.translatable()
  • PlayerChatMessage

    • 引用位置: 参数
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.localizedDateFormatter()