mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2026-04-08 16:10:26 +00:00
Implement network kick
This commit is contained in:
@@ -10,8 +10,8 @@ import com.imaginarycode.minecraft.redisbungee.api.AbstractRedisBungeeListener;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.AbstractDataManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.RedisUtil;
|
||||
import com.velocitypowered.api.event.Continuation;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.ResultedEvent;
|
||||
@@ -148,14 +148,14 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
||||
@Override
|
||||
public Void jedisTask(Jedis jedis) {
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
RedisUtil.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), pipeline);
|
||||
PayloadUtils.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), pipeline);
|
||||
pipeline.sync();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
||||
RedisUtil.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), jedisCluster);
|
||||
PayloadUtils.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), jedisCluster);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.RedisUtil;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.io.IOUtil;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.lua.LuaManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.NameFetcher;
|
||||
@@ -693,7 +694,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
if (!laggedPlayers.isEmpty()) {
|
||||
getLogger().info("Cleaning up lagged proxy {} ({} players)...", s, laggedPlayers.size());
|
||||
for (String laggedPlayer : laggedPlayers) {
|
||||
RedisUtil.cleanUpPlayer(laggedPlayer, jedis);
|
||||
PayloadUtils.cleanUpPlayer(laggedPlayer, jedis);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -714,7 +715,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
RedisUtil.cleanUpPlayer(member, jedis);
|
||||
PayloadUtils.cleanUpPlayer(member, jedis);
|
||||
getLogger().warn("Player found in set that was not found locally and globally: {}", member);
|
||||
} else {
|
||||
jedis.srem("proxy:" + configuration.getProxyId() + ":usersOnline", member);
|
||||
@@ -756,7 +757,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
if (!laggedPlayers.isEmpty()) {
|
||||
getLogger().info("Cleaning up lagged proxy {} ({} players)...", s, laggedPlayers.size());
|
||||
for (String laggedPlayer : laggedPlayers) {
|
||||
RedisUtil.cleanUpPlayer(laggedPlayer, jedisCluster);
|
||||
PayloadUtils.cleanUpPlayer(laggedPlayer, jedisCluster);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -777,7 +778,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
RedisUtil.cleanUpPlayer(member, jedisCluster);
|
||||
PayloadUtils.cleanUpPlayer(member, jedisCluster);
|
||||
getLogger().warn("Player found in set that was not found locally and globally: {}", member);
|
||||
} else {
|
||||
jedisCluster.srem("proxy:" + configuration.getProxyId() + ":usersOnline", member);
|
||||
@@ -811,7 +812,6 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
if (configuration.doOverrideBungeeCommands()) {
|
||||
getProxy().getCommandManager().register("glist", new RedisBungeeCommands.GlistCommand(this), "redisbungee", "rglist");
|
||||
}
|
||||
|
||||
getProxy().getCommandManager().register("sendtoall", new RedisBungeeCommands.SendToAll(this), "rsendtoall");
|
||||
getProxy().getCommandManager().register("serverid", new RedisBungeeCommands.ServerId(this), "rserverid");
|
||||
getProxy().getCommandManager().register("serverids", new RedisBungeeCommands.ServerIds(this));
|
||||
@@ -820,6 +820,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
getProxy().getCommandManager().register("lastseen", new RedisBungeeCommands.LastSeenCommand(this), "rlastseen");
|
||||
getProxy().getCommandManager().register("ip", new RedisBungeeCommands.IpCommand(this), "playerip", "rip", "rplayerip");
|
||||
getProxy().getCommandManager().register("find", new RedisBungeeCommands.FindCommand(this), "rfind");
|
||||
getProxy().getCommandManager().register("networkkick", new RedisBungeeCommands.KickCommand(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -841,7 +842,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
if (jedis.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
|
||||
Set<String> players = jedis.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
|
||||
for (String member : players)
|
||||
RedisUtil.cleanUpPlayer(member, jedis);
|
||||
PayloadUtils.cleanUpPlayer(member, jedis);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -852,7 +853,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
if (jedisCluster.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
|
||||
Set<String> players = jedisCluster.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
|
||||
for (String member : players)
|
||||
RedisUtil.cleanUpPlayer(member, jedisCluster);
|
||||
PayloadUtils.cleanUpPlayer(member, jedisCluster);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -954,6 +955,33 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kickPlayer(UUID playerUniqueId, String message) {
|
||||
// first handle on origin proxy if player not found publish the payload
|
||||
if (!dataManager.handleKick(playerUniqueId, message)) {
|
||||
new RedisTask<Void>(api) {
|
||||
@Override
|
||||
public Void jedisTask(Jedis jedis) {
|
||||
PayloadUtils.kickPlayer(playerUniqueId, message, jedis);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
||||
PayloadUtils.kickPlayer(playerUniqueId, message, jedisCluster);
|
||||
return null;
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kickPlayer(String playerName, String message) {
|
||||
// fetch the uuid
|
||||
UUID playerUUID = this.uuidTranslator.getTranslatedUuid(playerName,true);
|
||||
kickPlayer(playerUUID, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisBungeeMode getRedisBungeeMode() {
|
||||
return this.redisBungeeMode;
|
||||
|
||||
@@ -7,6 +7,11 @@ import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class VelocityDataManager extends AbstractDataManager<Player, PostLoginEvent, DisconnectEvent, PubSubMessageEvent> {
|
||||
@@ -32,4 +37,15 @@ public class VelocityDataManager extends AbstractDataManager<Player, PostLoginEv
|
||||
public void onPubSubMessage(PubSubMessageEvent event) {
|
||||
handlePubSubMessage(event.getChannel(), event.getMessage());
|
||||
}
|
||||
|
||||
private final LegacyComponentSerializer serializer = LegacyComponentSerializer.legacySection();
|
||||
@Override
|
||||
public boolean handleKick(UUID target, String message) {
|
||||
Player player = plugin.getPlayer(target);
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
player.disconnect(serializer.deserialize(message));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package com.imaginarycode.minecraft.redisbungee.commands;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
|
||||
Reference in New Issue
Block a user