Use a loop to hook AuthPlugin

This commit is contained in:
InkerBot
2021-04-06 21:58:53 +08:00
parent 68d23e127a
commit f766e6213e
3 changed files with 31 additions and 26 deletions

View File

@ -26,12 +26,13 @@
package com.github.games647.fastlogin.bungee; package com.github.games647.fastlogin.bungee;
import com.github.games647.fastlogin.bungee.hook.BungeeAuthHook; 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.hook.SodionAuthHook;
import com.github.games647.fastlogin.bungee.listener.ConnectListener; import com.github.games647.fastlogin.bungee.listener.ConnectListener;
import com.github.games647.fastlogin.bungee.listener.PluginMessageListener; import com.github.games647.fastlogin.bungee.listener.PluginMessageListener;
import com.github.games647.fastlogin.core.AsyncScheduler; import com.github.games647.fastlogin.core.AsyncScheduler;
import com.github.games647.fastlogin.core.CommonUtil; 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.ChangePremiumMessage;
import com.github.games647.fastlogin.core.message.ChannelMessage; import com.github.games647.fastlogin.core.message.ChannelMessage;
import com.github.games647.fastlogin.core.message.NamespaceKey; 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 com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ThreadFactory; 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.plugin.PluginManager;
import net.md_5.bungee.api.scheduler.GroupedThreadFactory; import net.md_5.bungee.api.scheduler.GroupedThreadFactory;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.slf4j.Logger; import org.slf4j.Logger;
/** /**
@ -111,23 +116,21 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSen
} }
private void registerHook() { private void registerHook() {
Plugin BungeeAuth = getProxy().getPluginManager().getPlugin("BungeeAuth"); try {
if (BungeeAuth != null) { List<Class<? extends AuthPlugin<ProxiedPlayer>>> hooks = Arrays.asList(
core.setAuthPluginHook(new BungeeAuthHook()); BungeeAuthHook.class, BungeeCordAuthenticatorBungeeHook.class, SodionAuthHook.class);
logger.info("Hooked into BungeeAuth");
} for (Class<? extends AuthPlugin<ProxiedPlayer>> clazz : hooks) {
Plugin BungeeCordAuthenticatorBungee = getProxy().getPluginManager().getPlugin("BungeeCordAuthenticatorBungee"); String pluginName = clazz.getSimpleName().replace("Hook", "");
if (BungeeCordAuthenticatorBungee != null) { //uses only member classes which uses AuthPlugin interface (skip interfaces)
logger.info("Try to hook into BungeeCordAuthenticatorBungee..."); Plugin plugin = getProxy().getPluginManager().getPlugin(pluginName);
BungeeCordAuthenticatorHook hook = new BungeeCordAuthenticatorHook(BungeeCordAuthenticatorBungee, logger); if (plugin != null) {
core.setAuthPluginHook(hook); core.setAuthPluginHook(
} clazz.getDeclaredConstructor(FastLoginBungee.class).newInstance(this));
Plugin SodionAuth = getProxy().getPluginManager().getPlugin("SodionAuth"); }
if (BungeeCordAuthenticatorBungee != null) { }
logger.info("Try to hook into SodionAuth..."); } catch (ReflectiveOperationException ex) {
SodionAuthHook hook = new SodionAuthHook(this); logger.error("Couldn't load the auth hook class", ex);
core.setAuthPluginHook(hook);
logger.info("Hooked into SodionAuth");
} }
} }

View File

@ -25,6 +25,7 @@
*/ */
package com.github.games647.fastlogin.bungee.hook; package com.github.games647.fastlogin.bungee.hook;
import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import me.vik1395.BungeeAuth.Main; import me.vik1395.BungeeAuth.Main;
@ -43,6 +44,9 @@ public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
private final RequestHandler requestHandler = new RequestHandler(); private final RequestHandler requestHandler = new RequestHandler();
public BungeeAuthHook(FastLoginBungee plugin) {
}
@Override @Override
public boolean forceLogin(ProxiedPlayer player) { public boolean forceLogin(ProxiedPlayer player) {
String playerName = player.getName(); String playerName = player.getName();

View File

@ -27,15 +27,13 @@ package com.github.games647.fastlogin.bungee.hook;
import java.sql.SQLException; import java.sql.SQLException;
import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import org.slf4j.Logger;
import de.xxschrandxx.bca.bungee.BungeeCordAuthenticatorBungee; import de.xxschrandxx.bca.bungee.BungeeCordAuthenticatorBungee;
import de.xxschrandxx.bca.bungee.api.BungeeCordAuthenticatorBungeeAPI; import de.xxschrandxx.bca.bungee.api.BungeeCordAuthenticatorBungeeAPI;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
/** /**
* GitHub: * GitHub:
@ -45,14 +43,14 @@ import net.md_5.bungee.api.plugin.Plugin;
* *
* Spigot: https://www.spigotmc.org/resources/bungeecordauthenticator.87669/ * Spigot: https://www.spigotmc.org/resources/bungeecordauthenticator.87669/
*/ */
public class BungeeCordAuthenticatorHook implements AuthPlugin<ProxiedPlayer> { public class BungeeCordAuthenticatorBungeeHook implements AuthPlugin<ProxiedPlayer> {
public final BungeeCordAuthenticatorBungeeAPI api; public final BungeeCordAuthenticatorBungeeAPI api;
public BungeeCordAuthenticatorHook(Plugin plugin, Logger logger) { public BungeeCordAuthenticatorBungeeHook(FastLoginBungee plugin) {
BungeeCordAuthenticatorBungee bcab = (BungeeCordAuthenticatorBungee) plugin; api = ((BungeeCordAuthenticatorBungee) plugin.getProxy().getPluginManager()
api = bcab.getAPI(); .getPlugin("BungeeCordAuthenticatorBungee")).getAPI();
logger.info("BungeeCordAuthenticatorHook | Hooked successful!"); plugin.getLog().info("BungeeCordAuthenticatorHook | Hooked successful!");
} }
@Override @Override