mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-27 02:40:51 +01:00
add documentation to the abstract Extension class it's methods
This commit is contained in:
parent
2c80e2f2c9
commit
10ab716789
@ -2,7 +2,6 @@ package main.extensions;
|
|||||||
|
|
||||||
import main.protocol.HMessage;
|
import main.protocol.HMessage;
|
||||||
import main.protocol.HPacket;
|
import main.protocol.HPacket;
|
||||||
import main.protocol.packethandler.PayloadBuffer;
|
|
||||||
import main.ui.extensions.Extensions;
|
import main.ui.extensions.Extensions;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
@ -36,7 +35,10 @@ public abstract class Extension {
|
|||||||
private FlagsCheckListener flagRequestCallback = null;
|
private FlagsCheckListener flagRequestCallback = null;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes the connection with G-Earth, pass the arguments given in the Main method "super(args)"
|
||||||
|
* @param args arguments
|
||||||
|
*/
|
||||||
public Extension(String[] args) {
|
public Extension(String[] args) {
|
||||||
//obtain port
|
//obtain port
|
||||||
int port = 0;
|
int port = 0;
|
||||||
@ -51,11 +53,6 @@ public abstract class Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HPacket lastwrapper = null;
|
|
||||||
HMessage lastM = null;
|
|
||||||
HPacket last = null;
|
|
||||||
|
|
||||||
|
|
||||||
Socket gEarthExtensionServer = null;
|
Socket gEarthExtensionServer = null;
|
||||||
try {
|
try {
|
||||||
gEarthExtensionServer = new Socket("localhost", port);
|
gEarthExtensionServer = new Socket("localhost", port);
|
||||||
@ -167,10 +164,20 @@ public abstract class Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//methods returns if succeed
|
/**
|
||||||
|
* Send a message to the client
|
||||||
|
* @param packet packet to be sent
|
||||||
|
* @return success or failure
|
||||||
|
*/
|
||||||
protected boolean sendToClient(HPacket packet) {
|
protected boolean sendToClient(HPacket packet) {
|
||||||
return send(packet, HMessage.Side.TOCLIENT);
|
return send(packet, HMessage.Side.TOCLIENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a message to the server
|
||||||
|
* @param packet packet to be sent
|
||||||
|
* @return success or failure
|
||||||
|
*/
|
||||||
protected boolean sendToServer(HPacket packet) {
|
protected boolean sendToServer(HPacket packet) {
|
||||||
return send(packet, HMessage.Side.TOSERVER);
|
return send(packet, HMessage.Side.TOSERVER);
|
||||||
}
|
}
|
||||||
@ -187,6 +194,12 @@ public abstract class Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a listener on a specific packet Type
|
||||||
|
* @param side ToClient or ToServer
|
||||||
|
* @param headerId the packet header ID
|
||||||
|
* @param messageListener the callback
|
||||||
|
*/
|
||||||
protected void intercept(HMessage.Side side, int headerId, MessageListener messageListener) {
|
protected void intercept(HMessage.Side side, int headerId, MessageListener messageListener) {
|
||||||
Map<Integer, List<MessageListener>> listeners =
|
Map<Integer, List<MessageListener>> listeners =
|
||||||
side == HMessage.Side.TOCLIENT ?
|
side == HMessage.Side.TOCLIENT ?
|
||||||
@ -199,17 +212,32 @@ public abstract class Extension {
|
|||||||
|
|
||||||
listeners.get(headerId).add(messageListener);
|
listeners.get(headerId).add(messageListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a listener on all packets
|
||||||
|
* @param side ToClient or ToServer
|
||||||
|
* @param messageListener the callback
|
||||||
|
*/
|
||||||
protected void intercept(HMessage.Side side, MessageListener messageListener) {
|
protected void intercept(HMessage.Side side, MessageListener messageListener) {
|
||||||
intercept(side, -1, messageListener);
|
intercept(side, -1, messageListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns "false" if another flag requester was busy
|
/**
|
||||||
|
* Requests the flags which have been given to G-Earth when it got executed
|
||||||
|
* For example, you might want this extension to do a specific thing if the flag "-e" was given
|
||||||
|
* @param flagRequestCallback callback
|
||||||
|
* @return if the request was successful, will return false if another flagrequest is busy
|
||||||
|
*/
|
||||||
protected boolean requestFlags(FlagsCheckListener flagRequestCallback) {
|
protected boolean requestFlags(FlagsCheckListener flagRequestCallback) {
|
||||||
if (this.flagRequestCallback != null) return false;
|
if (this.flagRequestCallback != null) return false;
|
||||||
this.flagRequestCallback = flagRequestCallback;
|
this.flagRequestCallback = flagRequestCallback;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write to the console in G-Earth
|
||||||
|
* @param s the text to be written
|
||||||
|
*/
|
||||||
protected void writeToConsole(String s) {
|
protected void writeToConsole(String s) {
|
||||||
HPacket packet = new HPacket(Extensions.INCOMING_MESSAGES_IDS.EXTENSIONCONSOLELOG);
|
HPacket packet = new HPacket(Extensions.INCOMING_MESSAGES_IDS.EXTENSIONCONSOLELOG);
|
||||||
packet.appendString(s);
|
packet.appendString(s);
|
||||||
@ -220,11 +248,27 @@ public abstract class Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// All methods under here block the stream, use threads if needed.
|
|
||||||
protected abstract void init();
|
/**
|
||||||
protected abstract void onDoubleClick();
|
* Gets called when a connection has been established with G-Earth.
|
||||||
protected abstract void onStartConnection();
|
* This does not imply a connection with Habbo is setup.
|
||||||
protected abstract void onEndConnection();
|
*/
|
||||||
|
protected void init(){}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application got doubleclicked from the G-Earth interface. Doing something here is optional
|
||||||
|
*/
|
||||||
|
protected void onDoubleClick(){}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 getTitle();
|
||||||
protected abstract String getDescription();
|
protected abstract String getDescription();
|
||||||
|
@ -6,6 +6,13 @@ import main.protocol.HPacket;
|
|||||||
/**
|
/**
|
||||||
* Created by Jonas on 24/06/18.
|
* Created by Jonas on 24/06/18.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* - getTitle(), getDescription(), getVersion() and getAuthor() must be implemented
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class SimpleTestExtension extends Extension {
|
public class SimpleTestExtension extends Extension {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -19,7 +26,6 @@ public class SimpleTestExtension extends Extension {
|
|||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
System.out.println("init");
|
System.out.println("init");
|
||||||
|
|
||||||
intercept(HMessage.Side.TOSERVER, 1926, this::onSendMessage);
|
intercept(HMessage.Side.TOSERVER, 1926, this::onSendMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +33,6 @@ public class SimpleTestExtension extends Extension {
|
|||||||
HPacket packet = message.getPacket();
|
HPacket packet = message.getPacket();
|
||||||
|
|
||||||
String watchasaid = packet.readString();
|
String watchasaid = packet.readString();
|
||||||
|
|
||||||
System.out.println("you said: " + watchasaid);
|
System.out.println("you said: " + watchasaid);
|
||||||
|
|
||||||
if (watchasaid.equals("blocked")) {
|
if (watchasaid.equals("blocked")) {
|
||||||
@ -52,22 +57,16 @@ public class SimpleTestExtension extends Extension {
|
|||||||
System.out.println("connection ended");
|
System.out.println("connection ended");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getTitle() {
|
protected String getTitle() {
|
||||||
return "Simple Test!";
|
return "Simple Test!";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getDescription() {
|
protected String getDescription() {
|
||||||
return "But just for testing purpose";
|
return "But just for testing purpose";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getVersion() {
|
protected String getVersion() {
|
||||||
return "0.1";
|
return "0.1";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getAuthor() {
|
protected String getAuthor() {
|
||||||
return "sirjonasxx";
|
return "sirjonasxx";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user