Skip to content

Commit

Permalink
AuthMe, SkinRestorer & LimboAuth integrations
Browse files Browse the repository at this point in the history
Closes #17, closes #24 and closes #26
  • Loading branch information
MrMicky-FR committed Jul 16, 2023
1 parent dea1597 commit 3d8b7a9
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
allprojects {
group 'com.azuriom'
version '1.3.0'
version '1.3.1'
}

subprojects {
Expand Down
1 change: 1 addition & 0 deletions bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
compileOnly 'io.netty:netty-all:4.1.25.Final'
compileOnly 'fr.xephi:authme:5.6.0-beta2'
compileOnly 'me.clip:placeholderapi:2.11.1'
compileOnly 'net.skinsrestorer:skinsrestorer-api:14.2.3'
}

// Folia is compiled with Java 17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azuriom.azlink.bukkit.integrations.AuthMeIntegration;
import com.azuriom.azlink.bukkit.integrations.FoliaSchedulerAdapter;
import com.azuriom.azlink.bukkit.integrations.MoneyPlaceholderExpansion;
import com.azuriom.azlink.bukkit.integrations.SkinRestorerIntegration;
import com.azuriom.azlink.common.AzLinkPlatform;
import com.azuriom.azlink.common.AzLinkPlugin;
import com.azuriom.azlink.common.command.CommandSender;
Expand Down Expand Up @@ -74,6 +75,11 @@ && getServer().getPluginManager().getPlugin("AuthMe") != null) {
getServer().getPluginManager().registerEvents(new AuthMeIntegration(this), this);
}

if (getConfig().getBoolean("skinrestorer-integration")
&& getServer().getPluginManager().getPlugin("SkinsRestorer") != null) {
getServer().getPluginManager().registerEvents(new SkinRestorerIntegration(this), this);
}

if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
MoneyPlaceholderExpansion.enable(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class AuthMeIntegration implements Listener {

Expand Down Expand Up @@ -89,6 +90,33 @@ public void onRegister(RegisterEvent event) {
});
}

private void handlePasswordHash(String playerName, String password, String hash) {
Player player = this.plugin.getServer().getPlayer(playerName);

if (player == null || !AuthMeApi.getInstance().isAuthenticated(player)) {
this.passwords.put(hash, password);

return;
}

this.plugin.getSchedulerAdapter().scheduleAsyncLater(() -> {
HashedPassword hashedPassword = this.dataSource.getPassword(playerName);

if (!hashedPassword.getHash().equals(hash)) {
return;
}

this.plugin.getPlugin()
.getHttpClient()
.updatePassword(player.getUniqueId(), password)
.exceptionally(ex -> {
this.plugin.getLoggerAdapter().error("Unable to update password for " + player.getName(), ex);

return null;
});
}, 1, TimeUnit.SECONDS);
}

