Merge branch 'runelite' into question_mark_full_stop

# Conflicts:
#	runelite-api/src/main/java/com/openosrs/api/Varbits.java
#	runelite-api/src/main/java/net/runelite/api/kit/KitType.java
#	runelite-client/src/main/java/com/openosrs/client/util/ImageUtil.java
This commit is contained in:
ThatGamerBlue
2021-02-04 06:20:06 +00:00
167 changed files with 7357 additions and 610 deletions

View File

@@ -94,7 +94,7 @@ import org.slf4j.LoggerFactory;
@Slf4j
public class RuneLite
{
public static final File RUNELITE_DIR = new File(System.getProperty("user.home"), ".runelite");
public static final File RUNELITE_DIR = new File(System.getProperty("user.home"), ".openosrs");
public static final File CACHE_DIR = new File(RUNELITE_DIR, "cache");
public static final File PLUGINS_DIR = new File(RUNELITE_DIR, "plugins");
public static final File PROFILES_DIR = new File(RUNELITE_DIR, "profiles");
@@ -334,7 +334,7 @@ public class RuneLite
oprsExternalPluginManager.startExternalPluginManager();
// Update external plugins
//oprsExternalPluginManager.update(); //TODO: Re-enable after fixing actions for new repo
oprsExternalPluginManager.update(); //TODO: Re-enable after fixing actions for new repo
// Load the plugins, but does not start them yet.
// This will initialize configuration

View File

@@ -25,6 +25,7 @@
package net.runelite.client;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.gson.Gson;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.name.Names;
@@ -58,6 +59,7 @@ import net.runelite.client.plugins.PluginManager;
import net.runelite.client.task.Scheduler;
import net.runelite.client.util.DeferredEventBus;
import net.runelite.client.util.ExecutorServiceExceptionLogger;
import net.runelite.http.api.RuneLiteAPI;
import net.runelite.http.api.chat.ChatClient;
import okhttp3.OkHttpClient;
import org.slf4j.Logger;
@@ -95,6 +97,8 @@ public class RuneLiteModule extends AbstractModule
bind(PluginManager.class);
bind(SessionManager.class);
bind(Gson.class).toInstance(RuneLiteAPI.GSON);
bind(Callbacks.class).to(Hooks.class);
bind(EventBus.class)

View File

@@ -64,6 +64,7 @@ public class SessionManager
private final WSClient wsClient;
private final File sessionFile;
private final AccountClient accountClient;
private final Gson gson;
@Inject
private SessionManager(
@@ -71,13 +72,15 @@ public class SessionManager
ConfigManager configManager,
EventBus eventBus,
WSClient wsClient,
OkHttpClient okHttpClient)
OkHttpClient okHttpClient,
Gson gson)
{
this.configManager = configManager;
this.eventBus = eventBus;
this.wsClient = wsClient;
this.sessionFile = sessionfile;
this.accountClient = new AccountClient(okHttpClient);
this.gson = gson;
eventBus.register(this);
}
@@ -94,7 +97,7 @@ public class SessionManager
try (FileInputStream in = new FileInputStream(sessionFile))
{
session = new Gson().fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), AccountSession.class);
session = gson.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), AccountSession.class);
log.debug("Loaded session for {}", session.getUsername());
}
@@ -124,7 +127,7 @@ public class SessionManager
try (Writer fw = new OutputStreamWriter(new FileOutputStream(sessionFile), StandardCharsets.UTF_8))
{
new Gson().toJson(accountSession, fw);
gson.toJson(accountSession, fw);
log.debug("Saved session to {}", sessionFile);
}

View File

@@ -24,6 +24,8 @@
*/
package net.runelite.client.config;
import com.openosrs.client.OpenOSRS;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -48,4 +50,11 @@ public @interface ConfigItem
boolean secret() default false;
String section() default "";
/*
OpenOSRS Lazy Helpers tm
*/
Class<?> enumClass() default OpenOSRS.class;
String unhide() default "";
String hide() default "";
}

View File

@@ -394,7 +394,7 @@ public class ConfigManager
parent.mkdirs();
File tempFile = new File(parent, RuneLite.DEFAULT_CONFIG_FILE.getName() + ".tmp");
File tempFile = File.createTempFile("runelite", null, parent);
try (FileOutputStream out = new FileOutputStream(tempFile))
{

View File

@@ -40,4 +40,12 @@ public @interface ConfigSection
int position();
boolean closedByDefault() default false;
/*
OpenOSRS Lazy Helpers tm
*/
String keyName() default "";
String section() default "";
boolean hidden() default false;
String unhide() default "";
}

View File

@@ -159,7 +159,7 @@ public class Keybind
String mod = "";
if (modifiers != 0)
{
mod = getModifiersExText(modifiers);
mod = InputEvent.getModifiersExText(modifiers);
}
if (mod.isEmpty() && key.isEmpty())
@@ -177,33 +177,6 @@ public class Keybind
return mod;
}
public static String getModifiersExText(int modifiers)
{
StringBuilder buf = new StringBuilder();
if ((modifiers & InputEvent.META_DOWN_MASK) != 0)
{
buf.append("Meta+");
}
if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0)
{
buf.append("Ctrl+");
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0)
{
buf.append("Alt+");
}
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0)
{
buf.append("Shift+");
}
if (buf.length() > 0)
{
buf.setLength(buf.length() - 1); // remove trailing '+'
}
return buf.toString();
}
@Nullable
public static Integer getModifierForKeyCode(int keyCode)
{

View File

@@ -42,8 +42,12 @@ public @interface Units
String MINUTES = " mins";
String PERCENT = "%";
String PIXELS = "px";
String POINTS = "pt";
String SECONDS = "s";
String TICKS = " ticks";
String LEVELS = " lvls";
String FPS = " fps";
String GP = " GP";
String value();
}

View File

@@ -24,18 +24,32 @@
*/
package net.runelite.client.externalplugins;
import java.lang.invoke.MethodHandles;
import java.net.URL;
import java.net.URLClassLoader;
import lombok.Getter;
import lombok.Setter;
import net.runelite.client.util.ReflectUtil;
class ExternalPluginClassLoader extends URLClassLoader
class ExternalPluginClassLoader extends URLClassLoader implements ReflectUtil.PrivateLookupableClassLoader
{
@Getter
private final ExternalPluginManifest manifest;
@Getter
@Setter
private MethodHandles.Lookup lookup;
ExternalPluginClassLoader(ExternalPluginManifest manifest, URL[] urls)
{
super(urls, ExternalPluginClassLoader.class.getClassLoader());
this.manifest = manifest;
ReflectUtil.installLookupHelper(this);
}
@Override
public Class<?> defineClass0(String name, byte[] b, int off, int len) throws ClassFormatError
{
return super.defineClass(name, b, off, len);
}
}

View File

@@ -25,6 +25,7 @@
package net.runelite.client.externalplugins;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
@@ -59,11 +60,13 @@ import okio.BufferedSource;
public class ExternalPluginClient
{
private final OkHttpClient okHttpClient;
private final Gson gson;
@Inject
private ExternalPluginClient(OkHttpClient okHttpClient)
private ExternalPluginClient(OkHttpClient okHttpClient, Gson gson)
{
this.okHttpClient = okHttpClient;
this.gson = gson;
}
public List<ExternalPluginManifest> downloadManifest() throws IOException, VerificationException
@@ -94,7 +97,7 @@ public class ExternalPluginClient
throw new VerificationException("Unable to verify external plugin manifest");
}
return RuneLiteAPI.GSON.fromJson(new String(data, StandardCharsets.UTF_8),
return gson.fromJson(new String(data, StandardCharsets.UTF_8),
new TypeToken<List<ExternalPluginManifest>>()
{
}.getType());
@@ -156,7 +159,7 @@ public class ExternalPluginClient
Request request = new Request.Builder()
.url(url)
.post(RequestBody.create(RuneLiteAPI.JSON, RuneLiteAPI.GSON.toJson(plugins)))
.post(RequestBody.create(RuneLiteAPI.JSON, gson.toJson(plugins)))
.build();
okHttpClient.newCall(request).enqueue(new Callback()
@@ -190,7 +193,7 @@ public class ExternalPluginClient
}
// CHECKSTYLE:OFF
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(res.body().byteStream()), new TypeToken<Map<String, Integer>>(){}.getType());
return gson.fromJson(new InputStreamReader(res.body().byteStream()), new TypeToken<Map<String, Integer>>(){}.getType());
// CHECKSTYLE:ON
}
catch (JsonSyntaxException ex)

View File

@@ -237,7 +237,7 @@ public enum AgilityShortcut
@Getter
private final int level;
/**
* Brief description of the shortcut (e.g. 'Rocks', 'Stepping Stones', 'Jump')
* Brief description of the shortcut. (e.g. 'Rocks', 'Stepping Stones', 'Jump')
*/
@Getter
private final String description;

View File

@@ -26,33 +26,25 @@ 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.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import java.util.Arrays;
import java.util.Collection;
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;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.NpcActionChanged;
import net.runelite.api.events.PlayerMenuOptionClicked;
import net.runelite.api.events.PlayerMenuOptionsChanged;
import net.runelite.api.events.WidgetMenuOptionClicked;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.util.Text;
@Singleton
@Slf4j
@@ -64,16 +56,13 @@ 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;
//Maps the indexes that are being used to the menu option.
private final Map<Integer, String> playerMenuIndexMap = new HashMap<>();
//Used to manage custom non-player menu options
private final Multimap<Integer, WidgetMenuOption> managedMenuOptions = HashMultimap.create();
private final Set<String> npcMenuOptions = new HashSet<>();
private final Multimap<Integer, WidgetMenuOption> managedMenuOptions = LinkedHashMultimap.create();
@Inject
@VisibleForTesting
@@ -123,7 +112,7 @@ public class MenuManager
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
if (client.getSpellSelected())
if (client.getSpellSelected() || event.getType() != MenuAction.CC_OP.getId())
{
return;
}
@@ -200,45 +189,12 @@ public class MenuManager
addPlayerMenuItem(newIdx, menuText);
}
@Subscribe
public void onNpcActionChanged(NpcActionChanged event)
{
NPCComposition composition = event.getNpcComposition();
for (String npcOption : npcMenuOptions)
{
addNpcOption(composition, npcOption);
}
}
private void addNpcOption(NPCComposition composition, String npcOption)
{
String[] actions = composition.getActions();
int unused = -1;
for (int i = 0; i < actions.length; ++i)
{
if (actions[i] == null && unused == -1)
{
unused = i;
}
else if (actions[i] != null && actions[i].equals(npcOption))
{
return;
}
}
if (unused == -1)
{
return;
}
actions[unused] = npcOption;
}
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
if (event.getMenuAction() != MenuAction.RUNELITE
&& event.getMenuAction() != MenuAction.RUNELITE_PLAYER)
if (event.getMenuAction() != MenuAction.RUNELITE)
{
return; // not a managed widget option or custom player option
return;
}
int widgetId = event.getWidgetId();
@@ -254,23 +210,9 @@ public class MenuManager
customMenu.setMenuTarget(event.getMenuTarget());
customMenu.setWidget(curMenuOption.getWidget());
eventBus.post(customMenu);
return; // don't continue because it's not a player option
return;
}
}
// 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>
String username = Text.removeTags(target).split("[(]")[0].trim();
PlayerMenuOptionClicked playerMenuOptionClicked = new PlayerMenuOptionClicked();
playerMenuOptionClicked.setMenuOption(event.getMenuOption());
playerMenuOptionClicked.setMenuTarget(username);
eventBus.post(playerMenuOptionClicked);
}
private void addPlayerMenuItem(int playerOptionIndex, String menuText)

