Getting Player Count And Name Of Server

Discussion in 'Spigot Plugin Development' started by toxiccoke, May 17, 2015.

  1. Hi
    I was making a MOTD for my network and i wanted to get the player count of the network and the name of the server the player has connected to.
    This is what i have but i am getting errors and i cannot work out why
    Code (Text):

    package me.toxiccoke.core.Motd;

    import me.toxiccoke.core.Main;
    import me.toxiccoke.core.Chat.ChatUtils;
    import net.md_5.bungee.api.ProxyServer;
    import net.md_5.bungee.api.connection.ProxiedPlayer;

    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;

    public class MOTD implements Listener{
     
        Main plugin;
     
        @EventHandler
        public void onJoin(PlayerJoinEvent e){
            Player p = e.getPlayer();
            e.setJoinMessage(null);

            ChatUtils.sendMessage(p, ChatColor.YELLOW + "Welcome To " + ChatColor.RED + "Inferno Network");
            ChatUtils.sendMessage(p, ChatColor.YELLOW + "There are " + ChatColor.RED + p.getServer().getOnlinePlayers().length + ChatColor.YELLOW + " Player Online");
            ChatUtils.sendMessage(p, ChatColor.YELLOW + "Visit Our Website At " + ChatColor.RED + "");
            ChatUtils.sendMessage(p, ChatColor.YELLOW + "You Are Connected To " + "");
            ChatUtils.sendMessage(p, ChatColor.YELLOW + "Use " + ChatColor.RED + "/Server" + ChatColor.YELLOW + " To Switch Between Servers");
        }
     
        @EventHandler
        public void onQuit(PlayerQuitEvent e){
            e.setQuitMessage(null);
        }
     

    }
     
    If you would like anymore information then pls post below i will be happy to supply you with what i can to help me out
    thanks toxiccoke
     
  2. Post the errors.
     
  3. Code (Text):
    [18:40:26 ERROR]: Could not pass event PlayerJoinEvent to INCore v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:302) ~[spigot.jar:git-Spigot-1649]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[spigot.jar:git-Spigot-1649]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:514) [spigot.jar:git-Spigot-1649]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:499) [spigot.jar:git-Spigot-1649]
            at net.minecraft.server.v1_7_R4.PlayerList.c(PlayerList.java:265) [spigo
    t.jar:git-Spigot-1649]
            at net.minecraft.server.v1_7_R4.PlayerList.a(PlayerList.java:152) [spigo
    t.jar:git-Spigot-1649]
            at net.minecraft.server.v1_7_R4.LoginListener.c(LoginListener.java:119)
    [spigot.jar:git-Spigot-1649]
            at net.minecraft.server.v1_7_R4.LoginListener.a(LoginListener.java:44) [
    spigot.jar:git-Spigot-1649]
            at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:189
    ) [spigot.jar:git-Spigot-1649]
            at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java
    :81) [spigot.jar:git-Spigot-1649]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:7
    34) [spigot.jar:git-Spigot-1649]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    89) [spigot.jar:git-Spigot-1649]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    84) [spigot.jar:git-Spigot-1649]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :490) [spigot.jar:git-Spigot-1649]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [spigot.jar:git-Spigot-1649]
    Caused by: java.lang.NoClassDefFoundError: net/md_5/bungee/api/ProxyServer
            at me.toxiccoke.core.Motd.MOTD.onJoin(MOTD.java:27) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0
    _76]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0
    _76]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_76]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_76]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:298) ~[spigot.jar:git-Spigot-1649]
            ... 14 more
    Caused by: java.lang.ClassNotFoundException: net.md_5.bungee.api.ProxyServer
            at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.7.0_76]
            at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.7.0_76]
            at java.security.AccessController.doPrivileged(Native Method) ~[?:1.7.0_
    76]
            at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.7.0_76]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.
    java:101) ~[spigot.jar:git-Spigot-1649]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.
    java:86) ~[spigot.jar:git-Spigot-1649]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_76]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_76]
            at me.toxiccoke.core.Motd.MOTD.onJoin(MOTD.java:27) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0
    _76]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0
    _76]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_76]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_76]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:298) ~[spigot.jar:git-Spigot-1649]
            ... 14 more
     
  4. JamesJ

    Supporter

    You're using BungeeCord imports :3
     
  5. yes i am using bungee imports because i am using bungee code to get the name of the server you cant check the bungee config with spigot code
     
  6. ...but you aren't running a BungeeCord server, thus you don't have the BungeeCord classes.

    Use plugin messages to get the server's name.
     
  7. i have my bungee cord server running so...
     
    • Optimistic Optimistic x 1
  8. Your plugin should be on your spigot server. Your bungeecord server uses different classes so it uses different imports. If you want to get

    Code (Text):
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
                            out.writeUTF("PlayerCount");
                            out.writeUTF("servername");
                            player.sendPluginMessage(this, "BungeeCord", out.toByteArray());

    http://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/