Skip to content
Merged
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
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>groupId</groupId>
<artifactId>JVote</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down Expand Up @@ -63,6 +63,12 @@
<version>1.1.8</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.johnymuffin.beta</groupId>
<artifactId>fundamentals</artifactId>
<version>1.0.7</version>
</dependency>
</dependencies>

</project>
33 changes: 26 additions & 7 deletions src/main/java/com/wkaye/jvote/JVoteCommand.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -28,6 +29,8 @@ public class JVoteCommand implements CommandExecutor {
HashSet<Player> playerHasVoted;
JVoteEnums currentVoteType;

private final boolean fundamentalsPresent;

public JVoteCommand(JVote plugin) {
System.out.println("plugin instance created");
this.plugin = plugin;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down