View File

@@ -33,11 +33,11 @@ import net.runelite.client.util.ColorUtil;
public final class WidgetMenuOption
{
/**
* The left hand text to be displayed on the menu option. Ex. the menuOption of "Drop Bones" is "Drop"
* The left hand text to be displayed on the menu option. (ex. the menuOption of "Drop Bones" is "Drop")
*/
private String menuOption;
/**
* The right hand text to be displayed on the menu option Ex. the menuTarget of "Drop Bones" is "Bones"
* The right hand text to be displayed on the menu option. (ex. the menuTarget of "Drop Bones" is "Bones")
*/
private String menuTarget;
/**

View File

@@ -34,6 +34,7 @@ import static net.runelite.api.MenuAction.RUNELITE_OVERLAY_CONFIG;
import net.runelite.api.Varbits;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.ui.FontManager;
import static net.runelite.client.ui.overlay.OverlayManager.OPTION_CONFIGURE;
import net.runelite.client.ui.overlay.OverlayMenuEntry;
import net.runelite.client.ui.overlay.OverlayPanel;
@@ -82,6 +83,7 @@ public class BarrowsBrotherSlainOverlay extends OverlayPanel
panelComponent.getChildren().add(LineComponent.builder()
.left(brother.getName())
.right(slain)
.rightFont(FontManager.getDefaultFont())
.rightColor(brotherSlain ? Color.GREEN : Color.RED)
.build());
}

View File

@@ -45,6 +45,7 @@ import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import static net.runelite.client.plugins.cluescrolls.ClueScrollOverlay.TITLED_CONTENT_COLOR;
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;
import static net.runelite.client.plugins.cluescrolls.clues.Enemy.*;
import net.runelite.client.plugins.cluescrolls.clues.emote.Emote;
import static net.runelite.client.plugins.cluescrolls.clues.emote.Emote.*;
import static net.runelite.client.plugins.cluescrolls.clues.emote.Emote.BULL_ROARER;
@@ -53,7 +54,7 @@ import static net.runelite.client.plugins.cluescrolls.clues.emote.STASHUnit.*;
import static net.runelite.client.plugins.cluescrolls.clues.emote.STASHUnit.SHANTAY_PASS;
import net.runelite.client.plugins.cluescrolls.clues.item.ItemRequirement;
import static net.runelite.client.plugins.cluescrolls.clues.item.ItemRequirements.*;
import static net.runelite.client.plugins.cluescrolls.clues.Enemy.*;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
@@ -258,6 +259,7 @@ public class EmoteClue extends ClueScroll implements TextClueScroll, LocationClu
panelComponent.getChildren().add(LineComponent.builder()
.left("STASH Unit:")
.right(stashUnitBuilt ? UNICODE_CHECK_MARK : UNICODE_BALLOT_X)
.rightFont(FontManager.getDefaultFont())
.rightColor(stashUnitBuilt ? Color.GREEN : Color.RED)
.build());
}
@@ -292,6 +294,7 @@ public class EmoteClue extends ClueScroll implements TextClueScroll, LocationClu
.left(requirement.getCollectiveName(client))
.leftColor(TITLED_CONTENT_COLOR)
.right(combinedFulfilled ? UNICODE_CHECK_MARK : UNICODE_BALLOT_X)
.rightFont(FontManager.getDefaultFont())
.rightColor(equipmentFulfilled ? Color.GREEN : (combinedFulfilled ? Color.ORANGE : Color.RED))
.build());
}

View File

@@ -41,6 +41,7 @@ import net.runelite.client.plugins.cluescrolls.clues.item.AnyRequirementCollecti
import net.runelite.client.plugins.cluescrolls.clues.item.ItemRequirement;
import net.runelite.client.plugins.cluescrolls.clues.item.RangeItemRequirement;
import net.runelite.client.plugins.cluescrolls.clues.item.SingleItemRequirement;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
@@ -134,6 +135,7 @@ public class FaloTheBardClue extends ClueScroll implements TextClueScroll, NpcCl
.left(requirement.getCollectiveName(plugin.getClient()))
.leftColor(TITLED_CONTENT_COLOR)
.right(inventoryFulfilled ? "\u2713" : "\u2717")
.rightFont(FontManager.getDefaultFont())
.rightColor(inventoryFulfilled ? Color.GREEN : Color.RED)
.build());
}

View File

@@ -25,6 +25,11 @@
package net.runelite.client.plugins.cluescrolls.clues;
import com.google.common.collect.ImmutableSet;
import java.awt.Color;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@@ -34,25 +39,21 @@ import net.runelite.api.ItemID;
import net.runelite.api.NPC;
import net.runelite.api.Point;
import net.runelite.api.TileObject;
import static net.runelite.client.plugins.cluescrolls.ClueScrollOverlay.TITLED_CONTENT_COLOR;
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.CLICKBOX_BORDER_COLOR;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.CLICKBOX_FILL_COLOR;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.CLICKBOX_HOVER_BORDER_COLOR;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.IMAGE_Z_OFFSET;
import net.runelite.client.plugins.cluescrolls.clues.item.AnyRequirementCollection;
import static net.runelite.client.plugins.cluescrolls.clues.item.ItemRequirements.*;
import net.runelite.client.plugins.cluescrolls.clues.item.ItemRequirement;
import static net.runelite.client.plugins.cluescrolls.clues.item.ItemRequirements.*;
import net.runelite.client.plugins.cluescrolls.clues.item.SingleItemRequirement;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
import java.awt.Color;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import static net.runelite.client.plugins.cluescrolls.ClueScrollOverlay.TITLED_CONTENT_COLOR;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.IMAGE_Z_OFFSET;
@Getter
public class SkillChallengeClue extends ClueScroll implements NpcClueScroll, NamedObjectClueScroll
@@ -379,6 +380,7 @@ public class SkillChallengeClue extends ClueScroll implements NpcClueScroll, Nam
.left(requirement.getCollectiveName(plugin.getClient()))
.leftColor(TITLED_CONTENT_COLOR)
.right(combinedFulfilled ? "\u2713" : "\u2717")
.rightFont(FontManager.getDefaultFont())
.rightColor(equipmentFulfilled || (combinedFulfilled && !requireEquipped) ? Color.GREEN : (combinedFulfilled ? Color.ORANGE : Color.RED))
.build());
}

View File

@@ -32,6 +32,7 @@ import javax.swing.JButton;
import lombok.Getter;
import net.runelite.client.config.Keybind;
import net.runelite.client.config.ModifierlessKeybind;
import net.runelite.client.ui.FontManager;
class HotkeyButton extends JButton
{
@@ -40,6 +41,7 @@ class HotkeyButton extends JButton
public HotkeyButton(Keybind value, boolean modifierless)
{
setFont(FontManager.getDefaultFont().deriveFont(12.f));
setValue(value);
addMouseListener(new MouseAdapter()
{

View File

@@ -32,7 +32,6 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import net.runelite.http.api.RuneLiteAPI;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
@@ -47,11 +46,13 @@ public class CrowdsourcingManager
{
private static final String CROWDSOURCING_BASE = "https://crowdsource.runescape.wiki/runelite";
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
private static final Gson GSON = RuneLiteAPI.GSON;
@Inject
private OkHttpClient okHttpClient;
@Inject
private Gson gson;
private List<Object> data = new ArrayList<>();
public void storeEvent(Object event)
@@ -77,7 +78,7 @@ public class CrowdsourcingManager
Request r = new Request.Builder()
.url(CROWDSOURCING_BASE)
.post(RequestBody.create(JSON, GSON.toJson(temp)))
.post(RequestBody.create(JSON, gson.toJson(temp)))
.build();
okHttpClient.newCall(r).enqueue(new Callback()

View File

@@ -470,7 +470,7 @@ enum DiscordGameEventType
private int priority;
/**
* Marks this event as root event, e.g event that should be used for total time tracking
* Marks this event as root event. (eg. event that should be used for total time tracking)
*/
private boolean root;

View File

@@ -128,7 +128,6 @@ public class GrandExchangePlugin extends Plugin
private static final String BUY_LIMIT_GE_TEXT = "<br>Buy limit: ";
private static final String BUY_LIMIT_KEY = "buylimit";
private static final Gson GSON = new Gson();
private static final Duration BUY_LIMIT_RESET = Duration.ofHours(4);
static final String SEARCH_GRAND_EXCHANGE = "Search Grand Exchange";
@@ -183,6 +182,9 @@ public class GrandExchangePlugin extends Plugin
@Inject
private ConfigManager configManager;
@Inject
private Gson gson;
private Widget grandExchangeText;
private Widget grandExchangeItem;
private String grandExchangeExamine;
@@ -253,12 +255,12 @@ public class GrandExchangePlugin extends Plugin
{
return null;
}
return GSON.fromJson(offer, SavedOffer.class);
return gson.fromJson(offer, SavedOffer.class);
}
private void setOffer(int slot, SavedOffer offer)
{
configManager.setRSProfileConfiguration("geoffer", Integer.toString(slot), GSON.toJson(offer));
configManager.setRSProfileConfiguration("geoffer", Integer.toString(slot), gson.toJson(offer));
}
private void deleteOffer(int slot)

View File

