Improve how parameters are passed to placeholders

This commit is contained in:
Vankka 2023-06-03 16:55:37 +03:00
parent 03c26a6ca2
commit ce055debde
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
6 changed files with 17 additions and 21 deletions

View File

@ -35,7 +35,7 @@ public class AwardMessageConfig implements IMessageConfig {
.addEmbed(
DiscordMessageEmbed.builder()
.setAuthor(
"%award_title|text_{player_name} made the achievement {award_name}%",
"%award_title|text:'{player_name} made the achievement {award_name}'%",
null,
"%player_avatar_url%"
)

View File

@ -35,11 +35,11 @@ public class DiscordToMinecraftChatConfig {
@Comment("The Discord to Minecraft message format for regular users and bots")
@Untranslated(Untranslated.Type.VALUE)
public String format = "[&#5865F2Discord&r] [hover:show_text:Tag: %user_tag%&r\nRoles: %user_roles_, |text_&7&oNone%]%user_color%%user_effective_name%&r » %message%%message_attachments%";
public String format = "[&#5865F2Discord&r] [hover:show_text:Tag: %user_tag%&r\nRoles: %user_roles:', '|text:'&7&oNone'%]%user_color%%user_effective_name%&r » %message%%message_attachments%";
@Comment("The Discord to Minecraft message format for webhook messages (if enabled)")
@Untranslated(Untranslated.Type.VALUE)
public String webhookFormat = "[&#5865F2Discord&r] [hover:show_text:Webhook message]%user_name%&r » %message%%message_attachments:' '%";
public String webhookFormat = "[&#5865F2Discord&r] [hover:show_text:Webhook message]%user_name%&r » %message%%message_attachments%";
@Comment("Attachment format")
@Untranslated(Untranslated.Type.VALUE)
@ -61,7 +61,7 @@ public class DiscordToMinecraftChatConfig {
public Format role = new Format("&#5865f2@%role_name%", "&#5865f2@deleted-role");
public Format channel = new Format("[hover:show_text:Click to go to channel][click:open_url:%channel_jump_url%]&#5865f2#%channel_name%", "&#5865f2#deleted-channel");
public Format user = new Format("[hover:show_text:Tag: %user_tag%&r\nRoles: %user_roles_, |text_&7&oNone%]&#5865f2@%user_effective_name|user_name%", "&#5865f2@Unknown user");
public Format user = new Format("[hover:show_text:Tag: %user_tag%&r\nRoles: %user_roles_, |text:'&7&oNone'%]&#5865f2@%user_effective_name|user_name%", "&#5865f2@Unknown user");
public String messageUrl = "[hover:show_text:Click to go to message][click:open_url:%jump_url%]&#5865f2#%channel_name% > ...";

View File

@ -142,12 +142,6 @@ public class DiscordGuildMemberImpl implements DiscordGuildMember {
@Placeholder("user_roles")
public Component _allRoles(@PlaceholderRemainder String suffix) {
if (suffix.startsWith("_")) {
suffix = suffix.substring(1);
} else if (!suffix.isEmpty()) {
return null;
}
List<Component> components = new ArrayList<>();
for (DiscordRole role : getRoles()) {
components.add(Component.text(role.getName()).color(TextColor.color(role.getColor().rgb())));

View File

@ -324,15 +324,6 @@ public class ReceivedDiscordMessageImpl implements ReceivedDiscordMessage {
@Placeholder("message_attachments")
public Component _attachments(BaseChannelConfig config, @PlaceholderRemainder String suffix) {
if (suffix.startsWith(":")) {
suffix = suffix.substring(1);
} else if (!suffix.isEmpty()) {
return null;
}
if (suffix.startsWith("'") && suffix.endsWith("'")) {
suffix = suffix.substring(1, suffix.length() - 1);
}
String attachmentFormat = config.discordToMinecraft.attachmentFormat;
List<Component> components = new ArrayList<>();
for (Attachment attachment : attachments) {

View File

@ -31,7 +31,7 @@ public class GlobalTextHandlingContext {
this.discordSRV = discordSRV;
}
@Placeholder("text_")
@Placeholder("text")
public MinecraftComponent text(@PlaceholderRemainder String text) {
return discordSRV.componentFactory().textBuilder(text).build();
}

View File

@ -39,8 +39,19 @@ public final class PlaceholderMethodUtil {
PlaceholderRemainder annotation = parameter.getAnnotation(PlaceholderRemainder.class);
if (annotation != null) {
parameters[i] = null;
if (parameter.getType().isAssignableFrom(String.class)) {
parameterValues[i] = remainder;
String suffix = remainder;
if (suffix.startsWith(":")) {
suffix = suffix.substring(1);
} else if (!suffix.isEmpty()) {
suffix = "";
}
if (suffix.startsWith("'") && suffix.endsWith("'")) {
suffix = suffix.substring(1, suffix.length() - 1);
}
parameterValues[i] = suffix;
} else {
parameterValues[i] = null;
}