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