Checking a players IP on login.

Discussion in 'Plugin Development' started by BR3TON, Mar 11, 2013.

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

    BR3TON

    I have Bungee network setup and I'm trying to add a plugin to only allow people to connect through the Bungee Proxy (I know you can block the port with firewall but its no currently an option for myself)

    I have tried this code but I am getting a null pointer exception:

    Code:
        @EventHandler
        public void  onPlayerLoginEvent(PlayerLoginEvent e){
            Player p = e.getPlayer();
            if(p.getAddress().getHostName().equalsIgnoreCase("127.0.0.1")){
                e.disallow(Result.KICK_OTHER, "You must connect via the portal hub.");
            }
     
    }
    Here is the error:

    [​IMG]
     
  2. Offline

    joehot2000

    NullPointerException.

    Something is null, either it is the address, or the player.
     
  3. Offline

    BR3TON

    Thanks for your reply but I theres no indication as to the root of the problem.
     
  4. Offline

    Tirelessly

  5. Offline

    joehot2000

    **shrugs** neither to i, and yet my console is spammed by errors from my ElementalSwords plugin :p.

    Debuging is hard.

    So, stop going "OH MY GOSH OH MY GOSH ITS AN ERROR!", and work through the problem ;)

    It is the check IP thing.

    Something to do with their IP is null

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

    obsessivecoder

    Here is the method i use:
    @EventHandler
    public void onplayerjoin(PlayerJoinEvent event)
    {
    String pn = event.getPlayer().getName();
    String pi = event.getPlayer().getAddress().toString().replaceAll("/", "").split(":")[0];
    }

    From there you can do whatever with the ip by using the string pi. The formating is needed otherwise you will get: /ip : port
    i made it so you just get the ip.

    So you can do:
    public void onplayerjoin(PlayerJoinEvent event)
    {
    Player p = event.getPlayer();
    String pi = event.getPlayer().getAddress().toString().replaceAll("/", "").split(":")[0];

    if(pi.equals("127.0.0.1"))
    {
    event.disallow(Result.KICK_OTHER, "You must connect via the portal hub.");
    }
    }


    gl with what your doing :)
     
Thread Status:
Not open for further replies.

Share This Page