Search in sources :

Example 11 with PlayerStat

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

the class VotesListener method onVote.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVote(final VotifierEvent event) {
    final PlayerStat stat = PlayerStat.VOTES;
    String userName = event.getVote().getUsername();
    // Get player
    final Player player = plugin.getServer().getPlayer(userName);
    UUID uuid = null;
    // Player is not online, so
    if (player == null) {
    } else {
        uuid = player.getUniqueId();
        userName = player.getName();
    }
    if (player != null) {
        // Do general check
        if (!plugin.doGeneralCheck(player, stat))
            return;
    }
    if (uuid == null) {
        @SuppressWarnings("deprecation") OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(userName);
        uuid = offlinePlayer.getUniqueId();
    }
    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(uuid, stat, StatzUtil.makeQuery("uuid", uuid.toString(), "value", 1));
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) OfflinePlayer(org.bukkit.OfflinePlayer) UUID(java.util.UUID) EventHandler(org.bukkit.event.EventHandler)

Example 12 with PlayerStat

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

the class WorldsChangedListener method onWorldSwitch.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldSwitch(final PlayerChangedWorldEvent event) {
    final PlayerStat stat = PlayerStat.WORLDS_CHANGED;
    // 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", event.getFrom().getName(), "destWorld", player.getWorld().getName()));
}
Also used : Player(org.bukkit.entity.Player) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) EventHandler(org.bukkit.event.EventHandler)

Example 13 with PlayerStat

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

the class DataManager method loadPlayerData.

/**
 * Load all data of a player into the cache, so it can be retrieved.
 * Note that this method will block the thread it is on and so it should be run asynchronously.
 *
 * @param uuid UUID of the player
 *
 * @return the PlayerInfo data that was loaded into the cache, ready for use.
 *
 * @throws IllegalArgumentException if the given uuid is null
 */
public PlayerInfo loadPlayerData(UUID uuid) throws IllegalArgumentException {
    if (uuid == null) {
        throw new IllegalArgumentException("UUID cannot be null.");
    }
    PlayerInfo info = new PlayerInfo(uuid);
    // Load all data of a player
    for (PlayerStat statType : PlayerStat.values()) {
        PlayerInfo freshPlayerInfo = getFreshPlayerInfo(uuid, statType);
        info.setData(statType, freshPlayerInfo.getDataOfPlayerStat(statType));
    }
    // Put new data into cache.
    plugin.getCachingManager().registerCachedData(uuid, info);
    return info;
}
Also used : PlayerInfo(me.staartvin.statz.datamanager.player.PlayerInfo) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat)

Example 14 with PlayerStat

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

the class GUIManager method getPlayerStatistics.

/**
 * Get all statistics of a player, except the players table.
 * @param uuid UUID of the player
 * @return all PlayerInfo per stat type of the given player.
 */
private Map<PlayerStat, PlayerInfo> getPlayerStatistics(UUID uuid) {
    Map<PlayerStat, PlayerInfo> statistics = new HashMap<>();
    for (PlayerStat stat : PlayerStat.values()) {
        if (stat == PlayerStat.PLAYERS) {
            continue;
        }
        PlayerInfo info = plugin.getDataManager().getPlayerInfo(uuid, stat);
        statistics.put(stat, info);
    }
    return statistics;
}
Also used : PlayerInfo(me.staartvin.statz.datamanager.player.PlayerInfo) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat)

Example 15 with PlayerStat

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

the class DamageTakenListener method onDamage.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDamage(final EntityDamageEvent event) {
    final PlayerStat stat = PlayerStat.DAMAGE_TAKEN;
    if (!(event.getEntity() instanceof Player)) {
        // It was not a player that got damage
        return;
    }
    // Get player
    final Player player = (Player) event.getEntity();
    // 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", event.getDamage(), "cause", event.getCause().toString(), "world", player.getWorld().getName()));
}
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