mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-01-29 22:51:35 +01:00
Improve how parameters are passed to placeholders
This commit is contained in:
parent
03c26a6ca2
commit
ce055debde
@ -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%"
|
||||
)
|
||||
|
@ -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 = "[ᛩF2Discord&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 = "[ᛩF2Discord&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 = "[ᛩF2Discord&r] [hover:show_text:Webhook message]%user_name%&r » %message%%message_attachments:' '%";
|
||||
public String webhookFormat = "[ᛩF2Discord&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("ᛩf2@%role_name%", "ᛩf2@deleted-role");
|
||||
public Format channel = new Format("[hover:show_text:Click to go to channel][click:open_url:%channel_jump_url%]ᛩf2#%channel_name%", "ᛩf2#deleted-channel");
|
||||
public Format user = new Format("[hover:show_text:Tag: %user_tag%&r\nRoles: %user_roles_, |text_&7&oNone%]ᛩf2@%user_effective_name|user_name%", "ᛩf2@Unknown user");
|
||||
public Format user = new Format("[hover:show_text:Tag: %user_tag%&r\nRoles: %user_roles_, |text:'&7&oNone'%]ᛩf2@%user_effective_name|user_name%", "ᛩf2@Unknown user");
|
||||
|
||||
public String messageUrl = "[hover:show_text:Click to go to message][click:open_url:%jump_url%]ᛩf2#%channel_name% > ...";
|
||||
|
||||
|
@ -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())));
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user