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 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() + ".");
    }
  }
  @EventHandler(priority = EventPriority.MONITOR)
  public void onPlayerKick(PlayerKickEvent event) {
    Player player = event.getPlayer();
    if (TotalFreedomMod.fuckoffEnabledFor.containsKey(player)) {
      TotalFreedomMod.fuckoffEnabledFor.remove(player);
    }
    TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
    playerdata.disarmMP44();
    if (playerdata.isCaged()) {
      playerdata.regenerateHistory();
      playerdata.clearHistory();
    }

    TFM_Log.info("[EXIT] " + player.getName() + " left the game.", true);
  }
  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();
    }
  }
  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 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);
      }
    }
  }
  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);
      }
    }
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    String command = event.getMessage();
    Player p = event.getPlayer();

    TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);
    playerdata.incrementMsgCount();
    playerdata.setLastCommand(command);

    if (playerdata.getMsgCount() > 10) {
      TFM_Util.bcastMsg(
          p.getName() + " was automatically kicked for spamming commands.", ChatColor.RED);
      TFM_Util.autoEject(p, "Kicked for spamming commands.");

      playerdata.resetMsgCount();

      TFM_Util.TFM_EntityWiper.wipeEntities(true, true);

      event.setCancelled(true);
      return;
    }

    if (playerdata.allCommandsBlocked()) {
      TFM_Util.playerMsg(p, "Your commands have been blocked by an admin.", ChatColor.RED);
      event.setCancelled(true);
      return;
    }

    // Block commands if player is muted
    if (playerdata.isMuted()) {
      if (!TFM_SuperadminList.isUserSuperadmin(p)) {
        for (String test_command : BLOCKED_MUTED_CMDS) {
          if (Pattern.compile("^/" + test_command.toLowerCase() + " ").matcher(command).find()) {
            p.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
            event.setCancelled(true);
            return;
          }
        }
      } else {
        playerdata.setMuted(false);
      }
    }

    if (TotalFreedomMod.preprocessLogEnabled) {
      TFM_Log.info(
          String.format(
              "[PREPROCESS_COMMAND] %s(%s): %s",
              p.getName(), ChatColor.stripColor(p.getDisplayName()), command),
          true);
    }

    command = command.toLowerCase().trim();

    // Blocked commands
    if (TFM_CommandBlockerNew.getInstance().isCommandBlocked(command, event.getPlayer())) {
      // CommandBlocker handles messages and broadcasts
      event.setCancelled(true);
    }

    if (!TFM_SuperadminList.isUserSuperadmin(p)) {
      for (Player pl : Bukkit.getOnlinePlayers()) {
        if (TFM_SuperadminList.isUserSuperadmin(pl)
            && TFM_PlayerData.getPlayerData(pl).cmdspyEnabled()) {
          TFM_Util.playerMsg(pl, p.getName() + ": " + command);
        }
      }
    }
  }
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;
        }
    }
  }
  @EventHandler(priority = EventPriority.MONITOR)
  public void onPlayerJoin(PlayerJoinEvent event) {
    final Player player = event.getPlayer();
    final String ip = TFM_Util.getIp(player);
    TFM_Log.info(
        "[JOIN] " + TFM_Util.formatPlayer(player) + " joined the game with IP address: " + ip,
        true);

    if (TFM_PlayerList.getInstance().existsEntry(player)) {
      final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player);
      entry.setLastJoinUnix(TFM_Util.getUnixTime());
      entry.setLastJoinName(player.getName());
      entry.save();
    } else {
      TFM_PlayerList.getInstance().getEntry(player);
      TFM_Log.info("Added new player: " + TFM_Util.formatPlayer(player));
    }

    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
    playerdata.setSuperadminIdVerified(false);

    // Verify strict IP match
    if (TFM_AdminList.isSuperAdmin(player)) {
      TFM_BanManager.getInstance().unbanIp(ip);
      TFM_BanManager.getInstance().unbanIp(TFM_Util.getFuzzyIp(ip));
      TFM_BanManager.getInstance().unbanUuid(player.getUniqueId());

      player.setOp(true);

      if (!TFM_AdminList.isIdentityMatched(player)) {
        playerdata.setSuperadminIdVerified(false);

        TFM_Util.bcastMsg(
            "Warning: "
                + player.getName()
                + " is an admin, but is using an account not registered to one of their ip-list.",
            ChatColor.RED);
      } else {
        playerdata.setSuperadminIdVerified(true);
        TFM_AdminList.updateLastLogin(player);
      }
    }

    // Handle admin impostors
    if (TFM_AdminList.isAdminImpostor(player)) {
      TFM_Util.bcastMsg(
          "Warning: " + player.getName() + " has been flagged as an impostor!", ChatColor.RED);
      TFM_Util.bcastMsg(
          ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
      player.getInventory().clear();
      player.setOp(false);
      player.setGameMode(GameMode.SURVIVAL);
    } else if (TFM_AdminList.isSuperAdmin(player)
        || TFM_Util.DEVELOPERS.contains(player.getName())) {
      TFM_Util.bcastMsg(
          ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
    }

    new BukkitRunnable() {
      @Override
      public void run() {
        if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean()) {
          player.sendMessage(ChatColor.RED + "Server is currently closed to non-superadmins.");
        }

        if (TotalFreedomMod.lockdownEnabled) {
          TFM_Util.playerMsg(
              player,
              "Warning: Server is currenty in lockdown-mode, new players will not be able to join!",
              ChatColor.RED);
        }
      }
    }.runTaskLater(TotalFreedomMod.plugin, 20L * 3L);
  }
  public final void load() {
    blockedCommands.clear();

    final CommandMap commandMap = TFM_CommandLoader.getInstance().getCommandMap();
    if (commandMap == null) {
      TFM_Log.severe("Error loading commandMap.");
      return;
    }

    List<String> _blockedCommands = (List<String>) TFM_ConfigEntry.BLOCKED_COMMANDS.getList();
    for (String rawEntry : _blockedCommands) {
      final String[] parts = rawEntry.split(":");
      if (parts.length < 3 || parts.length > 4) {
        continue;
      }

      final CommandBlockerRank rank = CommandBlockerRank.fromToken(parts[0]);
      if (rank == null) {
        continue;
      }

      final CommandBlockerAction action = CommandBlockerAction.fromToken(parts[1]);
      if (action == null) {
        continue;
      }

      String command = parts[2];
      if (command == null || command.isEmpty()) {
        continue;
      }
      final Matcher matcher = COMMAND_PATTERN.matcher(command);
      if (matcher.find()) {
        command = matcher.group(1);
        if (command == null) {
          continue;
        } else {
          command = command.toLowerCase().trim();
        }
      } else {
        continue;
      }

      String message = null;
      if (parts.length == 4) {
        message = parts[3];
      }

      final CommandBlockerEntry blockedCommandEntry =
          new CommandBlockerEntry(rank, action, command, message);

      final Command bukkitCommand = commandMap.getCommand(command);
      if (bukkitCommand == null) {
        // TFM_Log.info("Blocking unknown command: " + blockedCommandEntry.getCommand());
        blockedCommands.put(blockedCommandEntry.getCommand(), blockedCommandEntry);
      } else {
        blockedCommandEntry.setCommand(bukkitCommand.getName().toLowerCase());

        // TFM_Log.info("Blocking command: " + blockedCommandEntry.getCommand());
        blockedCommands.put(blockedCommandEntry.getCommand(), blockedCommandEntry);

        for (String alias : bukkitCommand.getAliases()) {
          // TFM_Log.info("Blocking alias: " + alias.toLowerCase() + " of " +
          // blockedCommandEntry.getCommand());
          blockedCommands.put(alias.toLowerCase(), blockedCommandEntry);
        }
      }
    }

    TFM_Log.info("Loaded " + blockedCommands.size() + " blocked commands.");
  }
 public void printTotalToLog(String timerName) {
   TFM_Log.info("DEBUG: " + timerName + " used " + this.getTotal() + " ms.");
 }