diff --git a/ResourcePack/pom.xml b/ResourcePack/pom.xml new file mode 100644 index 0000000..38feb72 --- /dev/null +++ b/ResourcePack/pom.xml @@ -0,0 +1,46 @@ + + + + InvUI-Parent + de.studiocode.invui + 0.2-SNAPSHOT + + 4.0.0 + + ResourcePack + + + 11 + 11 + + + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + + + + + + org.spigotmc + spigot-api + 1.18.1-R0.1-SNAPSHOT + provided + + + de.studiocode.invui + InvUI + 0.2-SNAPSHOT + + + fr.xephi + authme + 5.6.0-SNAPSHOT + provided + + + + \ No newline at end of file diff --git a/InvUI/src/main/java/de/studiocode/invui/resourcepack/ForceResourcePack.java b/ResourcePack/src/main/java/de/studiocode/invui/resourcepack/ForceResourcePack.java similarity index 92% rename from InvUI/src/main/java/de/studiocode/invui/resourcepack/ForceResourcePack.java rename to ResourcePack/src/main/java/de/studiocode/invui/resourcepack/ForceResourcePack.java index f7b26bd..7e1e500 100644 --- a/InvUI/src/main/java/de/studiocode/invui/resourcepack/ForceResourcePack.java +++ b/ResourcePack/src/main/java/de/studiocode/invui/resourcepack/ForceResourcePack.java @@ -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"); } -} +} \ No newline at end of file diff --git a/InvUI/src/main/java/de/studiocode/invui/resourcepack/Icon.java b/ResourcePack/src/main/java/de/studiocode/invui/resourcepack/Icon.java similarity index 100% rename from InvUI/src/main/java/de/studiocode/invui/resourcepack/Icon.java rename to ResourcePack/src/main/java/de/studiocode/invui/resourcepack/Icon.java diff --git a/ResourcePack/src/main/java/de/studiocode/invui/resourcepack/auth/AuthenticationService.java b/ResourcePack/src/main/java/de/studiocode/invui/resourcepack/auth/AuthenticationService.java new file mode 100644 index 0000000..5da3a11 --- /dev/null +++ b/ResourcePack/src/main/java/de/studiocode/invui/resourcepack/auth/AuthenticationService.java @@ -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); + } + +} diff --git a/ResourcePack/src/main/java/de/studiocode/invui/resourcepack/auth/AuthenticationServiceManager.java b/ResourcePack/src/main/java/de/studiocode/invui/resourcepack/auth/AuthenticationServiceManager.java new file mode 100644 index 0000000..357b30d --- /dev/null +++ b/ResourcePack/src/main/java/de/studiocode/invui/resourcepack/auth/AuthenticationServiceManager.java @@ -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 services = new ArrayList<>(); + private Consumer 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 serviceClass) { + try { + if (Bukkit.getPluginManager().isPluginEnabled(pluginName)) { + Constructor 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 loginHandler) { + this.loginHandler = loginHandler; + } + + public Consumer getLoginHandler() { + return loginHandler; + } + +} diff --git a/ResourcePack/src/main/java/de/studiocode/invui/resourcepack/auth/impl/AuthMe.java b/ResourcePack/src/main/java/de/studiocode/invui/resourcepack/auth/impl/AuthMe.java new file mode 100644 index 0000000..d9587a9 --- /dev/null +++ b/ResourcePack/src/main/java/de/studiocode/invui/resourcepack/auth/impl/AuthMe.java @@ -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()); + } + +} diff --git a/pom.xml b/pom.xml index 5c365ec..6cbea83 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,7 @@ InventoryAccess/IA-R8 InventoryAccess/IA InvUI + ResourcePack @@ -76,7 +77,7 @@ - + xenondevs