Detect Links or Server IP's in chat messages.

Discussion in 'Plugin Development' started by DerFreakey, Jan 9, 2015.

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

    DerFreakey

    Hey Guys,
    im developing a chat plugin, and there I want to add a link and serverip detection.
    But i actually don't know how to do this, so i need your help.

    Can you please tell me how i can detect links?

    If you know it, please give me permission to use this code in my plugin (i write it for a minecraft server).
     
  2. Offline

    SuperOriginal

    AsyncPlayerChatEvent:
    If message contains resemblance of a link or ip: do stuff
     
  3. Offline

    DerFreakey

  4. Offline

    MisterErwin

    leon3001 likes this.
  5. Offline

    DerFreakey

    Well, @MisterErwin
    Im pretty new in developing, so what is a regex? :) (Short description pls :))
     
  6. Offline

    API_Tutorials

  7. Offline

    NonameSL

    You dont need a regex. You can try creating a new URL for every part of the text, and if an exception is catched that mean that the piece isn't a URL and you can continue ewith the loop. But if there is no exception catched, that means that it is a url.
     
  8. Offline

    Luke_Lax

    Yeah let's just waste valuable resources why not...

    You do need regex, regex is short for regular expression and it's like a ctrl+f (find) function although it can do many other things like that. You can't really sum up how to use regex as it's quite powerful so I'd give this a read:
    http://docs.oracle.com/javase/tutorial/essential/regex/intro.html
     
    Konato_K, Experminator and AdamQpzm like this.
  9. Offline

    AdamQpzm

    @NonameSL As above, regex is a more powerful option, and using it will be much more... professional, I suppose. I'm curious - is there any real reason to use your alternative method, other than either a lack of understanding of how regex works, or an irrational hate for it?
     
  10. Offline

    mythbusterma

    @AdamQpzm

    He has a certain quotient for slowness, waiting for failed HTTP requests and network timeouts helps him fill that quotient quite quickly, as it could easily take upwards of a second for a long message
     
    AdamQpzm likes this.
  11. Offline

    NonameSL

    @AdamQpzm actually I think regex is great and I use it all the time, it's just that this is an easy way to detect any link: an email address, an IP, a link and so on...

    @mythbusterma You're right, it isn't efficient if it is used in this context, I am just stating that you can also do the same thing with creating new instances of URLs.
     
  12. Offline

    mine-care

    Well the best I can think of is a sum up of the above like a regex to match ips and domains and if matching returns a possible ip ect, you can delay the message like telling its user "processing suspicious message..." Or something and ping the host but that is a optional thingy and not the most efficient thing to do :/
    Good luck =]
     
Thread Status:
Not open for further replies.

Share This Page