Skip to content

Commit

Permalink
Setting for coloring the Report right-click option (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyborger1 authored Nov 9, 2022
1 parent 80f2d51 commit 8b1ed37
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Identifies bots by sending nearby players' information to a third-party machine
| 'Predict' Settings | 'Predict' Copy Name to Clipboard | Copies the predicted player's name to your clipboard when right-click predicting. |
| 'Predict' Settings | 'Predict' Default Color | If set, highlights unflagged/unfeedbacked players' 'Predict' option in the given color so that you can easily spot it on the in-game menu. |
| 'Predict' Settings | 'Predict' Voted/Flagged Color | If set, highlights flagged/feedbacked players' 'Predict' option in the given color so that you can easily spot it on the in-game menu. |
| 'Predict' Settings | Apply Colors to 'Report' | If set, applies the above 'Predict' color options to the in-game 'Report' option as well.<br>⚠️ May cause issues with other plugins that rely on the 'Report' option being unchanged.⚠️ |
| Other Settings | Enable Chat Status Messages | Inserts chat messages in your chatbox to inform you about your uploads being sent. |
| Other Settings | '!bdstats' Chat Command Detail Level | Enable processing the '!bdstats' command when it appears in the chatbox, which will fetch the message author's plugin stats and display them. Disable to reduce spam. |

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/botdetector/BotDetectorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@ default boolean predictOptionCopyName()
)
Color predictOptionFlaggedColor();

@ConfigItem(
position = 6,
keyName = "applyPredictColorsOnReportOption",
name = "Apply Colors to 'Report'",
description = "Applies the above 'Predict' color options to the in-game 'Report' option as well.",
section = predictSection,
warning = "Enabling this setting may cause issues with other plugins that rely on the 'Report' option being unchanged."
)
default boolean applyPredictColorsOnReportOption()
{
return false;
}

@ConfigItem(
position = 1,
keyName = "enableChatNotifications",
Expand Down
39 changes: 36 additions & 3 deletions src/main/java/com/botdetector/BotDetectorPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ private void onMenuOpened(MenuOpened event)
return;
}

boolean changeReportOption = config.applyPredictColorsOnReportOption();
// Do this once when the menu opens
// Avoids having to loop the menu entries on every 'added' event
MenuEntry[] menuEntries = event.getMenuEntries();
Expand All @@ -1016,16 +1017,28 @@ private void onMenuOpened(MenuOpened event)
entry.setOption(getPredictOption(player.getName()));
}
}

// Check for Report option
if (changeReportOption && entry.getOption().equals(REPORT_OPTION)
&& (PLAYER_MENU_ACTIONS.contains(entry.getType()) || entry.getType() == MenuAction.CC_OP_LOW_PRIORITY))
{
Player player = client.getCachedPlayers()[entry.getIdentifier()];
if (player != null)
{
entry.setOption(getReportOption(player.getName()));
}
}
}
}

@Subscribe
private void onMenuOptionClicked(MenuOptionClicked event)
{
String optionText = Text.removeTags(event.getMenuOption());
if (((event.getMenuAction() == MenuAction.RUNELITE || event.getMenuAction() == MenuAction.RUNELITE_PLAYER)
&& event.getMenuOption().endsWith(PREDICT_OPTION))
&& optionText.equals(PREDICT_OPTION))
|| (config.predictOnReport() && (PLAYER_MENU_ACTIONS.contains(event.getMenuAction()) || event.getMenuAction() == MenuAction.CC_OP_LOW_PRIORITY)
&& event.getMenuOption().equals(REPORT_OPTION)))
&& optionText.equals(REPORT_OPTION)))
{
String name;
if (event.getMenuAction() == MenuAction.RUNELITE_PLAYER
Expand Down Expand Up @@ -1167,12 +1180,32 @@ public String getUploaderName(boolean useAnonymousUUIDFormat)
* @return A variant of {@link #PREDICT_OPTION} prepended or not with some color.
*/
private String getPredictOption(String playerName)
{
return getMenuOption(playerName, PREDICT_OPTION);
}

/**
* Gets the correct variant of {@link #REPORT_OPTION} to show for the given {@code player}.
* @param playerName The player to get the menu option string for.
* @return A variant of {@link #REPORT_OPTION} prepended or not with some color.
*/
private String getReportOption(String playerName)
{
return getMenuOption(playerName, REPORT_OPTION);
}

/**
* Gets the correct variant of the given option string to show for the given {@code player}.
* @param playerName The player to get the menu option string for.
* @return A variant of the option string prepended or not with some color.
*/
private String getMenuOption(String playerName, String option)
{
CaseInsensitiveString name = normalizeAndWrapPlayerName(playerName);
Color prepend = (feedbackedPlayers.containsKey(name) || flaggedPlayers.containsKey(name)) ?
config.predictOptionFlaggedColor() : config.predictOptionDefaultColor();

return prepend != null ? ColorUtil.prependColorTag(PREDICT_OPTION, prepend) : PREDICT_OPTION;
return prepend != null ? ColorUtil.prependColorTag(option, prepend) : option;
}

/**
Expand Down

0 comments on commit 8b1ed37

Please sign in to comment.