use of uk.co.oliwali.HawkEye.entry.DataEntry in project HawkEye by oliverwoodings.
the class DataManager method run.
/**
* Empty the {@link DataEntry} queue into the database
*/
@Override
public void run() {
if (queue.isEmpty())
return;
JDCConnection conn = getConnection();
PreparedStatement stmnt = null;
try {
while (!queue.isEmpty()) {
DataEntry entry = queue.poll();
//Sort out player IDs
if (!dbPlayers.containsKey(entry.getPlayer()) && !addPlayer(entry.getPlayer())) {
Util.debug("Player '" + entry.getPlayer() + "' not found, skipping entry");
continue;
}
if (!dbWorlds.containsKey(entry.getWorld()) && !addWorld(entry.getWorld())) {
Util.debug("World '" + entry.getWorld() + "' not found, skipping entry");
continue;
}
//If player ID is unable to be found, continue
if (entry.getPlayer() == null || dbPlayers.get(entry.getPlayer()) == null) {
Util.debug("No player found, skipping entry");
continue;
}
//If we are re-inserting we need to also insert the data ID
if (entry.getDataId() > 0) {
stmnt = conn.prepareStatement("INSERT into `" + Config.DbHawkEyeTable + "` (date, player_id, action, world_id, x, y, z, data, plugin, data_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
stmnt.setInt(10, entry.getDataId());
} else
stmnt = conn.prepareStatement("INSERT into `" + Config.DbHawkEyeTable + "` (date, player_id, action, world_id, x, y, z, data, plugin) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);");
stmnt.setString(1, entry.getDate());
stmnt.setInt(2, dbPlayers.get(entry.getPlayer()));
stmnt.setInt(3, entry.getType().getId());
stmnt.setInt(4, dbWorlds.get(entry.getWorld()));
stmnt.setDouble(5, entry.getX());
stmnt.setDouble(6, entry.getY());
stmnt.setDouble(7, entry.getZ());
stmnt.setString(8, entry.getSqlData());
stmnt.setString(9, entry.getPlugin());
stmnt.executeUpdate();
stmnt.close();
}
conn.close();
} catch (Exception ex) {
Util.severe("Exception: " + ex);
} finally {
try {
if (stmnt != null)
stmnt.close();
conn.close();
} catch (Exception ex) {
Util.severe("Unable to close SQL connection: " + ex);
}
}
}
use of uk.co.oliwali.HawkEye.entry.DataEntry in project HawkEye by oliverwoodings.
the class Rollback method run.
/**
* Run the rollback.
* Contains appropriate methods of catching errors and notifying the player
*/
public void run() {
//Start rollback process
int i = 0;
while (i < 200 && rollbackQueue.hasNext()) {
i++;
DataEntry entry = rollbackQueue.next();
//If the action can't be rolled back, skip this entry
if (entry.getType() == null || !entry.getType().canRollback())
continue;
//If the world doesn't exist, skip this entry
World world = HawkEye.server.getWorld(entry.getWorld());
if (world == null)
continue;
//Get some data from the entry
Location loc = new Location(world, entry.getX(), entry.getY(), entry.getZ());
Block block = world.getBlockAt(loc);
BlockState state = block.getState();
//Attempt global rollback
if (rollbackType == RollbackType.GLOBAL && entry.rollback(world.getBlockAt(loc))) {
entry.setUndoState(state);
undo.add(entry);
} else //Local rollback preview
if (rollbackType == RollbackType.LOCAL && entry.rollbackPlayer(block, (Player) session.getSender())) {
entry.setUndoState(state);
undo.add(entry);
}
}
//Check if rollback is finished
if (!rollbackQueue.hasNext()) {
//End timer
Bukkit.getServer().getScheduler().cancelTask(timerID);
session.setDoingRollback(false);
session.setRollbackResults(undo);
//Store undo results and notify player
if (rollbackType == RollbackType.GLOBAL) {
Util.sendMessage(session.getSender(), "&cRollback complete, &7" + undo.size() + "&c edits performed");
Util.sendMessage(session.getSender(), "&cUndo this rollback using &7/hawk undo");
//Delete data if told to
if (Config.DeleteDataOnRollback)
DataManager.deleteEntries(undo);
} else {
Util.sendMessage(session.getSender(), "&cRollback preview complete, &7" + undo.size() + "&c edits performed to you");
Util.sendMessage(session.getSender(), "&cType &7/hawk apply&c to make these changes permanent or &7/hawk cancel&c to cancel");
}
Util.debug("Rollback complete, " + undo.size() + " edits performed");
}
}
use of uk.co.oliwali.HawkEye.entry.DataEntry in project HawkEye by oliverwoodings.
the class MonitorPlayerListener method onPlayerDropItem.
@HawkEvent(dataType = DataType.ITEM_DROP)
public void onPlayerDropItem(PlayerDropItemEvent event) {
Player player = event.getPlayer();
ItemStack stack = event.getItemDrop().getItemStack();
String data = null;
if (stack.getData() != null)
data = stack.getAmount() + "x " + stack.getTypeId() + ":" + stack.getData().getData();
else
data = stack.getAmount() + "x " + stack.getTypeId();
DataManager.addEntry(new DataEntry(player, DataType.ITEM_DROP, player.getLocation(), data));
}
use of uk.co.oliwali.HawkEye.entry.DataEntry in project HawkEye by oliverwoodings.
the class MonitorPlayerListener method onPlayerJoin.
@HawkEvent(dataType = DataType.JOIN)
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
Location loc = player.getLocation();
DataManager.addEntry(new DataEntry(player, DataType.JOIN, loc, Config.LogIpAddresses ? player.getAddress().getAddress().getHostAddress().toString() : ""));
}
use of uk.co.oliwali.HawkEye.entry.DataEntry in project HawkEye by oliverwoodings.
the class MonitorPlayerListener method onPlayerChat.
@HawkEvent(dataType = DataType.CHAT)
public void onPlayerChat(PlayerChatEvent event) {
Player player = event.getPlayer();
//Check for inventory close
HawkEye.containerManager.checkInventoryClose(event.getPlayer());
DataManager.addEntry(new DataEntry(player, DataType.CHAT, player.getLocation(), event.getMessage()));
}
Aggregations