-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #30
- Loading branch information
Showing
14 changed files
with
224 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
bukkit/src/main/java/com/azuriom/azlink/bukkit/integrations/NLoginIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
bungee/src/main/java/com/azuriom/azlink/bungee/integrations/NLoginIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
common/src/main/java/com/azuriom/azlink/common/integrations/BaseNLogin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
velocity/src/main/java/com/azuriom/azlink/velocity/integrations/NLoginIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |