Search in sources :

Example 31 with PlayerStat

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()));
}
Also used : Player(org.bukkit.entity.Player) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) EventHandler(org.bukkit.event.EventHandler)

Example 32 with PlayerStat

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()));
}
Also used : Vehicle(org.bukkit.entity.Vehicle) Player(org.bukkit.entity.Player) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) EventHandler(org.bukkit.event.EventHandler)

Example 33 with PlayerStat

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()));
}
Also used : Player(org.bukkit.entity.Player) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) EventHandler(org.bukkit.event.EventHandler)

Example 34 with PlayerStat

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()));
}
Also used : Entity(org.bukkit.entity.Entity) Item(org.bukkit.entity.Item) Player(org.bukkit.entity.Player) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 35 with PlayerStat

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());
    }
}
Also used : Player(org.bukkit.entity.Player) BukkitTask(org.bukkit.scheduler.BukkitTask) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PlayerStat (me.staartvin.statz.datamanager.player.PlayerStat)44 Player (org.bukkit.entity.Player)30 EventHandler (org.bukkit.event.EventHandler)29 Query (me.staartvin.statz.database.datatype.Query)11 PlayerInfo (me.staartvin.statz.datamanager.player.PlayerInfo)11 UUID (java.util.UUID)7 ItemStack (org.bukkit.inventory.ItemStack)6 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 OfflinePlayer (org.bukkit.OfflinePlayer)3 Entity (org.bukkit.entity.Entity)3 Block (org.bukkit.block.Block)2 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)2 Inventory (org.bukkit.inventory.Inventory)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Material (org.bukkit.Material)1 Arrow (org.bukkit.entity.Arrow)1 Item (org.bukkit.entity.Item)1 Vehicle (org.bukkit.entity.Vehicle)1