Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
1.8 kB
5
Indexable
Never
@Override
    public void onMessageReceived(MessageReceivedEvent event)
    {
        Message msg = event.getMessage();
        EmbedBuilder ebs = new EmbedBuilder();
        ebs.setColor(Color.RED);
        ebs.setTitle("No player specified");
        String msgs = msg.getContentRaw();
        String player = msgs.substring(7);
        Bukkit.getLogger().info(player);
        Bukkit.getLogger().info("a");
        if(!(msgs.startsWith("!stats"))) {
            Bukkit.getLogger().info("A");
            return;
        }
        if(msgs.length() < 6) {
            Bukkit.getLogger().info("B");
            msg.replyEmbeds(ebs.build());
            return;
        }
        Bukkit.getLogger().info("C");
        msg.replyEmbeds(getEmbed(player, event.getAuthor()));
        Bukkit.getLogger().info("D");
    }

    public static MessageEmbed getEmbed(String username, User sender) {
        Stats stats = new Stats(Bukkit.getOfflinePlayer(username));
        EmbedBuilder builder = new EmbedBuilder();
        builder.setTitle("Stats of " + username);
        builder.setColor(Color.green);
        builder.addField("Player kills", String.valueOf(stats.getPlayerKills()), false);
        builder.addField("Mob kills", String.valueOf(stats.getKills()), false);
        builder.addField("Deaths", String.valueOf(stats.getDeaths()), false);
        builder.addField("Miles walked", String.valueOf(stats.getMilesWalked()), false);
        builder.addField("Damage taken", String.valueOf(stats.getDamageTaken()), false);
        builder.addField("Damage dealt", String.valueOf(stats.getDamageDealt()), false);
        builder.setFooter("Requested by " + sender.getName(), sender.getAvatarUrl());
        return builder.build();
    }