Looping help! #ProblemSolved#

Discussion in 'Plugin Development' started by linkkwtf, Jul 23, 2012.

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

    linkkwtf

    Hey guys making a /me <msg> cmd and need some help, can anyone see whats wrong with my code?
    Code:
                }else if(commandLabel.equalsIgnoreCase("Me")){ // Different broadcast messages!
                    if(player.hasPermission("SimpleChat.Me")){
                        {
                            player.sendMessage(ChatColor.DARK_RED + "/me <Message>");
                                }
                                    String defaultString = "*" + player.getName();
                                    for (int n = 0; n < args.length; n++){
                                        if (args[n].length() > 0) {
                                            defaultString = defaultString + " " + args[n];
                                    }
                                            player.getServer().broadcastMessage(defaultString);
                                }
                    }else{
                        player.sendMessage(ChatColor.DARK_RED + "You do not have permission!");

    thanks:D<3
     
  2. Problem is you're checking if there is either one or no arguments, you must check if there's at least 1, so args.length > 0.
    Also, you should use a StringBuilder as it's better for memory.
     
  3. Offline

    linkkwtf

    well before u i saw ur comment i did this and i get the msg now but i get this bug so it does like this:
    u type /me test test, then it comes up in chat
    *linkkwtf test
    *linkkwtf test test

    and so on and so on but dont know how to go from there:/
    hmm ill check up what stringbuilder is, thanks:)
     
  4. Yeah I've already told you to change that but you didn't understand it seems :}

    When using String str = ""; and then str += ""; etc it will actually create a new String object every time... instead, using StringBuilder you can append to it directly without it creating new String objects every time, and at the end you can use strBuilt.toString() to get the single String object.
    Also, using "whatever " + var + " more text" will actually convert into StringBuilder style in the compiler, like new StringBuilder("whatever ").append(var).append(" more text").toString(), you don't need to do this manually but I'm just mentioning it so you know how things work.
     
  5. Offline

    linkkwtf

    thanks:)

    Hi man some how i F***** it all up so if u can check the code and help me? ill give some credit

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

    r0306

    linkkwtf
    You've misplaced some brackets:
    Code:
    [FONT=Consolas] }else if(commandLabel.equalsIgnoreCase("Me")){ // Different broadcast messages![/FONT]
    [FONT=Consolas]                if(player.hasPermission("SimpleChat.Me")) // extra bracket here > {
                    {
                            player.sendMessage(ChatColor.DARK_RED + "/me <Message>");
                                // idk whats happening here but don't need it > }
                                    String defaultString = "*" + player.getName();
                                    for (int n = 0; n < args.length; n++){
                                        if (args[n].length() > 0) {
                                            defaultString = defaultString + " " + args[n];[/FONT]
    [FONT=Consolas]                                    } //bracket here
                                    }
                                    player.getServer().broadcastMessage(defaultString);
                               // don't need this bracket > }
                    }else{ [/FONT]
    [FONT=Consolas]                    player.sendMessage(ChatColor.DARK_RED + "You do not have permission!");[/FONT]
     
    linkkwtf likes this.
  7. Offline

    linkkwtf

    yea noticed after my comment thanks anyway:D<3
     
Thread Status:
Not open for further replies.

Share This Page