mirror of
https://github.com/Shimeo98/DiscordWhitelisterSpigot.git
synced 2024-12-01 07:03:36 +01:00
Added Activity to Discord Bot to show number of Users Online.
This commit is contained in:
parent
fdfba50f86
commit
8cb168260a
@ -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)) {
|
||||
|
@ -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,9 @@ 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);
|
||||
|
||||
}
|
||||
|
||||
public static JavaPlugin getPlugin()
|
||||
@ -171,6 +178,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");
|
||||
|
Loading…
Reference in New Issue
Block a user