Skip to content

Commit

Permalink
Introduce a new /poll feature 🗳️ (#43)
Browse files Browse the repository at this point in the history
Signed-off-by: applenick <[email protected]>
  • Loading branch information
applenick authored Sep 22, 2023
1 parent 826bd47 commit 604a5a4
Show file tree
Hide file tree
Showing 32 changed files with 2,473 additions and 4 deletions.
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@
<includes>
<include>net.kyori:*:*</include>
<include>co.aikar:*</include>
<include>cloud.commandframework:cloud-*:*</include>
<include>me.lucko:commodore:*</include>
<include>tc.oc.pgm:util</include>
<include>redis.clients:jedis</include>
<include>org.apache.commons:commons-pool2</include>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/dev/pgm/community/CommunityPermissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public interface CommunityPermissions {
String PARTY_HOST = PARTY + ".host"; // Given to those who are currently hosting an event
String PARTY_ADMIN = PARTY + ".admin"; // Administrative event permission

// Polls
String POLL = ROOT + ".poll";

// General Commands
String FLIGHT = ROOT + ".fly";
String FLIGHT_SPEED = FLIGHT + ".speed";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import dev.pgm.community.nick.commands.NickCommands;
import dev.pgm.community.party.MapPartyCommands;
import dev.pgm.community.party.MapPartyType;
import dev.pgm.community.polls.PollThreshold;
import dev.pgm.community.polls.commands.PollManagementCommands;
import dev.pgm.community.polls.commands.PollVoteCommands;
import dev.pgm.community.requests.commands.RequestCommands;
import dev.pgm.community.requests.commands.SponsorCommands;
import dev.pgm.community.requests.commands.TokenCommands;
Expand Down Expand Up @@ -101,6 +104,7 @@ protected void setupParsers() {
registerParser(MapInfo.class, MapInfoParser::new);
registerParser(MapPartyType.class, new EnumParser<>(MapPartyType.class));
registerParser(MutationType.class, new EnumParser<>(MutationType.class));
registerParser(PollThreshold.class, new EnumParser<>(PollThreshold.class));
registerParser(TargetPlayer.class, new TargetPlayerParser());
registerParser(Player.class, new PlayerParser());
registerParser(Party.class, PartyParser::new);
Expand Down Expand Up @@ -145,6 +149,10 @@ protected void registerCommands() {
// Party
register(new MapPartyCommands());

// Polls
register(new PollManagementCommands());
register(new PollVoteCommands());

// Requests
register(new RequestCommands());
register(new SponsorCommands());
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/dev/pgm/community/feature/FeatureManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import dev.pgm.community.nick.feature.NickFeature;
import dev.pgm.community.nick.feature.types.SQLNickFeature;
import dev.pgm.community.party.feature.MapPartyFeature;
import dev.pgm.community.polls.feature.PollFeature;
import dev.pgm.community.requests.feature.RequestFeature;
import dev.pgm.community.requests.feature.types.SQLRequestFeature;
import dev.pgm.community.sessions.feature.SessionFeature;
Expand Down Expand Up @@ -54,6 +55,7 @@ public class FeatureManager {
private final BroadcastFeature broadcast;
private final MobFeature mob;
private final MapPartyFeature party;
private final PollFeature polls;

public FeatureManager(
Configuration config,
Expand Down Expand Up @@ -88,6 +90,7 @@ public FeatureManager(
this.chatNetwork = new NetworkChatFeature(config, logger, network);
this.mob = new MobFeature(config, logger);
this.party = new MapPartyFeature(config, logger);
this.polls = new PollFeature(config, logger);
}

public AssistanceFeature getReports() {
Expand Down Expand Up @@ -150,12 +153,16 @@ public RequestFeature getRequests() {
return requests;
}

public MobFeature getMobs() {
return mob;
}

public MapPartyFeature getParty() {
return party;
}

public MobFeature getMobs() {
return mob;
public PollFeature getPolls() {
return polls;
}

public void reloadConfig(Configuration config) {
Expand All @@ -176,6 +183,7 @@ public void reloadConfig(Configuration config) {
getRequests().getConfig().reload(config);
getMobs().getConfig().reload(config);
getParty().getConfig().reload(config);
getPolls().getConfig().reload(config);
// TODO: Look into maybe unregister commands for features that have been disabled
// commands#unregisterCommand
// Will need to check isEnabled
Expand All @@ -197,5 +205,7 @@ public void disable() {
if (getNetworkChat().isEnabled()) getNetworkChat().disable();
if (getRequests().isEnabled()) getRequests().disable();
if (getMobs().isEnabled()) getMobs().disable();
if (getParty().isEnabled()) getParty().disable();
if (getPolls().isEnabled()) getPolls().disable();
}
}
12 changes: 12 additions & 0 deletions src/main/java/dev/pgm/community/mutations/MutationType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package dev.pgm.community.mutations;

import static net.kyori.adventure.text.Component.text;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
Expand Down Expand Up @@ -70,4 +75,11 @@ public ItemStack getIcon(boolean enabled) {

return item.build();
}

public Component getComponent() {
return text()
.append(text(getDisplayName()))
.hoverEvent(HoverEvent.showText(text(getDescription(), NamedTextColor.GRAY)))
.build();
}
}
42 changes: 42 additions & 0 deletions src/main/java/dev/pgm/community/polls/Poll.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev.pgm.community.polls;

import dev.pgm.community.polls.ending.EndAction;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;

public interface Poll {

Component getQuestion();

UUID getCreator();

Instant getStartTime();

Instant getEndTime();

void setEndTime(Instant time);

boolean isRunning();

List<EndAction> getEndAction();

boolean vote(Player player, String option);

long getTotalVotes();

PollThreshold getRequiredThreshold();

Duration getTimeLeft();

boolean hasVoted(Player player);

void tallyVotes();

void start();

Component getVoteButtons(boolean compact);
}
Loading

0 comments on commit 604a5a4

Please sign in to comment.