mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-11-25 12:25:15 +01:00
Add linking instructions methods
This commit is contained in:
parent
bec1a2851a
commit
a94d8e1003
@ -22,6 +22,7 @@ import com.discordsrv.bukkit.BukkitDiscordSRV;
|
||||
import com.discordsrv.bukkit.config.main.BukkitRequiredLinkingConfig;
|
||||
import com.discordsrv.bukkit.requiredlinking.BukkitRequiredLinkingModule;
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.component.util.ComponentUtil;
|
||||
import com.discordsrv.common.player.IPlayer;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -93,7 +94,12 @@ public class BukkitRequiredLinkingListener implements Listener {
|
||||
private CompletableFuture<Component> getBlockReason(UUID playerUUID, String playerName) {
|
||||
BukkitRequiredLinkingModule module = getModule();
|
||||
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);
|
||||
|
@ -393,8 +393,8 @@ public abstract class AbstractDiscordSRV<
|
||||
public abstract MessagesConfigManager<MC> messagesConfigManager();
|
||||
|
||||
@Override
|
||||
public MC messagesConfig(Locale locale) {
|
||||
MessagesConfigSingleManager<MC> manager = messagesConfigManager().getManager(locale);
|
||||
public MC messagesConfig(@Nullable Locale locale) {
|
||||
MessagesConfigSingleManager<MC> manager = locale != null ? messagesConfigManager().getManager(locale) : null;
|
||||
if (manager == null) {
|
||||
manager = messagesConfigManager().getManager(defaultLocale());
|
||||
}
|
||||
|
@ -13,6 +13,6 @@ public class MessagesConfig implements Config {
|
||||
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";
|
||||
}
|
||||
|
@ -18,8 +18,11 @@
|
||||
|
||||
package com.discordsrv.common.linking;
|
||||
|
||||
import com.discordsrv.api.component.MinecraftComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -53,4 +56,6 @@ public interface LinkProvider {
|
||||
default Optional<UUID> getCachedPlayerUUID(long userId) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
MinecraftComponent getLinkingInstructions(String username, UUID playerUUID, @Nullable Locale locale);
|
||||
}
|
||||
|
@ -18,7 +18,9 @@
|
||||
|
||||
package com.discordsrv.common.linking.impl;
|
||||
|
||||
import com.discordsrv.api.component.MinecraftComponent;
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.component.util.ComponentUtil;
|
||||
import com.discordsrv.common.function.CheckedSupplier;
|
||||
import com.discordsrv.common.future.util.CompletableFutureUtil;
|
||||
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.platform.discord.DiscordAccount;
|
||||
import me.minecraftauth.lib.account.platform.minecraft.MinecraftAccount;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
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) {
|
||||
logger.debug("New link: " + playerUUID + " & " + Long.toUnsignedString(userId));
|
||||
linkStore.createLink(playerUUID, userId).whenComplete((v, t) -> {
|
||||
|
@ -18,11 +18,16 @@
|
||||
|
||||
package com.discordsrv.common.linking.impl;
|
||||
|
||||
import com.discordsrv.api.component.MinecraftComponent;
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.component.util.ComponentUtil;
|
||||
import com.discordsrv.common.linking.LinkProvider;
|
||||
import com.discordsrv.common.linking.LinkStore;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -72,4 +77,9 @@ public class StorageLinker extends CachedLinkProvider implements LinkProvider, L
|
||||
discordSRV.scheduler().executor()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftComponent getLinkingInstructions(String username, UUID playerUUID, @Nullable Locale locale) {
|
||||
return ComponentUtil.toAPI(Component.text("<linking instructions>"));
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.discordsrv.common.linking.requirelinking;
|
||||
|
||||
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.ServerRequiredLinkingConfig;
|
||||
import com.discordsrv.common.future.util.CompletableFutureUtil;
|
||||
@ -63,14 +64,23 @@ public abstract class ServerRequireLinkingModule<T extends DiscordSRV> extends R
|
||||
LinkProvider linkProvider = discordSRV.linkProvider();
|
||||
if (linkProvider == null) {
|
||||
// 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)
|
||||
.thenCompose(opt -> {
|
||||
if (!opt.isPresent()) {
|
||||
// User is not linked
|
||||
return CompletableFuture.completedFuture(Component.text("Not linked"));
|
||||
return CompletableFuture.completedFuture(
|
||||
ComponentUtil.fromAPI(
|
||||
linkProvider.getLinkingInstructions(playerName, playerUUID, null)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
List<CompiledRequirement> requirements;
|
||||
|
Loading…
Reference in New Issue
Block a user