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

Added the goal vote system #139

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -12,6 +12,7 @@
import io.minimum.minecraft.superbvote.votes.rewards.VoteReward;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -84,6 +85,51 @@ private void processVote(PlayerVotes pv, VoteStreak voteStreak, Vote vote, boole
Optional<Player> player = context.getPlayer().map(OfflinePlayer::getPlayer);
boolean hideBroadcast = player.isPresent() && player.get().hasPermission("superbvote.bypassbroadcast");

// Get the plugin config instance
FileConfiguration config = SuperbVote.getPlugin().getConfig();

// Get the current vote count
int votes = config.getInt("votes.globalVotes");

// Increment the vote count
votes++;

// Update the vote count in the config
config.set("votes.globalVotes", votes);

// Get the current vote goal
int goal = config.getInt("votes.voteGoal");

// Check if the vote goal has been reached
if (votes >= goal) {
// Broadcast the goal reached message
for (String text : config.getStringList("votes.goalText")) {
Bukkit.broadcastMessage(text);
}

// Double the vote goal
goal *= config.getInt("votes.multiply");
// Update the goal in the config
config.set("votes.voteGoal", goal);

// Reset the vote count
config.set("votes.globalVotes", 0);

// Execute the commands in the config
for (String command : config.getStringList("votes.commandGoal")) {
Bukkit.getScheduler().runTaskAsynchronously(SuperbVote.getPlugin(), () -> Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command));
}
} else {
// Broadcast the vote message
for (String text : config.getStringList("votes.voteText")) {
text = text.replace("%votes%", String.valueOf(votes)).replace("%goal%", String.valueOf(goal));
Bukkit.broadcastMessage(text);
}
}

// Save the config
SuperbVote.getPlugin().saveConfig();

if (bestRewards.isEmpty()) {
throw new RuntimeException("No vote rewards found for '" + vote + "'");
}
Expand Down Expand Up @@ -141,7 +187,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
if (!votes.isEmpty()) {
for (Vote vote : votes) {
processVote(pv, voteStreak, vote, false, false, true);
pv = new PlayerVotes(pv.getUuid(), event.getPlayer().getName(),pv.getVotes() + 1, PlayerVotes.Type.CURRENT);
pv = new PlayerVotes(pv.getUuid(), event.getPlayer().getName(), pv.getVotes() + 1, PlayerVotes.Type.CURRENT);
}
afterVoteProcessing();
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# https://github.com/minecrafter/SuperbVote/wiki

# Database configuration.

storage:
database: json
json:
Expand All @@ -19,6 +20,28 @@ storage:

# General vote configuration.
votes:
voteGoal: 100

globalVotes: 0

# When the goal is reached, this number will multiply the goal
# Set 1 to cancel the multiply goal
multiply: 2

goalText:
- "We hit the vote target"

# Placeholders:
# %votes% - Return the votes number
# %goal% - Return the atual goal

voteText: |-
We have %votes% and the mark is %goal%

# List the commands that will be executed when the votes goal is reached

commandGoal:
- say goal votes
# At least this many seconds must pass before allowing another vote (per-service). This will apply per service.
# Default: 3600 seconds (1 hour)
cooldown-per-service: 3600
Expand Down