From bdcca239a8ae7504e95ac497b0c305b05246f3fc Mon Sep 17 00:00:00 2001 From: Jon Langseth Date: Tue, 8 May 2012 15:32:53 +0200 Subject: [PATCH] Testing a different approach. Urp. --- plugin.yml | 4 +-- src/no/defcon/yavote/Votemanager.java | 47 ++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/plugin.yml b/plugin.yml index 1d311de..01a4a6c 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: YAVote main: no.defcon.yavote.YAVote -version: 1.4 +version: 1.5-test description: Yet Another Vote plugin for Bukkit website: http://minecraft.defcon.no/yavote authors: @@ -47,4 +47,4 @@ permissions: vote.time.*: true vote.weather.*: true vote.cancel: true - vote.status: true \ No newline at end of file + vote.status: true 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() { -- 2.39.2