Newline problems

Discussion in 'Spigot Plugin Development' started by UnlimitedNinjas, Apr 17, 2019 at 4:45 PM.

  1. So i am trying to make it so when you do \n it does a new line in a kick command
    Problem is \n isn't doing a new line. Tried System.getProperty("line.seperator") and tried a for loop AND tried with \\n (double backslash). Still nothing
    code: https://hastebin.com/midapozuca.js

    config line: kick: '&c&lKICKED \n &cKicked by &a%user% &cfor &a%reason%'
     
  2. You can split at \n the Config string and make and loop, where you add looped 1 to a int and get the stplitted string

    Gesendet von meinem ANE-LX1 mit Tapatalk
     
  3. This should work properly, tried it and have it in my plugins in this form with \n as new line.
     
  4. You have no excuse for using a string instead of a stringlist. You could get the list and split it by "\n", fairly easy.

    Example:

    Code (Java):

    // Get your arg array into a single string joined by space.
    String argm =  StringUtils.join(args, " ", 1, args.length);

    // Get your stringlist and join it by \n (new line)
    /*
    options:
      kick:
      - 'test message'
      - 'test2'
    */

    // That would return: test message\ntest2
    List<String> list = plugin.getConfig().getStringList("options.kick");
    String result = StringUtils.join(list, "\n");

    String reason = setcolor(result.replace("%user%", sender.getName()).replace("%reason%", argm));
    target.kickPlayer(reason);
    Fairly simple and easy.

    You'll not have to deal with messy single lines where \n is connected with different messages making the string hard to read.

    Example:

    This message\nfor example\nwould be a bit\nharder to read\nthan the one\nbelow obviously.

    This message
    for example
    would be a bit
    harder to read
    than the one
    below obviously.

    Pretty clear a stringlist is the way to go.
     

Share This Page