Add linking instructions methods

This commit is contained in:
Vankka 2023-08-26 16:35:04 +03:00
parent bec1a2851a
commit a94d8e1003
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
7 changed files with 47 additions and 7 deletions

View File

@ -22,6 +22,7 @@ import com.discordsrv.bukkit.BukkitDiscordSRV;
import com.discordsrv.bukkit.config.main.BukkitRequiredLinkingConfig; import com.discordsrv.bukkit.config.main.BukkitRequiredLinkingConfig;
import com.discordsrv.bukkit.requiredlinking.BukkitRequiredLinkingModule; import com.discordsrv.bukkit.requiredlinking.BukkitRequiredLinkingModule;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.player.IPlayer; import com.discordsrv.common.player.IPlayer;
import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer; import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -93,7 +94,12 @@ public class BukkitRequiredLinkingListener implements Listener {
private CompletableFuture<Component> getBlockReason(UUID playerUUID, String playerName) { private CompletableFuture<Component> getBlockReason(UUID playerUUID, String playerName) {
BukkitRequiredLinkingModule module = getModule(); BukkitRequiredLinkingModule module = getModule();
if (module == null) { if (module == null) {
return CompletableFuture.completedFuture(Component.text("Discord unavailable, please try again later")); Component message = ComponentUtil.fromAPI(
discordSRV.componentFactory().textBuilder(
discordSRV.messagesConfig(null).noDiscordConnection
).build()
);
return CompletableFuture.completedFuture(message);
} }
return module.getBlockReason(playerUUID, playerName); return module.getBlockReason(playerUUID, playerName);

View File

@ -393,8 +393,8 @@ public abstract class AbstractDiscordSRV<
public abstract MessagesConfigManager<MC> messagesConfigManager(); public abstract MessagesConfigManager<MC> messagesConfigManager();
@Override @Override
public MC messagesConfig(Locale locale) { public MC messagesConfig(@Nullable Locale locale) {
MessagesConfigSingleManager<MC> manager = messagesConfigManager().getManager(locale); MessagesConfigSingleManager<MC> manager = locale != null ? messagesConfigManager().getManager(locale) : null;
if (manager == null) { if (manager == null) {
manager = messagesConfigManager().getManager(defaultLocale()); manager = messagesConfigManager().getManager(defaultLocale());
} }

View File

@ -13,6 +13,6 @@ public class MessagesConfig implements Config {
return FILE_NAME; return FILE_NAME;
} }
public String testOption = "test option"; public String noDiscordConnection = "&cDiscord connection not available yet, please try again later";
public String unableToCheckLinkingStatus = "&cUnable to check linking status, please try again later";
} }

View File

@ -18,8 +18,11 @@
package com.discordsrv.common.linking; package com.discordsrv.common.linking;
import com.discordsrv.api.component.MinecraftComponent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Locale;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -53,4 +56,6 @@ public interface LinkProvider {
default Optional<UUID> getCachedPlayerUUID(long userId) { default Optional<UUID> getCachedPlayerUUID(long userId) {
return Optional.empty(); return Optional.empty();
} }
MinecraftComponent getLinkingInstructions(String username, UUID playerUUID, @Nullable Locale locale);
} }

View File

@ -18,7 +18,9 @@
package com.discordsrv.common.linking.impl; package com.discordsrv.common.linking.impl;
import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.function.CheckedSupplier; import com.discordsrv.common.function.CheckedSupplier;
import com.discordsrv.common.future.util.CompletableFutureUtil; import com.discordsrv.common.future.util.CompletableFutureUtil;
import com.discordsrv.common.linking.LinkProvider; import com.discordsrv.common.linking.LinkProvider;
@ -30,8 +32,10 @@ import me.minecraftauth.lib.AuthService;
import me.minecraftauth.lib.account.AccountType; import me.minecraftauth.lib.account.AccountType;
import me.minecraftauth.lib.account.platform.discord.DiscordAccount; import me.minecraftauth.lib.account.platform.discord.DiscordAccount;
import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount; import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Locale;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -79,6 +83,11 @@ public class MinecraftAuthenticationLinker extends CachedLinkProvider implements
}); });
} }
@Override
public MinecraftComponent getLinkingInstructions(String username, UUID playerUUID, Locale locale) {
return ComponentUtil.toAPI(Component.text("<linking instructions>"));
}
private void linked(UUID playerUUID, long userId) { private void linked(UUID playerUUID, long userId) {
logger.debug("New link: " + playerUUID + " & " + Long.toUnsignedString(userId)); logger.debug("New link: " + playerUUID + " & " + Long.toUnsignedString(userId));
linkStore.createLink(playerUUID, userId).whenComplete((v, t) -> { linkStore.createLink(playerUUID, userId).whenComplete((v, t) -> {

View File

@ -18,11 +18,16 @@
package com.discordsrv.common.linking.impl; package com.discordsrv.common.linking.impl;
import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.linking.LinkProvider; import com.discordsrv.common.linking.LinkProvider;
import com.discordsrv.common.linking.LinkStore; import com.discordsrv.common.linking.LinkStore;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Locale;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -72,4 +77,9 @@ public class StorageLinker extends CachedLinkProvider implements LinkProvider, L
discordSRV.scheduler().executor() discordSRV.scheduler().executor()
); );
} }
@Override
public MinecraftComponent getLinkingInstructions(String username, UUID playerUUID, @Nullable Locale locale) {
return ComponentUtil.toAPI(Component.text("<linking instructions>"));
}
} }

View File

@ -19,6 +19,7 @@
package com.discordsrv.common.linking.requirelinking; package com.discordsrv.common.linking.requirelinking;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.config.main.linking.RequirementsConfig; import com.discordsrv.common.config.main.linking.RequirementsConfig;
import com.discordsrv.common.config.main.linking.ServerRequiredLinkingConfig; import com.discordsrv.common.config.main.linking.ServerRequiredLinkingConfig;
import com.discordsrv.common.future.util.CompletableFutureUtil; import com.discordsrv.common.future.util.CompletableFutureUtil;
@ -63,14 +64,23 @@ public abstract class ServerRequireLinkingModule<T extends DiscordSRV> extends R
LinkProvider linkProvider = discordSRV.linkProvider(); LinkProvider linkProvider = discordSRV.linkProvider();
if (linkProvider == null) { if (linkProvider == null) {
// Link provider unavailable but required linking enabled: error message // Link provider unavailable but required linking enabled: error message
return CompletableFuture.completedFuture(Component.text("Unable to check linking status at this time")); Component message = ComponentUtil.fromAPI(
discordSRV.componentFactory().textBuilder(
discordSRV.messagesConfig(null).unableToCheckLinkingStatus
).build()
);
return CompletableFuture.completedFuture(message);
} }
return linkProvider.queryUserId(playerUUID) return linkProvider.queryUserId(playerUUID)
.thenCompose(opt -> { .thenCompose(opt -> {
if (!opt.isPresent()) { if (!opt.isPresent()) {
// User is not linked // User is not linked
return CompletableFuture.completedFuture(Component.text("Not linked")); return CompletableFuture.completedFuture(
ComponentUtil.fromAPI(
linkProvider.getLinkingInstructions(playerName, playerUUID, null)
)
);
} }
List<CompiledRequirement> requirements; List<CompiledRequirement> requirements;