Solved .trim() not working?

Discussion in 'Plugin Development' started by Cheesepro, Dec 14, 2014.

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


    .trim() not working? I don't know why... is it something because of the chat formatting thing in Bukkit?
        public void noAdsmsg(AsyncPlayerChatEvent e) {
            Player p = e.getPlayer();
            if(!p.hasPermission("")) {
                String link = e.getMessage().toLowerCase().trim();
                if (link.contains(".com") || link.contains(".net") || link.contains(".me") || link.contains(".tk") || link.contains(".org") || link.contains(".us") || link.contains(".eu") || link.contains(".ca") || link.contains(".biz") || link.contains(".co") || link.contains(".info")) {
                    p.sendMessage(ChatColor.YELLOW.toString() + ChatColor.BOLD + "!==================================!");
                    p.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "###!!!!!Link(s) detected in message!!!!!###");
                    p.sendMessage(ChatColor.RED.toString() + ChatColor.BOLD + " *Messages sending action cancelled!*");
                    p.sendMessage(ChatColor.YELLOW.toString() + ChatColor.BOLD + "!==================================!");
  2. Offline



    Considering you haven't described the desired behaviour or the observed behaviour, we can't help you.

    However, you are accessing configs asynchronously, which is a bad idea.
  3. Offline


  4. Offline


    @Cheesepro Split the string with a white space. this will return a collection of strings
    ( String[] ) and then check if a string in the collection of strings starts with www
  5. Offline


    @Funergy @teej107 @mythbusterma
    Thank you guys all, but the only reason I want to no space is to prevent some advertisers type out website link like "google . com" or "g o o g l e . com"

    And p.sendMessage(link); in the code prints out ". com" when I say ". com" in chat, since I think it should be printed like ".com"

    apparently .replaceAll(" ", "") works... for some reason

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 29, 2016
  6. Offline


    trim() just removes the whitespaces in the start and end of the string as I have quoted from the documentation.
  7. Offline


    Ohhhh s*** I forgot about dat xD
  8. replaceAll() is for when using regex - since you're not using regex, I recommend that you change it to replace(). It will still replace all occurrences. :)
    es359 likes this.
Thread Status:
Not open for further replies.

Share This Page