Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mode commands with filtered modes #1048

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 15 additions & 37 deletions core/src/main/java/tc/oc/pgm/modes/ObjectiveModesMatchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
import static net.kyori.adventure.sound.Sound.sound;
import static net.kyori.adventure.text.Component.text;

import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.annotation.Nullable;
import java.util.stream.Collectors;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
Expand All @@ -22,6 +20,7 @@
import tc.oc.pgm.api.match.MatchScope;
import tc.oc.pgm.api.module.exception.ModuleLoadException;
import tc.oc.pgm.countdowns.CountdownContext;
import tc.oc.pgm.countdowns.MatchCountdown;
import tc.oc.pgm.events.ListenerScope;
import tc.oc.pgm.filters.FilterMatchModule;

Expand Down Expand Up @@ -88,42 +87,21 @@ public List<ModeChangeCountdown> getAllCountdowns() {
.build();
}

public List<ModeChangeCountdown> getSortedCountdowns(boolean includeUnstarted) {
List<ModeChangeCountdown> listClone = new ArrayList<>(this.countdowns);
List<ModeChangeCountdown> unstartedCountdowns = new ArrayList<>();
// places countdowns triggered by filter at the bottom of list
for (ModeChangeCountdown listCloneItem : listClone) {
if (listCloneItem.getRemaining() == null) {
unstartedCountdowns.add(listCloneItem);
listClone.remove(listCloneItem);
}
}
Collections.sort(listClone);
if (includeUnstarted) {
listClone.addAll(unstartedCountdowns);
}

return listClone;
public List<ModeChangeCountdown> getSortedCountdowns(boolean includeAll) {
return this.countdowns.stream()
.filter(mcc -> includeAll || mcc.getRemaining() != null)
.sorted(
Comparator.<ModeChangeCountdown>nullsLast(
Comparator.comparing(MatchCountdown::getRemaining))
.thenComparing(mcc -> mcc.getMode().getAfter()))
.collect(Collectors.toList());
}

public List<ModeChangeCountdown> getActiveCountdowns() {
List<ModeChangeCountdown> activeCountdowns =
new ArrayList<>(
Collections2.filter(
this.getAllCountdowns(),
new Predicate<ModeChangeCountdown>() {
@Override
public boolean apply(@Nullable ModeChangeCountdown countdown) {
return ObjectiveModesMatchModule.this
.getCountdown()
.getTimeLeft(countdown)
.getSeconds()
> 0;
}
}));
Collections.sort(activeCountdowns);

return activeCountdowns;
return getAllCountdowns().stream()
.filter(mcc -> mcc.getRemaining().getSeconds() > 0)
.sorted()
.collect(Collectors.toList());
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
Expand Down