Search in sources :

Example 36 with PlayerStat

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

the class KillsMobsListener method onDie.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDie(final EntityDeathEvent event) {
    final PlayerStat stat = PlayerStat.KILLS_MOBS;
    Entity e = event.getEntity();
    if (!(e.getLastDamageCause() instanceof EntityDamageByEntityEvent)) {
        return;
    }
    EntityDamageByEntityEvent nEvent = (EntityDamageByEntityEvent) e.getLastDamageCause();
    if (nEvent.getDamager() instanceof Player) {
        // Entity died because of Player
        // Killer
        final Player player = (Player) nEvent.getDamager();
        // Do general check
        if (!plugin.doGeneralCheck(player, stat))
            return;
        if (e instanceof Player) {
        // Player killed player
        // Handled by other listener
        } else {
            // Player killed mob
            String mobType = StatzUtil.getMobType(e);
            String weapon = "";
            ItemStack item = player.getInventory().getItemInMainHand();
            if (item.getType() == Material.AIR) {
                weapon = "HAND";
            } else {
                weapon = item.getType().toString();
            }
            // Update value to new stat.
            plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1, "world", player.getWorld().getName(), "mob", mobType, "weapon", weapon));
        }
    } else if (nEvent.getDamager() instanceof Arrow) {
        // Entity was killed by an arrow, now check if it was shot by a player
        Arrow killerArrow = (Arrow) nEvent.getDamager();
        if (killerArrow.getShooter() instanceof Player) {
            Player shooter = (Player) killerArrow.getShooter();
            // Now update database.
            plugin.getDataManager().setPlayerInfo(shooter.getUniqueId(), stat, StatzUtil.makeQuery("uuid", shooter.getUniqueId().toString(), "value", 1, "world", shooter.getWorld().getName(), "mob", StatzUtil.getMobType(e), "weapon", "BOW"));
        }
    }
// 
}
Also used : Arrow(org.bukkit.entity.Arrow) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 37 with PlayerStat

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

the class ArrowsShotListener method onShootArrow.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onShootArrow(final EntityShootBowEvent event) {
    final PlayerStat stat = PlayerStat.ARROWS_SHOT;
    if (!(event.getEntity() instanceof Player)) {
        // It was not a player that shoot a bow
        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(), "value", 1, "world", player.getWorld().getName(), "forceShot", event.getForce()));
}
Also used : Player(org.bukkit.entity.Player) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) EventHandler(org.bukkit.event.EventHandler)

Example 38 with PlayerStat

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

the class BlocksPlacedListener method onBlockPlace.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(final BlockPlaceEvent event) {
    final PlayerStat stat = PlayerStat.BLOCKS_PLACED;
    // Get player
    final Player player = event.getPlayer();
    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;
    Block blockPlaced = event.getBlockPlaced();
    final int typeId = blockPlaced.getTypeId();
    final int dataValue = blockPlaced.getData();
    final String worldName = blockPlaced.getWorld().getName();
    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1, "typeid", typeId, "datavalue", dataValue, "world", worldName));
}
Also used : Player(org.bukkit.entity.Player) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 39 with PlayerStat

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

the class BucketsFilledListener method onBucketFill.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBucketFill(final PlayerBucketFillEvent event) {
    final PlayerStat stat = PlayerStat.BUCKETS_FILLED;
    // 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 40 with PlayerStat

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

the class DataManager method sendStatisticsList.

public void sendStatisticsList(CommandSender sender, String playerName, UUID uuid, int pageNumber, List<PlayerStat> list) {
    List<String> messages = new ArrayList<>();
    List<TextComponent> messagesSpigot = new ArrayList<>();
    for (PlayerStat statType : list) {
        // Skip data of players table
        if (statType.equals(PlayerStat.PLAYERS)) {
            continue;
        }
        PlayerInfo info = plugin.getDataManager().getPlayerInfo(uuid, statType);
        // Player is not loaded into cache yet, first load player data into cache.
        if (info == null) {
            info = plugin.getDataManager().loadPlayerData(uuid, statType);
        }
        // If data is empty, we have no data about the player and so skip it.
        if (info.getDataOfPlayerStat(statType).isEmpty()) {
            continue;
        }
        String messageString = DescriptionMatcher.getTotalDescription(info, statType);
        if (sender instanceof Player && plugin.getServer().getVersion().toLowerCase().contains("spigot")) {
            TextComponent spigotMessage = new TextComponent(messageString);
            spigotMessage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/statz list " + playerName + " " + statType.toString()));
            spigotMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click on me for more info about ").append(statType.toString()).color(net.md_5.bungee.api.ChatColor.GOLD).create()));
            messagesSpigot.add(spigotMessage);
        } else {
            messages.add(messageString);
        }
    }
    int messagesPerPage = 8;
    int pages = 0;
    if (sender instanceof Player) {
        pages = (int) Math.ceil(messagesSpigot.size() / (double) messagesPerPage);
    } else {
        pages = (int) Math.ceil(messages.size() / (double) messagesPerPage);
    }
    if (pageNumber > (pages - 1) || pageNumber < 0) {
        pageNumber = 0;
    }
    sender.sendMessage(ChatColor.YELLOW + "---------------- [Statz of " + playerName + "] ----------------");
    for (int j = 0; j < messagesPerPage; j++) {
        int index = (pageNumber == 0 ? j : (pageNumber * messagesPerPage) + j);
        // Don't try to get other messages, as there are no others.
        if (sender instanceof Player) {
            if (index >= messagesSpigot.size()) {
                break;
            }
        } else {
            if (index >= messages.size()) {
                break;
            }
        }
        if (sender instanceof Player) {
            Player p = (Player) sender;
            p.spigot().sendMessage(messagesSpigot.get(index));
        } else {
            sender.sendMessage(messages.get(index));
        }
    }
    // Create page clicker
    BaseComponent[] pageClicker = new ComponentBuilder("<<< ").color(net.md_5.bungee.api.ChatColor.GOLD).event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/statz list " + playerName + " " + (pageNumber < 0 ? 0 : pageNumber))).append("Page ").color(net.md_5.bungee.api.ChatColor.DARK_AQUA).append(pageNumber + 1 + "").color(net.md_5.bungee.api.ChatColor.GREEN).append(" of " + pages).color(net.md_5.bungee.api.ChatColor.DARK_AQUA).append(" >>>").color(net.md_5.bungee.api.ChatColor.GOLD).event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/statz list " + playerName + " " + (pageNumber + 2 > pages ? pages : pageNumber + 2))).create();
    if (sender instanceof Player) {
        Player p = (Player) sender;
        p.spigot().sendMessage(pageClicker);
    } else {
        sender.sendMessage(ChatColor.GOLD + "<<< " + ChatColor.DARK_AQUA + "Page " + ChatColor.GREEN + (pageNumber + 1) + ChatColor.DARK_AQUA + " of " + pages + ChatColor.GOLD + " >>>");
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) PlayerInfo(me.staartvin.statz.datamanager.player.PlayerInfo)

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