hiscore plugin: add config caching (#1572)
hiscore plugin: add config caching
This commit is contained in:
@@ -81,7 +81,7 @@ public interface HiscoreConfig extends Config
|
|||||||
name = "Bounty lookup",
|
name = "Bounty lookup",
|
||||||
description = "Automatically lookup the stats of your bounty hunter target"
|
description = "Automatically lookup the stats of your bounty hunter target"
|
||||||
)
|
)
|
||||||
default boolean bountylookup()
|
default boolean bountyLookup()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public class HiscorePanel extends PluginPanel
|
|||||||
@Nullable
|
@Nullable
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
private final HiscoreConfig config;
|
private final HiscorePlugin plugin;
|
||||||
|
|
||||||
private final IconTextField searchBar;
|
private final IconTextField searchBar;
|
||||||
|
|
||||||
@@ -141,10 +141,10 @@ public class HiscorePanel extends PluginPanel
|
|||||||
private boolean loading = false;
|
private boolean loading = false;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public HiscorePanel(HiscoreConfig config)
|
public HiscorePanel(HiscorePlugin plugin)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
this.config = config;
|
this.plugin = plugin;
|
||||||
|
|
||||||
// The layout seems to be ignoring the top margin and only gives it
|
// The layout seems to be ignoring the top margin and only gives it
|
||||||
// a 2-3 pixel margin, so I set the value to 18 to compensate
|
// a 2-3 pixel margin, so I set the value to 18 to compensate
|
||||||
@@ -423,7 +423,7 @@ public class HiscorePanel extends PluginPanel
|
|||||||
final long exp = s.getExperience();
|
final long exp = s.getExperience();
|
||||||
final boolean isSkill = SKILLS.contains(skill);
|
final boolean isSkill = SKILLS.contains(skill);
|
||||||
int level = -1;
|
int level = -1;
|
||||||
if (config.virtualLevels() && isSkill && exp > -1L)
|
if (plugin.isVirtualLevels() && isSkill && exp > -1L)
|
||||||
{
|
{
|
||||||
level = Experience.getLevelForXp((int) exp);
|
level = Experience.getLevelForXp((int) exp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ import javax.inject.Inject;
|
|||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
import net.runelite.api.ChatMessageType;
|
import net.runelite.api.ChatMessageType;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.MenuOpcode;
|
import net.runelite.api.MenuOpcode;
|
||||||
@@ -71,6 +73,14 @@ public class HiscorePlugin extends Plugin
|
|||||||
private static final ImmutableList<String> AFTER_OPTIONS = ImmutableList.of("Message", "Add ignore", "Remove friend", KICK_OPTION);
|
private static final ImmutableList<String> AFTER_OPTIONS = ImmutableList.of("Message", "Add ignore", "Remove friend", KICK_OPTION);
|
||||||
private static final Pattern BOUNTY_PATTERN = Pattern.compile("<col=ff0000>You've been assigned a target: (.*)</col>");
|
private static final Pattern BOUNTY_PATTERN = Pattern.compile("<col=ff0000>You've been assigned a target: (.*)</col>");
|
||||||
|
|
||||||
|
// config
|
||||||
|
private boolean playerOption;
|
||||||
|
private boolean menuOption;
|
||||||
|
@Getter(AccessLevel.PACKAGE)
|
||||||
|
private boolean virtualLevels;
|
||||||
|
private boolean autocomplete;
|
||||||
|
private boolean bountyLookup;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Nullable
|
@Nullable
|
||||||
private Client client;
|
private Client client;
|
||||||
@@ -106,6 +116,7 @@ public class HiscorePlugin extends Plugin
|
|||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
addSubscriptions();
|
addSubscriptions();
|
||||||
|
updateConfig();
|
||||||
|
|
||||||
hiscorePanel = injector.getInstance(HiscorePanel.class);
|
hiscorePanel = injector.getInstance(HiscorePanel.class);
|
||||||
|
|
||||||
@@ -120,11 +131,11 @@ public class HiscorePlugin extends Plugin
|
|||||||
|
|
||||||
clientToolbar.addNavigation(navButton);
|
clientToolbar.addNavigation(navButton);
|
||||||
|
|
||||||
if (config.playerOption() && client != null)
|
if (this.playerOption && client != null)
|
||||||
{
|
{
|
||||||
menuManager.get().addPlayerMenuItem(LOOKUP);
|
menuManager.get().addPlayerMenuItem(LOOKUP);
|
||||||
}
|
}
|
||||||
if (config.autocomplete())
|
if (this.autocomplete)
|
||||||
{
|
{
|
||||||
hiscorePanel.addInputKeyListener(autocompleter);
|
hiscorePanel.addInputKeyListener(autocompleter);
|
||||||
}
|
}
|
||||||
@@ -154,13 +165,17 @@ public class HiscorePlugin extends Plugin
|
|||||||
|
|
||||||
private void onConfigChanged(ConfigChanged event)
|
private void onConfigChanged(ConfigChanged event)
|
||||||
{
|
{
|
||||||
if (event.getGroup().equals("hiscore"))
|
|
||||||
|
if (!event.getGroup().equals("hiscore"))
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updateConfig();
|
||||||
if (client != null)
|
if (client != null)
|
||||||
{
|
{
|
||||||
menuManager.get().removePlayerMenuItem(LOOKUP);
|
menuManager.get().removePlayerMenuItem(LOOKUP);
|
||||||
|
|
||||||
if (config.playerOption())
|
if (this.playerOption)
|
||||||
{
|
{
|
||||||
menuManager.get().addPlayerMenuItem(LOOKUP);
|
menuManager.get().addPlayerMenuItem(LOOKUP);
|
||||||
}
|
}
|
||||||
@@ -168,7 +183,7 @@ public class HiscorePlugin extends Plugin
|
|||||||
|
|
||||||
if (event.getKey().equals("autocomplete"))
|
if (event.getKey().equals("autocomplete"))
|
||||||
{
|
{
|
||||||
if (config.autocomplete())
|
if (this.autocomplete)
|
||||||
{
|
{
|
||||||
hiscorePanel.addInputKeyListener(autocompleter);
|
hiscorePanel.addInputKeyListener(autocompleter);
|
||||||
}
|
}
|
||||||
@@ -178,11 +193,11 @@ public class HiscorePlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void onMenuEntryAdded(MenuEntryAdded event)
|
private void onMenuEntryAdded(MenuEntryAdded event)
|
||||||
{
|
{
|
||||||
if (!config.menuOption())
|
if (!this.menuOption)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -224,7 +239,7 @@ public class HiscorePlugin extends Plugin
|
|||||||
|
|
||||||
private void onChatMessage(ChatMessage event)
|
private void onChatMessage(ChatMessage event)
|
||||||
{
|
{
|
||||||
if (!config.bountylookup() || !event.getType().equals(ChatMessageType.GAMEMESSAGE))
|
if (!this.bountyLookup || !event.getType().equals(ChatMessageType.GAMEMESSAGE))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -237,6 +252,15 @@ public class HiscorePlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateConfig()
|
||||||
|
{
|
||||||
|
this.playerOption = config.playerOption();
|
||||||
|
this.menuOption = config.menuOption();
|
||||||
|
this.virtualLevels = config.virtualLevels();
|
||||||
|
this.autocomplete = config.autocomplete();
|
||||||
|
this.bountyLookup = config.bountyLookup();
|
||||||
|
}
|
||||||
|
|
||||||
private void insertMenuEntry(MenuEntry newEntry, MenuEntry[] entries)
|
private void insertMenuEntry(MenuEntry newEntry, MenuEntry[] entries)
|
||||||
{
|
{
|
||||||
MenuEntry[] newMenu = ObjectArrays.concat(entries, newEntry);
|
MenuEntry[] newMenu = ObjectArrays.concat(entries, newEntry);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class HiscorePanelTest
|
|||||||
@Test
|
@Test
|
||||||
public void testConstructor()
|
public void testConstructor()
|
||||||
{
|
{
|
||||||
new HiscorePanel(new HiscoreConfig()
|
new HiscorePanel(new HiscorePlugin()
|
||||||
{
|
{
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user