use of net.runelite.api.events.ConfigChanged in project runelite by runelite.
the class ConfigManager method load.
public void load() {
if (client == null) {
loadFromFile();
return;
}
Configuration configuration;
try {
configuration = client.get();
} catch (IOException ex) {
log.debug("Unable to load configuration from client, using saved configuration from disk", ex);
loadFromFile();
return;
}
if (configuration.getConfig().isEmpty()) {
log.debug("No configuration from client, using saved configuration on disk");
loadFromFile();
return;
}
properties.clear();
for (ConfigEntry entry : configuration.getConfig()) {
log.debug("Loading configuration value from client {}: {}", entry.getKey(), entry.getValue());
final String[] split = entry.getKey().split("\\.");
final String groupName = split[0];
final String key = split[1];
final String value = entry.getValue();
final String oldValue = (String) properties.setProperty(entry.getKey(), value);
ConfigChanged configChanged = new ConfigChanged();
configChanged.setGroup(groupName);
configChanged.setKey(key);
configChanged.setOldValue(oldValue);
configChanged.setNewValue(value);
eventBus.post(configChanged);
}
try {
saveToFile();
log.debug("Updated configuration on disk with the latest version");
} catch (IOException ex) {
log.warn("Unable to update configuration on disk", ex);
}
}
use of net.runelite.api.events.ConfigChanged in project runelite by runelite.
the class AttackIndicatorPluginTest method testWarning.
/*
* Verify that red text is displayed when attacking with a style that gains experience
* in one of the unwanted skills.
*/
@Test
public void testWarning() {
ConfigChanged warnForAttackEvent = new ConfigChanged();
warnForAttackEvent.setGroup("attackIndicator");
warnForAttackEvent.setKey("warnForAttack");
warnForAttackEvent.setNewValue("true");
attackPlugin.onConfigChanged(warnForAttackEvent);
// Verify there is a warned skill
Set<Skill> warnedSkills = attackPlugin.getWarnedSkills();
assertTrue(warnedSkills.contains(Skill.ATTACK));
// Set mock client to attack in style that gives attack xp
when(client.getSetting(Setting.ATTACK_STYLE)).thenReturn(AttackStyle.ACCURATE.ordinal());
// verify that earning xp in a warned skill will display red text on the widget
attackPlugin.onAttackStyleChange(new VarbitChanged());
assertTrue(attackPlugin.isWarnedSkillSelected());
// Switch to attack style that doesn't give attack xp
when(client.getSetting(Setting.ATTACK_STYLE)).thenReturn(AttackStyle.AGGRESSIVE.ordinal());
// Verify the widget will now display white text
attackPlugin.onAttackStyleChange(new VarbitChanged());
warnedSkills = attackPlugin.getWarnedSkills();
assertTrue(warnedSkills.contains(Skill.ATTACK));
assertFalse(attackPlugin.isWarnedSkillSelected());
}
use of net.runelite.api.events.ConfigChanged in project runelite by runelite.
the class AttackIndicatorPluginTest method testHiddenWidget.
/*
* Verify that attack style widgets are hidden when filtered with the AttackIndicatorPlugin.
*/
@Test
public void testHiddenWidget() {
ConfigChanged warnForAttackEvent = new ConfigChanged();
warnForAttackEvent.setGroup("attackIndicator");
warnForAttackEvent.setKey("warnForAttack");
warnForAttackEvent.setNewValue("true");
attackPlugin.onConfigChanged(warnForAttackEvent);
// Set up mock widgets for atk and str attack styles
Widget atkWidget = mock(Widget.class);
Widget strWidget = mock(Widget.class);
when(client.getWidget(WidgetInfo.COMBAT_STYLE_ONE)).thenReturn(atkWidget);
when(client.getWidget(WidgetInfo.COMBAT_STYLE_TWO)).thenReturn(strWidget);
// Set widgets to return their hidden value in widgetsToHide when isHidden() is called
when(atkWidget.isHidden()).thenAnswer(x -> isAtkHidden());
when(strWidget.isHidden()).thenAnswer(x -> isStrHidden());
// equip type_4 weapon type on player
when(client.getSetting(Varbits.EQUIPPED_WEAPON_TYPE)).thenReturn(WeaponType.TYPE_4.ordinal());
attackPlugin.onEquippedWeaponTypeChange(new VarbitChanged());
// Verify there is a warned skill
Set<Skill> warnedSkills = attackPlugin.getWarnedSkills();
assertTrue(warnedSkills.contains(Skill.ATTACK));
// Enable hiding widgets
ConfigChanged hideWidgetEvent = new ConfigChanged();
hideWidgetEvent.setGroup("attackIndicator");
hideWidgetEvent.setKey("removeWarnedStyles");
hideWidgetEvent.setNewValue("true");
attackPlugin.onConfigChanged(hideWidgetEvent);
when(attackConfig.removeWarnedStyles()).thenReturn(true);
// verify that the accurate attack style widget is hidden
assertTrue(atkWidget.isHidden());
// add another warned skill
ConfigChanged warnForStrengthEvent = new ConfigChanged();
warnForStrengthEvent.setGroup("attackIndicator");
warnForStrengthEvent.setKey("warnForStrength");
warnForStrengthEvent.setNewValue("true");
attackPlugin.onConfigChanged(warnForStrengthEvent);
// verify that the aggressive attack style widget is now hidden
assertTrue(strWidget.isHidden());
// disable hiding attack style widgets
hideWidgetEvent.setGroup("attackIndicator");
hideWidgetEvent.setKey("removeWarnedStyles");
hideWidgetEvent.setNewValue("false");
attackPlugin.onConfigChanged(hideWidgetEvent);
when(attackConfig.removeWarnedStyles()).thenReturn(false);
// verify that the aggressive and accurate attack style widgets are no longer hidden
assertFalse(attackPlugin.getHiddenWidgets().get(WeaponType.TYPE_4, WidgetInfo.COMBAT_STYLE_ONE));
assertFalse(attackPlugin.getHiddenWidgets().get(WeaponType.TYPE_4, WidgetInfo.COMBAT_STYLE_THREE));
}
use of net.runelite.api.events.ConfigChanged in project runelite by runelite.
the class ConfigManager method loadFromFile.
private synchronized void loadFromFile() {
properties.clear();
try (FileInputStream in = new FileInputStream(propertiesFile)) {
properties.load(in);
} catch (FileNotFoundException ex) {
log.debug("Unable to load settings - no such file");
} catch (IOException ex) {
log.warn("Unable to load settings", ex);
}
try {
Map<String, String> copy = (Map) ImmutableMap.copyOf(properties);
copy.forEach((groupAndKey, value) -> {
final String[] split = ((String) groupAndKey).split("\\.");
if (split.length != 2) {
log.debug("Properties key malformed!: {}", groupAndKey);
return;
}
final String groupName = split[0];
final String key = split[1];
ConfigChanged configChanged = new ConfigChanged();
configChanged.setGroup(groupName);
configChanged.setKey(key);
configChanged.setOldValue(null);
configChanged.setNewValue((String) value);
eventBus.post(configChanged);
});
} catch (Exception ex) {
log.warn("Error posting config events", ex);
}
}
use of net.runelite.api.events.ConfigChanged in project runelite by runelite.
the class ConfigManager method setConfiguration.
public void setConfiguration(String groupName, String key, String value) {
log.debug("Setting configuration value for {}.{} to {}", groupName, key, value);
String oldValue = (String) properties.setProperty(groupName + "." + key, value);
if (client != null) {
Runnable task = () -> {
try {
client.set(groupName + "." + key, value);
} catch (IOException ex) {
log.warn("unable to set configuration item", ex);
}
};
executor.execute(task);
}
Runnable task = () -> {
try {
saveToFile();
} catch (IOException ex) {
log.warn("unable to save configuration file", ex);
}
};
executor.execute(task);
ConfigChanged configChanged = new ConfigChanged();
configChanged.setGroup(groupName);
configChanged.setKey(key);
configChanged.setOldValue(oldValue);
configChanged.setNewValue(value);
eventBus.post(configChanged);
}
Aggregations