Re-structured configs

This commit is contained in:
Teriuihi 2022-12-18 21:35:37 +01:00
parent fd9ed1f8eb
commit 7b895443ab
17 changed files with 174 additions and 134 deletions

View File

@ -23,7 +23,6 @@ import com.velocitypowered.api.proxy.ProxyServer;
import java.io.File;
import java.nio.file.Path;
import java.sql.SQLException;
import java.util.logging.Logger;
@Plugin(id = "proxydiscordlink", name = "ProxyDiscordLink", version = "1.0.0",
description = "A plugin that links Discord accounts with uuid's",
@ -34,14 +33,14 @@ public class DiscordLink {
private static DiscordLink plugin;
private final ProxyServer server;
private final Logger logger;
private final ALogger logger;
private final Path dataDirectory;
private final Database database;
private final Cache cache;
private Bot bot;
@Inject
public DiscordLink(ProxyServer proxyServer, Logger proxyLogger, @DataDirectory Path proxydataDirectory)
public DiscordLink(ProxyServer proxyServer, ALogger proxyLogger, @DataDirectory Path proxydataDirectory)
{
plugin = this;
server = proxyServer;
@ -59,8 +58,8 @@ public class DiscordLink {
DatabaseConnection.initialize();
} catch (SQLException exception) {
exception.printStackTrace();
getLogger().severe("*** Could not connect to the database. ***");
getLogger().severe("*** This plugin will be disabled. ***");
ALogger.error("*** Could not connect to the database. ***");
ALogger.error("*** This plugin will be disabled. ***");
//TODO shutdown plugin
}
loadCommands();
@ -99,7 +98,7 @@ public class DiscordLink {
return plugin;
}
public Logger getLogger() {
public ALogger getLogger() {
return logger;
}

View File

@ -11,7 +11,7 @@ import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.exceptions.HierarchyException;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.requests.GatewayIntent;
@ -29,7 +29,7 @@ public class Bot {
disconnect();
try {
jda = JDABuilder
.createDefault(BotConfig.BOT_TOKEN)
.createDefault(BotConfig.DISCORD.BOT_TOKEN)
.setMemberCachePolicy(MemberCachePolicy.ALL)
.enableIntents(GatewayIntent.GUILD_MEMBERS)
.build();
@ -37,8 +37,8 @@ public class Bot {
jda.addEventListener(new DiscordMessageListener(),
new DiscordRoleListener());
DiscordCommand.loadCommands();
} catch (LoginException e) {
jda = null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@ -224,9 +224,9 @@ public class Bot {
private void discordBan(Member member, @Nullable String optionalReason) {
try {
if (optionalReason == null)
member.ban(0).queue();
member.ban(0, TimeUnit.DAYS).queue();
else
member.ban(0, optionalReason).queue();
member.ban(0, TimeUnit.DAYS).reason(optionalReason).queue();
} catch (InsufficientPermissionException exception) {
ALogger.warn("Unable to ban " + member.getAsMention() + " : " + member.getId() + " from Discord they might be above me.");
}

View File

@ -161,27 +161,31 @@ public class BotConfig {
return config.getNode(splitPath(path));
}
/**
* ONLY EDIT ANYTHING BELOW THIS LINE
**/
@SuppressWarnings("unused")
private static void loadSubclasses() {
BotConfig.DISCORD.settings();
}
public static class DISCORD {
public static String BOT_TOKEN = "unconfigured";
public static long COMMAND_CHANNEL = -1;
public static long STAFF_COMMAND_CHANNEL = -1;
public static long LINK_CHANNEL = -1;
public static long GUILD_ID = -1;
public static long EVIDENCE_CHANNEL_ID = -1;
public static long LINKED_ROLE_ID = -1;
public static String BOT_TOKEN = "unconfigured";
public static long COMMAND_CHANNEL = -1;
public static long STAFF_COMMAND_CHANNEL = -1;
public static long LINK_CHANNEL = -1;
public static long GUILD_ID = -1;
public static long EVIDENCE_CHANNEL_ID = -1;
public static long LINKED_ROLE_ID = -1;
private static void settings() {
BOT_TOKEN = getString("settings.token", BOT_TOKEN);
STAFF_COMMAND_CHANNEL = getLong("settings.staff-command-channel", STAFF_COMMAND_CHANNEL);
COMMAND_CHANNEL = getLong("settings.command-channel", COMMAND_CHANNEL);
LINK_CHANNEL = getLong("settings.link-channel", LINK_CHANNEL);
GUILD_ID = getLong("settings.guild-id", GUILD_ID);
EVIDENCE_CHANNEL_ID = getLong("settings.evidence-channel-id", EVIDENCE_CHANNEL_ID);
LINKED_ROLE_ID = getLong("settings.linked-role-id", LINKED_ROLE_ID);
private static void settings() {
BOT_TOKEN = getString("settings.token", BOT_TOKEN);
STAFF_COMMAND_CHANNEL = getLong("settings.staff-command-channel", STAFF_COMMAND_CHANNEL);
COMMAND_CHANNEL = getLong("settings.command-channel", COMMAND_CHANNEL);
LINK_CHANNEL = getLong("settings.link-channel", LINK_CHANNEL);
GUILD_ID = getLong("settings.guild-id", GUILD_ID);
EVIDENCE_CHANNEL_ID = getLong("settings.evidence-channel-id", EVIDENCE_CHANNEL_ID);
LINKED_ROLE_ID = getLong("settings.linked-role-id", LINKED_ROLE_ID);
}
}
public static String SL_MINIMUMRANK = "trainee";

View File

@ -161,68 +161,81 @@ public final class Config {
/**
* ONLY EDIT ANYTHING BELOW THIS LINE
**/
public static String DRIVERS = "mysql";
public static String IP = "localhost";
public static String PORT = "3306";
public static String DATABASE_NAME = "discordlink";
public static String USERNAME = "root";
public static String PASSWORD = "root";
private static void database() {
DRIVERS = getString("database.drivers", DRIVERS);
IP = getString("database.ip", IP);
PORT = getString("database.port", PORT);
DATABASE_NAME = getString("database.database_name", DATABASE_NAME);
USERNAME = getString("database.username", USERNAME);
PASSWORD = getString("database.password", PASSWORD);
}
public static List<String> DONOR_GROUPS = new ArrayList<>(List.of("donor"));
public static List<String> DISCORD_GROUPS = new ArrayList<>(List.of("nitro"));
@SuppressWarnings("unused")
private static void loadGroups() {
DONOR_GROUPS = getList("settings.donor-groups", DONOR_GROUPS);
DISCORD_GROUPS = getList("settings.discord-groups", DISCORD_GROUPS);
}
public static List<String> DISCORD_MESSAGE = new ArrayList<>(List.of("Invite code here."));
public static String DISCORD_LINK = "<click:run:command:discord link:><yellow>Your Minecraft and Discord accounts aren't linked yet, to link them click this message!</yellow></click>";
public static String GIVE_CODE = "<yellow>Your code is <gold><code></gold>, To link your accounts do <gold>&link <code></gold> in the Discord #link channel.</yellow>";
public static String ALREADY_LINKED_ACCOUNTS = "<yellow>Your accounts are already linked. You can unlink your accounts by doing <gold>/discord unlink</gold>.</yellow>";
public static String ALREADY_GOT_CODE = "<yellow>You have already got your code. Your code is <gold><code><gold></yellow>";
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>";
public static String RELOAD_CONFIG = "<green>Reloaded DiscordLink config.</green>";
public static String HELP_MESSAGE = "<yellow>DiscordLink commands:\n<commands></yellow>";
public static String HELP_LINK = "<yellow><gold>/discord link</gold>: Get a code which can be used to link 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_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>";
@SuppressWarnings("unused")
private static void loadSubclasses() {
DB.database();
MESSAGES.loadMessages();
}
private static void loadMessages() {
DISCORD_MESSAGE = getList("messages.discord-message", DISCORD_MESSAGE);
DISCORD_LINK = getString("messages.discord-link", DISCORD_LINK);
GIVE_CODE = getString("messages.give-code", GIVE_CODE);
ALREADY_LINKED_ACCOUNTS = getString("messages.already-linked-accounts", ALREADY_LINKED_ACCOUNTS);
ALREADY_GOT_CODE = getString("messages.already-got-code", ALREADY_GOT_CODE);
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);
RELOAD_CONFIG = getString("messages.reload-config", RELOAD_CONFIG);
HELP_MESSAGE = getString("messages.help-message", HELP_MESSAGE);
HELP_LINK = getString("messages.help-link", HELP_LINK);
HELP_UNLINK = getString("messages.help-unlink", HELP_UNLINK);
HELP_CHECK_LINKED = getString("messages.help-check-linked", HELP_CHECK_LINKED);
HELP_RELOAD = getString("messages.help-reload", HELP_RELOAD);
public static class DB {
public static String DRIVERS = "mysql";
public static String IP = "localhost";
public static String PORT = "3306";
public static String DATABASE_NAME = "discordlink";
public static String USERNAME = "root";
public static String PASSWORD = "root";
private static void database() {
DRIVERS = getString("database.drivers", DRIVERS);
IP = getString("database.ip", IP);
PORT = getString("database.port", PORT);
DATABASE_NAME = getString("database.database_name", DATABASE_NAME);
USERNAME = getString("database.username", USERNAME);
PASSWORD = getString("database.password", PASSWORD);
}
}
public static class MESSAGES {
public static String ALREADY_LINKED_ACCOUNTS = "<yellow>Your accounts are already linked. You can unlink your accounts by doing <gold>/discord unlink</gold>.</yellow>";
public static String ALREADY_GOT_CODE = "<yellow>You have already got your code. Your code is <gold><code><gold></yellow>";
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>";
public static String RELOAD_CONFIG = "<green>Reloaded DiscordLink config.</green>";
public static String HELP_MESSAGE = "<yellow>DiscordLink commands:\n<commands></yellow>";
public static String HELP_LINK = "<yellow><gold>/discord link</gold>: Get a code which can be used to link 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_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>";
public static List<String> DISCORD_MESSAGE = new ArrayList<>(List.of("Invite code here."));
public static String DISCORD_LINK = "<click:run:command:discord link:><yellow>Your Minecraft and Discord accounts aren't linked yet, to link them click this message!</yellow></click>";
public static String GIVE_CODE = "<yellow>Your code is <gold><code></gold>, To link your accounts do <gold>&link <code></gold> in the Discord #link channel.</yellow>";
private static void loadMessages() {
DISCORD_MESSAGE = getList("messages.discord-message", DISCORD_MESSAGE);
DISCORD_LINK = getString("messages.discord-link", DISCORD_LINK);
GIVE_CODE = getString("messages.give-code", GIVE_CODE);
ALREADY_LINKED_ACCOUNTS = getString("messages.already-linked-accounts", ALREADY_LINKED_ACCOUNTS);
ALREADY_GOT_CODE = getString("messages.already-got-code", ALREADY_GOT_CODE);
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);
RELOAD_CONFIG = getString("messages.reload-config", RELOAD_CONFIG);
HELP_MESSAGE = getString("messages.help-message", HELP_MESSAGE);
HELP_LINK = getString("messages.help-link", HELP_LINK);
HELP_UNLINK = getString("messages.help-unlink", HELP_UNLINK);
HELP_CHECK_LINKED = getString("messages.help-check-linked", HELP_CHECK_LINKED);
HELP_RELOAD = getString("messages.help-reload", HELP_RELOAD);
}
}
}

View File

@ -29,11 +29,11 @@ public class DatabaseConnection {
e.printStackTrace();
}
this.connection = DriverManager.getConnection("jdbc:"
+ Config.DRIVERS + "://"
+ Config.IP + ":"
+ Config.PORT + "/"
+ Config.DATABASE_NAME
+ "?autoReconnect=true&useSSL=false", Config.USERNAME, Config.PASSWORD);
+ Config.DB.DRIVERS + "://"
+ Config.DB.IP + ":"
+ Config.DB.PORT + "/"
+ Config.DB.DATABASE_NAME
+ "?autoReconnect=true&useSSL=false", Config.DB.USERNAME, Config.DB.PASSWORD);
}
}
}

View File

@ -34,11 +34,11 @@ public class MinecraftCommand implements SimpleCommand {
if (args.length < 1) {
if (!source.hasPermission("discordlink.link"))
source.sendMessage(miniMessage.deserialize(Config.NO_PERMISSION));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.NO_PERMISSION));
else if (source instanceof Player)
source.sendMessage(miniMessage.deserialize(Config.DISCORD_LINK));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.DISCORD_LINK));
else
source.sendMessage(miniMessage.deserialize(Config.NO_CONSOLE));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.NO_CONSOLE));
return;
}
@ -98,6 +98,6 @@ public class MinecraftCommand implements SimpleCommand {
if (stringBuilder.length() != 0)
stringBuilder.replace(stringBuilder.length() - 1, stringBuilder.length(), "");
return miniMessage.deserialize(Config.HELP_MESSAGE, Placeholder.unparsed("commands", stringBuilder.toString()));
return miniMessage.deserialize(Config.MESSAGES.HELP_MESSAGE, Placeholder.unparsed("commands", stringBuilder.toString()));
}
}

