mlm plugin: make MotherlodeSession a guice managed singleton
This commit is contained in:
@@ -41,15 +41,17 @@ import net.runelite.client.ui.overlay.components.TitleComponent;
|
|||||||
public class MotherlodeGemOverlay extends Overlay
|
public class MotherlodeGemOverlay extends Overlay
|
||||||
{
|
{
|
||||||
private final MotherlodePlugin plugin;
|
private final MotherlodePlugin plugin;
|
||||||
|
private final MotherlodeSession motherlodeSession;
|
||||||
private final MotherlodeConfig config;
|
private final MotherlodeConfig config;
|
||||||
private final PanelComponent panelComponent = new PanelComponent();
|
private final PanelComponent panelComponent = new PanelComponent();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
MotherlodeGemOverlay(MotherlodePlugin plugin, MotherlodeConfig config)
|
MotherlodeGemOverlay(MotherlodePlugin plugin, MotherlodeSession motherlodeSession, MotherlodeConfig config)
|
||||||
{
|
{
|
||||||
super(plugin);
|
super(plugin);
|
||||||
setPosition(OverlayPosition.TOP_LEFT);
|
setPosition(OverlayPosition.TOP_LEFT);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.motherlodeSession = motherlodeSession;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
getMenuEntries().add(new OverlayMenuEntry(RUNELITE_OVERLAY_CONFIG, OPTION_CONFIGURE, "Gem overlay"));
|
getMenuEntries().add(new OverlayMenuEntry(RUNELITE_OVERLAY_CONFIG, OPTION_CONFIGURE, "Gem overlay"));
|
||||||
}
|
}
|
||||||
@@ -57,7 +59,7 @@ public class MotherlodeGemOverlay extends Overlay
|
|||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics)
|
public Dimension render(Graphics2D graphics)
|
||||||
{
|
{
|
||||||
MotherlodeSession session = plugin.getSession();
|
MotherlodeSession session = motherlodeSession;
|
||||||
|
|
||||||
if (session.getLastGemFound() == null || !plugin.isInMlm() || !config.showGemsFound())
|
if (session.getLastGemFound() == null || !plugin.isInMlm() || !config.showGemsFound())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,14 +36,16 @@ import net.runelite.client.ui.overlay.components.TitleComponent;
|
|||||||
public class MotherlodeOreOverlay extends Overlay
|
public class MotherlodeOreOverlay extends Overlay
|
||||||
{
|
{
|
||||||
private final MotherlodePlugin plugin;
|
private final MotherlodePlugin plugin;
|
||||||
|
private final MotherlodeSession motherlodeSession;
|
||||||
private final MotherlodeConfig config;
|
private final MotherlodeConfig config;
|
||||||
private final PanelComponent panelComponent = new PanelComponent();
|
private final PanelComponent panelComponent = new PanelComponent();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
MotherlodeOreOverlay(MotherlodePlugin plugin, MotherlodeConfig config)
|
MotherlodeOreOverlay(MotherlodePlugin plugin, MotherlodeSession motherlodeSession, MotherlodeConfig config)
|
||||||
{
|
{
|
||||||
setPosition(OverlayPosition.TOP_LEFT);
|
setPosition(OverlayPosition.TOP_LEFT);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.motherlodeSession = motherlodeSession;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +57,7 @@ public class MotherlodeOreOverlay extends Overlay
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MotherlodeSession session = plugin.getSession();
|
MotherlodeSession session = motherlodeSession;
|
||||||
|
|
||||||
int nuggetsFound = session.getNuggetsFound();
|
int nuggetsFound = session.getNuggetsFound();
|
||||||
int coalFound = session.getCoalFound();
|
int coalFound = session.getCoalFound();
|
||||||
|
|||||||
@@ -51,16 +51,18 @@ class MotherlodeOverlay extends Overlay
|
|||||||
|
|
||||||
private final Client client;
|
private final Client client;
|
||||||
private final MotherlodePlugin plugin;
|
private final MotherlodePlugin plugin;
|
||||||
|
private final MotherlodeSession motherlodeSession;
|
||||||
private final MotherlodeConfig config;
|
private final MotherlodeConfig config;
|
||||||
private final PanelComponent panelComponent = new PanelComponent();
|
private final PanelComponent panelComponent = new PanelComponent();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
MotherlodeOverlay(Client client, MotherlodePlugin plugin, MotherlodeConfig config)
|
MotherlodeOverlay(Client client, MotherlodePlugin plugin, MotherlodeSession motherlodeSession, MotherlodeConfig config)
|
||||||
{
|
{
|
||||||
super(plugin);
|
super(plugin);
|
||||||
setPosition(OverlayPosition.TOP_LEFT);
|
setPosition(OverlayPosition.TOP_LEFT);
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.motherlodeSession = motherlodeSession;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +74,7 @@ class MotherlodeOverlay extends Overlay
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MotherlodeSession session = plugin.getSession();
|
MotherlodeSession session = motherlodeSession;
|
||||||
|
|
||||||
if (session.getLastPayDirtMined() == null)
|
if (session.getLastPayDirtMined() == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ public class MotherlodePlugin extends Plugin
|
|||||||
@Getter(AccessLevel.PACKAGE)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private Integer depositsLeft;
|
private Integer depositsLeft;
|
||||||
|
|
||||||
|
@Inject
|
||||||
private MotherlodeSession session;
|
private MotherlodeSession session;
|
||||||
private boolean shouldUpdateOres;
|
private boolean shouldUpdateOres;
|
||||||
|
|
||||||
@@ -155,7 +156,6 @@ public class MotherlodePlugin extends Plugin
|
|||||||
overlayManager.add(motherlodeOreOverlay);
|
overlayManager.add(motherlodeOreOverlay);
|
||||||
overlayManager.add(motherlodeSackOverlay);
|
overlayManager.add(motherlodeSackOverlay);
|
||||||
|
|
||||||
session = new MotherlodeSession();
|
|
||||||
inMlm = checkInMlm();
|
inMlm = checkInMlm();
|
||||||
|
|
||||||
if (inMlm)
|
if (inMlm)
|
||||||
@@ -165,14 +165,13 @@ public class MotherlodePlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void shutDown() throws Exception
|
protected void shutDown()
|
||||||
{
|
{
|
||||||
overlayManager.remove(overlay);
|
overlayManager.remove(overlay);
|
||||||
overlayManager.remove(rocksOverlay);
|
overlayManager.remove(rocksOverlay);
|
||||||
overlayManager.remove(motherlodeGemOverlay);
|
overlayManager.remove(motherlodeGemOverlay);
|
||||||
overlayManager.remove(motherlodeOreOverlay);
|
overlayManager.remove(motherlodeOreOverlay);
|
||||||
overlayManager.remove(motherlodeSackOverlay);
|
overlayManager.remove(motherlodeSackOverlay);
|
||||||
session = null;
|
|
||||||
veins.clear();
|
veins.clear();
|
||||||
rocks.clear();
|
rocks.clear();
|
||||||
|
|
||||||
@@ -187,11 +186,6 @@ public class MotherlodePlugin extends Plugin
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public MotherlodeSession getSession()
|
|
||||||
{
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onVarbitChanged(VarbitChanged event)
|
public void onVarbitChanged(VarbitChanged event)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ package net.runelite.client.plugins.motherlode;
|
|||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -33,6 +34,7 @@ import net.runelite.api.Item;
|
|||||||
import net.runelite.api.ItemID;
|
import net.runelite.api.ItemID;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Singleton
|
||||||
public class MotherlodeSession
|
public class MotherlodeSession
|
||||||
{
|
{
|
||||||
private static final Duration HOUR = Duration.ofHours(1);
|
private static final Duration HOUR = Duration.ofHours(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user