Solved Command not executing

Discussion in 'Plugin Help/Development/Requests' started by xxPatterson, Apr 12, 2015.

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

    xxPatterson

    This is the stacktrace I got:

    Code:
    [13:16:00 INFO]: MrBurnham issued server command: /claimthrone
    [13:16:00 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'clai
    mthrone' in plugin UHCPVP v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[min
    ecraft_server.jar:git-Bukkit-262c777]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    0) ~[minecraft_server.jar:git-Bukkit-262c777]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe
    r.java:622) ~[minecraft_server.jar:git-Bukkit-262c777]
            at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:1058) [minecraft_server.jar:git-Bukkit-262c777]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :919) [minecraft_server.jar:git-Bukkit-262c777]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:37) [minec
    raft_server.jar:git-Bukkit-262c777]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:9) [minecr
    aft_server.jar:git-Bukkit-262c777]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [min
    ecraft_server.jar:git-Bukkit-262c777]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_31]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_31]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    43) [minecraft_server.jar:git-Bukkit-262c777]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:2
    84) [minecraft_server.jar:git-Bukkit-262c777]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:5
    98) [minecraft_server.jar:git-Bukkit-262c777]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :506) [minecraft_server.jar:git-Bukkit-262c777]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    Caused by: java.lang.NullPointerException
            at me.patterson.uhc.Events.King.ClaimThrone.onCommand(ClaimThrone.java:2
    7) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[min
    ecraft_server.jar:git-Bukkit-262c777]
            ... 14 more
    >
    

    And this is the code, any idea whats wrong? I put the command in the plugin.yml and implemented it into main class:
    Code:
    public class ClaimThrone
    implements CommandExecutor
    {
          private Main plugin;
    
          public ClaimThrone()
          {
            this.plugin = plugin;
          }
    public boolean onCommand(CommandSender sender, Command command, String cmd, String[] args)
    {
          if (cmd.equalsIgnoreCase("claimthrone")) {
              Player p = (Player)sender;
              if(plugin.getConfig().getString("King").isEmpty()){
                  plugin.getConfig().set("King", p.getUniqueId());
                  plugin.getConfig().set("KingName", p.getDisplayName());
                  p.sendMessage("§e§lCongratulations, you have been crowned king of the land!");
                  Bukkit.broadcastMessage("§e§lWe have a new King, all hail " + plugin.getConfig().getString("KingName") + "!");
              
              }
          
          }
        return true;
    }
    }
     
  2. Offline

    bwfcwalshy Retired Staff

    @xxPatterson Check sender before casting. Use ChatColor not end code. Also do you have a config.yml in your plugin folder?
     
  3. Offline

    xxPatterson

    I have checked for sender before casting, and I do not have the config.yml in my plugin folder, I have it in my eclipse project but it won't load up into the plugin folder but it still isn't working@bwfcwalshy
     
  4. Offline

    Yaron_1231

    At line 12 you need to have 'cmd.getName().equalsIgnoreCase("claimthrone")'
     
  5. Offline

    bwfcwalshy Retired Staff

    @xxPatterson from that code I see no checks, you need to load the config so in onEnable add #saveDefaultConfig. Also
     
Thread Status:
Not open for further replies.

Share This Page