From bbbf872b4ffac95fe16308013b3447775a688209 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Sat, 22 Sep 2018 18:30:32 +0200 Subject: [PATCH] ExtensionForm development --- src/META-INF/MANIFEST.MF | 2 +- src/main/extensions/Extension.java | 17 ++- src/main/extensions/ExtensionForm.java | 134 ++++++++++++++++++ src/main/extensions/FXApplication.java | 58 ++++++++ .../{ => adminonconnect}/AdminOnConnect.java | 2 +- .../BlockAndReplacePackets.java | 48 +++++++ .../blockreplacepackets/blockreplace.fxml | 36 +++++ .../SpeechColorizer.java | 2 +- src/main/extensions/extra/Inspector.java | 7 + .../ui/extensions/ExtensionItemContainer.java | 3 + 10 files changed, 302 insertions(+), 7 deletions(-) create mode 100644 src/main/extensions/ExtensionForm.java create mode 100644 src/main/extensions/FXApplication.java rename src/main/extensions/examples/{ => adminonconnect}/AdminOnConnect.java (96%) create mode 100644 src/main/extensions/examples/blockreplacepackets/BlockAndReplacePackets.java create mode 100644 src/main/extensions/examples/blockreplacepackets/blockreplace.fxml rename src/main/extensions/examples/{ => speechcolorizer}/SpeechColorizer.java (96%) create mode 100644 src/main/extensions/extra/Inspector.java diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF index 1e663f8..889dc56 100644 --- a/src/META-INF/MANIFEST.MF +++ b/src/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ Manifest-Version: 1.0 -Main-Class: main.extensions.examples.AdminOnConnect +Main-Class: main.extensions.examples.adminonconnect.AdminOnConnect diff --git a/src/main/extensions/Extension.java b/src/main/extensions/Extension.java index 5aea3a3..89aeb25 100644 --- a/src/main/extensions/Extension.java +++ b/src/main/extensions/Extension.java @@ -258,11 +258,20 @@ public abstract class Extension { private boolean isOnClickMethodUsed() { - try { - return !getClass().getDeclaredMethod("onClick").getDeclaringClass().equals(Extension.class); - } catch (NoSuchMethodException e) { -// e.printStackTrace(); + Class c = getClass(); + + while (c != Extension.class) { + try { + c.getDeclaredMethod("onClick"); + // if it didnt error, onClick exists + return true; + } catch (NoSuchMethodException e) { +// e.printStackTrace(); + } + + c = (Class) c.getSuperclass(); } + return false; } diff --git a/src/main/extensions/ExtensionForm.java b/src/main/extensions/ExtensionForm.java new file mode 100644 index 0000000..88055a0 --- /dev/null +++ b/src/main/extensions/ExtensionForm.java @@ -0,0 +1,134 @@ +package main.extensions; + +import javafx.application.Application; +import javafx.application.Platform; +import javafx.event.EventHandler; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.stage.Stage; +import javafx.stage.WindowEvent; +import main.protocol.HMessage; +import main.protocol.HPacket; +import main.ui.GEarthController; + +import java.net.URL; + +/** + * Created by Jonas on 22/09/18. + */ +public abstract class ExtensionForm extends Application { + + private Extension extension = null; + protected static String[] args; + private volatile Stage primaryStage = null; + + @Override + public void start(Stage primaryStage) throws Exception { + Platform.setImplicitExit(false); + setStageData(primaryStage); + this.primaryStage = primaryStage; + primaryStage.setOnCloseRequest(event -> { + event.consume(); + Platform.runLater(primaryStage::hide); + }); + ExtensionForm thiss = this; + Thread t = new Thread(() -> { + extension = new Extension(args) { + @Override + protected String getTitle() { + return thiss.getTitle(); + } + + @Override + protected String getDescription() { + return thiss.getDescription(); + } + + @Override + protected String getVersion() { + return thiss.getVersion(); + } + + @Override + protected String getAuthor() { + return thiss.getAuthor(); + } + + @Override + protected void init() { + thiss.initExtension(); + } + + @Override + protected void onClick() { + thiss.onClick(); + } + + @Override + protected void onStartConnection() { + thiss.onStartConnection(); + } + + @Override + protected void onEndConnection() { + thiss.onEndConnection(); + } + }; + Platform.runLater(primaryStage::close); + }); + t.start(); + } + + public abstract void setStageData(Stage primaryStage) throws Exception; + + protected boolean requestFlags(Extension.FlagsCheckListener flagRequestCallback){ + return extension.requestFlags(flagRequestCallback); + } + protected void writeToConsole(String s) { + extension.writeToConsole(s); + } + protected void intercept(HMessage.Side side, Extension.MessageListener messageListener) { + extension.intercept(side, messageListener); + } + protected void intercept(HMessage.Side side, int headerId, Extension.MessageListener messageListener){ + extension.intercept(side, headerId, messageListener); + } + protected boolean sendToServer(HPacket packet){ + return extension.sendToServer(packet); + } + protected boolean sendToClient(HPacket packet){ + return extension.sendToClient(packet); + } + + + /** + * Gets called when a connection has been established with G-Earth. + * This does not imply a connection with Habbo is setup. + */ + protected void initExtension(){} + + /** + * The application got doubleclicked from the G-Earth interface. Doing something here is optional + */ + private void onClick(){ + Platform.runLater(() -> { + primaryStage.show(); + }); + } + + /** + * A connection with Habbo has been started + */ + protected void onStartConnection(){} + + /** + * A connection with Habbo has ended + */ + protected void onEndConnection(){} + + protected abstract String getTitle(); + protected abstract String getDescription(); + protected abstract String getVersion(); + protected abstract String getAuthor(); + +} diff --git a/src/main/extensions/FXApplication.java b/src/main/extensions/FXApplication.java new file mode 100644 index 0000000..6d2f030 --- /dev/null +++ b/src/main/extensions/FXApplication.java @@ -0,0 +1,58 @@ +package main.extensions; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.stage.Stage; + +import java.net.URL; + +/** + * Created by Jonas on 22/09/18. + */ +public class FXApplication extends Application { + + public interface InitStage { + void callback(Stage primaryStage, Parent root); + } + private InitStage initStage; + private URL layoutLocation; + private boolean[] isOpen = {false}; + + public FXApplication(URL layoutLocation, InitStage initStage) { + super(); + + this.layoutLocation = layoutLocation; + this.initStage = initStage; + } + + @Override + public void start(Stage primaryStage) throws Exception { + FXMLLoader loader = new FXMLLoader(layoutLocation); + Parent root = loader.load(); + + initStage.callback(primaryStage, root); + primaryStage.show(); + + primaryStage.setOnCloseRequest(event -> isOpen[0] = false); + isOpen[0] = true; + } + + @Override + public void stop() throws Exception { + super.stop(); + + isOpen[0] = false; + } + + public boolean isOpen() { + return isOpen[0]; + } + + public void open() { + if (!isOpen()) { + launch(); + } + } + +} diff --git a/src/main/extensions/examples/AdminOnConnect.java b/src/main/extensions/examples/adminonconnect/AdminOnConnect.java similarity index 96% rename from src/main/extensions/examples/AdminOnConnect.java rename to src/main/extensions/examples/adminonconnect/AdminOnConnect.java index 5ac4c53..a1e4c89 100644 --- a/src/main/extensions/examples/AdminOnConnect.java +++ b/src/main/extensions/examples/adminonconnect/AdminOnConnect.java @@ -1,4 +1,4 @@ -package main.extensions.examples; +package main.extensions.examples.adminonconnect; import main.extensions.Extension; import main.protocol.HMessage; diff --git a/src/main/extensions/examples/blockreplacepackets/BlockAndReplacePackets.java b/src/main/extensions/examples/blockreplacepackets/BlockAndReplacePackets.java new file mode 100644 index 0000000..1bd0c13 --- /dev/null +++ b/src/main/extensions/examples/blockreplacepackets/BlockAndReplacePackets.java @@ -0,0 +1,48 @@ +package main.extensions.examples.blockreplacepackets; + +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; +import main.extensions.ExtensionForm; +import main.ui.GEarthController; + +import java.net.URL; + +/** + * Created by Jonas on 22/09/18. + */ +public class BlockAndReplacePackets extends ExtensionForm { + + public static void main(String[] args) { + ExtensionForm.args = args; + launch(args); + } + + @Override + protected void initExtension() { + + } + + @Override + public void setStageData(Stage primaryStage) throws Exception { + FXMLLoader loader = new FXMLLoader(BlockAndReplacePackets.class.getResource("blockreplace.fxml")); + Parent root = loader.load(); + + primaryStage.setTitle("Packet blocker and replacer"); + primaryStage.setScene(new Scene(root, 565, 262)); + } + + protected String getTitle() { + return "iManipulate"; + } + protected String getDescription() { + return "Block &/ replace packets"; + } + protected String getVersion() { + return "0.1"; + } + protected String getAuthor() { + return "sirjonasxx"; + } +} diff --git a/src/main/extensions/examples/blockreplacepackets/blockreplace.fxml b/src/main/extensions/examples/blockreplacepackets/blockreplace.fxml new file mode 100644 index 0000000..917179b --- /dev/null +++ b/src/main/extensions/examples/blockreplacepackets/blockreplace.fxml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/extensions/examples/SpeechColorizer.java b/src/main/extensions/examples/speechcolorizer/SpeechColorizer.java similarity index 96% rename from src/main/extensions/examples/SpeechColorizer.java rename to src/main/extensions/examples/speechcolorizer/SpeechColorizer.java index 5ff340f..9d3bab7 100644 --- a/src/main/extensions/examples/SpeechColorizer.java +++ b/src/main/extensions/examples/speechcolorizer/SpeechColorizer.java @@ -1,4 +1,4 @@ -package main.extensions.examples; +package main.extensions.examples.speechcolorizer; import main.extensions.Extension; import main.protocol.HMessage; diff --git a/src/main/extensions/extra/Inspector.java b/src/main/extensions/extra/Inspector.java new file mode 100644 index 0000000..6da0308 --- /dev/null +++ b/src/main/extensions/extra/Inspector.java @@ -0,0 +1,7 @@ +package main.extensions.extra; + +/** + * Created by Jonas on 22/09/18. + */ +public class Inspector { +} diff --git a/src/main/ui/extensions/ExtensionItemContainer.java b/src/main/ui/extensions/ExtensionItemContainer.java index 56f3263..7a7549c 100644 --- a/src/main/ui/extensions/ExtensionItemContainer.java +++ b/src/main/ui/extensions/ExtensionItemContainer.java @@ -4,6 +4,7 @@ import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.Label; import javafx.scene.control.ScrollPane; +import javafx.scene.control.Tooltip; import javafx.scene.input.MouseEvent; import javafx.scene.layout.*; import javafx.scene.text.Font; @@ -66,6 +67,8 @@ public class ExtensionItemContainer extends GridPane { DeleteButton deleteButton = new DeleteButton(); + Tooltip delete = new Tooltip("Close connection with this extension"); + Tooltip.install(deleteButton,delete); deleteButton.show(); deleteButton.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> item.isRemoveClickTrigger()); SimpleClickButton clickButton = new SimpleClickButton();