Search in sources :

Example 16 with PlayerStat

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

the class EggsThrownListener method onEggThrow.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEggThrow(final PlayerEggThrowEvent event) {
    final PlayerStat stat = PlayerStat.EGGS_THROWN;
    // 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 17 with PlayerStat

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

the class FoodEatenListener method onEat.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEat(final PlayerItemConsumeEvent event) {
    final PlayerStat stat = PlayerStat.FOOD_EATEN;
    // Get player
    final Player player = event.getPlayer();
    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;
    final String foodName = StatzUtil.getFoodName(event.getItem());
    if (foodName == null)
        return;
    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1, "foodEaten", foodName, "world", player.getWorld().getName()));
}
Also used : Player(org.bukkit.entity.Player) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) EventHandler(org.bukkit.event.EventHandler)

Example 18 with PlayerStat

use of me.staartvin.statz.datamanager.player.PlayerStat 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);
}
Also used : Query(me.staartvin.statz.database.datatype.Query) PlayerInfo(me.staartvin.statz.datamanager.player.PlayerInfo) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) UUID(java.util.UUID) Test(org.junit.Test)

Example 19 with PlayerStat

use of me.staartvin.statz.datamanager.player.PlayerStat 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);
}
Also used : Query(me.staartvin.statz.database.datatype.Query) PlayerInfo(me.staartvin.statz.datamanager.player.PlayerInfo) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) UUID(java.util.UUID) Test(org.junit.Test)

Example 20 with PlayerStat

use of me.staartvin.statz.datamanager.player.PlayerStat 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);
}
Also used : Query(me.staartvin.statz.database.datatype.Query) PlayerInfo(me.staartvin.statz.datamanager.player.PlayerInfo) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) UUID(java.util.UUID) Test(org.junit.Test)

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