Skip to content

Commit

Permalink
chore(text-serializer-json): more renames
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Dec 17, 2023
1 parent ec79116 commit 4e23fcd
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.TranslationArgument;
import net.kyori.adventure.text.serializer.json.JSONFlags;
import net.kyori.adventure.text.serializer.json.JSONOptions;
import net.kyori.option.OptionState;
import org.jetbrains.annotations.Nullable;

Expand All @@ -79,7 +79,7 @@ final class ComponentSerializerImpl extends TypeAdapter<Component> {
static final Type TRANSLATABLE_ARGUMENT_LIST_TYPE = new TypeToken<List<TranslationArgument>>() {}.getType();

static TypeAdapter<Component> create(final OptionState features, final Gson gson) {
return new ComponentSerializerImpl(features.value(JSONFlags.EMIT_COMPACT_TEXT_COMPONENT), gson).nullSafe();
return new ComponentSerializerImpl(features.value(JSONOptions.EMIT_COMPACT_TEXT_COMPONENT), gson).nullSafe();
}

private final boolean emitCompactTextComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import net.kyori.adventure.builder.AbstractBuilder;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.json.JSONComponentSerializer;
import net.kyori.adventure.text.serializer.json.JSONFlags;
import net.kyori.adventure.text.serializer.json.JSONOptions;
import net.kyori.adventure.util.Buildable;
import net.kyori.adventure.util.PlatformAPI;
import net.kyori.option.OptionState;
Expand Down Expand Up @@ -125,10 +125,10 @@ static Builder builder() {
*/
interface Builder extends AbstractBuilder<GsonComponentSerializer>, Buildable.Builder<GsonComponentSerializer>, JSONComponentSerializer.Builder {
@Override
@NotNull Builder features(final @NotNull OptionState flags);
@NotNull Builder options(final @NotNull OptionState flags);

@Override
@NotNull Builder editFeatures(final @NotNull Consumer<OptionState.Builder> flagEditor);
@NotNull Builder editOptions(final @NotNull Consumer<OptionState.Builder> optionEditor);

/**
* Sets that the serializer should downsample hex colors to named colors.
Expand All @@ -138,7 +138,7 @@ interface Builder extends AbstractBuilder<GsonComponentSerializer>, Buildable.Bu
*/
@Override
default @NotNull Builder downsampleColors() {
return this.editFeatures(features -> features.value(JSONFlags.EMIT_RGB, false));
return this.editOptions(features -> features.value(JSONOptions.EMIT_RGB, false));
}

/**
Expand Down Expand Up @@ -167,7 +167,7 @@ interface Builder extends AbstractBuilder<GsonComponentSerializer>, Buildable.Bu
@Deprecated
@Override
default @NotNull Builder emitLegacyHoverEvent() {
return this.editFeatures(b -> b.value(JSONFlags.EMIT_HOVER_EVENT_TYPE, JSONFlags.HoverEventValueMode.BOTH));
return this.editOptions(b -> b.value(JSONOptions.EMIT_HOVER_EVENT_TYPE, JSONOptions.HoverEventValueMode.BOTH));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.function.Consumer;
import java.util.function.UnaryOperator;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.json.JSONFlags;
import net.kyori.adventure.text.serializer.json.JSONOptions;
import net.kyori.adventure.util.Services;
import net.kyori.option.OptionState;
import org.jetbrains.annotations.NotNull;
Expand All @@ -50,10 +50,10 @@ final class GsonComponentSerializerImpl implements GsonComponentSerializer {
static final class Instances {
static final GsonComponentSerializer INSTANCE = SERVICE
.map(Provider::gson)
.orElseGet(() -> new GsonComponentSerializerImpl(JSONFlags.byDataVersion(), null));
.orElseGet(() -> new GsonComponentSerializerImpl(JSONOptions.byDataVersion(), null));
static final GsonComponentSerializer LEGACY_INSTANCE = SERVICE
.map(Provider::gsonLegacy)
.orElseGet(() -> new GsonComponentSerializerImpl(JSONFlags.byDataVersion().at(2525 /* just before 1.16 */), null));
.orElseGet(() -> new GsonComponentSerializerImpl(JSONOptions.byDataVersion().at(2525 /* just before 1.16 */), null));
}

private final Gson serializer;
Expand Down Expand Up @@ -122,7 +122,7 @@ static final class Instances {
}

