use of uk.co.oliwali.HawkEye.entry.DataEntry in project HawkEye by oliverwoodings.
the class SearchQuery method run.
/**
* 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()) {
if (entry.getKey().toLowerCase().contains(player.toLowerCase()))
pids.add(entry.getValue());
else if (entry.getKey().toLowerCase().contains(player.replace("!", "").toLowerCase()))
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("date >= ?");
binds.add(parser.dateFrom);
}
if (parser.dateTo != null) {
args.add("date <= ?");
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.getX() + " AND " + parser.maxLoc.getX() + ")");
args.add("(y BETWEEN " + parser.minLoc.getY() + " AND " + parser.maxLoc.getY() + ")");
args.add("(z BETWEEN " + parser.minLoc.getZ() + " AND " + parser.maxLoc.getZ() + ")");
} 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` DESC";
// 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;
List<DataEntry> results = new ArrayList<DataEntry>();
JDCConnection conn = DataManager.getConnection();
PreparedStatement stmnt = null;
int deleted = 0;
try {
// 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");
// Retrieve results
while (res.next()) results.add(DataManager.createEntryFromRes(res));
// If ascending, reverse results
if (dir == SearchDir.ASC)
Collections.reverse(results);
}
} 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 (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");
}
use of uk.co.oliwali.HawkEye.entry.DataEntry in project HawkEye by oliverwoodings.
the class MonitorPlayerListener method onPlayerQuit.
@HawkEvent(dataType = DataType.QUIT)
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
Location loc = player.getLocation();
// Check for inventory close
HawkEye.containerManager.checkInventoryClose(player);
// Hackish workaround for random NPE given off by the address system
String ip = "";
try {
ip = player.getAddress().getAddress().getHostAddress().toString();
} catch (Exception e) {
}
DataManager.addEntry(new DataEntry(player, DataType.QUIT, loc, Config.LogIpAddresses ? ip : ""));
}
use of uk.co.oliwali.HawkEye.entry.DataEntry in project HawkEye by oliverwoodings.
the class MonitorPlayerListener method onPlayerTeleport.
@HawkEvent(dataType = DataType.TELEPORT)
public void onPlayerTeleport(PlayerTeleportEvent event) {
// Check for inventory close
HawkEye.containerManager.checkInventoryClose(event.getPlayer());
Location from = event.getFrom();
Location to = event.getTo();
if (Util.distance(from, to) > 5)
DataManager.addEntry(new DataEntry(event.getPlayer(), DataType.TELEPORT, from, to.getWorld().getName() + ": " + to.getX() + ", " + to.getY() + ", " + to.getZ()));
}
use of uk.co.oliwali.HawkEye.entry.DataEntry in project HawkEye by oliverwoodings.
the class MonitorPlayerListener method onPlayerCommandPreprocess.
@HawkEvent(dataType = DataType.COMMAND)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
// Check for inventory close
HawkEye.containerManager.checkInventoryClose(player);
// Check command filter
if (Config.CommandFilter.contains(event.getMessage().split(" ")[0]))
return;
DataManager.addEntry(new DataEntry(player, DataType.COMMAND, player.getLocation(), event.getMessage()));
}
use of uk.co.oliwali.HawkEye.entry.DataEntry in project HawkEye by oliverwoodings.
the class TptoCommand method execute.
@Override
public boolean execute() {
if (!Util.isInteger(args.get(0))) {
Util.sendMessage(sender, "&cPlease supply a entry id!");
return true;
}
DataEntry entry = DataManager.getEntry(Integer.parseInt(args.get(0)));
if (entry == null) {
Util.sendMessage(sender, "&cEntry not found");
return true;
}
World world = HawkEye.server.getWorld(entry.getWorld());
if (world == null) {
Util.sendMessage(sender, "&cWorld &7" + entry.getWorld() + "&c does not exist!");
return true;
}
Location loc = new Location(world, entry.getX(), entry.getY(), entry.getZ());
player.teleport(loc);
Util.sendMessage(sender, "&7Teleported to location of data entry &c" + args.get(0));
return true;
}
Aggregations