Broadcast

Discussion in 'Plugin Development' started by Developher, Jul 21, 2012.

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

    Developher

    Hello all,

    I am trying to create a 'Broadcasting' plugin for my server. It is identical to the bukkit /say, but I want to remove the [Server]. I am trying to make a stringBuilder that will save what the player says that is announcer and out put that via Bukkit.broadcastMessage(str);

    EX: /announce Hi
    Output: Hi

    EDIT: Needs to be accessible via console!

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args) {

    Player player = (Player) sender;

    if(!player.hasPermission("vannounce.announce")) {
    returntrue;
    }

    if(cmd.getName().equalsIgnoreCase("announce")) {

    Bukkit.broadcast(args, "vannounce.announce");

    }
     
  2. Offline

    CorrieKay

    Code:
    if(args.length>0){
      String message = "";
      for(String word : args){
        message+=word+" "; 
      }
      Bukkit.broadcastMessage(message.trim());
      return true;
    }
     
  3. Offline

    Developher

    'Args' in the for is erroring: cannot iterate:

    Update:
    if(!player.hasPermission("vannounce.announce")) {
    returntrue;
    }

    if(cmd.getName().equalsIgnoreCase("announce")) {
    if(args.length()>0){
    String message = "";
    for(String word : args){
    message+=word+" ";
    }
    Bukkit.broadcastMessage(message.trim());
    returntrue;
    }

    bump

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

    Dreeass

    Use String message = args.toString();

    On iPod, can't check. You have to make String[] a String.

    Edit: I think args should be a String[], but not sure.
     
  5. Offline

    CorrieKay

    wait, what? how cant it iterate? what is "args" at that point?
     
Thread Status:
Not open for further replies.

Share This Page