X-Git-Url: https://git.defcon.no/?p=YAVote;a=blobdiff_plain;f=src%2Fno%2Fdefcon%2Fyavote%2FVotemanager.java;fp=src%2Fno%2Fdefcon%2Fyavote%2FVotemanager.java;h=78c059ab1d903451b10e77e361904ef217e6f3de;hp=76bb4e88b3b41f8c874f389ff547f18f5312b9a3;hb=bdcca239a8ae7504e95ac497b0c305b05246f3fc;hpb=b7b8828e5c4c4ad90b00ed84f617ecc62caf4587 diff --git a/src/no/defcon/yavote/Votemanager.java b/src/no/defcon/yavote/Votemanager.java index 76bb4e8..78c059a 100644 --- a/src/no/defcon/yavote/Votemanager.java +++ b/src/no/defcon/yavote/Votemanager.java @@ -64,7 +64,8 @@ public class Votemanager { yesVoters.add(p.getName()); - if ( checkRatio( ) ) + //if ( checkRatio( ) ) + if ( ((float) yesVoters.size() / (float) plugin.getServer().getOnlinePlayers().length ) >= getRequired() ) { applyVote( voteType ); return true; @@ -118,9 +119,17 @@ public class Votemanager { noVoters.remove(player.getName()); plugin.getLogger().info("Debugging, removeVote() removed NO vote for " + player.getName() ); } - if( checkRatio( ) ) + + if ( yesVoters.size() + noVoters.size() == 0 ) { - plugin.getLogger().info("Debugging: after removing vote, checkRatio() returns TRUE, applying vote"); + plugin.getLogger().info("Debugging: No voters remaining in lists. Cancel vote."); + cancelVote(); + return; + } + //if( checkRatio( ) ) + if ( ((float) yesVoters.size() / (float) plugin.getServer().getOnlinePlayers().length -1 ) >= getRequired() ) + { + plugin.getLogger().info("Debugging: after removing vote, ratio test returns TRUE, applying vote"); applyVote( voteType ); } plugin.getLogger().info("Returning from removeVote()"); @@ -139,7 +148,8 @@ public class Votemanager { if (yes == true) yesVoters.add(player.getName()); else noVoters.add(player.getName()); - if ( (yes == true) && checkRatio( ) ) + //if ( (yes == true) && checkRatio( ) ) + if ( ( yes == true) && ( ((float) yesVoters.size() / (float) plugin.getServer().getOnlinePlayers().length ) >= getRequired() ) ) { applyVote( voteType ); return true; @@ -185,18 +195,37 @@ public class Votemanager { clearState(); } - private boolean checkRatio( ) + private float getRequired( ) { - float required = 0.5F; + float req = 0.0f; if ( voteType.equalsIgnoreCase("sun") || voteType.equalsIgnoreCase("rain") || voteType.equalsIgnoreCase("storm") ) - required = (float)plugin.getConfig().getInt("vote.weather.requiredPercent") / 100.0F; + req = (float)plugin.getConfig().getInt("vote.weather.requiredPercent") / 100.0F; else if ( voteType.equalsIgnoreCase("day") || voteType.equalsIgnoreCase("night") ) - required = (float)plugin.getConfig().getInt("vote.time.requiredPercent") / 100.0F; - + req = (float)plugin.getConfig().getInt("vote.time.requiredPercent") / 100.0F; + + return req; + } + + /* + // Original approach... + private boolean checkRatio( ) + { + float required = getRequired(); float ratio = (float) yesVoters.size() / (float) plugin.getServer().getOnlinePlayers().length; if ( ratio >= required ) return true; return false; } + + // Replacement code + private boolean checkRatio( ) + { + if ( ((float) yesVoters.size() / (float) plugin.getServer().getOnlinePlayers().length ) >= getRequired() ) + return true; + return false; + } + + // But, trying to do it inline instead + */ private void clearState() {