Skip to content

Commit

Permalink
fix: allowing duplicate elements in casualties (#80)
Browse files Browse the repository at this point in the history
* Updates getLoserName logic in Challenge
  • Loading branch information
RoinujNosde authored Jul 2, 2022
1 parent 5c89612 commit 3f9031c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/me/roinujnosde/titansbattle/BaseGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class BaseGame {
protected boolean battle;
protected final List<Warrior> participants = new ArrayList<>();
protected final HashMap<Warrior, Integer> killsCount = new HashMap<>();
protected final List<Warrior> casualties = new ArrayList<>();
protected final Set<Warrior> casualties = new HashSet<>();
protected final Set<Warrior> casualtiesWatching = new HashSet<>();

private final List<BukkitTask> tasks = new ArrayList<>();
Expand Down Expand Up @@ -225,7 +225,7 @@ public Map<Group, Integer> getGroupParticipants() {
return groups;
}

public List<Warrior> getCasualties() {
public Collection<Warrior> getCasualties() {
return casualties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class Challenge extends BaseGame {

private Group winnerGroup;
private List<Warrior> winners = new ArrayList<>();

private Warrior lastCasualty;

public Challenge(@NotNull TitansBattle plugin, @NotNull ArenaConfiguration config) {
super(plugin, config);
}
Expand All @@ -48,6 +49,7 @@ protected void onLobbyEnd() {

@Override
protected void processRemainingPlayers(@NotNull Warrior warrior) {
lastCasualty = warrior;
if (getConfig().isGroupMode()) {
if (getGroupParticipants().size() == 1) {
getGroupParticipants().keySet().stream().findAny().ifPresent(g -> {
Expand Down Expand Up @@ -124,10 +126,9 @@ public boolean isInBattle(@NotNull Warrior warrior) {

private String getLoserName() {
if (!getConfig().isGroupMode()) {
return casualties.get(0).getName();
return lastCasualty.getName();
}
Warrior loser = casualties.get(casualties.size() - 1);
//noinspection ConstantConditions
return loser.getGroup().getName();

return lastCasualty.getGroup().getName();
}
}
}

0 comments on commit 3f9031c

Please sign in to comment.