Solved How do I make a ping event

Discussion in 'Spigot Plugin Development' started by CreepersGamingMc, Jun 3, 2017.

  1. Hello, I need to make a ping event then put this code inside it.
    Code (Text):
    e.setMotd(getConfig().getString("message").replaceAll("%newline%, \n"));
    But I need it to be in this code right here: https://pastebin.com/whSyUwPD
    Please help, and thanks!
     
  2. Just listen to the ping event then (ServerListPingEvent or something). Also, use replace rather than replaceAll, as replaceAll is meant for regular expressions, and you're just using a literal String.
     
  3. How would I put this into my current code?
     
  4. Just make an eventhandler like this:

    @EventHander
    public void onPing(ServerListPingEvent evt) {
    e.setMotd(getConfig().getString("message").replaceAll("%newline%, \n"));
    }
     
  5. Okay, i'll add this to my code
     
  6. Good luck! It has to be work
     
  7. This is my code so far, please correct it if I did this wrong
    https://pastebin.com/G3N2GHad
     
  8. The plugin works, but how do I make a new line?
     
  9. For the motd
     
  10. Try this:

    e.setMotd(getConfig().getString("message").replace("%newline%", "\\n"));
     
  11. But then how do I make this work? (How do I make this add a line when they want to) How do I use this?
     
  12. Are you want to set the motd with command or not?
    I read your code and i think it has to work.

    Just type command ingame: /setmotd something in line1%newline%something in line2

    And wait for the miracle :D
     
  13. This didn't work, this is my current code, and it doesn't work
    https://pastebin.com/mSb0HAfL
     
  14. Is the motd message isn't work too or just the newline?
     
  15. Just the newline feature here's my current code that I edited
    https://pastebin.com/LnitMzyq
     
  16. I found the soulution. In you config the line must be between double quotes like this: "line1\nline2"
     
  17. What do you mean?
     
  18. Oh i get it
     
  19. Mas

    Mas

    If everything is working then please mark the thread as solved. Also, use #replace and not #replaceAll in your code, because s stated above #replaceAll is for regex.
     
  20. Great, I'm glad! :D