From 48a194622a651a67c3bf54a8aa6f03ce0b1f1e7a Mon Sep 17 00:00:00 2001 From: vacer25 Date: Mon, 27 Apr 2020 00:08:19 -0400 Subject: [PATCH] Fixed bug in player count when vanished and normal players join. Updated role error messages. Increased version to 1.3.3 --- plugin.yml | 2 +- src/main/java/uk/co/angrybee/joe/DiscordClient.java | 8 ++++---- .../java/uk/co/angrybee/joe/DiscordWhitelister.java | 10 +++++++++- .../uk/co/angrybee/joe/Events/JoinLeaveEvents.java | 2 ++ src/main/java/uk/co/angrybee/joe/VersionInfo.java | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/plugin.yml b/plugin.yml index d16e648..f2c73f1 100755 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: DiscordWhitelister -version: 1.3.2 +version: 1.3.3 author: Joe Shimell main: uk.co.angrybee.joe.DiscordWhitelister description: Discord whitelister bot. diff --git a/src/main/java/uk/co/angrybee/joe/DiscordClient.java b/src/main/java/uk/co/angrybee/joe/DiscordClient.java index 8338eb5..fe80460 100644 --- a/src/main/java/uk/co/angrybee/joe/DiscordClient.java +++ b/src/main/java/uk/co/angrybee/joe/DiscordClient.java @@ -386,7 +386,7 @@ public class DiscordClient extends ListenerAdapter { Member member = messageReceivedEvent.getMember(); messageReceivedEvent.getGuild().addRoleToMember(member, whitelistRole).queue(); } catch (Exception e) { - DiscordWhitelister.getPlugin().getLogger().severe("Could not add role with name " + whitelistedRoleName + " to " + author.getName() + ", check that it has the correct name in the config"); + DiscordWhitelister.getPlugin().getLogger().severe("Could not add role with name " + whitelistedRoleName + " to " + author.getName() + ", check that it has the correct name in the config and the bot has the Manage Roles permission"); } } @@ -415,7 +415,7 @@ public class DiscordClient extends ListenerAdapter { Member member = messageReceivedEvent.getMember(); messageReceivedEvent.getGuild().addRoleToMember(member, whitelistRole).queue(); } catch (Exception e) { - DiscordWhitelister.getPlugin().getLogger().severe("Could not add role with name " + whitelistedRoleName + " to " + author.getName() + ", check that it has the correct name in the config"); + DiscordWhitelister.getPlugin().getLogger().severe("Could not add role with name " + whitelistedRoleName + " to " + author.getName() + ", check that it has the correct name in the config and the bot has the Manage Roles permission"); } } @@ -527,7 +527,7 @@ public class DiscordClient extends ListenerAdapter { Member member = messageReceivedEvent.getMember(); messageReceivedEvent.getGuild().removeRoleFromMember(member, whitelistRole).queue(); } catch (Exception e) { - DiscordWhitelister.getPlugin().getLogger().severe("Could not remove role with name " + whitelistedRoleName + " from " + author.getName() + ", check that it has the correct name in the config"); + DiscordWhitelister.getPlugin().getLogger().severe("Could not remove role with name " + whitelistedRoleName + " from " + author.getName() + ", check that it has the correct name in the config and the bot has the Manage Roles permission"); } } @@ -555,7 +555,7 @@ public class DiscordClient extends ListenerAdapter { Member member = messageReceivedEvent.getMember(); messageReceivedEvent.getGuild().removeRoleFromMember(member, whitelistRole).queue(); } catch (Exception e) { - DiscordWhitelister.getPlugin().getLogger().severe("Could not remove role with name " + whitelistedRoleName + " from " + author.getName() + ", check that it has the correct name in the config"); + DiscordWhitelister.getPlugin().getLogger().severe("Could not remove role with name " + whitelistedRoleName + " from " + author.getName() + ", check that it has the correct name in the config and the bot has the Manage Roles permission"); } } diff --git a/src/main/java/uk/co/angrybee/joe/DiscordWhitelister.java b/src/main/java/uk/co/angrybee/joe/DiscordWhitelister.java index 9e0168a..281cf51 100755 --- a/src/main/java/uk/co/angrybee/joe/DiscordWhitelister.java +++ b/src/main/java/uk/co/angrybee/joe/DiscordWhitelister.java @@ -42,6 +42,9 @@ public class DiscordWhitelister extends JavaPlugin private static JavaPlugin thisPlugin; + // For not counting vanished players when other players join/leave + private static int vanishedPlayersCount; + @Override public void onEnable() { @@ -49,6 +52,7 @@ public class DiscordWhitelister extends JavaPlugin whitelisterBotConfig = new YamlConfiguration(); userList = new YamlConfiguration(); removedList = new YamlConfiguration(); + vanishedPlayersCount = 0; ConfigSetup(); @@ -186,7 +190,11 @@ public class DiscordWhitelister extends JavaPlugin getUserList().save(getUserListFile().getPath()); } - public static int getOnlineUsers() { return thisPlugin.getServer().getOnlinePlayers().size(); } + public static void addVanishedPlayer() { vanishedPlayersCount++; } + + public static void removeVanishedPlayer() { vanishedPlayersCount--; } + + public static int getOnlineUsers() { return thisPlugin.getServer().getOnlinePlayers().size() - vanishedPlayersCount; } public static int getMaximumAllowedPlayers() { return thisPlugin.getServer().getMaxPlayers(); } diff --git a/src/main/java/uk/co/angrybee/joe/Events/JoinLeaveEvents.java b/src/main/java/uk/co/angrybee/joe/Events/JoinLeaveEvents.java index 3ef4035..1236838 100644 --- a/src/main/java/uk/co/angrybee/joe/Events/JoinLeaveEvents.java +++ b/src/main/java/uk/co/angrybee/joe/Events/JoinLeaveEvents.java @@ -18,6 +18,7 @@ public class JoinLeaveEvents implements Listener event.getPlayer().hasPermission("discordsrv.silentquit") || event.getPlayer().hasPermission("sv.joinvanished")) { DiscordWhitelister.getPlugin().getLogger().info("Player " + event.getPlayer().getDisplayName() + " joined with silent joining/quitting permission, not incrementing player count"); + DiscordWhitelister.addVanishedPlayer(); return; } DiscordClient.SetPlayerCountStatus(DiscordWhitelister.getOnlineUsers()); @@ -30,6 +31,7 @@ public class JoinLeaveEvents implements Listener event.getPlayer().hasPermission("discordsrv.silentquit") || event.getPlayer().hasPermission("sv.joinvanished")) { DiscordWhitelister.getPlugin().getLogger().info("Player " + event.getPlayer().getDisplayName() + " quit with silent joining/quitting permission, not decrementing player count"); + DiscordWhitelister.removeVanishedPlayer(); return; } DiscordClient.SetPlayerCountStatus(DiscordWhitelister.getOnlineUsers() - 1); diff --git a/src/main/java/uk/co/angrybee/joe/VersionInfo.java b/src/main/java/uk/co/angrybee/joe/VersionInfo.java index f71c3cb..050a976 100644 --- a/src/main/java/uk/co/angrybee/joe/VersionInfo.java +++ b/src/main/java/uk/co/angrybee/joe/VersionInfo.java @@ -9,5 +9,5 @@ public class VersionInfo { return "v." + getVersion(); } - private static String version = "1.3.2"; + private static String version = "1.3.3"; }