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

Reintroduce request toggling #57

Merged
merged 1 commit into from
Mar 11, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,25 @@ public void clearRequests(CommandAudience audience, @Argument("map") @Greedy Map
}
}

@CommandMethod("requests|reqs toggle")
@CommandDescription("Toggle map requests")
@CommandPermission(CommunityPermissions.REQUEST_STAFF)
public void toggleRequests(CommandAudience audience) {
requests.toggleAccepting();
BroadcastUtils.sendAdminChatMessage(
text()
.append(audience.getStyledName())
.append(text(" has ", NamedTextColor.GRAY))
.append(
text(
requests.isAccepting() ? "enabled" : "disabled",
requests.isAccepting() ? NamedTextColor.GREEN : NamedTextColor.RED,
TextDecoration.BOLD))
.append(text(" map requests", NamedTextColor.GRAY))
.build(),
CommunityPermissions.REQUEST_STAFF);
}

private Component getRequestsButton(
String text, String hover, NamedTextColor color, String command) {
return text()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public interface RequestFeature extends Feature {
/** Remove all player requests */
void clearAllRequests();

/** Toggle requests */
boolean isAccepting();

void toggleAccepting();

/**
* Get a set of {@link UUID}s who have requested the provided {@link MapInfo}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public abstract class RequestFeatureBase extends FeatureBase implements RequestF
private SponsorRequest currentSponsor;
private SponsorVotingBookCreator bookCreator;

private boolean accepting;

public RequestFeatureBase(
RequestConfig config, Logger logger, String featureName, UsersFeature users) {
super(config, logger, "Requests (" + featureName + ")");
Expand All @@ -99,6 +101,7 @@ public RequestFeatureBase(
this.sponsors = Lists.newLinkedList();
this.currentSponsor = null;
this.bookCreator = new SponsorVotingBookCreator(this);
this.accepting = true;

if (getConfig().isEnabled() && PGMUtils.isPGMEnabled()) {
enable();
Expand Down Expand Up @@ -311,6 +314,12 @@ public void onVoteAddCommand(PlayerCommandPreprocessEvent event) {
public void request(Player player, MapInfo map) {
Audience viewer = Audience.get(player);

// Check if enabled
if (!isAccepting()) {
viewer.sendWarning(text("Sorry, map requests are not being accepted at this time"));
return;
}

// Cooldown
if (hasCooldown(player, viewer)) return;

Expand Down Expand Up @@ -524,6 +533,16 @@ public void clearAllRequests() {
requests.invalidateAll();
}

@Override
public boolean isAccepting() {
return accepting;
}

@Override
public void toggleAccepting() {
this.accepting = !accepting;
}

@Override
public boolean cancelSponsorRequest(UUID playerId) {
return this.sponsors.removeIf(s -> s.getPlayerId().equals(playerId));
Expand Down
Loading