@@ -51,6 +51,7 @@ import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.chatbox.ChatboxPanelManager;
import net.runelite.client.plugins.Plugin;
@@ -72,8 +73,6 @@ public class GroundMarkerPlugin extends Plugin
private static final String WALK_HERE = "Walk here";
private static final String REGION_PREFIX = "region_";
private static final Gson GSON = new Gson();
@Getter(AccessLevel.PACKAGE)
private final List<ColorTileMarker> points = new ArrayList<>();
@@ -98,7 +97,16 @@ public class GroundMarkerPlugin extends Plugin
@Inject
private ChatboxPanelManager chatboxPanelManager;
private void savePoints(int regionId, Collection<GroundMarkerPoint> points)
@Inject
private EventBus eventBus;
@Inject
private GroundMarkerSharingManager sharingManager;
@Inject
private Gson gson;
void savePoints(int regionId, Collection<GroundMarkerPoint> points)
{
if (points == null || points.isEmpty())
{
@@ -106,11 +114,11 @@ public class GroundMarkerPlugin extends Plugin
return;
}
String json = GSON.toJson(points);
String json = gson.toJson(points);
configManager.setConfiguration(CONFIG_GROUP, REGION_PREFIX + regionId, json);
}
private Collection<GroundMarkerPoint> getPoints(int regionId)
Collection<GroundMarkerPoint> getPoints(int regionId)
{
String json = configManager.getConfiguration(CONFIG_GROUP, REGION_PREFIX + regionId);
if (Strings.isNullOrEmpty(json))
@@ -119,7 +127,7 @@ public class GroundMarkerPlugin extends Plugin
}
// CHECKSTYLE:OFF
return GSON.fromJson(json, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
return gson.fromJson(json, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
// CHECKSTYLE:ON
}
@@ -129,7 +137,7 @@ public class GroundMarkerPlugin extends Plugin
return configManager.getConfig(GroundMarkerConfig.class);
}
private void loadPoints()
void loadPoints()
{
points.clear();
@@ -181,14 +189,18 @@ public class GroundMarkerPlugin extends Plugin
{
overlayManager.add(overlay);
overlayManager.add(minimapOverlay);
sharingManager.addMenuOptions();
loadPoints();
eventBus.register(sharingManager);
}
@Override
public void shutDown()
{
eventBus.unregister(sharingManager);
overlayManager.remove(overlay);
overlayManager.remove(minimapOverlay);
sharingManager.removeMenuOptions();
points.clear();
}

View File

@@ -0,0 +1,243 @@
/*
* Copyright (c) 2021, Adam <Adam@sigterm.info>
* 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.plugins.groundmarkers;
import com.google.common.base.Strings;
import com.google.common.util.concurrent.Runnables;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.events.WidgetMenuOptionClicked;
import static net.runelite.api.widgets.WidgetInfo.WORLD_MAP_OPTION;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.chat.QueuedMessage;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.chatbox.ChatboxPanelManager;
import net.runelite.client.menus.MenuManager;
import net.runelite.client.menus.WidgetMenuOption;
@Slf4j
class GroundMarkerSharingManager
{
private static final WidgetMenuOption EXPORT_MARKERS_OPTION = new WidgetMenuOption("Export", "Ground Markers", WORLD_MAP_OPTION);
private static final WidgetMenuOption IMPORT_MARKERS_OPTION = new WidgetMenuOption("Import", "Ground Markers", WORLD_MAP_OPTION);
private final GroundMarkerPlugin plugin;
private final Client client;
private final MenuManager menuManager;
private final ChatMessageManager chatMessageManager;
private final ChatboxPanelManager chatboxPanelManager;
private final Gson gson;
@Inject
private GroundMarkerSharingManager(GroundMarkerPlugin plugin, Client client, MenuManager menuManager,
ChatMessageManager chatMessageManager, ChatboxPanelManager chatboxPanelManager, Gson gson)
{
this.plugin = plugin;
this.client = client;
this.menuManager = menuManager;
this.chatMessageManager = chatMessageManager;
this.chatboxPanelManager = chatboxPanelManager;
this.gson = gson;
}
void addMenuOptions()
{
menuManager.addManagedCustomMenu(EXPORT_MARKERS_OPTION);
menuManager.addManagedCustomMenu(IMPORT_MARKERS_OPTION);
}
void removeMenuOptions()
{
menuManager.removeManagedCustomMenu(EXPORT_MARKERS_OPTION);
menuManager.removeManagedCustomMenu(IMPORT_MARKERS_OPTION);
}
private boolean widgetMenuClickedEquals(final WidgetMenuOptionClicked event, final WidgetMenuOption target)
{
return event.getMenuTarget().equals(target.getMenuTarget()) &&
event.getMenuOption().equals(target.getMenuOption());
}
@Subscribe
public void onWidgetMenuOptionClicked(WidgetMenuOptionClicked event)
{
// ensure that the option clicked is the export markers option
if (event.getWidget() != WORLD_MAP_OPTION)
{
return;
}
if (widgetMenuClickedEquals(event, EXPORT_MARKERS_OPTION))
{
exportGroundMarkers();
}
else if (widgetMenuClickedEquals(event, IMPORT_MARKERS_OPTION))
{
promptForImport();
}
}
private void exportGroundMarkers()
{
int[] regions = client.getMapRegions();
if (regions == null)
{
return;
}
List<GroundMarkerPoint> activePoints = Arrays.stream(regions)
.mapToObj(regionId -> plugin.getPoints(regionId).stream())
.flatMap(Function.identity())
.collect(Collectors.toList());
if (activePoints.isEmpty())
{
sendChatMessage("You have no ground markers to export.");
return;
}
final String exportDump = gson.toJson(activePoints);
log.debug("Exported ground markers: {}", exportDump);
Toolkit.getDefaultToolkit()
.getSystemClipboard()
.setContents(new StringSelection(exportDump), null);
sendChatMessage(activePoints.size() + " ground markers were copied to your clipboard.");
}
private void promptForImport()
{
final String clipboardText;
try
{
clipboardText = Toolkit.getDefaultToolkit()
.getSystemClipboard()
.getData(DataFlavor.stringFlavor)
.toString();
}
catch (IOException | UnsupportedFlavorException ex)
{
sendChatMessage("Unable to read system clipboard.");
log.warn("error reading clipboard", ex);
return;
}
log.debug("Clipboard contents: {}", clipboardText);
if (Strings.isNullOrEmpty(clipboardText))
{
sendChatMessage("You do not have any ground markers copied in your clipboard.");
return;
}
List<GroundMarkerPoint> importPoints;
try
{
// CHECKSTYLE:OFF
importPoints = gson.fromJson(clipboardText, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
// CHECKSTYLE:ON
}
catch (JsonSyntaxException e)
{
log.debug("Malformed JSON for clipboard import", e);
sendChatMessage("You do not have any ground markers copied in your clipboard.");
return;
}
if (importPoints.isEmpty())
{
sendChatMessage("You do not have any ground markers copied in your clipboard.");
return;
}
chatboxPanelManager.openTextMenuInput("Are you sure you want to import " + importPoints.size() + " ground markers?")
.option("Yes", () -> importGroundMarkers(importPoints))
.option("No", Runnables::doNothing)
.build();
}
private void importGroundMarkers(Collection<GroundMarkerPoint> importPoints)
{
// regions being imported may not be loaded on client,
// so need to import each bunch directly into the config
// first, collate the list of unique region ids in the import
Map<Integer, List<GroundMarkerPoint>> regionGroupedPoints = importPoints.stream()
.collect(Collectors.groupingBy(GroundMarkerPoint::getRegionId));
// now import each region into the config
regionGroupedPoints.forEach((regionId, groupedPoints) ->
{
// combine imported points with existing region points
log.debug("Importing {} points to region {}", groupedPoints.size(), regionId);
Collection<GroundMarkerPoint> regionPoints = plugin.getPoints(regionId);
List<GroundMarkerPoint> mergedList = new ArrayList<>(regionPoints.size() + groupedPoints.size());
// add existing points
mergedList.addAll(regionPoints);
// add new points
for (GroundMarkerPoint point : groupedPoints)
{
// filter out duplicates
if (!mergedList.contains(point))
{
mergedList.add(point);
}
}
plugin.savePoints(regionId, mergedList);
});
// reload points from config
log.debug("Reloading points after import");
plugin.loadPoints();
sendChatMessage(importPoints.size() + " ground markers were imported from the clipboard.");
}
private void sendChatMessage(final String message)
{
chatMessageManager.queue(QueuedMessage.builder()
.type(ChatMessageType.CONSOLE)
.runeLiteFormattedMessage(message)
.build());
}
}

View File

@@ -38,9 +38,10 @@ import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry;
import net.runelite.api.Player;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.PlayerMenuOptionClicked;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
@@ -174,11 +175,30 @@ public class HiscorePlugin extends Plugin
}
@Subscribe
public void onPlayerMenuOptionClicked(PlayerMenuOptionClicked event)
public void onMenuOptionClicked(MenuOptionClicked event)
{
if (event.getMenuOption().equals(LOOKUP))
if ((event.getMenuAction() == MenuAction.RUNELITE || event.getMenuAction() == MenuAction.RUNELITE_PLAYER)
&& event.getMenuOption().equals(LOOKUP))
{
lookupPlayer(Text.removeTags(event.getMenuTarget()));
final String target;
if (event.getMenuAction() == MenuAction.RUNELITE_PLAYER)
{
// The player id is included in the event, so we can use that to get the player name,
// which avoids having to parse out the combat level and any icons preceding the name.
Player player = client.getCachedPlayers()[event.getId()];
if (player == null)
{
return;
}
target = player.getName();
}
else
{
target = Text.removeTags(event.getMenuTarget());
}
lookupPlayer(target);
}
}

View File

@@ -27,6 +27,7 @@ package net.runelite.client.plugins.idlenotifier;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Range;
import net.runelite.client.config.Units;
@ConfigGroup("idlenotifier")
@@ -110,10 +111,36 @@ public interface IdleNotifierConfig extends Config
return 0;
}
@ConfigItem(
keyName = "lowEnergy",
name = "Low Energy Threshold",
description = "The amount of energy points remaining to send a notification at. A value of 100 will disable notification.",
position = 8
)
@Units(Units.PERCENT)
@Range(max = 100)
default int getLowEnergyThreshold()
{
return 100;
}
@ConfigItem(
keyName = "highEnergy",
name = "High Energy Threshold",
description = "The amount of energy points reached to send a notification. A value of 0 will disable notification.",
position = 9
)
@Units(Units.PERCENT)
@Range(max = 100)
default int getHighEnergyThreshold()
{
return 0;
}
@ConfigItem(
keyName = "oxygen",
name = "Oxygen Threshold",
position = 8,
position = 10,
description = "The amount of remaining oxygen to send a notification at. A value of 0 will disable notification."
)
@Units(Units.PERCENT)
@@ -125,7 +152,7 @@ public interface IdleNotifierConfig extends Config
@ConfigItem(
keyName = "spec",
name = "Spec Threshold",
position = 9,
position = 11,
description = "The amount of special attack energy reached to send a notification at. A value of 0 will disable notification."
)
@Units(Units.PERCENT)

View File

@@ -93,6 +93,8 @@ public class IdleNotifierPlugin extends Plugin
private boolean notifyPosition = false;
private boolean notifyHitpoints = true;
private boolean notifyPrayer = true;
private boolean shouldNotifyLowEnergy = false;
private boolean shouldNotifyHighEnergy = false;
private boolean notifyOxygen = true;
private boolean notifyIdleLogout = true;
private boolean notify6HourLogout = true;
@@ -471,6 +473,16 @@ public class IdleNotifierPlugin extends Plugin
notifier.notify("[" + local.getName() + "] has low prayer!");
}
if (checkLowEnergy())
{
notifier.notify("[" + local.getName() + "] has low run energy!");
}
if (checkHighEnergy())
{
notifier.notify("[" + local.getName() + "] has restored run energy!");
}
if (checkLowOxygen())
{
notifier.notify("[" + local.getName() + "] has low oxygen!");
@@ -572,6 +584,52 @@ public class IdleNotifierPlugin extends Plugin
return false;
}
private boolean checkLowEnergy()
{
if (config.getLowEnergyThreshold() >= 100)
{
return false;
}
if (client.getEnergy() <= config.getLowEnergyThreshold())
{
if (shouldNotifyLowEnergy)
{
shouldNotifyLowEnergy = false;
return true;
}
}
else
{
shouldNotifyLowEnergy = true;
}
return false;
}
private boolean checkHighEnergy()
{
if (config.getHighEnergyThreshold() == 0)
{
return false;
}
if (client.getEnergy() >= config.getHighEnergyThreshold())
{
if (shouldNotifyHighEnergy)
{
shouldNotifyHighEnergy = false;
return true;
}
}
else
{
shouldNotifyHighEnergy = true;
}
return false;
}
private boolean checkInteractionIdle(Duration waitDuration, Player local)
{
if (lastInteract == null)

View File

@@ -28,20 +28,74 @@ import java.awt.Color;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.ConfigSection;
import net.runelite.client.config.Range;
@ConfigGroup("inventorytags")
@ConfigGroup(InventoryTagsConfig.GROUP)
public interface InventoryTagsConfig extends Config
{
enum DisplayMode
{
OUTLINE,
UNDERLINE
}
String GROUP = "inventorytags";
@ConfigSection(
name = "Tag display mode",
description = "How tags are displayed in the inventory",
position = 0
)
String tagStyleSection = "tagStyleSection";
@ConfigItem(
position = 0,
keyName = "showTagOutline",
name = "Outline",
description = "Configures whether or not item tags show be outlined",
section = tagStyleSection
)
default boolean showTagOutline()
{
return true;
}
@ConfigItem(
position = 1,
keyName = "tagUnderline",
name = "Underline",
description = "Configures whether or not item tags should be underlined",
section = tagStyleSection
)
default boolean showTagUnderline()
{
return false;
}
@ConfigItem(
position = 2,
keyName = "tagFill",
name = "Fill",
description = "Configures whether or not item tags should be filled",
section = tagStyleSection
)
default boolean showTagFill()
{
return false;
}
@Range(
max = 255
)
@ConfigItem(
position = 3,
keyName = "fillOpacity",
name = "Fill opacity",
description = "Configures the opacity of the tag \"Fill\"",
section = tagStyleSection
)
default int fillOpacity()
{
return 50;
}
@ConfigItem(
position = 1,
keyName = "groupColor1",
name = "Group 1 Color",
description = "Color of the Tag"
@@ -52,7 +106,7 @@ public interface InventoryTagsConfig extends Config
}
@ConfigItem(
position = 1,
position = 2,
keyName = "groupColor2",
name = "Group 2 Color",
description = "Color of the Tag"
@@ -63,7 +117,7 @@ public interface InventoryTagsConfig extends Config
}
@ConfigItem(
position = 2,
position = 3,
keyName = "groupColor3",
name = "Group 3 Color",
description = "Color of the Tag"
@@ -74,7 +128,7 @@ public interface InventoryTagsConfig extends Config
}
@ConfigItem(
position = 3,
position = 4,
keyName = "groupColor4",
name = "Group 4 Color",
description = "Color of the Tag"
@@ -85,7 +139,7 @@ public interface InventoryTagsConfig extends Config
}
@ConfigItem(
position = 4,
position = 5,
keyName = "groupColor5",
name = "Group 5 Color",
description = "Color of the Tag"
@@ -96,7 +150,7 @@ public interface InventoryTagsConfig extends Config
}
@ConfigItem(
position = 5,
position = 6,
keyName = "groupColor6",
name = "Group 6 Color",
description = "Color of the Tag"
@@ -105,15 +159,4 @@ public interface InventoryTagsConfig extends Config
{
return new Color(0, 255, 255);
}
@ConfigItem(
position = 6,
keyName = "displayMode",
name = "Display mode",
description = "How tags are displayed in the inventory"
)
default DisplayMode getDisplayMode()
{
return DisplayMode.OUTLINE;
}
}

View File

@@ -24,21 +24,26 @@
*/
package net.runelite.client.plugins.inventorytags;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import javax.inject.Inject;
import net.runelite.api.widgets.WidgetItem;
import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.inventorytags.InventoryTagsConfig.DisplayMode;
import net.runelite.client.ui.overlay.WidgetItemOverlay;
import net.runelite.client.util.ColorUtil;
import net.runelite.client.util.ImageUtil;
public class InventoryTagsOverlay extends WidgetItemOverlay
{
private final ItemManager itemManager;
private final InventoryTagsPlugin plugin;
private final InventoryTagsConfig config;
private final Cache<Long, Image> fillCache;
@Inject
private InventoryTagsOverlay(ItemManager itemManager, InventoryTagsPlugin plugin, InventoryTagsConfig config)
@@ -48,6 +53,10 @@ public class InventoryTagsOverlay extends WidgetItemOverlay
this.config = config;
showOnEquipment();
showOnInventory();
fillCache = CacheBuilder.newBuilder()
.concurrencyLevel(1)
.maximumSize(32)
.build();
}
@Override
@@ -57,16 +66,22 @@ public class InventoryTagsOverlay extends WidgetItemOverlay
if (group != null)
{
final Color color = plugin.getGroupNameColor(group);
final DisplayMode displayMode = config.getDisplayMode();
if (color != null)
{
Rectangle bounds = widgetItem.getCanvasBounds();
if (displayMode == DisplayMode.OUTLINE)
if (config.showTagOutline())
{
final BufferedImage outline = itemManager.getItemOutline(itemId, widgetItem.getQuantity(), color);
graphics.drawImage(outline, (int) bounds.getX(), (int) bounds.getY(), null);
}
else
if (config.showTagFill())
{
final Image image = getFillImage(color, widgetItem.getId(), widgetItem.getQuantity());
graphics.drawImage(image, (int) bounds.getX(), (int) bounds.getY(), null);
}
if (config.showTagUnderline())
{
int heightOffSet = (int) bounds.getY() + (int) bounds.getHeight() + 2;
graphics.setColor(color);
@@ -75,4 +90,22 @@ public class InventoryTagsOverlay extends WidgetItemOverlay
}
}
}
private Image getFillImage(Color color, int itemId, int qty)
{
long key = (((long) itemId) << 32) | qty;
Image image = fillCache.getIfPresent(key);
if (image == null)
{
final Color fillColor = ColorUtil.colorWithAlpha(color, config.fillOpacity());
image = ImageUtil.fillImage(itemManager.getImage(itemId, qty, false), fillColor);
fillCache.put(key, image);
}
return image;
}
void invalidateCache()
{
fillCache.invalidateAll();
}
}

