OP not working?

Discussion in 'Plugin Development' started by jorster23, Sep 17, 2012.

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

    jorster23

    Code is here: http://pastebin.com/6QPN1LUj

    What I'm trying to do here, is make OP only toggleable from the console. However, when I do /op In game and In Console, It just says "/op [player]" Do I need to have code to disable the vanilla OP command, or what?
     
  2. Offline

    zack6849

    see if the sender is not an instanceof player and if so allow the command, else, send the sender a message stating that it could only be executed from the console
     
  3. Offline

    jorster23

    how would one do that? I'm fairly new to Java.
     
  4. Offline

    RingOfStorms

    Plater p = event.getPlayer();
    if(p instanceof Player) {
    sendmsg.(BAD);
    e.setcancelled(true);
    return;
    }else{
    //do nothing continue from console
    }

    @jorster23
     
  5. Offline

    DirtyStarfish

    In the PasteBin it looks like you are trying to override the onCommand method from JavaPlugin or CommandExecutor.

    The method only has one CommandSender as an argument, in the code provided, there is two. I would suggest to change the "cs" reference to "sender", and delete the ", CommandSender cs" part of the onCommand methods parameters. If you don't have it, add "@Override above the onCommand method, and it should tell you what parameter types it expects (assuming you are using an IDE).

    Try this code (untested).
    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    3. {
    4. if (cmd.getName().equalsIgnoreCase("op") && args.length == 1)
    5. {
    6. if (sender instanceof Player)
    7. {
    8. sender.sendMessage("This command is disabled!");
    9. return true;
    10. } else
    11. {
    12. Player op = Bukkit.getPlayer(args[0]);
    13. if (op != null)
    14. {
    15. op.setOp(true);
    16. return true;
    17. } else
    18. {
    19. sender.sendMessage("Player is not online!");
    20. }
    21. }
    22. }
    23. return false;
    24. }
    25.  
     
    zack6849 likes this.
  6. Offline

    jorster23

    DirtyStarfish
    Thanks! I will test this when I get home, and post a status update about whether or not it works.
     
Thread Status:
Not open for further replies.

Share This Page