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

The following examples show how to use net.runelite.client.events.ConfigChanged#setGroup() . 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: NpcIndicatorsPluginTest.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDeadNpcMenuHighlight()
{
	when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin");
	when(npcIndicatorsConfig.deadNpcMenuColor()).thenReturn(Color.RED);

	ConfigChanged configChanged = new ConfigChanged();
	configChanged.setGroup("npcindicators");
	npcIndicatorsPlugin.onConfigChanged(configChanged);

	NPC npc = mock(NPC.class);
	when(npc.getName()).thenReturn("Goblin");
	when(npc.isDead()).thenReturn(true);
	npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));

	when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0

	when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()});
	MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuOpcode.NPC_FIRST_OPTION.getId(), 0, -1, -1, false);
	npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);

	MenuEntry target = new MenuEntry();
	target.setTarget("<col=ff0000>Goblin"); // red
	verify(client).setMenuEntries(new MenuEntry[]{target});
}
 
Example 2
Source File: NpcIndicatorsPluginTest.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAliveNpcMenuHighlight()
{
	when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin");
	when(npcIndicatorsConfig.highlightMenuNames()).thenReturn(true);
	when(npcIndicatorsConfig.getHighlightColor()).thenReturn(Color.BLUE);

	ConfigChanged configChanged = new ConfigChanged();
	configChanged.setGroup("npcindicators");
	npcIndicatorsPlugin.onConfigChanged(configChanged);

	NPC npc = mock(NPC.class);
	when(npc.getName()).thenReturn("Goblin");
	npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));

	when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0

	when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()});
	MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuOpcode.NPC_FIRST_OPTION.getId(), 0, -1, -1, false);
	npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);

	MenuEntry target = new MenuEntry();
	target.setTarget("<col=0000ff>Goblin"); // blue
	verify(client).setMenuEntries(new MenuEntry[]{target});
}
 
Example 3
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 4
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 5
Source File: ConfigManager.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void unsetConfiguration(String groupName, String key)
{
	String oldValue = (String) properties.remove(groupName + "." + key);

	if (oldValue == null)
	{
		return;
	}

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

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

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

	eventBus.post(configChanged);
}
 
Example 6
Source File: NpcIndicatorsPluginTest.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testDeadNpcMenuHighlight()
{
	when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin");
	when(npcIndicatorsConfig.deadNpcMenuColor()).thenReturn(Color.RED);

	ConfigChanged configChanged = new ConfigChanged();
	configChanged.setGroup("npcindicators");
	npcIndicatorsPlugin.onConfigChanged(configChanged);

	NPC npc = mock(NPC.class);
	when(npc.getName()).thenReturn("Goblin");
	when(npc.isDead()).thenReturn(true);
	npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));

	when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0

	when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()});
	MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1);
	npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);

	MenuEntry target = new MenuEntry();
	target.setTarget("<col=ff0000>Goblin"); // red
	verify(client).setMenuEntries(new MenuEntry[]{target});
}
 
Example 7
Source File: NpcIndicatorsPluginTest.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testAliveNpcMenuHighlight()
{
	when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin");
	when(npcIndicatorsConfig.highlightMenuNames()).thenReturn(true);
	when(npcIndicatorsConfig.getHighlightColor()).thenReturn(Color.BLUE);

	ConfigChanged configChanged = new ConfigChanged();
	configChanged.setGroup("npcindicators");
	npcIndicatorsPlugin.onConfigChanged(configChanged);

	NPC npc = mock(NPC.class);
	when(npc.getName()).thenReturn("Goblin");
	npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));

	when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0

	when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()});
	MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1);
	npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);

	MenuEntry target = new MenuEntry();
	target.setTarget("<col=0000ff>Goblin"); // blue
	verify(client).setMenuEntries(new MenuEntry[]{target});
}
 
Example 8
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 9
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 10
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 11
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 12
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));
}