use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.
the class DistanceTravelledListener method onMove.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMove(final PlayerMoveEvent event) {
final PlayerStat stat = PlayerStat.DISTANCE_TRAVELLED;
// Get player
final Player player = event.getPlayer();
// Do general check
if (!plugin.doGeneralCheck(player, stat))
return;
String movementType = StatzUtil.getMovementType(player);
final double distTravelled;
try {
distTravelled = event.getFrom().distance(event.getTo());
} catch (IllegalArgumentException e) {
// Did not move correctly, so ignore it.
return;
}
if (distTravelled == 0) {
return;
}
final String movement = movementType;
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", (distTravelled), "moveType", movement, "world", player.getWorld().getName()));
}
use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.
the class DistanceTravelledVehicleListener method onMove.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMove(final VehicleMoveEvent event) {
final PlayerStat stat = PlayerStat.DISTANCE_TRAVELLED;
Vehicle vehicle = event.getVehicle();
if (vehicle.getPassenger() == null)
return;
// Get player
final Player player;
String movementType;
if (vehicle.getPassenger() instanceof Player) {
player = (Player) vehicle.getPassenger();
movementType = StatzUtil.getMovementType(player);
} else {
// No passenger on the passenger
if (vehicle.getPassenger().getPassenger() == null)
return;
// There is no player riding.
if (!(vehicle.getPassenger().getPassenger() instanceof Player))
return;
player = (Player) vehicle.getPassenger().getPassenger();
movementType = StatzUtil.getMovementType(player);
}
// No player found, no movementType found.
if (player == null || movementType == null)
return;
// Do general check
if (!plugin.doGeneralCheck(player, stat))
return;
final double distTravelled = event.getFrom().distance(event.getTo());
if (distTravelled == 0) {
return;
}
final String movement = movementType;
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", distTravelled, "moveType", movement, "world", player.getWorld().getName()));
}
use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.
the class EnteredBedsListener method onBedEnter.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBedEnter(final PlayerBedEnterEvent event) {
final PlayerStat stat = PlayerStat.ENTERED_BEDS;
// Get player
final Player player = event.getPlayer();
// Do general check
if (!plugin.doGeneralCheck(player, stat))
return;
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1, "world", player.getWorld().getName()));
}
use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.
the class ItemsCaughtListener method onFishCaught.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onFishCaught(final PlayerFishEvent event) {
final PlayerStat stat = PlayerStat.ITEMS_CAUGHT;
// Get player
final Player player = event.getPlayer();
// Do general check
if (!plugin.doGeneralCheck(player, stat))
return;
Entity entity;
ItemStack item;
String materialName = null;
if (event.getCaught() != null) {
entity = event.getCaught();
if (!(entity instanceof Item)) {
// Did not catch an item
return;
}
item = ((Item) entity).getItemStack();
if (event.getState().equals(State.CAUGHT_FISH)) {
materialName = StatzUtil.getFoodName(item);
if (materialName == null) {
materialName = item.getType().toString();
}
} else {
materialName = item.getType().toString();
}
} else {
// Did not catch anything.
return;
}
final String material = materialName;
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", item.getAmount(), "caught", material, "world", player.getWorld().getName()));
}
use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.
the class JoinsListener method onJoin.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onJoin(final PlayerJoinEvent event) {
final PlayerStat stat = PlayerStat.JOINS;
// Get player
final Player player = event.getPlayer();
// Do general check
if (!plugin.doGeneralCheck(player, stat))
return;
// Update name in database.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), PlayerStat.PLAYERS, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "playerName", player.getName()));
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1));
// Check if player already has a checker running.
if (!updateID.containsKey(player.getUniqueId())) {
// Player has joined, so create a timer that runs every minute to add time.
BukkitRunnable run = new BukkitRunnable() {
public void run() {
if (!player.isOnline()) {
updateID.remove(player.getUniqueId());
this.cancel();
return;
}
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), PlayerStat.TIME_PLAYED, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1, "world", player.getWorld().getName()));
}
};
BukkitTask task = run.runTaskTimerAsynchronously(plugin, 20 * 60, /*If currentValue is 0, schedule a check immediately, otherwise after a minute*/
20 * 60);
updateID.put(player.getUniqueId(), task.getTaskId());
}
}
Aggregations