mlm plugin: rewrite to use events
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2018, Seth <Sethtroll3@gmail.com>
|
||||
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2018, Seth <Sethtroll3@gmail.com>
|
||||
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -24,21 +24,15 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.motherlode;
|
||||
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.components.PanelComponent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import com.google.common.collect.Sets;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_ADAMANT;
|
||||
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_BLACK;
|
||||
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_BRONZE;
|
||||
@@ -49,11 +43,14 @@ import static net.runelite.api.AnimationID.MINING_MOTHERLODE_IRON;
|
||||
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_MITHRIL;
|
||||
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_RUNE;
|
||||
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_STEEL;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.components.PanelComponent;
|
||||
|
||||
class MotherlodeOverlay extends Overlay
|
||||
{
|
||||
private static final List<Integer> MINING_ANIMATION_IDS = Arrays.asList
|
||||
(
|
||||
private static final Set<Integer> MINING_ANIMATION_IDS = Sets.newHashSet(
|
||||
MINING_MOTHERLODE_BRONZE, MINING_MOTHERLODE_IRON, MINING_MOTHERLODE_STEEL,
|
||||
MINING_MOTHERLODE_BLACK, MINING_MOTHERLODE_MITHRIL, MINING_MOTHERLODE_ADAMANT,
|
||||
MINING_MOTHERLODE_RUNE, MINING_MOTHERLODE_DRAGON, MINING_MOTHERLODE_DRAGON_ORN,
|
||||
@@ -111,16 +108,15 @@ class MotherlodeOverlay extends Overlay
|
||||
}
|
||||
|
||||
panelComponent.getLines().add(new PanelComponent.Line(
|
||||
"Pay-dirt mined:",
|
||||
Integer.toString(session.getTotalMined())
|
||||
"Pay-dirt mined:",
|
||||
Integer.toString(session.getTotalMined())
|
||||
));
|
||||
|
||||
|
||||
panelComponent.getLines().add(new PanelComponent.Line(
|
||||
"Pay-dirt/hr:",
|
||||
session.getRecentMined() > 2
|
||||
? Integer.toString(session.getPerHour())
|
||||
: ""
|
||||
"Pay-dirt/hr:",
|
||||
session.getRecentMined() > 2
|
||||
? Integer.toString(session.getPerHour())
|
||||
: ""
|
||||
));
|
||||
|
||||
return panelComponent.render(graphics, parent);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2018, Seth <Sethtroll3@gmail.com>
|
||||
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -24,32 +25,54 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.motherlode;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Provides;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.task.Schedule;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.inject.Inject;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.inject.Inject;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.GameObject;
|
||||
import net.runelite.api.GameState;
|
||||
import static net.runelite.api.ObjectID.ORE_VEIN_26661;
|
||||
import static net.runelite.api.ObjectID.ORE_VEIN_26662;
|
||||
import static net.runelite.api.ObjectID.ORE_VEIN_26663;
|
||||
import static net.runelite.api.ObjectID.ORE_VEIN_26664;
|
||||
import static net.runelite.api.ObjectID.ROCKFALL;
|
||||
import static net.runelite.api.ObjectID.ROCKFALL_26680;
|
||||
import net.runelite.api.WallObject;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.GameObjectChanged;
|
||||
import net.runelite.api.events.GameObjectDespawned;
|
||||
import net.runelite.api.events.GameObjectSpawned;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.WallObjectChanged;
|
||||
import net.runelite.api.events.WallObjectDespawned;
|
||||
import net.runelite.api.events.WallObjectSpawned;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.task.Schedule;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Motherlode plugin"
|
||||
)
|
||||
public class MotherlodePlugin extends Plugin
|
||||
{
|
||||
private static final Set<Integer> MINE_SPOTS = Sets.newHashSet(ORE_VEIN_26661, ORE_VEIN_26662, ORE_VEIN_26663, ORE_VEIN_26664);
|
||||
private static final Set<Integer> ROCK_OBSTACLES = Sets.newHashSet(ROCKFALL, ROCKFALL_26680);
|
||||
|
||||
@Getter
|
||||
private BufferedImage mineIcon;
|
||||
|
||||
@@ -67,6 +90,11 @@ public class MotherlodePlugin extends Plugin
|
||||
|
||||
private final MotherlodeSession session = new MotherlodeSession();
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final Set<WallObject> veins = new HashSet<>();
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final Set<GameObject> rocks = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public void configure(Binder binder)
|
||||
{
|
||||
@@ -129,4 +157,76 @@ public class MotherlodePlugin extends Plugin
|
||||
session.resetRecent();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onWallObjectSpanwed(WallObjectSpawned event)
|
||||
{
|
||||
WallObject wallObject = event.getWallObject();
|
||||
if (MINE_SPOTS.contains(wallObject.getId()))
|
||||
{
|
||||
veins.add(wallObject);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onWallObjectChanged(WallObjectChanged event)
|
||||
{
|
||||
WallObject previous = event.getPrevious();
|
||||
WallObject wallObject = event.getWallObject();
|
||||
|
||||
veins.remove(previous);
|
||||
if (MINE_SPOTS.contains(wallObject.getId()))
|
||||
{
|
||||
veins.add(wallObject);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onWallObjectDespawned(WallObjectDespawned event)
|
||||
{
|
||||
WallObject wallObject = event.getWallObject();
|
||||
veins.remove(wallObject);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameObjectSpawned(GameObjectSpawned event)
|
||||
{
|
||||
GameObject gameObject = event.getGameObject();
|
||||
if (ROCK_OBSTACLES.contains(gameObject.getId()))
|
||||
{
|
||||
rocks.add(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameObjectChanged(GameObjectChanged event)
|
||||
{
|
||||
GameObject previous = event.getPrevious();
|
||||
GameObject gameObject = event.getGameObject();
|
||||
|
||||
rocks.remove(previous);
|
||||
if (ROCK_OBSTACLES.contains(gameObject.getId()))
|
||||
{
|
||||
rocks.add(gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameObjectDespawned(GameObjectDespawned event)
|
||||
{
|
||||
GameObject gameObject = event.getGameObject();
|
||||
rocks.remove(gameObject);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameStateChanged(GameStateChanged event)
|
||||
{
|
||||
if (event.getGameState() == GameState.LOADING)
|
||||
{
|
||||
// on region changes the tiles get set to null
|
||||
veins.clear();
|
||||
rocks.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2018, Seth <Sethtroll3@gmail.com>
|
||||
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -24,43 +25,26 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.motherlode;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameObject;
|
||||
import net.runelite.api.Perspective;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.Region;
|
||||
import net.runelite.api.Tile;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.api.WallObject;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayLayer;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.OverlayUtil;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Polygon;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static net.runelite.api.ObjectID.ORE_VEIN_26661;
|
||||
import static net.runelite.api.ObjectID.ORE_VEIN_26662;
|
||||
import static net.runelite.api.ObjectID.ORE_VEIN_26663;
|
||||
import static net.runelite.api.ObjectID.ORE_VEIN_26664;
|
||||
import static net.runelite.api.ObjectID.ROCKFALL;
|
||||
import static net.runelite.api.ObjectID.ROCKFALL_26680;
|
||||
|
||||
class MotherlodeRocksOverlay extends Overlay
|
||||
{
|
||||
private static final int REGION_SIZE = 104;
|
||||
private static final int MAX_DISTANCE = 2350;
|
||||
|
||||
private static final List<Integer> MINE_SPOTS = Arrays.asList(ORE_VEIN_26661, ORE_VEIN_26662, ORE_VEIN_26663, ORE_VEIN_26664);
|
||||
|
||||
private static final List<Integer> ROCK_OBSTACLES = Arrays.asList(ROCKFALL, ROCKFALL_26680);
|
||||
|
||||
private final Client client;
|
||||
private final MotherlodePlugin plugin;
|
||||
private final MotherlodeConfig config;
|
||||
@@ -76,7 +60,7 @@ class MotherlodeRocksOverlay extends Overlay
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics, Point parent)
|
||||
public Dimension render(Graphics2D graphics, java.awt.Point parent)
|
||||
{
|
||||
if (!config.enabled() || !config.showRocks())
|
||||
{
|
||||
@@ -85,7 +69,6 @@ class MotherlodeRocksOverlay extends Overlay
|
||||
|
||||
Player local = client.getLocalPlayer();
|
||||
|
||||
//Render mining spot
|
||||
renderTiles(graphics, local);
|
||||
|
||||
return null;
|
||||
@@ -93,57 +76,43 @@ class MotherlodeRocksOverlay extends Overlay
|
||||
|
||||
private void renderTiles(Graphics2D graphics, Player local)
|
||||
{
|
||||
Region region = client.getRegion();
|
||||
Tile[][][] tiles = region.getTiles();
|
||||
|
||||
int z = client.getPlane();
|
||||
|
||||
for (int x = 0; x < REGION_SIZE; ++x)
|
||||
Point localLocation = local.getLocalLocation();
|
||||
for (WallObject vein : plugin.getVeins())
|
||||
{
|
||||
for (int y = 0; y < REGION_SIZE; ++y)
|
||||
Point location = vein.getLocalLocation();
|
||||
if (localLocation.distanceTo(location) <= MAX_DISTANCE)
|
||||
{
|
||||
Tile tile = tiles[z][x][y];
|
||||
renderVein(graphics, vein);
|
||||
}
|
||||
}
|
||||
|
||||
if (tile == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (local.getLocalLocation().distanceTo(tile.getLocalLocation()) <= MAX_DISTANCE)
|
||||
{
|
||||
renderMine(graphics, tile);
|
||||
}
|
||||
for (GameObject rock : plugin.getRocks())
|
||||
{
|
||||
Point location = rock.getLocalLocation();
|
||||
if (localLocation.distanceTo(location) <= MAX_DISTANCE)
|
||||
{
|
||||
renderRock(graphics, rock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void renderMine(Graphics2D graphics, Tile tile)
|
||||
private void renderVein(Graphics2D graphics, WallObject vein)
|
||||
{
|
||||
//Draw the Pay-dirt spots
|
||||
WallObject wallObject = tile.getWallObject();
|
||||
if (wallObject != null && MINE_SPOTS.contains(wallObject.getId()))
|
||||
{
|
||||
net.runelite.api.Point canvasLoc = Perspective.getCanvasImageLocation(client, graphics, wallObject.getLocalLocation(), plugin.getMineIcon(), 150);
|
||||
Point canvasLoc = Perspective.getCanvasImageLocation(client, graphics, vein.getLocalLocation(), plugin.getMineIcon(), 150);
|
||||
|
||||
if (canvasLoc != null)
|
||||
{
|
||||
graphics.drawImage(plugin.getMineIcon(), canvasLoc.getX(), canvasLoc.getY(), null);
|
||||
return;
|
||||
}
|
||||
if (canvasLoc != null)
|
||||
{
|
||||
graphics.drawImage(plugin.getMineIcon(), canvasLoc.getX(), canvasLoc.getY(), null);
|
||||
}
|
||||
}
|
||||
|
||||
//Draw the rock obstacles
|
||||
GameObject[] gameObjects = tile.getGameObjects();
|
||||
for (GameObject gameObject : gameObjects)
|
||||
private void renderRock(Graphics2D graphics, GameObject rock)
|
||||
{
|
||||
Polygon poly = Perspective.getCanvasTilePoly(client, rock.getLocalLocation());
|
||||
|
||||
if (poly != null)
|
||||
{
|
||||
if (gameObject != null && ROCK_OBSTACLES.contains(gameObject.getId()))
|
||||
{
|
||||
Polygon poly = Perspective.getCanvasTilePoly(client, gameObject.getLocalLocation());
|
||||
|
||||
if (poly != null)
|
||||
{
|
||||
OverlayUtil.renderPolygon(graphics, poly, Color.red);
|
||||
}
|
||||
}
|
||||
OverlayUtil.renderPolygon(graphics, poly, Color.red);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2018, Seth <Sethtroll3@gmail.com>
|
||||
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -24,6 +25,10 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.motherlode;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
@@ -32,11 +37,6 @@ import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.components.PanelComponent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
class MotherlodeSackOverlay extends Overlay
|
||||
{
|
||||
private final Client client;
|
||||
@@ -70,8 +70,8 @@ class MotherlodeSackOverlay extends Overlay
|
||||
if (config.showSack())
|
||||
{
|
||||
panelComponent.getLines().add(new PanelComponent.Line(
|
||||
"Pay-dirt in sack:",
|
||||
String.valueOf(client.getSetting(Varbits.SACK_NUMBER))
|
||||
"Pay-dirt in sack:",
|
||||
String.valueOf(client.getSetting(Varbits.SACK_NUMBER))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2018, Seth <Sethtroll3@gmail.com>
|
||||
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
Reference in New Issue
Block a user