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));
}
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()));
}
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;
}
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;
}
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()));
}
Aggregations