location to cc plugin

This commit is contained in:
Kyleeld
2019-04-25 21:26:21 +01:00
parent cec8394ead
commit 7c2e71cc55
3 changed files with 270 additions and 110 deletions

View File

@@ -0,0 +1,16 @@
package net.runelite.client.plugins.locationchatter;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Keybind;
@ConfigGroup("locationchatter")
public interface LocationChatterConfig extends Config
{
@ConfigItem(keyName = "keybind", name = "Send to CC", description = "Configure button to send current location to CC")
default Keybind keybind()
{
return Keybind.NOT_SET;
}
}

View File

@@ -0,0 +1,140 @@
package net.runelite.client.plugins.locationchatter;
import com.google.inject.Provides;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.ScriptID;
import net.runelite.api.VarClientStr;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.VarClientStrChanged;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.input.KeyManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginManager;
import net.runelite.client.plugins.PluginType;
import net.runelite.client.plugins.wildernesslocations.WildernessLocationsPlugin;
import net.runelite.client.util.HotkeyListener;
import javax.inject.Inject;
@Slf4j
@PluginDescriptor(
name = "Location Chatter",
tags = {"location", "exilent", "pklite", "spammer"},
type = PluginType.UTILITY
)
public class LocationChatterPlugin extends Plugin
{
@Inject
private Client client;
@Inject
private ClientThread clientThread;
@Inject
LocationChatterConfig config;
@Inject
private KeyManager keyManager;
@Inject
private PluginManager pluginManager;
private WildernessLocationsPlugin wildyLocsPlugin;
private String oldChat = "";
private int currentCooldown = 0;
private final int COOLDOWN_TICKS = 30;
private final HotkeyListener hotkeyListener = new HotkeyListener(() -> config.keybind())
{
@Override
public void hotkeyPressed()
{
sendLocToCC();
}
};
@Override
public void startUp()
{
for (Plugin pl : pluginManager.getPlugins())
{
if (pl instanceof WildernessLocationsPlugin)
{
wildyLocsPlugin = (WildernessLocationsPlugin) pl;
}
}
keyManager.registerKeyListener(hotkeyListener);
}
@Override
public void shutDown()
{
keyManager.unregisterKeyListener(hotkeyListener);
}
@Provides
LocationChatterConfig getConfig(ConfigManager configManager)
{
return configManager.getConfig(LocationChatterConfig.class);
}
@Subscribe
public void onGameTick(GameTick tickEvent)
{
if (currentCooldown != 0)
{
currentCooldown--;
}
}
@Subscribe
public void onVarClientStrChanged(VarClientStrChanged varClient)
{
String newChat = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
if (varClient.getIndex() == VarClientStr.CHATBOX_TYPED_TEXT.getIndex() && !newChat.equals(oldChat))
{
oldChat = newChat;
}
}
private boolean inClanChat()
{
return client.getWidget(WidgetInfo.CLAN_CHAT_TITLE) != null;
}
private void sendMessage(String text)
{
int mode = 0;
if (inClanChat() && text.startsWith("/"))
{
mode = 2;
}
int finalMode = mode;
Runnable r = () ->
{
String cached = oldChat;
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, text);
client.runScript(ScriptID.CHATBOX_INPUT, finalMode, text);
oldChat = cached;
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, oldChat);
};
clientThread.invoke(r);
}
private void sendLocToCC()
{
String location = wildyLocsPlugin.getLocationString();
if (location.equals(""))
{
return;
}
sendMessage("/World: " + client.getWorld() + " Location: " + location);
currentCooldown = COOLDOWN_TICKS;
}
}

View File

