Fixed being unable to unlink

This commit is contained in:
Teriuihi 2021-09-20 02:36:47 +02:00
parent 722e1ea01b
commit 42931b2761
6 changed files with 8 additions and 10 deletions

View File

@ -93,6 +93,7 @@ public class DiscordLinkCommand extends DiscordCommand {
.queue(message1 -> message1.delete().queueAfter(5, TimeUnit.SECONDS)); .queue(message1 -> message1.delete().queueAfter(5, TimeUnit.SECONDS));
DiscordLinkPlayer.addDiscordLinkPlayer(discordLinkPlayer); DiscordLinkPlayer.addDiscordLinkPlayer(discordLinkPlayer);
DiscordLink.getPlugin().getDatabase().syncPlayer(discordLinkPlayer);
DiscordLink.getPlugin().getCache().removeCachedPlayer(discordLinkPlayer.getUuid()); DiscordLink.getPlugin().getCache().removeCachedPlayer(discordLinkPlayer.getUuid());
} }

View File

@ -42,7 +42,7 @@ public class DiscordUnlink extends DiscordCommand {
message.getChannel().sendMessage("Your accounts aren't linked.").queue(); message.getChannel().sendMessage("Your accounts aren't linked.").queue();
return; return;
} }
database.removeLinkedAccount(discordLinkPlayer.getUuid()); database.removeLinkedAccount(discordLinkPlayer);
discordLinkPlayer.updateDiscord( discordLinkPlayer.updateDiscord(
DiscordRole.getDiscordRoles().stream() DiscordRole.getDiscordRoles().stream()

View File

@ -85,16 +85,16 @@ public class Database {
return false; return false;
} }
public void removeLinkedAccount(UUID uuid) { public void removeLinkedAccount(DiscordLinkPlayer player) {
try { try {
PreparedStatement statement = DatabaseConnection.getConnection() PreparedStatement statement = DatabaseConnection.getConnection()
.prepareStatement("DELETE FROM linked_accounts WHERE discord_id = ?"); .prepareStatement("DELETE FROM linked_accounts WHERE discord_id = ?");
statement.setString(1, uuid.toString()); statement.setLong(1, player.getUserId());
statement.executeUpdate(); statement.executeUpdate();
PreparedStatement statement2 = DatabaseConnection.getConnection() PreparedStatement statement2 = DatabaseConnection.getConnection()
.prepareStatement("DELETE FROM account_roles WHERE discord_id = ?"); .prepareStatement("DELETE FROM account_roles WHERE uuid = ?");
statement2.setString(1, uuid.toString()); statement2.setString(1, player.getUuid().toString());
statement2.executeUpdate(); statement2.executeUpdate();
} catch (SQLException var2) { } catch (SQLException var2) {
var2.printStackTrace(); var2.printStackTrace();

View File

@ -59,7 +59,7 @@ public class Unlink implements SubCommand {
} }
DiscordLinkPlayer discordLinkPlayer = DiscordLinkPlayer.getDiscordLinkPlayer(player.getUniqueId()); DiscordLinkPlayer discordLinkPlayer = DiscordLinkPlayer.getDiscordLinkPlayer(player.getUniqueId());
database.removeLinkedAccount(discordLinkPlayer.getUuid()); database.removeLinkedAccount(discordLinkPlayer);
discordLinkPlayer.updateDiscord( discordLinkPlayer.updateDiscord(
DiscordRole.getDiscordRoles().stream() DiscordRole.getDiscordRoles().stream()

View File

@ -41,7 +41,7 @@ public class LuckpermsEvents {
if (discordLinkPlayer == null) if (discordLinkPlayer == null)
return; return;
discordLinkPlayer.updateMinecraft(List.of(optional.get()), added); discordLinkPlayer.updateDiscord(List.of(optional.get()), added);
} }
} }

View File

@ -69,8 +69,6 @@ public class DiscordLinkPlayer {
roles.stream().filter(DiscordRole::isUpdateToDiscord).forEach(role -> DiscordLink.getPlugin().getBot().addRole(userId, role.getId(), BotConfig.GUILD_ID)); //TODO test roles.stream().filter(DiscordRole::isUpdateToDiscord).forEach(role -> DiscordLink.getPlugin().getBot().addRole(userId, role.getId(), BotConfig.GUILD_ID)); //TODO test
else else
roles.stream().filter(DiscordRole::isUpdateToDiscord).forEach(role -> DiscordLink.getPlugin().getBot().removeRole(userId, role.getId(), BotConfig.GUILD_ID)); //TODO test roles.stream().filter(DiscordRole::isUpdateToDiscord).forEach(role -> DiscordLink.getPlugin().getBot().removeRole(userId, role.getId(), BotConfig.GUILD_ID)); //TODO test
DiscordLink.getPlugin().getDatabase().syncPlayer(this);
//TODO implement //TODO implement
//TODO SYNC ROLES TO DATABASE //TODO SYNC ROLES TO DATABASE
} }
@ -88,7 +86,6 @@ public class DiscordLinkPlayer {
user.data().remove(group); user.data().remove(group);
}); });
}); });
DiscordLink.getPlugin().getDatabase().syncPlayer(this);
//TODO implement //TODO implement
//TODO SYNC ROLES TO DATABASE //TODO SYNC ROLES TO DATABASE
} }