Solved @A in command

Discussion in 'Plugin Help/Development/Requests' started by bubblefat_, May 24, 2015.

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

    bubblefat_

    Right now I am trying to make a /announce command basically like /say but it pops text on your screen as well. I need to know how to do @a in a command. Here is my code, so if there is an alternate way to do it then that would be great.

    Code:
    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "title @a title {text:\"Announce\",color:\"gold\",bold:true}");
                    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "title @a times 15 70 15");
    Whole class file:
    Code:
    package Commands;
    
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    
    public class Announce implements CommandExecutor{
      
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
          
            if (cmd.getName().equalsIgnoreCase("announce")) {
              
                if(!sender.hasPermission("ct.admin")) {
                    sender.sendMessage(ChatColor.GOLD + "Permissoins> " + ChatColor.GRAY + "Only " + ChatColor.RED + "Admins+ " + ChatColor.GRAY + "can use this command.");
                    return true;
                } else {
                    String message = "";
                  
                    for (int i = 0; i != args.length; i++)
                    message += args[i] + " ";
                  
                    Bukkit.broadcastMessage("§l§ka " + ChatColor.GOLD + "Announcement> " + ChatColor.RED + message);
                  
                    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "title @a title {text:\"Announce\",color:\"gold\",bold:true}");
                    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "title @a times 15 70 15");
                  
                  
                }
                if(args.length == 0) {
                    sender.sendMessage(ChatColor.GOLD + "Say> " + ChatColor.GRAY + "Improper usage. " + ChatColor.RED + "/say <message>" + ChatColor.GRAY + ".");
                    return true;
                }
                  
                return true;  
            }
          
            return false;
        }
    
    }
    
     
  2. Online

    timtower Moderator Moderator

    Moved to Bukkit alternatives
     
  3. Offline

    mine-care

    So you want to implement @a in the command? Simple! if the command contains @a run a loop with all online players and in the loop body perform actions per player by replacing the @a with the name or whatever :p
     
  4. Offline

    bubblefat_

    I'm new to bukkit, and your message is a bit confusing to me. I understand what you are saying, but I don't know how to do it. Could you explain how to do it and remember I'm an amateur.
     
  5. Offline

    mine-care

    @bubblefat_
    If the command contains @a in it (Use command args .contains("@a")) and if that returns true, then loop through all online players and execute the command as you showed above^
     
Thread Status:
Not open for further replies.

Share This Page