Fix up avatar URL stuff + disable auto invite creation by default (#2)

* Start fixing up avatarurl stuff

* Fix some stuff

* Don't automatically create invite by default

* Add suggestion

Co-authored-by: Henri Schubin <vankka.main@gmail.com>

* Format + remove todos

Co-authored-by: Henri Schubin <vankka.main@gmail.com>

---------

Co-authored-by: Henri Schubin <vankka.main@gmail.com>
This commit is contained in:
Dinty1 2023-06-23 22:33:38 +01:00 committed by GitHub
parent 2f2b852b0d
commit 8e79c7abf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 10 deletions

View File

@ -0,0 +1,19 @@
package com.discordsrv.common.config.main;
import com.discordsrv.common.config.annotation.Untranslated;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Comment;
@ConfigSerializable
public class AvatarProviderConfig {
@Comment("Whether to let DiscordSRV decide an appropriate avatar URL automatically\n" +
"This will result in appropriate head renders being provided for Bedrock players (when using Floodgate) and Offline Mode players (via username).")
public boolean autoDecideAvatarUrl = true;
@Untranslated(Untranslated.Type.VALUE)
@Comment("The template for URLs of player avatars\n" +
"This will be used for offical Java players only if auto-decide-avatar-url is set to true\n" +
"This will be used ALWAYS if auto-decide-avatar-url is set to false")
public String avatarUrlTemplate = "https://crafatar.com/avatars/%uuid-nodashes%.png?size=128&overlay#%texture%";
}

View File

@ -33,6 +33,6 @@ public class DiscordInviteConfig {
@Comment("If the bot is only in one Discord server, it will attempt to automatically create a invite for it.\n"
+ "The bot will only attempt to do so if it has permission to \"Create Invite\"\n"
+ "The server must also have a rules channel (available for community servers) or default channel (automatically determined by Discord)")
public boolean autoCreateInvite = true;
public boolean autoCreateInvite = false;
}

View File

@ -80,6 +80,10 @@ public abstract class MainConfig implements Config {
@Comment("Configuration for the %discord_invite% placeholder. The below options will be attempted in the order they are in")
public DiscordInviteConfig invite = new DiscordInviteConfig();
@Order(10) // To go below required linking config @ 5
@Comment("Configuration for the %player_avatar_url% placeholder")
public AvatarProviderConfig avatarProvider = new AvatarProviderConfig();
public abstract PluginIntegrationConfig integrations();
@Order(1000)

View File

@ -39,10 +39,6 @@ public class BaseChannelConfig {
@Order(2)
public LeaveMessageConfig leaveMessages = new LeaveMessageConfig();
@Untranslated(Untranslated.Type.VALUE)
@Order(10)
public String avatarUrlProvider = "https://heads.discordsrv.com/head.png?texture=%texture%&uuid=%uuid%&name=%username%&overlay";
@Order(20)
public StartMessageConfig startMessage = new StartMessageConfig();
@Order(20)

View File

@ -23,7 +23,7 @@ import com.discordsrv.api.placeholder.util.Placeholders;
import com.discordsrv.api.player.DiscordSRVPlayer;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.command.game.sender.ICommandSender;
import com.discordsrv.common.config.main.channels.base.BaseChannelConfig;
import com.discordsrv.common.config.main.AvatarProviderConfig;
import com.discordsrv.common.permission.util.PermissionUtil;
import com.discordsrv.common.profile.Profile;
import net.kyori.adventure.text.Component;
@ -65,14 +65,24 @@ public interface IPlayer extends DiscordSRVPlayer, IOfflinePlayer, ICommandSende
@Nullable
@ApiStatus.NonExtendable
@Placeholder("player_avatar_url")
default String getAvatarUrl(BaseChannelConfig config) {
String avatarUrlProvider = config.avatarUrlProvider;
if (avatarUrlProvider == null) {
default String getAvatarUrl() {
AvatarProviderConfig avatarConfig = discordSRV().config().avatarProvider;
String avatarUrlTemplate = avatarConfig.avatarUrlTemplate;
if (avatarConfig.autoDecideAvatarUrl) {
// Offline mode
if (uniqueId().version() == 3) avatarUrlTemplate = "https://cravatar.eu/helmavatar/%username%/128.png#%texture%";
// Bedrock
else if (uniqueId().getLeastSignificantBits() == 0) avatarUrlTemplate = "https://api.tydiumcraft.net/skin?uuid=%uuid_nodashes%&type=avatar&size=128";
}
if (avatarUrlTemplate == null) {
return null;
}
return new Placeholders(avatarUrlProvider)
return new Placeholders(avatarUrlTemplate)
.replace("%uuid%", uniqueId().toString())
.replace("%uuid_nodashes%", uniqueId().toString().replaceAll("-", ""))
.replace("%username%", username())
.replace("%texture%", "") // TODO
.toString();