Esempio n. 1
0
  private void denyAlts(List<PlayerData> duplicates, final UUID uuid) throws SQLException {
    if (plugin.getPlayerBanStorage().isBanned(uuid)) {
      return;
    }

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

      final PlayerBanData ban = plugin.getPlayerBanStorage().getBan(player.getUUID());

      if (ban == null) {
        continue;
      }
      if (ban.hasExpired()) {
        continue;
      }

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

                @Override
                public void run() {
                  Player bukkitPlayer = plugin.getServer().getPlayer(uuid);

                  Message kickMessage =
                      Message.get("denyalts.player.disallowed")
                          .set("player", player.getName())
                          .set("reason", ban.getReason())
                          .set("actor", ban.getActor().getName());

                  bukkitPlayer.kickPlayer(kickMessage.toString());
                }
              });
    }
  }
Esempio n. 2
0
  private void punishAlts(List<PlayerData> duplicates, UUID uuid) throws SQLException {

    if (!plugin.getPlayerBanStorage().isBanned(uuid)) {
      // Auto ban
      for (PlayerData player : duplicates) {
        if (player.getUUID().equals(uuid)) {
          continue;
        }

        PlayerBanData ban = plugin.getPlayerBanStorage().getBan(player.getUUID());

        if (ban == null) {
          continue;
        }
        if (ban.hasExpired()) {
          continue;
        }

        final PlayerBanData newBan =
            new PlayerBanData(
                plugin.getPlayerStorage().queryForId(UUIDUtils.toBytes(uuid)),
                plugin.getPlayerStorage().getConsole(),
                ban.getReason(),
                ban.getExpires());

        plugin.getPlayerBanStorage().ban(newBan, false);

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

                  @Override
                  public void run() {
                    Player bukkitPlayer =
                        plugin.getServer().getPlayer(newBan.getPlayer().getUUID());

                    Message kickMessage =
                        Message.get("ban.player.kick")
                            .set("displayName", bukkitPlayer.getDisplayName())
                            .set("player", newBan.getPlayer().getName())
                            .set("reason", newBan.getReason())
                            .set("actor", newBan.getActor().getName());

                    bukkitPlayer.kickPlayer(kickMessage.toString());
                  }
                });
      }
    } else if (!plugin.getPlayerMuteStorage().isMuted(uuid)) {
      // Auto mute
      for (PlayerData player : duplicates) {
        if (player.getUUID().equals(uuid)) {
          continue;
        }

        PlayerMuteData mute = plugin.getPlayerMuteStorage().getMute(player.getUUID());

        if (mute == null) {
          continue;
        }
        if (mute.hasExpired()) {
          continue;
        }

        PlayerMuteData newMute =
            new PlayerMuteData(
                plugin.getPlayerStorage().queryForId(UUIDUtils.toBytes(uuid)),
                plugin.getPlayerStorage().getConsole(),
                mute.getReason(),
                mute.isSoft(),
                mute.getExpires());

        plugin.getPlayerMuteStorage().mute(newMute, false);
      }
    }
  }
Esempio n. 3
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());
  }