[FEAT] Try to use Linked Account names for chat relay

This commit is contained in:
2023-08-05 19:06:12 +02:00
parent 3bffb7cdc5
commit 1791389a9e
4 changed files with 27 additions and 3 deletions

View File

@@ -14,12 +14,13 @@ import com.hypherionmc.sdlink.core.services.SDLinkPlatform;
public class DiscordAuthor {
// User used for Server Messages
public static final DiscordAuthor SERVER = new DiscordAuthor(SDLinkConfig.INSTANCE.channelsAndWebhooks.serverName, SDLinkConfig.INSTANCE.channelsAndWebhooks.serverAvatar, "server", true);
public static final DiscordAuthor SERVER = new DiscordAuthor(SDLinkConfig.INSTANCE.channelsAndWebhooks.serverName, SDLinkConfig.INSTANCE.channelsAndWebhooks.serverAvatar, "server", true, "");
private final String displayName;
private final String avatar;
private final boolean isServer;
private final String username;
private final String uuid;
/**
* Internal. Use {@link #of(String, String, String)}
@@ -27,11 +28,12 @@ public class DiscordAuthor {
* @param avatar The avatar URL of the Author
* @param isServer Is the Author the Minecraft Server
*/
private DiscordAuthor(String displayName, String avatar, String username, boolean isServer) {
private DiscordAuthor(String displayName, String avatar, String username, boolean isServer, String uuid) {
this.displayName = displayName;
this.avatar = avatar;
this.username = username;
this.isServer = isServer;
this.uuid = uuid;
}
/**
@@ -45,7 +47,8 @@ public class DiscordAuthor {
displayName,
SDLinkConfig.INSTANCE.chatConfig.playerAvatarType.resolve(SDLinkPlatform.minecraftHelper.isOnlineMode() ? uuid : username),
username,
false
false,
SDLinkPlatform.minecraftHelper.isOnlineMode() ? uuid : username
);
}
@@ -64,4 +67,8 @@ public class DiscordAuthor {
public String getAvatar() {
return avatar;
}
public String getUuid() {
return uuid;
}
}

View File

@@ -97,6 +97,10 @@ public class MinecraftAccount {
return standard(profile.getName());
}
public static SDLinkAccount getStoredFromUUID(String uuid) {
return sdlinkDatabase.findById(uuid, SDLinkAccount.class);
}
public String getUsername() {
return username;
}

View File

@@ -17,6 +17,10 @@ import java.util.List;
*/
public class ChatSettingsConfig {
@Path("useLinkedNames")
@SpecComment("Use linked account names in Discord/Minecraft messages, instead of the default ones")
public boolean useLinkedNames = true;
@Path("formatting")
@SpecComment("Convert Discord to MC, and MC to Discord Formatting")
public boolean formatting = true;

View File

@@ -5,6 +5,7 @@
package com.hypherionmc.sdlink.core.messaging.discord;
import com.hypherionmc.sdlink.core.accounts.DiscordAuthor;
import com.hypherionmc.sdlink.core.accounts.MinecraftAccount;
import com.hypherionmc.sdlink.core.config.SDLinkConfig;
import com.hypherionmc.sdlink.core.config.impl.MessageIgnoreConfig;
import com.hypherionmc.sdlink.core.messaging.MessageType;
@@ -38,6 +39,14 @@ public final class DiscordMessageBuilder {
this.author = DiscordAuthor.SERVER;
}
if (SDLinkConfig.INSTANCE.chatConfig.useLinkedNames && this.author != DiscordAuthor.SERVER) {
MinecraftAccount account = MinecraftAccount.standard(author.getRawUsername());
if (account != null && account.getDiscordUser() != null) {
this.author = DiscordAuthor.of(account.getDiscordName(), author.getUuid(), author.getRawUsername());
}
}
return this;
}