Solved kick with newline

Discussion in 'Plugin Development' started by confuserr, Oct 26, 2012.

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

    confuserr

    I'm trying to kick a player with a reason which contains a newline, \n. I'm now using 1.4.2 as a client to test this, I'm sure this was working fine on 1.3.1 but the 1.4.2 client appears to just output \n rather than actually putting a new line. Was this feature removed from the 1.4.2 client?

    Also just tested with a 1.3.2 client and exact same thing is happening. I'm 100% sure they added the ability for the client to have new lines in kick messages.

    Happening on both the latest RB of craftbukkit (1.3.2) and latest of spigot (1.3.2 but allows 1.4.2 to connect)

    target.kickPlayer("You have been kicked for is this\\n on a new line? or do you see the \\ n characters?");

    This is what a player sees, https://dl.dropbox.com/u/16892708/IMG_26102012_175650.png

    Do I need to do some sort of formatting on the kick message?
     
  2. use 1 slash less
     
  3. Offline

    lol768

    You're escaping the slash which = a normal backslash. ferrybig is correct.
     
  4. Offline

    confuserr

    Does the same thing even if I do it via a command /kick player reason and include \n in the reason. Backslashes have to be escaped as they are a special character, Eclipse doesn't like it if its not escaped inside a string.
     
  5. Offline

    TerraVale

    I don't escape it and it seems to work just fine, try modifying this little snippet to your needs and see if it works.

    String motd = "Test Message\nTest Message2";
    event.getPlayer().sendMessage(motd.split("\n"));

    It's what I use to split messages in my MOTD, so figuratively speaking, it should work just as well in a kick message, providing you use the proper event.
     
  6. Offline

    md_5

    No idea why you would use that.... Might as well just use motd = 'Test Message' no?

    Anyway you can definitely do it with \n, note the single slash.
     
  7. Offline

    confuserr

    I still can't get this to work, even the inbuilt craftbukkit kick command still displays the \n rather than forcing it onto a new line.
     
  8. Offline

    Postkutsche

    I believe the kick command escapes these characters, perhaps you even get escaped Strings in onCommand method.
    Just try using the following code:
    Code:
    player.kick("Line 1\nLine 2");
     
  9. Offline

    confuserr

    Ok, appears to work if I hard code that in.

    Do hashmaps escape it? I'm using

    plugin.banMessages.get("kickReason")

    to set the kick message, where banMessages is a HashMap which contains a node from the config.yml
     
  10. A HashMap doesn't change its content in any way.

    I think in a YAML you have to escape the slash so it reaches you HashMap correctly. Try writing this in your config:
    YourNode: "This is\\na test"
    I might be wrong through...
     
  11. Offline

    confuserr

    Outputs \\n :(
     
  12. confuserr None the less I'm pretty sure the YAML is the problem here. I'll do some tests...
     
    confuserr likes this.
  13. Offline

    bergerkiller

    confuserr
    Entering \n into the chat will not result in a newline without additional conversion. The '\' character is entered by the user and converted to '\\', resulting in '\\n'.

    If you want to be absolutely sure everything is working, just replace the text...
    PHP:
    banMessage banMessage.replace("\\n""\n");
     
    Batman500, TigerHix and confuserr like this.
  14. Offline

    confuserr

  15. confuserr Writing this in the config:
    Test: This is\na test.
    didn't work, but writing this:
    Test: "This is\na test."
    worked. ;)
     
  16. Offline

    aciid

    I think you had to use double "quotes"
     
Thread Status:
Not open for further replies.

Share This Page