Skip to content

Commit

Permalink
chore: StringComponent(Decoder/Encoder) improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed May 21, 2024
1 parent 052c7d8 commit e02fed1
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public interface Distributor {

StringComponentEncoder getMindustryEncoder();

StringComponentDecoder getMindustryDecoder();

StringComponentEncoder getAnsiEncoder();

StringComponentEncoder getPlainTextEncoder();

StringComponentDecoder getMindustryDecoder();

AudienceProvider getAudienceProvider();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
package com.xpdustry.distributor.api.component.codec;

import com.xpdustry.distributor.api.component.Component;
import com.xpdustry.distributor.api.key.Key;

public interface ComponentDecoder<C, T> {

Component decode(final T input, final C context);

Key<Void> getKey();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
package com.xpdustry.distributor.api.component.codec;

import com.xpdustry.distributor.api.component.Component;
import com.xpdustry.distributor.api.key.Key;

public interface ComponentEncoder<C, T> {

T encode(final Component input, final C context);

Key<Void> getKey();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@
public interface StringComponentDecoder extends ComponentDecoder<MetadataContainer, String> {

Key<Void> MINDUSTRY_DECODER = Key.of(Key.DISTRIBUTOR_NAMESPACE, "mindustry-decoder");

Key<Void> getKey();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@ public interface StringComponentEncoder extends ComponentEncoder<MetadataContain
Key<Void> ANSI_ENCODER = Key.of(Key.DISTRIBUTOR_NAMESPACE, "ansi-encoder");

Key<Void> PLAINTEXT_ENCODER = Key.of(Key.DISTRIBUTOR_NAMESPACE, "plaintext-encoder");

Key<Void> getKey();
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public final class DistributorCommonPlugin extends AbstractMindustryPlugin imple
private @Nullable PlayerLookup lookup = null;
private @Nullable PermissionReader permissions = null;
private @Nullable StringComponentEncoder mindustryEncoder = null;
private @Nullable StringComponentDecoder mindustryDecoder = null;
private @Nullable StringComponentEncoder ansiEncoder = null;
private @Nullable StringComponentEncoder plainTextEncoder = null;
private @Nullable StringComponentDecoder mindustryDecoder = null;
private @Nullable AudienceProvider audienceProvider = null;

@Override
Expand Down Expand Up @@ -97,6 +97,11 @@ public StringComponentEncoder getMindustryEncoder() {
return ensureInitialized(this.mindustryEncoder, "mindustry-string-encoder");
}

@Override
public StringComponentDecoder getMindustryDecoder() {
return ensureInitialized(this.mindustryDecoder, "mindustry-string-decoder");
}

@Override
public StringComponentEncoder getPlainTextEncoder() {
return ensureInitialized(this.plainTextEncoder, "plaintext-string-encoder");
Expand All @@ -107,11 +112,6 @@ public StringComponentEncoder getAnsiEncoder() {
return ensureInitialized(this.ansiEncoder, "ansi-string-encoder");
}

@Override
public StringComponentDecoder getMindustryDecoder() {
return ensureInitialized(this.mindustryDecoder, "mindustry-string-decoder");
}

@Override
public AudienceProvider getAudienceProvider() {
return ensureInitialized(this.audienceProvider, "audience-provider");
Expand All @@ -136,6 +136,12 @@ public void onLoad() {
StringComponentEncoder.MINDUSTRY_ENCODER,
MindustryEncoderImpl::new);

this.mindustryDecoder = findNamedService(
StringComponentDecoder.class,
StringComponentDecoder::getKey,
MindustryDecoderImpl.MINDUSTRY_DECODER,
MindustryDecoderImpl::new);

this.ansiEncoder = findNamedService(
StringComponentEncoder.class,
StringComponentEncoder::getKey,
Expand All @@ -148,12 +154,6 @@ public void onLoad() {
StringComponentEncoder.PLAINTEXT_ENCODER,
PlainTextEncoderImpl::new);

this.mindustryDecoder = findNamedService(
StringComponentDecoder.class,
StringComponentDecoder::getKey,
MindustryDecoderImpl.MINDUSTRY_DECODER,
MindustryDecoderImpl::new);

this.audienceProvider = services.provideOrDefault(AudienceProvider.class, () -> new AudienceProviderImpl(this));

this.getLogger().info("Loaded distributor common api");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public final class AnsiEncoderImpl extends AbstractStringComponentEncoder {

@Override
public Key getKey() {
public Key<Void> getKey() {
return ANSI_ENCODER;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public final class MindustryEncoderImpl extends AbstractStringComponentEncoder {

@Override
public Key getKey() {
public Key<Void> getKey() {
return MINDUSTRY_ENCODER;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public final class PlainTextEncoderImpl extends AbstractStringComponentEncoder {

@Override
public Key getKey() {
public Key<Void> getKey() {
return PLAINTEXT_ENCODER;
}

Expand Down

0 comments on commit e02fed1

Please sign in to comment.