PlayerLoginEvent

事件存储尝试登录的玩家的详细信息

@EventHandler
public void onPlayerLogin(PlayerLoginEvent e) {
    Player tryingToLogin = e.getPlayer();

    //Disallowing a player login
    e.disallow(PlayerLoginEvent.Result.KICK_FULL , "The server is reserved and is full for you!");

    //Allowing a player login
    if (e.getResult() != PlayerLoginEvent.Result.ALLOW) {
        if (isVip(tryingToLogin) ){
            e.allow();
        }
    }

    //Getting player IP
    String ip = e.getAddress();

    //Get the hostname player used to login to the server
    String ipJoined = e.getHostname();

    //Get current result from the login attempt
    PlayerLoginEvent.Result result = e.getResult();

    //Set kick message if Result wasn't ALLOW
    e.setKickMessage("You were kicked!");

    //Retrieve the kick message
    String s = e.getKickMessage();

}

PlayerLoginEvent.Result ENUM:

  • 允许 - 允许玩家登录
  • KICK_BANNED - 由于被禁止,玩家不允许登录
  • KICK_FULL - 由于服务器已满,播放器不允许登录
  • KICK_OTHER - 由于未定义的原因,不允许玩家登录
  • KICK_WHITELIST - 由于玩家不在白名单上,因此不允许玩家登录