@@ -1,16 +1,14 @@
package net.runelite.client.plugins.wildernesslocations; package net.runelite.client.plugins.wildernesslocations;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.Getter;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.Player;
import net.runelite.api.Varbits; import net.runelite.api.Varbits;
import net.runelite.api.coords.WorldArea; import net.runelite.api.coords.WorldArea;
import net.runelite.api.coords.WorldPoint; import net.runelite.api.coords.WorldPoint;
@@ -18,113 +16,119 @@ import net.runelite.api.events.GameTick;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginType;
import net.runelite.client.plugins.wildernesslocations.WildernessLocationsOverlay;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.WildernessLocation; import net.runelite.client.util.WildernessLocation;
@PluginDescriptor(name="PvP Wild Locations", @PluginDescriptor(
description="Indicates the players current location in the wild", name = "Wild Locations",
tags={"Wildy,", "Wilderness Location", "location", "loc", "pvp", "pklite"}, description = "Indicates the players current location in the wild",
type = PluginType.PVP tags = {"Wildy", "Wilderness Location", "location", "loc", "pvp", "pklite"}
) )
public class WildernessLocationsPlugin extends Plugin
public class WildernessLocationsPlugin extends Plugin { {
@Inject
private Client client; @Inject
@Inject private Client client;
OverlayManager overlayManager;
@Inject @Inject
private WildernessLocationsOverlay overlay; OverlayManager overlayManager;
private final HashMap<WorldArea, String> wildLocs;
private boolean renderLocation; @Inject
private String locationString; private WildernessLocationsOverlay overlay = new WildernessLocationsOverlay(this.client, this);
private WorldPoint worldPoint;
private static int UPDATE_INTERVAL = 3; private final HashMap<WorldArea, String> wildLocs = getLocationMap();
@Getter
public WildernessLocationsPlugin() { private boolean renderLocation;
overlay = new WildernessLocationsOverlay(client, this); @Getter
wildLocs = WildernessLocationsPlugin.getLocationMap(); private String locationString = "";
locationString = ""; private WorldPoint worldPoint = null;
worldPoint = null;
}
@Override
@Override protected void startUp() throws Exception
protected void startUp() throws Exception { {
overlayManager.add(overlay); overlayManager.add(overlay);
} }
@Override @Override
protected void shutDown() throws Exception { protected void shutDown() throws Exception
overlayManager.add(overlay); {
} overlayManager.remove(overlay);
}
@Subscribe
public void onGameTick(GameTick event) { @Subscribe
if (UPDATE_INTERVAL > 0) { public void onGameTick(GameTick event)
--UPDATE_INTERVAL; {
return; renderLocation = client.getVar(Varbits.IN_WILDERNESS) == 1;
} if (renderLocation)
boolean bl = renderLocation = client.getVar(Varbits.IN_WILDERNESS) == 1; {
if (renderLocation) { if (client.getLocalPlayer().getWorldLocation() != worldPoint)
if (client.getLocalPlayer().getWorldLocation() != worldPoint) { {
locationString = location(); locationString = location();
worldPoint = client.getLocalPlayer().getWorldLocation(); worldPoint = client.getLocalPlayer().getWorldLocation();
} }
} else { }
worldPoint = null; else
locationString = ""; {
} worldPoint = null;
UPDATE_INTERVAL = 3; locationString = "";
} }
}
private String location() {
int dist = 10000;
String s = ""; private String location()
WorldArea closestArea = null; {
for (Map.Entry<WorldArea, String> entry : wildLocs.entrySet()) { int dist = 10000;
WorldArea worldArea = entry.getKey(); String s = "";
if (worldArea.toWorldPointList().contains(client.getLocalPlayer().getWorldLocation())) { WorldArea closestArea = null;
s = entry.getValue(); for (Map.Entry<WorldArea, String> entry : wildLocs.entrySet())
return s; {
} WorldArea worldArea = entry.getKey();
int distTo = worldArea.distanceTo(client.getLocalPlayer().getWorldLocation());
if (distTo >= dist) continue; if (worldArea.toWorldPointList().contains(client.getLocalPlayer().getWorldLocation()))
dist = distTo; {
closestArea = worldArea; s = entry.getValue();
} return s;
if (client.getLocalPlayer().getWorldLocation().getY() > ((WorldArea)Objects.requireNonNull(closestArea)).toWorldPoint().getY() + closestArea.getHeight()) { }
s = s + "N"; int distTo = worldArea.distanceTo(client.getLocalPlayer().getWorldLocation());
} if (distTo < dist)
if (client.getLocalPlayer().getWorldLocation().getY() < closestArea.toWorldPoint().getY()) { {
s = s + "S"; dist = distTo;
} closestArea = worldArea;
if (client.getLocalPlayer().getWorldLocation().getX() < closestArea.toWorldPoint().getX()) { }
s = s + "W"; }
} if (client.getLocalPlayer().getWorldLocation().getY() >
if (client.getLocalPlayer().getWorldLocation().getX() > closestArea.toWorldPoint().getX() + closestArea.getWidth()) { (Objects.requireNonNull(closestArea).toWorldPoint().getY() + closestArea.getHeight()))
s = s + "E"; {
} s = s + "N";
s = s + " of "; }
if ((s = s + wildLocs.get(closestArea)).startsWith(" of ")) { if (client.getLocalPlayer().getWorldLocation().getY() < closestArea.toWorldPoint().getY())
s = s.substring(3); {
} s = s + "S";
return s; }
} if (client.getLocalPlayer().getWorldLocation().getX() < closestArea.toWorldPoint().getX())
{
private static HashMap<WorldArea, String> getLocationMap() { s = s + "W";
HashMap<WorldArea, String> hashMap = new HashMap<WorldArea, String>(); }
Arrays.stream(WildernessLocation.values()).forEach(wildernessLocation -> hashMap.put(wildernessLocation.getWorldArea(), wildernessLocation.getName())); if (client.getLocalPlayer().getWorldLocation().getX() >
return hashMap; (closestArea.toWorldPoint().getX() + closestArea.getWidth()))
} {
s = s + "E";
public boolean isRenderLocation() { }
return renderLocation; s = s + " of ";
} s = s + wildLocs.get(closestArea);
if (s.startsWith(" of "))
public String getLocationString() { {
return locationString; s = s.substring(3);
} }
return s;
}
private static HashMap<WorldArea, String> getLocationMap()
{
HashMap<WorldArea, String> hashMap = new HashMap<>();
Arrays.stream(WildernessLocation.values()).forEach(wildernessLocation ->
hashMap.put(wildernessLocation.getWorldArea(), wildernessLocation.getName()));
return hashMap;
}
} }