Search in sources :

Example 1 with TextColor

use of org.spongepowered.api.text.format.TextColor in project Skree by Skelril.

the class ShnugglesPrimeInstance method sendAttackBroadcast.

protected void sendAttackBroadcast(String message, AttackSeverity severity) {
    TextColor color;
    switch(severity) {
        case INFO:
            color = TextColors.YELLOW;
            break;
        case ULTIMATE:
            color = TextColors.DARK_RED;
            break;
        default:
            color = TextColors.RED;
            break;
    }
    getPlayerMessageChannel(SPECTATOR).send(Text.of(color, message));
}
Also used : TextColor(org.spongepowered.api.text.format.TextColor)

Example 2 with TextColor

use of org.spongepowered.api.text.format.TextColor in project Skree by Skelril.

the class Luminositor method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (optHeldItem.isPresent()) /* && optClickedPosition.isPresent() */
    {
        if (this.equals(optHeldItem.get().getItem())) {
            Direction dir = event.getTargetSide();
            Optional<Location<World>> optTargetBlockLoc = event.getTargetBlock().getLocation();
            if (!optTargetBlockLoc.isPresent()) {
                return;
            }
            Location<World> targetBlockLoc = optTargetBlockLoc.get();
            Vector3i targPos = targetBlockLoc.getBlockPosition().add(dir.asBlockOffset());
            Location<World> trueTargBlock = new Location<>(targetBlockLoc.getExtent(), targPos);
            int lightLevel = LightLevelUtil.getMaxLightLevel(trueTargBlock).get();
            TextColor color;
            if (lightLevel >= 12) {
                color = TextColors.GREEN;
            } else if (lightLevel >= 8) {
                color = TextColors.RED;
            } else {
                color = TextColors.DARK_RED;
            }
            // TODO system message.color(color)
            player.sendMessage(Text.of(TextColors.YELLOW, "Light level: ", color, lightLevel));
            event.setUseBlockResult(Tristate.FALSE);
        }
    }
}
Also used : Vector3i(com.flowpowered.math.vector.Vector3i) TextColor(org.spongepowered.api.text.format.TextColor) ItemStack(org.spongepowered.api.item.inventory.ItemStack) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 3 with TextColor

use of org.spongepowered.api.text.format.TextColor in project modules-extra by CubeEngine.

the class ChatCommands method chatcolors.

@Command(desc = "Displays the colors")
public void chatcolors(CommandSource context) {
    i18n.send(context, POSITIVE, "The following chat codes are available:");
    Builder builder = Text.builder();
    int i = 0;
    for (TextColor color : Sponge.getRegistry().getAllOf(TextColor.class)) {
        if (color == TextColors.NONE) {
            continue;
        }
        if (i++ % 3 == 0) {
            builder.append(Text.NEW_LINE);
        }
        builder.append(Text.of(" ")).append(Text.of(color, color.getName())).append(Text.of(" (", FORMATTING_CODE.serialize(Text.of(color)), ")"));
    }
    builder.append(Text.NEW_LINE);
    builder.append(Text.of(" ")).append(Text.of(BOLD, "bold")).append(Text.of(" (", FORMATTING_CODE.serialize(Text.of(BOLD)), ")"));
    builder.append(Text.of(" ")).append(Text.of(ITALIC, "italic")).append(Text.of(" (", FORMATTING_CODE.serialize(Text.of(ITALIC)), ")"));
    builder.append(Text.of(" ")).append(Text.of(UNDERLINE, "underline")).append(Text.of(" (", FORMATTING_CODE.serialize(Text.of(UNDERLINE)), ")"));
    builder.append(Text.NEW_LINE);
    builder.append(Text.of(" ")).append(Text.of(STRIKETHROUGH, "strikethrough")).append(Text.of(" (", FORMATTING_CODE.serialize(Text.of(STRIKETHROUGH)), ")"));
    builder.append(Text.of(" ")).append(Text.of(OBFUSCATED, "obfuscated")).append(Text.of(" (", FORMATTING_CODE.serialize(Text.of(OBFUSCATED)), ")"));
    context.sendMessage(builder.build());
}
Also used : Builder(org.spongepowered.api.text.Text.Builder) TextColor(org.spongepowered.api.text.format.TextColor) Command(org.cubeengine.butler.parametric.Command)

Example 4 with TextColor

use of org.spongepowered.api.text.format.TextColor in project LanternServer by LanternPowered.

the class CodecPlayOutTeams method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutTeams message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeString(message.getTeamName());
    if (message instanceof MessagePlayOutTeams.CreateOrUpdate) {
        buf.writeByte((byte) (message instanceof MessagePlayOutTeams.Create ? 0 : 2));
        final MessagePlayOutTeams.CreateOrUpdate message1 = (MessagePlayOutTeams.CreateOrUpdate) message;
        buf.writeString(message1.getDisplayName());
        buf.writeString(message1.getPrefix());
        buf.writeString(message1.getSuffix());
        int flags = 0;
        if (message1.getFriendlyFire()) {
            flags |= 0x01;
        }
        if (message1.getSeeFriendlyInvisibles()) {
            flags |= 0x02;
        }
        buf.writeByte((byte) flags);
        buf.writeString(message1.getNameTagVisibility().getId());
        buf.writeString(message1.getCollisionRule().getName());
        final TextColor c = message1.getColor();
        buf.writeByte((byte) (c == TextColors.NONE || c == TextColors.RESET ? -1 : FormattingCodeTextSerializer.FORMATS_TO_CODE.getChar(c)));
    } else {
        buf.writeByte((byte) (message instanceof MessagePlayOutTeams.Remove ? 1 : message instanceof MessagePlayOutTeams.AddPlayers ? 3 : 4));
    }
    if (message instanceof MessagePlayOutTeams.Players) {
        final List<String> players = ((MessagePlayOutTeams.Players) message).getPlayers();
        buf.writeVarInt(players.size());
        players.forEach(buf::writeString);
    }
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer) MessagePlayOutTeams(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutTeams) TextColor(org.spongepowered.api.text.format.TextColor)

Example 5 with TextColor

use of org.spongepowered.api.text.format.TextColor in project LanternServer by LanternPowered.

the class JsonTextBaseSerializer method serialize.

public static void serialize(JsonObject json, Text text, JsonSerializationContext context, List<Text> children) {
    final TextColor color = text.getColor();
    if (color != TextColors.NONE) {
        json.addProperty(COLOR, color.getId());
    }
    final TextStyle style = text.getStyle();
    style.isBold().ifPresent(v -> json.addProperty(BOLD, v));
    style.isItalic().ifPresent(v -> json.addProperty(ITALIC, v));
    style.hasUnderline().ifPresent(v -> json.addProperty(UNDERLINE, v));
    style.hasStrikethrough().ifPresent(v -> json.addProperty(STRIKETHROUGH, v));
    style.isObfuscated().ifPresent(v -> json.addProperty(OBFUSCATED, v));
    if (!children.isEmpty()) {
        json.add(CHILDREN, context.serialize(children.toArray(new Text[children.size()]), Text[].class));
    }
    text.getClickAction().ifPresent(clickAction -> {
        final RawAction raw = LanternTextHelper.raw(clickAction);
        final JsonObject jsonEvent = new JsonObject();
        jsonEvent.addProperty(EVENT_ACTION, raw.getAction());
        jsonEvent.addProperty(EVENT_VALUE, raw.getValueAsString());
        json.add(CLICK_EVENT, jsonEvent);
    });
    text.getHoverAction().ifPresent(clickAction -> {
        final RawAction raw = LanternTextHelper.raw(clickAction);
        final JsonObject jsonEvent = new JsonObject();
        jsonEvent.addProperty(EVENT_ACTION, raw.getAction());
        jsonEvent.addProperty(EVENT_VALUE, raw.getValueAsString());
        json.add(HOVER_EVENT, jsonEvent);
    });
    text.getShiftClickAction().ifPresent(shiftClickAction -> {
        if (shiftClickAction instanceof ShiftClickAction.InsertText) {
            json.addProperty(INSERTION, ((ShiftClickAction.InsertText) shiftClickAction).getResult());
        }
    });
}
Also used : TextStyle(org.spongepowered.api.text.format.TextStyle) ShiftClickAction(org.spongepowered.api.text.action.ShiftClickAction) RawAction(org.lanternpowered.server.text.LanternTextHelper.RawAction) JsonObject(com.google.gson.JsonObject) TextColor(org.spongepowered.api.text.format.TextColor)

Aggregations

TextColor (org.spongepowered.api.text.format.TextColor)21 Text (org.spongepowered.api.text.Text)9 TextStyle (org.spongepowered.api.text.format.TextStyle)6 TextColors (org.spongepowered.api.text.format.TextColors)4 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 LanternDisplaySlot (org.lanternpowered.server.scoreboard.LanternDisplaySlot)3 Sponge (org.spongepowered.api.Sponge)3 Player (org.spongepowered.api.entity.living.player.Player)3 ItemStack (org.spongepowered.api.item.inventory.ItemStack)3 Score (org.spongepowered.api.scoreboard.Score)3 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2