Esempio n. 1
0
  public static void createBackups(String file) {
    final String save = file.split("\\.")[0];
    final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, "backup.yml", false);
    config.load();

    // Daily
    if (!config.isInt(save + ".daily")) {
      performBackup(file, "daily");
      config.set(save + ".daily", TFM_Util.getUnixTime());
    } else {
      int lastBackupDaily = config.getInt(save + ".daily");

      if (lastBackupDaily + 3600 * 24 < TFM_Util.getUnixTime()) {
        performBackup(file, "daily");
        config.set(save + ".daily", TFM_Util.getUnixTime());
      }
    }

    // Weekly
    if (!config.isInt(save + ".weekly")) {
      performBackup(file, "weekly");
      config.set(save + ".weekly", TFM_Util.getUnixTime());
    } else {
      int lastBackupWeekly = config.getInt(save + ".weekly");

      if (lastBackupWeekly + 3600 * 24 * 7 < TFM_Util.getUnixTime()) {
        performBackup(file, "weekly");
        config.set(save + ".weekly", TFM_Util.getUnixTime());
      }
    }

    config.save();
  }
Esempio n. 2
0
  public static String getIp(OfflinePlayer player) {
    if (player instanceof Player) {
      return ((Player) player).getAddress().getAddress().getHostAddress().trim();
    }

    final TFM_Player entry = TFM_PlayerList.getEntry(TFM_Util.getUuid(player));

    if (entry == null) {
      return null;
    }

    return entry.getIps().get(0);
  }
Esempio n. 3
0
  public static boolean getSavedFlag(String flag) throws Exception {
    Boolean flagValue = null;

    Map<String, Boolean> flags = TFM_Util.getSavedFlags();

    if (flags != null) {
      if (flags.containsKey(flag)) {
        flagValue = flags.get(flag);
      }
    }

    if (flagValue != null) {
      return flagValue.booleanValue();
    } else {
      throw new Exception();
    }
  }
Esempio n. 4
0
  public static void setSavedFlag(String flag, boolean value) {
    Map<String, Boolean> flags = TFM_Util.getSavedFlags();

    if (flags == null) {
      flags = new HashMap<String, Boolean>();
    }

    flags.put(flag, value);

    try {
      final FileOutputStream fos =
          new FileOutputStream(
              new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE));
      final ObjectOutputStream oos = new ObjectOutputStream(fos);
      oos.writeObject(flags);
      oos.close();
      fos.close();
    } catch (Exception ex) {
      TFM_Log.severe(ex);
    }
  }
Esempio n. 5
0
  public static void autoEject(Player player, String kickMessage) {
    EjectMethod method = EjectMethod.STRIKE_ONE;
    final String ip = TFM_Util.getIp(player);

    if (!TFM_Util.ejectTracker.containsKey(ip)) {
      TFM_Util.ejectTracker.put(ip, 0);
    }

    int kicks = TFM_Util.ejectTracker.get(ip);
    kicks += 1;

    TFM_Util.ejectTracker.put(ip, kicks);

    if (kicks <= 1) {
      method = EjectMethod.STRIKE_ONE;
    } else if (kicks == 2) {
      method = EjectMethod.STRIKE_TWO;
    } else if (kicks >= 3) {
      method = EjectMethod.STRIKE_THREE;
    }

    TFM_Log.info(
        "AutoEject -> name: "
            + player.getName()
            + " - player ip: "
            + ip
            + " - method: "
            + method.toString());

    player.setOp(false);
    player.setGameMode(GameMode.SURVIVAL);
    player.getInventory().clear();

    switch (method) {
      case STRIKE_ONE:
        {
          final Calendar cal = new GregorianCalendar();
          cal.add(Calendar.MINUTE, 1);
          final Date expires = cal.getTime();

          TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 1 minute.");

          TFM_BanManager.addIpBan(
              new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage));
          TFM_BanManager.addUuidBan(
              new TFM_Ban(
                  TFM_Util.getUuid(player), player.getName(), "AutoEject", expires, kickMessage));
          player.kickPlayer(kickMessage);

          break;
        }
      case STRIKE_TWO:
        {
          final Calendar c = new GregorianCalendar();
          c.add(Calendar.MINUTE, 3);
          final Date expires = c.getTime();

          TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 3 minutes.");

          TFM_BanManager.addIpBan(
              new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage));
          TFM_BanManager.addUuidBan(
              new TFM_Ban(
                  TFM_Util.getUuid(player), player.getName(), "AutoEject", expires, kickMessage));
          player.kickPlayer(kickMessage);
          break;
        }
      case STRIKE_THREE:
        {
          String[] ipAddressParts = ip.split("\\.");

          TFM_BanManager.addIpBan(
              new TFM_Ban(ip, player.getName(), "AutoEject", null, kickMessage));
          TFM_BanManager.addIpBan(
              new TFM_Ban(
                  ipAddressParts[0] + "." + ipAddressParts[1] + ".*.*",
                  player.getName(),
                  "AutoEject",
                  null,
                  kickMessage));
          TFM_BanManager.addUuidBan(
              new TFM_Ban(
                  TFM_Util.getUuid(player), player.getName(), "AutoEject", null, kickMessage));

          TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned.");

          player.kickPlayer(kickMessage);
          break;
        }
    }
  }
Esempio n. 6
0
 public static String formatPlayer(OfflinePlayer player) {
   return player.getName() + " (" + TFM_Util.getUuid(player) + ")";
 }
Esempio n. 7
0
 public static void adminAction(String adminName, String action, boolean isRed) {
   TFM_Util.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA));
 }
Esempio n. 8
0
 // Still in use by listeners
 public static void playerMsg(CommandSender sender, String message) {
   TFM_Util.playerMsg(sender, message, ChatColor.GRAY);
 }
Esempio n. 9
0
 public static void bcastMsg(String message) {
   TFM_Util.bcastMsg(message, null);
 }