Problem with isOP ect.

Discussion in 'Plugin Development' started by DirtyReignbow, Aug 17, 2014.

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

    DirtyReignbow

    Hello,

    I'm trying to code in a way for the OP's to only chat between themselves by using a /oc command which stands for operator chat. But when i deopped myself on the server the commands still work the same but only display the other message afterwards. I'm quite new to coding so that's probably why i don't understand where the error is coming from but please can you help me fix it?

    Here's the code section:
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("oc")) {
    2. for (Player player : Bukkit.getServer().getOnlinePlayers())
    3. {
    4. if(player.isOp());
    5. {
    6. player.sendMessage(ChatColor.RED + player.getName() + ": " + args[1] );
    7. }
    8. if(!player.isOp()){
    9. sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You are not an Operator");
    10. }
    11. }
    12. }


    Thank you!
    ~DirtyReignbow
     
  2. Offline

    TrollTaylor

    You put a ; after your if(player.isOp())
     
    Garris0n likes this.
  3. Offline

    fireblast709

    DirtyReignbow Do note, that when you use /oc, every non op on the server will get the no op message.
     
  4. Offline

    DirtyReignbow

    fireblast709 how would i change this so that only ops will see the messages and use multiple words instead of the arg only allowing one?

    Thanks.
    ~DirtyReignbow
     
  5. Offline

    _Filip

  6. Offline

    Skionz

    Personally I would have the user do /oc then it would send them saying the op chat is enabled and I would add them to a list or hashmap or something. Then whenever the player sends a chat message check if they are in that list and if they are only send the message to everyone that is op. When they use /oc again it would check if they are in the list and if they are it would remove them.
     
  7. Offline

    DinosParkour

    DirtyReignbow modify it a bit:
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("oc")){
    2. if(sender.isOp()){
    3. for(Player online : Bukkit.getOnlinePlayers(){
    4. if(online.isOp()){online.sendMessage(ChatColor.RED + sender.getName() + ": " + args[1] );}
    5. }
    6. }else{sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You are not an Operator");}
    7. }
     
  8. Offline

    DirtyReignbow

    DinosParkour would that work for all ops online or just the designated OP player? Also when i am opped the "You are not an operator" shows with the command? Is there any way around that?

    TheSpherret I've thought of making the chat for only OP's to see but with it being global, when you're not the op it doesn't allow you to use the command. I also have another problem which is when i don't add the values so if i just do "/oc" alone it will come up with an internal error. "An internal error occurred while attempting to perform this command" Is there any way to get rid of that?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page