Skip to content

Commit

Permalink
Improvements to sponsor map constraints
Browse files Browse the repository at this point in the history
Signed-off-by: applenick <applenick@users.noreply.github.com>
  • Loading branch information
applenick committed Jun 30, 2024
1 parent 1670d3f commit 9cf0eab
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 88 deletions.
15 changes: 15 additions & 0 deletions src/main/java/dev/pgm/community/requests/RequestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class RequestConfig extends FeatureConfigImpl {
private static final String MAX_TOKENS = SPONSORS + ".max-tokens";
private static final String REFUND = SPONSORS + ".refund";
private static final String MAP_COOLDOWN_MULTIPLY = SPONSORS + ".map-cooldown";
private static final String LOWER_LIMIT_OFFSET = SPONSORS + ".lower-limit-offset";
private static final String UPPER_LIMIT_OFFSET = SPONSORS + ".upper-limit-offset";

private Duration cooldown; // Cooldown for using /request
private Duration sponsorCooldown; // Default cooldown for sponsor requests
Expand All @@ -40,6 +42,9 @@ public class RequestConfig extends FeatureConfigImpl {

private int mapCooldownMultiply; // # to multiply match length by to determine cooldown

private int lowerLimitOffset; // Offset to apply on match end to lower map size bound
private int upperLimitOffset; // Offset to apply on match end to upper map size bound

public RequestConfig(Configuration config) {
super(KEY, config);
}
Expand Down Expand Up @@ -92,6 +97,14 @@ public int getMapCooldownMultiply() {
return mapCooldownMultiply;
}

public int getLowerLimitOffset() {
return lowerLimitOffset;
}

public int getUpperLimitOffset() {
return upperLimitOffset;
}

@Override
public void reload(Configuration config) {
super.reload(config);
Expand All @@ -104,5 +117,7 @@ public void reload(Configuration config) {
this.maxQueue = config.getInt(SPONSORS_LIMIT);
this.refund = config.getBoolean(REFUND);
this.mapCooldownMultiply = config.getInt(MAP_COOLDOWN_MULTIPLY);
this.lowerLimitOffset = config.getInt(LOWER_LIMIT_OFFSET);
this.upperLimitOffset = config.getInt(UPPER_LIMIT_OFFSET);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import dev.pgm.community.utils.BroadcastUtils;
import dev.pgm.community.utils.CommandAudience;
import dev.pgm.community.utils.MessageUtils;
import dev.pgm.community.utils.PGMUtils;
import dev.pgm.community.utils.PGMUtils.MapSizeBounds;
import dev.pgm.community.utils.PaginatedComponentResults;
import dev.pgm.community.utils.VisibilityUtils;
import java.util.Arrays;
Expand All @@ -39,11 +39,9 @@
import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import tc.oc.pgm.api.PGM;
import tc.oc.pgm.api.map.Contributor;
import tc.oc.pgm.api.map.MapInfo;
import tc.oc.pgm.api.map.MapTag;
import tc.oc.pgm.api.map.Phase;
import tc.oc.pgm.lib.org.incendo.cloud.annotation.specifier.Greedy;
import tc.oc.pgm.lib.org.incendo.cloud.annotations.Argument;
import tc.oc.pgm.lib.org.incendo.cloud.annotations.Command;
Expand Down Expand Up @@ -206,12 +204,7 @@ public void viewMapList(
List<String> tags,
@Flag(value = "author", aliases = "a") String author,
@Flag(value = "name", aliases = "n") String name) {
Stream<MapInfo> search = PGM.get()
.getMapLibrary()
.getMaps(name)
.filter(PGMUtils::isMapSizeAllowed)
.filter(m -> m.getPhase() == Phase.PRODUCTION)
.filter(m -> !requests.hasMapCooldown(m));
Stream<MapInfo> search = requests.getAvailableSponsorMaps().stream();

if (!tags.isEmpty()) {
final Map<Boolean, Set<String>> tagSet = tags.stream()
Expand All @@ -235,8 +228,23 @@ public void viewMapList(
int resultsPerPage = 8;
int pages = (maps.size() + resultsPerPage - 1) / resultsPerPage;

MapSizeBounds bounds = requests.getCurrentMapSizeBounds();
Component hover = text()
.append(text("Current online player range", NamedTextColor.DARK_AQUA))
.appendSpace()
.append(text("(", NamedTextColor.GRAY))
.append(text(bounds.getLowerBound(), NamedTextColor.GOLD))
.append(text("-", NamedTextColor.GRAY))
.append(text(bounds.getUpperBound(), NamedTextColor.GOLD))
.append(text(")", NamedTextColor.GRAY))
.build();
Component title = text()
.append(text("Available Maps"))
.hoverEvent(HoverEvent.showText(hover))
.build();

Component paginated = TextFormatter.paginate(
text("Available Maps"), page, pages, NamedTextColor.DARK_AQUA, NamedTextColor.AQUA, true);
title, page, pages, NamedTextColor.DARK_AQUA, NamedTextColor.AQUA, true);

Component formattedTitle = TextFormatter.horizontalLineHeading(
audience.getSender(), paginated, NamedTextColor.DARK_PURPLE, 250);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.pgm.community.requests.MapCooldown;
import dev.pgm.community.requests.RequestProfile;
import dev.pgm.community.requests.SponsorRequest;
import dev.pgm.community.utils.PGMUtils.MapSizeBounds;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -149,4 +150,6 @@ public interface RequestFeature extends Feature {
void openMenu(Player player);

List<MapInfo> getAvailableSponsorMaps();

MapSizeBounds getCurrentMapSizeBounds();
}
Loading

0 comments on commit 9cf0eab

Please sign in to comment.