Solved Not showing usage when command fails.

Discussion in 'Plugin Development' started by AlvinB, Jul 29, 2016.

Thread Status:
Not open for further replies.
  1. Hello, I have been wondering this for a while now, and figured I should ask here.

    So, say I have got a CommandExecutor, and I should return a boolean. Someone comes along and uses the command but doesn't have the proper permission, now I want to display a message to the user saying he doesn't have the right permission, but I don't want the usage aswell, but I should obviously return false, since the command did not execute properly. Should I return true even though the command wasn't properly executed?
     
  2. Offline

    Zombie_Striker

    @AlvinB
    The reason why you return false is so you get that message.The reason why you return false when something failed is because you want to tell the player the how to use the command. To be more precise, if the command is formatted like it should be, then you return true. As an example, if the first arg takes in an Integer, but the command is "/command String", then you return false because the command is not formatted correctly and the player needs to know how the command is formatted. If the first arg is a Target (I.e player), but the command is "/command hello" (where no player online is called "hello") , then you return false. Since what you're checking for is something besides how the command is formatted, you can return true.
     
  3. @Zombie_Striker
    Oh, thanks for clarifying, it makes more sense now.

    I should've asked this in the original post, but don't things like command blocks (which give redstone output depending on command success) use the value I return?
     
  4. Offline

    ArsenArsen

    *mindblown*

    Also, I think command blocks cant run commands like that. Not sure.
     
  5. Honestly the fact Bukkit has a Boolean just to return a usage is stupid in my opinion. Most people just add their own usage message anyway.
     
    AlvinB and ArsenArsen like this.
  6. Offline

    ArsenArsen

    Do I smell a rant? dips
     
  7. @bwfcwalshy
    I totally agree, but I was thinking the reason it was there was because of something minecraft related (the command block idea came from there), because if there is no real use for it, I'll go back to just ignoring it and adding my own messages, like I have been doing.

    Also, if nobody knows the answer to the command block thing I shall go investigate the sources once I get home.
     
  8. @AlvinB It is pretty damn useless, a void would easily work fine but what can you do. Luckily, I have a lib so I'm all good :p
     
  9. Offline

    I Al Istannen

    @ArsenArsen
    Oh, as long as you don't block the BlockCommandSender, command blocks will happily execute commands. Needed that here.

    @AlvinB
    From the source it seems returning true increaes the success count by one. You may want to try it though ;)
    Code:
     if (commandMap.dispatch(bSender, joiner.join(Arrays.asList((String[])commands.get(i))))) {
        ++completed;
    }
    Code:
    this.b = executeCommand(this, this.sender, this.e);
    Code:
    nbttagcompound.setInt("SuccessCount", this.b);
    And I just hope the successcount sets the redstone value. Too lazy to check.
     
  10. @I Al Istannen
    SuccessCount is the strength of the redstone signal emitted if I remember correctly (I stumbled upon this tag while making a commandblock spawner using fallingsand a while ago.. don't ask why..).

    Thanks for looking through the sources, I shall keep in mind that returning true works with commandblocks.

    Now for the stupid part.. How do I mark the thread as solved? (At 300 posts and this is my first thread...)
     
  11. @AlvinB THread Tools > Edit Thread > Prefix > Solved
     
  12. Offline

    I Al Istannen

    @AlvinB
    Go to the top right of this thread.
    Click on thread tools.
    Select "Edit Prefix"
    Set the prefix to solved (may need to click on "No-Prefix", haven't done this in a while :p)


    Good luck, I would test my assumption though the next time you need it xD

    Good night :)

    EDIT: Why does everybody ninja me???? What have I done to deserve this xD
     
  13. Offline

    ArsenArsen

    You ninjad me, and by the way,
    Okay enough of typo finding, night.
     
Thread Status:
Not open for further replies.

Share This Page