use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.
the class PlayerInfoTest method testResolvePlayerInfo5.
// Test two conflicting (of same statType) and two non conflicting (of another statType, that conflict with each
// other).
@Test
public void testResolvePlayerInfo5() {
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);
Query queryE = StatzUtil.makeQuery("UUID", uuid, "World", "worldName3", "value", 100);
playerInfo.addRow(statType, queryA);
playerInfo2.addRow(statType, queryB);
playerInfo2.addRow(statType2, queryC);
playerInfo.addRow(statType2, queryD);
playerInfo.addRow(statType, queryE);
PlayerInfo nonConflictingPlayerInfo = playerInfo.resolveConflicts(playerInfo2);
// Verify the number of rows
Assert.assertEquals(2, 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(111, nonConflictingPlayerInfo.getTotalValue(statType), 0);
Assert.assertEquals(53, nonConflictingPlayerInfo.getTotalValue(statType2), 0);
}
use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.
the class PlayerInfoTest method testResolvePlayerInfo2.
// Test with two conflicting and one non-conflicting query
@Test
public void testResolvePlayerInfo2() {
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);
Query queryC = StatzUtil.makeQuery("UUID", uuid, "World", "worldName2", "value", 8);
playerInfo.addRow(statType, queryA);
playerInfo2.addRow(statType, queryB);
playerInfo2.addRow(statType, queryC);
PlayerInfo nonConflictingPlayerInfo = playerInfo.resolveConflicts(playerInfo2);
// Verify that there is only 1 row
Assert.assertEquals(2, nonConflictingPlayerInfo.getNumberOfRows(statType));
// Verify that there is only 1 statistic stored
Assert.assertEquals(1, nonConflictingPlayerInfo.getNumberOfStatistics());
// Verify that value is correct
Assert.assertEquals(19, nonConflictingPlayerInfo.getTotalValue(statType), 0);
}
use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.
the class UpdateDatabaseTask method run.
@Override
public void run() {
if (UpdatePoolManager.isForcingPool) {
// Skip call, as we are still busy.
plugin.debugMessage("Skip database sync as there is still one running.");
return;
}
plugin.debugMessage("Sending local data to database...");
// Set lock so we can't accidentally run two sync tasks at the same time.
UpdatePoolManager.isForcingPool = true;
for (PlayerStat statType : PlayerStat.values()) {
// Grab updates that have happened since the last sync.
List<Query> updates = plugin.getUpdatePoolManager().getUpdateQueriesCopy(statType);
if (updates.isEmpty()) {
continue;
}
// Store queries that have already been converted
List<Query> convertedQueries = new ArrayList<>();
// Queries that should be send to the database
List<Query> resultingQueries = new ArrayList<>();
// Loop over all queries and remove duplicate queries.
for (Iterator<Query> iterator = updates.iterator(); iterator.hasNext(); ) {
// Get a query.
Query query = iterator.next();
// If we've already converted it, skip it.
if (convertedQueries.contains(query)) {
continue;
}
// Remove the current query so it doesn't conflict with itself.
iterator.remove();
// Find queries that conflict with the current query
List<Query> conflictingQueries = query.findConflicts(updates);
// Add queries that were conflicting to converted queries, so we don't count them again.
convertedQueries.addAll(conflictingQueries);
// Calculate sum of all conflicting queries.
Query sumQuery = query.resolveConflicts(conflictingQueries);
// Store the final query
resultingQueries.add(sumQuery);
}
// Update database with new data.
plugin.getDatabaseConnector().setBatchObjects(DatabaseConnector.getTable(statType), resultingQueries, 2);
plugin.getUpdatePoolManager().clearUpdateQueries(statType);
}
// Release lock
UpdatePoolManager.isForcingPool = false;
plugin.debugMessage("Successfully updated database with local data.");
plugin.getLogsManager().writeToLogFile("Updated database with local data.");
}
use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.
the class UpdatePoolManager method printPool.
/**
* Print all pools to the console.
*/
public void printPool() {
if (this.updateQueries.isEmpty()) {
System.out.println("POOL IS EMPTY");
return;
}
System.out.println("PRINT POOL");
System.out.println("------------------------");
for (PlayerStat stat : PlayerStat.values()) {
List<Query> queries = this.getUpdateQueriesCopy(stat);
if (queries == null || queries.isEmpty()) {
System.out.println("[PlayerStat: " + stat + "]: EMPTY");
continue;
}
System.out.println("------------------------");
System.out.println("[PlayerStat: " + stat + "] Size: " + queries.size());
for (Query query : queries) {
System.out.println("------------------------");
StringBuilder builder = new StringBuilder("{");
for (Map.Entry<String, String> entry : query.getEntrySet()) {
builder.append(entry.getKey() + ": " + entry.getValue() + ", ");
}
builder.append("}");
System.out.println(builder.toString());
}
}
}
use of me.staartvin.statz.datamanager.player.PlayerStat in project Statz by Staartvin.
the class TimesShornListener method onShear.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onShear(final PlayerShearEntityEvent event) {
final PlayerStat stat = PlayerStat.TIMES_SHORN;
// 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()));
}
Aggregations