View File

@ -37,7 +37,7 @@ public class CheckLinked implements SubCommand {
@Override
public void execute(String[] args, CommandSource source) {
if (!source.hasPermission(getPermission())) {
source.sendMessage(miniMessage.deserialize(Config.NO_PERMISSION));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.NO_PERMISSION));
return;
}
if (args.length != 2 || !args[1].matches("\\w{3,16}")) {
@ -54,7 +54,7 @@ public class CheckLinked implements SubCommand {
.getPlayer(UUID.fromString(uuidFromName));
if (optionalPlayer.isEmpty())
{
source.sendMessage(miniMessage.deserialize(Config.INVALID_PLAYER, Placeholder.unparsed("player", args[1])));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.INVALID_PLAYER, Placeholder.unparsed("player", args[1])));
return;
}
}
@ -68,7 +68,7 @@ public class CheckLinked implements SubCommand {
.playerIsLinked(player.getUniqueId()) ? "linked" : "not linked"),
Placeholder.unparsed("player", player.getUsername()));
source.sendMessage(miniMessage.deserialize(Config.IS_LINKED, tagResolver));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.IS_LINKED, tagResolver));
}
@Override
@ -78,6 +78,6 @@ public class CheckLinked implements SubCommand {
@Override
public String getHelpMessage() {
return Config.HELP_CHECK_LINKED;
return Config.MESSAGES.HELP_CHECK_LINKED;
}
}

