Command on NameTag

Discussion in 'Plugin Development' started by ItsBlockFighter, Apr 27, 2017.

Thread Status:
Not open for further replies.
  1. Hi!
    I made a command and I want to solve it if you type it then the name of the tab is red and if you type it again then it will not be red, how can it be resolved? How to add code?

    My Command Code:
    Code:
        private ArrayList<String> Duty = new ArrayList<>();
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            String command = cmd.getName();
    
            if (sender instanceof Player) {
    
                Player player = (Player) sender;
               
                if (command.equalsIgnoreCase("aduty")) {
                    if (player.hasPermission("risegaming.admin.duty") || player.isOp()) {
                       
                        if(!Duty.contains(player.getName())) {
                            player.sendMessage(ChatColor.BLACK + "[" + ChatColor.RED + "AdminSystem" + ChatColor.BLACK + "]" + ChatColor.GREEN + "Sikeresen admin szolgálatba léptél!");
                            player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, Integer.MAX_VALUE);
                            player.setAllowFlight(true);
                            player.setFlying(true);
                        } else {
                            player.sendMessage(ChatColor.BLACK + "[" + ChatColor.RED + "AdminSystem" + ChatColor.BLACK + "]" + ChatColor.GREEN + "Sikeresen kiléptél az admin szolgálatból!");
                            player.setAllowFlight(false);
                            player.setFlying(false);
    
                            Duty.remove(player.getName());
                        }
                    }
                    else {
                        player.sendMessage("Nincs jogod hozzá");
                        player.playSound(player.getLocation(), Sound.ENTITY_ZOMBIE_PIG_ANGRY, 1, Integer.MAX_VALUE);
                    }
                }
            }
            return false;
        }
    
    }
     
  2. Offline

    Zombie_Striker

    @ItsBlockFighter
    1. You forgot to add the player to Duty if they are not in it.
    2. Duty should be lower case. Variable names should start with a lowercase letter.
    3. You only use command once. Remove it and replace the reference to it with cmd.getName
    4. Main problem: If the player is in duty, have the chat message contain red.
     
  3. Offline

    Zombie_Striker

  4. Offline

    xXkguyXx

    Pretty sure he wants the name on top of the player red.
     
Thread Status:
Not open for further replies.

Share This Page