mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-01-03 18:38:26 +01:00
Simplify addContext usages
This commit is contained in:
parent
fdb02920a2
commit
0f573d50e4
@ -50,7 +50,12 @@ public class EnhancedTextBuilderImpl implements GameTextBuilder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull GameTextBuilder addContext(Object... context) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,18 +172,12 @@ public class DiscordSRVMinecraftRenderer extends DefaultMinecraftRenderer {
|
|||||||
DiscordUser user = discordSRV.discordAPI().getUserById(id);
|
DiscordUser user = discordSRV.discordAPI().getUserById(id);
|
||||||
DiscordGuildMember member = guild.getMemberById(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(
|
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) {
|
public Component makeRoleMention(long id, MentionsConfig.Format format) {
|
||||||
DiscordRole role = discordSRV.discordAPI().getRoleById(id);
|
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(
|
return ComponentUtil.fromAPI(
|
||||||
builder.applyPlaceholderService().build()
|
discordSRV.componentFactory()
|
||||||
|
.textBuilder(role != null ? format.format : format.unknownFormat)
|
||||||
|
.addContext(role)
|
||||||
|
.applyPlaceholderService()
|
||||||
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,13 +215,9 @@ public class DiscordChatMessageModule extends AbstractModule<DiscordSRV> {
|
|||||||
|
|
||||||
GameTextBuilder componentBuilder = discordSRV.componentFactory()
|
GameTextBuilder componentBuilder = discordSRV.componentFactory()
|
||||||
.textBuilder(format)
|
.textBuilder(format)
|
||||||
.addContext(discordMessage, author, channel, channelConfig)
|
.addContext(discordMessage, author, member, channel, channelConfig)
|
||||||
|
.applyPlaceholderService()
|
||||||
.addPlaceholder("message", messageComponent);
|
.addPlaceholder("message", messageComponent);
|
||||||
if (member != null) {
|
|
||||||
componentBuilder.addContext(member);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentBuilder.applyPlaceholderService();
|
|
||||||
|
|
||||||
MinecraftComponent component = DiscordSRVMinecraftRenderer.getWithContext(guild, chatConfig, componentBuilder::build);
|
MinecraftComponent component = DiscordSRVMinecraftRenderer.getWithContext(guild, chatConfig, componentBuilder::build);
|
||||||
if (ComponentUtil.isEmpty(component)) {
|
if (ComponentUtil.isEmpty(component)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user