Skip to content

Commit

Permalink
🎉 Created ranking command.
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurr0 committed Oct 2, 2021
1 parent 4f3479c commit 1d4c38c
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package pl.minecodes.mineeconomy.command.player;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.Default;
import com.google.common.collect.ImmutableMap;
import eu.okaeri.injector.annotation.Inject;
import org.bukkit.entity.Player;
import pl.minecodes.mineeconomy.data.configuration.Configuration;
import pl.minecodes.mineeconomy.data.configuration.Messages;
import pl.minecodes.mineeconomy.data.database.element.model.DataService;
import pl.minecodes.mineeconomy.profile.Profile;
import pl.minecodes.mineeconomy.profile.ProfileService;
import pl.minecodes.mineeconomy.util.MessageUtil;
import pl.minecodes.mineeconomy.util.Placeholders;

import java.util.Objects;

@CommandAlias("ranking")
public class RankingCommand extends BaseCommand {

@Inject
private Messages messages;
@Inject
private DataService dataService;
@Inject
private Configuration configuration;

@Default
public void onCheckRanking(Player player) {
int rankingOrder = 1;
for (String string : this.messages.getBalanceRanking()) {
if (!string.contains("username")) MessageUtil.sendMessage(player, string);

Profile order = this.dataService.order(rankingOrder);
if (order == null) {
MessageUtil.sendMessage(player, this.messages.getBalanceRankingNullObject());
} else {
MessageUtil.sendMessage(player, Placeholders.replace(string,
ImmutableMap.of(
"username", Objects.requireNonNull(order.getPlayer().getName(), "OfflinePlayer name is null."),
"balance", order.getBalance(),
"currency", this.configuration.getCurrency(order.getBalance())
)));
}
rankingOrder++;
}
}

}

0 comments on commit 1d4c38c

Please sign in to comment.