use of net.kyori.adventure.text.serializer.gson.GsonComponentSerializer in project SpongeCommon by SpongePowered.
the class SpongeAdventure method json.
// Horrible-ness
public static List<Component> json(final List<String> strings) {
final GsonComponentSerializer gcs = GsonComponentSerializer.gson();
final List<Component> components = new ArrayList<>();
for (final String string : strings) {
components.add(gcs.deserialize(string));
}
return components;
}
use of net.kyori.adventure.text.serializer.gson.GsonComponentSerializer in project SpongeCommon by SpongePowered.
the class SpongeAdventure method listTagJson.
public static ListTag listTagJson(final List<Component> components) {
final GsonComponentSerializer gcs = GsonComponentSerializer.gson();
final ListTag nbt = new ListTag();
for (final Component component : components) {
nbt.add(StringTag.valueOf(gcs.serialize(component)));
}
return nbt;
}
use of net.kyori.adventure.text.serializer.gson.GsonComponentSerializer in project SpongeCommon by SpongePowered.
the class SignItemStackData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(ItemStack.class).create(Keys.SIGN_LINES).get(h -> {
final CompoundTag tag = h.getTagElement(Constants.Item.BLOCK_ENTITY_TAG);
if (tag == null) {
return null;
}
final String id = tag.getString(Constants.Item.BLOCK_ENTITY_ID);
if (!id.equalsIgnoreCase(Constants.TileEntity.SIGN)) {
return null;
}
final GsonComponentSerializer gcs = GsonComponentSerializer.gson();
final List<Component> texts = Lists.newArrayListWithCapacity(4);
for (int i = 0; i < 4; i++) {
texts.add(gcs.deserialize(tag.getString("Text" + (i + 1))));
}
return texts;
}).set((h, v) -> {
final GsonComponentSerializer gcs = GsonComponentSerializer.gson();
final CompoundTag tag = h.getOrCreateTagElement(Constants.Item.BLOCK_ENTITY_TAG);
tag.putString(Constants.Item.BLOCK_ENTITY_ID, Constants.TileEntity.SIGN);
for (int i = 0; i < 4; i++) {
final Component line = v.size() > i ? v.get(i) : Component.empty();
if (line == null) {
throw new IllegalArgumentException("A null line was given at index " + i);
}
tag.putString("Text" + (i + 1), gcs.serialize(line));
}
}).delete(h -> h.removeTagKey(Constants.Item.BLOCK_ENTITY_TAG));
}
Aggregations