Skip to content

Commit

Permalink
Add nLogin integration (#37)
Browse files Browse the repository at this point in the history
Closes #30
  • Loading branch information
nickuc authored Jan 15, 2024
1 parent cca5cc3 commit 0b02fac
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://repo.papermc.io/repository/maven-public/' }
maven { url 'https://repo.codemc.io/repository/maven-public/' }
maven { url 'https://repo.nickuc.com/maven-releases/' }
maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
}

Expand All @@ -10,6 +11,7 @@ dependencies {
compileOnly 'dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT'
compileOnly 'io.netty:netty-all:4.1.25.Final'
compileOnly 'fr.xephi:authme:5.6.0-beta2'
compileOnly 'com.nickuc.login:nlogin-api:10.2'
compileOnly 'me.clip:placeholderapi:2.11.1'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azuriom.azlink.bukkit.integrations.FoliaSchedulerAdapter;
import com.azuriom.azlink.bukkit.integrations.MoneyPlaceholderExpansion;
import com.azuriom.azlink.bukkit.integrations.SkinsRestorerIntegration;
import com.azuriom.azlink.bukkit.integrations.NLoginIntegration;
import com.azuriom.azlink.common.AzLinkPlatform;
import com.azuriom.azlink.common.AzLinkPlugin;
import com.azuriom.azlink.common.command.CommandSender;
Expand Down Expand Up @@ -85,6 +86,11 @@ && getServer().getPluginManager().getPlugin("AuthMe") != null) {
getServer().getPluginManager().registerEvents(new AuthMeIntegration(this), this);
}

if (getConfig().getBoolean("nlogin-integration")
&& getServer().getPluginManager().getPlugin("nLogin") != null) {
NLoginIntegration.register(this);
}

if (getConfig().getBoolean("skinrestorer-integration")
&& getServer().getPluginManager().getPlugin("SkinsRestorer") != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.azuriom.azlink.bukkit.integrations;

import com.azuriom.azlink.bukkit.AzLinkBukkitPlugin;
import com.azuriom.azlink.common.integrations.BaseNLogin;
import com.nickuc.login.api.enums.TwoFactorType;
import com.nickuc.login.api.event.bukkit.auth.RegisterEvent;
import com.nickuc.login.api.event.bukkit.twofactor.TwoFactorAddEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import java.net.InetAddress;
import java.net.InetSocketAddress;

public class NLoginIntegration extends BaseNLogin implements Listener {

public NLoginIntegration(AzLinkBukkitPlugin plugin) {
super(plugin.getPlugin());
}

@EventHandler
public void onEmailAdded(TwoFactorAddEvent event) {
if (event.getType() != TwoFactorType.EMAIL) {
return;
}

handleEmailUpdated(event.getPlayerId(), event.getPlayerName(), event.getAccount());
}

@EventHandler
public void onRegister(RegisterEvent event) {
Player player = event.getPlayer();
InetSocketAddress socketAddress = player.getAddress();
InetAddress address = socketAddress != null ? socketAddress.getAddress() : null;

handleRegister(player.getUniqueId(), player.getName(), event.getPassword(), address);
}

public static void register(AzLinkBukkitPlugin plugin) {
if (ensureApiVersion(plugin)) {
plugin.getServer().getPluginManager().registerEvents(new NLoginIntegration(plugin), plugin);
}
}
}
8 changes: 7 additions & 1 deletion bukkit/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ ignore-vanished-players: false

# When enabled, new users registered with the AuthMe plugin will automatically be registered on the website
# WARNING: You need AuthMeReloaded version 5.6.0-beta2 or newer AND Azuriom version 1.0.0 or newer!
# If you are using multiples serves, you should use the same database for AuthMe to prevent users
# If you are using multiples servers, you should use the same database for AuthMe to prevent users
# from registering multiple times
authme-integration: false

# When enabled, new users registered with the nLogin plugin will automatically be registered on the website
# WARNING: You need nLogin version 10.2.43 or newer!
# If you are using multiples servers, you should use the same database for nLogin to prevent users
# from registering multiple times
nlogin-integration: false

# When enabled, if SkinsRestorer is installed, and the SkinAPI plugin is present on the website,
# the player's skin will be updated to the website's skin
skinrestorer-integration: false
2 changes: 2 additions & 0 deletions bungee/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://repo.nickuc.com/maven-releases/' }
}

