Merge pull request #9 from vacer25/Bugfix2

Fixed bug in player count when vanished and normal players join/leave.
This commit is contained in:
Joe Shimell 2020-04-27 09:21:48 +01:00 committed by GitHub
commit 36f81a2948
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 7 deletions

View File

@ -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.

View File

@ -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");
}
}

View File

@ -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(); }

View File

@ -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);

View File

@ -9,5 +9,5 @@ public class VersionInfo {
return "v." + getVersion();
}
private static String version = "1.3.2";
private static String version = "1.3.3";
}