Skip to content

Commit

Permalink
Make non-component placeholders preProcessParsed
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Sep 9, 2023
1 parent 9d6b1cc commit 7a43d07
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@

import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.moonshine.message.IMessageRenderer;

@FunctionalInterface
public interface CarbonMessageRenderer extends IMessageRenderer<Audience, String, Component, Component> {
public interface CarbonMessageRenderer extends IMessageRenderer<Audience, String, Component, Tag> {

default IMessageRenderer<SourcedAudience, String, Component, Component> asSourced() {
default IMessageRenderer<SourcedAudience, String, Component, Tag> asSourced() {
return this::render;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Map;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.moonshine.placeholder.ConclusionValue;
import net.kyori.moonshine.placeholder.ContinuanceValue;
import net.kyori.moonshine.placeholder.IPlaceholderResolver;
import net.kyori.moonshine.util.Either;
import org.checkerframework.checker.nullness.qual.Nullable;

public class BooleanPlaceholderResolver<R> implements IPlaceholderResolver<R, Boolean, Component> {
public class BooleanPlaceholderResolver<R> implements IPlaceholderResolver<R, Boolean, Tag> {

@Override
public @Nullable Map<String, Either<ConclusionValue<? extends Component>, ContinuanceValue<?>>>
resolve(
public @Nullable Map<String, Either<ConclusionValue<? extends Tag>, ContinuanceValue<?>>> resolve(
final String placeholderName,
final Boolean value,
final R receiver,
Expand All @@ -42,10 +41,10 @@ public class BooleanPlaceholderResolver<R> implements IPlaceholderResolver<R, Bo
final @Nullable Object[] parameters
) {
if (value == null) {
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Component.text("false"))));
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Tag.preProcessParsed("false"))));
}

return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Component.text(value.toString()))));
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Tag.preProcessParsed(value.toString()))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.lang.reflect.Type;
import java.util.Map;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.moonshine.placeholder.ConclusionValue;
import net.kyori.moonshine.placeholder.ContinuanceValue;
import net.kyori.moonshine.placeholder.IPlaceholderResolver;
Expand All @@ -32,19 +33,18 @@
import org.checkerframework.framework.qual.DefaultQualifier;

