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