Commands just randomly not working? Plus error on Startup.

Discussion in 'Plugin Development' started by MCForger, Sep 27, 2012.

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

    MCForger

    Hi,
    On startup of plugin and this is only happening when I add the file that manages that commands like sets executors and such and gives me an is it up to date error every time. I have traced the NPE error but it always changes. Any one know how to fix it? I simply call a class called ManageCommands and in that it has a loadCommands() which then just grabs command and sets executor.
    Any help is welcomed!

    Anyone know? Before I rewrite my plugin from scratch =P

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  2. Offline

    Theway2cool1

    Source code helps.

    Could you provide an exception (even though it changes)? It would help to at least have an idea of what's going wrong :3

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  3. Offline

    MCForger

    Stack Trace Error
    Code:
    2012-09-27 21:57:38 [INFO] [KingKraft] Enabling KingKraft v6.3
    2012-09-27 21:57:38 [SEVERE] Error occurred while enabling KingKraft v6.3 (Is it up to date?)
    java.lang.NullPointerException
    at com.mcforger.kingkraft.utils.KingKraftAPI.<init>(KingKraftAPI.java:43)
    at com.mcforger.kingkraft.KingKraft.onEnable(KingKraft.java:14)
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:365)
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
    at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:265)
    at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:247)
    at net.minecraft.server.MinecraftServer.i(MinecraftServer.java:296)
    at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:275)
    at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:225)
    at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:140)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:378)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    2012-09-27 21:57:38 [INFO] Server permissions file permissions.yml is empty, ignoring it
    2012-09-27 21:57:39 [INFO] Done (2.818s)! For help, type "help" or "?"
    
     
  4. Offline

    krazytraynz

    Is it compiled against the right API for the version of Bukkit that you're using? It could be what's causing the (Is it up to date?).
     
  5. Offline

    MCForger

    Latest on both craftbukkits and Bukkit
     
  6. Offline

    Theway2cool1

    In KingKraftAPI.java:
    Code:
    private BroadcastCommand bC;
    Why is this private? I think this may be your issue, just remove the private keyword and see what happens.
     
  7. Offline

    MCForger

    I know that wont change anything but tried it any way and nope still same error.

    V10later want to help out xD

    The line giving the NPE is
    Code:
    plugin.getCommand("broadcast").setExecutor(bC);
    The code that gets it and makes it is
    Code:
    bC = new BroadcastCommand(_plugin);
    private BroadcastCommand bC;
    Private is at the very top and not in the code and then setExecutor line comes after the bC = new line of code.

    Here is the code for the command class.
    Code:
    package com.mcforger.kingkraft.commands;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
     
    import com.mcforger.kingkraft.KingKraft;
    import com.mcforger.kingkraft.utils.KingKraftChatty;
     
    public class BroadcastCommand implements CommandExecutor
    {
        @SuppressWarnings("unused")
        private KingKraft _plugin;
     
        public BroadcastCommand(KingKraft plugin)
        {
            _plugin = plugin;
        }
     
        public boolean onCommand(CommandSender sender, Command command,
                String commandLabel, String[] args)
        {
            if (!sender.hasPermission("kingkraft.broadcast"))
            {
                sender.sendMessage(ChatColor.DARK_RED
                        + "You do not have permission!");
                return true;
            }
            if (command.getName().equalsIgnoreCase("broadcast"))
                return handleBroadcast(sender, args);
            return true;
        }
     
        private boolean handleBroadcast(CommandSender sender, String[] args)
        {
            String message = "";
            for (String s : args)
            {
                message = message + " " + s;
            }
            KingKraftChatty.broadcast(message.toString());
            return true;
        }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
Thread Status:
Not open for further replies.

Share This Page