A series of confusing errors

Discussion in 'Plugin Development' started by Caedus, Jan 24, 2016.

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

    Caedus

    Hi, so right now i'm struggling with some errors that I do not understand. In the following code:
    Code:
    HashMap<String, String> challenge = new HashMap<String, String>();
    
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("duel") && sender instanceof Player){
                if(sender.hasPermission("apvp.duel")){
                       
                    if(args.length == 1){
                        @SuppressWarnings("deprecation")
                        Player target = getServer().getPlayerExact(args[0]);
                        Player p = (Player) sender;
                       
                       
                        if(args[0].equalsIgnoreCase("accept")){
                           
                           
                            if(challenge.get(p.getName()).equals(target.getName())){
                               
                            Bukkit.broadcastMessage("this is where both parties should be tp'd to an arena");
                            challenge.remove(p.getName());
                            challenge.remove(target.getName());
                               
                            }
                           
                        } else if(args[0].equalsIgnoreCase("reject")){
                           
                           
                        }
                        if(!args[0].equalsIgnoreCase("accept") && !args[0].equalsIgnoreCase("reject")){
                            if(target != null){
                                challenge.put(p.getName(), target.getName());
                                challenge.put(target.getName(), p.getName());
                               
                               
                                target.sendMessage(ChatColor.GOLD+"You've been challenged to a duel by "+p.getName()+"! Type /duel accept to accept!");
                               
                               
                            } else {
                                p.sendMessage(ChatColor.RED+"Error: Player not found");
                            }
                           
                           
                        } else {
                            sender.sendMessage(ChatColor.RED+"Error: Command /duel expects one argument 'Player name'");
                           
                       
                    }
                    }
                   
                } else {
                    sender.sendMessage("You do not have permission to duel.");
                }
               
               
               
                return true;
            }
           
            return false;
        }
    When I type /duel accept, I get an internal error and the console throws the following erorr: http://pastebin.com/XNw8v1Fa#
    Now, as far as I can tell it's a NPE, but i'm not sure why that is because I check to make sure it's not null AND it's only the /duel accept that throws the NPE, not /duel *playername*

    When I type '/duel reject', the plugin tells me "Error: Command /duel expects one argument 'Player name'" Which is also weird.

    Any help would be appreciated.
     
  2. Offline

    Gorbit99

    @HenrySartori
    You could just help him without saying Learn Java 3 (yes, I counted) times. It is important, but putting it once in fornt of your message is enough, especially if you give him some links.


    @Caedus You should always post your whole code with all the imports and stuff and press Ctrl+Alt+F if you're using eclipse before doing so. This should fix indentations and help others see, which line is the problem by seeing the error. You're error by the way is that something is null on the 45th line
     
  3. Offline

    HenrySartori

    Yes, I said many times with good intentions, not like you, try to helping he with a code he even know what he's doing.
    Who is you to tell me what to do or not? You are trying to help with a code he CTRL+C CTRL+V in Eclipse.
    He need to learn Java, you need to learn how to help people and how to use your brain.
     
  4. Offline

    87pen

    @HenrySartori You are wrong? /extraenchants rune speed 3 100 0
    (Command name: extraenchants) (Args 0: rune) (Args 1: speed) (Args 2: 3) (args 3: 100) (Args 4: 0) I was sort of tempted to say learn bukkit 3 times in my post but I feel the verbal irony of the thread was enough.
     
    Last edited: Jan 24, 2016
    Gorbit99 likes this.
  5. Offline

    HenrySartori

    I was a stupid. Yes, I was wrong, but he still need to fix that "!" And "&&".
     
  6. Yeah @HenrySartori what are you on about?? If you do /this is a command, args[0] is 'is', args[1] is 'a' and args[2] is 'command'. Why don't you go and learn Java lol xD And also Henry there is nothing wrong with the ! and &&. It's fine lol. GO LEARN JAVA DAMMIT!

    @Caedus I think the NPE might be because you are trying to get a player from args[0] when it might not be a player? So if it isn't a player, when you do /duel accept, it's trying to interact with a non-existant player called 'accept' lol. Also, instead of using the ! and &&, simply use else { since it actually makes no difference.

    You are getting the second error message (expects one argument) because you do not return true; at the end of the if (args[0].equalsIgnoreCase("reject")) so it simply carries on to the else { at the end.

    Hope this helped! :)
     
    Caedus likes this.
  7. Offline

    HenrySartori

    Sure I don't know how to speak english, I'm from Brazil, a language you could never learn good too
     
    87pen likes this.
  8. Offline

    87pen

    @Gorbit99 That was kind of insanely rude. :/ A lot of people are not amazing at English and their first language is not English. To solve @Caedus actual problem, I'd redo the command. but your actual problem is that you get a player from args[0] which you check later to be accept. If target is null it will throw the error.
     
  9. Yeah.... and that's kinda what I said in my reply lol?
     
  10. Offline

    timtower Administrator Administrator Moderator

    To everybody: Don't just yell "Learn Java, learn English"
    If you don't have anything positive to say then it would be appreciated if you would stay silent.
    If I removed too much: sorry.
     
    HenrySartori, Sulphate and Jeyge like this.
  11. Offline

    HenrySartori

    You make good removing that. It was a descenessary discussion and I wouldn't do this anymore.
     
  12. Offline

    87pen

    @Caedus Did you solve your problem?
     
  13. Offline

    Caedus

    @87pen Not yet, been working on another plugin at the moment, but I think your solution is correct and i'll report back with results when I get to it. Cheers for the help.
     
  14. ;( rip he doesn't even notice my solution...
     
  15. Offline

    Caedus

    @Sulphate

    I responded in a post where I acknowledged your solution and thanked you, but one of the mods deleted the post.

    Anyway, thanks!
     
  16. Ah ok. :)
     
Thread Status:
Not open for further replies.

Share This Page