Merge pull request #6 from timroejr/feature/DiscordActivityIndicator

Feature: Added Discord Activity Indicator
This commit is contained in:
Joe Shimell 2020-04-20 12:22:53 +01:00 committed by GitHub
commit dda4a8f33e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -110,6 +110,10 @@ public class DiscordClient extends ListenerAdapter {
}
}
public static void onServerPlayerCountChange(int playerCount) {
javaDiscordAPI.getPresence().setActivity(Activity.watching(playerCount + "/" + DiscordWhitelister.getMaximumAllowedPlayers() + " players."));
}
@Override
public void onMessageReceived(MessageReceivedEvent messageReceivedEvent) {
if (messageReceivedEvent.isFromType(ChannelType.TEXT)) {

View File

@ -5,6 +5,10 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.Listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import uk.co.angrybee.joe.Commands.CommandAbout;
import uk.co.angrybee.joe.Commands.CommandStatus;
@ -12,7 +16,7 @@ import java.io.File;
import java.io.IOException;
import java.util.*;
public class DiscordWhitelister extends JavaPlugin
public class DiscordWhitelister extends JavaPlugin implements Listener
{
private static File whitelisterBotConfigFile;
private static File userListFile;
@ -113,6 +117,10 @@ public class DiscordWhitelister extends JavaPlugin
getLogger().severe("Discord Client failed to initialize, please check if your config file is valid.");
}
}
this.getServer().getPluginManager().registerEvents(this, this);
DiscordClient.onServerPlayerCountChange(getOnlineUsers());
}
public static JavaPlugin getPlugin()
@ -171,6 +179,20 @@ public class DiscordWhitelister extends JavaPlugin
getUserList().save(getUserListFile().getPath());
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
DiscordClient.onServerPlayerCountChange(getOnlineUsers());
}
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
DiscordClient.onServerPlayerCountChange(getOnlineUsers() - 1);
}
public static int getOnlineUsers() { return thisPlugin.getServer().getOnlinePlayers().size(); }
public static int getMaximumAllowedPlayers() { return thisPlugin.getServer().getMaxPlayers(); }
public void ConfigSetup()
{
whitelisterBotConfigFile = new File(getDataFolder(), "discord-whitelister.yml");