Search in sources :

Example 11 with DataEntry

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);
        }
    }
}
Also used : DataEntry(uk.co.oliwali.HawkEye.entry.DataEntry) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 12 with DataEntry

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");
    }
}
Also used : DataEntry(uk.co.oliwali.HawkEye.entry.DataEntry) BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) World(org.bukkit.World) Location(org.bukkit.Location)

Example 13 with DataEntry

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));
}
Also used : DataEntry(uk.co.oliwali.HawkEye.entry.DataEntry) Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) HawkEvent(uk.co.oliwali.HawkEye.HawkEvent)

Example 14 with DataEntry

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() : ""));
}
Also used : DataEntry(uk.co.oliwali.HawkEye.entry.DataEntry) Player(org.bukkit.entity.Player) Location(org.bukkit.Location) HawkEvent(uk.co.oliwali.HawkEye.HawkEvent)

Example 15 with DataEntry

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()));
}
Also used : DataEntry(uk.co.oliwali.HawkEye.entry.DataEntry) Player(org.bukkit.entity.Player) HawkEvent(uk.co.oliwali.HawkEye.HawkEvent)

Aggregations

DataEntry (uk.co.oliwali.HawkEye.entry.DataEntry)17 Player (org.bukkit.entity.Player)9 HawkEvent (uk.co.oliwali.HawkEye.HawkEvent)9 Location (org.bukkit.Location)7 Block (org.bukkit.block.Block)4 World (org.bukkit.World)3 ItemStack (org.bukkit.inventory.ItemStack)3 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 DataType (uk.co.oliwali.HawkEye.DataType)2 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 BlockState (org.bukkit.block.BlockState)1 Entity (org.bukkit.entity.Entity)1 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)1 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)1 DeleteCallback (uk.co.oliwali.HawkEye.callbacks.DeleteCallback)1 SimpleRollbackEntry (uk.co.oliwali.HawkEye.entry.SimpleRollbackEntry)1