add kick-kicked-players

This commit is contained in:
ajgeiss0702
2021-12-30 02:36:17 -07:00
parent 3573c34bc6
commit 0b44a259ea
5 changed files with 42 additions and 0 deletions
@@ -78,6 +78,12 @@ public interface AdaptedPlayer extends Handle, Audience {
*/ */
String getName(); String getName();
/**
* Kick a player from the proxy
* @param reason The reason to kick them with
*/
void kick(Component reason);
List<String> getPermissions(); List<String> getPermissions();
default boolean equals(AdaptedPlayer other) { default boolean equals(AdaptedPlayer other) {
@@ -217,10 +217,29 @@ public class EventHandlerImpl implements EventHandler {
QueuePlayer queuePlayer = server.findPlayer(player); QueuePlayer queuePlayer = server.findPlayer(player);
if(queuePlayer.getPosition() != 1) continue; if(queuePlayer.getPosition() != 1) continue;
List<String> kickReasons = main.getConfig().getStringList("kick-reasons"); List<String> kickReasons = main.getConfig().getStringList("kick-reasons");
boolean kickPlayer = main.getConfig().getBoolean("kick-kicked-players");
if(kickPlayer) {
List<String> svs = main.getConfig().getStringList("queue-servers");
boolean found = false;
for(String s : svs) {
if(!s.contains(":")) continue;
String[] parts = s.split(":");
String fromName = parts[0];
QueueServer toServer = main.getQueueManager().findServer(parts[1]);
if(fromName.equalsIgnoreCase(server.getName()) && toServer != null && toServer.equals(server)) {
found = true;
}
}
kickPlayer = found;
}
for(String kickReason : kickReasons) { for(String kickReason : kickReasons) {
if(plainReason.toLowerCase().contains(kickReason.toLowerCase())) { if(plainReason.toLowerCase().contains(kickReason.toLowerCase())) {
server.removePlayer(queuePlayer); server.removePlayer(queuePlayer);
if(kickPlayer) {
player.kick(reason);
}
break;
} }
} }
} }
+6
View File
@@ -38,6 +38,12 @@ kick-reasons:
- 'banned' - 'banned'
- 'blacklisted' - 'blacklisted'
# Should we completly kick the user from the server if they are in a queue-server
# and are kicked from the server with one of the above reasons?
# Note this will do nothing on servers that arent queue-servers
# (as in the config option queue-servers)
# Default: true
kick-kicked-players: true
# Should we remove a player from the queue if they move servers? # Should we remove a player from the queue if they move servers?
# This will remove the player from if they switch to any other server # This will remove the player from if they switch to any other server
@@ -6,6 +6,7 @@ import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.sound.SoundStop; import net.kyori.adventure.sound.SoundStop;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike; import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import net.kyori.adventure.title.Title; import net.kyori.adventure.title.Title;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -136,6 +137,11 @@ public class BungeePlayer implements AdaptedPlayer, Audience {
return handle.getName(); return handle.getName();
} }
@Override
public void kick(Component reason) {
handle.disconnect(BungeeComponentSerializer.get().serialize(reason));
}
@Override @Override
public List<String> getPermissions() { public List<String> getPermissions() {
return new ArrayList<>(handle.getPermissions()); return new ArrayList<>(handle.getPermissions());
@@ -174,6 +174,11 @@ public class VelocityPlayer implements AdaptedPlayer, Audience {
return handle.getUsername(); return handle.getUsername();
} }
@Override
public void kick(Component reason) {
handle.disconnect(reason);
}
@Override @Override
public List<String> getPermissions() { public List<String> getPermissions() {
throw new IllegalStateException("AdaptedPlayer#getPermissions cannot be used on velocity"); throw new IllegalStateException("AdaptedPlayer#getPermissions cannot be used on velocity");