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