diff --git a/src/main/java/dev/pgm/community/requests/commands/RequestCommands.java b/src/main/java/dev/pgm/community/requests/commands/RequestCommands.java index 16eb108c..c4cba3a6 100644 --- a/src/main/java/dev/pgm/community/requests/commands/RequestCommands.java +++ b/src/main/java/dev/pgm/community/requests/commands/RequestCommands.java @@ -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() diff --git a/src/main/java/dev/pgm/community/requests/feature/RequestFeature.java b/src/main/java/dev/pgm/community/requests/feature/RequestFeature.java index 75935c5f..3a021b13 100644 --- a/src/main/java/dev/pgm/community/requests/feature/RequestFeature.java +++ b/src/main/java/dev/pgm/community/requests/feature/RequestFeature.java @@ -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} * diff --git a/src/main/java/dev/pgm/community/requests/feature/RequestFeatureBase.java b/src/main/java/dev/pgm/community/requests/feature/RequestFeatureBase.java index f8252316..fd5ddeb5 100644 --- a/src/main/java/dev/pgm/community/requests/feature/RequestFeatureBase.java +++ b/src/main/java/dev/pgm/community/requests/feature/RequestFeatureBase.java @@ -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 + ")"); @@ -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(); @@ -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; @@ -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));