Simplify addContext usages

This commit is contained in:
Vankka 2024-03-02 17:14:42 +02:00
parent fdb02920a2
commit 0f573d50e4
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
3 changed files with 18 additions and 26 deletions

View File

@ -50,7 +50,12 @@ public class EnhancedTextBuilderImpl implements GameTextBuilder {
@Override
public @NotNull GameTextBuilder addContext(Object... context) {
this.context.addAll(Arrays.asList(context));
for (Object o : context) {
if (o == null) {
continue;
}
this.context.add(o);
}
return this;
}

View File

@ -172,18 +172,12 @@ public class DiscordSRVMinecraftRenderer extends DefaultMinecraftRenderer {
DiscordUser user = discordSRV.discordAPI().getUserById(id);
DiscordGuildMember member = guild.getMemberById(id);
GameTextBuilder builder = discordSRV.componentFactory()
.textBuilder(user != null ? format.format : format.unknownFormat);
if (user != null) {
builder.addContext(user);
}
if (member != null) {
builder.addContext(member);
}
return ComponentUtil.fromAPI(
builder.applyPlaceholderService().build()
discordSRV.componentFactory()
.textBuilder(user != null ? format.format : format.unknownFormat)
.addContext(user, member)
.applyPlaceholderService()
.build()
);
}
@ -202,15 +196,12 @@ public class DiscordSRVMinecraftRenderer extends DefaultMinecraftRenderer {
public Component makeRoleMention(long id, MentionsConfig.Format format) {
DiscordRole role = discordSRV.discordAPI().getRoleById(id);
GameTextBuilder builder = discordSRV.componentFactory()
.textBuilder(role != null ? format.format : format.unknownFormat);
if (role != null) {
builder.addContext(role);
}
return ComponentUtil.fromAPI(
builder.applyPlaceholderService().build()
discordSRV.componentFactory()
.textBuilder(role != null ? format.format : format.unknownFormat)
.addContext(role)
.applyPlaceholderService()
.build()
);
}

View File

@ -215,13 +215,9 @@ public class DiscordChatMessageModule extends AbstractModule<DiscordSRV> {
GameTextBuilder componentBuilder = discordSRV.componentFactory()
.textBuilder(format)
.addContext(discordMessage, author, channel, channelConfig)
.addContext(discordMessage, author, member, channel, channelConfig)
.applyPlaceholderService()
.addPlaceholder("message", messageComponent);
if (member != null) {
componentBuilder.addContext(member);
}
componentBuilder.applyPlaceholderService();
MinecraftComponent component = DiscordSRVMinecraftRenderer.getWithContext(guild, chatConfig, componentBuilder::build);
if (ComponentUtil.isEmpty(component)) {