2022-07-06 22:24:08 +00:00
|
|
|
package com.imaginarycode.minecraft.redisbungee;
|
|
|
|
|
|
|
|
import com.velocitypowered.api.proxy.Player;
|
|
|
|
import com.velocitypowered.api.proxy.ServerConnection;
|
2022-07-26 13:47:18 +00:00
|
|
|
import redis.clients.jedis.UnifiedJedis;
|
2022-07-06 22:24:08 +00:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Optional;
|
|
|
|
|
2022-07-20 08:32:04 +00:00
|
|
|
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerJoinPayload;
|
|
|
|
|
|
|
|
public class VelocityPlayerUtils {
|
2022-07-26 13:47:18 +00:00
|
|
|
protected static void createPlayer(Player player, UnifiedJedis unifiedJedis, boolean fireEvent) {
|
2022-07-17 05:51:24 +00:00
|
|
|
Optional<ServerConnection> server = player.getCurrentServer();
|
2022-07-26 13:47:18 +00:00
|
|
|
server.ifPresent(serverConnection -> unifiedJedis.hset("player:" + player.getUniqueId().toString(), "server", serverConnection.getServerInfo().getName()));
|
2022-07-17 05:51:24 +00:00
|
|
|
|
|
|
|
Map<String, String> playerData = new HashMap<>(4);
|
|
|
|
playerData.put("online", "0");
|
|
|
|
playerData.put("ip", player.getRemoteAddress().getHostName());
|
2022-07-27 13:43:51 +00:00
|
|
|
playerData.put("proxy", AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId());
|
2022-07-06 22:24:08 +00:00
|
|
|
|
2022-07-27 13:43:51 +00:00
|
|
|
unifiedJedis.sadd("proxy:" + AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId() + ":usersOnline", player.getUniqueId().toString());
|
2022-07-26 13:47:18 +00:00
|
|
|
unifiedJedis.hmset("player:" + player.getUniqueId().toString(), playerData);
|
2022-07-17 05:51:24 +00:00
|
|
|
|
|
|
|
if (fireEvent) {
|
2022-07-26 13:47:18 +00:00
|
|
|
playerJoinPayload(player.getUniqueId(), unifiedJedis, player.getRemoteAddress().getAddress());
|
2022-07-17 05:51:24 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-06 22:24:08 +00:00
|
|
|
}
|