Exemplo n.º 1
1
  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();
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerChat(AsyncPlayerChatEvent event) {
    try {
      final Player p = event.getPlayer();
      String message = event.getMessage().trim();

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

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

        playerdata.resetMsgCount();

        event.setCancelled(true);
        return;
      }

      // Check for message repeat
      if (playerdata.getLastMessage().equalsIgnoreCase(message)) {
        TFM_Util.playerMsg(p, "Please do not repeat messages.");
        event.setCancelled(true);
        return;
      }
      playerdata.setLastMessage(message);

      // Check for muted
      if (playerdata.isMuted()) {
        if (!TFM_SuperadminList.isUserSuperadmin(p)) {
          p.sendMessage(ChatColor.RED + "You are muted, STFU!");
          event.setCancelled(true);
          return;
        } else {
          playerdata.setMuted(false);
        }
      }

      // Strip color from messages
      message = ChatColor.stripColor(message);

      // Truncate messages that are too long - 100 characters is vanilla client max
      if (message.length() > 100) {
        message = message.substring(0, 100);
        TFM_Util.playerMsg(p, "Message was shortened because it was too long to send.");
      }

      // Check for caps
      if (message.length() >= 6) {
        int caps = 0;
        for (char c : message.toCharArray()) {
          if (Character.isUpperCase(c)) {
            caps++;
          }
        }
        if (((float) caps / (float) message.length())
            > 0.65) // Compute a ratio so that longer sentences can have more caps.
        {
          message = message.toLowerCase();
        }
      }

      // Check for adminchat
      if (playerdata.inAdminChat()) {
        TFM_Util.adminChatMessage(p, message, false);
        event.setCancelled(true);
        return;
      }

      // Finally, set message
      event.setMessage(message);

      // Set the tag
      if (playerdata.getTag() != null) {
        p.setDisplayName((playerdata.getTag() + " " + p.getDisplayName().replaceAll(" ", "")));
      }

    } catch (Exception ex) {
      TFM_Log.severe(ex);
    }
  }
Exemplo n.º 3
0
  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);
    }
  }
Exemplo n.º 4
0
  @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;
  }
Exemplo n.º 5
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);
    }
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerChat(AsyncPlayerChatEvent event) {
    try {
      final Player player = event.getPlayer();
      String message = event.getMessage().trim();

      final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

      // Check for spam
      final Long lastRan = TFM_Heartbeat.getLastRan();
      if (lastRan == null
          || lastRan + TotalFreedomMod.HEARTBEAT_RATE * 1000L < System.currentTimeMillis()) {
        // TFM_Log.warning("Heartbeat service timeout - can't check block place/break rates.");
      } else {
        if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT) {
          TFM_Util.bcastMsg(
              player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
          TFM_Util.autoEject(player, "Kicked for spamming chat.");

          playerdata.resetMsgCount();

          event.setCancelled(true);
          return;
        }
      }

      // Check for message repeat
      if (playerdata.getLastMessage().equalsIgnoreCase(message)) {
        TFM_Util.playerMsg(player, "Please do not repeat messages.");
        event.setCancelled(true);
        return;
      }

      playerdata.setLastMessage(message);

      // Check for muted
      if (playerdata.isMuted()) {
        if (!TFM_AdminList.isSuperAdmin(player)) {
          player.sendMessage(ChatColor.RED + "You are muted, STFU!");
          event.setCancelled(true);
          return;
        }

        playerdata.setMuted(false);
      }

      // Strip color from messages
      message = ChatColor.stripColor(message);

      // Truncate messages that are too long - 100 characters is vanilla client max
      if (message.length() > 100) {
        message = message.substring(0, 100);
        TFM_Util.playerMsg(player, "Message was shortened because it was too long to send.");
      }

      // Check for caps
      if (message.length() >= 6) {
        int caps = 0;
        for (char c : message.toCharArray()) {
          if (Character.isUpperCase(c)) {
            caps++;
          }
        }
        if (((float) caps / (float) message.length())
            > 0.65) // Compute a ratio so that longer sentences can have more caps.
        {
          message = message.toLowerCase();
        }
      }

      // Check for adminchat
      if (playerdata.inAdminChat()) {
        TFM_Util.adminChatMessage(player, message, false);
        event.setCancelled(true);
        return;
      }

      // Finally, set message
      event.setMessage(message);

      // Set the tag
      if (playerdata.getTag() != null) {
        player.setDisplayName(
            (playerdata.getTag() + " " + player.getDisplayName().replaceAll(" ", "")));
      }

    } catch (Exception ex) {
      TFM_Log.severe(ex);
    }
  }
  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.");
  }