I neeed help with development! (Strings)

Discussion in 'Plugin Development' started by Garneift, Apr 17, 2014.

Thread Status:
Not open for further replies.
  1. Hello there! I have wonderer a while now how to make strings in bukkit. What i mean by that is if i type (Example: /setmessage 1 Hello There Everyone!

    And it says that message when someone does /showmessage 1)



    I mean i wonder how to set things without configs!


    Hope you understand!

    Thanks for a reply!

    ~Garneift~
     
  2. Offline

    Konkz

    PHP:
    if (args.length 1) {
      
    StringBuilder strBuilder = new StringBuilder();
      for (
    int i 1args.lengthi++) {
        
    strBuilder.append(args[i]);
        
    strBuilder.append(" ");
      }
      
    String message strBuilder.toString();
      
    Bukkit.broadcastMessage(message);
      }
    You'd add checks before that for the label and such, but, if all of that was added and I'd do for example hi im a message it would broadcast "im a message".

    Garneift
     
    DrEinsteinium likes this.
  3. Offline

    RawCode

    JVM build appenders on its own, you can STRING + STRING
     
  4. Offline

    DrEinsteinium


    If you use String concatenation in a loop (something like:
    Code:
    String s ="";
    for(int i =0; i <100; i++)
    {
        s +=", "+ i;
    }
    then you should use a StringBuilder (not StringBuffer) instead of a String, because it is much faster and consumes less memory.
    If you have a single statement:
    Code:
    String s ="1, "+"2, "+"3, "+"4, "....;
    then you can use Strings, because the compiler will use StringBuilder automatically
     
    Konkz likes this.
  5. Offline

    RawCode

    much faster and consume less memory to use char[] directly (as you may know String is wrapper over char[])
     
  6. Offline

    1Rogue


    The amount of conversion and work into passing char/byte arrays into string constructors and accounting for encoding is more work than necessary compared to StringBuilders/appending. The only reason to store text in a primitive data array would be for temporarily storing things like password text to protect from core dumping exposure.
     
    Konkz likes this.
Thread Status:
Not open for further replies.

Share This Page