public static UUID generateUuidForName(String name) {
    TFM_Log.info("Generating spoof UUID for " + name);
    name = name.toLowerCase();
    try {
      final MessageDigest mDigest = MessageDigest.getInstance("SHA1");
      byte[] result = mDigest.digest(name.getBytes());
      final StringBuilder sb = new StringBuilder();
      for (int i = 0; i < result.length; i++) {
        sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
      }

      return UUID.fromString(
          sb.substring(0, 8)
              + "-"
              + sb.substring(8, 12)
              + "-"
              + sb.substring(12, 16)
              + "-"
              + sb.substring(16, 20)
              + "-"
              + sb.substring(20, 32));
    } catch (NoSuchAlgorithmException ex) {
      TFM_Log.severe(ex);
    }

    return UUID.randomUUID();
  }
 private static void performBackup(String file, String type) {
   TFM_Log.info("Backing up " + file + " to " + file + "." + type + ".bak");
   final File oldYaml = new File(TotalFreedomMod.plugin.getDataFolder(), file);
   final File newYaml =
       new File(TotalFreedomMod.plugin.getDataFolder(), file + "." + type + ".bak");
   FileUtil.copy(oldYaml, newYaml);
 }
  public static void bcastMsg(String message, ChatColor color) {
    TFM_Log.info(message, true);

    for (Player player : Bukkit.getOnlinePlayers()) {
      player.sendMessage((color == null ? "" : color) + message);
    }
  }
  public static void createDefaultConfiguration(final String configFileName) {
    final File targetFile = new File(TotalFreedomMod.plugin.getDataFolder(), configFileName);

    if (targetFile.exists()) {
      return;
    }

    TFM_Log.info("Installing default configuration file template: " + targetFile.getPath());

    try {
      final InputStream configFileStream = TotalFreedomMod.plugin.getResource(configFileName);
      FileUtils.copyInputStreamToFile(configFileStream, targetFile);
      configFileStream.close();
    } catch (IOException ex) {
      TFM_Log.severe(ex);
    }
  }
  public static void downloadFile(String url, File output, boolean verbose)
      throws java.lang.Exception {
    final URL website = new URL(url);
    ReadableByteChannel rbc = Channels.newChannel(website.openStream());
    FileOutputStream fos = new FileOutputStream(output);
    fos.getChannel().transferFrom(rbc, 0, 1 << 24);
    fos.close();

    if (verbose) {
      TFM_Log.info("Downloaded " + url + " to " + output.toString() + ".");
    }
  }
  public static void deleteCoreDumps() {
    final File[] coreDumps =
        new File(".")
            .listFiles(
                new FileFilter() {
                  @Override
                  public boolean accept(File file) {
                    return file.getName().startsWith("java.core");
                  }
                });

    for (File dump : coreDumps) {
      TFM_Log.info("Removing core dump file: " + dump.getName());
      dump.delete();
    }
  }
  @SuppressWarnings("unchecked")
  public static Map<String, Boolean> getSavedFlags() {
    Map<String, Boolean> flags = null;

    File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE);
    if (input.exists()) {
      try {
        FileInputStream fis = new FileInputStream(input);
        ObjectInputStream ois = new ObjectInputStream(fis);
        flags = (HashMap<String, Boolean>) ois.readObject();
        ois.close();
        fis.close();
      } catch (Exception ex) {
        TFM_Log.severe(ex);
      }
    }

    return flags;
  }
  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);
    }
  }
  public static void devadminChatMessage(
      CommandSender sender, String message, boolean senderIsConsole) {
    String name =
        sender.getName() + " " + TFM_PlayerRank.fromSender(sender).getPrefix() + ChatColor.WHITE;
    TFM_Log.info("[Dev-Chat] " + name + ": " + message);

    for (Player player : Bukkit.getOnlinePlayers()) {
      if (!TFM_Util.DEVELOPERS.contains(sender.getName())) {
        player.sendMessage(
            "["
                + ChatColor.DARK_GREEN
                + "Dev-Chat"
                + ChatColor.WHITE
                + "] "
                + ChatColor.DARK_RED
                + name
                + ": "
                + ChatColor.GOLD
                + message);
      }
    }
  }
Beispiel #10
0
  public static void adminChatMessage(
      CommandSender sender, String message, boolean senderIsConsole) {
    String name =
        sender.getName() + " " + TFM_PlayerRank.fromSender(sender).getPrefix() + ChatColor.WHITE;
    TFM_Log.info("[ADMIN] " + name + ": " + message);

    for (Player player : Bukkit.getOnlinePlayers()) {
      if (TFM_AdminList.isSuperAdmin(player)) {
        player.sendMessage(
            "["
                + ChatColor.AQUA
                + "ADMIN"
                + ChatColor.WHITE
                + "] "
                + ChatColor.DARK_RED
                + name
                + ": "
                + ChatColor.AQUA
                + message);
      }
    }
  }
Beispiel #11
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;
        }
    }
  }