mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-01-29 22:51:35 +01:00
Rename EnhancedTextBuilder to GameTextBuilder
This commit is contained in:
parent
2131fa3e86
commit
28b8d76887
@ -33,41 +33,41 @@ import java.util.regex.Pattern;
|
|||||||
/**
|
/**
|
||||||
* Minecraft equivalent for {@link com.discordsrv.api.discord.entity.message.SendableDiscordMessage.Formatter}.
|
* Minecraft equivalent for {@link com.discordsrv.api.discord.entity.message.SendableDiscordMessage.Formatter}.
|
||||||
*/
|
*/
|
||||||
public interface EnhancedTextBuilder {
|
public interface GameTextBuilder {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
EnhancedTextBuilder addContext(Object... context);
|
GameTextBuilder addContext(Object... context);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
default EnhancedTextBuilder addReplacement(String target, Object replacement) {
|
default GameTextBuilder addReplacement(String target, Object replacement) {
|
||||||
return addReplacement(Pattern.compile(target, Pattern.LITERAL), replacement);
|
return addReplacement(Pattern.compile(target, Pattern.LITERAL), replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
default EnhancedTextBuilder addReplacement(Pattern target, Object replacement) {
|
default GameTextBuilder addReplacement(Pattern target, Object replacement) {
|
||||||
return addReplacement(target, matcher -> replacement);
|
return addReplacement(target, matcher -> replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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);
|
return addReplacement(Pattern.compile(target, Pattern.LITERAL), replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
default EnhancedTextBuilder addReplacement(Pattern target, Supplier<Object> replacement) {
|
default GameTextBuilder addReplacement(Pattern target, Supplier<Object> replacement) {
|
||||||
return addReplacement(target, matcher -> replacement.get());
|
return addReplacement(target, matcher -> replacement.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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);
|
return addReplacement(Pattern.compile(target, Pattern.LITERAL), replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
EnhancedTextBuilder addReplacement(Pattern target, Function<Matcher, Object> replacement);
|
GameTextBuilder addReplacement(Pattern target, Function<Matcher, Object> replacement);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
EnhancedTextBuilder applyPlaceholderService();
|
GameTextBuilder applyPlaceholderService();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
MinecraftComponent build();
|
MinecraftComponent build();
|
@ -40,5 +40,5 @@ public interface MinecraftComponentFactory {
|
|||||||
@NotNull
|
@NotNull
|
||||||
MinecraftComponent empty();
|
MinecraftComponent empty();
|
||||||
|
|
||||||
EnhancedTextBuilder enhancedBuilder(String content);
|
GameTextBuilder enhancedBuilder(String content);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
package com.discordsrv.api.discord.entity.message;
|
package com.discordsrv.api.discord.entity.message;
|
||||||
|
|
||||||
|
import com.discordsrv.api.component.GameTextBuilder;
|
||||||
import com.discordsrv.api.discord.entity.message.impl.SendableDiscordMessageImpl;
|
import com.discordsrv.api.discord.entity.message.impl.SendableDiscordMessageImpl;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
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 {
|
interface Formatter {
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
package com.discordsrv.common.component;
|
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.MinecraftComponent;
|
||||||
import com.discordsrv.api.component.MinecraftComponentFactory;
|
import com.discordsrv.api.component.MinecraftComponentFactory;
|
||||||
import com.discordsrv.common.DiscordSRV;
|
import com.discordsrv.common.DiscordSRV;
|
||||||
@ -84,7 +84,7 @@ public class ComponentFactory implements MinecraftComponentFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnhancedTextBuilder enhancedBuilder(String content) {
|
public GameTextBuilder enhancedBuilder(String content) {
|
||||||
return new EnhancedTextBuilderImpl(discordSRV, content);
|
return new EnhancedTextBuilderImpl(discordSRV, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
package com.discordsrv.common.component;
|
package com.discordsrv.common.component;
|
||||||
|
|
||||||
import com.discordsrv.api.color.Color;
|
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.component.MinecraftComponent;
|
||||||
import com.discordsrv.api.placeholder.PlaceholderService;
|
import com.discordsrv.api.placeholder.PlaceholderService;
|
||||||
import com.discordsrv.common.DiscordSRV;
|
import com.discordsrv.common.DiscordSRV;
|
||||||
@ -35,7 +35,7 @@ import java.util.function.Function;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class EnhancedTextBuilderImpl implements EnhancedTextBuilder {
|
public class EnhancedTextBuilderImpl implements GameTextBuilder {
|
||||||
|
|
||||||
private final Set<Object> context = new HashSet<>();
|
private final Set<Object> context = new HashSet<>();
|
||||||
private final Map<Pattern, Function<Matcher, Object>> replacements = new LinkedHashMap<>();
|
private final Map<Pattern, Function<Matcher, Object>> replacements = new LinkedHashMap<>();
|
||||||
@ -49,19 +49,19 @@ public class EnhancedTextBuilderImpl implements EnhancedTextBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull EnhancedTextBuilder addContext(Object... context) {
|
public @NotNull GameTextBuilder addContext(Object... context) {
|
||||||
this.context.addAll(Arrays.asList(context));
|
this.context.addAll(Arrays.asList(context));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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));
|
this.replacements.put(target, wrapFunction(replacement));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull EnhancedTextBuilder applyPlaceholderService() {
|
public @NotNull GameTextBuilder applyPlaceholderService() {
|
||||||
this.replacements.put(PlaceholderService.PATTERN, wrapFunction(
|
this.replacements.put(PlaceholderService.PATTERN, wrapFunction(
|
||||||
matcher -> discordSRV.placeholderService().getResult(matcher, context)));
|
matcher -> discordSRV.placeholderService().getResult(matcher, context)));
|
||||||
return this;
|
return this;
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
package com.discordsrv.common.component.renderer;
|
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.DiscordUser;
|
||||||
import com.discordsrv.api.discord.entity.guild.DiscordGuild;
|
import com.discordsrv.api.discord.entity.guild.DiscordGuild;
|
||||||
import com.discordsrv.api.discord.entity.guild.DiscordGuildMember;
|
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);
|
DiscordUser user = discordSRV.discordAPI().getUserById(userId).orElse(null);
|
||||||
DiscordGuildMember member = guild.getMemberById(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);
|
.enhancedBuilder(user != null ? format.format : format.unknownFormat);
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
@ -135,7 +135,7 @@ public class DiscordSRVMinecraftRenderer extends DefaultMinecraftRenderer {
|
|||||||
long roleId = MiscUtil.parseLong(id);
|
long roleId = MiscUtil.parseLong(id);
|
||||||
DiscordRole role = discordSRV.discordAPI().getRoleById(roleId).orElse(null);
|
DiscordRole role = discordSRV.discordAPI().getRoleById(roleId).orElse(null);
|
||||||
|
|
||||||
EnhancedTextBuilder builder = discordSRV.componentFactory()
|
GameTextBuilder builder = discordSRV.componentFactory()
|
||||||
.enhancedBuilder(role != null ? format.format : format.unknownFormat);
|
.enhancedBuilder(role != null ? format.format : format.unknownFormat);
|
||||||
|
|
||||||
if (role != null) {
|
if (role != null) {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
package com.discordsrv.common.messageforwarding.discord;
|
package com.discordsrv.common.messageforwarding.discord;
|
||||||
|
|
||||||
import com.discordsrv.api.channel.GameChannel;
|
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.component.MinecraftComponent;
|
||||||
import com.discordsrv.api.discord.entity.DiscordUser;
|
import com.discordsrv.api.discord.entity.DiscordUser;
|
||||||
import com.discordsrv.api.discord.entity.channel.DiscordMessageChannel;
|
import com.discordsrv.api.discord.entity.channel.DiscordMessageChannel;
|
||||||
@ -107,7 +107,7 @@ public class DiscordChatMessageModule extends AbstractModule<DiscordSRV> {
|
|||||||
Component messageComponent = DiscordSRVMinecraftRenderer.getWithContext(event, chatConfig, () ->
|
Component messageComponent = DiscordSRVMinecraftRenderer.getWithContext(event, chatConfig, () ->
|
||||||
discordSRV.componentFactory().minecraftSerializer().serialize(message.toString()));
|
discordSRV.componentFactory().minecraftSerializer().serialize(message.toString()));
|
||||||
|
|
||||||
EnhancedTextBuilder componentBuilder = discordSRV.componentFactory()
|
GameTextBuilder componentBuilder = discordSRV.componentFactory()
|
||||||
.enhancedBuilder(format)
|
.enhancedBuilder(format)
|
||||||
.addContext(discordMessage, author, channel, channelConfig)
|
.addContext(discordMessage, author, channel, channelConfig)
|
||||||
.addReplacement("%message%", messageComponent);
|
.addReplacement("%message%", messageComponent);
|
||||||
|
Loading…
Reference in New Issue
Block a user