Search in sources :

Example 6 with TextColor

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

the class MarketSignManager method updateSignText.

public void updateSignText(MarketSignData data, Location<World> loc) {
    SignData sign = loc.get(SignData.class).orElse(null);
    if (sign == null) {
        return;
    }
    boolean isValid = isValidSign(data, null);
    boolean inEditMode = isInEditMode(loc);
    boolean isAdmin = data.isAdminOwner();
    // First Line: SignType
    TextColor color = inEditMode ? DARK_PURPLE : !isValid ? TextColors.DARK_RED : isAdmin ? TextColors.BLUE : TextColors.DARK_BLUE;
    if (this.signInventories.containsKey(data.getID())) {
        color = LIGHT_PURPLE;
    }
    String raw;
    if (data.getSignType() != null) {
        // Buy or Sell
        raw = data.getSignType().getName();
    } else if (// Edit
    inEditMode) {
        raw = "Edit";
    } else {
        // Invalid
        raw = "Invalid";
    }
    if (// Append Admin?
    isAdmin) {
        raw = "Admin-" + raw;
    } else if (// !isAdmin
    !inEditMode && isValid) {
        if (data.getSignType() == SignType.BUY && data.getStock() == 0) {
            color = TextColors.RED;
            // Replace with Sold out
            raw = "Sold out";
        } else if (data.getSignType() == SignType.SELL && data.isSatisfied()) {
            color = TextColors.RED;
            // Replace with Satisfied
            raw = "Satisfied";
        }
    }
    Text line1 = Text.of(color, TextStyles.BOLD, raw);
    // Second Line: Item
    Text line2 = getItemText(data, inEditMode);
    // Third Line: Amount
    color = inEditMode ? DARK_PURPLE : TextColors.DARK_RED;
    raw = "No amount";
    if (data.getAmount() != null) {
        raw = data.getAmount().toString();
        color = TextColors.BLACK;
    }
    String raw2 = "";
    TextColor color2 = TextColors.RED;
    if (data.getStock() != null && data.getAmount() != null) {
        if (data.getSignType() == SignType.BUY) {
            raw2 = " x" + data.getStock();
            if (data.getStock() >= data.getAmount()) {
                color2 = TextColors.DARK_BLUE;
            }
        } else // Sell
        {
            raw2 = " x?";
            color2 = TextColors.AQUA;
            if (data.getDemand() != null) {
                raw2 = " x" + (data.getDemand() - data.getStock());
                if (data.getStock() >= data.getDemand()) {
                    color2 = TextColors.DARK_RED;
                }
            }
        }
    }
    Text line3 = Text.of(color, raw, color2, raw2);
    // Fourth Line: Price
    color = inEditMode ? DARK_PURPLE : TextColors.DARK_RED;
    Text line4 = Text.of(color, "No Price");
    if (data.getPrice() != null && data.getPrice() != 0) {
        line4 = formatPrice(data).toBuilder().color(TextColors.BLACK).build();
    }
    sign.setElements(Arrays.asList(line1, line2, line3, line4));
    loc.offer(sign);
}
Also used : MarketSignData(org.cubeengine.module.signmarket.data.MarketSignData) SignData(org.spongepowered.api.data.manipulator.mutable.tileentity.SignData) IMarketSignData(org.cubeengine.module.signmarket.data.IMarketSignData) ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) Text(org.spongepowered.api.text.Text) TextColor(org.spongepowered.api.text.format.TextColor)

Example 7 with TextColor

use of org.spongepowered.api.text.format.TextColor in project SpongeAPI by SpongePowered.

the class TextFormatConfigSerializer method deserialize.

@Override
public TextFormat deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
    TextColor color = TextColors.NONE;
    GameRegistry registry = Sponge.getRegistry();
    String colorId = value.getNode(NODE_COLOR).getString();
    if (colorId != null) {
        color = registry.getType(TextColor.class, colorId).orElseThrow(() -> new ObjectMappingException("Color not found: " + colorId));
    }
    TextStyle style = TextStyles.NONE;
    ConfigurationNode styleNode = value.getNode(NODE_STYLE);
    for (TextStyle.Base component : registry.getAllOf(TextStyle.Base.class)) {
        if (styleNode.getNode(component.getId().toLowerCase()).getBoolean()) {
            style = style.and(component);
        }
    }
    return TextFormat.NONE.color(color).style(style);
}
Also used : TextStyle(org.spongepowered.api.text.format.TextStyle) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) GameRegistry(org.spongepowered.api.GameRegistry) TextColor(org.spongepowered.api.text.format.TextColor) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException)

Example 8 with TextColor

use of org.spongepowered.api.text.format.TextColor in project Nucleus by NucleusPowered.

the class TextParsingUtils method getLastColourAndStyle.

public static StyleTuple getLastColourAndStyle(TextRepresentable text, @Nullable StyleTuple current) {
    List<Text> texts = flatten(text.toText());
    if (texts.isEmpty()) {
        return current == null ? new StyleTuple(TextColors.NONE, TextStyles.NONE) : current;
    }
    TextColor tc = TextColors.NONE;
    TextStyle ts = texts.get(texts.size() - 1).getStyle();
    for (int i = texts.size() - 1; i > -1; i--) {
        // If we have both a Text Colour and a Text Style, then break out.
        if (tc == TextColors.NONE) {
            tc = texts.get(i).getColor();
            break;
        }
    }
    if (current == null) {
        return new StyleTuple(tc, ts);
    }
    return new StyleTuple(tc != TextColors.NONE ? tc : current.colour, ts);
}
Also used : TextStyle(org.spongepowered.api.text.format.TextStyle) Text(org.spongepowered.api.text.Text) TextColor(org.spongepowered.api.text.format.TextColor)

Example 9 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 10 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)

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