use of org.spongepowered.api.text.format.TextColor in project LanternServer by LanternPowered.
the class LegacyTexts method toLegacy.
private static StringBuilder toLegacy(StringBuilder builder, Locale locale, Text text, char legacyChar, Style base, Style applied) {
if (legacyChar != 0) {
final TextFormat format = text.getFormat();
final TextColor color = format.getColor();
final TextStyle style = format.getStyle();
// Create a new style object
final Style newStyle = base.copyTo(new Style());
base = newStyle;
if (color != TextColors.NONE) {
newStyle.color = color == TextColors.RESET ? null : color;
}
style.isBold().ifPresent(value -> newStyle.bold = value);
style.isItalic().ifPresent(value -> newStyle.italic = value);
style.isObfuscated().ifPresent(value -> newStyle.obfuscated = value);
style.hasUnderline().ifPresent(value -> newStyle.underlined = value);
style.hasStrikethrough().ifPresent(value -> newStyle.strikethrough = value);
if ((applied.color != null && newStyle.color == null) || (applied.bold && !newStyle.bold) || (applied.italic && !newStyle.italic) || (applied.obfuscated && !newStyle.obfuscated) || (applied.underlined && !newStyle.underlined) || (applied.strikethrough && !newStyle.strikethrough)) {
builder.append(legacyChar).append(TextConstants.RESET);
if (newStyle.color != null) {
builder.append(legacyChar).append(((FormattingCodeHolder) newStyle.color).getCode());
}
if (newStyle.bold) {
builder.append(legacyChar).append(TextConstants.BOLD);
}
if (newStyle.italic) {
builder.append(legacyChar).append(TextConstants.ITALIC);
}
if (newStyle.obfuscated) {
builder.append(legacyChar).append(TextConstants.OBFUSCATED);
}
if (newStyle.underlined) {
builder.append(legacyChar).append(TextConstants.UNDERLINE);
}
if (newStyle.strikethrough) {
builder.append(legacyChar).append(TextConstants.STRIKETHROUGH);
}
} else {
if (applied.color != newStyle.color) {
builder.append(legacyChar).append(((FormattingCodeHolder) newStyle.color).getCode());
}
if (applied.bold != newStyle.bold) {
builder.append(legacyChar).append(TextConstants.BOLD);
}
if (applied.italic != newStyle.italic) {
builder.append(legacyChar).append(TextConstants.ITALIC);
}
if (applied.obfuscated != newStyle.obfuscated) {
builder.append(legacyChar).append(TextConstants.OBFUSCATED);
}
if (applied.underlined != newStyle.underlined) {
builder.append(legacyChar).append(TextConstants.UNDERLINE);
}
if (applied.strikethrough != newStyle.strikethrough) {
builder.append(legacyChar).append(TextConstants.STRIKETHROUGH);
}
}
newStyle.copyTo(applied);
}
if (text instanceof LiteralText) {
builder.append(((LiteralText) text).getContent());
} else if (text instanceof SelectorText) {
builder.append(((SelectorText) text).getSelector().toPlain());
} else if (text instanceof TranslatableText) {
final TranslatableText text0 = (TranslatableText) text;
final Translation translation = text0.getTranslation();
final ImmutableList<Object> args = text0.getArguments();
final Object[] args0 = new Object[args.size()];
for (int i = 0; i < args0.length; i++) {
Object object = args.get(i);
if (object instanceof Text || object instanceof Text.Builder || object instanceof TextRepresentable) {
if (object instanceof Text) {
// Ignore
} else if (object instanceof Text.Builder) {
object = ((Text.Builder) object).build();
} else {
object = ((TextRepresentable) object).toText();
}
args0[i] = toLegacy(new StringBuilder(), locale, (Text) object, legacyChar, base, applied).toString();
} else {
args0[i] = object;
}
}
builder.append(translation.get(locale, args0));
} else if (text instanceof ScoreText) {
final ScoreText text0 = (ScoreText) text;
final Optional<String> override = text0.getOverride();
if (override.isPresent()) {
builder.append(override.get());
} else {
builder.append(text0.getScore().getScore());
}
}
for (Text child : text.getChildren()) {
toLegacy(builder, locale, child, legacyChar, base, applied);
}
return builder;
}
use of org.spongepowered.api.text.format.TextColor in project Nucleus by NucleusPowered.
the class NameUtil method getName.
/**
* Gets the display name from a {@link User} as Sponge sees it.
*
* @param player The {@link User} to get the data from.
* @return The {@link Text}
*/
public Text getName(User player) {
Preconditions.checkNotNull(player);
TextColor tc = getNameColour(player);
TextStyle ts = getNameStyle(player);
Optional<Text> dname = player.getPlayer().map(x -> x.get(Keys.DISPLAY_NAME).orElse(null));
Text.Builder tb = null;
if (plugin != null && plugin.isModuleLoaded(NicknameModule.ID)) {
Optional<ModularUserService> userService = plugin.getUserDataManager().get(player);
if (userService.isPresent()) {
Optional<Text> n = userService.get().get(NicknameUserDataModule.class).getNicknameWithPrefix();
if (n.isPresent()) {
tb = n.get().toBuilder();
}
}
} else if (dname.isPresent()) {
tb = dname.get().toBuilder();
}
if (tb == null) {
tb = Text.builder(player.getName());
}
tb.onHover(TextActions.showText(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("name.hover.ign", player.getName()))).build();
if (tc != TextColors.NONE && tb.getColor() == TextColors.NONE) {
List<Text> lt = tb.getChildren();
if (lt.isEmpty() || lt.get(0).getColor().equals(TextColors.NONE)) {
tb.color(tc);
}
}
if (!ts.isEmpty()) {
tb.style(ts);
}
return tb.build();
}
use of org.spongepowered.api.text.format.TextColor in project Nucleus by NucleusPowered.
the class ListPowertoolCommand method from.
private Text from(final PowertoolUserDataModule inu, Player src, String powertool, List<String> commands) {
Optional<ItemType> oit = Sponge.getRegistry().getType(ItemType.class, powertool);
MessageProvider mp = plugin.getMessageProvider();
// Create the click actions.
ClickAction viewAction = TextActions.executeCallback(pl -> Util.getPaginationBuilder(src).title(mp.getTextMessageWithFormat("command.powertool.ind.header", powertool)).padding(Text.of(TextColors.GREEN, "-")).contents(commands.stream().map(x -> Text.of(TextColors.YELLOW, x)).collect(Collectors.toList())).sendTo(src));
ClickAction deleteAction = TextActions.executeCallback(pl -> {
inu.clearPowertool(powertool);
pl.sendMessage(mp.getTextMessageWithFormat("command.powertool.removed", powertool));
});
TextColor tc = oit.map(itemType -> TextColors.YELLOW).orElse(TextColors.GRAY);
// id - [View] - [Delete]
return Text.builder().append(Text.of(tc, powertool)).append(Text.of(" - ")).append(Text.builder(mp.getMessageWithFormat("standard.view")).color(TextColors.YELLOW).onClick(viewAction).build()).append(Text.of(" - ")).append(Text.builder(mp.getMessageWithFormat("standard.delete")).color(TextColors.DARK_RED).onClick(deleteAction).build()).build();
}
use of org.spongepowered.api.text.format.TextColor in project Skree by Skelril.
the class PatientXInstance 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));
}
use of org.spongepowered.api.text.format.TextColor in project Skree by Skelril.
the class JungleRaidEffectListener method onPlayerInteract.
@Listener
public void onPlayerInteract(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<JungleRaidInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
JungleRaidInstance inst = optInst.get();
Optional<ItemStack> optStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optStack.isPresent()) {
return;
}
ItemStack stack = optStack.get();
if (stack.getItem() == ItemTypes.COMPASS) {
event.setUseBlockResult(Tristate.FALSE);
if (inst.getState() == JungleRaidState.IN_PROGRESS && inst.isFlagEnabled(JungleRaidFlag.ENHANCED_COMPASS)) {
Set<Text> resultSet = new HashSet<>();
for (Player aPlayer : inst.getPlayers(PlayerClassifier.PARTICIPANT)) {
// Check validity
if (player.equals(aPlayer)) {
continue;
}
// Check team
if (inst.isFriendlyFire(player, aPlayer)) {
continue;
}
TextColor color = tf(player).canEntityBeSeen(tf(aPlayer)) ? TextColors.DARK_RED : TextColors.RED;
resultSet.add(Text.of(color, aPlayer.getName(), " - ", player.getLocation().getPosition().distance(aPlayer.getLocation().getPosition())));
}
if (resultSet.isEmpty()) {
player.sendMessage(Text.of(TextColors.RED, "No players found."));
}
player.sendMessage(Text.of(TextColors.YELLOW, "Player - Distance"));
player.sendMessages(resultSet);
} else if (inst.getState() == JungleRaidState.INITIALIZE) {
player.setLocation(inst.getRandomLocation());
}
}
}
Aggregations