use of uk.co.oliwali.HawkEye.HawkEvent 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.HawkEvent in project HawkEye by oliverwoodings.
the class MonitorBlockListener method onBlockPlace.
@HawkEvent(dataType = DataType.BLOCK_PLACE)
public void onBlockPlace(BlockPlaceEvent event) {
Block block = event.getBlock();
if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
return;
DataManager.addEntry(new BlockChangeEntry(event.getPlayer(), DataType.BLOCK_PLACE, block.getLocation(), event.getBlockReplacedState(), block.getState()));
}
use of uk.co.oliwali.HawkEye.HawkEvent 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)));
}
}
}
use of uk.co.oliwali.HawkEye.HawkEvent 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.HawkEvent 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()));
}
Aggregations