Search in sources :

Example 1 with PlayerStat

use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.

the class Statz method registerListeners.

private void registerListeners() {
    if (!this.getConfigHandler().getStatsTracking()) {
        this.debugMessage(ChatColor.GOLD + "Statz won't track stats of any player!");
        // We don't track stats, so we don't register listeners
        return;
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.DEATHS)) {
        this.getServer().getPluginManager().registerEvents(new DeathsListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.JOINS)) {
        this.getServer().getPluginManager().registerEvents(new JoinsListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.ITEMS_CAUGHT)) {
        this.getServer().getPluginManager().registerEvents(new ItemsCaughtListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.BLOCKS_PLACED)) {
        this.getServer().getPluginManager().registerEvents(new BlocksPlacedListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.BLOCKS_BROKEN)) {
        this.getServer().getPluginManager().registerEvents(new BlocksBrokenListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.KILLS_MOBS)) {
        this.getServer().getPluginManager().registerEvents(new KillsMobsListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.KILLS_PLAYERS)) {
        this.getServer().getPluginManager().registerEvents(new KillsPlayersListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.FOOD_EATEN)) {
        this.getServer().getPluginManager().registerEvents(new FoodEatenListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.DAMAGE_TAKEN)) {
        this.getServer().getPluginManager().registerEvents(new DamageTakenListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.TIMES_SHORN)) {
        this.getServer().getPluginManager().registerEvents(new TimesShornListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.DISTANCE_TRAVELLED)) {
        this.getServer().getPluginManager().registerEvents(new DistanceTravelledListener(this), this);
        this.getServer().getPluginManager().registerEvents(new DistanceTravelledVehicleListener(this), this);
        this.getServer().getPluginManager().registerEvents(new DistanceTravelledToggleGlideListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.ITEMS_CRAFTED)) {
        this.getServer().getPluginManager().registerEvents(new ItemsCraftedListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.XP_GAINED)) {
        this.getServer().getPluginManager().registerEvents(new XPGainedListener(this), this);
    }
    // Important listeners that should always be on.
    this.getServer().getPluginManager().registerEvents(new JoinPlayerListener(this), this);
    this.getServer().getPluginManager().registerEvents(new QuitListener(this), this);
    if (this.getDependencyManager().isAvailable(StatzDependency.VOTIFIER) || this.getDependencyManager().isAvailable(StatzDependency.NUVOTIFIER) && !this.getConfigHandler().isStatDisabled(PlayerStat.VOTES)) {
        this.getServer().getPluginManager().registerEvents(new VotesListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.ARROWS_SHOT)) {
        this.getServer().getPluginManager().registerEvents(new ArrowsShotListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.ENTERED_BEDS)) {
        this.getServer().getPluginManager().registerEvents(new EnteredBedsListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.COMMANDS_PERFORMED)) {
        this.getServer().getPluginManager().registerEvents(new CommandsPerformedListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.TIMES_KICKED)) {
        this.getServer().getPluginManager().registerEvents(new TimesKickedListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.TOOLS_BROKEN)) {
        this.getServer().getPluginManager().registerEvents(new ToolsBrokenListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.EGGS_THROWN)) {
        this.getServer().getPluginManager().registerEvents(new EggsThrownListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.WORLDS_CHANGED)) {
        this.getServer().getPluginManager().registerEvents(new WorldsChangedListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.BUCKETS_FILLED)) {
        this.getServer().getPluginManager().registerEvents(new BucketsFilledListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.BUCKETS_EMPTIED)) {
        this.getServer().getPluginManager().registerEvents(new BucketsEmptiedListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.ITEMS_PICKED_UP)) {
        this.getServer().getPluginManager().registerEvents(new ItemsPickedUpListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.ITEMS_DROPPED)) {
        this.getServer().getPluginManager().registerEvents(new ItemsDroppedListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.TELEPORTS)) {
        this.getServer().getPluginManager().registerEvents(new TeleportsListener(this), this);
    }
    if (!this.getConfigHandler().isStatDisabled(PlayerStat.VILLAGER_TRADES)) {
        this.getServer().getPluginManager().registerEvents(new VillagerTradesListener(this), this);
    }
    for (PlayerStat stat : this.getConfigHandler().getDisabledStats()) {
        this.debugMessage(ChatColor.DARK_AQUA + "Statz won't track " + stat.toString() + "!");
    }
    // Register confirm command
    this.getServer().getPluginManager().registerEvents(new ConfirmTransferCommandListener(this), this);
}
Also used : PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat)

Example 2 with PlayerStat

use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.

the class BlocksBrokenListener method onBlockBreak.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(final BlockBreakEvent event) {
    final PlayerStat stat = PlayerStat.BLOCKS_BROKEN;
    // Get player
    final Player player = event.getPlayer();
    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;
    Block blockBroken = event.getBlock();
    final int typeId = blockBroken.getTypeId();
    final int dataValue = blockBroken.getData();
    final String worldName = blockBroken.getWorld().getName();
    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1, "typeid", typeId, "datavalue", dataValue, "world", worldName));
}
Also used : Player(org.bukkit.entity.Player) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 3 with PlayerStat

use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.

the class BucketsEmptiedListener method onBucketEmpty.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBucketEmpty(final PlayerBucketEmptyEvent event) {
    final PlayerStat stat = PlayerStat.BUCKETS_EMPTIED;
    // 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 4 with PlayerStat

use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.

the class UpdatePlayerCacheTask method run.

@Override
public void run() {
    PlayerInfo cachedData = new PlayerInfo(uuid);
    for (PlayerStat statType : PlayerStat.values()) {
        if (statType.equals(PlayerStat.PLAYERS)) {
            continue;
        }
        PlayerInfo databaseInfo = plugin.getDataManager().getFreshPlayerInfo(uuid, statType);
        // User is not loaded, or there is no cache so we don't bother overwriting the cache.
        if (databaseInfo == null) {
            continue;
        }
        // Remove all 'id' columns to prevent leakage from the database.
        for (Query query : databaseInfo.getRows()) {
            query.removeColumn("id");
        }
        cachedData = cachedData.resolveConflicts(databaseInfo);
    }
    plugin.debugMessage("Updated cache of " + uuid);
    // Store into cache.
    plugin.getCachingManager().registerCachedData(uuid, cachedData);
}
Also used : Query(me.staartvin.statz.database.datatype.Query) PlayerInfo(me.staartvin.statz.datamanager.player.PlayerInfo) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat)

Example 5 with PlayerStat

use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.

the class ItemsCraftedListener method onCraft.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCraft(final CraftItemEvent event) {
    final PlayerStat stat = PlayerStat.ITEMS_CRAFTED;
    // Get player
    final Player player = (Player) event.getWhoClicked();
    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;
    final String itemCrafted = event.getCurrentItem().getType().toString();
    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", getCraftAmount(event), "world", player.getWorld().getName(), "item", itemCrafted));
}
Also used : Player(org.bukkit.entity.Player) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) 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