Only letting a player do a certain command?

Discussion in 'Plugin Development' started by CdoingBaddie, Sep 21, 2013.

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

    CdoingBaddie

    Here's my code:
    Code:
       @EventHandler
    public void onCommandUse(PlayerCommandPreprocessEvent e){
    Player p = e.getPlayer();
    if(plugin.adminmode.contains(p.getName())){
    }else{
    e.setCancelled(true);
    p.sendMessage(ChatColor.RED + "You may not execute any commands in admin mode!");
    }
    }
    And I want to make it so when they're in admin mode, they can only do /admin.
    help please!

    Herro? :(

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

    Hoolean Retired Staff

    CdoingBaddie

    First, please only bump after 12/24 hours.

    Secondly, what's not working? What do you need to add in? Are there any errors? Etc.

    We need more infomation :p
     
  3. Offline

    CdoingBaddie

    And I want to make it so when they're in admin mode, they can only do /admin.
    help please! .. Look at the post.
     
  4. Offline

    JazzaG

    CdoingBaddie

    Your logic is flawed. You're cancelling the command if they're not in admin mode. Don't forget to check whether the command is 'admin':

    Code:
    @EventHandler
    public void onCommandUse(PlayerCommandPreprocessEvent e){
        Player p = e.getPlayer();
        if(plugin.adminmode.contains(p.getName())){
            if(!e.getMessage().equalsIgnoreCase("/admin")) {
                e.setCancelled(true);
                p.sendMessage(ChatColor.RED + "You may not execute any commands in admin mode!");
            }
        }
    } 
    
     
  5. Offline

    CdoingBaddie

Thread Status:
Not open for further replies.

Share This Page