[FEATURE] Staff whitelist/linking commands

This commit is contained in:
2023-09-10 17:54:25 +02:00
parent 6f7477fe84
commit 627e9bb83b
7 changed files with 228 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
version_major=0 version_major=0
version_minor=0 version_minor=0
version_patch=17 version_patch=18
shade_group=com.hypherionmc.sdlink.shaded. shade_group=com.hypherionmc.sdlink.shaded.

View File

@@ -108,6 +108,10 @@ public class MinecraftAccount {
* @param guild The server the command is run from * @param guild The server the command is run from
*/ */
public Result linkAccount(Member member, Guild guild) { public Result linkAccount(Member member, Guild guild) {
return this.linkAccount(member, guild, true);
}
public Result linkAccount(Member member, Guild guild, boolean updateNick) {
if (getStoredAccount() == null) { if (getStoredAccount() == null) {
return Result.error("We couldn't link your Minecraft and Discord Accounts together. If this error persists, please ask a staff member for help"); return Result.error("We couldn't link your Minecraft and Discord Accounts together. If this error persists, please ask a staff member for help");
} }
@@ -130,7 +134,7 @@ public class MinecraftAccount {
String finalnickname = SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.nicknameFormat.replace("%nick%", nickname).replace("%mcname%", suffix); String finalnickname = SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.nicknameFormat.replace("%nick%", nickname).replace("%mcname%", suffix);
if (SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.changeNickname) { if (SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.changeNickname && updateNick) {
try { try {
member.modifyNickname(finalnickname).queue(); member.modifyNickname(finalnickname).queue();
@@ -332,7 +336,9 @@ public class MinecraftAccount {
*/ */
public SDLinkAccount getStoredAccount() { public SDLinkAccount getStoredAccount() {
sdlinkDatabase.reloadCollection("accounts"); sdlinkDatabase.reloadCollection("accounts");
return sdlinkDatabase.findById(this.uuid.toString(), SDLinkAccount.class); SDLinkAccount account = sdlinkDatabase.findById(this.uuid.toString(), SDLinkAccount.class);
return account == null ? newDBEntry() : account;
} }
/** /**

View File

@@ -8,14 +8,8 @@ import com.hypherionmc.sdlink.core.config.SDLinkConfig;
import com.hypherionmc.sdlink.core.discord.commands.slash.general.HelpSlashCommand; import com.hypherionmc.sdlink.core.discord.commands.slash.general.HelpSlashCommand;
import com.hypherionmc.sdlink.core.discord.commands.slash.general.PlayerListSlashCommand; import com.hypherionmc.sdlink.core.discord.commands.slash.general.PlayerListSlashCommand;
import com.hypherionmc.sdlink.core.discord.commands.slash.general.ServerStatusSlashCommand; import com.hypherionmc.sdlink.core.discord.commands.slash.general.ServerStatusSlashCommand;
import com.hypherionmc.sdlink.core.discord.commands.slash.linking.ConfirmAccountLinkSlashCommand; import com.hypherionmc.sdlink.core.discord.commands.slash.linking.*;
import com.hypherionmc.sdlink.core.discord.commands.slash.linking.LinkAccountCommand; import com.hypherionmc.sdlink.core.discord.commands.slash.whitelist.*;
import com.hypherionmc.sdlink.core.discord.commands.slash.linking.UnlinkAccountSlashCommand;
import com.hypherionmc.sdlink.core.discord.commands.slash.linking.ViewLinkedAccountsCommand;
import com.hypherionmc.sdlink.core.discord.commands.slash.whitelist.ConfirmWhitelistSlashCommand;
import com.hypherionmc.sdlink.core.discord.commands.slash.whitelist.UnWhitelistAccountSlashCommand;
import com.hypherionmc.sdlink.core.discord.commands.slash.whitelist.ViewWhitelistedAccountsSlashCommand;
import com.hypherionmc.sdlink.core.discord.commands.slash.whitelist.WhitelistAccountCommand;
import com.jagrosh.jdautilities.command.CommandClient; import com.jagrosh.jdautilities.command.CommandClient;
import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommand;
@@ -61,6 +55,12 @@ public class CommandManager {
// Enable the Help command // Enable the Help command
commands.add(new HelpSlashCommand()); commands.add(new HelpSlashCommand());
// Staff commands
commands.add(new StaffLinkCommand());
commands.add(new StaffUnlinkCommand());
commands.add(new StaffWhitelist());
commands.add(new StaffUnwhitelist());
} }
/** /**

View File

@@ -0,0 +1,47 @@
package com.hypherionmc.sdlink.core.discord.commands.slash.linking;
import com.hypherionmc.sdlink.core.accounts.MinecraftAccount;
import com.hypherionmc.sdlink.core.discord.commands.slash.SDLinkSlashCommand;
import com.hypherionmc.sdlink.core.messaging.Result;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import java.util.ArrayList;
import java.util.List;
public class StaffLinkCommand extends SDLinkSlashCommand {
public StaffLinkCommand() {
super(true);
this.name = "stafflink";
this.help = "Allow staff members to link other minecraft players, without verification";
List<OptionData> options = new ArrayList<>() {{
add(new OptionData(OptionType.USER, "discorduser", "The discord user the minecraft account belongs to").setRequired(true));
add(new OptionData(OptionType.STRING, "mcname", "The minecraft account to link to the user").setRequired(true));
}};
this.options = options;
}
@Override
protected void execute(SlashCommandEvent event) {
String mcname = event.getOption("mcname").getAsString();
User user = event.getOption("discorduser").getAsUser();
Member member = event.getGuild().getMemberById(user.getId());
if (member == null) {
event.reply(user.getEffectiveName() + " is not a member of this discord server").setEphemeral(true).queue();
return;
}
MinecraftAccount minecraftAccount = MinecraftAccount.standard(mcname);
Result result = minecraftAccount.linkAccount(member, event.getGuild(), false);
event.reply(result.getMessage()).setEphemeral(true).queue();
}
}

View File

@@ -0,0 +1,59 @@
package com.hypherionmc.sdlink.core.discord.commands.slash.linking;
import com.hypherionmc.sdlink.core.accounts.MinecraftAccount;
import com.hypherionmc.sdlink.core.database.SDLinkAccount;
import com.hypherionmc.sdlink.core.discord.commands.slash.SDLinkSlashCommand;
import com.hypherionmc.sdlink.core.messaging.Result;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static com.hypherionmc.sdlink.core.managers.DatabaseManager.sdlinkDatabase;
public class StaffUnlinkCommand extends SDLinkSlashCommand {
public StaffUnlinkCommand() {
super(false);
this.name = "staffunlink";
this.help = "Unlink another linked Discord and Minecraft account";
List<OptionData> options = new ArrayList<>() {{
add(new OptionData(OptionType.USER, "discorduser", "The discord user the minecraft account belongs to").setRequired(true));
add(new OptionData(OptionType.STRING, "mcname", "The minecraft account of the linked user").setRequired(true));
}};
this.options = options;
}
@Override
protected void execute(SlashCommandEvent event) {
sdlinkDatabase.reloadCollection("accounts");
List<SDLinkAccount> accounts = sdlinkDatabase.findAll(SDLinkAccount.class);
if (accounts.isEmpty()) {
event.reply("Sorry, but this server does not contain any stored players in its database").setEphemeral(true).queue();
return;
}
String mcname = event.getOption("mcname").getAsString();
User user = event.getOption("discorduser").getAsUser();
Member member = event.getGuild().getMemberById(user.getId());
if (member == null) {
event.reply(user.getEffectiveName() + " is not a member of this discord server").setEphemeral(true).queue();
return;
}
MinecraftAccount minecraftAccount = MinecraftAccount.standard(mcname);
Result result = minecraftAccount.unlinkAccount(member, event.getGuild());
event.reply(result.getMessage()).setEphemeral(true).queue();
}
}

View File

@@ -0,0 +1,58 @@
package com.hypherionmc.sdlink.core.discord.commands.slash.whitelist;
import com.hypherionmc.sdlink.core.accounts.MinecraftAccount;
import com.hypherionmc.sdlink.core.database.SDLinkAccount;
import com.hypherionmc.sdlink.core.discord.commands.slash.SDLinkSlashCommand;
import com.hypherionmc.sdlink.core.messaging.Result;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import java.util.ArrayList;
import java.util.List;
import static com.hypherionmc.sdlink.core.managers.DatabaseManager.sdlinkDatabase;
public class StaffUnwhitelist extends SDLinkSlashCommand {
public StaffUnwhitelist() {
super(false);
this.name = "staffunwhitelist";
this.help = "Unwhitelist another linked Discord and Minecraft account";
List<OptionData> options = new ArrayList<>() {{
add(new OptionData(OptionType.USER, "discorduser", "The discord user the minecraft account belongs to").setRequired(true));
add(new OptionData(OptionType.STRING, "mcname", "The minecraft account of the whitelisted user").setRequired(true));
}};
this.options = options;
}
@Override
protected void execute(SlashCommandEvent event) {
sdlinkDatabase.reloadCollection("accounts");
List<SDLinkAccount> accounts = sdlinkDatabase.findAll(SDLinkAccount.class);
if (accounts.isEmpty()) {
event.reply("Sorry, but this server does not contain any stored players in its database").setEphemeral(true).queue();
return;
}
String mcname = event.getOption("mcname").getAsString();
User user = event.getOption("discorduser").getAsUser();
Member member = event.getGuild().getMemberById(user.getId());
if (member == null) {
event.reply(user.getEffectiveName() + " is not a member of this discord server").setEphemeral(true).queue();
return;
}
MinecraftAccount minecraftAccount = MinecraftAccount.standard(mcname);
Result result = minecraftAccount.unwhitelistAccount(member, event.getGuild());
event.reply(result.getMessage()).setEphemeral(true).queue();
}
}

View File

@@ -0,0 +1,47 @@
package com.hypherionmc.sdlink.core.discord.commands.slash.whitelist;
import com.hypherionmc.sdlink.core.accounts.MinecraftAccount;
import com.hypherionmc.sdlink.core.discord.commands.slash.SDLinkSlashCommand;
import com.hypherionmc.sdlink.core.messaging.Result;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import java.util.ArrayList;
import java.util.List;
public class StaffWhitelist extends SDLinkSlashCommand {
public StaffWhitelist() {
super(true);
this.name = "staffwhitelist";
this.help = "Allow staff members to whitelist other minecraft players, without verification";
List<OptionData> options = new ArrayList<>() {{
add(new OptionData(OptionType.USER, "discorduser", "The discord user the minecraft account belongs to").setRequired(true));
add(new OptionData(OptionType.STRING, "mcname", "The minecraft account to link to the user").setRequired(true));
}};
this.options = options;
}
@Override
protected void execute(SlashCommandEvent event) {
String mcname = event.getOption("mcname").getAsString();
User user = event.getOption("discorduser").getAsUser();
Member member = event.getGuild().getMemberById(user.getId());
if (member == null) {
event.reply(user.getEffectiveName() + " is not a member of this discord server").setEphemeral(true).queue();
return;
}
MinecraftAccount minecraftAccount = MinecraftAccount.standard(mcname);
Result result = minecraftAccount.whitelistAccount(member, event.getGuild());
event.reply(result.getMessage()).setEphemeral(true).queue();
}
}