Skip to content
Merged

2.1.7 #1647

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ project.build.group=net.runelite
project.build.version=1.12.10

glslang.path=
microbot.version=2.1.6
microbot.version=2.1.7
microbot.commit.sha=nogit
microbot.repo.url=http://138.201.81.246:8081/repository/microbot-snapshot/
microbot.repo.username=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package net.runelite.client.plugins.microbot;

import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.RuneLiteProperties;
import net.runelite.http.api.RuneLiteAPI;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;

Expand All @@ -24,12 +28,15 @@ public class MicrobotApi {

private final OkHttpClient client;
private final Gson gson;
private final String pluginTelemetryToken;

private final String microbotApiUrl = "https://microbot.cloud/api";
@Inject
MicrobotApi(OkHttpClient client, Gson gson) {
this.client = client;
this.gson = gson;

this.pluginTelemetryToken = "zeifkdsjqfiedfb15181==";
}

/**
Expand All @@ -56,6 +63,48 @@ public UUID microbotOpen() throws IOException {
}
}

/**
* Increments the install counter for the given plugin.
*
* @param internalName plugin internal name
* @param displayName display name
* @param version version installed
*/
public void increasePluginInstall(String internalName, String displayName, String version)
{
if (Strings.isNullOrEmpty(internalName)) {
return;
}

if (Strings.isNullOrEmpty(pluginTelemetryToken)) {
log.debug("Skipping plugin telemetry for {}: missing token", internalName);
return;
}

JsonObject payload = new JsonObject();
payload.addProperty("pluginName", Strings.nullToEmpty(internalName));
payload.addProperty("internalName", internalName);
payload.addProperty("pluginInternalName", internalName);
if (!Strings.isNullOrEmpty(version)) {
payload.addProperty("version", version);
payload.addProperty("pluginVersion", version);
}

Request request = new Request.Builder()
.url(microbotApiUrl + "/plugintelemetry/plugin-install/increase")
.header("X-Plugin-Telemetry-Token", pluginTelemetryToken)
.post(RequestBody.create(RuneLiteAPI.JSON, gson.toJson(payload)))
.build();

try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
log.debug("Plugin telemetry call failed for {}: HTTP {}", internalName, response.code());
}
} catch (IOException ex) {
log.debug("Plugin telemetry call failed for {}", internalName, ex);
}
}

/**
* Sends a ping request to the microbot API to update the session status.
*
Expand Down Expand Up @@ -100,4 +149,4 @@ public void microbotDelete(UUID uuid) throws IOException {

client.newCall(request).execute().close();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.runelite.client.plugins.microbot.api.boat.models;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.*;
import net.runelite.api.coords.LocalPoint;
Expand All @@ -16,6 +17,7 @@
import net.runelite.client.plugins.microbot.api.boat.data.PortTaskVarbits;
import net.runelite.client.plugins.microbot.api.player.models.Rs2PlayerModel;
import net.runelite.client.plugins.microbot.globval.enums.InterfaceTab;
import net.runelite.client.plugins.microbot.shortestpath.WorldPointUtil;
import net.runelite.client.plugins.microbot.util.gameobject.Rs2GameObject;
import net.runelite.client.plugins.microbot.util.menu.NewMenuEntry;
import net.runelite.client.plugins.microbot.util.tabs.Rs2Tab;
Expand Down Expand Up @@ -104,6 +106,7 @@ public Rs2BoatModel(WorldEntity boat)
SAILING_MOORING_GRIMSTONE
};

@Getter
private Heading currentHeading = Heading.SOUTH;


Expand Down Expand Up @@ -521,19 +524,27 @@ public void sailTo(WorldPoint target)
}
}

public int getDirection(WorldPoint target)
public int getDirection(WorldPoint target)
{
double angle = getAngle(target);
WorldPoint current = getPlayerBoatLocation();
int deltaX = target.getX() - current.getX();
int deltaY = target.getY() - current.getY();

double rotated = 270.0 - angle;
if (deltaX == 0 && deltaY == 0) {
return Heading.SOUTH.getValue();
}

rotated %= 360.0;
if (rotated < 0)
{
rotated += 360.0;
double angleDegrees = Math.toDegrees(Math.atan2(deltaY, deltaX));
double headingDegrees = (270.0 - angleDegrees + 360.0) % 360.0;
int headingValue = (int) ((headingDegrees + 11.25) / 22.5) & 0xF;

for (Heading heading : Heading.values()) {
if (heading.getValue() == headingValue) {
return heading.getValue();
}
}

return (int) Math.round(rotated / 22.5) & 0xF;
return Heading.SOUTH.getValue();
}

private double getAngle(WorldPoint target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import net.runelite.client.events.ClientShutdown;
import net.runelite.client.events.ExternalPluginsChanged;
import net.runelite.client.plugins.*;
import net.runelite.client.plugins.microbot.MicrobotApi;
import net.runelite.client.plugins.microbot.Microbot;
import net.runelite.client.plugins.microbot.util.misc.Rs2UiHelper;
import net.runelite.client.ui.SplashScreen;
Expand Down Expand Up @@ -94,6 +95,7 @@ public class MicrobotPluginManager {
private final PluginManager pluginManager;
private final Gson gson;
private final ConfigManager configManager;
private final MicrobotApi microbotApi;

private final Map<String, URLClassLoader> loaders = new ConcurrentHashMap<>();

Expand All @@ -115,7 +117,8 @@ private MicrobotPluginManager(
ScheduledExecutorService executor,
PluginManager pluginManager,
Gson gson,
ConfigManager configManager
ConfigManager configManager,
MicrobotApi microbotApi
) {
this.okHttpClient = okHttpClient;
this.microbotPluginClient = microbotPluginClient;
Expand All @@ -124,6 +127,7 @@ private MicrobotPluginManager(
this.pluginManager = pluginManager;
this.gson = gson;
this.configManager = configManager;
this.microbotApi = microbotApi;

PLUGIN_DIR.mkdirs();
}
Expand Down Expand Up @@ -1027,6 +1031,7 @@ public void install(MicrobotPluginManifest manifest, @Nullable String versionOve
if (result) {
//verifiy hash inside loadSidePlugin doesn't work
loadSideLoadPlugin(internalName);
sendPluginInstallTelemetry(manifest, versionOverride);
}

log.info("Added plugin {} to installed list", manifest.getDisplayName());
Expand Down Expand Up @@ -1096,6 +1101,16 @@ public void remove(MicrobotPluginManifest manifest) {
eventBus.post(new ExternalPluginsChanged());
}

private void sendPluginInstallTelemetry(MicrobotPluginManifest manifest, @Nullable String versionOverride)
{
if (manifest == null) {
return;
}

String version = Strings.isNullOrEmpty(versionOverride) ? manifest.getVersion() : versionOverride;
microbotApi.increasePluginInstall(manifest.getInternalName(), manifest.getDisplayName(), version);
}

/**
* Updates a plugin by redownloading and reloading it.
*
Expand Down