From 83ab4b80791fb2061b8779612e29d69324f0bd02 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Sun, 3 Nov 2024 20:50:48 +0100 Subject: [PATCH] Search through plugin classloaders when loading accounts --- .../viaproxy/saves/impl/AccountsSaveV3.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/raphimc/viaproxy/saves/impl/AccountsSaveV3.java b/src/main/java/net/raphimc/viaproxy/saves/impl/AccountsSaveV3.java index e27a7c5..86d87ff 100644 --- a/src/main/java/net/raphimc/viaproxy/saves/impl/AccountsSaveV3.java +++ b/src/main/java/net/raphimc/viaproxy/saves/impl/AccountsSaveV3.java @@ -20,7 +20,9 @@ package net.raphimc.viaproxy.saves.impl; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.lenni0451.reflect.Classes; import net.raphimc.viaproxy.ViaProxy; +import net.raphimc.viaproxy.plugins.ViaProxyPlugin; import net.raphimc.viaproxy.saves.AbstractSave; import net.raphimc.viaproxy.saves.impl.accounts.Account; import net.raphimc.viaproxy.saves.impl.accounts.OfflineAccount; @@ -43,7 +45,19 @@ public class AccountsSaveV3 extends AbstractSave { for (JsonElement element : jsonElement.getAsJsonArray()) { final JsonObject jsonObject = element.getAsJsonObject(); final String type = jsonObject.get("accountType").getAsString(); - final Class clazz = Class.forName(type); + Class clazz = Classes.byName(type); + if (clazz == null) { + for (ViaProxyPlugin plugin : ViaProxy.getPluginManager().getPlugins()) { + clazz = Classes.byName(type, plugin.getClass().getClassLoader()); + if (clazz != null) { + break; + } + } + } + if (clazz == null) { + throw new ClassNotFoundException(type); + } + final Account account = (Account) clazz.getConstructor(JsonObject.class).newInstance(jsonObject); this.accounts.add(account); }