simple command not running

Discussion in 'Plugin Development' started by Minesuchtiiii, Sep 29, 2017.

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

    Minesuchtiiii

    So I have a command and i check if the args[0] eguals to "all", but when typing /<command> all nothing happens, here's the code

    Code:
                    if(args[0].equalsIgnoreCase("all")) {
                       
                        for(Player all : Bukkit.getOnlinePlayers()) {
                           
                            if(all != p) {
                                if(!(all.isOp())) {
                                if(!(all.hasPermission("troll.bypass"))) {
                                   
                                    all.setVelocity(all.getVelocity().setY(3));
                                   
                                }
                                else {
                                    return true;
                                }
                               
                                }
                                else if(all.isOp()) {
                                    if(this.plugin.trollop) {
                                       
                                        all.setVelocity(all.getVelocity().setY(3));
                                       
                                    }
                                    else {
                                       
                                        p.sendMessage(this.plugin.bypass);
                                       
                                    }
                                   
                                }
                            }
                            else {
                                return true;
                            }
                           
                        }
                       
                        this.plugin.addTroll();
                        this.plugin.addStats("Launch");
                        p.sendMessage(this.plugin.prefix + "§eYou launched everyone, except the players who can bypass it!");
                       
                    }
    command is registered in the main class, /<command> [player] works
     
  2. Offline

    Zombie_Striker

    @Minesuchtiiii
    Try adding Bukkit.broadcastMessage("test"); before the for loop. If you issue the command, do you see the message? If so, something with your if statements below is wrong. If not, then you most likely have not registered the command/class as an executor.
     
  3. Offline

    yPedx

  4. Offline

    JaySN

    I also suggest you to check your plugin.yml file to see if you have done anything wrong.

    It must look somewhat like this
    Code:
    name: //Your plugin name
    version: 1.0
    author: //Your IGN or Name
    main: // Your Main class com.mainclass.yourmainclass.MainClass
    website: //If Any
    commands:
          all:
                   description: //your description
                   usage: /all
    Probably player because of this
    Code:
    p.sendMessage(this.plugin.prefix + "§eYou launched everyone, except the players who can bypass it!");
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  5. Offline

    Minesuchtiiii

    @Zombie_Striker Added the message, and yes I see it when executing the command, will check the if statements now
    @yPedx
    Code:
    if(sender instanceof Player) {
    
    Player p = (Player) sender;
    
    }
    
    @JaySN Checked the plugin.yml and there's nothing wrong
     
  6. Offline

    JaySN

    what I can tell is that to take your time and go through your whole code 1 by 1 to see if there are any errors. Just try not to rush and go through all of them. It worked for me every time when I want to troubleshoot the errors in my plugin
     
  7. Offline

    Minesuchtiiii

    It works fine, but the code after the for loop is not running, I don't know why
     
  8. Offline

    Zombie_Striker

    @Minesuchtiiii
    Try printing out the onlineplayers.length. Is it empty (0)? If so, then somehow you are issuing this command when there are no players online that bukkit can detect. If not, then broadcast the message inside of the for loop, above the first if statement.
     
  9. Offline

    Minesuchtiiii

    @Zombie_Striker Already tried that, when I'm alone on the server it shows "1", when someone else joined it still showed "1", I printed out the name and it was me. Added the debug message just as you said above the first if statement.. the other player was a free user, the server was set to "Onlinemode = false".. I don't know, maybe this is the reason he was not detected? hmm
     
  10. Offline

    Caderape2

    @Minesuchtiiii
    It's because you return true when the player is you. So the code stop. It also stop when the player dun have the permission.
    For loop use the keyword 'continue' for skip to the next iteration. 'break' for break the current loop, and 'return' will stop the whole method.
     
  11. Online

    timtower Administrator Administrator Moderator

  12. Offline

    Minesuchtiiii

    But then I have no one to test it on :D
     
Thread Status:
Not open for further replies.

Share This Page