let extensions use passed path in CONNECTIONSTART for harble messages

This commit is contained in:
sirjonasxx 2019-01-22 18:06:54 +01:00
parent 0a7da856c2
commit 84f40ba982
3 changed files with 8 additions and 22 deletions

View File

@ -138,7 +138,8 @@ public abstract class Extension implements IExtension{
String host = packet.readString(); String host = packet.readString();
int connectionPort = packet.readInteger(); int connectionPort = packet.readInteger();
String hotelVersion = packet.readString(); String hotelVersion = packet.readString();
notifyConnectionListeners(host, connectionPort, hotelVersion); String harbleMessagesPath = packet.readString();
notifyConnectionListeners(host, connectionPort, hotelVersion, harbleMessagesPath);
onStartConnection(); onStartConnection();
} }
else if (packet.headerId() == Extensions.OUTGOING_MESSAGES_IDS.CONNECTIONEND) { else if (packet.headerId() == Extensions.OUTGOING_MESSAGES_IDS.CONNECTIONEND) {
@ -370,15 +371,15 @@ public abstract class Extension implements IExtension{
public interface OnConnectionListener { public interface OnConnectionListener {
void act(String host, int port, String hotelversion); void act(String host, int port, String hotelversion, String harbleMessagesPath);
} }
private List<OnConnectionListener> onConnectionListeners = new ArrayList<>(); private List<OnConnectionListener> onConnectionListeners = new ArrayList<>();
public void onConnect(OnConnectionListener listener){ public void onConnect(OnConnectionListener listener){
onConnectionListeners.add(listener); onConnectionListeners.add(listener);
} }
private void notifyConnectionListeners(String host, int port, String hotelversion) { private void notifyConnectionListeners(String host, int port, String hotelversion, String harbleMessagesPath) {
for (OnConnectionListener listener : onConnectionListeners) { for (OnConnectionListener listener : onConnectionListeners) {
listener.act(host, port, hotelversion); listener.act(host, port, hotelversion, harbleMessagesPath);
} }
} }

View File

@ -43,7 +43,7 @@ public class ChatConsole {
final boolean[] doOncePerConnection = {false}; final boolean[] doOncePerConnection = {false};
extension.onConnect((s, i, s1) -> doOncePerConnection[0] = true); extension.onConnect((s, i, s1, h1) -> doOncePerConnection[0] = true);
extension.intercept(HMessage.Side.TOSERVER, hMessage -> { extension.intercept(HMessage.Side.TOSERVER, hMessage -> {
// if the first packet on init is not 4000, the extension was already running, so we open the chat instantly // if the first packet on init is not 4000, the extension was already running, so we open the chat instantly

View File

@ -32,24 +32,9 @@ public class HashSupport {
public HashSupport(IExtension extension) { public HashSupport(IExtension extension) {
this.extension = extension; this.extension = extension;
boolean[] isDebug = {false}; extension.onConnect((host, port, hotelversion, cachePath) -> {
File GEarthDir = null;
try {
GEarthDir = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile();
if (!GEarthDir.getName().equals("Extensions")) { //we're probably in debugging mode / not an installed extension
//this means; no harble api is provided in our Cache
isDebug[0] = true;
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
extension.onConnect((host, port, hotelversion) -> {
// synchronized (lock) { // synchronized (lock) {
if (isDebug[0]) { harbleAPI = new HarbleAPI(hotelversion, cachePath);
HarbleAPIFetcher.fetch(hotelversion);
}
harbleAPI = new HarbleAPI(hotelversion);
// } // }
}); });