From f766e6213e2151fa479de6ccaf1d8b9e0c421724 Mon Sep 17 00:00:00 2001 From: InkerBot <2924657226@qq.com> Date: Tue, 6 Apr 2021 21:58:53 +0800 Subject: [PATCH] Use a loop to hook AuthPlugin --- .../fastlogin/bungee/FastLoginBungee.java | 39 ++++++++++--------- .../fastlogin/bungee/hook/BungeeAuthHook.java | 4 ++ ...=> BungeeCordAuthenticatorBungeeHook.java} | 14 +++---- 3 files changed, 31 insertions(+), 26 deletions(-) rename bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/{BungeeCordAuthenticatorHook.java => BungeeCordAuthenticatorBungeeHook.java} (85%) diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java index 3c1410da..439877da 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java @@ -26,12 +26,13 @@ package com.github.games647.fastlogin.bungee; import com.github.games647.fastlogin.bungee.hook.BungeeAuthHook; -import com.github.games647.fastlogin.bungee.hook.BungeeCordAuthenticatorHook; +import com.github.games647.fastlogin.bungee.hook.BungeeCordAuthenticatorBungeeHook; import com.github.games647.fastlogin.bungee.hook.SodionAuthHook; import com.github.games647.fastlogin.bungee.listener.ConnectListener; import com.github.games647.fastlogin.bungee.listener.PluginMessageListener; import com.github.games647.fastlogin.core.AsyncScheduler; import com.github.games647.fastlogin.core.CommonUtil; +import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.message.ChangePremiumMessage; import com.github.games647.fastlogin.core.message.ChannelMessage; import com.github.games647.fastlogin.core.message.NamespaceKey; @@ -44,6 +45,8 @@ import com.google.common.io.ByteStreams; import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ThreadFactory; @@ -56,6 +59,8 @@ import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.PluginManager; import net.md_5.bungee.api.scheduler.GroupedThreadFactory; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.slf4j.Logger; /** @@ -111,23 +116,21 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin>> hooks = Arrays.asList( + BungeeAuthHook.class, BungeeCordAuthenticatorBungeeHook.class, SodionAuthHook.class); + + for (Class> clazz : hooks) { + String pluginName = clazz.getSimpleName().replace("Hook", ""); + //uses only member classes which uses AuthPlugin interface (skip interfaces) + Plugin plugin = getProxy().getPluginManager().getPlugin(pluginName); + if (plugin != null) { + core.setAuthPluginHook( + clazz.getDeclaredConstructor(FastLoginBungee.class).newInstance(this)); + } + } + } catch (ReflectiveOperationException ex) { + logger.error("Couldn't load the auth hook class", ex); } } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/BungeeAuthHook.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/BungeeAuthHook.java index cb22a6ee..abddb172 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/BungeeAuthHook.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/BungeeAuthHook.java @@ -25,6 +25,7 @@ */ package com.github.games647.fastlogin.bungee.hook; +import com.github.games647.fastlogin.bungee.FastLoginBungee; import com.github.games647.fastlogin.core.hooks.AuthPlugin; import me.vik1395.BungeeAuth.Main; @@ -43,6 +44,9 @@ public class BungeeAuthHook implements AuthPlugin { private final RequestHandler requestHandler = new RequestHandler(); + public BungeeAuthHook(FastLoginBungee plugin) { + } + @Override public boolean forceLogin(ProxiedPlayer player) { String playerName = player.getName(); diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/BungeeCordAuthenticatorHook.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/BungeeCordAuthenticatorBungeeHook.java similarity index 85% rename from bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/BungeeCordAuthenticatorHook.java rename to bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/BungeeCordAuthenticatorBungeeHook.java index 2af0a6e6..beb56d96 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/BungeeCordAuthenticatorHook.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/hook/BungeeCordAuthenticatorBungeeHook.java @@ -27,15 +27,13 @@ package com.github.games647.fastlogin.bungee.hook; import java.sql.SQLException; +import com.github.games647.fastlogin.bungee.FastLoginBungee; import com.github.games647.fastlogin.core.hooks.AuthPlugin; -import org.slf4j.Logger; - import de.xxschrandxx.bca.bungee.BungeeCordAuthenticatorBungee; import de.xxschrandxx.bca.bungee.api.BungeeCordAuthenticatorBungeeAPI; import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Plugin; /** * GitHub: @@ -45,14 +43,14 @@ import net.md_5.bungee.api.plugin.Plugin; * * Spigot: https://www.spigotmc.org/resources/bungeecordauthenticator.87669/ */ -public class BungeeCordAuthenticatorHook implements AuthPlugin { +public class BungeeCordAuthenticatorBungeeHook implements AuthPlugin { public final BungeeCordAuthenticatorBungeeAPI api; - public BungeeCordAuthenticatorHook(Plugin plugin, Logger logger) { - BungeeCordAuthenticatorBungee bcab = (BungeeCordAuthenticatorBungee) plugin; - api = bcab.getAPI(); - logger.info("BungeeCordAuthenticatorHook | Hooked successful!"); + public BungeeCordAuthenticatorBungeeHook(FastLoginBungee plugin) { + api = ((BungeeCordAuthenticatorBungee) plugin.getProxy().getPluginManager() + .getPlugin("BungeeCordAuthenticatorBungee")).getAPI(); + plugin.getLog().info("BungeeCordAuthenticatorHook | Hooked successful!"); } @Override