Skip to content

Commit

Permalink
Add super votes
Browse files Browse the repository at this point in the history
Signed-off-by: applenick <[email protected]>
  • Loading branch information
applenick committed Jul 1, 2024
1 parent b6bad75 commit c8a699e
Show file tree
Hide file tree
Showing 20 changed files with 941 additions and 170 deletions.
13 changes: 13 additions & 0 deletions src/main/java/dev/pgm/community/CommunityConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.pgm.community;

import dev.pgm.community.utils.NetworkUtils;
import dev.pgm.community.utils.ranks.RanksConfig;
import org.bukkit.configuration.Configuration;
import tc.oc.occ.environment.Environment;

Expand All @@ -10,16 +11,20 @@ public class CommunityConfig {
private String serverId;
private boolean useEnvironment;
private String environmentServerIdKey;
private RanksConfig ranks;
private String storeLink;

public CommunityConfig(Configuration config) {
reload(config);
}

public void reload(Configuration config) {
this.ranks = new RanksConfig(config);
this.serverDisplayName = config.getString("general.server-name", "");
this.serverId = config.getString("general.server-id", "");
this.useEnvironment = config.getBoolean("general.use-environment");
this.environmentServerIdKey = config.getString("general.environment-server-id");
this.storeLink = config.getString("general.store-link");
}

public String getServerDisplayName() {
Expand All @@ -39,4 +44,12 @@ public String getServerId() {
public boolean isEnvironmentEnabled() {
return useEnvironment && Environment.get() != null;
}

public RanksConfig getRanksConfig() {
return ranks;
}

public String getStoreLink() {
return storeLink;
}
}
4 changes: 4 additions & 0 deletions src/main/java/dev/pgm/community/CommunityPermissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public interface CommunityPermissions {

String VIEW_MAP_COOLDOWNS = ROOT + ".view-map-cooldown";

// Super Votes
String SUPER_VOTE = REQUEST + ".super-vote";
String SUPER_VOTE_BALANCE = SUPER_VOTE + ".balance";

// Translations
String TRANSLATE = ROOT + ".translate"; // Access to /translate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
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;
import dev.pgm.community.requests.commands.sponsor.SponsorCommands;
import dev.pgm.community.requests.commands.sponsor.TokenCommands;
import dev.pgm.community.requests.commands.supervotes.SuperVoteAdminCommands;
import dev.pgm.community.requests.commands.supervotes.SuperVoteCommand;
import dev.pgm.community.teleports.TeleportCommand;
import dev.pgm.community.users.commands.UserInfoCommands;
import dev.pgm.community.utils.CommandAudience;
Expand Down Expand Up @@ -138,6 +140,8 @@ protected void registerCommands() {
register(new RequestCommands());
register(new SponsorCommands());
register(new TokenCommands());
register(new SuperVoteCommand());
register(new SuperVoteAdminCommands());

// Teleport
register(new TeleportCommand());
Expand All @@ -158,14 +162,11 @@ protected void registerCommands() {
register(new CommunityPluginCommand());

// Help command
manager.command(
manager
.commandBuilder("community")
.literal("help")
.optional("query", StringParser.greedyStringParser())
.handler(
context ->
minecraftHelp.queryCommands(
context.<String>optional("query").orElse(""), context.sender())));
manager.command(manager
.commandBuilder("community")
.literal("help")
.optional("query", StringParser.greedyStringParser())
.handler(context -> minecraftHelp.queryCommands(
context.<String>optional("query").orElse(""), context.sender())));
}
}
29 changes: 26 additions & 3 deletions src/main/java/dev/pgm/community/requests/RequestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ public class RequestConfig extends FeatureConfigImpl {
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 static final String SUPER_VOTE = KEY + ".super-votes";
private static final String SUPER_VOTE_ENABLED = SUPER_VOTE + ".enabled";
private static final String SUPER_VOTE_MULTIPLIER = SUPER_VOTE + ".multiplier";
private static final String SUPER_VOTE_BROADCAST = SUPER_VOTE + ".broadcast";

private Duration cooldown; // Cooldown for using /request
private Duration sponsorCooldown; // Default cooldown for sponsor requests

private boolean sponsors; // If sponsor is enabled
private boolean sponsorEnabled; // If sponsor is enabled
private boolean superVoteEnabled; // If super votes are enabled

private int dailyTokens; // Amount of tokens given on a daily basis
private int weeklyTokens; // Amount of tokens given on a weekly basis
Expand All @@ -45,6 +50,9 @@ public class RequestConfig extends FeatureConfigImpl {
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

private int superVoteMultiplier; // The value a super vote should add
private boolean superVoteBroadcast; // If super vote activation should be broadcasted

public RequestConfig(Configuration config) {
super(KEY, config);
}
Expand All @@ -54,7 +62,7 @@ public Duration getCooldown() {
}

public boolean isSponsorEnabled() {
return sponsors;
return sponsorEnabled;
}

public Duration getSponsorCooldown(Player player) {
Expand Down Expand Up @@ -105,11 +113,23 @@ public int getUpperLimitOffset() {
return upperLimitOffset;
}

public boolean isSuperVoteEnabled() {
return superVoteEnabled;
}

public int getSuperVoteMultiplier() {
return superVoteMultiplier;
}

public boolean isSuperVoteBroadcast() {
return superVoteBroadcast;
}

@Override
public void reload(Configuration config) {
super.reload(config);
this.cooldown = parseDuration(config.getString(COOLDOWN, "15s"));
this.sponsors = config.getBoolean(SPONSORS_ENABLED);
this.sponsorEnabled = config.getBoolean(SPONSORS_ENABLED);
this.sponsorCooldown = parseDuration(config.getString(SPONSORS_COOLDOWN, "1h"));
this.dailyTokens = config.getInt(DAILY_TOKENS);
this.weeklyTokens = config.getInt(WEEKLY_TOKENS);
Expand All @@ -119,5 +139,8 @@ public void reload(Configuration config) {
this.mapCooldownMultiply = config.getInt(MAP_COOLDOWN_MULTIPLY);
this.lowerLimitOffset = config.getInt(LOWER_LIMIT_OFFSET);
this.upperLimitOffset = config.getInt(UPPER_LIMIT_OFFSET);
this.superVoteEnabled = config.getBoolean(SUPER_VOTE_ENABLED);
this.superVoteMultiplier = config.getInt(SUPER_VOTE_MULTIPLIER);
this.superVoteBroadcast = config.getBoolean(SUPER_VOTE_BROADCAST);
}
}
41 changes: 34 additions & 7 deletions src/main/java/dev/pgm/community/requests/RequestProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ public class RequestProfile {
private int sponsorTokens;
private Instant lastTokenRefreshTime;

private int superVotes;
private Instant lastSuperVote;

public RequestProfile(UUID playerId) {
this(playerId, null, null, null, null, 0, null);
this(playerId, null, null, null, null, 0, null, 0, null);
}

public RequestProfile(
Expand All @@ -28,21 +31,30 @@ public RequestProfile(
Instant lastSponsorTime,
String lastSponsorMap,
int sponsorTokens,
Instant lastTokenRefreshTime) {
Instant lastTokenRefreshTime,
int superVotes,
Instant lastSuperVote) {
this.playerId = playerId;
this.lastRequestTime = lastRequestTime;
this.lastRequestMap = lastRequestMap;
this.lastSponsorTime = lastSponsorTime;
this.lastSponsorMap = lastSponsorMap;
this.sponsorTokens = sponsorTokens;
this.lastTokenRefreshTime = lastTokenRefreshTime;
this.superVotes = superVotes;
this.lastSuperVote = lastSuperVote;
}

public int award(int amount) {
public int giveSponsorToken(int amount) {
this.sponsorTokens = Math.max(0, sponsorTokens + amount);
return sponsorTokens;
}

public int giveSuperVotes(int amount) {
this.superVotes = Math.max(0, superVotes + amount);
return superVotes;
}

public void request(MapInfo map) {
this.lastRequestMap = map.getId();
this.lastRequestTime = Instant.now();
Expand All @@ -51,7 +63,12 @@ public void request(MapInfo map) {
public void sponsor(MapInfo map) {
this.lastSponsorMap = map.getId();
this.lastSponsorTime = Instant.now();
award(-1);
giveSponsorToken(-1);
}

public void superVote() {
this.lastSuperVote = Instant.now();
giveSuperVotes(-1);
}

public Instant getLastRequestTime() {
Expand All @@ -74,12 +91,20 @@ public int getSponsorTokens() {
return sponsorTokens;
}

public int getSuperVotes() {
return superVotes;
}

public Instant getLastSuperVote() {
return lastSuperVote;
}

public Instant getLastTokenRefreshTime() {
return lastTokenRefreshTime;
}

public void refreshTokens(int amount) {
award(amount);
giveSponsorToken(amount);
this.lastTokenRefreshTime = Instant.now();
}

Expand All @@ -100,13 +125,15 @@ public boolean hasDayElapsed() {
@Override
public String toString() {
return String.format(
"RequestProfile{id = %d, tokens = %d, requestMap = %s, sponsorMap = %s, lastRequest = %s, lastSponsor = %s, lastRefresh = %s}",
"RequestProfile{id = %d, tokens = %d, requestMap = %s, sponsorMap = %s, lastRequest = %s, lastSponsor = %s, lastRefresh = %s, superVotes = %s, lastSuperVote = %s}",
getPlayerId().toString(),
getSponsorTokens(),
getLastRequestMap(),
getLastSponsorMap(),
getLastRequestTime().toString(),
getLastSponsorTime().toString(),
getLastTokenRefreshTime().toString());
getLastTokenRefreshTime().toString(),
getSuperVotes(),
getLastSuperVote().toString());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.pgm.community.requests.commands;
package dev.pgm.community.requests.commands.sponsor;

import static net.kyori.adventure.text.Component.empty;
import static net.kyori.adventure.text.Component.text;
Expand All @@ -12,7 +12,7 @@
import dev.pgm.community.requests.RequestConfig;
import dev.pgm.community.requests.RequestProfile;
import dev.pgm.community.requests.SponsorRequest;
import dev.pgm.community.requests.commands.TokenCommands.TokenRefreshAmount;
import dev.pgm.community.requests.commands.sponsor.TokenCommands.TokenRefreshAmount;
import dev.pgm.community.requests.feature.RequestFeature;
import dev.pgm.community.utils.BroadcastUtils;
import dev.pgm.community.utils.CommandAudience;
Expand Down
Loading

0 comments on commit c8a699e

Please sign in to comment.