Skip to content

Commit

Permalink
fix: NPE on ranking command
Browse files Browse the repository at this point in the history
  • Loading branch information
RoinujNosde committed Apr 30, 2023
1 parent f626104 commit df7dd56
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/me/roinujnosde/titansbattle/BaseGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void onJoin(@NotNull Warrior warrior) {
SoundUtils.playSound(JOIN_GAME, plugin.getConfig(), player);
participants.add(warrior);
setKit(warrior);
broadcastKey("player_joined", player.getName());
broadcastKey("player_joined", warrior.getName());
player.sendMessage(getLang("objective"));
if (participants.size() == getConfig().getMaximumPlayers() && lobbyTask != null) {
lobbyTask.processEnd();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private int getNameSize(List<Group> groups) {
}

private int getNickSize(final List<Warrior> warriors) {
int nickSize = warriors.stream().mapToInt(w -> w.toPlayer().getName().length()).max().orElse(0);
int nickSize = warriors.stream().mapToInt(w -> w.getName().length()).max().orElse(0);
if (getNicknameTitle().length() > nickSize) {
nickSize = getNicknameTitle().length();
}
Expand Down Expand Up @@ -340,7 +340,7 @@ private String makeGroupLine(Group g, final String game, String line, int pos, L
}

private String makeWarriorLine(String line, int pos, Warrior w, String game, List<Warrior> warriors) {
String name = w.toPlayer().getName();
String name = w.getName();
int victories = w.getVictories(game);
int kills = w.getKills(game);
int deaths = w.getDeaths(game);
Expand Down Expand Up @@ -469,7 +469,7 @@ public void winners(CommandSender sender, @Values("@games") GameConfiguration ga
if (uuid == null) {
name = plugin.getLang("winners-no-killer", game);
} else {
name = Bukkit.getOfflinePlayer(uuid).getName();
name = databaseManager.getWarrior(uuid).getName();
}

String group = winners.getWinnerGroup(game.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.roinujnosde.titansbattle.TitansBattle;
import me.roinujnosde.titansbattle.managers.DatabaseManager;
import me.roinujnosde.titansbattle.types.GameConfiguration;
import me.roinujnosde.titansbattle.types.Group;
import me.roinujnosde.titansbattle.types.Warrior;
import me.roinujnosde.titansbattle.types.Winners;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -163,9 +163,10 @@ private String getKillerPrefix(@NotNull OfflinePlayer player, @NotNull String ga
List<UUID> list = w.getPlayerWinners(game);
return list != null && !list.isEmpty();
});
DatabaseManager db = plugin.getDatabaseManager();

return winners.map(value -> value.getPlayerWinners(game).stream().map(Bukkit::getOfflinePlayer)
.map(OfflinePlayer::getName).collect(Collectors.joining(", "))).orElse("");
return winners.map(value -> value.getPlayerWinners(game).stream().map(db::getWarrior)
.map(Warrior::getName).collect(Collectors.joining(", "))).orElse("");
}

private @NotNull String getLastKiller(String game) {
Expand All @@ -174,7 +175,7 @@ private String getKillerPrefix(@NotNull OfflinePlayer player, @NotNull String ga
return "";
}
UUID killer = winners.get().getKiller(game);
return Bukkit.getOfflinePlayer(killer).getName();
return plugin.getDatabaseManager().getWarrior(killer).getName();
}

private @NotNull String getLastWinnerGroup(String game) {
Expand Down

0 comments on commit df7dd56

Please sign in to comment.