Solved "Strange" Error.

Discussion in 'Spigot Plugin Development' started by darkshadow22mc, May 27, 2016.

Thread Status:
Not open for further replies.
  1. Hi!
    I'm developing a command that allows the use of /freeze <player>.
    The point is that I get this console error while loading the plugin.
    Code (Text):
    [18:33:33 ERROR]: Error occurred while enabling OdiNServer v1.0 (Is it up to date?)
    java.lang.NullPointerException
            at core.Nexus.onEnable(Nexus.java:45) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[s
    pigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:335) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:405) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at com.rylinaux.plugman.util.PluginUtil.load(PluginUtil.java:363) [PlugM
    an.jar:?]
            at com.rylinaux.plugman.util.PluginUtil.load(PluginUtil.java:316) [PlugM
    an.jar:?]
            at com.rylinaux.plugman.util.PluginUtil.reload(PluginUtil.java:377) [Plu
    gMan.jar:?]
            at com.rylinaux.plugman.command.ReloadCommand.execute(ReloadCommand.java
    :122) [PlugMan.jar:?]
            at com.rylinaux.plugman.PlugManCommandHandler.onCommand(PlugManCommandHa
    ndler.java:95) [PlugMan.jar:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) [spig
    ot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe
    r.java:646) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchServerCommand(Craf
    tServer.java:632) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.DedicatedServer.aM(DedicatedServer.java:
    353) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:3
    17) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    34) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :537) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    As is says, the error is on Nexus line 45. But the Line 45 of my plugin is the next one:
    Code (Text):
    getCommand("freeze").setExecutor(new FreezeCommand(this));
    The strange part is that I'm using the same method to load other commands (such as /kit)
    Here you have the code that I'm using on the class FreezeCommand.java
    Code (Text):
    package perks;

    import net.md_5.bungee.api.ChatColor;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import core.Nexus;

    public class FreezeCommand implements CommandExecutor{
        Nexus nexus;
        public FreezeCommand(Nexus nexus){
            this.nexus = nexus;
        }
        public boolean onCommand(CommandSender sender,Command cmd,String commandLabel,String[] args){
       
            if(cmd.getName().equalsIgnoreCase("freeze")){
           
                if(sender instanceof Player){
               
                    Player p = (Player) sender;
                    if(p.isOp() || p.hasPermission("odin.freeze")){
                   
                        if(args.length == 0){
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7[&3&l*&7] &c&lError: &cCorrect usage /freeze <player>"));
                        }else if(args.length == 1){
                       
                            Player target = Bukkit.getPlayer(args[0]);
                            if(target != null){
                                if(target.getWalkSpeed() == 1 || target.getFlySpeed() == 1){
                                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7[&3&l*&7] &3&lRemember: &3Remember to do /freeze "+target.getName()+" after finish!"));
                                    target.setWalkSpeed(0);
                                    target.setFlySpeed(0);
                                }else{
                                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7[&3&l*&7] &3Player "+target.getName()+" can walk again."));
                                    target.setWalkSpeed(1);
                                    target.setFlySpeed(1);
                                }
                            }else{
                                p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7[&3&l*&7] &c&lError: &cThis player isn't online."));
                            }
                       
                        }else if(args.length != 1 || args.length != 0){
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7[&3&l*&7] &c&lError: &cToo many arguments."));
                        }
                   
                    }else{
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&3&l[&f&lOdiN&3&l] &cUnknown command. Type /help to get information."));
                    }
               
                }else{
                    Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&7[&3&l*&7] &c&lERROR: Only"
                            + " players can perform the command."));
                }
           
            }
       
            return true;
       
        }
    }

    I hope that someone knows why it happens.

    EDIT:
    As logical, line 45 is on the onEnable method and Nexus is the class that extends JavaPlugin.​
     
  2. Why are you using PlugMan?
     
  3. I'm using a lot of plugins developed by other people. I think PlugMan shouldn't be a problem, am I right?
     
  4. I think I know exactly what your issue is because I got this same error in the exact same scenario you are having. Did you rememeber to add the command to the plugin.yml file? That was my problem. It confused me for a while too, until I realized what I did.
     
  5. Thanks... I feel so stupid ;-;
     
Thread Status:
Not open for further replies.