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