Add /votenight support
This commit is contained in:
@@ -15,7 +15,8 @@ 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>> worldVotes = new HashMap<>();
|
private final Map<String, Set<UUID>> dayVotes = new HashMap<>();
|
||||||
|
private final Map<String, Set<UUID>> nightVotes = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -24,13 +25,17 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
Objects.requireNonNull(getCommand("voteday")).setExecutor(this);
|
Objects.requireNonNull(getCommand("voteday")).setExecutor(this);
|
||||||
Objects.requireNonNull(getCommand("voteday")).setTabCompleter(this);
|
Objects.requireNonNull(getCommand("voteday")).setTabCompleter(this);
|
||||||
|
|
||||||
|
Objects.requireNonNull(getCommand("votenight")).setExecutor(this);
|
||||||
|
Objects.requireNonNull(getCommand("votenight")).setTabCompleter(this);
|
||||||
|
|
||||||
Objects.requireNonNull(getCommand("dirtsleep")).setExecutor(this);
|
Objects.requireNonNull(getCommand("dirtsleep")).setExecutor(this);
|
||||||
Objects.requireNonNull(getCommand("dirtsleep")).setTabCompleter(this);
|
Objects.requireNonNull(getCommand("dirtsleep")).setTabCompleter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
worldVotes.clear();
|
dayVotes.clear();
|
||||||
|
nightVotes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -45,6 +50,16 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (command.getName().equalsIgnoreCase("votenight")) {
|
||||||
|
if (!(sender instanceof Player player)) {
|
||||||
|
sender.sendMessage(color("&cOnly players can use /votenight."));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleVoteNight(player);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (command.getName().equalsIgnoreCase("dirtsleep")) {
|
if (command.getName().equalsIgnoreCase("dirtsleep")) {
|
||||||
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
|
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
|
||||||
if (!sender.hasPermission("dirtsleep.admin")) {
|
if (!sender.hasPermission("dirtsleep.admin")) {
|
||||||
@@ -53,7 +68,8 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
worldVotes.clear();
|
dayVotes.clear();
|
||||||
|
nightVotes.clear();
|
||||||
sender.sendMessage(message("messages.reloaded"));
|
sender.sendMessage(message("messages.reloaded"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -78,14 +94,14 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canVoteInWorld(world)) {
|
if (!canVoteDayInWorld(world)) {
|
||||||
player.sendMessage(message("messages.not-night"));
|
player.sendMessage(message("messages.not-night"));
|
||||||
clearVotes(world);
|
clearDayVotes(world);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String worldKey = world.getName().toLowerCase(Locale.ROOT);
|
String worldKey = world.getName().toLowerCase(Locale.ROOT);
|
||||||
Set<UUID> votes = worldVotes.computeIfAbsent(worldKey, k -> new HashSet<>());
|
Set<UUID> votes = dayVotes.computeIfAbsent(worldKey, k -> new HashSet<>());
|
||||||
|
|
||||||
if (votes.contains(player.getUniqueId())) {
|
if (votes.contains(player.getUniqueId())) {
|
||||||
player.sendMessage(message("messages.already-voted"));
|
player.sendMessage(message("messages.already-voted"));
|
||||||
@@ -107,19 +123,76 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
|
|
||||||
if (currentVotes >= requiredVotes) {
|
if (currentVotes >= requiredVotes) {
|
||||||
makeDay(world);
|
makeDay(world);
|
||||||
clearVotes(world);
|
clearDayVotes(world);
|
||||||
|
clearNightVotes(world);
|
||||||
broadcast(world, message("messages.vote-passed"));
|
broadcast(world, message("messages.vote-passed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleVoteNight(Player player) {
|
||||||
|
if (!getConfig().getBoolean("vote-night.enabled", true)) {
|
||||||
|
player.sendMessage(message("messages.night-disabled"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
Set<UUID> votes = nightVotes.computeIfAbsent(worldKey, k -> new HashSet<>());
|
||||||
|
|
||||||
|
if (votes.contains(player.getUniqueId())) {
|
||||||
|
player.sendMessage(message("messages.night-already-voted"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
votes.add(player.getUniqueId());
|
||||||
|
|
||||||
|
int currentVotes = countValidVotes(world, votes);
|
||||||
|
int requiredVotes = getRequiredVotes(world);
|
||||||
|
|
||||||
|
String voteMessage = message("messages.night-vote-added")
|
||||||
|
.replace("%player%", player.getName())
|
||||||
|
.replace("%votes%", String.valueOf(currentVotes))
|
||||||
|
.replace("%required%", String.valueOf(requiredVotes))
|
||||||
|
.replace("%remaining%", String.valueOf(Math.max(0, requiredVotes - currentVotes)));
|
||||||
|
|
||||||
|
broadcast(world, voteMessage);
|
||||||
|
|
||||||
|
if (currentVotes >= requiredVotes) {
|
||||||
|
makeNight(world);
|
||||||
|
clearNightVotes(world);
|
||||||
|
clearDayVotes(world);
|
||||||
|
broadcast(world, message("messages.night-vote-passed"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void makeDay(World world) {
|
private void makeDay(World world) {
|
||||||
world.setTime(1000);
|
world.setTime(1000);
|
||||||
world.setStorm(false);
|
world.setStorm(false);
|
||||||
world.setThundering(false);
|
world.setThundering(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearVotes(World world) {
|
private void makeNight(World world) {
|
||||||
worldVotes.remove(world.getName().toLowerCase(Locale.ROOT));
|
world.setTime(13000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearDayVotes(World world) {
|
||||||
|
dayVotes.remove(world.getName().toLowerCase(Locale.ROOT));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearNightVotes(World world) {
|
||||||
|
nightVotes.remove(world.getName().toLowerCase(Locale.ROOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int countValidVotes(World world, Set<UUID> votes) {
|
private int countValidVotes(World world, Set<UUID> votes) {
|
||||||
@@ -135,7 +208,7 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
return worlds.isEmpty() || worlds.contains(world.getName());
|
return worlds.isEmpty() || worlds.contains(world.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canVoteInWorld(World world) {
|
private boolean canVoteDayInWorld(World world) {
|
||||||
if (world.getEnvironment() != World.Environment.NORMAL) {
|
if (world.getEnvironment() != World.Environment.NORMAL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -149,6 +222,20 @@ public final class DirtSleepPlugin extends JavaPlugin implements TabExecutor {
|
|||||||
return time >= nightStartsAt && time < 24000;
|
return time >= nightStartsAt && time < 24000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean canVoteNightInWorld(World world) {
|
||||||
|
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) {
|
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-day.exclude-bypass", true);
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
vote-day:
|
vote-day:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
# Empty list = all worlds
|
# Plugin will only work in these worlds
|
||||||
worlds: []
|
worlds:
|
||||||
|
- "world"
|
||||||
|
|
||||||
# Only allow /voteday during night
|
# Only allow /voteday during night
|
||||||
only-during-night: true
|
only-during-night: true
|
||||||
@@ -18,14 +19,31 @@ vote-day:
|
|||||||
# dirtsleep.bypass
|
# dirtsleep.bypass
|
||||||
exclude-bypass: true
|
exclude-bypass: true
|
||||||
|
|
||||||
|
vote-night:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
# Only allow /votenight during daytime
|
||||||
|
only-during-day: true
|
||||||
|
|
||||||
|
# Tick time where day effectively ends for vote checks
|
||||||
|
day-ends-at: 12542
|
||||||
|
|
||||||
messages:
|
messages:
|
||||||
prefix: "&8[&bDirtSleep&8] &7"
|
prefix: "&8[&6DirtBagMC&8] &7"
|
||||||
|
|
||||||
vote-added: "%prefix%&e%player% &7voted for day. &f(%votes%/%required% votes, %remaining% remaining)"
|
vote-added: "%prefix%&e%player% &7voted for day. &f(%votes%/%required% votes, %remaining% remaining)"
|
||||||
vote-passed: "%prefix%&aVote passed! Skipping to day."
|
vote-passed: "%prefix%&aVote passed! Skipping to day."
|
||||||
already-voted: "%prefix%&cYou already voted."
|
already-voted: "%prefix%&cYou already voted."
|
||||||
not-night: "%prefix%&cYou can only use this at night."
|
not-night: "%prefix%&cYou can only use this at night."
|
||||||
disabled: "%prefix%&cVote day is disabled."
|
disabled: "%prefix%&cVote day is disabled."
|
||||||
world-disabled: "%prefix%&cVote day is disabled in this world."
|
|
||||||
|
night-vote-added: "%prefix%&e%player% &7voted for night. &f(%votes%/%required% votes, %remaining% remaining)"
|
||||||
|
night-vote-passed: "%prefix%&aVote passed! Skipping to night."
|
||||||
|
night-already-voted: "%prefix%&cYou already voted for night."
|
||||||
|
not-day: "%prefix%&cYou can only use this during the day."
|
||||||
|
night-disabled: "%prefix%&cVote night is disabled."
|
||||||
|
|
||||||
|
world-disabled: "%prefix%&cVote commands are disabled in this world."
|
||||||
reloaded: "%prefix%&aConfig reloaded."
|
reloaded: "%prefix%&aConfig reloaded."
|
||||||
no-permission: "%prefix%&cYou do not have permission."
|
no-permission: "%prefix%&cYou do not have permission."
|
||||||
usage: "%prefix%&7Use: &f/dirtsleep reload"
|
usage: "%prefix%&7Use: &f/dirtsleep reload"
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ commands:
|
|||||||
voteday:
|
voteday:
|
||||||
description: Vote to make it day
|
description: Vote to make it day
|
||||||
usage: /voteday
|
usage: /voteday
|
||||||
|
votenight:
|
||||||
|
description: Vote to make it night
|
||||||
|
usage: /votenight
|
||||||
dirtsleep:
|
dirtsleep:
|
||||||
description: DirtSleep admin command
|
description: DirtSleep admin command
|
||||||
usage: /dirtsleep reload
|
usage: /dirtsleep reload
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1,8 +1,9 @@
|
|||||||
vote-day:
|
vote-day:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
# Empty list = all worlds
|
# Plugin will only work in these worlds
|
||||||
worlds: []
|
worlds:
|
||||||
|
- "world"
|
||||||
|
|
||||||
# Only allow /voteday during night
|
# Only allow /voteday during night
|
||||||
only-during-night: true
|
only-during-night: true
|
||||||
@@ -18,14 +19,31 @@ vote-day:
|
|||||||
# dirtsleep.bypass
|
# dirtsleep.bypass
|
||||||
exclude-bypass: true
|
exclude-bypass: true
|
||||||
|
|
||||||
|
vote-night:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
# Only allow /votenight during daytime
|
||||||
|
only-during-day: true
|
||||||
|
|
||||||
|
# Tick time where day effectively ends for vote checks
|
||||||
|
day-ends-at: 12542
|
||||||
|
|
||||||
messages:
|
messages:
|
||||||
prefix: "&8[&bDirtSleep&8] &7"
|
prefix: "&8[&6DirtBagMC&8] &7"
|
||||||
|
|
||||||
vote-added: "%prefix%&e%player% &7voted for day. &f(%votes%/%required% votes, %remaining% remaining)"
|
vote-added: "%prefix%&e%player% &7voted for day. &f(%votes%/%required% votes, %remaining% remaining)"
|
||||||
vote-passed: "%prefix%&aVote passed! Skipping to day."
|
vote-passed: "%prefix%&aVote passed! Skipping to day."
|
||||||
already-voted: "%prefix%&cYou already voted."
|
already-voted: "%prefix%&cYou already voted."
|
||||||
not-night: "%prefix%&cYou can only use this at night."
|
not-night: "%prefix%&cYou can only use this at night."
|
||||||
disabled: "%prefix%&cVote day is disabled."
|
disabled: "%prefix%&cVote day is disabled."
|
||||||
world-disabled: "%prefix%&cVote day is disabled in this world."
|
|
||||||
|
night-vote-added: "%prefix%&e%player% &7voted for night. &f(%votes%/%required% votes, %remaining% remaining)"
|
||||||
|
night-vote-passed: "%prefix%&aVote passed! Skipping to night."
|
||||||
|
night-already-voted: "%prefix%&cYou already voted for night."
|
||||||
|
not-day: "%prefix%&cYou can only use this during the day."
|
||||||
|
night-disabled: "%prefix%&cVote night is disabled."
|
||||||
|
|
||||||
|
world-disabled: "%prefix%&cVote commands are disabled in this world."
|
||||||
reloaded: "%prefix%&aConfig reloaded."
|
reloaded: "%prefix%&aConfig reloaded."
|
||||||
no-permission: "%prefix%&cYou do not have permission."
|
no-permission: "%prefix%&cYou do not have permission."
|
||||||
usage: "%prefix%&7Use: &f/dirtsleep reload"
|
usage: "%prefix%&7Use: &f/dirtsleep reload"
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ commands:
|
|||||||
voteday:
|
voteday:
|
||||||
description: Vote to make it day
|
description: Vote to make it day
|
||||||
usage: /voteday
|
usage: /voteday
|
||||||
|
votenight:
|
||||||
|
description: Vote to make it night
|
||||||
|
usage: /votenight
|
||||||
dirtsleep:
|
dirtsleep:
|
||||||
description: DirtSleep admin command
|
description: DirtSleep admin command
|
||||||
usage: /dirtsleep reload
|
usage: /dirtsleep reload
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#Generated by Maven
|
#Generated by Maven
|
||||||
#Tue Jun 09 16:14:06 EDT 2026
|
#Tue Jun 09 20:09:21 EDT 2026
|
||||||
artifactId=DirtSleep
|
artifactId=DirtSleep
|
||||||
groupId=com.bitnix
|
groupId=com.bitnix
|
||||||
version=1.0-SNAPSHOT
|
version=1.0-SNAPSHOT
|
||||||
|
|||||||
Reference in New Issue
Block a user