Clean up most resources, Completable > Observable
This commit is contained in:
@@ -84,9 +84,8 @@ public class RuneLiteAPI
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
try (InputStream in = RuneLiteAPI.class.getResourceAsStream("/runelite.properties"))
|
||||
{
|
||||
InputStream in = RuneLiteAPI.class.getResourceAsStream("/runelite.properties");
|
||||
properties.load(in);
|
||||
|
||||
version = properties.getProperty("runelite.version");
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ClientSessionManager
|
||||
sessionClient.pingSession(sessionId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.from(clientThread))
|
||||
.doOnError(e -> this.error((Throwable) e))
|
||||
.doOnError(this::error)
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class ClientSessionManager
|
||||
sessionClient.delete(sessionId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.from(clientThread))
|
||||
.doOnError(e -> this.error((Throwable) e))
|
||||
.doOnError(this::error)
|
||||
.subscribe();
|
||||
|
||||
sessionId = null;
|
||||
|
||||
@@ -24,12 +24,10 @@
|
||||
*/
|
||||
package net.runelite.client;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
@Singleton
|
||||
public class RuneLiteProperties
|
||||
{
|
||||
private static final String RUNELITE_TITLE = "open.osrs.title";
|
||||
|
||||
@@ -24,7 +24,9 @@
|
||||
*/
|
||||
package net.runelite.client;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Observable;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import okhttp3.HttpUrl;
|
||||
@@ -50,34 +52,36 @@ class SessionClient
|
||||
});
|
||||
}
|
||||
|
||||
Observable pingSession(UUID uuid)
|
||||
Completable pingSession(UUID uuid)
|
||||
{
|
||||
final HttpUrl url = RuneLiteAPI.getSessionBase().newBuilder()
|
||||
.addPathSegment("ping")
|
||||
.addQueryParameter("session", uuid.toString())
|
||||
.build();
|
||||
|
||||
return Observable.defer(() ->
|
||||
return Completable.fromAction(() ->
|
||||
{
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.build();
|
||||
|
||||
|
||||
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||
{
|
||||
return Observable.empty();
|
||||
if (!response.isSuccessful())
|
||||
{
|
||||
throw new IOException("Unsuccesful ping");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Observable delete(UUID uuid)
|
||||
Completable delete(UUID uuid)
|
||||
{
|
||||
final HttpUrl url = RuneLiteAPI.getSessionBase().newBuilder()
|
||||
.addQueryParameter("session", uuid.toString())
|
||||
.build();
|
||||
|
||||
return Observable.defer(() ->
|
||||
return Completable.fromAction(() ->
|
||||
{
|
||||
Request request = new Request.Builder()
|
||||
.delete()
|
||||
@@ -85,7 +89,6 @@ class SessionClient
|
||||
.build();
|
||||
|
||||
RuneLiteAPI.CLIENT.newCall(request).execute().close();
|
||||
return Observable.empty();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ public interface EventBusInterface
|
||||
{
|
||||
<T> void subscribe(Class<T> eventClass, @NonNull Object lifecycle, @NonNull Consumer<T> action);
|
||||
|
||||
<T> void subscribe(Class<T> eventClass, @NonNull Object lifecycle, @NonNull Consumer<T> action, int takeUntil);
|
||||
|
||||
void unregister(@NonNull Object lifecycle);
|
||||
|
||||
<T> void post(Class<T> eventClass, @NonNull Event event);
|
||||
|
||||
@@ -28,11 +28,11 @@
|
||||
package net.runelite.client.plugins.grandexchange;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.inject.Provides;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
@@ -85,6 +85,7 @@ import net.runelite.client.ui.NavigationButton;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
import net.runelite.client.util.StackFormatter;
|
||||
import net.runelite.api.util.Text;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import net.runelite.http.api.ge.GrandExchangeClient;
|
||||
import net.runelite.http.api.ge.GrandExchangeTrade;
|
||||
import net.runelite.http.api.osbuddy.OSBGrandExchangeClient;
|
||||
@@ -107,7 +108,6 @@ public class GrandExchangePlugin extends Plugin
|
||||
private static final OSBGrandExchangeClient CLIENT = new OSBGrandExchangeClient();
|
||||
private static final String OSB_GE_TEXT = "<br>OSBuddy Actively traded price: ";
|
||||
private static final String BUY_LIMIT_GE_TEXT = "<br>Buy limit: ";
|
||||
private static final Gson GSON = new Gson();
|
||||
private static final TypeToken<Map<Integer, Integer>> BUY_LIMIT_TOKEN = new TypeToken<Map<Integer, Integer>>()
|
||||
{
|
||||
};
|
||||
@@ -173,12 +173,14 @@ public class GrandExchangePlugin extends Plugin
|
||||
private boolean enableGELimits;
|
||||
private boolean enableAfford;
|
||||
|
||||
private static Map<Integer, Integer> loadGELimits()
|
||||
private static Map<Integer, Integer> loadGELimits() throws IOException
|
||||
{
|
||||
final InputStream geLimitData = GrandExchangePlugin.class.getResourceAsStream("ge_limits.json");
|
||||
final Map<Integer, Integer> itemGELimits = GSON.fromJson(new InputStreamReader(geLimitData), BUY_LIMIT_TOKEN.getType());
|
||||
log.debug("Loaded {} limits", itemGELimits.size());
|
||||
return itemGELimits;
|
||||
try (final JsonReader geLimitData = new JsonReader(new InputStreamReader(GrandExchangePlugin.class.getResourceAsStream("ge_limits.json"))))
|
||||
{
|
||||
final Map<Integer, Integer> itemGELimits = RuneLiteAPI.GSON.fromJson(geLimitData, BUY_LIMIT_TOKEN.getType());
|
||||
log.debug("Loaded {} limits", itemGELimits.size());
|
||||
return itemGELimits;
|
||||
}
|
||||
}
|
||||
|
||||
private SavedOffer getOffer(int slot)
|
||||
@@ -188,12 +190,12 @@ public class GrandExchangePlugin extends Plugin
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return GSON.fromJson(offer, SavedOffer.class);
|
||||
return RuneLiteAPI.GSON.fromJson(offer, SavedOffer.class);
|
||||
}
|
||||
|
||||
private void setOffer(int slot, SavedOffer offer)
|
||||
{
|
||||
configManager.setConfiguration("geoffer." + client.getUsername().toLowerCase(), Integer.toString(slot), GSON.toJson(offer));
|
||||
configManager.setConfiguration("geoffer." + client.getUsername().toLowerCase(), Integer.toString(slot), RuneLiteAPI.GSON.toJson(offer));
|
||||
}
|
||||
|
||||
private void deleteOffer(int slot)
|
||||
@@ -208,7 +210,7 @@ public class GrandExchangePlugin extends Plugin
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startUp()
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
updateConfig();
|
||||
addSubscriptions();
|
||||
|
||||
@@ -26,6 +26,7 @@ package net.runelite.client.plugins.slayer;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.List;
|
||||
@@ -38,14 +39,15 @@ class SlayerXpDropLookup
|
||||
// floating point math equality
|
||||
private static final double EPSILON = 1e-6;
|
||||
|
||||
private void loadXpJson()
|
||||
private void loadXpJson() throws IOException
|
||||
{
|
||||
final InputStream xpFile = getClass().getResourceAsStream("/slayer_xp.json");
|
||||
Gson gson = new Gson();
|
||||
xpMap = gson.fromJson(new InputStreamReader(xpFile), new TypeToken<Map<String, List<Double>>>()
|
||||
try (final InputStream xpFile = getClass().getResourceAsStream("/slayer_xp.json"))
|
||||
{
|
||||
|
||||
}.getType());
|
||||
Gson gson = new Gson();
|
||||
xpMap = gson.fromJson(new InputStreamReader(xpFile), new TypeToken<Map<String, List<Double>>>()
|
||||
{
|
||||
}.getType());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,6 +131,13 @@ class SlayerXpDropLookup
|
||||
|
||||
SlayerXpDropLookup()
|
||||
{
|
||||
loadXpJson();
|
||||
try
|
||||
{
|
||||
loadXpJson();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.swing.SwingUtilities;
|
||||
@@ -84,6 +83,7 @@ import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import net.runelite.client.util.ExecutorServiceExceptionLogger;
|
||||
import net.runelite.client.util.HotkeyListener;
|
||||
import net.runelite.api.util.Text;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
import net.runelite.client.util.WorldUtil;
|
||||
import net.runelite.client.util.ping.Ping;
|
||||
import net.runelite.http.api.worlds.World;
|
||||
@@ -215,11 +215,7 @@ public class WorldHopperPlugin extends Plugin
|
||||
|
||||
panel = new WorldSwitcherPanel(this);
|
||||
|
||||
final BufferedImage icon;
|
||||
synchronized (ImageIO.class)
|
||||
{
|
||||
icon = ImageIO.read(getClass().getResourceAsStream("icon.png"));
|
||||
}
|
||||
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(WorldHopperPlugin.class, "icon.png");
|
||||
|
||||
navButton = NavigationButton.builder()
|
||||
.tooltip("World Switcher")
|
||||
|
||||
@@ -38,7 +38,7 @@ import net.runelite.client.util.StringFileUtils;
|
||||
|
||||
final class ClientPanel extends JPanel
|
||||
{
|
||||
public ClientPanel(@Nullable Applet client)
|
||||
ClientPanel(@Nullable Applet client)
|
||||
{
|
||||
setSize(Constants.GAME_FIXED_SIZE);
|
||||
setMinimumSize(Constants.GAME_FIXED_SIZE);
|
||||
@@ -71,7 +71,7 @@ final class ClientPanel extends JPanel
|
||||
|
||||
add(client, BorderLayout.CENTER);
|
||||
|
||||
// api.renderableThis causes the whole game frame to be redrawn each frame instead
|
||||
// This causes the whole game frame to be redrawn each frame instead
|
||||
// of only the viewport, so we can hook to MainBufferProvider#draw
|
||||
// and draw anywhere without it leaving artifacts
|
||||
if (client instanceof Client)
|
||||
|
||||
@@ -114,8 +114,8 @@ public class ClientUI
|
||||
private static final String CONFIG_OPACITY_AMOUNT = "opacityPercentage";
|
||||
private static final int CLIENT_WELL_HIDDEN_MARGIN = 160;
|
||||
private static final int CLIENT_WELL_HIDDEN_MARGIN_TOP = 10;
|
||||
public static boolean allowInput = false;
|
||||
public static final BufferedImage ICON = ImageUtil.getResourceStreamFromClass(ClientUI.class, "/openosrs.png");
|
||||
public static boolean allowInput = false;
|
||||
|
||||
@Getter
|
||||
private TrayIcon trayIcon;
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.awt.Font;
|
||||
import java.awt.FontFormatException;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import javax.swing.text.StyleContext;
|
||||
|
||||
public class FontManager
|
||||
@@ -42,31 +43,42 @@ public class FontManager
|
||||
|
||||
try
|
||||
{
|
||||
Font font = Font.createFont(Font.TRUETYPE_FONT,
|
||||
FontManager.class.getResourceAsStream("runescape.ttf"))
|
||||
.deriveFont(Font.PLAIN, 16);
|
||||
ge.registerFont(font);
|
||||
Font font;
|
||||
|
||||
try (InputStream runescapeIn = FontManager.class.getResourceAsStream("runescape.ttf"))
|
||||
{
|
||||
font = Font.createFont(Font.TRUETYPE_FONT,
|
||||
runescapeIn)
|
||||
.deriveFont(Font.PLAIN, 16);
|
||||
ge.registerFont(font);
|
||||
}
|
||||
|
||||
runescapeFont = StyleContext.getDefaultStyleContext()
|
||||
.getFont(font.getName(), Font.PLAIN, 16);
|
||||
ge.registerFont(runescapeFont);
|
||||
|
||||
Font smallFont = Font.createFont(Font.TRUETYPE_FONT,
|
||||
FontManager.class.getResourceAsStream("runescape_small.ttf"))
|
||||
.deriveFont(Font.PLAIN, 16);
|
||||
ge.registerFont(smallFont);
|
||||
try (InputStream smallIn = FontManager.class.getResourceAsStream("runescape_small.ttf"))
|
||||
{
|
||||
font = Font.createFont(Font.TRUETYPE_FONT,
|
||||
smallIn)
|
||||
.deriveFont(Font.PLAIN, 16);
|
||||
ge.registerFont(font);
|
||||
}
|
||||
|
||||
runescapeSmallFont = StyleContext.getDefaultStyleContext()
|
||||
.getFont(smallFont.getName(), Font.PLAIN, 16);
|
||||
.getFont(font.getName(), Font.PLAIN, 16);
|
||||
ge.registerFont(runescapeSmallFont);
|
||||
|
||||
Font boldFont = Font.createFont(Font.TRUETYPE_FONT,
|
||||
FontManager.class.getResourceAsStream("runescape_bold.ttf"))
|
||||
.deriveFont(Font.PLAIN, 16);
|
||||
ge.registerFont(boldFont);
|
||||
try (InputStream boldIn = FontManager.class.getResourceAsStream("runescape_bold.ttf"))
|
||||
{
|
||||
font = Font.createFont(Font.TRUETYPE_FONT,
|
||||
boldIn)
|
||||
.deriveFont(Font.PLAIN, 16);
|
||||
ge.registerFont(font);
|
||||
}
|
||||
|
||||
runescapeBoldFont = StyleContext.getDefaultStyleContext()
|
||||
.getFont(boldFont.getName(), Font.PLAIN, 16);
|
||||
.getFont(font.getName(), Font.PLAIN, 16);
|
||||
ge.registerFont(runescapeBoldFont);
|
||||
}
|
||||
catch (FontFormatException ex)
|
||||
|
||||
@@ -35,7 +35,6 @@ import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.client.ui.components.InfoPanel;
|
||||
import net.runelite.client.ui.components.MessagePanel;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
|
||||
@Slf4j
|
||||
public class RuneLiteSplashScreen extends JFrame
|
||||
@@ -53,7 +52,7 @@ public class RuneLiteSplashScreen extends JFrame
|
||||
this.setSize(FRAME_SIZE);
|
||||
this.setLayout(new BorderLayout());
|
||||
this.setUndecorated(true);
|
||||
this.setIconImage(ImageUtil.getResourceStreamFromClass(RuneLiteSplashScreen.class, "/openosrs.png"));
|
||||
this.setIconImage(ClientUI.ICON);
|
||||
|
||||
final JPanel panel = new JPanel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.awt.image.PixelGrabber;
|
||||
import java.awt.image.RescaleOp;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -361,7 +362,10 @@ public class ImageUtil
|
||||
{
|
||||
synchronized (ImageIO.class)
|
||||
{
|
||||
return ImageIO.read(c.getResourceAsStream(path));
|
||||
try (InputStream in = c.getResourceAsStream(path))
|
||||
{
|
||||
return ImageIO.read(in);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
|
||||
Reference in New Issue
Block a user