Exemplo n.º 1
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void onPlayerLogin(final PlayerLoginEvent event) {
    if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
      return;
    }

    if (plugin.getGeoIpConfig().isEnabled()
        && !event.getPlayer().hasPermission("bm.exempt.country")) {
      try {
        CountryResponse countryResponse =
            plugin.getGeoIpConfig().getCountryDatabase().country(event.getAddress());

        if (!plugin.getGeoIpConfig().isCountryAllowed(countryResponse)) {
          Message message =
              Message.get("deniedCountry")
                  .set("country", countryResponse.getCountry().getName())
                  .set("countryIso", countryResponse.getCountry().getIsoCode());
          event.disallow(PlayerLoginEvent.Result.KICK_BANNED, message.toString());
          return;
        }

      } catch (IOException | GeoIp2Exception e) {
      }
    }

    if (plugin.getConfiguration().getMaxOnlinePerIp() > 0) {
      long ip = IPUtils.toLong(event.getAddress());
      int count = 0;

      for (Player player : plugin.getServer().getOnlinePlayers()) {
        if (IPUtils.toLong(player.getAddress().getAddress()) == ip) {
          count++;
        }
      }

      if (count >= plugin.getConfiguration().getMaxOnlinePerIp()) {
        event.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.getString("deniedMaxIp"));
        return;
      }
    }

    if (!plugin.getConfiguration().isDuplicateIpCheckEnabled()) {
      return;
    }

    plugin
        .getServer()
        .getScheduler()
        .runTaskLaterAsynchronously(
            plugin,
            new Runnable() {

              @Override
              public void run() {
                final long ip = IPUtils.toLong(event.getAddress());
                final UUID uuid = event.getPlayer().getUniqueId();
                List<PlayerData> duplicates = plugin.getPlayerBanStorage().getDuplicates(ip);

                if (duplicates.isEmpty()) {
                  return;
                }

                if (plugin.getConfiguration().isDenyAlts()) {
                  try {
                    denyAlts(duplicates, uuid);
                  } catch (SQLException e) {
                    PluginLogger.warn(e);
                  }
                }

                if (plugin.getConfiguration().isPunishAlts()) {
                  try {
                    punishAlts(duplicates, uuid);
                  } catch (SQLException e) {
                    PluginLogger.warn(e);
                  }
                }

                StringBuilder sb = new StringBuilder();

                for (PlayerData player : duplicates) {
                  if (player.getUUID().equals(uuid)) {
                    continue;
                  }

                  sb.append(player.getName());
                  sb.append(", ");
                }

                if (sb.length() == 0) {
                  return;
                }
                if (sb.length() >= 2) {
                  sb.setLength(sb.length() - 2);
                }

                Message message = Message.get("duplicateIP");
                message.set("player", event.getPlayer().getName());
                message.set("players", sb.toString());

                CommandUtils.broadcast(message.toString(), "bm.notify.duplicateips");
              }
            },
            20L);
  }
Exemplo n.º 2
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void banCheck(final AsyncPlayerPreLoginEvent event) {
    if (plugin.getConfiguration().isCheckOnJoin()) {
      // Check for new bans/mutes
      if (!plugin.getIpBanStorage().isBanned(event.getAddress())) {
        try {
          IpBanData ban = plugin.getIpBanStorage().retrieveBan(IPUtils.toLong(event.getAddress()));

          if (ban != null) {
            plugin.getIpBanStorage().addBan(ban);
          }
        } catch (SQLException e) {
          PluginLogger.warn(e);
        }
      }

      if (!plugin.getPlayerBanStorage().isBanned(event.getUniqueId())) {
        try {
          PlayerBanData ban = plugin.getPlayerBanStorage().retrieveBan(event.getUniqueId());

          if (ban != null) {
            plugin.getPlayerBanStorage().addBan(ban);
          }
        } catch (SQLException e) {
          PluginLogger.warn(e);
        }
      }

      if (!plugin.getPlayerMuteStorage().isMuted(event.getUniqueId())) {
        try {
          PlayerMuteData mute = plugin.getPlayerMuteStorage().retrieveMute(event.getUniqueId());

          if (mute != null) {
            plugin.getPlayerMuteStorage().addMute(mute);
          }
        } catch (SQLException e) {
          PluginLogger.warn(e);
        }
      }
    }

    if (plugin.getIpRangeBanStorage().isBanned(event.getAddress())) {
      IpRangeBanData data = plugin.getIpRangeBanStorage().getBan(event.getAddress());

      if (data.hasExpired()) {
        try {
          plugin.getIpRangeBanStorage().unban(data, plugin.getPlayerStorage().getConsole());
        } catch (SQLException e) {
          PluginLogger.warn(e);
        }

        return;
      }

      Message message;

      if (data.getExpires() == 0) {
        message = Message.get("baniprange.ip.disallowed");
      } else {
        message = Message.get("tempbaniprange.ip.disallowed");
        message.set("expires", DateUtils.getDifferenceFormat(data.getExpires()));
      }

      message.set("ip", event.getAddress().toString());
      message.set("reason", data.getReason());
      message.set("actor", data.getActor().getName());

      event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_BANNED);
      event.setKickMessage(message.toString());
      return;
    }

    if (plugin.getIpBanStorage().isBanned(event.getAddress())) {
      IpBanData data = plugin.getIpBanStorage().getBan(event.getAddress());

      if (data.hasExpired()) {
        try {
          plugin.getIpBanStorage().unban(data, plugin.getPlayerStorage().getConsole());
        } catch (SQLException e) {
          PluginLogger.warn(e);
        }

        return;
      }

      Message message;

      if (data.getExpires() == 0) {
        message = Message.get("banip.ip.disallowed");
      } else {
        message = Message.get("tempbanip.ip.disallowed");
        message.set("expires", DateUtils.getDifferenceFormat(data.getExpires()));
      }

      message.set("ip", event.getAddress().toString());
      message.set("reason", data.getReason());
      message.set("actor", data.getActor().getName());

      event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_BANNED);
      event.setKickMessage(message.toString());
      handleJoinDeny(event.getAddress().toString(), data.getReason());
      return;
    }

    PlayerBanData data = plugin.getPlayerBanStorage().getBan(event.getUniqueId());

    if (data != null && data.hasExpired()) {
      try {
        plugin.getPlayerBanStorage().unban(data, plugin.getPlayerStorage().getConsole());
      } catch (SQLException e) {
        PluginLogger.warn(e);
      }

      return;
    }

    if (data == null) {
      return;
    }

    Message message;

    if (data.getExpires() == 0) {
      message = Message.get("ban.player.disallowed");
    } else {
      message = Message.get("tempban.player.disallowed");
      message.set("expires", DateUtils.getDifferenceFormat(data.getExpires()));
    }

    message.set("player", data.getPlayer().getName());
    message.set("reason", data.getReason());
    message.set("actor", data.getActor().getName());

    event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_BANNED);
    event.setKickMessage(message.toString());
    handleJoinDeny(data.getPlayer(), data.getReason());
  }