diff --git a/README.md b/README.md index 4aaf19e..fcfd785 100755 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A simple spigot plugin which allows whitelisting through a discord text channel. Features: -- use '!whitelist MinecraftUsername' in a valid channel to whitelist people on your minecraft server +- use '!whitelist ' in a valid channel to whitelist people on your minecraft server - only select Discord roles can whitelist through the bot - bot only listens for messages in select text channels - logs whitelist attempts from valid roles in the console diff --git a/plugin.yml b/plugin.yml index b6e4a16..9a3aad0 100755 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: DiscordWhitelister -version: 1.0.0 +version: 1.0.1 author: Joe Shimell main: uk.co.angrybee.joe.DiscordWhitelister description: Discord whitelister bot. diff --git a/src/main/java/uk/co/angrybee/joe/DiscordWhitelister.java b/src/main/java/uk/co/angrybee/joe/DiscordWhitelister.java index 99d14ca..f49ee0c 100755 --- a/src/main/java/uk/co/angrybee/joe/DiscordWhitelister.java +++ b/src/main/java/uk/co/angrybee/joe/DiscordWhitelister.java @@ -1,5 +1,6 @@ package uk.co.angrybee.joe; +import org.bukkit.Server; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -47,6 +48,14 @@ public class DiscordWhitelister extends JavaPlugin { getLogger().info("Initializing Discord client"); serverDiscordClient = new ServerDiscordClient(); + + serverDiscordClient.allowedToUseRoles = new String[DiscordWhitelister.getWhitelisterBotConfig().getList("allowed-to-use-roles").size()]; + + for(int roles = 0; roles < serverDiscordClient.allowedToUseRoles.length; ++roles) + { + serverDiscordClient.allowedToUseRoles[roles] = DiscordWhitelister.getWhitelisterBotConfig().getList("allowed-to-use-roles").get(roles).toString(); + } + serverDiscordClient.InitializeClient(botToken); getLogger().info("Successfully initialized Discord client"); } diff --git a/src/main/java/uk/co/angrybee/joe/ServerDiscordClient.java b/src/main/java/uk/co/angrybee/joe/ServerDiscordClient.java index 103f138..b5cfbad 100755 --- a/src/main/java/uk/co/angrybee/joe/ServerDiscordClient.java +++ b/src/main/java/uk/co/angrybee/joe/ServerDiscordClient.java @@ -23,6 +23,8 @@ import java.util.Arrays; // handles Discord interaction public class ServerDiscordClient extends ListenerAdapter { + public static String[] allowedToUseRoles; + public void InitializeClient(String clientToken) { try @@ -63,13 +65,6 @@ public class ServerDiscordClient extends ListenerAdapter boolean userHasPerms = false; - String[] allowedToUseRoles = new String[DiscordWhitelister.getWhitelisterBotConfig().getList("allowed-to-use-roles").size()]; - - for(int roles = 0; roles < allowedToUseRoles.length; ++roles) - { - allowedToUseRoles[roles] = DiscordWhitelister.getWhitelisterBotConfig().getList("allowed-to-use-roles").get(roles).toString(); - } - for(Role role : messageReceivedEvent.getGuild().getMember(messageReceivedEvent.getAuthor()).getRoles()) { if(Arrays.stream(allowedToUseRoles).parallel().anyMatch(role.getName()::contains)) @@ -89,7 +84,9 @@ public class ServerDiscordClient extends ListenerAdapter if(finalNameToWhitelist.isEmpty()) { - channel.sendMessage(author.getAsMention() + ", please enter a valid Minecraft username").queue(); + channel.sendMessage(author.getAsMention() + ", Whitelist command usage:" + System.lineSeparator() + + "```!whitelist " + System.lineSeparator() + + "If you encounter an issue, please report it here: https://github.com/JoeShimo/DiscordWhitelisterBot-Spigot/issues```").queue(); } else {