Skip to content

Commit

Permalink
Fix sponsoring not considering variants (#87)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
  • Loading branch information
Pablete1234 authored Jan 18, 2025
1 parent 5d37eb7 commit 778dab5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
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

0 comments on commit 778dab5

Please sign in to comment.