View File

@@ -39,6 +39,7 @@ import net.runelite.api.events.WidgetMenuOptionClicked;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.menus.MenuManager;
import net.runelite.client.menus.WidgetMenuOption;
import net.runelite.client.plugins.Plugin;
@@ -147,6 +148,15 @@ public class InventoryTagsPlugin extends Plugin
editorMode = false;
}
@Subscribe
public void onConfigChanged(ConfigChanged configChanged)
{
if (configChanged.getGroup().equals(InventoryTagsConfig.GROUP))
{
overlay.invalidateCache();
}
}
@Subscribe
public void onWidgetMenuOptionClicked(final WidgetMenuOptionClicked event)
{

View File

@@ -215,7 +215,7 @@ public class ItemStatChanges
add(new GauntletPotion(), EGNIOL_POTION_1, EGNIOL_POTION_2, EGNIOL_POTION_3, EGNIOL_POTION_4);
// Soul Wars
add(combo(2, heal(HITPOINTS, perc(.20, 2)), heal(RUN_ENERGY, 100)), BANDAGES_25202);
add(combo(2, heal(HITPOINTS, perc(.15, 1)), heal(RUN_ENERGY, 100)), BANDAGES_25202);
add(combo(6, boost(ATTACK, perc(.15, 5)), boost(STRENGTH, perc(.15, 5)), boost(DEFENCE, perc(.15, 5)), boost(RANGED, perc(.15, 5)), boost(MAGIC, perc(.15, 5)), heal(PRAYER, perc(.25, 8))), POTION_OF_POWER1, POTION_OF_POWER2, POTION_OF_POWER3, POTION_OF_POWER4);
log.debug("{} items; {} behaviours loaded", effects.size(), new HashSet<>(effects.values()).size());

View File

@@ -52,7 +52,7 @@ public abstract class Stat
public abstract int getValue(Client client);
/**
* Get the base stat maximum, ie. the bottom half of the stat fraction.
* Get the base stat maximum. (ie. the bottom half of the stat fraction)
*/
public abstract int getMaximum(Client client);
}

View File

