Search in sources :

Example 6 with DataEntry

use of uk.co.oliwali.HawkEye.entry.DataEntry in project HawkEye by oliverwoodings.

the class MonitorEntityListener method onEntityDeath.

/**
	 * Uses the lastAttacker field in the players {@link PlayerSession} to log the death and cause
	 */
@HawkEvent(dataType = { DataType.PVP_DEATH, DataType.MOB_DEATH, DataType.OTHER_DEATH, DataType.ENTITY_KILL })
public void onEntityDeath(EntityDeathEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof Player) {
        //Player death
        Player victim = (Player) entity;
        //Mob or PVP death
        if (victim.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
            Entity damager = ((EntityDamageByEntityEvent) (victim.getLastDamageCause())).getDamager();
            if (damager instanceof Player) {
                if (!Config.isLogged(DataType.PVP_DEATH) && !Config.LogDeathDrops)
                    return;
                DataManager.addEntry(new DataEntry(victim, DataType.PVP_DEATH, victim.getLocation(), Util.getEntityName(damager)));
            } else {
                if (!Config.isLogged(DataType.MOB_DEATH) && !Config.LogDeathDrops)
                    return;
                DataManager.addEntry(new DataEntry(victim, DataType.MOB_DEATH, victim.getLocation(), Util.getEntityName(damager)));
            }
        //Other death
        } else {
            if (!Config.isLogged(DataType.OTHER_DEATH) && !Config.LogDeathDrops)
                return;
            EntityDamageEvent dEvent = victim.getLastDamageCause();
            String cause = dEvent == null ? "Unknown" : victim.getLastDamageCause().getCause().name();
            String[] words = cause.split("_");
            for (int i = 0; i < words.length; i++) words[i] = words[i].substring(0, 1).toUpperCase() + words[i].substring(1).toLowerCase();
            cause = Util.join(Arrays.asList(words), " ");
            DataManager.addEntry(new DataEntry(victim, DataType.OTHER_DEATH, victim.getLocation(), cause));
        }
        //Log item drops
        if (Config.LogDeathDrops) {
            String data = null;
            for (ItemStack stack : event.getDrops()) {
                if (stack.getData() != null)
                    data = stack.getAmount() + "x " + stack.getTypeId() + ":" + stack.getData().getData();
                else
                    data = stack.getAmount() + "x " + stack.getTypeId();
                DataManager.addEntry(new DataEntry(victim, DataType.ITEM_DROP, victim.getLocation(), data));
            }
        }
    } else {
        //Mob Death
        if (!Config.isLogged(DataType.ENTITY_KILL))
            return;
        if (entity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
            Entity damager = ((EntityDamageByEntityEvent) entity.getLastDamageCause()).getDamager();
            //Only interested in player kills
            if (!(damager instanceof Player))
                return;
            Player player = (Player) damager;
            DataManager.addEntry(new DataEntry(player, DataType.ENTITY_KILL, entity.getLocation(), Util.getEntityName(entity)));
        }
    }
}
Also used : DataEntry(uk.co.oliwali.HawkEye.entry.DataEntry) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) ItemStack(org.bukkit.inventory.ItemStack) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) HawkEvent(uk.co.oliwali.HawkEye.HawkEvent)

Example 7 with DataEntry

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 : ""));
}
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 8 with DataEntry

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

Example 9 with DataEntry

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

Example 10 with DataEntry

use of uk.co.oliwali.HawkEye.entry.DataEntry in project HawkEye by oliverwoodings.

the class DisplayManager method displayPage.

/**
	 * Displays a page of data from the specified {@link PlayerSession} search results.
	 * Contains appropriate methods for detecing errors e.g. no results
	 * @param session {@link PlayerSession}
	 * @param page page number to display
	 */
public static void displayPage(PlayerSession session, int page) {
    //Check if any results are found
    List<DataEntry> results = session.getSearchResults();
    if (results == null || results.size() == 0) {
        Util.sendMessage(session.getSender(), "&cNo results found");
        return;
    }
    //Work out max pages. Return if page is higher than max pages
    int maxLines = 6;
    int maxPages = (int) Math.ceil((double) results.size() / 6);
    if (page > maxPages || page < 1)
        return;
    //Begin displaying page
    Util.sendMessage(session.getSender(), "&8--------------------- &7Page (&c" + page + "&7/&c" + maxPages + "&7) &8--------------------" + (maxPages < 9 ? "-" : ""));
    for (int i = (page - 1) * maxLines; i < ((page - 1) * maxLines) + maxLines; i++) {
        if (i == results.size())
            break;
        DataEntry entry = results.get(i);
        sendLine(session.getSender(), "&cid:" + entry.getDataId() + " &7" + entry.getDate().substring(5) + " &c" + entry.getPlayer() + " &7" + entry.getType().getConfigName());
        sendLine(session.getSender(), "   &cLoc: &7" + entry.getWorld() + "-" + entry.getX() + "," + entry.getY() + "," + entry.getZ() + " &cData: &7" + entry.getStringData());
    }
    Util.sendMessage(session.getSender(), "&8-----------------------------------------------------");
    return;
}
Also used : DataEntry(uk.co.oliwali.HawkEye.entry.DataEntry)

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