add extension examples

This commit is contained in:
sirjonasxx 2018-06-26 21:20:10 +02:00
parent 10ab716789
commit 6c2cc002da
3 changed files with 115 additions and 73 deletions

View File

@ -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";
}
}

View File

@ -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";
}
}

View File

@ -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";
}
}