Skip to content

Commit

Permalink
Filter out null values in stats commands
Browse files Browse the repository at this point in the history
  • Loading branch information
PainOchoco committed Nov 15, 2023
1 parent 9c3ca01 commit 1111f1c
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -37,7 +38,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String alias, String
OfflinePlayer source = null;
if (args.length > 0) {
if (args[0].equalsIgnoreCase("leaderboard")) {
if (args.length == 1) return false;
if (args.length == 1)
return false;
int page = 0;
if (args.length > 2) {
try {
Expand All @@ -55,12 +57,13 @@ public boolean onCommand(CommandSender sender, Command cmd, String alias, String
File folder = new File(LaBoulangerieMmo.PLUGIN.getDataFolder(), "players/");
Stream<MmoPlayer> listAllPlayers = List.of(folder.listFiles()).stream()
.map(file -> LaBoulangerieMmo.PLUGIN.getMmoPlayerManager().getOfflinePlayer(
Bukkit.getOfflinePlayer(UUID.fromString(file.getName().split(".json")[0]))));
Bukkit.getOfflinePlayer(UUID.fromString(file.getName().split(".json")[0]))))
.filter(Objects::isNull);

if (args[1].equalsIgnoreCase("all")) {
orderedPlayers =
listAllPlayers.sorted((v1, v2) -> ((Integer) v2.getPalier()).compareTo(v1.getPalier()))
.collect(Collectors.toList());
orderedPlayers = listAllPlayers
.sorted((v1, v2) -> ((Integer) v2.getPalier()).compareTo(v1.getPalier()))
.collect(Collectors.toList());
} else if (talentTopCache.get(args[1]) == null) {
if (LaBoulangerieMmo.talentsRegistry.getTalent(args[1]) == null) {
sender.sendMessage("§4Invalid talent.");
Expand Down Expand Up @@ -105,7 +108,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String alias, String
if (source == null && !(sender instanceof Player)) {
sender.sendMessage("§4You must be in game to use this command!");
return true;
} else if (source == null) source = (OfflinePlayer) sender;
} else if (source == null)
source = (OfflinePlayer) sender;

MmoPlayer mmoSource = LaBoulangerieMmo.PLUGIN.getMmoPlayerManager().getOfflinePlayer(source);
sendStatsTo(sender, mmoSource);
Expand Down Expand Up @@ -133,8 +137,9 @@ private void sendStatsTo(CommandSender target, MmoPlayer source) {

if (args.length == 1) {
suggestions.add("leaderboard");
if (sender.hasPermission("laboulangeriemmo.stats.see")) suggestions
.addAll(Bukkit.getOnlinePlayers().stream().map(p -> p.getName()).collect(Collectors.toList()));
if (sender.hasPermission("laboulangeriemmo.stats.see"))
suggestions
.addAll(Bukkit.getOnlinePlayers().stream().map(p -> p.getName()).collect(Collectors.toList()));
} else if (args[0].equalsIgnoreCase("leaderboard")) {
switch (args.length) {
case 2:
Expand All @@ -152,7 +157,8 @@ private void sendStatsTo(CommandSender target, MmoPlayer source) {
}

/**
* Clear the entry for the specified talent in {@code talentTopCache} in 1 minute
* Clear the entry for the specified talent in {@code talentTopCache} in 1
* minute
*
* @param talent
*/
Expand Down

0 comments on commit 1111f1c

Please sign in to comment.