Development Assistance Can't Fire Player Join Event

Discussion in 'Plugin Help/Development/Requests' started by FlipSide_Mike, Dec 12, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    FlipSide_Mike

    The PlayerJoinEvent for my plugin won't fire on player join, and leaves an error

    ERROR:
    Code:
    [00:19:21] [Server thread/ERROR]: Could not pass event PlayerJoinEvent to PrefixesPlus v1.0.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[spigot.jar:git-Spigot-1453]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1453]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1453]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-1453]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-1453]
        at net.minecraft.server.v1_7_R3.PlayerList.c(PlayerList.java:251) [spigot.jar:git-Spigot-1453]
        at net.minecraft.server.v1_7_R3.PlayerList.a(PlayerList.java:138) [spigot.jar:git-Spigot-1453]
        at net.minecraft.server.v1_7_R3.LoginListener.c(LoginListener.java:105) [spigot.jar:git-Spigot-1453]
        at net.minecraft.server.v1_7_R3.LoginListener.a(LoginListener.java:43) [spigot.jar:git-Spigot-1453]
        at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:179) [spigot.jar:git-Spigot-1453]
        at net.minecraft.server.v1_7_R3.ServerConnection.c(ServerConnection.java:77) [spigot.jar:git-Spigot-1453]
        at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:713) [spigot.jar:git-Spigot-1453]
        at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:283) [spigot.jar:git-Spigot-1453]
        at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:576) [spigot.jar:git-Spigot-1453]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:482) [spigot.jar:git-Spigot-1453]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1453]
    Caused by: java.lang.NullPointerException
        at com.AN.Petro.Prefix.Core.onJoin(Core.java:94) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_11]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_11]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1453]
        ... 15 more
    [00:19:21]
    EVENT:
    Code:
    @EventHandler
        public void onJoin(PlayerJoinEvent event){
            Player player = event.getPlayer();
            player.setScoreboard(sb);
            if(player.hasPermission("prefix.owner")) {
                OP.addPlayer(player);
            }
            else if(player.hasPermission("prefix.admin")) {
                ADMIN.addPlayer(player);
            }
            else if(player.hasPermission("prefix.srmod")) {
                SRMOD.addPlayer(player);
            }
            else if(player.hasPermission("prefix.mod")) {
                MOD.addPlayer(player);
            }
            else if(player.hasPermission("prefix.helper")) {
                HELPER.addPlayer(player);
            }
            else if(player.hasPermission("prefix.builder")) {
                BUILDER.addPlayer(player);
            }
            else if(player.hasPermission("prefix.youtuber")) {
                YOUTUBER.addPlayer(player);
            }
            else if(player.hasPermission("prefix.vip")) {
                VIP.addPlayer(player);
            } else {
                MEMBER.addPlayer(player);
            }
        }
    For those wondering Line 94 is
    Code:
    OP.addPlayer(player);
    Which leads me to wonder if the teams are made wrong, here is the full plugin

    Code:
    package com.AN.Petro.Prefix;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    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.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    import org.bukkit.scoreboard.Team;
    import ru.tehkode.permissions.PermissionUser;
    import ru.tehkode.permissions.bukkit.PermissionsEx;
    
    import java.util.ArrayList;
    import java.util.List;
    
    /**
    * * **************************************************************************************
    * Copyright TheFlipSide (c) 2014.  All Rights Reserved.
    * Any code contained within PrefixPlus (this document), and any associated APIs with similar branding
    * are the sole property of Michael Petramalo.  Distribution, reproduction, taking sections, or
    * claiming any contents as your own will break the terms of the license, and void any
    * agreements with the third-party, you.
    * Thanks.
    * Created on 12/10/2014 at 4:20 PM.
    * ******************************************************************************************
    */
    public class Core extends JavaPlugin implements Listener{
    
        List<Team> teams = new ArrayList<Team>();
    
        public String red = "&4";
        public String purple = "&5";
        public String green = "&2";
        public String lime = "&a";
        public String orange = "&6";
        public String pink = "&d";
        public String lightred = "&c";
        public String yellow = "&e";
        public String blue = "&9";
        public String bold = "&l";
        public String reset = "&r";
        public String space = " ";
    
        public static ScoreboardManager man = null;
        public static Scoreboard sb = null;
    
        public static Team OP = null;
        public static Team ADMIN = null;
        public static Team SRMOD = null;
        public static Team MOD = null;
        public static Team HELPER = null;
        public static Team BUILDER = null;
        public static Team YOUTUBER = null;
        public static Team VIP = null;
        public static Team MEMBER = null;
    
        @Override
        public void onEnable() {
            getLogger().info("PrefixPlus Enabing...");
            getServer().getPluginManager().registerEvents(this, this);
    
            man = Bukkit.getScoreboardManager();
            sb = man.getMainScoreboard();
    
            teams.add(OP);
            teams.add(ADMIN);
            teams.add(SRMOD);
            teams.add(MOD);
            teams.add(HELPER);
            teams.add(BUILDER);
            teams.add(YOUTUBER);
            teams.add(VIP);
            teams.add(MEMBER);
    
            scoreBoard();
        }
    
        @Override
        public void onDisable() {
            getLogger().info("PrefixPlus Disabling...");
        }
    
        @EventHandler
        public void onJoin(PlayerJoinEvent event){
            Player player = event.getPlayer();
            player.setScoreboard(sb);
            if(player.hasPermission("prefix.owner")) {
                OP.addPlayer(player);
            }
            else if(player.hasPermission("prefix.admin")) {
                ADMIN.addPlayer(player);
            }
            else if(player.hasPermission("prefix.srmod")) {
                SRMOD.addPlayer(player);
            }
            else if(player.hasPermission("prefix.mod")) {
                MOD.addPlayer(player);
            }
            else if(player.hasPermission("prefix.helper")) {
                HELPER.addPlayer(player);
            }
            else if(player.hasPermission("prefix.builder")) {
                BUILDER.addPlayer(player);
            }
            else if(player.hasPermission("prefix.youtuber")) {
                YOUTUBER.addPlayer(player);
            }
            else if(player.hasPermission("prefix.vip")) {
                VIP.addPlayer(player);
            } else {
                MEMBER.addPlayer(player);
            }
        }
    
        public void scoreBoard(){
            if(teams.contains(OP)){
                getLogger().info("OP Team already introduced");
            }else{
                OP = sb.registerNewTeam("OP");
                OP.setPrefix(ChatColor.translateAlternateColorCodes('&', red + bold + "OWNER" + reset + space));
            }
            if(teams.contains(ADMIN)){
                getLogger().info("ADMIN Team already introduced");
            }else{
                ADMIN = sb.registerNewTeam("ADMIN");
                ADMIN.setPrefix(ChatColor.translateAlternateColorCodes('&', orange + bold + "ADMIN" + reset + space));
            }
            if(teams.contains(SRMOD)){
                getLogger().info("SRMOD Team already introduced");
            }else{
                SRMOD = sb.registerNewTeam("SRMOD");
                SRMOD.setPrefix(ChatColor.translateAlternateColorCodes('&', green + bold + "SRMOD" + reset + space));
            }
            if(teams.contains(MOD)){
                getLogger().info("MOD Team already introduced");
            }else{
                MOD = sb.registerNewTeam("MOD");
                MOD.setPrefix(ChatColor.translateAlternateColorCodes('&', lime + bold + "MOD" + reset + space));
            }
            if(teams.contains(HELPER)){
                getLogger().info("HELPER Team already introduced");
            }else{
                HELPER = sb.registerNewTeam("HELPER");
                HELPER.setPrefix(ChatColor.translateAlternateColorCodes('&', pink + bold + "HELPER" + reset + space));
            }
            if(teams.contains(BUILDER)){
                getLogger().info("BUILDER Team already introduced");
            }else{
                BUILDER = sb.registerNewTeam("BUILDER");
                BUILDER.setPrefix(ChatColor.translateAlternateColorCodes('&', purple + bold + "BUILDER" + reset + space));
            }
            if(teams.contains(YOUTUBER)){
                getLogger().info("YOUTUBER Team already introduced");
            }else{
                YOUTUBER = sb.registerNewTeam("YOUTUBER");
                YOUTUBER.setPrefix(ChatColor.translateAlternateColorCodes('&', lightred + bold + "YOUTUBER" + reset + space));
            }
            if(teams.contains(VIP)){
                getLogger().info("VIP Team already introduced");
            }else{
                VIP = sb.registerNewTeam("VIP");
                VIP.setPrefix(ChatColor.translateAlternateColorCodes('&', blue + bold + "VIP" + reset + space));
            }
            if(teams.contains(MEMBER)){
                getLogger().info("MEMBER Team already introduced");
            }else {
                MEMBER = sb.registerNewTeam("MEMBER");
            }
        }
    }
    
     
  2. Offline

    PreFiXAUT

    @FlipSide_Mike Well you haven't initialized your Variables yet. All Of your Teams are NULL.
     
  3. Offline

    TheOatBaron

    Try replacing @EventHandler with @EventHandler(priority = EventPriority.MONITOR)
     
  4. Offline

    mythbusterma

    @TheOatBaron

    So the guy above you has sufficiently identified the problem, and you feel the best solution is changing what worked to worst practises?


    @FlipSide_Mike

    Initialize variables, also, it's probably not a good idea to have all of those static, but I can see why you would. Furthermore, you've done the work of ChatColor by redefining all the colors, just use ChatColor.

    What is the reason for building these lists anyway?
     
    FlipSide_Mike likes this.
  5. Offline

    FlipSide_Mike

    @mythbusterma
    Sorry for the delayed response, I'm working on making teams so the tab list looks nice and organized. I used the String for colors because when I do §a (Or any format code) its gives me a smiley face where it should be, and as far as I know I can't do "ChatColor.RED + ChatColor.BOLD + "WORD"" So I use the translation codes, if you know any work arounds I'm all ears. I never realized that having them static could be causing the problem, but I had originally had it in multiple classes, and called the teams like that, since I don't know any other methods to do that!

    I'll try switching the Teams to just pubic!

    @PreFiXAUT
    I initialized them in the scoreBoards(); method. If they are not created they become created and then added to the array list so they cannot be created again!
     
  6. Offline

    Gingerbreadman

    Or you can do ChatColor.RED + ChatColor.BOLD.toString() + "WORD"
     
  7. Offline

    mythbusterma

    @FlipSide_Mike

    I would recommend not making them public, and just using an accessor method instead.
     
    ChipDev likes this.
  8. Offline

    FlipSide_Mike

    @Gingerbreadman Definitely note-worthy! Thanks for the great tip!!!
    @mythbusterma That didn't fix anything, I took the 'public' and 'static' out of everything, and it still throws the error on line 94!

    EDIT: Maybe un-registering the teams upon disable would help solve the issue? I wouldn't need to loop for the teams having been created!
     
    Last edited: Dec 12, 2014
  9. Offline

    Gingerbreadman

    @FlipSide_Mike Instead of "Team OP = null" try "Team Op = new Team()"

    You can also do this with all the other Teams xD
     
  10. Offline

    PreFiXAUT

    @FlipSide_Mike Well...you only create them AFTER you have added them. Initialize them in the onEnable() or create a custom Method (To re-init them from an other Class maybe) and then you're good to go.

    Because the Problem you're having is: First you init them as NULL. Then the Teams are adding NULL and you're checking if they contain NULL...and that's true, since it has a NULL-Object in it. So you basicly have only NULL's in your Team instead of the actual Team.
     
  11. Online

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
     
Thread Status:
Not open for further replies.

Share This Page