diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/agility/AgilityPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/agility/AgilityPlugin.java index d283864740..54f2108588 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/agility/AgilityPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/agility/AgilityPlugin.java @@ -24,6 +24,7 @@ */ package net.runelite.client.plugins.agility; +import com.google.common.primitives.Ints; import com.google.inject.Provides; import java.awt.Color; import java.util.ArrayList; @@ -507,21 +508,17 @@ public class AgilityPlugin extends Plugin return; } - final int entryId = event.getIdentifier(); - MenuEntry[] menuEntries = client.getMenuEntries(); - for (Obstacle nearbyObstacle : getObstacles().values()) { AgilityShortcut shortcut = nearbyObstacle.getShortcut(); - if (shortcut != null && Arrays.stream(shortcut.getObstacleIds()).anyMatch(i -> i == entryId)) + if (shortcut != null && Ints.contains(shortcut.getObstacleIds(), event.getIdentifier())) { - MenuEntry entry = menuEntries[menuEntries.length - 1]; - int level = shortcut.getLevel(); - Color color = level <= getAgilityLevel() ? Color.GREEN : Color.RED; - String requirementText = " (level-" + level + ")"; + final MenuEntry entry = event.getMenuEntry(); + final int reqLevel = shortcut.getLevel(); + final String requirementText = ColorUtil.getLevelColorString(reqLevel, getAgilityLevel()) + " (level-" + reqLevel + ")"; - entry.setTarget(event.getTarget() + ColorUtil.prependColorTag(requirementText, color)); - client.setMenuEntries(menuEntries); + entry.setTarget(event.getTarget() + requirementText); + event.setWasModified(true); return; } } diff --git a/runelite-client/src/main/java/net/runelite/client/util/ColorUtil.java b/runelite-client/src/main/java/net/runelite/client/util/ColorUtil.java index 6012e1ae10..7b881f8f2f 100644 --- a/runelite-client/src/main/java/net/runelite/client/util/ColorUtil.java +++ b/runelite-client/src/main/java/net/runelite/client/util/ColorUtil.java @@ -267,4 +267,65 @@ public class ColorUtil } return (color & 0x00ffffff) | (alpha << 24); } + + /** + * Returns the color a ' (level-xxx)' would have, based on + * the difference between your and their level. + * This method is the same as in rs-client. + * + * @param theirLvl The level you're comparing against + * @param yourLvl Your level + */ + public static String getLevelColorString(final int theirLvl, final int yourLvl) + { + final int diff = yourLvl - theirLvl; + + if (diff < -9) + { + return colorStartTag(0xff0000); + } + else if (diff < -6) + { + return colorStartTag(0xff3000); + } + else if (diff < -3) + { + return colorStartTag(0xff7000); + } + else if (diff < 0) + { + return colorStartTag(0xffb000); + } + else if (diff > 9) + { + return colorStartTag(0x00ff00); + } + else if (diff > 6) + { + return colorStartTag(0x40ff00); + } + else if (diff > 3) + { + return colorStartTag(0x80ff00); + } + else if (diff > 0) + { + return colorStartTag(0xc0ff00); + } + else + { + return colorStartTag(0xffff00); + } + } + + /** + * Creates a color start tag from a rgb color as a int value + * + * @param rgb the int value of a rgb color + * @return a color tag which can be put in front of stuff + */ + public static String colorStartTag(final int rgb) + { + return "