Merge branch 'upstream-master' into runelite

# Conflicts:
#	deobfuscator/src/test/java/net/runelite/deob/deobfuscators/gson/ColorTypeAdapterTest.java
#	deobfuscator/src/test/java/net/runelite/deob/deobfuscators/gson/InstantTypeAdapterTest.java
#	runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java
This commit is contained in:
zeruth
2021-02-01 12:06:49 -05:00
74 changed files with 470 additions and 115 deletions

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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -73,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<>();
@@ -105,6 +103,9 @@ public class GroundMarkerPlugin extends Plugin
@Inject
private GroundMarkerSharingManager sharingManager;
@Inject
private Gson gson;
void savePoints(int regionId, Collection<GroundMarkerPoint> points)
{
if (points == null || points.isEmpty())
@@ -113,7 +114,7 @@ public class GroundMarkerPlugin extends Plugin
return;
}
String json = GSON.toJson(points);
String json = gson.toJson(points);
configManager.setConfiguration(CONFIG_GROUP, REGION_PREFIX + regionId, json);
}
@@ -126,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
}

View File

@@ -53,7 +53,6 @@ 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;
import net.runelite.http.api.RuneLiteAPI;
@Slf4j
class GroundMarkerSharingManager
@@ -61,22 +60,23 @@ 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 static final Gson GSON = RuneLiteAPI.GSON;
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)
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()
@@ -135,7 +135,7 @@ class GroundMarkerSharingManager
return;
}
final String exportDump = GSON.toJson(activePoints);
final String exportDump = gson.toJson(activePoints);
log.debug("Exported ground markers: {}", exportDump);
@@ -173,7 +173,7 @@ class GroundMarkerSharingManager
try
{
// CHECKSTYLE:OFF
importPoints = GSON.fromJson(clipboardText, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
importPoints = gson.fromJson(clipboardText, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
// CHECKSTYLE:ON
}
catch (JsonSyntaxException e)

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

@@ -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

@@ -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

@@ -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

@@ -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());
}
}
}