From 6c2cc002dacb8daf9a4c31e629428111df60fbcb Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Tue, 26 Jun 2018 21:20:10 +0200 Subject: [PATCH] add extension examples --- src/main/extensions/SimpleTestExtension.java | 73 ------------------- .../extensions/examples/AdminOnConnect.java | 56 ++++++++++++++ .../extensions/examples/SpeechColorizer.java | 59 +++++++++++++++ 3 files changed, 115 insertions(+), 73 deletions(-) delete mode 100644 src/main/extensions/SimpleTestExtension.java create mode 100644 src/main/extensions/examples/AdminOnConnect.java create mode 100644 src/main/extensions/examples/SpeechColorizer.java diff --git a/src/main/extensions/SimpleTestExtension.java b/src/main/extensions/SimpleTestExtension.java deleted file mode 100644 index a405af8..0000000 --- a/src/main/extensions/SimpleTestExtension.java +++ /dev/null @@ -1,73 +0,0 @@ -package main.extensions; - -import main.protocol.HMessage; -import main.protocol.HPacket; - -/** - * Created by Jonas on 24/06/18. - */ - -/** - * - getTitle(), getDescription(), getVersion() and getAuthor() must be implemented - * - */ - - -public class SimpleTestExtension extends Extension { - - public static void main(String[] args) { - new SimpleTestExtension(args); - } - - private SimpleTestExtension(String[] args) { - super(args); - } - - @Override - protected void init() { - System.out.println("init"); - intercept(HMessage.Side.TOSERVER, 1926, this::onSendMessage); - } - - private void onSendMessage(HMessage message) { - HPacket packet = message.getPacket(); - - String watchasaid = packet.readString(); - System.out.println("you said: " + watchasaid); - - if (watchasaid.equals("blocked")) { - message.setBlocked(true); - } - - packet.replaceString(6, "@cyan@" + watchasaid); - } - - @Override - protected void onDoubleClick() { - System.out.println("doubleclick"); - } - - @Override - protected void onStartConnection() { - System.out.println("connection started"); - } - - @Override - protected void onEndConnection() { - System.out.println("connection ended"); - } - - - protected String getTitle() { - return "Simple Test!"; - } - protected String getDescription() { - return "But just for testing purpose"; - } - protected String getVersion() { - return "0.1"; - } - protected String getAuthor() { - return "sirjonasxx"; - } -} diff --git a/src/main/extensions/examples/AdminOnConnect.java b/src/main/extensions/examples/AdminOnConnect.java new file mode 100644 index 0000000..046a0f7 --- /dev/null +++ b/src/main/extensions/examples/AdminOnConnect.java @@ -0,0 +1,56 @@ +package main.extensions.examples; + +import main.extensions.Extension; +import main.protocol.HMessage; +import main.protocol.HPacket; + +/** + * Created by Jonas on 26/06/18. + */ +public class AdminOnConnect extends Extension { + + + public static void main(String[] args) { + new AdminOnConnect(args); + } + public AdminOnConnect(String[] args) { + super(args); + } + + private boolean done = true; + + protected void init() { + intercept(HMessage.Side.TOCLIENT, -1, message -> { + if (!done) { + HPacket packet = message.getPacket(); + if (packet.length() == 11) { + if (packet.readByte(14) == 0 || packet.readByte(14) == 1) { + packet.replaceInt(6, 7); + packet.replaceInt(10, 7); + packet.replaceBoolean(14, true); + + done = true; + } + } + } + }); + } + + protected void onStartConnection() { + done = false; + + } + + protected String getTitle() { + return "Always admin!"; + } + protected String getDescription() { + return "Gives you admin permission on connect"; + } + protected String getVersion() { + return "1.0"; + } + protected String getAuthor() { + return "sirjonasxx"; + } +} diff --git a/src/main/extensions/examples/SpeechColorizer.java b/src/main/extensions/examples/SpeechColorizer.java new file mode 100644 index 0000000..4458286 --- /dev/null +++ b/src/main/extensions/examples/SpeechColorizer.java @@ -0,0 +1,59 @@ +package main.extensions.examples; + +import main.extensions.Extension; +import main.protocol.HMessage; +import main.protocol.HPacket; + +import java.util.Random; + +/** + * Created by Jonas on 24/06/18. + */ + +/** + * - getTitle(), getDescription(), getVersion() and getAuthor() must be implemented + * + */ + + +public class SpeechColorizer extends Extension { + + public static void main(String[] args) { + new SpeechColorizer(args); + } + private SpeechColorizer(String[] args) { + super(args); + } + + private static final int SPEECH_ID = 1926; + private static final String[] COLORS = {"red", "blue", "cyan", "green", "purple"}; + private static final Random r = new Random(); + + @Override + protected void init() { + intercept(HMessage.Side.TOSERVER, SPEECH_ID, this::onSendMessage); + } + + private void onSendMessage(HMessage message) { + HPacket packet = message.getPacket(); + + String speechtext = packet.readString(); + System.out.println("you said: " + speechtext); + + message.setBlocked(speechtext.equals("blocked")); + packet.replaceString(6, "@" + COLORS[r.nextInt(COLORS.length)] + "@" + speechtext); + } + + protected String getTitle() { + return "Colorize me!"; + } + protected String getDescription() { + return "Because we like to be weird"; + } + protected String getVersion() { + return "1.0"; + } + protected String getAuthor() { + return "sirjonasxx"; + } +}