Solved Player's locale always "en_US"

Discussion in 'Plugin Development' started by Desle, Jul 23, 2014.

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

    Desle

    Heya. I'm trying to retrieve the language of a player on the PlayerLoginEvent, although for some reason it always returns "en_US", even though I have tried german, dutch and pirate speak.

    Here's the code I'm using that I got from here;
    Code:java
    1. private static String getLanguage(Player p){
    2. try {
    3. Object obj = getMethod("getHandle", p.getClass()).invoke(p, (Object[]) null);
    4. Field f = obj.getClass().getDeclaredField("locale");
    5. f.setAccessible(true);
    6. String language = (String) f.get(obj);
    7.  
    8. return language;
    9.  
    10. } catch (Exception e) {
    11. return "en";
    12. }
    13. }
    14.  
    15. private static Method getMethod(String n, Class<?> c) {
    16. for (Method m : c.getDeclaredMethods()) {
    17. if (m.getName().equals(n))
    18. return m;
    19. }
    20. return null;
    21. }



    Any help much appreciated. =)
     
  2. Offline

    SpaceManiac

    PlayerLoginEvent is too soon to know what locale the player has selected. Wait a little while before trying to check it.
     
  3. Desle As per the above advice by SpaceManiac I would try out PlayerJoinEvent - it's the one that's called when the player actually joins the server as opposed to when they login - login is often too early for most uses, it's good for things like ban management.
     
  4. Offline

    RainoBoy97

    The locale field is always en_US, and does not change. You have to intercept the client settings packet (id 0x15) to get their locale, this packet is sent when a player logs in or changes their settings while on the server.
     
  5. Offline

    Desle

Thread Status:
Not open for further replies.

Share This Page