Search in sources :

Example 21 with MutableText

use of net.minecraft.text.MutableText in project Essential-Commands by John-Paul-R.

the class PlayerData method reloadFullNickname.

public void reloadFullNickname() {
    MutableText baseName = new LiteralText(this.getPlayer().getGameProfile().getName());
    MutableText tempFullNickname = new LiteralText("");
    // because our mixin to getDisplayName does a null check on getNickname
    if (this.nickname != null) {
        tempFullNickname.append(CONFIG.NICKNAME_PREFIX.getValue()).append(this.nickname);
    } else {
        tempFullNickname.append(baseName);
    }
    if (CONFIG.NICK_REVEAL_ON_HOVER.getValue()) {
        tempFullNickname.setStyle(tempFullNickname.getStyle().withHoverEvent(HoverEvent.Action.SHOW_TEXT.buildHoverEvent(baseName)));
    }
    this.fullNickname = tempFullNickname;
}
Also used : MutableText(net.minecraft.text.MutableText) LiteralText(net.minecraft.text.LiteralText)

Example 22 with MutableText

use of net.minecraft.text.MutableText in project Essential-Commands by John-Paul-R.

the class ServerPlayerEntityMixin method onGetDisplayName.

// method = "getDisplayName", at = @At("RETURN"), cancellable = true
@Override
public void onGetDisplayName(CallbackInfoReturnable<Text> cir) {
    try {
        if (this.getEcPlayerData().getNickname() != null) {
            MutableText nickname = this.getEcPlayerData().getFullNickname();
            // Re-add "whisper" click event unless the nickname has a click event set.
            Style nicknameStyle = nickname.getStyle();
            if (nicknameStyle.getClickEvent() == null) {
                nickname.setStyle(nicknameStyle.withClickEvent(cir.getReturnValue().getStyle().getClickEvent()));
            }
            // Send nickname (styled appropriately for player team) as return value for getDisplayName().
            ServerPlayerEntity serverPlayerEntity = ((ServerPlayerEntity) (Object) this);
            cir.setReturnValue(Team.decorateName(serverPlayerEntity.getScoreboard().getPlayerTeam(serverPlayerEntity.getEntityName()), nickname));
            cir.cancel();
        }
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}
Also used : MutableText(net.minecraft.text.MutableText) Style(net.minecraft.text.Style) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 23 with MutableText

use of net.minecraft.text.MutableText in project twitch-chat by pblop.

the class TwitchChatMod method addTwitchMessage.

public static void addTwitchMessage(String time, String username, String message, Formatting textColor, boolean isMeMessage) {
    MutableText timestampText = new LiteralText(time);
    MutableText usernameText = new LiteralText(username).formatted(textColor);
    MutableText messageBodyText;
    if (!isMeMessage) {
        messageBodyText = new LiteralText(": " + message);
    } else {
        // '/me' messages have the same color as the username in the Twitch website.
        // And thus I set the color of the message to be the same as the username.
        // They also don't have a colon after the username.
        messageBodyText = new LiteralText(" " + message).formatted(textColor);
        // In Minecraft, a '/me' message is marked with a star before the name, like so:
        // 
        // <Player> This is a normal message
        // * Player this is a '/me' message
        // 
        // The star is always white (that's why I don't format it).
        usernameText = new LiteralText("* ").append(usernameText);
    }
    if (ModConfig.getConfig().isBroadcastEnabled()) {
        try {
            String plainTextMessage = ModConfig.getConfig().getBroadcastPrefix() + username + ": " + message;
            plainTextMessage = sanitiseMessage(plainTextMessage);
            if (MinecraftClient.getInstance().player != null) {
                MinecraftClient.getInstance().player.sendChatMessage(plainTextMessage);
            }
        } catch (NullPointerException e) {
            System.err.println("TWITCH BOT FAILED TO BROADCAST MESSAGE: " + e.getMessage());
        }
    } else {
        MinecraftClient.getInstance().inGameHud.addChatMessage(MessageType.CHAT, timestampText.append(usernameText).append(messageBodyText), UUID.randomUUID());
    }
}
Also used : MutableText(net.minecraft.text.MutableText) LiteralText(net.minecraft.text.LiteralText)

Example 24 with MutableText

use of net.minecraft.text.MutableText in project ArmorStandEditor by Patbox.

the class GeneralCommands method listPresets.

private static int listPresets(CommandContext<ServerCommandSource> context) {
    MutableText text = new LiteralText("").formatted(Formatting.DARK_GRAY);
    Iterator<ArmorStandPreset> iterator = ConfigManager.PRESETS.values().iterator();
    while (iterator.hasNext()) {
        ArmorStandPreset preset = iterator.next();
        if (preset.id.startsWith("$")) {
            text.append(new LiteralText(preset.name).formatted(Formatting.YELLOW).append(new LiteralText(" (").formatted(Formatting.GRAY).append(new LiteralText("buildin/" + preset.id.substring(1)).formatted(Formatting.RED)).append(new LiteralText(")").formatted(Formatting.GRAY))));
        } else {
            text.append(new LiteralText(preset.name).formatted(Formatting.WHITE).append(new LiteralText(" (").formatted(Formatting.GRAY).append(new LiteralText(preset.id).formatted(Formatting.BLUE)).append(new LiteralText(")").formatted(Formatting.GRAY))));
        }
        if (iterator.hasNext()) {
            text.append(new LiteralText(", "));
        }
    }
    context.getSource().sendFeedback(text, false);
    return 0;
}
Also used : MutableText(net.minecraft.text.MutableText) ArmorStandPreset(eu.pb4.armorstandeditor.config.ArmorStandPreset) LiteralText(net.minecraft.text.LiteralText)

Example 25 with MutableText

use of net.minecraft.text.MutableText in project meteor-client by MeteorDevelopment.

the class ClientConnectionMixin method disconnect.

@Inject(method = "disconnect", at = @At("HEAD"))
private void disconnect(Text disconnectReason, CallbackInfo ci) {
    if (Modules.get().get(HighwayBuilder.class).isActive()) {
        MutableText text = new LiteralText(String.format("\n\n%s[%sHighway Builder%s] Statistics:", Formatting.GRAY, Formatting.BLUE, Formatting.GRAY)).append("\n");
        text.append(Modules.get().get(HighwayBuilder.class).getStatsText());
        ((MutableText) disconnectReason).append(text);
    }
}
Also used : MutableText(net.minecraft.text.MutableText) HighwayBuilder(meteordevelopment.meteorclient.systems.modules.world.HighwayBuilder) LiteralText(net.minecraft.text.LiteralText) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

MutableText (net.minecraft.text.MutableText)40 LiteralText (net.minecraft.text.LiteralText)34 HoverEvent (net.minecraft.text.HoverEvent)8 ClickEvent (net.minecraft.text.ClickEvent)7 Text (net.minecraft.text.Text)7 Formatting (net.minecraft.util.Formatting)6 List (java.util.List)5 TranslatableText (net.minecraft.text.TranslatableText)5 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)4 CommandSource (net.minecraft.command.CommandSource)3 JsonObject (com.google.gson.JsonObject)2 JsonPrimitive (com.google.gson.JsonPrimitive)2 SINGLE_SUCCESS (com.mojang.brigadier.Command.SINGLE_SUCCESS)2 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2