-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
17 changed files
with
204 additions
and
23 deletions.
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
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
37 changes: 37 additions & 0 deletions
37
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,37 @@ | ||
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.bungee.twofactor.TwoFactorAddEvent; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
|
||
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 ip = player.getAddress(); | ||
|
||
handleRegister(player.getUniqueId(), player.getName(), event.getPassword(), ip != null ? ip.getAddress() : null); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
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,40 @@ | ||
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 ip = socketAddress instanceof InetSocketAddress ? ((InetSocketAddress) socketAddress).getAddress() : null; | ||
|
||
handleRegister(player.getUniqueId(), player.getName(), event.getPassword(), ip); | ||
} | ||
} |
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 serves, 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
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
39 changes: 39 additions & 0 deletions
39
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,39 @@ | ||
package com.azuriom.azlink.common.integrations; | ||
|
||
import com.azuriom.azlink.common.AzLinkPlugin; | ||
|
||
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 playerId, String playerName, String newEmail) { | ||
this.plugin | ||
.getHttpClient() | ||
.updateEmail(playerId, newEmail) | ||
.exceptionally(ex -> { | ||
this.plugin.getLogger().error("Unable to update email for " + playerName, ex); | ||
|
||
return null; | ||
}); | ||
} | ||
|
||
protected void handleRegister(UUID playerId, String playerName, String password, InetAddress ip) { | ||
this.plugin | ||
.getHttpClient() | ||
.registerUser(playerName, null, playerId, password, ip) | ||
.exceptionally(ex -> { | ||
this.plugin.getLogger().error("Unable to register " + playerName, ex); | ||
|
||
return null; | ||
}); | ||
} | ||
} |
6 changes: 1 addition & 5 deletions
6
common/src/main/java/com/azuriom/azlink/common/scheduler/JavaSchedulerAdapter.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
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
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
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.bungee.twofactor.TwoFactorAddEvent; | ||
import com.nickuc.login.api.event.velocity.auth.RegisterEvent; | ||
import com.velocitypowered.api.event.Subscribe; | ||
import com.velocitypowered.api.proxy.Player; | ||
|
||
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(); | ||
|
||
handleRegister(player.getUniqueId(), player.getUsername(), event.getPassword(), player.getRemoteAddress().getAddress()); | ||
} | ||
} |