Command error NullPoiterException

Discussion in 'Spigot Plugin Development' started by FromageDeTortue, Jun 22, 2015.

  1. Hello , I create multiple command and just the version and main command work ^^


    Command code:
    Code (Text):
          public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
          {
            CommandSender p = sender;
            if (cmd.getName().equalsIgnoreCase("UltimateManager")) {
                if (!sender.hasPermission("um.help")) {
                p.sendMessage( this.prefix + getConfig().getString("PermissionMsg").replace("&", "§"));
                return true;
              }
             
              if (args.length == 0) {
                p.sendMessage( this.prefix + "");
                p.sendMessage("");
                p.sendMessage(" &3- &6&l/um &3reload".replace("&", "§"));
                p.sendMessage(" &3- &6&l/um &3clearchat".replace("&", "§"));
                p.sendMessage(" &3- &6&l/um &3version".replace("&", "§"));
                p.sendMessage(" &3- &6&l/um &3broadcast <message>".replace("&", "§"));
                p.sendMessage("");
                return true;
              }
           
              if (args[0].equalsIgnoreCase("version")) {
                    if (!sender.hasPermission("um.version")) {
                        p.sendMessage( this.prefix + getConfig().getString("PermissionMsg").replace("&", "§"));
                        return true;
                      }
                    p.sendMessage( this.prefix + "");
                    p.sendMessage("");
                    p.sendMessage("&3Currently version is :".replace("&", "§") + this.version);
                    p.sendMessage("");
                    return true;
              }
           
              if (args[0].equalsIgnoreCase("reload")) {
                    if (!sender.hasPermission("um.reload")) {
                        p.sendMessage( this.prefix + getConfig().getString("PermissionMsg").replace("&", "§"));
                        return true;
                      }
                    reloadConfig();
                    saveConfig();
                    p.sendMessage( this.prefix + getConfig().getString("ReloadMsg").replace("&", "§"));
                    return true;
              }
           
              if (args[0].equalsIgnoreCase("broadcast")) {
                    if (!sender.hasPermission("um.broadcast")) {
                        p.sendMessage( this.prefix + getConfig().getString("PermissionMsg").replace("&", "§"));
                        return true;
                      }
                    String Broadcast = "";
                    for (String s : args)
                      Broadcast = Broadcast + s + " ";
                    if (args.length == 1)
                      sender.sendMessage(getConfig().getString("NoTextEntered").replaceAll("&", "§"));
                    else
                      Bukkit.broadcastMessage(getConfig().getString("BroadcastPrefix").replaceAll("&", "§") + Broadcast);
                  }
                  else {
                        p.sendMessage( this.prefix + getConfig().getString("PermissionMsg").replace("&", "§"));
                  }
                 
              }if (args[0].equalsIgnoreCase("clearchat")) {
                    if (!sender.hasPermission("um.clearchat")) {
                    p.sendMessage( this.prefix + getConfig().getString("PermissionMsg").replace("&", "§"));
                    return true;
                  }
                  for (int i = 0; i < 100; i++) {
                    Bukkit.broadcastMessage("");
                  }
                }
            return true;
          }
    plugin.yml
    Code (Text):
    commands:
      ultimatemanager:
        description: Main command.
        aliases: [um]

    Error message in the log:
    Code (Text):
    [08:54:30 INFO]: FromageDeTortue issued server command: /um broadcast
    [08:54:30 ERROR]: null

    org.bukkit.command.CommandException: Unhandled exception executing command 'um' in plugin UltimateManager v1.0

    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[minecraft_openmod.jar:git-PaperSpigot-43]

    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[minecraft_openmod.jar:git-PaperSpigot-43]

    at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:766) ~[minecraft_openmod.jar:git-PaperSpigot-43]

    at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:1044) [minecraft_openmod.jar:git-PaperSpigot-43]

    at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:881) [minecraft_openmod.jar:git-PaperSpigot-43]

    at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [minecraft_openmod.jar:git-PaperSpigot-43]

    at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:65) [minecraft_openmod.jar:git-PaperSpigot-43]

    at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:189) [minecraft_openmod.jar:git-PaperSpigot-43]

    at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [minecraft_openmod.jar:git-PaperSpigot-43]

    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:789) [minecraft_openmod.jar:git-PaperSpigot-43]

    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:307) [minecraft_openmod.jar:git-PaperSpigot-43]

    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:638) [minecraft_openmod.jar:git-PaperSpigot-43]

    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:544) [minecraft_openmod.jar:git-PaperSpigot-43]

    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [minecraft_openmod.jar:git-PaperSpigot-43]

    Caused by: java.lang.NullPointerException
    at WarPhoenix.Plugin.Main.onCommand(Main.java:223) ~[?:?]

    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[minecraft_openmod.jar:git-PaperSpigot-43]
    ... 13 more
     
  2. What's line 223 on your Main class?
     
  3. sender.sendMessage(getConfig().getString("NoTextEntered").replaceAll("&", "§"));
     
  4. and whats in the config section
    ?
     
  5. The config file is empty in the plugin folder .
    He doesn't load
     
  6. then thats the error

    EDIT:
    inside the onEnable() you just put saveDefaultConfig(); (and then it should work)
     
  7. It's already done
    Code (Text):
          public void launchConfig() {
            saveDefaultConfig();
          }
         
          public void onEnable() {
             
            launchConfig();
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
           
          }
     
  8. PHP:
    getConfig().options().copyDefaults();
    in your
     
  9. wut then just put saveDefaultConfig(); in your onEnable() { and not launchConfig()?
     
  10. Code (Text):
          public void onEnable() {
             
            System.out.println(this.consoleprefix + "Developed by Mr-Freezi !");
            saveDefaultConfig();
            getConfig().options().copyDefaults();
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
           
          }
    Not work :(
     
  11. Well, what tends to work for me is:
    Code (Text):
    saveDefaultConfig();
    saveConfig();
     
    • Agree Agree x 1
  12. Code (Text):
          public void onEnable() {
             
            System.out.println(this.consoleprefix + "Developed by Mr-Freezi !");
            saveDefaultConfig();
            saveConfig();
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
           
          }
    Not work :(:(:(:(:(
     
  13. Try:
    Code (Text):
    public void onEnable() {
     getConfig().options.copyDefaults(true);
    }
     
  14. Why Sysout?
    Use the Bukkit logger or the ConsoleCommandSender..
     
  15. Not work
     
  16. Same errors?
     
  17. can i see a screenshot of your project folder/outline (if u don't know its the area that shows all the packages, classes, files, ect that are apart of your project). Also a screenshot of the default config file