@DefaultQualifier(NonNull.class)
public class ComponentPlaceholderResolver<R> implements IPlaceholderResolver<R, Component, Component> {
public class ComponentPlaceholderResolver<R> implements IPlaceholderResolver<R, Component, Tag> {

@Override
public @Nullable Map<String, Either<ConclusionValue<? extends Component>, ContinuanceValue<?>>>
resolve(
public @Nullable Map<String, Either<ConclusionValue<? extends Tag>, ContinuanceValue<?>>> resolve(
final String placeholderName,
final Component value,
final R receiver,
final Type owner,
final Method method,
final @Nullable Object[] parameters
) {
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(value)));
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Tag.inserting(value))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Map;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.moonshine.placeholder.ConclusionValue;
import net.kyori.moonshine.placeholder.ContinuanceValue;
import net.kyori.moonshine.placeholder.IPlaceholderResolver;
import net.kyori.moonshine.util.Either;
import org.checkerframework.checker.nullness.qual.Nullable;

public class IntPlaceholderResolver<R> implements IPlaceholderResolver<R, Integer, Component> {
public class IntPlaceholderResolver<R> implements IPlaceholderResolver<R, Integer, Tag> {

@Override
public @Nullable Map<String, Either<ConclusionValue<? extends Component>, ContinuanceValue<?>>> resolve(
public @Nullable Map<String, Either<ConclusionValue<? extends Tag>, ContinuanceValue<?>>> resolve(
final String placeholderName,
final Integer value,
final R receiver,
final Type owner,
final Method method,
final @Nullable Object[] parameters
) {
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Component.text(value))));
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Tag.preProcessParsed(String.valueOf(value)))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,25 @@
import java.lang.reflect.Type;
import java.util.Map;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.moonshine.placeholder.ConclusionValue;
import net.kyori.moonshine.placeholder.ContinuanceValue;
import net.kyori.moonshine.placeholder.IPlaceholderResolver;
import net.kyori.moonshine.util.Either;
import org.checkerframework.checker.nullness.qual.Nullable;

public class KeyPlaceholderResolver<R> implements IPlaceholderResolver<R, Key, Component> {
public class KeyPlaceholderResolver<R> implements IPlaceholderResolver<R, Key, Tag> {

@Override
public @Nullable Map<String, Either<ConclusionValue<? extends Component>, ContinuanceValue<?>>>
resolve(
public @Nullable Map<String, Either<ConclusionValue<? extends Tag>, ContinuanceValue<?>>> resolve(
final String placeholderName,
final Key value,
final R receiver,
final Type owner,
final Method method,
final @Nullable Object[] parameters
) {
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Component.text(value.toString()))));
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Tag.preProcessParsed(value.toString()))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,25 @@
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Map;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.moonshine.placeholder.ConclusionValue;
import net.kyori.moonshine.placeholder.ContinuanceValue;
import net.kyori.moonshine.placeholder.IPlaceholderResolver;
import net.kyori.moonshine.util.Either;
import org.checkerframework.checker.nullness.qual.Nullable;

public class StringPlaceholderResolver<R> implements IPlaceholderResolver<R, String, Component> {
public class StringPlaceholderResolver<R> implements IPlaceholderResolver<R, String, Tag> {

@Override
public @Nullable Map<String, Either<ConclusionValue<? extends Component>, ContinuanceValue<?>>>
resolve(
public @Nullable Map<String, Either<ConclusionValue<? extends Tag>, ContinuanceValue<?>>> resolve(
final String placeholderName,
final String value,
final R receiver,
final Type owner,
final Method method,
final @Nullable Object[] parameters
) {
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Component.text(value))));
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Tag.preProcessParsed(value))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.lang.reflect.Type;
import java.util.Map;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.moonshine.placeholder.ConclusionValue;
import net.kyori.moonshine.placeholder.ContinuanceValue;
import net.kyori.moonshine.placeholder.IPlaceholderResolver;
Expand All @@ -33,19 +33,18 @@
import org.checkerframework.framework.qual.DefaultQualifier;

@DefaultQualifier(NonNull.class)
public class UUIDPlaceholderResolver<R> implements IPlaceholderResolver<R, UUID, Component> {
public class UUIDPlaceholderResolver<R> implements IPlaceholderResolver<R, UUID, Tag> {

@Override
public @Nullable Map<String, Either<ConclusionValue<? extends Component>, ContinuanceValue<?>>>
resolve(
public @Nullable Map<String, Either<ConclusionValue<? extends Tag>, ContinuanceValue<?>>> resolve(
final String placeholderName,
final UUID value,
final R receiver,
final Type owner,
final Method method,
final @Nullable Object[] parameters
) {
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Component.text(value.toString()))));
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Tag.preProcessParsed(value.toString()))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public FabricMessageRenderer(final ConfigManager configManager) {
public Component render(
final Audience receiver,
final String intermediateMessage,
final Map<String, ? extends Component> resolvedPlaceholders,
final Map<String, ? extends Tag> resolvedPlaceholders,
final Method method,
final Type owner
) {
final TagResolver.Builder tagResolver = TagResolver.builder();

for (final var entry : resolvedPlaceholders.entrySet()) {
tagResolver.tag(entry.getKey(), Tag.inserting(entry.getValue()));
tagResolver.tag(entry.getKey(), entry.getValue());
}

final String placeholderResolvedMessage = this.configManager.primaryConfig().applyCustomPlaceholders(intermediateMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public PaperMessageRenderer(final ConfigManager configManager) {
public Component render(
final Audience receiver,
final String intermediateMessage,
final Map<String, ? extends Component> resolvedPlaceholders,
final Map<String, ? extends Tag> resolvedPlaceholders,
final Method method,
final Type owner
) {
final TagResolver.Builder tagResolver = TagResolver.builder();

for (final var entry : resolvedPlaceholders.entrySet()) {
tagResolver.tag(entry.getKey(), Tag.inserting(entry.getValue()));
tagResolver.tag(entry.getKey(), entry.getValue());
}

final String placeholderResolvedMessage = this.configManager.primaryConfig().applyCustomPlaceholders(intermediateMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public VelocityMessageRenderer(final ConfigManager configManager, final PluginMa
public Component render(
final Audience receiver,
final String intermediateMessage,
final Map<String, ? extends Component> resolvedPlaceholders,
final Map<String, ? extends Tag> resolvedPlaceholders,
final Method method,
final Type owner
) {
final TagResolver.Builder tagResolver = TagResolver.builder();

for (final var entry : resolvedPlaceholders.entrySet()) {
tagResolver.tag(entry.getKey(), Tag.inserting(entry.getValue()));
tagResolver.tag(entry.getKey(), entry.getValue());
}

final String placeholderResolvedMessage = this.configManager.primaryConfig().applyCustomPlaceholders(intermediateMessage);
Expand Down

0 comments on commit 7a43d07

Please sign in to comment.