Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] nlogin integration #2

Open
bejoeled opened this issue Jul 7, 2022 · 6 comments
Open

[FEATURE REQUEST] nlogin integration #2

bejoeled opened this issue Jul 7, 2022 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@bejoeled
Copy link

bejoeled commented Jul 7, 2022

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

@bejoeled bejoeled added the enhancement New feature or request label Jul 7, 2022
@bejoeled bejoeled closed this as completed Jul 7, 2022
@bejoeled bejoeled reopened this Jul 7, 2022
@Polda18 Polda18 self-assigned this Jul 19, 2022
@Polda18
Copy link
Owner

Polda18 commented Jul 19, 2022

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
Copy link

nickuc commented Jul 19, 2022

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.

if(!Bukkit.getOnlineMode()) {
boolean is_mojang_player = (entry.getOnlineUUID() != null);
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
Objects.requireNonNull(plugin.getLanguage().getConfig()
.getString("messages.mojang-player.message"))
.replace("(mojang)",
Objects.requireNonNull((is_mojang_player)
? plugin.getLanguage().getConfig()
.getString("messages.mojang-player.true")
: plugin.getLanguage().getConfig()
.getString("messages.mojang-player.false")))));
String mojang_player = UUIDGenerator.lookupMojangPlayerName(entry.getPlayer());
if(mojang_player != null) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
Objects.requireNonNull(plugin.getLanguage().getConfig()
.getString("messages.mojang-player.name"))
.replace("(player)", mojang_player)));
}
}

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

/**
* Event that is fired when player joins the server
* @param event The event handle containing informations necessary for the function
* @throws IOException Fired when there was an input/output error
* @throws AlreadyInWhitelistException Fired when the player was somehow found in whitelist (online mode update, failsafe mechanism)
* @throws OnlineUUIDException Fired when an online UUID couldn't be found (online mode update, failsafe mechanism)
* @throws InvalidEntryException Fired when specified old player wasn't found in the whitelist (online mode update, failsafe mechanism)
*/
@EventHandler
public void onPlayerConnect(AsyncPlayerPreLoginEvent event) throws IOException, AlreadyInWhitelistException, OnlineUUIDException, InvalidEntryException {

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

@Polda18
Copy link
Owner

Polda18 commented Jul 19, 2022

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
Copy link

nickuc commented Jul 19, 2022

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(), since, as you said, many other plugins can block login with PlayerLoginEvent.

@Polda18
Copy link
Owner

Polda18 commented Jul 20, 2022

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
Copy link

nickuc commented Jul 20, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants