From 86c546adc66d61b5050667deda873681c41eef85 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Sat, 22 Sep 2018 02:30:11 +0200 Subject: [PATCH] support for installing extensions, working extensions filesystem --- src/META-INF/MANIFEST.MF | 3 + src/main/extensions/Extension.java | 20 ++-- .../extensions/examples/AdminOnConnect.java | 2 +- src/main/ui/extensions/Extensions.fxml | 2 +- src/main/ui/extensions/Extensions.java | 28 ++++- .../ui/extensions/executer/ExecutionInfo.java | 32 +++++ .../extensions/executer/ExtensionRunner.java | 18 +++ .../executer/ExtensionRunnerFactory.java | 14 +++ .../executer/NormalExtensionRunner.java | 110 ++++++++++++++++++ 9 files changed, 219 insertions(+), 10 deletions(-) create mode 100644 src/META-INF/MANIFEST.MF create mode 100644 src/main/ui/extensions/executer/ExecutionInfo.java create mode 100644 src/main/ui/extensions/executer/ExtensionRunner.java create mode 100644 src/main/ui/extensions/executer/ExtensionRunnerFactory.java create mode 100644 src/main/ui/extensions/executer/NormalExtensionRunner.java diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..1e663f8 --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: main.extensions.examples.AdminOnConnect + diff --git a/src/main/extensions/Extension.java b/src/main/extensions/Extension.java index ee236e4..9c57b87 100644 --- a/src/main/extensions/Extension.java +++ b/src/main/extensions/Extension.java @@ -4,10 +4,7 @@ import main.protocol.HMessage; import main.protocol.HPacket; import main.ui.extensions.Extensions; -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.net.Socket; import java.util.ArrayList; import java.util.HashMap; @@ -63,7 +60,15 @@ public abstract class Extension { while (!gEarthExtensionServer.isClosed()) { - int length = dIn.readInt(); + int length; + try { + length = dIn.readInt(); + } + catch(EOFException exception) { + //g-earth closed the extension + break; + } + byte[] headerandbody = new byte[length + 4]; int amountRead = 0; @@ -142,10 +147,11 @@ public abstract class Extension { } } - + System.out.println("Extension closed"); } catch (IOException | ArrayIndexOutOfBoundsException e) { - e.printStackTrace(); + System.err.println("Connection failed; is G-Earth open?"); +// e.printStackTrace(); } finally { if (gEarthExtensionServer != null && !gEarthExtensionServer.isClosed()) { diff --git a/src/main/extensions/examples/AdminOnConnect.java b/src/main/extensions/examples/AdminOnConnect.java index 2508549..11f1dde 100644 --- a/src/main/extensions/examples/AdminOnConnect.java +++ b/src/main/extensions/examples/AdminOnConnect.java @@ -20,7 +20,7 @@ public class AdminOnConnect extends Extension { private boolean done = true; protected void init() { - intercept(HMessage.Side.TOCLIENT, -1, message -> { + intercept(HMessage.Side.TOCLIENT, message -> { if (!done) { HPacket packet = message.getPacket(); if (packet.length() == 11) { diff --git a/src/main/ui/extensions/Extensions.fxml b/src/main/ui/extensions/Extensions.fxml index 153d095..b07e03e 100644 --- a/src/main/ui/extensions/Extensions.fxml +++ b/src/main/ui/extensions/Extensions.fxml @@ -83,7 +83,7 @@ -