]> git.defcon.no Git - YAVote/commitdiff
Testing a different approach. Urp.
authorJon Langseth <jon.langseth@hig.no>
Tue, 8 May 2012 13:32:53 +0000 (15:32 +0200)
committerJon Langseth <jon.langseth@hig.no>
Tue, 8 May 2012 13:32:53 +0000 (15:32 +0200)
plugin.yml
src/no/defcon/yavote/Votemanager.java

index 1d311de24c90dbc50e3aea633ec030b10ba40f9c..01a4a6ceab28a07ead9a22f26947cd479392a501 100644 (file)
@@ -1,6 +1,6 @@
 name: YAVote\r
 main: no.defcon.yavote.YAVote\r
-version: 1.4\r
+version: 1.5-test\r
 description: Yet Another Vote plugin for Bukkit\r
 website: http://minecraft.defcon.no/yavote\r
 authors:\r
@@ -47,4 +47,4 @@ permissions:
       vote.time.*: true\r
       vote.weather.*: true\r
       vote.cancel: true\r
-      vote.status: true
\ No newline at end of file
+      vote.status: true\r
index 76bb4e88b3b41f8c874f389ff547f18f5312b9a3..78c059ab1d903451b10e77e361904ef217e6f3de 100644 (file)
@@ -64,7 +64,8 @@ public class Votemanager {
 \r
                yesVoters.add(p.getName());\r
 \r
-               if ( checkRatio( ) )\r
+               //if ( checkRatio( ) )\r
+               if ( ((float) yesVoters.size() / (float) plugin.getServer().getOnlinePlayers().length ) >= getRequired() )\r
                {\r
                        applyVote( voteType );\r
                        return true;\r
@@ -118,9 +119,17 @@ public class Votemanager {
                        noVoters.remove(player.getName());\r
                        plugin.getLogger().info("Debugging, removeVote() removed NO vote for " + player.getName() );\r
                }\r
-               if( checkRatio( ) )\r
+\r
+               if ( yesVoters.size() + noVoters.size() == 0 )\r
                {\r
-                       plugin.getLogger().info("Debugging: after removing vote, checkRatio() returns TRUE, applying vote");\r
+                       plugin.getLogger().info("Debugging: No voters remaining in lists. Cancel vote.");\r
+                       cancelVote();\r
+                       return;\r
+               }\r
+               //if( checkRatio( ) )\r
+               if ( ((float) yesVoters.size() / (float) plugin.getServer().getOnlinePlayers().length -1 ) >= getRequired() )\r
+               {\r
+                       plugin.getLogger().info("Debugging: after removing vote, ratio test returns TRUE, applying vote");\r
                        applyVote( voteType );\r
                }\r
                plugin.getLogger().info("Returning from removeVote()");\r
@@ -139,7 +148,8 @@ public class Votemanager {
                if (yes == true) yesVoters.add(player.getName());\r
                else noVoters.add(player.getName());\r
                \r
-               if ( (yes == true) && checkRatio( ) )\r
+               //if ( (yes == true) && checkRatio( ) )\r
+               if ( ( yes == true) && ( ((float) yesVoters.size() / (float) plugin.getServer().getOnlinePlayers().length ) >= getRequired() ) )\r
                {\r
                        applyVote( voteType );\r
                        return true;\r
@@ -185,18 +195,37 @@ public class Votemanager {
                clearState();\r
        }\r
        \r
-       private boolean checkRatio( )\r
+       private float getRequired( )\r
        {\r
-               float required = 0.5F;\r
+               float req = 0.0f;\r
                if ( voteType.equalsIgnoreCase("sun") || voteType.equalsIgnoreCase("rain") || voteType.equalsIgnoreCase("storm") )\r
-                       required = (float)plugin.getConfig().getInt("vote.weather.requiredPercent") / 100.0F;\r
+                       req = (float)plugin.getConfig().getInt("vote.weather.requiredPercent") / 100.0F;\r
                else if ( voteType.equalsIgnoreCase("day") || voteType.equalsIgnoreCase("night") )\r
-                       required = (float)plugin.getConfig().getInt("vote.time.requiredPercent") / 100.0F;\r
-               \r
+                       req = (float)plugin.getConfig().getInt("vote.time.requiredPercent") / 100.0F;\r
+\r
+               return req;\r
+       }\r
+\r
+       /*\r
+       // Original approach...\r
+       private boolean checkRatio( )\r
+       {\r
+               float required = getRequired();\r
                float ratio = (float) yesVoters.size() / (float) plugin.getServer().getOnlinePlayers().length;\r
                if ( ratio >= required ) return true;\r
                return false;\r
        }\r
+\r
+       // Replacement code\r
+       private boolean checkRatio( )\r
+       {\r
+               if ( ((float) yesVoters.size() / (float) plugin.getServer().getOnlinePlayers().length ) >= getRequired() )\r
+                       return true;\r
+               return false;\r
+       }\r
+\r
+       // But, trying to do it inline instead\r
+       */\r
        \r
        private void clearState()\r
        {\r