diff --git a/pom.xml b/pom.xml
index 839c5cb..0c64e48 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
groupId
JVote
- 1.0.2
+ 1.0.3
8
@@ -63,6 +63,12 @@
1.1.8
provided
+
+
+ com.johnymuffin.beta
+ fundamentals
+ 1.0.7
+
\ No newline at end of file
diff --git a/src/main/java/com/wkaye/jvote/JVoteCommand.java b/src/main/java/com/wkaye/jvote/JVoteCommand.java
index 5956b4b..14ba3b2 100644
--- a/src/main/java/com/wkaye/jvote/JVoteCommand.java
+++ b/src/main/java/com/wkaye/jvote/JVoteCommand.java
@@ -1,5 +1,6 @@
package com.wkaye.jvote;
+import com.johnymuffin.beta.fundamentals.FundamentalsPlayerMap;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
@@ -28,6 +29,8 @@ public class JVoteCommand implements CommandExecutor {
HashSet playerHasVoted;
JVoteEnums currentVoteType;
+ private final boolean fundamentalsPresent;
+
public JVoteCommand(JVote plugin) {
System.out.println("plugin instance created");
this.plugin = plugin;
@@ -37,8 +40,9 @@ public JVoteCommand(JVote plugin) {
playerHasVoted = new HashSet<>();
isOnCooldown = new ConcurrentHashMap<>();
countdownTaskId = new AtomicInteger();
- }
+ fundamentalsPresent = Bukkit.getPluginManager().isPluginEnabled("Fundamentals");
+ }
/*
This command should have two stages: one where the voting commences and another where people vote yes/no
@@ -141,6 +145,20 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}
+ private int getEligiblePlayerCount() {
+ if (!fundamentalsPresent) {
+ return Bukkit.getServer().getOnlinePlayers().length;
+ }
+
+ int count = 0;
+ for (Player player : Bukkit.getServer().getOnlinePlayers()) {
+ if (!FundamentalsPlayerMap.getInstance().getPlayer(player).isAFK()) {
+ count++;
+ }
+ }
+ return count;
+ }
+
private boolean checkVote(String arg, CommandSender sender) {
Player player = (Player) sender;
double currentVotePercentage = 0;
@@ -152,12 +170,12 @@ private boolean checkVote(String arg, CommandSender sender) {
}
sender.sendMessage(JVoteUtils.printMessage("You have voted"));
playerHasVoted.add(player);
+ int eligible = getEligiblePlayerCount();
+ if (eligible == 0) return false;
if ("yes".contains(arg.toLowerCase()) || "ok".contains(arg.toLowerCase())) {
- currentVotePercentage = (double) totalVotes.incrementAndGet()
- / Bukkit.getServer().getOnlinePlayers().length;
+ currentVotePercentage = (double) totalVotes.incrementAndGet() / eligible;
} else if ("no".contains(arg.toLowerCase())) {
- currentVotePercentage = (double) totalVotes.decrementAndGet()
- / Bukkit.getServer().getOnlinePlayers().length;
+ currentVotePercentage = (double) totalVotes.decrementAndGet() / eligible;
}
if (plugin.getDebugLevel() > 0) {
plugin.logger(Level.INFO, "voting percentage at: " + currentVotePercentage);
@@ -166,8 +184,9 @@ private boolean checkVote(String arg, CommandSender sender) {
}
private boolean checkVote() {
- double currentVotePercentage = (double) totalVotes.get()
- / Bukkit.getServer().getOnlinePlayers().length;
+ int eligible = getEligiblePlayerCount();
+ if (eligible == 0) return false;
+ double currentVotePercentage = (double) totalVotes.get() / eligible;
if (plugin.getDebugLevel() > 0) {
plugin.logger(Level.INFO, "voting percentage at: " + currentVotePercentage);
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 3cec81a..14ec103 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,8 +1,9 @@
name: JVote
-version: 1.0.2
+version: 1.0.3
main: com.wkaye.jvote.JVote
authors: [ xXGunner989Xx ]
description: A weather voting plugin for Minecraft Beta 1.7.3 designed for Project Poseidon w/ Fundamentals
+softdepend: [Fundamentals]
commands:
vote:
description: a vote command to change weather or time