Rename EnhancedTextBuilder to GameTextBuilder

This commit is contained in:
Vankka 2022-06-14 18:58:36 +03:00
parent 2131fa3e86
commit 28b8d76887
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
7 changed files with 24 additions and 23 deletions

View File

@ -33,41 +33,41 @@ import java.util.regex.Pattern;
/**
* Minecraft equivalent for {@link com.discordsrv.api.discord.entity.message.SendableDiscordMessage.Formatter}.
*/
public interface EnhancedTextBuilder {
public interface GameTextBuilder {
@NotNull
EnhancedTextBuilder addContext(Object... context);
GameTextBuilder addContext(Object... context);
@NotNull
default EnhancedTextBuilder addReplacement(String target, Object replacement) {
default GameTextBuilder addReplacement(String target, Object replacement) {
return addReplacement(Pattern.compile(target, Pattern.LITERAL), replacement);
}
@NotNull
default EnhancedTextBuilder addReplacement(Pattern target, Object replacement) {
default GameTextBuilder addReplacement(Pattern target, Object replacement) {
return addReplacement(target, matcher -> replacement);
}
@NotNull
default EnhancedTextBuilder addReplacement(String target, Supplier<Object> replacement) {
default GameTextBuilder addReplacement(String target, Supplier<Object> replacement) {
return addReplacement(Pattern.compile(target, Pattern.LITERAL), replacement);
}
@NotNull
default EnhancedTextBuilder addReplacement(Pattern target, Supplier<Object> replacement) {
default GameTextBuilder addReplacement(Pattern target, Supplier<Object> replacement) {
return addReplacement(target, matcher -> replacement.get());
}
@NotNull
default EnhancedTextBuilder addReplacement(String target, Function<Matcher, Object> replacement) {
default GameTextBuilder addReplacement(String target, Function<Matcher, Object> replacement) {
return addReplacement(Pattern.compile(target, Pattern.LITERAL), replacement);
}
@NotNull
EnhancedTextBuilder addReplacement(Pattern target, Function<Matcher, Object> replacement);
GameTextBuilder addReplacement(Pattern target, Function<Matcher, Object> replacement);
@NotNull
EnhancedTextBuilder applyPlaceholderService();
GameTextBuilder applyPlaceholderService();
@NotNull
MinecraftComponent build();

View File

@ -40,5 +40,5 @@ public interface MinecraftComponentFactory {
@NotNull
MinecraftComponent empty();
EnhancedTextBuilder enhancedBuilder(String content);
GameTextBuilder enhancedBuilder(String content);
}

View File

@ -23,6 +23,7 @@
package com.discordsrv.api.discord.entity.message;
import com.discordsrv.api.component.GameTextBuilder;
import com.discordsrv.api.discord.entity.message.impl.SendableDiscordMessageImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -219,7 +220,7 @@ public interface SendableDiscordMessage {
}
/**
* Discord equivalent for {@link com.discordsrv.api.component.EnhancedTextBuilder}.
* Discord equivalent for {@link GameTextBuilder}.
*/
interface Formatter {

View File

@ -18,7 +18,7 @@
package com.discordsrv.common.component;
import com.discordsrv.api.component.EnhancedTextBuilder;
import com.discordsrv.api.component.GameTextBuilder;
import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.component.MinecraftComponentFactory;
import com.discordsrv.common.DiscordSRV;
@ -84,7 +84,7 @@ public class ComponentFactory implements MinecraftComponentFactory {
}
@Override
public EnhancedTextBuilder enhancedBuilder(String content) {
public GameTextBuilder enhancedBuilder(String content) {
return new EnhancedTextBuilderImpl(discordSRV, content);
}

View File

@ -19,7 +19,7 @@
package com.discordsrv.common.component;
import com.discordsrv.api.color.Color;
import com.discordsrv.api.component.EnhancedTextBuilder;
import com.discordsrv.api.component.GameTextBuilder;
import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.placeholder.PlaceholderService;
import com.discordsrv.common.DiscordSRV;
@ -35,7 +35,7 @@ import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EnhancedTextBuilderImpl implements EnhancedTextBuilder {
public class EnhancedTextBuilderImpl implements GameTextBuilder {
private final Set<Object> context = new HashSet<>();
private final Map<Pattern, Function<Matcher, Object>> replacements = new LinkedHashMap<>();
@ -49,19 +49,19 @@ public class EnhancedTextBuilderImpl implements EnhancedTextBuilder {
}
@Override
public @NotNull EnhancedTextBuilder addContext(Object... context) {
public @NotNull GameTextBuilder addContext(Object... context) {
this.context.addAll(Arrays.asList(context));
return this;
}
@Override
public @NotNull EnhancedTextBuilder addReplacement(Pattern target, Function<Matcher, Object> replacement) {
public @NotNull GameTextBuilder addReplacement(Pattern target, Function<Matcher, Object> replacement) {
this.replacements.put(target, wrapFunction(replacement));
return this;
}
@Override
public @NotNull EnhancedTextBuilder applyPlaceholderService() {
public @NotNull GameTextBuilder applyPlaceholderService() {
this.replacements.put(PlaceholderService.PATTERN, wrapFunction(
matcher -> discordSRV.placeholderService().getResult(matcher, context)));
return this;

View File

@ -18,7 +18,7 @@
package com.discordsrv.common.component.renderer;
import com.discordsrv.api.component.EnhancedTextBuilder;
import com.discordsrv.api.component.GameTextBuilder;
import com.discordsrv.api.discord.entity.DiscordUser;
import com.discordsrv.api.discord.entity.guild.DiscordGuild;
import com.discordsrv.api.discord.entity.guild.DiscordGuildMember;
@ -108,7 +108,7 @@ public class DiscordSRVMinecraftRenderer extends DefaultMinecraftRenderer {
DiscordUser user = discordSRV.discordAPI().getUserById(userId).orElse(null);
DiscordGuildMember member = guild.getMemberById(userId).orElse(null);
EnhancedTextBuilder builder = discordSRV.componentFactory()
GameTextBuilder builder = discordSRV.componentFactory()
.enhancedBuilder(user != null ? format.format : format.unknownFormat);
if (user != null) {
@ -135,7 +135,7 @@ public class DiscordSRVMinecraftRenderer extends DefaultMinecraftRenderer {
long roleId = MiscUtil.parseLong(id);
DiscordRole role = discordSRV.discordAPI().getRoleById(roleId).orElse(null);
EnhancedTextBuilder builder = discordSRV.componentFactory()
GameTextBuilder builder = discordSRV.componentFactory()
.enhancedBuilder(role != null ? format.format : format.unknownFormat);
if (role != null) {

View File

@ -19,7 +19,7 @@
package com.discordsrv.common.messageforwarding.discord;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.EnhancedTextBuilder;
import com.discordsrv.api.component.GameTextBuilder;
import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.discord.entity.DiscordUser;
import com.discordsrv.api.discord.entity.channel.DiscordMessageChannel;
@ -107,7 +107,7 @@ public class DiscordChatMessageModule extends AbstractModule<DiscordSRV> {
Component messageComponent = DiscordSRVMinecraftRenderer.getWithContext(event, chatConfig, () ->
discordSRV.componentFactory().minecraftSerializer().serialize(message.toString()));
EnhancedTextBuilder componentBuilder = discordSRV.componentFactory()
GameTextBuilder componentBuilder = discordSRV.componentFactory()
.enhancedBuilder(format)
.addContext(discordMessage, author, channel, channelConfig)
.addReplacement("%message%", messageComponent);