Refactor MenuModifier
This commit is contained in:
@@ -31,24 +31,51 @@ import net.runelite.client.config.ConfigItem;
|
|||||||
@ConfigGroup("menumodifier")
|
@ConfigGroup("menumodifier")
|
||||||
public interface MenuModifierConfig extends Config
|
public interface MenuModifierConfig extends Config
|
||||||
{
|
{
|
||||||
@ConfigItem(position = 0, keyName = "hideCancel", name = "Hide Cancel", description = "Hides the 'cancel' option from the right click menu")
|
@ConfigItem(
|
||||||
default boolean hideCancel() { return true; }
|
position = 0,
|
||||||
|
keyName = "hideExamine",
|
||||||
@ConfigItem(position = 1, keyName = "hideExamine", name = "Hide Examine", description = "Hides the 'examine' option from the right click menu")
|
name = "Hide Examine",
|
||||||
|
description = "Hides the 'examine' option from the right click menu"
|
||||||
|
)
|
||||||
default boolean hideExamine() { return true; }
|
default boolean hideExamine() { return true; }
|
||||||
|
|
||||||
@ConfigItem(position = 2, keyName = "hideTradeWith", name = "Hide Trade With", description = "Hides the 'trade with' option from the right click menu")
|
@ConfigItem(
|
||||||
|
position = 1,
|
||||||
|
keyName = "hideTradeWith",
|
||||||
|
name = "Hide Trade With",
|
||||||
|
description = "Hides the 'trade with' option from the right click menu"
|
||||||
|
)
|
||||||
default boolean hideTradeWith() { return true; }
|
default boolean hideTradeWith() { return true; }
|
||||||
|
|
||||||
@ConfigItem(position = 3, keyName = "hideReport", name = "Hide Report", description = "Hides the 'report' option from the right click menu")
|
@ConfigItem(
|
||||||
|
position = 2,
|
||||||
|
keyName = "hideReport",
|
||||||
|
name = "Hide Report",
|
||||||
|
description = "Hides the 'report' option from the right click menu"
|
||||||
|
)
|
||||||
default boolean hideReport() { return true; }
|
default boolean hideReport() { return true; }
|
||||||
|
|
||||||
@ConfigItem(position = 4, keyName = "hideLookup", name = "Hide Lookup", description = "Hides the 'lookup' option from the right click menu")
|
@ConfigItem(
|
||||||
|
position = 3,
|
||||||
|
keyName = "hideLookup",
|
||||||
|
name = "Hide Lookup",
|
||||||
|
description = "Hides the 'lookup' option from the right click menu"
|
||||||
|
)
|
||||||
default boolean hideLookup() { return true; }
|
default boolean hideLookup() { return true; }
|
||||||
|
|
||||||
@ConfigItem(position = 4, keyName = "hideNet", name = "Hide Net", description = "Hides the 'net' option from the right click menu")
|
@ConfigItem(
|
||||||
|
position = 4,
|
||||||
|
keyName = "hideNet",
|
||||||
|
name = "Hide Net",
|
||||||
|
description = "Hides the 'net' option from the right click menu"
|
||||||
|
)
|
||||||
default boolean hideNet() { return true; }
|
default boolean hideNet() { return true; }
|
||||||
|
|
||||||
@ConfigItem(position = 4, keyName = "hideBait", name = "Hide Bait", description = "Hides the 'Bait' option from the right click menu")
|
@ConfigItem(
|
||||||
|
position = 5,
|
||||||
|
keyName = "hideBait",
|
||||||
|
name = "Hide Bait",
|
||||||
|
description = "Hides the 'Bait' option from the right click menu"
|
||||||
|
)
|
||||||
default boolean hideBait() { return true; }
|
default boolean hideBait() { return true; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,40 +24,39 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.menumodifier;
|
package net.runelite.client.plugins.menumodifier;
|
||||||
|
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import javax.inject.Inject;
|
||||||
import net.runelite.client.input.KeyListener;
|
import net.runelite.client.input.KeyListener;
|
||||||
import net.runelite.client.input.MouseAdapter;
|
import net.runelite.client.input.MouseAdapter;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
|
|
||||||
public class MenuModifierInputListener extends MouseAdapter implements KeyListener
|
public class MenuModifierInputListener extends MouseAdapter implements KeyListener
|
||||||
{
|
{
|
||||||
private static final int HOTKEY = KeyEvent.VK_CONTROL;
|
private static final int HOTKEY = KeyEvent.VK_CONTROL;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(KeyEvent e)
|
public void keyTyped(KeyEvent e)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private MenuModifierPlugin plugin;
|
private MenuModifierPlugin plugin;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e)
|
public void keyPressed(KeyEvent e)
|
||||||
{
|
{
|
||||||
if (e.getKeyCode() == HOTKEY)
|
if (e.getKeyCode() == HOTKEY)
|
||||||
{
|
{
|
||||||
plugin.setHotKeyPressed(true);
|
plugin.setHotKeyPressed(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e)
|
public void keyReleased(KeyEvent e)
|
||||||
{
|
{
|
||||||
if (e.getKeyCode() == HOTKEY)
|
if (e.getKeyCode() == HOTKEY)
|
||||||
{
|
{
|
||||||
plugin.setHotKeyPressed(false);
|
plugin.setHotKeyPressed(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,18 +24,19 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.menumodifier;
|
package net.runelite.client.plugins.menumodifier;
|
||||||
|
|
||||||
import net.runelite.api.events.MenuOpened;
|
|
||||||
import net.runelite.client.eventbus.Subscribe;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.inject.Inject;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.MenuEntry;
|
import net.runelite.api.MenuEntry;
|
||||||
import net.runelite.api.Player;
|
import net.runelite.api.Player;
|
||||||
import net.runelite.api.events.GameTick;
|
import net.runelite.api.events.MenuOpened;
|
||||||
import net.runelite.api.events.MenuEntryAdded;
|
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
import net.runelite.client.input.KeyManager;
|
import net.runelite.client.input.KeyManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
@@ -43,158 +44,174 @@ import net.runelite.client.plugins.PluginType;
|
|||||||
import net.runelite.client.util.MiscUtils;
|
import net.runelite.client.util.MiscUtils;
|
||||||
import net.runelite.client.util.Text;
|
import net.runelite.client.util.Text;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Menu Modifier",
|
name = "Menu Modifier",
|
||||||
description = "Changes right click menu for players",
|
description = "Changes right click menu for players",
|
||||||
tags = { "menu", "modifier", "right", "click", "pk", "bogla" },
|
tags = {"menu", "modifier", "right", "click", "pk", "bogla"},
|
||||||
enabledByDefault = false,
|
enabledByDefault = false,
|
||||||
type = PluginType.UTILITY
|
type = PluginType.UTILITY
|
||||||
)
|
)
|
||||||
public class MenuModifierPlugin extends Plugin
|
public class MenuModifierPlugin extends Plugin
|
||||||
{
|
{
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private MenuModifierConfig config;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private MenuModifierInputListener inputListener;
|
private MenuModifierConfig config;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private KeyManager keyManager;
|
private MenuModifierInputListener inputListener;
|
||||||
|
|
||||||
@Provides
|
@Inject
|
||||||
MenuModifierConfig provideConfig(ConfigManager configManager)
|
private KeyManager keyManager;
|
||||||
{
|
|
||||||
return configManager.getConfig(MenuModifierConfig.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void startUp() throws Exception
|
|
||||||
{
|
|
||||||
keyManager.registerKeyListener(inputListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void shutDown() throws Exception
|
|
||||||
{
|
|
||||||
keyManager.unregisterKeyListener(inputListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter(AccessLevel.PACKAGE)
|
@Provides
|
||||||
@Setter(AccessLevel.PACKAGE)
|
MenuModifierConfig provideConfig(ConfigManager configManager)
|
||||||
private boolean hotKeyPressed;
|
{
|
||||||
|
return configManager.getConfig(MenuModifierConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Override
|
||||||
public void onMenuOpened(MenuOpened event)
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
Player localPlayer = client.getLocalPlayer();
|
keyManager.registerKeyListener(inputListener);
|
||||||
|
}
|
||||||
if (localPlayer == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!(MiscUtils.getWildernessLevelFrom(client, localPlayer.getWorldLocation()) >= 0))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (hotKeyPressed)
|
@Override
|
||||||
return;
|
protected void shutDown() throws Exception
|
||||||
|
{
|
||||||
|
keyManager.unregisterKeyListener(inputListener);
|
||||||
|
}
|
||||||
|
|
||||||
List<MenuEntry> menu_entries = new ArrayList<MenuEntry>();
|
@Getter(AccessLevel.PACKAGE)
|
||||||
|
@Setter(AccessLevel.PACKAGE)
|
||||||
|
private boolean hotKeyPressed;
|
||||||
|
|
||||||
for (MenuEntry entry : event.getMenuEntries())
|
@Subscribe
|
||||||
{
|
public void onMenuOpened(MenuOpened event)
|
||||||
String option = Text.removeTags(entry.getOption()).toLowerCase();
|
{
|
||||||
|
Player localPlayer = client.getLocalPlayer();
|
||||||
|
|
||||||
if (option.contains("trade with") && config.hideTradeWith())
|
if (localPlayer == null)
|
||||||
continue;
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (option.contains("lookup") && config.hideLookup())
|
if (!(MiscUtils.getWildernessLevelFrom(client, localPlayer.getWorldLocation()) >= 0))
|
||||||
continue;
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (option.contains("report") && config.hideReport())
|
if (hotKeyPressed)
|
||||||
continue;
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (option.contains("examine") && config.hideExamine())
|
List<MenuEntry> menu_entries = new ArrayList<>();
|
||||||
continue;
|
|
||||||
|
for (MenuEntry entry : event.getMenuEntries())
|
||||||
|
{
|
||||||
|
String option = Text.removeTags(entry.getOption()).toLowerCase();
|
||||||
|
|
||||||
|
if (option.contains("trade with") && config.hideTradeWith())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (option.contains("lookup") && config.hideLookup())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (option.contains("report") && config.hideReport())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (option.contains("examine") && config.hideExamine())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (option.contains("net") && config.hideNet())
|
if (option.contains("net") && config.hideNet())
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (option.contains("bait") && config.hideBait())
|
if (option.contains("bait") && config.hideBait())
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int identifier = entry.getIdentifier();
|
int identifier = entry.getIdentifier();
|
||||||
|
|
||||||
Player[] players = client.getCachedPlayers();
|
Player[] players = client.getCachedPlayers();
|
||||||
Player player = null;
|
Player player = null;
|
||||||
|
|
||||||
if (identifier >= 0 && identifier < players.length)
|
if (identifier >= 0 && identifier < players.length)
|
||||||
player = players[identifier];
|
{
|
||||||
|
player = players[identifier];
|
||||||
|
}
|
||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
menu_entries.add(entry);
|
menu_entries.add(entry);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((option.contains("attack") || option.contains("cast")) && (player.isFriend() || player.isClanMember()))
|
if ((option.contains("attack") || option.contains("cast")) && (player.isFriend() || player.isClanMember()))
|
||||||
continue;
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
menu_entries.add(entry);
|
menu_entries.add(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuEntry[] updated_menu_entries = new MenuEntry[menu_entries.size()];
|
MenuEntry[] updated_menu_entries = new MenuEntry[menu_entries.size()];
|
||||||
updated_menu_entries = menu_entries.toArray(updated_menu_entries);
|
updated_menu_entries = menu_entries.toArray(updated_menu_entries);
|
||||||
|
|
||||||
client.setMenuEntries(updated_menu_entries);
|
client.setMenuEntries(updated_menu_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@Subscribe
|
/*@Subscribe
|
||||||
public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded)
|
public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded)
|
||||||
{
|
{
|
||||||
if (true)
|
if (true)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!inWilderness)
|
if (!inWilderness)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (hotKeyPressed)
|
if (hotKeyPressed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String option = Text.removeTags(menuEntryAdded.getOption()).toLowerCase();
|
|
||||||
|
|
||||||
if ((option.contains("trade with") && config.hideTradeWith())
|
String option = Text.removeTags(menuEntryAdded.getOption()).toLowerCase();
|
||||||
|| (option.contains("lookup") && config.hideLookup())
|
|
||||||
|| (option.contains("report") && config.hideReport())
|
|
||||||
|| (option.contains("examine") && config.hideExamine())
|
|
||||||
|| (option.contains("cancel") && config.hideCancel()))
|
|
||||||
{
|
|
||||||
int identifier = menuEntryAdded.getIdentifier();
|
|
||||||
|
|
||||||
Player[] players = client.getCachedPlayers();
|
if ((option.contains("trade with") && config.hideTradeWith())
|
||||||
Player player = null;
|
|| (option.contains("lookup") && config.hideLookup())
|
||||||
|
|| (option.contains("report") && config.hideReport())
|
||||||
|
|| (option.contains("examine") && config.hideExamine())
|
||||||
|
|| (option.contains("cancel") && config.hideCancel()))
|
||||||
|
{
|
||||||
|
int identifier = menuEntryAdded.getIdentifier();
|
||||||
|
|
||||||
if (identifier >= 0 && identifier < players.length)
|
Player[] players = client.getCachedPlayers();
|
||||||
player = players[identifier];
|
Player player = null;
|
||||||
|
|
||||||
if (player == null)
|
if (identifier >= 0 && identifier < players.length)
|
||||||
return;
|
player = players[identifier];
|
||||||
|
|
||||||
//allow trading with friends/clanmates
|
if (player == null)
|
||||||
if (option.contains("trade with") && (player.isFriend() || player.isClanMember()))
|
return;
|
||||||
return;
|
|
||||||
|
|
||||||
MenuEntry[] menuEntries = client.getMenuEntries();
|
//allow trading with friends/clanmates
|
||||||
|
if (option.contains("trade with") && (player.isFriend() || player.isClanMember()))
|
||||||
|
return;
|
||||||
|
|
||||||
if (menuEntries.length > 0)
|
MenuEntry[] menuEntries = client.getMenuEntries();
|
||||||
client.setMenuEntries(Arrays.copyOf(menuEntries, menuEntries.length - 1));
|
|
||||||
}
|
if (menuEntries.length > 0)
|
||||||
}*/
|
client.setMenuEntries(Arrays.copyOf(menuEntries, menuEntries.length - 1));
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user