menu manager: Remove bounty hunter emblem text from player name (#11541)
This commit is contained in:
@@ -46,7 +46,8 @@ public enum IconID
|
||||
SKULL(9),
|
||||
HARDCORE_IRONMAN(10),
|
||||
NO_ENTRY(11),
|
||||
CHAIN_LINK(12);
|
||||
CHAIN_LINK(12),
|
||||
BOUNTY_HUNTER_EMBLEM(20);
|
||||
|
||||
private final int index;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package net.runelite.client.menus;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
@@ -33,10 +34,12 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.IconID;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.NPCComposition;
|
||||
@@ -61,6 +64,8 @@ public class MenuManager
|
||||
private static final int IDX_LOWER = 4;
|
||||
private static final int IDX_UPPER = 8;
|
||||
|
||||
private static final Pattern BOUNTY_EMBLEM_TAG_AND_TIER_REGEXP = Pattern.compile(String.format("%s[1-9]0?", IconID.BOUNTY_HUNTER_EMBLEM.toString()));
|
||||
|
||||
private final Client client;
|
||||
private final EventBus eventBus;
|
||||
|
||||
@@ -71,7 +76,8 @@ public class MenuManager
|
||||
private final Set<String> npcMenuOptions = new HashSet<>();
|
||||
|
||||
@Inject
|
||||
private MenuManager(Client client, EventBus eventBus)
|
||||
@VisibleForTesting
|
||||
MenuManager(Client client, EventBus eventBus)
|
||||
{
|
||||
this.client = client;
|
||||
this.eventBus = eventBus;
|
||||
@@ -269,7 +275,9 @@ public class MenuManager
|
||||
}
|
||||
}
|
||||
|
||||
String target = event.getMenuTarget();
|
||||
// removes bounty hunter emblem tag and tier from player name, e.g:
|
||||
// "username<img=20>5<col=40ff00> (level-42)" -> "username<col=40ff00> (level-42)"
|
||||
String target = BOUNTY_EMBLEM_TAG_AND_TIER_REGEXP.matcher(event.getMenuTarget()).replaceAll("");
|
||||
|
||||
// removes tags and level from player names for example:
|
||||
// <col=ffffff>username<col=40ff00> (level-42) or <col=ffffff><img=2>username</col>
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2020, bfmoatbio <bfmoatbio@protonmail.com>
|
||||
* Copyright (c) 2020, Jordan Atwood <nightfirecat@protonmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.menus;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.events.MenuOptionClicked;
|
||||
import net.runelite.api.events.PlayerMenuOptionClicked;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MenuManagerTest
|
||||
{
|
||||
@Inject
|
||||
private MenuManager menuManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private Client client;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private EventBus eventBus;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayerMenuOptionClicked()
|
||||
{
|
||||
MenuOptionClicked event = new MenuOptionClicked();
|
||||
event.setMenuAction(MenuAction.RUNELITE);
|
||||
event.setMenuTarget("username<col=40ff00> (level-42)");
|
||||
|
||||
menuManager.onMenuOptionClicked(event);
|
||||
|
||||
ArgumentCaptor<PlayerMenuOptionClicked> captor = ArgumentCaptor.forClass(PlayerMenuOptionClicked.class);
|
||||
verify(eventBus).post(captor.capture());
|
||||
PlayerMenuOptionClicked clicked = captor.getValue();
|
||||
assertEquals("username", clicked.getMenuTarget());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayerMenuOptionWithBountyHunterEmblemClicked()
|
||||
{
|
||||
MenuOptionClicked event = new MenuOptionClicked();
|
||||
event.setMenuAction(MenuAction.RUNELITE);
|
||||
event.setMenuTarget("username<img=20>5<col=40ff00> (level-42)");
|
||||
|
||||
menuManager.onMenuOptionClicked(event);
|
||||
|
||||
ArgumentCaptor<PlayerMenuOptionClicked> captor = ArgumentCaptor.forClass(PlayerMenuOptionClicked.class);
|
||||
verify(eventBus).post(captor.capture());
|
||||
PlayerMenuOptionClicked clicked = captor.getValue();
|
||||
assertEquals("username", clicked.getMenuTarget());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user