From 1cb01789a9b0035eb03f6ec0e37afc7b063df1a6 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Sat, 22 Apr 2023 20:30:59 +0200 Subject: [PATCH] Added new events --- .../java/net/raphimc/viaproxy/ViaProxy.java | 7 +++++++ .../plugins/events/ProxyStartEvent.java | 21 +++++++++++++++++++ .../plugins/events/ProxyStopEvent.java | 21 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 src/main/java/net/raphimc/viaproxy/plugins/events/ProxyStartEvent.java create mode 100644 src/main/java/net/raphimc/viaproxy/plugins/events/ProxyStopEvent.java diff --git a/src/main/java/net/raphimc/viaproxy/ViaProxy.java b/src/main/java/net/raphimc/viaproxy/ViaProxy.java index ea70c4f..d0c97a0 100644 --- a/src/main/java/net/raphimc/viaproxy/ViaProxy.java +++ b/src/main/java/net/raphimc/viaproxy/ViaProxy.java @@ -38,6 +38,8 @@ import net.raphimc.viaproxy.cli.options.Options; import net.raphimc.viaproxy.injection.Java17ToJava8; import net.raphimc.viaproxy.plugins.PluginManager; import net.raphimc.viaproxy.plugins.events.Client2ProxyHandlerCreationEvent; +import net.raphimc.viaproxy.plugins.events.ProxyStartEvent; +import net.raphimc.viaproxy.plugins.events.ProxyStopEvent; import net.raphimc.viaproxy.proxy.EventListener; import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyChannelInitializer; import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyHandler; @@ -165,6 +167,9 @@ public class ViaProxy { throw new IllegalStateException("Proxy is already running"); } try { + Logger.LOGGER.info("Starting proxy server"); + PluginManager.EVENT_MANAGER.call(new ProxyStartEvent()); + currentProxyServer = new NetServer(() -> PluginManager.EVENT_MANAGER.call(new Client2ProxyHandlerCreationEvent(new Client2ProxyHandler())).getHandler(), Client2ProxyChannelInitializer::new); Logger.LOGGER.info("Binding proxy server to " + Options.BIND_ADDRESS + ":" + Options.BIND_PORT); currentProxyServer.bind(Options.BIND_ADDRESS, Options.BIND_PORT, false); @@ -177,6 +182,8 @@ public class ViaProxy { public static void stopProxy() { if (currentProxyServer != null) { Logger.LOGGER.info("Stopping proxy server"); + PluginManager.EVENT_MANAGER.call(new ProxyStopEvent()); + currentProxyServer.getChannel().close(); currentProxyServer = null; diff --git a/src/main/java/net/raphimc/viaproxy/plugins/events/ProxyStartEvent.java b/src/main/java/net/raphimc/viaproxy/plugins/events/ProxyStartEvent.java new file mode 100644 index 0000000..854837b --- /dev/null +++ b/src/main/java/net/raphimc/viaproxy/plugins/events/ProxyStartEvent.java @@ -0,0 +1,21 @@ +/* + * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy + * Copyright (C) 2023 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 . + */ +package net.raphimc.viaproxy.plugins.events; + +public class ProxyStartEvent { +} diff --git a/src/main/java/net/raphimc/viaproxy/plugins/events/ProxyStopEvent.java b/src/main/java/net/raphimc/viaproxy/plugins/events/ProxyStopEvent.java new file mode 100644 index 0000000..46703dd --- /dev/null +++ b/src/main/java/net/raphimc/viaproxy/plugins/events/ProxyStopEvent.java @@ -0,0 +1,21 @@ +/* + * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy + * Copyright (C) 2023 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 . + */ +package net.raphimc.viaproxy.plugins.events; + +public class ProxyStopEvent { +}