Preventing a player from doing commands unless they do a certain command

Discussion in 'Plugin Development' started by superchris05326, Sep 30, 2014.

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

    superchris05326

    For my plugin, players must join a team before they can do any other commands. I tried this using this code but I can't do /team. Any ideas on how I could go about doing this?
    Code:java
    1. @EventHandler
    2. public void preCommand(PlayerCommandPreprocessEvent e){
    3. Player p = e.getPlayer();
    4. String pname = p.getName();
    5. if(!(PrayManager.inTeam(pname))){
    6. //not in a team
    7. if(!(e.getMessage().startsWith("team"))){
    8. e.setCancelled(true);
    9. p.sendMessage(ChatColor.RED + "Select a team using /team <good|bad> to be able to do commands!");
    10. return;
    11. }else{
    12. return;
    13. }
    14.  
    15. }else{
    16. //in a team
    17. return;
    18. }
    19. }
     
  2. Offline

    MCMatters

    Remove all

    return;

    AND

    Replace "team" with "/teams"
     
  3. Offline

    superchris05326

    MCMatters Ok and sorry about the second thing the command is /team - I just messed up when writing it. Which means that it still doesn't work.
     
  4. Offline

    MCMatters

  5. Offline

    superchris05326

    MCMatters
    Code:java
    1. @EventHandler
    2. public void preCommand(PlayerCommandPreprocessEvent e){
    3. Player p = e.getPlayer();
    4. String pname = p.getName();
    5. if(!(PrayManager.inTeam(pname))){
    6. //not in a team
    7. if(!(e.getMessage().startsWith("team"))){
    8. e.setCancelled(true);
    9. p.sendMessage(ChatColor.RED + "Select a team using /team <good|bad> to be able to do commands!");
    10. }
    11. }
    12. }
     
  6. Offline

    MCMatters

    I said do /team not team
     
  7. Offline

    superchris05326

Thread Status:
Not open for further replies.

Share This Page