Can you help me find the Error?

Discussion in 'Spigot Plugin Development' started by MedusTv, Jul 27, 2018.

Thread Status:
Not open for further replies.
  1. The Error code in the Console:

    Code (Text):
    [13:19:54 ERROR]: Could not pass event PlayerJoinEvent to RankMedus v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[1.9.jar:git-Spigot-7d15d07-c194444]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[1.9.jar:git-Spigot-7d15d07-c194444]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [1.9.jar:git-Spigot-7d15d07-c194444]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [1.9.jar:git-Spigot-7d15d07-c194444]
            at net.minecraft.server.v1_9_R1.PlayerList.onPlayerJoin(PlayerList.java:332) [1.9.jar:git-Spigot-7d15d07-c194444]
            at net.minecraft.server.v1_9_R1.PlayerList.a(PlayerList.java:158) [1.9.jar:git-Spigot-7d15d07-c194444]
            at net.minecraft.server.v1_9_R1.LoginListener.b(LoginListener.java:144) [1.9.jar:git-Spigot-7d15d07-c194444]
            at net.minecraft.server.v1_9_R1.LoginListener.c(LoginListener.java:54) [1.9.jar:git-Spigot-7d15d07-c194444]
            at net.minecraft.server.v1_9_R1.NetworkManager.a(NetworkManager.java:232) [1.9.jar:git-Spigot-7d15d07-c194444]
            at net.minecraft.server.v1_9_R1.ServerConnection.c(ServerConnection.java:141) [1.9.jar:git-Spigot-7d15d07-c194444]
            at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:815) [1.9.jar:git-Spigot-7d15d07-c194444]
            at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:400) [1.9.jar:git-Spigot-7d15d07-c194444]
            at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:655) [1.9.jar:git-Spigot-7d15d07-c194444]
            at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:554) [1.9.jar:git-Spigot-7d15d07-c194444]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_171]
    Caused by: java.lang.NullPointerException
            at de.jonas.RankMedus.main.Main.onPlayerJoin(Main.java:149) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_171]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_171]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_171]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[1.9.jar:git-Spigot-7d15d07-c194444]
            ... 14 more
    here is the soucecode::
    Code (Text):
    package de.jonas.RankMedus.main;

    import java.io.File;

    import org.bukkit.Bukkit;

    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.Scoreboard;

    public class Main extends JavaPlugin implements Listener {
       
        public static Main instance;
       
        public static String prefix = "[§cRang§r] ";
        public static boolean updateavailable = false;
        Scoreboard sb;
       
       
        public static Main getInstance() {
            return instance;
        }
       
        @SuppressWarnings("deprecation")
        @Override
        public void onEnable() {
            loadConfig();
            Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
               
                @Override
                public void run() {
                }
            }, 216000L, 216000L);
           
           
            Bukkit.getPluginManager().registerEvents(this, this);
           
           
            sb = Bukkit.getScoreboardManager().getNewScoreboard();
           
            sb.registerNewTeam("001Inhaber");
            sb.registerNewTeam("002Admin");
            sb.registerNewTeam("003Dev");
            sb.registerNewTeam("004Sr.Mod");
            sb.registerNewTeam("005Mod");
            sb.registerNewTeam("006Sup");
            sb.registerNewTeam("007Sr.Builder");
            sb.registerNewTeam("008Builder");
            sb.registerNewTeam("009Techniker");
            sb.registerNewTeam("010T-Sup");
            sb.registerNewTeam("011T-Builder");
            sb.registerNewTeam("012Freund");
            sb.registerNewTeam("013YT");
            sb.registerNewTeam("014Emerald");
            sb.registerNewTeam("015Diamond");
            sb.registerNewTeam("016Iron");
            sb.registerNewTeam("017Gold");
            sb.registerNewTeam("018Stone");
            sb.registerNewTeam("019Spieler");
           
            sb.getTeam("001Inhaber").setPrefix("§8[§4Inhaber§8] §4");
            sb.getTeam("002Admin").setPrefix("§8[§cAdmin§8] §c");
            sb.getTeam("003Dev").setPrefix("§8[§bDev§8] §b");
            sb.getTeam("004Sr.Mod").setPrefix("§8[§9Sr.Mod§8] §9");
            sb.getTeam("005Mod").setPrefix("§8[§9Mod§8] §9");
            sb.getTeam("006Sup").setPrefix("§8[§2Sup§8] §2");
            sb.getTeam("007Sr.Builder").setPrefix("§8[§eSr.Builder§8] §e");
            sb.getTeam("008Builder").setPrefix("§8[§eBuilder§8] §e");
            sb.getTeam("009Techniker").setPrefix("§8[§bTechniker§8] §b");
            sb.getTeam("010T-Sup").setPrefix("§8[§aT-Sup§8] §a");
            sb.getTeam("011T-Builder").setPrefix("§8[§eT-Builder§8] §e");
            sb.getTeam("012Freund").setPrefix("§8[§6Freund§8] §6");
            sb.getTeam("013YT").setPrefix("§8[§5YT§8] §5");
            sb.getTeam("014Emerald").setPrefix("§8[§2Emerald§8] §2");
            sb.getTeam("015Diamond").setPrefix("§8[§bDiamond§8] §b");
            sb.getTeam("016Iron").setPrefix("§8[§3Iron§8] §3");
            sb.getTeam("017Gold").setPrefix("§8[§6Gold§8] §6");
            sb.getTeam("018Stone").setPrefix("§8[§8§lStone§8] §8§l");
            sb.getTeam("019Spieler").setPrefix("§8[§7Spieler§8] §7");
           
        }
       
        @Override
        public void onDisable() {
            Bukkit.getConsoleSender().sendMessage(Main.prefix + "§3§lDas Plugin wurde gestoppt");
        }
       
        @SuppressWarnings("deprecation")
        public void setPrefix(final Player p) {
            String team = "";
            if(p.hasPermission("rang.inhaber")) {
                team = "001Inhaber";
            } else if(p.hasPermission("rang.admin")) {
                team = "002Admin";
            } else if(p.hasPermission("rang.dev")) {
                team = "003Dev";
            } else if(p.hasPermission("rang.sr.mod")) {
                team = "004Sr.Mod";
            } else if(p.hasPermission("rang.mod")) {
                team = "005Mod";
            } else if(p.hasPermission("rang.sup")) {
                team = "006Sup";
            } else if(p.hasPermission("rang.sr.builder")) {
                team = "007Sr.Builder";  
            } else if(p.hasPermission("rang.builder")) {
                team = "008Builder";
            } else if(p.hasPermission("rang.techniker")) {
                team = "009Techniker";
            } else if(p.hasPermission("rang.t.sup")) {
                team = "010T-Sup";
            } else if(p.hasPermission("rang.t.builder")) {
                team = "011T-Builder";
            } else if(p.hasPermission("rang.Freund")) {
                team = "012Freund";  
            } else if(p.hasPermission("rang.yt")) {
                team = "013YT";
            } else if(p.hasPermission("rang.Emerald")) {
                team = "014Emerald";
            } else if(p.hasPermission("rang.diamond")) {
                team = "015Diamond";
            } else if(p.hasPermission("rang.iron")) {
                team = "016Iron";
            } else if(p.hasPermission("rang.gold")) {
                team = "017Gold";
            } else if(p.hasPermission("rang.stone")) {
                team = "018Stone";
            } else
                team = "019Spieler";
           
            sb.getTeam(team).addPlayer(p);
            p.setDisplayName(sb.getTeam(team).getPrefix() + p.getName() + "§r");
           
            for(Player all : Bukkit.getOnlinePlayers()) {
                all.setScoreboard(sb);
            }
        }
       
        @EventHandler
        public void onAsyncPlayerChat(final AsyncPlayerChatEvent e) {
            e.setFormat("§f" + e.getPlayer().getDisplayName() + "§7§l >> §e" + e.getMessage());
        }
       
        @EventHandler
        public void onPlayerJoin(final PlayerJoinEvent e) {
            Main.getInstance().setPrefix(e.getPlayer());
        }
       
        private void loadConfig() {
            File file = new File("plugins/" + getDescription().getName() + "/config.yml");
            if (!file.exists()) {
                saveDefaultConfig();
            }
        }
       

    }
     
  2. What’s line 149?
     
  3. Main.getInstance().setPrefix(e.getPlayer());
     
  4. You didn't initialize the 'instance' variable in your main class.
     
  5. Naturally
    public static Main instance;
     
  6. What?
    He said you didn't initialise it,
    put on the onEnable at the start; instance = this;
     
Thread Status:
Not open for further replies.