Allow linking for unlinked players while the server is whitelisted

This commit is contained in:
Teriuihi 2021-09-17 15:59:01 +02:00
parent 74a98e340b
commit 49e53fb01c
4 changed files with 22 additions and 2 deletions

View File

@ -14,6 +14,7 @@ import com.alttd.proxydiscordlink.util.Cache;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
@ -25,7 +26,8 @@ import java.util.logging.Logger;
@Plugin(id = "proxydiscordlink", name = "ProxyDiscordLink", version = "1.0.0",
description = "A plugin that links Discord accounts with uuid's",
authors = {"Teri"}
authors = {"Teri"},
dependencies = {@Dependency(id = "luckperms"),@Dependency(id = "shutdowninfo")}
)
public class DiscordLink {

View File

@ -193,6 +193,7 @@ public final class Config {
public static String ACCOUNTS_NOT_LINKED = "<yellow>Your Minecraft and Discord accounts aren't linked</yellow>";
public static String UNLINKED_ACCOUNTS = "<yellow>You have successfully unlinked your accounts.</yellow>";
public static String IS_LINKED = "<yellow><player> is <linked_status>.</yellow>";
public static String WHITELIST_LINK_MESSAGE = "<green>You aren't linked yet! If you would like to link your account join our discord and use the following command in the link channel: <gold>&link <code></gold>.</green>";
public static String INVALID_PLAYER = "<red><player> is not online or is not a valid player.</red>";
public static String NO_PERMISSION = "<red>You do not have permission to do that.</red>";
public static String NO_CONSOLE = "<red>This command can not be executed from console.</red>";
@ -212,6 +213,7 @@ public final class Config {
ACCOUNTS_NOT_LINKED = getString("messages.accounts-not-linked", ACCOUNTS_NOT_LINKED);
UNLINKED_ACCOUNTS = getString("messages.unlinked-accounts", UNLINKED_ACCOUNTS);
IS_LINKED = getString("messages.is-linked", IS_LINKED);
WHITELIST_LINK_MESSAGE = getString("messages.whitelist-link-message", WHITELIST_LINK_MESSAGE);
INVALID_PLAYER = getString("messages.invalid-player", INVALID_PLAYER);
NO_PERMISSION = getString("messages.no-permission", NO_PERMISSION);
NO_CONSOLE = getString("messages.no-console", NO_CONSOLE);

View File

@ -9,6 +9,8 @@ public class PlayerLeave {
@Subscribe(order = PostOrder.LATE)
public void playerDisconnect(DisconnectEvent event) {
if (event.getLoginStatus().equals(DisconnectEvent.LoginStatus.CANCELLED_BY_PROXY))
return;
DiscordLink.getPlugin().getCache().removeCachedPlayer(event.getPlayer().getUniqueId());
}

View File

@ -1,13 +1,27 @@
package com.alttd.proxydiscordlink.minecraft.listeners;
import com.alttd.proxydiscordlink.DiscordLink;
import com.alttd.proxydiscordlink.config.Config;
import com.alttd.proxydiscordlink.util.Utilities;
import com.alttd.shutdowninfo.events.WhitelistKickEvent;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.minimessage.Template;
public class WhitelistKick {
@Subscribe
public void onWhitelistKick(WhitelistKickEvent event) {
Player player = event.getPlayer();
if (DiscordLink.getPlugin().getDatabase().playerIsLinked(player))
return;
String authCode = Utilities.getAuthKey();
DiscordLink.getPlugin().getCache().removeCachedPlayer(player.getUniqueId());
DiscordLink.getPlugin().getCache()
.cacheCode(player.getUniqueId(), authCode);
event.appendTemplates(Template.of("code", authCode));
event.appendMessage("\n\n" + Config.WHITELIST_LINK_MESSAGE);
}
}