public class ForwardingEncryptionMethod implements EncryptionMethod {

private final EncryptionMethod method;
Expand All @@ -100,14 +128,14 @@ public ForwardingEncryptionMethod(EncryptionMethod method) {
@Override
public HashedPassword computeHash(String password, String name) {
HashedPassword hash = this.method.computeHash(password, name);
AuthMeIntegration.this.passwords.put(hash.getHash(), password);
handlePasswordHash(name, password, hash.getHash());
return hash;
}

@Override
public String computeHash(String password, String salt, String name) {
String hash = this.method.computeHash(password, salt, name);
AuthMeIntegration.this.passwords.put(hash, password);
handlePasswordHash(name, password, hash);
return hash;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.azuriom.azlink.bukkit.integrations;

import com.azuriom.azlink.bukkit.AzLinkBukkitPlugin;
import net.skinsrestorer.api.PlayerWrapper;
import net.skinsrestorer.api.SkinsRestorerAPI;
import net.skinsrestorer.api.exception.SkinRequestException;
import net.skinsrestorer.api.property.IProperty;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

public class SkinRestorerIntegration implements Listener {

private final AzLinkBukkitPlugin plugin;

public SkinRestorerIntegration(AzLinkBukkitPlugin plugin) {
this.plugin = plugin;

this.plugin.getLoggerAdapter().info("SkinRestorer integration enabled.");
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
String baseUrl = this.plugin.getPlugin().getConfig().getSiteUrl();


if (baseUrl == null) {
return;
}

try {
String url = baseUrl + "/api/skin-api/skins/" + player.getName();
IProperty skin = SkinsRestorerAPI.getApi().genSkinUrl(url, null);

SkinsRestorerAPI.getApi().applySkin(new PlayerWrapper(player), skin);
} catch (SkinRequestException ex) {
this.plugin.getLoggerAdapter().warn("Unable to apply skin for " + player.getName() + ": " + ex.getMessage());
}
}
}
4 changes: 4 additions & 0 deletions bukkit/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ ignore-vanished-players: false
# If you are using multiples serves, you should use the same database for AuthMe to prevent users
# from registering multiple times
authme-integration: false

# When enabled, if SkinRestorer 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: 1 addition & 1 deletion bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: The plugin to link your Azuriom website with your server.
website: https://azuriom.com
main: com.azuriom.azlink.bukkit.AzLinkBukkitPlugin
api-version: 1.13
softdepend: [PlaceholderAPI]
softdepend: [PlaceholderAPI, SkinsRestorer]
loadbefore: [AuthMe]
folia-supported: true
commands:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void execute(CommandSender sender, String[] args) {

if (args[0].equalsIgnoreCase("setup")) {
if (args.length < 3) {
sender.sendMessage("&cUsage: /azlink setup <url> <key>");
sender.sendMessage("&6You must first add this server in your Azuriom admin dashboard, in the 'Servers' section.");
return;
}

Expand Down Expand Up @@ -177,7 +177,7 @@ public String getUsage() {
private void sendUsage(CommandSender sender) {
String version = this.plugin.getPlatform().getPluginVersion();
sender.sendMessage("&9AzLink v" + version + "&7. Website: &9https://azuriom.com");
sender.sendMessage("&8- /azlink setup <url> <key>");
sender.sendMessage("&8- /azlink setup");
sender.sendMessage("&8- /azlink port <port>");
sender.sendMessage("&8- /azlink status");
sender.sendMessage("&8- /azlink money <add|remove|set> <player> <amount>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public CompletableFuture<Void> updateEmail(UUID uuid, String email) {
return request(RequestMethod.POST, "/azlink/email", params);
}

public CompletableFuture<Void> updatePassword(UUID uuid, String password) {
JsonObject params = new JsonObject();
params.addProperty("game_id", uuid.toString());
params.addProperty("password", password);

return request(RequestMethod.POST, "/azlink/password", params);
}

public CompletableFuture<EditMoneyResult> editMoney(UserInfo user, String action, double amount) {
String endpoint = "/azlink/user/" + user.getId() + "/money/" + action;
JsonObject params = new JsonObject();
Expand Down
6 changes: 6 additions & 0 deletions velocity/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ plugins {

repositories {
maven { url 'https://nexus.velocitypowered.com/repository/maven-public/' }
maven { url 'https://maven.elytrium.net/repo/' }
}

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

// LimboAuth support
disableAutoTargetJvm()

blossom {
replaceToken '${pluginVersion}', project.version, 'src/main/java/com/azuriom/azlink/velocity/AzLinkVelocityPlugin.java'
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import com.azuriom.azlink.common.scheduler.SchedulerAdapter;
import com.azuriom.azlink.velocity.command.VelocityCommandExecutor;
import com.azuriom.azlink.velocity.command.VelocityCommandSender;
import com.azuriom.azlink.velocity.integrations.LimboAuthIntegration;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
Expand All @@ -29,7 +31,10 @@
version = "${pluginVersion}",
description = "The plugin to link your Azuriom website with your server.",
url = "https://azuriom.com",
authors = "Azuriom Team"
authors = "Azuriom Team",
dependencies = {
@Dependency(id = "limboauth", optional = true),
}
)
public final class AzLinkVelocityPlugin implements AzLinkPlatform {

Expand Down Expand Up @@ -61,7 +66,12 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
this.plugin = new AzLinkPlugin(this);
this.plugin.init();

this.proxy.getCommandManager().register("azlink", new VelocityCommandExecutor(this.plugin), "azuriomlink");
this.proxy.getCommandManager()
.register("azlink", new VelocityCommandExecutor(this.plugin), "azuriomlink");

if (this.proxy.getPluginManager().getPlugin("limboauth").isPresent()) {
this.proxy.getEventManager().register(this, new LimboAuthIntegration(this));
}
}

@Subscribe
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.azuriom.azlink.velocity.integrations;

import com.azuriom.azlink.velocity.AzLinkVelocityPlugin;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.proxy.Player;
import net.elytrium.limboauth.event.PostRegisterEvent;

import java.net.InetAddress;

public class LimboAuthIntegration {

private final AzLinkVelocityPlugin plugin;

public LimboAuthIntegration(AzLinkVelocityPlugin plugin) {
this.plugin = plugin;

this.plugin.getLoggerAdapter().info("LimboAuth integration enabled.");
}

@Subscribe
public void onPostRegister(PostRegisterEvent event) {
Player player = event.getPlayer().getProxyPlayer();
String password = event.getPassword();
InetAddress ip = player.getRemoteAddress().getAddress();

this.plugin.getPlugin()
.getHttpClient()
.registerUser(player.getUsername(), null, player.getUniqueId(), password, ip)
.exceptionally(ex -> {
this.plugin.getLoggerAdapter().error("Unable to register " + player.getUsername(), ex);

return null;
});
}
}

0 comments on commit 3d8b7a9

Please sign in to comment.