[FEAT] Try to use Linked Account names for chat relay
This commit is contained in:
@@ -14,12 +14,13 @@ import com.hypherionmc.sdlink.core.services.SDLinkPlatform;
|
|||||||
public class DiscordAuthor {
|
public class DiscordAuthor {
|
||||||
|
|
||||||
// User used for Server Messages
|
// 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 displayName;
|
||||||
private final String avatar;
|
private final String avatar;
|
||||||
private final boolean isServer;
|
private final boolean isServer;
|
||||||
private final String username;
|
private final String username;
|
||||||
|
private final String uuid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal. Use {@link #of(String, String, String)}
|
* Internal. Use {@link #of(String, String, String)}
|
||||||
@@ -27,11 +28,12 @@ public class DiscordAuthor {
|
|||||||
* @param avatar The avatar URL of the Author
|
* @param avatar The avatar URL of the Author
|
||||||
* @param isServer Is the Author the Minecraft Server
|
* @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.displayName = displayName;
|
||||||
this.avatar = avatar;
|
this.avatar = avatar;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.isServer = isServer;
|
this.isServer = isServer;
|
||||||
|
this.uuid = uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,7 +47,8 @@ public class DiscordAuthor {
|
|||||||
displayName,
|
displayName,
|
||||||
SDLinkConfig.INSTANCE.chatConfig.playerAvatarType.resolve(SDLinkPlatform.minecraftHelper.isOnlineMode() ? uuid : username),
|
SDLinkConfig.INSTANCE.chatConfig.playerAvatarType.resolve(SDLinkPlatform.minecraftHelper.isOnlineMode() ? uuid : username),
|
||||||
username,
|
username,
|
||||||
false
|
false,
|
||||||
|
SDLinkPlatform.minecraftHelper.isOnlineMode() ? uuid : username
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,4 +67,8 @@ public class DiscordAuthor {
|
|||||||
public String getAvatar() {
|
public String getAvatar() {
|
||||||
return avatar;
|
return avatar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -97,6 +97,10 @@ public class MinecraftAccount {
|
|||||||
return standard(profile.getName());
|
return standard(profile.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SDLinkAccount getStoredFromUUID(String uuid) {
|
||||||
|
return sdlinkDatabase.findById(uuid, SDLinkAccount.class);
|
||||||
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,10 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class ChatSettingsConfig {
|
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")
|
@Path("formatting")
|
||||||
@SpecComment("Convert Discord to MC, and MC to Discord Formatting")
|
@SpecComment("Convert Discord to MC, and MC to Discord Formatting")
|
||||||
public boolean formatting = true;
|
public boolean formatting = true;
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
package com.hypherionmc.sdlink.core.messaging.discord;
|
package com.hypherionmc.sdlink.core.messaging.discord;
|
||||||
|
|
||||||
import com.hypherionmc.sdlink.core.accounts.DiscordAuthor;
|
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.SDLinkConfig;
|
||||||
import com.hypherionmc.sdlink.core.config.impl.MessageIgnoreConfig;
|
import com.hypherionmc.sdlink.core.config.impl.MessageIgnoreConfig;
|
||||||
import com.hypherionmc.sdlink.core.messaging.MessageType;
|
import com.hypherionmc.sdlink.core.messaging.MessageType;
|
||||||
@@ -38,6 +39,14 @@ public final class DiscordMessageBuilder {
|
|||||||
this.author = DiscordAuthor.SERVER;
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user