Search through plugin classloaders when loading accounts
Some checks are pending
build-docker / build (push) Waiting to run
build / build (push) Waiting to run

This commit is contained in:
RaphiMC 2024-11-03 20:50:48 +01:00
parent 197f9dd256
commit 83ab4b8079
No known key found for this signature in database
GPG key ID: 0F6BB0657A03AC94

View file

@ -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);
}