-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/pl/minecodes/mineeconomy/command/player/RankingCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | ||
} | ||
} | ||
|
||
} |