dependencies {
implementation project(':azlink-common')
compileOnly 'net.md-5:bungeecord-api:1.16-R0.4'
compileOnly 'com.nickuc.login:nlogin-api:10.2'
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.azuriom.azlink.bungee.command.BungeeCommandExecutor;
import com.azuriom.azlink.bungee.command.BungeeCommandSender;
import com.azuriom.azlink.bungee.integrations.NLoginIntegration;
import com.azuriom.azlink.bungee.integrations.SkinsRestorerIntegration;
import com.azuriom.azlink.common.AzLinkPlatform;
import com.azuriom.azlink.common.AzLinkPlugin;
Expand Down Expand Up @@ -43,6 +44,11 @@ public void onEnable() {

loadConfig();

if (this.config.getBoolean("nlogin-integration")
&& getProxy().getPluginManager().getPlugin("nLogin") != null) {
NLoginIntegration.register(this);
}

if (this.config.getBoolean("skinsrestorer-integration")
&& getProxy().getPluginManager().getPlugin("SkinsRestorer") != null) {
getProxy().getPluginManager().registerListener(this, new SkinsRestorerIntegration(this));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.azuriom.azlink.bungee.integrations;

import com.azuriom.azlink.bungee.AzLinkBungeePlugin;
import com.azuriom.azlink.common.integrations.BaseNLogin;
import com.nickuc.login.api.enums.TwoFactorType;
import com.nickuc.login.api.event.bungee.auth.RegisterEvent;
import com.nickuc.login.api.event.bungee.twofactor.TwoFactorAddEvent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;

public class NLoginIntegration extends BaseNLogin implements Listener {

public NLoginIntegration(AzLinkBungeePlugin plugin) {
super(plugin.getPlugin());
}

@EventHandler
public void onEmailAdded(TwoFactorAddEvent event) {
if (event.getType() != TwoFactorType.EMAIL) {
return;
}

handleEmailUpdated(event.getPlayerId(), event.getPlayerName(), event.getAccount());
}

@EventHandler
public void onRegister(RegisterEvent event) {
ProxiedPlayer player = event.getPlayer();
SocketAddress socketAddress = player.getSocketAddress();
InetAddress address = socketAddress instanceof InetSocketAddress
? ((InetSocketAddress) socketAddress).getAddress() : null;

handleRegister(player.getUniqueId(), player.getName(), event.getPassword(), address);
}

public static void register(AzLinkBungeePlugin plugin) {
if (ensureApiVersion(plugin)) {
plugin.getProxy().getPluginManager().registerListener(plugin, new NLoginIntegration(plugin));
}
}
}
6 changes: 6 additions & 0 deletions bungee/src/main/resources/bungee-config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# When enabled, new users registered with the nLogin plugin will automatically be registered on the website
# WARNING: You need nLogin version 10.2.43 or newer!
# If you are using multiples servers, you should use the same database for nLogin to prevent users
# from registering multiple times
nlogin-integration: false

# When enabled, if SkinsRestorer is installed, and the SkinAPI plugin is present on the website,
# the player's skin will be updated to the website's skin
skinsrestorer-integration: false
2 changes: 2 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
repositories {
maven { url 'https://repo.codemc.io/repository/maven-public/' }
maven { url 'https://repo.nickuc.com/maven-releases/' }
}

dependencies {
compileOnly 'org.slf4j:slf4j-api:1.7.36'
compileOnly 'com.google.code.gson:gson:2.10.1'
compileOnly 'io.netty:netty-all:4.1.42.Final'
compileOnly 'net.skinsrestorer:skinsrestorer-api:15.0.2'
compileOnly 'com.nickuc.login:nlogin-api:10.2'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.azuriom.azlink.common.integrations;

import com.azuriom.azlink.common.AzLinkPlatform;
import com.azuriom.azlink.common.AzLinkPlugin;
import com.nickuc.login.api.nLoginAPI;

import java.net.InetAddress;
import java.util.UUID;

public class BaseNLogin {

protected final AzLinkPlugin plugin;

public BaseNLogin(AzLinkPlugin plugin) {
this.plugin = plugin;

this.plugin.getLogger().info("nLogin integration enabled.");
}

protected void handleEmailUpdated(UUID uuid, String name, String email) {
this.plugin.getHttpClient()
.updateEmail(uuid, email)
.exceptionally(ex -> {
this.plugin.getLogger().error("Unable to update email for " + name, ex);

return null;
});
}

protected void handleRegister(UUID uuid, String name, String password, InetAddress address) {
this.plugin.getHttpClient()
.registerUser(name, null, uuid, password, address)
.exceptionally(ex -> {
this.plugin.getLogger().error("Unable to register " + name, ex);

return null;
});
}

protected static boolean ensureApiVersion(AzLinkPlatform platform) {
if (nLoginAPI.getApi().getApiVersion() < 5) {
platform.getPlugin().getLogger().warn("nLogin integration requires API v5 or higher");
return false;
}

return true;
}
}
2 changes: 2 additions & 0 deletions velocity/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ plugins {
repositories {
maven { url 'https://nexus.velocitypowered.com/repository/maven-public/' }
maven { url 'https://maven.elytrium.net/repo/' }
maven { url 'https://repo.nickuc.com/maven-releases/' }
}

dependencies {
implementation project(':azlink-common')
compileOnly 'com.velocitypowered:velocity-api:3.1.1'
compileOnly 'net.elytrium.limboapi:api:1.1.13'
compileOnly 'net.elytrium:limboauth:1.1.1'
compileOnly 'com.nickuc.login:nlogin-api:10.2'
annotationProcessor 'com.velocitypowered:velocity-api:3.1.1'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.azuriom.azlink.velocity.command.VelocityCommandExecutor;
import com.azuriom.azlink.velocity.command.VelocityCommandSender;
import com.azuriom.azlink.velocity.integrations.LimboAuthIntegration;
import com.azuriom.azlink.velocity.integrations.NLoginIntegration;
import com.azuriom.azlink.velocity.integrations.SkinsRestorerIntegration;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
Expand Down Expand Up @@ -81,6 +82,11 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
this.proxy.getEventManager().register(this, new LimboAuthIntegration(this));
}

if (this.proxy.getPluginManager().getPlugin("nlogin").isPresent()
&& this.config.getNode("nlogin-integration").getBoolean()) {
NLoginIntegration.register(this);
}

if (this.proxy.getPluginManager().getPlugin("skinsrestorer").isPresent()
&& this.config.getNode("skinsrestorer-integration").getBoolean()) {
this.proxy.getEventManager().register(this, new SkinsRestorerIntegration(this));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.azuriom.azlink.velocity.integrations;

import com.azuriom.azlink.common.integrations.BaseNLogin;
import com.azuriom.azlink.velocity.AzLinkVelocityPlugin;
import com.nickuc.login.api.enums.TwoFactorType;
import com.nickuc.login.api.event.velocity.twofactor.TwoFactorAddEvent;
import com.nickuc.login.api.event.velocity.auth.RegisterEvent;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.proxy.Player;

import java.net.InetAddress;

public class NLoginIntegration extends BaseNLogin {

public NLoginIntegration(AzLinkVelocityPlugin plugin) {
super(plugin.getPlugin());
}

@Subscribe
public void onEmailAdded(TwoFactorAddEvent event) {
if (event.getType() != TwoFactorType.EMAIL) {
return;
}

handleEmailUpdated(event.getPlayerId(), event.getPlayerName(), event.getAccount());
}

@Subscribe
public void onRegister(RegisterEvent event) {
Player player = event.getPlayer();
InetAddress address = player.getRemoteAddress().getAddress();

handleRegister(player.getUniqueId(), player.getUsername(), event.getPassword(), address);
}

public static void register(AzLinkVelocityPlugin plugin) {
if (ensureApiVersion(plugin)) {
plugin.getProxy().getEventManager().register(plugin, new NLoginIntegration(plugin));
}
}
}
6 changes: 6 additions & 0 deletions velocity/src/main/resources/velocity-config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# When enabled, if SkinsRestorer is installed, and the SkinAPI plugin is present on the website,
# the player's skin will be updated to the website's skin
skinsrestorer-integration: false

# When enabled, new users registered with the nLogin plugin will automatically be registered on the website
# WARNING: You need nLogin version 10.2.43 or newer!
# If you are using multiples servers, you should use the same database for nLogin to prevent users
# from registering multiple times
nlogin-integration: false

0 comments on commit 0b02fac

Please sign in to comment.