static final class BuilderImpl implements Builder {
private OptionState flags = JSONFlags.byDataVersion(); // latest
private OptionState flags = JSONOptions.byDataVersion(); // latest
private net.kyori.adventure.text.serializer.json.@Nullable LegacyHoverEventSerializer legacyHoverSerializer;

BuilderImpl() {
Expand All @@ -136,16 +136,16 @@ static final class BuilderImpl implements Builder {
}

@Override
public @NotNull Builder features(final @NotNull OptionState flags) {
public @NotNull Builder options(final @NotNull OptionState flags) {
this.flags = requireNonNull(flags, "flags");
return this;
}

@Override
public @NotNull Builder editFeatures(final @NotNull Consumer<OptionState.Builder> flagEditor) {
public @NotNull Builder editOptions(final @NotNull Consumer<OptionState.Builder> optionEditor) {
final OptionState.Builder builder = OptionState.optionState()
.values(this.flags);
requireNonNull(flagEditor, "flagEditor").accept(builder);
requireNonNull(optionEditor, "flagEditor").accept(builder);
this.flags = builder.build();
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.json.JSONFlags;
import net.kyori.adventure.text.serializer.json.JSONOptions;
import net.kyori.option.OptionState;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -86,7 +86,7 @@ public <T> TypeAdapter<T> create(final Gson gson, final TypeToken<T> type) {
} else if (COLOR_WRAPPER_TYPE.isAssignableFrom(rawType)) {
return (TypeAdapter<T>) TextColorWrapper.Serializer.INSTANCE;
} else if (COLOR_TYPE.isAssignableFrom(rawType)) {
return (TypeAdapter<T>) (this.features.value(JSONFlags.EMIT_RGB) ? TextColorSerializer.INSTANCE : TextColorSerializer.DOWNSAMPLE_COLOR);
return (TypeAdapter<T>) (this.features.value(JSONOptions.EMIT_RGB) ? TextColorSerializer.INSTANCE : TextColorSerializer.DOWNSAMPLE_COLOR);
} else if (TEXT_DECORATION_TYPE.isAssignableFrom(rawType)) {
return (TypeAdapter<T>) TextDecorationSerializer.INSTANCE;
} else if (BLOCK_NBT_POS_TYPE.isAssignableFrom(rawType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.json.JSONFlags;
import net.kyori.adventure.text.serializer.json.JSONOptions;
import net.kyori.adventure.util.Codec;
import net.kyori.option.OptionState;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -83,12 +83,12 @@ final class StyleSerializer extends TypeAdapter<Style> {
}

static TypeAdapter<Style> create(final net.kyori.adventure.text.serializer.json.@Nullable LegacyHoverEventSerializer legacyHover, final OptionState features, final Gson gson) {
final JSONFlags.HoverEventValueMode hoverMode = features.value(JSONFlags.EMIT_HOVER_EVENT_TYPE);
final JSONOptions.HoverEventValueMode hoverMode = features.value(JSONOptions.EMIT_HOVER_EVENT_TYPE);
return new StyleSerializer(
legacyHover,
hoverMode == JSONFlags.HoverEventValueMode.LEGACY_ONLY || hoverMode == JSONFlags.HoverEventValueMode.BOTH,
hoverMode == JSONFlags.HoverEventValueMode.MODERN_ONLY || hoverMode == JSONFlags.HoverEventValueMode.BOTH,
features.value(JSONFlags.VALIDATE_STRICT_EVENTS),
hoverMode == JSONOptions.HoverEventValueMode.LEGACY_ONLY || hoverMode == JSONOptions.HoverEventValueMode.BOTH,
hoverMode == JSONOptions.HoverEventValueMode.MODERN_ONLY || hoverMode == JSONOptions.HoverEventValueMode.BOTH,
features.value(JSONOptions.VALIDATE_STRICT_EVENTS),
gson
).nullSafe();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.UUID;
import net.kyori.adventure.text.serializer.json.JSONFlags;
import net.kyori.adventure.text.serializer.json.JSONOptions;
import net.kyori.option.OptionState;

final class UUIDSerializer extends TypeAdapter<UUID> {
private final boolean emitIntArray;

static TypeAdapter<UUID> uuidSerializer(final OptionState features) {
return new UUIDSerializer(features.value(JSONFlags.EMIT_HOVER_SHOW_ENTITY_ID_AS_INT_ARRAY)).nullSafe();
return new UUIDSerializer(features.value(JSONOptions.EMIT_HOVER_SHOW_ENTITY_ID_AS_INT_ARRAY)).nullSafe();
}

private UUIDSerializer(final boolean emitIntArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ final class DummyJSONComponentSerializer implements JSONComponentSerializer {
// A no-op builder that just returns the unsupported instance.
static final class BuilderImpl implements Builder {
@Override
public @NotNull Builder features(final @NotNull OptionState flags) {
public @NotNull Builder options(final @NotNull OptionState flags) {
return this;
}

@Override
public @NotNull Builder editFeatures(final @NotNull Consumer<OptionState.Builder> flagEditor) {
public @NotNull Builder editOptions(final @NotNull Consumer<OptionState.Builder> optionEditor) {
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,33 @@ public interface JSONComponentSerializer extends ComponentSerializer<Component,
*/
interface Builder {
/**
* Set the feature flag set to apply on this serializer.
* Set the option state to apply on this serializer.
*
* <p>This controls how the serializer emits and interprets components.</p>
*
* @param flags the flag set to use
* @return this builder
* @see JSONFlags
* @see JSONOptions
* @since 4.15.0
*/
@NotNull Builder features(final @NotNull OptionState flags);
@NotNull Builder options(final @NotNull OptionState flags);

/**
* Edit the active set of feature flags.
* Edit the active set of serializer options.
*
* @param flagEditor the consumer operating on the existing flag set
* @param optionEditor the consumer operating on the existing flag set
* @return this builder
* @see JSONFlags
* @see JSONOptions
* @since 4.15.0
*/
@NotNull Builder editFeatures(final @NotNull Consumer<OptionState.Builder> flagEditor);
@NotNull Builder editOptions(final @NotNull Consumer<OptionState.Builder> optionEditor);

/**
* Sets that the serializer should downsample hex colors to named colors.
*
* @return this builder
* @since 4.14.0
* @deprecated for removal since 4.15.0, change the {@link JSONFlags#EMIT_RGB} flag instead
* @deprecated for removal since 4.15.0, change the {@link JSONOptions#EMIT_RGB} flag instead
*/
@Deprecated
@NotNull Builder downsampleColors();
Expand All @@ -119,7 +119,7 @@ interface Builder {
*
* @return this builder
* @since 4.14.0
* @deprecated for removal since 4.15.0, change the {@link JSONFlags#EMIT_HOVER_EVENT_TYPE} flag instead
* @deprecated for removal since 4.15.0, change the {@link JSONOptions#EMIT_HOVER_EVENT_TYPE} flag instead
*/
@Deprecated
@NotNull Builder emitLegacyHoverEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
import org.jetbrains.annotations.NotNull;

/**
* Feature flags that can apply to JSON serializers.
* Options that can apply to JSON serializers.
*
* <p>See serializer documentation for specific details on which flags are supported.</p>
*
* @since 4.15.0
*/
public final class JSONFlags {
private JSONFlags() {
public final class JSONOptions {
private JSONOptions() {
}

private static final int VERSION_INITIAL = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void testDeserializeArray() {
@SuppressWarnings("deprecation")
void testSkipInvalidHoverEventWhenLenient() {
final JSONComponentSerializer serializer = JSONComponentSerializer.builder()
.editFeatures(b -> b.value(JSONFlags.VALIDATE_STRICT_EVENTS, false))
.editOptions(b -> b.value(JSONOptions.VALIDATE_STRICT_EVENTS, false))
.build();

final Component expected = Component.text("hello");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class ShowEntitySerializerTest extends SerializerTest {
void testWithStringUuid() {
final UUID id = UUID.randomUUID();
final JSONComponentSerializer cereal = JSONComponentSerializer.builder()
.editFeatures(b -> b.value(JSONFlags.EMIT_HOVER_SHOW_ENTITY_ID_AS_INT_ARRAY, false))
.editOptions(b -> b.value(JSONOptions.EMIT_HOVER_SHOW_ENTITY_ID_AS_INT_ARRAY, false))
.build();

this.testStyle(cereal, Style.style().hoverEvent(HoverEvent.showEntity(Key.key("zombie"), id)).build(), json -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class StyleTest extends SerializerTest {
@Override
protected JSONComponentSerializer createSerializer() {
return JSONComponentSerializer.builder()
.editFeatures(b -> b.value(JSONFlags.EMIT_COMPACT_TEXT_COMPONENT, false))
.editOptions(b -> b.value(JSONOptions.EMIT_COMPACT_TEXT_COMPONENT, false))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class TranslatableComponentTest extends SerializerTest {
@Override
protected JSONComponentSerializer createSerializer() {
return JSONComponentSerializer.builder()
.editFeatures(b -> b.value(JSONFlags.EMIT_COMPACT_TEXT_COMPONENT, false))
.editOptions(b -> b.value(JSONOptions.EMIT_COMPACT_TEXT_COMPONENT, false))
.build();
}

Expand Down

0 comments on commit 4e23fcd

Please sign in to comment.