Made the vote clickable
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
package com.bitnix.dirtsleep;
|
package com.bitnix.dirtsleep;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@@ -9,14 +12,14 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
||||||
|
|
||||||
private final Map<String, Set<UUID>> dayVotes = new HashMap<>();
|
private final Map<String, ActiveVote> activeVotes = new HashMap<>();
|
||||||
private final Map<String, Set<UUID>> nightVotes = new HashMap<>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -34,8 +37,12 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
dayVotes.clear();
|
for (ActiveVote vote : activeVotes.values()) {
|
||||||
nightVotes.clear();
|
if (vote.timeoutTask != null) {
|
||||||
|
vote.timeoutTask.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
activeVotes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -46,7 +53,12 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleVoteDay(player);
|
if (args.length == 1 && (args[0].equalsIgnoreCase("yes") || args[0].equalsIgnoreCase("no"))) {
|
||||||
|
handleResponseVote(player, VoteType.DAY, args[0].equalsIgnoreCase("yes"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
startVote(player, VoteType.DAY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +68,12 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleVoteNight(player);
|
if (args.length == 1 && (args[0].equalsIgnoreCase("yes") || args[0].equalsIgnoreCase("no"))) {
|
||||||
|
handleResponseVote(player, VoteType.NIGHT, args[0].equalsIgnoreCase("yes"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
startVote(player, VoteType.NIGHT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,8 +85,14 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
dayVotes.clear();
|
|
||||||
nightVotes.clear();
|
for (ActiveVote vote : activeVotes.values()) {
|
||||||
|
if (vote.timeoutTask != null) {
|
||||||
|
vote.timeoutTask.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
activeVotes.clear();
|
||||||
|
|
||||||
sender.sendMessage(message("messages.reloaded"));
|
sender.sendMessage(message("messages.reloaded"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -81,164 +104,184 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleVoteDay(Player player) {
|
private void startVote(Player starter, VoteType type) {
|
||||||
if (!getConfig().getBoolean("vote-day.enabled", true)) {
|
if (!getConfig().getBoolean("vote-" + type.configName + ".enabled", true)) {
|
||||||
player.sendMessage(message("messages.disabled"));
|
starter.sendMessage(message(type == VoteType.DAY ? "messages.disabled" : "messages.night-disabled"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
World world = player.getWorld();
|
World world = starter.getWorld();
|
||||||
|
|
||||||
if (!isWorldEnabled(world)) {
|
if (!isWorldEnabled(world)) {
|
||||||
player.sendMessage(message("messages.world-disabled"));
|
starter.sendMessage(message("messages.world-disabled"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canVoteDayInWorld(world)) {
|
if (!canStartVote(world, type)) {
|
||||||
player.sendMessage(message("messages.not-night"));
|
starter.sendMessage(message(type == VoteType.DAY ? "messages.not-night" : "messages.not-day"));
|
||||||
clearDayVotes(world);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String worldKey = world.getName().toLowerCase(Locale.ROOT);
|
String worldKey = world.getName().toLowerCase(Locale.ROOT);
|
||||||
Set<UUID> votes = dayVotes.computeIfAbsent(worldKey, k -> new HashSet<>());
|
if (activeVotes.containsKey(worldKey)) {
|
||||||
|
starter.sendMessage(message("messages.vote-already-running"));
|
||||||
if (votes.contains(player.getUniqueId())) {
|
|
||||||
player.sendMessage(message("messages.already-voted"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
votes.add(player.getUniqueId());
|
int requiredYesVotes = getRequiredVotes(world, type);
|
||||||
|
long durationSeconds = Math.max(5, getConfig().getLong("vote-session.duration-seconds", 30));
|
||||||
|
|
||||||
int currentVotes = countValidVotes(world, votes);
|
ActiveVote activeVote = new ActiveVote(type, requiredYesVotes);
|
||||||
int requiredVotes = getRequiredVotes(world);
|
activeVote.yesVotes.add(starter.getUniqueId());
|
||||||
|
|
||||||
String voteMessage = message("messages.vote-added")
|
BukkitTask task = Bukkit.getScheduler().runTaskLater(this, () -> timeoutVote(world), durationSeconds * 20L);
|
||||||
.replace("%player%", player.getName())
|
activeVote.timeoutTask = task;
|
||||||
.replace("%votes%", String.valueOf(currentVotes))
|
|
||||||
.replace("%required%", String.valueOf(requiredVotes))
|
|
||||||
.replace("%remaining%", String.valueOf(Math.max(0, requiredVotes - currentVotes)));
|
|
||||||
|
|
||||||
broadcast(world, voteMessage);
|
activeVotes.put(worldKey, activeVote);
|
||||||
|
|
||||||
if (currentVotes >= requiredVotes) {
|
String startedMessage = message(type == VoteType.DAY ? "messages.vote-started-day" : "messages.vote-started-night")
|
||||||
makeDay(world);
|
.replace("%player%", starter.getName())
|
||||||
clearDayVotes(world);
|
.replace("%yes%", String.valueOf(activeVote.yesVotes.size()))
|
||||||
clearNightVotes(world);
|
.replace("%no%", String.valueOf(activeVote.noVotes.size()))
|
||||||
broadcast(world, message("messages.vote-passed"));
|
.replace("%required%", String.valueOf(requiredYesVotes));
|
||||||
|
|
||||||
|
String clickPrompt = message("messages.click-prompt");
|
||||||
|
|
||||||
|
for (Player player : world.getPlayers()) {
|
||||||
|
player.sendMessage(startedMessage);
|
||||||
|
player.sendMessage(clickPrompt);
|
||||||
|
sendClickableVoteMessage(player, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkVoteResult(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleVoteNight(Player player) {
|
private void handleResponseVote(Player player, VoteType commandType, boolean yes) {
|
||||||
if (!getConfig().getBoolean("vote-night.enabled", true)) {
|
|
||||||
player.sendMessage(message("messages.night-disabled"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
World world = player.getWorld();
|
World world = player.getWorld();
|
||||||
|
|
||||||
if (!isWorldEnabled(world)) {
|
|
||||||
player.sendMessage(message("messages.world-disabled"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!canVoteNightInWorld(world)) {
|
|
||||||
player.sendMessage(message("messages.not-day"));
|
|
||||||
clearNightVotes(world);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String worldKey = world.getName().toLowerCase(Locale.ROOT);
|
String worldKey = world.getName().toLowerCase(Locale.ROOT);
|
||||||
Set<UUID> votes = nightVotes.computeIfAbsent(worldKey, k -> new HashSet<>());
|
ActiveVote activeVote = activeVotes.get(worldKey);
|
||||||
|
|
||||||
if (votes.contains(player.getUniqueId())) {
|
if (activeVote == null) {
|
||||||
player.sendMessage(message("messages.night-already-voted"));
|
player.sendMessage(message("messages.no-active-vote"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
votes.add(player.getUniqueId());
|
if (activeVote.type != commandType) {
|
||||||
|
player.sendMessage(message("messages.wrong-vote-command"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int currentVotes = countValidVotes(world, votes);
|
activeVote.yesVotes.remove(player.getUniqueId());
|
||||||
int requiredVotes = getRequiredVotes(world);
|
activeVote.noVotes.remove(player.getUniqueId());
|
||||||
|
|
||||||
String voteMessage = message("messages.night-vote-added")
|
if (yes) {
|
||||||
.replace("%player%", player.getName())
|
activeVote.yesVotes.add(player.getUniqueId());
|
||||||
.replace("%votes%", String.valueOf(currentVotes))
|
player.sendMessage(message("messages.vote-yes-confirm"));
|
||||||
.replace("%required%", String.valueOf(requiredVotes))
|
} else {
|
||||||
.replace("%remaining%", String.valueOf(Math.max(0, requiredVotes - currentVotes)));
|
activeVote.noVotes.add(player.getUniqueId());
|
||||||
|
player.sendMessage(message("messages.vote-no-confirm"));
|
||||||
|
}
|
||||||
|
|
||||||
broadcast(world, voteMessage);
|
broadcastVoteStatus(world, activeVote);
|
||||||
|
checkVoteResult(world);
|
||||||
|
}
|
||||||
|
|
||||||
if (currentVotes >= requiredVotes) {
|
private void broadcastVoteStatus(World world, ActiveVote activeVote) {
|
||||||
makeNight(world);
|
cleanupInvalidVotes(world, activeVote);
|
||||||
clearNightVotes(world);
|
|
||||||
clearDayVotes(world);
|
String path = activeVote.type == VoteType.DAY ? "messages.vote-progress-day" : "messages.vote-progress-night";
|
||||||
broadcast(world, message("messages.night-vote-passed"));
|
String msg = message(path)
|
||||||
|
.replace("%yes%", String.valueOf(activeVote.yesVotes.size()))
|
||||||
|
.replace("%no%", String.valueOf(activeVote.noVotes.size()))
|
||||||
|
.replace("%required%", String.valueOf(activeVote.requiredYesVotes));
|
||||||
|
|
||||||
|
broadcast(world, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkVoteResult(World world) {
|
||||||
|
String worldKey = world.getName().toLowerCase(Locale.ROOT);
|
||||||
|
ActiveVote activeVote = activeVotes.get(worldKey);
|
||||||
|
if (activeVote == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanupInvalidVotes(world, activeVote);
|
||||||
|
|
||||||
|
int yesVotes = activeVote.yesVotes.size();
|
||||||
|
int noVotes = activeVote.noVotes.size();
|
||||||
|
int requiredYes = activeVote.requiredYesVotes;
|
||||||
|
int eligible = getEligiblePlayers(world, activeVote.type);
|
||||||
|
|
||||||
|
if (yesVotes >= requiredYes) {
|
||||||
|
if (activeVote.type == VoteType.DAY) {
|
||||||
|
makeDay(world);
|
||||||
|
broadcast(world, message("messages.vote-passed"));
|
||||||
|
} else {
|
||||||
|
makeNight(world);
|
||||||
|
broadcast(world, message("messages.night-vote-passed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
endVote(world);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int remainingPossibleYes = Math.max(0, eligible - noVotes);
|
||||||
|
if (remainingPossibleYes < requiredYes) {
|
||||||
|
broadcast(world, message("messages.vote-failed"));
|
||||||
|
endVote(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeDay(World world) {
|
private void timeoutVote(World world) {
|
||||||
world.setTime(1000);
|
String worldKey = world.getName().toLowerCase(Locale.ROOT);
|
||||||
world.setStorm(false);
|
ActiveVote activeVote = activeVotes.get(worldKey);
|
||||||
world.setThundering(false);
|
if (activeVote == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanupInvalidVotes(world, activeVote);
|
||||||
|
|
||||||
|
if (activeVote.type == VoteType.DAY) {
|
||||||
|
broadcast(world, message("messages.vote-expired"));
|
||||||
|
} else {
|
||||||
|
broadcast(world, message("messages.night-vote-expired"));
|
||||||
|
}
|
||||||
|
|
||||||
|
endVote(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeNight(World world) {
|
private void endVote(World world) {
|
||||||
world.setTime(13000);
|
String worldKey = world.getName().toLowerCase(Locale.ROOT);
|
||||||
|
ActiveVote activeVote = activeVotes.remove(worldKey);
|
||||||
|
if (activeVote != null && activeVote.timeoutTask != null) {
|
||||||
|
activeVote.timeoutTask.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearDayVotes(World world) {
|
private void cleanupInvalidVotes(World world, ActiveVote activeVote) {
|
||||||
dayVotes.remove(world.getName().toLowerCase(Locale.ROOT));
|
activeVote.yesVotes.removeIf(uuid -> !isEligibleVoter(world, uuid, activeVote.type));
|
||||||
|
activeVote.noVotes.removeIf(uuid -> !isEligibleVoter(world, uuid, activeVote.type));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearNightVotes(World world) {
|
private boolean isEligibleVoter(World world, UUID uuid, VoteType type) {
|
||||||
nightVotes.remove(world.getName().toLowerCase(Locale.ROOT));
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
}
|
if (player == null || !player.isOnline()) {
|
||||||
|
return false;
|
||||||
private int countValidVotes(World world, Set<UUID> votes) {
|
}
|
||||||
votes.removeIf(uuid -> {
|
if (!player.getWorld().equals(world)) {
|
||||||
Player p = Bukkit.getPlayer(uuid);
|
return false;
|
||||||
return p == null || !p.isOnline() || !p.getWorld().equals(world);
|
}
|
||||||
});
|
if (player.getGameMode() == GameMode.SPECTATOR) {
|
||||||
return votes.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isWorldEnabled(World world) {
|
|
||||||
List<String> worlds = getConfig().getStringList("vote-day.worlds");
|
|
||||||
return worlds.isEmpty() || worlds.contains(world.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean canVoteDayInWorld(World world) {
|
|
||||||
if (world.getEnvironment() != World.Environment.NORMAL) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!getConfig().getBoolean("vote-day.only-during-night", true)) {
|
boolean excludeBypass = getConfig().getBoolean("vote-" + type.configName + ".exclude-bypass", true);
|
||||||
return true;
|
return !excludeBypass || !player.hasPermission("dirtsleep.bypass");
|
||||||
}
|
|
||||||
|
|
||||||
long time = world.getTime();
|
|
||||||
int nightStartsAt = getConfig().getInt("vote-day.night-starts-at", 12542);
|
|
||||||
return time >= nightStartsAt && time < 24000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canVoteNightInWorld(World world) {
|
private int getEligiblePlayers(World world, VoteType type) {
|
||||||
if (world.getEnvironment() != World.Environment.NORMAL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!getConfig().getBoolean("vote-night.only-during-day", true)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
long time = world.getTime();
|
|
||||||
int dayEndsAt = getConfig().getInt("vote-night.day-ends-at", 12542);
|
|
||||||
return time >= 0 && time < dayEndsAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getRequiredVotes(World world) {
|
|
||||||
int eligible = 0;
|
int eligible = 0;
|
||||||
boolean excludeBypass = getConfig().getBoolean("vote-day.exclude-bypass", true);
|
boolean excludeBypass = getConfig().getBoolean("vote-" + type.configName + ".exclude-bypass", true);
|
||||||
|
|
||||||
for (Player player : world.getPlayers()) {
|
for (Player player : world.getPlayers()) {
|
||||||
if (player.getGameMode() == GameMode.SPECTATOR) {
|
if (player.getGameMode() == GameMode.SPECTATOR) {
|
||||||
@@ -252,11 +295,40 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
eligible++;
|
eligible++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eligible <= 0) {
|
return Math.max(1, eligible);
|
||||||
return 1;
|
}
|
||||||
|
|
||||||
|
private boolean isWorldEnabled(World world) {
|
||||||
|
List<String> worlds = getConfig().getStringList("vote-day.worlds");
|
||||||
|
return worlds.isEmpty() || worlds.contains(world.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canStartVote(World world, VoteType type) {
|
||||||
|
if (world.getEnvironment() != World.Environment.NORMAL) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String raw = getConfig().getString("vote-day.required-votes", "50%");
|
long time = world.getTime();
|
||||||
|
|
||||||
|
if (type == VoteType.DAY) {
|
||||||
|
if (!getConfig().getBoolean("vote-day.only-during-night", true)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int nightStartsAt = getConfig().getInt("vote-day.night-starts-at", 12542);
|
||||||
|
return time >= nightStartsAt && time < 24000;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!getConfig().getBoolean("vote-night.only-during-day", true)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int dayEndsAt = getConfig().getInt("vote-night.day-ends-at", 12542);
|
||||||
|
return time >= 0 && time < dayEndsAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getRequiredVotes(World world, VoteType type) {
|
||||||
|
int eligible = getEligiblePlayers(world, type);
|
||||||
|
|
||||||
|
String raw = getConfig().getString("vote-" + type.configName + ".required-votes", "50%");
|
||||||
if (raw == null) {
|
if (raw == null) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -281,6 +353,29 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void makeDay(World world) {
|
||||||
|
world.setTime(1000);
|
||||||
|
world.setStorm(false);
|
||||||
|
world.setThundering(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void makeNight(World world) {
|
||||||
|
world.setTime(13000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendClickableVoteMessage(Player player, VoteType type) {
|
||||||
|
String yesCommand = type == VoteType.DAY ? "/voteday yes" : "/votenight yes";
|
||||||
|
String noCommand = type == VoteType.DAY ? "/voteday no" : "/votenight no";
|
||||||
|
|
||||||
|
Component yes = Component.text("[YES]", NamedTextColor.GREEN)
|
||||||
|
.clickEvent(ClickEvent.runCommand(yesCommand));
|
||||||
|
Component spacer = Component.text(" ", NamedTextColor.GRAY);
|
||||||
|
Component no = Component.text("[NO]", NamedTextColor.RED)
|
||||||
|
.clickEvent(ClickEvent.runCommand(noCommand));
|
||||||
|
|
||||||
|
player.sendMessage(yes.append(spacer).append(no));
|
||||||
|
}
|
||||||
|
|
||||||
private void broadcast(World world, String message) {
|
private void broadcast(World world, String message) {
|
||||||
for (Player player : world.getPlayers()) {
|
for (Player player : world.getPlayers()) {
|
||||||
player.sendMessage(message);
|
player.sendMessage(message);
|
||||||
@@ -307,6 +402,38 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (command.getName().equalsIgnoreCase("voteday") || command.getName().equalsIgnoreCase("votenight")) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
return Arrays.asList("yes", "no").stream()
|
||||||
|
.filter(s -> s.toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum VoteType {
|
||||||
|
DAY("day"),
|
||||||
|
NIGHT("night");
|
||||||
|
|
||||||
|
private final String configName;
|
||||||
|
|
||||||
|
VoteType(String configName) {
|
||||||
|
this.configName = configName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class ActiveVote {
|
||||||
|
private final VoteType type;
|
||||||
|
private final int requiredYesVotes;
|
||||||
|
private final Set<UUID> yesVotes = new HashSet<>();
|
||||||
|
private final Set<UUID> noVotes = new HashSet<>();
|
||||||
|
private BukkitTask timeoutTask;
|
||||||
|
|
||||||
|
private ActiveVote(VoteType type, int requiredYesVotes) {
|
||||||
|
this.type = type;
|
||||||
|
this.requiredYesVotes = requiredYesVotes;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ vote-day:
|
|||||||
# Tick time where night starts
|
# Tick time where night starts
|
||||||
night-starts-at: 12542
|
night-starts-at: 12542
|
||||||
|
|
||||||
# Required votes before changing to day
|
# Required YES votes before changing to day
|
||||||
# Examples: "1", "2", "50%", "75%"
|
# Examples: "1", "2", "50%", "75%"
|
||||||
required-votes: "50%"
|
required-votes: "50%"
|
||||||
|
|
||||||
@@ -28,19 +28,50 @@ vote-night:
|
|||||||
# Tick time where day effectively ends for vote checks
|
# Tick time where day effectively ends for vote checks
|
||||||
day-ends-at: 12542
|
day-ends-at: 12542
|
||||||
|
|
||||||
|
# Required YES votes before changing to night
|
||||||
|
# Examples: "1", "2", "50%", "75%"
|
||||||
|
required-votes: "50%"
|
||||||
|
|
||||||
|
# Ignore players with this permission from vote requirement:
|
||||||
|
# dirtsleep.bypass
|
||||||
|
exclude-bypass: true
|
||||||
|
|
||||||
|
vote-session:
|
||||||
|
# How long a vote stays open
|
||||||
|
duration-seconds: 30
|
||||||
|
|
||||||
messages:
|
messages:
|
||||||
prefix: "&8[&6DirtBagMC&8] &7"
|
prefix: "&8[&6DirtBagMC&8] &7"
|
||||||
|
|
||||||
vote-added: "%prefix%&e%player% &7voted for day. &f(%votes%/%required% votes, %remaining% remaining)"
|
vote-started-day: "%prefix%&e%player% &7started a vote to make it &fday&7. &aYES: &f%yes%&7/&f%required% &8| &cNO: &f%no%"
|
||||||
vote-passed: "%prefix%&aVote passed! Skipping to day."
|
vote-started-night: "%prefix%&e%player% &7started a vote to make it &fnight&7. &aYES: &f%yes%&7/&f%required% &8| &cNO: &f%no%"
|
||||||
already-voted: "%prefix%&cYou already voted."
|
|
||||||
not-night: "%prefix%&cYou can only use this at night."
|
|
||||||
disabled: "%prefix%&cVote day is disabled."
|
|
||||||
|
|
||||||
night-vote-added: "%prefix%&e%player% &7voted for night. &f(%votes%/%required% votes, %remaining% remaining)"
|
click-prompt: "%prefix%&7Click below to vote."
|
||||||
|
|
||||||
|
vote-progress-day: "%prefix%&7Day vote status: &aYES: &f%yes%&7/&f%required% &8| &cNO: &f%no%"
|
||||||
|
vote-progress-night: "%prefix%&7Night vote status: &aYES: &f%yes%&7/&f%required% &8| &cNO: &f%no%"
|
||||||
|
|
||||||
|
vote-passed: "%prefix%&aVote passed! Skipping to day."
|
||||||
night-vote-passed: "%prefix%&aVote passed! Skipping to night."
|
night-vote-passed: "%prefix%&aVote passed! Skipping to night."
|
||||||
|
|
||||||
|
vote-failed: "%prefix%&cVote failed."
|
||||||
|
vote-expired: "%prefix%&cVote to make it day expired."
|
||||||
|
night-vote-expired: "%prefix%&cVote to make it night expired."
|
||||||
|
|
||||||
|
vote-yes-confirm: "%prefix%&aYou voted YES."
|
||||||
|
vote-no-confirm: "%prefix%&cYou voted NO."
|
||||||
|
|
||||||
|
vote-already-running: "%prefix%&cA vote is already running in this world."
|
||||||
|
no-active-vote: "%prefix%&cThere is no active vote in this world."
|
||||||
|
wrong-vote-command: "%prefix%&cUse the correct vote buttons for the current vote."
|
||||||
|
|
||||||
|
already-voted: "%prefix%&cYou already voted."
|
||||||
night-already-voted: "%prefix%&cYou already voted for night."
|
night-already-voted: "%prefix%&cYou already voted for night."
|
||||||
not-day: "%prefix%&cYou can only use this during the day."
|
|
||||||
|
not-night: "%prefix%&cYou can only start this vote at night."
|
||||||
|
not-day: "%prefix%&cYou can only start this vote during the day."
|
||||||
|
|
||||||
|
disabled: "%prefix%&cVote day is disabled."
|
||||||
night-disabled: "%prefix%&cVote night is disabled."
|
night-disabled: "%prefix%&cVote night is disabled."
|
||||||
|
|
||||||
world-disabled: "%prefix%&cVote commands are disabled in this world."
|
world-disabled: "%prefix%&cVote commands are disabled in this world."
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ version: 1.0
|
|||||||
main: com.bitnix.dirtsleep.DirtSleepPlugin
|
main: com.bitnix.dirtsleep.DirtSleepPlugin
|
||||||
api-version: '1.21'
|
api-version: '1.21'
|
||||||
author: bitnix
|
author: bitnix
|
||||||
description: Simple vote day plugin
|
description: Simple vote day/night plugin
|
||||||
commands:
|
commands:
|
||||||
voteday:
|
voteday:
|
||||||
description: Vote to make it day
|
description: Start a vote to make it day
|
||||||
usage: /voteday
|
usage: /voteday
|
||||||
votenight:
|
votenight:
|
||||||
description: Vote to make it night
|
description: Start a vote to make it night
|
||||||
usage: /votenight
|
usage: /votenight
|
||||||
dirtsleep:
|
dirtsleep:
|
||||||
description: DirtSleep admin command
|
description: DirtSleep admin command
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -11,7 +11,7 @@ vote-day:
|
|||||||
# Tick time where night starts
|
# Tick time where night starts
|
||||||
night-starts-at: 12542
|
night-starts-at: 12542
|
||||||
|
|
||||||
# Required votes before changing to day
|
# Required YES votes before changing to day
|
||||||
# Examples: "1", "2", "50%", "75%"
|
# Examples: "1", "2", "50%", "75%"
|
||||||
required-votes: "50%"
|
required-votes: "50%"
|
||||||
|
|
||||||
@@ -28,19 +28,50 @@ vote-night:
|
|||||||
# Tick time where day effectively ends for vote checks
|
# Tick time where day effectively ends for vote checks
|
||||||
day-ends-at: 12542
|
day-ends-at: 12542
|
||||||
|
|
||||||
|
# Required YES votes before changing to night
|
||||||
|
# Examples: "1", "2", "50%", "75%"
|
||||||
|
required-votes: "50%"
|
||||||
|
|
||||||
|
# Ignore players with this permission from vote requirement:
|
||||||
|
# dirtsleep.bypass
|
||||||
|
exclude-bypass: true
|
||||||
|
|
||||||
|
vote-session:
|
||||||
|
# How long a vote stays open
|
||||||
|
duration-seconds: 30
|
||||||
|
|
||||||
messages:
|
messages:
|
||||||
prefix: "&8[&6DirtBagMC&8] &7"
|
prefix: "&8[&6DirtBagMC&8] &7"
|
||||||
|
|
||||||
vote-added: "%prefix%&e%player% &7voted for day. &f(%votes%/%required% votes, %remaining% remaining)"
|
vote-started-day: "%prefix%&e%player% &7started a vote to make it &fday&7. &aYES: &f%yes%&7/&f%required% &8| &cNO: &f%no%"
|
||||||
vote-passed: "%prefix%&aVote passed! Skipping to day."
|
vote-started-night: "%prefix%&e%player% &7started a vote to make it &fnight&7. &aYES: &f%yes%&7/&f%required% &8| &cNO: &f%no%"
|
||||||
already-voted: "%prefix%&cYou already voted."
|
|
||||||
not-night: "%prefix%&cYou can only use this at night."
|
|
||||||
disabled: "%prefix%&cVote day is disabled."
|
|
||||||
|
|
||||||
night-vote-added: "%prefix%&e%player% &7voted for night. &f(%votes%/%required% votes, %remaining% remaining)"
|
click-prompt: "%prefix%&7Click below to vote."
|
||||||
|
|
||||||
|
vote-progress-day: "%prefix%&7Day vote status: &aYES: &f%yes%&7/&f%required% &8| &cNO: &f%no%"
|
||||||
|
vote-progress-night: "%prefix%&7Night vote status: &aYES: &f%yes%&7/&f%required% &8| &cNO: &f%no%"
|
||||||
|
|
||||||
|
vote-passed: "%prefix%&aVote passed! Skipping to day."
|
||||||
night-vote-passed: "%prefix%&aVote passed! Skipping to night."
|
night-vote-passed: "%prefix%&aVote passed! Skipping to night."
|
||||||
|
|
||||||
|
vote-failed: "%prefix%&cVote failed."
|
||||||
|
vote-expired: "%prefix%&cVote to make it day expired."
|
||||||
|
night-vote-expired: "%prefix%&cVote to make it night expired."
|
||||||
|
|
||||||
|
vote-yes-confirm: "%prefix%&aYou voted YES."
|
||||||
|
vote-no-confirm: "%prefix%&cYou voted NO."
|
||||||
|
|
||||||
|
vote-already-running: "%prefix%&cA vote is already running in this world."
|
||||||
|
no-active-vote: "%prefix%&cThere is no active vote in this world."
|
||||||
|
wrong-vote-command: "%prefix%&cUse the correct vote buttons for the current vote."
|
||||||
|
|
||||||
|
already-voted: "%prefix%&cYou already voted."
|
||||||
night-already-voted: "%prefix%&cYou already voted for night."
|
night-already-voted: "%prefix%&cYou already voted for night."
|
||||||
not-day: "%prefix%&cYou can only use this during the day."
|
|
||||||
|
not-night: "%prefix%&cYou can only start this vote at night."
|
||||||
|
not-day: "%prefix%&cYou can only start this vote during the day."
|
||||||
|
|
||||||
|
disabled: "%prefix%&cVote day is disabled."
|
||||||
night-disabled: "%prefix%&cVote night is disabled."
|
night-disabled: "%prefix%&cVote night is disabled."
|
||||||
|
|
||||||
world-disabled: "%prefix%&cVote commands are disabled in this world."
|
world-disabled: "%prefix%&cVote commands are disabled in this world."
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ version: 1.0
|
|||||||
main: com.bitnix.dirtsleep.DirtSleepPlugin
|
main: com.bitnix.dirtsleep.DirtSleepPlugin
|
||||||
api-version: '1.21'
|
api-version: '1.21'
|
||||||
author: bitnix
|
author: bitnix
|
||||||
description: Simple vote day plugin
|
description: Simple vote day/night plugin
|
||||||
commands:
|
commands:
|
||||||
voteday:
|
voteday:
|
||||||
description: Vote to make it day
|
description: Start a vote to make it day
|
||||||
usage: /voteday
|
usage: /voteday
|
||||||
votenight:
|
votenight:
|
||||||
description: Vote to make it night
|
description: Start a vote to make it night
|
||||||
usage: /votenight
|
usage: /votenight
|
||||||
dirtsleep:
|
dirtsleep:
|
||||||
description: DirtSleep admin command
|
description: DirtSleep admin command
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#Generated by Maven
|
#Generated by Maven
|
||||||
#Tue Jun 09 20:09:21 EDT 2026
|
#Tue Jun 09 20:37:04 EDT 2026
|
||||||
artifactId=DirtSleep
|
artifactId=DirtSleep
|
||||||
groupId=com.bitnix
|
groupId=com.bitnix
|
||||||
version=1.0-SNAPSHOT
|
version=1.0-SNAPSHOT
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
|
com/bitnix/dirtsleep/DirtSleepPlugin$VoteType.class
|
||||||
com/bitnix/dirtsleep/DirtSleepPlugin.class
|
com/bitnix/dirtsleep/DirtSleepPlugin.class
|
||||||
|
com/bitnix/dirtsleep/DirtSleepPlugin$ActiveVote.class
|
||||||
|
|||||||
Reference in New Issue
Block a user