Stop onCommand or Something Equivalent

Discussion in 'Plugin Development' started by knightidus, Jan 5, 2012.

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

    knightidus

    Hi guys! Sorry i have come across a really big problem that i would really appreciate some help on :)! Well basically im trying to make an all inclusive plugin for my RPG server that i want to setup! it was all going really well until i tried to make a permission part of it.

    My problem is that i want to get the permission node from the command (from onCommand) then check if the player has that node in a separate Yaml file and if not cancel it! but the cancelling thing is the problem! I have been fiddling around with onPlyaerCommandPreprocessEvent and have all the appropriate code done, such as checking the Yaml file etc! But it wont seen to be triggered when a command is made. If it would, then there would be no problem at all. Any help would be much appreciated :)

    Ohh and i kinda want to keep as much script as possible to myself if you know what i mean, but if necessary i will probably post it if needed! and also im trying to stay away from using the default permissions system, i personally dont really like it, thanks!

    Lol

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
  2. Offline

    number1_Master

    What you said was kind of confusing, but do you want to add permission nodes in an onCommand statement?
    If so, this is what I did (doing) for my plugin with random variables:
    Code:
    if(cmdlabel.equalsIgnoreCase("something") && (playervariable.hasPermission("permission.node") || playervariable.isOp()))
    {
    
    }
    then in the plugin.yml format the commands like so:
    Code:
    commands:
      something:
        description: This is an awesome description!
        permission: permission.node
     
  3. Offline

    knightidus


    Thanks for your reply and help!
    My problem is not to be able to do that for my own plugin, that's kinda easy, but if you return true on your plugin it will still be passed to other plugins, I want to stop it straight after I've checked it, that's the problem! You can cancel it via the PlayerCommandPreprocessEvent because its an event, but onCommand isn't its just a boolean, if I return false or true the server still passes it on!
     
  4. Offline

    Don Redhorse

    switch to PlayerCommandPreprocessEvent in this case so player chat listener
     
  5. Offline

    number1_Master

    ya i never really understood return true or return false. i just know that i should put return false at the end of the statement, and that apparently return true "cancels" the process"

    Edit: Wait, I think I understand now! A little. If I put return true at the end of an if statement, or at the end of onCommand, it will return to the top, but if it were false, it would wait for it to be executed again! Yes?!

    I re-read what you said, and you want the opposite of what I said. If a player doesn't have a permission node, then do this. Well, basicly put another if statement within the one I put, and get rid of the permissions I used.
    Code:
    if(cmdlabel.equalsIgnoreCase("something"))
    {
      if(player.hasPermission("permission.node"))
      {
         //put code here if does has a node
      }
      else
      {
       return true;
      }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
  6. return true; says that the command worked and return false; says it didn't and shows the usage(plugin.yml) to the player.
     
  7. Offline

    number1_Master

    so return true; will say something like "Command Succes" and return false; will say the usage(if anything)
    no wonder i was always getting the usage
    so should i change my code to return true;
     
  8. If the user typed the command right then you do return true; and that wont send a message or anything. If he did something wrong you return false; (or return true; and then give him a message using player.sendMessage(), thats how I like to do it)
     
  9. Offline

    knightidus

    ahh thanks for trying to resolve this everyone!
    The thing is the way the command system works in bukkit is kinda weird, and being weird it makes it harder to work with! If it were an event it would be much easier!

    One of the hardest things to do is stop other plugins, the command is passed to every plugin that asks for it, you cant stop what they do without using some clever method, or doing something im not aware of. If you return false it simply means YOUR plugin doesn't do any thing! Even if you return true, it still gets passed around, which is frankly a pain.

    The only possible ways to do this would be to either set the information given in the onCommand (CommandSender, Command, etc...) to either null or a other command that says you dont have permission or something. I have struggled with this issue for a long time and got many headaches over it.

    Yeah, return true; simply means that your plugin has "handled" the command, if you return false it means that you dont.

    Yeah that seems like the best thing to do (and easiest!).

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
  10. Offline

    number1_Master

    ya i have player.sendMessage, but return false;
    ill change it to true
     
  11. Offline

    knightidus

    Yah thats it.

    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
  12. I don't think you'd be able to prevent other plugins from recieving a command but as others have suggested your best bet would probably be to register the player Command pre-process event.

    However if you registered this at the lowest priority it would be executed first and then you could run your code and cancel the event?
     
    Royal_Soda likes this.
  13. Offline

    knightidus

    Yeah that seems like my best bet, thanks every one!
     
Thread Status:
Not open for further replies.

Share This Page