View File

@ -36,11 +36,11 @@ public class Link implements SubCommand {
@Override
public void execute(String[] args, CommandSource source) {
if (!(source instanceof Player player)) {
source.sendMessage(miniMessage.deserialize(Config.NO_CONSOLE));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.NO_CONSOLE));
return;
}
if (!player.hasPermission(getPermission())) {
source.sendMessage(miniMessage.deserialize(Config.NO_PERMISSION));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.NO_PERMISSION));
return;
}
@ -51,18 +51,18 @@ public class Link implements SubCommand {
Database database = DiscordLink.getPlugin().getDatabase();
if (database.playerIsLinked(player.getUniqueId())) {
player.sendMessage(miniMessage.deserialize(Config.ALREADY_LINKED_ACCOUNTS));
player.sendMessage(miniMessage.deserialize(Config.MESSAGES.ALREADY_LINKED_ACCOUNTS));
return;
}
String authCode = DiscordLink.getPlugin().getCache().getCode(player.getUniqueId());
if (authCode != null) {
player.sendMessage(miniMessage.deserialize(Config.ALREADY_GOT_CODE, Placeholder.unparsed("code", authCode)));
player.sendMessage(miniMessage.deserialize(Config.MESSAGES.ALREADY_GOT_CODE, Placeholder.unparsed("code", authCode)));
return;
}
authCode = Utilities.getAuthKey();
player.sendMessage(miniMessage.deserialize(Config.GIVE_CODE, Placeholder.unparsed("code", authCode)));
player.sendMessage(miniMessage.deserialize(Config.MESSAGES.GIVE_CODE, Placeholder.unparsed("code", authCode)));
DiscordLink.getPlugin().getCache()
.cacheCode(player.getUniqueId(), authCode);
}
@ -74,6 +74,6 @@ public class Link implements SubCommand {
@Override
public String getHelpMessage() {
return Config.HELP_LINK;
return Config.MESSAGES.HELP_LINK;
}
}

