mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2026-05-15 17:26:51 +00:00
finishup bungeecord, move to mini message as serialzier
This commit is contained in:
+34
-3
@@ -16,7 +16,10 @@ import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetwork
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.LoginEvent;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
@@ -26,13 +29,16 @@ import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
public class BungeePlayerDataManager extends PlayerDataManager<ProxiedPlayer> implements Listener {
|
||||
|
||||
public BungeePlayerDataManager(RedisBungeePlugin<ProxiedPlayer> plugin) {
|
||||
private final RedisBungee bPlugin;
|
||||
public BungeePlayerDataManager(RedisBungee plugin) {
|
||||
super(plugin);
|
||||
bPlugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -62,6 +68,29 @@ public class BungeePlayerDataManager extends PlayerDataManager<ProxiedPlayer> im
|
||||
super.playerChangedServer(event.getPlayer().getUniqueId(), oldServer, currentServer);
|
||||
}
|
||||
|
||||
private final BungeeComponentSerializer BUNGEE_COMPONENT_SERIALIZER = BungeeComponentSerializer.get();
|
||||
|
||||
private final static MiniMessage MINI_MESSAGE_SERIALIZER = MiniMessage.miniMessage();
|
||||
@Override
|
||||
public boolean handleSerializedKick(UUID uuid, String serializedMiniMessage) {
|
||||
ProxiedPlayer player = plugin.getPlayer(uuid);
|
||||
if (player == null) return false;
|
||||
// decode the adventure component
|
||||
if (serializedMiniMessage == null) {
|
||||
// kick the player too even if the message is invalid
|
||||
player.disconnect(BUNGEE_COMPONENT_SERIALIZER.serialize(Component.empty()));
|
||||
plugin.logWarn("unable to decode serialized adventure component because its empty or null");
|
||||
} else {
|
||||
Component message = MINI_MESSAGE_SERIALIZER.deserialize(serializedMiniMessage);
|
||||
player.disconnect(BUNGEE_COMPONENT_SERIALIZER.serialize(message));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void kickPlayer(UUID player, Component message) {
|
||||
serializedPlayerKick(player, MINI_MESSAGE_SERIALIZER.serialize(message));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLoginEvent(LoginEvent event) {
|
||||
event.registerIntent((Plugin) plugin);
|
||||
@@ -74,12 +103,12 @@ public class BungeePlayerDataManager extends PlayerDataManager<ProxiedPlayer> im
|
||||
event.completeIntent((Plugin) plugin);
|
||||
} else {
|
||||
if (plugin.configuration().kickWhenOnline()) {
|
||||
serializedPlayerKick(event.getConnection().getUniqueId(), plugin.langConfiguration().messages().loggedInFromOtherLocation());
|
||||
kickPlayer(event.getConnection().getUniqueId(), bPlugin.langConfiguration().messages().loggedInFromOtherLocation());
|
||||
// wait 3 seconds before releasing the event
|
||||
plugin.executeAsyncAfter(() -> event.completeIntent((Plugin) plugin), TimeUnit.SECONDS, 3);
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
event.setCancelReason(BungeeComponentSerializer.get().serialize(plugin.langConfiguration().messages().alreadyLoggedIn()));
|
||||
event.setCancelReason(BungeeComponentSerializer.get().serialize(bPlugin.langConfiguration().messages().alreadyLoggedIn()));
|
||||
event.completeIntent((Plugin) plugin);
|
||||
}
|
||||
}
|
||||
@@ -89,11 +118,13 @@ public class BungeePlayerDataManager extends PlayerDataManager<ProxiedPlayer> im
|
||||
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onLoginEvent(PostLoginEvent event) {
|
||||
super.addPlayer(event.getPlayer().getUniqueId(), event.getPlayer().getName(), event.getPlayer().getAddress().getAddress());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onDisconnectEvent(PlayerDisconnectEvent event) {
|
||||
super.removePlayer(event.getPlayer().getUniqueId());
|
||||
|
||||
+8
-33
@@ -15,10 +15,8 @@ import com.imaginarycode.minecraft.redisbungee.api.PlayerDataManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.ProxyDataManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
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;
|
||||
@@ -33,7 +31,8 @@ import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.limework.valiobungee.config.lang.LangConfigLoader;
|
||||
import net.limework.valiobungee.config.lang.LangConfiguration;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
@@ -41,7 +40,6 @@ import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -53,9 +51,8 @@ import java.util.concurrent.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlayer>, ConfigLoader, LangConfigLoader {
|
||||
public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlayer>, ConfigLoader, LangConfigLoader, ApiPlatformSupport {
|
||||
|
||||
private static RedisBungeeAPI apiStatic;
|
||||
private AbstractRedisBungeeAPI api;
|
||||
private RedisBungeeMode redisBungeeMode;
|
||||
private ProxyDataManager proxyDataManager;
|
||||
@@ -76,7 +73,6 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LangConfiguration langConfiguration() {
|
||||
return this.langConfiguration;
|
||||
}
|
||||
@@ -161,15 +157,6 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
||||
return this.getProxy().getPlayer(player).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePlatformKick(UUID uuid, Component message) {
|
||||
ProxiedPlayer player = getPlayer(uuid);
|
||||
if (player == null) return false;
|
||||
if (!player.isConnected()) return false;
|
||||
player.disconnect(BungeeComponentSerializer.get().serialize(message));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerServerName(ProxiedPlayer player) {
|
||||
return player.getServer().getInfo().getName();
|
||||
@@ -243,7 +230,6 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
||||
|
||||
// init the api
|
||||
this.api = new RedisBungeeAPI(this);
|
||||
apiStatic = (RedisBungeeAPI) this.api;
|
||||
|
||||
// commands
|
||||
CommandPlatformHelper.init(new BungeeCommandPlatformHelper());
|
||||
@@ -337,22 +323,6 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
||||
this.summoner = summoner;
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns an instance of {@link RedisBungeeAPI}
|
||||
*
|
||||
* @return the {@link AbstractRedisBungeeAPI} object instance.
|
||||
* @deprecated Please use {@link RedisBungeeAPI#getRedisBungeeApi()} this class intended to for old plugins that no longer updated.
|
||||
*/
|
||||
@Deprecated
|
||||
public static RedisBungeeAPI getApi() {
|
||||
return apiStatic;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public JedisPool getPool() {
|
||||
return api.getJedisPool();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLangConfigLoad(LangConfiguration langConfiguration) {
|
||||
this.langConfiguration = langConfiguration;
|
||||
@@ -362,4 +332,9 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
||||
public String platformId() {
|
||||
return "bungeecord";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kickPlayer(UUID player, Component message) {
|
||||
this.playerDataManager.kickPlayer(player, message);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -37,9 +37,9 @@ import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.MultiMa
|
||||
|
||||
public class RedisBungeeListener implements Listener {
|
||||
|
||||
private final RedisBungeePlugin<ProxiedPlayer> plugin;
|
||||
private final RedisBungee plugin;
|
||||
|
||||
public RedisBungeeListener(RedisBungeePlugin<ProxiedPlayer> plugin) {
|
||||
public RedisBungeeListener(RedisBungee plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user