From c0a27f5cc0b84de918e3cb5f0f0bbf4ae1fe75b7 Mon Sep 17 00:00:00 2001 From: Jules Date: Sun, 27 Aug 2023 18:16:13 +0200 Subject: [PATCH] Fixed force-class-selection when using proxy-based profiles --- .../profile/ForceClassProfileDataModule.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/profile/ForceClassProfileDataModule.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/profile/ForceClassProfileDataModule.java index 5ac77ccb..43d84994 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/profile/ForceClassProfileDataModule.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/profile/ForceClassProfileDataModule.java @@ -6,11 +6,13 @@ import fr.phoenixdevt.profiles.event.ProfileCreateEvent; import fr.phoenixdevt.profiles.event.ProfileRemoveEvent; import fr.phoenixdevt.profiles.event.ProfileSelectEvent; import fr.phoenixdevt.profiles.event.ProfileUnloadEvent; -import fr.phoenixdevt.profiles.placeholder.PlaceholderRequest; +import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.event.SynchronizedDataLoadEvent; +import io.lumine.mythic.lib.comp.profile.ProfileMode; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.manager.InventoryManager; +import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -27,26 +29,23 @@ public class ForceClassProfileDataModule implements ProfileDataModule, Listener return MMOCore.plugin; } - @Override - public boolean hasPlaceholders() { - return false; - } - @Override public String getIdentifier() { return "mmocore_force_class"; } - @Override - public void processPlaceholderRequest(PlaceholderRequest placeholderRequest) { - throw new RuntimeException("Not supported"); - } - /** * Force class before profile creation */ @EventHandler public void onProfileCreate(ProfileCreateEvent event) { + + // Proxy-based profiles + if (MythicLib.plugin.getProfileMode() == ProfileMode.PROXY) { + event.validate(this); + return; + } + final PlayerData playerData = PlayerData.get(event.getPlayerData().getUniqueId()); InventoryManager.CLASS_SELECT.newInventory(playerData, () -> event.validate(this)).open(); } @@ -58,6 +57,16 @@ public class ForceClassProfileDataModule implements ProfileDataModule, Listener public void onDataLoad(SynchronizedDataLoadEvent event) { if (event.getManager().getOwningPlugin().equals(MMOCore.plugin)) { final PlayerData playerData = (PlayerData) event.getHolder(); + + // Proxy-based profiles + if (!event.hasProfileEvent()) { + Validate.isTrue(MythicLib.plugin.getProfileMode() == ProfileMode.PROXY, "Listened to a data load event with no profile event attached but proxy-based profiles are disabled"); + if (playerData.getProfess().equals(MMOCore.plugin.classManager.getDefaultClass())) + InventoryManager.CLASS_SELECT.newInventory(playerData, () -> { + }).open(); + return; + } + final ProfileSelectEvent event1 = (ProfileSelectEvent) event.getProfileEvent(); // Validate if necessary