ResourcePack module, send resource pack after AuthMe login

This commit is contained in:
NichtStudioCode 2022-01-14 21:23:41 +01:00
parent 2f6ead0882
commit c40bda1434
7 changed files with 141 additions and 12 deletions

46
ResourcePack/pom.xml Normal file

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>InvUI-Parent</artifactId>
<groupId>de.studiocode.invui</groupId>
<version>0.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ResourcePack</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.studiocode.invui</groupId>
<artifactId>InvUI</artifactId>
<version>0.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>fr.xephi</groupId>
<artifactId>authme</artifactId>
<version>5.6.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

@ -4,13 +4,13 @@ import de.studiocode.inventoryaccess.util.ReflectionRegistry;
import de.studiocode.inventoryaccess.util.VersionUtils;
import de.studiocode.inventoryaccess.version.InventoryAccess;
import de.studiocode.invui.InvUI;
import de.studiocode.invui.resourcepack.auth.AuthenticationServiceManager;
import de.studiocode.invui.util.DataUtils;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.Nullable;
@ -30,9 +30,6 @@ public class ForceResourcePack implements Listener {
private static final String RP_VERSION = "v0.8";
private static final ForceResourcePack INSTANCE = new ForceResourcePack();
/**
* A resource pack with all the {@link Icon}s
*/
public static final String RESOURCE_PACK_URL =
"https://github.com/NichtStudioCode/InvUIRP/releases/download/"
+ RP_VERSION + (ReflectionRegistry.VERSION > 14 ? "" : "-legacy") + "/InvUIRP.zip";
@ -45,6 +42,10 @@ public class ForceResourcePack implements Listener {
private ForceResourcePack() {
Bukkit.getPluginManager().registerEvents(this, InvUI.getInstance().getPlugin());
AuthenticationServiceManager.getInstance().setLoginHandler(player -> {
if (resourcePackUrl != null) sendResourcePack(player);
});
}
public static ForceResourcePack getInstance() {
@ -90,11 +91,6 @@ public class ForceResourcePack implements Listener {
}
}
@EventHandler
public void handleJoin(PlayerJoinEvent event) {
if (resourcePackUrl != null) sendResourcePack(event.getPlayer());
}
public void sendResourcePack(Player player) {
if (VersionUtils.isServerHigherOrEqual("1.17.0")) {
InventoryAccess.getPlayerUtils().sendResourcePack(player, resourcePackUrl, hash, prompt, true);
@ -106,7 +102,7 @@ public class ForceResourcePack implements Listener {
}
@EventHandler
public void handleResourcePackStatus(PlayerResourcePackStatusEvent event) {
private void handleResourcePackStatus(PlayerResourcePackStatusEvent event) {
if (resourcePackUrl != null) {
Player player = event.getPlayer();
if (tasks.containsKey(player)) {
@ -121,4 +117,4 @@ public class ForceResourcePack implements Listener {
player.kickPlayer("§cPlease accept the custom resource pack");
}
}
}

@ -0,0 +1,12 @@
package de.studiocode.invui.resourcepack.auth;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
public abstract class AuthenticationService implements Listener {
public void handleAuthentication(Player player) {
AuthenticationServiceManager.getInstance().getLoginHandler().accept(player);
}
}

@ -0,0 +1,60 @@
package de.studiocode.invui.resourcepack.auth;
import de.studiocode.invui.InvUI;
import de.studiocode.invui.resourcepack.auth.impl.AuthMe;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.function.Consumer;
public class AuthenticationServiceManager implements Listener {
private static final AuthenticationServiceManager INSTANCE = new AuthenticationServiceManager();
private final ArrayList<AuthenticationService> services = new ArrayList<>();
private Consumer<Player> loginHandler;
private AuthenticationServiceManager() {
registerAuthenticationService("AuthMe", AuthMe.class);
if (services.isEmpty()) {
Bukkit.getPluginManager().registerEvents(this, InvUI.getInstance().getPlugin());
}
}
public static AuthenticationServiceManager getInstance() {
return INSTANCE;
}
private void registerAuthenticationService(String pluginName, Class<? extends AuthenticationService> serviceClass) {
try {
if (Bukkit.getPluginManager().isPluginEnabled(pluginName)) {
Constructor<? extends AuthenticationService> con = serviceClass.getConstructor();
AuthenticationService service = con.newInstance();
Bukkit.getPluginManager().registerEvents(service, InvUI.getInstance().getPlugin());
services.add(service);
}
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
@EventHandler
private void handleJoin(PlayerJoinEvent event) {
loginHandler.accept(event.getPlayer());
}
public void setLoginHandler(Consumer<Player> loginHandler) {
this.loginHandler = loginHandler;
}
public Consumer<Player> getLoginHandler() {
return loginHandler;
}
}

@ -0,0 +1,14 @@
package de.studiocode.invui.resourcepack.auth.impl;
import de.studiocode.invui.resourcepack.auth.AuthenticationService;
import fr.xephi.authme.events.LoginEvent;
import org.bukkit.event.EventHandler;
public class AuthMe extends AuthenticationService {
@EventHandler
private void handleLoginEvent(LoginEvent event) {
handleAuthentication(event.getPlayer());
}
}

@ -44,6 +44,7 @@
<module>InventoryAccess/IA-R8</module>
<module>InventoryAccess/IA</module>
<module>InvUI</module>
<module>ResourcePack</module>
</modules>
<build>
@ -76,7 +77,7 @@
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>xenondevs</id>