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