Help with String Builders

Discussion in 'Plugin Development' started by TheFoolswithTools, Jul 24, 2013.

Thread Status:
Not open for further replies.
  1. Hey everyone! I've been making this one plugin and I'm trying to add this thing into the plugin that will allow for the user to force a user to chat.. Which I've done but I need it for my string builder won't call args[0] here's my code
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("fakechat")) {
    2. if (!sender.hasPermission("prank.fakechat")) {
    3. sender.sendMessage(ChatColor.RED + "You do not have permission to do this!");
    4. return true;
    5. }
    6. if (args.length == 0) {
    7. sender.sendMessage(ChatColor.RED + "Please specify a name!");
    8. return true;
    9. }
    10. Player target = Bukkit.getServer().getPlayer(args[0]);
    11. if (target == null) {
    12. player.sendMessage(ChatColor.RED + "Could not find player!");
    13. return true;
    14. }
    15. if (args.length == 1) {
    16. sender.sendMessage(ChatColor.RED + "Please specify text!");
    17. return true;
    18. }
    19. StringBuilder message = new StringBuilder("");
    20. for (String part : args) {
    21. if (!message.toString().equals(""))
    22. message.append(" ");
    23. message.append(part);
    24. }
    25. target.chat(message.toString());
    26. }
    27. return true;
    28.  


    I'm still learning Java and all that so I appreciate all the help I can get :D So yeah.. I just don't know how to stop args[0] from being called in the String builder any help?
     
  2. Offline

    ZeusAllMighty11

    Just use an iterator to skip over the arg(s)

    Code:
    for(int i=1; i<args.length; i++){ // change 1
        sb.append(args[i]).append(" ");
    }
    String s = sb.toString();
    
     
Thread Status:
Not open for further replies.

Share This Page