Solved OP CMDS AND ISSUES HELP!!!!!!

Discussion in 'Plugin Development' started by LukeZurg22, Oct 6, 2016.

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

    LukeZurg22

    Ok, heres my problem. I am trying to update and work on my plugin but i found an issue i cant seem to fix, i am new to bukkit coding and i know a little bit of java but this issue keeps being a problem to me no matter what i do. What happends is that when i test the plugin out, i try /web and it says i dont have permission to use /vur but shows the link in the config anyways (also i am op ingame, i am trying to make it say i dont have permission when im not op and when i dont have the permission node and not say the msg if i dont have permission.) But in /vur it says i dont have permission to do /web but this time it DOESNT show its own set message, which is not set in config.yml also the same for /cred but it says i dont have permission to use /web aswell but im also trying to make it work just fine and say its messages as /op without any permission denied thing or when players can normally use it as long as they have the permission node.

    The codes of the commands are here: http://pastebin.com/ADdg3Gy5

    I didnt see it to be necessary to copy and paste every bit of code, only the commands.
     
  2. Offline

    kameronn

    put return true where the no perm messages are
     
  3. Offline

    LukeZurg22

    before: let me try that hold on
    (just now: it says that its unreachable code so i dont know how exactly where i need to put it, you didnt really sound that descriptive)
     
    Last edited: Oct 6, 2016
  4. Offline

    mehboss

    @LukeZurg22
    I do mine like this:
    Code:
                }
                if (cmd.getName().equalsIgnoreCase("test") {
                  if (!sender.hasPermission("test.perms")) {
                    sender.sendMessage(ChatColor.YELLOW + "You are lacking permission");
                    return false;
                }
                  sender.sendMessage(ChatColor.YELLOW + "Nice you have the permissions!");
                  return true;
          }
    
    for your code, try this if the returns didn't work, which they should. Here is one example:
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
            if (cmd.getName().equalsIgnoreCase("web")&& !sender.hasPermission("linkdis.perm.web")){
                  //send player message here
                  //make sure it doesn't return
         }
                  //send player message here
                 //make it return
                }
    }
     
    Last edited: Oct 7, 2016
  5. Offline

    Zombie_Striker

    This is useless. The only way you can even get to this point is if the sender does have the permission (since you checked for it before). Remove this if statement.

    This is far more than an "example". This is writing his plugin for him. In the future, if you want to post an example, make sure the member can't just copy in paste the code without making any modifications.
     
    bwfcwalshy likes this.
  6. Offline

    LukeZurg22

    i want ops to be able to use the command with or without the permission node thats not/is given to them but the "you do not have permission" message shouldnt show up for ops and the commands to be used by default players who MUST HAVE the permission node
     
  7. Offline

    mehboss

    OPs have every permission node.
     
    Last edited: Oct 7, 2016
  8. Offline

    LukeZurg22

    well OPs cant use the /vur, and /cred when they do /web it says they dont have permission like the other commands but still shows the message anyways
     
  9. Offline

    mehboss

    @LukeZurg22
    Are you still using that code at the way beginning?
    Send me the code and the config so we can examine it.

    Sorry, didn't think he would copy and paste it :)

    Spoon feeding is bad!
     
    Last edited: Oct 7, 2016
  10. Offline

    I Al Istannen

    @mehboss
    And don't return false just because he has no permission. This will send the usage which is totally useless. Return false only if the arguments of the command were mismached.

    Personally I NEVER return false but send the message myself (or let my system send it), as it can be coloured this way.

    EDIT: Code snippet:
    Code:
                  if (!sender.hasPermission("test.perms")) {
                    sender.sendMessage(ChatColor.YELLOW + "You are lacking permission");
                    return false;
     
  11. Offline

    LukeZurg22

    @I Al Istannen

    is anyone seriously trying to help my current situation? i posted on the forums for a reason :/
     
    Last edited: Oct 7, 2016
  12. Offline

    I Al Istannen

    @LukeZurg22
    I have honestly no idea what your problem is. Your off post is very confusing.

    But you have a few logic errors in that (unformatted, Press Ctrl+Shift+F in eclipse) code.

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2.  
    3. if (cmd.getName().equalsIgnoreCase("web") && sender.hasPermission("linkdis.perm.web")) {
    4. sender.sendMessage(getConfig().getString("WebCommandMsg"));
    5. // web executed, we can return here
    6. } else { // this will fire for all commands, if the sender doesn't have the permission for web
    7. sender.sendMessage(ChatColor.DARK_RED + "You don't have permission to do /web!");
    8. return true;
    9. }
    10. if (cmd.getName().equalsIgnoreCase("cred")) {
    11. // no permission check here?
    12. sender.sendMessage(ChatColor.YELLOW + "Credit Goes To" + ChatColor.GOLD + " LukeZurg22");
    13. return true;
    14. }
    15. if (cmd.getName().equalsIgnoreCase("vur") && sender.hasPermission("linkdis.perm.vur")) {
    16. sender.sendMessage(ChatColor.YELLOW + "Version: 1.5");
    17. } else { // this will fire for all commands, if the player doesn't have permission for vur or entered an unknwown command.
    18. sender.sendMessage(ChatColor.DARK_RED + "You don't have permission to do /vur!");
    19. return true;
    20. }
    21. return false;
    22. }


    You need to restructure that.
    Use this structure:
    Code:text
    1. if( command name equals wb) {
    2. if(has permission) {
    3. execute web
    4. return true;
    5. }
    6. else {
    7. send no permission message
    8. return true;
    9. }
    10. }
    11. else if( command name equals cred) {
    12. execute cred
    13. return true;
    14. }
    15. else if( command name equals vur) {
    16. if(has permission) {
    17. execute vur
    18. return true;
    19. }
    20. else {
    21. send no permission message
    22. return true;
    23. }
    24. }
    25. else {
    26. return false;
    27. }
     
  13. Offline

    LukeZurg22

    @I Al Istannen
    That is a bit confusing but here is a recording of what actually happends so you get a better idea of what my problem is.
     

    Attached Files:

  14. Offline

    Zombie_Striker

    @LukeZurg22
    No one will download anything here. If it's code or from a txt file, post it using the [code.][/code] tags.
     
  15. Offline

    LukeZurg22

    What? i simply made a video that shows the problem! Ill just post on youtube and give the link, is that fine?

    Youtube video of problem:

    It clearly shows what happends ingame when the commands are executed. The structure I AI ISTANNEN recommended confuses doesnt help much.
    Also, www.google.com in the video is what is entered in the config.yml, but that is of no importance.
     
  16. Offline

    PumpMelon

    Your structure is probably way off if stuff like that is happening, make sure your { } are in tact.
    Also, I'd suggest learning more Java as this is simple stuff. What I would recommend is reading Java for dummies 6th edition, it helped me a lot and the author (Barry Burd) makes it entertaining and fun.
     
  17. Offline

    LukeZurg22

    where do i find a proper guide? not youtube videos but like the actual guide? ive read this https://docs.google.com/document/d/1RABwEM8FNPHwREOtH3AjTKsPt0jNsvGqb0okPn5-5TY/edit#
    and it helped me find out how to make a plugin etc. but sofar my problem hasnt been resolved and im still waiting for help with it instead of being told "its simple" when if its that simple, it should be THAT simple to give a direct, and clear answer on what i need to do to fix it.
     
  18. Offline

    Zombie_Striker

    You can find tutorials HERE.

    The reason this is happening is because of bad code structure. This is what the last few posts have been discussing.
    Lets discuss what this says:
    1. Check if the command is "web" and if the sender has permission. If so, send the string from config.
    2. If either of those two cases are not met, just say it did not work and stop reading the rest of the command.
    If the command if not "web", you will receive the permission error. So that means the command "/vur" will never be checked for.

    How to solve: Use @I Al Istannen 's format. Here's another (hopefully better) explanation:
    Code:
    if(the command is "web"){
      if(player has perm){
         //Do what you want if they have the perms
      }else{
       ///Do what you want if they DONT have perms
      }
    } else if (command is "vur"){
      if(player has perm){
         //Do what you want if they have the perms
      }else{
       ///Do what you want if they DONT have perms
      }
    }
     
    I Al Istannen likes this.
  19. Offline

    LukeZurg22

    ok THAT makes a ton more sense! thank you! also /cred isnt supposed to have a permission node, its meant to be used by any player.
     
  20. Offline

    Zombie_Striker

    @LukeZurg22
    In which case, you do not need to add the perm checks.

    If your problem has been solved, mark this thread as solved.
     
  21. Offline

    LukeZurg22

Thread Status:
Not open for further replies.

Share This Page