mirror of
https://github.com/Shimeo98/DiscordWhitelisterSpigot.git
synced 2024-12-01 07:03:36 +01:00
Added config option for showing player count. Moved join & leave Events to a new class.
This commit is contained in:
parent
dda4a8f33e
commit
be4bc8fff5
@ -102,15 +102,20 @@ public class DiscordClient extends ListenerAdapter {
|
||||
removeCommandInfo = embedBuilderInfo.build();
|
||||
}
|
||||
|
||||
public static String getOnlineStatus() {
|
||||
try {
|
||||
public static String getOnlineStatus()
|
||||
{
|
||||
try
|
||||
{
|
||||
return javaDiscordAPI.getStatus().name();
|
||||
} catch(NullPointerException ex) {
|
||||
}
|
||||
catch(NullPointerException ex)
|
||||
{
|
||||
return "OFFLINE";
|
||||
}
|
||||
}
|
||||
|
||||
public static void onServerPlayerCountChange(int playerCount) {
|
||||
public static void SetPlayerCountStatus(int playerCount)
|
||||
{
|
||||
javaDiscordAPI.getPresence().setActivity(Activity.watching(playerCount + "/" + DiscordWhitelister.getMaximumAllowedPlayers() + " players."));
|
||||
}
|
||||
|
||||
|
@ -11,12 +11,13 @@ 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;
|
||||
import uk.co.angrybee.joe.Events.JoinLeaveEvents;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class DiscordWhitelister extends JavaPlugin implements Listener
|
||||
public class DiscordWhitelister extends JavaPlugin
|
||||
{
|
||||
private static File whitelisterBotConfigFile;
|
||||
private static File userListFile;
|
||||
@ -118,9 +119,14 @@ public class DiscordWhitelister extends JavaPlugin implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
DiscordClient.onServerPlayerCountChange(getOnlineUsers());
|
||||
if(getWhitelisterBotConfig().getBoolean("show-player-count"))
|
||||
{
|
||||
// Register events if enabled
|
||||
getServer().getPluginManager().registerEvents(new JoinLeaveEvents(), this);
|
||||
|
||||
// Set initial player count
|
||||
DiscordClient.SetPlayerCountStatus(getOnlineUsers());
|
||||
}
|
||||
}
|
||||
|
||||
public static JavaPlugin getPlugin()
|
||||
@ -179,16 +185,6 @@ public class DiscordWhitelister extends JavaPlugin implements Listener
|
||||
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(); }
|
||||
@ -400,6 +396,16 @@ public class DiscordWhitelister extends JavaPlugin implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
if(getWhitelisterBotConfig().get("show-player-count") == null)
|
||||
{
|
||||
getWhitelisterBotConfig().set("show-player-count", true);
|
||||
|
||||
if(!configCreated)
|
||||
{
|
||||
getPlugin().getLogger().warning("Entry 'show-player-count' was not found, adding it to the config...");
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
getWhitelisterBotConfig().save((whitelisterBotConfigFile.getPath()));
|
||||
|
25
src/main/java/uk/co/angrybee/joe/Events/JoinLeaveEvents.java
Normal file
25
src/main/java/uk/co/angrybee/joe/Events/JoinLeaveEvents.java
Normal file
@ -0,0 +1,25 @@
|
||||
package uk.co.angrybee.joe.Events;
|
||||
|
||||
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||
import uk.co.angrybee.joe.DiscordClient;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
// Used for showing player count in the discord bots status
|
||||
public class JoinLeaveEvents implements Listener
|
||||
{
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
DiscordClient.SetPlayerCountStatus(DiscordWhitelister.getOnlineUsers());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event)
|
||||
{
|
||||
DiscordClient.SetPlayerCountStatus(DiscordWhitelister.getOnlineUsers() - 1);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user