Solved Args dont work :(

Discussion in 'Plugin Development' started by niels1k, Dec 2, 2012.

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

    niels1k

    SOLVED!!!!!
    SOLVED!!!!!
    SOLVED!!!!!

    This is really annoying. I have a command /niels1k and it works fine. But my command /niels1k heal doesnt work. When my plugin gets enabled i get a console error. Here it is:
    Code:
    17:41:06 [INFO] [Niels1K] Loading Niels1K v0.1
    17:41:06 [INFO] [Niels1K] Enabling Niels1K v0.1
    17:41:06 [INFO] [Niels1K] Niels1K Plugin Has Been Enabled!
    17:41:06 [SEVERE] Error occurred while enabling Niels1K v0.1 (Is it up to date?)
     
    java.lang.NullPointerException
            at com.niels1k.plugin.Main.onEnable(Main.java:12)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:374)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:381)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:270)
            at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:252
    )
            at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:579)
            at org.bukkit.Bukkit.reload(Bukkit.java:183)
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
    23)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    6)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:5
    02)
            at org.bukkit.craftbukkit.CraftServer.dispatchServerCommand(CraftServer.
    java:494)
            at net.minecraft.server.DedicatedServer.al(DedicatedServer.java:258)
            at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:223)
            at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:493)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:426)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:856)
    Here is my main class called Main.java:
    Code:
    package com.niels1k.plugin;
     
    import java.util.logging.Logger;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin{
        Logger logger = Logger.getLogger("Minecraft");
        @Override
        public void onEnable() {
            getLogger().info("Niels1K Plugin Has Been Enabled!");
            getCommand("niels1k").setExecutor(new Niels1kCommandExecutor(this));
            getCommand("niels1k heal").setExecutor(new Niels1kCommandExecutor(this));
        }
        @Override
        public void onDisable() {
            getLogger().info("Niels1K Plugin Has Been Disabled!");
        }
    }
    And my Command executor class called Niels1kCommandExecutor.java:
    Code:
    package com.niels1k.plugin;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class Niels1kCommandExecutor implements CommandExecutor{
        private Main plugin;
        public Niels1kCommandExecutor(Main plugin) {
            this.plugin = plugin;
        }
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
                if(cmd.getName().equalsIgnoreCase("niels1k")){
                    if(sender instanceof Player){
                        Player player = (Player) sender;
                        if(player.hasPermission("niels1k.all")){
                            if(args.length == 0){
                                player.sendMessage(ChatColor.LIGHT_PURPLE+"<------HELP------>");
                                player.sendMessage(ChatColor.GOLD+"niels1k: Shows this menu.");
                            }else if(args.length == 1){
                                if(args.equals("heal")){
                                    player.setHealth(20);
                                    player.setFireTicks(0);
                                    player.sendMessage(ChatColor.AQUA+"You've been healed!");
                                }
                            }else if(args.length == 2){
                                Player targetPlayer = player.getServer().getPlayer(args[1]);
                                targetPlayer.setHealth(20);
                                player.sendMessage(ChatColor.AQUA+"You've been healed by "+sender.getName()+"!");
                            }
                        }
                    }
                }
            return false;
        }
    }
    And my plugin.yml:
    Code:
    name: Niels1K
    version: 0.1
    description: The official Niels1K plugin
    main: com.niels1k.plugin.Main
    author: niels1k
    website: http://www.niels1k.comoj.com
     
    commands:
        niels1k:
            description: Shows all commands
    I dont get any errors in the console when i do /niels1k heal and it doesnt give me a message either. Please take your time to read the code and please help me if you can.
     
  2. Offline

    Barinade

    getCommand("niels1k heal").setExecutor(new Niels1kCommandExecutor(this));

    Remove it
     
  3. Offline

    niels1k

    No it was because i'm a dork i did
    if(args.equals("heal"))
    I should have done
    if(args[0].equals("heal"))
    I had to specify the first argument.
     
  4. Offline

    Barinade

    Still, remove it
     
  5. Offline

    niels1k

    You abviously dont know what it does. I have a seperate class for my commands, and my main class needs to know what class that is. That code is setting the executer of that command in my Niels1kCommandExecutor class. It even states on the bukkit wiki Plugin Tutorial that this is needed. So there.
     
  6. Offline

    Barinade

    You obviously don't understand that you don't have to register arguments, lol.

    getCommand("niels1k heal").setExecutor(new Niels1kCommandExecutor(this));

    and

    getCommand("niels1k").setExecutor(new Niels1kCommandExecutor(this));

    Do the same thing.
     
  7. Offline

    niels1k

    Sorry for being mean :D
    I now understand that i dont need to register args. Thank You
     
  8. Offline

    Barinade

    Looking over your code I see a lot of issues, lol. Do you have someone that you can work with that better understands programming? You leave so much room for errors, it's not even funny :p Basically, your code assumes waaay too much.

    I can give you a hand if you have no one else, but I'm in the middle of a huge project so I can't really devote all my time.

    And I have another guy under my wing atm.
     
  9. Offline

    niels1k

    Actually already fixed al lot of the code, but i'm just to lazy to update the thread :p
     
  10. Offline

    gomeow

    Can you post what you have so far so we might be able to point out more things?
     
Thread Status:
Not open for further replies.

Share This Page