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 sponsoring not considering variants #87

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
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
18 changes: 6 additions & 12 deletions core/src/main/java/dev/pgm/community/requests/MapCooldown.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@

import java.time.Duration;
import java.time.Instant;
import tc.oc.pgm.util.TimeUtils;

public class MapCooldown {
private Instant endTime;
private Duration matchLength;
private final Instant endsAt;

public MapCooldown(Instant endTime, Duration matchLength) {
this.endTime = endTime;
this.matchLength = matchLength;
}

public Instant getEndTime() {
return endTime;
public MapCooldown(Duration cooldown) {
this.endsAt = Instant.now().plus(cooldown);
}

public boolean hasExpired() {
return getTimeRemaining().isNegative();
return !getTimeRemaining().isPositive();
}

public Duration getTimeRemaining() {
Duration timeSince = Duration.between(endTime, Instant.now());
return matchLength.minus(timeSince);
return TimeUtils.max(Duration.ZERO, Duration.between(Instant.now(), endsAt));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ record MapWithCooldown(MapInfo map, Duration cooldown) {}

var maps = StreamUtils.of(library.getMaps())
.map(map -> new MapWithCooldown(map, requests.getApproximateCooldown(map)))
.filter(mcd -> mcd.cooldown.isPositive())
.filter(mcd -> mcd.cooldown.toSeconds() > 0)
.sorted(Comparator.comparing(MapWithCooldown::cooldown))
.toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@

public abstract class RequestFeatureBase extends FeatureBase implements RequestFeature {

// Multiplier for minimum score to allow sponsoring
private static final double MIN_SCORE_MUL = 0.35;

private Cache<UUID, MapInfo> requests;

private Cache<UUID, Instant> cooldown;
Expand Down Expand Up @@ -641,7 +644,7 @@ public Duration getApproximateCooldown(MapInfo map) {
return map.getVariants().values().stream()
.map(variant -> mapLibrary.getMapById(variant.getId()))
.filter(Objects::nonNull)
.map(m -> TimeUtils.max(sponsor.getSponsorCooldown(map), getPgmCooldown(map)))
.map(m -> TimeUtils.max(sponsor.getSponsorCooldown(m), getPgmCooldown(m)))
.max(Comparator.naturalOrder())
.orElse(Duration.ZERO);
}
Expand All @@ -652,7 +655,7 @@ private Duration getPgmCooldown(MapInfo map) {
var data = pool.getVoteData(map);
Duration cd = data.remainingCooldown(pool.constants);
if (cd.isPositive()) return cd;
return data.getScore() < (pool.constants.defaultScore() / 2)
return data.getScore() < (pool.constants.defaultScore() * MIN_SCORE_MUL)
? Duration.ofMillis(1L)
: Duration.ZERO;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import dev.pgm.community.utils.PGMUtils.MapSizeBounds;
import dev.pgm.community.utils.Sounds;
import java.time.Duration;
import java.time.Instant;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -90,8 +89,7 @@ public Duration getSponsorCooldown(MapInfo map) {

public void startNewMapCooldown(MapInfo map, Duration matchLength) {
this.mapCooldown.putIfAbsent(
map.getId(),
new MapCooldown(Instant.now(), matchLength.multipliedBy(config.getMapCooldownMultiply())));
map.getId(), new MapCooldown(matchLength.multipliedBy(config.getMapCooldownMultiply())));
}

public MapSizeBounds getCurrentMapSizeBounds() {
Expand Down
Loading