Refactor WildernessLocations
This commit is contained in:
@@ -28,14 +28,13 @@ public class WildernessLocationsOverlay extends Overlay
|
|||||||
private WildernessLocationsConfig wildyConfig;
|
private WildernessLocationsConfig wildyConfig;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public WildernessLocationsOverlay(Client client, WildernessLocationsPlugin plugin)
|
public WildernessLocationsOverlay(WildernessLocationsPlugin plugin)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setLayer(OverlayLayer.ABOVE_WIDGETS);
|
setLayer(OverlayLayer.ABOVE_WIDGETS);
|
||||||
setPriority(OverlayPriority.HIGH);
|
setPriority(OverlayPriority.HIGH);
|
||||||
setPosition(OverlayPosition.BOTTOM_RIGHT);
|
setPosition(OverlayPosition.BOTTOM_RIGHT);
|
||||||
textComponent = new TextComponent();
|
textComponent = new TextComponent();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,17 +6,16 @@
|
|||||||
* Written by PKLite(ST0NEWALL, others) <stonewall@thots.cc.usa>, 2019
|
* Written by PKLite(ST0NEWALL, others) <stonewall@thots.cc.usa>, 2019
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.runelite.client.plugins.wildernesslocations;
|
package net.runelite.client.plugins.wildernesslocations;
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.inject.Provides;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
@@ -34,7 +33,6 @@ import net.runelite.client.eventbus.Subscribe;
|
|||||||
import net.runelite.client.input.KeyManager;
|
import net.runelite.client.input.KeyManager;
|
||||||
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.PluginManager;
|
|
||||||
import net.runelite.client.plugins.PluginType;
|
import net.runelite.client.plugins.PluginType;
|
||||||
import net.runelite.client.ui.overlay.OverlayManager;
|
import net.runelite.client.ui.overlay.OverlayManager;
|
||||||
import net.runelite.client.util.HotkeyListener;
|
import net.runelite.client.util.HotkeyListener;
|
||||||
@@ -42,44 +40,43 @@ import net.runelite.client.util.WildernessLocation;
|
|||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Wild Locations",
|
name = "Wild Locations",
|
||||||
description = "Indicates the players current location in the wild",
|
description = "Indicates the players current location in the wild",
|
||||||
tags = {"Wildy", "Wilderness Location", "location", "loc", "pvp", "pklite"},
|
tags = {"Wildy", "Wilderness Location", "location", "loc", "pvp", "pklite"},
|
||||||
type = PluginType.PVP
|
type = PluginType.PVP
|
||||||
)
|
)
|
||||||
public class WildernessLocationsPlugin extends Plugin
|
public class WildernessLocationsPlugin extends Plugin
|
||||||
{
|
{
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
OverlayManager overlayManager;
|
OverlayManager overlayManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private WildernessLocationsOverlay overlay = new WildernessLocationsOverlay(this.client, this);
|
private WildernessLocationsOverlay overlay = new WildernessLocationsOverlay(this.client, this);
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private boolean renderLocation;
|
private boolean renderLocation;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private String locationString = "";
|
private String locationString = "";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ClientThread clientThread;
|
private ClientThread clientThread;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private WildernessLocationsConfig wildyConfig;
|
private WildernessLocationsConfig wildyConfig;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private KeyManager keyManager;
|
private KeyManager keyManager;
|
||||||
|
|
||||||
private String oldChat = "";
|
private String oldChat = "";
|
||||||
private int currentCooldown = 0;
|
private int currentCooldown = 0;
|
||||||
private final int COOLDOWN_TICKS = 30;
|
|
||||||
private WorldPoint worldPoint = null;
|
private WorldPoint worldPoint = null;
|
||||||
private final HashMap<WorldArea, String> wildLocs = getLocationMap();
|
private final HashMap<WorldArea, String> wildLocs = getLocationMap();
|
||||||
|
|
||||||
private final HotkeyListener hotkeyListener = new HotkeyListener(() -> wildyConfig.keybind())
|
private final HotkeyListener hotkeyListener = new HotkeyListener(() -> wildyConfig.keybind())
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -88,27 +85,27 @@ public class WildernessLocationsPlugin extends Plugin
|
|||||||
sendLocToCC();
|
sendLocToCC();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
WildernessLocationsConfig getConfig(ConfigManager configManager)
|
WildernessLocationsConfig getConfig(ConfigManager configManager)
|
||||||
{
|
{
|
||||||
return configManager.getConfig(WildernessLocationsConfig.class);
|
return configManager.getConfig(WildernessLocationsConfig.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
overlayManager.add(overlay);
|
overlayManager.add(overlay);
|
||||||
keyManager.registerKeyListener(hotkeyListener);
|
keyManager.registerKeyListener(hotkeyListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void shutDown() throws Exception
|
protected void shutDown() throws Exception
|
||||||
{
|
{
|
||||||
overlayManager.remove(overlay);
|
overlayManager.remove(overlay);
|
||||||
keyManager.unregisterKeyListener(hotkeyListener);
|
keyManager.unregisterKeyListener(hotkeyListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameTick(GameTick event)
|
public void onGameTick(GameTick event)
|
||||||
{
|
{
|
||||||
@@ -131,7 +128,7 @@ public class WildernessLocationsPlugin extends Plugin
|
|||||||
locationString = "";
|
locationString = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String location()
|
private String location()
|
||||||
{
|
{
|
||||||
int dist = 10000;
|
int dist = 10000;
|
||||||
@@ -140,7 +137,7 @@ public class WildernessLocationsPlugin extends Plugin
|
|||||||
for (Map.Entry<WorldArea, String> entry : wildLocs.entrySet())
|
for (Map.Entry<WorldArea, String> entry : wildLocs.entrySet())
|
||||||
{
|
{
|
||||||
WorldArea worldArea = entry.getKey();
|
WorldArea worldArea = entry.getKey();
|
||||||
|
|
||||||
if (worldArea.toWorldPointList().contains(client.getLocalPlayer().getWorldLocation()))
|
if (worldArea.toWorldPointList().contains(client.getLocalPlayer().getWorldLocation()))
|
||||||
{
|
{
|
||||||
s = entry.getValue();
|
s = entry.getValue();
|
||||||
@@ -154,7 +151,7 @@ public class WildernessLocationsPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (client.getLocalPlayer().getWorldLocation().getY() >
|
if (client.getLocalPlayer().getWorldLocation().getY() >
|
||||||
(Objects.requireNonNull(closestArea).toWorldPoint().getY() + closestArea.getHeight()))
|
(Objects.requireNonNull(closestArea).toWorldPoint().getY() + closestArea.getHeight()))
|
||||||
{
|
{
|
||||||
s = s + "N";
|
s = s + "N";
|
||||||
}
|
}
|
||||||
@@ -167,7 +164,7 @@ public class WildernessLocationsPlugin extends Plugin
|
|||||||
s = s + "W";
|
s = s + "W";
|
||||||
}
|
}
|
||||||
if (client.getLocalPlayer().getWorldLocation().getX() >
|
if (client.getLocalPlayer().getWorldLocation().getX() >
|
||||||
(closestArea.toWorldPoint().getX() + closestArea.getWidth()))
|
(closestArea.toWorldPoint().getX() + closestArea.getWidth()))
|
||||||
{
|
{
|
||||||
s = s + "E";
|
s = s + "E";
|
||||||
}
|
}
|
||||||
@@ -179,15 +176,15 @@ public class WildernessLocationsPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashMap<WorldArea, String> getLocationMap()
|
private static HashMap<WorldArea, String> getLocationMap()
|
||||||
{
|
{
|
||||||
HashMap<WorldArea, String> hashMap = new HashMap<>();
|
HashMap<WorldArea, String> hashMap = new HashMap<>();
|
||||||
Arrays.stream(WildernessLocation.values()).forEach(wildernessLocation ->
|
Arrays.stream(WildernessLocation.values()).forEach(wildernessLocation ->
|
||||||
hashMap.put(wildernessLocation.getWorldArea(), wildernessLocation.getName()));
|
hashMap.put(wildernessLocation.getWorldArea(), wildernessLocation.getName()));
|
||||||
return hashMap;
|
return hashMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onVarClientStrChanged(VarClientStrChanged varClient)
|
public void onVarClientStrChanged(VarClientStrChanged varClient)
|
||||||
{
|
{
|
||||||
@@ -197,12 +194,12 @@ public class WildernessLocationsPlugin extends Plugin
|
|||||||
oldChat = newChat;
|
oldChat = newChat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean inClanChat()
|
private boolean inClanChat()
|
||||||
{
|
{
|
||||||
return client.getWidget(WidgetInfo.CLAN_CHAT_TITLE) != null;
|
return client.getWidget(WidgetInfo.CLAN_CHAT_TITLE) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(String text)
|
private void sendMessage(String text)
|
||||||
{
|
{
|
||||||
int mode = 0;
|
int mode = 0;
|
||||||
@@ -221,7 +218,7 @@ public class WildernessLocationsPlugin extends Plugin
|
|||||||
};
|
};
|
||||||
clientThread.invoke(r);
|
clientThread.invoke(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendLocToCC()
|
private void sendLocToCC()
|
||||||
{
|
{
|
||||||
if (currentCooldown != 0)
|
if (currentCooldown != 0)
|
||||||
@@ -234,6 +231,6 @@ public class WildernessLocationsPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendMessage("/World: " + client.getWorld() + " Location: " + location);
|
sendMessage("/World: " + client.getWorld() + " Location: " + location);
|
||||||
currentCooldown = COOLDOWN_TICKS;
|
currentCooldown = 30;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user