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_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_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_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() {
|
private static void loadMessages() {
|
||||||
DISCORD_MESSAGE = getList("messages.discord-message", DISCORD_MESSAGE);
|
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 {
|
try {
|
||||||
PreparedStatement statement = DatabaseConnection.getConnection()
|
PreparedStatement statement = DatabaseConnection.getConnection()
|
||||||
.prepareStatement("SELECT * FROM linked_accounts WHERE player_uuid = ?");
|
.prepareStatement("SELECT * FROM linked_accounts WHERE player_uuid = ?");
|
||||||
statement.setString(1, player.getUniqueId().toString());
|
statement.setString(1,uuid.toString());
|
||||||
ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ public class CheckLinked implements SubCommand {
|
||||||
private void isLinked(CommandSource source, Player player) {
|
private void isLinked(CommandSource source, Player player) {
|
||||||
List<Template> templates = List.of(
|
List<Template> templates = List.of(
|
||||||
Template.of("linked_status", DiscordLink.getPlugin().getDatabase()
|
Template.of("linked_status", DiscordLink.getPlugin().getDatabase()
|
||||||
.playerIsLinked(player) ? "linked" : "not linked"),
|
.playerIsLinked(player.getUniqueId()) ? "linked" : "not linked"),
|
||||||
Template.of("player", player.getUsername()));
|
Template.of("player", player.getUsername()));
|
||||||
|
|
||||||
source.sendMessage(miniMessage.parse(Config.IS_LINKED, templates));
|
source.sendMessage(miniMessage.parse(Config.IS_LINKED, templates));
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ public class Link implements SubCommand {
|
||||||
private void startLinkAccounts(Player player) {
|
private void startLinkAccounts(Player player) {
|
||||||
Database database = DiscordLink.getPlugin().getDatabase();
|
Database database = DiscordLink.getPlugin().getDatabase();
|
||||||
|
|
||||||
if (database.playerIsLinked(player)) {
|
if (database.playerIsLinked(player.getUniqueId())) {
|
||||||
player.sendMessage(miniMessage.parse(Config.ALREADY_LINKED_ACCOUNTS));
|
player.sendMessage(miniMessage.parse(Config.ALREADY_LINKED_ACCOUNTS));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,20 @@ package com.alttd.proxydiscordlink.minecraft.commands.subcommands;
|
||||||
|
|
||||||
import com.alttd.proxydiscordlink.DiscordLink;
|
import com.alttd.proxydiscordlink.DiscordLink;
|
||||||
import com.alttd.proxydiscordlink.bot.objects.DiscordRole;
|
import com.alttd.proxydiscordlink.bot.objects.DiscordRole;
|
||||||
import com.alttd.proxydiscordlink.minecraft.commands.SubCommand;
|
|
||||||
import com.alttd.proxydiscordlink.config.Config;
|
import com.alttd.proxydiscordlink.config.Config;
|
||||||
import com.alttd.proxydiscordlink.database.Database;
|
import com.alttd.proxydiscordlink.database.Database;
|
||||||
|
import com.alttd.proxydiscordlink.minecraft.commands.SubCommand;
|
||||||
import com.alttd.proxydiscordlink.objects.DiscordLinkPlayer;
|
import com.alttd.proxydiscordlink.objects.DiscordLinkPlayer;
|
||||||
|
import com.alttd.proxydiscordlink.util.Utilities;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.luckperms.api.model.user.User;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Unlink implements SubCommand {
|
public class Unlink implements SubCommand {
|
||||||
|
|
@ -38,6 +42,9 @@ public class Unlink implements SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(String[] args, CommandSource source) {
|
public void execute(String[] args, CommandSource source) {
|
||||||
|
if (args.length > 1) {
|
||||||
|
unlinkOther(args, source);
|
||||||
|
}
|
||||||
if (!(source instanceof Player player)) {
|
if (!(source instanceof Player player)) {
|
||||||
source.sendMessage(miniMessage.parse(Config.NO_CONSOLE));
|
source.sendMessage(miniMessage.parse(Config.NO_CONSOLE));
|
||||||
return;
|
return;
|
||||||
|
|
@ -47,18 +54,31 @@ public class Unlink implements SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlinkAccounts(player);
|
player.sendMessage(unlinkAccounts(player.getUniqueId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unlinkAccounts(Player player) {
|
private void unlinkOther(String[] args, CommandSource source) {
|
||||||
Database database = DiscordLink.getPlugin().getDatabase();
|
if (!source.hasPermission(getPermission() + ".other")) {
|
||||||
|
source.sendMessage(miniMessage.parse(Config.NO_PERMISSION));
|
||||||
if (!database.playerIsLinked(player)) {
|
return;
|
||||||
player.sendMessage(miniMessage.parse(Config.ACCOUNTS_NOT_LINKED));
|
}
|
||||||
|
User user = Utilities.getLuckPerms().getUserManager().getUser(args[1]);
|
||||||
|
if (user == null) {
|
||||||
|
source.sendMessage(miniMessage.parse(Config.INVALID_PLAYER));
|
||||||
return;
|
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.setActive(false);
|
||||||
discordLinkPlayer.updateDiscord(
|
discordLinkPlayer.updateDiscord(
|
||||||
|
|
@ -71,7 +91,7 @@ public class Unlink implements SubCommand {
|
||||||
.filter(role -> discordLinkPlayer.getRoles().contains(role.getInternalName()))
|
.filter(role -> discordLinkPlayer.getRoles().contains(role.getInternalName()))
|
||||||
.collect(Collectors.toList()),
|
.collect(Collectors.toList()),
|
||||||
false);
|
false);
|
||||||
player.sendMessage(miniMessage.parse(Config.UNLINKED_ACCOUNTS));
|
return miniMessage.parse(Config.UNLINKED_ACCOUNTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ public class WhitelistKick {
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onWhitelistKick(WhitelistKickEvent event) {
|
public void onWhitelistKick(WhitelistKickEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (DiscordLink.getPlugin().getDatabase().playerIsLinked(player))
|
if (DiscordLink.getPlugin().getDatabase().playerIsLinked(player.getUniqueId()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String authCode = Utilities.getAuthKey();
|
String authCode = Utilities.getAuthKey();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user