From efde092b906b94ef1d4cf0800ae6b5acdfce7161 Mon Sep 17 00:00:00 2001 From: Mengyang Li Date: Tue, 4 Feb 2020 22:00:33 -0800 Subject: [PATCH] unvote on player left --- src/main/java/rtv/RockTheVotePlugin.java | 15 +++++++++++++++ src/main/resources/plugin.json | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/rtv/RockTheVotePlugin.java b/src/main/java/rtv/RockTheVotePlugin.java index 23c7007..3595ea8 100644 --- a/src/main/java/rtv/RockTheVotePlugin.java +++ b/src/main/java/rtv/RockTheVotePlugin.java @@ -19,7 +19,22 @@ public class RockTheVotePlugin extends Plugin { // register event handlers and create variables in the constructor public RockTheVotePlugin() { + // un-vote on player leave + Events.on(PlayerLeave.class, e-> { + Player player = e.player; + int cur = this.votes.size(); + int req = (int) Math.ceil(ratio * Vars.playerGroup.size()); + if(votes.contains(player)) { + votes.remove(player); + Call.sendMessage("RTV: [accent]" + player.name + "[] left, [green]" + cur + "[] votes, [green]" + req + "[] required"); + } + }); + // clear votes on game over + Events.on(GameOverEvent.class, e -> { + this.votes.clear(); + }); } + //register commands that player can invoke in-game @Override diff --git a/src/main/resources/plugin.json b/src/main/resources/plugin.json index efddc55..8840ef6 100644 --- a/src/main/resources/plugin.json +++ b/src/main/resources/plugin.json @@ -3,5 +3,5 @@ "author": "mayli", "main": "rtv.RockTheVotePlugin", "description": "A plugin to change map by /rtv.", - "version": 1.1 + "version": 1.2 }