Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.plugins.events;

import net.raphimc.viaproxy.plugins.events.types.EventCancellable;
import net.raphimc.viaproxy.ui.UITab;
import net.raphimc.viaproxy.ui.ViaProxyWindow;

public class UITabInitializeEvent extends EventCancellable {

private final ViaProxyWindow window;
private UITab tab;

public UITabInitializeEvent(ViaProxyWindow window, UITab tab) {
this.window = window;
this.tab = tab;
}

public ViaProxyWindow getWindow() {
return window;
}

public UITab getTab() {
return tab;
}

public void setTab(UITab tab) {
this.tab = tab;
}
}
23 changes: 19 additions & 4 deletions src/main/java/net/raphimc/viaproxy/saves/impl/AccountsSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
public class AccountsSave extends AbstractSave {

private final List<Account> accounts = new ArrayList<>();
private final List<JsonObject> unknownAccounts = new ArrayList<>();

public AccountsSave() {
super("accountsV4");
Expand All @@ -48,17 +49,30 @@ public void load(JsonElement jsonElement) throws Exception {

this.accounts.clear();
for (JsonElement element : jsonElement.getAsJsonArray()) {
JsonObject jsonObject = null;
try {
final JsonObject jsonObject = element.getAsJsonObject();
final String type = jsonObject.get("accountType").getAsString();
jsonObject = element.getAsJsonObject();
if (!jsonObject.has("accountType")) {
Logger.LOGGER.error("Failed to load an account, missing accountType");
continue;
}

String type = jsonObject.get("accountType").getAsString();
final Class<?> clazz = Classes.find(type, true, classLoaders);

final Account account = (Account) clazz.getConstructor(JsonObject.class).newInstance(jsonObject);
this.accounts.add(account);
} catch (Throwable e) {
Logger.LOGGER.error("Failed to load an account", e);
} catch (Throwable t) {
if (t instanceof ClassNotFoundException classNotFoundException) {
Logger.LOGGER.error("Failed to load an account, unknown accountType: " + classNotFoundException.getMessage());
this.unknownAccounts.add(jsonObject);
continue;
}

Logger.LOGGER.error("Failed to load an account", t);
}
}
Logger.LOGGER.info("Loaded " + this.accounts.size() + " accounts, " + this.unknownAccounts.size() + " unknown accounts");
}

@Override
Expand All @@ -69,6 +83,7 @@ public JsonElement save() {
jsonObject.addProperty("accountType", account.getClass().getName());
array.add(jsonObject);
}
this.unknownAccounts.forEach(array::add);
return array;
}

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/net/raphimc/viaproxy/ui/ViaProxyWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.lenni0451.reflect.JavaBypass;
import net.lenni0451.reflect.stream.RStream;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.plugins.events.UITabInitializeEvent;
import net.raphimc.viaproxy.ui.events.UICloseEvent;
import net.raphimc.viaproxy.ui.impl.*;
import net.raphimc.viaproxy.util.logging.Logger;
Expand Down Expand Up @@ -111,8 +112,17 @@ private void initTabs() {
.fields()
.filter(field -> UITab.class.isAssignableFrom(field.type()))
.forEach(field -> {
final UITab tab = field.get();
this.tabs.add(field.get());
UITab tab = field.get();

UITabInitializeEvent event = ViaProxy.EVENT_MANAGER.call(new UITabInitializeEvent(ViaProxyWindow.this, tab));
if (event.isCancelled())
return;

tab = event.getTab();
if (tab == null)
throw new IllegalStateException("UITabInitializeEvent returned null tab");

this.tabs.add(tab);
tab.add(this.contentPane);
this.eventManager.register(tab);
});
Expand Down