Fix DiscordAuthor using wrong username to retrieve avatars
This commit is contained in:
@@ -21,7 +21,6 @@ repositories {
|
||||
maven { url "https://maven.firstdarkdev.xyz/releases" }
|
||||
maven { url "https://maven.firstdarkdev.xyz/snapshots" }
|
||||
maven { url "https://m2.dv8tion.net/releases" }
|
||||
maven { url "https://nexus.velocitypowered.com/repository/maven-public/" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -61,6 +60,7 @@ dependencies {
|
||||
implementation("commons-io:commons-io:${commonsio}")
|
||||
implementation("com.google.code.gson:gson:${gson}")
|
||||
implementation("com.google.guava:guava:31.1-jre")
|
||||
implementation 'com.mojang:authlib:4.0.43'
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
version_major=0
|
||||
version_minor=0
|
||||
version_patch=1
|
||||
version_patch=3
|
||||
|
||||
shade_group=com.hypherionmc.sdlink.shaded.
|
||||
|
||||
|
@@ -14,39 +14,46 @@ 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, true);
|
||||
public static final DiscordAuthor SERVER = new DiscordAuthor(SDLinkConfig.INSTANCE.channelsAndWebhooks.serverName, SDLinkConfig.INSTANCE.channelsAndWebhooks.serverAvatar, "server", true);
|
||||
|
||||
private final String username;
|
||||
private final String displayName;
|
||||
private final String avatar;
|
||||
private final boolean isServer;
|
||||
private final String username;
|
||||
|
||||
/**
|
||||
* Internal. Use {@link #of(String, String)}
|
||||
* @param username The Username of the Author
|
||||
* Internal. Use {@link #of(String, String, String)}
|
||||
* @param displayName The Username of the Author
|
||||
* @param avatar The avatar URL of the Author
|
||||
* @param isServer Is the Author the Minecraft Server
|
||||
*/
|
||||
private DiscordAuthor(String username, String avatar, boolean isServer) {
|
||||
this.username = username;
|
||||
private DiscordAuthor(String displayName, String avatar, String username, boolean isServer) {
|
||||
this.displayName = displayName;
|
||||
this.avatar = avatar;
|
||||
this.username = username;
|
||||
this.isServer = isServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Discord Author
|
||||
* @param username The name/Username of the Author
|
||||
* @param displayName The name/Username of the Author
|
||||
* @param uuid The Mojang UUID of the Author
|
||||
* @return A constructed {@link DiscordAuthor}
|
||||
*/
|
||||
public static DiscordAuthor of(String username, String uuid) {
|
||||
public static DiscordAuthor of(String displayName, String uuid, String username) {
|
||||
return new DiscordAuthor(
|
||||
username,
|
||||
displayName,
|
||||
SDLinkConfig.INSTANCE.chatConfig.playerAvatarType.resolve(SDLinkPlatform.minecraftHelper.isOnlineMode() ? uuid : username),
|
||||
username,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public String getRawUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
|
@@ -10,6 +10,7 @@ import com.hypherionmc.sdlink.core.discord.BotController;
|
||||
import com.hypherionmc.sdlink.core.managers.RoleManager;
|
||||
import com.hypherionmc.sdlink.core.messaging.Result;
|
||||
import com.hypherionmc.sdlink.core.services.SDLinkPlatform;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
@@ -78,7 +79,7 @@ public class MinecraftAccount {
|
||||
* Convert a username to an offline account
|
||||
* @param username The Username to search for
|
||||
*/
|
||||
public static MinecraftAccount offline(String username) {
|
||||
private static MinecraftAccount offline(String username) {
|
||||
Pair<String, UUID> player = offlinePlayer(username);
|
||||
return new MinecraftAccount(
|
||||
player.getLeft(),
|
||||
@@ -88,6 +89,14 @@ public class MinecraftAccount {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert GameProfile to Minecraft account
|
||||
* @param profile The profile of the player
|
||||
*/
|
||||
public static MinecraftAccount fromGameProfile(GameProfile profile) {
|
||||
return standard(profile.getName());
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ public final class DiscordMessage {
|
||||
// Check if a webhook is configured, and use that instead
|
||||
if (channel.getMiddle() != null && SDLinkConfig.INSTANCE.channelsAndWebhooks.webhooks.enabled) {
|
||||
WebhookMessageBuilder builder = new WebhookMessageBuilder();
|
||||
builder.setUsername(this.author.getUsername());
|
||||
builder.setUsername(this.author.getDisplayName());
|
||||
if (!this.author.getAvatar().isEmpty()) {
|
||||
builder.setAvatarUrl(this.author.getAvatar());
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public final class DiscordMessage {
|
||||
} else {
|
||||
channel.getLeft().sendMessage(
|
||||
this.messageType == MessageType.CHAT ?
|
||||
SDLinkConfig.INSTANCE.messageFormatting.chat.replace("%player%", author.getUsername()).replace("%message%", message)
|
||||
SDLinkConfig.INSTANCE.messageFormatting.chat.replace("%player%", author.getDisplayName()).replace("%message%", message)
|
||||
: message)
|
||||
.queue(success -> {
|
||||
if (afterSend != null)
|
||||
@@ -140,7 +140,7 @@ public final class DiscordMessage {
|
||||
|
||||
if (withAuthor) {
|
||||
builder.setAuthor(
|
||||
this.author.getUsername(),
|
||||
this.author.getDisplayName(),
|
||||
null,
|
||||
this.author.getAvatar().isEmpty() ? null : this.author.getAvatar()
|
||||
);
|
||||
|
@@ -32,7 +32,7 @@ public final class DiscordMessageBuilder {
|
||||
public DiscordMessageBuilder author(DiscordAuthor author) {
|
||||
this.author = author;
|
||||
|
||||
if (author.getUsername().equalsIgnoreCase("server")) {
|
||||
if (author.getRawUsername().equalsIgnoreCase("server")) {
|
||||
this.author = DiscordAuthor.SERVER;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user