games647 / FastLogin

Checks if a minecraft player has a valid paid account. If so, they can skip offline authentication automatically. (premium auto login)
https://www.spigotmc.org/resources/fastlogin.14153
MIT License
493 stars 121 forks source link

Custom AuthPlugin won't work... #447

Closed xXSchrandXx closed 3 years ago

xXSchrandXx commented 3 years ago

Hey,

I wanted to create a hook for your plugin, but everytime I use a static variable, it is null... ( Tested static getAPI() and getInstance() ) Maybe you could help me with that.

Code for new AuthPlugin ```JAVA package com.github.games647.fastlogin.bungee.hook; import java.sql.SQLException; 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: * https://github.com/xXSchrandXx/SpigotPlugins/tree/master/BungeeCordAuthenticator * * Project page: * * Spigot: https://www.spigotmc.org/resources/bungeecordauthenticator.87669/ */ public class BungeeCordAuthenticatorHook implements AuthPlugin { public BungeeCordAuthenticatorBungeeAPI api; public boolean register(Plugin plugin, Logger log) { if (plugin instanceof BungeeCordAuthenticatorBungee) { BungeeCordAuthenticatorBungee bcab = (BungeeCordAuthenticatorBungee) plugin; if (bcab != null) { api = bcab.getAPI(); } } else { log.warn("BungeeCordAuthenticatorBungee is null!"); BungeeCordAuthenticatorBungee bcab = BungeeCordAuthenticatorBungee.getInstance(); if (bcab != null) { api = bcab.getAPI(); } else { log.warn("BungeeCordAuthenticatorBungee is null, again!"); } } if (api == null) { return false; } else { return true; } } @Override public boolean forceLogin(ProxiedPlayer player) { if (api.isAuthenticated(player)) { return true; } else { try { api.setAuthenticated(player); } catch (SQLException e) { e.printStackTrace(); return false; } return true; } } @Override public boolean isRegistered(String playerName) { try { return api.getSQL().checkPlayerEntry(playerName); } catch (SQLException e) { e.printStackTrace(); return false; } } @Override public boolean forceRegister(ProxiedPlayer player, String password) { try { return api.createPlayerEntry(player, password); } catch (SQLException e) { e.printStackTrace(); return false; } } } ```

Here is the Link to my class with onEnable(): https://github.com/xXSchrandXx/SpigotPlugins/blob/master/BungeeCordAuthenticator/src/main/java/de/xxschrandxx/bca/bungee/BungeeCordAuthenticatorBungee.java

With best regards

xXSchrandXx

xXSchrandXx commented 3 years ago

I can't even cast the Plugin to my main class...

xXSchrandXx commented 3 years ago

new registerHook()

new BungeeCordAuthenticatorHook

games647 commented 3 years ago

It's properly null at the moment you want to register it. You need to set a dependency in the plugin.yml file, that FastLogin loads after your plugin.

xXSchrandXx commented 3 years ago

It is in the softdepend, it is getting set and FastLogin would even load after BCA because of the alphabetical loading of BungeeCord...

Even in my plugin it can use the method getInstance() without getting Null...

Edit: [listFiles()](https://docs.oracle.com/javase/7/docs/api/java/io/File.html#listFiles()) does not load alphabetical.

games647 commented 3 years ago

Your plugin name is incorrect: https://github.com/xXSchrandXx/SpigotPlugins/blob/bdb3555a30da0ad9c397c4fa6fc91b10cb27af01/BungeeCordAuthenticator/src/main/resources/plugin.yml#L1

xXSchrandXx commented 3 years ago

BungeeCord will use the bungee.yml and the filter is set as well.

Edit: Decompiled jar has this bungee.yml

name: BungeeCordAuthenticatorBungee
main: de.xxschrandxx.bca.bungee.BungeeCordAuthenticatorBungee
version: 0.0.2-SNAPSHOT
author: xXSchrandXx
description: BungeeCordAuthenticatorBungee
loadbefore: [FastLogin]
xXSchrandXx commented 3 years ago

Moved this here: https://www.spigotmc.org/threads/getinstance-an-getapi-returns-null-in-second-plugin.485542/