From 70bb7aff540f3ae438b5a318c2d91e86104b346e Mon Sep 17 00:00:00 2001 From: frieda666 <103875616+frieda666@users.noreply.github.com> Date: Sat, 3 Jun 2023 20:45:55 -0700 Subject: [PATCH] Improvement on votekick (#8664) * Add test case for achievement * Allow admins to cancel votekick & allow players to change vote * Require reason to start votekick * Require reason to start votekick * Update message sent by votekick button --- core/src/mindustry/core/NetServer.java | 38 +++++++++++++------ .../ui/fragments/PlayerListFragment.java | 2 +- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/core/src/mindustry/core/NetServer.java b/core/src/mindustry/core/NetServer.java index 50fb7193df..479ca7aa04 100644 --- a/core/src/mindustry/core/NetServer.java +++ b/core/src/mindustry/core/NetServer.java @@ -349,7 +349,7 @@ public class NetServer implements ApplicationListener{ class VoteSession{ Player target; - ObjectSet voted = new ObjectSet<>(); + ObjectIntMap voted = new ObjectIntMap<>(); VoteSession[] map; Timer.Task task; int votes; @@ -367,8 +367,12 @@ public class NetServer implements ApplicationListener{ } void vote(Player player, int d){ + int lastVote = voted.get(player.uuid(), 0) | voted.get(admins.getInfo(player.uuid()).lastIP, 0); + votes -= lastVote; + votes += d; - voted.addAll(player.uuid(), admins.getInfo(player.uuid()).lastIP); + voted.put(player.uuid(), d); + voted.put(admins.getInfo(player.uuid()).lastIP, d); Call.sendMessage(Strings.format("[lightgray]@[lightgray] has voted on kicking[orange] @[lightgray].[accent] (@/@)\n[lightgray]Type[orange] /vote [] to agree.", player.name, target.name, votes, votesRequired())); @@ -393,7 +397,7 @@ public class NetServer implements ApplicationListener{ //current kick sessions VoteSession[] currentlyKicking = {null}; - clientCommands.register("votekick", "[player...]", "Vote to kick a player.", (args, player) -> { + clientCommands.register("votekick", "[player] [reason...]", "Vote to kick a player with a valid reason.", (args, player) -> { if(!Config.enableVotekick.bool()){ player.sendMessage("[scarlet]Vote-kick is disabled on this server."); return; @@ -422,6 +426,8 @@ public class NetServer implements ApplicationListener{ builder.append("[lightgray] ").append(p.name).append("[accent] (#").append(p.id()).append(")\n"); }); player.sendMessage(builder.toString()); + }else if(args.length == 1){ + player.sendMessage("[orange]You need a valid reason to kick the player. Add a reason after the player name."); }else{ Player found; if(args[0].length() > 1 && args[0].startsWith("#") && Strings.canParseInt(args[0].substring(1))){ @@ -450,6 +456,7 @@ public class NetServer implements ApplicationListener{ VoteSession session = new VoteSession(currentlyKicking, found); session.vote(player, 1); + Call.sendMessage(Strings.format("[lightgray]Reason:[orange] @[lightgray].", args[1])); vtime.reset(); currentlyKicking[0] = session; } @@ -459,18 +466,31 @@ public class NetServer implements ApplicationListener{ } }); - clientCommands.register("vote", "", "Vote to kick the current player.", (arg, player) -> { + clientCommands.register("vote", "", "Vote to kick the current player. Admin can cancel the voting with 'c'.", (arg, player) -> { if(currentlyKicking[0] == null){ player.sendMessage("[scarlet]Nobody is being voted on."); }else{ + if(player.admin && arg[0].equalsIgnoreCase("c")){ + Call.sendMessage(Strings.format("[lightgray]Vote canceled by admin[orange] @[lightgray].", player.name)); + currentlyKicking[0].task.cancel(); + currentlyKicking[0] = null; + return; + } + if(player.isLocal()){ player.sendMessage("[scarlet]Local players can't vote. Kick the player yourself instead."); return; } + int sign = switch(arg[0].toLowerCase()){ + case "y", "yes" -> 1; + case "n", "no" -> -1; + default -> 0; + }; + //hosts can vote all they want - if((currentlyKicking[0].voted.contains(player.uuid()) || currentlyKicking[0].voted.contains(admins.getInfo(player.uuid()).lastIP))){ - player.sendMessage("[scarlet]You've already voted. Sit down."); + if((currentlyKicking[0].voted.get(player.uuid(), 2) == sign || currentlyKicking[0].voted.get(admins.getInfo(player.uuid()).lastIP, 2) == sign)){ + player.sendMessage(Strings.format("[scarlet]You've already voted @. Sit down.", arg[0].toLowerCase())); return; } @@ -484,12 +504,6 @@ public class NetServer implements ApplicationListener{ return; } - int sign = switch(arg[0].toLowerCase()){ - case "y", "yes" -> 1; - case "n", "no" -> -1; - default -> 0; - }; - if(sign == 0){ player.sendMessage("[scarlet]Vote either 'y' (yes) or 'n' (no)."); return; diff --git a/core/src/mindustry/ui/fragments/PlayerListFragment.java b/core/src/mindustry/ui/fragments/PlayerListFragment.java index 81ed310b04..c1359c5d80 100644 --- a/core/src/mindustry/ui/fragments/PlayerListFragment.java +++ b/core/src/mindustry/ui/fragments/PlayerListFragment.java @@ -200,7 +200,7 @@ public class PlayerListFragment{ button.button(Icon.hammer, ustyle, () -> ui.showConfirm("@confirm", Core.bundle.format("confirmvotekick", user.name()), - () -> Call.sendChatMessage("/votekick #" + user.id))) + () -> Call.sendChatMessage("/votekick #" + user.id + " No reason is provided"))) .size(h); }