Solved Twitter-Tagging in the Game-Chat...

Discussion in 'Plugin Development' started by TheLexoPlexx, Sep 9, 2014.

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

    TheLexoPlexx

    Hey there,

    I'm really confused and I just want to get the Name of the Player when somebody writes maybe:
    "Hey there @Homer04"

    I did it about a 1 million times with commands but never with the chat. Somebody ever worked on that? :D
     
  2. Offline

    SmooshCakez

    Listen for AsyncPlayerChatEvent, use e.getMessage(), and check if it contains the name of an online player.
     
  3. Offline

    TheLexoPlexx

    Thats exactly what I have, except:
     
  4. Offline

    SmooshCakez

    Loop through the online players, each time you loop, check if the message contains their name.
     
  5. Offline

    TheLexoPlexx

    And how do I check for the "@"??
    There's a difference between:
    "@Homer04 who griefed this?"
    and...
    "I think Alex did it
     
  6. TheLexoPlexx When checking for the name, check for the @ + the name... show code for how you've tried :)
     
  7. Offline

    MrSparkzz

    TheLexoPlexx
    You need to loop through the online players.. doing what you did wont loop. You wanna do something like this
    Code:java
    1. for (Player player : Bukkit.getOnlinePlayers()) { // for every online player, it will put that player in a Player variable, then you can use player.someMethod(); within the loop.
    2. // post your code here
    3. }
     
  8. Offline

    TheLexoPlexx

    So...
    Code:
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onChat(AsyncPlayerChatEvent e) {
            if (e.getMessage().contains("@" + Bukkit.getOnlinePlayers())) {
                for (Player player : Bukkit.getOnlinePlayers()) {
                    player.playSound(player.getLocation(), Sound.ANVIL_LAND, 10, 10);
                    }
            }
        }
     
  9. Offline

    MrSparkzz

    TheLexoPlexx
    No, you would wanna put this
    Code:java
    1. if (e.getMessage().contains("@" + Bukkit.getOnlinePlayers())) {
    2. }
    inside the code (for loop) I gave you, also change ("@" + Bukkit.getOnlinePlayers()) to ("@" + player.getName())
     
  10. Offline

    TheLexoPlexx

    Okay thanks. Hell, I was so confused. Thanks.
     
    MrSparkzz likes this.
Thread Status:
Not open for further replies.

Share This Page