Scoreboard

Discussion in 'Spigot Plugin Development' started by Angeles, Jun 6, 2017.

  1. Code (Text):
    [19:34:42 ERROR]: Could not pass event PlayerJoinEvent to Nexus v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:297) ~[paperspigot.jar:git-PaperSpigot-a925999]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[paperspigot.jar:git-PaperSpigot-a925999]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:513) [paperspigot.jar:git-PaperSpigot-a925999]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:498) [paperspigot.jar:git-PaperSpigot-a925999]
            at net.minecraft.server.v1_7_R4.PlayerList.c(PlayerList.java:305) [paperspigot.jar:git-PaperSpigot-a925999]
            at net.minecraft.server.v1_7_R4.PlayerList.a(PlayerList.java:192) [paperspigot.jar:git-PaperSpigot-a925999]
            at net.minecraft.server.v1_7_R4.LoginListener.c(LoginListener.java:119) [paperspigot.jar:git-PaperSpigot-a925999]
            at net.minecraft.server.v1_7_R4.LoginListener.a(LoginListener.java:44) [paperspigot.jar:git-PaperSpigot-a925999]
            at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:192) [paperspigot.jar:git-PaperSpigot-a925999]
            at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:103) [paperspigot.jar:git-PaperSpigot-a925999]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:801) [paperspigot.jar:git-PaperSpigot-a925999]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:286) [paperspigot.jar:git-PaperSpigot-a925999]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:651) [paperspigot.jar:git-PaperSpigot-a925999]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:557) [paperspigot.jar:git-PaperSpigot-a925999]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [paperspigot.jar:git-PaperSpigot-a925999]
    Caused by: java.lang.NullPointerException
            at io.complete.scoreboard.ScoreboardAdapter.getRank(ScoreboardAdapter.java:40) ~[?:?]
            at io.complete.scoreboard.ScoreboardAdapter.onPlayerJoin(ScoreboardAdapter.java:32) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_101]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_101]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_101]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:293) ~[paperspigot.jar:git-PaperSpigot-a925999]
            ... 14 more
    Code (Text):
    import org.bukkit.Bukkit;
    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 com.alexandeh.glaedr.scoreboards.Entry;
    import com.alexandeh.glaedr.scoreboards.PlayerScoreboard;
    import com.google.common.io.ByteArrayDataInput;
    import com.google.common.io.ByteStreams;

    import io.complete.Nexus;
    import net.milkbowl.vault.permission.Permission;

    public class ScoreboardAdapter implements Listener
    {
         public static int Online = 1;
         public static Permission perms = null;
         Player[] aplayer;
         int players = (aplayer = Bukkit.getOnlinePlayers()).length;
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e)
        {
            Player player = e.getPlayer();
            PlayerScoreboard scoreboard = PlayerScoreboard.getScoreboard(player);
            new Entry("Online", scoreboard).setCountdown(false).setText(ChatColor.GOLD + "Online" + ChatColor.GRAY + ": " + Online).send();
            new Entry("1", scoreboard).setCountdown(false).setText(ChatColor.GOLD + "").send();
            new Entry("Rank", scoreboard).setCountdown(false).setText(ChatColor.GOLD + "Rank" + ChatColor.GRAY + ": " + getRank(player)).send();
            new Entry("1", scoreboard).setCountdown(false).setText(ChatColor.GOLD + "").send();
            new Entry("Store", scoreboard).setCountdown(false).setText(ChatColor.GOLD + "store.nexus.com").send();
            new Entry("1", scoreboard).setCountdown(false).setText(ChatColor.GOLD + "").send();
            new Entry("ProfileSync", scoreboard).setCountdown(true).setText(ChatColor.GREEN + ChatColor.BOLD.toString() + "Profile Sync" + ": " + ChatColor.GRAY).setTime(10).send();
        }
       
        public String getRank(Player p) {
            if (Nexus.getInstance().getConfig().getString("rank." + perms.getPrimaryGroup(p).toLowerCase()) != null) {
                return Nexus.getInstance().getConfig().getString("rank." + perms.getPrimaryGroup(p).toLowerCase());
            }
            return perms.getPrimaryGroup(p);
        }
       
        public void onPluginMessageReceived(String channel, Player player, byte[] message) {
            if (!channel.equals("BungeeCord")) {
                return;
            }
            try {
                ByteArrayDataInput in = ByteStreams.newDataInput(message);
                String command = in.readUTF();

                if (command.equals("PlayerCount")) {
                    String subchannel = in.readUTF();
                    if (subchannel.equals("ALL")) {
                        int playercount = in.readInt();
                        Online = playercount;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
     
  2. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    NPE means that something in your code is null when trying to act on it. Check what's on line 40, and dissect what could be returning null.
    No offense, but NPEs really don't merit a forum post (unless it's part of Spigot).
     
  3. Code (Text):
    Caused by: java.lang.NullPointerException
            at io.complete.scoreboard.ScoreboardAdapter.getRank(ScoreboardAdapter.java:40) ~[?:?]
    I noticed that you imported some sort of Nexus plugin but I don't see any way to access its methods. It's possible that this section of code:
    Code (Text):
    Nexus.getInstance().getConfig().getString("rank." + perms.getPrimaryGroup(p).toLowerCase()) != null
    isn't actually grabbing anything. I had a similar problem with a Banknote plugin. I found a way around my issue but I couldn't access anything because that plugin didn't have support for it.
     
  4. The problem is coming from you trying to use .getRank(); maybe your permission plugin isn't supported?