From 0362e030f7ee687323e977ccc87aa11b1c61d01b Mon Sep 17 00:00:00 2001 From: TofaDev <94196761+TofaDev@users.noreply.github.com> Date: Sun, 17 Sep 2023 00:43:14 +0700 Subject: [PATCH 01/18] Change confirmation sent message into minimessage format (#69) * change confirmation sent message into minimessage format * Added click to copy confirmation code in config --- core/src/main/resources/configurations/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/resources/configurations/config.yml b/core/src/main/resources/configurations/config.yml index f46df9ce..2e03e043 100644 --- a/core/src/main/resources/configurations/config.yml +++ b/core/src/main/resources/configurations/config.yml @@ -281,7 +281,7 @@ messages: usage: '&a/addvk' link-limit-reached: 'Слишком много привязанных аккаунтов на данный ВК' already-linked: '&cВы уже привязали аккаунт ВК' - confirmation-sent: '&aВсё почти готово. Напиши в личные сообщения в группу &lhttps://vk.com/examplegroup: /code %code% После ввода бот Вконтакте ответит вам что всё прошло успешно' + confirmation-sent: '[MINIMESSAGE]Всё почти готово. Напиши в личные сообщения в группу https://vk.com/examplegroup: /code Нажми, чтобы скопировать код">%code% После ввода бот Вконтакте ответит вам что всё прошло успешно' confirmation-success: '&aАккаунт успешно привязан' kicked: '&cВы были кикнуты из сервера по запросу ВК' enter-confirmed: '&aВы подтвердили аккаунт в вк' @@ -297,7 +297,7 @@ messages: usage: '&a/addtg' link-limit-reached: 'Слишком много привязанных аккаунтов на данный Telegram' already-linked: '&cВы уже привязали аккаунт Telegram' - confirmation-sent: '&aВсё почти готово. Напиши в личные сообщения боту в телеграм @examplebot: /code %code% После ввода бот Telegram ответит вам что всё прошло успешно' + confirmation-sent: '[MINIMESSAGE]Всё почти готово. Напиши в личные сообщения в телеграм @examplebot https://vk.com/examplegroup: /code Нажми, чтобы скопировать код">%code% После ввода бот Телеграм ответит вам что всё прошло успешно' confirmation-success: '&aАккаунт успешно привязан' kicked: '&cВы были кикнуты из сервера по запросу Telegram' enter-confirmed: '&aВы подтвердили аккаунт в Telegram' @@ -313,7 +313,7 @@ messages: usage: '&a/adddiscord' link-limit-reached: 'Слишком много привязанных аккаунтов на данный Discord' already-linked: '&cВы уже привязали аккаунт Discord' - confirmation-sent: '&aВсё почти готово. Напиши в личные сообщения боту в дискорде: /code %code% После ввода бот Discord ответит вам что всё прошло успешно' + confirmation-sent: '[MINIMESSAGE]Всё почти готово. Напиши в личные сообщения в Дискорд https://vk.com/examplegroup: /code Нажми, чтобы скопировать код">%code% После ввода Дискорд бот ответит вам что всё прошло успешно' confirmation-success: '&aАккаунт успешно привязан' already-sent: '&cВы уже отправили код в Discord. Пожалуйста проверьте ваши сообщения Discord' kicked: '&cВы были кикнуты из сервера по запросу Discord' From f4d19a1017aac96f7f6d9e050edb97511c2087bf Mon Sep 17 00:00:00 2001 From: bivashy <85439143+bivashy@users.noreply.github.com> Date: Fri, 22 Sep 2023 19:16:38 +0600 Subject: [PATCH 02/18] Delay support for commands (#70) * Add CommandCooldown annotation * Add CommandCooldownCondition * Add cooldown-command message * Register CommandCooldownCondition --- .../commands/MessengerCommandRegistry.java | 6 ++- .../commands/ServerCommandsRegistry.java | 2 + .../commands/annotation/CommandCooldown.java | 17 +++++++ .../validator/CommandCooldownCondition.java | 48 +++++++++++++++++++ .../main/resources/configurations/config.yml | 2 +- .../configurations/discord-config.yml | 2 + .../configurations/telegram-config.yml | 4 +- .../resources/configurations/vk-config.yml | 4 +- 8 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 core/src/main/java/me/mastercapexd/auth/shared/commands/annotation/CommandCooldown.java create mode 100644 core/src/main/java/me/mastercapexd/auth/shared/commands/validator/CommandCooldownCondition.java diff --git a/core/src/main/java/me/mastercapexd/auth/messenger/commands/MessengerCommandRegistry.java b/core/src/main/java/me/mastercapexd/auth/messenger/commands/MessengerCommandRegistry.java index 5b66cac6..a3a06c74 100644 --- a/core/src/main/java/me/mastercapexd/auth/messenger/commands/MessengerCommandRegistry.java +++ b/core/src/main/java/me/mastercapexd/auth/messenger/commands/MessengerCommandRegistry.java @@ -23,6 +23,7 @@ import me.mastercapexd.auth.shared.commands.LinkCodeCommand; import me.mastercapexd.auth.shared.commands.MessengerLinkCommandTemplate; import me.mastercapexd.auth.shared.commands.parameter.MessengerLinkContext; +import me.mastercapexd.auth.shared.commands.validator.CommandCooldownCondition; import revxrsal.commands.CommandHandler; import revxrsal.commands.command.CommandActor; import revxrsal.commands.exception.SendMessageException; @@ -30,6 +31,7 @@ import revxrsal.commands.orphan.Orphans; public abstract class MessengerCommandRegistry { + private static final AuthPlugin PLUGIN = AuthPlugin.instance(); private final CommandHandler commandHandler; private final LinkType linkType; @@ -50,6 +52,7 @@ private void registerContexts() { commandHandler.registerContextValue(LinkType.class, linkType); + commandHandler.registerCondition(new CommandCooldownCondition<>(linkType.getLinkMessages(), SendMessageException::new)); commandHandler.registerCondition((actor, command, arguments) -> { if (!command.hasAnnotation(GoogleUse.class)) return; @@ -105,7 +108,7 @@ private void registerContexts() { throw new SendMessageException(linkType.getSettings().getMessages().getMessage("account-not-found")); Optional linkUser = account.findFirstLinkUser(user -> user.getLinkType().equals(linkType)); - if(!linkType.getSettings().isAdministrator(userId)) { + if (!linkType.getSettings().isAdministrator(userId)) { if (!linkUser.isPresent()) throw new SendMessageException(linkType.getSettings().getMessages().getMessage("not-your-account", linkType.newMessageContext(account))); @@ -171,4 +174,5 @@ protected LinkCommandActorWrapper wrapActor(CommandActor actor) { } protected abstract MessengerLinkCommandTemplate createLinkCommand(); + } diff --git a/core/src/main/java/me/mastercapexd/auth/server/commands/ServerCommandsRegistry.java b/core/src/main/java/me/mastercapexd/auth/server/commands/ServerCommandsRegistry.java index 743b9ffd..42d13c26 100644 --- a/core/src/main/java/me/mastercapexd/auth/server/commands/ServerCommandsRegistry.java +++ b/core/src/main/java/me/mastercapexd/auth/server/commands/ServerCommandsRegistry.java @@ -37,6 +37,7 @@ import me.mastercapexd.auth.shared.commands.TelegramLinkCommand; import me.mastercapexd.auth.shared.commands.VKLinkCommand; import me.mastercapexd.auth.shared.commands.parameter.MessengerLinkContext; +import me.mastercapexd.auth.shared.commands.validator.CommandCooldownCondition; import revxrsal.commands.CommandHandler; import revxrsal.commands.command.ArgumentStack; import revxrsal.commands.command.CommandActor; @@ -149,6 +150,7 @@ private void registerCommandContexts() { })); }); + commandHandler.registerCondition(new CommandCooldownCondition<>(config.getServerMessages(), SendComponentException::new)); commandHandler.registerCondition((actor, command, arguments) -> { if (!command.hasAnnotation(GoogleUse.class)) return; diff --git a/core/src/main/java/me/mastercapexd/auth/shared/commands/annotation/CommandCooldown.java b/core/src/main/java/me/mastercapexd/auth/shared/commands/annotation/CommandCooldown.java new file mode 100644 index 00000000..88c9a140 --- /dev/null +++ b/core/src/main/java/me/mastercapexd/auth/shared/commands/annotation/CommandCooldown.java @@ -0,0 +1,17 @@ +package me.mastercapexd.auth.shared.commands.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.concurrent.TimeUnit; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface CommandCooldown { + + long value(); + + TimeUnit unit() default TimeUnit.MILLISECONDS; + +} diff --git a/core/src/main/java/me/mastercapexd/auth/shared/commands/validator/CommandCooldownCondition.java b/core/src/main/java/me/mastercapexd/auth/shared/commands/validator/CommandCooldownCondition.java new file mode 100644 index 00000000..f7d370da --- /dev/null +++ b/core/src/main/java/me/mastercapexd/auth/shared/commands/validator/CommandCooldownCondition.java @@ -0,0 +1,48 @@ +package me.mastercapexd.auth.shared.commands.validator; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import com.bivashy.auth.api.config.message.Messages; + +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; +import revxrsal.commands.command.CommandActor; +import revxrsal.commands.command.ExecutableCommand; +import revxrsal.commands.process.CommandCondition; + +public class CommandCooldownCondition implements CommandCondition { + + private final Map cooldownMap = new HashMap<>(); + private final Messages messages; + private final Function messageException; + + public CommandCooldownCondition(Messages messages, Function messageException) { + this.messages = messages; + this.messageException = messageException; + } + + @Override + public void test(@NotNull CommandActor commandActor, @NotNull ExecutableCommand executableCommand, @NotNull @Unmodifiable List list) { + if (!executableCommand.hasAnnotation(CommandCooldown.class)) + return; + + CommandCooldown commandCooldown = executableCommand.getAnnotation(CommandCooldown.class); + long cooldownInMillis = commandCooldown.unit().toMillis(commandCooldown.value()); + + if (!cooldownMap.containsKey(executableCommand.getId())) { + cooldownMap.putIfAbsent(executableCommand.getId(), System.currentTimeMillis()); + return; + } + + long timestampDelta = System.currentTimeMillis() - cooldownMap.get(executableCommand.getId()); + if (timestampDelta < cooldownInMillis) + throw messageException.apply(messages.getMessage("command-cooldown")); + cooldownMap.put(executableCommand.getId(), System.currentTimeMillis()); + } + +} diff --git a/core/src/main/resources/configurations/config.yml b/core/src/main/resources/configurations/config.yml index 2e03e043..bfbdd15d 100644 --- a/core/src/main/resources/configurations/config.yml +++ b/core/src/main/resources/configurations/config.yml @@ -363,7 +363,7 @@ messages: config-migrated: '&aКонфигурация успешно мигрирована' # Ошибки в командах player-offline: '&cИгрок с ником %account_name% оффлайн!' - + command-cooldown: '&cВы слишком часто используете данную команду! Попробуйте позже.' # Название аргумента указывается в виде arg1, arg2, arg3... unresolved-argument: '&cВы не указали аргумент: %argument_name%' unresolved-number: '&cОжидалось число, но вы указали %input%' diff --git a/core/src/main/resources/configurations/discord-config.yml b/core/src/main/resources/configurations/discord-config.yml index a9657960..fb20022f 100644 --- a/core/src/main/resources/configurations/discord-config.yml +++ b/core/src/main/resources/configurations/discord-config.yml @@ -422,6 +422,8 @@ discord: google-unlink-not-have-google: 'Ошибка! У аккаунта нету гугл ключа' google-unlinked: 'Гугл успешно сброшен!' + command-cooldown: '&cВы слишком часто используете данную команду! Попробуйте позже.' + not-enough-permission: 'Недостаточно прав для использования этой команды! Вы должны добавить себя в список админов!' unresolved-argument: 'Вы не указали аргумент: %argument_name%' diff --git a/core/src/main/resources/configurations/telegram-config.yml b/core/src/main/resources/configurations/telegram-config.yml index 9095b056..99e2a836 100644 --- a/core/src/main/resources/configurations/telegram-config.yml +++ b/core/src/main/resources/configurations/telegram-config.yml @@ -305,7 +305,9 @@ telegram: google-unlink-not-enough-arguments: 'Недостаточно аргументов! Правильный ввод: /гуглотвязать [ник]' google-unlink-not-have-google: 'Ошибка! У аккаунта нету гугл ключа' google-unlinked: 'Гугл успешно сброшен!' - + + command-cooldown: '&cВы слишком часто используете данную команду! Попробуйте позже.' + not-enough-permission: 'Недостаточно прав для использования этой команды! Вы должны добавить себя в список админов!' unresolved-argument: 'Вы не указали аргумент: %argument_name%' diff --git a/core/src/main/resources/configurations/vk-config.yml b/core/src/main/resources/configurations/vk-config.yml index 9202ebac..802a54be 100644 --- a/core/src/main/resources/configurations/vk-config.yml +++ b/core/src/main/resources/configurations/vk-config.yml @@ -365,7 +365,9 @@ vk: google-unlink-not-enough-arguments: 'Недостаточно аргументов! Правильный ввод: /гуглотвязать [ник]' google-unlink-not-have-google: 'Ошибка! У аккаунта нету гугл ключа' google-unlinked: 'Гугл успешно сброшен!' - + + command-cooldown: '&cВы слишком часто используете данную команду! Попробуйте позже.' + not-enough-permission: 'Недостаточно прав для использования этой команды! Вы должны добавить себя в список админов!' unresolved-argument: 'Вы не указали аргумент: %argument_name%' From d802eb3cbe5a5008c8d9aafc78f7550a09c467b3 Mon Sep 17 00:00:00 2001 From: bivashy Date: Tue, 26 Sep 2023 00:12:15 +0600 Subject: [PATCH 03/18] Bump libby version 1.3.4 -> 2.0.0 --- api/pom.xml | 2 +- .../auth/api/management/LibraryManagement.java | 6 +++--- bungee/pom.xml | 2 +- .../auth/bungee/BungeeAuthPluginBootstrap.java | 6 ++---- .../auth/management/BaseLibraryManagement.java | 5 ++--- pom.xml | 14 ++++++-------- velocity/pom.xml | 2 +- .../auth/velocity/VelocityAuthPluginBootstrap.java | 6 ++++-- 8 files changed, 20 insertions(+), 23 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 45ad3a18..a2be0b51 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -20,7 +20,7 @@ 1.5.0 1.2 4.0.2 - 1.3.4 + 2.0.0 diff --git a/api/src/main/java/com/bivashy/auth/api/management/LibraryManagement.java b/api/src/main/java/com/bivashy/auth/api/management/LibraryManagement.java index b83c798c..5b95e31f 100644 --- a/api/src/main/java/com/bivashy/auth/api/management/LibraryManagement.java +++ b/api/src/main/java/com/bivashy/auth/api/management/LibraryManagement.java @@ -2,9 +2,9 @@ import java.util.Collection; -import net.byteflux.libby.Library; -import net.byteflux.libby.LibraryManager; -import net.byteflux.libby.transitive.ExcludedDependency; +import com.alessiodp.libby.Library; +import com.alessiodp.libby.LibraryManager; +import com.alessiodp.libby.transitive.ExcludedDependency; public interface LibraryManagement { diff --git a/bungee/pom.xml b/bungee/pom.xml index 7d2d3e82..30173cc3 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -16,7 +16,7 @@ 4.3.0 6.5.0 0.4.2 - 1.3.4 + 2.0.0 diff --git a/bungee/src/main/java/me/mastercapexd/auth/bungee/BungeeAuthPluginBootstrap.java b/bungee/src/main/java/me/mastercapexd/auth/bungee/BungeeAuthPluginBootstrap.java index 8f5238c1..b1de1f83 100644 --- a/bungee/src/main/java/me/mastercapexd/auth/bungee/BungeeAuthPluginBootstrap.java +++ b/bungee/src/main/java/me/mastercapexd/auth/bungee/BungeeAuthPluginBootstrap.java @@ -1,5 +1,6 @@ package me.mastercapexd.auth.bungee; +import com.alessiodp.libby.BungeeLibraryManager; import com.bivashy.auth.api.AuthPlugin; import com.bivashy.auth.api.management.LoginManagement; import com.bivashy.messenger.vk.message.VkMessage; @@ -14,11 +15,11 @@ import me.mastercapexd.auth.hooks.VkPluginHook; import me.mastercapexd.auth.management.BaseLibraryManagement; import me.mastercapexd.auth.vk.command.VKCommandRegistry; -import net.byteflux.libby.BungeeLibraryManager; import net.kyori.adventure.platform.bungeecord.BungeeAudiences; import net.md_5.bungee.api.plugin.Plugin; public class BungeeAuthPluginBootstrap extends Plugin { + private static BungeeAuthPluginBootstrap instance; private BungeeAudiences bungeeAudiences; private LoginManagement loginManagement; @@ -70,7 +71,4 @@ public BungeeAudiences getBungeeAudiences() { return bungeeAudiences; } - public AuthPlugin getAuthPlugin() { - return authPlugin; - } } \ No newline at end of file diff --git a/core/src/main/java/me/mastercapexd/auth/management/BaseLibraryManagement.java b/core/src/main/java/me/mastercapexd/auth/management/BaseLibraryManagement.java index 48a2fe30..6432f2ce 100644 --- a/core/src/main/java/me/mastercapexd/auth/management/BaseLibraryManagement.java +++ b/core/src/main/java/me/mastercapexd/auth/management/BaseLibraryManagement.java @@ -4,11 +4,10 @@ import java.util.Collection; import java.util.List; +import com.alessiodp.libby.Library; +import com.alessiodp.libby.LibraryManager; import com.bivashy.auth.api.management.LibraryManagement; -import net.byteflux.libby.Library; -import net.byteflux.libby.LibraryManager; - public class BaseLibraryManagement implements LibraryManagement { private static final String JDA_VERSION = "5.0.0-beta.11"; diff --git a/pom.xml b/pom.xml index 6fc63f10..a03cf08b 100644 --- a/pom.xml +++ b/pom.xml @@ -81,6 +81,12 @@ META-INF/SPONGEPO.RSA + + com.github.bivashy.libby:libby-core + + com/alessiodp/libby/** + + @@ -183,18 +189,10 @@ javax.annotation ${dependencies.relocation.package}.javax.annotation - - org.eclipse.aether - ${dependencies.relocation.package}.org.eclipse.aether - org.codehaus.plexus ${dependencies.relocation.package}.org.codehaus.plexus - - org.apache.maven - ${dependencies.relocation.package}.org.apache.maven - true diff --git a/velocity/pom.xml b/velocity/pom.xml index 7bc44f74..b00384c8 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -16,7 +16,7 @@ 6.1.0 3.1.6 1.1.7 - 1.3.4 + 2.0.0 11 diff --git a/velocity/src/main/java/me/mastercapexd/auth/velocity/VelocityAuthPluginBootstrap.java b/velocity/src/main/java/me/mastercapexd/auth/velocity/VelocityAuthPluginBootstrap.java index a607eb4e..346e2bbf 100644 --- a/velocity/src/main/java/me/mastercapexd/auth/velocity/VelocityAuthPluginBootstrap.java +++ b/velocity/src/main/java/me/mastercapexd/auth/velocity/VelocityAuthPluginBootstrap.java @@ -5,6 +5,7 @@ import org.slf4j.Logger; +import com.alessiodp.libby.VelocityLibraryManager; import com.bivashy.auth.api.AuthPlugin; import com.bivashy.auth.api.server.ServerCore; import com.bivashy.messenger.vk.message.VkMessage; @@ -29,10 +30,10 @@ import me.mastercapexd.auth.velocity.listener.AuthenticationListener; import me.mastercapexd.auth.velocity.listener.VkDispatchListener; import me.mastercapexd.auth.vk.command.VKCommandRegistry; -import net.byteflux.libby.VelocityLibraryManager; import net.kyori.adventure.platform.AudienceProvider; public class VelocityAuthPluginBootstrap { + private static VelocityAuthPluginBootstrap instance; private final AudienceProvider audienceProvider; private final ServerCore core; @@ -59,7 +60,7 @@ public static VelocityAuthPluginBootstrap getInstance() { public void onProxyInitialize(ProxyInitializeEvent event) { this.authPlugin = new BaseAuthPlugin(audienceProvider, proxyServer.getPluginManager().fromInstance(this).map(PluginContainer::getDescription).flatMap(PluginDescription::getVersion).orElse("unknown"), - dataFolder, core, new BaseLibraryManagement(new VelocityLibraryManager<>(logger, dataFolder.toPath(), proxyServer.getPluginManager(), this))); + dataFolder, core, new BaseLibraryManagement(new VelocityLibraryManager<>(this, logger, dataFolder.toPath(), proxyServer.getPluginManager()))); initializeListener(); initializeCommand(); initializeLimbo(); @@ -98,4 +99,5 @@ public ProxyServer getProxyServer() { public AuthPlugin getAuthPlugin() { return authPlugin; } + } From b7b44bc073c1a4302144c37b92adeb5093920067 Mon Sep 17 00:00:00 2001 From: bivashy Date: Tue, 26 Sep 2023 00:31:31 +0600 Subject: [PATCH 04/18] Replace redundant Sets#newHashSet with built-in HashSet --- .../auth/bungee/api/bossbar/BungeeServerBossbar.java | 4 ++-- .../auth/server/commands/ChangePasswordCommand.java | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bungee/src/main/java/me/mastercapexd/auth/bungee/api/bossbar/BungeeServerBossbar.java b/bungee/src/main/java/me/mastercapexd/auth/bungee/api/bossbar/BungeeServerBossbar.java index faf52120..8d48dd6f 100644 --- a/bungee/src/main/java/me/mastercapexd/auth/bungee/api/bossbar/BungeeServerBossbar.java +++ b/bungee/src/main/java/me/mastercapexd/auth/bungee/api/bossbar/BungeeServerBossbar.java @@ -2,19 +2,19 @@ import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.Set; import java.util.UUID; import com.bivashy.auth.api.server.bossbar.ServerBossbar; import com.bivashy.auth.api.server.message.ServerComponent; import com.bivashy.auth.api.server.player.ServerPlayer; -import com.google.common.collect.Sets; import me.mastercapexd.auth.bungee.player.BungeeServerPlayer; import net.md_5.bungee.protocol.packet.BossBar; public class BungeeServerBossbar extends ServerBossbar { - private final Set players = Sets.newHashSet(); + private final Set players = new HashSet<>(); private final UUID uuid = UUID.randomUUID(); public BungeeServerBossbar(ServerComponent component) { diff --git a/core/src/main/java/me/mastercapexd/auth/server/commands/ChangePasswordCommand.java b/core/src/main/java/me/mastercapexd/auth/server/commands/ChangePasswordCommand.java index 864d9097..2c156fdf 100644 --- a/core/src/main/java/me/mastercapexd/auth/server/commands/ChangePasswordCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/server/commands/ChangePasswordCommand.java @@ -9,12 +9,14 @@ import io.github.revxrsal.eventbus.PostResult; import me.mastercapexd.auth.server.commands.parameters.DoublePassword; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import revxrsal.commands.annotation.Command; import revxrsal.commands.annotation.DefaultFor; import revxrsal.commands.annotation.Dependency; @Command({"passchange", "changepass", "changepassword"}) public class ChangePasswordCommand { + @Dependency private AuthPlugin plugin; @Dependency @@ -23,6 +25,7 @@ public class ChangePasswordCommand { private AccountDatabase accountStorage; @DefaultFor({"passchange", "changepass", "changepassword"}) + @CommandCooldown(5000) public void changePlayerPassword(ServerPlayer sender, DoublePassword password) { String id = config.getActiveIdentifierType().getId(sender); accountStorage.getAccount(id).thenAcceptAsync(account -> { @@ -49,4 +52,5 @@ public void changePlayerPassword(ServerPlayer sender, DoublePassword password) { sender.sendMessage(config.getServerMessages().getMessage("change-success")); }); } + } \ No newline at end of file From 1bf5d57c8eb5aebd8980a40728f63311e3ba8578 Mon Sep 17 00:00:00 2001 From: bivashy Date: Tue, 26 Sep 2023 00:53:26 +0600 Subject: [PATCH 05/18] Replace 'Bungee' with 'Velocity' in velocity pom.xml --- velocity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/velocity/pom.xml b/velocity/pom.xml index b00384c8..58d87bb4 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -52,7 +52,7 @@ - + com.github.bivashy.Lamp velocity From d0e5b83b600cf085e3f108474b108916dc353365 Mon Sep 17 00:00:00 2001 From: bivashy Date: Tue, 26 Sep 2023 01:03:56 +0600 Subject: [PATCH 06/18] Replace 'Elytrium' repository with 'repo-public' --- velocity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/velocity/pom.xml b/velocity/pom.xml index 58d87bb4..85f584d9 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -33,8 +33,8 @@ - elytrium-repo - https://maven.elytrium.net/repo/ + jnngl-public + https://maven.jnngl.me/public From 1f0812922f745ca263e1329a251534d0044a76dc Mon Sep 17 00:00:00 2001 From: bivashy <85439143+bivashy@users.noreply.github.com> Date: Sat, 30 Sep 2023 17:02:02 +0600 Subject: [PATCH 07/18] Bump Lamp version to 3.2.5 (#73) --- bungee/pom.xml | 2 +- core/pom.xml | 2 +- velocity/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bungee/pom.xml b/bungee/pom.xml index 30173cc3..00771214 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -12,7 +12,7 @@ 1.19-R0.1-SNAPSHOT - 3.1.6 + 3.2.5 4.3.0 6.5.0 0.4.2 diff --git a/core/pom.xml b/core/pom.xml index d7c1e883..9167008f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -16,7 +16,7 @@ 3.5.1 4.0.2 4.1.2 - 3.2.4 + 3.2.5 1.0.0 1.0.0 6.5.0 diff --git a/velocity/pom.xml b/velocity/pom.xml index 85f584d9..8ca4316b 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -14,7 +14,7 @@ 3.1.1 0.4.2 6.1.0 - 3.1.6 + 3.2.5 1.1.7 2.0.0 From 67b93371c11902ef8d4da8e48318da689bd77b82 Mon Sep 17 00:00:00 2001 From: bivashy <85439143+bivashy@users.noreply.github.com> Date: Sun, 1 Oct 2023 04:21:47 +0600 Subject: [PATCH 08/18] NanoLimboPlugin support (#74) * Add LimboPluginHook * Deprecate LimboServerWrapper * Soft depend on NanoLimboPlugin * Add NanoLimboPluginHook * Add VelocityNanoLimboPluginHook * Add dependencies for NanoLimboPlugin in velocity module pom.xml * Implement PluginHook in LimboPluginHook * Replace NanoLimboPluginHook with NanoLimboProvider * Add BungeeNanoLimboPluginHook * Add NanoLimbo as dependency in bungee pom.xml * Implement LimboPluginHook in LimboAPIHook * Properly implement LimboAPIHook#canHook * Remove redundant LimboHook * Use LimboPluginHook in ServerCore implementations * Create limbo-port in config.yml * Hook into NanoLimboPlugin if possible * Reuse IntStream in NanoLimboPluginHook * Define proper ClassLoader for NanoLimboProvider * Define limbo as initial server in velocity if required * Remove unused import statement * Define initial server on proxy joining * Remove LimboAPI support * Define initial server on proxy joining in velocity --- .../bivashy/auth/api/config/PluginConfig.java | 3 + .../auth/api/hook/LimboPluginHook.java | 9 ++ .../proxy/limbo/LimboServerWrapper.java | 1 + bungee/pom.xml | 9 ++ .../bungee/BungeeAuthPluginBootstrap.java | 16 +- .../auth/bungee/BungeeProxyCore.java | 15 +- .../nanolimbo/BungeeNanoLimboPluginHook.java | 58 +++++++ .../nanolimbo/BungeeNanoLimboProvider.java | 24 +++ bungee/src/main/resources/bungee.yml | 5 +- core/pom.xml | 9 ++ .../me/mastercapexd/auth/BaseAuthPlugin.java | 11 ++ .../auth/config/PluginConfigTemplate.java | 10 ++ .../auth/hooks/limbo/LimboHook.java | 10 -- .../nanolimbo/InfoForwardingFactory.java | 55 +++++++ .../auth/hooks/nanolimbo/NanoLimboConfig.java | 146 ++++++++++++++++++ .../hooks/nanolimbo/NanoLimboProvider.java | 59 +++++++ .../main/resources/configurations/config.yml | 4 + velocity/pom.xml | 21 ++- .../velocity/VelocityAuthPluginBootstrap.java | 14 +- .../auth/velocity/VelocityProxyCore.java | 17 +- .../velocity/hooks/limbo/LimboAPIHook.java | 42 ----- .../hooks/limbo/LimboAPIProvider.java | 47 ------ .../velocity/hooks/limbo/LimboAPIServer.java | 61 -------- .../hooks/limbo/config/LimboAPIConfig.java | 46 ------ .../hooks/limbo/config/LimboConfig.java | 63 -------- .../VelocityNanoLimboPluginHook.java | 52 +++++++ .../nanolimbo/VelocityNanoLimboProvider.java | 50 ++++++ velocity/src/main/resources/limbo.yml | 10 -- .../src/main/resources/velocity-plugin.json | 2 +- 29 files changed, 551 insertions(+), 318 deletions(-) create mode 100644 api/src/main/java/com/bivashy/auth/api/hook/LimboPluginHook.java create mode 100644 bungee/src/main/java/me/mastercapexd/auth/bungee/hooks/nanolimbo/BungeeNanoLimboPluginHook.java create mode 100644 bungee/src/main/java/me/mastercapexd/auth/bungee/hooks/nanolimbo/BungeeNanoLimboProvider.java delete mode 100644 core/src/main/java/me/mastercapexd/auth/hooks/limbo/LimboHook.java create mode 100644 core/src/main/java/me/mastercapexd/auth/hooks/nanolimbo/InfoForwardingFactory.java create mode 100644 core/src/main/java/me/mastercapexd/auth/hooks/nanolimbo/NanoLimboConfig.java create mode 100644 core/src/main/java/me/mastercapexd/auth/hooks/nanolimbo/NanoLimboProvider.java delete mode 100644 velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/LimboAPIHook.java delete mode 100644 velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/LimboAPIProvider.java delete mode 100644 velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/LimboAPIServer.java delete mode 100644 velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/config/LimboAPIConfig.java delete mode 100644 velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/config/LimboConfig.java create mode 100644 velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/nanolimbo/VelocityNanoLimboPluginHook.java create mode 100644 velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/nanolimbo/VelocityNanoLimboProvider.java delete mode 100644 velocity/src/main/resources/limbo.yml diff --git a/api/src/main/java/com/bivashy/auth/api/config/PluginConfig.java b/api/src/main/java/com/bivashy/auth/api/config/PluginConfig.java index 31f50154..40594a9c 100644 --- a/api/src/main/java/com/bivashy/auth/api/config/PluginConfig.java +++ b/api/src/main/java/com/bivashy/auth/api/config/PluginConfig.java @@ -2,6 +2,7 @@ import java.util.List; import java.util.regex.Pattern; +import java.util.stream.IntStream; import com.bivashy.auth.api.config.bossbar.BossBarSettings; import com.bivashy.auth.api.config.database.DatabaseSettings; @@ -42,6 +43,8 @@ public interface PluginConfig { List getAllowedCommands(); + IntStream getLimboPortRange(); + List getAuthenticationSteps(); String getAuthenticationStepName(int index); diff --git a/api/src/main/java/com/bivashy/auth/api/hook/LimboPluginHook.java b/api/src/main/java/com/bivashy/auth/api/hook/LimboPluginHook.java new file mode 100644 index 00000000..e1c5a630 --- /dev/null +++ b/api/src/main/java/com/bivashy/auth/api/hook/LimboPluginHook.java @@ -0,0 +1,9 @@ +package com.bivashy.auth.api.hook; + +import com.bivashy.auth.api.server.proxy.ProxyServer; + +public interface LimboPluginHook extends PluginHook { + + ProxyServer createServer(String serverName); + +} diff --git a/api/src/main/java/com/bivashy/auth/api/server/proxy/limbo/LimboServerWrapper.java b/api/src/main/java/com/bivashy/auth/api/server/proxy/limbo/LimboServerWrapper.java index 67e087dc..32cfeba6 100644 --- a/api/src/main/java/com/bivashy/auth/api/server/proxy/limbo/LimboServerWrapper.java +++ b/api/src/main/java/com/bivashy/auth/api/server/proxy/limbo/LimboServerWrapper.java @@ -2,5 +2,6 @@ import com.bivashy.auth.api.server.proxy.ProxyServer; +@Deprecated public interface LimboServerWrapper extends ProxyServer { } diff --git a/bungee/pom.xml b/bungee/pom.xml index 00771214..1f3b940d 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -17,6 +17,7 @@ 6.5.0 0.4.2 2.0.0 + 1.0.6 @@ -87,6 +88,14 @@ provided + + + com.github.bivashy.NanoLimboPlugin + api + ${nanolimbo.version} + provided + + com.github.bivashy.libby diff --git a/bungee/src/main/java/me/mastercapexd/auth/bungee/BungeeAuthPluginBootstrap.java b/bungee/src/main/java/me/mastercapexd/auth/bungee/BungeeAuthPluginBootstrap.java index b1de1f83..2ff8c64a 100644 --- a/bungee/src/main/java/me/mastercapexd/auth/bungee/BungeeAuthPluginBootstrap.java +++ b/bungee/src/main/java/me/mastercapexd/auth/bungee/BungeeAuthPluginBootstrap.java @@ -1,8 +1,10 @@ package me.mastercapexd.auth.bungee; +import java.util.Collection; +import java.util.Collections; + import com.alessiodp.libby.BungeeLibraryManager; -import com.bivashy.auth.api.AuthPlugin; -import com.bivashy.auth.api.management.LoginManagement; +import com.bivashy.auth.api.hook.LimboPluginHook; import com.bivashy.messenger.vk.message.VkMessage; import com.bivashy.messenger.vk.provider.VkApiProvider; import com.ubivashka.vk.bungee.BungeeVkApiPlugin; @@ -10,6 +12,7 @@ import me.mastercapexd.auth.BaseAuthPlugin; import me.mastercapexd.auth.bungee.commands.BungeeCommandsRegistry; import me.mastercapexd.auth.bungee.hooks.BungeeVkPluginHook; +import me.mastercapexd.auth.bungee.hooks.nanolimbo.BungeeNanoLimboPluginHook; import me.mastercapexd.auth.bungee.listener.AuthenticationListener; import me.mastercapexd.auth.bungee.listener.VkDispatchListener; import me.mastercapexd.auth.hooks.VkPluginHook; @@ -22,7 +25,6 @@ public class BungeeAuthPluginBootstrap extends Plugin { private static BungeeAuthPluginBootstrap instance; private BungeeAudiences bungeeAudiences; - private LoginManagement loginManagement; private BaseAuthPlugin authPlugin; public static BungeeAuthPluginBootstrap getInstance() { @@ -39,6 +41,7 @@ public void onEnable() { new BaseLibraryManagement(new BungeeLibraryManager(this))); initializeListener(); initializeCommand(); + initializeLimbo(); if (authPlugin.getConfig().getVKSettings().isEnabled()) initializeVk(); } @@ -57,6 +60,13 @@ private void initializeCommand() { new BungeeCommandsRegistry(this, authPlugin); } + private void initializeLimbo() { + Collection limboPluginHooks = Collections.singleton(new BungeeNanoLimboPluginHook(authPlugin.getConfig().getLimboPortRange())); + limboPluginHooks.stream() + .filter(LimboPluginHook::canHook) + .forEach(limboPluginHook -> authPlugin.putHook(LimboPluginHook.class, limboPluginHook)); + } + private void initializeVk() { authPlugin.putHook(VkPluginHook.class, new BungeeVkPluginHook()); diff --git a/bungee/src/main/java/me/mastercapexd/auth/bungee/BungeeProxyCore.java b/bungee/src/main/java/me/mastercapexd/auth/bungee/BungeeProxyCore.java index 20542fa5..53ad0728 100644 --- a/bungee/src/main/java/me/mastercapexd/auth/bungee/BungeeProxyCore.java +++ b/bungee/src/main/java/me/mastercapexd/auth/bungee/BungeeProxyCore.java @@ -10,11 +10,11 @@ import java.util.stream.Collectors; import com.bivashy.auth.api.AuthPlugin; +import com.bivashy.auth.api.hook.LimboPluginHook; import com.bivashy.auth.api.server.ServerCore; import com.bivashy.auth.api.server.bossbar.ServerBossbar; import com.bivashy.auth.api.server.message.ServerComponent; import com.bivashy.auth.api.server.player.ServerPlayer; -import com.bivashy.auth.api.server.proxy.limbo.LimboServerWrapper; import com.bivashy.auth.api.server.scheduler.ServerScheduler; import com.bivashy.auth.api.server.title.ServerTitle; @@ -25,7 +25,6 @@ import me.mastercapexd.auth.bungee.player.BungeeServerPlayer; import me.mastercapexd.auth.bungee.scheduler.BungeeSchedulerWrapper; import me.mastercapexd.auth.bungee.server.BungeeServer; -import me.mastercapexd.auth.hooks.limbo.LimboHook; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; @@ -109,15 +108,9 @@ public ServerComponent componentLegacy(String legacy) { @Override public Optional serverFromName(String serverName) { ServerInfo serverInfo = PROXY_SERVER.getServerInfo(serverName); - LimboHook limboHook = AuthPlugin.instance().getHook(LimboHook.class); - if (serverInfo == null && limboHook != null) { - if (!limboHook.isLimbo(serverName)) - return Optional.empty(); - LimboServerWrapper server = limboHook.createLimboWrapper(serverName); - if (!server.isExists()) - return Optional.empty(); - return Optional.of(server); - } + LimboPluginHook limboHook = AuthPlugin.instance().getHook(LimboPluginHook.class); + if (serverInfo == null && limboHook != null) + return Optional.of(limboHook.createServer(serverName)); return Optional.of(new BungeeServer(serverInfo)); } diff --git a/bungee/src/main/java/me/mastercapexd/auth/bungee/hooks/nanolimbo/BungeeNanoLimboPluginHook.java b/bungee/src/main/java/me/mastercapexd/auth/bungee/hooks/nanolimbo/BungeeNanoLimboPluginHook.java new file mode 100644 index 00000000..9841b798 --- /dev/null +++ b/bungee/src/main/java/me/mastercapexd/auth/bungee/hooks/nanolimbo/BungeeNanoLimboPluginHook.java @@ -0,0 +1,58 @@ +package me.mastercapexd.auth.bungee.hooks.nanolimbo; + +import java.net.SocketAddress; +import java.util.stream.IntStream; + +import com.bivashy.auth.api.AuthPlugin; +import com.bivashy.auth.api.config.PluginConfig; +import com.bivashy.auth.api.hook.LimboPluginHook; + +import me.mastercapexd.auth.bungee.BungeeAuthPluginBootstrap; +import me.mastercapexd.auth.bungee.server.BungeeServer; +import me.mastercapexd.auth.hooks.nanolimbo.NanoLimboProvider; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.config.ServerInfo; +import net.md_5.bungee.api.event.ServerConnectEvent; +import net.md_5.bungee.api.event.ServerConnectEvent.Reason; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.event.EventHandler; +import net.md_5.bungee.event.EventPriority; + +public class BungeeNanoLimboPluginHook implements LimboPluginHook, Listener { + + private final int[] limboPorts; + private NanoLimboProvider provider; + + public BungeeNanoLimboPluginHook(IntStream limboPortRange) { + this.limboPorts = limboPortRange.toArray(); + if (!canHook()) + return; + this.provider = new BungeeNanoLimboProvider(ProxyServer.getInstance().getPluginManager().getPlugin("NanoLimboBungee").getClass().getClassLoader()); + ProxyServer.getInstance().getPluginManager().registerListener(BungeeAuthPluginBootstrap.getInstance(), this); + } + + @Override + public com.bivashy.auth.api.server.proxy.ProxyServer createServer(String serverName) { + SocketAddress address = provider.findAvailableAddress(limboPorts).orElseThrow( + () -> new IllegalStateException("Cannot find available port for limbo server!")); + provider.createAndStartLimbo(address); + ServerInfo serverInfo = ProxyServer.getInstance().constructServerInfo(serverName, address, "", false); + ProxyServer.getInstance().getConfig().getServers().put(serverInfo.getName(), serverInfo); + return new BungeeServer(serverInfo); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onServerChoose(ServerConnectEvent event) { + // TODO: Implement ServerConnectEvent in the InitialServerManagement + if (event.getReason() != Reason.JOIN_PROXY) + return; + PluginConfig config = AuthPlugin.instance().getConfig(); + event.setTarget(config.findServerInfo(config.getAuthServers()).asProxyServer().as(BungeeServer.class).getServerInfo()); + } + + @Override + public boolean canHook() { + return ProxyServer.getInstance().getPluginManager().getPlugin("NanoLimboBungee") != null; + } + +} diff --git a/bungee/src/main/java/me/mastercapexd/auth/bungee/hooks/nanolimbo/BungeeNanoLimboProvider.java b/bungee/src/main/java/me/mastercapexd/auth/bungee/hooks/nanolimbo/BungeeNanoLimboProvider.java new file mode 100644 index 00000000..abf52d04 --- /dev/null +++ b/bungee/src/main/java/me/mastercapexd/auth/bungee/hooks/nanolimbo/BungeeNanoLimboProvider.java @@ -0,0 +1,24 @@ +package me.mastercapexd.auth.bungee.hooks.nanolimbo; + +import me.mastercapexd.auth.hooks.nanolimbo.NanoLimboProvider; +import ua.nanit.limbo.server.data.InfoForwarding; + +public class BungeeNanoLimboProvider implements NanoLimboProvider { + + private final ClassLoader classLoader; + + public BungeeNanoLimboProvider(ClassLoader classLoader) { + this.classLoader = classLoader; + } + + @Override + public InfoForwarding createForwarding() { + return FORWARDING_FACTORY.legacy(); + } + + @Override + public ClassLoader classLoader() { + return classLoader; + } + +} diff --git a/bungee/src/main/resources/bungee.yml b/bungee/src/main/resources/bungee.yml index 8c412cad..17998a56 100644 --- a/bungee/src/main/resources/bungee.yml +++ b/bungee/src/main/resources/bungee.yml @@ -1,5 +1,8 @@ name: mcAuth main: me.mastercapexd.auth.bungee.BungeeAuthPluginBootstrap version: ${project.version} -softDepends: [VK-API,JavaTelegramBotApi] +softDepends: + - VK-API + - JavaTelegramBotApi + - NanoLimboBungee author: bivashy, MasterCapeXD diff --git a/core/pom.xml b/core/pom.xml index 9167008f..30a8d87e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,6 +25,7 @@ 1.7.0 1.4.2 5.0.0-beta.11 + 1.0.6 1.9.15 3.9.4 @@ -162,5 +163,13 @@ ${jda.version} provided + + + + com.github.bivashy.NanoLimboPlugin + api + ${nanolimbo.version} + provided + \ No newline at end of file diff --git a/core/src/main/java/me/mastercapexd/auth/BaseAuthPlugin.java b/core/src/main/java/me/mastercapexd/auth/BaseAuthPlugin.java index cefa1e91..8e923eaa 100644 --- a/core/src/main/java/me/mastercapexd/auth/BaseAuthPlugin.java +++ b/core/src/main/java/me/mastercapexd/auth/BaseAuthPlugin.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.Executors; +import java.util.stream.IntStream; import com.bivashy.auth.api.AuthPlugin; import com.bivashy.auth.api.AuthPluginProvider; @@ -240,6 +241,16 @@ private void registerConfigurationProcessor() { if (path.isEmpty()) return null; return new File(path.replace("%plugin_folder%", getFolder().getAbsolutePath())); + }) + .registerFieldResolver(IntStream.class, (context) -> { + String number = context.getString(""); + if (number.isEmpty()) + return IntStream.of(0); + if (number.contains("-")) { + String[] range = number.split("-"); + return IntStream.range(Integer.parseInt(range[0]), Integer.parseInt(range[1])); + } + return IntStream.of(Integer.parseInt(number)); }); } diff --git a/core/src/main/java/me/mastercapexd/auth/config/PluginConfigTemplate.java b/core/src/main/java/me/mastercapexd/auth/config/PluginConfigTemplate.java index fe12a8ed..bc01c56f 100644 --- a/core/src/main/java/me/mastercapexd/auth/config/PluginConfigTemplate.java +++ b/core/src/main/java/me/mastercapexd/auth/config/PluginConfigTemplate.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.stream.IntStream; import com.bivashy.auth.api.AuthPlugin; import com.bivashy.auth.api.config.PluginConfig; @@ -37,6 +38,7 @@ import me.mastercapexd.auth.config.vk.BaseVKSettings; public abstract class PluginConfigTemplate implements PluginConfig { + protected final AuthPlugin plugin; private final List allowedPatternCommands; protected ConfigurationSectionHolder configurationRoot; @@ -101,6 +103,8 @@ public abstract class PluginConfigTemplate implements PluginConfig { private ConfigurationDuration joinDelay = new ConfigurationDuration(0); @ConfigField("block-chat") private boolean blockChat = true; + @ConfigField("limbo-port") + private IntStream limboPortRange = IntStream.range(49152, 65535); @ConfigField("authentication-steps") private List authenticationSteps = Arrays.asList("REGISTER", "LOGIN", "VK_LINK", "TELEGRAM_LINK", "GOOGLE_LINK", "ENTER_SERVER"); @@ -287,5 +291,11 @@ public String getAuthenticationStepName(int index) { return index >= 0 && index < authenticationSteps.size() ? authenticationSteps.get(index) : "NULL"; } + @Override + public IntStream getLimboPortRange() { + return limboPortRange; + } + protected abstract ConfigurationSectionHolder createConfiguration(AuthPlugin plugin); + } \ No newline at end of file diff --git a/core/src/main/java/me/mastercapexd/auth/hooks/limbo/LimboHook.java b/core/src/main/java/me/mastercapexd/auth/hooks/limbo/LimboHook.java deleted file mode 100644 index d0ca8225..00000000 --- a/core/src/main/java/me/mastercapexd/auth/hooks/limbo/LimboHook.java +++ /dev/null @@ -1,10 +0,0 @@ -package me.mastercapexd.auth.hooks.limbo; - -import com.bivashy.auth.api.hook.PluginHook; -import com.bivashy.auth.api.server.proxy.limbo.LimboServerWrapper; - -public interface LimboHook extends PluginHook { - boolean isLimbo(String serverName); - - LimboServerWrapper createLimboWrapper(String serverName); -} diff --git a/core/src/main/java/me/mastercapexd/auth/hooks/nanolimbo/InfoForwardingFactory.java b/core/src/main/java/me/mastercapexd/auth/hooks/nanolimbo/InfoForwardingFactory.java new file mode 100644 index 00000000..f3cf93c6 --- /dev/null +++ b/core/src/main/java/me/mastercapexd/auth/hooks/nanolimbo/InfoForwardingFactory.java @@ -0,0 +1,55 @@ +package me.mastercapexd.auth.hooks.nanolimbo; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import ua.nanit.limbo.server.data.InfoForwarding; +import ua.nanit.limbo.server.data.InfoForwarding.Type; + +// Class for hiding InfoForwarding dirty way initialization +public class InfoForwardingFactory { + + public InfoForwarding none() { + Map map = Collections.singletonMap("type", Type.NONE); + return createForwarding(map); + } + + public InfoForwarding legacy() { + Map map = Collections.singletonMap("type", Type.LEGACY); + return createForwarding(map); + } + + public InfoForwarding modern(byte[] secretKey) { + Map map = new HashMap<>(); + map.put("type", Type.MODERN); + map.put("secretKey", secretKey); + return createForwarding(map); + } + + public InfoForwarding bungeeGuard(Collection tokens) { + Map map = new HashMap<>(); + map.put("type", Type.BUNGEE_GUARD); + map.put("tokens", new ArrayList<>(tokens)); + return createForwarding(map); + } + + private InfoForwarding createForwarding(Map map) { + InfoForwarding forwarding = new InfoForwarding(); + for (Entry entry : map.entrySet()) { + Class clazz = forwarding.getClass(); + try { + Field field = clazz.getDeclaredField(entry.getKey()); + field.setAccessible(true); + field.set(forwarding, entry.getValue()); + } catch (NoSuchFieldException | IllegalAccessException ignored) { + } + } + return forwarding; + } + +} \ No newline at end of file diff --git a/core/src/main/java/me/mastercapexd/auth/hooks/nanolimbo/NanoLimboConfig.java b/core/src/main/java/me/mastercapexd/auth/hooks/nanolimbo/NanoLimboConfig.java new file mode 100644 index 00000000..03671932 --- /dev/null +++ b/core/src/main/java/me/mastercapexd/auth/hooks/nanolimbo/NanoLimboConfig.java @@ -0,0 +1,146 @@ +package me.mastercapexd.auth.hooks.nanolimbo; + +import java.net.SocketAddress; +import java.time.Duration; + +import ua.nanit.limbo.configuration.LimboConfig; +import ua.nanit.limbo.server.data.BossBar; +import ua.nanit.limbo.server.data.InfoForwarding; +import ua.nanit.limbo.server.data.PingData; +import ua.nanit.limbo.server.data.Title; + +public class NanoLimboConfig implements LimboConfig { + private final PingData pingData; + private final SocketAddress address; + private final InfoForwarding forwarding; + + public NanoLimboConfig(SocketAddress address, InfoForwarding forwarding) { + this.pingData = new PingData(); + + this.pingData.setDescription("NanoLimbo"); + this.pingData.setVersion("NanoLimbo"); + + this.address = address; + this.forwarding = forwarding; + } + + @Override + public SocketAddress getAddress() { + return address; + } + + @Override + public int getMaxPlayers() { + return -1; + } + + @Override + public PingData getPingData() { + return pingData; + } + + @Override + public String getDimensionType() { + return "the_end"; + } + + @Override + public int getGameMode() { + return 2; // Adventure game mode + } + + @Override + public InfoForwarding getInfoForwarding() { + return forwarding; + } + + @Override + public long getReadTimeout() { + return Duration.ofSeconds(30).toMillis(); + } + + @Override + public int getDebugLevel() { + return 0; // Display only errors + } + + @Override + public boolean isUseBrandName() { + return false; + } + + @Override + public boolean isUseJoinMessage() { + return false; + } + + @Override + public boolean isUseBossBar() { + return false; + } + + @Override + public boolean isUseTitle() { + return false; + } + + @Override + public boolean isUsePlayerList() { + return false; + } + + @Override + public boolean isUseHeaderAndFooter() { + return false; + } + + @Override + public String getBrandName() { + return null; + } + + @Override + public String getJoinMessage() { + return null; + } + + @Override + public BossBar getBossBar() { + return null; + } + + @Override + public Title getTitle() { + return null; + } + + @Override + public String getPlayerListUsername() { + return ""; + } + + @Override + public String getPlayerListHeader() { + return null; + } + + @Override + public String getPlayerListFooter() { + return null; + } + + @Override + public boolean isUseEpoll() { + return false; + } + + @Override + public int getBossGroupSize() { + return 1; // Default value + } + + @Override + public int getWorkerGroupSize() { + return 4; // Default value + } +} \ No newline at end of file diff --git a/core/src/main/java/me/mastercapexd/auth/hooks/nanolimbo/NanoLimboProvider.java b/core/src/main/java/me/mastercapexd/auth/hooks/nanolimbo/NanoLimboProvider.java new file mode 100644 index 00000000..06448631 --- /dev/null +++ b/core/src/main/java/me/mastercapexd/auth/hooks/nanolimbo/NanoLimboProvider.java @@ -0,0 +1,59 @@ +package me.mastercapexd.auth.hooks.nanolimbo; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.SocketAddress; +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.stream.IntStream; + +import ua.nanit.limbo.server.Command; +import ua.nanit.limbo.server.CommandHandler; +import ua.nanit.limbo.server.LimboServer; +import ua.nanit.limbo.server.data.InfoForwarding; + +public interface NanoLimboProvider { + + CommandHandler DUMMY_COMMAND_HANDLER = new CommandHandler() { + @Override + public Collection getCommands() { + return Collections.emptyList(); + } + + @Override + public void register(Command command) { + } + + @Override + public boolean executeCommand(String s) { + return false; + } + }; + InfoForwardingFactory FORWARDING_FACTORY = new InfoForwardingFactory(); + + InfoForwarding createForwarding(); + + ClassLoader classLoader(); + + default void createAndStartLimbo(SocketAddress address) { + LimboServer limboServer = new LimboServer(new NanoLimboConfig(address, createForwarding()), DUMMY_COMMAND_HANDLER, classLoader()); + try { + limboServer.start(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + default Optional findAvailableAddress(int[] ports) { + return IntStream.of(ports).filter(port -> { + try (ServerSocket ignored = new ServerSocket(port)) { + return true; + } catch (IOException ignored) { + return false; + } + }).mapToObj(InetSocketAddress::new).findFirst(); + } + +} diff --git a/core/src/main/resources/configurations/config.yml b/core/src/main/resources/configurations/config.yml index bfbdd15d..be29eef9 100644 --- a/core/src/main/resources/configurations/config.yml +++ b/core/src/main/resources/configurations/config.yml @@ -199,6 +199,10 @@ auth-time: 60 # Должен ли обычный чат быть заблокирован у игроков block-chat: true +# Определяет порт на котором работает лимбо. Если у вас не установлен NanoLimboPlugin, эта опция не будет иметь какого либо эффекта. +# Рекомендуется использовать значение 49152-65535. Подробнее: https://en.wikipedia.org/wiki/Ephemeral_port +limbo-port: 49152-65535 + # Доступные команды в ВК,Telegram! # /принять,/accept -> Подтверждение входа через ВК # /отклонить,/decline -> Отклонение входа через ВК diff --git a/velocity/pom.xml b/velocity/pom.xml index 8ca4316b..70c797a9 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -12,11 +12,12 @@ 3.1.1 + 3.0.1 0.4.2 6.1.0 3.2.5 - 1.1.7 2.0.0 + 1.0.6 11 @@ -33,8 +34,8 @@ - jnngl-public - https://maven.jnngl.me/public + exceptionflug + https://mvn.exceptionflug.de/repository/exceptionflug-public/ @@ -83,11 +84,19 @@ provided - + - net.elytrium.limboapi + com.velocitypowered + velocity-proxy + ${velocity-proxy.version} + provided + + + + + com.github.bivashy.NanoLimboPlugin api - ${limbo.api.version} + ${nanolimbo.version} provided diff --git a/velocity/src/main/java/me/mastercapexd/auth/velocity/VelocityAuthPluginBootstrap.java b/velocity/src/main/java/me/mastercapexd/auth/velocity/VelocityAuthPluginBootstrap.java index 346e2bbf..f4d8eafa 100644 --- a/velocity/src/main/java/me/mastercapexd/auth/velocity/VelocityAuthPluginBootstrap.java +++ b/velocity/src/main/java/me/mastercapexd/auth/velocity/VelocityAuthPluginBootstrap.java @@ -2,11 +2,14 @@ import java.io.File; import java.nio.file.Path; +import java.util.Collection; +import java.util.Collections; import org.slf4j.Logger; import com.alessiodp.libby.VelocityLibraryManager; import com.bivashy.auth.api.AuthPlugin; +import com.bivashy.auth.api.hook.LimboPluginHook; import com.bivashy.auth.api.server.ServerCore; import com.bivashy.messenger.vk.message.VkMessage; import com.bivashy.messenger.vk.provider.VkApiProvider; @@ -21,12 +24,11 @@ import me.mastercapexd.auth.BaseAuthPlugin; import me.mastercapexd.auth.hooks.VkPluginHook; -import me.mastercapexd.auth.hooks.limbo.LimboHook; import me.mastercapexd.auth.management.BaseLibraryManagement; import me.mastercapexd.auth.velocity.adventure.VelocityAudienceProvider; import me.mastercapexd.auth.velocity.commands.VelocityCommandRegistry; import me.mastercapexd.auth.velocity.hooks.VelocityVkPluginHook; -import me.mastercapexd.auth.velocity.hooks.limbo.LimboAPIHook; +import me.mastercapexd.auth.velocity.hooks.nanolimbo.VelocityNanoLimboPluginHook; import me.mastercapexd.auth.velocity.listener.AuthenticationListener; import me.mastercapexd.auth.velocity.listener.VkDispatchListener; import me.mastercapexd.auth.vk.command.VKCommandRegistry; @@ -86,10 +88,10 @@ private void initializeCommand() { } private void initializeLimbo() { - LimboAPIHook limboAPIHook = new LimboAPIHook(); - if (!limboAPIHook.canHook()) - return; - authPlugin.putHook(LimboHook.class, limboAPIHook); + Collection limboPluginHooks = Collections.singleton(new VelocityNanoLimboPluginHook(authPlugin.getConfig().getLimboPortRange(), proxyServer)); + limboPluginHooks.stream() + .filter(LimboPluginHook::canHook) + .forEach(limboPluginHook -> authPlugin.putHook(LimboPluginHook.class, limboPluginHook)); } public ProxyServer getProxyServer() { diff --git a/velocity/src/main/java/me/mastercapexd/auth/velocity/VelocityProxyCore.java b/velocity/src/main/java/me/mastercapexd/auth/velocity/VelocityProxyCore.java index f405a72d..e1e334c8 100644 --- a/velocity/src/main/java/me/mastercapexd/auth/velocity/VelocityProxyCore.java +++ b/velocity/src/main/java/me/mastercapexd/auth/velocity/VelocityProxyCore.java @@ -8,18 +8,17 @@ import java.util.stream.Collectors; import com.bivashy.auth.api.AuthPlugin; +import com.bivashy.auth.api.hook.LimboPluginHook; import com.bivashy.auth.api.server.ServerCore; import com.bivashy.auth.api.server.bossbar.ServerBossbar; import com.bivashy.auth.api.server.message.ServerComponent; import com.bivashy.auth.api.server.player.ServerPlayer; -import com.bivashy.auth.api.server.proxy.limbo.LimboServerWrapper; import com.bivashy.auth.api.server.scheduler.ServerScheduler; import com.bivashy.auth.api.server.title.ServerTitle; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.server.RegisteredServer; -import me.mastercapexd.auth.hooks.limbo.LimboHook; import me.mastercapexd.auth.velocity.api.bossbar.VelocityServerBossbar; import me.mastercapexd.auth.velocity.api.title.VelocityServerTitle; import me.mastercapexd.auth.velocity.component.VelocityComponent; @@ -31,6 +30,7 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; public class VelocityProxyCore implements ServerCore { + private final ProxyServer server; public VelocityProxyCore(ProxyServer server) { @@ -101,15 +101,9 @@ public ServerComponent componentLegacy(String legacy) { @Override public Optional serverFromName(String serverName) { Optional serverOptional = server.getServer(serverName); - LimboHook limboHook = AuthPlugin.instance().getHook(LimboHook.class); - if (!serverOptional.isPresent() && limboHook != null) { - if (!limboHook.isLimbo(serverName)) - return Optional.empty(); - LimboServerWrapper server = limboHook.createLimboWrapper(serverName); - if (!server.isExists()) - return Optional.empty(); - return Optional.of(server); - } + LimboPluginHook limboHook = AuthPlugin.instance().getHook(LimboPluginHook.class); + if (!serverOptional.isPresent() && limboHook != null) + return Optional.of(limboHook.createServer(serverName)); return serverOptional.map(VelocityProxyServer::new); } @@ -139,4 +133,5 @@ public void runAsync(Runnable task) { public String colorize(String text) { return text; } + } diff --git a/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/LimboAPIHook.java b/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/LimboAPIHook.java deleted file mode 100644 index 63ee8f81..00000000 --- a/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/LimboAPIHook.java +++ /dev/null @@ -1,42 +0,0 @@ -package me.mastercapexd.auth.velocity.hooks.limbo; - -import com.bivashy.auth.api.server.proxy.limbo.LimboServerWrapper; - -import me.mastercapexd.auth.hooks.limbo.LimboHook; -import me.mastercapexd.auth.velocity.VelocityAuthPluginBootstrap; - -public class LimboAPIHook implements LimboHook { - private static final VelocityAuthPluginBootstrap PLUGIN = VelocityAuthPluginBootstrap.getInstance(); - private LimboAPIProvider provider; - - public LimboAPIHook() { - if (!canHook()) - return; - this.provider = new LimboAPIProvider(); - PLUGIN.getProxyServer().getEventManager().register(PLUGIN, provider); - } - - @Override - public boolean isLimbo(String serverName) { - if (provider == null) - return false; - return provider.isLimbo(serverName); - } - - @Override - public LimboServerWrapper createLimboWrapper(String serverName) { - if (provider == null) - return null; - return provider.createLimboWrapper(serverName); - } - - @Override - public boolean canHook() { - try { - net.elytrium.limboapi.api.LimboFactory.class.getName(); - return true; - } catch(NoClassDefFoundError e) { - return false; - } - } -} diff --git a/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/LimboAPIProvider.java b/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/LimboAPIProvider.java deleted file mode 100644 index 0cdfc994..00000000 --- a/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/LimboAPIProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -package me.mastercapexd.auth.velocity.hooks.limbo; - -import java.util.List; -import java.util.stream.Collectors; - -import com.bivashy.auth.api.server.proxy.limbo.LimboServerWrapper; -import com.velocitypowered.api.event.Subscribe; -import com.velocitypowered.api.plugin.PluginContainer; - -import me.mastercapexd.auth.velocity.VelocityAuthPluginBootstrap; -import me.mastercapexd.auth.velocity.hooks.limbo.config.LimboAPIConfig; -import net.elytrium.limboapi.api.LimboFactory; -import net.elytrium.limboapi.api.event.LoginLimboRegisterEvent; - -public class LimboAPIProvider { - public static final String LIMBO_API_NAME = "limboapi"; - private static final VelocityAuthPluginBootstrap PLUGIN = VelocityAuthPluginBootstrap.getInstance(); - private final LimboFactory limboFactory = (LimboFactory) PLUGIN - .getProxyServer() - .getPluginManager() - .getPlugin(LIMBO_API_NAME) - .flatMap(PluginContainer::getInstance) - .orElseThrow(NullPointerException::new); - private final LimboAPIConfig limboAPIConfig = new LimboAPIConfig(); - private final List wrappers; - - public LimboAPIProvider() { - LimboAPIConfig limboConfig = new LimboAPIConfig(); - wrappers = limboConfig.getLimboConfigs() - .stream() - .map(config -> new LimboAPIServer(config.getName(), config.createLimbo(limboFactory))) - .collect(Collectors.toList()); - } - - public LimboServerWrapper createLimboWrapper(String serverName) { - return wrappers.stream().filter(server -> server.getServerName().equals(serverName)).findFirst().orElseThrow(IllegalArgumentException::new); - } - - public boolean isLimbo(String serverName) { - return wrappers.stream().anyMatch(server -> server.getServerName().equals(serverName)); - } - - @Subscribe - public void onLimboLogin(LoginLimboRegisterEvent e) { - PLUGIN.getAuthPlugin().getCore().wrapPlayer(e.getPlayer()).ifPresent(PLUGIN.getAuthPlugin().getLoginManagement()::onLogin); - } -} diff --git a/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/LimboAPIServer.java b/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/LimboAPIServer.java deleted file mode 100644 index 980cfaba..00000000 --- a/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/LimboAPIServer.java +++ /dev/null @@ -1,61 +0,0 @@ -package me.mastercapexd.auth.velocity.hooks.limbo; - -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; - -import com.bivashy.auth.api.server.player.ServerPlayer; -import com.bivashy.auth.api.server.proxy.limbo.LimboServerWrapper; -import com.velocitypowered.api.proxy.Player; - -import net.elytrium.limboapi.api.Limbo; -import net.elytrium.limboapi.api.LimboSessionHandler; - -public class LimboAPIServer implements LimboServerWrapper { - private final Set onlinePlayers = new HashSet<>(); - private final String name; - private final Limbo limbo; - - public LimboAPIServer(String name, Limbo limbo) { - this.name = name; - this.limbo = limbo; - } - - @Override - public String getServerName() { - return name; - } - - @Override - public void sendPlayer(ServerPlayer... players) { - for (ServerPlayer player : players) { - if (onlinePlayers.contains(player.getUniqueId())) - continue; - onlinePlayers.add(player.getUniqueId()); - Player velocityPlayer = player.getRealPlayer(); - limbo.spawnPlayer(velocityPlayer, new LimboSessionHandler() { - @Override - public void onDisconnect() { - onlinePlayers.remove(player.getUniqueId()); - } - }); - } - } - - @Override - public List getPlayers() { - return Collections.emptyList(); - } - - @Override - public int getPlayersCount() { - return 0; - } - - @Override - public boolean isExists() { - return limbo != null; - } -} diff --git a/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/config/LimboAPIConfig.java b/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/config/LimboAPIConfig.java deleted file mode 100644 index eb2d9fa0..00000000 --- a/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/config/LimboAPIConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -package me.mastercapexd.auth.velocity.hooks.limbo.config; - -import java.io.File; -import java.io.IOException; -import java.util.Collections; -import java.util.List; - -import org.spongepowered.configurate.ConfigurationNode; -import org.spongepowered.configurate.yaml.YamlConfigurationLoader; - -import com.bivashy.auth.api.asset.resource.ResourceReader; -import com.bivashy.configuration.ConfigurationProcessor; -import com.bivashy.configuration.annotation.ConfigField; -import com.bivashy.configuration.configurate.SpongeConfigurateProcessor; - -import me.mastercapexd.auth.velocity.VelocityAuthPluginBootstrap; - -public class LimboAPIConfig { - public static final ConfigurationProcessor CONFIGURATION_PROCESSOR = new SpongeConfigurateProcessor(); - public static final String CONFIGURATION_NAME = "limbo.yml"; - private static final VelocityAuthPluginBootstrap PLUGIN = VelocityAuthPluginBootstrap.getInstance(); - private static final File CONFIGURATION_FILE = new File(PLUGIN.getAuthPlugin().getFolder(), CONFIGURATION_NAME); - private ConfigurationNode node; - @ConfigField("values") - private List limboConfigs; - - public LimboAPIConfig() { - try { - ResourceReader.defaultReader(VelocityAuthPluginBootstrap.getInstance().getClass().getClassLoader(), CONFIGURATION_NAME) - .read() - .write(CONFIGURATION_FILE); - node = YamlConfigurationLoader.builder().file(CONFIGURATION_FILE).build().load(); - CONFIGURATION_PROCESSOR.resolve(node, this); - } catch(IOException e) { - e.printStackTrace(); - } - } - - public List getLimboConfigs() { - return Collections.unmodifiableList(limboConfigs); - } - - public ConfigurationNode getNode() { - return node; - } -} diff --git a/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/config/LimboConfig.java b/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/config/LimboConfig.java deleted file mode 100644 index 65843fdf..00000000 --- a/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/limbo/config/LimboConfig.java +++ /dev/null @@ -1,63 +0,0 @@ -package me.mastercapexd.auth.velocity.hooks.limbo.config; - -import com.bivashy.configuration.ConfigurationHolder; -import com.bivashy.configuration.annotation.ConfigField; -import com.bivashy.configuration.holder.ConfigurationSectionHolder; - -import net.elytrium.limboapi.api.Limbo; -import net.elytrium.limboapi.api.LimboFactory; -import net.elytrium.limboapi.api.chunk.Dimension; - -public class LimboConfig implements ConfigurationHolder { - @ConfigField - private Dimension dimension = Dimension.OVERWORLD; - @ConfigField - private long time; - @ConfigField - private double x, y, z; - @ConfigField - private float yaw, pitch; - - private final String name; - - public LimboConfig(ConfigurationSectionHolder sectionHolder) { - LimboAPIConfig.CONFIGURATION_PROCESSOR.resolve(sectionHolder, this); - this.name = sectionHolder.key(); - } - - public Limbo createLimbo(LimboFactory factory) { - return factory.createLimbo(factory.createVirtualWorld(dimension, x, y, z, yaw, pitch)).setWorldTime(time).setName(name); - } - - public Dimension getDimension() { - return dimension; - } - - public long getTime() { - return time; - } - - public double getX() { - return x; - } - - public double getY() { - return y; - } - - public double getZ() { - return z; - } - - public float getYaw() { - return yaw; - } - - public float getPitch() { - return pitch; - } - - public String getName() { - return name; - } -} diff --git a/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/nanolimbo/VelocityNanoLimboPluginHook.java b/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/nanolimbo/VelocityNanoLimboPluginHook.java new file mode 100644 index 00000000..0086a689 --- /dev/null +++ b/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/nanolimbo/VelocityNanoLimboPluginHook.java @@ -0,0 +1,52 @@ +package me.mastercapexd.auth.velocity.hooks.nanolimbo; + +import java.net.InetSocketAddress; +import java.util.stream.IntStream; + +import com.bivashy.auth.api.AuthPlugin; +import com.bivashy.auth.api.config.PluginConfig; +import com.bivashy.auth.api.hook.LimboPluginHook; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent; +import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.server.ServerInfo; + +import me.mastercapexd.auth.hooks.nanolimbo.NanoLimboProvider; +import me.mastercapexd.auth.velocity.VelocityAuthPluginBootstrap; +import me.mastercapexd.auth.velocity.server.VelocityProxyServer; + +public class VelocityNanoLimboPluginHook implements LimboPluginHook { + + private final int[] limboPorts; + private final ProxyServer proxyServer; + private NanoLimboProvider provider; + + public VelocityNanoLimboPluginHook(IntStream limboPorts, ProxyServer proxyServer) { + this.limboPorts = limboPorts.toArray(); + this.proxyServer = proxyServer; + if (!canHook()) + return; + provider = new VelocityNanoLimboProvider(proxyServer); + proxyServer.getEventManager().register(VelocityAuthPluginBootstrap.getInstance(), this); + } + + @Override + public com.bivashy.auth.api.server.proxy.ProxyServer createServer(String serverName) { + InetSocketAddress address = provider.findAvailableAddress(limboPorts).orElseThrow( + () -> new IllegalStateException("Cannot find available port for limbo server!")); + provider.createAndStartLimbo(address); + return new VelocityProxyServer(proxyServer.registerServer(new ServerInfo(serverName, address))); + } + + @Subscribe + public void onServerChoose(PlayerChooseInitialServerEvent event) { + PluginConfig config = AuthPlugin.instance().getConfig(); + event.setInitialServer(config.findServerInfo(config.getAuthServers()).asProxyServer().as(VelocityProxyServer.class).getServer()); + } + + @Override + public boolean canHook() { + return proxyServer.getPluginManager().isLoaded("nanolimbovelocity"); + } + +} diff --git a/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/nanolimbo/VelocityNanoLimboProvider.java b/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/nanolimbo/VelocityNanoLimboProvider.java new file mode 100644 index 00000000..1f7f7f30 --- /dev/null +++ b/velocity/src/main/java/me/mastercapexd/auth/velocity/hooks/nanolimbo/VelocityNanoLimboProvider.java @@ -0,0 +1,50 @@ +package me.mastercapexd.auth.velocity.hooks.nanolimbo; + +import java.net.SocketAddress; +import java.nio.charset.StandardCharsets; +import java.util.Collections; + +import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.proxy.config.PlayerInfoForwarding; +import com.velocitypowered.proxy.config.VelocityConfiguration; + +import me.mastercapexd.auth.hooks.nanolimbo.NanoLimboProvider; +import ua.nanit.limbo.NanoLimbo; +import ua.nanit.limbo.server.data.InfoForwarding; + +public class VelocityNanoLimboProvider implements NanoLimboProvider { + + private final ClassLoader classLoader; + private final ProxyServer proxyServer; + + public VelocityNanoLimboProvider(ProxyServer proxyServer) { + this.classLoader = NanoLimbo.class.getClassLoader(); + this.proxyServer = proxyServer; + } + + @Override + public void createAndStartLimbo(SocketAddress address) { + NanoLimboProvider.super.createAndStartLimbo(address); + } + + @Override + public InfoForwarding createForwarding() { + VelocityConfiguration velocityConfiguration = (VelocityConfiguration) proxyServer.getConfiguration(); + PlayerInfoForwarding forwardingMode = velocityConfiguration.getPlayerInfoForwardingMode(); + if (forwardingMode == PlayerInfoForwarding.NONE) + return FORWARDING_FACTORY.none(); + if (forwardingMode == PlayerInfoForwarding.LEGACY) + return FORWARDING_FACTORY.legacy(); + if (forwardingMode == PlayerInfoForwarding.MODERN) + return FORWARDING_FACTORY.modern(velocityConfiguration.getForwardingSecret()); + if (forwardingMode == PlayerInfoForwarding.BUNGEEGUARD) + return FORWARDING_FACTORY.bungeeGuard(Collections.singleton(new String(velocityConfiguration.getForwardingSecret(), StandardCharsets.UTF_8))); + return FORWARDING_FACTORY.none(); + } + + @Override + public ClassLoader classLoader() { + return classLoader; + } + +} diff --git a/velocity/src/main/resources/limbo.yml b/velocity/src/main/resources/limbo.yml deleted file mode 100644 index 8bb5ef90..00000000 --- a/velocity/src/main/resources/limbo.yml +++ /dev/null @@ -1,10 +0,0 @@ -values: - auth: # Название лимбо которое нужно указывать в config.yml - # OVERWORLD, THE_END, NETHER - dimension: OVERWORLD - x: 0 - y: 0 - z: 0 - yaw: 90 - pitch: 0 - time: 9000 \ No newline at end of file diff --git a/velocity/src/main/resources/velocity-plugin.json b/velocity/src/main/resources/velocity-plugin.json index 3f0966b4..7ce56fe0 100644 --- a/velocity/src/main/resources/velocity-plugin.json +++ b/velocity/src/main/resources/velocity-plugin.json @@ -15,7 +15,7 @@ "optional": true }, { - "id": "limboapi", + "id": "nanolimbovelocity", "optional": true } ], From 6e025ec7dba86eb329dc0c03259fc5dc8a60b99f Mon Sep 17 00:00:00 2001 From: bivashy <85439143+bivashy@users.noreply.github.com> Date: Tue, 10 Oct 2023 23:45:35 +0600 Subject: [PATCH 09/18] Use original Lamp library over the fork (#78) * Change lamp version into 3.1.7 * Change Lamp groupId from **.bivashy.** into **.Revxrsal.** --- bungee/pom.xml | 4 ++-- core/pom.xml | 6 +++--- velocity/pom.xml | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bungee/pom.xml b/bungee/pom.xml index 1f3b940d..45cc46bb 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -12,7 +12,7 @@ 1.19-R0.1-SNAPSHOT - 3.2.5 + 3.1.7 4.3.0 6.5.0 0.4.2 @@ -60,7 +60,7 @@ - com.github.bivashy.Lamp + com.github.Revxrsal.Lamp bungee ${lamp.command-library.version} diff --git a/core/pom.xml b/core/pom.xml index 30a8d87e..085294f0 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -16,7 +16,7 @@ 3.5.1 4.0.2 4.1.2 - 3.2.5 + 3.1.7 1.0.0 1.0.0 6.5.0 @@ -87,7 +87,7 @@ - com.github.bivashy.Lamp + com.github.Revxrsal.Lamp common ${lamp.command-library.version} @@ -114,7 +114,7 @@ - com.github.bivashy.Lamp + com.github.Revxrsal.Lamp jda ${lamp.command-library.version} diff --git a/velocity/pom.xml b/velocity/pom.xml index 70c797a9..8cc65888 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -15,7 +15,7 @@ 3.0.1 0.4.2 6.1.0 - 3.2.5 + 3.1.7 2.0.0 1.0.6 @@ -55,7 +55,7 @@ - com.github.bivashy.Lamp + com.github.Revxrsal.Lamp velocity ${lamp.command-library.version} From e1f306a3a811102ff491fe89f64f8b7f8e30b897 Mon Sep 17 00:00:00 2001 From: bivashy Date: Tue, 10 Oct 2023 23:52:55 +0600 Subject: [PATCH 10/18] Add %player_name% placeholder into 'player-offline' message --- .../auth/bungee/commands/BungeeCommandsRegistry.java | 3 ++- .../auth/bungee/commands/exception/BungeeExceptionHandler.java | 2 +- core/src/main/resources/configurations/config.yml | 2 +- .../auth/velocity/commands/VelocityCommandRegistry.java | 3 ++- .../velocity/commands/exception/VelocityExceptionHandler.java | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bungee/src/main/java/me/mastercapexd/auth/bungee/commands/BungeeCommandsRegistry.java b/bungee/src/main/java/me/mastercapexd/auth/bungee/commands/BungeeCommandsRegistry.java index 404ef5ea..53b1a6a6 100644 --- a/bungee/src/main/java/me/mastercapexd/auth/bungee/commands/BungeeCommandsRegistry.java +++ b/bungee/src/main/java/me/mastercapexd/auth/bungee/commands/BungeeCommandsRegistry.java @@ -5,6 +5,7 @@ import com.bivashy.auth.api.AuthPlugin; import com.bivashy.auth.api.account.Account; import com.bivashy.auth.api.config.PluginConfig; +import com.bivashy.auth.api.config.message.MessageContext; import com.bivashy.auth.api.model.PlayerIdSupplier; import com.bivashy.auth.api.server.command.ServerCommandActor; import com.bivashy.auth.api.server.player.ServerPlayer; @@ -42,7 +43,7 @@ public BungeeCommandsRegistry(BungeeAuthPluginBootstrap pluginBootstrap, AuthPlu String value = context.pop(); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(value); if (player == null) { - throw new SendComponentException(config.getServerMessages().getMessage("player-offline")); + throw new SendComponentException(config.getServerMessages().getMessage("player-offline", MessageContext.of("%player_name%", value))); } return new ArgumentServerPlayer(new BungeeServerPlayer(player)); }); diff --git a/bungee/src/main/java/me/mastercapexd/auth/bungee/commands/exception/BungeeExceptionHandler.java b/bungee/src/main/java/me/mastercapexd/auth/bungee/commands/exception/BungeeExceptionHandler.java index ef1b8b96..f4345122 100644 --- a/bungee/src/main/java/me/mastercapexd/auth/bungee/commands/exception/BungeeExceptionHandler.java +++ b/bungee/src/main/java/me/mastercapexd/auth/bungee/commands/exception/BungeeExceptionHandler.java @@ -46,7 +46,7 @@ public void senderNotConsole(CommandActor actor, SenderNotConsoleException excep @Override public void invalidPlayer(CommandActor actor, InvalidPlayerException exception) { - sendComponent(actor, messages.getMessage("player-offline", MessageContext.of("%player%", exception.getInput()))); + sendComponent(actor, messages.getMessage("player-offline", MessageContext.of("%player_name%", exception.getInput()))); } @Override diff --git a/core/src/main/resources/configurations/config.yml b/core/src/main/resources/configurations/config.yml index be29eef9..7241f21d 100644 --- a/core/src/main/resources/configurations/config.yml +++ b/core/src/main/resources/configurations/config.yml @@ -366,7 +366,7 @@ messages: auth-reloaded: '&aПлагин успешно перезагрузил конфигурацию' config-migrated: '&aКонфигурация успешно мигрирована' # Ошибки в командах - player-offline: '&cИгрок с ником %account_name% оффлайн!' + player-offline: '&cИгрок с ником %player_name% оффлайн!' command-cooldown: '&cВы слишком часто используете данную команду! Попробуйте позже.' # Название аргумента указывается в виде arg1, arg2, arg3... unresolved-argument: '&cВы не указали аргумент: %argument_name%' diff --git a/velocity/src/main/java/me/mastercapexd/auth/velocity/commands/VelocityCommandRegistry.java b/velocity/src/main/java/me/mastercapexd/auth/velocity/commands/VelocityCommandRegistry.java index 03b25ac7..1237a21b 100644 --- a/velocity/src/main/java/me/mastercapexd/auth/velocity/commands/VelocityCommandRegistry.java +++ b/velocity/src/main/java/me/mastercapexd/auth/velocity/commands/VelocityCommandRegistry.java @@ -6,6 +6,7 @@ import com.bivashy.auth.api.AuthPlugin; import com.bivashy.auth.api.account.Account; import com.bivashy.auth.api.config.PluginConfig; +import com.bivashy.auth.api.config.message.MessageContext; import com.bivashy.auth.api.model.PlayerIdSupplier; import com.bivashy.auth.api.server.command.ServerCommandActor; import com.bivashy.auth.api.server.player.ServerPlayer; @@ -42,7 +43,7 @@ public VelocityCommandRegistry(VelocityAuthPluginBootstrap pluginBootstrap, Auth String value = context.pop(); Optional player = authPlugin.getCore().getPlayer(value); if (!player.isPresent()) - throw new SendComponentException(config.getServerMessages().getMessage("player-offline")); + throw new SendComponentException(config.getServerMessages().getMessage("player-offline", MessageContext.of("%player_name%"))); return new ArgumentServerPlayer(player.get()); }); commandHandler.registerCondition((actor, command, arguments) -> { diff --git a/velocity/src/main/java/me/mastercapexd/auth/velocity/commands/exception/VelocityExceptionHandler.java b/velocity/src/main/java/me/mastercapexd/auth/velocity/commands/exception/VelocityExceptionHandler.java index 7efcd7c2..a5ab2904 100644 --- a/velocity/src/main/java/me/mastercapexd/auth/velocity/commands/exception/VelocityExceptionHandler.java +++ b/velocity/src/main/java/me/mastercapexd/auth/velocity/commands/exception/VelocityExceptionHandler.java @@ -45,7 +45,7 @@ public void senderNotConsole(@NotNull CommandActor actor, revxrsal.commands.velo @Override public void invalidPlayer(@NotNull CommandActor actor, revxrsal.commands.velocity.exception.@NotNull InvalidPlayerException exception) { - sendComponent(actor, messages.getMessage("player-offline", MessageContext.of("%player%", exception.getInput()))); + sendComponent(actor, messages.getMessage("player-offline", MessageContext.of("%player_name%", exception.getInput()))); } @Override From 7e225e3c4a573f8f62d5aa572a7532ac7cf66253 Mon Sep 17 00:00:00 2001 From: bivashy <85439143+bivashy@users.noreply.github.com> Date: Fri, 13 Oct 2023 01:33:15 +0600 Subject: [PATCH 11/18] Create dependabot.yml (#83) --- .github/dependabot.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..5b063201 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "maven" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "daily" From 7ce8d7b53145b35da0a6f89e2b1b8f8455603883 Mon Sep 17 00:00:00 2001 From: bivashy Date: Fri, 13 Oct 2023 02:15:29 +0600 Subject: [PATCH 12/18] Apply @CommandCooldown to all database-related commands --- .../mastercapexd/auth/messenger/commands/AccountCommand.java | 2 ++ .../auth/messenger/commands/AccountsListCommand.java | 2 ++ .../auth/messenger/commands/ChangePasswordCommand.java | 2 ++ .../auth/messenger/commands/ConfirmationToggleCommand.java | 4 ++++ .../mastercapexd/auth/messenger/commands/GoogleCommand.java | 2 ++ .../auth/messenger/commands/GoogleUnlinkCommand.java | 2 ++ .../mastercapexd/auth/messenger/commands/RestoreCommand.java | 2 ++ .../auth/server/commands/ChangePasswordCommand.java | 2 +- .../me/mastercapexd/auth/server/commands/GoogleCommand.java | 2 ++ .../auth/server/commands/GoogleUnlinkCommand.java | 2 ++ .../mastercapexd/auth/shared/commands/DiscordLinkCommand.java | 2 ++ .../me/mastercapexd/auth/shared/commands/LinkCodeCommand.java | 2 ++ .../auth/shared/commands/TelegramLinkCommand.java | 2 ++ .../me/mastercapexd/auth/shared/commands/VKLinkCommand.java | 2 ++ .../auth/shared/commands/annotation/CommandCooldown.java | 3 +++ 15 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/me/mastercapexd/auth/messenger/commands/AccountCommand.java b/core/src/main/java/me/mastercapexd/auth/messenger/commands/AccountCommand.java index 5df1eca9..d0d48cc4 100644 --- a/core/src/main/java/me/mastercapexd/auth/messenger/commands/AccountCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/messenger/commands/AccountCommand.java @@ -6,6 +6,7 @@ import me.mastercapexd.auth.link.LinkCommandActorWrapper; import me.mastercapexd.auth.messenger.commands.annotation.CommandKey; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import revxrsal.commands.annotation.DefaultFor; import revxrsal.commands.orphan.OrphanCommand; @@ -14,6 +15,7 @@ public class AccountCommand implements OrphanCommand { public static final String CONFIGURATION_KEY = "account-control"; @DefaultFor("~") + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void accountMenu(LinkCommandActorWrapper actorWrapper, LinkType linkType, Account account) { Keyboard accountKeyboard = linkType.getSettings().getKeyboards().createKeyboard("account", "%account_name%", account.getName()); actorWrapper.send(linkType.newMessageBuilder(linkType.getLinkMessages().getMessage("account-control", linkType.newMessageContext(account))) diff --git a/core/src/main/java/me/mastercapexd/auth/messenger/commands/AccountsListCommand.java b/core/src/main/java/me/mastercapexd/auth/messenger/commands/AccountsListCommand.java index 3134a63d..40defb22 100644 --- a/core/src/main/java/me/mastercapexd/auth/messenger/commands/AccountsListCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/messenger/commands/AccountsListCommand.java @@ -16,6 +16,7 @@ import me.mastercapexd.auth.discord.command.annotation.RenameTo; import me.mastercapexd.auth.link.LinkCommandActorWrapper; import me.mastercapexd.auth.messenger.commands.annotation.CommandKey; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import revxrsal.commands.annotation.Default; import revxrsal.commands.annotation.DefaultFor; import revxrsal.commands.annotation.Dependency; @@ -32,6 +33,7 @@ public class AccountsListCommand implements OrphanCommand { private LinkType linkType; @DefaultFor("~") + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void onAccountsMenu(LinkCommandActorWrapper actorWrapper, LinkType linkType, @Flag("page") @Default("1") Integer page, @RenameTo(value = "size", type = "NUMBER") @Flag("pagesize") @Default("5") Integer accountsPerPage, @Flag("type") @Default("my") AccountListType type) { diff --git a/core/src/main/java/me/mastercapexd/auth/messenger/commands/ChangePasswordCommand.java b/core/src/main/java/me/mastercapexd/auth/messenger/commands/ChangePasswordCommand.java index 8ef278cd..827e97ef 100644 --- a/core/src/main/java/me/mastercapexd/auth/messenger/commands/ChangePasswordCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/messenger/commands/ChangePasswordCommand.java @@ -11,6 +11,7 @@ import me.mastercapexd.auth.messenger.commands.annotation.CommandKey; import me.mastercapexd.auth.messenger.commands.annotation.ConfigurationArgumentError; import me.mastercapexd.auth.server.commands.parameters.NewPassword; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import revxrsal.commands.annotation.DefaultFor; import revxrsal.commands.annotation.Dependency; import revxrsal.commands.orphan.OrphanCommand; @@ -25,6 +26,7 @@ public class ChangePasswordCommand implements OrphanCommand { @ConfigurationArgumentError("changepass-not-enough-arguments") @DefaultFor("~") + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void onPasswordChange(LinkCommandActorWrapper actorWrapper, LinkType linkType, Account account, NewPassword newPassword) { plugin.getEventBus().publish(AccountTryChangePasswordEvent.class, account, false, true).thenAccept(tryChangePasswordEventPostResult -> { if (tryChangePasswordEventPostResult.getEvent().isCancelled()) diff --git a/core/src/main/java/me/mastercapexd/auth/messenger/commands/ConfirmationToggleCommand.java b/core/src/main/java/me/mastercapexd/auth/messenger/commands/ConfirmationToggleCommand.java index 5ab09ef3..03f63578 100644 --- a/core/src/main/java/me/mastercapexd/auth/messenger/commands/ConfirmationToggleCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/messenger/commands/ConfirmationToggleCommand.java @@ -11,12 +11,14 @@ import me.mastercapexd.auth.link.LinkCommandActorWrapper; import me.mastercapexd.auth.messenger.commands.annotation.CommandKey; import me.mastercapexd.auth.messenger.commands.annotation.ConfigurationArgumentError; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import revxrsal.commands.annotation.DefaultFor; import revxrsal.commands.annotation.Dependency; import revxrsal.commands.orphan.OrphanCommand; @CommandKey(ConfirmationToggleCommand.CONFIGURATION_KEY) public class ConfirmationToggleCommand implements OrphanCommand { + public static final String CONFIGURATION_KEY = "confirmation-toggle"; @Dependency private AccountDatabase accountDatabase; @@ -25,6 +27,7 @@ public class ConfirmationToggleCommand implements OrphanCommand { @ConfigurationArgumentError("confirmation-no-player") @DefaultFor("~") + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void onConfirmationToggle(LinkCommandActorWrapper actorWrapper, LinkType linkType, Account account) { if (!linkType.getSettings().getConfirmationSettings().canToggleConfirmation()) { actorWrapper.reply(linkType.getLinkMessages().getMessage("confirmation-toggle-disabled", linkType.newMessageContext(account))); @@ -40,4 +43,5 @@ public void onConfirmationToggle(LinkCommandActorWrapper actorWrapper, LinkType accountDatabase.saveOrUpdateAccount(account); }); } + } diff --git a/core/src/main/java/me/mastercapexd/auth/messenger/commands/GoogleCommand.java b/core/src/main/java/me/mastercapexd/auth/messenger/commands/GoogleCommand.java index 2f72dc71..9439ea94 100644 --- a/core/src/main/java/me/mastercapexd/auth/messenger/commands/GoogleCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/messenger/commands/GoogleCommand.java @@ -24,6 +24,7 @@ import me.mastercapexd.auth.messenger.commands.annotation.CommandKey; import me.mastercapexd.auth.messenger.commands.annotation.ConfigurationArgumentError; import me.mastercapexd.auth.server.commands.annotations.GoogleUse; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import me.mastercapexd.auth.util.GoogleAuthenticatorQRGenerator; import me.mastercapexd.auth.util.RandomCodeFactory; import revxrsal.commands.annotation.DefaultFor; @@ -43,6 +44,7 @@ public class GoogleCommand implements OrphanCommand { @GoogleUse @ConfigurationArgumentError("google-not-enough-arguments") @DefaultFor("~") + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void linkGoogle(LinkCommandActorWrapper actorWrapper, LinkType linkType, Account account) { String rawKey = plugin.getGoogleAuthenticator().createCredentials().getKey(); String nickname = account.getName(); diff --git a/core/src/main/java/me/mastercapexd/auth/messenger/commands/GoogleUnlinkCommand.java b/core/src/main/java/me/mastercapexd/auth/messenger/commands/GoogleUnlinkCommand.java index bef3fdb8..65c8ba83 100644 --- a/core/src/main/java/me/mastercapexd/auth/messenger/commands/GoogleUnlinkCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/messenger/commands/GoogleUnlinkCommand.java @@ -13,6 +13,7 @@ import me.mastercapexd.auth.messenger.commands.annotation.CommandKey; import me.mastercapexd.auth.messenger.commands.annotation.ConfigurationArgumentError; import me.mastercapexd.auth.server.commands.annotations.GoogleUse; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import revxrsal.commands.annotation.DefaultFor; import revxrsal.commands.annotation.Dependency; import revxrsal.commands.orphan.OrphanCommand; @@ -30,6 +31,7 @@ public class GoogleUnlinkCommand implements OrphanCommand { @GoogleUse @ConfigurationArgumentError("google-unlink-not-enough-arguments") @DefaultFor("~") + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void unlink(LinkCommandActorWrapper actorWrapper, LinkType linkType, Account account) { LinkUser linkUser = account.findFirstLinkUserOrNew(GoogleLinkType.LINK_USER_FILTER, GoogleLinkType.getInstance()); diff --git a/core/src/main/java/me/mastercapexd/auth/messenger/commands/RestoreCommand.java b/core/src/main/java/me/mastercapexd/auth/messenger/commands/RestoreCommand.java index a758370e..73eca4e1 100644 --- a/core/src/main/java/me/mastercapexd/auth/messenger/commands/RestoreCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/messenger/commands/RestoreCommand.java @@ -9,6 +9,7 @@ import me.mastercapexd.auth.link.LinkCommandActorWrapper; import me.mastercapexd.auth.messenger.commands.annotation.CommandKey; import me.mastercapexd.auth.messenger.commands.annotation.ConfigurationArgumentError; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import revxrsal.commands.annotation.DefaultFor; import revxrsal.commands.annotation.Dependency; import revxrsal.commands.orphan.OrphanCommand; @@ -23,6 +24,7 @@ public class RestoreCommand implements OrphanCommand { @ConfigurationArgumentError("restore-not-enough-arguments") @DefaultFor("~") + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void onRestore(LinkCommandActorWrapper actorWrapper, LinkType linkType, Account account) { String generatedPassword = linkType.getSettings().getRestoreSettings().generateCode(); account.setPasswordHash(account.getCryptoProvider().hash(HashInput.of(generatedPassword))); diff --git a/core/src/main/java/me/mastercapexd/auth/server/commands/ChangePasswordCommand.java b/core/src/main/java/me/mastercapexd/auth/server/commands/ChangePasswordCommand.java index 2c156fdf..70edc373 100644 --- a/core/src/main/java/me/mastercapexd/auth/server/commands/ChangePasswordCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/server/commands/ChangePasswordCommand.java @@ -25,7 +25,7 @@ public class ChangePasswordCommand { private AccountDatabase accountStorage; @DefaultFor({"passchange", "changepass", "changepassword"}) - @CommandCooldown(5000) + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void changePlayerPassword(ServerPlayer sender, DoublePassword password) { String id = config.getActiveIdentifierType().getId(sender); accountStorage.getAccount(id).thenAcceptAsync(account -> { diff --git a/core/src/main/java/me/mastercapexd/auth/server/commands/GoogleCommand.java b/core/src/main/java/me/mastercapexd/auth/server/commands/GoogleCommand.java index db5918e3..28a7fc92 100644 --- a/core/src/main/java/me/mastercapexd/auth/server/commands/GoogleCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/server/commands/GoogleCommand.java @@ -15,6 +15,7 @@ import me.mastercapexd.auth.link.google.GoogleLinkType; import me.mastercapexd.auth.server.commands.annotations.GoogleUse; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import revxrsal.commands.annotation.Command; import revxrsal.commands.annotation.DefaultFor; import revxrsal.commands.annotation.Dependency; @@ -31,6 +32,7 @@ public class GoogleCommand { @GoogleUse @DefaultFor("google") + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void linkGoogle(ServerPlayer player) { String id = config.getActiveIdentifierType().getId(player); accountStorage.getAccount(id).thenAccept(account -> { diff --git a/core/src/main/java/me/mastercapexd/auth/server/commands/GoogleUnlinkCommand.java b/core/src/main/java/me/mastercapexd/auth/server/commands/GoogleUnlinkCommand.java index 12baecbc..cdcafa59 100644 --- a/core/src/main/java/me/mastercapexd/auth/server/commands/GoogleUnlinkCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/server/commands/GoogleUnlinkCommand.java @@ -13,6 +13,7 @@ import io.github.revxrsal.eventbus.EventBus; import me.mastercapexd.auth.link.google.GoogleLinkType; import me.mastercapexd.auth.server.commands.annotations.GoogleUse; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import revxrsal.commands.annotation.Command; import revxrsal.commands.annotation.DefaultFor; import revxrsal.commands.annotation.Dependency; @@ -29,6 +30,7 @@ public class GoogleUnlinkCommand { @GoogleUse @DefaultFor({"googleunlink", "google unlink", "gunlink"}) + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void unlink(MessageableCommandActor actor, ServerPlayer player) { String id = config.getActiveIdentifierType().getId(player); accountStorage.getAccount(id).thenAccept(account -> { diff --git a/core/src/main/java/me/mastercapexd/auth/shared/commands/DiscordLinkCommand.java b/core/src/main/java/me/mastercapexd/auth/shared/commands/DiscordLinkCommand.java index 1d1dae16..575d947c 100644 --- a/core/src/main/java/me/mastercapexd/auth/shared/commands/DiscordLinkCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/shared/commands/DiscordLinkCommand.java @@ -13,6 +13,7 @@ import me.mastercapexd.auth.link.user.confirmation.BaseLinkConfirmationUser; import me.mastercapexd.auth.messenger.commands.annotation.CommandKey; import me.mastercapexd.auth.server.commands.annotations.DiscordUse; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import revxrsal.commands.annotation.DefaultFor; import revxrsal.commands.annotation.Dependency; import revxrsal.commands.annotation.Optional; @@ -33,6 +34,7 @@ public DiscordLinkCommand(Messages messages) { @DiscordUse @DefaultFor("~") + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void discordLink(MessageableCommandActor commandActor, PlayerIdSupplier idSupplier, @Optional LinkUserIdentificator linkUserIdentificator) { String accountId = idSupplier.getPlayerId(); diff --git a/core/src/main/java/me/mastercapexd/auth/shared/commands/LinkCodeCommand.java b/core/src/main/java/me/mastercapexd/auth/shared/commands/LinkCodeCommand.java index 23fd733e..89085140 100644 --- a/core/src/main/java/me/mastercapexd/auth/shared/commands/LinkCodeCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/shared/commands/LinkCodeCommand.java @@ -17,6 +17,7 @@ import me.mastercapexd.auth.link.LinkCommandActorWrapper; import me.mastercapexd.auth.messenger.commands.annotation.CommandKey; import me.mastercapexd.auth.messenger.commands.annotation.ConfigurationArgumentError; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import me.mastercapexd.auth.shared.commands.parameter.MessengerLinkContext; import revxrsal.commands.annotation.DefaultFor; import revxrsal.commands.annotation.Dependency; @@ -37,6 +38,7 @@ public class LinkCodeCommand implements OrphanCommand { @ConfigurationArgumentError("confirmation-not-enough-arguments") @DefaultFor("~") + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void onLink(MessageableCommandActor actor, MessengerLinkContext linkContext, @Optional LinkUserIdentificator possibleIdentificator) { LinkConfirmationType linkConfirmationType = getLinkConfirmationType(actor); Messages messages = linkConfirmationType.getConfirmationMessages(linkContext.getConfirmationUser()); diff --git a/core/src/main/java/me/mastercapexd/auth/shared/commands/TelegramLinkCommand.java b/core/src/main/java/me/mastercapexd/auth/shared/commands/TelegramLinkCommand.java index 4bb5e422..14f0af0b 100644 --- a/core/src/main/java/me/mastercapexd/auth/shared/commands/TelegramLinkCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/shared/commands/TelegramLinkCommand.java @@ -13,6 +13,7 @@ import me.mastercapexd.auth.link.user.confirmation.BaseLinkConfirmationUser; import me.mastercapexd.auth.messenger.commands.annotation.CommandKey; import me.mastercapexd.auth.server.commands.annotations.TelegramUse; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import revxrsal.commands.annotation.DefaultFor; import revxrsal.commands.annotation.Dependency; import revxrsal.commands.annotation.Optional; @@ -34,6 +35,7 @@ public TelegramLinkCommand(Messages messages) { @TelegramUse @DefaultFor("~") + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void telegramLink(MessageableCommandActor commandActor, PlayerIdSupplier idSupplier, @Optional LinkUserIdentificator linkUserIdentificator) { String accountId = idSupplier.getPlayerId(); diff --git a/core/src/main/java/me/mastercapexd/auth/shared/commands/VKLinkCommand.java b/core/src/main/java/me/mastercapexd/auth/shared/commands/VKLinkCommand.java index 325fd608..809e13b2 100644 --- a/core/src/main/java/me/mastercapexd/auth/shared/commands/VKLinkCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/shared/commands/VKLinkCommand.java @@ -17,6 +17,7 @@ import me.mastercapexd.auth.link.vk.VKLinkType; import me.mastercapexd.auth.messenger.commands.annotation.CommandKey; import me.mastercapexd.auth.server.commands.annotations.VkUse; +import me.mastercapexd.auth.shared.commands.annotation.CommandCooldown; import revxrsal.commands.annotation.DefaultFor; import revxrsal.commands.annotation.Dependency; import revxrsal.commands.annotation.Optional; @@ -38,6 +39,7 @@ public VKLinkCommand(Messages messages) { @VkUse @DefaultFor("~") + @CommandCooldown(CommandCooldown.DEFAULT_VALUE) public void vkLink(MessageableCommandActor commandActor, PlayerIdSupplier idSupplier, @Optional LinkUserIdentificator linkUserIdentificator) { String accountId = idSupplier.getPlayerId(); diff --git a/core/src/main/java/me/mastercapexd/auth/shared/commands/annotation/CommandCooldown.java b/core/src/main/java/me/mastercapexd/auth/shared/commands/annotation/CommandCooldown.java index 88c9a140..53468af9 100644 --- a/core/src/main/java/me/mastercapexd/auth/shared/commands/annotation/CommandCooldown.java +++ b/core/src/main/java/me/mastercapexd/auth/shared/commands/annotation/CommandCooldown.java @@ -10,6 +10,9 @@ @Target(ElementType.METHOD) public @interface CommandCooldown { + int DEFAULT_VALUE = 3000; + + long value(); TimeUnit unit() default TimeUnit.MILLISECONDS; From cd73b1beba4e957d4898ee37c2955985c568aa16 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 Oct 2023 02:56:00 +0600 Subject: [PATCH 13/18] Bump org.apache.maven.plugins:maven-shade-plugin from 3.4.1 to 3.5.1 (#90) Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.4.1 to 3.5.1. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.4.1...maven-shade-plugin-3.5.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a03cf08b..3a7a0f80 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ 3.8.1 - 3.4.1 + 3.5.1 3.2.0 From 7c5bd26063bfa509ae179c28240efdf6f605bc4d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 Oct 2023 02:56:09 +0600 Subject: [PATCH 14/18] Bump zxing.library.version from 3.5.1 to 3.5.2 (#89) Bumps `zxing.library.version` from 3.5.1 to 3.5.2. Updates `com.google.zxing:core` from 3.5.1 to 3.5.2 - [Release notes](https://github.com/zxing/zxing/releases) - [Changelog](https://github.com/zxing/zxing/blob/master/CHANGES) - [Commits](https://github.com/zxing/zxing/compare/zxing-3.5.1...zxing-3.5.2) Updates `com.google.zxing:javase` from 3.5.1 to 3.5.2 - [Release notes](https://github.com/zxing/zxing/releases) - [Changelog](https://github.com/zxing/zxing/blob/master/CHANGES) - [Commits](https://github.com/zxing/zxing/compare/zxing-3.5.1...zxing-3.5.2) --- updated-dependencies: - dependency-name: com.google.zxing:core dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: com.google.zxing:javase dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/pom.xml b/core/pom.xml index 085294f0..b82121e7 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -13,7 +13,7 @@ ${project.version} 0.4 - 3.5.1 + 3.5.2 4.0.2 4.1.2 3.1.7 From 1fb751f17fc51ab9873bfe8c95c30e1d421a141a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 Oct 2023 02:56:46 +0600 Subject: [PATCH 15/18] Bump com.github.Revxrsal:EventBus from 1.2 to 1.3 (#88) Bumps [com.github.Revxrsal:EventBus](https://github.com/Revxrsal/EventBus) from 1.2 to 1.3. - [Release notes](https://github.com/Revxrsal/EventBus/releases) - [Commits](https://github.com/Revxrsal/EventBus/compare/1.2...1.3) --- updated-dependencies: - dependency-name: com.github.Revxrsal:EventBus dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index a2be0b51..39d6a4ea 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -18,7 +18,7 @@ 4.3.0 6.1 1.5.0 - 1.2 + 1.3 4.0.2 2.0.0 From 0b42db3b0918c353c173dc673fd5d8af032e2bd6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 Oct 2023 02:56:55 +0600 Subject: [PATCH 16/18] Bump net.dv8tion:JDA from 5.0.0-beta.11 to 5.0.0-beta.15 (#87) Bumps [net.dv8tion:JDA](https://github.com/discord-jda/JDA) from 5.0.0-beta.11 to 5.0.0-beta.15. - [Release notes](https://github.com/discord-jda/JDA/releases) - [Commits](https://github.com/discord-jda/JDA/compare/v5.0.0-beta.11...v5.0.0-beta.15) --- updated-dependencies: - dependency-name: net.dv8tion:JDA dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/pom.xml b/core/pom.xml index b82121e7..96293f84 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -24,7 +24,7 @@ 0.4.2 1.7.0 1.4.2 - 5.0.0-beta.11 + 5.0.0-beta.15 1.0.6 1.9.15 3.9.4 From c440d196cdeb3497f84fb0119ee610bf6a746f71 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 Oct 2023 02:57:12 +0600 Subject: [PATCH 17/18] Bump adventure.serializer.version from 4.13.0 to 4.14.0 (#86) Bumps `adventure.serializer.version` from 4.13.0 to 4.14.0. Updates `net.kyori:adventure-text-serializer-gson` from 4.13.0 to 4.14.0 - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.13.0...v4.14.0) Updates `net.kyori:adventure-text-serializer-legacy` from 4.13.0 to 4.14.0 - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.13.0...v4.14.0) Updates `net.kyori:adventure-text-serializer-plain` from 4.13.0 to 4.14.0 - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.13.0...v4.14.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-text-serializer-gson dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: net.kyori:adventure-text-serializer-legacy dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: net.kyori:adventure-text-serializer-plain dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index 39d6a4ea..1c166331 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -14,7 +14,7 @@ 0.4 1.0.5 - 4.13.0 + 4.14.0 4.3.0 6.1 1.5.0 From 31debf5097fa18b023d55730376216fccbe7a907 Mon Sep 17 00:00:00 2001 From: bivashy <85439143+bivashy@users.noreply.github.com> Date: Sun, 15 Oct 2023 02:58:30 +0600 Subject: [PATCH 18/18] Ignore administrator account in link count check (#79) Simply ignores max-link count check if user defined as user in configuration --- .../auth/shared/commands/LinkCodeCommand.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/me/mastercapexd/auth/shared/commands/LinkCodeCommand.java b/core/src/main/java/me/mastercapexd/auth/shared/commands/LinkCodeCommand.java index 89085140..1ed9258b 100644 --- a/core/src/main/java/me/mastercapexd/auth/shared/commands/LinkCodeCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/shared/commands/LinkCodeCommand.java @@ -26,6 +26,7 @@ @CommandKey(LinkCodeCommand.CONFIGURATION_KEY) public class LinkCodeCommand implements OrphanCommand { + public static final String CONFIGURATION_KEY = "code"; @Dependency private PluginConfig config; @@ -50,7 +51,7 @@ public void onLink(MessageableCommandActor actor, MessengerLinkContext linkConte accountDatabase.getAccount(linkContext.getConfirmationUser().getLinkTarget().getPlayerId()) .thenAccept(account -> accountDatabase.getAccountsFromLinkIdentificator(identificator).thenAccept(accounts -> { - if (linkType.getSettings().getMaxLinkCount() > 0 && accounts.size() >= linkType.getSettings().getMaxLinkCount()) { + if (!validateLinkCount(linkType, identificator, accounts.size())) { actor.replyWithMessage(messages.getMessage("link-limit-reached")); return; } @@ -68,6 +69,13 @@ public void onLink(MessageableCommandActor actor, MessengerLinkContext linkConte })); } + private boolean validateLinkCount(LinkType linkType, LinkUserIdentificator identificator, int linkedAccountAmount) { + int maxLinkCount = linkType.getSettings().getMaxLinkCount(); + if (maxLinkCount > 0) + return true; + return !linkType.getSettings().isAdministrator(identificator) && maxLinkCount >= linkedAccountAmount; + } + private LinkConfirmationType getLinkConfirmationType(MessageableCommandActor actor) { if (actor instanceof ServerCommandActor) return LinkConfirmationType.FROM_GAME; @@ -75,4 +83,5 @@ private LinkConfirmationType getLinkConfirmationType(MessageableCommandActor act return LinkConfirmationType.FROM_LINK; throw new IllegalArgumentException("Cannot resolve confirmation type for actor: " + actor); } + }