@Override
  public boolean execute() {
    Util.sendMessage(sender, "&c-----------&8[ &7Reload Process Started &8]&c-----------");

    HawkEye hawk = HawkEye.instance;

    hawk.reloadConfig();
    hawk.config = new Config(hawk);

    for (DataType dt : DataType.values()) {
      dt.reload();
    }

    Util.sendMessage(sender, "&8|  &7- &cConfig has been reloaded..");

    HandlerList.unregisterAll(hawk); // Unregisters all listeners registered to hawkeye

    hawk.registerListeners(Bukkit.getPluginManager());

    Util.sendMessage(sender, "&8|  &7- &cListeners have been reloaded..");

    Util.sendMessage(sender, "&c-----------&8[ &7Reload Process Finished &8]&c-----------");
    return true;
  }
Exemple #2
0
  @Override
  public boolean execute() {

    // Check if player already has a rollback processing
    if (session.doingRollback()) {
      Util.sendMessage(sender, "&cYou already have a rollback command processing!");
      return true;
    }

    // Parse arguments
    SearchParser parser = null;
    try {

      parser = new SearchParser(player, args);
      parser.loc = null;

      // Check that supplied actions can rollback
      if (parser.actions.size() > 0) {
        for (DataType type : parser.actions)
          if (!type.canRollback())
            throw new IllegalArgumentException(
                "You cannot rollback that action type: &7" + type.getConfigName());
      }
      // If none supplied, add in all rollback types
      else {
        for (DataType type : DataType.values()) if (type.canRollback()) parser.actions.add(type);
      }

    } catch (IllegalArgumentException e) {
      Util.sendMessage(sender, "&c" + e.getMessage());
      return true;
    }

    // Create new SearchQuery with data
    new SearchQuery(new RollbackCallback(session, RollbackType.LOCAL), parser, SearchDir.DESC);
    session.setInPreview(true);
    return true;
  }
  /** Run the search query */
  @Override
  public void run() {

    Util.debug("Beginning search query");
    String sql;

    if (delete) sql = "DELETE FROM ";
    else sql = "SELECT * FROM ";

    sql += "`" + Config.DbHawkEyeTable + "` WHERE ";
    List<String> args = new LinkedList<String>();
    List<Object> binds = new LinkedList<Object>();

    // Match players from database list
    Util.debug("Building players");
    if (parser.players.size() >= 1) {
      List<Integer> pids = new ArrayList<Integer>();
      List<Integer> npids = new ArrayList<Integer>();
      for (String player : parser.players) {
        for (Map.Entry<String, Integer> entry : DataManager.dbPlayers.entrySet()) {
          String name = entry.getKey().toLowerCase();

          if (name.equals(player.replace("*", ""))) pids.add(entry.getValue());
          else if (name.contains(player)) pids.add(entry.getValue());
          else if (name.contains(player.replace("!", ""))) npids.add(entry.getValue());
        }
      }
      // Include players
      if (pids.size() > 0) args.add("player_id IN (" + Util.join(pids, ",") + ")");
      // Exclude players
      if (npids.size() > 0) args.add("player_id NOT IN (" + Util.join(npids, ",") + ")");
      if (npids.size() + pids.size() < 1) {
        callBack.error(SearchError.NO_PLAYERS, "No players found matching your specifications");
        return;
      }
    }

    // Match worlds from database list
    Util.debug("Building worlds");
    if (parser.worlds != null) {
      List<Integer> wids = new ArrayList<Integer>();
      List<Integer> nwids = new ArrayList<Integer>();
      for (String world : parser.worlds) {
        for (Map.Entry<String, Integer> entry : DataManager.dbWorlds.entrySet()) {
          if (entry.getKey().toLowerCase().contains(world.toLowerCase()))
            wids.add(entry.getValue());
          else if (entry.getKey().toLowerCase().contains(world.replace("!", "").toLowerCase()))
            nwids.add(entry.getValue());
        }
      }
      // Include worlds
      if (wids.size() > 0) args.add("world_id IN (" + Util.join(wids, ",") + ")");
      // Exclude worlds
      if (nwids.size() > 0) args.add("world_id NOT IN (" + Util.join(nwids, ",") + ")");
      if (nwids.size() + wids.size() < 1) {
        callBack.error(SearchError.NO_WORLDS, "No worlds found matching your specifications");
        return;
      }
    }

    // Compile actions into SQL form
    Util.debug("Building actions");
    if (parser.actions != null && parser.actions.size() > 0) {
      List<Integer> acs = new ArrayList<Integer>();
      for (DataType act : parser.actions) acs.add(act.getId());
      args.add("action IN (" + Util.join(acs, ",") + ")");
    }

    // Add dates
    Util.debug("Building dates");
    if (parser.dateFrom != null) {
      args.add("timestamp >= ?");
      binds.add(parser.dateFrom);
    }
    if (parser.dateTo != null) {
      args.add("timestamp <= ?");
      binds.add(parser.dateTo);
    }

    // Check if location is exact or a range
    Util.debug("Building location");
    if (parser.minLoc != null) {
      args.add(
          "(x BETWEEN " + parser.minLoc.getBlockX() + " AND " + parser.maxLoc.getBlockX() + ")");
      args.add(
          "(y BETWEEN " + parser.minLoc.getBlockY() + " AND " + parser.maxLoc.getBlockY() + ")");
      args.add(
          "(z BETWEEN " + parser.minLoc.getBlockZ() + " AND " + parser.maxLoc.getBlockZ() + ")");
    } else if (parser.loc != null) {
      args.add("x = " + parser.loc.getX());
      args.add("y = " + parser.loc.getY());
      args.add("z = " + parser.loc.getZ());
    }

    // Build the filters into SQL form
    Util.debug("Building filters");
    if (parser.filters != null) {
      for (String filter : parser.filters) {
        args.add("data LIKE ?");
        binds.add("%" + filter + "%");
      }
    }

    // Build WHERE clause
    sql += Util.join(args, " AND ");

    // Add order by
    Util.debug("Ordering by data_id");
    sql += " ORDER BY `data_id` " + (dir == SearchDir.DESC ? "DESC" : "ASC");

    // Check the limits
    Util.debug("Building limits");
    if (Config.MaxLines > 0) sql += " LIMIT " + Config.MaxLines;

    // Util.debug("Searching: " + sql);

    // Set up some stuff for the search
    ResultSet res = null;
    List<DataEntry> results = new ArrayList<DataEntry>();
    JDCConnection conn = DataManager.getConnection();
    PreparedStatement stmnt = null;
    int deleted = 0;

    try {
      conn.setAutoCommit(false);
      // Execute query
      stmnt = conn.prepareStatement(sql);

      Util.debug("Preparing statement");
      for (int i = 0; i < binds.size(); i++) stmnt.setObject(i + 1, binds.get(i));

      Util.debug("Searching: " + stmnt.toString());

      if (delete) {
        Util.debug("Deleting entries");
        deleted = stmnt.executeUpdate();
      } else {
        res = stmnt.executeQuery();

        Util.debug("Getting results");

        DataType type = null;
        DataEntry entry = null;

        // Retrieve results
        while (res.next()) {
          type = DataType.fromId(res.getInt(4));
          entry =
              (DataEntry)
                  type.getEntryConstructor()
                      .newInstance(
                          res.getInt(3),
                          res.getTimestamp(2),
                          res.getInt(1),
                          res.getInt(4),
                          res.getString(9),
                          res.getString(10),
                          res.getInt(5),
                          res.getInt(6),
                          res.getInt(7),
                          res.getInt(8));
          results.add(entry);
        }
      }
      conn.commit();
      conn.setAutoCommit(true);
    } catch (Exception ex) {
      Util.severe("Error executing MySQL query: " + ex);
      ex.printStackTrace();
      callBack.error(SearchError.MYSQL_ERROR, "Error executing MySQL query: " + ex);
      return;
    } finally {
      try {
        if (res != null) res.close();
        if (stmnt != null) stmnt.close();
        conn.close();
      } catch (SQLException ex) {
        Util.severe("Unable to close SQL connection: " + ex);
        callBack.error(SearchError.MYSQL_ERROR, "Unable to close SQL connection: " + ex);
      }
    }

    Util.debug(results.size() + " results found");

    // Run callback
    if (delete) ((DeleteCallback) callBack).deleted = deleted;
    else callBack.results = results;

    callBack.execute();

    Util.debug("Search complete");
  }
Exemple #4
0
 /**
  * Check if a {@link DataType} is logged or not
  *
  * @param dataType
  * @return true or false
  */
 public static boolean isLogged(DataType dataType) {
   if (config.getBoolean("log." + dataType.getConfigName(), false) == true) return true;
   return false;
 }