From 26ad0eb17675b63d86a683592839a01540aeabfb Mon Sep 17 00:00:00 2001 From: Nathan Martin <63524975+nathan-i-martin@users.noreply.github.com> Date: Wed, 18 Oct 2023 19:35:56 -0400 Subject: [PATCH] Fix some things, make MySQL bootable --- .../implementors/redis/RedisConnector.java | 2 +- .../plugin/velocity/central/Flame.java | 2 +- .../central/command/CommandRusty.java | 522 +++++++++--------- .../events/OnPlayerChooseInitialServer.java | 9 +- .../velocity/events/OnPlayerDisconnect.java | 4 +- .../velocity/lib/family/ResolvableFamily.java | 27 + .../lib/family/bases/BaseServerFamily.java | 2 + .../bases/PlayerFocusedServerFamily.java | 7 + .../lib/family/config/FamiliesConfig.java | 13 +- .../static_family/ResidenceDataEnclave.java | 21 +- .../family/static_family/ServerResidence.java | 166 ++---- .../static_family/StaticServerFamily.java | 34 +- .../viewport/endpoints/GetFamilyEndpoint.java | 2 +- .../velocity/lib/friends/FriendMapping.java | 18 +- .../velocity/lib/friends/FriendRequest.java | 12 +- .../lib/friends/FriendsDataEnclave.java | 12 +- .../velocity/lib/friends/FriendsService.java | 28 +- .../lib/friends/commands/CommandFM.java | 8 +- .../lib/friends/commands/CommandFriends.java | 17 +- .../lib/friends/commands/CommandUnFriend.java | 11 +- .../velocity/lib/lang/VelocityLang.java | 4 +- .../velocity/lib/parties/PartyInvite.java | 14 +- .../velocity/lib/parties/PartyService.java | 4 +- .../lib/parties/commands/CommandParty.java | 10 +- .../velocity/lib/players/PlayerService.java | 9 +- ...{FakePlayer.java => ResolvablePlayer.java} | 14 +- .../velocity/lib/server/PlayerServer.java | 6 +- .../velocity/lib/server/ResolvableServer.java | 29 + .../velocity/lib/server/ServerService.java | 11 + .../events/ServerPlayerCountEvent.java | 2 +- .../velocity/lib/storage/MySQLStorage.java | 6 +- .../velocity/lib/storage/StorageRoot.java | 6 +- 32 files changed, 529 insertions(+), 503 deletions(-) create mode 100644 plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/ResolvableFamily.java rename plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/players/{FakePlayer.java => ResolvablePlayer.java} (68%) create mode 100644 plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/ResolvableServer.java diff --git a/plugin/core/src/main/java/group/aelysium/rustyconnector/core/lib/messenger/implementors/redis/RedisConnector.java b/plugin/core/src/main/java/group/aelysium/rustyconnector/core/lib/messenger/implementors/redis/RedisConnector.java index 7434e829d..fa2887980 100644 --- a/plugin/core/src/main/java/group/aelysium/rustyconnector/core/lib/messenger/implementors/redis/RedisConnector.java +++ b/plugin/core/src/main/java/group/aelysium/rustyconnector/core/lib/messenger/implementors/redis/RedisConnector.java @@ -24,7 +24,7 @@ private RedisConnector(AESCryptor cryptor, PacketOrigin origin, InetSocketAddres @Override public RedisConnection connect() throws ConnectException { this.connection = new RedisConnection( - origin, + origin, this.toClientBuilder(), this.cryptor ); diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/Flame.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/Flame.java index 92afdec4f..b1088f021 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/Flame.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/Flame.java @@ -323,7 +323,7 @@ public DependencyInjector.DI2 connectors(Dependenc messenger.connect(); MessengerConnection connection = messenger.connection().orElseThrow(); connection.startListening(dependencies.d2(), dependencies.d3(), handlers); - bootOutput.add(Component.text("Finished booting CMessenger.", NamedTextColor.GREEN)); + bootOutput.add(Component.text("Finished booting Messenger.", NamedTextColor.GREEN)); MySQLStorage storage = MySQLStorage.create( config.getMysql_address(), diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/command/CommandRusty.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/command/CommandRusty.java index b817b37e5..530a0c7fd 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/command/CommandRusty.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/command/CommandRusty.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.LongArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.tree.LiteralCommandNode; @@ -41,80 +42,103 @@ public static BrigadierCommand create(DependencyInjector.DI3literal("message") - .executes(context -> { - logger.send(VelocityLang.RC_MESSAGE_ROOT_USAGE); - return Command.SINGLE_SUCCESS; - }) - .then(LiteralArgumentBuilder.literal("list") - .executes(context -> { - new Thread(() -> { - try { - if(messageCacheService.size() > 10) { - int numberOfPages = Math.floorDiv(messageCacheService.size(),10) + 1; + .then(Message.build(flame, logger, messageCacheService)) + .then(Family.build(flame, logger, messageCacheService)) + .then(Send.build(flame, logger, messageCacheService)) + .then(Debug.build(flame, logger, messageCacheService)) + .then(Reload.build(flame, logger, messageCacheService)) + .build(); + + // BrigadierCommand implements Command + return new BrigadierCommand(rusty); + } +} + +class Message { + public static ArgumentBuilder build(Flame flame, PluginLogger logger, MessageCacheService messageCacheService) { + return LiteralArgumentBuilder.literal("message") + .executes(context -> { + logger.send(VelocityLang.RC_MESSAGE_ROOT_USAGE); + return Command.SINGLE_SUCCESS; + }) + .then(listMessages(flame, logger, messageCacheService)) + .then(getMessage(flame, logger, messageCacheService)); + } - List messagesPage = messageCacheService.fetchMessagesPage(1); + private static ArgumentBuilder listMessages(Flame flame, PluginLogger logger, MessageCacheService messageCacheService) { + return LiteralArgumentBuilder.literal("list") + .executes(context -> { + new Thread(() -> { + try { + if(messageCacheService.size() > 10) { + int numberOfPages = Math.floorDiv(messageCacheService.size(),10) + 1; - VelocityLang.RC_MESSAGE_PAGE.send(logger,messagesPage,1,numberOfPages); + List messagesPage = messageCacheService.fetchMessagesPage(1); - return; - } + VelocityLang.RC_MESSAGE_PAGE.send(logger,messagesPage,1,numberOfPages); - List messages = messageCacheService.messages(); + return; + } - VelocityLang.RC_MESSAGE_PAGE.send(logger,messages,1,1); + List messages = messageCacheService.messages(); - } catch (Exception e) { - VelocityLang.RC_MESSAGE_ERROR.send(logger,"There was an issue getting those messages!\n"+e.getMessage()); - } - }).start(); - - return Command.SINGLE_SUCCESS; - }) - .then(RequiredArgumentBuilder.argument("page-number", IntegerArgumentType.integer()) - .executes(context -> { - new Thread(() -> { - try { - int pageNumber = context.getArgument("page-number", Integer.class); - - List messages = messageCacheService.fetchMessagesPage(pageNumber); - - int numberOfPages = Math.floorDiv(messageCacheService.size(),10) + 1; - - VelocityLang.RC_MESSAGE_PAGE.send(logger,messages,pageNumber,numberOfPages); - } catch (Exception e) { - VelocityLang.RC_MESSAGE_ERROR.send(logger,"There was an issue getting that page!\n"+e.getMessage()); - } - - }).start(); - return Command.SINGLE_SUCCESS; - }) - ) - ) - .then(LiteralArgumentBuilder.literal("get") - .executes(context -> { - logger.send(VelocityLang.RC_MESSAGE_GET_USAGE); - - return Command.SINGLE_SUCCESS; - }) - .then(RequiredArgumentBuilder.argument("snowflake", LongArgumentType.longArg()) - .executes(context -> { - try { - Long snowflake = context.getArgument("snowflake", Long.class); - - CacheableMessage message = messageCacheService.findMessage(snowflake); - - VelocityLang.RC_MESSAGE_GET_MESSAGE.send(logger, message); - } catch (Exception e) { - VelocityLang.RC_MESSAGE_ERROR.send(logger,"There's no saved message with that ID!"); - } + VelocityLang.RC_MESSAGE_PAGE.send(logger,messages,1,1); + + } catch (Exception e) { + VelocityLang.RC_MESSAGE_ERROR.send(logger,"There was an issue getting those messages!\n"+e.getMessage()); + } + }).start(); + + return Command.SINGLE_SUCCESS; + }) + .then(RequiredArgumentBuilder.argument("page-number", IntegerArgumentType.integer()) + .executes(context -> { + new Thread(() -> { + try { + int pageNumber = context.getArgument("page-number", Integer.class); + + List messages = messageCacheService.fetchMessagesPage(pageNumber); + + int numberOfPages = Math.floorDiv(messageCacheService.size(),10) + 1; + + VelocityLang.RC_MESSAGE_PAGE.send(logger,messages,pageNumber,numberOfPages); + } catch (Exception e) { + VelocityLang.RC_MESSAGE_ERROR.send(logger,"There was an issue getting that page!\n"+e.getMessage()); + } + + }).start(); + return Command.SINGLE_SUCCESS; + }) + ); + } + + private static ArgumentBuilder getMessage(Flame flame, PluginLogger logger, MessageCacheService messageCacheService) { + return LiteralArgumentBuilder.literal("get") + .executes(context -> { + logger.send(VelocityLang.RC_MESSAGE_GET_USAGE); + + return Command.SINGLE_SUCCESS; + }) + .then(RequiredArgumentBuilder.argument("snowflake", LongArgumentType.longArg()) + .executes(context -> { + try { + Long snowflake = context.getArgument("snowflake", Long.class); - return Command.SINGLE_SUCCESS; - }) - ) - ) - ) - .then(LiteralArgumentBuilder.literal("family") + CacheableMessage message = messageCacheService.findMessage(snowflake); + + VelocityLang.RC_MESSAGE_GET_MESSAGE.send(logger, message); + } catch (Exception e) { + VelocityLang.RC_MESSAGE_ERROR.send(logger,"There's no saved message with that ID!"); + } + + return Command.SINGLE_SUCCESS; + }) + ); + } +} +class Family { + public static ArgumentBuilder build(Flame flame, PluginLogger logger, MessageCacheService messageCacheService) { + return LiteralArgumentBuilder.literal("family") .executes(context -> { try { VelocityLang.RC_FAMILY.send(logger); @@ -142,197 +166,203 @@ public static BrigadierCommand create(DependencyInjector.DI3literal("resetIndex") - .executes(context -> { - try { - String familyName = context.getArgument("familyName", String.class); - BaseServerFamily family = flame.services().familyService().find(familyName); - if(family == null) throw new NullPointerException(); - if(!(family instanceof PlayerFocusedServerFamily)) { - VelocityLang.RC_FAMILY_ERROR.send(logger,"You can only resetIndex on scalar and static families!"); - return Command.SINGLE_SUCCESS; - } + .then(resetIndex(flame, logger, messageCacheService)) + .then(sort(flame, logger, messageCacheService)) + .then(locked(flame, logger, messageCacheService)) + ); + } + + private static ArgumentBuilder resetIndex(Flame flame, PluginLogger logger, MessageCacheService messageCacheService) { + return LiteralArgumentBuilder.literal("resetIndex") + .executes(context -> { + try { + String familyName = context.getArgument("familyName", String.class); + BaseServerFamily family = flame.services().familyService().find(familyName); + if(family == null) throw new NullPointerException(); + if(!(family instanceof PlayerFocusedServerFamily)) { + VelocityLang.RC_FAMILY_ERROR.send(logger,"You can only resetIndex on scalar and static families!"); + return Command.SINGLE_SUCCESS; + } - ((PlayerFocusedServerFamily) family).loadBalancer().resetIndex(); + ((PlayerFocusedServerFamily) family).loadBalancer().resetIndex(); - if(family instanceof ScalarServerFamily) - VelocityLang.RC_SCALAR_FAMILY_INFO.send(logger, (ScalarServerFamily) family); - if(family instanceof StaticServerFamily) - VelocityLang.RC_STATIC_FAMILY_INFO.send(logger, (StaticServerFamily) family); - } catch (NullPointerException e) { - VelocityLang.RC_FAMILY_ERROR.send(logger,"A family with that name doesn't exist!"); - } catch (Exception e) { - VelocityLang.RC_FAMILY_ERROR.send(logger,"Something prevented us from doing that!\n"+e.getMessage()); - } + if(family instanceof ScalarServerFamily) + VelocityLang.RC_SCALAR_FAMILY_INFO.send(logger, (ScalarServerFamily) family); + if(family instanceof StaticServerFamily) + VelocityLang.RC_STATIC_FAMILY_INFO.send(logger, (StaticServerFamily) family); + } catch (NullPointerException e) { + VelocityLang.RC_FAMILY_ERROR.send(logger,"A family with that name doesn't exist!"); + } catch (Exception e) { + VelocityLang.RC_FAMILY_ERROR.send(logger,"Something prevented us from doing that!\n"+e.getMessage()); + } + return Command.SINGLE_SUCCESS; + }); + } + + private static ArgumentBuilder sort(Flame flame, PluginLogger logger, MessageCacheService messageCacheService) { + return LiteralArgumentBuilder.literal("sort") + .executes(context -> { + try { + String familyName = context.getArgument("familyName", String.class); + BaseServerFamily family = flame.services().familyService().find(familyName); + if(family == null) throw new NullPointerException(); + if(!(family instanceof PlayerFocusedServerFamily)) { + VelocityLang.RC_FAMILY_ERROR.send(logger,"You can only use sort on scalar and static families!"); + return Command.SINGLE_SUCCESS; + } + + ((PlayerFocusedServerFamily) family).loadBalancer().completeSort(); + + if(family instanceof ScalarServerFamily) + VelocityLang.RC_SCALAR_FAMILY_INFO.send(logger, (ScalarServerFamily) family); + if(family instanceof StaticServerFamily) + VelocityLang.RC_STATIC_FAMILY_INFO.send(logger, (StaticServerFamily) family); + } catch (NullPointerException e) { + VelocityLang.RC_FAMILY_ERROR.send(logger,"A family with that name doesn't exist!"); + } catch (Exception e) { + VelocityLang.RC_FAMILY_ERROR.send(logger,"Something prevented us from doing that!\n"+e.getMessage()); + } + return 1; + }); + } + + private static ArgumentBuilder locked(Flame flame, PluginLogger logger, MessageCacheService messageCacheService) { + return LiteralArgumentBuilder.literal("locked") + .executes(context -> { + try { + String familyName = context.getArgument("familyName", String.class); + BaseServerFamily family = flame.services().familyService().find(familyName); + if(family == null) throw new NullPointerException(); + + if(family instanceof ScalarServerFamily) + VelocityLang.RC_SCALAR_FAMILY_INFO_LOCKED.send(logger, (ScalarServerFamily) family); + if(family instanceof StaticServerFamily) + VelocityLang.RC_STATIC_FAMILY_INFO_LOCKED.send(logger, (StaticServerFamily) family); + } catch (NullPointerException e) { + VelocityLang.RC_FAMILY_ERROR.send(logger,"A family with that name doesn't exist!"); + } catch (Exception e) { + VelocityLang.RC_FAMILY_ERROR.send(logger,"Something prevented us from doing that!\n"+e.getMessage()); + } + return 1; + }); + } +} +class Send { + public static ArgumentBuilder build(Flame flame, PluginLogger logger, MessageCacheService messageCacheService) { + return LiteralArgumentBuilder.literal("send") + .executes(context -> { + logger.send(VelocityLang.RC_SEND_USAGE); + return Command.SINGLE_SUCCESS; + }) + .then(defaultSender(flame, logger, messageCacheService)) + .then(serverSender(flame, logger, messageCacheService)); + } + + private static ArgumentBuilder defaultSender(Flame flame, PluginLogger logger, MessageCacheService messageCacheService) { + return RequiredArgumentBuilder.argument("username", StringArgumentType.string()) + .executes(context -> { + logger.send(VelocityLang.RC_SEND_USAGE); + return Command.SINGLE_SUCCESS; + }) + .then(RequiredArgumentBuilder.argument("familyName", StringArgumentType.greedyString()) + .executes(context -> { + try { + String familyName = context.getArgument("familyName", String.class); + String username = context.getArgument("username", String.class); + + Player player = Tinder.get().velocityServer().getPlayer(username).orElse(null); + if(player == null) { + logger.send(VelocityLang.RC_SEND_NO_PLAYER.build(username)); return Command.SINGLE_SUCCESS; - }) - ) - .then(LiteralArgumentBuilder.literal("sort") + } + + BaseServerFamily family = flame.services().familyService().find(familyName); + if(family == null) { + logger.send(VelocityLang.RC_SEND_NO_FAMILY.build(familyName)); + return Command.SINGLE_SUCCESS; + } + if(!(family instanceof PlayerFocusedServerFamily)) { + VelocityLang.RC_FAMILY_ERROR.send(logger,"You can only directly send player to scalar and static families!"); + return Command.SINGLE_SUCCESS; + } + + ((PlayerFocusedServerFamily) family).connect(player); + } catch (Exception e) { + logger.send(VelocityLang.BOXED_MESSAGE_COLORED.build("There was an issue using that command! "+e.getMessage(), NamedTextColor.RED)); + } + return Command.SINGLE_SUCCESS; + }) + ); + } + + private static ArgumentBuilder serverSender(Flame flame, PluginLogger logger, MessageCacheService messageCacheService) { + return LiteralArgumentBuilder.literal("server") + .executes(context -> { + logger.send(VelocityLang.RC_SEND_USAGE); + return Command.SINGLE_SUCCESS; + }) + .then(RequiredArgumentBuilder.argument("username", StringArgumentType.string()) + .executes(context -> { + logger.send(VelocityLang.RC_SEND_USAGE); + return Command.SINGLE_SUCCESS; + }) + .then(RequiredArgumentBuilder.argument("serverName", StringArgumentType.greedyString()) .executes(context -> { try { - String familyName = context.getArgument("familyName", String.class); - BaseServerFamily family = flame.services().familyService().find(familyName); - if(family == null) throw new NullPointerException(); - if(!(family instanceof PlayerFocusedServerFamily)) { - VelocityLang.RC_FAMILY_ERROR.send(logger,"You can only use sort on scalar and static families!"); + String serverName = context.getArgument("serverName", String.class); + String username = context.getArgument("username", String.class); + + Player player = Tinder.get().velocityServer().getPlayer(username).orElse(null); + if (player == null) { + logger.send(VelocityLang.RC_SEND_NO_PLAYER.build(username)); return Command.SINGLE_SUCCESS; } - ((PlayerFocusedServerFamily) family).loadBalancer().completeSort(); + RegisteredServer registeredServer = Tinder.get().velocityServer().getServer(serverName).orElse(null); + if (registeredServer == null) { + logger.send(VelocityLang.RC_SEND_NO_SERVER.build(serverName)); + return Command.SINGLE_SUCCESS; + } - if(family instanceof ScalarServerFamily) - VelocityLang.RC_SCALAR_FAMILY_INFO.send(logger, (ScalarServerFamily) family); - if(family instanceof StaticServerFamily) - VelocityLang.RC_STATIC_FAMILY_INFO.send(logger, (StaticServerFamily) family); - } catch (NullPointerException e) { - VelocityLang.RC_FAMILY_ERROR.send(logger,"A family with that name doesn't exist!"); - } catch (Exception e) { - VelocityLang.RC_FAMILY_ERROR.send(logger,"Something prevented us from doing that!\n"+e.getMessage()); - } - return 1; - }) - ) - .then(LiteralArgumentBuilder.literal("locked") - .executes(context -> { - try { - String familyName = context.getArgument("familyName", String.class); - BaseServerFamily family = flame.services().familyService().find(familyName); - if(family == null) throw new NullPointerException(); - - if(family instanceof ScalarServerFamily) - VelocityLang.RC_SCALAR_FAMILY_INFO_LOCKED.send(logger, (ScalarServerFamily) family); - if(family instanceof StaticServerFamily) - VelocityLang.RC_STATIC_FAMILY_INFO_LOCKED.send(logger, (StaticServerFamily) family); - } catch (NullPointerException e) { - VelocityLang.RC_FAMILY_ERROR.send(logger,"A family with that name doesn't exist!"); + PlayerServer server = flame.services().serverService().search(registeredServer.getServerInfo()); + if (server == null) { + logger.send(VelocityLang.RC_SEND_NO_SERVER.build(serverName)); + return Command.SINGLE_SUCCESS; + } + + server.connect(player); } catch (Exception e) { - VelocityLang.RC_FAMILY_ERROR.send(logger,"Something prevented us from doing that!\n"+e.getMessage()); + logger.send(VelocityLang.BOXED_MESSAGE_COLORED.build("There was an issue using that command! "+e.getMessage(), NamedTextColor.RED)); } - return 1; + + return Command.SINGLE_SUCCESS; }) ) - ) - ) - .then(LiteralArgumentBuilder.literal("parties") - .executes(context -> { - try { - flame.services().partyService().orElseThrow().dump().forEach(party -> { - logger.log(party.toString()); - }); - } catch (Exception e) { - VelocityLang.RC_FAMILY_ERROR.send(logger,"Something prevented us from getting the parties!\n"+e.getMessage()); - } - - return Command.SINGLE_SUCCESS; - }) - ) - .then(LiteralArgumentBuilder.literal("reload") - .executes(context -> { - logger.log("Reloading the proxy..."); - try { - Tinder.get().rekindle(); - logger.log("Done reloading!"); - return 1; - } catch (Exception e) { - logger.error(e.getMessage(),e); - } - return 0; - }) - ) - .then(LiteralArgumentBuilder.literal("send") - .executes(context -> { - logger.send(VelocityLang.RC_SEND_USAGE); - return Command.SINGLE_SUCCESS; - }) - .then(RequiredArgumentBuilder.argument("username", StringArgumentType.string()) - .executes(context -> { - logger.send(VelocityLang.RC_SEND_USAGE); - return Command.SINGLE_SUCCESS; - }) - .then(RequiredArgumentBuilder.argument("familyName", StringArgumentType.greedyString()) - .executes(context -> { - try { - String familyName = context.getArgument("familyName", String.class); - String username = context.getArgument("username", String.class); - - Player player = Tinder.get().velocityServer().getPlayer(username).orElse(null); - if(player == null) { - logger.send(VelocityLang.RC_SEND_NO_PLAYER.build(username)); - return Command.SINGLE_SUCCESS; - } - - BaseServerFamily family = flame.services().familyService().find(familyName); - if(family == null) { - logger.send(VelocityLang.RC_SEND_NO_FAMILY.build(familyName)); - return Command.SINGLE_SUCCESS; - } - if(!(family instanceof PlayerFocusedServerFamily)) { - VelocityLang.RC_FAMILY_ERROR.send(logger,"You can only directly send player to scalar and static families!"); - return Command.SINGLE_SUCCESS; - } - - ((PlayerFocusedServerFamily) family).connect(player); - } catch (Exception e) { - logger.send(VelocityLang.BOXED_MESSAGE_COLORED.build("There was an issue using that command! "+e.getMessage(), NamedTextColor.RED)); - } - return Command.SINGLE_SUCCESS; - }) - ) - ) - .then(LiteralArgumentBuilder.literal("server") - .executes(context -> { - logger.send(VelocityLang.RC_SEND_USAGE); - return Command.SINGLE_SUCCESS; - }) - .then(RequiredArgumentBuilder.argument("username", StringArgumentType.string()) - .executes(context -> { - logger.send(VelocityLang.RC_SEND_USAGE); - return Command.SINGLE_SUCCESS; - }) - .then(RequiredArgumentBuilder.argument("serverName", StringArgumentType.greedyString()) - .executes(context -> { - try { - String serverName = context.getArgument("serverName", String.class); - String username = context.getArgument("username", String.class); - - Player player = Tinder.get().velocityServer().getPlayer(username).orElse(null); - if (player == null) { - logger.send(VelocityLang.RC_SEND_NO_PLAYER.build(username)); - return Command.SINGLE_SUCCESS; - } - - RegisteredServer registeredServer = Tinder.get().velocityServer().getServer(serverName).orElse(null); - if (registeredServer == null) { - logger.send(VelocityLang.RC_SEND_NO_SERVER.build(serverName)); - return Command.SINGLE_SUCCESS; - } - - PlayerServer server = flame.services().serverService().search(registeredServer.getServerInfo()); - if (server == null) { - logger.send(VelocityLang.RC_SEND_NO_SERVER.build(serverName)); - return Command.SINGLE_SUCCESS; - } - - server.connect(player); - } catch (Exception e) { - logger.send(VelocityLang.BOXED_MESSAGE_COLORED.build("There was an issue using that command! "+e.getMessage(), NamedTextColor.RED)); - } - - return Command.SINGLE_SUCCESS; - }) - ) - ) - ) - ) - .then(LiteralArgumentBuilder.literal("debug") - .executes(context -> { - flame.bootLog().forEach(logger::send); - return Command.SINGLE_SUCCESS; - }) - ) - .build(); - - // BrigadierCommand implements Command - return new BrigadierCommand(rusty); + ); + } +} +class Debug { + public static ArgumentBuilder build(Flame flame, PluginLogger logger, MessageCacheService messageCacheService) { + return LiteralArgumentBuilder.literal("debug") + .executes(context -> { + flame.bootLog().forEach(logger::send); + return Command.SINGLE_SUCCESS; + }); + } +} +class Reload { + public static ArgumentBuilder build(Flame flame, PluginLogger logger, MessageCacheService messageCacheService) { + return LiteralArgumentBuilder.literal("reload") + .executes(context -> { + logger.log("Reloading the proxy..."); + try { + Tinder.get().rekindle(); + logger.log("Done reloading!"); + return 1; + } catch (Exception e) { + logger.error(e.getMessage(),e); + } + return 0; + }); } } \ No newline at end of file diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/events/OnPlayerChooseInitialServer.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/events/OnPlayerChooseInitialServer.java index 3995ed3c6..4669b92ab 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/events/OnPlayerChooseInitialServer.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/events/OnPlayerChooseInitialServer.java @@ -12,7 +12,7 @@ import group.aelysium.rustyconnector.plugin.velocity.lib.friends.FriendRequest; import group.aelysium.rustyconnector.plugin.velocity.lib.friends.FriendsService; import group.aelysium.rustyconnector.plugin.velocity.lib.lang.VelocityLang; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import group.aelysium.rustyconnector.plugin.velocity.lib.server.PlayerServer; import group.aelysium.rustyconnector.plugin.velocity.lib.whitelist.Whitelist; import group.aelysium.rustyconnector.plugin.velocity.lib.webhook.WebhookAlertFlag; @@ -20,13 +20,10 @@ import group.aelysium.rustyconnector.plugin.velocity.lib.webhook.DiscordWebhookMessage; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; -import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.TextDecoration; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.atomic.AtomicReference; public class OnPlayerChooseInitialServer { /** @@ -69,7 +66,7 @@ public EventTask onPlayerChooseInitialServer(PlayerChooseInitialServerEvent even // Check for active friend requests try { FriendsService friendsService = api.services().friendsService().orElseThrow(); - List requests = friendsService.findRequestsToTarget(FakePlayer.from(player)); + List requests = friendsService.findRequestsToTarget(ResolvablePlayer.from(player)); if(requests.size() == 0) throw new NoOutputException(); @@ -79,7 +76,7 @@ public EventTask onPlayerChooseInitialServer(PlayerChooseInitialServerEvent even // Check for online friends try { FriendsService friendsService = api.services().friendsService().orElseThrow(); - List friends = friendsService.findFriends(player).orElseThrow(); + List friends = friendsService.findFriends(player).orElseThrow(); if(friends.size() == 0) throw new NoOutputException(); diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/events/OnPlayerDisconnect.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/events/OnPlayerDisconnect.java index b5ca9b811..7be199139 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/events/OnPlayerDisconnect.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/events/OnPlayerDisconnect.java @@ -11,7 +11,7 @@ import group.aelysium.rustyconnector.plugin.velocity.lib.lang.VelocityLang; import group.aelysium.rustyconnector.plugin.velocity.lib.parties.Party; import group.aelysium.rustyconnector.plugin.velocity.lib.parties.PartyService; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import group.aelysium.rustyconnector.plugin.velocity.lib.server.PlayerServer; import group.aelysium.rustyconnector.plugin.velocity.lib.webhook.WebhookAlertFlag; import group.aelysium.rustyconnector.plugin.velocity.lib.webhook.WebhookEventManager; @@ -66,7 +66,7 @@ public EventTask onPlayerDisconnect(DisconnectEvent event) { FriendsService friendsService = api.services().friendsService().orElseThrow(); if(!friendsService.settings().allowMessaging()) throw new NoOutputException(); - List friends = friendsService.findFriends(player).orElseThrow(); + List friends = friendsService.findFriends(player).orElseThrow(); if(friends.size() == 0) throw new NoOutputException(); diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/ResolvableFamily.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/ResolvableFamily.java new file mode 100644 index 000000000..307bd2067 --- /dev/null +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/ResolvableFamily.java @@ -0,0 +1,27 @@ +package group.aelysium.rustyconnector.plugin.velocity.lib.family; + +import group.aelysium.rustyconnector.plugin.velocity.central.Tinder; +import group.aelysium.rustyconnector.plugin.velocity.lib.family.bases.BaseServerFamily; + +import java.util.Objects; +import java.util.Optional; + +public record ResolvableFamily(String name) { + public Optional> resolve() { + BaseServerFamily potentialFamily = Tinder.get().services().familyService().find(this.name); + if(potentialFamily == null) return Optional.empty(); + return Optional.of(potentialFamily); + } + + @Override + public boolean equals(Object object) { + if (this == object) return true; + if (object == null || getClass() != object.getClass()) return false; + + ResolvableFamily that = (ResolvableFamily) object; + return this.name.equals(that.name()); + } + public static ResolvableFamily from(BaseServerFamily family) { + return new ResolvableFamily(family.name()); + } +} diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/bases/BaseServerFamily.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/bases/BaseServerFamily.java index 8a851627b..91e83d294 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/bases/BaseServerFamily.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/bases/BaseServerFamily.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.UUID; public abstract class BaseServerFamily { protected final String name; @@ -27,6 +28,7 @@ public String name() { * @return A found server or `null` if there's no match. */ abstract public S findServer(@NotNull ServerInfo serverInfo); + abstract public S findServer(@NotNull UUID uuid); /** * Add a server to the family. diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/bases/PlayerFocusedServerFamily.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/bases/PlayerFocusedServerFamily.java index 2dd19f175..8086c9a1d 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/bases/PlayerFocusedServerFamily.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/bases/PlayerFocusedServerFamily.java @@ -148,6 +148,13 @@ public PlayerServer findServer(@NotNull ServerInfo serverInfo) { ).findFirst().orElse(null); } + @Override + public PlayerServer findServer(@NotNull UUID uuid) { + return this.registeredServers().stream() + .filter(server -> server.id().equals(uuid) + ).findFirst().orElse(null); + } + @Override public List allPlayers(int max) { List players = new ArrayList<>(); diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/config/FamiliesConfig.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/config/FamiliesConfig.java index d536010d5..91fda8a81 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/config/FamiliesConfig.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/config/FamiliesConfig.java @@ -17,11 +17,10 @@ public class FamiliesConfig extends YAML { private Boolean rootFamily_catchDisconnectingPlayers = false; private List scalar = new ArrayList<>(); private List staticF = new ArrayList<>(); - private String staticFamilyStorage = ""; public FamiliesConfig(File configPointer) { super(configPointer); - } + }d . public String rootFamilyName() { return this.rootFamily_name; @@ -37,10 +36,6 @@ public List staticFamilies() { return this.staticF; } - public String staticFamilyStorage() { - return this.staticFamilyStorage; - } - @SuppressWarnings("unchecked") public void register() throws IllegalStateException, NoOutputException { PluginLogger logger = Tinder.get().logger(); @@ -87,12 +82,6 @@ public void register() throws IllegalStateException, NoOutputException { this.scalar.remove(this.rootFamily_name); this.staticF.remove(this.rootFamily_name); } - - - // MySQL - if(this.staticF.size() > 0) { - this.staticFamilyStorage = this.getNode(this.data, "static-family-storage", String.class); - } } private boolean doDuplicatesExist() { diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/static_family/ResidenceDataEnclave.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/static_family/ResidenceDataEnclave.java index 946b97c37..af1435e6b 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/static_family/ResidenceDataEnclave.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/static_family/ResidenceDataEnclave.java @@ -2,6 +2,8 @@ import com.velocitypowered.api.proxy.Player; import group.aelysium.rustyconnector.core.lib.model.LiquidTimestamp; +import group.aelysium.rustyconnector.plugin.velocity.lib.family.ResolvableFamily; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import group.aelysium.rustyconnector.plugin.velocity.lib.server.PlayerServer; import group.aelysium.rustyconnector.plugin.velocity.lib.storage.MySQLStorage; import group.aelysium.rustyconnector.plugin.velocity.lib.storage.StorageRoot; @@ -24,7 +26,10 @@ public Optional fetch(Player player, StaticServerFamily family) StorageRoot root = (StorageRoot) this.storage.root(); Optional serverResidence = root.residence().stream() - .filter(residence -> residence.player().equals(player) && residence.family().equals(family)) + .filter(residence -> + residence.rawPlayer().equals(ResolvablePlayer.from(player)) && + residence.rawFamily().equals(ResolvableFamily.from(family)) + ) .findAny(); return serverResidence; @@ -48,7 +53,10 @@ public void delete(Player player, StaticServerFamily family) { StorageRoot root = (StorageRoot) this.storage.root(); List residences = root.residence(); - residences.removeIf(residence -> residence.player().equals(player) && residence.family().equals(family)); + residences.removeIf(residence -> + residence.rawPlayer().equals(ResolvablePlayer.from(player)) && + residence.rawFamily().equals(ResolvableFamily.from(family)) + ); this.storage.store(residences); } @@ -68,7 +76,10 @@ protected void purgeExpired(StaticServerFamily family) { StorageRoot root = (StorageRoot) this.storage.root(); List residenceList = root.residence(); - residenceList.removeIf(serverResidence -> serverResidence.expiration() < Instant.EPOCH.getEpochSecond() && serverResidence.family().equals(family)); + residenceList.removeIf(serverResidence -> + serverResidence.expiration() < Instant.EPOCH.getEpochSecond() && + serverResidence.rawFamily().equals(ResolvableFamily.from(family)) + ); this.storage.store(residenceList); } @@ -83,7 +94,7 @@ protected void updateNullExpirations(StaticServerFamily family) { List residenceList = root.residence(); residenceList.forEach(serverResidence -> { - if(!serverResidence.family().equals(family)) return; + if(!serverResidence.rawFamily().equals(ResolvableFamily.from(family))) return; serverResidence.expiration(null); }); @@ -100,7 +111,7 @@ protected void updateValidExpirations(StaticServerFamily family) { List residenceList = root.residence(); residenceList.forEach(serverResidence -> { - if(!serverResidence.family().equals(family)) return; + if(!serverResidence.rawFamily().equals(ResolvableFamily.from(family))) return; serverResidence.expiration(family.homeServerExpiration()); }); diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/static_family/ServerResidence.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/static_family/ServerResidence.java index d25b6e7c1..87787e0ad 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/static_family/ServerResidence.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/static_family/ServerResidence.java @@ -2,33 +2,50 @@ import com.velocitypowered.api.proxy.Player; import group.aelysium.rustyconnector.core.lib.model.LiquidTimestamp; +import group.aelysium.rustyconnector.plugin.velocity.central.Tinder; +import group.aelysium.rustyconnector.plugin.velocity.lib.family.ResolvableFamily; +import group.aelysium.rustyconnector.plugin.velocity.lib.family.bases.BaseServerFamily; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import group.aelysium.rustyconnector.plugin.velocity.lib.server.PlayerServer; +import group.aelysium.rustyconnector.plugin.velocity.lib.server.ResolvableServer; -public class ServerResidence { - protected Player player; - protected PlayerServer server; +import java.util.Optional; - protected StaticServerFamily family; +public class ServerResidence { + protected ResolvablePlayer player; + protected ResolvableServer server; + protected ResolvableFamily family; protected Long expiration; public ServerResidence(Player player, PlayerServer server, StaticServerFamily family, LiquidTimestamp expiration) { - this.player = player; - this.server = server; - this.family = family; + this.player = ResolvablePlayer.from(player); + this.server = ResolvableServer.from(server); + this.family = ResolvableFamily.from(family); + if(expiration == null) this.expiration = null; else this.expiration = expiration.epochFromNow(); } - public Player player() { - return player; + public Optional player() { + return Tinder.get().velocityServer().getPlayer(this.player.uuid()); + } + public ResolvablePlayer rawPlayer() { + return this.player; } - public PlayerServer server() { - return server; + + public Optional server() { + return this.server.resolve(); + } + public ResolvableServer rawServer() { + return this.server; } - public StaticServerFamily family() { - return family; + public Optional> family() { + return this.family.resolve(); + } + public ResolvableFamily rawFamily() { + return this.family; } public Long expiration() { @@ -39,125 +56,4 @@ public void expiration(LiquidTimestamp expiration) { if(expiration == null) this.expiration = null; else this.expiration = expiration.epochFromNow(); } -} - -/* - - protected static class ServerResidence extends SyncedResource { - private static final StorageQuery FIND_HOME_SERVER_IN_FAMILY = StorageQuery.create("SELECT * FROM home_server_mappings WHERE player_uuid = ? AND family_name = ?;"); - private static final StorageQuery CHECK_IF_PLAYER_HAS_HOME = StorageQuery.create("SELECT * FROM home_server_mappings WHERE player_uuid = ? AND family_name = ?;"); - private static final StorageQuery DELETE_PLAYERS_HOME_SERVER = StorageQuery.create("DELETE FROM home_server_mappings WHERE player_uuid = ? AND family_name = ?;"); - private static final StorageQuery SAVE_PLAYERS_HOME_SERVER = StorageQuery.create("REPLACE INTO home_server_mappings (player_uuid, family_name, server_address, server_name, expiration) VALUES(?, ?, ?, ?, FROM_UNIXTIME(?));"); - - protected Player player; - protected PlayerServer server; - protected StaticServerFamily family; - protected ServerResidence(StorageConnector connector, Player player, PlayerServer server, StaticServerFamily family) { - super(connector); - this.player = player; - this.server = server; - this.family = family; - } - protected ServerResidence(Player player, PlayerServer server, StaticServerFamily family) { - this.player = player; - this.server = server; - this.family = family; - } - - @Destroyable - public Player player() { - this.throwDestroyed(); - return this.player; - } - - @Destroyable - public PlayerServer server() { - this.throwDestroyed(); - return this.server; - } - - @Destroyable - public StaticServerFamily family() { - this.throwDestroyed(); - return this.family; - } - - protected static Optional fetch(StorageConnector connector, Player player, StaticServerFamily family) throws Exception { - Tinder api = Tinder.get(); - - StorageConnection connection = connector.connection().orElseThrow(); - - AtomicReference> homeServerMapping = new AtomicReference<>(Optional.empty()); - try { - Consumer> consumer = (result) -> { - ResultConsumer resultConsumer = result.consumer(); - - resultConsumer.forMySQL((mysqlResult) -> { - try { - RegisteredServer registeredServer = api.velocityServer().getServer(mysqlResult.first().getString("server_name")).orElse(null); - if(registeredServer == null) return; - PlayerServer server = api.services().serverService().search(registeredServer.getServerInfo()); - - homeServerMapping.set(Optional.of(new ServerResidence(player, server, family))); - } catch (SQLException e) { - throw new RuntimeException(e); - } - }); - - resultConsumer.trigger(); - }; - - connection.query(FIND_HOME_SERVER_IN_FAMILY, consumer, player.getUniqueId().toString(), family.name()); - } catch (Exception e) { - throw new RuntimeException(e); - } - - return homeServerMapping.get(); - } - - public void sync(StorageConnector connector) throws Exception { - this.throwDestroyed(); - - StorageConnection connection = connector.connection().orElseThrow(); - - LiquidTimestamp expiration = family.homeServerExpiration(); - - if(expiration == null) - connection.query( - SAVE_PLAYERS_HOME_SERVER, - player.getUniqueId().toString(), - family.name(), - server.address(), - server.serverInfo().getName(), - null - ); - else - connection.query( - DELETE_PLAYERS_HOME_SERVER, - player.getUniqueId().toString(), - family.name(), - server.address(), - server.serverInfo().getName(), - expiration.epochFromNow() - ); - - this.connector = connector; - this.synced = true; - } - - @Unsynced - public static ServerResidence from(Player player, PlayerServer server, StaticServerFamily family) { - return new ServerResidence(player, server, family); - } - - @Override - @Destructive - public void delete() throws Exception { - StorageConnection> connection = connector.connection().orElseThrow(); - - connection.query(DELETE_PLAYERS_HOME_SERVER, player.getUniqueId().toString(), family.name()); - - this.destroyed = true; - } - } - */ \ No newline at end of file +} \ No newline at end of file diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/static_family/StaticServerFamily.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/static_family/StaticServerFamily.java index cc7358df0..806d9d4ef 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/static_family/StaticServerFamily.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/static_family/StaticServerFamily.java @@ -146,11 +146,15 @@ public StaticFamilyConnector(StaticServerFamily family, Player player) { } public PlayerServer connect() throws RuntimeException { + System.out.println("Attempting to connect player."); + System.out.println("Checking for servers."); if(this.family.loadBalancer().size() == 0) throw new RuntimeException("There are no servers for you to connect to!"); + System.out.println("Validating whitelist."); this.validateWhitelist(); + System.out.println("Establishing any connection."); PlayerServer server = this.establishAnyConnection(); return server; @@ -174,8 +178,10 @@ public void validateWhitelist() throws RuntimeException { public PlayerServer establishAnyConnection() { PlayerServer server; try { + System.out.println("Attempting to connect to home server."); server = this.connectHomeServer(); } catch (Exception ignore) { + System.out.println("Unable to connect to home server. Establishing a brand new connection"); server = establishNewConnection(true); } @@ -190,17 +196,21 @@ public PlayerServer establishAnyConnection() { * @return The player server that this player was connected to. */ public PlayerServer establishNewConnection(boolean shouldRegisterNew) { + System.out.println("Establishing new wildcard connection using loadbalancer."); PlayerServer server; if(this.family.loadBalancer().persistent() && this.family.loadBalancer().attempts() > 1) server = this.connectPersistent(); else server = this.connectSingleton(); + System.out.println("Sending post connection error message if needed."); this.sendPostConnectErrorMessage(); + System.out.println("Checking if the current connection should be saved as a new resident server."); if(!shouldRegisterNew) return server; try { + System.out.println("Saving current server as player's new residence."); this.family.dataEnclave().save(player, server, this.family); } catch (Exception e) { Tinder.get().logger().send(Component.text("Unable to save "+ this.player.getUsername() +" home server into MySQL! Their home server will only be saved until the server shuts down, or they log out!", NamedTextColor.RED)); @@ -219,22 +229,31 @@ public PlayerServer establishNewConnection(boolean shouldRegisterNew) { */ public PlayerServer connectHomeServer() throws RuntimeException { try { + System.out.println("Fetching player's residence."); Optional residence = this.family.dataEnclave().fetch(player, this.family); + System.out.println("checking is player's residence exists."); if(residence.isPresent()) { - residence.orElseThrow().server().connect(this.player); - return residence.orElseThrow().server(); + if(residence.orElseThrow().server().isPresent()) { + System.out.println("Connecting player to their residence"); + residence.orElseThrow().server().orElseThrow().connect(this.player); + return residence.orElseThrow().server().orElseThrow(); + } } + System.out.println("Unable to fetch player's residence. Running unavailable protocol."); switch (this.family.unavailableProtocol()) { case ASSIGN_NEW_HOME -> { + System.out.println("Assigning a new home."); this.family.dataEnclave().delete(player, this.family); return this.establishNewConnection(true); } case CONNECT_WITH_ERROR -> { + System.out.println("sending an error and connecting anyways."); this.postConnectionError = VelocityLang.MISSING_HOME_SERVER; return this.establishNewConnection(false); } case CANCEL_CONNECTION_ATTEMPT -> { + System.out.println("Canceling connection attempt."); player.sendMessage(VelocityLang.BLOCKED_STATIC_FAMILY_JOIN_ATTEMPT); return null; } @@ -246,14 +265,19 @@ public PlayerServer connectHomeServer() throws RuntimeException { } private PlayerServer connectSingleton() { + System.out.println("Connecting singleton."); + System.out.println("Fetching server."); PlayerServer server = this.family.loadBalancer().current(); try { + System.out.println("Validating player."); if(!server.validatePlayer(this.player)) throw new RuntimeException("The server you're trying to connect to is full!"); + System.out.println("Connecting player to server."); if (!server.connect(this.player)) throw new RuntimeException("There was an issue connecting you to the server!"); + System.out.println("Iterating load balancer."); this.family.loadBalancer().iterate(); return server; @@ -263,22 +287,28 @@ private PlayerServer connectSingleton() { } private PlayerServer connectPersistent() { + System.out.println("connecting persistently."); int attemptsLeft = this.family.loadBalancer().attempts(); + System.out.println("Entering persistence loop."); for (int attempt = 1; attempt <= attemptsLeft; attempt++) { boolean isFinal = (attempt == attemptsLeft); + System.out.println("Fetching the current load balanced server."); PlayerServer server = this.family.loadBalancer().current(); // Get the server that is currently listed as highest priority try { + System.out.println("Validating player."); if (!server.validatePlayer(this.player)) throw new RuntimeException("The server you're trying to connect to is full!"); + System.out.println("Connecting to server.."); if (server.connect(this.player)) { this.family.loadBalancer().forceIterate(); return server; } else throw new RuntimeException("Unable to connect you to the server in time!"); } catch (Exception e) { + System.out.println("Persistence connection failed! Disconnecting!"); if (isFinal) this.player.disconnect(Component.text(e.getMessage())); } diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/viewport/endpoints/GetFamilyEndpoint.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/viewport/endpoints/GetFamilyEndpoint.java index 5bd18b8a6..ee6229295 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/viewport/endpoints/GetFamilyEndpoint.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/family/viewport/endpoints/GetFamilyEndpoint.java @@ -29,7 +29,7 @@ public APIResponse handle(Request request, Response response) { Tinder.get().services().familyService().find(familyName).registeredServers().forEach(server -> { JsonObject object = new JsonObject(); object.add("name", new JsonPrimitive(server.serverInfo().getName())); - object.add("id", new JsonPrimitive(server.id())); + object.add("id", new JsonPrimitive(server.id().toString())); object.add("player_count", new JsonPrimitive(server.playerCount())); servers.add(object); }); diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendMapping.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendMapping.java index 4e5311ac8..5d322ddc9 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendMapping.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendMapping.java @@ -1,14 +1,14 @@ package group.aelysium.rustyconnector.plugin.velocity.lib.friends; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import java.util.Objects; public class FriendMapping { - private final FakePlayer player1; - private final FakePlayer player2; + private final ResolvablePlayer player1; + private final ResolvablePlayer player2; - protected FriendMapping(FakePlayer player1, FakePlayer player2) { + protected FriendMapping(ResolvablePlayer player1, ResolvablePlayer player2) { // Ensure that players are always in order of the lowest uuid to the highest uuid. if(player1.uuid().compareTo(player2.uuid()) > 0) { this.player1 = player2; @@ -21,15 +21,15 @@ protected FriendMapping(FakePlayer player1, FakePlayer player2) { this.player2 = player2; } - public FakePlayer player1() { + public ResolvablePlayer player1() { return player1; } - public FakePlayer player2() { + public ResolvablePlayer player2() { return player2; } - public boolean contains(FakePlayer player) { + public boolean contains(ResolvablePlayer player) { return this.player1.equals(player) || this.player2.equals(player); } @@ -41,11 +41,11 @@ public boolean equals(Object o) { return Objects.equals(player1, that.player1) && Objects.equals(player2, that.player2); } - public static FriendMapping from(FakePlayer player1, FakePlayer player2) { + public static FriendMapping from(ResolvablePlayer player1, ResolvablePlayer player2) { return new FriendMapping(player1, player2); } - public FakePlayer fetchOther(FakePlayer player) { + public ResolvablePlayer fetchOther(ResolvablePlayer player) { if(this.player1.equals(player)) return this.player2; if(this.player2.equals(player)) return this.player1; diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendRequest.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendRequest.java index 199cdcaf6..fa608aa4c 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendRequest.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendRequest.java @@ -2,18 +2,18 @@ import com.velocitypowered.api.proxy.Player; import group.aelysium.rustyconnector.plugin.velocity.lib.lang.VelocityLang; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import java.util.NoSuchElementException; public class FriendRequest { private final FriendsService friendsService; private long id; - private FakePlayer sender; - private FakePlayer target; + private ResolvablePlayer sender; + private ResolvablePlayer target; private Boolean isAcknowledged = null; - public FriendRequest(FriendsService friendsService, long id, FakePlayer sender, FakePlayer target) { + public FriendRequest(FriendsService friendsService, long id, ResolvablePlayer sender, ResolvablePlayer target) { this.friendsService = friendsService; this.id = id; this.sender = sender; @@ -23,10 +23,10 @@ public FriendRequest(FriendsService friendsService, long id, FakePlayer sender, public long id() { return this.id; } - public FakePlayer sender() { + public ResolvablePlayer sender() { return this.sender; } - public FakePlayer target() { + public ResolvablePlayer target() { return this.target; } diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendsDataEnclave.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendsDataEnclave.java index 455fa7fc1..a2112c021 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendsDataEnclave.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendsDataEnclave.java @@ -1,6 +1,6 @@ package group.aelysium.rustyconnector.plugin.velocity.lib.friends; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import group.aelysium.rustyconnector.plugin.velocity.lib.storage.MySQLStorage; import group.aelysium.rustyconnector.plugin.velocity.lib.storage.StorageRoot; import one.microstream.storage.embedded.types.EmbeddedStorageManager; @@ -21,7 +21,7 @@ public FriendsDataEnclave(MySQLStorage storage) { * @return A list of friends. * @throws SQLException If there was an issue. */ - public Optional> findFriends(FakePlayer player) { + public Optional> findFriends(ResolvablePlayer player) { try { StorageRoot root = (StorageRoot) this.storage.root(); @@ -43,7 +43,7 @@ public Optional> findFriends(FakePlayer player) { * @param player2 The second player. * @return `true` If the two players are friends. */ - public boolean areFriends(FakePlayer player1, FakePlayer player2) throws RuntimeException { + public boolean areFriends(ResolvablePlayer player1, ResolvablePlayer player2) throws RuntimeException { StorageRoot root = (StorageRoot) this.storage.root(); return root.friends().contains(new FriendMapping(player1, player2)); } @@ -54,7 +54,7 @@ public boolean areFriends(FakePlayer player1, FakePlayer player2) throws Runtime * @return The number of friends a player has. * @throws SQLException If there was an issue. */ - public Optional getFriendCount(FakePlayer player) { + public Optional getFriendCount(ResolvablePlayer player) { try { StorageRoot root = (StorageRoot) this.storage.root(); long count = root.friends().stream().filter(friendMapping -> friendMapping.contains(player)).count(); @@ -67,7 +67,7 @@ public Optional getFriendCount(FakePlayer player) { return Optional.empty(); } - public Optional addFriend(FakePlayer player1, FakePlayer player2) { + public Optional addFriend(ResolvablePlayer player1, ResolvablePlayer player2) { try { StorageRoot root = (StorageRoot) this.storage.root(); @@ -86,7 +86,7 @@ public Optional addFriend(FakePlayer player1, FakePlayer player2) return Optional.empty(); } - public void removeFriend(FakePlayer player1, FakePlayer player2) { + public void removeFriend(ResolvablePlayer player1, ResolvablePlayer player2) { try { StorageRoot root = (StorageRoot) this.storage.root(); diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendsService.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendsService.java index 5d9b169a1..7e19aa356 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendsService.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/FriendsService.java @@ -11,7 +11,7 @@ import group.aelysium.rustyconnector.plugin.velocity.lib.friends.commands.CommandFriends; import group.aelysium.rustyconnector.plugin.velocity.lib.friends.commands.CommandUnFriend; import group.aelysium.rustyconnector.plugin.velocity.lib.lang.VelocityLang; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import group.aelysium.rustyconnector.plugin.velocity.lib.storage.MySQLStorage; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -82,7 +82,7 @@ public FriendsSettings settings() { return this.settings; } - public List findRequestsToTarget(FakePlayer target) { + public List findRequestsToTarget(ResolvablePlayer target) { List> entries = this.friendRequests.asMap().entrySet().stream().filter(request -> request.getValue().target().equals(target)).findAny().stream().toList(); List requests = new ArrayList<>(); @@ -91,40 +91,40 @@ public List findRequestsToTarget(FakePlayer target) { return requests; } - public Optional findRequest(FakePlayer target, FakePlayer sender) { + public Optional findRequest(ResolvablePlayer target, ResolvablePlayer sender) { Optional> entry = this.friendRequests.asMap().entrySet().stream().filter(invite -> invite.getValue().target().equals(target) && invite.getValue().sender().equals(sender)).findFirst(); return entry.map(Map.Entry::getValue); } - public Optional> findFriends(Player player) { - List friends = new ArrayList<>(); - List friendMappings = this.dataEnclave.findFriends(FakePlayer.from(player)).orElse(null); + public Optional> findFriends(Player player) { + List friends = new ArrayList<>(); + List friendMappings = this.dataEnclave.findFriends(ResolvablePlayer.from(player)).orElse(null); if(friendMappings == null) return Optional.empty(); friendMappings.forEach(mapping -> { try { - friends.add(mapping.fetchOther(FakePlayer.from(player))); + friends.add(mapping.fetchOther(ResolvablePlayer.from(player))); } catch (NullPointerException ignore) {} }); return Optional.of(friends); } - public boolean areFriends(FakePlayer player1, FakePlayer player2) { + public boolean areFriends(ResolvablePlayer player1, ResolvablePlayer player2) { return this.dataEnclave.areFriends(player1, player2); } - public void addFriends(FakePlayer player1, FakePlayer player2) { + public void addFriends(ResolvablePlayer player1, ResolvablePlayer player2) { this.dataEnclave.addFriend(player1, player2); } - public void removeFriends(FakePlayer player1, FakePlayer player2) { + public void removeFriends(ResolvablePlayer player1, ResolvablePlayer player2) { this.dataEnclave.removeFriend(player1, player2); } - public FriendMapping sendRequest(Player sender, FakePlayer target) { - if(this.friendCount(FakePlayer.from(sender)).orElseThrow() > this.settings().maxFriends()) + public FriendMapping sendRequest(Player sender, ResolvablePlayer target) { + if(this.friendCount(ResolvablePlayer.from(sender)).orElseThrow() > this.settings().maxFriends()) sender.sendMessage(VelocityLang.MAX_FRIENDS_REACHED); - FakePlayer fakeSender = FakePlayer.from(sender); + ResolvablePlayer fakeSender = ResolvablePlayer.from(sender); FriendRequest friendRequest = new FriendRequest(this, snowflakeGenerator.nextId(), fakeSender, target); this.friendRequests.put(friendRequest.id(), friendRequest); @@ -144,7 +144,7 @@ public void closeInvite(FriendRequest request) { request.decompose(); } - public Optional friendCount(FakePlayer player) { + public Optional friendCount(ResolvablePlayer player) { return this.dataEnclave.getFriendCount(player); } diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/commands/CommandFM.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/commands/CommandFM.java index 775bcf638..e4e98d013 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/commands/CommandFM.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/commands/CommandFM.java @@ -13,7 +13,7 @@ import group.aelysium.rustyconnector.plugin.velocity.lib.Permission; import group.aelysium.rustyconnector.plugin.velocity.lib.friends.FriendsService; import group.aelysium.rustyconnector.plugin.velocity.lib.lang.VelocityLang; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; @@ -52,7 +52,7 @@ public static BrigadierCommand create(FriendsService friendsService) { if(!(context.getSource() instanceof Player player)) return builder.buildFuture(); try { - List friends = friendsService.findFriends(player).orElseThrow(); + List friends = friendsService.findFriends(player).orElseThrow(); friends.forEach(friend -> { try { @@ -98,8 +98,8 @@ public static BrigadierCommand create(FriendsService friendsService) { if(player.equals(targetPlayer)) return closeMessage(player, VelocityLang.FRIEND_MESSAGING_NO_SELF_MESSAGING); if(!friendsService.areFriends( - FakePlayer.from(player), - FakePlayer.from(targetPlayer) + ResolvablePlayer.from(player), + ResolvablePlayer.from(targetPlayer) )) return closeMessage(player, VelocityLang.FRIEND_MESSAGING_ONLY_FRIENDS); diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/commands/CommandFriends.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/commands/CommandFriends.java index 666703095..280cf6012 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/commands/CommandFriends.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/commands/CommandFriends.java @@ -16,11 +16,10 @@ import group.aelysium.rustyconnector.plugin.velocity.lib.friends.FriendRequest; import group.aelysium.rustyconnector.plugin.velocity.lib.friends.FriendsService; import group.aelysium.rustyconnector.plugin.velocity.lib.lang.VelocityLang; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import java.io.SyncFailedException; import java.util.List; public final class CommandFriends { @@ -80,9 +79,9 @@ public static BrigadierCommand create(FriendsService friendsService) { } String username = context.getArgument("username", String.class); - FakePlayer targetPlayer = api.services().playerService().fetch(username).orElseThrow(); + ResolvablePlayer targetPlayer = api.services().playerService().fetch(username).orElseThrow(); - if(friendsService.areFriends(FakePlayer.from(player), targetPlayer)) + if(friendsService.areFriends(ResolvablePlayer.from(player), targetPlayer)) return closeMessage(player, VelocityLang.FRIEND_REQUEST_ALREADY_FRIENDS.build(username)); if(targetPlayer == null) @@ -114,7 +113,7 @@ public static BrigadierCommand create(FriendsService friendsService) { if(!(context.getSource() instanceof Player player)) return builder.buildFuture(); try { - List requests = friendsService.findRequestsToTarget(FakePlayer.from(player)); + List requests = friendsService.findRequestsToTarget(ResolvablePlayer.from(player)); if(requests.size() == 0) { builder.suggest("You have no pending friend requests!"); @@ -158,13 +157,13 @@ public static BrigadierCommand create(FriendsService friendsService) { } String username = context.getArgument("username", String.class); - FakePlayer senderPlayer = api.services().playerService().fetch(username).orElseThrow(); + ResolvablePlayer senderPlayer = api.services().playerService().fetch(username).orElseThrow(); if(senderPlayer == null) return closeMessage(player, VelocityLang.NO_PLAYER.build(username)); try { - FriendRequest invite = friendsService.findRequest(FakePlayer.from(player), senderPlayer).orElse(null); + FriendRequest invite = friendsService.findRequest(ResolvablePlayer.from(player), senderPlayer).orElse(null); if (invite == null) throw new NoOutputException(); try { @@ -195,12 +194,12 @@ public static BrigadierCommand create(FriendsService friendsService) { } String username = context.getArgument("username", String.class); - FakePlayer senderPlayer = api.services().playerService().fetch(username).orElseThrow(); + ResolvablePlayer senderPlayer = api.services().playerService().fetch(username).orElseThrow(); if (senderPlayer == null) return closeMessage(player, VelocityLang.NO_PLAYER.build(username)); - FriendRequest invite = friendsService.findRequest(FakePlayer.from(player), senderPlayer).orElse(null); + FriendRequest invite = friendsService.findRequest(ResolvablePlayer.from(player), senderPlayer).orElse(null); if (invite == null) return closeMessage(player, VelocityLang.FRIEND_REQUEST_EXPIRED); diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/commands/CommandUnFriend.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/commands/CommandUnFriend.java index 8879578f2..5d1b3dad1 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/commands/CommandUnFriend.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/friends/commands/CommandUnFriend.java @@ -13,11 +13,10 @@ import group.aelysium.rustyconnector.plugin.velocity.lib.Permission; import group.aelysium.rustyconnector.plugin.velocity.lib.friends.FriendsService; import group.aelysium.rustyconnector.plugin.velocity.lib.lang.VelocityLang; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import java.io.SyncFailedException; import java.util.List; public final class CommandUnFriend { @@ -51,7 +50,7 @@ public static BrigadierCommand create(FriendsService friendsService) { if(!(context.getSource() instanceof Player player)) return builder.buildFuture(); try { - List friends = friendsService.findFriends(player).orElseThrow(); + List friends = friendsService.findFriends(player).orElseThrow(); friends.forEach(friend -> { try { @@ -77,16 +76,16 @@ public static BrigadierCommand create(FriendsService friendsService) { } String username = context.getArgument("username", String.class); - FakePlayer targetPlayer = api.services().playerService().fetch(username).orElseThrow(); + ResolvablePlayer targetPlayer = api.services().playerService().fetch(username).orElseThrow(); - if(!friendsService.areFriends(FakePlayer.from(player), targetPlayer)) + if(!friendsService.areFriends(ResolvablePlayer.from(player), targetPlayer)) return closeMessage(player, VelocityLang.UNFRIEND_NOT_FRIENDS.build(username)); if(targetPlayer == null) return closeMessage(player, VelocityLang.NO_PLAYER.build(username)); try { - friendsService.removeFriends(FakePlayer.from(player), targetPlayer); + friendsService.removeFriends(ResolvablePlayer.from(player), targetPlayer); return closeMessage(player, VelocityLang.UNFRIEND_SUCCESS.build(username)); } catch (IllegalStateException e) { diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/lang/VelocityLang.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/lang/VelocityLang.java index d60f74254..d6e47e2df 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/lang/VelocityLang.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/lang/VelocityLang.java @@ -15,7 +15,7 @@ import group.aelysium.rustyconnector.plugin.velocity.lib.friends.FriendRequest; import group.aelysium.rustyconnector.plugin.velocity.lib.friends.FriendsService; import group.aelysium.rustyconnector.plugin.velocity.lib.parties.Party; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import group.aelysium.rustyconnector.plugin.velocity.lib.server.PlayerServer; import group.aelysium.rustyconnector.plugin.velocity.lib.family.bases.BaseServerFamily; import net.kyori.adventure.text.Component; @@ -881,7 +881,7 @@ else for (PlayerServer server : family.lockedServers()) { boolean isFriendMessagingEnabled = friendsService.settings().allowMessaging(); boolean canSeeFriendFamilies = friendsService.settings().showFamilies(); - List friends = friendsService.findFriends(player).orElse(null); + List friends = friendsService.findFriends(player).orElse(null); if(friends != null && friends.size() != 0) { final Component[] playersList = {text("")}; diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/parties/PartyInvite.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/parties/PartyInvite.java index 6759dd28a..c2da9f142 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/parties/PartyInvite.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/parties/PartyInvite.java @@ -2,7 +2,7 @@ import com.velocitypowered.api.proxy.Player; import group.aelysium.rustyconnector.plugin.velocity.lib.lang.VelocityLang; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import java.lang.ref.WeakReference; import java.util.Objects; @@ -11,21 +11,21 @@ public class PartyInvite { private final PartyService partyService; private final WeakReference party; - private FakePlayer sender; - private FakePlayer target; + private ResolvablePlayer sender; + private ResolvablePlayer target; private Boolean isAcknowledged = null; public PartyInvite(PartyService partyService, Party party, Player sender, Player target) { this.partyService = partyService; this.party = new WeakReference<>(party); - this.sender = FakePlayer.from(sender); - this.target = FakePlayer.from(target); + this.sender = ResolvablePlayer.from(sender); + this.target = ResolvablePlayer.from(target); } - public FakePlayer sender() { + public ResolvablePlayer sender() { return this.sender; } - public FakePlayer target() { + public ResolvablePlayer target() { return this.target; } diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/parties/PartyService.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/parties/PartyService.java index 0c1d4c182..7203f9729 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/parties/PartyService.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/parties/PartyService.java @@ -8,7 +8,7 @@ import group.aelysium.rustyconnector.plugin.velocity.lib.friends.FriendsService; import group.aelysium.rustyconnector.plugin.velocity.lib.lang.VelocityLang; import group.aelysium.rustyconnector.plugin.velocity.lib.parties.commands.CommandParty; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import group.aelysium.rustyconnector.plugin.velocity.lib.server.PlayerServer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -114,7 +114,7 @@ public PartyInvite invitePlayer(Party party, Player sender, Player target) { } public List findInvitesToTarget(Player target) { - return this.invites.stream().filter(invite -> invite.target().equals(FakePlayer.from(target))).findAny().stream().toList(); + return this.invites.stream().filter(invite -> invite.target().equals(ResolvablePlayer.from(target))).findAny().stream().toList(); } public Optional findInvite(Player target, Player sender) { return this.invites.stream().filter(invite -> invite.target().equals(target) && invite.sender().equals(sender)).findFirst(); diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/parties/commands/CommandParty.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/parties/commands/CommandParty.java index eeda4b31f..92e48b6f7 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/parties/commands/CommandParty.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/parties/commands/CommandParty.java @@ -17,7 +17,7 @@ import group.aelysium.rustyconnector.plugin.velocity.lib.parties.Party; import group.aelysium.rustyconnector.plugin.velocity.lib.parties.PartyInvite; import group.aelysium.rustyconnector.plugin.velocity.lib.parties.PartyService; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import group.aelysium.rustyconnector.plugin.velocity.lib.server.PlayerServer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -271,7 +271,7 @@ public static BrigadierCommand create(PartyService partyService) { } FriendsService friendsService = api.services().friendsService().orElseThrow(); - List friends = friendsService.findFriends(player).orElseThrow(); + List friends = friendsService.findFriends(player).orElseThrow(); if(friends.size() == 0) { builder.suggest("You don't have any friends you can invite to your party!"); return builder.buildFuture(); @@ -317,7 +317,7 @@ public static BrigadierCommand create(PartyService partyService) { return closeMessage(player, VelocityLang.PARTY_INVITE_ONLY_LEADER_CAN_SEND); String username = context.getArgument("username", String.class); - FakePlayer targetPlayerResolvable = api.services().playerService().fetch(username).orElse(null); + ResolvablePlayer targetPlayerResolvable = api.services().playerService().fetch(username).orElse(null); if(targetPlayerResolvable == null || targetPlayerResolvable.resolve().isEmpty()) return closeMessage(player, VelocityLang.NO_PLAYER.build(username)); @@ -333,8 +333,8 @@ public static BrigadierCommand create(PartyService partyService) { try { if (partyService.settings().friendsOnly()) if (!api.services().friendsService().orElseThrow().areFriends( - FakePlayer.from(player), - FakePlayer.from(targetPlayer) + ResolvablePlayer.from(player), + ResolvablePlayer.from(targetPlayer) )) return closeMessage(player, VelocityLang.PARTY_INVITE_FRIENDS_ONLY); } catch (Exception ignore) {} diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/players/PlayerService.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/players/PlayerService.java index 1aa864b74..cf35c5c6b 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/players/PlayerService.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/players/PlayerService.java @@ -6,7 +6,6 @@ import group.aelysium.rustyconnector.plugin.velocity.lib.storage.StorageRoot; import one.microstream.storage.embedded.types.EmbeddedStorageManager; -import java.io.SyncFailedException; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -18,7 +17,7 @@ public PlayerService(MySQLStorage storage) { this.storage = storage.storageManager(); } - public Optional fetch(UUID uuid) { + public Optional fetch(UUID uuid) { try { StorageRoot root = (StorageRoot) this.storage.root(); @@ -30,7 +29,7 @@ public Optional fetch(UUID uuid) { return Optional.empty(); } - public Optional fetch(String username) { + public Optional fetch(String username) { try { StorageRoot root = (StorageRoot) this.storage.root(); @@ -46,8 +45,8 @@ public void savePlayer(Player player) { try { StorageRoot root = (StorageRoot) this.storage.root(); - List players = root.players(); - players.add(FakePlayer.from(player)); + List players = root.players(); + players.add(ResolvablePlayer.from(player)); this.storage.store(players); } catch (Exception e) { diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/players/FakePlayer.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/players/ResolvablePlayer.java similarity index 68% rename from plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/players/FakePlayer.java rename to plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/players/ResolvablePlayer.java index a059e8734..7bbbf15e7 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/players/FakePlayer.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/players/ResolvablePlayer.java @@ -7,11 +7,11 @@ import java.util.Optional; import java.util.UUID; -public class FakePlayer { +public class ResolvablePlayer { protected UUID uuid; protected String username; - protected FakePlayer(UUID uuid, String username) { + protected ResolvablePlayer(UUID uuid, String username) { this.uuid = uuid; this.username = username; } @@ -28,14 +28,14 @@ public boolean equals(Object object) { if (this == object) return true; if (object == null || getClass() != object.getClass()) return false; - FakePlayer that = (FakePlayer) object; + ResolvablePlayer that = (ResolvablePlayer) object; return Objects.equals(uuid, that.uuid) && Objects.equals(username, that.username); } - public static FakePlayer from(Player player) { - return new FakePlayer(player.getUniqueId(), player.getUsername()); + public static ResolvablePlayer from(Player player) { + return new ResolvablePlayer(player.getUniqueId(), player.getUsername()); } - public static FakePlayer from(UUID uuid, String username) { - return new FakePlayer(uuid, username); + public static ResolvablePlayer from(UUID uuid, String username) { + return new ResolvablePlayer(uuid, username); } } \ No newline at end of file diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/PlayerServer.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/PlayerServer.java index 7bf662763..e7477fb37 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/PlayerServer.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/PlayerServer.java @@ -19,11 +19,12 @@ import java.rmi.ConnectException; import java.security.InvalidAlgorithmParameterException; +import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; public class PlayerServer implements group.aelysium.rustyconnector.core.lib.model.PlayerServer { - private final String id; + private final UUID id = UUID.randomUUID(); private RegisteredServer registeredServer = null; private final ServerInfo serverInfo; private BaseServerFamily family; @@ -46,7 +47,6 @@ public PlayerServer(ServerInfo serverInfo, int softPlayerCap, int hardPlayerCap, if(this.softPlayerCap > this.hardPlayerCap) this.softPlayerCap = this.hardPlayerCap; this.timeout = new AtomicInteger(timeout); - this.id = MD5.hash(serverInfo.getName() + serverInfo.getAddress()); } public boolean stale() { @@ -58,7 +58,7 @@ public void setTimeout(int newTimeout) { this.timeout.set(newTimeout); } - public String id() { + public UUID id() { return this.id; } diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/ResolvableServer.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/ResolvableServer.java new file mode 100644 index 000000000..e7ac6a731 --- /dev/null +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/ResolvableServer.java @@ -0,0 +1,29 @@ +package group.aelysium.rustyconnector.plugin.velocity.lib.server; + +import com.velocitypowered.api.proxy.server.ServerInfo; +import group.aelysium.rustyconnector.plugin.velocity.central.Tinder; +import group.aelysium.rustyconnector.plugin.velocity.lib.family.ResolvableFamily; + +import java.util.Optional; +import java.util.UUID; + +public record ResolvableServer(UUID uuid, ServerInfo serverInfo, ResolvableFamily family) { + public Optional resolve() { + PlayerServer potentialPlayerServer = Tinder.get().services().serverService().search(this.uuid); + if(potentialPlayerServer == null) return Optional.empty(); + return Optional.of(potentialPlayerServer); + } + + @Override + public boolean equals(Object object) { + if (this == object) return true; + if (object == null || getClass() != object.getClass()) return false; + + ResolvableServer that = (ResolvableServer) object; + return this.serverInfo.equals(that.serverInfo()); + } + + public static ResolvableServer from(PlayerServer server) { + return new ResolvableServer(server.id(), server.serverInfo(), ResolvableFamily.from(server.family())); + } +} diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/ServerService.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/ServerService.java index dbe096876..94c1742fd 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/ServerService.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/ServerService.java @@ -17,6 +17,7 @@ import java.lang.ref.Reference; import java.lang.ref.WeakReference; import java.net.InetSocketAddress; +import java.util.UUID; import java.util.Vector; public class ServerService extends Service { @@ -38,6 +39,16 @@ public int serverInterval() { return this.serverInterval; } + public PlayerServer search(UUID uuid) { + for(BaseServerFamily family : Tinder.get().services().familyService().dump()) { + PlayerServer server = family.findServer(uuid); + if(server == null) continue; + + return server; + } + return null; + } + /** * Search for a server. * @param serverInfo The server info to search for. diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/viewport/events/ServerPlayerCountEvent.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/viewport/events/ServerPlayerCountEvent.java index 4bc9f3472..a2a4c2ece 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/viewport/events/ServerPlayerCountEvent.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/server/viewport/events/ServerPlayerCountEvent.java @@ -25,7 +25,7 @@ public ServerPlayerCountEvent(PlayerServer server, int playerCount) { public String toJsonPacket() { JsonObject object = new JsonObject(); - object.add("id", new JsonPrimitive(server.id())); + object.add("id", new JsonPrimitive(server.id().toString())); object.add("name", new JsonPrimitive(server.serverInfo().getName())); object.add("player_count", new JsonPrimitive(playerCount)); diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/storage/MySQLStorage.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/storage/MySQLStorage.java index b6109a138..acdd1c1f8 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/storage/MySQLStorage.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/storage/MySQLStorage.java @@ -7,12 +7,14 @@ import one.microstream.afs.sql.types.SqlProviderMariaDb; import one.microstream.storage.embedded.types.EmbeddedStorage; import one.microstream.storage.embedded.types.EmbeddedStorageManager; +import one.microstream.storage.types.StorageConfiguration; import org.mariadb.jdbc.MariaDbDataSource; import java.net.InetSocketAddress; import java.sql.SQLException; public class MySQLStorage extends Service { + protected String jdbc; protected InetSocketAddress address; protected UserPass userPass; protected String database; @@ -34,9 +36,7 @@ protected MySQLStorage(InetSocketAddress address, UserPass userPass, String data ) ); - final EmbeddedStorageManager storageManager = EmbeddedStorage.start( - fileSystem.ensureDirectoryPath("RustyConnector_storage") - ); + final EmbeddedStorageManager storageManager = EmbeddedStorage.start(); if(storageManager.root() == null) { storageManager.setRoot(new StorageRoot()); diff --git a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/storage/StorageRoot.java b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/storage/StorageRoot.java index ecc6f4adb..b4c03e49f 100644 --- a/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/storage/StorageRoot.java +++ b/plugin/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/storage/StorageRoot.java @@ -2,7 +2,7 @@ import group.aelysium.rustyconnector.plugin.velocity.lib.family.static_family.ServerResidence; import group.aelysium.rustyconnector.plugin.velocity.lib.friends.FriendMapping; -import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer; +import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer; import java.util.ArrayList; import java.util.List; @@ -10,11 +10,11 @@ public class StorageRoot{ private final String name = "RustyConnector-storage"; - private final List players = new ArrayList<>(); + private final List players = new ArrayList<>(); private final List friends = new ArrayList<>(); private final List residence = new ArrayList<>(); - public List players() { + public List players() { return players; }