use of uk.co.oliwali.HawkEye.DataType in project HawkEye by oliverwoodings.
the class HawkEyeListener method registerEvents.
public final void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
Method[] methods = this.getClass().getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
final Method method = methods[i];
final HawkEvent he = method.getAnnotation(HawkEvent.class);
if (he == null)
continue;
boolean register = false;
for (DataType dt : he.dataType()) {
if (Config.isLogged(dt))
register = true;
}
if (!register)
continue;
Class<?>[] params = method.getParameterTypes();
if (!Event.class.isAssignableFrom(params[0]) || params.length != 1) {
continue;
}
final Class<? extends Event> eventClass = params[0].asSubclass(Event.class);
method.setAccessible(true);
EventExecutor executor = new EventExecutor() {
public void execute(Listener listener, Event event) throws EventException {
try {
if (!eventClass.isAssignableFrom(event.getClass())) {
return;
}
Util.debug(DebugLevel.HIGH, "Calling event: " + event.getEventName());
method.invoke(listener, event);
Util.debug(DebugLevel.HIGH, "Event call complete: " + event.getEventName());
} catch (Exception ex) {
throw new EventException(ex.getCause());
}
}
};
Util.debug("Registering listener for " + eventClass.getName());
pm.registerEvent(eventClass, this, he.priority(), executor, plugin, he.ignoreCancelled());
}
}
use of uk.co.oliwali.HawkEye.DataType in project HawkEye by oliverwoodings.
the class DataManager method createEntryFromRes.
/**
* Creates a {@link DataEntry} from the inputted {ResultSet}
* @param res
* @return returns a {@link DataEntry}
* @throws SQLException
*/
public static DataEntry createEntryFromRes(ResultSet res) throws Exception {
DataType type = DataType.fromId(res.getInt("action"));
DataEntry entry = (DataEntry) type.getEntryClass().newInstance();
entry.setPlayer(DataManager.getPlayer(res.getInt("player_id")));
entry.setDate(res.getString("date"));
entry.setDataId(res.getInt("data_id"));
entry.setType(DataType.fromId(res.getInt("action")));
entry.interpretSqlData(res.getString("data"));
entry.setPlugin(res.getString("plugin"));
entry.setWorld(DataManager.getWorld(res.getInt("world_id")));
entry.setX(res.getInt("x"));
entry.setY(res.getInt("y"));
entry.setZ(res.getInt("z"));
return entry;
}
use of uk.co.oliwali.HawkEye.DataType 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.DataType in project HawkEye by oliverwoodings.
the class RollbackCommand method execute.
@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());
} else //If none supplied, add in all rollback types
{
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.GLOBAL), parser, SearchDir.DESC);
return true;
}
use of uk.co.oliwali.HawkEye.DataType in project HawkEye by oliverwoodings.
the class RollbackCommand method moreHelp.
@Override
public void moreHelp() {
List<String> acs = new ArrayList<String>();
for (DataType type : DataType.values()) if (type.canRollback())
acs.add(type.getConfigName());
Util.sendMessage(sender, "&7There are 6 parameters you can use - &ca: p: w: r: f: t:");
Util.sendMessage(sender, "&6Action &ca:&7 - list of actions separated by commas. Select from the following: &8" + Util.join(acs, " "));
Util.sendMessage(sender, "&6Player &cp:&7 - list of players. &6World &cw:&7 - list of worlds");
Util.sendMessage(sender, "&6Filter &cf:&7 - list of keywords (e.g. block id)");
Util.sendMessage(sender, "&6Radius &cr:&7 - radius to search around given location");
Util.sendMessage(sender, "&6Time &ct:&7 - time bracket in the following format:");
Util.sendMessage(sender, "&7 -&c t:10h45m10s &7-back specified amount of time");
Util.sendMessage(sender, "&7 -&c t:2011-06-02,10:45:10 &7-from given date");
Util.sendMessage(sender, "&7 -&c t:2011-06-02,10:45:10,2011-07-04,18:15:00 &7-between dates");
}
Aggregations