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;
}
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();
}
}
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());
}
}
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;
}
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);
}
}
Aggregations