mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2025-03-09 14:15:31 +00:00
reimpl kick api using serialized messages instead, Move language to own module, depenedcies fixes
This commit is contained in:
parent
1d3bd7e101
commit
338297192c
@ -20,8 +20,6 @@ import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerJoinedNetworkEv
|
||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerLeftNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPubSubMessageEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisPipelineTask;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.json.JSONComponentSerializer;
|
||||
import org.json.JSONObject;
|
||||
import redis.clients.jedis.ClusterPipeline;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
@ -45,7 +43,6 @@ public abstract class PlayerDataManager<P> {
|
||||
private final LoadingCache<UUID, InetAddress> ipCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build(this::getIpAddressFromRedis);
|
||||
private final LoadingCache<UUID, Long> lastOnlineCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build(this::getLastOnlineFromRedis);
|
||||
private final LoadingCache<Object, Multimap<String, UUID>> serverToPlayersCache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).build(this::serversToPlayersBuilder);
|
||||
private final JSONComponentSerializer COMPONENT_SERIALIZER = JSONComponentSerializer.json();
|
||||
|
||||
public PlayerDataManager(RedisBungeePlugin<P> plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -99,50 +96,33 @@ public abstract class PlayerDataManager<P> {
|
||||
this.serverToPlayersCache.invalidate(SERVERS_TO_PLAYERS_KEY);
|
||||
}
|
||||
|
||||
|
||||
protected void handlePubSubMessageEvent(IPubSubMessageEvent event) {
|
||||
// kick api
|
||||
if (event.getChannel().equals("redisbungee-kick")) {
|
||||
JSONObject data = new JSONObject(event.getMessage());
|
||||
String proxy = data.getString("proxy");
|
||||
if (proxy.equals(this.proxyId)) {
|
||||
return;
|
||||
switch (event.getChannel()) {
|
||||
case "redisbungee-serverchange" -> {
|
||||
JSONObject data = new JSONObject(event.getMessage());
|
||||
UUID uuid = UUID.fromString(data.getString("uuid"));
|
||||
String from = null;
|
||||
if (data.has("from")) from = data.getString("from");
|
||||
String to = data.getString("to");
|
||||
plugin.fireEvent(plugin.createPlayerChangedServerNetworkEvent(uuid, from, to));
|
||||
}
|
||||
UUID uuid = UUID.fromString(data.getString("uuid"));
|
||||
String message = data.getString("message");
|
||||
plugin.handlePlatformKick(uuid, COMPONENT_SERIALIZER.deserialize(message));
|
||||
return;
|
||||
}
|
||||
if (event.getChannel().equals("redisbungee-serverchange")) {
|
||||
JSONObject data = new JSONObject(event.getMessage());
|
||||
String proxy = data.getString("proxy");
|
||||
if (proxy.equals(this.proxyId)) {
|
||||
return;
|
||||
case "redisbungee-player-join" -> {
|
||||
JSONObject data = new JSONObject(event.getMessage());
|
||||
UUID uuid = UUID.fromString(data.getString("uuid"));
|
||||
plugin.fireEvent(plugin.createPlayerJoinedNetworkEvent(uuid));
|
||||
}
|
||||
UUID uuid = UUID.fromString(data.getString("uuid"));
|
||||
String from = null;
|
||||
if (data.has("from")) from = data.getString("from");
|
||||
String to = data.getString("to");
|
||||
plugin.fireEvent(plugin.createPlayerChangedServerNetworkEvent(uuid, from, to));
|
||||
return;
|
||||
}
|
||||
if (event.getChannel().equals("redisbungee-player-join")) {
|
||||
JSONObject data = new JSONObject(event.getMessage());
|
||||
String proxy = data.getString("proxy");
|
||||
if (proxy.equals(this.proxyId)) {
|
||||
return;
|
||||
case "redisbungee-player-leave" -> {
|
||||
JSONObject data = new JSONObject(event.getMessage());
|
||||
UUID uuid = UUID.fromString(data.getString("uuid"));
|
||||
plugin.fireEvent(plugin.createPlayerLeftNetworkEvent(uuid));
|
||||
}
|
||||
UUID uuid = UUID.fromString(data.getString("uuid"));
|
||||
plugin.fireEvent(plugin.createPlayerJoinedNetworkEvent(uuid));
|
||||
return;
|
||||
}
|
||||
if (event.getChannel().equals("redisbungee-player-leave")) {
|
||||
JSONObject data = new JSONObject(event.getMessage());
|
||||
String proxy = data.getString("proxy");
|
||||
if (proxy.equals(this.proxyId)) {
|
||||
return;
|
||||
case "redisbungee-player-kick" -> {
|
||||
JSONObject data = new JSONObject(event.getMessage());
|
||||
UUID uuid = UUID.fromString(data.getString("uuid"));
|
||||
String message = data.getString("serialized-message");
|
||||
handleSerializedKick(uuid, message);
|
||||
}
|
||||
UUID uuid = UUID.fromString(data.getString("uuid"));
|
||||
plugin.fireEvent(plugin.createPlayerLeftNetworkEvent(uuid));
|
||||
}
|
||||
|
||||
}
|
||||
@ -158,14 +138,16 @@ public abstract class PlayerDataManager<P> {
|
||||
handleServerChangeRedis(uuid, to);
|
||||
}
|
||||
|
||||
public void kickPlayer(UUID uuid, Component message) {
|
||||
if (!plugin.handlePlatformKick(uuid, message)) { // handle locally before SENDING a message
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("proxy", this.proxyId);
|
||||
data.put("uuid", uuid);
|
||||
data.put("message", COMPONENT_SERIALIZER.serialize(message));
|
||||
plugin.proxyDataManager().sendChannelMessage("redisbungee-kick", data.toString());
|
||||
}
|
||||
// must check if player is on the local proxy
|
||||
protected abstract boolean handleSerializedKick(UUID player, String serializedMessage);
|
||||
|
||||
public void serializedPlayerKick(UUID player, String serializedMessage) {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("proxy", this.proxyId);
|
||||
data.put("uuid", player);
|
||||
data.put("serialized-message", serializedMessage);
|
||||
if (!handleSerializedKick(player, serializedMessage))
|
||||
plugin.proxyDataManager().sendChannelMessage("redisbungee-player-kick", data.toString());
|
||||
}
|
||||
|
||||
private void handleServerChangeRedis(UUID uuid, String server) {
|
||||
|
@ -103,7 +103,6 @@ public abstract class ProxyDataManager implements Runnable {
|
||||
|
||||
public synchronized void sendChannelMessage(String channel, String message) {
|
||||
if (isClosed()) return;
|
||||
this.plugin.fireEvent(this.plugin.createPubSubEvent(channel, message));
|
||||
publishPayload(new PubSubPayload(this.proxyId, channel, message));
|
||||
}
|
||||
|
||||
|
@ -11,12 +11,10 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.api;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.LangConfiguration;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.events.EventsPlatform;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDTranslator;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.UUID;
|
||||
@ -55,8 +53,6 @@ public interface RedisBungeePlugin<P> extends EventsPlatform {
|
||||
|
||||
RedisBungeeConfiguration configuration();
|
||||
|
||||
LangConfiguration langConfiguration();
|
||||
|
||||
Summoner<?> getSummoner();
|
||||
|
||||
RedisBungeeMode getRedisBungeeMode();
|
||||
@ -77,11 +73,8 @@ public interface RedisBungeePlugin<P> extends EventsPlatform {
|
||||
|
||||
UUID getPlayerUUID(String player);
|
||||
|
||||
|
||||
String getPlayerName(UUID player);
|
||||
|
||||
boolean handlePlatformKick(UUID uuid, Component message);
|
||||
|
||||
String getPlayerServerName(P player);
|
||||
|
||||
boolean isPlayerOnAServer(P player);
|
||||
|
@ -5,6 +5,9 @@ plugins {
|
||||
dependencies {
|
||||
compileOnly(project(":RedisBungee-API"))
|
||||
implementation(libs.acf.core)
|
||||
compileOnly(libs.adventure.api)
|
||||
compileOnly(libs.adventure.miniMessage)
|
||||
compileOnly(libs.adventure.gson)
|
||||
}
|
||||
|
||||
description = "RedisBungee common commands"
|
||||
|
@ -33,16 +33,16 @@ public class CommandRedisBungeeDebug extends AdventureBaseCommand {
|
||||
@Description("kicks a player from the network by name")
|
||||
@Private
|
||||
public void kick(CommandIssuer issuer, String playerName) {
|
||||
|
||||
plugin.getAbstractRedisBungeeApi().kickPlayer(playerName, Component.text("debug kick"));
|
||||
String message = serializeMessage(Component.text("kicked using redisbungee api using name"));
|
||||
plugin.playerDataManager().serializedPlayerKick(plugin.getUuidTranslator().getTranslatedUuid(playerName, false), message);
|
||||
}
|
||||
|
||||
@Subcommand("kickByUUID")
|
||||
@Description("kicks a player from the network by UUID")
|
||||
@Private
|
||||
public void kick(CommandIssuer issuer, UUID uuid) {
|
||||
|
||||
plugin.getAbstractRedisBungeeApi().kickPlayer(uuid, Component.text("debug kick"));
|
||||
String message = serializeMessage(Component.text("kicked using redisbungee api using uuid"));
|
||||
plugin.playerDataManager().serializedPlayerKick(uuid, message);
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,14 +13,21 @@ package com.imaginarycode.minecraft.redisbungee.commands.utils;
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
/**
|
||||
* this just dumb class that wraps the adventure stuff into base command
|
||||
*/
|
||||
public abstract class AdventureBaseCommand extends BaseCommand {
|
||||
|
||||
public static void sendMessage(CommandIssuer issuer, Component component) {
|
||||
protected void sendMessage(CommandIssuer issuer, Component component) {
|
||||
CommandPlatformHelper.getPlatformHelper().sendMessage(issuer, component);
|
||||
}
|
||||
|
||||
private static final GsonComponentSerializer COMPONENT_SERIALIZER = GsonComponentSerializer.gson();
|
||||
|
||||
protected String serializeMessage(Component message) {
|
||||
return COMPONENT_SERIALIZER.serialize(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
49
lang/build.gradle.kts
Normal file
49
lang/build.gradle.kts
Normal file
@ -0,0 +1,49 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":RedisBungee-API"))
|
||||
compileOnly(libs.adventure.api)
|
||||
compileOnly(libs.adventure.miniMessage)
|
||||
}
|
||||
|
||||
description = "RedisBungee languages"
|
||||
|
||||
java {
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
tasks {
|
||||
// thanks again for paper too
|
||||
withType<Javadoc> {
|
||||
val options = options as StandardJavadocDocletOptions
|
||||
options.use()
|
||||
options.isDocFilesSubDirs = true
|
||||
val adventureVersion = libs.adventure.plain.get().version
|
||||
options.links(
|
||||
"https://jd.advntr.dev/api/$adventureVersion"
|
||||
)
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
options.release.set(17)
|
||||
}
|
||||
javadoc {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
}
|
||||
processResources {
|
||||
filteringCharset = Charsets.UTF_8.name()
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("maven") {
|
||||
from(components["java"])
|
||||
}
|
||||
}
|
||||
}
|
@ -8,10 +8,10 @@
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
|
||||
package com.imaginarycode.minecraft.redisbungee.api.config.loaders;
|
||||
package net.limework.valiobungee.config.lang;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.LangConfiguration;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.loaders.GenericConfigLoader;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
@ -8,7 +8,7 @@
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
|
||||
package com.imaginarycode.minecraft.redisbungee.api.config;
|
||||
package net.limework.valiobungee.config.lang;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
@ -12,7 +12,6 @@ package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.PlayerDataManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerJoinedNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent;
|
||||
@ -75,7 +74,7 @@ public class BungeePlayerDataManager extends PlayerDataManager<ProxiedPlayer> im
|
||||
event.completeIntent((Plugin) plugin);
|
||||
} else {
|
||||
if (plugin.configuration().kickWhenOnline()) {
|
||||
kickPlayer(event.getConnection().getUniqueId(), plugin.langConfiguration().messages().loggedInFromOtherLocation());
|
||||
serializedPlayerKick(event.getConnection().getUniqueId(), plugin.langConfiguration().messages().loggedInFromOtherLocation());
|
||||
// wait 3 seconds before releasing the event
|
||||
plugin.executeAsyncAfter(() -> event.completeIntent((Plugin) plugin), TimeUnit.SECONDS, 3);
|
||||
} else {
|
||||
|
@ -46,8 +46,6 @@ import redis.clients.jedis.JedisPool;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetAddress;
|
||||
import java.sql.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
@ -10,6 +10,7 @@ dependencies {
|
||||
annotationProcessor(libs.platform.velocity)
|
||||
implementation(project(":RedisBungee-Commands"))
|
||||
implementation(libs.acf.velocity)
|
||||
implementation(project(":RedisBungee-Lang"))
|
||||
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,9 @@ import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.MultiMa
|
||||
|
||||
public class RedisBungeeListener {
|
||||
|
||||
private final RedisBungeePlugin<Player> plugin;
|
||||
private final RedisBungeeVelocityPlugin plugin;
|
||||
|
||||
public RedisBungeeListener(RedisBungeePlugin<Player> plugin) {
|
||||
public RedisBungeeListener(RedisBungeeVelocityPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
@ -18,18 +18,14 @@ import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.CommandLoader;
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.utils.CommandPlatformHelper;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.LangConfiguration;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.loaders.ConfigLoader;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.loaders.LangConfigLoader;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerChangedServerNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerJoinedNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerLeftNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPubSubMessageEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.InitialUtils;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.NameFetcher;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDFetcher;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDTranslator;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent;
|
||||
@ -48,6 +44,8 @@ import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.limework.valiobungee.config.lang.LangConfiguration;
|
||||
import net.limework.valiobungee.config.lang.LangConfigLoader;
|
||||
import org.slf4j.Logger;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
|
||||
@ -55,18 +53,15 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.Date;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Plugin(id = "redisbungee", name = "RedisBungee", version = Constants.VERSION, url = "https://github.com/ProxioDev/RedisBungee", authors = {"astei", "ProxioDev"})
|
||||
public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, ConfigLoader, LangConfigLoader, ServerObjectFetcher {
|
||||
public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, ConfigLoader, LangConfigLoader, ApiPlatformSupport {
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
private final Path dataFolder;
|
||||
@ -208,7 +203,6 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, Con
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LangConfiguration langConfiguration() {
|
||||
return this.langConfiguration;
|
||||
}
|
||||
@ -233,15 +227,6 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, Con
|
||||
return this.getProxy().getPlayer(player).map(Player::getUsername).orElse(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean handlePlatformKick(UUID uuid, Component message) {
|
||||
Player player = getPlayer(uuid);
|
||||
if (player == null) return false;
|
||||
player.disconnect(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerServerName(Player player) {
|
||||
return player.getCurrentServer().map(serverConnection -> serverConnection.getServerInfo().getName()).orElse(null);
|
||||
@ -356,6 +341,11 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, Con
|
||||
return server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kickPlayer(UUID player, Component message) {
|
||||
this.playerDataManager.kickPlayer(player, message);
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
@ -11,8 +11,6 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.PlayerDataManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent;
|
||||
@ -26,12 +24,18 @@ import com.velocitypowered.api.event.connection.PostLoginEvent;
|
||||
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class VelocityPlayerDataManager extends PlayerDataManager<Player> {
|
||||
public VelocityPlayerDataManager(RedisBungeePlugin<Player> plugin) {
|
||||
|
||||
private final RedisBungeeVelocityPlugin vplugin;
|
||||
|
||||
public VelocityPlayerDataManager(RedisBungeeVelocityPlugin plugin) {
|
||||
super(plugin);
|
||||
this.vplugin = plugin;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@ -66,6 +70,36 @@ public class VelocityPlayerDataManager extends PlayerDataManager<Player> {
|
||||
super.playerChangedServer(event.getPlayer().getUniqueId(), oldServer, currentServer);
|
||||
}
|
||||
|
||||
private final GsonComponentSerializer COMPONENT_SERIALIZER = GsonComponentSerializer.gson();
|
||||
|
||||
@Override
|
||||
public boolean handleSerializedKick(UUID uuid, String serializedMessage) {
|
||||
Player player = plugin.getPlayer(uuid);
|
||||
if (player == null) return false;
|
||||
// decode the adventure component
|
||||
if (serializedMessage == null || serializedMessage.isEmpty()) {
|
||||
// kick the player too even if the message is invalid
|
||||
player.disconnect(Component.empty());
|
||||
plugin.logWarn("unable to decode serialized adventure component because its empty or null");
|
||||
} else {
|
||||
try {
|
||||
Component message = COMPONENT_SERIALIZER.deserialize(serializedMessage);
|
||||
player.disconnect(message);
|
||||
} catch (Exception e) {
|
||||
plugin.logFatal("Kick message is invalid", e);
|
||||
plugin.logFatal("The serialized kick message:");
|
||||
plugin.logFatal(serializedMessage);
|
||||
// kick the player too even if the message is invalid
|
||||
player.disconnect(Component.empty());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void kickPlayer(UUID player, Component message) {
|
||||
serializedPlayerKick(player, COMPONENT_SERIALIZER.serialize(message));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onLoginEvent(LoginEvent event, Continuation continuation) {
|
||||
// check if online
|
||||
@ -77,11 +111,11 @@ public class VelocityPlayerDataManager extends PlayerDataManager<Player> {
|
||||
continuation.resume();
|
||||
} else {
|
||||
if (plugin.configuration().kickWhenOnline()) {
|
||||
kickPlayer(event.getPlayer().getUniqueId(), plugin.langConfiguration().messages().loggedInFromOtherLocation());
|
||||
kickPlayer(event.getPlayer().getUniqueId(), vplugin.langConfiguration().messages().loggedInFromOtherLocation());
|
||||
// wait 3 seconds before releasing the event
|
||||
plugin.executeAsyncAfter(continuation::resume, TimeUnit.SECONDS, 3);
|
||||
} else {
|
||||
event.setResult(ResultedEvent.ComponentResult.denied(plugin.langConfiguration().messages().alreadyLoggedIn()));
|
||||
event.setResult(ResultedEvent.ComponentResult.denied(vplugin.langConfiguration().messages().alreadyLoggedIn()));
|
||||
continuation.resume();
|
||||
}
|
||||
}
|
||||
|
@ -10,15 +10,9 @@ dependencies {
|
||||
exclude("com.google.code.gson", "gson")
|
||||
exclude("org.spongepowered", "configurate-yaml")
|
||||
exclude("com.github.ben-manes.caffeine", "caffeine")
|
||||
// exclude also adventure api
|
||||
exclude("net.kyori", "adventure-api")
|
||||
exclude("net.kyori", "adventure-text-serializer-gson")
|
||||
exclude("net.kyori", "adventure-text-serializer-legacy")
|
||||
exclude("net.kyori", "adventure-text-serializer-plain")
|
||||
exclude("net.kyori", "adventure-text-minimessage")
|
||||
}
|
||||
implementation(project(":RedisBungee-Lang"))
|
||||
compileOnly(libs.platform.velocity)
|
||||
|
||||
}
|
||||
|
||||
description = "RedisBungee Velocity API"
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2013-present RedisBungee contributors
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
// this class used to redirect calls to keep the implementation and api separate
|
||||
public interface ApiPlatformSupport {
|
||||
|
||||
ProxyServer getProxy();
|
||||
|
||||
void kickPlayer(UUID Player, Component message);
|
||||
|
||||
}
|
@ -50,7 +50,7 @@ public class RedisBungeeAPI extends AbstractRedisBungeeAPI {
|
||||
public final ServerInfo getServerFor(@NonNull UUID player) {
|
||||
String serverName = this.getServerNameFor(player);
|
||||
if (serverName == null) return null;
|
||||
return ((ServerObjectFetcher) this.plugin).getProxy().getServer(serverName).map((RegisteredServer::getServerInfo)).orElse(null);
|
||||
return ((ApiPlatformSupport) this.plugin).getProxy().getServer(serverName).map((RegisteredServer::getServerInfo)).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,7 +73,7 @@ public class RedisBungeeAPI extends AbstractRedisBungeeAPI {
|
||||
* @since 0.12.0
|
||||
*/
|
||||
public void kickPlayer(UUID playerUUID, Component message) {
|
||||
this.plugin.playerDataManager().kickPlayer(playerUUID, message);
|
||||
((ApiPlatformSupport) this.plugin).kickPlayer(playerUUID, message);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,10 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
||||
public interface ServerObjectFetcher {
|
||||
|
||||
ProxyServer getProxy();
|
||||
|
||||
|
||||
}
|
@ -13,6 +13,7 @@ fun configureProject(name: String, path: String) {
|
||||
}
|
||||
|
||||
configureProject(":RedisBungee-API", "api")
|
||||
configureProject(":RedisBungee-Lang", "lang")
|
||||
configureProject(":RedisBungee-Commands", "commands")
|
||||
|
||||
configureProject(":RedisBungee-Bungee", "proxies/bungeecord/bungeecord-api")
|
||||
|
Loading…
Reference in New Issue
Block a user