[FEATURE] ClientProcessBuilder events

This commit is contained in:
Gravit 2020-04-03 17:44:25 +07:00
parent eef76a2b4e
commit 30cd1f21f0
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 24 additions and 5 deletions

View file

@ -3,8 +3,10 @@
import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.LauncherEngine;
import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.guard.LauncherGuardInterface;
import pro.gravit.launcher.guard.LauncherGuardManager;
import pro.gravit.launcher.client.events.client.ClientProcessBuilderCreateEvent;
import pro.gravit.launcher.client.events.client.ClientProcessBuilderLaunchedEvent;
import pro.gravit.launcher.client.events.client.ClientProcessBuilderParamsWrittedEvent;
import pro.gravit.launcher.client.events.client.ClientProcessBuilderPreLaunchEvent;
import pro.gravit.launcher.hasher.HashedDir;
import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.PlayerProfile;
@ -13,10 +15,7 @@
import pro.gravit.utils.Version;
import pro.gravit.utils.helper.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
@ -87,6 +86,7 @@ private void applyClientProfile()
this.jvmArgs.add("-Xmx" + params.ram + 'M');
}
this.params.session = Request.getSession();
LauncherEngine.modulesManager.invokeEvent(new ClientProcessBuilderCreateEvent(this));
}
@ -215,6 +215,7 @@ private void addModernClientArgs(Collection<String> args) {
public void start(boolean pipeOutput) throws IOException, InterruptedException {
if(isStarted) throw new IllegalStateException("Process already started");
if(LauncherEngine.guard != null) LauncherEngine.guard.applyGuardParams(this);
LauncherEngine.modulesManager.invokeEvent(new ClientProcessBuilderPreLaunchEvent(this));
List<String> processArgs = new LinkedList<>();
processArgs.add(executeFile.toString());
processArgs.addAll(jvmArgs);
@ -243,6 +244,7 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException {
processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE);
}
process = processBuilder.start();
LauncherEngine.modulesManager.invokeEvent(new ClientProcessBuilderLaunchedEvent(this));
isStarted = true;
}
public void runWriteParams(SocketAddress address) throws IOException
@ -265,6 +267,7 @@ public void runWriteParams(SocketAddress address) throws IOException
params.javaHDir.write(output);
}
}
LauncherEngine.modulesManager.invokeEvent(new ClientProcessBuilderParamsWrittedEvent(this));
}
public Process getProcess() {

View file

@ -0,0 +1,12 @@
package pro.gravit.launcher.client.events.client;
import pro.gravit.launcher.client.ClientLauncherProcess;
import pro.gravit.launcher.modules.LauncherModule;
public class ClientProcessBuilderParamsWrittedEvent extends LauncherModule.Event {
public final ClientLauncherProcess process;
public ClientProcessBuilderParamsWrittedEvent(ClientLauncherProcess process) {
this.process = process;
}
}

View file

@ -25,6 +25,10 @@ public void registerEventHandler(EventHandler handler)
{
eventHandlers.add(handler);
}
public void unregisterEventHandler(EventHandler handler)
{
eventHandlers.remove(handler);
}
public<T extends WebSocketEvent> void processEventHandlers(T event)
{
for(EventHandler handler : eventHandlers)