Java Code Examples for net.runelite.client.events.ConfigChanged#setNewValue()

The following examples show how to use net.runelite.client.events.ConfigChanged#setNewValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimestampPluginTest.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGenerateTimestamp()
{
	when(config.timestampFormat()).thenReturn("[yyyy:MM:dd:HH:hh:mm:ss]");

	ConfigChanged configChanged = new ConfigChanged();
	configChanged.setGroup("timestamp");
	configChanged.setKey("format");
	configChanged.setNewValue("true");
	plugin.onConfigChanged(configChanged);

	int testInput = 1554667116;
	String testOutput = "[2019:04:07:15:03:58:36]";
	TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
	plugin.getFormatter().setTimeZone(timeZone);
	assertEquals(plugin.generateTimestamp(testInput, timeZone.toZoneId()), testOutput);
}
 
Example 2
Source File: ConfigManager.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void setConfiguration(String groupName, String key, String value)
{
	String oldValue = (String) properties.setProperty(groupName + "." + key, value);

	if (Objects.equals(oldValue, value))
	{
		return;
	}

	log.debug("Setting configuration value for {}.{} to {}", groupName, key, value);
	handler.invalidate();

	synchronized (pendingChanges)
	{
		pendingChanges.put(groupName + "." + key, value);
	}

	ConfigChanged configChanged = new ConfigChanged();
	configChanged.setGroup(groupName);
	configChanged.setKey(key);
	configChanged.setOldValue(oldValue);
	configChanged.setNewValue(value);

	eventBus.post(configChanged);
}
 
Example 3
Source File: TimestampPluginTest.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testGenerateTimestamp()
{
	when(config.timestampFormat()).thenReturn("[yyyy:MM:dd:HH:hh:mm:ss]");

	ConfigChanged configChanged = new ConfigChanged();
	configChanged.setGroup("timestamp");
	configChanged.setKey("format");
	configChanged.setNewValue("true");
	plugin.onConfigChanged(configChanged);

	int testInput = 1554667116;
	String testOutput = "[2019:04:07:15:03:58:36]";
	TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
	plugin.getFormatter().setTimeZone(timeZone);
	assertTrue(plugin.generateTimestamp(testInput, timeZone.toZoneId()).equals(testOutput));
}
 
Example 4
Source File: AttackStylesPluginTest.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@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.getVar(VarPlayer.ATTACK_STYLE)).thenReturn(AttackStyle.ACCURATE.ordinal());

	// verify that earning xp in a warned skill will display red text on the widget
	attackPlugin.onVarbitChanged(new VarbitChanged());
	assertTrue(attackPlugin.isWarnedSkillSelected());

	// Switch to attack style that doesn't give attack xp
	when(client.getVar(VarPlayer.ATTACK_STYLE)).thenReturn(AttackStyle.AGGRESSIVE.ordinal());

	// Verify the widget will now display white text
	attackPlugin.onVarbitChanged(new VarbitChanged());
	warnedSkills = attackPlugin.getWarnedSkills();
	assertTrue(warnedSkills.contains(Skill.ATTACK));
	assertFalse(attackPlugin.isWarnedSkillSelected());
}
 
Example 5
Source File: AttackStylesPluginTest.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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.getVar(VarPlayer.ATTACK_STYLE)).thenReturn(AttackStyle.ACCURATE.ordinal());

	// verify that earning xp in a warned skill will display red text on the widget
	attackPlugin.onVarbitChanged(new VarbitChanged());
	assertTrue(attackPlugin.isWarnedSkillSelected());

	// Switch to attack style that doesn't give attack xp
	when(client.getVar(VarPlayer.ATTACK_STYLE)).thenReturn(AttackStyle.AGGRESSIVE.ordinal());

	// Verify the widget will now display white text
	attackPlugin.onVarbitChanged(new VarbitChanged());
	warnedSkills = attackPlugin.getWarnedSkills();
	assertTrue(warnedSkills.contains(Skill.ATTACK));
	assertFalse(attackPlugin.isWarnedSkillSelected());
}
 
Example 6
Source File: AttackStylesPluginTest.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@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.getVar(Varbits.EQUIPPED_WEAPON_TYPE)).thenReturn(WeaponType.TYPE_4.ordinal());
	attackPlugin.onVarbitChanged(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);

	// 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));
}
 
Example 7
Source File: AttackStylesPluginTest.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@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.getVar(Varbits.EQUIPPED_WEAPON_TYPE)).thenReturn(WeaponType.TYPE_4.ordinal());
	attackPlugin.onVarbitChanged(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);

	// 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));
}