Skip to content

Commit

Permalink
Add default poll duration & threshold to config
Browse files Browse the repository at this point in the history
Signed-off-by: applenick <[email protected]>
  • Loading branch information
applenick committed Aug 15, 2023
1 parent 1aef9c0 commit 5c600f1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/main/java/dev/pgm/community/polls/PollBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ public class PollBuilder {

private PollEditAlerter alert; // Used to broadcast changes to values

public PollBuilder(PollEditAlerter alert) {
this.alert = alert;
}

// Required
private Component question;
private UUID creator;
Expand All @@ -36,6 +32,12 @@ public PollBuilder(PollEditAlerter alert) {
private Duration duration;
private EndAction endAction = new NullEndAction();

public PollBuilder(PollConfig config, PollEditAlerter alert) {
this.alert = alert;
this.duration = (config.getDuration().isNegative() ? null : config.getDuration());
this.threshold = config.getThreshold();
}

public PollBuilder question(CommandAudience sender, String question) {
this.question = (question != null ? text(question) : null);
alert.broadcastChange(sender, "Poll Question", question);
Expand All @@ -48,6 +50,7 @@ public PollBuilder creator(UUID creator) {
}

public PollBuilder duration(CommandAudience sender, Duration duration) {
duration = duration.abs();
this.duration = duration;
alert.broadcastChange(sender, "Poll Duration", duration);
return this;
Expand Down Expand Up @@ -133,6 +136,7 @@ public Component getQuestion() {
return question;
}

@Nullable
public Duration getDuration() {
return duration;
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/dev/pgm/community/polls/PollConfig.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
package dev.pgm.community.polls;

import static tc.oc.pgm.util.text.TextParser.parseDuration;

import dev.pgm.community.feature.config.FeatureConfigImpl;
import java.time.Duration;
import org.bukkit.configuration.Configuration;

public class PollConfig extends FeatureConfigImpl {

private static final String KEY = "polls";

private Duration duration;
private PollThreshold threshold;

public PollConfig(Configuration config) {
super(KEY, config);
}

public Duration getDuration() {
return duration;
}

public PollThreshold getThreshold() {
return threshold;
}

@Override
public void reload(Configuration config) {
super.reload(config);
this.duration = parseDuration(config.getString(KEY + ".duration"));
this.threshold = PollThreshold.valueOf(config.getString(KEY + ".threshold").toUpperCase());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public PollFeature(Configuration config, Logger logger) {
}
}

private PollConfig getPollConfig() {
return (PollConfig) getConfig();
}

private void task() {
if (!isRunning()) return;

Expand Down Expand Up @@ -80,7 +84,7 @@ public PollBuilder getBuilder() {
}

public void resetBuilder() {
this.builder = new PollBuilder(this);
this.builder = new PollBuilder(getPollConfig(), this);
}

public boolean canStart() {
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,17 @@ party:
# List of map names if mode is CUSTOM
maps: []

# Polls - Feature that allows polling of players in-game
# Polls - Feature that empowers players to collectively decide on in-game questions asked by staff.
polls:
# Set to true to enable polls, false to disable.
enabled: true

# Default time limit for polls upon creation. Set to -1 for open ended polls.
duration: 5m # for 5 minutes

# The default threshold required for a poll to pass.
# Options: "CLEAR_MINORITY", "SIMPLE", "TWO_THIRDS", "STRONG_MAJORITY"
threshold: "simple"

# Network - Features which assist in running Community on multiple servers
network:
Expand Down

0 comments on commit 5c600f1

Please sign in to comment.