Updated stuff
This commit is contained in:
parent
4b94502668
commit
ca303d267b
|
|
@ -203,6 +203,7 @@ public final class Config {
|
|||
public static String HELP_UNLINK = "<yellow><gold>/discord unlink</gold>: Unlink your Minecraft and Discord accounts.</yellow>";
|
||||
public static String HELP_CHECK_LINKED = "<yellow><gold>/discord checklinked <user></gold>: Check if the specified user has their Minecraft and Discord accounts linked.</yellow>";
|
||||
public static String HELP_RELOAD = "<yellow><gold>/discord reload</gold>: Reload the config.</yellow>";
|
||||
public static String HELP_SYNC = "<yellow><gold>/discord sync</gold>: Manually synchronize your roles across Discord and Minecraft.</yellow>";
|
||||
|
||||
private static void loadMessages() {
|
||||
DISCORD_MESSAGE = getList("messages.discord-message", DISCORD_MESSAGE);
|
||||
|
|
|
|||
|
|
@ -103,11 +103,11 @@ public class Database {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean playerIsLinked(Player player) { //TODO maybe this can be using the discord api instead? (or a cache idk)
|
||||
public boolean playerIsLinked(UUID uuid) { //TODO maybe this can be using the discord api instead? (or a cache idk)
|
||||
try {
|
||||
PreparedStatement statement = DatabaseConnection.getConnection()
|
||||
.prepareStatement("SELECT * FROM linked_accounts WHERE player_uuid = ?");
|
||||
statement.setString(1, player.getUniqueId().toString());
|
||||
statement.setString(1,uuid.toString());
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class CheckLinked implements SubCommand {
|
|||
private void isLinked(CommandSource source, Player player) {
|
||||
List<Template> templates = List.of(
|
||||
Template.of("linked_status", DiscordLink.getPlugin().getDatabase()
|
||||
.playerIsLinked(player) ? "linked" : "not linked"),
|
||||
.playerIsLinked(player.getUniqueId()) ? "linked" : "not linked"),
|
||||
Template.of("player", player.getUsername()));
|
||||
|
||||
source.sendMessage(miniMessage.parse(Config.IS_LINKED, templates));
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class Link implements SubCommand {
|
|||
private void startLinkAccounts(Player player) {
|
||||
Database database = DiscordLink.getPlugin().getDatabase();
|
||||
|
||||
if (database.playerIsLinked(player)) {
|
||||
if (database.playerIsLinked(player.getUniqueId())) {
|
||||
player.sendMessage(miniMessage.parse(Config.ALREADY_LINKED_ACCOUNTS));
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,16 +2,20 @@ package com.alttd.proxydiscordlink.minecraft.commands.subcommands;
|
|||
|
||||
import com.alttd.proxydiscordlink.DiscordLink;
|
||||
import com.alttd.proxydiscordlink.bot.objects.DiscordRole;
|
||||
import com.alttd.proxydiscordlink.minecraft.commands.SubCommand;
|
||||
import com.alttd.proxydiscordlink.config.Config;
|
||||
import com.alttd.proxydiscordlink.database.Database;
|
||||
import com.alttd.proxydiscordlink.minecraft.commands.SubCommand;
|
||||
import com.alttd.proxydiscordlink.objects.DiscordLinkPlayer;
|
||||
import com.alttd.proxydiscordlink.util.Utilities;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.luckperms.api.model.user.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Unlink implements SubCommand {
|
||||
|
|
@ -38,6 +42,9 @@ public class Unlink implements SubCommand {
|
|||
|
||||
@Override
|
||||
public void execute(String[] args, CommandSource source) {
|
||||
if (args.length > 1) {
|
||||
unlinkOther(args, source);
|
||||
}
|
||||
if (!(source instanceof Player player)) {
|
||||
source.sendMessage(miniMessage.parse(Config.NO_CONSOLE));
|
||||
return;
|
||||
|
|
@ -47,18 +54,31 @@ public class Unlink implements SubCommand {
|
|||
return;
|
||||
}
|
||||
|
||||
unlinkAccounts(player);
|
||||
player.sendMessage(unlinkAccounts(player.getUniqueId()));
|
||||
}
|
||||
|
||||
private void unlinkAccounts(Player player) {
|
||||
Database database = DiscordLink.getPlugin().getDatabase();
|
||||
|
||||
if (!database.playerIsLinked(player)) {
|
||||
player.sendMessage(miniMessage.parse(Config.ACCOUNTS_NOT_LINKED));
|
||||
private void unlinkOther(String[] args, CommandSource source) {
|
||||
if (!source.hasPermission(getPermission() + ".other")) {
|
||||
source.sendMessage(miniMessage.parse(Config.NO_PERMISSION));
|
||||
return;
|
||||
}
|
||||
User user = Utilities.getLuckPerms().getUserManager().getUser(args[1]);
|
||||
if (user == null) {
|
||||
source.sendMessage(miniMessage.parse(Config.INVALID_PLAYER));
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordLinkPlayer discordLinkPlayer = DiscordLinkPlayer.getDiscordLinkPlayer(player.getUniqueId());
|
||||
unlinkAccounts(user.getUniqueId());
|
||||
}
|
||||
|
||||
private Component unlinkAccounts(UUID uuid) {
|
||||
Database database = DiscordLink.getPlugin().getDatabase();
|
||||
|
||||
if (!database.playerIsLinked(uuid)) {
|
||||
return miniMessage.parse(Config.ACCOUNTS_NOT_LINKED);
|
||||
}
|
||||
|
||||
DiscordLinkPlayer discordLinkPlayer = DiscordLinkPlayer.getDiscordLinkPlayer(uuid);
|
||||
|
||||
discordLinkPlayer.setActive(false);
|
||||
discordLinkPlayer.updateDiscord(
|
||||
|
|
@ -71,7 +91,7 @@ public class Unlink implements SubCommand {
|
|||
.filter(role -> discordLinkPlayer.getRoles().contains(role.getInternalName()))
|
||||
.collect(Collectors.toList()),
|
||||
false);
|
||||
player.sendMessage(miniMessage.parse(Config.UNLINKED_ACCOUNTS));
|
||||
return miniMessage.parse(Config.UNLINKED_ACCOUNTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class WhitelistKick {
|
|||
@Subscribe
|
||||
public void onWhitelistKick(WhitelistKickEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (DiscordLink.getPlugin().getDatabase().playerIsLinked(player))
|
||||
if (DiscordLink.getPlugin().getDatabase().playerIsLinked(player.getUniqueId()))
|
||||
return;
|
||||
|
||||
String authCode = Utilities.getAuthKey();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user