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:
@@ -349,7 +349,7 @@ public class NetServer implements ApplicationListener{
|
|||||||
|
|
||||||
class VoteSession{
|
class VoteSession{
|
||||||
Player target;
|
Player target;
|
||||||
ObjectSet<String> voted = new ObjectSet<>();
|
ObjectIntMap<String> voted = new ObjectIntMap<>();
|
||||||
VoteSession[] map;
|
VoteSession[] map;
|
||||||
Timer.Task task;
|
Timer.Task task;
|
||||||
int votes;
|
int votes;
|
||||||
@@ -367,8 +367,12 @@ public class NetServer implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void vote(Player player, int d){
|
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;
|
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.",
|
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()));
|
player.name, target.name, votes, votesRequired()));
|
||||||
@@ -393,7 +397,7 @@ public class NetServer implements ApplicationListener{
|
|||||||
//current kick sessions
|
//current kick sessions
|
||||||
VoteSession[] currentlyKicking = {null};
|
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()){
|
if(!Config.enableVotekick.bool()){
|
||||||
player.sendMessage("[scarlet]Vote-kick is disabled on this server.");
|
player.sendMessage("[scarlet]Vote-kick is disabled on this server.");
|
||||||
return;
|
return;
|
||||||
@@ -422,6 +426,8 @@ public class NetServer implements ApplicationListener{
|
|||||||
builder.append("[lightgray] ").append(p.name).append("[accent] (#").append(p.id()).append(")\n");
|
builder.append("[lightgray] ").append(p.name).append("[accent] (#").append(p.id()).append(")\n");
|
||||||
});
|
});
|
||||||
player.sendMessage(builder.toString());
|
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{
|
}else{
|
||||||
Player found;
|
Player found;
|
||||||
if(args[0].length() > 1 && args[0].startsWith("#") && Strings.canParseInt(args[0].substring(1))){
|
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);
|
VoteSession session = new VoteSession(currentlyKicking, found);
|
||||||
session.vote(player, 1);
|
session.vote(player, 1);
|
||||||
|
Call.sendMessage(Strings.format("[lightgray]Reason:[orange] @[lightgray].", args[1]));
|
||||||
vtime.reset();
|
vtime.reset();
|
||||||
currentlyKicking[0] = session;
|
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){
|
if(currentlyKicking[0] == null){
|
||||||
player.sendMessage("[scarlet]Nobody is being voted on.");
|
player.sendMessage("[scarlet]Nobody is being voted on.");
|
||||||
}else{
|
}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()){
|
if(player.isLocal()){
|
||||||
player.sendMessage("[scarlet]Local players can't vote. Kick the player yourself instead.");
|
player.sendMessage("[scarlet]Local players can't vote. Kick the player yourself instead.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sign = switch(arg[0].toLowerCase()){
|
||||||
|
case "y", "yes" -> 1;
|
||||||
|
case "n", "no" -> -1;
|
||||||
|
default -> 0;
|
||||||
|
};
|
||||||
|
|
||||||
//hosts can vote all they want
|
//hosts can vote all they want
|
||||||
if((currentlyKicking[0].voted.contains(player.uuid()) || currentlyKicking[0].voted.contains(admins.getInfo(player.uuid()).lastIP))){
|
if((currentlyKicking[0].voted.get(player.uuid(), 2) == sign || currentlyKicking[0].voted.get(admins.getInfo(player.uuid()).lastIP, 2) == sign)){
|
||||||
player.sendMessage("[scarlet]You've already voted. Sit down.");
|
player.sendMessage(Strings.format("[scarlet]You've already voted @. Sit down.", arg[0].toLowerCase()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,12 +504,6 @@ public class NetServer implements ApplicationListener{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sign = switch(arg[0].toLowerCase()){
|
|
||||||
case "y", "yes" -> 1;
|
|
||||||
case "n", "no" -> -1;
|
|
||||||
default -> 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
if(sign == 0){
|
if(sign == 0){
|
||||||
player.sendMessage("[scarlet]Vote either 'y' (yes) or 'n' (no).");
|
player.sendMessage("[scarlet]Vote either 'y' (yes) or 'n' (no).");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ public class PlayerListFragment{
|
|||||||
|
|
||||||
button.button(Icon.hammer, ustyle,
|
button.button(Icon.hammer, ustyle,
|
||||||
() -> ui.showConfirm("@confirm", Core.bundle.format("confirmvotekick", user.name()),
|
() -> 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);
|
.size(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user