[SOLVED]Another Bukkit NPE ! onPlayerLogin() Strings

Discussion in 'Plugin Development' started by Ribesg, Oct 28, 2011.

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

    Ribesg

    Hi !
    Trying to get the IP and playerName from a player like that (line 5) :
    Code:java
    1. public void onPlayerLogin(PlayerLoginEvent event) {
    2. if (event.getResult().equals(Result.ALLOWED)) {
    3. String playerIP = event.getKickMessage();
    4. String playerName = event.getPlayer().getName();
    5. plugin.getServer().broadcastMessage(plugin.HEADER + ChatColor.RED + "IP : " + playerIP); // NPE !
    6. plugin.getServer().broadcastMessage(plugin.HEADER + ChatColor.RED + "Pseudo : " + playerName);
    7. }
    8. }


    I've tried to do a something like
    if (playerIP==null) { System.out.println("NULLIP"); }
    But nothing is written in the console.

    It seems that I can't use String in onPlayerLogin() ? Oo

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  2. Offline

    coldandtired

    KickMessage only works if the result != Allowed.
     
  3. Offline

    Ribesg

    Here I'm getting the IP of the player, and getKickMessage() should work.
    And playerName raise a NPE too ! Oo
    Code:java
    1. @Override
    2. public void onPlayerLogin(PlayerLoginEvent event) {
    3. if (event.getResult() != Result.ALLOWED || event.getPlayer() == null) {
    4. return;
    5. } else {
    6. Player player = event.getPlayer();
    7. String playerIP = event.getKickMessage();
    8. String playerName = player.getName();
    9.  
    10. // Enregistrer le pseudo/IP dans la BD
    11. if (!plugin.players.isPlayerKnown(playerName) || !plugin.players.isIpKnown(playerIP)) {
    12. plugin.players.add(playerName, playerIP);
    13. }
    14.  
    15. // Check si banni ou non
    16. if (plugin.bans.isBan(playerName, playerIP)) {
    17. if (plugin.bans.isTempBan(playerName, playerIP)) {
    18. Calendar c1 = plugin.bans.getTempIpBanTime(playerIP);
    19. Calendar c2 = plugin.bans.getTempPseudoBanTime(playerName);
    20. Calendar c = (c1.after(c2) ? c1 : c2);
    21. Calendar now = Calendar.getInstance();
    22. if (c.after(now)) {
    23. if (c.get(Calendar.DAY_OF_YEAR) != now.get(Calendar.DAY_OF_YEAR)) {
    24. event.disallow(Result.KICK_BANNED, plugin.HEADER + ChatColor.RED + "Vous êtes banni jusqu'au : " + plugin.calendarToString(c));
    25. event.setResult(Result.KICK_BANNED);
    26. } else {
    27. event.disallow(Result.KICK_BANNED, plugin.HEADER + ChatColor.RED + "Vous êtes banni jusqu'à : " + plugin.calendarToString(c).substring(11, 18));
    28. event.setResult(Result.KICK_BANNED);
    29. }
    30. } else {
    31. plugin.bans.unBan(playerName, playerIP);
    32. }
    33. } else {
    34. event.disallow(Result.KICK_BANNED, plugin.HEADER + ChatColor.RED + "Vous êtes banni de manière permanente");
    35. event.setResult(Result.KICK_BANNED);
    36. }
    37. }
    38. }
    39. }

    NPE at line 11.

    2 hours to find this.
    Code:java
    1. public Itsn3wBanPlayerListener(Itsn3wBan instance) {
    2. //plugin = instance;
    3. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
Thread Status:
Not open for further replies.

Share This Page