Solved Command only broadcasting args[0]

Discussion in 'Plugin Development' started by Techno, Apr 3, 2014.

Thread Status:
Not open for further replies.
  1. So, as the title says, when I run the command: /billcast I am cool, it only broadcasts 'I'...

    Code:
    Code:java
    1.  
    2. f (cmd.getName().equalsIgnoreCase("billcast")) {
    3. if(sender instanceof Player){
    4.  
    5. if(args.length == 0){
    6.  
    7. sender.sendMessage(ChatColor.RED + "You must have a message to broadcast, silly!");
    8.  
    9. }
    10.  
    11. if(args.length == 1) {
    12. Bukkit.broadcastMessage(ChatColor.GRAY + "[" + ChatColor.AQUA + "BillCast" + ChatColor.GRAY + "] " + ChatColor.AQUA + args[0]);
    13. }
    14. }
    15. return true;
    16. }
    17.  
     
  2. Offline

    Arcoz

    It only does that, because that's what you've made your code do.

    Check instead if the args is => 1 and set up a string builder.
     
  3. Arcoz
    How would I set up a string builder? And theres an error on
    Code:
    if(args.length => 1) {
     
  4. Offline

    Born2PvP

    Techno
    Code:java
    1. String message = "";
    2. for (String part : args) {
    3. if (message != "") message += " ";
    4. message += part;
    5. }
    6. Bukkit.getServer().broadcastMessage("[Broadcast]" + message);
     
  5. Offline

    Arcoz

    My mistake, it should be >=

    Also StringBuilder shouldn't be that hard to google...

    But since I'm so nice, I'll show you an example.

    PHP:
                        StringBuilder message = new StringBuilder("");
                        for (
    String part args) {
                            if (!
    message.toString().equals(""))
                                
    message.append(" ");
               
                            
    message.append(part);
                        }
               
                        
    Bukkit.getServer().broadcastMessage("prefix " message.toString());
                    }
     
  6. Arcoz
    Born2PvP
    So?:
    Code:java
    1.  
    2. if(args.length >= 1) {
    3.  
    4. String message = "";
    5. for (String part : args) {
    6. if (message != "") message += " ";
    7. message += part;
    8. }
    9.  
    10. Bukkit.broadcastMessage(ChatColor.GRAY + "[" + ChatColor.AQUA + "BillCast" + ChatColor.GRAY + "] " + ChatColor.AQUA + args[0]);
    11. }
    12.  


    Solved

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page