Skip to content

Commit

Permalink
Update passwords by implementing PasswordUpdateEvent for nLogin
Browse files Browse the repository at this point in the history
  • Loading branch information
nickuc committed Apr 12, 2024
1 parent 76128da commit 8a01779
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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 'com.nickuc.login:nlogin-api:10.3'
compileOnly 'me.clip:placeholderapi:2.11.1'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.account.PasswordUpdateEvent;
import com.nickuc.login.api.event.bukkit.auth.RegisterEvent;
import com.nickuc.login.api.event.bukkit.twofactor.TwoFactorAddEvent;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -36,6 +37,11 @@ public void onRegister(RegisterEvent event) {
handleRegister(player.getUniqueId(), player.getName(), event.getPassword(), address);
}

@EventHandler
public void onPasswordUpdate(PasswordUpdateEvent event) {
handleUpdatePassword(event.getPlayerId(), event.getPlayerName(), event.getNewPassword());
}

public static void register(AzLinkBukkitPlugin plugin) {
if (ensureApiVersion(plugin)) {
plugin.getServer().getPluginManager().registerEvents(new NLoginIntegration(plugin), plugin);
Expand Down
2 changes: 1 addition & 1 deletion bungee/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repositories {
dependencies {
implementation project(':azlink-common')
compileOnly 'net.md-5:bungeecord-api:1.16-R0.4'
compileOnly 'com.nickuc.login:nlogin-api:10.2'
compileOnly 'com.nickuc.login:nlogin-api:10.3'
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.account.PasswordUpdateEvent;
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;
Expand Down Expand Up @@ -38,6 +39,11 @@ public void onRegister(RegisterEvent event) {
handleRegister(player.getUniqueId(), player.getName(), event.getPassword(), address);
}

@EventHandler
public void onPasswordUpdate(PasswordUpdateEvent event) {
handleUpdatePassword(event.getPlayerId(), event.getPlayerName(), event.getNewPassword());
}

public static void register(AzLinkBungeePlugin plugin) {
if (ensureApiVersion(plugin)) {
plugin.getProxy().getPluginManager().registerListener(plugin, new NLoginIntegration(plugin));
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
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'
compileOnly 'com.nickuc.login:nlogin-api:10.3'

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
Expand Up @@ -37,6 +37,16 @@ protected void handleRegister(UUID uuid, String name, String password, InetAddre
});
}

protected void handleUpdatePassword(UUID uuid, String name, String password) {
this.plugin.getHttpClient()
.updatePassword(uuid, password)
.exceptionally(ex -> {
this.plugin.getLogger().error("Unable to update password for " + 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");
Expand Down
2 changes: 1 addition & 1 deletion velocity/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
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'
compileOnly 'com.nickuc.login:nlogin-api:10.3'
annotationProcessor 'com.velocitypowered:velocity-api:3.1.1'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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.account.PasswordUpdateEvent;
import com.nickuc.login.api.event.velocity.auth.RegisterEvent;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.proxy.Player;
Expand Down Expand Up @@ -33,6 +34,11 @@ public void onRegister(RegisterEvent event) {
handleRegister(player.getUniqueId(), player.getUsername(), event.getPassword(), address);
}

@Subscribe
public void onPasswordUpdate(PasswordUpdateEvent event) {
handleUpdatePassword(event.getPlayerId(), event.getPlayerName(), event.getNewPassword());
}

public static void register(AzLinkVelocityPlugin plugin) {
if (ensureApiVersion(plugin)) {
plugin.getProxy().getEventManager().register(plugin, new NLoginIntegration(plugin));
Expand Down

0 comments on commit 8a01779

Please sign in to comment.