-
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
10 changed files
with
133 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
31 changes: 31 additions & 0 deletions
31
src/main/java/pl/csrv/divinecraft/evirth/cryptomarket/commands/models/Stats.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,31 @@ | ||
package main.java.pl.csrv.divinecraft.evirth.cryptomarket.commands.models; | ||
|
||
public class Stats { | ||
private int depositedDiamonds; | ||
private int withdrawnDiamonds; | ||
private int finalStats; | ||
private String playerName; | ||
|
||
public Stats(String playerName, int depositedDiamonds, int withdrawnDiamonds, int finalStats) { | ||
this.playerName = playerName; | ||
this.depositedDiamonds = depositedDiamonds; | ||
this.withdrawnDiamonds = withdrawnDiamonds; | ||
this.finalStats = finalStats; | ||
} | ||
|
||
public int getDepositedDiamonds() { | ||
return this.depositedDiamonds; | ||
} | ||
|
||
public int getWithdrawnDiamonds() { | ||
return this.withdrawnDiamonds; | ||
} | ||
|
||
public int getFinalStats() { | ||
return this.finalStats; | ||
} | ||
|
||
public String getPlayerName() { | ||
return this.playerName; | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
src/main/java/pl/csrv/divinecraft/evirth/cryptomarket/commands/player/TopCommand.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,59 @@ | ||
package main.java.pl.csrv.divinecraft.evirth.cryptomarket.commands.player; | ||
|
||
import main.java.pl.csrv.divinecraft.evirth.cryptomarket.CryptoMarket; | ||
import main.java.pl.csrv.divinecraft.evirth.cryptomarket.api.Player; | ||
import main.java.pl.csrv.divinecraft.evirth.cryptomarket.commands.ICommand; | ||
import main.java.pl.csrv.divinecraft.evirth.cryptomarket.commands.Permissions; | ||
import main.java.pl.csrv.divinecraft.evirth.cryptomarket.commands.models.Stats; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.command.CommandSender; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
public class TopCommand implements ICommand { | ||
|
||
@Override | ||
public boolean execute(CommandSender commandSender, String[] strings) { | ||
try { | ||
if (!commandSender.hasPermission(Permissions.CRYPTOMARKET_PLAYER)) { | ||
commandSender.sendMessage(CryptoMarket.resourceManager.getResource("MissingPermission")); | ||
return true; | ||
} | ||
|
||
List<Stats> stats = new ArrayList<>(); | ||
OfflinePlayer[] players = Bukkit.getOfflinePlayers(); | ||
for (OfflinePlayer o : players) { | ||
Player p = new Player(o.getName()); | ||
Stats s = p.getStats(); | ||
if (s != null) { | ||
stats.add(s); | ||
} | ||
} | ||
|
||
stats.sort(Comparator.comparing(Stats::getFinalStats)); | ||
Collections.reverse(stats); | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(ChatColor.translateAlternateColorCodes('&', "&6----- CryptoMarket ----- Top Players -----\n")); | ||
for (int i = 0; i < stats.size() && i < 3; i++) { | ||
sb.append(ChatColor.translateAlternateColorCodes('&', | ||
String.format("#%d. &5%s&f - Stats: &%s%d&f (Withdrawn: &a%d&f : Deposited: &c%d&f)\n", | ||
i + 1, | ||
stats.get(i).getPlayerName(), | ||
stats.get(i).getFinalStats() < 0 ? "c" : "a", | ||
stats.get(i).getFinalStats(), | ||
stats.get(i).getWithdrawnDiamonds(), | ||
stats.get(i).getDepositedDiamonds()))); | ||
} | ||
sb.append(ChatColor.translateAlternateColorCodes('&', "&6---------------------------------------")); | ||
commandSender.sendMessage(sb.toString().split("\n")); | ||
} catch (Exception e) { | ||
commandSender.sendMessage(CryptoMarket.resourceManager.getResource("CouldNotGetTopList")); | ||
} | ||
return true; | ||
} | ||
} |
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
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
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