use of me.staartvin.statz.datamanager.player.PlayerInfo 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.PlayerInfo 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.PlayerInfo in project Statz by Staartvin.
the class PlayerInfoTest method testResolvePlayerInfo.
// Test two conflicting queries
@Test
public void testResolvePlayerInfo() {
UUID uuid = UUID.fromString("3657b9cc-2518-4265-ad69-323e11286ce2");
PlayerStat statType = PlayerStat.ARROWS_SHOT;
PlayerInfo playerInfo = new PlayerInfo(uuid);
PlayerInfo playerInfo2 = new PlayerInfo(uuid);
Query queryA = StatzUtil.makeQuery("UUID", uuid, "World", "worldName1", "value", 5);
Query queryB = StatzUtil.makeQuery("UUID", uuid, "World", "worldName1", "value", 6);
playerInfo.addRow(statType, queryA);
playerInfo2.addRow(statType, queryB);
PlayerInfo nonConflictingPlayerInfo = playerInfo.resolveConflicts(playerInfo2);
List<Query> nonConflictingQueries = nonConflictingPlayerInfo.getDataOfPlayerStat(statType);
// Verify that size is correct
Assert.assertEquals(1, nonConflictingQueries.size());
// Verify that there is only 1 row
Assert.assertEquals(1, nonConflictingPlayerInfo.getNumberOfRows(statType));
// Verify that there is only 1 statistic stored
Assert.assertEquals(1, nonConflictingPlayerInfo.getNumberOfStatistics());
// Verify that value is correct
Assert.assertEquals(11, nonConflictingPlayerInfo.getTotalValue(statType), 0);
}
use of me.staartvin.statz.datamanager.player.PlayerInfo in project Statz by Staartvin.
the class PlayerInfoTest method testResolvePlayerInfo4.
// Test two conflicting (of same statType) and two non conflicting (of another statType, that conflict with each
// other).
@Test
public void testResolvePlayerInfo4() {
UUID uuid = UUID.fromString("3657b9cc-2518-4265-ad69-323e11286ce2");
PlayerStat statType = PlayerStat.ARROWS_SHOT;
PlayerStat statType2 = PlayerStat.KILLS_MOBS;
PlayerInfo playerInfo = new PlayerInfo(uuid);
PlayerInfo playerInfo2 = new PlayerInfo(uuid);
Query queryA = StatzUtil.makeQuery("UUID", uuid, "World", "worldName1", "value", 5);
Query queryB = StatzUtil.makeQuery("UUID", uuid, "World", "worldName1", "value", 6);
Query queryC = StatzUtil.makeQuery("UUID", uuid, "World", "worldName2", "value", 8);
Query queryD = StatzUtil.makeQuery("UUID", uuid, "World", "worldName2", "value", 45);
playerInfo.addRow(statType, queryA);
playerInfo2.addRow(statType, queryB);
playerInfo2.addRow(statType2, queryC);
playerInfo.addRow(statType2, queryD);
PlayerInfo nonConflictingPlayerInfo = playerInfo.resolveConflicts(playerInfo2);
// Verify the number of rows
Assert.assertEquals(1, nonConflictingPlayerInfo.getNumberOfRows(statType));
Assert.assertEquals(1, nonConflictingPlayerInfo.getNumberOfRows(statType2));
// Verify the number of statistics stored.
Assert.assertEquals(2, nonConflictingPlayerInfo.getNumberOfStatistics());
// Verify that value is correct
Assert.assertEquals(11, nonConflictingPlayerInfo.getTotalValue(statType), 0);
Assert.assertEquals(53, nonConflictingPlayerInfo.getTotalValue(statType2), 0);
}
use of me.staartvin.statz.datamanager.player.PlayerInfo in project Statz by Staartvin.
the class PlayerInfoTest method testResolvePlayerInfo3.
// Test two conflicting (of same statType) and one non conflicting (of another statType).
@Test
public void testResolvePlayerInfo3() {
UUID uuid = UUID.fromString("3657b9cc-2518-4265-ad69-323e11286ce2");
PlayerStat statType = PlayerStat.ARROWS_SHOT;
PlayerStat statType2 = PlayerStat.KILLS_MOBS;
PlayerInfo playerInfo = new PlayerInfo(uuid);
PlayerInfo playerInfo2 = new PlayerInfo(uuid);
Query queryA = StatzUtil.makeQuery("UUID", uuid, "World", "worldName1", "value", 5);
Query queryB = StatzUtil.makeQuery("UUID", uuid, "World", "worldName1", "value", 6);
Query queryC = StatzUtil.makeQuery("UUID", uuid, "World", "worldName2", "value", 8);
playerInfo.addRow(statType, queryA);
playerInfo2.addRow(statType, queryB);
playerInfo2.addRow(statType2, queryC);
PlayerInfo nonConflictingPlayerInfo = playerInfo.resolveConflicts(playerInfo2);
// Verify the number of rows
Assert.assertEquals(1, nonConflictingPlayerInfo.getNumberOfRows(statType));
Assert.assertEquals(1, nonConflictingPlayerInfo.getNumberOfRows(statType2));
// Verify the number of statistics stored.
Assert.assertEquals(2, nonConflictingPlayerInfo.getNumberOfStatistics());
// Verify that value is correct
Assert.assertEquals(11, nonConflictingPlayerInfo.getTotalValue(statType), 0);
Assert.assertEquals(8, nonConflictingPlayerInfo.getTotalValue(statType2), 0);
}
Aggregations