View File

@ -34,7 +34,7 @@ public class Reload implements SubCommand {
@Override
public void execute(String[] args, CommandSource source) {
DiscordLink.getPlugin().reloadConfig();
source.sendMessage(miniMessage.deserialize(Config.RELOAD_CONFIG));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.RELOAD_CONFIG));
}
@Override
@ -44,6 +44,6 @@ public class Reload implements SubCommand {
@Override
public String getHelpMessage() {
return Config.HELP_RELOAD;
return Config.MESSAGES.HELP_RELOAD;
}
}

View File

@ -45,16 +45,16 @@ public class Sync implements SubCommand { //TODO implement
@Override
public void execute(String[] args, CommandSource source) {
if (!(source instanceof Player player)) {
source.sendMessage(miniMessage.deserialize(Config.NO_CONSOLE));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.NO_CONSOLE));
return;
}
if (!player.hasPermission(getPermission())) {
source.sendMessage(miniMessage.deserialize(Config.NO_PERMISSION));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.NO_PERMISSION));
return;
}
User user = Utilities.getLuckPerms().getUserManager().getUser(player.getUniqueId());
if (user == null) {
source.sendMessage(miniMessage.deserialize(Config.INVALID_PLAYER));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.INVALID_PLAYER));
return;
}
player.sendMessage(syncAccounts(user));
@ -64,7 +64,7 @@ public class Sync implements SubCommand { //TODO implement
Database database = DiscordLink.getPlugin().getDatabase();
if (!database.playerIsLinked(user.getUniqueId())) {
return miniMessage.deserialize(Config.ACCOUNTS_NOT_LINKED);
return miniMessage.deserialize(Config.MESSAGES.ACCOUNTS_NOT_LINKED);
}
DiscordLinkPlayer discordLinkPlayer = DiscordLinkPlayer.getDiscordLinkPlayer(user.getUniqueId());
@ -83,6 +83,6 @@ public class Sync implements SubCommand { //TODO implement
@Override
public String getHelpMessage() {
return Config.HELP_SYNC;
return Config.MESSAGES.HELP_SYNC;
}
}

View File

@ -46,11 +46,11 @@ public class Unlink implements SubCommand {
unlinkOther(args, source);
}
if (!(source instanceof Player player)) {
source.sendMessage(miniMessage.deserialize(Config.NO_CONSOLE));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.NO_CONSOLE));
return;
}
if (!player.hasPermission(getPermission())) {
source.sendMessage(miniMessage.deserialize(Config.NO_PERMISSION));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.NO_PERMISSION));
return;
}
@ -59,12 +59,12 @@ public class Unlink implements SubCommand {
private void unlinkOther(String[] args, CommandSource source) {
if (!source.hasPermission(getPermission() + ".other")) {
source.sendMessage(miniMessage.deserialize(Config.NO_PERMISSION));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.NO_PERMISSION));
return;
}
User user = Utilities.getLuckPerms().getUserManager().getUser(args[1]);
if (user == null) {
source.sendMessage(miniMessage.deserialize(Config.INVALID_PLAYER));
source.sendMessage(miniMessage.deserialize(Config.MESSAGES.INVALID_PLAYER));
return;
}
@ -75,7 +75,7 @@ public class Unlink implements SubCommand {
Database database = DiscordLink.getPlugin().getDatabase();
if (!database.playerIsLinked(uuid)) {
return miniMessage.deserialize(Config.ACCOUNTS_NOT_LINKED);
return miniMessage.deserialize(Config.MESSAGES.ACCOUNTS_NOT_LINKED);
}
DiscordLinkPlayer discordLinkPlayer = DiscordLinkPlayer.getDiscordLinkPlayer(uuid);
@ -91,7 +91,7 @@ public class Unlink implements SubCommand {
.filter(role -> discordLinkPlayer.getRoles().contains(role.getInternalName()))
.collect(Collectors.toList()),
false);
return miniMessage.deserialize(Config.UNLINKED_ACCOUNTS);
return miniMessage.deserialize(Config.MESSAGES.UNLINKED_ACCOUNTS);
}
@Override
@ -101,6 +101,6 @@ public class Unlink implements SubCommand {
@Override
public String getHelpMessage() {
return Config.HELP_UNLINK;
return Config.MESSAGES.HELP_UNLINK;
}
}