@@ -145,7 +145,8 @@ public class LootTrackerPlugin extends Plugin
// Chest loot handling
private static final String CHEST_LOOTED_MESSAGE = "You find some treasure in the chest!";
private static final Pattern LARRAN_LOOTED_PATTERN = Pattern.compile("You have opened Larran's (big|small) chest .*");
private static final String STONE_CHEST_LOOTED_MESSAGE = "You steal some loot from the chest.";
// Used by Stone Chest, Isle of Souls chest, Dark Chest
private static final String OTHER_CHEST_LOOTED_MESSAGE = "You steal some loot from the chest.";
private static final String DORGESH_KAAN_CHEST_LOOTED_MESSAGE = "You find treasure inside!";
private static final String GRUBBY_CHEST_LOOTED_MESSAGE = "You have opened the Grubby Chest";
private static final Pattern HAM_CHEST_LOOTED_PATTERN = Pattern.compile("Your (?<key>[a-z]+) key breaks in the lock.*");
@@ -161,6 +162,8 @@ public class LootTrackerPlugin extends Plugin
put(10835, "Dorgesh-Kaan Chest").
put(10834, "Dorgesh-Kaan Chest").
put(7323, "Grubby Chest").
put(8593, "Isle of Souls Chest").
put(7827, "Dark Chest").
build();
// Shade chest loot handling
@@ -186,6 +189,11 @@ public class LootTrackerPlugin extends Plugin
put(ObjectID.SILVER_CHEST_4128, "Silver key crimson").
put(ObjectID.SILVER_CHEST_4129, "Silver key black").
put(ObjectID.SILVER_CHEST_4130, "Silver key purple").
put(ObjectID.GOLD_CHEST, "Gold key red").
put(ObjectID.GOLD_CHEST_41213, "Gold key brown").
put(ObjectID.GOLD_CHEST_41214, "Gold key crimson").
put(ObjectID.GOLD_CHEST_41215, "Gold key black").
put(ObjectID.GOLD_CHEST_41216, "Gold key purple").
build();
// Hallow Sepulchre Coffin handling
@@ -625,7 +633,7 @@ public class LootTrackerPlugin extends Plugin
final String message = event.getMessage();
if (message.equals(CHEST_LOOTED_MESSAGE) || message.equals(STONE_CHEST_LOOTED_MESSAGE)
if (message.equals(CHEST_LOOTED_MESSAGE) || message.equals(OTHER_CHEST_LOOTED_MESSAGE)
|| message.equals(DORGESH_KAAN_CHEST_LOOTED_MESSAGE) || message.startsWith(GRUBBY_CHEST_LOOTED_MESSAGE)
|| LARRAN_LOOTED_PATTERN.matcher(message).matches())
{

View File

@@ -466,6 +466,7 @@ public class MusicPlugin extends Plugin
public void update()
{
handle.setNoClickThrough(false);
handle.setOnDragListener((JavaScriptCallback) this::drag);
handle.setOnDragCompleteListener((JavaScriptCallback) this::drag);
handle.setHasListener(true);
@@ -511,6 +512,9 @@ public class MusicPlugin extends Plugin
int level = (x * channel.max) / getWidth();
level = Ints.constrainToRange(level, 0, channel.max);
channel.setLevel(level);
int percent = (int) Math.round((level * 100.0 / channel.getMax()));
sliderTooltip = new Tooltip(channel.getName() + ": " + percent + "%");
}
protected int getWidth()

View File

@@ -36,6 +36,7 @@ import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.util.Text;
public class NpcMinimapOverlay extends Overlay
{
@@ -56,7 +57,7 @@ public class NpcMinimapOverlay extends Overlay
{
for (NPC npc : plugin.getHighlightedNpcs())
{
renderNpcOverlay(graphics, npc, npc.getName(), config.getHighlightColor());
renderNpcOverlay(graphics, npc, Text.removeTags(npc.getName()), config.getHighlightColor());
}
return null;

View File

@@ -88,7 +88,6 @@ public class ObjectIndicatorsPlugin extends Plugin
private static final String MARK = "Mark object";
private static final String UNMARK = "Unmark object";
private final Gson GSON = new Gson();
@Getter(AccessLevel.PACKAGE)
private final List<ColorTileObject> objects = new ArrayList<>();
private final Map<Integer, Set<ObjectPoint>> points = new HashMap<>();
@@ -108,6 +107,9 @@ public class ObjectIndicatorsPlugin extends Plugin
@Inject
private ObjectIndicatorsConfig config;
@Inject
private Gson gson;
@Provides
ObjectIndicatorsConfig provideConfig(ConfigManager configManager)
{
@@ -428,7 +430,7 @@ public class ObjectIndicatorsPlugin extends Plugin
}
else
{
final String json = GSON.toJson(points);
final String json = gson.toJson(points);
configManager.setConfiguration(CONFIG_GROUP, "region_" + id, json);
}
}
@@ -442,7 +444,7 @@ public class ObjectIndicatorsPlugin extends Plugin
return null;
}
Set<ObjectPoint> points = GSON.fromJson(json, new TypeToken<Set<ObjectPoint>>()
Set<ObjectPoint> points = gson.fromJson(json, new TypeToken<Set<ObjectPoint>>()
{
}.getType());
// Prior to multiloc support the plugin would mark objects named "null", which breaks

View File

@@ -88,6 +88,9 @@ public class ScreenMarkerPlugin extends Plugin
@Inject
private ScreenMarkerCreationOverlay overlay;
@Inject
private Gson gson;
@Getter
@Inject
private ColorPickerManager colorPickerManager;
@@ -266,7 +269,6 @@ public class ScreenMarkerPlugin extends Plugin
return;
}
final Gson gson = new Gson();
final String json = gson
.toJson(screenMarkers.stream().map(ScreenMarkerOverlay::getMarker).collect(Collectors.toList()));
configManager.setConfiguration(CONFIG_GROUP, CONFIG_KEY, json);
@@ -279,7 +281,6 @@ public class ScreenMarkerPlugin extends Plugin
return Stream.empty();
}
final Gson gson = new Gson();
final List<ScreenMarker> screenMarkerData = gson.fromJson(json, new TypeToken<ArrayList<ScreenMarker>>()
{
}.getType());

View File

@@ -99,7 +99,7 @@ public class SlayerPlugin extends Plugin
//Chat messages
private static final Pattern CHAT_GEM_PROGRESS_MESSAGE = Pattern.compile("^(?:You're assigned to kill|You have received a new Slayer assignment from .*:) (?:[Tt]he )?(?<name>.+?)(?: (?:in|on|south of) (?:the )?(?<location>[^;]+))?(?:; only | \\()(?<amount>\\d+)(?: more to go\\.|\\))$");
private static final String CHAT_GEM_COMPLETE_MESSAGE = "You need something new to hunt.";
private static final Pattern CHAT_COMPLETE_MESSAGE = Pattern.compile("(?:\\d+,)*\\d+");
private static final Pattern CHAT_COMPLETE_MESSAGE = Pattern.compile("You've completed (?:at least )?(?<tasks>[\\d,]+) (?:Wilderness )?tasks?(?: and received \\d+ points, giving you a total of (?<points>[\\d,]+)| and reached the maximum amount of Slayer points \\((?<points2>[\\d,]+)\\))?");
private static final String CHAT_CANCEL_MESSAGE = "Your task has been cancelled.";
private static final String CHAT_CANCEL_MESSAGE_JAD = "You no longer have a slayer task as you left the fight cave.";
private static final String CHAT_CANCEL_MESSAGE_ZUK = "You no longer have a slayer task as you left the Inferno.";
@@ -450,6 +450,7 @@ public class SlayerPlugin extends Plugin
expeditiousChargeCount = Integer.parseInt(mExpeditious.group(1));
config.expeditious(expeditiousChargeCount);
}
if (chatMsg.startsWith(CHAT_BRACELET_SLAUGHTER_CHARGE))
{
Matcher mSlaughter = CHAT_BRACELET_SLAUGHTER_CHARGE_REGEX.matcher(chatMsg);
@@ -466,35 +467,25 @@ public class SlayerPlugin extends Plugin
{
Matcher mComplete = CHAT_COMPLETE_MESSAGE.matcher(chatMsg);
List<String> matches = new ArrayList<>();
while (mComplete.find())
if (mComplete.find())
{
matches.add(mComplete.group(0).replaceAll(",", ""));
}
String mTasks = mComplete.group("tasks");
String mPoints = mComplete.group("points");
if (mPoints == null)
{
mPoints = mComplete.group("points2");
}
int streak = -1, points = -1;
switch (matches.size())
{
case 0:
streak = 1;
break;
case 1:
streak = Integer.parseInt(matches.get(0));
break;
case 3:
streak = Integer.parseInt(matches.get(0));
points = Integer.parseInt(matches.get(2));
break;
default:
log.warn("Unreachable default case for message ending in '; return to Slayer master'");
}
if (streak != -1)
{
config.streak(streak);
}
if (points != -1)
{
config.points(points);
if (mTasks != null)
{
int streak = Integer.parseInt(mTasks.replace(",", ""));
config.streak(streak);
}
if (mPoints != null)
{
int points = Integer.parseInt(mPoints.replace(",", ""));
config.points(points);
}
}
setTask("", 0, 0);

View File

@@ -60,7 +60,7 @@ import net.runelite.client.ws.WSClient;
@PluginDescriptor(
name = "Special Attack Counter",
description = "Track DWH, Arclight, Darklight, and BGS special attacks used on NPCs",
description = "Track special attacks used on NPCs",
tags = {"combat", "npcs", "overlay"},
enabledByDefault = false
)

View File

@@ -37,7 +37,13 @@ enum SpecialWeapon
ARCLIGHT("Arclight", ItemID.ARCLIGHT, false, SpecialCounterConfig::arclightThreshold),
DARKLIGHT("Darklight", ItemID.DARKLIGHT, false, SpecialCounterConfig::darklightThreshold),
BANDOS_GODSWORD("Bandos Godsword", ItemID.BANDOS_GODSWORD, true, SpecialCounterConfig::bandosGodswordThreshold),
BANDOS_GODSWORD_OR("Bandos Godsword", ItemID.BANDOS_GODSWORD_OR, true, SpecialCounterConfig::bandosGodswordThreshold);
BANDOS_GODSWORD_OR("Bandos Godsword", ItemID.BANDOS_GODSWORD_OR, true, SpecialCounterConfig::bandosGodswordThreshold),
BARRELCHEST_ANCHOR("Barrelchest Anchor", ItemID.BARRELCHEST_ANCHOR, true, (c) -> 0),
BONE_DAGGER("Bone Dagger", ItemID.BONE_DAGGER, true, (c) -> 0),
BONE_DAGGER_P("Bone Dagger (p)", ItemID.BONE_DAGGER_P, true, (c) -> 0),
BONE_DAGGER_P8876("Bone Dagger (p+)", ItemID.BONE_DAGGER_P_8876, true, (c) -> 0),
BONE_DAGGER_P8878("Bone Dagger (p++)", ItemID.BONE_DAGGER_P_8878, true, (c) -> 0),
DORGESHUUN_CROSSBOW("Dorgeshuun Crossbow", ItemID.DORGESHUUN_CROSSBOW, true, (c) -> 0);
private final String name;
private final int itemID;

View File

@@ -39,7 +39,7 @@ import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.components.ComponentOrientation;
import net.runelite.client.ui.overlay.components.ImageComponent;
public class TeamCapesOverlay extends OverlayPanel
class TeamCapesOverlay extends OverlayPanel
{
private final TeamCapesPlugin plugin;
private final TeamCapesConfig config;

View File

@@ -25,21 +25,24 @@
package net.runelite.client.plugins.teamcapes;
import com.google.inject.Provides;
import java.time.temporal.ChronoUnit;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.Player;
import net.runelite.api.events.PlayerChanged;
import net.runelite.api.events.PlayerDespawned;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.task.Schedule;
import net.runelite.client.ui.overlay.OverlayManager;
@PluginDescriptor(
@@ -48,19 +51,26 @@ import net.runelite.client.ui.overlay.OverlayManager;
tags = {"overlay", "players"},
enabledByDefault = false
)
@Slf4j
public class TeamCapesPlugin extends Plugin
{
@Inject
private Client client;
@Inject
private ClientThread clientThread;
@Inject
private OverlayManager overlayManager;
@Inject
private TeamCapesOverlay overlay;
// Hashmap of team capes: Key is the teamCape #, Value is the count of teamcapes in the area.
private Map<Integer, Integer> teams = new HashMap<>();
// Team number -> Number of players
@Getter(AccessLevel.PACKAGE)
private Map<Integer, Integer> teams = new LinkedHashMap<>();
// Player -> Team number
private final Map<Player, Integer> playerTeam = new HashMap<>();
@Provides
TeamCapesConfig provideConfig(ConfigManager configManager)
@@ -72,6 +82,8 @@ public class TeamCapesPlugin extends Plugin
protected void startUp() throws Exception
{
overlayManager.add(overlay);
clientThread.invokeLater(() -> client.getPlayers().forEach(this::update));
}
@Override
@@ -79,48 +91,61 @@ public class TeamCapesPlugin extends Plugin
{
overlayManager.remove(overlay);
teams.clear();
playerTeam.clear();
}
@Schedule(
period = 1800,
unit = ChronoUnit.MILLIS
)
public void update()
@Subscribe
public void onPlayerChanged(PlayerChanged playerChanged)
{
if (client.getGameState() != GameState.LOGGED_IN)
Player player = playerChanged.getPlayer();
update(player);
}
private void update(Player player)
{
int oldTeam = playerTeam.getOrDefault(player, 0);
if (oldTeam == player.getTeam())
{
return;
}
List<Player> players = client.getPlayers();
teams.clear();
for (Player player : players)
log.debug("{} has changed teams: {} -> {}", player.getName(), oldTeam, player.getTeam());
if (oldTeam > 0)
{
int team = player.getTeam();
if (team > 0)
{
if (teams.containsKey(team))
{
teams.put(team, teams.get(team) + 1);
}
else
{
teams.put(team, 1);
}
}
teams.computeIfPresent(oldTeam, (key, value) -> value > 1 ? value - 1 : null);
playerTeam.remove(player);
}
if (player.getTeam() > 0)
{
teams.merge(player.getTeam(), 1, Integer::sum);
playerTeam.put(player, player.getTeam());
}
sort();
}
@Subscribe
public void onPlayerDespawned(PlayerDespawned playerDespawned)
{
Player player = playerDespawned.getPlayer();
Integer team = playerTeam.remove(player);
if (team != null)
{
teams.computeIfPresent(team, (key, value) -> value > 1 ? value - 1 : null);
sort();
}
}
private void sort()
{
// Sort teams by value in descending order and then by key in ascending order, limited to 5 entries
teams = teams.entrySet().stream()
.sorted(
Comparator.comparing(Map.Entry<Integer, Integer>::getValue, Comparator.reverseOrder())
.thenComparingInt(Map.Entry::getKey)
)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
.sorted(
Comparator.comparing(Map.Entry<Integer, Integer>::getValue, Comparator.reverseOrder())
.thenComparingInt(Map.Entry::getKey)
)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}
public Map<Integer, Integer> getTeams()
{
return teams;
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2020, cgati <https://github.com/cgati>
* 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.plugins.tearsofguthix;
import java.awt.Color;
import net.runelite.client.config.Alpha;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.util.ColorUtil;
@ConfigGroup("tearsofguthix")
public interface TearsOfGuthixConfig extends Config
{
@ConfigItem(
keyName = "showGreenTearsTimer",
name = "Enable Green Tears Timer",
description = "Configures whether to display a timer for green tears or not",
position = 1
)
default boolean showGreenTearsTimer()
{
return true;
}
@Alpha
@ConfigItem(
keyName = "blueTearsColor",
name = "Blue Tears Color",
description = "Color of Blue Tears timer",
position = 2
)
default Color getBlueTearsColor()
{
return ColorUtil.colorWithAlpha(Color.CYAN, 100);
}
@Alpha
@ConfigItem(
keyName = "greenTearsColor",
name = "Green Tears Color",
description = "Color of Green Tears timer",
position = 3
)
default Color getGreenTearsColor()
{
return ColorUtil.colorWithAlpha(Color.GREEN, 100);
}
}

View File

@@ -36,17 +36,18 @@ import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.components.ProgressPieComponent;
import net.runelite.client.util.ColorUtil;
class TearsOfGuthixOverlay extends Overlay
{
private static final Color CYAN_ALPHA = new Color(Color.CYAN.getRed(), Color.CYAN.getGreen(), Color.CYAN.getBlue(), 100);
private static final Color GREEN_ALPHA = new Color(Color.GREEN.getRed(), Color.GREEN.getGreen(), Color.GREEN.getBlue(), 100);
private static final Duration MAX_TIME = Duration.ofSeconds(9);
private final TearsOfGuthixConfig config;
private final TearsOfGuthixPlugin plugin;
@Inject
private TearsOfGuthixOverlay(TearsOfGuthixPlugin plugin)
private TearsOfGuthixOverlay(TearsOfGuthixConfig config, TearsOfGuthixPlugin plugin)
{
this.config = config;
this.plugin = plugin;
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE);
@@ -55,8 +56,24 @@ class TearsOfGuthixOverlay extends Overlay
@Override
public Dimension render(Graphics2D graphics)
{
if (plugin.getStreams().isEmpty())
{
return null;
}
Color blueTearsFill = config.getBlueTearsColor();
Color greenTearsFill = config.getGreenTearsColor();
Color blueTearsBorder = ColorUtil.colorWithAlpha(blueTearsFill, 255);
Color greenTearsBorder = ColorUtil.colorWithAlpha(greenTearsFill, 255);
plugin.getStreams().forEach((object, timer) ->
{
if ((object.getId() == ObjectID.GREEN_TEARS || object.getId() == ObjectID.GREEN_TEARS_6666)
&& !config.showGreenTearsTimer())
{
return;
}
final Point position = object.getCanvasLocation(100);
if (position == null)
@@ -70,14 +87,14 @@ class TearsOfGuthixOverlay extends Overlay
if (object.getId() == ObjectID.BLUE_TEARS ||
object.getId() == ObjectID.BLUE_TEARS_6665)
{
progressPie.setFill(CYAN_ALPHA);
progressPie.setBorderColor(Color.CYAN);
progressPie.setFill(blueTearsFill);
progressPie.setBorderColor(blueTearsBorder);
}
else if (object.getId() == ObjectID.GREEN_TEARS ||
object.getId() == ObjectID.GREEN_TEARS_6666)
{
progressPie.setFill(GREEN_ALPHA);
progressPie.setBorderColor(Color.GREEN);
progressPie.setFill(greenTearsFill);
progressPie.setBorderColor(greenTearsBorder);
}
progressPie.setPosition(position);

View File

@@ -28,6 +28,7 @@ import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import com.google.inject.Provides;
import lombok.Getter;
import net.runelite.api.Client;
import net.runelite.api.DecorativeObject;
@@ -35,6 +36,7 @@ import net.runelite.api.ObjectID;
import net.runelite.api.events.DecorativeObjectDespawned;
import net.runelite.api.events.DecorativeObjectSpawned;
import net.runelite.api.events.GameStateChanged;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
@@ -61,6 +63,12 @@ public class TearsOfGuthixPlugin extends Plugin
@Getter
private final Map<DecorativeObject, Instant> streams = new HashMap<>();
@Provides
TearsOfGuthixConfig provideConfig(ConfigManager configManager)
{
return configManager.getConfig(TearsOfGuthixConfig.class);
}
@Override
protected void startUp()
{

View File

@@ -40,6 +40,7 @@ public interface TimeTrackingConfig extends Config
String BOTANIST = "botanist";
String TIMERS = "timers";
String STOPWATCHES = "stopwatches";
String PREFER_SOONEST = "preferSoonest";
@ConfigItem(
keyName = "timeFormatMode",
@@ -120,6 +121,17 @@ public interface TimeTrackingConfig extends Config
return 10;
}
@ConfigItem(
keyName = PREFER_SOONEST,
name = "Prefer soonest completion",
description = "When displaying completion times on the overview, prefer showing the soonest any patch will complete.",
position = 7
)
default boolean preferSoonest()
{
return false;
}
@ConfigItem(
keyName = "activeTab",
name = "Active Tab",

View File

@@ -51,6 +51,7 @@ import net.runelite.client.events.RuneScapeProfileChanged;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import static net.runelite.client.plugins.timetracking.TimeTrackingConfig.CONFIG_GROUP;
import static net.runelite.client.plugins.timetracking.TimeTrackingConfig.PREFER_SOONEST;
import static net.runelite.client.plugins.timetracking.TimeTrackingConfig.STOPWATCHES;
import static net.runelite.client.plugins.timetracking.TimeTrackingConfig.TIMERS;
import net.runelite.client.plugins.timetracking.clocks.ClockManager;
@@ -173,6 +174,10 @@ public class TimeTrackingPlugin extends Plugin
{
clockManager.loadStopwatches();
}
else if (e.getKey().equals(PREFER_SOONEST))
{
farmingTracker.loadCompletionTimes();
}
}
@Subscribe

View File

@@ -53,6 +53,9 @@ public class ClockManager
@Inject
private Notifier notifier;
@Inject
private Gson gson;
@Getter
private final List<Timer> timers = new CopyOnWriteArrayList<>();
@@ -183,7 +186,6 @@ public class ClockManager
if (!Strings.isNullOrEmpty(timersJson))
{
final Gson gson = new Gson();
final List<Timer> timers = gson.fromJson(timersJson, new TypeToken<ArrayList<Timer>>()
{
}.getType());
@@ -200,7 +202,6 @@ public class ClockManager
if (!Strings.isNullOrEmpty(stopwatchesJson))
{
final Gson gson = new Gson();
final List<Stopwatch> stopwatches = gson.fromJson(stopwatchesJson, new TypeToken<ArrayList<Stopwatch>>()
{
}.getType());
@@ -227,14 +228,12 @@ public class ClockManager
void saveTimers()
{
final Gson gson = new Gson();
final String json = gson.toJson(timers);
configManager.setConfiguration(TimeTrackingConfig.CONFIG_GROUP, TimeTrackingConfig.TIMERS, json);
}
void saveStopwatches()
{
final Gson gson = new Gson();
final String json = gson.toJson(stopwatches);
configManager.setConfiguration(TimeTrackingConfig.CONFIG_GROUP, TimeTrackingConfig.STOPWATCHES, json);
}

View File

@@ -407,7 +407,7 @@ public class FarmingTracker
{
for (Map.Entry<Tab, Set<FarmingPatch>> tab : farmingWorld.getTabs().entrySet())
{
long maxCompletionTime = 0;
long extremumCompletionTime = config.preferSoonest() ? Long.MAX_VALUE : 0;
boolean allUnknown = true;
boolean allEmpty = true;
@@ -426,7 +426,15 @@ public class FarmingTracker
allEmpty = false;
// update max duration if this patch takes longer to grow
maxCompletionTime = Math.max(maxCompletionTime, prediction.getDoneEstimate());
if (config.preferSoonest())
{
extremumCompletionTime = Math.min(extremumCompletionTime, prediction.getDoneEstimate());
}
else
{
extremumCompletionTime = Math.max(extremumCompletionTime, prediction.getDoneEstimate());
}
}
}
@@ -443,7 +451,7 @@ public class FarmingTracker
state = SummaryState.EMPTY;
completionTime = -1L;
}
else if (maxCompletionTime <= Instant.now().getEpochSecond())
else if (extremumCompletionTime <= Instant.now().getEpochSecond())
{
state = SummaryState.COMPLETED;
completionTime = 0;
@@ -451,7 +459,7 @@ public class FarmingTracker
else
{
state = SummaryState.IN_PROGRESS;
completionTime = maxCompletionTime;
completionTime = extremumCompletionTime;
}
summaries.put(tab.getKey(), state);
completionTimes.put(tab.getKey(), completionTime);

View File

@@ -67,7 +67,6 @@ public class WikiSearchChatboxTextInput extends ChatboxTextInput
private static final int PREDICTION_DEBOUNCE_DELAY_MS = 200;
private final ChatboxPanelManager chatboxPanelManager;
private final Gson gson = new Gson();
private Future<?> runningRequest = null;
private List<String> predictions = ImmutableList.of();
@@ -78,7 +77,7 @@ public class WikiSearchChatboxTextInput extends ChatboxTextInput
@Inject
public WikiSearchChatboxTextInput(ChatboxPanelManager chatboxPanelManager, ClientThread clientThread,
ScheduledExecutorService scheduledExecutorService, @Named("developerMode") final boolean developerMode,
OkHttpClient okHttpClient)
OkHttpClient okHttpClient, Gson gson)
{
super(chatboxPanelManager, clientThread);
this.chatboxPanelManager = chatboxPanelManager;

View File

@@ -47,10 +47,10 @@ import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.ChatPlayer;
import net.runelite.api.FriendsChatMember;
import net.runelite.api.FriendsChatManager;
import net.runelite.api.Client;
import net.runelite.api.Friend;
import net.runelite.api.FriendsChatManager;
import net.runelite.api.FriendsChatMember;
import net.runelite.api.GameState;
import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry;
@@ -60,10 +60,11 @@ import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.PlayerMenuOptionClicked;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.VarbitChanged;
import net.runelite.api.events.WorldListLoad;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.chat.ChatColorType;
import net.runelite.client.chat.ChatMessageBuilder;
import net.runelite.client.chat.ChatMessageManager;
@@ -111,6 +112,9 @@ public class WorldHopperPlugin extends Plugin
@Inject
private Client client;
@Inject
private ClientThread clientThread;
@Inject
private ConfigManager configManager;
@@ -162,7 +166,7 @@ public class WorldHopperPlugin extends Plugin
@Override
public void hotkeyPressed()
{
hop(true);
clientThread.invoke(() -> hop(true));
}
};
private final HotkeyListener nextKeyListener = new HotkeyListener(() -> config.nextKey())
@@ -170,7 +174,7 @@ public class WorldHopperPlugin extends Plugin
@Override
public void hotkeyPressed()
{
hop(false);
clientThread.invoke(() -> hop(false));
}
};
@@ -304,7 +308,7 @@ public class WorldHopperPlugin extends Plugin
void hopTo(World world)
{
hop(world.getId());
clientThread.invoke(() -> hop(world.getId()));
}
void addToFavorites(World world)
@@ -408,9 +412,9 @@ public class WorldHopperPlugin extends Plugin
}
@Subscribe
public void onPlayerMenuOptionClicked(PlayerMenuOptionClicked event)
public void onMenuOptionClicked(MenuOptionClicked event)
{
if (!event.getMenuOption().equals(HOP_TO))
if (event.getMenuAction() != MenuAction.RUNELITE || !event.getMenuOption().equals(HOP_TO))
{
return;
}
@@ -613,6 +617,8 @@ public class WorldHopperPlugin extends Plugin
private void hop(int worldId)
{
assert client.isClientThread();
WorldResult worldResult = worldService.getWorlds();
// Don't try to hop if the world doesn't exist
World world = worldResult.findWorld(worldId);

View File

@@ -370,10 +370,7 @@ class WorldSwitcherPanel extends PluginPanel
private WorldTableRow buildRow(World world, boolean stripe, boolean current, boolean favorite)
{
WorldTableRow row = new WorldTableRow(world, current, favorite, plugin.getStoredPing(world),
world1 ->
{
plugin.hopTo(world1);
},
plugin::hopTo,
(world12, add) ->
{
if (add)

View File

@@ -55,6 +55,7 @@ enum MinigameLocation
PYRAMID_PLUNDER("Pyramid Plunder", new WorldPoint(3288, 2787, 0)),
RANGING_GUILD("Ranging Guild", new WorldPoint(2671, 3419, 0)),
ROGUES_DEN("Rogues' Den", new WorldPoint(2905, 3537, 0)),
SHADES_OF_MORTTON("Shades of Mort'ton", new WorldPoint(3505, 3315, 0)),
SORCERESSS_GARDEN("Sorceress's Garden", new WorldPoint(3285, 3180, 0)),
TROUBLE_BREWING("Trouble Brewing", new WorldPoint(3811, 3021, 0)),
VOLCANIC_MINE("Volcanic Mine", new WorldPoint(3812, 3810, 0)),

View File

@@ -186,7 +186,7 @@ public class WorldMapPlugin extends Plugin
{
case AGILITY:
{
int newAgilityLevel = statChanged.getLevel();
int newAgilityLevel = statChanged.getBoostedLevel();
if (newAgilityLevel != agilityLevel)
{
agilityLevel = newAgilityLevel;
@@ -196,7 +196,7 @@ public class WorldMapPlugin extends Plugin
}
case WOODCUTTING:
{
int newWoodcutLevel = statChanged.getLevel();
int newWoodcutLevel = statChanged.getBoostedLevel();
if (newWoodcutLevel != woodcuttingLevel)
{
woodcuttingLevel = newWoodcutLevel;

View File

@@ -89,11 +89,22 @@ public interface XpGlobesConfig extends Config
return false;
}
@ConfigItem(
keyName = "showVirtualLevel",
name = "Show virtual level",
description = "Shows virtual level if over 99 in a skill and Hide maxed skill is not checked",
position = 5
)
default boolean showVirtualLevel()
{
return false;
}
@ConfigItem(
keyName = "enableCustomArcColor",
name = "Enable custom arc color",
description = "Enables the custom coloring of the globe's arc instead of using the skill's default color.",
position = 5
position = 6
)
default boolean enableCustomArcColor()
{
@@ -105,7 +116,7 @@ public interface XpGlobesConfig extends Config
keyName = "Progress arc color",
name = "Progress arc color",
description = "Change the color of the progress arc in the xp orb",
position = 6
position = 7
)
default Color progressArcColor()
{
@@ -117,7 +128,7 @@ public interface XpGlobesConfig extends Config
keyName = "Progress orb outline color",
name = "Progress orb outline color",
description = "Change the color of the progress orb outline",
position = 7
position = 8
)
default Color progressOrbOutLineColor()
{
@@ -129,7 +140,7 @@ public interface XpGlobesConfig extends Config
keyName = "Progress orb background color",
name = "Progress orb background color",
description = "Change the color of the progress orb background",
position = 8
position = 9
)
default Color progressOrbBackgroundColor()
{
@@ -140,7 +151,7 @@ public interface XpGlobesConfig extends Config
keyName = "Progress arc width",
name = "Progress arc width",
description = "Change the stroke width of the progress arc",
position = 9
position = 10
)
@Units(Units.PIXELS)
default int progressArcStrokeWidth()
@@ -152,7 +163,7 @@ public interface XpGlobesConfig extends Config
keyName = "Orb size",
name = "Size of orbs",
description = "Change the size of the xp orbs",
position = 10
position = 11
)
@Units(Units.PIXELS)
default int xpOrbSize()
@@ -164,7 +175,7 @@ public interface XpGlobesConfig extends Config
keyName = "Orb duration",
name = "Duration of orbs",
description = "Change the duration the xp orbs are visible",
position = 11
position = 12
)
@Units(Units.SECONDS)
default int xpOrbDuration()

View File

@@ -106,9 +106,17 @@ public class XpGlobesPlugin extends Plugin
return;
}
if (config.hideMaxed() && currentLevel >= Experience.MAX_REAL_LEVEL)
if (currentLevel >= Experience.MAX_REAL_LEVEL)
{
return;
if (config.hideMaxed())
{
return;
}
if (config.showVirtualLevel())
{
currentLevel = Experience.getLevelForXp(currentXp);
}
}
if (cachedGlobe != null)

View File

@@ -159,8 +159,8 @@ class XpState
}
/**
* Update number of actions performed for skill (e.g amount of kills in this case) if last interacted
* NPC died
* Update number of actions performed for skill if last interacted NPC died.
* (eg. amount of kills in this case)
* @param skill skill to update actions for
* @param npc npc that just died
* @param npcHealth max health of npc that just died

View File

@@ -24,17 +24,25 @@
*/
package net.runelite.client.ui;
import javax.swing.text.StyleContext;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.io.IOException;
import javax.swing.text.StyleContext;
import lombok.Getter;
public class FontManager
{
@Getter
private static final Font runescapeFont;
@Getter
private static final Font runescapeSmallFont;
@Getter
private static final Font runescapeBoldFont;
@Getter
private static final Font defaultFont;
@Getter
private static final Font defaultBoldFont;
static
{
@@ -48,7 +56,7 @@ public class FontManager
ge.registerFont(font);
runescapeFont = StyleContext.getDefaultStyleContext()
.getFont(font.getName(), Font.PLAIN, 16);
.getFont(font.getName(), Font.PLAIN, 16);
ge.registerFont(runescapeFont);
Font smallFont = Font.createFont(Font.TRUETYPE_FONT,
@@ -57,16 +65,16 @@ public class FontManager
ge.registerFont(smallFont);
runescapeSmallFont = StyleContext.getDefaultStyleContext()
.getFont(smallFont.getName(), Font.PLAIN, 16);
.getFont(smallFont.getName(), Font.PLAIN, 16);
ge.registerFont(runescapeSmallFont);
Font boldFont = Font.createFont(Font.TRUETYPE_FONT,
FontManager.class.getResourceAsStream("runescape_bold.ttf"))
.deriveFont(Font.BOLD, 16);
FontManager.class.getResourceAsStream("runescape_bold.ttf"))
.deriveFont(Font.BOLD, 16);
ge.registerFont(boldFont);
runescapeBoldFont = StyleContext.getDefaultStyleContext()
.getFont(boldFont.getName(), Font.BOLD, 16);
.getFont(boldFont.getName(), Font.BOLD, 16);
ge.registerFont(runescapeBoldFont);
}
catch (FontFormatException ex)
@@ -77,20 +85,8 @@ public class FontManager
{
throw new RuntimeException("Font file not found.", ex);
}
}
public static Font getRunescapeFont()
{
return runescapeFont;
}
public static Font getRunescapeSmallFont()
{
return runescapeSmallFont;
}
public static Font getRunescapeBoldFont()
{
return runescapeBoldFont;
defaultFont = new Font(Font.DIALOG, Font.PLAIN, 16);
defaultBoldFont = new Font(Font.DIALOG, Font.BOLD, 16);
}
}

View File

@@ -29,6 +29,7 @@ package net.runelite.client.ui.components;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
@@ -125,7 +126,7 @@ public class IconTextField extends JPanel
textField.addMouseListener(hoverEffect);
innerTxt.addMouseListener(hoverEffect);
clearButton = createRHSButton(ColorScheme.PROGRESS_ERROR_COLOR, Color.PINK);
clearButton = createRHSButton(ColorScheme.PROGRESS_ERROR_COLOR, Color.PINK, FontManager.getRunescapeBoldFont());
clearButton.setText("×");
clearButton.addActionListener(evt ->
{
@@ -192,7 +193,7 @@ public class IconTextField extends JPanel
}
});
suggestionButton = createRHSButton(ColorScheme.LIGHT_GRAY_COLOR, ColorScheme.MEDIUM_GRAY_COLOR);
suggestionButton = createRHSButton(ColorScheme.LIGHT_GRAY_COLOR, ColorScheme.MEDIUM_GRAY_COLOR, FontManager.getDefaultBoldFont());
suggestionButton.setText("");
suggestionButton.addActionListener(e ->
{
@@ -237,11 +238,11 @@ public class IconTextField extends JPanel
add(rhsButtons, BorderLayout.EAST);
}
private JButton createRHSButton(Color fg, Color rollover)
private JButton createRHSButton(Color fg, Color rollover, Font font)
{
JButton b = new JButton();
b.setPreferredSize(new Dimension(30, 0));
b.setFont(FontManager.getRunescapeBoldFont());
b.setFont(font);
b.setBorder(null);
b.setRolloverEnabled(true);
SwingUtil.removeButtonDecorations(b);

View File

@@ -28,6 +28,7 @@ import com.google.common.base.MoreObjects;
import com.google.common.base.Strings;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
@@ -50,6 +51,10 @@ public class LineComponent implements LayoutableRenderableEntity
@Builder.Default
private Color rightColor = Color.WHITE;
private Font leftFont;
private Font rightFont;
@Builder.Default
private Point preferredLocation = new Point();
@@ -67,13 +72,16 @@ public class LineComponent implements LayoutableRenderableEntity
final String left = MoreObjects.firstNonNull(this.left, "");
final String right = MoreObjects.firstNonNull(this.right, "");
final FontMetrics metrics = graphics.getFontMetrics();
final Font leftFont = MoreObjects.firstNonNull(this.leftFont, graphics.getFont());
final Font rightFont = MoreObjects.firstNonNull(this.rightFont, graphics.getFont());
final FontMetrics lfm = graphics.getFontMetrics(leftFont), rfm = graphics.getFontMetrics(rightFont);
final int fmHeight = Math.max(lfm.getHeight(), rfm.getHeight());
final int baseX = preferredLocation.x;
final int baseY = preferredLocation.y + metrics.getHeight();
final int baseY = preferredLocation.y + fmHeight;
int x = baseX;
int y = baseY;
final int leftFullWidth = getLineWidth(left, metrics);
final int rightFullWidth = getLineWidth(right, metrics);
final int leftFullWidth = getLineWidth(left, lfm);
final int rightFullWidth = getLineWidth(right, rfm);
final TextComponent textComponent = new TextComponent();
if (preferredSize.width < leftFullWidth + rightFullWidth)
@@ -87,8 +95,8 @@ public class LineComponent implements LayoutableRenderableEntity
leftSmallWidth -= rightSmallWidth;
}
final String[] leftSplitLines = lineBreakText(left, leftSmallWidth, metrics);
final String[] rightSplitLines = lineBreakText(right, rightSmallWidth, metrics);
final String[] leftSplitLines = lineBreakText(left, leftSmallWidth, lfm);
final String[] rightSplitLines = lineBreakText(right, rightSmallWidth, rfm);
int lineCount = Math.max(leftSplitLines.length, rightSplitLines.length);
@@ -100,19 +108,21 @@ public class LineComponent implements LayoutableRenderableEntity
textComponent.setPosition(new Point(x, y));
textComponent.setText(leftText);
textComponent.setColor(leftColor);
textComponent.setFont(leftFont);
textComponent.render(graphics);
}
if (i < rightSplitLines.length)
{
final String rightText = rightSplitLines[i];
textComponent.setPosition(new Point(x + preferredSize.width - getLineWidth(rightText, metrics), y));
textComponent.setPosition(new Point(x + preferredSize.width - getLineWidth(rightText, rfm), y));
textComponent.setText(rightText);
textComponent.setColor(rightColor);
textComponent.setFont(rightFont);
textComponent.render(graphics);
}
y += metrics.getHeight();
y += fmHeight;
}
final Dimension dimension = new Dimension(preferredSize.width, y - baseY);
@@ -126,6 +136,7 @@ public class LineComponent implements LayoutableRenderableEntity
textComponent.setPosition(new Point(x, y));
textComponent.setText(left);
textComponent.setColor(leftColor);
textComponent.setFont(leftFont);
textComponent.render(graphics);
}
@@ -134,10 +145,11 @@ public class LineComponent implements LayoutableRenderableEntity
textComponent.setPosition(new Point(x + preferredSize.width - rightFullWidth, y));
textComponent.setText(right);
textComponent.setColor(rightColor);
textComponent.setFont(rightFont);
textComponent.render(graphics);
}
y += metrics.getHeight();
y += fmHeight;
final Dimension dimension = new Dimension(preferredSize.width, y - baseY);
bounds.setLocation(preferredLocation);

View File

@@ -26,10 +26,12 @@ package net.runelite.client.ui.overlay.components;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import lombok.Setter;
import net.runelite.client.ui.overlay.RenderableEntity;
import net.runelite.client.util.ColorUtil;
@@ -45,10 +47,22 @@ public class TextComponent implements RenderableEntity
private Point position = new Point();
private Color color = Color.WHITE;
private boolean outline;
/**
* The text font.
*/
@Nullable
private Font font;
@Override
public Dimension render(Graphics2D graphics)
{
Font originalFont = null;
if (font != null)
{
originalFont = graphics.getFont();
graphics.setFont(font);
}
final FontMetrics fontMetrics = graphics.getFontMetrics();
if (COL_TAG_PATTERN_W_LOOKAHEAD.matcher(text).find())
@@ -105,6 +119,14 @@ public class TextComponent implements RenderableEntity
graphics.drawString(text, position.x, position.y);
}
return new Dimension(fontMetrics.stringWidth(text), fontMetrics.getHeight());
int width = fontMetrics.stringWidth(text);
int height = fontMetrics.getHeight();
if (originalFont != null)
{
graphics.setFont(originalFont);
}
return new Dimension(width, height);
}
}

View File

@@ -26,6 +26,7 @@
package net.runelite.client.util;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.datatransfer.Clipboard;
@@ -54,7 +55,6 @@ import net.runelite.api.GameState;
import net.runelite.api.WorldType;
import net.runelite.client.Notifier;
import static net.runelite.client.RuneLite.SCREENSHOT_DIR;
import net.runelite.http.api.RuneLiteAPI;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.HttpUrl;
@@ -75,6 +75,7 @@ public class ImageCapture
private final Client client;
private final Notifier notifier;
private final OkHttpClient okHttpClient;
private final Gson gson;
private final String imgurClientId;
@Inject
@@ -82,12 +83,14 @@ public class ImageCapture
final Client client,
final Notifier notifier,
final OkHttpClient okHttpClient,
final Gson gson,
@Named("runelite.imgur.client.id") final String imgurClientId
)
{
this.client = client;
this.notifier = notifier;
this.okHttpClient = okHttpClient;
this.gson = gson;
this.imgurClientId = imgurClientId;
}
@@ -204,7 +207,7 @@ public class ImageCapture
*/
private void uploadScreenshot(File screenshotFile, boolean notify) throws IOException
{
String json = RuneLiteAPI.GSON.toJson(new ImageUploadRequest(screenshotFile));
String json = gson.toJson(new ImageUploadRequest(screenshotFile));
Request request = new Request.Builder()
.url(IMGUR_IMAGE_UPLOAD_URL)
@@ -225,8 +228,8 @@ public class ImageCapture
{
try (InputStream in = response.body().byteStream())
{
ImageUploadResponse imageUploadResponse = RuneLiteAPI.GSON
.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), ImageUploadResponse.class);
ImageUploadResponse imageUploadResponse =
gson.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), ImageUploadResponse.class);
if (imageUploadResponse.isSuccess())
{

View File

@@ -397,8 +397,9 @@ public class ImageUtil
{
for (int y = 0; y < filledImage.getHeight(); y++)
{
final Color pixelColor = new Color(image.getRGB(x, y), true);
if (pixelColor.getAlpha() == 0)
int pixel = image.getRGB(x, y);
int a = pixel >>> 24;
if (a == 0)
{
continue;
}

View File

@@ -182,7 +182,7 @@ public class QuantityFormatter
}
/**
* Calculates, given a string with a value denominator (ex. 20K)
* Calculates, given a string with a value denominator (for example, 20K)
* the multiplier that the denominator represents (in this case 1000).
*
* @param string The string to check.

View File

@@ -25,6 +25,8 @@
*/
package net.runelite.client.util;
import com.google.common.io.ByteStreams;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@@ -36,7 +38,7 @@ public class ReflectUtil
{
}
public static MethodHandles.Lookup privateLookupIn(Class clazz)
public static MethodHandles.Lookup privateLookupIn(Class<?> clazz)
{
try
{
@@ -44,7 +46,16 @@ public class ReflectUtil
// we need to access it via reflection. This is preferred way because it's Java 9+ public api and is
// likely to not change
final Method privateLookupIn = MethodHandles.class.getMethod("privateLookupIn", Class.class, MethodHandles.Lookup.class);
return (MethodHandles.Lookup) privateLookupIn.invoke(null, clazz, MethodHandles.lookup());
MethodHandles.Lookup caller;
if (clazz.getClassLoader() instanceof PrivateLookupableClassLoader)
{
caller = ((PrivateLookupableClassLoader) clazz.getClassLoader()).getLookup();
}
else
{
caller = MethodHandles.lookup();
}
return (MethodHandles.Lookup) privateLookupIn.invoke(null, clazz, caller);
}
catch (InvocationTargetException | IllegalAccessException e)
{
@@ -69,4 +80,51 @@ public class ReflectUtil
}
}
}
public interface PrivateLookupableClassLoader
{
// define class is protected final so this needs a different name to become public
Class<?> defineClass0(String name, byte[] b, int off, int len) throws ClassFormatError;
MethodHandles.Lookup getLookup();
void setLookup(MethodHandles.Lookup lookup);
}
/**
* Allows private Lookups to be created for classes in this ClassLoader
* <p>
* Due to JDK-8173978 it is impossible to create get a lookup with module scoped permissions when teleporting
* between modules. Since external plugins are loaded in a separate classloader to us they are contained in unique
* unnamed modules. Since we (via LambdaMetafactory) are creating a hidden class in that module, we require module
* scoped access to it, and since the methods can be private, we also require private access. The only way to get
* MODULE|PRIVATE is to either 1) invokedynamic in that class, 2) call MethodHandles.lookup() from that class, or
* 3) call privateLookupIn with an existing lookup with PRIVATE|MODULE created from a class in the same module.
* Our solution is to make classloaders call this method which will define a class in the classloader's unnamed
* module that calls MethodHandles.lookup() and stores it in the classloader for later use.
*/
public static void installLookupHelper(PrivateLookupableClassLoader cl)
{
try
{
String name = PrivateLookupHelper.class.getName();
byte[] classData = ByteStreams.toByteArray(ReflectUtil.class.getResourceAsStream("/" + name.replace('.', '/') + ".class"));
Class<?> clazz = cl.defineClass0(name, classData, 0, classData.length);
// force <clinit> to run
clazz.getConstructor().newInstance();
}
catch (IOException | ReflectiveOperationException e)
{
throw new RuntimeException("unable to install lookup helper", e);
}
}
public static class PrivateLookupHelper
{
static
{
PrivateLookupableClassLoader pcl = (PrivateLookupableClassLoader) PrivateLookupHelper.class.getClassLoader();
pcl.setLookup(MethodHandles.lookup());
}
}
}