Polda18 / BetterWhitelist

A Minecraft Spigot plugin for better whitelist
GNU General Public License v3.0
6 stars 1 forks source link

[FEATURE REQUEST] nlogin integration #2

Open bejoeled opened 2 years ago

bejoeled commented 2 years ago

Is your feature request related to a problem? Please describe. We have an authentication plugin in our server called nlogin (https://en.docs.nickuc.com/about) and it allows Premium Minecraft users to automatically login without typing in the password. They use a different UUID system in their configuration. However, after installing BetterWhitelist, it stopped letting premium Minecraft users to automatically login. Perhaps because BetterWhitelist uses offline UUID which nlogin does not use.

Describe the solution you'd like Is it possible to make BetterWhitelist work perfectly with nlogin?

Describe alternatives you've considered

Additional context Here's their discord server: https://discord.gg/JXzf9YrDJN

Polda18 commented 2 years ago

Hello. I've looked into the linked website and it seems like this plugin could be used with an API (eighter BungeeCord plugin messaging, or direct Spigot library mapping). Theoretically, it could be possible, however, it's going to require quite a lot of resources to learn and properly test out, I'll have to contact a friend so we could test it out on a live server he owns, but first of all I'll have to contact the developers so I can fine tune exactly how this soft dependency is going to be implemented in my plugin (which conveniently enough may be at the Discord link as a starting point). I'll let you know with a further development of this. I've also received a similar feature request on Discord by another user, so I might end up looking into ways of implementing various APIs in my plugin.

nickuc commented 2 years ago

I checked the code here and came up with an idea that should be able to support nLogin without problems.

I thought of using Server#getOfflinePlayer(String) instead of the internal generator, since the UUID of nLogin is forwarded to the backend servers, so it will be stored in usercache.json.

https://github.com/Polda18/BetterWhitelist/blob/bfc1ec6259fa7d4a0386723189e0d9a4e69424c4/src/main/java/me/polda18/betterwhitelist/commands/WhitelistCommand.java#L182-L203

And here it might be worth changing the AsyncPlayerPreLoginEvent event to PlayerLoginEvent, since the UUID will already be available through the getPlayer() method

https://github.com/Polda18/BetterWhitelist/blob/bfc1ec6259fa7d4a0386723189e0d9a4e69424c4/src/main/java/me/polda18/betterwhitelist/events/EventsListener.java#L32-L41

Those were my ideas, that was the most simplified way I thought of.

Polda18 commented 2 years ago

I was using PlayerLoginEvent previously and didn't really work well, because it caused the player to join the server for a split moment before being kicked if the player wasn't on whitelist, and if you're using a plugin for player analytics, an auth plugin, etc, they clog your server with junk data. Even just vanilla server gets clogged with junk player data, because each player that joins will get assigned their inventory and ender chest. AsyncPlayerPreLoginEvent makes sure that the player will never get to the server if the player is banned or not whitelisted and won't clog the server with junk data. I guess the only option now would be communicate with plugin API and get the correct UUID another way.

Not to mention that occasionally you could see a message that someone joined and immediately leaved, or depending on what plugins you used for authentication, only a leave message. With this simple fix, that issue no longer happens.

nickuc commented 2 years ago

I was using PlayerLoginEvent previously and didn't really work well, because it caused the player to join the server for a split moment before being kicked if the player wasn't on whitelist

I think you can fix this by using PlayerLoginEvent#disallow() instead of Player#kickPlayer().

I recommend you check if the event has already been canceled before blocking - with [PlayerLoginEvent#getResult()](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerLoginEvent.html#getResult()), since, as you said, many other plugins can block login with PlayerLoginEvent.

Polda18 commented 2 years ago

Okay, I'll experiment a little bit with this thing and see how it will work. Although, I'll still need to use an API with this thing in order to ensure that servers using custom auth systems can work properly with my plugin.

nickuc commented 2 years ago

You can see more details of the nLogin API here:

JavaDocs: https://jd.nickuc.com/nlogin/ Maven/Gradle: https://en.docs.nickuc.com/development/maven-gradle