View File

@ -45,14 +45,14 @@ public class LiteBansBanListener {
return;
discordLinkPlayer.setActive(false);
DiscordLink.getPlugin().getBot().discordBan(BotConfig.GUILD_ID, discordLinkPlayer.getUserId(), "Auto ban due to Minecraft ban");
DiscordLink.getPlugin().getBot().discordBan(BotConfig.DISCORD.GUILD_ID, discordLinkPlayer.getUserId(), "Auto ban due to Minecraft ban");
Optional<Player> player = DiscordLink.getPlugin().getProxy().getPlayer(uuid);
String username = discordLinkPlayer.getUsername();
if (player.isPresent())
username = player.get().getUsername();
DiscordLink.getPlugin().getBot().sendEmbedToDiscord(BotConfig.EVIDENCE_CHANNEL_ID,
DiscordLink.getPlugin().getBot().sendEmbedToDiscord(BotConfig.DISCORD.EVIDENCE_CHANNEL_ID,
new EmbedBuilder()
.setColor(Color.RED)
.setAuthor(username, null, "https://crafatar.com/avatars/" + stringUuid + "?overlay")
@ -74,7 +74,7 @@ public class LiteBansBanListener {
if (uuid == null)
return;
DiscordLinkPlayer discordLinkPlayer = DiscordLinkPlayer.getDiscordLinkPlayer(UUID.fromString(uuid));
DiscordLink.getPlugin().getBot().discordUnban(BotConfig.GUILD_ID, discordLinkPlayer.getUserId());
DiscordLink.getPlugin().getBot().discordUnban(BotConfig.DISCORD.GUILD_ID, discordLinkPlayer.getUserId());
}
}

View File

@ -27,7 +27,7 @@ public class PlayerJoin {
sync = true;
if (!discordLinkPlayer.hasNick())
DiscordLink.getPlugin().getBot().changeNick(BotConfig.GUILD_ID, discordLinkPlayer.getUserId(), username);
DiscordLink.getPlugin().getBot().changeNick(BotConfig.DISCORD.GUILD_ID, discordLinkPlayer.getUserId(), username);
}
if (discordLinkPlayer.hasNick()) { //If they have a nick update it, if nick is empty set it to false and use username
@ -36,7 +36,7 @@ public class PlayerJoin {
discordLinkPlayer.setNick(false);
nick = discordLinkPlayer.getUsername();
}
DiscordLink.getPlugin().getBot().changeNick(BotConfig.GUILD_ID, discordLinkPlayer.getUserId(), nick);
DiscordLink.getPlugin().getBot().changeNick(BotConfig.DISCORD.GUILD_ID, discordLinkPlayer.getUserId(), nick);
}
if (sync) //Sync if needed

View File

@ -24,6 +24,6 @@ public class WhitelistKick {
HashMap<String, String> stringStringHashMap = new HashMap<>();
stringStringHashMap.put("code", authCode);
event.appendTemplate(stringStringHashMap);
event.appendMessage("\n\n" + Config.WHITELIST_LINK_MESSAGE);
event.appendMessage("\n\n" + Config.MESSAGES.WHITELIST_LINK_MESSAGE);
}
}

View File

@ -89,9 +89,9 @@ public class DiscordLinkPlayer {
public void updateDiscord(List<DiscordRole> roles, boolean added) {
if (added)
roles.stream().filter(DiscordRole::isUpdateToDiscord).forEach(role -> DiscordLink.getPlugin().getBot().addRole(userId, role.getId(), BotConfig.GUILD_ID));
roles.stream().filter(DiscordRole::isUpdateToDiscord).forEach(role -> DiscordLink.getPlugin().getBot().addRole(userId, role.getId(), BotConfig.DISCORD.GUILD_ID));
else
roles.stream().filter(DiscordRole::isUpdateToDiscord).forEach(role -> DiscordLink.getPlugin().getBot().removeRole(userId, role.getId(), BotConfig.GUILD_ID));
roles.stream().filter(DiscordRole::isUpdateToDiscord).forEach(role -> DiscordLink.getPlugin().getBot().removeRole(userId, role.getId(), BotConfig.DISCORD.GUILD_ID));
}
public void updateMinecraft(List<DiscordRole> roles, boolean added) {
@ -111,9 +111,9 @@ public class DiscordLinkPlayer {
public void linkedRole(boolean add) {
if (add)
DiscordLink.getPlugin().getBot().addRole(userId, BotConfig.LINKED_ROLE_ID, BotConfig.GUILD_ID);
DiscordLink.getPlugin().getBot().addRole(userId, BotConfig.DISCORD.LINKED_ROLE_ID, BotConfig.DISCORD.GUILD_ID);
else
DiscordLink.getPlugin().getBot().removeRole(userId, BotConfig.LINKED_ROLE_ID, BotConfig.GUILD_ID);
DiscordLink.getPlugin().getBot().removeRole(userId, BotConfig.DISCORD.LINKED_ROLE_ID, BotConfig.DISCORD.GUILD_ID);
}
public void unlinkDiscordLinkPlayer() {

View File

@ -1,29 +1,26 @@
package com.alttd.proxydiscordlink.util;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ALogger {
private static Logger logger;
private static ALogger logger;
public static void init(Logger log) {
public static void init(ALogger log) {
logger = log;
}
private void log(String message) {
logger.info(message);
logger.log(message);
}
public static void warn(String message) {
logger.warning(message);
logger.log("WARNING: " + message);
}
public static void info(String message) {
logger.info(message);
logger.log("INFO: " + message);
}
public static void error(String message) {
logger.log(Level.SEVERE, message);
logger.log("ERROR: " + message);
}
}

View File

@ -1,12 +1,18 @@
package com.alttd.proxydiscordlink.util;
import com.alttd.proxydiscordlink.DiscordLink;
import com.alttd.proxydiscordlink.bot.commandManager.CommandManager;
import com.alttd.proxydiscordlink.bot.objects.DiscordRole;
import com.alttd.proxydiscordlink.config.BotConfig;
import com.alttd.proxydiscordlink.config.Config;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.requests.RestAction;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
@ -130,4 +136,25 @@ public class Utilities {
})
.collect(Collectors.toList());
}
public static void registerCommand(CommandManager commandManager, JDA jda, CommandData commandData, String commandName) {
Guild guild = jda.getGuildById(BotConfig.DISCORD.GUILD_ID);
if (guild == null) {
ALogger.error("Unable to find guild id to register commands");
return;
}
registerCommand(guild, commandData, commandName);
}
public static void registerCommand(Guild guild, CommandData commandData, String commandName) {
guild.upsertCommand(commandData).queue(RestAction.getDefaultSuccess(), Utilities::handleFailure);
}
public static void ignoreSuccess(Object o) {
// IDK I thought this looked nicer in the .queue call
}
public static void handleFailure(Throwable failure) {
ALogger.error(failure.getMessage());
}
}