]> git.defcon.no Git - YAVote/commitdiff
Adding trigger for Logout/Quit handling. Should correct ratio-tests when players...
authorJon Langseth <jon.langseth@hig.no>
Tue, 8 May 2012 12:34:39 +0000 (14:34 +0200)
committerJon Langseth <jon.langseth@hig.no>
Tue, 8 May 2012 12:34:39 +0000 (14:34 +0200)
src/no/defcon/yavote/Votemanager.java
src/no/defcon/yavote/YAVote.java

index 2212b7a40f7c254324d65b3feecc98e994dc986e..76bb4e88b3b41f8c874f389ff547f18f5312b9a3 100644 (file)
@@ -101,6 +101,31 @@ public class Votemanager {
                return voteType;\r
        }\r
 \r
+       public void removeVote(Player player )\r
+       {\r
+               if ( ! voteRunning || (voteType == null ) )\r
+                       return;\r
+\r
+               plugin.getLogger().info("Debugging removeVote() with player: " + player.getName() );\r
+               if ( yesVoters.contains(player.getName()) )\r
+               {\r
+                       yesVoters.remove(player.getName());\r
+                       plugin.getLogger().info("Debugging, removeVote() removed YES vote for " + player.getName() );\r
+               }\r
+\r
+               if ( noVoters.contains(player.getName()) )\r
+               {\r
+                       noVoters.remove(player.getName());\r
+                       plugin.getLogger().info("Debugging, removeVote() removed NO vote for " + player.getName() );\r
+               }\r
+               if( checkRatio( ) )\r
+               {\r
+                       plugin.getLogger().info("Debugging: after removing vote, checkRatio() returns TRUE, applying vote");\r
+                       applyVote( voteType );\r
+               }\r
+               plugin.getLogger().info("Returning from removeVote()");\r
+       }\r
+\r
        public boolean addVote(Player player, boolean yes) \r
        {\r
                if ( ! voteRunning || (voteType == null ) )\r
@@ -169,7 +194,7 @@ public class Votemanager {
                        required = (float)plugin.getConfig().getInt("vote.time.requiredPercent") / 100.0F;\r
                \r
                float ratio = (float) yesVoters.size() / (float) plugin.getServer().getOnlinePlayers().length;\r
-               if ( ratio > required ) return true;\r
+               if ( ratio >= required ) return true;\r
                return false;\r
        }\r
        \r
index f12edb3c28b10f92a1de991585c5cbea303dc7ce..98433ba107aa0b09834bb09a930649c1b46fd49c 100644 (file)
@@ -10,7 +10,11 @@ import org.bukkit.plugin.java.JavaPlugin;
 \r
 import org.bukkit.plugin.PluginLogger;\r
 \r
-public class YAVote extends JavaPlugin {\r
+import org.bukkit.event.Listener;\r
+import org.bukkit.event.EventHandler;\r
+import org.bukkit.event.player.PlayerQuitEvent;\r
+\r
+public class YAVote extends JavaPlugin implements Listener {\r
        public PluginLogger logger;\r
        private Votemanager manager;\r
        \r
@@ -51,8 +55,18 @@ public class YAVote extends JavaPlugin {
                        logger.info("Creating configuration file");\r
                        saveConfig();\r
                }\r
+\r
+               getServer().getPluginManager().registerEvents(this, this);\r
+\r
                logger.info("Version " + getDescription().getVersion() + " is enabled!");\r
        }\r
+\r
+       @EventHandler\r
+       public void onLogout(PlayerQuitEvent event)\r
+       {\r
+               logger.info("Triggered onLogout() with " + getServer().getOnlinePlayers().length + " players online.");\r
+               manager.removeVote( event.getPlayer() );\r
+       }\r
        \r
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){\r
                if(cmd.getName().equalsIgnoreCase("vote")){\r