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
This commit is contained in:
frieda666
2023-06-03 20:45:55 -07:00
committed by GitHub
parent fc673de556
commit 70bb7aff54
2 changed files with 27 additions and 13 deletions

View File

@@ -349,7 +349,7 @@ public class NetServer implements ApplicationListener{
class VoteSession{
Player target;
ObjectSet<String> voted = new ObjectSet<>();
ObjectIntMap<String> 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 <y/n>[] to agree.",
player.name, target.name, votes, votesRequired()));
@@ -393,7 +397,7 @@ public class NetServer implements ApplicationListener{
//current kick sessions
VoteSession[] currentlyKicking = {null};
clientCommands.<Player>register("votekick", "[player...]", "Vote to kick a player.", (args, player) -> {
clientCommands.<Player>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.<Player>register("vote", "<y/n>", "Vote to kick the current player.", (arg, player) -> {
clientCommands.<Player>register("vote", "<y/n/c>", "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;

View File

@@ -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);
}