Replace Player name of String.toLowerCase to Player exact name

Discussion in 'Plugin Development' started by Maxx_Qc, Apr 25, 2015.

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

    Maxx_Qc

    Hi, I want to make my chat cleaner so I tried this:

    Code:
    for(Player eno : Bukkit.getServer().getOnlinePlayers()){
                String msg = event.getMessage();
                if(!msg.endsWith(".") && !msg.endsWith("?") && !msg.endsWith("!")) {
                    Player name = Bukkit.getServer().getPlayerExact(eno.getName());
                    String basemsg = msg.substring(1).toLowerCase();
                    String newmsg = basemsg.replaceAll(eno.getName(), name.getName());
                    event.setMessage(("" + msg.charAt(0)).toUpperCase() + newmsg + ".");
                } else {
                    event.setMessage(("" + msg.charAt(0)).toUpperCase() + msg.substring(1));
                }
            }
    
    It doesn't works, any one know a way I could do it?
    Thank your :)
     
  2. Offline

    Gater12

    @Maxx_Qc
    What exactly are you trying to do?
    You shouldn't use getPlayerExact(eno.getName()) because it's redundant (The Player object 'eno' is already provided) and decrease performance.
     
  3. Offline

    1Rogue

    I don't see how this will clean anything, only make players angry that they can't use any capitalization or puncuation.
     
  4. Offline

    Maxx_Qc

    Ok so I'm trying to do this:
    When a player send a message in the chat, for example 'SDFGGDFG DG DS Notch', if the sentence doesn't end with a '.', a '!' or a '?', it will put a '.' at the end. It will also put the message to lowercase but when it puts the message to lowercase, it also put username to lowercase. The example will go like this 'Sdfggdfg dg ds notch.' I want only username to be "normal", to be exact.
    @Gater12
    I wish you understand, sorry for mistakes
     
  5. Offline

    Msrules123

    @Maxx_Qc

    Try:
    1. Splitting the message into two parts at the desired character. (For example, > or : [Some chats use the <Name> format, some use the Name: format] Ex. http://prntscr.com/6yhi6a and http://prntscr.com/6yhkm2)
    2. Taking the second part of the string and doing your changes.
    3. Re-add it to the first string
    4. Set the message
     
  6. Offline

    Maxx_Qc

  7. Offline

    Msrules123

    @Maxx_Qc
    Code:
    String[] messageParts = e.getMessage().split(/* Your constant here */);
    String realMessage = messageParts[1];
    // Your check here, but on realMessage
    e.setMessage(messageParts[0] + /* Edited "realMessage" */); // This line replaces your current e.setMessage() 
    That's all I'm giving you, and if you don't understand my signature I'd advise you to learn Java.
     
  8. Last spoon feed of the day :D
    Code:
    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent event) {
        String[] message = event.getMessage().split(" ");
        StringBuilder sb = new StringBuilder();
        for(String string : message) {
            Player player = Bukkit.getPlayer(string);
            if(player == null) {
                sb.append(string).append(" ");
            } else {
                sb.append(player.getName()).append(" ");
            }
        }
        event.setMessage(sb.toString().trim());
    }
    
     
  9. Offline

    1Rogue

    ...wat

    that literally does nothing about what the op requested
     
    AdamQpzm and Msrules123 like this.
  10. @1Rogue From his attitude before, and the fact you yourself have already spoken to him about it, he doesn't actually want to help people anyway. I'm surprised his spoon-feeding is ever even relevant to be honest.

    @Maxx_Qc Please... just don't do this. Especially not the way you're doing it at the moment. I know it can be annoying when a player uses all caps, but I absolutely despise servers that try to enforce this with a plugin. I have never seen a system like this that didn't end up causing me far more frustration than has been caused by all caps speech. All the fancy methods and regex in the world isn't going to make a suitable system, because of the simple fact that there are far too many possibilities that a human wouldn't actually see as annoying, but a computer would 'fix' anyway.

    I'll give some examples of that. Say someone said something funny or cool or whatever, and I wanted to simply respond with an emoticon, such as one like this: : D (without the space, otherwise the forum will turn it into :D) Now, being the internet, most of the people have embraced this form of communication, and wouldn't see it as an annoying response. However, it consist purely of a colon and a capital letter. Most anti-caps system won't like that. They won't like that at all. The resulting message will ": d" (again, without the space) which just looks ridiculous.

    So, maybe you have some system that factors in emoticons or whatever. That still leads another problem, another story. I am one of the people who recognise that "lol" doesn't really have much of an impact, because people tend to use it loosely. Not that I'm pointing blame, I tend to do it myself too. So to get around this problem, a few friends and I have gotten into the habit of using "LOL" when something actually makes us laugh. Now, while I can't speak for everyone, I know a lot of people wouldn't find this annoying when it's a response on its own. But again, it's an all caps message, so I'm afraid that's out the window now...

    Finally, on to what you're doing wrong exactly: Currently the only capitals you allow are the first letter, and usernames, in which case you force a capital or force matching capitals. The primary problem with this is that there are genuine uses of capitals, not just for the start of a message, or for usernames. "I", proper nouns, even the start of sentences... doomed to lowercase, they will be. You also have introduced another issue, which I admit isn't really that likely to be abused, but it's quite easy and can be annoying. And if there's anything the internet has proven, people will abuse something annoying if it's easy. Just think why you're making this plugin in the first place...

    Okay, so say I went out and bought a Minecraft account, or even changed one of my alt accounts name, to a fairly common word. Let's take "because" as an example. Now, being the sort of fellow that I am, I'm going to use a weird mix of capitals for my name. Henceforth, I shall be known as "beCAUsE". And I'm about to join your server. Now, thanks to your plugin, people are going to be forced to match my capital style. Here goes an example conversation:

    Player 1: We should head down that cave.
    Player 2: Why's that?
    Player 1: Well beCAUsE there's iron down there.
    Player 2: Why did you type beCAUsE like beCAUsE?
    Player 1: I didn't, I just typed beCAUsE but it came out like beCAUsE for some reason.

    Don't you think that would get annoying? More annoying than the odd player who would insist on using excessive caps? I think so. So please, just don't make a plugin like this. I detest them, and I think I've shown I have good reason to. Also, forcing someone to use a full stop really is quite rude.
     
  11. No ? that's how I understood his problem. 12 am xD

    @Maxx_Qc Can you explain me your problem better ?
     
    Last edited: Apr 27, 2015
  12. Offline

    Maxx_Qc

    @MaTaMoR_ Nervermind it appears to be too hard for everyone in here
     
  13. Offline

    1Rogue

    It's not "too hard", it's just a terrible idea.
     
  14. Offline

    Look

    Is this fixed? If yes just nvm. If it's not, I understood what he mean and that's not a terrible idea, that's kinda easy to understand. He wants basically to replace every "?", "!" to a "."(dot). And every capital letter(like "C", "A"...) to a non-capital one, like to make all sentence toLowerCase(). That's not a useless thing, quiet to the contrary, can be very useful to huge and big servers which have a lot of people talking and CAPS LOCKING.
    That's what I understood by what he said, if I am wrong correct me please, but if I am right and this problem is not solved, I can help you :D

    P.S.: I don't give free answers like the final code, I explain what you need to do to get the answer to your problem and understand what you asked, so If you don't know Java, like someone said up there: "better you to learn it". =p

    Thank you, and sorry if my English is bad, that's because I am Brazilian.
     
  15. Offline

    1Rogue

    Please enter the following lines in chat with those features in place:

    Emoticons :D
    My real name is Bob
    something something Proper Nouns
     
  16. Offline

    Maxx_Qc

    @Look You don't get it.
    Exemple : I type in chat : HI MAXX I REALLY LOVE CAPS
    It will set my message to : Hi Maxx i really love caps.
    Maxx = Username so Caps are not replace with lowerCase
    If the sentence doesn't end with a ".", "!" or a "?" it will put a dat
    Example 2 : I type in chat : What is your name?
    It will set my message to : What is your name?
    Because there's no capitals and there's a "?" at the end
     
  17. Offline

    1Rogue


    Okay, but that still doesn't solve any of this:

    Code:
    Emoticons :D
    My real name is Bob
    something something Proper Nouns
    ->

    Code:
    Emoticons :d
    My real name is bob
    Something something proper nouns
    Are people on your server only going to say pre-determined sentences?
     
  18. Offline

    Maxx_Qc

    It's better then these noob spamming chat with caps!
    @1Rogue
     
  19. Offline

    mythbusterma

    @Maxx_Qc

    Not really, get a halfway decent moderating team and you won't have this issue at all.
     
  20. Offline

    Konato_K

    @Maxx_Qc If your real problem is just caps then checking if the message contains more than 5 or so caps can do the job (can be adjusted according to the length of the message, etc, etc, but way less intensive than other things).
     
  21. Offline

    1Rogue

    I can guarantee you that players will not see it that way.
     
  22. Offline

    Look

    So, just the first letter as uppercase?
     
  23. Offline

    Maxx_Qc

    Fine, solved!
     
Thread Status:
Not open for further replies.

Share This Page